From patchwork Fri Mar 8 15:19:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Petazzoni X-Patchwork-Id: 2238851 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id A7203DF215 for ; Fri, 8 Mar 2013 15:28:11 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UDz8B-0001Er-4u; Fri, 08 Mar 2013 15:22:48 +0000 Received: from mail.free-electrons.com ([94.23.35.102]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UDz54-0000Bu-RC for linux-arm-kernel@lists.infradead.org; Fri, 08 Mar 2013 15:19:42 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id 4F8A71130; Fri, 8 Mar 2013 16:19:36 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.3.2 Received: from localhost (col31-4-88-188-83-94.fbx.proxad.net [88.188.83.94]) by mail.free-electrons.com (Postfix) with ESMTPSA id CFA437FF; Fri, 8 Mar 2013 16:19:35 +0100 (CET) From: Thomas Petazzoni To: Bjorn Helgaas , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 03/18] of/pci: Add of_pci_get_bus() function Date: Fri, 8 Mar 2013 16:19:05 +0100 Message-Id: <1362755960-30791-4-git-send-email-thomas.petazzoni@free-electrons.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1362755960-30791-1-git-send-email-thomas.petazzoni@free-electrons.com> References: <1362755960-30791-1-git-send-email-thomas.petazzoni@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130308_101935_720425_00939E62 X-CRM114-Status: GOOD ( 13.00 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.6 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Lior Amsalem , Andrew Lunn , Yehuda Yitschak , Russell King , Jason Cooper , Arnd Bergmann , Maen Suleiman , Thierry Reding , Eran Ben-Avi , Nadav Haklai , Gregory Clement , Shadi Ammouri , Ezequiel Garcia , Stephen Warren , Olof Johansson , Tawfik Bayouk , Jason Gunthorpe X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Thierry Reding This function can be used to parse the number of a device's parent PCI bus from a standard 5-cell PCI resource. Signed-off-by: Thierry Reding --- drivers/of/of_pci.c | 21 +++++++++++++++++++++ include/linux/of_pci.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 4dd7b9b..d6e6de5 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -43,6 +43,27 @@ struct device_node *of_pci_find_child_device(struct device_node *parent, EXPORT_SYMBOL_GPL(of_pci_find_child_device); /** + * of_pci_get_bus() - Get bus number for a device node + * @np: device node + * + * Parses a standard 5-cell PCI resource and returns the 8-bit bus number of + * the device's parent PCI bus. On error a negative error code is returned. + */ +int of_pci_get_bus(struct device_node *np) +{ + unsigned int size; + const __be32 *reg; + + reg = of_get_property(np, "reg", &size); + + if (!reg || size < 5 * sizeof(__be32)) + return -EINVAL; + + return (be32_to_cpup(reg) >> 16) & 0xff; +} +EXPORT_SYMBOL_GPL(of_pci_get_bus); + +/** * of_pci_get_devfn() - Get device and function numbers for a device node * @np: device node * diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h index 91ec484..9118321 100644 --- a/include/linux/of_pci.h +++ b/include/linux/of_pci.h @@ -10,6 +10,7 @@ int of_irq_map_pci(const struct pci_dev *pdev, struct of_irq *out_irq); struct device_node; struct device_node *of_pci_find_child_device(struct device_node *parent, unsigned int devfn); +int of_pci_get_bus(struct device_node *np); int of_pci_get_devfn(struct device_node *np); #endif