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: 5316671 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@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 03983C11AC for ; Mon, 17 Nov 2014 09:43:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 14E342020E for ; Mon, 17 Nov 2014 09:43:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 18AFB201FA for ; Mon, 17 Nov 2014 09:43:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751962AbaKQJmJ (ORCPT ); Mon, 17 Nov 2014 04:42:09 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:28889 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752090AbaKQJk5 (ORCPT ); Mon, 17 Nov 2014 04:40:57 -0500 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 CC: , , Xinwei Hu , Wuyun , , Russell King , , Thomas Gleixner , Benjamin Herrenschmidt , , Tony Luck , , Thierry Reding , Liviu Dudau , , Yijing Wang 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 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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)