Skip to contentSkip to conversation

ARM: RPi5: Enable PCIe

PATCH Superseded Torsten Duwe 3 participants 13 messages May 16 – May 21

Subsystems (7)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover ARM: RPi5: Enable PCIe

Basic PCIe support for the RPi5. This is the prerequisite for PCIe slot adapters / HATs and NVMe storage. Those might require their own supporting drivers or changes.

Changes from v2:
- fix wrong subject prefixes
- make reset drivers only found on the RPi5 depend on ARCH_BCM283X
- some patches Reviewed-by Peter Robinson

Changes from v1:
- fixed inbound window rewrite, which broke RPi4
- series Tested-by Pedro Falcato

Andrea della Porta (1):
pci: brcmstb: Fix PCIe bus numbers

Torsten Duwe (8):
ARM: bcm283x: Add bcm2712 PCIe memory window
pci: brcmstb: Support different variants using a cfg struct
reset: Add RPi5 brcmstb reset facilities
reset: Add RPi5 rescal reset facilities
pci: brcmstb: Get and use bridge and rescal reset properties
pci: brcmstb: Fix iBAR size calculation
pci: brcmstb: rework iBAR handling
pci: brcmstb: Adapt to AXI bridge

 .../mach-bcm283x/include/mach/acpi/bcm2711.h  |   7 +-
 arch/arm/mach-bcm283x/init.c                  |  10 +-
 configs/rpi_arm64_defconfig                   |   2 +
 drivers/pci/pcie_brcmstb.c                    | 391 ++++++++++++++++--
 drivers/reset/Kconfig                         |  16 +
 drivers/reset/Makefile                        |   2 +
 drivers/reset/reset-brcmstb-rescal.c          | 103 +++++
 drivers/reset/reset-brcmstb.c                 |  97 +++++
 8 files changed, 590 insertions(+), 38 deletions(-)
 create mode 100644 drivers/reset/reset-brcmstb-rescal.c
 create mode 100644 drivers/reset/reset-brcmstb.c
Signature · 1 line
2.54.0
#1 lore raw

PATCH v3 1/9 ARM: bcm283x: Add bcm2712 PCIe memory window

From: Torsten Duwe <[email protected]>

Add a mapping region for the PCIe bus address spaces to the BCM2712 memory controller setup. Generously merging the PCIe address spaces works sufficiently well for a boot loader.

---
 arch/arm/mach-bcm283x/init.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
arch/arm/mach-bcm283x/init.c +9 -1
index 7a1de22e0ae..7a2faaa4de6 100644
@@ -18,7 +18,7 @@
 #ifdef CONFIG_ARM64
 #include <asm/armv8/mmu.h>
 
