mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] PCI: register and active bridge device before proceeding to scan
@ 2015-04-29 19:59 Lucas Stach
  2015-04-29 19:59 ` [PATCH 2/3] PCI: fill in bus primary field Lucas Stach
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Lucas Stach @ 2015-04-29 19:59 UTC (permalink / raw)
  To: barebox

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.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
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(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 40e0fe7..470ea66 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -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);
-- 
2.1.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] PCI: fill in bus primary field
  2015-04-29 19:59 [PATCH 1/3] PCI: register and active bridge device before proceeding to scan Lucas Stach
@ 2015-04-29 19:59 ` Lucas Stach
  2015-04-29 19:59 ` [PATCH 3/3] PCI: imx6: simplify config access code Lucas Stach
  2015-05-01  6:38 ` [PATCH 1/3] PCI: register and active bridge device before proceeding to scan Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Lucas Stach @ 2015-04-29 19:59 UTC (permalink / raw)
  To: barebox

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.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 drivers/pci/pci.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 470ea66..3a0e7a5 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -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;
 
-- 
2.1.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] PCI: imx6: simplify config access code
  2015-04-29 19:59 [PATCH 1/3] PCI: register and active bridge device before proceeding to scan Lucas Stach
  2015-04-29 19:59 ` [PATCH 2/3] PCI: fill in bus primary field Lucas Stach
@ 2015-04-29 19:59 ` Lucas Stach
  2015-05-01  6:38 ` [PATCH 1/3] PCI: register and active bridge device before proceeding to scan Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Lucas Stach @ 2015-04-29 19:59 UTC (permalink / raw)
  To: barebox

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

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 drivers/pci/pcie-designware.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/pcie-designware.c b/drivers/pci/pcie-designware.c
index 4edaede..4962a19 100644
--- a/drivers/pci/pcie-designware.c
+++ b/drivers/pci/pcie-designware.c
@@ -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);
-- 
2.1.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] PCI: register and active bridge device before proceeding to scan
  2015-04-29 19:59 [PATCH 1/3] PCI: register and active bridge device before proceeding to scan Lucas Stach
  2015-04-29 19:59 ` [PATCH 2/3] PCI: fill in bus primary field Lucas Stach
  2015-04-29 19:59 ` [PATCH 3/3] PCI: imx6: simplify config access code Lucas Stach
@ 2015-05-01  6:38 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2015-05-01  6:38 UTC (permalink / raw)
  To: Lucas Stach; +Cc: barebox

On Wed, Apr 29, 2015 at 09:59:46PM +0200, Lucas Stach wrote:
> 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.
> 
> Signed-off-by: Lucas Stach <dev@lynxeye.de>
> ---
> 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

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-05-01  6:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-29 19:59 [PATCH 1/3] PCI: register and active bridge device before proceeding to scan Lucas Stach
2015-04-29 19:59 ` [PATCH 2/3] PCI: fill in bus primary field Lucas Stach
2015-04-29 19:59 ` [PATCH 3/3] PCI: imx6: simplify config access code Lucas Stach
2015-05-01  6:38 ` [PATCH 1/3] PCI: register and active bridge device before proceeding to scan Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox