From patchwork Fri May 8 07:22:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yijing Wang X-Patchwork-Id: 6363141 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DA5A29F373 for ; Fri, 8 May 2015 07:34:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F202120219 for ; Fri, 8 May 2015 07:34:06 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0ED752020F for ; Fri, 8 May 2015 07:34:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YqclB-0000JS-0M; Fri, 08 May 2015 07:31:49 +0000 Received: from szxga02-in.huawei.com ([119.145.14.65]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yqckh-0008Sx-OP for linux-arm-kernel@lists.infradead.org; Fri, 08 May 2015 07:31:23 +0000 Received: from 172.24.2.119 (EHLO szxeml430-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CLA54981; Fri, 08 May 2015 15:26:46 +0800 (CST) Received: from localhost.localdomain (10.175.100.166) by szxeml430-hub.china.huawei.com (10.82.67.185) with Microsoft SMTP Server id 14.3.158.1; Fri, 8 May 2015 15:26:34 +0800 From: Yijing Wang To: Bjorn Helgaas Subject: [PATCH Part3 v11 7/9] PCI: Create pci host bridge prior to root bus Date: Fri, 8 May 2015 15:22:57 +0800 Message-ID: <1431069779-29346-8-git-send-email-wangyijing@huawei.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1431069779-29346-1-git-send-email-wangyijing@huawei.com> References: <1431069779-29346-1-git-send-email-wangyijing@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.100.166] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150508_003120_163095_A187ED2D X-CRM114-Status: GOOD ( 11.71 ) X-Spam-Score: -2.3 (--) Cc: Liviu Dudau , linux-ia64@vger.kernel.org, Arnd Bergmann , Benjamin Herrenschmidt , x86@kernel.org, linux-pci@vger.kernel.org, Yijing Wang , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, dja@axtens.net X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Pci_host_bridge hold the domain number, we need to assign domain number prior to root bus creation, because root bus need to know the domain number to check whether it's alreay exist. Signed-off-by: Yijing Wang --- drivers/pci/probe.c | 60 ++++++++++++++++++++++++++------------------------ 1 files changed, 31 insertions(+), 29 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 9ed8ab7..e4ef791 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -515,7 +515,7 @@ static void pci_release_host_bridge_dev(struct device *dev) kfree(bridge); } -static struct pci_host_bridge *pci_alloc_host_bridge(struct pci_bus *b) +static struct pci_host_bridge *pci_alloc_host_bridge(void) { struct pci_host_bridge *bridge; @@ -524,7 +524,6 @@ static struct pci_host_bridge *pci_alloc_host_bridge(struct pci_bus *b) return NULL; INIT_LIST_HEAD(&bridge->windows); - bridge->bus = b; return bridge; } @@ -1902,48 +1901,51 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int domain, { int error; struct pci_host_bridge *bridge; - struct pci_bus *b, *b2; + struct pci_bus *b; struct resource_entry *window, *n; struct resource *res; resource_size_t offset; char bus_addr[64]; char *fmt; - b = pci_alloc_bus(NULL); - if (!b) - return NULL; - - b->sysdata = sysdata; - b->ops = ops; - b->number = b->busn_res.start = bus; - pci_bus_assign_domain_nr(b, parent); - b2 = pci_find_bus(pci_domain_nr(b), bus); - if (b2) { - /* If we already got to this bus through a different bridge, ignore it */ - dev_dbg(&b2->dev, "bus already known\n"); - goto err_out; - } - - bridge = pci_alloc_host_bridge(b); + bridge = pci_alloc_host_bridge(); if (!bridge) - goto err_out; + return NULL; - bridge->domain = domain; bridge->dev.parent = parent; + pci_host_assign_domain_nr(bridge, domain); bridge->dev.release = pci_release_host_bridge_dev; dev_set_drvdata(&bridge->dev, sysdata); - dev_set_name(&bridge->dev, "pci%04x:%02x", pci_domain_nr(b), bus); + dev_set_name(&bridge->dev, "pci%04x:%02x", bridge->domain, bus); error = pcibios_root_bridge_prepare(bridge); if (error) { kfree(bridge); - goto err_out; + return NULL; } error = device_register(&bridge->dev); if (error) { put_device(&bridge->dev); - goto err_out; + return NULL; } + + b = pci_find_bus(bridge->domain, bus); + if (b) { + /* If we already got to this bus through a different bridge, ignore it */ + dev_dbg(&b->dev, "bus already known\n"); + goto unregister_host; + } + + b = pci_alloc_bus(NULL); + if (!b) + goto unregister_host; + + bridge->bus = b; + b->sysdata = sysdata; + b->ops = ops; + b->number = b->busn_res.start = bus; + pci_bus_assign_domain_nr(b, parent); + b->bridge = get_device(&bridge->dev); device_enable_async_suspend(b->bridge); pci_set_bus_of_node(b); @@ -1956,11 +1958,11 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int domain, dev_set_name(&b->dev, "%04x:%02x", pci_domain_nr(b), bus); error = pcibios_root_bus_prepare(bridge); if (error) - goto class_dev_reg_err; + goto free_bus; error = device_register(&b->dev); if (error) - goto class_dev_reg_err; + goto free_bus; pcibios_add_bus(b); @@ -2000,11 +2002,11 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int domain, return b; -class_dev_reg_err: +free_bus: + kfree(b); put_device(&bridge->dev); +unregister_host: device_unregister(&bridge->dev); -err_out: - kfree(b); return NULL; } EXPORT_SYMBOL_GPL(pci_create_root_bus);