From 72133122d480d071966ea6f0d04f570b8ee5ad30 Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 24 Mar 2005 18:13:11 +0000 Subject: Move implementation of hw.bus.rman sysctl to subr_rman.c so that subr_bus.c doesn't need to peek inside struct resource. OK from: imp --- sys/kern/subr_bus.c | 87 ---------------------------------------------------- sys/kern/subr_rman.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ sys/sys/sysctl.h | 1 + 3 files changed, 88 insertions(+), 87 deletions(-) (limited to 'sys') diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 570eca7..9edcbae 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -29,7 +29,6 @@ __FBSDID("$FreeBSD$"); #include "opt_bus.h" -#define __RMAN_RESOURCE_VISIBLE #include #include #include @@ -3918,92 +3917,6 @@ sysctl_devices(SYSCTL_HANDLER_ARGS) SYSCTL_NODE(_hw_bus, OID_AUTO, devices, CTLFLAG_RD, sysctl_devices, "system device tree"); -/* - * Sysctl interface for scanning the resource lists. - * - * We take two input parameters; the index into the list of resource - * managers, and the resource offset into the list. - */ -static int -sysctl_rman(SYSCTL_HANDLER_ARGS) -{ - int *name = (int *)arg1; - u_int namelen = arg2; - int rman_idx, res_idx; - struct rman *rm; - struct resource *res; - struct u_rman urm; - struct u_resource ures; - int error; - - if (namelen != 3) - return (EINVAL); - - if (bus_data_generation_check(name[0])) - return (EINVAL); - rman_idx = name[1]; - res_idx = name[2]; - - /* - * Find the indexed resource manager - */ - TAILQ_FOREACH(rm, &rman_head, rm_link) { - if (rman_idx-- == 0) - break; - } - if (rm == NULL) - return (ENOENT); - - /* - * If the resource index is -1, we want details on the - * resource manager. - */ - if (res_idx == -1) { - urm.rm_handle = (uintptr_t)rm; - strlcpy(urm.rm_descr, rm->rm_descr, RM_TEXTLEN); - urm.rm_start = rm->rm_start; - urm.rm_size = rm->rm_end - rm->rm_start + 1; - urm.rm_type = rm->rm_type; - - error = SYSCTL_OUT(req, &urm, sizeof(urm)); - return (error); - } - - /* - * Find the indexed resource and return it. - */ - TAILQ_FOREACH(res, &rm->rm_list, r_link) { - if (res_idx-- == 0) { - ures.r_handle = (uintptr_t)res; - ures.r_parent = (uintptr_t)res->r_rm; - ures.r_device = (uintptr_t)res->r_dev; - if (res->r_dev != NULL) { - if (device_get_name(res->r_dev) != NULL) { - snprintf(ures.r_devname, RM_TEXTLEN, - "%s%d", - device_get_name(res->r_dev), - device_get_unit(res->r_dev)); - } else { - strlcpy(ures.r_devname, "nomatch", - RM_TEXTLEN); - } - } else { - ures.r_devname[0] = '\0'; - } - ures.r_start = res->r_start; - ures.r_size = res->r_end - res->r_start + 1; - ures.r_flags = res->r_flags; - - error = SYSCTL_OUT(req, &ures, sizeof(ures)); - return (error); - } - } - return (ENOENT); -} - -SYSCTL_NODE(_hw_bus, OID_AUTO, rman, CTLFLAG_RD, sysctl_rman, - "kernel resource manager"); - int bus_data_generation_check(int generation) { diff --git a/sys/kern/subr_rman.c b/sys/kern/subr_rman.c index 9901c41..f68dd24 100644 --- a/sys/kern/subr_rman.c +++ b/sys/kern/subr_rman.c @@ -713,3 +713,90 @@ rman_get_device(struct resource *r) { return (r->r_dev); } + +/* + * Sysctl interface for scanning the resource lists. + * + * We take two input parameters; the index into the list of resource + * managers, and the resource offset into the list. + */ +static int +sysctl_rman(SYSCTL_HANDLER_ARGS) +{ + int *name = (int *)arg1; + u_int namelen = arg2; + int rman_idx, res_idx; + struct rman *rm; + struct resource *res; + struct u_rman urm; + struct u_resource ures; + int error; + + if (namelen != 3) + return (EINVAL); + + if (bus_data_generation_check(name[0])) + return (EINVAL); + rman_idx = name[1]; + res_idx = name[2]; + + /* + * Find the indexed resource manager + */ + TAILQ_FOREACH(rm, &rman_head, rm_link) { + if (rman_idx-- == 0) + break; + } + if (rm == NULL) + return (ENOENT); + + /* + * If the resource index is -1, we want details on the + * resource manager. + */ + if (res_idx == -1) { + urm.rm_handle = (uintptr_t)rm; + strlcpy(urm.rm_descr, rm->rm_descr, RM_TEXTLEN); + urm.rm_start = rm->rm_start; + urm.rm_size = rm->rm_end - rm->rm_start + 1; + urm.rm_type = rm->rm_type; + + error = SYSCTL_OUT(req, &urm, sizeof(urm)); + return (error); + } + + /* + * Find the indexed resource and return it. + */ + TAILQ_FOREACH(res, &rm->rm_list, r_link) { + if (res_idx-- == 0) { + ures.r_handle = (uintptr_t)res; + ures.r_parent = (uintptr_t)res->r_rm; + ures.r_device = (uintptr_t)res->r_dev; + if (res->r_dev != NULL) { + if (device_get_name(res->r_dev) != NULL) { + snprintf(ures.r_devname, RM_TEXTLEN, + "%s%d", + device_get_name(res->r_dev), + device_get_unit(res->r_dev)); + } else { + strlcpy(ures.r_devname, "nomatch", + RM_TEXTLEN); + } + } else { + ures.r_devname[0] = '\0'; + } + ures.r_start = res->r_start; + ures.r_size = res->r_end - res->r_start + 1; + ures.r_flags = res->r_flags; + + error = SYSCTL_OUT(req, &ures, sizeof(ures)); + return (error); + } + } + return (ENOENT); +} + +SYSCTL_NODE(_hw_bus, OID_AUTO, rman, CTLFLAG_RD, sysctl_rman, + "kernel resource manager"); + diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index a91f5cb..7879e42 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -596,6 +596,7 @@ SYSCTL_DECL(_net); SYSCTL_DECL(_debug); SYSCTL_DECL(_debug_sizeof); SYSCTL_DECL(_hw); +SYSCTL_DECL(_hw_bus); SYSCTL_DECL(_machdep); SYSCTL_DECL(_user); SYSCTL_DECL(_compat); -- cgit v1.1