From 4316754674ba457de645747ccdae5b7c323b70ac Mon Sep 17 00:00:00 2001 From: Hasso Tepper Date: Wed, 12 Sep 2007 07:59:31 +0000 Subject: [PATCH] Add bus_alloc_resources() and bus_release_resources() functions to allow to simplify the code and to make it easier to port drivers (initially the agp(4)) from FreeBSD. Obtained-from: FreeBSD --- sys/kern/subr_bus.c | 35 ++++++++++++++++++++++++++++++++++- sys/sys/bus.h | 13 ++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 107ec1c2eb..e12bb6246b 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/subr_bus.c,v 1.54.2.9 2002/10/10 15:13:32 jhb Exp $ - * $DragonFly: src/sys/kern/subr_bus.c,v 1.39 2007/07/31 20:47:14 corecode Exp $ + * $DragonFly: src/sys/kern/subr_bus.c,v 1.40 2007/09/12 07:59:31 hasso Exp $ */ #include "opt_bus.h" @@ -2319,6 +2319,39 @@ bus_generic_child_present(device_t bus, device_t child) * less-wordy code. In the future, it might make sense for this code * to maintain some sort of a list of resources allocated by each device. */ +int +bus_alloc_resources(device_t dev, struct resource_spec *rs, + struct resource **res) +{ + int i; + + for (i = 0; rs[i].type != -1; i++) + res[i] = NULL; + for (i = 0; rs[i].type != -1; i++) { + res[i] = bus_alloc_resource_any(dev, + rs[i].type, &rs[i].rid, rs[i].flags); + if (res[i] == NULL) { + bus_release_resources(dev, rs, res); + return (ENXIO); + } + } + return (0); +} + +void +bus_release_resources(device_t dev, const struct resource_spec *rs, + struct resource **res) +{ + int i; + + for (i = 0; rs[i].type != -1; i++) + if (res[i] != NULL) { + bus_release_resource( + dev, rs[i].type, rs[i].rid, res[i]); + res[i] = NULL; + } +} + struct resource * bus_alloc_resource(device_t dev, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) diff --git a/sys/sys/bus.h b/sys/sys/bus.h index baed9b9944..c984b2e8fc 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/sys/bus.h,v 1.30.2.5 2004/03/17 17:54:25 njl Exp $ - * $DragonFly: src/sys/sys/bus.h,v 1.25 2007/05/01 00:05:18 dillon Exp $ + * $DragonFly: src/sys/sys/bus.h,v 1.26 2007/09/12 07:59:31 hasso Exp $ */ #ifndef _SYS_BUS_H_ @@ -252,6 +252,17 @@ int bus_generic_rl_release_resource (device_t, device_t, int, int, * Wrapper functions for the BUS_*_RESOURCE methods to make client code * a little simpler. */ +struct resource_spec { + int type; + int rid; + int flags; +}; + +int bus_alloc_resources(device_t dev, struct resource_spec *rs, + struct resource **res); +void bus_release_resources(device_t dev, const struct resource_spec *rs, + struct resource **res); + struct resource *bus_alloc_resource(device_t dev, int type, int *rid, u_long start, u_long end, u_long count, u_int flags); -- 2.11.4.GIT