pci: Add pci_get_devfn() to extract devfn from the fdt_pci_addr
authorStefan Roese <sr@denx.de>
Fri, 25 Jan 2019 10:52:42 +0000 (11:52 +0100)
committerStefan Roese <sr@denx.de>
Tue, 5 Feb 2019 13:22:24 +0000 (14:22 +0100)
This function will be used by the Marvell Armada XP/38x PCIe driver,
which is moved to DM right now. So let's extract the functionality
from pci_uclass_child_post_bind() to make it available.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
drivers/pci/pci-uclass.c
include/pci.h

index 2cf55cb743d71ba2532d3a41029011349167b14d..47f3cc9107d961c2a2c188237e8e8a16104060ad 100644 (file)
@@ -1007,10 +1007,25 @@ static int pci_uclass_post_probe(struct udevice *bus)
        return 0;
 }
 
+int pci_get_devfn(struct udevice *dev)
+{
+       struct fdt_pci_addr addr;
+       int ret;
+
+       /* Extract the devfn from fdt_pci_addr */
+       ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG,
+                                  "reg", &addr);
+       if (ret) {
+               if (ret != -ENOENT)
+                       return -EINVAL;
+       }
+
+       return addr.phys_hi & 0xff00;
+}
+
 static int pci_uclass_child_post_bind(struct udevice *dev)
 {
        struct pci_child_platdata *pplat;
-       struct fdt_pci_addr addr;
        int ret;
 
        if (!dev_of_valid(dev))
@@ -1022,14 +1037,9 @@ static int pci_uclass_child_post_bind(struct udevice *dev)
        ofnode_read_pci_vendev(dev_ofnode(dev), &pplat->vendor, &pplat->device);
 
        /* Extract the devfn from fdt_pci_addr */
-       ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG, "reg",
-                                  &addr);
-       if (ret) {
-               if (ret != -ENOENT)
-                       return -EINVAL;
-       } else {
-               pplat->devfn = addr.phys_hi & 0xff00;
-       }
+       pplat->devfn = pci_get_devfn(dev);
+       if (ret < 0)
+               return ret;
 
        return 0;
 }
index 785d7d28b7e44c3500587624665349dcae90c493..041f8e37476538f0fe63b8dee892b66e7bb17a88 100644 (file)
@@ -1560,6 +1560,16 @@ struct dm_pci_emul_ops {
 int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn,
                         struct udevice **containerp, struct udevice **emulp);
 
+/**
+ * pci_get_devfn() - Extract the devfn from fdt_pci_addr of the device
+ *
+ * Get devfn from fdt_pci_addr of the specifified device
+ *
+ * @dev:       PCI device
+ * @return devfn in bits 15...8 if found, -ENODEV if not found
+ */
+int pci_get_devfn(struct udevice *dev);
+
 #endif /* CONFIG_DM_PCI */
 
 /**