From patchwork Wed Jan 9 20:43:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1955341 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 1D0BE3FD40 for ; Wed, 9 Jan 2013 20:47:50 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tt2V2-00045Y-1B; Wed, 09 Jan 2013 20:43:48 +0000 Received: from moutng.kundenserver.de ([212.227.17.8]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Tt2Uj-000423-2J for linux-arm-kernel@lists.infradead.org; Wed, 09 Jan 2013 20:43:29 +0000 Received: from mailbox.adnet.avionic-design.de (mailbox.avionic-design.de [109.75.18.3]) by mrelayeu.kundenserver.de (node=mrbap0) with ESMTP (Nemesis) id 0Lsfxh-1Sqo312vnt-012AnS; Wed, 09 Jan 2013 21:43:23 +0100 Received: from localhost (localhost [127.0.0.1]) by mailbox.adnet.avionic-design.de (Postfix) with ESMTP id C47B82A2813E; Wed, 9 Jan 2013 21:43:21 +0100 (CET) X-Virus-Scanned: amavisd-new at avionic-design.de Received: from mailbox.adnet.avionic-design.de ([127.0.0.1]) by localhost (mailbox.avionic-design.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LHNIACQGk6r9; Wed, 9 Jan 2013 21:43:20 +0100 (CET) Received: from mailman.adnet.avionic-design.de (mailman.adnet.avionic-design.de [172.20.31.172]) by mailbox.adnet.avionic-design.de (Postfix) with ESMTP id A12432A28145; Wed, 9 Jan 2013 21:43:15 +0100 (CET) Received: from localhost (avionic-0098.adnet.avionic-design.de [172.20.31.233]) by mailman.adnet.avionic-design.de (Postfix) with ESMTP id BC66410051E; Wed, 9 Jan 2013 21:43:11 +0100 (CET) From: Thierry Reding To: linux-tegra@vger.kernel.org Subject: [PATCH 03/14] of/pci: Add of_pci_get_bus() function Date: Wed, 9 Jan 2013 21:43:03 +0100 Message-Id: <1357764194-12677-4-git-send-email-thierry.reding@avionic-design.de> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1357764194-12677-1-git-send-email-thierry.reding@avionic-design.de> References: <1357764194-12677-1-git-send-email-thierry.reding@avionic-design.de> X-Provags-ID: V02:K0:nlD7iuq5xpPzGGStVlWnLT87jw4qDZr/JsT/G8Es246 wSg85jlzZ/Pzvx8T/ke0TU2G1ps3kYuKxqNw/ae8nPjV9b+VgV kCAptRcEPzuAVbegh6qpASeHlnU8Rt1sum/JEGgoKonpTEcPYM bToHYTHuGgZPrvqbVBevRzUWExms/dARRLd8wE0L7q/qqpk7Vn GTv7YJVloDppbQxGirkPESkaFLuFv6o1MRNn+07pdYD8/4VzcW N1UXdLCC3jBEU3uefsttHKV7bJpv1ozwia8JVG7+JJBbPEh/h0 rOb93dtDb6KZG4nyqhm1XJ+tHVfnFclVsNxeB39mEE0Z7jGXv5 IUw1jeUR9/BpJoE5S7+yeC7fW9Sz91pNpweeKLJd/B/F4Lv+wu FlR5bMZ9SIyMeCxJC9DM7m2o5NzfDeeq082em9pW1pXaxqmESV vbWNl X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130109_154329_410174_94230609 X-CRM114-Status: GOOD ( 12.13 ) X-Spam-Score: 1.1 (+) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (1.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [212.227.17.8 listed in list.dnswl.org] 3.0 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Thomas Petazzoni , Jason Gunthorpe , Russell King , Arnd Bergmann , Stephen Warren , linux-pci@vger.kernel.org, devicetree-discuss@lists.ozlabs.org, linux-kernel@vger.kernel.org, Rob Herring , Grant Likely , Bjorn Helgaas , Andrew Murray , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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 0dd52df..7d5d2c3 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