Skip to contentSkip to conversation

pci: Do not access Freescale PCI controllers BARs registers

PATCH In review Pali Rohár 3 participants 14 messages Apr 20, 2023 – May 4, 2023 PCI

lore
Share & tools
lore
#0 lore raw

cover pci: Do not access Freescale PCI controllers BARs registers

Freescale PCI and PCIe controllers export in config space in BARs offset for BDF address 00:00.0 internal controller registers, instead of BAR registers. Avoid access to these registers to prevent overwriting them.

Fixes autoconfiguration of PCI and PCIe devices on Freescale PowerPC platforms.

Pali Rohár (3):
pci: mpc85xx: Do not access PCI BARs registers of BDF address 00:00.0
pci: fsl: Do not access PCI BAR0 register of PCIe Root Port
pci: auto: Remove PCI_CLASS_PROCESSOR_POWERPC autoconfig case

 drivers/pci/pci_auto.c    |  4 ----
 drivers/pci/pci_mpc85xx.c | 12 ++++++++++++
 drivers/pci/pcie_fsl.c    | 14 ++++++++++++++
 3 files changed, 26 insertions(+), 4 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 pci: mpc85xx: Do not access PCI BARs registers of BDF address 00:00.0

At BDF address 00:00.0 is fictional device which PCI configuration header is for configuring mpc85xx PCI controller itself. PCI config space of this device has ATMU inbound registers on position of PCI BARs. Trying to do PCI auto configuration of this device cause rewriting ATMU inbound registers. To avoid it, do not allow overwriting registers at BARs positions. And because this device does not have any PCI memory, return zeros when trying to read PCI BARs config space registers. It signals to auto configuration tool to not allocate any PCI memory for this device.

This information is taken from MPC8544E Reference Manual, sections 17.3.1.3, 17.3.1.1.1, 17.3.2 and 17.3.2.11. Available at NXP website:
https://www.nxp.com/docs/en/reference-manual/MPC8544ERM.pdf

---
 drivers/pci/pci_mpc85xx.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/pci/pci_mpc85xx.c +12 -0
index 833de816c459..249cfe66466b 100644
@@ -27,6 +27,13 @@ static int mpc85xx_pci_dm_read_config(const struct udevice *dev, pci_dev_t bdf,
 		return 0;
 	}
 
+	/* Skip mpc85xx PCI controller's ATMU inbound registers */
+	if (PCI_BUS(bdf) == 0 && PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 &&
+	    (offset & ~3) >= PCI_BASE_ADDRESS_0 && (offset & ~3) <= PCI_BASE_ADDRESS_5) {
+		*value = 0;
+		return 0;
+	}
+
 	addr = PCI_CONF1_ADDRESS(PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), offset);
 	out_be32(priv->cfg_addr, addr);
 	sync();
@@ -56,6 +63,11 @@ static int mpc85xx_pci_dm_write_config(struct udevice *dev, pci_dev_t bdf,
 	if (offset > 0xff)
 		return 0;
 
+	/* Skip mpc85xx PCI controller's ATMU inbound registers */
+	if (PCI_BUS(bdf) == 0 && PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 &&
+	    (offset & ~3) >= PCI_BASE_ADDRESS_0 && (offset & ~3) <= PCI_BASE_ADDRESS_5)
+		return 0;
+
 	addr = PCI_CONF1_ADDRESS(PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), offset);
 	out_be32(priv->cfg_addr, addr);
 	sync();
Signature · 1 line
2.20.1
Reviewed-by Tested-by on v1 1/3
#2 lore raw

Re: [PATCH u-boot 1/3] pci: mpc85xx: Do not access PCI BARs registers of BDF address 00:00.0

Hello Pali,

Quoted 9 lines · Pali Rohár

At BDF address 00:00.0 is fictional device which PCI configuration header is for configuring mpc85xx PCI controller itself. PCI config space of this device has ATMU inbound registers on position of PCI BARs. Trying to do PCI auto configuration of this device cause rewriting ATMU inbound registers. To avoid it, do not allow overwriting registers at BARs positions. And because this device does not have any PCI memory, return zeros when trying to read PCI BARs config space registers. It signals to auto configuration tool to not allocate any PCI memory for this device.

