Skip to contentSkip to conversation

Add support for Andes Qilai SoC PCIe controller

PATCH Superseded Randolph Lin 3 participants 9 messages Oct 14, 2025 – Oct 23, 2025

Subsystems (7)

v8 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Randolph Lin

author maintainer
#0 lore raw

v8 cover Add support for Andes Qilai SoC PCIe controller

Add support for Andes Qilai SoC PCIe controller

These patches introduce driver support for the PCIe controller on the Andes Qilai SoC.

---
Changes in v8:
- Fix the compile error reported by the kernel test robot.

---
Changes in v7:
- Remove unnecessary nodes and property in DTS bindings

---
Changes in v6:
- Fix typo in the logic for adjusting the number of OB/IB windows

---
Changes in v5:
- Add support to adjust the number of OB/IB windows in the glue driver.
- Fix the number of OB windows in the Qilai PCIe driver.
- Remove meaningless properties from the device tree.
- Made minor adjustments based on the reviewer's suggestions.

---
Changes in v4:
- Add .post_init callback for enabling IOCP cache.
- Sort by vender name in Kconfig
- Using PROBE_PREFER_ASYNCHRONOUS as default probe type.
- Made minor adjustments based on the reviewer's suggestions.

---
Changes in v3:
- Remove outbound ATU address range validation callback and logic.
- Add logic to skip failed outbound iATU configuration and continue.
- Using PROBE_PREFER_ASYNCHRONOUS as default probe type.
- Made minor adjustments based on the reviewer's suggestions.

---
Changes in v2:
- Remove the patch that adds the dma-ranges property to the SoC node.
- Add dma-ranges to the PCIe parent node bus node.
- Refactor and rename outbound ATU address range validation callback and logic.
- Use parent_bus_offset instead of cpu_addr_fixup().
- Using PROBE_DEFAULT_STRATEGY as default probe type.
- Made minor adjustments based on the reviewer's suggestions.

Randolph Lin (5):
PCI: dwc: Allow adjusting the number of ob/ib windows in glue driver
dt-bindings: PCI: Add Andes QiLai PCIe support
riscv: dts: andes: Add PCIe node into the QiLai SoC
PCI: andes: Add Andes QiLai SoC PCIe host driver support
MAINTAINERS: Add maintainers for Andes QiLai PCIe driver

 .../bindings/pci/andestech,qilai-pcie.yaml    |  84 ++++++
 MAINTAINERS                                   |   7 +
 arch/riscv/boot/dts/andes/qilai.dtsi          | 106 ++++++++
 drivers/pci/controller/dwc/Kconfig            |  13 +
 drivers/pci/controller/dwc/Makefile           |   1 +
 drivers/pci/controller/dwc/pcie-andes-qilai.c | 240 ++++++++++++++++++
 drivers/pci/controller/dwc/pcie-designware.c  |  12 +-
 7 files changed, 461 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/pci/andestech,qilai-pcie.yaml
 create mode 100644 drivers/pci/controller/dwc/pcie-andes-qilai.c
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH v8 2/5 dt-bindings: PCI: Add Andes QiLai PCIe support

Add the Andes QiLai PCIe node, which includes 3 Root Complexes. Only one example is required in the DTS bindings YAML file.

---
 .../bindings/pci/andestech,qilai-pcie.yaml    | 84 +++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/andestech,qilai-pcie.yaml
Documentation/devicetree/bindings/pci/andestech,qilai-pcie.yaml new file +84 -0
new file mode 100644
index 000000000000..ca444e4766ec
@@ -0,0 +1,84 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/andestech,qilai-pcie.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Andes QiLai PCIe host controller
+
+description:
+  Andes QiLai PCIe host controller is based on the Synopsys DesignWare
+  PCI core. It shares common features with the PCIe DesignWare core and
+  inherits common properties defined in
+  Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml.
+
+maintainers:
+  - Randolph Lin <[email protected]>
+
+allOf:
+  - $ref: /schemas/pci/snps,dw-pcie.yaml#
+
+properties:
+  compatible:
+    const: andestech,qilai-pcie
+
+  reg:
+    items:
+      - description: Data Bus Interface (DBI) registers.
+      - description: APB registers.
+      - description: PCIe configuration space region.
+
+  reg-names:
+    items:
+      - const: dbi
+      - const: apb
+      - const: config
+
+  ranges:
+    maxItems: 2
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - reg
+  - reg-names
+  - interrupts
+  - interrupt-names
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    soc {
+      #address-cells = <2>;
+      #size-cells = <2>;
+
+      pcie@80000000 {
+        compatible = "andestech,qilai-pcie";
+        device_type = "pci";
+        reg = <0x0 0x80000000 0x0 0x20000000>,
+              <0x0 0x04000000 0x0 0x00001000>,
+              <0x0 0x00000000 0x0 0x00010000>;
+        reg-names = "dbi", "apb", "config";
+
+        linux,pci-domain = <0>;
+        #address-cells = <3>;
+        #size-cells = <2>;
+        ranges = <0x02000000 0x00 0x10000000 0x00 0x10000000 0x0 0xf0000000>,
+                 <0x43000000 0x01 0x00000000 0x01 0x0000000 0x1f 0x00000000>;
+
+        #interrupt-cells = <1>;
+        interrupts = <0xf>;
+        interrupt-names = "msi";
+        interrupt-parent = <&plic0>;
+        interrupt-map-mask = <0 0 0 7>;
+        interrupt-map = <0 0 0 1 &plic0 0xf IRQ_TYPE_LEVEL_HIGH>,
+                        <0 0 0 2 &plic0 0xf IRQ_TYPE_LEVEL_HIGH>,
+                        <0 0 0 3 &plic0 0xf IRQ_TYPE_LEVEL_HIGH>,
+                        <0 0 0 4 &plic0 0xf IRQ_TYPE_LEVEL_HIGH>;
+      };
+    };
+...
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v8 1/5 PCI: dwc: Allow adjusting the number of ob/ib windows in glue driver

In reply to Randolph Lin

The number of ob/ib windows is determined through write-read loops on registers in the core driver. Some glue drivers need to adjust the number of ob/ib windows to meet specific requirements,such as hardware limitations. This change allows the glue driver to adjust the number of ob/ib windows to satisfy platform-specific constraints. The glue driver may adjust the number of ob/ib windows, but the values must stay within hardware limits.

---
 drivers/pci/controller/dwc/pcie-designware.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/pci/controller/dwc/pcie-designware.c +10 -2
index c644216995f6..a860890febc3 100644
@@ -851,8 +851,16 @@ void dw_pcie_iatu_detect(struct dw_pcie *pci)
 		max = 0;
 	}
 
-	pci->num_ob_windows = ob;
-	pci->num_ib_windows = ib;
+	if (!pci->num_ob_windows)
+		pci->num_ob_windows = ob;
+	else if (pci->num_ob_windows > ob)
+		dev_err(pci->dev, "Adjusted ob windows exceed the limit\n");
+
+	if (!pci->num_ib_windows)
+		pci->num_ib_windows = ib;
+	else if (pci->num_ib_windows > ib)
+		dev_err(pci->dev, "Adjusted ib windows exceed the limit\n");
+
 	pci->region_align = 1 << fls(min);
 	pci->region_limit = (max << 32) | (SZ_4G - 1);
 
Signature · 1 line
2.34.1
author maintainer
#4 lore raw

PATCH v8 3/5 riscv: dts: andes: Add PCIe node into the QiLai SoC

In reply to Randolph Lin

Add the Andes QiLai PCIe node, which includes 3 Root Complexes.

---
 arch/riscv/boot/dts/andes/qilai.dtsi | 106 +++++++++++++++++++++++++++
 1 file changed, 106 insertions(+)
arch/riscv/boot/dts/andes/qilai.dtsi +106 -0
index de3de32f8c39..afa7b75a7e7a 100644
@@ -182,5 +182,111 @@ uart0: serial@30300000 {
 			reg-io-width = <4>;
 			no-loopback-test;
 		};
