git: 5bda26333a8e - main - gpiobus: Use bus_generic_rman_*
Date: Wed, 14 Feb 2024 22:52:38 UTC
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=5bda26333a8ebf34190e3a9124895e6a18e58e93 commit 5bda26333a8ebf34190e3a9124895e6a18e58e93 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2024-02-14 22:07:32 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2024-02-14 22:07:32 +0000 gpiobus: Use bus_generic_rman_* Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D43887 --- sys/dev/gpio/gpiobus.c | 57 +++++++++++++++++--------------------------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/sys/dev/gpio/gpiobus.c b/sys/dev/gpio/gpiobus.c index 99d3114d51da..6d739597b759 100644 --- a/sys/dev/gpio/gpiobus.c +++ b/sys/dev/gpio/gpiobus.c @@ -809,20 +809,29 @@ gpiobus_write_ivar(device_t dev, device_t child, int which, uintptr_t value) return (0); } +static struct rman * +gpiobus_get_rman(device_t bus, int type, u_int flags) +{ + struct gpiobus_softc *sc; + + sc = device_get_softc(bus); + switch (type) { + case SYS_RES_IRQ: + return (&sc->sc_intr_rman); + default: + return (NULL); + } +} + static struct resource * gpiobus_alloc_resource(device_t bus, device_t child, int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) { - struct gpiobus_softc *sc; - struct resource *rv; struct resource_list *rl; struct resource_list_entry *rle; int isdefault; - if (type != SYS_RES_IRQ) - return (NULL); isdefault = (RMAN_IS_DEFAULT_RANGE(start, end) && count == 1); - rle = NULL; if (isdefault) { rl = BUS_GET_RESOURCE_LIST(bus, child); if (rl == NULL) @@ -830,40 +839,12 @@ gpiobus_alloc_resource(device_t bus, device_t child, int type, int *rid, rle = resource_list_find(rl, type, *rid); if (rle == NULL) return (NULL); - if (rle->res != NULL) - panic("%s: resource entry is busy", __func__); start = rle->start; count = rle->count; end = rle->end; } - sc = device_get_softc(bus); - rv = rman_reserve_resource(&sc->sc_intr_rman, start, end, count, flags, - child); - if (rv == NULL) - return (NULL); - rman_set_rid(rv, *rid); - if ((flags & RF_ACTIVE) != 0 && - bus_activate_resource(child, type, *rid, rv) != 0) { - rman_release_resource(rv); - return (NULL); - } - - return (rv); -} - -static int -gpiobus_release_resource(device_t bus __unused, device_t child, int type, - int rid, struct resource *r) -{ - int error; - - if (rman_get_flags(r) & RF_ACTIVE) { - error = bus_deactivate_resource(child, type, rid, r); - if (error) - return (error); - } - - return (rman_release_resource(r)); + return (bus_generic_rman_alloc_resource(bus, child, type, rid, start, + end, count, flags)); } static struct resource_list * @@ -1060,9 +1041,9 @@ static device_method_t gpiobus_methods[] = { DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource), DEVMETHOD(bus_alloc_resource, gpiobus_alloc_resource), - DEVMETHOD(bus_release_resource, gpiobus_release_resource), - DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), - DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), + DEVMETHOD(bus_release_resource, bus_generic_rman_release_resource), + DEVMETHOD(bus_activate_resource, bus_generic_rman_activate_resource), + DEVMETHOD(bus_deactivate_resource, bus_generic_rman_deactivate_resource), DEVMETHOD(bus_get_resource_list, gpiobus_get_resource_list), DEVMETHOD(bus_add_child, gpiobus_add_child), DEVMETHOD(bus_rescan, gpiobus_rescan),