From patchwork Wed Mar 8 23:37:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 9612105 X-Patchwork-Delegate: bhelgaas@google.com 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 C067D6016C for ; Wed, 8 Mar 2017 23:39:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2A7D28633 for ; Wed, 8 Mar 2017 23:39:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A76AD28640; Wed, 8 Mar 2017 23:39:32 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36AEA28633 for ; Wed, 8 Mar 2017 23:39:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754484AbdCHXjb (ORCPT ); Wed, 8 Mar 2017 18:39:31 -0500 Received: from mail-pf0-f177.google.com ([209.85.192.177]:36529 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752378AbdCHXjE (ORCPT ); Wed, 8 Mar 2017 18:39:04 -0500 Received: by mail-pf0-f177.google.com with SMTP id o126so20819625pfb.3 for ; Wed, 08 Mar 2017 15:38:02 -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=WIIbSRVWOvoLD7EFTwe0+qgkna3ljo2IpJI3ByZvQx8=; b=hiyI8U9G1DA+LvetQxw72UeJ8MNYiAxWoaH63kH4OdxaTwOopbW1nKaqjToycj/Ncl VHSYfpkkbkKGjwCQZ7x/iEshyfDSWNbXxv4PdQA5NlI7MBoELUecgU5m41FIYWApM7rE wj6V8Le1ketJnqdpsL6karj+OeAmcwq3twjeo= 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=WIIbSRVWOvoLD7EFTwe0+qgkna3ljo2IpJI3ByZvQx8=; b=PBEYZmAQeXsNQgfDYzfyAaOj/ZS72dAkpuDfI3kRp6lYDKQcw5oFzy/q6M2etHGd6V Xpl6mw8tVSAOQZo+sBuSU9BaHPDP3xtIFK25f34+3e5711IO1GVe4QMcQFsFK/BZT6CQ X9aq3EwJ1sSsvJOXzLbg+8zAQsuyVJ6lRDTE9ymNyKtonHOsn68lJiXOmjT4JFqLzfUA G3/q3WpIHMpX00JZgc8u54b0PTXK0QyGH3hJ4r39MICmGAP4eFuv+WOK06vDqK64R3rJ haJCi1R7HsDSf+ZRhfYOIrrCNLqndptiO2Dwxvw1zfoZXo97JbNEhNMU6h8jpdxCur1M Wbhg== X-Gm-Message-State: AMke39lYJtk8zdrwRiUMDa7iLEQ2KKIsuF00cdqK6hMD+PljAVZnVwfS+WoaaCBGuQp0i3qz X-Received: by 10.84.169.227 with SMTP id h90mr12380673plb.155.1489016281882; Wed, 08 Mar 2017 15:38:01 -0800 (PST) Received: from ban.mtv.corp.google.com ([172.22.64.120]) by smtp.gmail.com with ESMTPSA id m21sm8266533pgh.4.2017.03.08.15.38.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Mar 2017 15:38:01 -0800 (PST) From: Brian Norris To: Bjorn Helgaas Cc: , Brian Norris , Shawn Lin , Jeffy Chen , Wenrui Li , linux-pci@vger.kernel.org, linux-rockchip@lists.infradead.org, Brian Norris Subject: [RFC PATCH 3/3] WIP: PCI: rockchip: add remove() support Date: Wed, 8 Mar 2017 15:37:48 -0800 Message-Id: <20170308233748.54706-3-briannorris@chromium.org> X-Mailer: git-send-email 2.12.0.246.ga2ecc84866-goog In-Reply-To: <20170308233748.54706-1-briannorris@chromium.org> References: <20170308233748.54706-1-briannorris@chromium.org> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP *** THIS IS WIP; DO NOT MERGE *** I haven't quite figured out the right way to invert pci_remap_iospace(). I guess no one supports this yet? So currently, if you try to remove/re-probe we'll hit a BUG() in ioremap code when we call this a second time. I post the unfinished work here as a bug report, so that if I can't get this cleaned up quickly, we should instead prevent unbinding the device once it's probed. *** 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. Signed-off-by: Brian Norris --- drivers/pci/host/pcie-rockchip.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/pci/host/pcie-rockchip.c b/drivers/pci/host/pcie-rockchip.c index 5d7b27b1e941..e111b3bf63ca 100644 --- a/drivers/pci/host/pcie-rockchip.c +++ b/drivers/pci/host/pcie-rockchip.c @@ -225,6 +225,7 @@ struct rockchip_pcie { struct irq_domain *irq_domain; u32 io_size; int offset; + struct pci_bus *root_bus; phys_addr_t io_bus_addr; void __iomem *msg_region; u32 mem_size; @@ -1391,6 +1392,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 +1423,32 @@ 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); + + 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 +1466,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);