+
+		bus@80000000 {
+			compatible = "simple-bus";
+			#address-cells = <2>;
+			#size-cells = <2>;
+			dma-ranges = <0x44 0x00000000 0x04 0x00000000 0x04 0x00000000>;
+			ranges = <0x00 0x80000000 0x00 0x80000000 0x00 0x20000000>,
+				 <0x00 0x04000000 0x00 0x04000000 0x00 0x00001000>,
+				 <0x00 0x00000000 0x20 0x00000000 0x20 0x00000000>;
+
+			pcie@80000000 {
+				compatible = "andestech,qilai-pcie";
+				device_type = "pci";
+				reg = <0x00 0x80000000 0x00 0x20000000>, /* DBI registers */
+				      <0x00 0x04000000 0x00 0x00001000>, /* APB registers */
+				      <0x00 0x00000000 0x00 0x00010000>; /* Configuration registers */
+				reg-names = "dbi", "apb", "config";
+
+				linux,pci-domain = <0>;
+				#address-cells = <3>;
+				#size-cells = <2>;
+				ranges = <0x02000000 0x00 0x10000000 0x00 0x10000000 0x00 0xf0000000>,
+					 <0x43000000 0x01 0x00000000 0x01 0x00000000 0x1f 0x00000000>;
+
+				#interrupt-cells = <1>;
+				interrupts = <0xf 0x4>;
+				interrupt-names = "msi";
+				interrupt-parent = <&plic>;
+				interrupt-map-mask = <0 0 0 0>;
+				interrupt-map = <0 0 0 1 &plic 0xf 0x4>,
+						<0 0 0 2 &plic 0xf 0x4>,
+						<0 0 0 3 &plic 0xf 0x4>,
+						<0 0 0 4 &plic 0xf 0x4>;
+			};
+		};
+
+		bus@a0000000 {
+			compatible = "simple-bus";
+			#address-cells = <2>;
+			#size-cells = <2>;
+			dma-ranges = <0x44 0x00000000 0x04 0x00000000 0x04 0x00000000>;
+			ranges = <0x00 0xa0000000 0x00 0xa0000000 0x00 0x20000000>,
+				 <0x00 0x04001000 0x00 0x04001000 0x00 0x00001000>,
+				 <0x00 0x00000000 0x10 0x00000000 0x08 0x00000000>;
+
+			pcie@a0000000 {
+				compatible = "andestech,qilai-pcie";
+				device_type = "pci";
+				reg = <0x00 0xa0000000 0x00 0x20000000>, /* DBI registers */
+				      <0x00 0x04001000 0x00 0x00001000>, /* APB registers */
+				      <0x00 0x00000000 0x00 0x00010000>; /* Configuration registers */
+				reg-names = "dbi", "apb", "config";
+
+				linux,pci-domain = <1>;
+				#address-cells = <3>;
+				#size-cells = <2>;
+				ranges = <0x02000000 0x00 0x10000000 0x00 0x10000000 0x0 0xf0000000>,
+					 <0x43000000 0x01 0x00000000 0x01 0x00000000 0x7 0x00000000>;
+
+				#interrupt-cells = <1>;
+				interrupts = <0xe 0x4>;
+				interrupt-names = "msi";
+				interrupt-parent = <&plic>;
+				interrupt-map-mask = <0 0 0 0>;
+				interrupt-map = <0 0 0 1 &plic 0xe 0x4>,
+						<0 0 0 2 &plic 0xe 0x4>,
+						<0 0 0 3 &plic 0xe 0x4>,
+						<0 0 0 4 &plic 0xe 0x4>;
+			};
+		};
+
+		bus@c0000000 {
+			compatible = "simple-bus";
+			#address-cells = <2>;
+			#size-cells = <2>;
+			dma-ranges = <0x44 0x00000000 0x04 0x00000000 0x04 0x00000000>;
+			ranges = <0x00 0xc0000000 0x00 0xc0000000 0x00 0x20000000>,
+				 <0x00 0x04002000 0x00 0x04002000 0x00 0x00001000>,
+				 <0x00 0x00000000 0x18 0x00000000 0x08 0x00000000>;
+
+			pcie@c0000000 {
+				compatible = "andestech,qilai-pcie";
+				device_type = "pci";
+				reg = <0x00 0xc0000000 0x00 0x20000000>, /* DBI registers */
+				      <0x00 0x04002000 0x00 0x00001000>, /* APB registers */
+				      <0x00 0x00000000 0x00 0x00010000>; /* Configuration registers */
+				reg-names = "dbi", "apb", "config";
+
+				linux,pci-domain = <2>;
+				#address-cells = <3>;
+				#size-cells = <2>;
+				ranges = <0x02000000 0x00 0x10000000 0x00 0x10000000 0x0 0xf0000000>,
+					 <0x43000000 0x01 0x00000000 0x01 0x00000000 0x7 0x00000000>;
+
+				#interrupt-cells = <1>;
+				interrupts = <0xd 0x4>;
+				interrupt-names = "msi";
+				interrupt-parent = <&plic>;
+				interrupt-map-mask = <0 0 0 0>;
+				interrupt-map = <0 0 0 1 &plic 0xd 0x4>,
+						<0 0 0 2 &plic 0xd 0x4>,
+						<0 0 0 3 &plic 0xd 0x4>,
+						<0 0 0 4 &plic 0xd 0x4>;
+			};
+		};
+
 	};
 };
Signature · 1 line
2.34.1
author maintainer
#5 lore raw

PATCH v8 4/5 PCI: andes: Add Andes QiLai SoC PCIe host driver support

In reply to Randolph Lin

Add driver support for DesignWare based PCIe controller in Andes QiLai SoC. The driver only supports the Root Complex mode.

---
 drivers/pci/controller/dwc/Kconfig            |  13 +
 drivers/pci/controller/dwc/Makefile           |   1 +
 drivers/pci/controller/dwc/pcie-andes-qilai.c | 240 ++++++++++++++++++
 3 files changed, 254 insertions(+)
 create mode 100644 drivers/pci/controller/dwc/pcie-andes-qilai.c
drivers/pci/controller/dwc/Kconfig +13 -0
index 349d4657393c..09ce40640e2f 100644
@@ -61,6 +61,19 @@ config PCI_MESON
 	  and therefore the driver re-uses the DesignWare core functions to
 	  implement the driver.
 
+config PCIE_ANDES_QILAI
+	tristate "Andes QiLai PCIe controller"
+	depends on ARCH_ANDES || COMPILE_TEST
+	depends on PCI_MSI
+	select PCIE_DW_HOST
+	help
+	  Say Y here to enable PCIe controller support on Andes QiLai SoCs,
+	  which operate in Root Complex mode. The Andes QiLai SoC PCIe
+	  controller is based on DesignWare IP (5.97a version) and therefore
+	  the driver re-uses the DesignWare core functions to implement the
+	  driver. The Andes QiLai SoC features three Root Complexes, each
+	  operating on PCIe 4.0.
+
 config PCIE_ARTPEC6
 	bool
 
drivers/pci/controller/dwc/Makefile +1 -0
index 7ae28f3b0fb3..5d3ec2d26275 100644
@@ -5,6 +5,7 @@ obj-$(CONFIG_PCIE_DW_HOST) += pcie-designware-host.o
 obj-$(CONFIG_PCIE_DW_EP) += pcie-designware-ep.o
 obj-$(CONFIG_PCIE_DW_PLAT) += pcie-designware-plat.o
 obj-$(CONFIG_PCIE_AMD_MDB) += pcie-amd-mdb.o
+obj-$(CONFIG_PCIE_ANDES_QILAI) += pcie-andes-qilai.o
 obj-$(CONFIG_PCIE_BT1) += pcie-bt1.o
 obj-$(CONFIG_PCI_DRA7XX) += pci-dra7xx.o
 obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o
drivers/pci/controller/dwc/pcie-andes-qilai.c new file +240 -0

240 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#8 lore raw

PATCH v8 5/5 MAINTAINERS: Add maintainers for Andes QiLai PCIe driver

In reply to Randolph Lin

Here add maintainer information for Andes QiLai PCIe driver.

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index 46126ce2f968..fb1d4daafe44 100644
@@ -19591,6 +19591,13 @@ S:	Supported
 F:	Documentation/devicetree/bindings/pci/altr,pcie-root-port.yaml
 F:	drivers/pci/controller/pcie-altera.c
 
+PCI DRIVER FOR ANDES QILAI PCIE
+M:	Randolph Lin <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/pci/andestech,qilai-pcie.yaml
+F:	drivers/pci/controller/dwc/pcie-andes-qilai.c
+
 PCI DRIVER FOR APPLIEDMICRO XGENE
 M:	Toan Le <[email protected]>
 L:	[email protected]
Signature · 1 line
2.34.1
maintainer
#3 lore raw

Re: [PATCH v8 2/5] dt-bindings: PCI: Add Andes QiLai PCIe support

In reply to Randolph Lin
Quoted 18 lines · Randolph Lin

Add the Andes QiLai PCIe node, which includes 3 Root Complexes. Only one example is required in the DTS bindings YAML file.

---
 .../bindings/pci/andestech,qilai-pcie.yaml    | 84 +++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/andestech,qilai-pcie.yaml
Documentation/devicetree/bindings/pci/andestech,qilai-pcie.yaml new file +3 -0
new file mode 100644
index 000000000000..ca444e4766ec
@@ -0,0 +1,84 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---

Documentation/devicetree/bindings/pci/andestech,qilai-pcie.yaml line 13

