From patchwork Wed Apr 3 14:45:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 2388131 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 234EF4020C for ; Wed, 3 Apr 2013 14:52:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761126Ab3DCOpo (ORCPT ); Wed, 3 Apr 2013 10:45:44 -0400 Received: from moutng.kundenserver.de ([212.227.17.10]:58261 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761015Ab3DCOpl (ORCPT ); Wed, 3 Apr 2013 10:45:41 -0400 Received: from mailbox.adnet.avionic-design.de (mailbox.avionic-design.de [109.75.18.3]) by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis) id 0McRue-1U5jYx3iF6-00HxTR; Wed, 03 Apr 2013 16:45:24 +0200 Received: from localhost (localhost [127.0.0.1]) by mailbox.adnet.avionic-design.de (Postfix) with ESMTP id CCFCF2A28131; Wed, 3 Apr 2013 16:45:22 +0200 (CEST) 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 LZdvY+zYxlIN; Wed, 3 Apr 2013 16:45:21 +0200 (CEST) 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 090112A280CB; Wed, 3 Apr 2013 16:45:18 +0200 (CEST) Received: from localhost (avionic-0098.adnet.avionic-design.de [172.20.31.233]) by mailman.adnet.avionic-design.de (Postfix) with ESMTP id 748BD1007CF; Wed, 3 Apr 2013 16:45:16 +0200 (CEST) From: Thierry Reding To: Grant Likely , Rob Herring , Stephen Warren , Bjorn Helgaas Cc: Russell King , Andrew Murray , Jason Gunthorpe , Arnd Bergmann , Thomas Petazzoni , devicetree-discuss@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, linux-pci@vger.kernel.org Subject: [PATCH v3 02/12] of/pci: Add of_pci_get_devfn() function Date: Wed, 3 Apr 2013 16:45:08 +0200 Message-Id: <1365000318-28256-3-git-send-email-thierry.reding@avionic-design.de> X-Mailer: git-send-email 1.8.2 In-Reply-To: <1365000318-28256-1-git-send-email-thierry.reding@avionic-design.de> References: <1365000318-28256-1-git-send-email-thierry.reding@avionic-design.de> X-Provags-ID: V02:K0:sMbCCrVSiVUZdwhQYMhDa4ZRqswtIKRFIvaayyruitJ NiERnkIn8bSI6tD+eDxAdIQjwV+J6G3tMJTCzHkpNMl7Uajbvw jKmfSbvLI0OMzg6INkdLb2dPiZ4G5WSoXJYj5b07b+jF7CY1s8 Lbzt0yXxFUeVImaFRIgCqPajFsD0/fyLmDlfWKa2it5sclNILI 5+L2Ru//CED1fjcBqdZjy1LJAeaC+VN+x4+moQIPPkHHyMW+wp h+q+0Q9cUvHBG3SeUQ6PbPpbT23NiaHray6ikvd2SGAtH9B90/ KJFpW9ZDeMxID9sRYYxhQTX6y1T/dmfg4SeAP7/PcUqqz5J6yN nZB7L1JKOHiH2ofFa5D0pemukn6AWesYC1uldfiqS8JLg3hxIu tmcG2wWOu+62yH27BcB9XArWDHtCJQKi6JHj+fmxF95n0Qirl2 DaejR Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.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 --- Changes in v2: - rename devfn and err variables for clarity drivers/of/of_pci.c | 34 +++++++++++++++++++++++++++++----- include/linux/of_pci.h | 1 + 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 13e37e2..4dd7b9b 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -5,14 +5,15 @@ #include static inline int __of_pci_pci_compare(struct device_node *node, - unsigned int devfn) + unsigned int data) { - unsigned int size; - const __be32 *reg = of_get_property(node, "reg", &size); + int devfn; - if (!reg || size < 5 * sizeof(__be32)) + devfn = of_pci_get_devfn(node); + if (devfn < 0) return 0; - return ((be32_to_cpup(®[0]) >> 8) & 0xff) == devfn; + + return devfn == data; } 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