From nobody Tue Jan 23 17:46:00 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 4TKDyx3pjWz57mYc; Tue, 23 Jan 2024 17:46:01 +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 4TKDyw6YrRz47PS; Tue, 23 Jan 2024 17:46:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706031960; 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=PYg1RPYB3X31tttfHjLZwfcEBPjzz0NNf4S2nN+CQ4g=; b=ywygEqMUf6c7UdxPcdowN6Ud+tjC120aBgLA/ZItUF5zyi5jKaxo6qGvhHcuLwLa/oJzTP Z6Cz4KCOD5luETlaF4B19lewUD73gJCwX/21YeGO5RBxY2cccD4vxgkkRnrtaPvIzXGKjx KST0tUOlYvOxZHN50Uz/fIGSVic/Gf5od/uL70WDuT2x4KW19PgFmUS8jpBFXJxHD+HiHl MEMMXoi1imL3sVR8H/56ub67Fo/mr//fNLrPte00cxXwtaYAmu4vqdK8XhIhMu0ty7JBlA IjNe3Ebra6hG8EgRvfMbbPKBVt4TqoBVes7AuHuUgmpZuOs2wFyBGwFp3deirQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706031960; 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=PYg1RPYB3X31tttfHjLZwfcEBPjzz0NNf4S2nN+CQ4g=; b=SOm0SDgYTosX6GJFonABYLU/RwmvF6+LNDg9yPPk7TZzDZYXbpuqDcKH9XbH17Esv1pFtY tauPAv+Lt941ez/mYQjhUQexx/ArJR5yCF7LPRZus6P3KFbz7gc+OtOkRYi81SW3Cxi5Po Ub4+a0S7hS7AJoU+KRyJpfSr4WpIO5RBBacOm42mpnZSLOnk5PxzbHMuboVM8UZ7p49i4K C93hLPSRvXd2sjkQQNXEcEWtenhtFYfqJYEl+nvdQEhzKzwIZXgC3gXJRjBD0/tRlpvmbm jQEvmMK8bCHbfFkCUntj3HpPP2oDJJJohGHgZdxD0SKbBQx2H8ynWJacbqtIpw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706031960; a=rsa-sha256; cv=none; b=RwApt6QQ3O186FQMRr7jQb3Azan3znXQ5jqqZhHIEWqjtlDuwAWiFMj+9eTGiUnSpxaJ7m ++mMmzgN6+UD5598n6fJEdRe2NCP/vBIMmWspM5eWeaMfS2UYr/TTHpldPehZaw4HhpLyM AihlKAnCJC4LDGVrTGTRqsq1n2lbDK0HS70W0cApoiRkbSKgG2UPseHxct8uraviU47yU1 s98Hcg5IipYJr5+YltEx/NSjdFpYIOTpAmUqMoAE07IcAl9cRxg81q6a6GU6/xd84LkyKe R7y7lR3fRCG++Tti2+uQJc4mCdaKeS1KSDZIFwHFcTpM1SFu8AIvPdgSRfMW6A== 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 4TKDyw5gc6zgNQ; Tue, 23 Jan 2024 17:46:00 +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 40NHk0Ho076010; Tue, 23 Jan 2024 17:46:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40NHk0iW076007; Tue, 23 Jan 2024 17:46:00 GMT (envelope-from git) Date: Tue, 23 Jan 2024 17:46:00 GMT Message-Id: <202401231746.40NHk0iW076007@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: 4e1d94d99798 - main - arm mv_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: 4e1d94d99798b9176b477062a9c7502c33d3e810 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=4e1d94d99798b9176b477062a9c7502c33d3e810 commit 4e1d94d99798b9176b477062a9c7502c33d3e810 Author: John Baldwin AuthorDate: 2024-01-23 17:37:30 +0000 Commit: John Baldwin CommitDate: 2024-01-23 17:37:30 +0000 arm mv_pcib: Use bus_generic_rman_* - Implement bus_get_rman pulling bits from mv_pcib_alloc_resource. - Implement bus_map/unmap_resource pulling bits from mv_pcib_activate/deactivate_resource. - Use bus_generic_rman_* to handle memory and I/O resources for mv_pcib_alloc/activate/adjust/deactivate/release_resource. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D43438 --- sys/arm/mv/mv_pci.c | 180 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 157 insertions(+), 23 deletions(-) diff --git a/sys/arm/mv/mv_pci.c b/sys/arm/mv/mv_pci.c index 74fc0419bf22..76da1c4da7a7 100644 --- a/sys/arm/mv/mv_pci.c +++ b/sys/arm/mv/mv_pci.c @@ -342,10 +342,21 @@ static int mv_pcib_mem_init(struct mv_pcib_softc *); static int mv_pcib_probe(device_t); static int mv_pcib_attach(device_t); +static struct rman *mv_pcib_get_rman(device_t, int, u_int); static struct resource *mv_pcib_alloc_resource(device_t, device_t, int, int *, rman_res_t, rman_res_t, rman_res_t, u_int); +static int mv_pcib_adjust_resource(device_t, device_t, int, struct resource *, + rman_res_t, rman_res_t); static int mv_pcib_release_resource(device_t, device_t, int, int, struct resource *); +static int mv_pcib_activate_resource(device_t, device_t, int, int, + struct resource *r); +static int mv_pcib_deactivate_resource(device_t, device_t, int, int, + struct resource *r); +static int mv_pcib_map_resource(device_t, device_t, int, struct resource *, + struct resource_map_request *, struct resource_map *); +static int mv_pcib_unmap_resource(device_t, device_t, int, struct resource *, + struct resource_map *); static int mv_pcib_read_ivar(device_t, device_t, int, uintptr_t *); static int mv_pcib_write_ivar(device_t, device_t, int, uintptr_t); @@ -370,10 +381,14 @@ static device_method_t mv_pcib_methods[] = { /* Bus interface */ DEVMETHOD(bus_read_ivar, mv_pcib_read_ivar), DEVMETHOD(bus_write_ivar, mv_pcib_write_ivar), + DEVMETHOD(bus_get_rman, mv_pcib_get_rman), DEVMETHOD(bus_alloc_resource, mv_pcib_alloc_resource), + DEVMETHOD(bus_adjust_resource, mv_pcib_adjust_resource), DEVMETHOD(bus_release_resource, mv_pcib_release_resource), - DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), - DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), + DEVMETHOD(bus_activate_resource, mv_pcib_activate_resource), + DEVMETHOD(bus_deactivate_resource, mv_pcib_deactivate_resource), + DEVMETHOD(bus_map_resource, mv_pcib_map_resource), + DEVMETHOD(bus_unmap_resource, mv_pcib_unmap_resource), DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), @@ -876,20 +891,30 @@ mv_pcib_init_all_bars(struct mv_pcib_softc *sc, int bus, int slot, return (0); } +static struct rman * +mv_pcib_get_rman(device_t dev, int type, u_int flags) +{ + struct mv_pcib_softc *sc = device_get_softc(dev); + + switch (type) { + case SYS_RES_IOPORT: + return (&sc->sc_io_rman); + case SYS_RES_MEMORY: + return (&sc->sc_mem_rman); + default: + return (NULL); + } +} + static struct resource * mv_pcib_alloc_resource(device_t dev, device_t child, int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) { struct mv_pcib_softc *sc = device_get_softc(dev); - struct rman *rm = NULL; - struct resource *res; switch (type) { case SYS_RES_IOPORT: - rm = &sc->sc_io_rman; - break; case SYS_RES_MEMORY: - rm = &sc->sc_mem_rman; break; #ifdef PCI_RES_BUS case PCI_RES_BUS: @@ -911,21 +936,32 @@ mv_pcib_alloc_resource(device_t dev, device_t child, int type, int *rid, (end > sc->sc_mem_base + sc->sc_mem_size - 1)) return (NULL); - res = rman_reserve_resource(rm, start, end, count, flags, child); - if (res == NULL) - return (NULL); - - rman_set_rid(res, *rid); - rman_set_bustag(res, fdtbus_bs_tag); - rman_set_bushandle(res, start); + return (bus_generic_rman_alloc_resource(dev, child, type, rid, + start, end, count, flags)); +} - if (flags & RF_ACTIVE) - if (bus_activate_resource(child, type, *rid, res)) { - rman_release_resource(res); - return (NULL); - } +static int +mv_pcib_adjust_resource(device_t dev, device_t child, int type, + struct resource *r, rman_res_t start, rman_res_t end) +{ +#ifdef PCI_RES_BUS + struct mv_pcib_softc *sc = device_get_softc(dev); +#endif - return (res); + switch (type) { + case SYS_RES_IOPORT: + case SYS_RES_MEMORY: + return (bus_generic_rman_adjust_resource(dev, child, type, r, + start, end)); +#ifdef PCI_RES_BUS + case PCI_RES_BUS: + return (pci_domain_adjust_bus(sc->ap_segment, child, r, start, + end)); +#endif + default: + return (bus_generic_adjust_resource(dev, child, type, r, + start, end)); + } } static int @@ -934,15 +970,113 @@ mv_pcib_release_resource(device_t dev, device_t child, int type, int rid, { #ifdef PCI_RES_BUS struct mv_pcib_softc *sc = device_get_softc(dev); +#endif - if (type == PCI_RES_BUS) + switch (type) { + case SYS_RES_IOPORT: + case SYS_RES_MEMORY: + return (bus_generic_rman_release_resource(dev, child, type, + rid, res)); +#ifdef PCI_RES_BUS + case PCI_RES_BUS: return (pci_domain_release_bus(sc->ap_segment, child, rid, res)); #endif - if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY) + default: return (BUS_RELEASE_RESOURCE(device_get_parent(dev), child, type, rid, res)); + } +} + +static int +mv_pcib_activate_resource(device_t dev, device_t child, int type, int rid, + struct resource *r) +{ +#ifdef PCI_RES_BUS + struct mv_pcib_softc *sc = device_get_softc(dev); +#endif + + switch (type) { + case SYS_RES_IOPORT: + case SYS_RES_MEMORY: + return (bus_generic_rman_activate_resource(dev, child, type, + rid, r)); +#ifdef PCI_RES_BUS + case PCI_RES_BUS: + return (pci_domain_activate_bus(sc->ap_segment, child, rid, r)); +#endif + default: + return (bus_generic_activate_resource(dev, child, type, rid, + r)); + } +} + +static int +mv_pcib_deactivate_resource(device_t dev, device_t child, int type, int rid, + struct resource *r) +{ +#ifdef PCI_RES_BUS + struct mv_pcib_softc *sc = device_get_softc(dev); +#endif + + switch (type) { + case SYS_RES_IOPORT: + case SYS_RES_MEMORY: + return (bus_generic_rman_deactivate_resource(dev, child, type, + rid, r)); +#ifdef PCI_RES_BUS + case PCI_RES_BUS: + return (pci_domain_deactivate_bus(sc->ap_segment, child, rid, + r)); +#endif + default: + return (bus_generic_deactivate_resource(dev, child, type, rid, + r)); + } +} + +static int +mv_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; + rman_res_t length, start; + int error; - return (rman_release_resource(res)); + /* Resources must be active to be mapped. */ + if (!(rman_get_flags(r) & RF_ACTIVE)) + return (ENXIO); + + /* Mappings are only supported on I/O and memory resources. */ + switch (type) { + case SYS_RES_IOPORT: + case SYS_RES_MEMORY: + break; + default: + return (EINVAL); + } + + resource_init_map_request(&args); + error = resource_validate_map_request(r, argsp, &args, &start, &length); + if (error) + return (error); + + map->r_bustag = fdtbus_bs_tag; + map->r_bushandle = start; + map->r_size = length; + return (0); +} + +static int +mv_pcib_unmap_resource(device_t dev, device_t child, int type, + struct resource *r, struct resource_map *map) +{ + switch (type) { + case SYS_RES_IOPORT: + case SYS_RES_MEMORY: + return (0); + default: + return (EINVAL); + } } static int