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.
This commit is contained in:
parent
13fb665772
commit
87b1520ae4
@ -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.
|
||||
*/
|
||||
|
@ -179,6 +179,14 @@ int resource_list_release(struct resource_list *rl,
|
||||
device_t bus, device_t child,
|
||||
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.
|
||||
*/
|
||||
@ -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_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user