From patchwork Fri Mar 10 02:46:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 9614517 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0328C604DD for ; Fri, 10 Mar 2017 02:47:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB6362846A for ; Fri, 10 Mar 2017 02:46:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFFE1285B0; Fri, 10 Mar 2017 02:46:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8FD52285A4 for ; Fri, 10 Mar 2017 02:46:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=JzgsMB7/gX8PaQ6mOro0zbUlDRdQeGZ04rUA3NXiQuI=; b=Deq6UwApJwRBhMf4RDl8FLIA4X PBs7ip/230gnMqslwy/ThyGjO3O0LtleR8Mj8fXjfDqciQGyjwEAYSmaXpxo0YwBbn3eDosGtvqG8 R0BmcCc39XIIXJpQ3ezppDEbfYCq9FJu+kHKtmzFZct0+fAzSr/J3WR8FhPtwzFrkSlfEq2PngATk srRRl6yv5FrRTK6RJSYHorNVpnAqt2xz4RJX5iF/nuBRFa4IPLwiOC1X34xZQU95S8ah5sKlpH5il VQag+Cf6NtzWeoo8PA7vT0c5QRwLLyHRovYOvXQWcF6+aTnP6nQPH1gKYYfY75ozSV5jWOc76dGYj 1P2tkSTw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cmAa3-0006SG-8J; Fri, 10 Mar 2017 02:46:59 +0000 Received: from mail-pg0-x232.google.com ([2607:f8b0:400e:c05::232]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cmAZw-0006Mr-SN for linux-rockchip@lists.infradead.org; Fri, 10 Mar 2017 02:46:57 +0000 Received: by mail-pg0-x232.google.com with SMTP id g2so16044145pge.3 for ; Thu, 09 Mar 2017 18:46:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=m59oQ9n5gDPwQ8O5RM1WRx+FPSUTLdNRVBTjODnQkuc=; b=oYB6SnMShp+6Atlu+jgd3lfYOzAnRoJO64QByLS/46+1vg00RPr1ZGOgPb8EgEgcXU wVbkMVJqxAS01dSgiaoPZph4t+NtLuGxiknv/N3p/ZHH5pVj4d61zR4EdLSsG70sDD/Q 4XEmh2IqI5jxsZmApOQAzYN1UE5La9kVVkChE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=m59oQ9n5gDPwQ8O5RM1WRx+FPSUTLdNRVBTjODnQkuc=; b=IrzmluX3G9m1YCytgmfg+40aXDw7x32gXRr6a4WB+2saYXlhK+gJp0IKT+xoXlJu2k 5BuWr/cB7pX4aXdDPp5zKKsF1yzZXY/sah0iYgQX7rE0fCRBD2Q5NQGZKeZis1nYjAy9 Oqitmn4psHIEOBYPPJ/7c9hsOvTF7Ql1j0jzj1+8JVbTWukb+jvEGFdYftRL45o3l79r cUcwpTmUx4FQpo0alo/6u16m4AYL3KrM5P5aMOX2uNX9h7ekAiR4J9DTjkWlJPbP8S6M i+IaoyLn0bcp7SHaNcGiSnSbfYfaB7VFA+WxfN2PHQzvufDx/YOx036n98d1rmZhIxJS hUYg== X-Gm-Message-State: AMke39kfv8BdIwt/HtbKs9GdPSL0bRAWkoD3QjlIgo0p+vKSMbVk2K8gTsBmvjboJu63XO9a X-Received: by 10.84.228.208 with SMTP id y16mr21746331pli.168.1489113990720; Thu, 09 Mar 2017 18:46:30 -0800 (PST) Received: from ban.mtv.corp.google.com ([172.22.64.120]) by smtp.gmail.com with ESMTPSA id w29sm14830573pfi.131.2017.03.09.18.46.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Mar 2017 18:46:30 -0800 (PST) From: Brian Norris To: Bjorn Helgaas Subject: [PATCH v2 3/5] PCI: rockchip: add remove() support Date: Thu, 9 Mar 2017 18:46:15 -0800 Message-Id: <20170310024617.67303-3-briannorris@chromium.org> X-Mailer: git-send-email 2.12.0.246.ga2ecc84866-goog In-Reply-To: <20170310024617.67303-1-briannorris@chromium.org> References: <20170310024617.67303-1-briannorris@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170309_184652_951143_C7F76B21 X-CRM114-Status: GOOD ( 13.07 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jeffy Chen , linux-pci@vger.kernel.org, Shawn Lin , Wenrui Li , linux-kernel@vger.kernel.org, Brian Norris , linux-rockchip@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, if we try to unbind the platform device, the remove will succeed, but the removal won't undo most of the registration, leaving partially-configured PCI devices in the system. This allows, for example, a simple 'lspci' to crash the system, as it will try to touch the freed (via devm_*) driver structures. So let's implement device remove(). Signed-off-by: Brian Norris --- v2: * unmap IO space with pci_unmap_iospace() * remove IRQ domain --- drivers/pci/host/pcie-rockchip.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/drivers/pci/host/pcie-rockchip.c b/drivers/pci/host/pcie-rockchip.c index 5d7b27b1e941..d2e5078ae331 100644 --- a/drivers/pci/host/pcie-rockchip.c +++ b/drivers/pci/host/pcie-rockchip.c @@ -223,9 +223,11 @@ struct rockchip_pcie { int link_gen; struct device *dev; struct irq_domain *irq_domain; - u32 io_size; int offset; + struct pci_bus *root_bus; + struct resource *io; phys_addr_t io_bus_addr; + u32 io_size; void __iomem *msg_region; u32 mem_size; phys_addr_t msg_bus_addr; @@ -1360,6 +1362,7 @@ static int rockchip_pcie_probe(struct platform_device *pdev) err, io); continue; } + rockchip->io = io; break; case IORESOURCE_MEM: mem = win->res; @@ -1391,6 +1394,7 @@ static int rockchip_pcie_probe(struct platform_device *pdev) err = -ENOMEM; goto err_free_res; } + rockchip->root_bus = bus; pci_bus_size_bridges(bus); pci_bus_assign_resources(bus); @@ -1421,6 +1425,34 @@ static int rockchip_pcie_probe(struct platform_device *pdev) return err; } +static int rockchip_pcie_remove(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct rockchip_pcie *rockchip = dev_get_drvdata(dev); + + pci_stop_root_bus(rockchip->root_bus); + pci_remove_root_bus(rockchip->root_bus); + pci_unmap_iospace(rockchip->io); + irq_domain_remove(rockchip->irq_domain); + + phy_power_off(rockchip->phy); + phy_exit(rockchip->phy); + + clk_disable_unprepare(rockchip->clk_pcie_pm); + clk_disable_unprepare(rockchip->hclk_pcie); + clk_disable_unprepare(rockchip->aclk_perf_pcie); + clk_disable_unprepare(rockchip->aclk_pcie); + + if (!IS_ERR(rockchip->vpcie3v3)) + regulator_disable(rockchip->vpcie3v3); + if (!IS_ERR(rockchip->vpcie1v8)) + regulator_disable(rockchip->vpcie1v8); + if (!IS_ERR(rockchip->vpcie0v9)) + regulator_disable(rockchip->vpcie0v9); + + return 0; +} + static const struct dev_pm_ops rockchip_pcie_pm_ops = { SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(rockchip_pcie_suspend_noirq, rockchip_pcie_resume_noirq) @@ -1438,6 +1470,6 @@ static struct platform_driver rockchip_pcie_driver = { .pm = &rockchip_pcie_pm_ops, }, .probe = rockchip_pcie_probe, - + .remove = rockchip_pcie_remove, }; builtin_platform_driver(rockchip_pcie_driver);