Module Name:    src
Committed By:   thorpej
Date:           Sun Mar  8 02:42:00 UTC 2020

Modified Files:
        src/sys/sys: bus.h

Log Message:
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@.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/sys/bus.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/bus.h
diff -u src/sys/sys/bus.h:1.12 src/sys/sys/bus.h:1.13
--- src/sys/sys/bus.h:1.12	Thu Apr 19 21:19:07 2018
+++ src/sys/sys/bus.h	Sun Mar  8 02:42:00 2020
@@ -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_ */

Reply via email to