From patchwork Tue Aug 7 16:10:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1286901 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id E737C3FC23 for ; Tue, 7 Aug 2012 16:23:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755623Ab2HGQUT (ORCPT ); Tue, 7 Aug 2012 12:20:19 -0400 Received: from mail-yw0-f46.google.com ([209.85.213.46]:51881 "EHLO mail-yw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755618Ab2HGQUQ (ORCPT ); Tue, 7 Aug 2012 12:20:16 -0400 Received: by mail-yw0-f46.google.com with SMTP id m54so3845558yhm.19 for ; Tue, 07 Aug 2012 09:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=s/MCbrgT3lsGfn28EKWS+EtjWoRz8t56Xnp3FLXzF4M=; b=f/6iKvAK0WIGIe9K0OZKeFmWERdgh+YbX8bbBaK9jNx2Tf2omryeQXDehMH8erhgiz sw5fH/z0/zhO9UDSJJ2Pj3aiX9SxWXJ00mRzEOWcMG824wMJ5iFqd5WMCwAhlX31HqRt naddUdi72kAWBCGtqZV7c6sYiTFrtMDxtuFZRljFsmhTmoQmtFRpNBeW9wrAfAzEI31O 4Oa1j1ASOJLXEN2sBV8n3PmpfDTOVNhAQK9Z53Gt0mpTCSt/8exVpiTI58lnotw3Rqhn W7faCD6qekdV+f7BfIWwFXf4c9vxBbP3b50Fm2PVUocCNr+Rjq9K8TRBeNWmtHkptK0n V24g== Received: by 10.66.75.201 with SMTP id e9mr27174511paw.54.1344356416137; Tue, 07 Aug 2012 09:20:16 -0700 (PDT) Received: from localhost.localdomain ([58.250.81.2]) by mx.google.com with ESMTPS id pt2sm11429362pbb.58.2012.08.07.09.20.07 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 07 Aug 2012 09:20:15 -0700 (PDT) From: Jiang Liu To: Bjorn Helgaas , Don Dutile , Yinghai Lu , Greg KH , Kenji Kaneshige Cc: Jiang Liu , Taku Izumi , "Rafael J . Wysocki" , Yijing Wang , Xinwei Hu , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Jiang Liu Subject: [RFC PATCH v1 11/22] PCI: enhance PCI resource assignment logic to support PCI bus lock mechanism Date: Wed, 8 Aug 2012 00:10:51 +0800 Message-Id: <1344355862-2726-12-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1344355862-2726-1-git-send-email-jiang.liu@huawei.com> References: <1344355862-2726-1-git-send-email-jiang.liu@huawei.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This patch enhances PCI resource assignemnt logic to support PCI bus lock mechanism. Signed-off-by: Jiang Liu --- drivers/pci/setup-bus.c | 65 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 192172c..08bac37 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -47,6 +47,7 @@ static void free_list(struct list_head *head) list_for_each_entry_safe(dev_res, tmp, head, list) { list_del(&dev_res->list); + pci_dev_put(dev_res->dev); kfree(dev_res); } } @@ -73,7 +74,7 @@ static int add_to_list(struct list_head *head, } tmp->res = res; - tmp->dev = dev; + tmp->dev = pci_dev_get(dev); tmp->start = res->start; tmp->end = res->end; tmp->flags = res->flags; @@ -93,6 +94,7 @@ static void remove_from_list(struct list_head *head, list_for_each_entry_safe(dev_res, tmp, head, list) { if (dev_res->res == res) { list_del(&dev_res->list); + pci_dev_put(dev_res->dev); kfree(dev_res); break; } @@ -151,7 +153,7 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) panic("pdev_sort_resources(): " "kmalloc() failed!\n"); tmp->res = r; - tmp->dev = dev; + tmp->dev = pci_dev_get(dev); /* fallback is smallest one or list is empty*/ n = head; @@ -257,6 +259,7 @@ static void reassign_resources_sorted(struct list_head *realloc_head, } out: list_del(&add_res->list); + pci_dev_put(add_res->dev); kfree(add_res); } } @@ -982,15 +985,16 @@ handle_done: ; } -void __ref __pci_bus_size_bridges(struct pci_bus *bus, +static void __ref __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) { struct pci_dev *dev; + struct pci_bus *b; unsigned long mask, prefmask; resource_size_t additional_mem_size = 0, additional_io_size = 0; list_for_each_entry(dev, &bus->devices, bus_list) { - struct pci_bus *b = dev->subordinate; + b = pci_lock_subordinate(dev, PCI_BUS_STATE_STOPPING - 1); if (!b) continue; @@ -1004,6 +1008,8 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus, __pci_bus_size_bridges(b, realloc_head); break; } + + pci_bus_unlock(b); } /* The root bus? */ @@ -1063,7 +1069,7 @@ static void __ref __pci_bus_assign_resources(const struct pci_bus *bus, pbus_assign_resources_sorted(bus, realloc_head, fail_head); list_for_each_entry(dev, &bus->devices, bus_list) { - b = dev->subordinate; + b = pci_lock_subordinate(dev, PCI_BUS_STATE_STOPPING - 1); if (!b) continue; @@ -1084,6 +1090,8 @@ static void __ref __pci_bus_assign_resources(const struct pci_bus *bus, "%04x:%02x\n", pci_domain_nr(b), b->number); break; } + + pci_bus_unlock(b); } } @@ -1098,11 +1106,11 @@ static void __ref __pci_bridge_assign_resources(const struct pci_dev *bridge, struct list_head *fail_head) { struct pci_bus *b; + struct pci_dev *dev = (struct pci_dev *)bridge; - pdev_assign_resources_sorted((struct pci_dev *)bridge, - add_head, fail_head); + pdev_assign_resources_sorted(dev, add_head, fail_head); - b = bridge->subordinate; + b = pci_lock_subordinate(dev, PCI_BUS_STATE_STOPPING - 1); if (!b) return; @@ -1122,7 +1130,10 @@ static void __ref __pci_bridge_assign_resources(const struct pci_dev *bridge, "%04x:%02x\n", pci_domain_nr(b), b->number); break; } + + pci_bus_unlock(b); } + static void pci_bridge_release_resources(struct pci_bus *bus, unsigned long type) { @@ -1169,6 +1180,7 @@ enum release_type { leaf_only, whole_subtree, }; + /* * try to release pci bridge resources that is from leaf bridge, * so we can allocate big new one later @@ -1190,9 +1202,14 @@ static void __ref pci_bus_release_bridge_resources(struct pci_bus *bus, if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI) continue; - if (rel_type == whole_subtree) + if (rel_type != whole_subtree) + continue; + + if (pci_bus_lock_states(b, PCI_BUS_STATE_STOPPING - 1) > 0) { pci_bus_release_bridge_resources(b, type, whole_subtree); + pci_bus_unlock(b); + } } if (pci_is_root_bus(bus)) @@ -1253,6 +1270,7 @@ static int __init pci_bus_get_depth(struct pci_bus *bus) return depth; } + static int __init pci_get_max_depth(void) { int depth = 0; @@ -1285,6 +1303,7 @@ enum enable_type { }; static enum enable_type pci_realloc_enable __initdata = undefined; + void __init pci_realloc_get_opt(char *str) { if (!strncmp(str, "off", 3)) @@ -1292,6 +1311,7 @@ void __init pci_realloc_get_opt(char *str) else if (!strncmp(str, "on", 2)) pci_realloc_enable = user_enabled; } + static bool __init pci_realloc_enabled(void) { return pci_realloc_enable >= user_enabled; @@ -1428,7 +1448,7 @@ enable_and_dump: void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge) { - struct pci_bus *parent = bridge->subordinate; + struct pci_bus *parent; LIST_HEAD(add_list); /* list of resources that want additional resources */ int tried_times = 0; @@ -1438,6 +1458,10 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge) unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH; + parent = pci_lock_subordinate(bridge, PCI_BUS_STATE_STOPPING - 1); + if (!parent) + return; + again: __pci_bus_size_bridges(parent, &add_list); __pci_bridge_assign_resources(bridge, &add_list, &fail_head); @@ -1464,8 +1488,13 @@ again: struct pci_bus *bus = fail_res->dev->bus; unsigned long flags = fail_res->flags; + if (bus != parent && pci_bus_lock_states(bus, + PCI_BUS_STATE_STOPPING - 1) < 0) + continue; pci_bus_release_bridge_resources(bus, flags & type_mask, whole_subtree); + if (bus != parent) + pci_bus_unlock(bus); } /* restore size and flags */ list_for_each_entry(fail_res, &fail_head, list) { @@ -1485,6 +1514,7 @@ enable_all: retval = pci_reenable_device(bridge); pci_set_master(bridge); pci_enable_bridges(parent); + pci_bus_unlock(parent); } EXPORT_SYMBOL_GPL(pci_assign_unassigned_bridge_resources); @@ -1502,19 +1532,22 @@ unsigned int __ref pci_rescan_bus(struct pci_bus *bus) { unsigned int max; struct pci_dev *dev; + struct pci_bus *b; LIST_HEAD(add_list); /* list of resources that want additional resources */ max = pci_scan_child_bus(bus); - down_read(&pci_bus_sem); list_for_each_entry(dev, &bus->devices, bus_list) if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || - dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) - if (dev->subordinate) - __pci_bus_size_bridges(dev->subordinate, - &add_list); - up_read(&pci_bus_sem); + dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) { + b = pci_lock_subordinate(dev, + PCI_BUS_STATE_STOPPING - 1); + if (b) { + __pci_bus_size_bridges(b, &add_list); + pci_bus_unlock(b); + } + } __pci_bus_assign_resources(bus, &add_list, NULL); BUG_ON(!list_empty(&add_list));