From patchwork Mon Nov 17 10:21:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yijing Wang X-Patchwork-Id: 5316941 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C1752C11AC for ; Mon, 17 Nov 2014 09:47:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DA0EB2012F for ; Mon, 17 Nov 2014 09:47:15 +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 D9B3C2012B for ; Mon, 17 Nov 2014 09:47:14 +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 1XqIrS-0000wN-1C; Mon, 17 Nov 2014 09:44:42 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XqIpQ-0007zS-4k for linux-arm-kernel@bombadil.infradead.org; Mon, 17 Nov 2014 09:42:36 +0000 Received: from szxga02-in.huawei.com ([119.145.14.65]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XqIpM-0004eE-Cd for linux-arm-kernel@lists.infradead.org; Mon, 17 Nov 2014 09:42:34 +0000 Received: from 172.24.2.119 (EHLO szxeml462-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CCM04935; Mon, 17 Nov 2014 17:40:49 +0800 (CST) Received: from localhost.localdomain (10.175.100.166) by szxeml462-hub.china.huawei.com (10.82.67.205) with Microsoft SMTP Server id 14.3.158.1; Mon, 17 Nov 2014 17:40:38 +0800 From: Yijing Wang To: Bjorn Helgaas Subject: [RFC PATCH 13/16] ia64/PCI: Use pci_scan_host_bridge() to refactor pci_acpi_scan_root() Date: Mon, 17 Nov 2014 18:21:47 +0800 Message-ID: <1416219710-26088-14-git-send-email-wangyijing@huawei.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1416219710-26088-1-git-send-email-wangyijing@huawei.com> References: <1416219710-26088-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-20141117_094233_450736_92D2A026 X-CRM114-Status: GOOD ( 17.71 ) X-Spam-Score: -2.6 (--) Cc: Liviu Dudau , Tony Luck , Russell King , linux-pci@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Xinwei Hu , Thierry Reding , Suravee.Suthikulpanit@amd.com, Benjamin Herrenschmidt , Yijing Wang , linux-ia64@vger.kernel.org, Thomas Gleixner , Wuyun , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org 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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 Signed-off-by: Yijing Wang --- arch/ia64/pci/pci.c | 84 +++++++++++++++++++++++--------------------------- 1 files changed, 39 insertions(+), 45 deletions(-) diff --git a/arch/ia64/pci/pci.c b/arch/ia64/pci/pci.c index aac3220..c7d97ae 100644 --- a/arch/ia64/pci/pci.c +++ b/arch/ia64/pci/pci.c @@ -115,23 +115,10 @@ struct pci_ops pci_root_ops = { .write = pci_write, }; -/* Called by ACPI when it finds a new root bus. */ - -static struct pci_controller *alloc_pci_controller(int seg) -{ - struct pci_controller *controller; - - controller = kzalloc(sizeof(*controller), GFP_KERNEL); - if (!controller) - return NULL; - - controller->segment = seg; - return controller; -} - struct pci_root_info { struct acpi_device *bridge; - struct pci_controller *controller; + struct pci_controller controller; + struct acpi_pci_root *root; struct list_head resources; struct resource *res; resource_size_t *res_offset; @@ -340,8 +327,6 @@ static void free_pci_root_info_res(struct pci_root_info *info) kfree(info->res_offset); info->res_offset = NULL; info->res_num = 0; - kfree(info->controller); - info->controller = NULL; } static void __release_pci_root_info(struct pci_root_info *info) @@ -395,7 +380,7 @@ probe_pci_root_info(struct pci_root_info *info, struct acpi_device *device, if (info->res_num) { info->res = kzalloc_node(sizeof(*info->res) * info->res_num, - GFP_KERNEL, info->controller->node); + GFP_KERNEL, info->controller.node); if (!info->res) { kfree(name); return -ENOMEM; @@ -403,7 +388,7 @@ probe_pci_root_info(struct pci_root_info *info, struct acpi_device *device, info->res_offset = kzalloc_node(sizeof(*info->res_offset) * info->res_num, - GFP_KERNEL, info->controller->node); + GFP_KERNEL, info->controller.node); if (!info->res_offset) { kfree(name); kfree(info->res); @@ -420,6 +405,27 @@ probe_pci_root_info(struct pci_root_info *info, struct acpi_device *device, return 0; } +static int pci_acpi_init_res(struct pci_host_bridge *host, + struct pci_host_info *info) +{ + int ret; + struct pci_host_bridge_window *window, *n; + struct pci_controller *ctrl = info->arg; + struct pci_root_info *arg = container_of(ctrl, + struct pci_root_info, controller); + + ret = probe_pci_root_info(arg, arg->root->device, + host->busnum, host->domain); + if (ret) + return -1; + list_for_each_entry_safe(window, n, &arg->resources, + list) + list_move_tail(&window->list, &host->windows); + /* insert busn resource at first */ + pci_add_resource(&host->windows, &arg->root->secondary); + return 0; +} + struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) { struct acpi_device *device = root->device; @@ -427,55 +433,43 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) struct pci_controller *controller; struct pci_root_info *info = NULL; int busnum = root->secondary.start; - struct pci_bus *pbus; - int ret; - - controller = alloc_pci_controller(domain); - if (!controller) - return NULL; - - controller->companion = device; - controller->node = acpi_get_node(device->handle); + struct pci_host_bridge *host; + struct pci_host_info arg; info = kzalloc(sizeof(*info), GFP_KERNEL); if (!info) { dev_err(&device->dev, "pci_bus %04x:%02x: ignored (out of memory)\n", domain, busnum); - kfree(controller); return NULL; } - info->controller = controller; + controller = &info->controller; + controller->segment = domain; + controller->companion = device; + controller->node = acpi_get_node(device->handle); INIT_LIST_HEAD(&info->io_resources); INIT_LIST_HEAD(&info->resources); + init_pci_host_info(&arg); + arg.arg = controller; + arg.init_res = pci_acpi_init_res; - ret = probe_pci_root_info(info, device, busnum, domain); - if (ret) { - kfree(info->controller); - kfree(info); - return NULL; - } - /* insert busn resource at first */ - pci_add_resource(&info->resources, &root->secondary); /* * See arch/x86/pci/acpi.c. * The desired pci bus might already be scanned in a quirk. We * should handle the case here, but it appears that IA64 hasn't * such quirk. So we just ignore the case now. */ - pbus = pci_create_root_bus(NULL, busnum, &pci_root_ops, controller, - &info->resources); - if (!pbus) { - pci_free_resource_list(&info->resources); + host = pci_scan_host_bridge(NULL, PCI_DOMBUS(domain, busnum), + &pci_root_ops, &arg); + if (!host) { __release_pci_root_info(info); return NULL; } - pci_set_host_bridge_release(to_pci_host_bridge(pbus->bridge), + pci_set_host_bridge_release(host, release_pci_root_info, info); - pci_scan_child_bus(pbus); - return pbus; + return host->bus; } int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)