diff mbox

[U-Boot,04/23] fdt: Add a function to return PCI BDF triplet

Message ID 1408346196-30419-5-git-send-email-thierry.reding@gmail.com
State Superseded
Delegated to: Simon Glass
Headers show

Commit Message

Thierry Reding Aug. 18, 2014, 7:16 a.m. UTC
From: Thierry Reding <treding@nvidia.com>

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.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 include/fdtdec.h | 11 +++++++++++
 lib/fdtdec.c     | 14 ++++++++++++++
 2 files changed, 25 insertions(+)

Comments

Simon Glass Aug. 18, 2014, 6:20 p.m. UTC | #1
On 18 August 2014 01:16, Thierry Reding <thierry.reding@gmail.com> wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> 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.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>

Acked-by: Simon Glass <sjg@chromium.org>
diff mbox

Patch

diff --git a/include/fdtdec.h b/include/fdtdec.h
index e9091eee6bae..56bc29375128 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -631,4 +631,15 @@  int fdt_get_named_resource(const void *fdt, int node, const char *property,
 			   const char *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 fbfae4a7cbaf..d2f2c9164b37 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -734,4 +734,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