diff --git a/sys/dev/dpaa2/dpaa2_mc.h b/sys/dev/dpaa2/dpaa2_mc.h --- a/sys/dev/dpaa2/dpaa2_mc.h +++ b/sys/dev/dpaa2/dpaa2_mc.h @@ -179,6 +179,7 @@ /* 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.c b/sys/dev/dpaa2/dpaa2_mc.c --- a/sys/dev/dpaa2/dpaa2_mc.c +++ b/sys/dev/dpaa2/dpaa2_mc.c @@ -115,7 +115,6 @@ 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 @@ 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 @@ } } - 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 @@ { 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 @@ { 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 @@ 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 @@ 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 @@ 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 @@ * @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_acpi.c b/sys/dev/dpaa2/dpaa2_mc_acpi.c --- a/sys/dev/dpaa2/dpaa2_mc_acpi.c +++ b/sys/dev/dpaa2/dpaa2_mc_acpi.c @@ -352,6 +352,7 @@ 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 --- a/sys/dev/dpaa2/dpaa2_mc_fdt.c +++ b/sys/dev/dpaa2/dpaa2_mc_fdt.c @@ -355,6 +355,7 @@ 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),