]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
fdt: Add a function to return PCI BDF triplet
authorThierry Reding <treding@nvidia.com>
Tue, 26 Aug 2014 15:33:54 +0000 (17:33 +0200)
committerSimon Glass <sjg@chromium.org>
Wed, 22 Oct 2014 22:56:41 +0000 (16:56 -0600)
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 <sjg@chromium.org>
Signed-off-by: Thierry Reding <treding@nvidia.com>
include/fdtdec.h
lib/fdtdec.c

index 8b24deb767d05a1c05037a930bf829d83693f032..99cb3538041e1a5e63cc140959d99db2706e78ec 100644 (file)
@@ -649,4 +649,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
index b3c43be89d5db04d00bcce4f3e7cf7e1d1099a77..4f66ae172fe1ec3a0db742f31fc44fb76ce1c8c6 100644 (file)
@@ -765,4 +765,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