From nobody Mon Jul 04 14:27:21 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 D0A238312C1; Mon, 4 Jul 2022 14:27:21 +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 4Lc7Rs31cZz3N31; Mon, 4 Jul 2022 14:27:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656944841; 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=Tpt7y9SYqlsfycg2LX5vVmog+0ewRcKgyPxV3Oe9tfg=; b=d16Xa2aBzkR3nWg7Luyu5pbBDp8gHX4BXL6ki0g69pzkyPa3ALUdHGWLHtuWM5A4/My2Pf 1ZX0b13jG9ixyhrmzN015JUOoQjn7alPr/vof9KZlvj5mesbijxxKbT0NCILgCGrQppAuh uwG3NsifUPlJKhWDEb0vfUOcVKA4fBuQzHjQk/KIFsxDG9alAepQx//lkVAmCWn0yty2po d4hXawEsYnE/LgEpFjbK6gGatreDCiFEuIam5sI5C8R3Py22mC7rygzeSbkyo0Dhi/lVYQ ZDUB0Qi89q09NJyMNdRK+1ApZs1LlanpzOK3iUV36j6ISjAeZGpZuMYeCrnSbw== 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 379AE12F0C; Mon, 4 Jul 2022 14:27:21 +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 264ERL1R064464; Mon, 4 Jul 2022 14:27:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 264ERLGe064463; Mon, 4 Jul 2022 14:27:21 GMT (envelope-from git) Date: Mon, 4 Jul 2022 14:27:21 GMT Message-Id: <202207041427.264ERLGe064463@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: ee2324aaf6e3 - main - Add Rockchip PCIe cleanup on attach faulure 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: ee2324aaf6e3256ef7396ef6063ec4261486ef94 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656944841; 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=Tpt7y9SYqlsfycg2LX5vVmog+0ewRcKgyPxV3Oe9tfg=; b=bdS3mWv+Y290rgctGlFOWPWawAorbaEhHxIMiEfOz7hphGhwJOjOb8dd9hYA/x4RcG27tJ M5OMkQmuKkaTjRaGWQNUQNWxGS6kjDJpBKtTwAymkt5vbYu3RAVmmx1QogZJS/nKD6tfDZ cIjSOnpleeaxw3yRMax6fo38wIFhlcgkTOoJQsT2gItLqOrigQ/gfHqwfGRGi7cNSm7/+6 R0zFj2mOPPjX4L47eCLOYKmt41oQk1HelfRaDwZOEeyjMaW8frwGizPWbVAU25CZJe3qlF Lm4smJLcnAsfJbh83+8X/hD+xXb1RKyQcKSUY8ichDiK53kIOqgvgEQOfjv5Fw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656944841; a=rsa-sha256; cv=none; b=oGR9U5Y4RO/7uQm0K2CatWFoTQx4L72OcrMDs1NVYBSm2v8YkgBjFBsOo/SE7L9/5paQWM U/Rm4ivi3DC3i9HgFj9lCXG9WLwdHjuUVvgjYKbRxGtbe9AmBGDY2067siWopDRQoguFUC jynbCXE9BXzRJrCxSkKw9yCqumB5IlBSZ620f6EQiHykZs7oTvzpRu/F6PwonkMjnsRTj8 296tE2Yj5Uj0DmNr6c2UHl3QanIPFadSjXt1Q7MNX7hBSvibxpJ9NrrnWt8Hr6MNXeoDas yzmdn6dRsRT8X7UoKv3maF6t1RWC+XA0yLJBIkqupP5SKgA5AhRrJ4a8K56jZA== 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=ee2324aaf6e3256ef7396ef6063ec4261486ef94 commit ee2324aaf6e3256ef7396ef6063ec4261486ef94 Author: Andrew Turner AuthorDate: 2022-06-30 18:16:34 +0000 Commit: Andrew Turner CommitDate: 2022-07-04 14:27:01 +0000 Add Rockchip PCIe cleanup on attach faulure We should clean up on failure as it may panic the kernel later, e.g. if we crate the rman, but fail to destroy it on attach faulure. Reviewed by: imp Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35682 --- sys/arm64/rockchip/rk_pcie.c | 50 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/sys/arm64/rockchip/rk_pcie.c b/sys/arm64/rockchip/rk_pcie.c index 1711d52d2b3e..32f70a9c9b44 100644 --- a/sys/arm64/rockchip/rk_pcie.c +++ b/sys/arm64/rockchip/rk_pcie.c @@ -1162,7 +1162,7 @@ rk_pcie_attach(device_t dev) /* Read FDT properties */ rv = rk_pcie_parse_fdt_resources(sc); if (rv != 0) - return (rv); + goto out; sc->coherent = OF_hasprop(sc->node, "dma-coherent"); sc->no_l0s = OF_hasprop(sc->node, "aspm-no-l0s"); @@ -1283,21 +1283,21 @@ rk_pcie_attach(device_t dev) rv = rk_pcie_decode_ranges(sc, sc->ofw_pci.sc_range, sc->ofw_pci.sc_nrange); if (rv != 0) - goto out; + goto out_full; rv = rk_pcie_setup_hw(sc); if (rv != 0) - goto out; + goto out_full; rv = rk_pcie_setup_sw(sc); if (rv != 0) - goto out; + goto out_full; rv = bus_setup_intr(dev, sc->client_irq_res, INTR_TYPE_BIO | INTR_MPSAFE, rk_pcie_client_irq, NULL, sc, &sc->client_irq_cookie); if (rv != 0) { device_printf(dev, "cannot setup client interrupt handler\n"); rv = ENXIO; - goto out; + goto out_full; } rv = bus_setup_intr(dev, sc->legacy_irq_res, INTR_TYPE_BIO | INTR_MPSAFE, @@ -1305,7 +1305,7 @@ rk_pcie_attach(device_t dev) if (rv != 0) { device_printf(dev, "cannot setup client interrupt handler\n"); rv = ENXIO; - goto out; + goto out_full; } rv = bus_setup_intr(dev, sc->sys_irq_res, INTR_TYPE_BIO | INTR_MPSAFE, @@ -1313,7 +1313,7 @@ rk_pcie_attach(device_t dev) if (rv != 0) { device_printf(dev, "cannot setup client interrupt handler\n"); rv = ENXIO; - goto out; + goto out_full; } /* Enable interrupts */ @@ -1344,8 +1344,42 @@ rk_pcie_attach(device_t dev) DELAY(250000); device_add_child(dev, "pci", -1); return (bus_generic_attach(dev)); + +out_full: + bus_teardown_intr(dev, sc->sys_irq_res, sc->sys_irq_cookie); + bus_teardown_intr(dev, sc->legacy_irq_res, sc->legacy_irq_cookie); + bus_teardown_intr(dev, sc->client_irq_res, sc->client_irq_cookie); + ofw_pcib_fini(dev); out: - /* XXX Cleanup */ + bus_dma_tag_destroy(sc->dmat); + bus_free_resource(dev, SYS_RES_IRQ, sc->sys_irq_res); + bus_free_resource(dev, SYS_RES_IRQ, sc->legacy_irq_res); + bus_free_resource(dev, SYS_RES_IRQ, sc->client_irq_res); + bus_free_resource(dev, SYS_RES_MEMORY, sc->apb_mem_res); + bus_free_resource(dev, SYS_RES_MEMORY, sc->axi_mem_res); + /* GPIO */ + gpio_pin_release(sc->gpio_ep); + /* Phys */ + for (int i = 0; i < MAX_LANES; i++) { + phy_release(sc->phys[i]); + } + /* Clocks */ + clk_release(sc->clk_aclk); + clk_release(sc->clk_aclk_perf); + clk_release(sc->clk_hclk); + clk_release(sc->clk_pm); + /* Resets */ + hwreset_release(sc->hwreset_core); + hwreset_release(sc->hwreset_mgmt); + hwreset_release(sc->hwreset_pipe); + hwreset_release(sc->hwreset_pm); + hwreset_release(sc->hwreset_aclk); + hwreset_release(sc->hwreset_pclk); + /* Regulators */ + regulator_release(sc->supply_12v); + regulator_release(sc->supply_3v3); + regulator_release(sc->supply_1v8); + regulator_release(sc->supply_0v9); return (rv); }