Add BUS_ADDR_{LO,HI}32() macros to correctly extract the lower and

upper halves of 64-bit DMA addresses for 32-bit and 64-bit bus_addr_t.
This is a common pattern in modern drivers, so it's a good idea to provide
a common correct definition.

This particular implementation suggested by riastradh@.
This commit is contained in:
thorpej 2020-03-08 02:42:00 +00:00
parent 0020741559
commit 89af285019
1 changed files with 9 additions and 1 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: bus.h,v 1.12 2018/04/19 21:19:07 christos Exp $ */
/* $NetBSD: bus.h,v 1.13 2020/03/08 02:42:00 thorpej Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -245,4 +245,12 @@ typedef struct bus_dmamap {
} *bus_dmamap_t;
#endif /* __HAVE_NO_BUS_DMA */
/*
* Convenience macros to correctly extract the upper and lower
* 32 bits of a bus_addr_t (which may be a 32-bit or 64-bit
* value).
*/
#define BUS_ADDR_HI32(a) ((uint32_t) __SHIFTOUT(a, __BITS(32,63)))
#define BUS_ADDR_LO32(a) ((uint32_t) __SHIFTOUT(a, __BITS(0,31)))
#endif /* _SYS_BUS_H_ */