Skip to contentSkip to conversation

Raspberry Pi 4 PCIe support

PATCH Applied Nicolas Saenz Julienne 5 participants 22 messages Dec 16, 2019 – Jan 16, 2020

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v5 cover Raspberry Pi 4 PCIe support

This series aims at providing support for Raspberry Pi 4's PCIe controller, which is also shared with the Broadcom STB family of devices.

There was a previous attempt to upstream this some years ago[1] but was blocked as most STB PCIe integrations have a sparse DMA mapping[2] which is something currently not supported by the kernel. Luckily this is not the case for the Raspberry Pi 4.

Note the series is based on top of linux next, as the DTS patch depends on it.

[1] https://patchwork.kernel.org/cover/10605933/
[2] https://patchwork.kernel.org/patch/10605957/

---

Changes since v4:
- Rebase DTS patch
- Respin log2.h code into it's own series as it's still contentious yet mostly unrelated to the PCIe part

Changes since v3:
- Moved all the log2.h related changes at the end of the series, as I presume they will be contentious and I don't want the PCIe patches to depend on them. Ultimately I think I'll respin them on their own series but wanted to keep them in for this submission just for the sake of continuity.
- Addressed small nits here and there.

Changes since v2:
- Redo register access in driver avoiding indirection while keeping the naming intact
- Add patch editing ARM64's config
- Last MSI cleanups, notably removing MSIX flag
- Got rid of all _RB writes
- Got rid of all of_data
- Overall churn removal
- Address the rest of Andrew's comments

Changes since v1:
- add generic rounddown/roundup_pow_two64() patch
- Add MAINTAINERS patch
- Fix Kconfig
- Cleanup probe, use up to date APIs, exit on MSI failure
- Get rid of linux,pci-domain and other unused constructs
- Use edge triggered setup for MSI
- Cleanup MSI implementation
- Fix multiple cosmetic issues
- Remove supend/resume code

Jim Quinlan (3):
dt-bindings: PCI: Add bindings for brcmstb's PCIe device
PCI: brcmstb: Add Broadcom STB PCIe host controller driver
PCI: brcmstb: Add MSI support

Nicolas Saenz Julienne (3):
ARM: dts: bcm2711: Enable PCIe controller
MAINTAINERS: Add brcmstb PCIe controller
arm64: defconfig: Enable Broadcom's STB PCIe controller

 .../bindings/pci/brcm,stb-pcie.yaml           |   97 ++
 MAINTAINERS                                   |    4 +
 arch/arm/boot/dts/bcm2711.dtsi                |   31 +-
 arch/arm64/configs/defconfig                  |    1 +
 drivers/pci/controller/Kconfig                |    9 +
 drivers/pci/controller/Makefile               |    1 +
 drivers/pci/controller/pcie-brcmstb.c         | 1007 +++++++++++++++++
 7 files changed, 1149 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml
 create mode 100644 drivers/pci/controller/pcie-brcmstb.c
Signature · 1 line
2.24.0
#1 lore raw

PATCH v5 1/6 dt-bindings: PCI: Add bindings for brcmstb's PCIe device

From: Jim Quinlan <[email protected]>

The DT bindings description of the brcmstb PCIe device is described. This node can only be used for now on the Raspberry Pi 4.

---

Changes since v2:
- Add pci reference schema
- Drop all default properties
- Assume msi-controller and msi-parent are properly defined
- Add num entries on multiple properties
- use unevaluatedProperties
- Update required properties
- Fix license

Changes since v1:
- Fix commit Subject
- Remove linux,pci-domain

This was based on Jim's original submission[1], converted to yaml and adapted to the RPi4 case.

[1] https://patchwork.kernel.org/patch/10605937/

 .../bindings/pci/brcm,stb-pcie.yaml           | 97 +++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml
Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml new file +97 -0
new file mode 100644
index 000000000000..77d3e81a437b
@@ -0,0 +1,97 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/brcm,stb-pcie.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Brcmstb PCIe Host Controller Device Tree Bindings
+
+maintainers:
+  - Nicolas Saenz Julienne <[email protected]>
+
+allOf:
+  - $ref: /schemas/pci/pci-bus.yaml#
+
+properties:
+  compatible:
+    const: brcm,bcm2711-pcie # The Raspberry Pi 4
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    minItems: 1
+    maxItems: 2
+    items:
+      - description: PCIe host controller
+      - description: builtin MSI controller
+
+  interrupt-names:
+    minItems: 1
+    maxItems: 2
+    items:
+      - const: pcie
+      - const: msi
+
+  ranges:
+    maxItems: 1
+
+  dma-ranges:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: sw_pcie
+
+  msi-controller:
+    description: Identifies the node as an MSI controller.
+
+  msi-parent:
+    description: MSI controller the device is capable of using.
+
+  brcm,enable-ssc:
+    description: Indicates usage of spread-spectrum clocking.
+    type: boolean
+
+required:
+  - reg
+  - dma-ranges
+  - "#interrupt-cells"
+  - interrupts
+  - interrupt-names
+  - interrupt-map-mask
+  - interrupt-map
+  - msi-controller
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    scb {
+            #address-cells = <2>;
+            #size-cells = <1>;
+            pcie0: pcie@7d500000 {
+                    compatible = "brcm,bcm2711-pcie";
+                    reg = <0x0 0x7d500000 0x9310>;
+                    device_type = "pci";
+                    #address-cells = <3>;
+                    #size-cells = <2>;
+                    #interrupt-cells = <1>;
+                    interrupts = <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>,
+                                 <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
+                    interrupt-names = "pcie", "msi";
+                    interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+                    interrupt-map = <0 0 0 1 &gicv2 GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH>;
+                    msi-parent = <&pcie0>;
+                    msi-controller;
+                    ranges = <0x02000000 0x0 0xf8000000 0x6 0x00000000 0x0 0x04000000>;
+                    dma-ranges = <0x02000000 0x0 0x00000000 0x0 0x00000000 0x0 0x80000000>;
+                    brcm,enable-ssc;
+            };
+    };
Signature · 1 line
2.24.0
#2 lore raw

Re: [PATCH v5 1/6] dt-bindings: PCI: Add bindings for brcmstb's PCIe device

Quoted 81 lines · Nicolas Saenz Julienne

From: Jim Quinlan <[email protected]>

The DT bindings description of the brcmstb PCIe device is described. This node can only be used for now on the Raspberry Pi 4.

---

Changes since v2:
- Add pci reference schema
- Drop all default properties
- Assume msi-controller and msi-parent are properly defined
- Add num entries on multiple properties
- use unevaluatedProperties
- Update required properties
- Fix license

Changes since v1:
- Fix commit Subject
- Remove linux,pci-domain

This was based on Jim's original submission[1], converted to yaml and adapted to the RPi4 case.

[1] https://patchwork.kernel.org/patch/10605937/

 .../bindings/pci/brcm,stb-pcie.yaml           | 97 +++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml
Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml new file +40 -0
new file mode 100644
index 000000000000..77d3e81a437b
@@ -0,0 +1,97 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/brcm,stb-pcie.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Brcmstb PCIe Host Controller Device Tree Bindings
+
+maintainers:
+  - Nicolas Saenz Julienne <[email protected]>
+
+allOf:
+  - $ref: /schemas/pci/pci-bus.yaml#
+
+properties:
+  compatible:
+    const: brcm,bcm2711-pcie # The Raspberry Pi 4
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    minItems: 1
+    maxItems: 2
+    items:
+      - description: PCIe host controller
+      - description: builtin MSI controller
+
+  interrupt-names:
+    minItems: 1
+    maxItems: 2
+    items:
+      - const: pcie
+      - const: msi
+
+  ranges:
+    maxItems: 1
+
+  dma-ranges:
+    maxItems: 1

Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml line 50