Quoted 8 lines

This information is taken from MPC8544E Reference Manual, sections 17.3.1.3, 17.3.1.1.1, 17.3.2 and 17.3.2.11. Available at NXP website:
https://www.nxp.com/docs/en/reference-manual/MPC8544ERM.pdf

---
 drivers/pci/pci_mpc85xx.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Tested on the socrates board, it fixes the problem:

PCI: Failed autoconfig bar 18
PCI: Failed autoconfig bar 20

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]
#3 lore raw

Re: [PATCH u-boot 1/3] pci: mpc85xx: Do not access PCI BARs registers of BDF address 00:00.0

In reply to Pali Rohár
Quoted 9 lines · Pali Rohár

At BDF address 00:00.0 is fictional device which PCI configuration header is for configuring mpc85xx PCI controller itself. PCI config space of this device has ATMU inbound registers on position of PCI BARs. Trying to do PCI auto configuration of this device cause rewriting ATMU inbound registers. To avoid it, do not allow overwriting registers at BARs positions. And because this device does not have any PCI memory, return zeros when trying to read PCI BARs config space registers. It signals to auto configuration tool to not allocate any PCI memory for this device.

Quoted 7 lines

This information is taken from MPC8544E Reference Manual, sections 17.3.1.3, 17.3.1.1.1, 17.3.2 and 17.3.2.11. Available at NXP website:
https://www.nxp.com/docs/en/reference-manual/MPC8544ERM.pdf

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#4 lore raw

PATCH 2/3 pci: fsl: Do not access PCI BAR0 register of PCIe Root Port

In reply to Pali Rohár

Freescale PCIe Root Port has PEXCSRBAR register at position of PCI BAR0. PCIe Root Port does not have any PCIe memory, so returns zero when trying to read from PCIe Root Port BAR0 and ignore any writes.

---
 drivers/pci/pcie_fsl.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/pci/pcie_fsl.c +14 -0
index 4600652f2b1b..06601840da85 100644
@@ -58,6 +58,14 @@ static int fsl_pcie_read_config(const struct udevice *bus, pci_dev_t bdf,
 		return 0;
 	}
 
+	/* Skip Freescale PCIe controller's PEXCSRBAR register */
+	if (PCI_BUS(bdf) - dev_seq(bus) == 0 &&
+	    PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 &&
+	    (offset & ~3) == PCI_BASE_ADDRESS_0) {
+		*value = 0;
+		return 0;
+	}
+
 	val = PCI_CONF1_EXT_ADDRESS(PCI_BUS(bdf) - dev_seq(bus),
 				    PCI_DEV(bdf), PCI_FUNC(bdf),
 				    offset);
@@ -95,6 +103,12 @@ static int fsl_pcie_write_config(struct udevice *bus, pci_dev_t bdf,
 	if (fsl_pcie_addr_valid(pcie, bdf))
 		return 0;
 
+	/* Skip Freescale PCIe controller's PEXCSRBAR register */
+	if (PCI_BUS(bdf) - dev_seq(bus) == 0 &&
+	    PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 &&
+	    (offset & ~3) == PCI_BASE_ADDRESS_0)
+		return 0;
+
 	val = PCI_CONF1_EXT_ADDRESS(PCI_BUS(bdf) - dev_seq(bus),
 				    PCI_DEV(bdf), PCI_FUNC(bdf),
 				    offset);
Signature · 1 line
2.20.1
Reviewed-by on v1 2/3
#5 lore raw

Re: [PATCH u-boot 2/3] pci: fsl: Do not access PCI BAR0 register of PCIe Root Port

Hello Plai,

Quoted 8 lines · Pali Rohár

Freescale PCIe Root Port has PEXCSRBAR register at position of PCI BAR0. PCIe Root Port does not have any PCIe memory, so returns zero when trying to read from PCIe Root Port BAR0 and ignore any writes.

---
 drivers/pci/pcie_fsl.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]
#6 lore raw

Re: [PATCH u-boot 2/3] pci: fsl: Do not access PCI BAR0 register of PCIe Root Port

