From patchwork Wed Jan 9 20:43:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1955411 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 C385D3FD40 for ; Wed, 9 Jan 2013 20:48:54 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tt2Wc-0004g7-Cr; Wed, 09 Jan 2013 20:45:26 +0000 Received: from moutng.kundenserver.de ([212.227.17.9]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Tt2Uy-00045P-0Z for linux-arm-kernel@lists.infradead.org; Wed, 09 Jan 2013 20:43:47 +0000 Received: from mailbox.adnet.avionic-design.de (mailbox.avionic-design.de [109.75.18.3]) by mrelayeu.kundenserver.de (node=mreu3) with ESMTP (Nemesis) id 0Lx0lJ-1SvBlh3z8j-016iFJ; Wed, 09 Jan 2013 21:43:21 +0100 Received: from localhost (localhost [127.0.0.1]) by mailbox.adnet.avionic-design.de (Postfix) with ESMTP id 0BB8D2A28147; Wed, 9 Jan 2013 21:43:20 +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 8SMo0Yu+Hs3f; Wed, 9 Jan 2013 21:43:18 +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 884132A2813E; 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 A8EE210051D; Wed, 9 Jan 2013 21:43:11 +0100 (CET) From: Thierry Reding To: linux-tegra@vger.kernel.org Subject: [PATCH 02/14] of/pci: Add of_pci_get_devfn() function Date: Wed, 9 Jan 2013 21:43:02 +0100 Message-Id: <1357764194-12677-3-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:kSnrPVGIArMVLyWs2q0arebTlipX3hwt63btPabA7Rv 83izFYJTDwCUlUB2gbQRMtFLcprpX/wDR/UF9hj0/VzJgo/zxF JgXHoYsXtS5tNljtEpxEp4vcsdQAUQsfJXEWv6gtCSewuFW7OV PgqQGW2JHTrNOP3JpNlgV1KoroX4iXRFhV1jH/HW5fr834b8CV zynVA7Yy8JC00uIS/FD5ZaKybeyHoDDER6C+Sah/Lkbz8UIqWk jdI5XugF5MAGkz0xn2IN3lmggSBAXtUvF7RwmWdCkYw9om2CQK KCUUanNJ8X3Ark+ueX/cbT3ScFtmSToqnSTZqI4Z/VCknSbgDr oApwKjKpS0xLDvPhhYdCaT5r21MUjSuK4XWlKj8IUumszQ0E0K Z96wfigPCnAjitzmERQzH9LqIl5JFoeuPKP7vKacmOsQ0B8Oqg E64W5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130109_154345_204957_47E41DF8 X-CRM114-Status: GOOD ( 14.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.9 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 device and function number from a standard 5-cell PCI resource. PCI_SLOT() and PCI_FUNC() can be used on the returned value obtain the device and function numbers respectively. Signed-off-by: Thierry Reding --- drivers/of/of_pci.c | 32 ++++++++++++++++++++++++++++---- include/linux/of_pci.h | 1 + 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 13e37e2..0dd52df 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -7,12 +7,13 @@ static inline int __of_pci_pci_compare(struct device_node *node, unsigned int devfn) { - unsigned int size; - const __be32 *reg = of_get_property(node, "reg", &size); + int err; - if (!reg || size < 5 * sizeof(__be32)) + err = of_pci_get_devfn(node); + if (err < 0) return 0; - return ((be32_to_cpup(®[0]) >> 8) & 0xff) == devfn; + + return devfn == err; } struct device_node *of_pci_find_child_device(struct device_node *parent, @@ -40,3 +41,26 @@ struct device_node *of_pci_find_child_device(struct device_node *parent, return NULL; } EXPORT_SYMBOL_GPL(of_pci_find_child_device); + +/** + * of_pci_get_devfn() - Get device and function numbers for a device node + * @np: device node + * + * Parses a standard 5-cell PCI resource and returns an 8-bit value that can + * be passed to the PCI_SLOT() and PCI_FUNC() macros to extract the device + * and function numbers respectively. On error a negative error code is + * returned. + */ +int of_pci_get_devfn(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) >> 8) & 0xff; +} +EXPORT_SYMBOL_GPL(of_pci_get_devfn); diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h index bb115de..91ec484 100644 --- a/include/linux/of_pci.h +++ b/include/linux/of_pci.h @@ -10,5 +10,6 @@ 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_devfn(struct device_node *np); #endif