Commit b52142004fbdfd6db0091ba7ae33c91e3b459034

Authored by Stefan Roese
1 parent e5fd39c886

pci: Add pci_get_devfn() to extract devfn from the fdt_pci_addr

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>

Showing 2 changed files with 29 additions and 9 deletions Side-by-side Diff

drivers/pci/pci-uclass.c
... ... @@ -1007,10 +1007,25 @@
1007 1007 return 0;
1008 1008 }
1009 1009  
  1010 +int pci_get_devfn(struct udevice *dev)
  1011 +{
  1012 + struct fdt_pci_addr addr;
  1013 + int ret;
  1014 +
  1015 + /* Extract the devfn from fdt_pci_addr */
  1016 + ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG,
  1017 + "reg", &addr);
  1018 + if (ret) {
  1019 + if (ret != -ENOENT)
  1020 + return -EINVAL;
  1021 + }
  1022 +
  1023 + return addr.phys_hi & 0xff00;
  1024 +}
  1025 +
1010 1026 static int pci_uclass_child_post_bind(struct udevice *dev)
1011 1027 {
1012 1028 struct pci_child_platdata *pplat;
1013   - struct fdt_pci_addr addr;
1014 1029 int ret;
1015 1030  
1016 1031 if (!dev_of_valid(dev))
... ... @@ -1022,14 +1037,9 @@
1022 1037 ofnode_read_pci_vendev(dev_ofnode(dev), &pplat->vendor, &pplat->device);
1023 1038  
1024 1039 /* Extract the devfn from fdt_pci_addr */
1025   - ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG, "reg",
1026   - &addr);
1027   - if (ret) {
1028   - if (ret != -ENOENT)
1029   - return -EINVAL;
1030   - } else {
1031   - pplat->devfn = addr.phys_hi & 0xff00;
1032   - }
  1040 + pplat->devfn = pci_get_devfn(dev);
  1041 + if (ret < 0)
  1042 + return ret;
1033 1043  
1034 1044 return 0;
1035 1045 }
... ... @@ -1560,6 +1560,16 @@
1560 1560 int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn,
1561 1561 struct udevice **containerp, struct udevice **emulp);
1562 1562  
  1563 +/**
  1564 + * pci_get_devfn() - Extract the devfn from fdt_pci_addr of the device
  1565 + *
  1566 + * Get devfn from fdt_pci_addr of the specifified device
  1567 + *
  1568 + * @dev: PCI device
  1569 + * @return devfn in bits 15...8 if found, -ENODEV if not found
  1570 + */
  1571 +int pci_get_devfn(struct udevice *dev);
  1572 +
1563 1573 #endif /* CONFIG_DM_PCI */
1564 1574  
1565 1575 /**