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: wangyijing X-Patchwork-Id: 40889 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E12FD24035 for ; Mon, 17 Nov 2014 09:43:00 +0000 (UTC) Received: by mail-la0-f69.google.com with SMTP id gq15sf537203lab.4 for ; Mon, 17 Nov 2014 01:42:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=TMy1m+Ood+UqJJ4qmfOVOec3ad4vzlbVSMxO5pd1etg=; b=J+2kEoPomyc9pp25g7N5H4p4gSIq45ZwjRukCiOG8eOXL2DleigFZwd6qoEFBfwY4B wgelSYMQVVmJxXWG7l3/GY3Awk8qFIL2clFjg4+korR8YS4DU61rZN2sW71AROKcXOTE R5JQJ1oRqILV3GIBfMs8ZmrLRgpPK8XzztqlaDKsO8L7wXrIIOX1SvhOjh1bJgQu9FKV vJis5kmdW3XikK7OqiQontX5m9HZSVKHsuHwHpo9uqCco/MXaOob3phDMhmisAGu6EZM Edi8D/wOpmojpVm7nR428sonR4U0rMUc1uivm91MedaJrIGXj/Nl8MPBmpgEX6hXSjLN jThA== X-Gm-Message-State: ALoCoQnPBD+l7rq+4ve1I5xybUVcbGUKjj5VzZEosJu5jzssrpHaBPht39e2psWQbJaUQPlj3GXw X-Received: by 10.195.17.134 with SMTP id ge6mr1140770wjd.2.1416217379849; Mon, 17 Nov 2014 01:42:59 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.197.100 with SMTP id it4ls1170519lac.7.gmail; Mon, 17 Nov 2014 01:42:59 -0800 (PST) X-Received: by 10.112.73.39 with SMTP id i7mr25952783lbv.8.1416217379126; Mon, 17 Nov 2014 01:42:59 -0800 (PST) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id be17si4479641lab.86.2014.11.17.01.42.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Nov 2014 01:42:59 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by mail-lb0-f180.google.com with SMTP id z11so8924326lbi.11 for ; Mon, 17 Nov 2014 01:42:58 -0800 (PST) X-Received: by 10.152.42.226 with SMTP id r2mr25977789lal.29.1416217378943; Mon, 17 Nov 2014 01:42:58 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp1127322lbc; Mon, 17 Nov 2014 01:42:58 -0800 (PST) X-Received: by 10.68.201.130 with SMTP id ka2mr28538556pbc.112.1416217377275; Mon, 17 Nov 2014 01:42:57 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rv11si34799895pac.81.2014.11.17.01.42.56 for ; Mon, 17 Nov 2014 01:42:57 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751934AbaKQJmK (ORCPT + 26 others); Mon, 17 Nov 2014 04:42:10 -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-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: wangyijing@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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)