-#define MEM_MAP_MAX_ENTRIES (4)
+#define MEM_MAP_MAX_ENTRIES (5)
 
 static struct mm_region bcm283x_mem_map[MEM_MAP_MAX_ENTRIES] = {
 	{
@@ -83,6 +83,14 @@ static struct mm_region bcm2712_mem_map[MEM_MAP_MAX_ENTRIES] = {
 		.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
 			 PTE_BLOCK_NON_SHARE |
 			 PTE_BLOCK_PXN | PTE_BLOCK_UXN
+	}, {
+		/* Whole PCIe section */
+		.virt = 0x1800000000UL,
+		.phys = 0x1800000000UL,
+		.size = 0x0800000000UL,
+		.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
+			 PTE_BLOCK_NON_SHARE |
+			 PTE_BLOCK_PXN | PTE_BLOCK_UXN
 	}, {
 		/* SoC bus */
 		.virt = 0x107c000000UL,
Signature · 1 line
2.54.0
#2 lore raw

PATCH v3 2/9 pci: brcmstb: Fix PCIe bus numbers

In reply to Torsten Duwe

From: Andrea della Porta <[email protected]>

The linux kernel assigns a new domain for every Root Complex where bus numbering starts from 0 for each domain. U-Boot does not have domains and uses a flattened bus numbering scheme instead. This means that any device or bridge on the second enumerated RC will receive a bus number equal to the last assigned one +1. This bus number contributes to the address written into the index register, which will select the configuration space to be read. Compensate for this contribution by subtracting the base bus number.

---
 drivers/pci/pcie_brcmstb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pcie_brcmstb.c +1 -1
index f089c48f028..47c0802df23 100644
@@ -125,7 +125,7 @@ static int brcm_pcie_config_address(const struct udevice *dev, pci_dev_t bdf,
 				    uint offset, void **paddress)
 {
 	struct brcm_pcie *pcie = dev_get_priv(dev);
-	unsigned int pci_bus = PCI_BUS(bdf);
+	unsigned int pci_bus = PCI_BUS(bdf) - dev_seq(dev);
 	unsigned int pci_dev = PCI_DEV(bdf);
 	unsigned int pci_func = PCI_FUNC(bdf);
 	int idx;
Signature · 1 line
2.54.0
#3 lore raw

PATCH v3 3/9 pci: brcmstb: Support different variants using a cfg struct

In reply to Torsten Duwe

From: Torsten Duwe <[email protected]>

The Linux kernel driver already had support for multiple hardware variants when the bcm2712 was added (see e.g. linux commit 10dbedad3c818 which is the last in a longer set of changes). This patch brings in this required infrastructure and adds a differentiation between 2711 and 2712 register layouts on top. It also accounts for the bcm2712 reset logic quirk that the software init bit must not remain set, albeit the reset control location is only corrected in patch#6 of this series.

---
 .../mach-bcm283x/include/mach/acpi/bcm2711.h  |   6 +-
 drivers/pci/pcie_brcmstb.c                    | 122 ++++++++++++++++--
 2 files changed, 114 insertions(+), 14 deletions(-)
arch/arm/mach-bcm283x/include/mach/acpi/bcm2711.h +5 -1
index a86875b1833..6eb5389b858 100644
@@ -70,6 +70,7 @@
 #define PCIE_MISC_RC_BAR2_CONFIG_HI               0x4038
 #define PCIE_MISC_RC_BAR3_CONFIG_LO               0x403c
 #define  RC_BAR3_CONFIG_LO_SIZE_MASK                0x1f
+#define PCIE_MISC_PCIE_CTRL			  0x4064
 #define PCIE_MISC_PCIE_STATUS                     0x4068
 #define  STATUS_PCIE_PORT_MASK                      0x80
 #define  STATUS_PCIE_PORT_SHIFT                        7
@@ -107,7 +108,10 @@
 #define PCIE_MSI_INTR2_MASK_SET               0x4510
 
 #define PCIE_RGR1_SW_INIT_1                   0x9210
-#define PCIE_EXT_CFG_INDEX                    0x9000
+#define  RGR1_SW_INIT_1_PERST_MASK			0x1
+#define  RGR1_SW_INIT_1_PERSTB_MASK			0x4
+#define  RGR1_SW_INIT_1_INIT_MASK			0x2
+
 /* A small window pointing at the ECAM of the device selected by CFG_INDEX */
 #define PCIE_EXT_CFG_DATA                     0x8000
 
drivers/pci/pcie_brcmstb.c +109 -13

195 lines not on this page · raw message

Signature · 1 line
2.54.0
#4 lore raw

PATCH v3 4/9 reset: Add RPi5 brcmstb reset facilities

In reply to Torsten Duwe

From: Torsten Duwe <[email protected]>

A driver for Broadcom reset controllers ported from linux/drivers/reset/reset-brcmstb.c to U-Boot.

---
 configs/rpi_arm64_defconfig   |  1 +
 drivers/reset/Kconfig         |  8 +++
 drivers/reset/Makefile        |  1 +
 drivers/reset/reset-brcmstb.c | 97 +++++++++++++++++++++++++++++++++++
 4 files changed, 107 insertions(+)
 create mode 100644 drivers/reset/reset-brcmstb.c
configs/rpi_arm64_defconfig +1 -0
index 69e8e72c5d7..153d7ed301e 100644
@@ -44,6 +44,7 @@ CONFIG_BCMGENET=y
 CONFIG_PCI_BRCMSTB=y
 CONFIG_PINCTRL=y
 # CONFIG_PINCTRL_GENERIC is not set
+CONFIG_RESET_BRCMSTB=y
 CONFIG_DM_RNG=y
 CONFIG_RNG_IPROC200=y
 # CONFIG_REQUIRE_SERIAL_CONSOLE is not set
drivers/reset/Kconfig +8 -0
index ebf484d9df4..7f1b2a304e3 100644
@@ -64,6 +64,14 @@ config RESET_BCM6345
 	help
 	  Support reset controller on BCM6345.
 
+config RESET_BRCMSTB
+	depends on ARCH_BCM283X
+	bool "Generic Reset controller driver for Broadcom"
+	help
+	  This enables reset controller for Broadcom devices.
+	  If you wish to use reset resources managed by the Broadcom
+	  Reset Controller, say Y here. Otherwise, say N.
+
 config RESET_UNIPHIER
 	bool "Reset controller driver for UniPhier SoCs"
 	depends on ARCH_UNIPHIER
drivers/reset/Makefile +1 -0
index 088545c6473..ad5fe6b6184 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_RESET_AIROHA) += reset-airoha.o
 obj-$(CONFIG_RESET_TI_SCI) += reset-ti-sci.o
 obj-$(CONFIG_RESET_HSDK) += reset-hsdk.o
 obj-$(CONFIG_RESET_BCM6345) += reset-bcm6345.o
+obj-$(CONFIG_RESET_BRCMSTB) += reset-brcmstb.o
 obj-$(CONFIG_RESET_UNIPHIER) += reset-uniphier.o
 obj-$(CONFIG_RESET_AST2500) += reset-ast2500.o
 obj-$(CONFIG_RESET_AST2600) += reset-ast2600.o
drivers/reset/reset-brcmstb.c new file +97 -0

97 lines not on this page · raw message

Signature · 1 line
2.54.0
#5 lore raw

PATCH v3 5/9 reset: Add RPi5 rescal reset facilities

In reply to Torsten Duwe

From: Torsten Duwe <[email protected]>

A driver for Broadcom rescal reset controllers ported from linux/drivers/reset/reset-brcmstb-rescal.c to U-Boot.

---
 configs/rpi_arm64_defconfig          |   1 +
 drivers/reset/Kconfig                |   8 +++
 drivers/reset/Makefile               |   1 +
 drivers/reset/reset-brcmstb-rescal.c | 103 +++++++++++++++++++++++++++
 4 files changed, 113 insertions(+)
 create mode 100644 drivers/reset/reset-brcmstb-rescal.c
configs/rpi_arm64_defconfig +1 -0
index 153d7ed301e..38af5029403 100644
@@ -45,6 +45,7 @@ CONFIG_PCI_BRCMSTB=y
 CONFIG_PINCTRL=y
 # CONFIG_PINCTRL_GENERIC is not set
 CONFIG_RESET_BRCMSTB=y
+CONFIG_RESET_BRCMSTB_RESCAL=y
 CONFIG_DM_RNG=y
 CONFIG_RNG_IPROC200=y
 # CONFIG_REQUIRE_SERIAL_CONSOLE is not set
drivers/reset/Kconfig +8 -0
index 7f1b2a304e3..485f907b041 100644
@@ -72,6 +72,14 @@ config RESET_BRCMSTB
 	  If you wish to use reset resources managed by the Broadcom
 	  Reset Controller, say Y here. Otherwise, say N.
 
+config RESET_BRCMSTB_RESCAL
+	depends on ARCH_BCM283X
+	bool "Generic Rescal Reset controller driver for Broadcom"
+	help
+	  Support rescal reset controller on Broadcom.
+	  If you wish to use reset resources managed by the Broadcom
+	  Reset Controller, say Y here. Otherwise, say N.
+
 config RESET_UNIPHIER
 	bool "Reset controller driver for UniPhier SoCs"
 	depends on ARCH_UNIPHIER
drivers/reset/Makefile +1 -0
index ad5fe6b6184..c369bdb3d6c 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_RESET_TI_SCI) += reset-ti-sci.o
 obj-$(CONFIG_RESET_HSDK) += reset-hsdk.o
 obj-$(CONFIG_RESET_BCM6345) += reset-bcm6345.o
 obj-$(CONFIG_RESET_BRCMSTB) += reset-brcmstb.o
+obj-$(CONFIG_RESET_BRCMSTB_RESCAL) += reset-brcmstb-rescal.o
 obj-$(CONFIG_RESET_UNIPHIER) += reset-uniphier.o
 obj-$(CONFIG_RESET_AST2500) += reset-ast2500.o
 obj-$(CONFIG_RESET_AST2600) += reset-ast2600.o
drivers/reset/reset-brcmstb-rescal.c new file +103 -0

103 lines not on this page · raw message

Signature · 1 line
2.54.0
#6 lore raw

PATCH v3 6/9 pci: brcmstb: Get and use bridge and rescal reset properties

In reply to Torsten Duwe

From: Torsten Duwe <[email protected]>

Check whether the device tree has nodes for the two reset controls and use them if so.

---
 drivers/pci/pcie_brcmstb.c | 51 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)
drivers/pci/pcie_brcmstb.c +50 -1
index 261f8790528..1f97cda5cc7 100644
@@ -21,6 +21,7 @@
 #include <linux/bitfield.h>
 #include <linux/log2.h>
 #include <linux/iopoll.h>
+#include <reset.h>
 
 /* PCIe parameters */
 #define BRCM_NUM_PCIE_OUT_WINS				4
@@ -83,6 +84,8 @@ struct brcm_pcie {
 
 	int			gen;
 	bool			ssc;
+	struct reset_ctl	rescal;
+	struct reset_ctl	bridge_reset;
 	const struct brcm_pcie_cfg_data *pcie_cfg;
 };
 
@@ -147,6 +150,34 @@ static void brcm_pcie_perst_set_2712(struct brcm_pcie *pcie, u32 val)
 	writel(tmp, pcie->base + PCIE_MISC_PCIE_CTRL);
 }
 
