Index: sys/kern/subr_bus.c =================================================================== --- sys/kern/subr_bus.c (revision 276982) +++ sys/kern/subr_bus.c (working copy) @@ -2991,6 +2991,18 @@ device_set_unit(device_t dev, int unit) * Some useful method implementations to make life easier for bus drivers. */ +typedef int (*resource_list_printer)(struct resource_list_entry *, int, const char *, int, const char *); + +struct rl_printer { + STAILQ_ENTRY(rl_printer) link; + resource_list_printer callback; + int type; +}; +STAILQ_HEAD(rl_printer_head, rl_printer) rlp_head = + STAILQ_HEAD_INITIALIZER(rlp_head); +MALLOC_DEFINE(M_RL_PRINT, "rl-print", "Resource list printint structures"); +void resource_list_print_register(int type, resource_list_printer cb); + /** * @brief Initialise a resource list. * @@ -3475,6 +3487,25 @@ resource_list_unreserve(struct resource_list *rl, return (resource_list_release(rl, bus, child, type, rid, rle->res)); } +static int +resource_list_print_default(struct resource_list_entry *rle, int printed, + const char *name, int type, const char *format) +{ + int retval = 0; + + if (printed == 0) + retval += printf(" %s ", name); + else + retval += printf(","); + retval += printf(format, rle->start); + if (rle->count > 1) { + retval += printf("-"); + retval += printf(format, rle->start + rle->count - 1); + } + + return retval; +} + /** * @brief Print a description of resources in a resource list * @@ -3495,29 +3526,42 @@ resource_list_print_type(struct resource_list *rl, const char *format) { struct resource_list_entry *rle; + struct rl_printer *rlpe; + resource_list_printer cb; int printed, retval; + cb = resource_list_print_default; + STAILQ_FOREACH(rlpe, &rlp_head, link) { + if (rlpe->type == type) { + cb = rlpe->callback; + break; + } + } + printed = 0; retval = 0; /* Yes, this is kinda cheating */ STAILQ_FOREACH(rle, rl, link) { if (rle->type == type) { - if (printed == 0) - retval += printf(" %s ", name); - else - retval += printf(","); + retval += cb(rle, printed, name, type, format); printed++; - retval += printf(format, rle->start); - if (rle->count > 1) { - retval += printf("-"); - retval += printf(format, rle->start + - rle->count - 1); - } } } return (retval); } +void +resource_list_print_register(int type, resource_list_printer cb) +{ + struct rl_printer *rlpe; + + rlpe = malloc(sizeof(struct rl_printer), M_RL_PRINT, M_ZERO); + rlpe->type = type; + rlpe->callback = cb; + + STAILQ_INSERT_TAIL(&rlp_head, rlpe, link); +} + /** * @brief Releases all the resources in a list. *