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: 9615175 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 E42ED60417 for ; Fri, 10 Mar 2017 08:01:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDD8028703 for ; Fri, 10 Mar 2017 08:01:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C227228708; Fri, 10 Mar 2017 08:01:48 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham 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 4B2A328703 for ; Fri, 10 Mar 2017 08:01:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752637AbdCJIBs (ORCPT ); Fri, 10 Mar 2017 03:01:48 -0500 Received: from lucky1.263xmail.com ([211.157.147.130]:52036 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752187AbdCJIBr (ORCPT ); Fri, 10 Mar 2017 03:01:47 -0500 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 Cc: Bjorn Helgaas , linux-pci@vger.kernel.org, linux-rockchip@lists.infradead.org, Wenrui Li , Jeffy Chen , Shawn Lin 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 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 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)