+static void brcm_pcie_get_resets_dt(struct udevice *dev)
+{
+	struct brcm_pcie *pcie = dev_get_priv(dev);
+	int ret;
+
+	ret = reset_get_by_name(dev, "rescal", &pcie->rescal);
+	if (ret) {
+		printf("Unable to get rescal reset\n");
+		return;
+	}
+
+	ret = reset_get_by_name(dev, "bridge", &pcie->bridge_reset);
+	if (ret) {
+		printf("Unable to get bridge reset\n");
+		return;
+	}
+}
+
+static void brcm_pcie_do_reset(struct udevice *dev)
+{
+	struct brcm_pcie *pcie = dev_get_priv(dev);
+	int ret;
+
+	ret = reset_deassert(&pcie->rescal);
+	if (ret)
+		printf("failed to deassert 'rescal'\n");
+}
+
 static void brcm_pcie_bridge_sw_init_set_generic(struct brcm_pcie *pcie, u32 val)
 {
 	if (val)
@@ -157,6 +188,14 @@ static void brcm_pcie_bridge_sw_init_set_generic(struct brcm_pcie *pcie, u32 val
 			     RGR1_SW_INIT_1_INIT_MASK);
 }
 
+static void brcm_pcie_bridge_sw_init_set_2712(struct brcm_pcie *pcie, u32 val)
+{
+	if (val)
+		reset_assert(&pcie->bridge_reset);
+	else
+		reset_deassert(&pcie->bridge_reset);
+}
+
 /**
  * brcm_pcie_link_up() - Check whether the PCIe link is up
  * @pcie: Pointer to the PCIe controller state
@@ -413,6 +452,12 @@ static int brcm_pcie_probe(struct udevice *dev)
 	u16 nlw, cls, lnksta;
 	u32 tmp;
 
+	/*
+	 * Ensure rescal reset for BCM2712 is really disabled.
+	 */
+	if (pcie->pcie_cfg->type == BCM2712)
+		brcm_pcie_do_reset(dev);
+
 	/*
 	 * Reset the bridge, assert the fundamental reset. Note for some SoCs,
 	 * e.g. BCM7278, the fundamental reset should not be asserted here.
@@ -611,6 +656,10 @@ static int brcm_pcie_of_to_plat(struct udevice *dev)
 		pcie->gen = max_link_speed;
 
 	pcie->pcie_cfg = (const struct brcm_pcie_cfg_data *)dev_get_driver_data(dev);
+
+	if (pcie->pcie_cfg->type == BCM2712)
+		brcm_pcie_get_resets_dt(dev);
+
 	return 0;
 }
 
@@ -645,7 +694,7 @@ static const struct brcm_pcie_cfg_data bcm2712_cfg = {
 	.offsets	= pcie_offsets_bcm2712,
 	.type		= BCM2712,
 	.perst_set	= brcm_pcie_perst_set_2712,
-	.bridge_sw_init_set = brcm_pcie_bridge_sw_init_set_generic,
+	.bridge_sw_init_set = brcm_pcie_bridge_sw_init_set_2712,
 	.rc_mode	= brcm_pcie_rc_mode,
 };
 
Signature · 1 line
2.54.0
#7 lore raw

PATCH v3 7/9 pci: brcmstb: Fix iBAR size calculation

In reply to Torsten Duwe

From: Torsten Duwe <[email protected]>

Fix inbound window size calculation, like Linux commit 25a98c7270156.

---
 drivers/pci/pcie_brcmstb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/pcie_brcmstb.c +2 -2
index 1f97cda5cc7..8a25fb04563 100644
@@ -105,8 +105,8 @@ static int brcm_pcie_encode_ibar_size(u64 size)
 	if (log2_in >= 12 && log2_in <= 15)
 		/* Covers 4KB to 32KB (inclusive) */
 		return (log2_in - 12) + 0x1c;
