From nobody Tue Feb 27 19:45:07 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TknyC3kbYz5CKF7; Tue, 27 Feb 2024 19:45:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TknyC1y6mz57FC; Tue, 27 Feb 2024 19:45:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709063107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=eDiC2lF1v10+ZLumGmrUAJ3pprrMwz3quvuQRm6E2uw=; b=WJh5pv9+/htPeN8XsCIoQ9SapJYJqd27X3CLrnPCnXr85cSYcFr78pYquOnk1+GeUKqUqi YDytSBZfaOvVQdnh2AKkfKej0tRhqo0YXaQpZ8P6zTjoXyIS2mT0iUa76njruU9A70uUdV oeTh92Yi0+zig6XNIO21FICYU9J58DsUEiHlJrEijJ/ihMPGKqQfhkVnqpwVqG9f+tt8x7 dtkyFMBcWHq1p+WPX4nCD5ywdP2reX+WO69bMxHRaGw9pqCAFxkbrHn0UtYeObVAK9sBjv aVPxr4AMYYG3RzwL3ZzCusSJN+dcxLVV7rOmuWssP6Z1hP21ItkHXeXMuGo8cw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1709063107; a=rsa-sha256; cv=none; b=eTh556g5NR5SM0iCroHvAVmEiCkhjjBciyZ5sUa6FOVgO/mCdKzq7tSVWTb/kOv0GE0497 vjf4gBct606yeIrLdWv0HHPwzHjRvTKaGNDllxOINKvljJIrRRC2oQDIa5DcRduIPI9uvq F5w+R8zbK9lTWrFhYZvp3Vn5fE2Nc/qtw5gOXfuG9EjzR4pFhlKsNJSUgJ1Kco9CU8xV6z 1EJeVHkck/XcaCU+L53LqDF74SNxq0xgXmVSibSF5WZe0wAgcUhKcbAZoS9bjgvT/6/mHP LVKWFyqVHf0AXvuDfvlA9YklSB556Low7tKqWMWdWe79Zz0RhwqGhoqZ1GExkQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709063107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=eDiC2lF1v10+ZLumGmrUAJ3pprrMwz3quvuQRm6E2uw=; b=djw4ppFmhuSHN5m9wDCjy1sbRIfPZ0pA/Fxs4FhBH84DEHXWHPwmwxvXh7ey0yS4II3nlW z/zRyUkCAqtuDJBTWxGjmrGWIuRo3TnZXdULxBspHOej2vBxjPNac8ShHaIRmhr4RNyA0N +ToTAEAHVCDpPz7oMloVs4IUxrZXM/cZbDIuS/DvdRt6ZUtAzLHmKi6qifQdLKax2vGVmm QqrFxVNBKG1VT7RHwtACs7RYC0JdlkkkcIskK/i/YWYzvopx6XicDgzv2nx4LwKlpuGax0 0Bl76VpEfbbD37AgCN5abuXca4w7JHy0YEw6sK/SaqawdbEA7G0dCXCx52osbQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TknyC0tDKzQnD; Tue, 27 Feb 2024 19:45:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41RJj7ZS093063; Tue, 27 Feb 2024 19:45:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41RJj7SD093060; Tue, 27 Feb 2024 19:45:07 GMT (envelope-from git) Date: Tue, 27 Feb 2024 19:45:07 GMT Message-Id: <202402271945.41RJj7SD093060@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 3a48dfe115f3 - main - bhnd_chipc: Make use of bus_generic_rman_* to simplify some code List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3a48dfe115f35abac6c2d9ec03a6a574baeaf0bc Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=3a48dfe115f35abac6c2d9ec03a6a574baeaf0bc commit 3a48dfe115f35abac6c2d9ec03a6a574baeaf0bc Author: John Baldwin AuthorDate: 2024-02-27 19:44:22 +0000 Commit: John Baldwin CommitDate: 2024-02-27 19:44:22 +0000 bhnd_chipc: Make use of bus_generic_rman_* to simplify some code This uses bus_generic_rman_alloc/release_resource to reduce some code duplication. However, I've left the custom activate/deactivate methods as-is. Differential Revision: https://reviews.freebsd.org/D43939 --- sys/dev/bhnd/cores/chipc/chipc.c | 68 +++++++++++++--------------------------- 1 file changed, 22 insertions(+), 46 deletions(-) diff --git a/sys/dev/bhnd/cores/chipc/chipc.c b/sys/dev/bhnd/cores/chipc/chipc.c index 0510a3195015..f99f42fb3ac3 100644 --- a/sys/dev/bhnd/cores/chipc/chipc.c +++ b/sys/dev/bhnd/cores/chipc/chipc.c @@ -123,13 +123,13 @@ static void chipc_disable_otp_power(struct chipc_softc *sc); static int chipc_enable_sprom_pins(struct chipc_softc *sc); static void chipc_disable_sprom_pins(struct chipc_softc *sc); -static int chipc_try_activate_resource(struct chipc_softc *sc, +static int chipc_try_activate_resource(device_t dev, device_t child, int type, int rid, struct resource *r, bool req_direct); static int chipc_init_rman(struct chipc_softc *sc); static void chipc_free_rman(struct chipc_softc *sc); -static struct rman *chipc_get_rman(struct chipc_softc *sc, int type); +static struct rman *chipc_get_rman(device_t dev, int type, u_int flags); /* quirk and capability flag convenience macros */ #define CHIPC_QUIRK(_sc, _name) \ @@ -747,10 +747,13 @@ chipc_free_rman(struct chipc_softc *sc) * * @param sc The chipc device state. * @param type The resource type (e.g. SYS_RES_MEMORY, SYS_RES_IRQ, ...) + * @param flags Resource flags (e.g. RF_PREFETCHABLE) */ static struct rman * -chipc_get_rman(struct chipc_softc *sc, int type) +chipc_get_rman(device_t dev, int type, u_int flags) { + struct chipc_softc *sc = device_get_softc(dev); + switch (type) { case SYS_RES_MEMORY: return (&sc->mem_rman); @@ -782,7 +785,7 @@ chipc_alloc_resource(device_t dev, device_t child, int type, rle = NULL; /* Fetch the resource manager, delegate request if necessary */ - rm = chipc_get_rman(sc, type); + rm = chipc_get_rman(dev, type, flags); if (rm == NULL) { /* Requested resource type is delegated to our parent */ rv = bus_generic_rl_alloc_resource(dev, child, type, rid, @@ -851,31 +854,13 @@ chipc_alloc_resource(device_t dev, device_t child, int type, return (NULL); /* Make our rman reservation */ - rv = rman_reserve_resource(rm, start, end, count, flags & ~RF_ACTIVE, - child); + rv = bus_generic_rman_alloc_resource(dev, child, type, rid, start, end, + count, flags); if (rv == NULL) { chipc_release_region(sc, cr, RF_ALLOCATED); return (NULL); } - rman_set_rid(rv, *rid); - - /* Activate */ - if (flags & RF_ACTIVE) { - error = bus_activate_resource(child, type, *rid, rv); - if (error) { - device_printf(dev, - "failed to activate entry %#x type %d for " - "child %s: %d\n", - *rid, type, device_get_nameunit(child), error); - - chipc_release_region(sc, cr, RF_ALLOCATED); - rman_release_resource(rv); - - return (NULL); - } - } - /* Update child's resource list entry */ if (rle != NULL) { rle->res = rv; @@ -900,7 +885,7 @@ chipc_release_resource(device_t dev, device_t child, int type, int rid, sc = device_get_softc(dev); /* Handled by parent bus? */ - rm = chipc_get_rman(sc, type); + rm = chipc_get_rman(dev, type, rman_get_flags(r)); if (rm == NULL || !rman_is_region_manager(r, rm)) { return (bus_generic_rl_release_resource(dev, child, type, rid, r)); @@ -912,13 +897,8 @@ chipc_release_resource(device_t dev, device_t child, int type, int rid, return (EINVAL); /* Deactivate resources */ - if (rman_get_flags(r) & RF_ACTIVE) { - error = BUS_DEACTIVATE_RESOURCE(dev, child, type, rid, r); - if (error) - return (error); - } - - if ((error = rman_release_resource(r))) + error = bus_generic_rman_release_resource(dev, child, type, rid, r); + if (error != 0) return (error); /* Drop allocation reference */ @@ -943,7 +923,7 @@ chipc_adjust_resource(device_t dev, device_t child, int type, sc = device_get_softc(dev); /* Handled by parent bus? */ - rm = chipc_get_rman(sc, type); + rm = chipc_get_rman(dev, type, rman_get_flags(r)); if (rm == NULL || !rman_is_region_manager(r, rm)) { return (bus_generic_adjust_resource(dev, child, type, r, start, end)); @@ -978,16 +958,17 @@ chipc_adjust_resource(device_t dev, device_t child, int type, * as RF_ACTIVE if bhnd direct resource allocation fails. */ static int -chipc_try_activate_resource(struct chipc_softc *sc, device_t child, int type, +chipc_try_activate_resource(device_t dev, device_t child, int type, int rid, struct resource *r, bool req_direct) { + struct chipc_softc *sc = device_get_softc(dev); struct rman *rm; struct chipc_region *cr; bhnd_size_t cr_offset; rman_res_t r_start, r_end, r_size; int error; - rm = chipc_get_rman(sc, type); + rm = chipc_get_rman(dev, type, rman_get_flags(r)); if (rm == NULL || !rman_is_region_manager(r, rm)) return (EINVAL); @@ -1033,21 +1014,18 @@ static int chipc_activate_bhnd_resource(device_t dev, device_t child, int type, int rid, struct bhnd_resource *r) { - struct chipc_softc *sc; struct rman *rm; int error; - sc = device_get_softc(dev); - /* Delegate non-locally managed resources to parent */ - rm = chipc_get_rman(sc, type); + rm = chipc_get_rman(dev, type, rman_get_flags(r->res)); if (rm == NULL || !rman_is_region_manager(r->res, rm)) { return (bhnd_bus_generic_activate_resource(dev, child, type, rid, r)); } /* Try activating the chipc region resource */ - error = chipc_try_activate_resource(sc, child, type, rid, r->res, + error = chipc_try_activate_resource(dev, child, type, rid, r->res, false); if (error) return (error); @@ -1064,20 +1042,17 @@ static int chipc_activate_resource(device_t dev, device_t child, int type, int rid, struct resource *r) { - struct chipc_softc *sc; struct rman *rm; - sc = device_get_softc(dev); - /* Delegate non-locally managed resources to parent */ - rm = chipc_get_rman(sc, type); + rm = chipc_get_rman(dev, type, rman_get_flags(r)); if (rm == NULL || !rman_is_region_manager(r, rm)) { return (bus_generic_activate_resource(dev, child, type, rid, r)); } /* Try activating the chipc region-based resource */ - return (chipc_try_activate_resource(sc, child, type, rid, r, true)); + return (chipc_try_activate_resource(dev, child, type, rid, r, true)); } /** @@ -1095,7 +1070,7 @@ chipc_deactivate_resource(device_t dev, device_t child, int type, sc = device_get_softc(dev); /* Handled by parent bus? */ - rm = chipc_get_rman(sc, type); + rm = chipc_get_rman(dev, type, rman_get_flags(r)); if (rm == NULL || !rman_is_region_manager(r, rm)) { return (bus_generic_deactivate_resource(dev, child, type, rid, r)); @@ -1396,6 +1371,7 @@ static device_method_t chipc_methods[] = { DEVMETHOD(bus_activate_resource, chipc_activate_resource), DEVMETHOD(bus_deactivate_resource, chipc_deactivate_resource), DEVMETHOD(bus_get_resource_list, chipc_get_resource_list), + DEVMETHOD(bus_get_rman, chipc_get_rman), DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),