diff options
author | tmm <tmm@FreeBSD.org> | 2001-12-21 21:45:09 +0000 |
---|---|---|
committer | tmm <tmm@FreeBSD.org> | 2001-12-21 21:45:09 +0000 |
commit | 5d1f367b0b4b0ca0ef88b09b083d747e457c9f7d (patch) | |
tree | 2d00173ab25b2c22cef03261498ca1bd9426b18d /sys | |
parent | dadac692002f0972c05f77679ecf7a78e8446731 (diff) | |
download | FreeBSD-src-5d1f367b0b4b0ca0ef88b09b083d747e457c9f7d.zip FreeBSD-src-5d1f367b0b4b0ca0ef88b09b083d747e457c9f7d.tar.gz |
Add a generic __BUS_ACCESSOR macro to construct ivar accessor functions,
and a generic resource_list_print_type() function to print all resouces
of a certain type in a resource list.
Use ulmin()/ulmax() instead of min()/max() in two places to handle
u_longs correctly.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/subr_bus.c | 32 | ||||
-rw-r--r-- | sys/sys/bus.h | 28 |
2 files changed, 58 insertions, 2 deletions
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 7e0e86f..df73c8f 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -1207,8 +1207,8 @@ resource_list_alloc(struct resource_list *rl, device_t bus, device_t child, if (isdefault) { start = rle->start; - count = max(count, rle->count); - end = max(rle->end, start + count - 1); + count = ulmax(count, rle->count); + end = ulmax(rle->end, start + count - 1); } rle->res = BUS_ALLOC_RESOURCE(device_get_parent(bus), child, @@ -1255,6 +1255,34 @@ resource_list_release(struct resource_list *rl, device_t bus, device_t child, return (0); } +int +resource_list_print_type(struct resource_list *rl, const char *name, int type, + const char *format) +{ + struct resource_list_entry *rle; + int printed, retval; + + printed = 0; + retval = 0; + /* Yes, this is kinda cheating */ + SLIST_FOREACH(rle, rl, link) { + if (rle->type == type) { + if (printed == 0) + retval += printf(" %s ", name); + else + retval += printf(","); + printed++; + retval += printf(format, rle->start); + if (rle->count > 1) { + retval += printf("-"); + retval += printf(format, rle->start + + rle->count - 1); + } + } + } + return retval; +} + /* * Call DEVICE_IDENTIFY for each driver. */ diff --git a/sys/sys/bus.h b/sys/sys/bus.h index 28a2c94..f5d5d6f 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -180,6 +180,14 @@ int resource_list_release(struct resource_list *rl, int type, int rid, struct resource *res); /* + * Print all resources of a specified type, for use in bus_print_child. + * The name is printed if at least one resource of the given type is available. + * The format ist used to print resource start and end. + */ +int resource_list_print_type(struct resource_list *rl, + const char *name, int type, + const char *format); +/* * The root bus, to which all top-level busses are attached. */ extern device_t root_bus; @@ -411,6 +419,26 @@ static moduledata_t name##_##busname##_mod = { \ DECLARE_MODULE(name##_##busname, name##_##busname##_mod, \ SI_SUB_DRIVERS, SI_ORDER_MIDDLE) +/* + * Generic ivar accessor generation macros for bus drivers + */ +#define __BUS_ACCESSOR(varp, var, ivarp, ivar, type) \ + \ +static __inline type varp ## _get_ ## var(device_t dev) \ +{ \ + uintptr_t v; \ + BUS_READ_IVAR(device_get_parent(dev), dev, \ + ivarp ## _IVAR_ ## ivar, &v); \ + return ((type) v); \ +} \ + \ +static __inline void varp ## _set_ ## var(device_t dev, type t) \ +{ \ + uintptr_t v = (uintptr_t) t; \ + BUS_WRITE_IVAR(device_get_parent(dev), dev, \ + ivarp ## _IVAR_ ## ivar, v); \ +} + #endif /* _KERNEL */ #endif /* !_SYS_BUS_H_ */ |