summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorthorpej <thorpej@NetBSD.org>2020-03-08 02:42:00 +0000
committerthorpej <thorpej@NetBSD.org>2020-03-08 02:42:00 +0000
commita2c3c26bf080f9f0c3fde8b34a480decaeb1f2d2 (patch)
tree9e923dea96ff558a8d4725e386e9a18cff0180bb /sys
parent39563cf7493ff9949e5d5e49da6a0a52a2a6c6e3 (diff)
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@.
Diffstat (limited to 'sys')
-rw-r--r--sys/sys/bus.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/sys/sys/bus.h b/sys/sys/bus.h
index fc011fa4e65..3845658b015 100644
--- a/sys/sys/bus.h
+++ b/sys/sys/bus.h
@@ -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_ */