git: 9b619f0e9082 - main - dpaa2: Use bus_generic_rman_*
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 27 Feb 2024 19:45:04 UTC
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=9b619f0e9082b8f97f0e20ec5176fe40ba8565f8 commit 9b619f0e9082b8f97f0e20ec5176fe40ba8565f8 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2024-02-27 19:43:50 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2024-02-27 19:43:50 +0000 dpaa2: Use bus_generic_rman_* Reviewed by: dsl Differential Revision: https://reviews.freebsd.org/D43937 --- sys/dev/dpaa2/dpaa2_mc.c | 76 +++++++++++++++++-------------------------- sys/dev/dpaa2/dpaa2_mc.h | 1 + sys/dev/dpaa2/dpaa2_mc_acpi.c | 1 + sys/dev/dpaa2/dpaa2_mc_fdt.c | 1 + 4 files changed, 33 insertions(+), 46 deletions(-) diff --git a/sys/dev/dpaa2/dpaa2_mc.c b/sys/dev/dpaa2/dpaa2_mc.c index 0deebf7e8b24..6d11e50b1f98 100644 --- a/sys/dev/dpaa2/dpaa2_mc.c +++ b/sys/dev/dpaa2/dpaa2_mc.c @@ -115,7 +115,6 @@ static struct resource_spec dpaa2_mc_spec[] = { static u_int dpaa2_mc_get_xref(device_t, device_t); static u_int dpaa2_mc_map_id(device_t, device_t, uintptr_t *); -static struct rman *dpaa2_mc_rman(device_t, int); static int dpaa2_mc_alloc_msi_impl(device_t, device_t, int, int, int *); static int dpaa2_mc_release_msi_impl(device_t, device_t, int, int *); @@ -312,10 +311,10 @@ dpaa2_mc_alloc_resource(device_t mcdev, device_t child, int type, int *rid, struct rman *rm; int error; - rm = dpaa2_mc_rman(mcdev, type); - if (!rm) - return (BUS_ALLOC_RESOURCE(device_get_parent(mcdev), child, - type, rid, start, end, count, flags)); + rm = dpaa2_mc_rman(mcdev, type, flags); + if (rm == NULL) + return (bus_generic_alloc_resource(mcdev, child, type, rid, + start, end, count, flags)); /* * Skip managing DPAA2-specific resource. It must be provided to MC by @@ -331,24 +330,10 @@ dpaa2_mc_alloc_resource(device_t mcdev, device_t child, int type, int *rid, } } - res = rman_reserve_resource(rm, start, end, count, flags, child); - if (!res) { - device_printf(mcdev, "rman_reserve_resource() failed: " - "start=%#jx, end=%#jx, count=%#jx\n", start, end, count); + res = bus_generic_rman_alloc_resource(mcdev, child, type, rid, start, + end, count, flags); + if (res == NULL) goto fail; - } - - rman_set_rid(res, *rid); - - if (flags & RF_ACTIVE) { - if (bus_activate_resource(child, type, *rid, res)) { - device_printf(mcdev, "bus_activate_resource() failed: " - "rid=%d, res=%#jx\n", *rid, (uintmax_t) res); - rman_release_resource(res); - goto fail; - } - } - return (res); fail: device_printf(mcdev, "%s() failed: type=%d, rid=%d, start=%#jx, " @@ -363,9 +348,10 @@ dpaa2_mc_adjust_resource(device_t mcdev, device_t child, int type, { struct rman *rm; - rm = dpaa2_mc_rman(mcdev, type); + rm = dpaa2_mc_rman(mcdev, type, rman_get_flags(r)); if (rm) - return (rman_adjust_resource(r, start, end)); + return (bus_generic_rman_adjust_resource(mcdev, child, type, r, + start, end)); return (bus_generic_adjust_resource(mcdev, child, type, r, start, end)); } @@ -375,12 +361,10 @@ dpaa2_mc_release_resource(device_t mcdev, device_t child, int type, int rid, { struct rman *rm; - rm = dpaa2_mc_rman(mcdev, type); - if (rm) { - KASSERT(rman_is_region_manager(r, rm), ("rman mismatch")); - rman_release_resource(r); - } - + rm = dpaa2_mc_rman(mcdev, type, rman_get_flags(r)); + if (rm) + return (bus_generic_rman_release_resource(mcdev, child, type, + rid, r)); return (bus_generic_release_resource(mcdev, child, type, rid, r)); } @@ -388,26 +372,26 @@ int dpaa2_mc_activate_resource(device_t mcdev, device_t child, int type, int rid, struct resource *r) { - int rc; - - if ((rc = rman_activate_resource(r)) != 0) - return (rc); + struct rman *rm; - return (BUS_ACTIVATE_RESOURCE(device_get_parent(mcdev), child, type, - rid, r)); + rm = dpaa2_mc_rman(mcdev, type, rman_get_flags(r)); + if (rm) + return (bus_generic_rman_activate_resource(mcdev, child, type, + rid, r)); + return (bus_generic_activate_resource(mcdev, child, type, rid, r)); } int dpaa2_mc_deactivate_resource(device_t mcdev, device_t child, int type, int rid, struct resource *r) { - int rc; - - if ((rc = rman_deactivate_resource(r)) != 0) - return (rc); + struct rman *rm; - return (BUS_DEACTIVATE_RESOURCE(device_get_parent(mcdev), child, type, - rid, r)); + rm = dpaa2_mc_rman(mcdev, type, rman_get_flags(r)); + if (rm) + return (bus_generic_rman_deactivate_resource(mcdev, child, type, + rid, r)); + return (bus_generic_deactivate_resource(mcdev, child, type, rid, r)); } /* @@ -498,7 +482,7 @@ dpaa2_mc_manage_dev(device_t mcdev, device_t dpaa2_dev, uint32_t flags) if (flags & DPAA2_MC_DEV_ALLOCATABLE) { /* Select rman based on a type of the DPAA2 device. */ - rm = dpaa2_mc_rman(mcdev, dinfo->dtype); + rm = dpaa2_mc_rman(mcdev, dinfo->dtype, 0); if (!rm) return (ENOENT); /* Manage DPAA2 device as an allocatable resource. */ @@ -523,7 +507,7 @@ dpaa2_mc_get_free_dev(device_t mcdev, device_t *dpaa2_dev, return (EINVAL); /* Select resource manager based on a type of the DPAA2 device. */ - rm = dpaa2_mc_rman(mcdev, devtype); + rm = dpaa2_mc_rman(mcdev, devtype, 0); if (!rm) return (ENOENT); /* Find first free DPAA2 device of the given type. */ @@ -749,8 +733,8 @@ dpaa2_mc_map_id(device_t mcdev, device_t child, uintptr_t *id) * @internal * @brief Obtain a resource manager based on the given type of the resource. */ -static struct rman * -dpaa2_mc_rman(device_t mcdev, int type) +struct rman * +dpaa2_mc_rman(device_t mcdev, int type, u_int flags) { struct dpaa2_mc_softc *sc; diff --git a/sys/dev/dpaa2/dpaa2_mc.h b/sys/dev/dpaa2/dpaa2_mc.h index 9a21c9724b82..40b318c4c9e7 100644 --- a/sys/dev/dpaa2/dpaa2_mc.h +++ b/sys/dev/dpaa2/dpaa2_mc.h @@ -179,6 +179,7 @@ int dpaa2_mc_detach(device_t dev); /* For bus interface. */ +struct rman *dpaa2_mc_rman(device_t mcdev, int type, u_int flags); struct resource * dpaa2_mc_alloc_resource(device_t mcdev, device_t child, int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags); diff --git a/sys/dev/dpaa2/dpaa2_mc_acpi.c b/sys/dev/dpaa2/dpaa2_mc_acpi.c index 388bb764afff..2007c18bec67 100644 --- a/sys/dev/dpaa2/dpaa2_mc_acpi.c +++ b/sys/dev/dpaa2/dpaa2_mc_acpi.c @@ -352,6 +352,7 @@ static device_method_t dpaa2_mc_acpi_methods[] = { DEVMETHOD(device_detach, dpaa2_mc_detach), /* Bus interface */ + DEVMETHOD(bus_get_rman, dpaa2_mc_rman), DEVMETHOD(bus_alloc_resource, dpaa2_mc_alloc_resource), DEVMETHOD(bus_adjust_resource, dpaa2_mc_adjust_resource), DEVMETHOD(bus_release_resource, dpaa2_mc_release_resource), diff --git a/sys/dev/dpaa2/dpaa2_mc_fdt.c b/sys/dev/dpaa2/dpaa2_mc_fdt.c index 8e9ab10dec9d..a6babfc89ca9 100644 --- a/sys/dev/dpaa2/dpaa2_mc_fdt.c +++ b/sys/dev/dpaa2/dpaa2_mc_fdt.c @@ -355,6 +355,7 @@ static device_method_t dpaa2_mc_fdt_methods[] = { DEVMETHOD(device_detach, dpaa2_mc_detach), /* Bus interface */ + DEVMETHOD(bus_get_rman, dpaa2_mc_rman), DEVMETHOD(bus_alloc_resource, dpaa2_mc_alloc_resource), DEVMETHOD(bus_adjust_resource, dpaa2_mc_adjust_resource), DEVMETHOD(bus_release_resource, dpaa2_mc_release_resource),