Quoted 10 lines
Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml new file +10 -0
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: sw_pcie
+
+  msi-controller:
+    description: Identifies the node as an MSI controller.

are you missing "type: boolean" here?

Regards,
Matthias

Quoted 48 lines
Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml new file +47 -0
+
+  msi-parent:
+    description: MSI controller the device is capable of using.
+
+  brcm,enable-ssc:
+    description: Indicates usage of spread-spectrum clocking.
+    type: boolean
+
+required:
+  - reg
+  - dma-ranges
+  - "#interrupt-cells"
+  - interrupts
+  - interrupt-names
+  - interrupt-map-mask
+  - interrupt-map
+  - msi-controller
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    scb {
+            #address-cells = <2>;
+            #size-cells = <1>;
+            pcie0: pcie@7d500000 {
+                    compatible = "brcm,bcm2711-pcie";
+                    reg = <0x0 0x7d500000 0x9310>;
+                    device_type = "pci";
+                    #address-cells = <3>;
+                    #size-cells = <2>;
+                    #interrupt-cells = <1>;
+                    interrupts = <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>,
+                                 <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
+                    interrupt-names = "pcie", "msi";
+                    interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+                    interrupt-map = <0 0 0 1 &gicv2 GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH>;
+                    msi-parent = <&pcie0>;
+                    msi-controller;
+                    ranges = <0x02000000 0x0 0xf8000000 0x6 0x00000000 0x0 0x04000000>;
+                    dma-ranges = <0x02000000 0x0 0x00000000 0x0 0x00000000 0x0 0x80000000>;
+                    brcm,enable-ssc;
+            };
+    };
#3 lore raw

Re: [PATCH v5 1/6] dt-bindings: PCI: Add bindings for brcmstb's PCIe device

Quoted 5 lines · Matthias Brugger

Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml line 50

Quoted 3 lines
Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml new file +3 -0
+
+  msi-controller:
+    description: Identifies the node as an MSI controller.

are you missing "type: boolean" here?

As per RobH's suggestion[1] I assumed the type on msi-controller and msi-parent is alredy defined.

Regards,
Nicolas

[1] https://patchwork.kernel.org/patch/11239717/#23008585

#4 lore raw

PATCH v5 2/6 ARM: dts: bcm2711: Enable PCIe controller

In reply to Nicolas Saenz Julienne

This enables bcm2711's PCIe bus, which is hardwired to a VIA Technologies XHCI USB 3.0 controller.

---

Changes since v4:
- Rebase commit taking into account genet support series

Changes since v3:
- Remove unwarranted comment

Changes since v2:
- Remove unused interrupt-map
- correct dma-ranges to it's full size, non power of 2 bus DMA constraints now supported in linux-next[1]
- add device_type
- rename alias from pcie_0 to pcie0

Changes since v1:
- remove linux,pci-domain

[1] https://lkml.org/lkml/2019/11/21/235

 arch/arm/boot/dts/bcm2711.dtsi | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