-	else if (log2_in >= 16 && log2_in <= 37)
-		/* Covers 64KB to 32GB, (inclusive) */
+	else if (log2_in >= 16 && log2_in <= 36)
+		/* Covers 64KB to 64GB, (inclusive) */
 		return log2_in - 15;
 
 	/* Something is awry so disable */
Signature · 1 line
2.54.0
#8 lore raw

PATCH v3 8/9 pci: brcmstb: rework iBAR handling

In reply to Torsten Duwe

From: Torsten Duwe <[email protected]>

Rework the setup of inbound PCIe windows: use the convenience functions from Linux kernel commit ae6476c6de187 to calculate the BAR offsets and factor out the setup code into a separate function.

The Linux kernel first allocates and populates an array of inbound_win[] and sets the BARs from it later, while U-Boot does it all on the fly, in one go, so the code is not 1:1 comparable.

---
 drivers/pci/pcie_brcmstb.c | 150 ++++++++++++++++++++++++++++++++-----
 1 file changed, 131 insertions(+), 19 deletions(-)
drivers/pci/pcie_brcmstb.c +131 -19
index 8a25fb04563..05b80a45b50 100644
@@ -50,6 +50,29 @@
 #define SSC_STATUS_PLL_LOCK_MASK			0x800
 #define SSC_STATUS_PLL_LOCK_SHIFT			11
 
