From nobody Tue Feb 27 19:45:05 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 4TknyB27lRz5CKBl; Tue, 27 Feb 2024 19:45:06 +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 4TknyB0qcMz572T; Tue, 27 Feb 2024 19:45:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709063106; 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=9OZdavtyx8zP38kfn5xSQz+m1y0/Pl53xH16Ab50d9U=; b=TuFcXQOGKagcgjxkSFI6nzqW/rj63y5M5rhhn52MaMcwrTGWfTa1M4XcwRTlY64vdQTBhS kuaY2kG8RgpDwoWddPRpEhLMZeaH5n8P9vsorUa9lpupkqLbOYoXq/aICIGBTYkaWaH8kG IlONKR7U1m1xW1SNfbqyb91/B9kBehK6x8h+XCbSZ/KAe7Ztlo4aoIZc+9oxqe2wSZgn+0 t5gOM/OiMtyLraZK2dhHR/7CfagaLzjWCDED6fpIhXnAEygEpBWADFKRQbZCPK8EZdam7c IKiKWWHnHwYo/d2TdkNyL0DxhZY7DO9mIhQAtu0LbEMJxDHYlkTSuN1YRj3Z0Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1709063106; a=rsa-sha256; cv=none; b=U7d6DVioobtcXT1/F+El+cVjMnz03KlR71JTdQQJ3Gz550neghvZt6Tq5W2lnyrsmFon6S V4OOFFqfw71wt2+wos8HKwm9nxLa50c0rGPpxVDcI4zaaTfnizVY48T4iQr8T3CSV2/vLE iV+vnaRAvs9229PEIB8hnsq81v+n1JCVwtrDvvUBhCEDd+RyxGf4k/tXwbTdr50UGEGlpU qibOBb8HKJEL2mKXY32ISbhdm/dWWCSyfr8n/6UKGJ8VCDb9epDLikUTPy//G1WiBc4hLR Wlkc/gDabm+FEYs9qekbj3QjZsiWzO+/6hhM/8usL4mPrSuqDI01V/IPiO52dQ== 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=1709063106; 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=9OZdavtyx8zP38kfn5xSQz+m1y0/Pl53xH16Ab50d9U=; b=S1GP93XW86sscZSi7ssZ5hFhRfuEZ700IKGN5XbvtFt+Y5o7MqEIjW5tSx+EvNx21S+WI9 MA9GReXXcC/Fr1VrHc6TFVGUOtSs36caUWjJf/asY0N2+QmIL34cRQAm5Tuji7qsWrAKsS JIyrGLdOOF1U2KiNhPC86hhVKuqGP7iI0MppJxjzl8ncp57W5FWf8fmXRGAYSxU+OuuFEF PU7lJjOdmeqQI6lPpyOAjgeEeodGfJtA4Q6LZmd7vlV6zLE9jZkdGpq90/M5f7wCw3rBlq Z1hHlJxWyFh6N0wpudDR7BWK8h8fY2Xx5fxcQBgs2cM6AFZLsGdjiy7cumK4Wg== 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 4Tkny96yqvzQYV; Tue, 27 Feb 2024 19:45:05 +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 41RJj5mj093009; Tue, 27 Feb 2024 19:45:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41RJj5OY093006; Tue, 27 Feb 2024 19:45:05 GMT (envelope-from git) Date: Tue, 27 Feb 2024 19:45:05 GMT Message-Id: <202402271945.41RJj5OY093006@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: b25f03a1a272 - main - bhnd_usb: Use bus_generic_rman_* 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: b25f03a1a27256c8d638a7e82ac3f6248994d5f3 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=b25f03a1a27256c8d638a7e82ac3f6248994d5f3 commit b25f03a1a27256c8d638a7e82ac3f6248994d5f3 Author: John Baldwin AuthorDate: 2024-02-27 19:44:03 +0000 Commit: John Baldwin CommitDate: 2024-02-27 19:44:03 +0000 bhnd_usb: Use bus_generic_rman_* For SYS_RES_MEMORY, use bus_generic_rman_* for activate/deactivate_resource methods as well as custom map/unmap_resource methods that request submappings of the sc_mem resource allocated from the parent bus. Differential Revision: https://reviews.freebsd.org/D43938 --- sys/dev/bhnd/cores/usb/bhnd_usb.c | 111 +++++++++++++++++++++++++++++--------- 1 file changed, 85 insertions(+), 26 deletions(-) diff --git a/sys/dev/bhnd/cores/usb/bhnd_usb.c b/sys/dev/bhnd/cores/usb/bhnd_usb.c index e3bcd8f40bf8..68701df14c50 100644 --- a/sys/dev/bhnd/cores/usb/bhnd_usb.c +++ b/sys/dev/bhnd/cores/usb/bhnd_usb.c @@ -234,6 +234,19 @@ bhnd_usb_attach(device_t dev) return (0); } +static struct rman * +bhnd_usb_get_rman(device_t bus, int type, u_int flags) +{ + struct bhnd_usb_softc *sc = device_get_softc(bus); + + switch (type) { + case SYS_RES_MEMORY: + return (&sc->sc_mem_rman); + default: + return (NULL); + } +} + static struct resource * bhnd_usb_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) @@ -241,12 +254,10 @@ bhnd_usb_alloc_resource(device_t bus, device_t child, int type, int *rid, struct resource *rv; struct resource_list *rl; struct resource_list_entry *rle; - int passthrough, isdefault, needactivate; - struct bhnd_usb_softc *sc = device_get_softc(bus); + int passthrough, isdefault; isdefault = RMAN_IS_DEFAULT_RANGE(start,end); passthrough = (device_get_parent(child) != bus); - needactivate = flags & RF_ACTIVE; rle = NULL; if (!passthrough && isdefault) { @@ -272,20 +283,11 @@ bhnd_usb_alloc_resource(device_t bus, device_t child, int type, int *rid, * attempt to satisfy the allocation ourselves. */ if (type == SYS_RES_MEMORY) { - rv = rman_reserve_resource(&sc->mem_rman, start, end, count, - flags, child); + rv = bus_generic_rman_alloc_resource(bus, child, type, rid, + start, end, count, flags); if (rv == NULL) { - BHND_ERROR_DEV(bus, "could not reserve resource"); - return (0); - } - - rman_set_rid(rv, *rid); - - if (needactivate && - bus_activate_resource(child, type, *rid, rv)) { - BHND_ERROR_DEV(bus, "could not activate resource"); - rman_release_resource(rv); - return (0); + BHND_ERROR_DEV(bus, "could not allocate resource"); + return (NULL); } return (rv); @@ -327,14 +329,8 @@ bhnd_usb_release_resource(device_t dev, device_t child, int type, r)); } - /* 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); if (!passthrough) { @@ -348,6 +344,66 @@ bhnd_usb_release_resource(device_t dev, device_t child, int type, return (0); } +static int +bhnd_usb_activate_resource(device_t dev, device_t child, int type, int rid, + struct resource *r) +{ + if (type != SYS_RES_MEMORY) + return (bus_generic_activate_resource(dev, child, type, rid, + r)); + return (bus_generic_rman_activate_resource(dev, child, type, rid, r)); +} + +static int +bhnd_usb_deactivate_resource(device_t dev, device_t child, int type, int rid, + struct resource *r) +{ + if (type != SYS_RES_MEMORY) + return (bus_generic_deactivate_resource(dev, child, type, rid, + r)); + return (bus_generic_rman_deactivate_resource(dev, child, type, rid, r)); +} + +static int +bhnd_usb_map_resource(device_t dev, device_t child, int type, + struct resource *r, struct resource_map_request *argsp, + struct resource_map *map) +{ + struct bhnd_usb_softc *sc = device_get_softc(dev); + struct resource_map_request args; + rman_res_t length, start; + int error; + + if (type != SYS_RES_MEMORY) + return (bus_generic_map_resource(dev, child, type, r, argsp, + map)); + + /* Resources must be active to be mapped. */ + if (!(rman_get_flags(r) & RF_ACTIVE)) + return (ENXIO); + + resource_init_map_request(&args); + error = resource_validate_map_request(r, argsp, &args, &start, &length); + if (error) + return (error); + + args.offset = start - rman_get_start(sc->sc_mem); + args.length = length; + return (bus_generic_map_resource(dev, child, type, sc->sc_mem, &args, + map)); +} + +static int +bhnd_usb_unmap_resource(device_t dev, device_t child, int type, + struct resource *r, struct resource_map *map) +{ + struct bhnd_usb_softc *sc = device_get_softc(dev); + + if (type == SYS_RES_MEMORY) + r = sc->sc_mem; + return (bus_generic_unmap_resource(dev, child, type, r, map)); +} + static int bhnd_usb_print_all_resources(device_t dev) { @@ -478,11 +534,14 @@ static device_method_t bhnd_usb_methods[] = { DEVMETHOD(bus_child_deleted, bhnd_usb_child_deleted), DEVMETHOD(bus_alloc_resource, bhnd_usb_alloc_resource), DEVMETHOD(bus_get_resource_list, bhnd_usb_get_reslist), + DEVMETHOD(bus_get_rman, bhnd_usb_get_rman), DEVMETHOD(bus_print_child, bhnd_usb_print_child), DEVMETHOD(bus_release_resource, bhnd_usb_release_resource), + DEVMETHOD(bus_activate_resource, bhnd_usb_activate_resource), + DEVMETHOD(bus_deactivate_resource, bhnd_usb_deactivate_resource), + DEVMETHOD(bus_map_resource, bhnd_usb_map_resource), + DEVMETHOD(bus_unmap_resource, bhnd_usb_unmap_resource), /* Bus interface: generic part */ - DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), - DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),