From nobody Fri Jun 17 09:43:54 2022 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 EE6B185DBDA; Fri, 17 Jun 2022 09:43:54 +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 4LPYyf5g2Nz4dK3; Fri, 17 Jun 2022 09:43:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655459034; 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=CIP07NxPHzvb3sWq+iWDvGPhMD+ppkw7fuziYn45F1A=; b=sMFBNkwX+qKbg1I1uKEOy7t2aGVNMRdV7g7fjMfZc2zB8eG/Jr9Cx7M3BOa1wI3T2Kvy6s rrNWJGzvd9dTV40lrJoScxaRvmwnAzBP+ZxP0QlvG2j2URLWwy39KnOky/cj5QmGoBiXXd TKuqWxH3xwEviDq7MUotQGKfqmvpsP8GiB82HLDWrzhJLAOZ248Iz4UcrXXoOM0sCRmMtr 8bdLkGVGBzEfAyrl7MR2DgPdjRATiwG0vzVplPQm/2rShHdjZdum+o+ppdLH438Fisj/mm TT4VyY7FgAq1IY9yqFutBQZv7wyFV87T/w7Z64YUWayk2RFtZz6AZ1e57nOY/A== 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 8E5A71D34E; Fri, 17 Jun 2022 09:43:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25H9hsEQ012885; Fri, 17 Jun 2022 09:43:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25H9hsU8012884; Fri, 17 Jun 2022 09:43:54 GMT (envelope-from git) Date: Fri, 17 Jun 2022 09:43:54 GMT Message-Id: <202206170943.25H9hsU8012884@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: d843dd0e1add - main - Clean up in the pci host generic driver 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: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d843dd0e1addd2aa69a78be99e251147aafcfd80 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655459034; 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=CIP07NxPHzvb3sWq+iWDvGPhMD+ppkw7fuziYn45F1A=; b=lyoQrn402lVeJra19EtzIouh1hXQI7D78J/bNT7uchhysjmQKfux3tl/F0PB3+F18cx8EC p0fHLL53uvMOoY49ZQs97BGjltB+aX8h+xxCxTHEogRk+w6p+x+B8G1nqRl5y7fQBn/Q8Y EEXgnYwQ4g2SYAgQXr5OP4uu8CW9Jx7GNttHs7s3KVnmgTO58+CAbFQGJWX4I1SmoNCWVB SUsJhvpDowSTHvk5tk+b1aTFBJ3KgpQ2mNbQVcnJykgmvDFkNKOlLytMbET2cWsZnusSsT gRekv66lh0I11lYgoaolzPYN7qzDEVUy9hn/OEPk5+ISac7M/9aQM9tQx4nQOQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655459034; a=rsa-sha256; cv=none; b=hWYn9e6Wbts6Y4x4OUkWJfwll5DJl5ZBP6/Vbr0Y/dJnF34p2th60vngRwCyXnNVW/Occs A6OHwhWYNYsc+jF2jZee7DExH/f0BNThToDt+fW90caDsfEo41UmMUlejyMDVm01wGX8VH BRAOqQTFs2qSHHZbud60rnzGEAyhEeV2Kl3f/Pe/SBRIQ3S021B4/kDuLArvJFwvRehI3M 9xYmRqRIrPUH+7E1ihRoIpIVtK+UjsxTHX8gadjLcYxxsCYgEpjuSwwL1hEFc3NAPKOR44 rTu8HIC/FTZ05T8mGaqjPFaXM9kMiL02rXWBAGH/HUmQCKzIwHRHjtjHzszITg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=d843dd0e1addd2aa69a78be99e251147aafcfd80 commit d843dd0e1addd2aa69a78be99e251147aafcfd80 Author: Andrew Turner AuthorDate: 2022-05-23 09:41:36 +0000 Commit: Andrew Turner CommitDate: 2022-06-17 09:36:17 +0000 Clean up in the pci host generic driver Add clean up on failure and a detach function to the pci host generic driver. Reviewed by: jhb (earlier version) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35291 --- sys/dev/pci/pci_host_generic.c | 51 ++++++++++++++++++++++++++++++++++-------- sys/dev/pci/pci_host_generic.h | 1 + 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/sys/dev/pci/pci_host_generic.c b/sys/dev/pci/pci_host_generic.c index a231d51b77c3..31462a198541 100644 --- a/sys/dev/pci/pci_host_generic.c +++ b/sys/dev/pci/pci_host_generic.c @@ -97,8 +97,9 @@ pci_host_generic_core_attach(device_t dev) rid = 0; sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (sc->res == NULL) { - device_printf(dev, "could not map memory.\n"); - return (ENXIO); + device_printf(dev, "could not allocate memory.\n"); + error = ENXIO; + goto err_resource; } sc->bst = rman_get_bustag(sc->res); @@ -118,19 +119,19 @@ pci_host_generic_core_attach(device_t dev) error = rman_init(&sc->pmem_rman); if (error) { device_printf(dev, "rman_init() failed. error = %d\n", error); - return (error); + goto err_pmem_rman; } error = rman_init(&sc->mem_rman); if (error) { device_printf(dev, "rman_init() failed. error = %d\n", error); - return (error); + goto err_mem_rman; } error = rman_init(&sc->io_rman); if (error) { device_printf(dev, "rman_init() failed. error = %d\n", error); - return (error); + goto err_io_rman; } for (tuple = 0; tuple < MAX_RANGES_TUPLES; tuple++) { @@ -159,13 +160,43 @@ pci_host_generic_core_attach(device_t dev) if (error) { device_printf(dev, "rman_manage_region() failed." "error = %d\n", error); - rman_fini(&sc->pmem_rman); - rman_fini(&sc->mem_rman); - rman_fini(&sc->io_rman); - return (error); + goto err_rman_manage; } } + return (0); + +err_rman_manage: + rman_fini(&sc->io_rman); +err_io_rman: + rman_fini(&sc->mem_rman); +err_mem_rman: + rman_fini(&sc->pmem_rman); +err_pmem_rman: + bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->res); +err_resource: + bus_dma_tag_destroy(sc->dmat); + return (error); +} + +int +pci_host_generic_core_detach(device_t dev) +{ + struct generic_pcie_core_softc *sc; + int error; + + sc = device_get_softc(dev); + + error = bus_generic_detach(dev); + if (error != 0) + return (error); + + rman_fini(&sc->io_rman); + rman_fini(&sc->mem_rman); + rman_fini(&sc->pmem_rman); + bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->res); + bus_dma_tag_destroy(sc->dmat); + return (0); } @@ -538,6 +569,8 @@ generic_pcie_get_dma_tag(device_t dev, device_t child) static device_method_t generic_pcie_methods[] = { DEVMETHOD(device_attach, pci_host_generic_core_attach), + DEVMETHOD(device_detach, pci_host_generic_core_detach), + DEVMETHOD(bus_read_ivar, generic_pcie_read_ivar), DEVMETHOD(bus_write_ivar, generic_pcie_write_ivar), DEVMETHOD(bus_alloc_resource, pci_host_generic_core_alloc_resource), diff --git a/sys/dev/pci/pci_host_generic.h b/sys/dev/pci/pci_host_generic.h index 20117cbe32e3..80da4f523165 100644 --- a/sys/dev/pci/pci_host_generic.h +++ b/sys/dev/pci/pci_host_generic.h @@ -94,6 +94,7 @@ struct generic_pcie_core_softc { DECLARE_CLASS(generic_pcie_core_driver); int pci_host_generic_core_attach(device_t); +int pci_host_generic_core_detach(device_t); struct resource *pci_host_generic_core_alloc_resource(device_t, device_t, int, int *, rman_res_t, rman_res_t, rman_res_t, u_int); int pci_host_generic_core_release_resource(device_t, device_t, int, int,