git: b937f9bf7509 - main - bus: Add __BUS_ACCESSOR_DEFAULT
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 24 Feb 2026 20:33:27 UTC
The branch main has been updated by jhb:
URL: https://cgit.FreeBSD.org/src/commit/?id=b937f9bf750907602606691dd92fb6d70e9f88da
commit b937f9bf750907602606691dd92fb6d70e9f88da
Author: John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2026-02-24 20:29:40 +0000
Commit: John Baldwin <jhb@FreeBSD.org>
CommitDate: 2026-02-24 20:29:40 +0000
bus: Add __BUS_ACCESSOR_DEFAULT
This macro is similar to __BUS_ACCESSOR in that it creates three
helper routines for an ivar, but the "get" wrapper returns a default
value if BUS_READ_IVAR does not return a value.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D55353
---
sys/sys/bus.h | 40 +++++++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 11 deletions(-)
diff --git a/sys/sys/bus.h b/sys/sys/bus.h
index 0d1baaafb4cd..a2e315bb9dee 100644
--- a/sys/sys/bus.h
+++ b/sys/sys/bus.h
@@ -943,7 +943,7 @@ DECLARE_MODULE(_name##_##busname, _name##_##busname##_mod, \
/**
* Generic ivar accessor generation macros for bus drivers
*/
-#define __BUS_ACCESSOR(varp, var, ivarp, ivar, type) \
+#define __BUS_ACCESSOR_COMMON(varp, var, ivarp, ivar, type) \
\
static __inline bool \
varp ## _has_ ## var(device_t dev) \
@@ -956,29 +956,47 @@ varp ## _has_ ## var(device_t dev) \
return (e == 0); \
} \
\
+static __inline void \
+varp ## _set_ ## var(device_t dev, type t) \
+{ \
+ uintptr_t v = (uintptr_t) t; \
+ int e __diagused; \
+ e = BUS_WRITE_IVAR(device_get_parent(dev), dev, \
+ ivarp ## _IVAR_ ## ivar, v); \
+ KASSERT(e == 0, ("%s failed for %s on bus %s, error = %d", \
+ __func__, device_get_nameunit(dev), \
+ device_get_nameunit(device_get_parent(dev)), e)); \
+}
+
+#define __BUS_ACCESSOR(varp, var, ivarp, ivar, type) \
+ __BUS_ACCESSOR_COMMON(varp, var, ivarp, ivar, type) \
+ \
static __inline type \
varp ## _get_ ## var(device_t dev) \
{ \
uintptr_t v = 0; \
int e __diagused; \
+ \
e = BUS_READ_IVAR(device_get_parent(dev), dev, \
ivarp ## _IVAR_ ## ivar, &v); \
KASSERT(e == 0, ("%s failed for %s on bus %s, error = %d", \
__func__, device_get_nameunit(dev), \
device_get_nameunit(device_get_parent(dev)), e)); \
return ((type) v); \
-} \
+}
+
+#define __BUS_ACCESSOR_DEFAULT(varp, var, ivarp, ivar, type, default) \
+ __BUS_ACCESSOR_COMMON(varp, var, ivarp, ivar, type) \
\
-static __inline void \
-varp ## _set_ ## var(device_t dev, type t) \
+static __inline type \
+varp ## _get_ ## var(device_t dev) \
{ \
- uintptr_t v = (uintptr_t) t; \
- int e __diagused; \
- e = BUS_WRITE_IVAR(device_get_parent(dev), dev, \
- ivarp ## _IVAR_ ## ivar, v); \
- KASSERT(e == 0, ("%s failed for %s on bus %s, error = %d", \
- __func__, device_get_nameunit(dev), \
- device_get_nameunit(device_get_parent(dev)), e)); \
+ uintptr_t v = 0; \
+ int e; \
+ \
+ e = BUS_READ_IVAR(device_get_parent(dev), dev, \
+ ivarp ## _IVAR_ ## ivar, &v); \
+ return (e == 0 ? (type) v : (default)); \
}
struct device_location_cache;