From patchwork Wed Mar 22 09:42:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Lin X-Patchwork-Id: 9638343 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 6102760327 for ; Wed, 22 Mar 2017 09:46:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61A6B28420 for ; Wed, 22 Mar 2017 09:46:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54C262842C; Wed, 22 Mar 2017 09:46:26 +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 911D728420 for ; Wed, 22 Mar 2017 09:46:25 +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=7Aogl7rKcmg1gTI39Z9cXz3Z0FJdVs5r1HLgEUFYzLA=; b=c4I b99AO0coSChZ+C0wx5cIlnES7VkvuYzJZWKgWCpt/6ncg4O5rJzWJI6+/dHJxdnn+3LzG0NeY/rDn vYgFn+Pdv/A9nJNpYIKLZgw93h5sbykpAZ/Y8F1zeeEkytvxgpQQ4ipGu/sn6jRcfCkPqC0HuUSEF E7+z4BHLUW9M360yYA9PkmxnNRIJz2mTse5S1LDtWI+iH2AT36JN5w3ywoeAThpyVHoXlDlybSiXE DAh0iO79231n7y5pYQwfa+hVSUkaaFplCo4sc7RuRKdEy/ij5w2ZTLkTQQsM11td+VmvlFj0594Hj wWx3qEppiVOmfyV155klMeXA00SMT2g==; 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 1cqcqW-0007q6-09; Wed, 22 Mar 2017 09:46:24 +0000 Received: from lucky1.263xmail.com ([211.157.147.134]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cqcqR-0007p9-Ot for linux-rockchip@lists.infradead.org; Wed, 22 Mar 2017 09:46:22 +0000 Received: from shawn.lin?rock-chips.com (unknown [192.168.167.138]) by lucky1.263xmail.com (Postfix) with ESMTP id 0A451BA2; Wed, 22 Mar 2017 17:45:50 +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 4B0E140D; Wed, 22 Mar 2017 17:45:49 +0800 (CST) X-RL-SENDER: shawn.lin@rock-chips.com X-FST-TO: bhelgaas@google.com X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: shawn.lin@rock-chips.com X-UNIQUE-TAG: <2ee8a4492e4943cb26ba03305fedb409> 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 4344U9Q8AH; Wed, 22 Mar 2017 17:45:50 +0800 (CST) From: Shawn Lin To: Bjorn Helgaas Subject: [PATCH] PCI: use IDA to manage domain number if not getting it from DT Date: Wed, 22 Mar 2017 17:42:24 +0800 Message-Id: <1490175744-22727-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-20170322_024620_113221_1C2C1C89 X-CRM114-Status: GOOD ( 12.84 ) 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 , Brian Norris , linux-rockchip@lists.infradead.org, Wenrui Li 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 If not getting domain number from DT, the domain number will keep increasing once doing unbind/bind RC drivers. This could introduce pointless tree view of lspci as shows below: -+-[0001:00]---00.0-[01]----00.0 \-[0000:00]- The more test we do, the lengthier it would be. The more serious issue is that if attaching two hierarchies for two different domains belonging to two root bridges, so when doing unbind/bind test for one of them and keep the other, then the domain number would finally overflow and make the two hierarchies of devices share the some domain number but actually they shouldn't. So it looks like we need to invent a new indexing ID mechanism to manage domain number. This patch introduces idr to achieve our purpose. Cc: Brian Norris Cc: Jeffy Chen Signed-off-by: Shawn Lin --- drivers/pci/pci.c | 11 +++++++---- drivers/pci/remove.c | 5 +++++ include/linux/pci.h | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index a881c0d..1752ccc 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -5172,15 +5173,16 @@ static void pci_no_domains(void) } #ifdef CONFIG_PCI_DOMAINS -static atomic_t __domain_nr = ATOMIC_INIT(-1); +DEFINE_IDA(__domain_nr); int pci_get_new_domain_nr(void) { - return atomic_inc_return(&__domain_nr); + return ida_simple_get(&__domain_nr, 0, sizeof(u64), GFP_KERNEL); } #ifdef CONFIG_PCI_DOMAINS_GENERIC -static int of_pci_bus_find_domain_nr(struct device *parent) +static int of_pci_bus_find_domain_nr(struct pci_bus *bus, + struct device *parent) { static int use_dt_domains = -1; int domain = -1; @@ -5224,12 +5226,13 @@ static int of_pci_bus_find_domain_nr(struct device *parent) domain = -1; } + bus->use_dt_domains = use_dt_domains; return domain; } int pci_bus_find_domain_nr(struct pci_bus *bus, struct device *parent) { - return acpi_disabled ? of_pci_bus_find_domain_nr(parent) : + return acpi_disabled ? of_pci_bus_find_domain_nr(bus, parent) : acpi_pci_bus_find_domain_nr(bus); } #endif diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index 73a03d3..ad93378 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -157,6 +157,11 @@ void pci_remove_root_bus(struct pci_bus *bus) list_for_each_entry_safe(child, tmp, &bus->devices, bus_list) pci_remove_bus_device(child); + #ifdef CONFIG_PCI_DOMAINS_GENERIC + if (!bus->use_dt_domains) + ida_simple_remove(&__domain_nr, bus->domain_nr); + #endif + pci_remove_bus(bus); host_bridge->bus = NULL; diff --git a/include/linux/pci.h b/include/linux/pci.h index 6732d32..235b336 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -505,6 +505,7 @@ struct pci_bus { unsigned char cur_bus_speed; /* enum pci_bus_speed */ #ifdef CONFIG_PCI_DOMAINS_GENERIC int domain_nr; + int use_dt_domains; #endif char name[48]; @@ -1449,6 +1450,7 @@ static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity) * configuration space. */ #ifdef CONFIG_PCI_DOMAINS +extern struct ida __domain_nr; extern int pci_domains_supported; int pci_get_new_domain_nr(void); #else