Project

General

Profile

Bug #804 ยป new-bus-resources-functions.patch

hasso, 09/10/2007 10:02 AM

View differences:

sys/kern/subr_bus.c
* 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)
sys/sys/bus.h
* 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);
    (1-1/1)