From patchwork Fri Mar 10 07:58:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Lin X-Patchwork-Id: 9615177 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 B059360417 for ; Fri, 10 Mar 2017 08:02:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A161A204BA for ; Fri, 10 Mar 2017 08:02:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9670726224; Fri, 10 Mar 2017 08:02:09 +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=unavailable 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 4AAF0252D5 for ; Fri, 10 Mar 2017 08:02:08 +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: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:In-Reply-To: References:List-Owner; bh=fisMEMel91sPIljQxFOlxrGqLdyReTZMMR8tiAKnTOk=; b=PNM hs10KPT1sb7j+WS278fRmFwDpkQKOKgq7pkGzIozwRpveK4Z49dIxmeWbj8QDgxu+A0vHESnswV6z zn+uyyxGNh1glnfK+QtMif+BRDq9vKCK89N61VtG2zgqxFe/EaDPXDDLGJuhw8yJj5Z8MCMeoASzb pGBKQpEh5QQ6aar6IQ/2S6vQ/5EJlnirIIbxVgh4yb2WgN0MJhCAF1Zo/GbzeXc7eZtuCngA7xrJR scYKY5ab76Iu4H0uhQ7mbNtTMoFfiWz1NjPcRLV/VI99+QSHlTsiEbSX2Dwl0H60VwVl9C6AMXata MszCecL2DjR5nU4XCG5xqAYdEzsrc8w==; 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 1cmFV1-0001pp-Vv; Fri, 10 Mar 2017 08:02:07 +0000 Received: from lucky1.263xmail.com ([211.157.147.130]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cmFUw-0001Yj-VJ for linux-rockchip@lists.infradead.org; Fri, 10 Mar 2017 08:02:06 +0000 Received: from shawn.lin?rock-chips.com (unknown [192.168.167.157]) by lucky1.263xmail.com (Postfix) with ESMTP id 9BC631EF30B; Fri, 10 Mar 2017 16:01:36 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTP id 20B9B417; Fri, 10 Mar 2017 16:01:37 +0800 (CST) X-RL-SENDER: shawn.lin@rock-chips.com X-FST-TO: briannorris@chromium.org X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: shawn.lin@rock-chips.com X-UNIQUE-TAG: <3a87fd1ef2599f743c63f3a81679b606> X-ATTACHMENT-NUM: 0 X-SENDER: lintao@rock-chips.com X-DNS-TYPE: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith ESMTP id 22428L6YAXL; Fri, 10 Mar 2017 16:01:37 +0800 (CST) From: Shawn Lin To: Brian Norris Subject: [RFT PATCH] PCI: provide helper to reset all domain for host drivers Date: Fri, 10 Mar 2017 15:58:26 +0800 Message-Id: <1489132706-56952-1-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170310_000203_370240_246925F3 X-CRM114-Status: UNSURE ( 6.61 ) X-CRM114-Notice: Please train this message. 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: Wenrui Li , linux-pci@vger.kernel.org, Shawn Lin , Jeffy Chen , linux-rockchip@lists.infradead.org, Bjorn Helgaas 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 Otherwise the domain_nr will be increased if doing ubind and bind host drives. I don't find any useful routine to reset it from current code, so add this helper. This patch is based on patchset[1] from Brian. [1]: https://patchwork.kernel.org/patch/9614517/ Signed-off-by: Shawn Lin --- Hi Brian, I wasn't able to run my platfrom with linux-next but I test this for my local kernel-v4.4, and I just send this for test! drivers/pci/host/pcie-rockchip.c | 1 + drivers/pci/pci.c | 6 ++++++ include/linux/pci.h | 3 +++ 3 files changed, 10 insertions(+) diff --git a/drivers/pci/host/pcie-rockchip.c b/drivers/pci/host/pcie-rockchip.c index bd6df72..61787e7 100644 --- a/drivers/pci/host/pcie-rockchip.c +++ b/drivers/pci/host/pcie-rockchip.c @@ -1435,6 +1435,7 @@ static int rockchip_pcie_remove(struct platform_device *pdev) pci_remove_root_bus(rockchip->root_bus); pci_unmap_iospace(rockchip->io); irq_domain_remove(rockchip->irq_domain); + pci_reset_all_domain(); phy_power_off(rockchip->phy); phy_exit(rockchip->phy); diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 3ec24877..7c7c63b 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -5181,6 +5181,12 @@ int pci_get_new_domain_nr(void) return atomic_inc_return(&__domain_nr); } +void pci_reset_all_domain(void) +{ + atomic_set(&__domain_nr, -1); +} +EXPORT_SYMBOL(pci_reset_all_domain); + #ifdef CONFIG_PCI_DOMAINS_GENERIC static int of_pci_bus_find_domain_nr(struct device *parent) { diff --git a/include/linux/pci.h b/include/linux/pci.h index eb3da1a..c9bd939 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1456,11 +1456,13 @@ static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity) #ifdef CONFIG_PCI_DOMAINS extern int pci_domains_supported; int pci_get_new_domain_nr(void); +void pci_reset_all_domain(void); #else enum { pci_domains_supported = 0 }; static inline int pci_domain_nr(struct pci_bus *bus) { return 0; } static inline int pci_proc_domain(struct pci_bus *bus) { return 0; } static inline int pci_get_new_domain_nr(void) { return -ENOSYS; } +static inline void pci_reset_all_domain(void) {} #endif /* CONFIG_PCI_DOMAINS */ /* @@ -1617,6 +1619,7 @@ static inline struct pci_dev *pci_get_bus_and_slot(unsigned int bus, static inline int pci_domain_nr(struct pci_bus *bus) { return 0; } static inline struct pci_dev *pci_dev_get(struct pci_dev *dev) { return NULL; } static inline int pci_get_new_domain_nr(void) { return -ENOSYS; } +static inline void pci_reset_all_domain(void) {}; #define dev_is_pci(d) (false) #define dev_is_pf(d) (false)