From nobody Thu Feb 27 14:17:11 2025 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 4Z3YLv6T6Gz5qGFV; Thu, 27 Feb 2025 14:17:11 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Z3YLv5qNLz3xPV; Thu, 27 Feb 2025 14:17:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740665831; 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=zyNxCC95qpxUUEkLIoGJofHa/X7BBPNU0JnuTMWUIik=; b=UiOnKHc89wweE7YWUgiea4/OyElU4RiDPmyYJFmNQj7Qz2Hp8A8Ey3DxvxjzJQZXuya8Pt 7YVvr8HNbMb5Epbg9hheGJQA55xDkiGhk3KiaHJ0xUdqluk78ld+76tu4DuTVTAWKzA88x O9lCRw32ltBaAZ3Spbu8J1k6bDy52tbP4WDCIojxT9d9x8qr5bIyYkvELcDUFoHsPTrTn2 Eo6rJ9YT6rDlagGuAvdpGqX8rDzS9bndKxIu+Js1tNN++HY+6ZPbJgONh870TXe0X1JEK6 I9T7nHumkNSfKROT2h4yIFuFvz+Nfw/zI9vXzdilJ1e2nkpv5igrEz3A5MDjDw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1740665831; a=rsa-sha256; cv=none; b=vyCdGxtZNIxw2lIfReceZFnYrsIJ9jv9nYo9Zx/gbgDCvWXSCkyW0I5sU8MFHb/PNpAfme E2TelvU/OZKPmtbWnd6yxyCNlA4MsJjsg4YZAUEIM1IUj45dd8bvhx2avaJvejg3icIo5O vTzOzi7SpsaroaQvtCr+NbLXvfp5jdqZwRJT0GOUbXdK8dVRkqVBG5dgxYzG00vsZiiYq9 vRre0Nz0GdAaFaDKdpj3E7HJHA++QDGqfmNno/j7s6B05TQUVowo63uD3SnU4phyf9jGSs 9mxAfZ0kQJZnol6f8gsy0JtInLROFaWg4UMcXrG7pZadVtgBQCQib2+ErH3XNw== 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=1740665831; 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=zyNxCC95qpxUUEkLIoGJofHa/X7BBPNU0JnuTMWUIik=; b=DCnfQxhQALl04ImLzf5h3j37PzTchuiJAxWZ+K9LhuchkpCrAXmXP0Gr7qhrLocp3n24FN rWpOTNJITOb7d7gWYNPLHZsuC92Ug+nL1RdXJd08iC8dGUvTcZ5dNT0o7+H5FstRe/o+gY ARUtkgxk8C6UgmKBoInUcd9biSzyZtowpMslWKUROLjEmxoeRu2+Hm7sL9YgrvzhldarH5 9jiXfioroXo/PeRzCFiZJvquaIwFH9gihPNZuHTC/3tId8VsxNvxnEwOABsME90ZlSgIyr cj2D/tQmTsGHuMJj3h3yzvKHrOfOlHuQkzLduVv2AxlK0LWYta1bNp9cfVZbhg== 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 4Z3YLv5PcMzmZX; Thu, 27 Feb 2025 14:17:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 51REHBU3016916; Thu, 27 Feb 2025 14:17:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 51REHBpu016913; Thu, 27 Feb 2025 14:17:11 GMT (envelope-from git) Date: Thu, 27 Feb 2025 14:17:11 GMT Message-Id: <202502271417.51REHBpu016913@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 7f2360a108f9 - stable/14 - 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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/stable/14 X-Git-Reftype: branch X-Git-Commit: 7f2360a108f910d5f126c39dcb968c8a720520e6 Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=7f2360a108f910d5f126c39dcb968c8a720520e6 commit 7f2360a108f910d5f126c39dcb968c8a720520e6 Author: John Baldwin AuthorDate: 2024-02-27 19:44:22 +0000 Commit: John Baldwin CommitDate: 2025-02-27 13:09: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 (cherry picked from commit 3a48dfe115f35abac6c2d9ec03a6a574baeaf0bc) --- 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),