Quoted 10 lines
Documentation/devicetree/bindings/pci/andestech,qilai-pcie.yaml new file +10 -0
+$id: http://devicetree.org/schemas/pci/andestech,qilai-pcie.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Andes QiLai PCIe host controller
+
+description:
+  Andes QiLai PCIe host controller is based on the Synopsys DesignWare
+  PCI core. It shares common features with the PCIe DesignWare core and
+  inherits common properties defined in
+  Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml.

Drop the 2nd sentence as the schema says the same thing with the $ref.

Quoted 18 lines
Documentation/devicetree/bindings/pci/andestech,qilai-pcie.yaml new file +18 -0
+
+maintainers:
+  - Randolph Lin <[email protected]>
+
+allOf:
+  - $ref: /schemas/pci/snps,dw-pcie.yaml#
+
+properties:
+  compatible:
+    const: andestech,qilai-pcie
+
+  reg:
+    items:
+      - description: Data Bus Interface (DBI) registers.
+      - description: APB registers.
+      - description: PCIe configuration space region.
+
+  reg-names:

Documentation/devicetree/bindings/pci/andestech,qilai-pcie.yaml line 41

Quoted 10 lines
Documentation/devicetree/bindings/pci/andestech,qilai-pcie.yaml new file +10 -0
+    items:
+      - const: dbi
+      - const: apb
+      - const: config
+
+  ranges:
+    maxItems: 2
+
+  interrupts:
+    maxItems: 1

interrupt-names:
const: msi

Quoted 46 lines
Documentation/devicetree/bindings/pci/andestech,qilai-pcie.yaml new file +43 -0
+
+required:
+  - reg
+  - reg-names
+  - interrupts
+  - interrupt-names
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    soc {
+      #address-cells = <2>;
+      #size-cells = <2>;
+
+      pcie@80000000 {
+        compatible = "andestech,qilai-pcie";
+        device_type = "pci";
+        reg = <0x0 0x80000000 0x0 0x20000000>,
+              <0x0 0x04000000 0x0 0x00001000>,
+              <0x0 0x00000000 0x0 0x00010000>;
+        reg-names = "dbi", "apb", "config";
+
+        linux,pci-domain = <0>;
+        #address-cells = <3>;
+        #size-cells = <2>;
+        ranges = <0x02000000 0x00 0x10000000 0x00 0x10000000 0x0 0xf0000000>,
+                 <0x43000000 0x01 0x00000000 0x01 0x0000000 0x1f 0x00000000>;
+
+        #interrupt-cells = <1>;
+        interrupts = <0xf>;
+        interrupt-names = "msi";
+        interrupt-parent = <&plic0>;
+        interrupt-map-mask = <0 0 0 7>;
+        interrupt-map = <0 0 0 1 &plic0 0xf IRQ_TYPE_LEVEL_HIGH>,
+                        <0 0 0 2 &plic0 0xf IRQ_TYPE_LEVEL_HIGH>,
+                        <0 0 0 3 &plic0 0xf IRQ_TYPE_LEVEL_HIGH>,
+                        <0 0 0 4 &plic0 0xf IRQ_TYPE_LEVEL_HIGH>;
+      };
+    };
+...
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH v8 4/5] PCI: andes: Add Andes QiLai SoC PCIe host driver support

In reply to Randolph Lin
Quoted 5 lines · Randolph Lin

Add driver support for DesignWare based PCIe controller in Andes QiLai SoC. The driver only supports the Root Complex mode.

+ * Setup the Qilai PCIe IOCP (IO Coherence Port) Read/Write Behaviors to the
+ * Write-Back, Read and Write Allocate mode.

s/Setup/Set up/
s/Qilai/QiLai/

Quoted 24 lines

+ * The QiLai SoC PCIe controller's outbound iATU region supports
+ * a maximum size of SZ_4G - 1. To prevent programming failures,
+ * only consider bridge->windows with sizes within this limit.
+ *
+ * To ensure compatibility with most endpoint devices, at least
+ * one memory region must be mapped within the 32-bits address space.
+ */

