From patchwork Tue Sep 25 15:56:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1504971 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 745CCDF283 for ; Tue, 25 Sep 2012 15:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753808Ab2IYP7W (ORCPT ); Tue, 25 Sep 2012 11:59:22 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:56926 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753411Ab2IYP7W (ORCPT ); Tue, 25 Sep 2012 11:59:22 -0400 Received: by pbbrr4 with SMTP id rr4so332674pbb.19 for ; Tue, 25 Sep 2012 08:59:22 -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=GLICW2m48TynTr1eET2AcFtLmf2L5cyHjDFGBiOoq/0=; b=CLpa6cv0GkPgZvmEGtPJvYPzRgntuJe804/BA4CNXtisdHQJs4mtzSJMmUWmntYIpD kj1+0G1YuiEg8yrSax86yL1sir5LZMZmhAtMYpih6yETJTmPuXy6T7ZMW0V2OXNnSwhZ 53SqdZilW4NJiKXU2A5U4chqI2gj/BlDgTe5+VRg1Yj2d5cZ9wLYOdAUO9+9JmQEUSrQ R1+b3z1qVktHy/yvebLX5qSF+OISQDylKZeEVJMhhPjvucSanQXpPooPhjG+f0W3/NPP yHf5QgVx9srdUASZSSe7fbvVIMIyC+ccNiDIQOfHKxrUvinRNNiVuN7hkzurU0IWtVUB Q2ng== Received: by 10.66.88.233 with SMTP id bj9mr41779401pab.72.1348588761982; Tue, 25 Sep 2012 08:59:21 -0700 (PDT) Received: from localhost.localdomain ([221.221.22.12]) by mx.google.com with ESMTPS id i2sm336660pay.31.2012.09.25.08.59.15 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 25 Sep 2012 08:59:19 -0700 (PDT) From: Jiang Liu To: Yinghai Lu Cc: Bjorn Helgaas , Jiang Liu , Len Brown , linux-pci@vger.kernel.org Subject: [PATCH] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge Date: Tue, 25 Sep 2012 23:56:19 +0800 Message-Id: <1348588579-16970-1-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1348561590-28067-13-git-send-email-yinghai@kernel.org> References: <1348561590-28067-13-git-send-email-yinghai@kernel.org> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Yinghai Lu use bus_find_device to loop host_bridges. Signed-off-by: Yinghai Lu --- drivers/pci/search.c | 22 ++++++++++++++++++++++ include/linux/pci.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/drivers/pci/search.c b/drivers/pci/search.c index bf969ba..5e82905 100644 --- a/drivers/pci/search.c +++ b/drivers/pci/search.c @@ -178,6 +178,28 @@ struct pci_dev *pci_get_domain_bus_and_slot(int domain, unsigned int bus, } EXPORT_SYMBOL(pci_get_domain_bus_and_slot); +static int match_pci_host_bridge(struct device *dev, void *data) +{ + return 1; +} + +struct pci_bus *pci_get_next_root_bus(struct pci_bus *bus) +{ + struct device *dev; + + WARN_ON(in_interrupt()); + dev = bus_find_device(&pci_host_bridge_bus_type, + bus ? bus->bridge : NULL, + NULL, + match_pci_host_bridge); + if (bus) + put_device(bus->bridge); + if (dev) + return to_pci_host_bridge(dev)->bus; + + return NULL; +} + static int match_pci_dev_by_id(struct device *dev, void *data) { struct pci_dev *pdev = to_pci_dev(dev); diff --git a/include/linux/pci.h b/include/linux/pci.h index be1de01..54e8fa1 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -394,6 +394,8 @@ struct pci_host_bridge { }; #define to_pci_host_bridge(n) container_of(n, struct pci_host_bridge, dev) +#define for_each_pci_root_bus(bus) while (bus = pci_get_next_root_bus(bus)) + void pci_set_host_bridge_release(struct pci_host_bridge *bridge, void (*release_fn)(struct pci_host_bridge *), void *release_data); @@ -757,6 +759,7 @@ int pci_find_ht_capability(struct pci_dev *dev, int ht_cap); int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap); struct pci_bus *pci_find_next_bus(const struct pci_bus *from); +struct pci_bus *pci_get_next_root_bus(struct pci_bus *from); struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device, struct pci_dev *from); struct pci_dev *pci_get_subsys(unsigned int vendor, unsigned int device,