arch/arm/boot/dts/bcm2711.dtsi +30 -1
index e2f6ffb00aa9..b56388ce1216 100644
@@ -331,7 +331,36 @@ scb {
 		#address-cells = <2>;
 		#size-cells = <1>;
 
-		ranges = <0x0 0x7c000000  0x0 0xfc000000  0x03800000>;
+		ranges = <0x0 0x7c000000  0x0 0xfc000000  0x03800000>,
+			 <0x6 0x00000000  0x6 0x00000000  0x40000000>;
+
+		pcie0: pcie@7d500000 {
+			compatible = "brcm,bcm2711-pcie";
+			reg = <0x0 0x7d500000 0x9310>;
+			device_type = "pci";
+			#address-cells = <3>;
+			#interrupt-cells = <1>;
+			#size-cells = <2>;
+			interrupts = <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "pcie", "msi";
+			interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+			interrupt-map = <0 0 0 1 &gicv2 GIC_SPI 143
+							IRQ_TYPE_LEVEL_HIGH>;
+			msi-controller;
+			msi-parent = <&pcie0>;
+
+			ranges = <0x02000000 0x0 0xf8000000 0x6 0x00000000
+				  0x0 0x04000000>;
+			/*
+			 * The wrapper around the PCIe block has a bug
+			 * preventing it from accessing beyond the first 3GB of
+			 * memory.
+			 */
+			dma-ranges = <0x02000000 0x0 0x00000000 0x0 0x00000000
+				      0x0 0xc0000000>;
+			brcm,enable-ssc;
+		};
 
 		genet: ethernet@7d580000 {
 			compatible = "brcm,bcm2711-genet-v5";
Signature · 1 line
2.24.0
#5 lore raw

Re: [PATCH v5 2/6] ARM: dts: bcm2711: Enable PCIe controller

Quoted 20 lines · Nicolas Saenz Julienne

This enables bcm2711's PCIe bus, which is hardwired to a VIA Technologies XHCI USB 3.0 controller.

---

Changes since v4:
- Rebase commit taking into account genet support series

Changes since v3:
- Remove unwarranted comment

Changes since v2:
- Remove unused interrupt-map
- correct dma-ranges to it's full size, non power of 2 bus DMA constraints now supported in linux-next[1]
- add device_type
- rename alias from pcie_0 to pcie0

Quoted 7 lines

Changes since v1:
- remove linux,pci-domain

[1] https://lkml.org/lkml/2019/11/21/235

 arch/arm/boot/dts/bcm2711.dtsi | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

Olof as we discussed previously, I will not merge this dts change and drop it from the series - Nicolas should redirect it to arm-soc, please let me know if my understanding is correct.

Thanks,
Lorenzo

Quoted 45 lines
arch/arm/boot/dts/bcm2711.dtsi +30 -1
index e2f6ffb00aa9..b56388ce1216 100644
@@ -331,7 +331,36 @@ scb {
 		#address-cells = <2>;
 		#size-cells = <1>;
 
-		ranges = <0x0 0x7c000000  0x0 0xfc000000  0x03800000>;
+		ranges = <0x0 0x7c000000  0x0 0xfc000000  0x03800000>,
+			 <0x6 0x00000000  0x6 0x00000000  0x40000000>;
+
+		pcie0: pcie@7d500000 {
+			compatible = "brcm,bcm2711-pcie";
+			reg = <0x0 0x7d500000 0x9310>;
+			device_type = "pci";
+			#address-cells = <3>;
+			#interrupt-cells = <1>;
+			#size-cells = <2>;
+			interrupts = <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "pcie", "msi";
+			interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+			interrupt-map = <0 0 0 1 &gicv2 GIC_SPI 143
+							IRQ_TYPE_LEVEL_HIGH>;
+			msi-controller;
+			msi-parent = <&pcie0>;
+
+			ranges = <0x02000000 0x0 0xf8000000 0x6 0x00000000
+				  0x0 0x04000000>;
+			/*
+			 * The wrapper around the PCIe block has a bug
+			 * preventing it from accessing beyond the first 3GB of
+			 * memory.
+			 */
+			dma-ranges = <0x02000000 0x0 0x00000000 0x0 0x00000000
+				      0x0 0xc0000000>;
+			brcm,enable-ssc;
+		};
 
 		genet: ethernet@7d580000 {
 			compatible = "brcm,bcm2711-genet-v5";
Signature · 1 line
2.24.0
#6 lore raw

Re: [PATCH v5 2/6] ARM: dts: bcm2711: Enable PCIe controller

Quoted 24 lines · Lorenzo Pieralisi
Quoted 23 lines · Nicolas Saenz Julienne

This enables bcm2711's PCIe bus, which is hardwired to a VIA Technologies XHCI USB 3.0 controller.

---

Changes since v4:
- Rebase commit taking into account genet support series

Changes since v3:
- Remove unwarranted comment

Changes since v2:
- Remove unused interrupt-map
- correct dma-ranges to it's full size, non power of 2 bus DMA constraints now supported in linux-next[1]
- add device_type
- rename alias from pcie_0 to pcie0

Changes since v1:
- remove linux,pci-domain

Quoted 8 lines
Quoted 4 lines

[1] https://lkml.org/lkml/2019/11/21/235

 arch/arm/boot/dts/bcm2711.dtsi | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

Olof as we discussed previously, I will not merge this dts change and drop it from the series - Nicolas should redirect it to arm-soc, please let me know if my understanding is correct.

Correct, I will take patches 2, 5 and 6 through the Broadcom ARM SoC pull requests and you will take 1, 3 and 4.

Signature · 1 line
Florian
#8 lore raw

PATCH v5 3/6 PCI: brcmstb: Add Broadcom STB PCIe host controller driver

In reply to Nicolas Saenz Julienne

From: Jim Quinlan <[email protected]>

This adds a basic driver for Broadcom's STB PCIe controller, for now aimed at Raspberry Pi 4's SoC, bcm2711.

---

Changes since v3:
- Update commit message
- rollback roundup_pow_two usage, it'll be updated later down the line
- Remove comment in register definition

Changes since v2:
- Correct rc_bar2_offset sign
- Invert IRQ clear and masking in setup code
- Use bitfield.h, redo all register ops while keeping the register names intact
- Remove all SHIFT register definitions
- Get rid of all _RB writes
- Get rid of of_data
- Don't iterate over inexisting dma-ranges
- Add comment regarding dma-ranges validation
- Small cosmetic cleanups
- Fix license mismatch
- Set driver Kconfig tristate
- Didn't add any comment about the controller not being I/O coherent for now as I wait for Jeremy's reply

Changes since v1:
- Fix Kconfig
- Remove pci domain check
- Remove all MSI related code
- Remove supend/resume code
- Simplify link state wait routine
- Prefix all functions
- Use of_device_get_match_data()
- Use devm_clk_get_optional()
- Get rid of irq variable
- Use STB all over the driver
- Simplify map_bus() function
- Fix license mismatch
- Remove unused register definitions
- Small cleanups, spell errors

This is based on Jim's original submission[1] but adapted and tailored specifically to bcm2711's needs (that's the Raspberry Pi 4). Support for the rest of the brcmstb family will soon follow once we get support for multiple dma-ranges in dma/direct.

[1] https://patchwork.kernel.org/patch/10605959/

 drivers/pci/controller/Kconfig        |   8 +
 drivers/pci/controller/Makefile       |   1 +
 drivers/pci/controller/pcie-brcmstb.c | 748 ++++++++++++++++++++++++++
 3 files changed, 757 insertions(+)
 create mode 100644 drivers/pci/controller/pcie-brcmstb.c
drivers/pci/controller/Kconfig +8 -0
index c77069c8ee5d..27504f108ee5 100644
@@ -253,6 +253,14 @@ config VMD
 	  To compile this driver as a module, choose M here: the
 	  module will be called vmd.
 
+config PCIE_BRCMSTB
+	tristate "Broadcom Brcmstb PCIe host controller"
+	depends on ARCH_BCM2835 || COMPILE_TEST
+	depends on OF
+	help
+	  Say Y here to enable PCIe host controller support for
+	  Broadcom STB based SoCs, like the Raspberry Pi 4.
+
 config PCI_HYPERV_INTERFACE
 	tristate "Hyper-V PCI Interface"
 	depends on X86 && HYPERV && PCI_MSI && PCI_MSI_IRQ_DOMAIN && X86_64
drivers/pci/controller/Makefile +1 -0
index 3d4f597f15ce..01b2502a5323 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_PCIE_MEDIATEK) += pcie-mediatek.o
 obj-$(CONFIG_PCIE_MOBIVEIL) += pcie-mobiveil.o
 obj-$(CONFIG_PCIE_TANGO_SMP8759) += pcie-tango.o
 obj-$(CONFIG_VMD) += vmd.o
+obj-$(CONFIG_PCIE_BRCMSTB) += pcie-brcmstb.o
 # pcie-hisi.o quirks are needed even without CONFIG_PCIE_DW
 obj-y				+= dwc/
 
drivers/pci/controller/pcie-brcmstb.c new file +748 -0

748 lines not on this page · raw message

Signature · 1 line
2.24.0
#9 lore raw

Re: [PATCH v5 3/6] PCI: brcmstb: Add Broadcom STB PCIe host controller driver

Quoted 13 lines · Nicolas Saenz Julienne

From: Jim Quinlan <[email protected]>

This adds a basic driver for Broadcom's STB PCIe controller, for now aimed at Raspberry Pi 4's SoC, bcm2711.

---

Quoted 7 lines

Changes since v3:
- Update commit message
- rollback roundup_pow_two usage, it'll be updated later down the line
- Remove comment in register definition

Changes since v2:
- Correct rc_bar2_offset sign

In relation to this change.

[...]

drivers/pci/controller/pcie-brcmstb.c line 392

Quoted 13 lines
drivers/pci/controller/pcie-brcmstb.c new file +13 -0
+static inline int brcm_pcie_get_rc_bar2_size_and_offset(struct brcm_pcie *pcie,
+							u64 *rc_bar2_size,
+							u64 *rc_bar2_offset)
+{
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
+	struct device *dev = pcie->dev;
+	struct resource_entry *entry;
+
+	entry = resource_list_first_type(&bridge->dma_ranges, IORESOURCE_MEM);
+	if (!entry)
+		return -ENODEV;
+
+	*rc_bar2_offset = -entry->offset;

I think this deserves a comment - I guess it has to do with how the controller expects CPU<->PCI offsets to be expressed compared to how it is computed in dma_ranges entries.

I will try to complete the review shortly and try to apply it given that it has already been reviewed by others.

Lorenzo

Quoted 359 lines
drivers/pci/controller/pcie-brcmstb.c new file +356 -0
+	*rc_bar2_size = 1ULL << fls64(entry->res->end - entry->res->start);
+
+	/*
+	 * We validate the inbound memory view even though we should trust
+	 * whatever the device-tree provides. This is because of an HW issue on
+	 * early Raspberry Pi 4's revisions (bcm2711). It turns out its
+	 * firmware has to dynamically edit dma-ranges due to a bug on the
+	 * PCIe controller integration, which prohibits any access above the
+	 * lower 3GB of memory. Given this, we decided to keep the dma-ranges
+	 * in check, avoiding hard to debug device-tree related issues in the
+	 * future:
+	 *
+	 * The PCIe host controller by design must set the inbound viewport to
+	 * be a contiguous arrangement of all of the system's memory.  In
+	 * addition, its size mut be a power of two.  To further complicate
+	 * matters, the viewport must start on a pcie-address that is aligned
+	 * on a multiple of its size.  If a portion of the viewport does not
+	 * represent system memory -- e.g. 3GB of memory requires a 4GB
+	 * viewport -- we can map the outbound memory in or after 3GB and even
+	 * though the viewport will overlap the outbound memory the controller
+	 * will know to send outbound memory downstream and everything else
+	 * upstream.
+	 *
+	 * For example:
+	 *
+	 * - The best-case scenario, memory up to 3GB, is to place the inbound
+	 *   region in the first 4GB of pcie-space, as some legacy devices can
+	 *   only address 32bits. We would also like to put the MSI under 4GB
+	 *   as well, since some devices require a 32bit MSI target address.
+	 *
+	 * - If the system memory is 4GB or larger we cannot start the inbound
+	 *   region at location 0 (since we have to allow some space for
+	 *   outbound memory @ 3GB). So instead it will  start at the 1x
+	 *   multiple of its size
+	 */
+	if (!*rc_bar2_size || *rc_bar2_offset % *rc_bar2_size ||
+	    (*rc_bar2_offset < SZ_4G && *rc_bar2_offset > SZ_2G)) {
+		dev_err(dev, "Invalid rc_bar2_offset/size: size 0x%llx, off 0x%llx\n",
+			*rc_bar2_size, *rc_bar2_offset);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int brcm_pcie_setup(struct brcm_pcie *pcie)
+{
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
+	u64 rc_bar2_offset, rc_bar2_size;
+	void __iomem *base = pcie->base;
+	struct device *dev = pcie->dev;
+	struct resource_entry *entry;
+	unsigned int scb_size_val;
+	bool ssc_good = false;
+	struct resource *res;
+	int num_out_wins = 0;
+	u16 nlw, cls, lnksta;
+	int i, ret;
+	u32 tmp;
+
+	/* Reset the bridge */
+	brcm_pcie_bridge_sw_init_set(pcie, 1);
+
+	usleep_range(100, 200);
+
+	/* Take the bridge out of reset */
+	brcm_pcie_bridge_sw_init_set(pcie, 0);
+
+	tmp = readl(base + PCIE_MISC_HARD_PCIE_HARD_DEBUG);
+	tmp &= ~PCIE_MISC_HARD_PCIE_HARD_DEBUG_SERDES_IDDQ_MASK;
+	writel(tmp, base + PCIE_MISC_HARD_PCIE_HARD_DEBUG);
+	/* Wait for SerDes to be stable */
+	usleep_range(100, 200);
+
+	/* Set SCB_MAX_BURST_SIZE, CFG_READ_UR_MODE, SCB_ACCESS_EN */
+	u32p_replace_bits(&tmp, 1, PCIE_MISC_MISC_CTRL_SCB_ACCESS_EN_MASK);
+	u32p_replace_bits(&tmp, 1, PCIE_MISC_MISC_CTRL_CFG_READ_UR_MODE_MASK);
+	u32p_replace_bits(&tmp, PCIE_MISC_MISC_CTRL_MAX_BURST_SIZE_128,
+			  PCIE_MISC_MISC_CTRL_MAX_BURST_SIZE_MASK);
+	writel(tmp, base + PCIE_MISC_MISC_CTRL);
+
+	ret = brcm_pcie_get_rc_bar2_size_and_offset(pcie, &rc_bar2_size,
+						    &rc_bar2_offset);
+	if (ret)
+		return ret;
+
+	tmp = lower_32_bits(rc_bar2_offset);
+	u32p_replace_bits(&tmp, brcm_pcie_encode_ibar_size(rc_bar2_size),
+			  PCIE_MISC_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,
+			  PCIE_MISC_MISC_CTRL_SCB0_SIZE_MASK);
+	writel(tmp, base + PCIE_MISC_MISC_CTRL);
+
+	/* disable the PCIe->GISB memory window (RC_BAR1) */
+	tmp = readl(base + PCIE_MISC_RC_BAR1_CONFIG_LO);
+	tmp &= ~PCIE_MISC_RC_BAR1_CONFIG_LO_SIZE_MASK;
+	writel(tmp, base + PCIE_MISC_RC_BAR1_CONFIG_LO);
+
+	/* disable the PCIe->SCB memory window (RC_BAR3) */
+	tmp = readl(base + PCIE_MISC_RC_BAR3_CONFIG_LO);
+	tmp &= ~PCIE_MISC_RC_BAR3_CONFIG_LO_SIZE_MASK;
+	writel(tmp, base + PCIE_MISC_RC_BAR3_CONFIG_LO);
+
+	/* Mask all interrupts since we are not handling any yet */
+	writel(0xffffffff, pcie->base + PCIE_MSI_INTR2_MASK_SET);
+
+	/* clear any interrupts we find on boot */
+	writel(0xffffffff, pcie->base + PCIE_MSI_INTR2_CLR);
+
+	if (pcie->gen)
+		brcm_pcie_set_gen(pcie, pcie->gen);
+
+	/* Unassert the fundamental reset */
+	brcm_pcie_perst_set(pcie, 0);
+
+	/*
+	 * Give the RC/EP time to wake up, before trying to configure RC.
+	 * Intermittently check status for link-up, up to a total of 100ms.
+	 */
+	for (i = 0; i < 100 && !brcm_pcie_link_up(pcie); i += 5)
+		msleep(5);
+
+	if (!brcm_pcie_link_up(pcie)) {
+		dev_err(dev, "link down\n");
+		return -ENODEV;
+	}
+
+	if (!brcm_pcie_rc_mode(pcie)) {
+		dev_err(dev, "PCIe misconfigured; is in EP mode\n");
+		return -EINVAL;
+	}
+
+	resource_list_for_each_entry(entry, &bridge->windows) {
+		res = entry->res;
+
+		if (resource_type(res) != IORESOURCE_MEM)
+			continue;
+
+		if (num_out_wins >= BRCM_NUM_PCIE_OUT_WINS) {
+			dev_err(pcie->dev, "too many outbound wins\n");
+			return -EINVAL;
+		}
+
+		brcm_pcie_set_outbound_win(pcie, num_out_wins, res->start,
+					   res->start - entry->offset,
+					   res->end - res->start + 1);
+		num_out_wins++;
+	}
+
+	/*
+	 * For config space accesses on the RC, show the right class for
+	 * a PCIe-PCIe bridge (the default setting is to be EP mode).
+	 */
+	tmp = readl(base + PCIE_RC_CFG_PRIV1_ID_VAL3);
+	u32p_replace_bits(&tmp, 0x060400,
+			  PCIE_RC_CFG_PRIV1_ID_VAL3_CLASS_CODE_MASK);
+	writel(tmp, base + PCIE_RC_CFG_PRIV1_ID_VAL3);
+
+	if (pcie->ssc) {
+		ret = brcm_pcie_set_ssc(pcie);
+		if (ret == 0)
+			ssc_good = true;
+		else
+			dev_err(dev, "failed attempt to enter ssc mode\n");
+	}
+
+	lnksta = readw(base + BRCM_PCIE_CAP_REGS + PCI_EXP_LNKSTA);
+	cls = FIELD_GET(PCI_EXP_LNKSTA_CLS, lnksta);
+	nlw = FIELD_GET(PCI_EXP_LNKSTA_NLW, lnksta);
+	dev_info(dev, "link up, %s x%u %s\n",
+		 PCIE_SPEED2STR(cls + PCI_SPEED_133MHz_PCIX_533),
+		 nlw, ssc_good ? "(SSC)" : "(!SSC)");
+
+	/* PCIe->SCB endian mode for BAR */
+	tmp = readl(base + PCIE_RC_CFG_VENDOR_VENDOR_SPECIFIC_REG1);
+	u32p_replace_bits(&tmp, PCIE_RC_CFG_VENDOR_SPCIFIC_REG1_LITTLE_ENDIAN,
+		PCIE_RC_CFG_VENDOR_VENDOR_SPECIFIC_REG1_ENDIAN_MODE_BAR2_MASK);
+	writel(tmp, base + PCIE_RC_CFG_VENDOR_VENDOR_SPECIFIC_REG1);
+
+	/*
+	 * Refclk from RC should be gated with CLKREQ# input when ASPM L0s,L1
+	 * is enabled => setting the CLKREQ_DEBUG_ENABLE field to 1.
+	 */
+	tmp = readl(base + PCIE_MISC_HARD_PCIE_HARD_DEBUG);
+	tmp |= PCIE_MISC_HARD_PCIE_HARD_DEBUG_CLKREQ_DEBUG_ENABLE_MASK;
+	writel(tmp, base + PCIE_MISC_HARD_PCIE_HARD_DEBUG);
+
+	return 0;
+}
+
+/* L23 is a low-power PCIe link state */
+static void brcm_pcie_enter_l23(struct brcm_pcie *pcie)
+{
+	void __iomem *base = pcie->base;
+	int l23, i;
+	u32 tmp;
+
+	/* Assert request for L23 */
+	tmp = readl(base + PCIE_MISC_PCIE_CTRL);
+	u32p_replace_bits(&tmp, 1, PCIE_MISC_PCIE_CTRL_PCIE_L23_REQUEST_MASK);
+	writel(tmp, base + PCIE_MISC_PCIE_CTRL);
+
+	/* Wait up to 36 msec for L23 */
+	tmp = readl(base + PCIE_MISC_PCIE_STATUS);
+	l23 = FIELD_GET(PCIE_MISC_PCIE_STATUS_PCIE_LINK_IN_L23_MASK, tmp);
+	for (i = 0; i < 15 && !l23; i++) {
+		usleep_range(2000, 2400);
+		tmp = readl(base + PCIE_MISC_PCIE_STATUS);
+		l23 = FIELD_GET(PCIE_MISC_PCIE_STATUS_PCIE_LINK_IN_L23_MASK,
+				tmp);
+	}
+
+	if (!l23)
+		dev_err(pcie->dev, "failed to enter low-power link state\n");
+}
+
+static void brcm_pcie_turn_off(struct brcm_pcie *pcie)
+{
+	void __iomem *base = pcie->base;
+	int tmp;
+
+	if (brcm_pcie_link_up(pcie))
+		brcm_pcie_enter_l23(pcie);
+	/* Assert fundamental reset */
+	brcm_pcie_perst_set(pcie, 1);
+
+	/* Deassert request for L23 in case it was asserted */
+	tmp = readl(base + PCIE_MISC_PCIE_CTRL);
+	u32p_replace_bits(&tmp, 0, PCIE_MISC_PCIE_CTRL_PCIE_L23_REQUEST_MASK);
+	writel(tmp, base + PCIE_MISC_PCIE_CTRL);
+
+	/* Turn off SerDes */
+	tmp = readl(base + PCIE_MISC_HARD_PCIE_HARD_DEBUG);
+	u32p_replace_bits(&tmp, 1, PCIE_MISC_HARD_PCIE_HARD_DEBUG_SERDES_IDDQ_MASK);
+	writel(tmp, base + PCIE_MISC_HARD_PCIE_HARD_DEBUG);
+
+	/* Shutdown PCIe bridge */
+	brcm_pcie_bridge_sw_init_set(pcie, 1);
+}
+
+static void __brcm_pcie_remove(struct brcm_pcie *pcie)
+{
+	brcm_pcie_turn_off(pcie);
+	clk_disable_unprepare(pcie->clk);
+	clk_put(pcie->clk);
+}
+
+static int brcm_pcie_remove(struct platform_device *pdev)
+{
+	struct brcm_pcie *pcie = platform_get_drvdata(pdev);
+
+	pci_stop_root_bus(pcie->root_bus);
+	pci_remove_root_bus(pcie->root_bus);
+	__brcm_pcie_remove(pcie);
+
+	return 0;
+}
+
+static int brcm_pcie_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct pci_host_bridge *bridge;
+	struct brcm_pcie *pcie;
+	struct pci_bus *child;
+	struct resource *res;
+	int ret;
+
+	bridge = devm_pci_alloc_host_bridge(&pdev->dev, sizeof(*pcie));
+	if (!bridge)
+		return -ENOMEM;
+
+	pcie = pci_host_bridge_priv(bridge);
+	pcie->dev = &pdev->dev;
+	pcie->np = np;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	pcie->base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(pcie->base))
+		return PTR_ERR(pcie->base);
+
+	pcie->clk = devm_clk_get_optional(&pdev->dev, "sw_pcie");
+	if (IS_ERR(pcie->clk))
+		return PTR_ERR(pcie->clk);
+
+	ret = of_pci_get_max_link_speed(np);
+	pcie->gen = (ret < 0) ? 0 : ret;
+
+	pcie->ssc = of_property_read_bool(np, "brcm,enable-ssc");
+
+	ret = pci_parse_request_of_pci_ranges(pcie->dev, &bridge->windows,
+					      &bridge->dma_ranges, NULL);
+	if (ret)
+		return ret;
+
+	ret = clk_prepare_enable(pcie->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "could not enable clock\n");
+		return ret;
+	}
+
+	ret = brcm_pcie_setup(pcie);
+	if (ret)
+		goto fail;
+
+	bridge->dev.parent = &pdev->dev;
+	bridge->busnr = 0;
+	bridge->ops = &brcm_pcie_ops;
+	bridge->sysdata = pcie;
+	bridge->map_irq = of_irq_parse_and_map_pci;
+	bridge->swizzle_irq = pci_common_swizzle;
+
+	ret = pci_scan_root_bus_bridge(bridge);
+	if (ret < 0) {
+		dev_err(pcie->dev, "Scanning root bridge failed\n");
+		goto fail;
+	}
+
+	pci_assign_unassigned_bus_resources(bridge->bus);
+	list_for_each_entry(child, &bridge->bus->children, node)
+		pcie_bus_configure_settings(child);
+	pci_bus_add_devices(bridge->bus);
+	platform_set_drvdata(pdev, pcie);
+	pcie->root_bus = bridge->bus;
+
+	return 0;
+fail:
+	__brcm_pcie_remove(pcie);
+	return ret;
+}
+
+static const struct of_device_id brcm_pcie_match[] = {
+	{ .compatible = "brcm,bcm2711-pcie" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, brcm_pcie_match);
+
+static struct platform_driver brcm_pcie_driver = {
+	.probe = brcm_pcie_probe,
+	.remove = brcm_pcie_remove,
+	.driver = {
+		.name = "brcm-pcie",
+		.of_match_table = brcm_pcie_match,
+	},
+};
+module_platform_driver(brcm_pcie_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Broadcom STB PCIe RC driver");
+MODULE_AUTHOR("Broadcom");
Signature · 1 line
2.24.0
#10 lore raw

Re: [PATCH v5 3/6] PCI: brcmstb: Add Broadcom STB PCIe host controller driver

Hi Lorenzo,

Quoted 36 lines · Lorenzo Pieralisi
Quoted 13 lines · Nicolas Saenz Julienne

From: Jim Quinlan <[email protected]>

This adds a basic driver for Broadcom's STB PCIe controller, for now aimed at Raspberry Pi 4's SoC, bcm2711.

---

Quoted 7 lines

Changes since v3:
- Update commit message
- rollback roundup_pow_two usage, it'll be updated later down the line
- Remove comment in register definition

Changes since v2:
- Correct rc_bar2_offset sign

In relation to this change.

[...]

Quoted 10 lines

+static inline int brcm_pcie_get_rc_bar2_size_and_offset(struct brcm_pcie *pcie,

drivers/pci/controller/pcie-brcmstb.c new file +8 -0
+							u64 *rc_bar2_size,
+							u64 *rc_bar2_offset)
+{
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
+	struct device *dev = pcie->dev;
+	struct resource_entry *entry;
+
+	entry = resource_list_first_type(&bridge->dma_ranges, IORESOURCE_MEM);
Quoted 8 lines

drivers/pci/controller/pcie-brcmstb.c line 392

Quoted 4 lines
drivers/pci/controller/pcie-brcmstb.c new file +4 -0
+	if (!entry)
+		return -ENODEV;
+
+	*rc_bar2_offset = -entry->offset;

I think this deserves a comment - I guess it has to do with how the controller expects CPU<->PCI offsets to be expressed compared to how it is computed in dma_ranges entries.

You're right, OF code calculates it by doing:

offset = cpu_start_addr - pci_start_addr (see
devm_of_pci_get_host_bridge_resources())

While the RC_BAR2_CONFIG register expects the opposite subtraction. I'll add a comment on the next revision.

Quoted 2 lines

I will try to complete the review shortly and try to apply it given that it has already been reviewed by others.

Thanks!

Regards,
Nicolas

Quoted 2 lines

Lorenzo

#11 lore raw

Re: [PATCH v5 3/6] PCI: brcmstb: Add Broadcom STB PCIe host controller driver

Quoted 48 lines · Nicolas Saenz Julienne

Hi Lorenzo,

Quoted 36 lines · Lorenzo Pieralisi
Quoted 13 lines · Nicolas Saenz Julienne

From: Jim Quinlan <[email protected]>

This adds a basic driver for Broadcom's STB PCIe controller, for now aimed at Raspberry Pi 4's SoC, bcm2711.

---

Quoted 7 lines

Changes since v3:
- Update commit message
- rollback roundup_pow_two usage, it'll be updated later down the line
- Remove comment in register definition

Changes since v2:
- Correct rc_bar2_offset sign

In relation to this change.

[...]

Quoted 10 lines

+static inline int brcm_pcie_get_rc_bar2_size_and_offset(struct brcm_pcie *pcie,

drivers/pci/controller/pcie-brcmstb.c new file +8 -0
+							u64 *rc_bar2_size,
+							u64 *rc_bar2_offset)
+{
+	struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
+	struct device *dev = pcie->dev;
+	struct resource_entry *entry;
+
+	entry = resource_list_first_type(&bridge->dma_ranges, IORESOURCE_MEM);
Quoted 8 lines

drivers/pci/controller/pcie-brcmstb.c line 392

Quoted 4 lines
drivers/pci/controller/pcie-brcmstb.c new file +4 -0
+	if (!entry)
+		return -ENODEV;
+
+	*rc_bar2_offset = -entry->offset;

I think this deserves a comment - I guess it has to do with how the controller expects CPU<->PCI offsets to be expressed compared to how it is computed in dma_ranges entries.

Quoted 7 lines

You're right, OF code calculates it by doing:

offset = cpu_start_addr - pci_start_addr (see
devm_of_pci_get_host_bridge_resources())

While the RC_BAR2_CONFIG register expects the opposite subtraction. I'll add a comment on the next revision.

There is no need for a new posting, either write that comment here and I update the code or inline the patch or just resend *this* updated patch to the list.

Thanks,
Lorenzo

#12 lore raw

Re: [PATCH v5 3/6] PCI: brcmstb: Add Broadcom STB PCIe host controller driver

Quoted 59 lines · Lorenzo Pieralisi
Quoted 58 lines · Nicolas Saenz Julienne

Hi Lorenzo,

Quoted 41 lines · Lorenzo Pieralisi
Quoted 13 lines · Nicolas Saenz Julienne

From: Jim Quinlan <[email protected]>

This adds a basic driver for Broadcom's STB PCIe controller, for now aimed at Raspberry Pi 4's SoC, bcm2711.

---

Quoted 7 lines

Changes since v3:
- Update commit message
- rollback roundup_pow_two usage, it'll be updated later down the line
- Remove comment in register definition

Changes since v2:
- Correct rc_bar2_offset sign

In relation to this change.

[...]

Quoted 15 lines

+static inline int brcm_pcie_get_rc_bar2_size_and_offset(struct brcm_pcie
*pcie,

(quoted diff) +1 -0
+							u64

*rc_bar2_size,

(quoted diff) +1 -0
+							u64

*rc_bar2_offset)

(quoted diff) +2 -0
+{
+	struct pci_host_bridge *bridge =

pci_host_bridge_from_priv(pcie);

drivers/pci/controller/pcie-brcmstb.c new file +4 -0
+	struct device *dev = pcie->dev;
+	struct resource_entry *entry;
+
+	entry = resource_list_first_type(&bridge->dma_ranges,

IORESOURCE_MEM);

Quoted 8 lines

drivers/pci/controller/pcie-brcmstb.c line 392

Quoted 4 lines
drivers/pci/controller/pcie-brcmstb.c new file +4 -0
+	if (!entry)
+		return -ENODEV;
+
+	*rc_bar2_offset = -entry->offset;

I think this deserves a comment - I guess it has to do with how the controller expects CPU<->PCI offsets to be expressed compared to how it is computed in dma_ranges entries.

You're right, OF code calculates it by doing:

offset = cpu_start_addr - pci_start_addr (see
devm_of_pci_get_host_bridge_resources())

Quoted 6 lines
Quoted 2 lines

While the RC_BAR2_CONFIG register expects the opposite subtraction. I'll add a comment on the next revision.

There is no need for a new posting, either write that comment here and I update the code or inline the patch or just resend *this* updated patch to the list.

OK, hope this sounds good enough:

/*
* The controller expects the inbound window offset to be calculated as
* the difference between PCIe's address space and CPU's. The offset
* provided by the firmware is calculated the opposite way, so we
* negate it.
*/

Regards,
Nicolas

#13 lore raw

PATCH v5 4/6 PCI: brcmstb: Add MSI support

In reply to Nicolas Saenz Julienne

From: Jim Quinlan <[email protected]>

This adds MSI support to the Broadcom STB PCIe host controller. The MSI controller is physically located within the PCIe block, however, there is no reason why the MSI controller could not be moved elsewhere in the future. MSIX is not supported by the HW.

Since the internal Brcmstb MSI controller is intertwined with the PCIe controller, it is not its own platform device but rather part of the PCIe platform device.

---

Changes since v3 (kept Marc's reviewed by as changes seem small enough):
- Use define to access MSI_DATA_CONFIG_VAL
- Update commit message

Changes since v2:
- Use standard APIs on register operations
- Get rid of revision code
- Update rules to msi_target_addr selection
- Remove unwarranted MSI_FLAG_PCI_MSIX
- Small cosmetic changes

Changes since v1:
- Move revision code and some registers to this patch
- Use PCIE_MSI_IRQ_DOMAIN in Kconfig
- Remove redundant register read from ISR
- Fail probe on MSI init error
- Get rid of msi_internal
- Use bitmap family of functions
- Use edge triggered setup
- Add comment regarding MultiMSI
- Simplify compose_msi_msg to avoid reg read

This is based on Jim's original submission[1] with some slight changes regarding how pcie->msi_target_addr is decided.

[1] https://patchwork.kernel.org/patch/10605955/

 drivers/pci/controller/Kconfig        |   1 +
 drivers/pci/controller/pcie-brcmstb.c | 261 +++++++++++++++++++++++++-
 2 files changed, 261 insertions(+), 1 deletion(-)
drivers/pci/controller/Kconfig +1 -0
index 27504f108ee5..918e283bbff1 100644
@@ -257,6 +257,7 @@ config PCIE_BRCMSTB
 	tristate "Broadcom Brcmstb PCIe host controller"
 	depends on ARCH_BCM2835 || COMPILE_TEST
 	depends on OF
+	depends on PCI_MSI_IRQ_DOMAIN
 	help
 	  Say Y here to enable PCIe host controller support for
 	  Broadcom STB based SoCs, like the Raspberry Pi 4.
drivers/pci/controller/pcie-brcmstb.c +260 -1

332 lines not on this page · raw message

Signature · 1 line
2.24.0
#14 lore raw

PATCH v5 5/6 MAINTAINERS: Add brcmstb PCIe controller

In reply to Nicolas Saenz Julienne

The controller serves both the Raspberry Pi 4 (bcm2711) and brcmstb platforms.

---
 MAINTAINERS | 4 ++++
 1 file changed, 4 insertions(+)
MAINTAINERS +4 -0
index d10d73276fed..ace78ab1e6f4 100644
@@ -3238,6 +3238,8 @@ S:	Maintained
 N:	bcm2711
 N:	bcm2835
 F:	drivers/staging/vc04_services
+F:	Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml
+F:	drivers/pci/controller/pcie-brcmstb.c
 
 BROADCOM BCM47XX MIPS ARCHITECTURE
 M:	Hauke Mehrtens <[email protected]>
@@ -3293,6 +3295,8 @@ F:	drivers/bus/brcmstb_gisb.c
 F:	arch/arm/mm/cache-b15-rac.c
 F:	arch/arm/include/asm/hardware/cache-b15-rac.h
 N:	brcmstb
+F:	Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml
+F:	drivers/pci/controller/pcie-brcmstb.c
 
 BROADCOM BMIPS CPUFREQ DRIVER
 M:	Markus Mayer <[email protected]>
Signature · 1 line
2.24.0
#15 lore raw

Re: [PATCH v5 5/6] MAINTAINERS: Add brcmstb PCIe controller

Quoted 5 lines · Nicolas Saenz Julienne

The controller serves both the Raspberry Pi 4 (bcm2711) and brcmstb platforms.

---

Applied to maintainers/next, thanks!

Signature · 1 line
Florian
#16 lore raw

PATCH v5 6/6 arm64: defconfig: Enable Broadcom's STB PCIe controller

In reply to Nicolas Saenz Julienne

For now mainly used in the Raspberry Pi 4.

---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
index 2646fc76b8db..2b80980ef576 100644
@@ -192,6 +192,7 @@ CONFIG_PCIE_ALTERA_MSI=y
 CONFIG_PCI_HOST_THUNDER_PEM=y
 CONFIG_PCI_HOST_THUNDER_ECAM=y
 CONFIG_PCIE_ROCKCHIP_HOST=m
+CONFIG_PCIE_BRCMSTB=m
 CONFIG_PCI_LAYERSCAPE=y
 CONFIG_PCI_HISI=y
 CONFIG_PCIE_QCOM=y
Signature · 1 line
2.24.0
#18 lore raw
In reply to Nicolas Saenz Julienne
Quoted 9 lines · Nicolas Saenz Julienne

This series aims at providing support for Raspberry Pi 4's PCIe controller, which is also shared with the Broadcom STB family of devices.

There was a previous attempt to upstream this some years ago[1] but was blocked as most STB PCIe integrations have a sparse DMA mapping[2] which is something currently not supported by the kernel. Luckily this is not the case for the Raspberry Pi 4.

Hi Nicolas,

This series looks good to me now. Unless there is further feedback I'll ask Lorenzo to merge this when he returns in the new year.

Thanks for the log2.h efforts - perhaps this can be picked up again one day.

Thanks,

Andrew Murray

Quoted 66 lines

Note the series is based on top of linux next, as the DTS patch depends on it.

[1] https://patchwork.kernel.org/cover/10605933/
[2] https://patchwork.kernel.org/patch/10605957/

---

Changes since v4:
- Rebase DTS patch
- Respin log2.h code into it's own series as it's still contentious yet mostly unrelated to the PCIe part

Changes since v3:
- Moved all the log2.h related changes at the end of the series, as I presume they will be contentious and I don't want the PCIe patches to depend on them. Ultimately I think I'll respin them on their own series but wanted to keep them in for this submission just for the sake of continuity.
- Addressed small nits here and there.

Changes since v2:
- Redo register access in driver avoiding indirection while keeping the naming intact
- Add patch editing ARM64's config
- Last MSI cleanups, notably removing MSIX flag
- Got rid of all _RB writes
- Got rid of all of_data
- Overall churn removal
- Address the rest of Andrew's comments

Changes since v1:
- add generic rounddown/roundup_pow_two64() patch
- Add MAINTAINERS patch
- Fix Kconfig
- Cleanup probe, use up to date APIs, exit on MSI failure
- Get rid of linux,pci-domain and other unused constructs
- Use edge triggered setup for MSI
- Cleanup MSI implementation
- Fix multiple cosmetic issues
- Remove supend/resume code

Jim Quinlan (3):
dt-bindings: PCI: Add bindings for brcmstb's PCIe device
PCI: brcmstb: Add Broadcom STB PCIe host controller driver
PCI: brcmstb: Add MSI support

Nicolas Saenz Julienne (3):
ARM: dts: bcm2711: Enable PCIe controller
MAINTAINERS: Add brcmstb PCIe controller
arm64: defconfig: Enable Broadcom's STB PCIe controller

 .../bindings/pci/brcm,stb-pcie.yaml           |   97 ++
 MAINTAINERS                                   |    4 +
 arch/arm/boot/dts/bcm2711.dtsi                |   31 +-
 arch/arm64/configs/defconfig                  |    1 +
 drivers/pci/controller/Kconfig                |    9 +
 drivers/pci/controller/Makefile               |    1 +
 drivers/pci/controller/pcie-brcmstb.c         | 1007 +++++++++++++++++
 7 files changed, 1149 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml
 create mode 100644 drivers/pci/controller/pcie-brcmstb.c
Signature · 1 line
2.24.0
#19 lore raw
Quoted 11 lines · Andrew Murray
Quoted 9 lines · Nicolas Saenz Julienne

This series aims at providing support for Raspberry Pi 4's PCIe controller, which is also shared with the Broadcom STB family of devices.

There was a previous attempt to upstream this some years ago[1] but was blocked as most STB PCIe integrations have a sparse DMA mapping[2] which is something currently not supported by the kernel. Luckily this is not the case for the Raspberry Pi 4.

Quoted 4 lines

Hi Nicolas,

This series looks good to me now. Unless there is further feedback I'll ask Lorenzo to merge this when he returns in the new year.

Thanks!

Quoted 1 line

Thanks for the log2.h efforts - perhaps this can be picked up again one day.

I'm not giving up on it yet :)

Regards,
Nicolas

#20 lore raw
In reply to Nicolas Saenz Julienne
Quoted 61 lines · Nicolas Saenz Julienne

This series aims at providing support for Raspberry Pi 4's PCIe controller, which is also shared with the Broadcom STB family of devices.

There was a previous attempt to upstream this some years ago[1] but was blocked as most STB PCIe integrations have a sparse DMA mapping[2] which is something currently not supported by the kernel. Luckily this is not the case for the Raspberry Pi 4.

Note the series is based on top of linux next, as the DTS patch depends on it.

[1] https://patchwork.kernel.org/cover/10605933/
[2] https://patchwork.kernel.org/patch/10605957/

---

Changes since v4:
- Rebase DTS patch
- Respin log2.h code into it's own series as it's still contentious yet mostly unrelated to the PCIe part

Changes since v3:
- Moved all the log2.h related changes at the end of the series, as I presume they will be contentious and I don't want the PCIe patches to depend on them. Ultimately I think I'll respin them on their own series but wanted to keep them in for this submission just for the sake of continuity.
- Addressed small nits here and there.

Changes since v2:
- Redo register access in driver avoiding indirection while keeping the naming intact
- Add patch editing ARM64's config
- Last MSI cleanups, notably removing MSIX flag
- Got rid of all _RB writes
- Got rid of all of_data
- Overall churn removal
- Address the rest of Andrew's comments

Changes since v1:
- add generic rounddown/roundup_pow_two64() patch
- Add MAINTAINERS patch
- Fix Kconfig
- Cleanup probe, use up to date APIs, exit on MSI failure
- Get rid of linux,pci-domain and other unused constructs
- Use edge triggered setup for MSI
- Cleanup MSI implementation
- Fix multiple cosmetic issues
- Remove supend/resume code

Jim Quinlan (3):
dt-bindings: PCI: Add bindings for brcmstb's PCIe device
PCI: brcmstb: Add Broadcom STB PCIe host controller driver
PCI: brcmstb: Add MSI support

Nicolas Saenz Julienne (3):
ARM: dts: bcm2711: Enable PCIe controller
MAINTAINERS: Add brcmstb PCIe controller
arm64: defconfig: Enable Broadcom's STB PCIe controller

Quoted 10 lines
 .../bindings/pci/brcm,stb-pcie.yaml           |   97 ++
 MAINTAINERS                                   |    4 +
 arch/arm/boot/dts/bcm2711.dtsi                |   31 +-
 arch/arm64/configs/defconfig                  |    1 +
 drivers/pci/controller/Kconfig                |    9 +
 drivers/pci/controller/Makefile               |    1 +
 drivers/pci/controller/pcie-brcmstb.c         | 1007 +++++++++++++++++
 7 files changed, 1149 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml
 create mode 100644 drivers/pci/controller/pcie-brcmstb.c

Applied patches [1,3,4] to pci/brcmstb, please have a look to check everything is in order after the minor update I included.

Thanks !
Lorenzo

#21 lore raw
Quoted 73 lines · Lorenzo Pieralisi
Quoted 61 lines · Nicolas Saenz Julienne

This series aims at providing support for Raspberry Pi 4's PCIe controller, which is also shared with the Broadcom STB family of devices.

There was a previous attempt to upstream this some years ago[1] but was blocked as most STB PCIe integrations have a sparse DMA mapping[2] which is something currently not supported by the kernel. Luckily this is not the case for the Raspberry Pi 4.

Note the series is based on top of linux next, as the DTS patch depends on it.

[1] https://patchwork.kernel.org/cover/10605933/
[2] https://patchwork.kernel.org/patch/10605957/

---

Changes since v4:
- Rebase DTS patch
- Respin log2.h code into it's own series as it's still contentious yet mostly unrelated to the PCIe part

Changes since v3:
- Moved all the log2.h related changes at the end of the series, as I presume they will be contentious and I don't want the PCIe patches to depend on them. Ultimately I think I'll respin them on their own series but wanted to keep them in for this submission just for the sake of continuity.
- Addressed small nits here and there.

Changes since v2:
- Redo register access in driver avoiding indirection while keeping the naming intact
- Add patch editing ARM64's config
- Last MSI cleanups, notably removing MSIX flag
- Got rid of all _RB writes
- Got rid of all of_data
- Overall churn removal
- Address the rest of Andrew's comments

Changes since v1:
- add generic rounddown/roundup_pow_two64() patch
- Add MAINTAINERS patch
- Fix Kconfig
- Cleanup probe, use up to date APIs, exit on MSI failure
- Get rid of linux,pci-domain and other unused constructs
- Use edge triggered setup for MSI
- Cleanup MSI implementation
- Fix multiple cosmetic issues
- Remove supend/resume code

Jim Quinlan (3):
dt-bindings: PCI: Add bindings for brcmstb's PCIe device
PCI: brcmstb: Add Broadcom STB PCIe host controller driver
PCI: brcmstb: Add MSI support

Nicolas Saenz Julienne (3):
ARM: dts: bcm2711: Enable PCIe controller
MAINTAINERS: Add brcmstb PCIe controller
arm64: defconfig: Enable Broadcom's STB PCIe controller

Quoted 10 lines
 .../bindings/pci/brcm,stb-pcie.yaml           |   97 ++
 MAINTAINERS                                   |    4 +
 arch/arm/boot/dts/bcm2711.dtsi                |   31 +-
 arch/arm64/configs/defconfig                  |    1 +
 drivers/pci/controller/Kconfig                |    9 +
 drivers/pci/controller/Makefile               |    1 +
 drivers/pci/controller/pcie-brcmstb.c         | 1007 +++++++++++++++++
 7 files changed, 1149 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml
 create mode 100644 drivers/pci/controller/pcie-brcmstb.c
Quoted 2 lines

Applied patches [1,3,4] to pci/brcmstb, please have a look to check everything is in order after the minor update I included.

Looks good to me.

Thanks,
Nicolas