From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Reding Date: Tue, 26 Aug 2014 17:33:54 +0200 Subject: [U-Boot] [PATCH v2 06/40] fdt: Add a function to return PCI BDF triplet In-Reply-To: <1409067268-956-1-git-send-email-thierry.reding@gmail.com> References: <1409067268-956-1-git-send-email-thierry.reding@gmail.com> Message-ID: <1409067268-956-7-git-send-email-thierry.reding@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de From: Thierry Reding The fdtdec_pci_get_bdf() function returns the bus, device, function triplet of a PCI device by parsing the "reg" property according to the PCI device tree binding. Acked-by: Simon Glass Signed-off-by: Thierry Reding --- include/fdtdec.h | 11 +++++++++++ lib/fdtdec.c | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/fdtdec.h b/include/fdtdec.h index c35d378602d2..5c669a5c8e03 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -635,4 +635,15 @@ int fdt_get_named_resource(const void *fdt, int node, const char *property, const char *prop_names, const char *name, struct fdt_resource *res); +/** + * Look at the reg property of a device node that represents a PCI device + * and parse the bus, device and function number from it. + * + * @param fdt FDT blob + * @param node node to examine + * @param bdf returns bus, device, function triplet + * @return 0 if ok, negative on error + */ +int fdtdec_pci_get_bdf(const void *fdt, int node, int *bdf); + #endif diff --git a/lib/fdtdec.c b/lib/fdtdec.c index c3fa82f1a28a..fa5da0c0147d 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -748,4 +748,18 @@ int fdt_get_named_resource(const void *fdt, int node, const char *property, return fdt_get_resource(fdt, node, property, index, res); } + +int fdtdec_pci_get_bdf(const void *fdt, int node, int *bdf) +{ + const fdt32_t *prop; + int len; + + prop = fdt_getprop(fdt, node, "reg", &len); + if (!prop) + return len; + + *bdf = fdt32_to_cpu(*prop) & 0xffffff; + + return 0; +} #endif -- 2.0.4