Skip to contentSkip to conversation

PCI: register and active bridge device before proceeding to scan

PATCH Applied Lucas Stach 2 participants 4 messages Apr 29, 2015 – May 1, 2015 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 PCI: register and active bridge device before proceeding to scan

The bridge device needs to be registered and activated before the scanning can proceed, as the bridge is the parent for other devices.

This fixes a NULL ptr derefernce when scanning PCI hierarchies with bridges behind bridges.

---
Please apply to master, as this fixes a crash when activating PCI support on the GW54xx board.

---
 drivers/pci/pci.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/pci/pci.c +6 -2
index 40e0fe7..470ea66 100644
@@ -371,11 +371,15 @@ unsigned int pci_scan_bus(struct pci_bus *bus)
 			list_add_tail(&child_bus->node, &bus->children);
 			dev->subordinate = child_bus;
 
+			/* activate bridge device */
+			pci_register_device(dev);
+
+			/* scan pci hierarchy behind bridge */
 			prescan_setup_bridge(dev);
 			pci_scan_bus(child_bus);
 			postscan_setup_bridge(dev);
-			/* first activate bridge then all devices on it's bus */
-			pci_register_device(dev);
+
+			/* finally active all devices behind the bridge */
 			list_for_each_entry(dev, &child_bus->devices, bus_list)
 				if (!dev->subordinate)
 					pci_register_device(dev);
Signature · 7 lines
2.1.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 2/3 PCI: fill in bus primary field

This was erroneously left uninitialzed as nothing was using it. The i.MX6 PCI driver needs this to be filled properly to decide if a config space access is allowed for a specific devfn.

This fixes PCI enumeration on the Gateworks GW54xx board.

---
 drivers/pci/pci.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/pci.c +1 -0
index 470ea66..3a0e7a5 100644
@@ -368,6 +368,7 @@ unsigned int pci_scan_bus(struct pci_bus *bus)
 
 			child_bus->parent = &dev->dev;
 			child_bus->number = bus_index++;
+			child_bus->primary = bus->number;
 			list_add_tail(&child_bus->node, &bus->children);
 			dev->subordinate = child_bus;
 
Signature · 7 lines
2.1.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 3/3 PCI: imx6: simplify config access code

In reply to Lucas Stach

The PCI core fills in the primary bus number, so there is no need to walk up the PCI hierarchy in the driver manually.

---
 drivers/pci/pcie-designware.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/pci/pcie-designware.c +2 -9
index 4edaede..4962a19 100644
@@ -350,13 +350,6 @@ static void dw_pcie_prog_viewport_io_outbound(struct pcie_port *pp)
 	dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2);
 }
 
-struct pci_bus *get_parent_bus(struct pci_bus *bus)
-{
-	struct pci_dev *bridge = container_of(bus->parent, struct pci_dev, dev);
-
-	return bridge->bus;
-}
-
 static int dw_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus,
 		u32 devfn, int where, int size, u32 *val)
 {
@@ -367,7 +360,7 @@ static int dw_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus,
 		 PCIE_ATU_FUNC(PCI_FUNC(devfn));
 	address = where & ~0x3;
 
-	if (get_parent_bus(bus)->number == pp->root_bus_nr) {
+	if (bus->primary == pp->root_bus_nr) {
 		dw_pcie_prog_viewport_cfg0(pp, busdev);
 		ret = dw_pcie_cfg_read(pp->va_cfg0_base + address, where, size,
 				val);
@@ -392,7 +385,7 @@ static int dw_pcie_wr_other_conf(struct pcie_port *pp, struct pci_bus *bus,
 		 PCIE_ATU_FUNC(PCI_FUNC(devfn));
 	address = where & ~0x3;
 
-	if (get_parent_bus(bus)->number == pp->root_bus_nr) {
+	if (bus->primary == pp->root_bus_nr) {
 		dw_pcie_prog_viewport_cfg0(pp, busdev);
 		ret = dw_pcie_cfg_write(pp->va_cfg0_base + address, where, size,
 				val);
Signature · 7 lines
2.1.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#3 lore raw
In reply to Lucas Stach
Quoted 7 lines · Lucas Stach

The bridge device needs to be registered and activated before the scanning can proceed, as the bridge is the parent for other devices.

This fixes a NULL ptr derefernce when scanning PCI hierarchies with bridges behind bridges.

Quoted 7 lines

---
Please apply to master, as this fixes a crash when activating PCI support on the GW54xx board.

---
 drivers/pci/pci.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox