[U-Boot] [PATCH] core: ofnode: Add ofnode_pci_get_devfn()

Stefan Roese sr at denx.de
Fri Jan 18 11:46:38 UTC 2019


This function will be used by the Marvell Armada XP/38x PCIe driver,
which is moved to DM right now. It's mostly copied from the Linux
version.

Signed-off-by: Stefan Roese <sr at denx.de>
Cc: Simon Glass <sjg at chromium.org>
---
 drivers/core/ofnode.c | 12 ++++++++++++
 include/dm/ofnode.h   | 11 +++++++++++
 2 files changed, 23 insertions(+)

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 0e584c12dc..b74b95ff61 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -666,6 +666,18 @@ int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device)
 	return -ENOENT;
 }
 
+int ofnode_pci_get_devfn(ofnode node)
+{
+	u32 reg[5];
+	int error;
+
+	error = ofnode_read_u32_array(node, "reg", reg, ARRAY_SIZE(reg));
+	if (error)
+		return error;
+
+	return (reg[0] >> 8) & 0xff;
+}
+
 int ofnode_read_addr_cells(ofnode node)
 {
 	if (ofnode_is_np(node))
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index d206ee2caa..66d7f8d055 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -608,6 +608,17 @@ int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
  */
 int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device);
 
+/**
+ * ofnode_pci_get_devfn() - Get device and function numbers for a device node
+ * @ofnode: node to examine
+ *
+ * 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 ofnode_pci_get_devfn(ofnode node);
+
 /**
  * ofnode_read_addr_cells() - Get the number of address cells for a node
  *
-- 
2.20.1



More information about the U-Boot mailing list