+#define PCIE_RC_PL_PHY_CTL_15				0x184c
+#define PCIE_RC_PL_PHY_CTL_15_DIS_PLL_PD_MASK		0x400000
+#define PCIE_RC_PL_PHY_CTL_15_PM_CLK_PERIOD_MASK	0xff
+
+#define PCIE_MISC_UBUS_CTRL				0x40a4
+#define  PCIE_MISC_UBUS_CTRL_UBUS_PCIE_REPLY_ERR_DIS_MASK	BIT(13)
+#define  PCIE_MISC_UBUS_CTRL_UBUS_PCIE_REPLY_DECERR_DIS_MASK	BIT(19)
+#define PCIE_MISC_AXI_READ_ERROR_DATA			0x4170
+#define PCIE_MISC_UBUS_TIMEOUT				0x40A8
+#define PCIE_MISC_RC_CONFIG_RETRY_TIMEOUT		0x405c
+#define PCIE_MISC_RC_BAR4_CONFIG_LO			0x40d4
+#define PCIE_MISC_RC_BAR4_CONFIG_HI			0x40d8
+#define PCIE_MISC_UBUS_BAR_CONFIG_REMAP_HI_MASK		0xff
+#define PCIE_MISC_UBUS_BAR4_CONFIG_REMAP_HI		0x4110
+#define PCIE_MISC_UBUS_BAR_CONFIG_REMAP_ENABLE		0x1
+#define PCIE_MISC_UBUS_BAR_CONFIG_REMAP_LO_MASK		0xfffff000
+#define PCIE_MISC_UBUS_BAR4_CONFIG_REMAP_LO		0x410c
+
+#define PCIE_MISC_UBUS_BAR1_CONFIG_REMAP		0x40ac
+#define PCIE_MISC_UBUS_BAR2_CONFIG_REMAP		0x40b4
+#define  PCIE_MISC_UBUS_BAR2_CONFIG_REMAP_ACCESS_ENABLE_MASK	BIT(0)
+#define  MISC_CTRL_PCIE_RCB_MPS_MODE_MASK		0x400
+
 enum {
 	RGR1_SW_INIT_1,
 	EXT_CFG_INDEX,
@@ -437,17 +460,105 @@ static void brcm_pcie_set_outbound_win(struct brcm_pcie *pcie,
 	writel(tmp, base + PCIE_MEM_WIN0_LIMIT_HI(win));
 }
 
+static u32 brcm_bar_reg_offset(int bar)
+{
+	if (bar <= 3)
+		return PCIE_MISC_RC_BAR1_CONFIG_LO + 8 * (bar - 1);
+	else
+		return PCIE_MISC_RC_BAR4_CONFIG_LO + 8 * (bar - 4);
+}
+
+static u32 brcm_ubus_reg_offset(int bar)
+{
+	if (bar <= 3)
+		return PCIE_MISC_UBUS_BAR1_CONFIG_REMAP + 8 * (bar - 1);
+	else
+		return PCIE_MISC_UBUS_BAR4_CONFIG_REMAP_LO + 8 * (bar - 4);
+}
+
+/*
+ * Round size up to the next power of two, as required by
+ * brcm_pcie_encode_ibar_size().  If size is already a power of two
+ * fls64(size - 1) still gives the correct result because the hardware
+ * encodes the exponent, not the raw value.
+ */
+static u64 brcm_ibar_round_size(u64 size)
+{
+	return 1ULL << fls64(size - 1);
+}
+
+static void brcm_pcie_set_inbound_windows(struct udevice *dev)
+{
+	struct brcm_pcie *pcie = dev_get_priv(dev);
+	void __iomem *base = pcie->base;
+	bool is_2712 = (pcie->pcie_cfg->type == BCM2712);
+	int i, ibar_no, ret;
+	u32 tmp;
+
+	ibar_no = 0;
+	/* pre-2712 chips leave the first entry empty */
+	if (pcie->pcie_cfg->type != BCM2712)
+		ibar_no++;
+
+	/* program inbound windows from OF property "dma-regions" */
+	for (i = 0; i < 7; i++, ibar_no++) {
+		u64 bar_cpu, bar_size, bar_pci;
+		struct pci_region region;
+		int ubus_bar_offset, rc_bar_offset;
+
+		ret = pci_get_dma_regions(dev, &region, i);
+		if (ret)	/* no region #i? Then we're done. */
+			break;
+		ubus_bar_offset = brcm_ubus_reg_offset(ibar_no + 1);
+		rc_bar_offset = brcm_bar_reg_offset(ibar_no + 1);
+
+		bar_pci = region.bus_start;
+		bar_cpu = region.phys_start;
+		bar_size = region.size;
+
+		if (is_2712) {
+			/* BCM2712: BAR holds raw PCI address; UBUS remap
+			 * registers supply the CPU-side translation. */
+			tmp = lower_32_bits(bar_pci);
+			u32p_replace_bits(&tmp, brcm_pcie_encode_ibar_size(bar_size),
+					  RC_BAR2_CONFIG_LO_SIZE_MASK);
+			writel(tmp, base + rc_bar_offset);
+			writel(upper_32_bits(bar_pci), base + rc_bar_offset + 4);
+
+			tmp = lower_32_bits(bar_cpu) &
+					PCIE_MISC_UBUS_BAR_CONFIG_REMAP_LO_MASK;
+			tmp |= PCIE_MISC_UBUS_BAR_CONFIG_REMAP_ENABLE;
+			writel(tmp, base + ubus_bar_offset);
+
+			tmp = upper_32_bits(bar_cpu) &
+				PCIE_MISC_UBUS_BAR_CONFIG_REMAP_HI_MASK;
+			writel(tmp, base + ubus_bar_offset + 4);
+		} else {
+			/* Pre-BCM2712 (e.g. BCM2711 / RPi4): the BAR config
+			 * register holds the offset (bus_start - phys_start),
+			 * not the raw PCI address.  The size must be rounded
+			 * up to the next power of two before encoding. */
+			u64 bar_offset = bar_pci - bar_cpu;
+			u64 bar_size_po2 = brcm_ibar_round_size(bar_size);
+
+			tmp = lower_32_bits(bar_offset);
+			u32p_replace_bits(&tmp, brcm_pcie_encode_ibar_size(bar_size_po2),
+					  RC_BAR2_CONFIG_LO_SIZE_MASK);
+			writel(tmp, base + rc_bar_offset);
+			writel(upper_32_bits(bar_offset), base + rc_bar_offset + 4);
+			/* UBUS remap registers are not used on pre-2712 hardware. */
+		}
+	}
+}
+
 static int brcm_pcie_probe(struct udevice *dev)
 {
 	struct udevice *ctlr = pci_get_controller(dev);
 	struct pci_controller *hose = dev_get_uclass_priv(ctlr);
 	struct brcm_pcie *pcie = dev_get_priv(dev);
 	void __iomem *base = pcie->base;
-	struct pci_region region;
 	bool ssc_good = false;
 	int num_out_wins = 0;
-	u64 rc_bar2_offset, rc_bar2_size;
-	unsigned int scb_size_val;
 	int i, ret;
 	u16 nlw, cls, lnksta;
 	u32 tmp;
@@ -488,23 +599,22 @@ static int brcm_pcie_probe(struct udevice *dev)
 			MISC_CTRL_CFG_READ_UR_MODE_MASK |
 			MISC_CTRL_MAX_BURST_SIZE_128);
 
-	pci_get_dma_regions(dev, &region, 0);
-	rc_bar2_offset = region.bus_start - region.phys_start;
-	rc_bar2_size = 1ULL << fls64(region.size - 1);
-
-	tmp = lower_32_bits(rc_bar2_offset);
-	u32p_replace_bits(&tmp, brcm_pcie_encode_ibar_size(rc_bar2_size),
-			  RC_BAR2_CONFIG_LO_SIZE_MASK);
-	writel(tmp, base + PCIE_MISC_RC_BAR2_CONFIG_LO);
-	writel(upper_32_bits(rc_bar2_offset),
-	       base + PCIE_MISC_RC_BAR2_CONFIG_HI);
-
-	scb_size_val = rc_bar2_size ?
-		       ilog2(rc_bar2_size) - 15 : 0xf; /* 0xf is 1GB */
-
 	tmp = readl(base + PCIE_MISC_MISC_CTRL);
-	u32p_replace_bits(&tmp, scb_size_val,
-			  MISC_CTRL_SCB0_SIZE_MASK);
+	if (pcie->pcie_cfg->type == BCM2712) {
+		/* BCM2712: fixed 32GB SCB0 window */
+		u32p_replace_bits(&tmp, 20, MISC_CTRL_SCB0_SIZE_MASK);
+	} else {
+		/* Pre-BCM2712: size SCB0 to match the actual DMA region.
+		 * rc_bar2_size must be a power of two; ilog2(size) - 15
+		 * gives the hardware encoding (e.g. 1GB -> 15). */
+		struct pci_region region;
+		u64 rc_bar2_size;
+
+		pci_get_dma_regions(dev, &region, 0);
+		rc_bar2_size = brcm_ibar_round_size(region.size);
+		u32p_replace_bits(&tmp, rc_bar2_size ? ilog2(rc_bar2_size) - 15 : 0xf,
+				  MISC_CTRL_SCB0_SIZE_MASK);
+	}
 	writel(tmp, base + PCIE_MISC_MISC_CTRL);
 
 	/* Disable the PCIe->GISB memory window (RC_BAR1) */
@@ -521,6 +631,8 @@ static int brcm_pcie_probe(struct udevice *dev)
 	/* Clear any interrupts we find on boot */
 	writel(0xffffffff, base + PCIE_MSI_INTR2_CLR);
 
+	brcm_pcie_set_inbound_windows(dev);
+
 	if (pcie->gen)
 		brcm_pcie_set_gen(pcie, pcie->gen);
 
Signature · 1 line
2.54.0
#9 lore raw

PATCH v3 9/9 pci: brcmstb: Adapt to AXI bridge

In reply to Torsten Duwe

From: Torsten Duwe <[email protected]>

Fix-ups for the BCM root complex when it is located behind an AXI bridge and clocked with 54MHz. Some are from kernel commit 377bced88c326, some where picked by Oleksii off a now-stale older branch. All reworked for the simpler setup code in U-Boot.

---
 .../mach-bcm283x/include/mach/acpi/bcm2711.h  |  1 +
 drivers/pci/pcie_brcmstb.c                    | 64 ++++++++++++++++++-
 2 files changed, 64 insertions(+), 1 deletion(-)
arch/arm/mach-bcm283x/include/mach/acpi/bcm2711.h +1 -0
index 6eb5389b858..869482eaffe 100644
@@ -54,6 +54,7 @@
 #define  MISC_CTRL_CFG_READ_UR_MODE_MASK          0x2000
 #define  MISC_CTRL_MAX_BURST_SIZE_MASK            0x300000
 #define  MISC_CTRL_MAX_BURST_SIZE_128             0x0
+#define  MISC_CTRL_MAX_BURST_SIZE_128_2712		0x100000
 #define  MISC_CTRL_SCB0_SIZE_MASK                 0xf8000000
 
 #define PCIE_MISC_CPU_2_PCIE_MEM_WIN0_LO          0x400c
drivers/pci/pcie_brcmstb.c +63 -1

87 lines not on this page · raw message

Signature · 1 line
2.54.0
#10 lore raw
In reply to Torsten Duwe
Quoted 8 lines · Torsten Duwe

Basic PCIe support for the RPi5. This is the prerequisite for PCIe slot adapters / HATs and NVMe storage. Those might require their own supporting drivers or changes.

Changes from v2:
- fix wrong subject prefixes
- make reset drivers only found on the RPi5 depend on ARCH_BCM283X
- some patches Reviewed-by Peter Robinson

It seems you completely ignored by comments and review on v2:
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/#t
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/

Thanks,
Neil

Quoted 30 lines

Changes from v1:
- fixed inbound window rewrite, which broke RPi4
- series Tested-by Pedro Falcato

Andrea della Porta (1):
pci: brcmstb: Fix PCIe bus numbers

Torsten Duwe (8):
ARM: bcm283x: Add bcm2712 PCIe memory window
pci: brcmstb: Support different variants using a cfg struct
reset: Add RPi5 brcmstb reset facilities
reset: Add RPi5 rescal reset facilities
pci: brcmstb: Get and use bridge and rescal reset properties
pci: brcmstb: Fix iBAR size calculation
pci: brcmstb: rework iBAR handling
pci: brcmstb: Adapt to AXI bridge

  .../mach-bcm283x/include/mach/acpi/bcm2711.h  |   7 +-
  arch/arm/mach-bcm283x/init.c                  |  10 +-
  configs/rpi_arm64_defconfig                   |   2 +
  drivers/pci/pcie_brcmstb.c                    | 391 ++++++++++++++++--
  drivers/reset/Kconfig                         |  16 +
  drivers/reset/Makefile                        |   2 +
  drivers/reset/reset-brcmstb-rescal.c          | 103 +++++
  drivers/reset/reset-brcmstb.c                 |  97 +++++
  8 files changed, 590 insertions(+), 38 deletions(-)

create mode 100644 drivers/reset/reset-brcmstb-rescal.c create mode 100644 drivers/reset/reset-brcmstb.c

#11 lore raw

Hi Torsten,

I've set this version to Changes Requested to take into account Neil's review from v2.

Cheers,
Peter

Quoted 51 lines · Neil Armstrong
Quoted 8 lines · Torsten Duwe

Basic PCIe support for the RPi5. This is the prerequisite for PCIe slot adapters / HATs and NVMe storage. Those might require their own supporting drivers or changes.

Changes from v2:
- fix wrong subject prefixes
- make reset drivers only found on the RPi5 depend on ARCH_BCM283X
- some patches Reviewed-by Peter Robinson

It seems you completely ignored by comments and review on v2:
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/#t
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/

Thanks,
Neil

Quoted 30 lines

Changes from v1:
- fixed inbound window rewrite, which broke RPi4
- series Tested-by Pedro Falcato

Andrea della Porta (1):
pci: brcmstb: Fix PCIe bus numbers

Torsten Duwe (8):
ARM: bcm283x: Add bcm2712 PCIe memory window
pci: brcmstb: Support different variants using a cfg struct
reset: Add RPi5 brcmstb reset facilities
reset: Add RPi5 rescal reset facilities
pci: brcmstb: Get and use bridge and rescal reset properties
pci: brcmstb: Fix iBAR size calculation
pci: brcmstb: rework iBAR handling
pci: brcmstb: Adapt to AXI bridge

  .../mach-bcm283x/include/mach/acpi/bcm2711.h  |   7 +-
  arch/arm/mach-bcm283x/init.c                  |  10 +-
  configs/rpi_arm64_defconfig                   |   2 +
  drivers/pci/pcie_brcmstb.c                    | 391 ++++++++++++++++--
  drivers/reset/Kconfig                         |  16 +
  drivers/reset/Makefile                        |   2 +
  drivers/reset/reset-brcmstb-rescal.c          | 103 +++++
  drivers/reset/reset-brcmstb.c                 |  97 +++++
  8 files changed, 590 insertions(+), 38 deletions(-)

create mode 100644 drivers/reset/reset-brcmstb-rescal.c create mode 100644 drivers/reset/reset-brcmstb.c

#12 lore raw
In reply to Neil Armstrong
Quoted 11 lines · On Mon, 18 May 2026 10:02:04 +0200 Neil Armstrong <[email protected]>…
Quoted 9 lines · Torsten Duwe

Basic PCIe support for the RPi5. This is the prerequisite for PCIe slot adapters / HATs and NVMe storage. Those might require their own supporting drivers or changes.

Changes from v2:
- fix wrong subject prefixes
- make reset drivers only found on the RPi5 depend on
ARCH_BCM283X
- some patches Reviewed-by Peter Robinson

Quoted 6 lines

It seems you completely ignored by comments and review on v2:
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/#t
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/

You're very well right. I kept actively checking the list for about a week after my submission, and haven't checked again before v3, apologies.

V4 including your feedback is coming...

Torsten