drivers/pci/controller/dwc/pcie-andes-qilai.c new file +17 -0
+static int qilai_pcie_host_fix_ob_iatu_count(struct dw_pcie_rp *pp)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
+	struct device *dev = pci->dev;
+	struct resource_entry *entry;
+	/* Reserved 1 ob iATU for config space */
+	int count = 1;
+	bool ranges_32bits = false;
+	u64 pci_addr;
+	u64 size;
+
+	resource_list_for_each_entry(entry, &pp->bridge->windows) {
+		if (resource_type(entry->res) != IORESOURCE_MEM)
+			continue;
+
+		size = resource_size(entry->res);
+		if (size < SZ_4G)

drivers/pci/controller/dwc/pcie-andes-qilai.c line 159

Quoted 10 lines
drivers/pci/controller/dwc/pcie-andes-qilai.c new file +10 -0
+			count++;
+
+		pci_addr = entry->res->start - entry->offset;
+		if (pci_addr < SZ_4G)
+			ranges_32bits = true;
+	}
+
+	if (!ranges_32bits) {
+		dev_err(dev, "Bridge window must contain 32-bits address\n");
+		return -EINVAL;

Is this really a PCI host controller driver probe failure? I assume there are devices that only have 64-bit BARs and could work fine without a 32-bit window?

If a device requires a 32-bit BAR, and the PCI core can't assign such an address, and gracefully decline to enable a device where we couldn't assign the BAR, I think that would be preferable and would identify the specific device that doesn't work.

Quoted 6 lines
drivers/pci/controller/dwc/pcie-andes-qilai.c new file +6 -0
+	}
+
+	pci->num_ob_windows = count;
+
+	return 0;
+}
author maintainer
#7 lore raw

Re: [PATCH v8 4/5] PCI: andes: Add Andes QiLai SoC PCIe host driver support

Hello Bjorn,

Quoted 12 lines · Bjorn Helgaas

[EXTERNAL MAIL]

Quoted 5 lines · Randolph Lin

Add driver support for DesignWare based PCIe controller in Andes QiLai SoC. The driver only supports the Root Complex mode.

+ * Setup the Qilai PCIe IOCP (IO Coherence Port) Read/Write Behaviors to the
+ * Write-Back, Read and Write Allocate mode.

s/Setup/Set up/
s/Qilai/QiLai/

ok

Quoted 39 lines
Quoted 24 lines

+ * The QiLai SoC PCIe controller's outbound iATU region supports
+ * a maximum size of SZ_4G - 1. To prevent programming failures,
+ * only consider bridge->windows with sizes within this limit.
+ *
+ * To ensure compatibility with most endpoint devices, at least
+ * one memory region must be mapped within the 32-bits address space.
+ */

drivers/pci/controller/dwc/pcie-andes-qilai.c new file +17 -0
+static int qilai_pcie_host_fix_ob_iatu_count(struct dw_pcie_rp *pp)
+{
+     struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
+     struct device *dev = pci->dev;
+     struct resource_entry *entry;
+     /* Reserved 1 ob iATU for config space */
+     int count = 1;
+     bool ranges_32bits = false;
+     u64 pci_addr;
+     u64 size;
+
+     resource_list_for_each_entry(entry, &pp->bridge->windows) {
+             if (resource_type(entry->res) != IORESOURCE_MEM)
+                     continue;
+
+             size = resource_size(entry->res);
+             if (size < SZ_4G)

drivers/pci/controller/dwc/pcie-andes-qilai.c line 159

Quoted 10 lines
drivers/pci/controller/dwc/pcie-andes-qilai.c new file +10 -0
+                     count++;
+
+             pci_addr = entry->res->start - entry->offset;
+             if (pci_addr < SZ_4G)
+                     ranges_32bits = true;
+     }
+
+     if (!ranges_32bits) {
+             dev_err(dev, "Bridge window must contain 32-bits address\n");
+             return -EINVAL;

Is this really a PCI host controller driver probe failure? I assume there are devices that only have 64-bit BARs and could work fine without a 32-bit window?

Quoted 5 lines

If a device requires a 32-bit BAR, and the PCI core can't assign such an address, and gracefully decline to enable a device where we couldn't assign the BAR, I think that would be preferable and would identify the specific device that doesn't work.

I have a clear understanding of the meaning behind this.
However, based on reviewer Niklas's suggestion, I have decided to use patch [1]. As a result, the function that adjusts the number of ib/ob window is no longer needed.

[1]: https://lore.kernel.org/linux-pci/aPDObXsvMoz1OYso@ryzen/T/#m11c3d95215982411d0bbd36940e70122b70ae820

Quoted 7 lines

drivers/pci/controller/dwc/pcie-andes-qilai.c line 165

Quoted 6 lines
drivers/pci/controller/dwc/pcie-andes-qilai.c new file +6 -0
+     }
+
+     pci->num_ob_windows = count;
+
+     return 0;
+}

Sincerely,
Randolph Lin