In reply to Pali Rohár
Quoted 19 lines · Pali Rohár

Freescale PCIe Root Port has PEXCSRBAR register at position of PCI BAR0. PCIe Root Port does not have any PCIe memory, so returns zero when trying to read from PCIe Root Port BAR0 and ignore any writes.

---
 drivers/pci/pcie_fsl.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/pci/pcie_fsl.c +1 -0
index 4600652f2b1b..06601840da85 100644
@@ -58,6 +58,14 @@ static int fsl_pcie_read_config(const struct udevice *bus, pci_dev_t bdf,
 		return 0;
 	}
 
+	/* Skip Freescale PCIe controller's PEXCSRBAR register */

drivers/pci/pcie_fsl.c static int fsl_pcie_read_config(const struct udevice *bus, pci_dev_t bdf, · line 71

Quoted 10 lines
drivers/pci/pcie_fsl.c +7 -0
+	if (PCI_BUS(bdf) - dev_seq(bus) == 0 &&
+	    PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 &&
+	    (offset & ~3) == PCI_BASE_ADDRESS_0) {
+		*value = 0;
+		return 0;
+	}
+
 	val = PCI_CONF1_EXT_ADDRESS(PCI_BUS(bdf) - dev_seq(bus),
 				    PCI_DEV(bdf), PCI_FUNC(bdf),
 				    offset);

There is no "value" in this function, only "val", which in turn is local to the function, and *valuep which we are passed by the caller, please re-work and send v2, thanks.

Signature · 1 line
Tom
#7 lore raw

PATCH v2 1/1 pci: fsl: Do not access PCI BAR0 register of PCIe Root Port

Freescale PCIe Root Port has PEXCSRBAR register at position of PCI BAR0. PCIe Root Port does not have any PCIe memory, so returns zero when trying to read from PCIe Root Port BAR0 and ignore any writes.

---
 drivers/pci/pcie_fsl.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/pci/pcie_fsl.c +14 -0
index 4600652f2b1b..8d89a1e5919c 100644
@@ -58,6 +58,14 @@ static int fsl_pcie_read_config(const struct udevice *bus, pci_dev_t bdf,
 		return 0;
 	}
 
+	/* Skip Freescale PCIe controller's PEXCSRBAR register */
+	if (PCI_BUS(bdf) - dev_seq(bus) == 0 &&
+	    PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 &&
+	    (offset & ~3) == PCI_BASE_ADDRESS_0) {
+		*valuep = 0;
+		return 0;
+	}
+
 	val = PCI_CONF1_EXT_ADDRESS(PCI_BUS(bdf) - dev_seq(bus),
 				    PCI_DEV(bdf), PCI_FUNC(bdf),
 				    offset);
@@ -95,6 +103,12 @@ static int fsl_pcie_write_config(struct udevice *bus, pci_dev_t bdf,
 	if (fsl_pcie_addr_valid(pcie, bdf))
 		return 0;
 
+	/* Skip Freescale PCIe controller's PEXCSRBAR register */
+	if (PCI_BUS(bdf) - dev_seq(bus) == 0 &&
+	    PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 &&
+	    (offset & ~3) == PCI_BASE_ADDRESS_0)
+		return 0;
+
 	val = PCI_CONF1_EXT_ADDRESS(PCI_BUS(bdf) - dev_seq(bus),
 				    PCI_DEV(bdf), PCI_FUNC(bdf),
 				    offset);
Signature · 1 line
2.20.1
#8 lore raw

Re: [PATCH v2 u-boot] pci: fsl: Do not access PCI BAR0 register of PCIe Root Port

Quoted 5 lines · Pali Rohár

Freescale PCIe Root Port has PEXCSRBAR register at position of PCI BAR0. PCIe Root Port does not have any PCIe memory, so returns zero when trying to read from PCIe Root Port BAR0 and ignore any writes.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#9 lore raw

PATCH 3/3 pci: auto: Remove PCI_CLASS_PROCESSOR_POWERPC autoconfig case

In reply to Pali Rohár

PCI autoconfig case for PCI_CLASS_PROCESSOR_POWERPC just prints debug message and then calls autoconfig setup code like for any other standard endpoint device. We do not need special debug message for it, so remove this case and handle PCI_CLASS_PROCESSOR_POWERPC via default code path.

---
 drivers/pci/pci_auto.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/pci/pci_auto.c +0 -4
index 14fd3bbf679e..01230360bad2 100644
@@ -580,10 +580,6 @@ int dm_pciauto_config_device(struct udevice *dev)
 		break;
 #endif
 
-	case PCI_CLASS_PROCESSOR_POWERPC: /* an agent or end-point */
-		debug("PCI AutoConfig: Found PowerPC device\n");
-		/* fall through */
-
 	default:
 		dm_pciauto_setup_device(dev, pci_mem, pci_prefetch, pci_io);
 		break;
Signature · 1 line
2.20.1
Reviewed-by on v1 3/3
#10 lore raw

Re: [PATCH u-boot 3/3] pci: auto: Remove PCI_CLASS_PROCESSOR_POWERPC autoconfig case

Hello Pali,

Quoted 9 lines · Pali Rohár

PCI autoconfig case for PCI_CLASS_PROCESSOR_POWERPC just prints debug message and then calls autoconfig setup code like for any other standard endpoint device. We do not need special debug message for it, so remove this case and handle PCI_CLASS_PROCESSOR_POWERPC via default code path.

---
 drivers/pci/pci_auto.c | 4 ----
 1 file changed, 4 deletions(-)

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]
#11 lore raw

Re: [PATCH u-boot 3/3] pci: auto: Remove PCI_CLASS_PROCESSOR_POWERPC autoconfig case

In reply to Pali Rohár
Quoted 7 lines · Pali Rohár

PCI autoconfig case for PCI_CLASS_PROCESSOR_POWERPC just prints debug message and then calls autoconfig setup code like for any other standard endpoint device. We do not need special debug message for it, so remove this case and handle PCI_CLASS_PROCESSOR_POWERPC via default code path.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#12 lore raw
In reply to Pali Rohár

Hello Pali,

Quoted 12 lines · Pali Rohár

Freescale PCI and PCIe controllers export in config space in BARs offset for BDF address 00:00.0 internal controller registers, instead of BAR registers. Avoid access to these registers to prevent overwriting them.

Fixes autoconfiguration of PCI and PCIe devices on Freescale PowerPC platforms.

Pali Rohár (3):
pci: mpc85xx: Do not access PCI BARs registers of BDF address 00:00.0
pci: fsl: Do not access PCI BAR0 register of PCIe Root Port
pci: auto: Remove PCI_CLASS_PROCESSOR_POWERPC autoconfig case

Quoted 4 lines
 drivers/pci/pci_auto.c    |  4 ----
 drivers/pci/pci_mpc85xx.c | 12 ++++++++++++
 drivers/pci/pcie_fsl.c    | 14 ++++++++++++++
 3 files changed, 26 insertions(+), 4 deletions(-)

Many thanks for this series!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]
#13 lore raw
Quoted 15 lines · On Friday 21 April 2023 05:54:29 Heiko Schocher wrote:

Hello Pali,

Quoted 12 lines · Pali Rohár

Freescale PCI and PCIe controllers export in config space in BARs offset for BDF address 00:00.0 internal controller registers, instead of BAR registers. Avoid access to these registers to prevent overwriting them.

Fixes autoconfiguration of PCI and PCIe devices on Freescale PowerPC platforms.

Pali Rohár (3):
pci: mpc85xx: Do not access PCI BARs registers of BDF address 00:00.0
pci: fsl: Do not access PCI BAR0 register of PCIe Root Port
pci: auto: Remove PCI_CLASS_PROCESSOR_POWERPC autoconfig case

Quoted 6 lines
Quoted 4 lines
 drivers/pci/pci_auto.c    |  4 ----
 drivers/pci/pci_mpc85xx.c | 12 ++++++++++++
 drivers/pci/pcie_fsl.c    | 14 ++++++++++++++
 3 files changed, 26 insertions(+), 4 deletions(-)

Many thanks for this series!

Ok, is something more needed?

Quoted 6 lines

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]