Re: [U-Boot] [PATCH 06/23] pci: Set of_offset for devices not probed via DT compatible strings

2016-09-26 Thread Simon Glass
Hi Paul,

On 26 September 2016 at 12:29, Paul Burton  wrote:
> A PCI device may be probed through standard PCI config space probing but
> still be represented in a device tree. However U-Boot would not
> previously set the of_offset field of the struct udevice for such PCI
> devices. Fix this by searching for a DT node based upon its "reg"
> property after binding a PCI device that wasn't already seen in the DT.
>
> Signed-off-by: Paul Burton 
>
> ---
>
>  drivers/pci/pci-uclass.c | 32 
>  1 file changed, 32 insertions(+)

I can't see how this can happen. The PCI binding is supposed to
operate using the device tree:

/* Find this device in the device tree */
ret = pci_bus_find_devfn(bus, PCI_MASK_BUS(bdf), );

Do you know what is going wrong?

Regards,
Simon
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 06/23] pci: Set of_offset for devices not probed via DT compatible strings

2016-09-26 Thread Paul Burton
A PCI device may be probed through standard PCI config space probing but
still be represented in a device tree. However U-Boot would not
previously set the of_offset field of the struct udevice for such PCI
devices. Fix this by searching for a DT node based upon its "reg"
property after binding a PCI device that wasn't already seen in the DT.

Signed-off-by: Paul Burton 

---

 drivers/pci/pci-uclass.c | 32 
 1 file changed, 32 insertions(+)

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 3b00e6a..415c632 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -670,6 +670,33 @@ error:
return ret;
 }
 
+static int find_pci_of_offset(struct udevice *bus, struct udevice *dev,
+ pci_dev_t bdf)
+{
+   struct fdt_pci_addr addr;
+   int offset, err;
+
+   if (bus->of_offset == -1)
+   return -ENOENT;
+
+   fdt_for_each_subnode(gd->fdt_blob, offset, bus->of_offset) {
+   err = fdtdec_get_pci_addr(gd->fdt_blob, offset,
+ FDT_PCI_SPACE_CONFIG, "reg", );
+   if (err == -ENOENT)
+   continue;
+   if (err)
+   return err;
+
+   if (bdf != (addr.phys_hi & 0x00))
+   continue;
+
+   dev->of_offset = offset;
+   return 0;
+   }
+
+   return -ENOENT;
+}
+
 int pci_bind_bus_devices(struct udevice *bus)
 {
ulong vendor, device;
@@ -731,6 +758,11 @@ int pci_bind_bus_devices(struct udevice *bus)
}
ret = pci_find_and_bind_driver(bus, _id, bdf,
   );
+   if (!ret) {
+   ret = find_pci_of_offset(bus, dev, bdf);
+   if (ret == -ENOENT)
+   ret = 0;
+   }
}
if (ret == -EPERM)
continue;
-- 
2.10.0

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot