From nobody Tue Jan 23 17:46:04 2024 X-Original-To: dev-commits-src-main@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 4TKDz03zsxz57mYx; Tue, 23 Jan 2024 17:46:04 +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 4TKDz02VkQz47FL; Tue, 23 Jan 2024 17:46:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706031964; 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=H/1J2n4Lj7bLYgijacash8EKRytzTXfHwU26EPpVqqg=; b=nkYeipN6sMJEkrICZh23sseBhzfmmGUVGCRjFOUVvQWD190YLXdr4AqSDkYqzH99BAckH1 EReI7ZCC/MVBkWpaDl94ZdlO9zkHu+U2azopr6/rk3b/0q8rXSW2iALp8p8zR85sc/F0Fu R29RKFQ8Y9Ult37OuqqcD8T+kkjcQUmgas+/iSIocYnJDgWaOs6sU4ghUGs+RWRcbae6aq xZh4bLTN/mIXX/1/AvgTofIMWKerW+jPlhERADdaDU1uSVCcsYPD9vZqcch2RfPAA8UdNb lW71CDFi7nXg+L6uBX1nwwN0rfN/qH6rq6rEox6yuSeWi/wdK3PteC4ndoGg7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706031964; 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=H/1J2n4Lj7bLYgijacash8EKRytzTXfHwU26EPpVqqg=; b=e+QQFOYY+8L43F3iRBKfx9VwpqijyBtEOg10eCrc+U+glf6AJAU82coJBC4lvVVhfZXlv8 zc4zfa71lWIvnEt9z2HIGHLK9Gm2qRpVJIybPbCKEZp21K2VZLhAeQlHu30V4YaH7e6IRS NqFXM0WnI23Zm7neYzsZyJOo76DvLYry5f0TFtlYopxRYlF4kVwdhvV53HQzWljDrymdDC W/W0clzwt+UWeIuTDKmGszuECRkKYh6jhke/6PVlzNh2VnrwP4IAG4r0YLZlLvQauH5qdH ngnpV7qUGo9fiN2Fvq/OWXabMd1dVIudFrUJu0/qs+xJH9Hs6M5SGmq+bPFrIg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706031964; a=rsa-sha256; cv=none; b=tOGeW0ryFGwJrMqJ+6NPSCcyXMpjXe2s2keQDNkPmlNusDXHI8GQOL0P+bhSY5uPZswVIB IyFaJpa9f3M/RzUwSNoyG3gL/bhcBAdOaIJ3Gl5RBEmULujA5jKjY+lmx61PXZtJr8z+kc sYT31Bsbn7wNaSHM9zpEKH5u2wPS9e/Ut6Q6sdy9sckMjg5q7wriQicdpTN8YrAQKmYPwf aEskvLxgJ0satLeJicYYBqEgZmTEjcUUQ4G+CeJXmBVeCQK6G2sfFWFU2rYyx6Pt/zbgau JDmY6Y62H4NJBu4y8OTE8kWxqmFsNTAoGce7s5Y+8yvzX3WB9ii1BI1WcQxzJQ== 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 4TKDz01Y4dzfyC; Tue, 23 Jan 2024 17:46:04 +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 40NHk42e076133; Tue, 23 Jan 2024 17:46:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40NHk4Sp076130; Tue, 23 Jan 2024 17:46:04 GMT (envelope-from git) Date: Tue, 23 Jan 2024 17:46:04 GMT Message-Id: <202401231746.40NHk4Sp076130@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: 0b60d7a60099 - main - ofw_pcib: Use bus_generic_rman_* List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: 0b60d7a60099e6ce81e0fb012946a1e77b0626c4 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=0b60d7a60099e6ce81e0fb012946a1e77b0626c4 commit 0b60d7a60099e6ce81e0fb012946a1e77b0626c4 Author: John Baldwin AuthorDate: 2024-01-23 17:38:09 +0000 Commit: John Baldwin CommitDate: 2024-01-23 17:38:09 +0000 ofw_pcib: Use bus_generic_rman_* - Implement bus_map/unmap_resource pulling bits from the previous ofw_pcib_activate/deactivate_resource. One difference here is that the bus_unmap_resource implementation uses bus_space_unmap instead of pmap_unmapdev as a complement to the existing use of bus_space_map. - Use bus_generic_rman_* in various routines for memory and I/O port resources. - Use pci_domain_* for PCI_RES_BUS in ofw_pcib_activate/deactivate_resource. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D43441 --- sys/dev/ofw/ofw_pcib.c | 215 ++++++++++++++++++++++++++++--------------------- 1 file changed, 123 insertions(+), 92 deletions(-) diff --git a/sys/dev/ofw/ofw_pcib.c b/sys/dev/ofw/ofw_pcib.c index 2bcaa05ab1ed..f8d0fc8e7029 100644 --- a/sys/dev/ofw/ofw_pcib.c +++ b/sys/dev/ofw/ofw_pcib.c @@ -64,6 +64,7 @@ /* * bus interface. */ +static struct rman *ofw_pcib_get_rman(device_t, int, u_int); static struct resource * ofw_pcib_alloc_resource(device_t, device_t, int, int *, rman_res_t, rman_res_t, rman_res_t, u_int); static int ofw_pcib_release_resource(device_t, device_t, int, int, @@ -74,6 +75,10 @@ static int ofw_pcib_deactivate_resource(device_t, device_t, int, int, struct resource *); static int ofw_pcib_adjust_resource(device_t, device_t, int, struct resource *, rman_res_t, rman_res_t); +static int ofw_pcib_map_resource(device_t, device_t, int, struct resource *, + struct resource_map_request *, struct resource_map *); +static int ofw_pcib_unmap_resource(device_t, device_t, int, struct resource *, + struct resource_map *); static int ofw_pcib_translate_resource(device_t bus, int type, rman_res_t start, rman_res_t *newstart); @@ -95,7 +100,6 @@ static phandle_t ofw_pcib_get_node(device_t, device_t); * local methods */ static int ofw_pcib_fill_ranges(phandle_t, struct ofw_pci_range *); -static struct rman *ofw_pcib_get_rman(struct ofw_pci_softc *, int, u_int); /* * Driver methods. @@ -110,11 +114,14 @@ static device_method_t ofw_pcib_methods[] = { DEVMETHOD(bus_write_ivar, ofw_pcib_write_ivar), DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), + DEVMETHOD(bus_get_rman, ofw_pcib_get_rman), DEVMETHOD(bus_alloc_resource, ofw_pcib_alloc_resource), DEVMETHOD(bus_release_resource, ofw_pcib_release_resource), DEVMETHOD(bus_activate_resource, ofw_pcib_activate_resource), DEVMETHOD(bus_deactivate_resource, ofw_pcib_deactivate_resource), DEVMETHOD(bus_adjust_resource, ofw_pcib_adjust_resource), + DEVMETHOD(bus_map_resource, ofw_pcib_map_resource), + DEVMETHOD(bus_unmap_resource, ofw_pcib_unmap_resource), DEVMETHOD(bus_translate_resource, ofw_pcib_translate_resource), #ifdef __powerpc__ DEVMETHOD(bus_get_bus_tag, ofw_pcib_bus_get_bus_tag), @@ -417,80 +424,50 @@ static struct resource * ofw_pcib_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) { +#if defined(NEW_PCIB) && defined(PCI_RES_BUS) struct ofw_pci_softc *sc; - struct resource *rv; - struct rman *rm; - int needactivate; - - needactivate = flags & RF_ACTIVE; - flags &= ~RF_ACTIVE; sc = device_get_softc(bus); - +#endif + switch (type) { #if defined(NEW_PCIB) && defined(PCI_RES_BUS) - if (type == PCI_RES_BUS) { - return (pci_domain_alloc_bus(sc->sc_pci_domain, child, rid, - start, end, count, flags | needactivate)); - } + case PCI_RES_BUS: + return (pci_domain_alloc_bus(sc->sc_pci_domain, child, rid, + start, end, count, flags)); #endif - - rm = ofw_pcib_get_rman(sc, type, flags); - if (rm == NULL) { + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + return (bus_generic_rman_alloc_resource(bus, child, type, rid, + start, end, count, flags)); + default: return (bus_generic_alloc_resource(bus, child, type, rid, - start, end, count, flags | needactivate)); - } - - rv = rman_reserve_resource(rm, start, end, count, flags, child); - if (rv == NULL) { - device_printf(bus, "failed to reserve resource for %s\n", - device_get_nameunit(child)); - return (NULL); + start, end, count, flags)); } - - rman_set_rid(rv, *rid); - - if (needactivate) { - if (bus_activate_resource(child, type, *rid, rv) != 0) { - device_printf(bus, - "failed to activate resource for %s\n", - device_get_nameunit(child)); - rman_release_resource(rv); - return (NULL); - } - } - - return (rv); } static int ofw_pcib_release_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { +#if defined(NEW_PCIB) && defined(PCI_RES_BUS) struct ofw_pci_softc *sc; - struct rman *rm; - int error; sc = device_get_softc(bus); - +#endif + switch (type) { #if defined(NEW_PCIB) && defined(PCI_RES_BUS) - if (type == PCI_RES_BUS) + case PCI_RES_BUS: return (pci_domain_release_bus(sc->sc_pci_domain, child, rid, res)); #endif - - rm = ofw_pcib_get_rman(sc, type, rman_get_flags(res)); - if (rm == NULL) { + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + return (bus_generic_rman_release_resource(bus, child, type, rid, + res)); + default: return (bus_generic_release_resource(bus, child, type, rid, res)); } - KASSERT(rman_is_region_manager(res, rm), ("rman mismatch")); - - if (rman_get_flags(res) & RF_ACTIVE) { - error = bus_deactivate_resource(child, type, rid, res); - if (error != 0) - return (error); - } - return (rman_release_resource(res)); } static int @@ -536,26 +513,59 @@ static int ofw_pcib_activate_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { +#if defined(NEW_PCIB) && defined(PCI_RES_BUS) struct ofw_pci_softc *sc; - bus_space_handle_t handle; - bus_space_tag_t tag; - struct ofw_pci_range *rp; - vm_paddr_t start; - int space; - int rv; sc = device_get_softc(bus); - - if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY) { +#endif + switch (type) { +#if defined(NEW_PCIB) && defined(PCI_RES_BUS) + case PCI_RES_BUS: + return (pci_domain_activate_bus(sc->sc_pci_domain, child, rid, + res)); +#endif + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + return (bus_generic_rman_activate_resource(bus, child, type, rid, + res)); + default: return (bus_generic_activate_resource(bus, child, type, rid, res)); } +} + +static int +ofw_pcib_map_resource(device_t dev, device_t child, int type, + struct resource *r, struct resource_map_request *argsp, + struct resource_map *map) +{ + struct resource_map_request args; + struct ofw_pci_softc *sc; + struct ofw_pci_range *rp; + rman_res_t length, start; + int error, space; + + /* Resources must be active to be mapped. */ + if (!(rman_get_flags(r) & RF_ACTIVE)) + return (ENXIO); + + switch (type) { + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + break; + default: + return (EINVAL); + } - start = (vm_paddr_t)rman_get_start(res); + resource_init_map_request(&args); + error = resource_validate_map_request(r, argsp, &args, &start, &length); + if (error) + return (error); /* * Map this through the ranges list */ + sc = device_get_softc(dev); for (rp = sc->sc_range; rp < sc->sc_range + sc->sc_nrange && rp->pci_hi != 0; rp++) { if (start < rp->pci || start >= rp->pci + rp->size) @@ -571,7 +581,7 @@ ofw_pcib_activate_resource(device_t bus, device_t child, int type, int rid, break; default: space = -1; - } + } if (type == space) { start += (rp->host - rp->pci); @@ -580,23 +590,35 @@ ofw_pcib_activate_resource(device_t bus, device_t child, int type, int rid, } if (bootverbose) - printf("ofw_pci mapdev: start %jx, len %jd\n", - (rman_res_t)start, rman_get_size(res)); + printf("ofw_pci mapdev: start %jx, len %jd\n", start, length); - tag = BUS_GET_BUS_TAG(child, child); - if (tag == NULL) + map->r_bustag = BUS_GET_BUS_TAG(child, child); + if (map->r_bustag == NULL) return (ENOMEM); - rman_set_bustag(res, tag); - rv = bus_space_map(tag, start, - rman_get_size(res), 0, &handle); - if (rv != 0) - return (ENOMEM); + error = bus_space_map(map->r_bustag, start, length, 0, + &map->r_bushandle); + if (error != 0) + return (error); - rman_set_bushandle(res, handle); - rman_set_virtual(res, (void *)handle); /* XXX for powerpc only ? */ + /* XXX for powerpc only? */ + map->r_vaddr = (void *)map->r_bushandle; + map->r_size = length; + return (0); +} - return (rman_activate_resource(res)); +static int +ofw_pcib_unmap_resource(device_t dev, device_t child, int type, + struct resource *r, struct resource_map *map) +{ + switch (type) { + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + bus_space_unmap(map->r_bustag, map->r_bushandle, map->r_size); + return (0); + default: + return (EINVAL); + } } #ifdef __powerpc__ @@ -612,43 +634,50 @@ static int ofw_pcib_deactivate_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { - vm_size_t psize; +#if defined(NEW_PCIB) && defined(PCI_RES_BUS) + struct ofw_pci_softc *sc; - if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY) { + sc = device_get_softc(bus); +#endif + switch (type) { +#if defined(NEW_PCIB) && defined(PCI_RES_BUS) + case PCI_RES_BUS: + return (pci_domain_deactivate_bus(sc->sc_pci_domain, child, rid, + res)); +#endif + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + return (bus_generic_rman_deactivate_resource(bus, child, type, + rid, res)); + default: return (bus_generic_deactivate_resource(bus, child, type, rid, res)); } - - psize = rman_get_size(res); - pmap_unmapdev(rman_get_virtual(res), psize); - - return (rman_deactivate_resource(res)); } static int ofw_pcib_adjust_resource(device_t bus, device_t child, int type, struct resource *res, rman_res_t start, rman_res_t end) { - struct rman *rm; +#if defined(NEW_PCIB) && defined(PCI_RES_BUS) struct ofw_pci_softc *sc; sc = device_get_softc(bus); +#endif + switch (type) { #if defined(NEW_PCIB) && defined(PCI_RES_BUS) - if (type == PCI_RES_BUS) + case PCI_RES_BUS: return (pci_domain_adjust_bus(sc->sc_pci_domain, child, res, start, end)); #endif - - rm = ofw_pcib_get_rman(sc, type, rman_get_flags(res)); - if (rm == NULL) { + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + return (bus_generic_rman_adjust_resource(bus, child, type, res, + start, end)); + default: return (bus_generic_adjust_resource(bus, child, type, res, start, end)); } - KASSERT(rman_is_region_manager(res, rm), ("rman mismatch")); - KASSERT(!(rman_get_flags(res) & RF_ACTIVE), - ("active resources cannot be adjusted")); - - return (rman_adjust_resource(res, start, end)); } static phandle_t @@ -710,9 +739,11 @@ ofw_pcib_fill_ranges(phandle_t node, struct ofw_pci_range *ranges) } static struct rman * -ofw_pcib_get_rman(struct ofw_pci_softc *sc, int type, u_int flags) +ofw_pcib_get_rman(device_t bus, int type, u_int flags) { + struct ofw_pci_softc *sc; + sc = device_get_softc(bus); switch (type) { case SYS_RES_IOPORT: return (&sc->sc_io_rman);