Skip to contentSkip to conversation

Add support for AMD MDB IP as Root Port

PATCH Superseded Thippeswamy Havalige 5 participants 14 messages Feb 24, 2025 – Feb 25, 2025

Subsystems (4)

v14 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v14 cover Add support for AMD MDB IP as Root Port

This series of patch add support for AMD MDB IP as Root Port.

The AMD MDB IP support's 32 bit and 64bit BAR's at Gen5 speed. As Root Port it supports MSI and legacy interrupts.

Thippeswamy Havalige (3):
dt-bindings: PCI: dwc: Add AMD Versal2 mdb slcr support
dt-bindings: PCI: amd-mdb: Add AMD Versal2 MDB PCIe Root Port Bridge
PCI: amd-mdb: Add AMD MDB Root Port driver

 .../bindings/pci/amd,versal2-mdb-host.yaml    | 121 +++++
 .../devicetree/bindings/pci/snps,dw-pcie.yaml |   2 +
 drivers/pci/controller/dwc/Kconfig            |  11 +
 drivers/pci/controller/dwc/Makefile           |   1 +
 drivers/pci/controller/dwc/pcie-amd-mdb.c     | 481 ++++++++++++++++++
 5 files changed, 616 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/amd,versal2-mdb-host.yaml
 create mode 100644 drivers/pci/controller/dwc/pcie-amd-mdb.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v14 1/3 dt-bindings: PCI: dwc: Add AMD Versal2 mdb slcr support

Add support for mdb slcr aperture that is only supported for AMD Versal2 devices.

---
Changes in v3:
-------------
- Introduced below changes in dwc yaml schema.
Changes in v5:
-------------
- Modify mdb_pcie_slcr as constant.
Changes in v6:
-------------
-Modify slcr constant
Changes in v11:
-None

---
 Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml +2 -0
index 205326fb2d75..fdecfe6ad5f1 100644
@@ -113,6 +113,8 @@ properties:
               enum: [ smu, mpu ]
             - description: Tegra234 aperture
               enum: [ ecam ]
+            - description: AMD MDB PCIe slcr region
+              const: slcr
     allOf:
       - contains:
           const: dbi
Signature · 1 line
2.43.0
#2 lore raw

PATCH v14 2/3 dt-bindings: PCI: amd-mdb: Add AMD Versal2 MDB PCIe Root Port Bridge

In reply to Thippeswamy Havalige

Add AMD Versal2 MDB (Multimedia DMA Bridge) PCIe Root Port Bridge.

---
Changes in v2:
-------------
- Modify patch subject.
- Add pcie host bridge reference.
- Modify filename as per compatible string.
- Remove standard PCI properties.
- Modify interrupt controller description.
- Indentation

Changes in v3:
-------------
- Modified SLCR to lower case.
- Add dwc schemas.
- Remove common properties.
- Move additionalProperties below properties.
- Remove ranges property from required properties.
- Drop blank line.
- Modify pci@ to pcie@

Changes in v4:
-------------
- None.

Changes in v5:
-------------
- None.
Changes in v6:
--------------
- Reduce dbi size to 4k.
- update register name to slcr.
Changes in v7:
--------------
- Add reviewed-by
Changes in v10:
--------------
- None
Changes in v11:
---------------
- None
Changes in v12:
---------------
-None

---
 .../bindings/pci/amd,versal2-mdb-host.yaml    | 121 ++++++++++++++++++
 1 file changed, 121 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/amd,versal2-mdb-host.yaml
Documentation/devicetree/bindings/pci/amd,versal2-mdb-host.yaml new file +121 -0
new file mode 100644
index 000000000000..43dc2585c237
@@ -0,0 +1,121 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/amd,versal2-mdb-host.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: AMD Versal2 MDB(Multimedia DMA Bridge) Host Controller
+
+maintainers:
+  - Thippeswamy Havalige <[email protected]>
+
+allOf:
+  - $ref: /schemas/pci/pci-host-bridge.yaml#
+  - $ref: /schemas/pci/snps,dw-pcie.yaml#
+
+properties:
+  compatible:
+    const: amd,versal2-mdb-host
+
+  reg:
+    items:
+      - description: MDB System Level Control and Status Register (SLCR) Base
+      - description: configuration region
+      - description: data bus interface
+      - description: address translation unit register
+
+  reg-names:
+    items:
+      - const: slcr
+      - const: config
+      - const: dbi
+      - const: atu
+
+  ranges:
+    maxItems: 2
+
+  msi-map:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  interrupt-map-mask:
+    items:
+      - const: 0
+      - const: 0
+      - const: 0
+      - const: 7
+
+  interrupt-map:
+    maxItems: 4
+
+  "#interrupt-cells":
+    const: 1
+
+  interrupt-controller:
+    description: identifies the node as an interrupt controller
+    type: object
+    additionalProperties: false
+    properties:
+      interrupt-controller: true
+
+      "#address-cells":
+        const: 0
+
+      "#interrupt-cells":
+        const: 1
+
+    required:
+      - interrupt-controller
+      - "#address-cells"
+      - "#interrupt-cells"
+
+required:
+  - reg
+  - reg-names
+  - interrupts
+  - interrupt-map
+  - interrupt-map-mask
+  - msi-map
+  - "#interrupt-cells"
+  - interrupt-controller
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+        pcie@ed931000 {
+            compatible = "amd,versal2-mdb-host";
+            reg = <0x0 0xed931000 0x0 0x2000>,
+                  <0x1000 0x100000 0x0 0xff00000>,
+                  <0x1000 0x0 0x0 0x1000>,
+                  <0x0 0xed860000 0x0 0x2000>;
+            reg-names = "slcr", "config", "dbi", "atu";
+            ranges = <0x2000000 0x00 0xa0000000 0x00 0xa0000000 0x00 0x10000000>,
+                     <0x43000000 0x1100 0x00 0x1100 0x00 0x00 0x1000000>;
+            interrupts = <GIC_SPI 165 IRQ_TYPE_LEVEL_HIGH>;
+            interrupt-parent = <&gic>;
+            interrupt-map-mask = <0 0 0 7>;
+            interrupt-map = <0 0 0 1 &pcie_intc_0 0>,
+                            <0 0 0 2 &pcie_intc_0 1>,
+                            <0 0 0 3 &pcie_intc_0 2>,
+                            <0 0 0 4 &pcie_intc_0 3>;
+            msi-map = <0x0 &gic_its 0x00 0x10000>;
+            #address-cells = <3>;
+            #size-cells = <2>;
+            #interrupt-cells = <1>;
+            device_type = "pci";
+            pcie_intc_0: interrupt-controller {
+                #address-cells = <0>;
+                #interrupt-cells = <1>;
+                interrupt-controller;
+           };
+        };
+    };
Signature · 1 line
2.43.0
#3 lore raw

PATCH v14 3/3 PCI: amd-mdb: Add AMD MDB Root Port driver

In reply to Thippeswamy Havalige

Add support for AMD MDB (Multimedia DMA Bridge) IP core as Root Port.

The Versal2 devices include MDB Module. The integrated block for MDB along with the integrated bridge can function as PCIe Root Port controller at Gen5 32-Gb/s operation per lane.

Bridge supports error and legacy interrupts and are handled using platform specific interrupt line in Versal2.

| Reported-by: kernel test robot <[email protected]>
| Closes:
| https://lore.kernel.org/oe-kbuild-all/202502191741.xrVmEAG4-lkp@intel.
| com/

---
changes in v2:
-------------
- Update Gen5 speed in the patch description.
- Modify Kconfig file.
- Update string _leg_ to intx.
- Get platform structure through automic variables.
- Remove _rp_ in function.
Changes in v3:
--------------
-None.
Changes in v4:
--------------
-None.
Changes in v5:
--------------
-None.
Changes in v6:
--------------
- Remove pdev automatic variable.
- Update register name to slcr.
- Fix whitespace.
- remove Spurious extra line.
- Update Legacy to INTx.
- Add space before (SLCR).
- Update menuconfig description.
Changes in v7:
--------------
- None.
Changes in v8:
--------------
- Remove inline keyword.
- Fix indentations.
- Add AMD MDB prefix to interrupt names.
- Remove Kernel doc.
- Fix return types.
- Modify dev_warn to dev_warn_once.
- Add Intx handler & callbacks.
Changes in v10:
---------------
- Add intx assert & deassert macros.
- Move amd_mdb_pcie_init_port function.
- Add kernel doc for error warning messages. Changes in v11:
---------------
- Remove intx deassert macro & generic handler.
- Update Kconfig description.
- Update INTx mask macro to handle only asser bits.
- Move INTx handler.
- Address other review comments.
Changes in v12:
---------------
- ADD TLP_IR_DISABLE_MISC register.
- Modify intx call back function
Changes in v13:
- Add kernel doc for intx_irq
Changes in v14:
--------------
- Modify mask in intx_irq_mask/unmask functions.
- Modify mask in intx_flow handler.

---
 drivers/pci/controller/dwc/Kconfig        |  11 +
 drivers/pci/controller/dwc/Makefile       |   1 +
 drivers/pci/controller/dwc/pcie-amd-mdb.c | 481 ++++++++++++++++++++++
 3 files changed, 493 insertions(+)
 create mode 100644 drivers/pci/controller/dwc/pcie-amd-mdb.c
drivers/pci/controller/dwc/Kconfig +11 -0
index b6d6778b0698..882f4b558133 100644
@@ -27,6 +27,17 @@ config PCIE_AL
 	  required only for DT-based platforms. ACPI platforms with the
 	  Annapurna Labs PCIe controller don't need to enable this.
 
+config PCIE_AMD_MDB
+	bool "AMD MDB Versal2 PCIe Host controller"
+	depends on OF || COMPILE_TEST
+	depends on PCI && PCI_MSI
+	select PCIE_DW_HOST
+	help
+	  Say Y here if you want to enable PCIe controller support on AMD
+	  Versal2 SoCs. The AMD MDB Versal2 PCIe controller is based on
+	  DesignWare IP and therefore the driver re-uses the Designware core
+	  functions to implement the driver.
+
 config PCI_MESON
 	tristate "Amlogic Meson PCIe controller"
 	default m if ARCH_MESON
drivers/pci/controller/dwc/Makefile +1 -0
index a8308d9ea986..ae27eda6ec5e 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_PCIE_DW) += pcie-designware.o
 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_BT1) += pcie-bt1.o
 obj-$(CONFIG_PCI_DRA7XX) += pci-dra7xx.o
 obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +481 -0

481 lines not on this page · raw message

Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH v14 3/3] PCI: amd-mdb: Add AMD MDB Root Port driver

Quoted 6 lines · Thippeswamy Havalige

Add support for AMD MDB (Multimedia DMA Bridge) IP core as Root Port.

The Versal2 devices include MDB Module. The integrated block for MDB along with the integrated bridge can function as PCIe Root Port controller at Gen5 32-Gb/s operation per lane.

Quoted 8 lines

Bridge supports error and legacy interrupts and are handled using platform specific interrupt line in Versal2.

| Reported-by: kernel test robot <[email protected]>
| Closes:
| https://lore.kernel.org/oe-kbuild-all/202502191741.xrVmEAG4-lkp@intel.
| com/

Tags never start with | and are not wrapped. But anyway, robot did not report this patch. Drop these.

Best regards,
Krzysztof

#5 lore raw

RE: [PATCH v14 3/3] PCI: amd-mdb: Add AMD MDB Root Port driver

Hi Krzysztof,

Thank you for reviewing, Will remove it in next patch.

Regards,
Thippeswamy H

-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Monday, February 24, 2025 1:28 PM
To: Havalige, Thippeswamy <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; Gogada, Bharat Kumar <[email protected]>; [email protected]
Subject: Re: [PATCH v14 3/3] PCI: amd-mdb: Add AMD MDB Root Port driver

Quoted 7 lines · Thippeswamy Havalige

Add support for AMD MDB (Multimedia DMA Bridge) IP core as Root Port.

The Versal2 devices include MDB Module. The integrated block for MDB along with the integrated bridge can function as PCIe Root Port controller at
Gen5 32-Gb/s operation per lane.

Quoted 8 lines

Bridge supports error and legacy interrupts and are handled using platform specific interrupt line in Versal2.

| Reported-by: kernel test robot <[email protected]>
| Closes:
| https://lore.kernel.org/oe-kbuild-all/202502191741.xrVmEAG4-lkp@intel.
| com/

Tags never start with | and are not wrapped. But anyway, robot did not report this patch. Drop these.

Best regards,
Krzysztof

#6 lore raw

Re: [PATCH v14 3/3] PCI: amd-mdb: Add AMD MDB Root Port driver

In reply to Thippeswamy Havalige
Quoted 5 lines · Thippeswamy Havalige

Add support for AMD MDB (Multimedia DMA Bridge) IP core as Root Port.

The Versal2 devices include MDB Module. The integrated block for MDB along with the integrated bridge can function as PCIe Root Port controller at Gen5 32-Gb/s operation per lane.

Please use GT/s

Quoted 9 lines

Bridge supports error and legacy interrupts and are handled using platform specific interrupt line in Versal2.

| Reported-by: kernel test robot <[email protected]>
| Closes:
| https://lore.kernel.org/oe-kbuild-all/202502191741.xrVmEAG4-lkp@intel.
| com/

These tags are irrelevant.

Quoted 127 lines

---
changes in v2:
-------------
- Update Gen5 speed in the patch description.
- Modify Kconfig file.
- Update string _leg_ to intx.
- Get platform structure through automic variables.
- Remove _rp_ in function.
Changes in v3:
--------------
-None.
Changes in v4:
--------------
-None.
Changes in v5:
--------------
-None.
Changes in v6:
--------------
- Remove pdev automatic variable.
- Update register name to slcr.
- Fix whitespace.
- remove Spurious extra line.
- Update Legacy to INTx.
- Add space before (SLCR).
- Update menuconfig description.
Changes in v7:
--------------
- None.
Changes in v8:
--------------
- Remove inline keyword.
- Fix indentations.
- Add AMD MDB prefix to interrupt names.
- Remove Kernel doc.
- Fix return types.
- Modify dev_warn to dev_warn_once.
- Add Intx handler & callbacks.
Changes in v10:
---------------
- Add intx assert & deassert macros.
- Move amd_mdb_pcie_init_port function.
- Add kernel doc for error warning messages. Changes in v11:
---------------
- Remove intx deassert macro & generic handler.
- Update Kconfig description.
- Update INTx mask macro to handle only asser bits.
- Move INTx handler.
- Address other review comments.
Changes in v12:
---------------
- ADD TLP_IR_DISABLE_MISC register.
- Modify intx call back function
Changes in v13:
- Add kernel doc for intx_irq
Changes in v14:
--------------
- Modify mask in intx_irq_mask/unmask functions.
- Modify mask in intx_flow handler.

---
 drivers/pci/controller/dwc/Kconfig        |  11 +
 drivers/pci/controller/dwc/Makefile       |   1 +
 drivers/pci/controller/dwc/pcie-amd-mdb.c | 481 ++++++++++++++++++++++
 3 files changed, 493 insertions(+)
 create mode 100644 drivers/pci/controller/dwc/pcie-amd-mdb.c
drivers/pci/controller/dwc/Kconfig +11 -0
index b6d6778b0698..882f4b558133 100644
@@ -27,6 +27,17 @@ config PCIE_AL
 	  required only for DT-based platforms. ACPI platforms with the
 	  Annapurna Labs PCIe controller don't need to enable this.
 
+config PCIE_AMD_MDB
+	bool "AMD MDB Versal2 PCIe Host controller"
+	depends on OF || COMPILE_TEST
+	depends on PCI && PCI_MSI
+	select PCIE_DW_HOST
+	help
+	  Say Y here if you want to enable PCIe controller support on AMD
+	  Versal2 SoCs. The AMD MDB Versal2 PCIe controller is based on
+	  DesignWare IP and therefore the driver re-uses the Designware core
+	  functions to implement the driver.
+
 config PCI_MESON
 	tristate "Amlogic Meson PCIe controller"
 	default m if ARCH_MESON
drivers/pci/controller/dwc/Makefile +1 -0
index a8308d9ea986..ae27eda6ec5e 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_PCIE_DW) += pcie-designware.o
 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_BT1) += pcie-bt1.o
 obj-$(CONFIG_PCI_DRA7XX) += pci-dra7xx.o
 obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +20 -0
new file mode 100644
index 000000000000..01d27cb5a70d
@@ -0,0 +1,481 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * PCIe host controller driver for AMD MDB PCIe Bridge
+ *
+ * Copyright (C) 2024-2025, Advanced Micro Devices, Inc.
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/gpio.h>
+#include <linux/interrupt.h>
+#include <linux/irqdomain.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/of_device.h>
+#include <linux/pci.h>
+#include <linux/platform_device.h>
+#include <linux/resource.h>
+#include <linux/types.h>
+

drivers/pci/controller/dwc/pcie-amd-mdb.c line 30

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+#include "pcie-designware.h"
+
+#define AMD_MDB_TLP_IR_STATUS_MISC		0x4C0
+#define AMD_MDB_TLP_IR_MASK_MISC		0x4C4
+#define AMD_MDB_TLP_IR_ENABLE_MISC		0x4C8
+#define AMD_MDB_TLP_IR_DISABLE_MISC		0x4CC
+
+#define AMD_MDB_TLP_PCIE_INTX_MASK	GENMASK(23, 16)
+
+#define AMD_MDB_PCIE_INTR_INTX_ASSERT(x)	BIT((x) * 2)

How does these values correspond to the AMD_MDB_TLP_PCIE_INTX_MASK? These values could be: 0, 2, 4, and 6 corresponding to: 0b01010101? Looks wierd.

Quoted 35 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +35 -0
+
+/* Interrupt registers definitions */
+#define AMD_MDB_PCIE_INTR_CMPL_TIMEOUT		15
+#define AMD_MDB_PCIE_INTR_INTX			16
+#define AMD_MDB_PCIE_INTR_PM_PME_RCVD		24
+#define AMD_MDB_PCIE_INTR_PME_TO_ACK_RCVD	25
+#define AMD_MDB_PCIE_INTR_MISC_CORRECTABLE	26
+#define AMD_MDB_PCIE_INTR_NONFATAL		27
+#define AMD_MDB_PCIE_INTR_FATAL			28
+
+#define IMR(x) BIT(AMD_MDB_PCIE_INTR_ ##x)
+#define AMD_MDB_PCIE_IMR_ALL_MASK			\
+	(						\
+		IMR(CMPL_TIMEOUT)	|		\
+		IMR(PM_PME_RCVD)	|		\
+		IMR(PME_TO_ACK_RCVD)	|		\
+		IMR(MISC_CORRECTABLE)	|		\
+		IMR(NONFATAL)		|		\
+		IMR(FATAL)		|		\
+		AMD_MDB_TLP_PCIE_INTX_MASK		\
+	)
+
+/**
+ * struct amd_mdb_pcie - PCIe port information
+ * @pci: DesignWare PCIe controller structure
+ * @slcr: MDB System Level Control and Status Register (SLCR) Base
+ * @intx_domain: INTx IRQ domain pointer
+ * @mdb_domain: MDB IRQ domain pointer
+ * @intx_irq: INTx IRQ interrupt number
+ */
+struct amd_mdb_pcie {
+	struct dw_pcie			pci;
+	void __iomem			*slcr;
+	struct irq_domain		*intx_domain;
+	struct irq_domain		*mdb_domain;

drivers/pci/controller/dwc/pcie-amd-mdb.c line 75

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+	int				intx_irq;
+};
+
+static const struct dw_pcie_host_ops amd_mdb_pcie_host_ops = {
+};
+
+static inline u32 pcie_read(struct amd_mdb_pcie *pcie, u32 reg)
+{
+	return readl_relaxed(pcie->slcr + reg);
+}

I think I already commented on these helpers. Please get rid of them. I don't see any value in this new driver. Moreover, 'inline' keywords are not required.

Quoted 69 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +69 -0
+
+static inline void pcie_write(struct amd_mdb_pcie *pcie,
+			      u32 val, u32 reg)
+{
+	writel_relaxed(val, pcie->slcr + reg);
+}
+
+static void amd_mdb_intx_irq_mask(struct irq_data *data)
+{
+	struct amd_mdb_pcie *pcie = irq_data_get_irq_chip_data(data);
+	struct dw_pcie *pci = &pcie->pci;
+	struct dw_pcie_rp *port = &pci->pp;
+	unsigned long flags;
+	u32 val;
+
+	raw_spin_lock_irqsave(&port->lock, flags);
+	val = FIELD_PREP(AMD_MDB_TLP_PCIE_INTX_MASK,
+			 AMD_MDB_PCIE_INTR_INTX_ASSERT(data->hwirq));
+
+	/*
+	 * Writing '1' to a bit in AMD_MDB_TLP_IR_DISABLE_MISC disables that
+	 * interrupt, writing '0' has no effect.
+	 */
+	pcie_write(pcie, val, AMD_MDB_TLP_IR_DISABLE_MISC);
+	raw_spin_unlock_irqrestore(&port->lock, flags);
+}
+
+static void amd_mdb_intx_irq_unmask(struct irq_data *data)
+{
+	struct amd_mdb_pcie *pcie = irq_data_get_irq_chip_data(data);
+	struct dw_pcie *pci = &pcie->pci;
+	struct dw_pcie_rp *port = &pci->pp;
+	unsigned long flags;
+	u32 val;
+
+	raw_spin_lock_irqsave(&port->lock, flags);
+	val = FIELD_PREP(AMD_MDB_TLP_PCIE_INTX_MASK,
+			 AMD_MDB_PCIE_INTR_INTX_ASSERT(data->hwirq));
+
+	/*
+	 * Writing '1' to a bit in AMD_MDB_TLP_IR_ENABLE_MISC enables that interrupt.
+	 * Writing '0' has no effect.
+	 */
+	pcie_write(pcie, val, AMD_MDB_TLP_IR_ENABLE_MISC);
+	raw_spin_unlock_irqrestore(&port->lock, flags);
+}
+
+static struct irq_chip amd_mdb_intx_irq_chip = {
+	.name		= "AMD MDB INTx",
+	.irq_mask	= amd_mdb_intx_irq_mask,
+	.irq_unmask	= amd_mdb_intx_irq_unmask,
+};
+
+/**
+ * amd_mdb_pcie_intx_map - Set the handler for the INTx and mark IRQ
+ * as valid
+ * @domain: IRQ domain
+ * @irq: Virtual IRQ number
+ * @hwirq: HW interrupt number
+ *
+ * Return: Always returns 0.
+ */
+static int amd_mdb_pcie_intx_map(struct irq_domain *domain,
+				 unsigned int irq, irq_hw_number_t hwirq)
+{
+	irq_set_chip_and_handler(irq, &amd_mdb_intx_irq_chip,
+				 handle_level_irq);
+	irq_set_chip_data(irq, domain->host_data);
+	irq_set_status_flags(irq, IRQ_LEVEL);

drivers/pci/controller/dwc/pcie-amd-mdb.c line 154

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+
+	return 0;
+}
+
+/* INTx IRQ Domain operations */
+static const struct irq_domain_ops amd_intx_domain_ops = {
+	.map = amd_mdb_pcie_intx_map,
+};
+
+static irqreturn_t dw_pcie_rp_intx_flow(int irq, void *args)

What does the _flow suffix mean?

drivers/pci/controller/dwc/pcie-amd-mdb.c line 160

Quoted 6 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +6 -0
+{
+	struct amd_mdb_pcie *pcie = args;
+	unsigned long val;
+	int i, int_status;
+
+	val = pcie_read(pcie, AMD_MDB_TLP_IR_STATUS_MISC);

You don't need port->lock here?

drivers/pci/controller/dwc/pcie-amd-mdb.c line 161

Quoted 1 line
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +1 -0
+	int_status = FIELD_GET(AMD_MDB_TLP_PCIE_INTX_MASK, val);

You don't need to ack/clear the IRQ?

Quoted 22 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +22 -0
+
+	for (i = 0; i < PCI_NUM_INTX; i++) {
+		if (int_status & AMD_MDB_PCIE_INTR_INTX_ASSERT(i))
+			generic_handle_domain_irq(pcie->intx_domain, i);
+	}
+
+	return IRQ_HANDLED;
+}
+
+#define _IC(x, s)[AMD_MDB_PCIE_INTR_ ## x] = { __stringify(x), s }
+
+static const struct {
+	const char	*sym;
+	const char	*str;
+} intr_cause[32] = {
+	_IC(CMPL_TIMEOUT,	"completion timeout"),
+	_IC(PM_PME_RCVD,	"PM_PME message received"),
+	_IC(PME_TO_ACK_RCVD,	"PME_TO_ACK message received"),
+	_IC(MISC_CORRECTABLE,	"Correctable error message"),
+	_IC(NONFATAL,		"Non fatal error message"),
+	_IC(FATAL,		"Fatal error message"),
+};

drivers/pci/controller/dwc/pcie-amd-mdb.c line 193

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+
+static void amd_mdb_event_irq_mask(struct irq_data *d)
+{
+	struct amd_mdb_pcie *pcie = irq_data_get_irq_chip_data(d);
+	struct dw_pcie *pci = &pcie->pci;
+	struct dw_pcie_rp *port = &pci->pp;
+	u32 val;
+
+	raw_spin_lock(&port->lock);
+	val = pcie_read(pcie, AMD_MDB_TLP_IR_STATUS_MISC);

This register is accessed in the IRQ handler also. So don't you need raw_spin_lock_irq{save/restore}?

drivers/pci/controller/dwc/pcie-amd-mdb.c line 206

Quoted 13 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +13 -0
+	val &= ~BIT(d->hwirq);
+	pcie_write(pcie, val, AMD_MDB_TLP_IR_STATUS_MISC);
+	raw_spin_unlock(&port->lock);
+}
+
+static void amd_mdb_event_irq_unmask(struct irq_data *d)
+{
+	struct amd_mdb_pcie *pcie = irq_data_get_irq_chip_data(d);
+	struct dw_pcie *pci = &pcie->pci;
+	struct dw_pcie_rp *port = &pci->pp;
+	u32 val;
+
+	raw_spin_lock(&port->lock);

Same here

Quoted 24 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +24 -0
+	val = pcie_read(pcie, AMD_MDB_TLP_IR_STATUS_MISC);
+	val |= BIT(d->hwirq);
+	pcie_write(pcie, val, AMD_MDB_TLP_IR_STATUS_MISC);
+	raw_spin_unlock(&port->lock);
+}
+
+static struct irq_chip amd_mdb_event_irq_chip = {
+	.name		= "AMD MDB RC-Event",
+	.irq_mask	= amd_mdb_event_irq_mask,
+	.irq_unmask	= amd_mdb_event_irq_unmask,
+};
+
+static int amd_mdb_pcie_event_map(struct irq_domain *domain,
+				  unsigned int irq, irq_hw_number_t hwirq)
+{
+	irq_set_chip_and_handler(irq, &amd_mdb_event_irq_chip,
+				 handle_level_irq);
+	irq_set_chip_data(irq, domain->host_data);
+	irq_set_status_flags(irq, IRQ_LEVEL);
+
+	return 0;
+}
+
+static const struct irq_domain_ops event_domain_ops = {

drivers/pci/controller/dwc/pcie-amd-mdb.c line 240

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+	.map = amd_mdb_pcie_event_map,
+};
+
+static irqreturn_t amd_mdb_pcie_event_flow(int irq, void *args)
+{
+	struct amd_mdb_pcie *pcie = args;
+	unsigned long val;
+	int i;
+
+	val = pcie_read(pcie, AMD_MDB_TLP_IR_STATUS_MISC);

Here also, no lock?

Quoted 45 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +45 -0
+	val &= ~pcie_read(pcie, AMD_MDB_TLP_IR_MASK_MISC);
+	for_each_set_bit(i, &val, 32)
+		generic_handle_domain_irq(pcie->mdb_domain, i);
+	pcie_write(pcie, val, AMD_MDB_TLP_IR_STATUS_MISC);
+
+	return IRQ_HANDLED;
+}
+
+static void amd_mdb_pcie_free_irq_domains(struct amd_mdb_pcie *pcie)
+{
+	if (pcie->intx_domain) {
+		irq_domain_remove(pcie->intx_domain);
+		pcie->intx_domain = NULL;
+	}
+
+	if (pcie->mdb_domain) {
+		irq_domain_remove(pcie->mdb_domain);
+		pcie->mdb_domain = NULL;
+	}
+}
+
+static int amd_mdb_pcie_init_port(struct amd_mdb_pcie *pcie)
+{
+	/* Disable all TLP Interrupts */
+	pcie_write(pcie, AMD_MDB_PCIE_IMR_ALL_MASK,
+		   AMD_MDB_TLP_IR_DISABLE_MISC);
+
+	/* Clear pending TLP interrupts */
+	pcie_write(pcie, pcie_read(pcie, AMD_MDB_TLP_IR_STATUS_MISC) &
+		   AMD_MDB_PCIE_IMR_ALL_MASK,
+		   AMD_MDB_TLP_IR_STATUS_MISC);
+
+	/* Enable all TLP Interrupts */
+	pcie_write(pcie,  AMD_MDB_PCIE_IMR_ALL_MASK,
+		   AMD_MDB_TLP_IR_ENABLE_MISC);
+
+	return 0;
+}
+
+/**
+ * amd_mdb_pcie_init_irq_domains - Initialize IRQ domain
+ * @pcie: PCIe port information
+ * @pdev: platform device
+ * Return: '0' on success and error value on failure
+ */

drivers/pci/controller/dwc/pcie-amd-mdb.c line 295

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+static int amd_mdb_pcie_init_irq_domains(struct amd_mdb_pcie *pcie,
+					 struct platform_device *pdev)
+{
+	struct dw_pcie *pci = &pcie->pci;
+	struct dw_pcie_rp *pp = &pci->pp;
+	struct device *dev = &pdev->dev;
+	struct device_node *node = dev->of_node;
+	struct device_node *pcie_intc_node;
+
+	/* Setup INTx */

This comment is quite misleading. This Intc node is not specific to INTx as far as I can see.

drivers/pci/controller/dwc/pcie-amd-mdb.c line 299

Quoted 4 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +4 -0
+	pcie_intc_node = of_get_next_child(node, NULL);
+	if (!pcie_intc_node) {
+		dev_err(dev, "No PCIe Intc node found\n");
+		return -ENODATA;

-ENODEV

Quoted 20 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +20 -0
+	}
+
+	pcie->mdb_domain = irq_domain_add_linear(pcie_intc_node, 32,
+						 &event_domain_ops, pcie);
+	if (!pcie->mdb_domain) {
+		dev_err(dev, "Failed to add mdb_domain\n");
+		goto out;
+	}
+
+	irq_domain_update_bus_token(pcie->mdb_domain, DOMAIN_BUS_NEXUS);
+
+	pcie->intx_domain = irq_domain_add_linear(pcie_intc_node, PCI_NUM_INTX,
+						  &amd_intx_domain_ops, pcie);
+	if (!pcie->intx_domain) {
+		dev_err(dev, "Failed to add intx_domain\n");
+		goto mdb_out;
+	}
+
+	of_node_put(pcie_intc_node);
+	irq_domain_update_bus_token(pcie->intx_domain, DOMAIN_BUS_WIRED);

drivers/pci/controller/dwc/pcie-amd-mdb.c line 329

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+
+	raw_spin_lock_init(&pp->lock);
+
+	return 0;
+mdb_out:
+	amd_mdb_pcie_free_irq_domains(pcie);
+out:
+	of_node_put(pcie_intc_node);
+
+	return -ENOMEM;

No please. This is just asking for trouble. Please pass the relevant errno.

Quoted 38 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +38 -0
+}
+
+static irqreturn_t amd_mdb_pcie_intr_handler(int irq, void *args)
+{
+	struct amd_mdb_pcie *pcie = args;
+	struct device *dev;
+	struct irq_data *d;
+
+	dev = pcie->pci.dev;
+
+	/*
+	 * In future, error reporting will be hooked to the AER subsystem.
+	 * Currently, the driver prints a warning message to the user.
+	 */
+	d = irq_domain_get_irq_data(pcie->mdb_domain, irq);
+	if (intr_cause[d->hwirq].str)
+		dev_warn(dev, "%s\n", intr_cause[d->hwirq].str);
+	else
+		dev_warn_once(dev, "Unknown IRQ %ld\n", d->hwirq);
+
+	return IRQ_HANDLED;
+}
+
+static int amd_mdb_setup_irq(struct amd_mdb_pcie *pcie,
+			     struct platform_device *pdev)
+{
+	struct dw_pcie *pci = &pcie->pci;
+	struct dw_pcie_rp *pp = &pci->pp;
+	struct device *dev = &pdev->dev;
+	int i, irq, err;
+
+	amd_mdb_pcie_init_port(pcie);
+
+	pp->irq = platform_get_irq(pdev, 0);
+	if (pp->irq < 0)
+		return pp->irq;
+
+	for (i = 0; i < ARRAY_SIZE(intr_cause); i++) {

drivers/pci/controller/dwc/pcie-amd-mdb.c line 377

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+		if (!intr_cause[i].str)
+			continue;
+		irq = irq_create_mapping(pcie->mdb_domain, i);
+		if (!irq) {
+			dev_err(dev, "Failed to map mdb domain interrupt\n");
+			return -ENOMEM;
+		}
+		err = devm_request_irq(dev, irq, amd_mdb_pcie_intr_handler,
+				       IRQF_SHARED | IRQF_NO_THREAD,
+				       intr_cause[i].sym, pcie);

Aren't these IRQs just part of a single IRQ? I'm wondering why do you need to represent them individually instead of having a single IRQ handler.

Btw, you are not disposing these IRQs anywhere. Especially in error paths.

Quoted 14 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +14 -0
+		if (err) {
+			dev_err(dev, "Failed to request IRQ %d\n", irq);
+			return err;
+		}
+	}
+
+	pcie->intx_irq = irq_create_mapping(pcie->mdb_domain,
+					    AMD_MDB_PCIE_INTR_INTX);
+	if (!pcie->intx_irq) {
+		dev_err(dev, "Failed to map INTx interrupt\n");
+		return -ENXIO;
+	}
+
+	err = devm_request_irq(dev, pcie->intx_irq,

drivers/pci/controller/dwc/pcie-amd-mdb.c line 401

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+			       dw_pcie_rp_intx_flow,
+			       IRQF_SHARED | IRQF_NO_THREAD, NULL, pcie);
+	if (err) {
+		dev_err(dev, "Failed to request INTx IRQ %d\n", irq);
+		return err;
+	}
+
+	/* Plug the main event handler */
+	err = devm_request_irq(dev, pp->irq, amd_mdb_pcie_event_flow,
+			       IRQF_SHARED | IRQF_NO_THREAD, "amd_mdb pcie_irq",

Why is this a SHARED IRQ?

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
#7 lore raw

RE: [PATCH v14 3/3] PCI: amd-mdb: Add AMD MDB Root Port driver

Hi Manivannan,

-----Original Message-----
From: Manivannan Sadhasivam <[email protected]>
Sent: Monday, February 24, 2025 3:00 PM
To: Havalige, Thippeswamy <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; Gogada, Bharat Kumar <[email protected]>; [email protected]
Subject: Re: [PATCH v14 3/3] PCI: amd-mdb: Add AMD MDB Root Port driver

Quoted 6 lines · Thippeswamy Havalige

Add support for AMD MDB (Multimedia DMA Bridge) IP core as Root Port.

The Versal2 devices include MDB Module. The integrated block for MDB along with the integrated bridge can function as PCIe Root Port controller at
Gen5 32-Gb/s operation per lane.

Please use GT/s

Thank you for reviewing, ll update this in next patch.

Quoted 9 lines

Bridge supports error and legacy interrupts and are handled using platform specific interrupt line in Versal2.

| Reported-by: kernel test robot <[email protected]>
| Closes:
| https://lore.kernel.org/oe-kbuild-all/202502191741.xrVmEAG4-lkp@intel.
| com/

These tags are irrelevant.
Thank you for reviewing, Will remove this in next patch.

Quoted 131 lines

---
changes in v2:
-------------
- Update Gen5 speed in the patch description.
- Modify Kconfig file.
- Update string _leg_ to intx.
- Get platform structure through automic variables.
- Remove _rp_ in function.
Changes in v3:
--------------
-None.
Changes in v4:
--------------
-None.
Changes in v5:
--------------
-None.
Changes in v6:
--------------
- Remove pdev automatic variable.
- Update register name to slcr.
- Fix whitespace.
- remove Spurious extra line.
- Update Legacy to INTx.
- Add space before (SLCR).
- Update menuconfig description.
Changes in v7:
--------------
- None.
Changes in v8:
--------------
- Remove inline keyword.
- Fix indentations.
- Add AMD MDB prefix to interrupt names.
- Remove Kernel doc.
- Fix return types.
- Modify dev_warn to dev_warn_once.
- Add Intx handler & callbacks.
Changes in v10:
---------------
- Add intx assert & deassert macros.
- Move amd_mdb_pcie_init_port function.
- Add kernel doc for error warning messages. Changes in v11:
---------------
- Remove intx deassert macro & generic handler.
- Update Kconfig description.
- Update INTx mask macro to handle only asser bits.
- Move INTx handler.
- Address other review comments.
Changes in v12:
---------------
- ADD TLP_IR_DISABLE_MISC register.
- Modify intx call back function
Changes in v13:
- Add kernel doc for intx_irq
Changes in v14:
--------------
- Modify mask in intx_irq_mask/unmask functions.
- Modify mask in intx_flow handler.

---
 drivers/pci/controller/dwc/Kconfig        |  11 +
 drivers/pci/controller/dwc/Makefile       |   1 +
 drivers/pci/controller/dwc/pcie-amd-mdb.c | 481
++++++++++++++++++++++
 3 files changed, 493 insertions(+)
 create mode 100644 drivers/pci/controller/dwc/pcie-amd-mdb.c
drivers/pci/controller/dwc/Kconfig +11 -0
index b6d6778b0698..882f4b558133 100644
@@ -27,6 +27,17 @@ config PCIE_AL
 	  required only for DT-based platforms. ACPI platforms with the
 	  Annapurna Labs PCIe controller don't need to enable this.
 
+config PCIE_AMD_MDB
+	bool "AMD MDB Versal2 PCIe Host controller"
+	depends on OF || COMPILE_TEST
+	depends on PCI && PCI_MSI
+	select PCIE_DW_HOST
+	help
+	  Say Y here if you want to enable PCIe controller support on AMD
+	  Versal2 SoCs. The AMD MDB Versal2 PCIe controller is based on
+	  DesignWare IP and therefore the driver re-uses the Designware core
+	  functions to implement the driver.
+
 config PCI_MESON
 	tristate "Amlogic Meson PCIe controller"
 	default m if ARCH_MESON
drivers/pci/controller/dwc/Makefile +1 -0
index a8308d9ea986..ae27eda6ec5e 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_PCIE_DW) += pcie-designware.o
 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_BT1) += pcie-bt1.o
 obj-$(CONFIG_PCI_DRA7XX) += pci-dra7xx.o
 obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o diff --git 

a/drivers/pci/controller/dwc/pcie-amd-mdb.c
b/drivers/pci/controller/dwc/pcie-amd-mdb.c
new file mode 100644
index 000000000000..01d27cb5a70d

drivers/pci/controller/dwc/pcie-amd-mdb.c new file +20 -0
@@ -0,0 +1,481 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * PCIe host controller driver for AMD MDB PCIe Bridge
+ *
+ * Copyright (C) 2024-2025, Advanced Micro Devices, Inc.
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/gpio.h>
+#include <linux/interrupt.h>
+#include <linux/irqdomain.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/of_device.h>
+#include <linux/pci.h>
+#include <linux/platform_device.h>
+#include <linux/resource.h>
+#include <linux/types.h>
+

drivers/pci/controller/dwc/pcie-amd-mdb.c line 30

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+#include "pcie-designware.h"
+
+#define AMD_MDB_TLP_IR_STATUS_MISC		0x4C0
+#define AMD_MDB_TLP_IR_MASK_MISC		0x4C4
+#define AMD_MDB_TLP_IR_ENABLE_MISC		0x4C8
+#define AMD_MDB_TLP_IR_DISABLE_MISC		0x4CC
+
+#define AMD_MDB_TLP_PCIE_INTX_MASK	GENMASK(23, 16)
+
+#define AMD_MDB_PCIE_INTR_INTX_ASSERT(x)	BIT((x) * 2)

How does these values correspond to the AMD_MDB_TLP_PCIE_INTX_MASK? These values could be: 0, 2, 4, and 6 corresponding to: 0b01010101? Looks wierd. Thank you for reviewing, Yes in register status/Enable/Disable register bits are laid in this way.

drivers/pci/controller/dwc/pcie-amd-mdb.c

Quoted 9 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +7 -0
+
+/* Interrupt registers definitions */
+#define AMD_MDB_PCIE_INTR_CMPL_TIMEOUT		15
+#define AMD_MDB_PCIE_INTR_INTX			16
+#define AMD_MDB_PCIE_INTR_PM_PME_RCVD		24
 
 
+static inline u32 pcie_read(struct amd_mdb_pcie *pcie, u32 reg) {
+	return readl_relaxed(pcie->slcr + reg); }

I think I already commented on these helpers. Please get rid of them. I don't see any value in this new driver. Moreover, 'inline' keywords are not required. Thanks for the review. While I agree to remove the 'inline', I would like pcie_read/pcie_write APIs. Could you please clarify the reason for explicitly removing pcie_read/pcie_write here? If I remove the pcie_read/pcie_write, it will require changes in multiple places throughout the code."

drivers/pci/controller/dwc/pcie-amd-mdb.c line 154

Quoted 11 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +11 -0
+
+static inline void pcie_write(struct amd_mdb_pcie *pcie,
+			      u32 val, u32 reg)
+{
+	writel_relaxed(val, pcie->slcr + reg); }
+
+static const struct irq_domain_ops amd_intx_domain_ops = {
+	.map = amd_mdb_pcie_intx_map,
+};
+
+static irqreturn_t dw_pcie_rp_intx_flow(int irq, void *args)

What does the _flow suffix mean?
Thanks for reviewing, The _flow suffix in the function name dw_pcie_rp_intx_flow indicates that the function handles the flow or processing related to interrupt handling for the PCIe root port's INTx interrupts through generic_handle_domain_irq.

drivers/pci/controller/dwc/pcie-amd-mdb.c line 160

Quoted 6 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +6 -0
+{
+	struct amd_mdb_pcie *pcie = args;
+	unsigned long val;
+	int i, int_status;
+
+	val = pcie_read(pcie, AMD_MDB_TLP_IR_STATUS_MISC);

You don't need port->lock here?
Thank you for reviewing. In this case, I'm simply reading the status of the INTX register bits without modifying any registers. Since no shared resources are being updated or accessed concurrently, there’s no need for a lock here.

drivers/pci/controller/dwc/pcie-amd-mdb.c line 161

Quoted 1 line
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +1 -0
+	int_status = FIELD_GET(AMD_MDB_TLP_PCIE_INTX_MASK, val);

You don't need to ack/clear the IRQ?
- Thank you for reviewing, Thank you for reviewing. In this case, I am using IRQ domains, and the generic_handle_domain_irq function will invoke the necessary irq_mask and irq_unmask operations internally, which will take care of clearing the IRQ.

Quoted 7 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +7 -0
+
+	for (i = 0; i < PCI_NUM_INTX; i++) {
+		if (int_status & AMD_MDB_PCIE_INTR_INTX_ASSERT(i))
+			generic_handle_domain_irq(pcie->intx_domain, i);
+	}
+
+	return IRQ_HANDLED;

drivers/pci/controller/dwc/pcie-amd-mdb.c line 193

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+}
+
+static void amd_mdb_event_irq_mask(struct irq_data *d) {
+	struct amd_mdb_pcie *pcie = irq_data_get_irq_chip_data(d);
+	struct dw_pcie *pci = &pcie->pci;
+	struct dw_pcie_rp *port = &pci->pp;
+	u32 val;
+
+	raw_spin_lock(&port->lock);
+	val = pcie_read(pcie, AMD_MDB_TLP_IR_STATUS_MISC);

This register is accessed in the IRQ handler also. So don't you need raw_spin_lock_irq{save/restore}?
- Thank you for reviewing, In handler I am just reading the status & calling this irq_mask/irq_unmask API's I don't need to have save/restore spin_lock_irq's here.

drivers/pci/controller/dwc/pcie-amd-mdb.c line 206

Quoted 12 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +12 -0
+	val &= ~BIT(d->hwirq);
+	pcie_write(pcie, val, AMD_MDB_TLP_IR_STATUS_MISC);
+	raw_spin_unlock(&port->lock);
+}
+
+static void amd_mdb_event_irq_unmask(struct irq_data *d) {
+	struct amd_mdb_pcie *pcie = irq_data_get_irq_chip_data(d);
+	struct dw_pcie *pci = &pcie->pci;
+	struct dw_pcie_rp *port = &pci->pp;
+	u32 val;
+
+	raw_spin_lock(&port->lock);

Same here

Quoted 22 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +22 -0
+	val = pcie_read(pcie, AMD_MDB_TLP_IR_STATUS_MISC);
+	val |= BIT(d->hwirq);
+	pcie_write(pcie, val, AMD_MDB_TLP_IR_STATUS_MISC);
+	raw_spin_unlock(&port->lock);
+}
+
+static struct irq_chip amd_mdb_event_irq_chip = {
+	.name		= "AMD MDB RC-Event",
+	.irq_mask	= amd_mdb_event_irq_mask,
+	.irq_unmask	= amd_mdb_event_irq_unmask,
+};
+
+static int amd_mdb_pcie_event_map(struct irq_domain *domain,
+				  unsigned int irq, irq_hw_number_t hwirq) {
+	irq_set_chip_and_handler(irq, &amd_mdb_event_irq_chip,
+				 handle_level_irq);
+	irq_set_chip_data(irq, domain->host_data);
+	irq_set_status_flags(irq, IRQ_LEVEL);
+
+	return 0;
+}
+

drivers/pci/controller/dwc/pcie-amd-mdb.c line 240

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+static const struct irq_domain_ops event_domain_ops = {
+	.map = amd_mdb_pcie_event_map,
+};
+
+static irqreturn_t amd_mdb_pcie_event_flow(int irq, void *args) {
+	struct amd_mdb_pcie *pcie = args;
+	unsigned long val;
+	int i;
+
+	val = pcie_read(pcie, AMD_MDB_TLP_IR_STATUS_MISC);

Here also, no lock?
- Thank you for reviewing, In handler I am just reading the status & calling this irq_mask/irq_unmask API's I don't need to have save/restore spin_lock_irq's here.

Quoted 43 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +43 -0
+	val &= ~pcie_read(pcie, AMD_MDB_TLP_IR_MASK_MISC);
+	for_each_set_bit(i, &val, 32)
+		generic_handle_domain_irq(pcie->mdb_domain, i);
+	pcie_write(pcie, val, AMD_MDB_TLP_IR_STATUS_MISC);
+
+	return IRQ_HANDLED;
+}
+
+static void amd_mdb_pcie_free_irq_domains(struct amd_mdb_pcie *pcie) 
+{
+	if (pcie->intx_domain) {
+		irq_domain_remove(pcie->intx_domain);
+		pcie->intx_domain = NULL;
+	}
+
+	if (pcie->mdb_domain) {
+		irq_domain_remove(pcie->mdb_domain);
+		pcie->mdb_domain = NULL;
+	}
+}
+
+static int amd_mdb_pcie_init_port(struct amd_mdb_pcie *pcie) {
+	/* Disable all TLP Interrupts */
+	pcie_write(pcie, AMD_MDB_PCIE_IMR_ALL_MASK,
+		   AMD_MDB_TLP_IR_DISABLE_MISC);
+
+	/* Clear pending TLP interrupts */
+	pcie_write(pcie, pcie_read(pcie, AMD_MDB_TLP_IR_STATUS_MISC) &
+		   AMD_MDB_PCIE_IMR_ALL_MASK,
+		   AMD_MDB_TLP_IR_STATUS_MISC);
+
+	/* Enable all TLP Interrupts */
+	pcie_write(pcie,  AMD_MDB_PCIE_IMR_ALL_MASK,
+		   AMD_MDB_TLP_IR_ENABLE_MISC);
+
+	return 0;
+}
+
+/**
+ * amd_mdb_pcie_init_irq_domains - Initialize IRQ domain
+ * @pcie: PCIe port information
+ * @pdev: platform device
+ * Return: '0' on success and error value on failure  */ static int 

drivers/pci/controller/dwc/pcie-amd-mdb.c line 295

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+amd_mdb_pcie_init_irq_domains(struct amd_mdb_pcie *pcie,
+					 struct platform_device *pdev)
+{
+	struct dw_pcie *pci = &pcie->pci;
+	struct dw_pcie_rp *pp = &pci->pp;
+	struct device *dev = &pdev->dev;
+	struct device_node *node = dev->of_node;
+	struct device_node *pcie_intc_node;
+
+	/* Setup INTx */

This comment is quite misleading. This Intc node is not specific to INTx as far as I can see. Thank you for reviewing, I ll remove this comment.

drivers/pci/controller/dwc/pcie-amd-mdb.c line 299

Quoted 4 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +4 -0
+	pcie_intc_node = of_get_next_child(node, NULL);
+	if (!pcie_intc_node) {
+		dev_err(dev, "No PCIe Intc node found\n");
+		return -ENODATA;

-ENODEV

Thank you for reviewing, Ll update this in next patch.

Quoted 20 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +20 -0
+	}
+
+	pcie->mdb_domain = irq_domain_add_linear(pcie_intc_node, 32,
+						 &event_domain_ops, pcie);
+	if (!pcie->mdb_domain) {
+		dev_err(dev, "Failed to add mdb_domain\n");
+		goto out;
+	}
+
+	irq_domain_update_bus_token(pcie->mdb_domain, DOMAIN_BUS_NEXUS);
+
+	pcie->intx_domain = irq_domain_add_linear(pcie_intc_node, PCI_NUM_INTX,
+						  &amd_intx_domain_ops, pcie);
+	if (!pcie->intx_domain) {
+		dev_err(dev, "Failed to add intx_domain\n");
+		goto mdb_out;
+	}
+
+	of_node_put(pcie_intc_node);
+	irq_domain_update_bus_token(pcie->intx_domain, DOMAIN_BUS_WIRED);

drivers/pci/controller/dwc/pcie-amd-mdb.c line 329

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+
+	raw_spin_lock_init(&pp->lock);
+
+	return 0;
+mdb_out:
+	amd_mdb_pcie_free_irq_domains(pcie);
+out:
+	of_node_put(pcie_intc_node);
+
+	return -ENOMEM;

No please. This is just asking for trouble. Please pass the relevant errno.

Thank you for reviewing, ll update this in next patch.

Quoted 36 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +36 -0
+}
+
+static irqreturn_t amd_mdb_pcie_intr_handler(int irq, void *args) {
+	struct amd_mdb_pcie *pcie = args;
+	struct device *dev;
+	struct irq_data *d;
+
+	dev = pcie->pci.dev;
+
+	/*
+	 * In future, error reporting will be hooked to the AER subsystem.
+	 * Currently, the driver prints a warning message to the user.
+	 */
+	d = irq_domain_get_irq_data(pcie->mdb_domain, irq);
+	if (intr_cause[d->hwirq].str)
+		dev_warn(dev, "%s\n", intr_cause[d->hwirq].str);
+	else
+		dev_warn_once(dev, "Unknown IRQ %ld\n", d->hwirq);
+
+	return IRQ_HANDLED;
+}
+
+static int amd_mdb_setup_irq(struct amd_mdb_pcie *pcie,
+			     struct platform_device *pdev) {
+	struct dw_pcie *pci = &pcie->pci;
+	struct dw_pcie_rp *pp = &pci->pp;
+	struct device *dev = &pdev->dev;
+	int i, irq, err;
+
+	amd_mdb_pcie_init_port(pcie);
+
+	pp->irq = platform_get_irq(pdev, 0);
+	if (pp->irq < 0)
+		return pp->irq;
+
+	for (i = 0; i < ARRAY_SIZE(intr_cause); i++) {

drivers/pci/controller/dwc/pcie-amd-mdb.c line 377

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+		if (!intr_cause[i].str)
+			continue;
+		irq = irq_create_mapping(pcie->mdb_domain, i);
+		if (!irq) {
+			dev_err(dev, "Failed to map mdb domain interrupt\n");
+			return -ENOMEM;
+		}
+		err = devm_request_irq(dev, irq, amd_mdb_pcie_intr_handler,
+				       IRQF_SHARED | IRQF_NO_THREAD,
+				       intr_cause[i].sym, pcie);

Aren't these IRQs just part of a single IRQ? I'm wondering why do you need to represent them individually instead of having a single IRQ handler.

Btw, you are not disposing these IRQs anywhere. Especially in error paths.
Thank you for reviewing. This code is based on the work authored by Marc Zyngier and Bjorn during the development of our CPM drivers, and it follows the same design principles. The individual IRQ handling is consistent with that approach. For reference, you can review the driver here: pcie-xilinx-cpm.c. All of your comments have been incorporated into this driver as requested.

Quoted 14 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +14 -0
+		if (err) {
+			dev_err(dev, "Failed to request IRQ %d\n", irq);
+			return err;
+		}
+	}
+
+	pcie->intx_irq = irq_create_mapping(pcie->mdb_domain,
+					    AMD_MDB_PCIE_INTR_INTX);
+	if (!pcie->intx_irq) {
+		dev_err(dev, "Failed to map INTx interrupt\n");
+		return -ENXIO;
+	}
+
+	err = devm_request_irq(dev, pcie->intx_irq,

drivers/pci/controller/dwc/pcie-amd-mdb.c line 401

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+			       dw_pcie_rp_intx_flow,
+			       IRQF_SHARED | IRQF_NO_THREAD, NULL, pcie);
+	if (err) {
+		dev_err(dev, "Failed to request INTx IRQ %d\n", irq);
+		return err;
+	}
+
+	/* Plug the main event handler */
+	err = devm_request_irq(dev, pp->irq, amd_mdb_pcie_event_flow,
+			       IRQF_SHARED | IRQF_NO_THREAD, "amd_mdb pcie_irq",

Why is this a SHARED IRQ?
Thank you for reviewing. The IRQ is shared because all the events, errors, and INTx interrupts are routed through the same IRQ line, so multiple handlers need to be able to respond to the same interrupt.
- Mani

Regards,
Thippeswamy H

#8 lore raw

Re: [PATCH v14 3/3] PCI: amd-mdb: Add AMD MDB Root Port driver

On Mon, Feb 24, 2025 at 11:05:19AM +0000, Havalige, Thippeswamy wrote:

[...]

Quoted 10 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c line 30

Quoted 8 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +8 -0
+#define AMD_MDB_TLP_IR_STATUS_MISC		0x4C0
+#define AMD_MDB_TLP_IR_MASK_MISC		0x4C4
+#define AMD_MDB_TLP_IR_ENABLE_MISC		0x4C8
+#define AMD_MDB_TLP_IR_DISABLE_MISC		0x4CC
+
+#define AMD_MDB_TLP_PCIE_INTX_MASK	GENMASK(23, 16)
+
+#define AMD_MDB_PCIE_INTR_INTX_ASSERT(x)	BIT((x) * 2)

How does these values correspond to the AMD_MDB_TLP_PCIE_INTX_MASK? These values could be: 0, 2, 4, and 6 corresponding to: 0b01010101? Looks wierd.

I don't know if it is your mailer issue or your workflow. Looks like my review comments are copy pasted here. So it becomes harder to distinguish between my previous comments and your replies.

Please fix it.

Quoted 9 lines

Thank you for reviewing, Yes in register status/Enable/Disable register bits are laid in this way.

Quoted 5 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +5 -0
+
+/* Interrupt registers definitions */
+#define AMD_MDB_PCIE_INTR_CMPL_TIMEOUT		15
+#define AMD_MDB_PCIE_INTR_INTX			16
+#define AMD_MDB_PCIE_INTR_PM_PME_RCVD		24
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+static inline u32 pcie_read(struct amd_mdb_pcie *pcie, u32 reg) {
+	return readl_relaxed(pcie->slcr + reg); }

I think I already commented on these helpers. Please get rid of them. I don't see any value in this new driver. Moreover, 'inline' keywords are not required. Thanks for the review. While I agree to remove the 'inline', I would like pcie_read/pcie_write APIs. Could you please clarify the reason for explicitly removing pcie_read/pcie_write here? If I remove the pcie_read/pcie_write, it will require changes in multiple places throughout the code."

What value does the helper really add? It just wraps the {readl/writel}_relaxed calls. Plus it hides which kind of I/O accessors are used. So I don't see a value in keeping them.

Quoted 16 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c line 154

Quoted 12 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +11 -0
+
+static inline void pcie_write(struct amd_mdb_pcie *pcie,
+			      u32 val, u32 reg)
+{
+	writel_relaxed(val, pcie->slcr + reg); }
+
+static const struct irq_domain_ops amd_intx_domain_ops = {
+	.map = amd_mdb_pcie_intx_map,
+};
+
+static irqreturn_t dw_pcie_rp_intx_flow(int irq, void *args)

What does the _flow suffix mean?
Thanks for reviewing, The _flow suffix in the function name dw_pcie_rp_intx_flow indicates that the function handles the flow or processing related to interrupt handling for the PCIe root port's INTx interrupts through generic_handle_domain_irq.

(Please wrap your replies to 80 column width)

So it is the regular interrupt handler. I don't see a necessity to add the _flow suffix.

Quoted 11 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c line 160

Quoted 6 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +6 -0
+{
+	struct amd_mdb_pcie *pcie = args;
+	unsigned long val;
+	int i, int_status;
+
+	val = pcie_read(pcie, AMD_MDB_TLP_IR_STATUS_MISC);

You don't need port->lock here?
Thank you for reviewing. In this case, I'm simply reading the status of the INTX register bits without modifying any registers. Since no shared resources are being updated or accessed concurrently, there’s no need for a lock here.

What if the handler and mask/unmask functions are executed in different CPUs? Sharing the same register without lock feels nervous. Locking principle is that you would lock both read as well as write.

Quoted 6 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c line 161

Quoted 2 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +1 -0
+	int_status = FIELD_GET(AMD_MDB_TLP_PCIE_INTX_MASK, val);

You don't need to ack/clear the IRQ?
- Thank you for reviewing, Thank you for reviewing. In this case, I am using IRQ domains, and the generic_handle_domain_irq function will invoke the necessary irq_mask and irq_unmask operations internally, which will take care of clearing the IRQ.

Ok.

Quoted 12 lines
Quoted 12 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +12 -0
+
+	for (i = 0; i < PCI_NUM_INTX; i++) {
+		if (int_status & AMD_MDB_PCIE_INTR_INTX_ASSERT(i))
+			generic_handle_domain_irq(pcie->intx_domain, i);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static void amd_mdb_event_irq_mask(struct irq_data *d) {
+	struct amd_mdb_pcie *pcie = irq_data_get_irq_chip_data(d);
+	struct dw_pcie *pci = &pcie->pci;
Quoted 9 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c line 193

Quoted 5 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +5 -0
+	struct dw_pcie_rp *port = &pci->pp;
+	u32 val;
+
+	raw_spin_lock(&port->lock);
+	val = pcie_read(pcie, AMD_MDB_TLP_IR_STATUS_MISC);

This register is accessed in the IRQ handler also. So don't you need raw_spin_lock_irq{save/restore}?
- Thank you for reviewing, In handler I am just reading the status & calling this irq_mask/irq_unmask API's I don't need to have save/restore spin_lock_irq's here.

Same as above.

Quoted 5 lines
Quoted 5 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +5 -0
+	val &= ~BIT(d->hwirq);
+	pcie_write(pcie, val, AMD_MDB_TLP_IR_STATUS_MISC);
+	raw_spin_unlock(&port->lock);
+}
+

[...]

Quoted 14 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c line 377

Quoted 11 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +11 -0
+	for (i = 0; i < ARRAY_SIZE(intr_cause); i++) {
+		if (!intr_cause[i].str)
+			continue;
+		irq = irq_create_mapping(pcie->mdb_domain, i);
+		if (!irq) {
+			dev_err(dev, "Failed to map mdb domain interrupt\n");
+			return -ENOMEM;
+		}
+		err = devm_request_irq(dev, irq, amd_mdb_pcie_intr_handler,
+				       IRQF_SHARED | IRQF_NO_THREAD,
+				       intr_cause[i].sym, pcie);

Aren't these IRQs just part of a single IRQ? I'm wondering why do you need to represent them individually instead of having a single IRQ handler.

Quoted 4 lines

Btw, you are not disposing these IRQs anywhere. Especially in error paths.
Thank you for reviewing. This code is based on the work authored by Marc Zyngier and Bjorn during the development of our CPM drivers, and it follows the same design principles. The individual IRQ handling is consistent with that approach. For reference, you can review the driver here: pcie-xilinx-cpm.c. All of your comments have been incorporated into this driver as requested.

Ok for the separate IRQ question. But you still need to dispose the IRQs in error path.

Quoted 19 lines
Quoted 19 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +19 -0
+		if (err) {
+			dev_err(dev, "Failed to request IRQ %d\n", irq);
+			return err;
+		}
+	}
+
+	pcie->intx_irq = irq_create_mapping(pcie->mdb_domain,
+					    AMD_MDB_PCIE_INTR_INTX);
+	if (!pcie->intx_irq) {
+		dev_err(dev, "Failed to map INTx interrupt\n");
+		return -ENXIO;
+	}
+
+	err = devm_request_irq(dev, pcie->intx_irq,
+			       dw_pcie_rp_intx_flow,
+			       IRQF_SHARED | IRQF_NO_THREAD, NULL, pcie);
+	if (err) {
+		dev_err(dev, "Failed to request INTx IRQ %d\n", irq);
+		return err;
Quoted 8 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c line 401

Quoted 5 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +5 -0
+	}
+
+	/* Plug the main event handler */
+	err = devm_request_irq(dev, pp->irq, amd_mdb_pcie_event_flow,
+			       IRQF_SHARED | IRQF_NO_THREAD, "amd_mdb pcie_irq",

Why is this a SHARED IRQ?
Thank you for reviewing. The IRQ is shared because all the events, errors, and INTx interrupts are routed through the same IRQ line, so multiple handlers need to be able to respond to the same interrupt.

IIUC, you have a single handler for this IRQ and that handler is invoking other handlers (for events, INTx etc...). So I don't see how this IRQ is shared.

Shared IRQ is only required if multiple handlers are sharing the same IRQ line. But that is not the case here afaics.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
#9 lore raw

RE: [PATCH v14 3/3] PCI: amd-mdb: Add AMD MDB Root Port driver

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Mani,

Quoted 25 lines

-----Original Message-----
From: Manivannan Sadhasivam <[email protected]>
Sent: Monday, February 24, 2025 6:42 PM
To: Havalige, Thippeswamy <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; linux- [email protected]; Simek, Michal <[email protected]>; Gogada, Bharat Kumar <[email protected]>; [email protected]
Subject: Re: [PATCH v14 3/3] PCI: amd-mdb: Add AMD MDB Root Port driver

On Mon, Feb 24, 2025 at 11:05:19AM +0000, Havalige, Thippeswamy wrote:

[...]

Quoted 10 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c line 30

Quoted 8 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +8 -0
+#define AMD_MDB_TLP_IR_STATUS_MISC               0x4C0
+#define AMD_MDB_TLP_IR_MASK_MISC         0x4C4
+#define AMD_MDB_TLP_IR_ENABLE_MISC               0x4C8
+#define AMD_MDB_TLP_IR_DISABLE_MISC              0x4CC
+
+#define AMD_MDB_TLP_PCIE_INTX_MASK       GENMASK(23, 16)
+
+#define AMD_MDB_PCIE_INTR_INTX_ASSERT(x) BIT((x) * 2)

How does these values correspond to the

Quoted 8 lines

AMD_MDB_TLP_PCIE_INTX_MASK? These values could be: 0, 2, 4, and 6 corresponding to: 0b01010101? Looks wierd.

I don't know if it is your mailer issue or your workflow. Looks like my review comments are copy pasted here. So it becomes harder to distinguish between my previous comments and your replies.

Please fix it.

Thanks for reviewing, will fix this in next patch.

Quoted 17 lines
Quoted 2 lines

Thank you for reviewing, Yes in register status/Enable/Disable register bits

are laid in this way.

Quoted 8 lines
Quoted 6 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +5 -0
+
+/* Interrupt registers definitions */
+#define AMD_MDB_PCIE_INTR_CMPL_TIMEOUT           15
+#define AMD_MDB_PCIE_INTR_INTX                   16
+#define AMD_MDB_PCIE_INTR_PM_PME_RCVD            24
Quoted 4 lines
Quoted 2 lines

+static inline u32 pcie_read(struct amd_mdb_pcie *pcie, u32 reg) {
+ return readl_relaxed(pcie->slcr + reg); }

I think I already commented on these helpers. Please get rid of them. I don't

see any value in this new driver. Moreover, 'inline' keywords are not required.

Quoted 1 line

Thanks for the review. While I agree to remove the 'inline', I would like

Quoted 8 lines

pcie_read/pcie_write APIs. Could you please clarify the reason for explicitly removing pcie_read/pcie_write here?

Quoted 1 line

If I remove the pcie_read/pcie_write, it will require changes in multiple

places throughout the code."

What value does the helper really add? It just wraps the {readl/writel}_relaxed calls. Plus it hides which kind of I/O accessors are used. So I don't see a value in keeping them.

- Thanks for reviewing, Will fix this in next patch

Quoted 21 lines
Quoted 16 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c line 154

Quoted 13 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +11 -0
+
+static inline void pcie_write(struct amd_mdb_pcie *pcie,
+                       u32 val, u32 reg)
+{
+ writel_relaxed(val, pcie->slcr + reg); }
+
+static const struct irq_domain_ops amd_intx_domain_ops = {
+ .map = amd_mdb_pcie_intx_map,
+};
+
+static irqreturn_t dw_pcie_rp_intx_flow(int irq, void *args)

What does the _flow suffix mean?
Thanks for reviewing, The _flow suffix in the function name

dw_pcie_rp_intx_flow indicates that the function handles the flow or processing related to interrupt handling for the PCIe root port's INTx interrupts through generic_handle_domain_irq.

Quoted 1 line
Quoted 4 lines

(Please wrap your replies to 80 column width)

So it is the regular interrupt handler. I don't see a necessity to add the _flow suffix.

- Thanks for reviewing, Will fix this in next patch.

Quoted 11 lines
Quoted 10 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c line 160

Quoted 7 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +6 -0
+{
+ struct amd_mdb_pcie *pcie = args;
+ unsigned long val;
+ int i, int_status;
+
+ val = pcie_read(pcie, AMD_MDB_TLP_IR_STATUS_MISC);

You don't need port->lock here?
Thank you for reviewing. In this case, I'm simply reading the status of the

INTX register bits without modifying any registers.

Quoted 8 lines
Quoted 1 line

Since no shared resources are being updated or accessed concurrently,

there’s no need for a lock here.

Quoted 1 line

What if the handler and mask/unmask functions are executed in different CPUs?
Sharing the same register without lock feels nervous. Locking principle is that you would lock both read as well as write.

Thank you for reviewing.
I have incorporated the locking mechanism within the intx_irq_{mask/unmask} callback functions. Since the IRQ line is disabled while executing the interrupt handler, there is no need to explicitly acquire a lock within the handler itself.

Additionally, when INTA occurs, it will be immediately masked within the irq_mask() function, ensuring that no other instance of the same interrupt is triggered while it is being processed. This guarantees proper synchronization and prevents race conditions.

Let me know if my understanding is correct & any further concerns.

Quoted 70 lines
Quoted 6 lines
Quoted 3 lines

+ int_status = FIELD_GET(AMD_MDB_TLP_PCIE_INTX_MASK, val);

You don't need to ack/clear the IRQ?
- Thank you for reviewing, Thank you for reviewing. In this case, I am using

IRQ domains, and the generic_handle_domain_irq function will invoke the necessary irq_mask and irq_unmask operations internally, which will take care of clearing the IRQ.

Quoted 1 line

Ok.

Quoted 11 lines
Quoted 11 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +11 -0
+
+ for (i = 0; i < PCI_NUM_INTX; i++) {
+         if (int_status & AMD_MDB_PCIE_INTR_INTX_ASSERT(i))
+                 generic_handle_domain_irq(pcie->intx_domain, i);
+ }
+
+ return IRQ_HANDLED;
+}
+
+static void amd_mdb_event_irq_mask(struct irq_data *d) {
+ struct amd_mdb_pcie *pcie = irq_data_get_irq_chip_data(d);
Quoted 8 lines
Quoted 6 lines

+ struct dw_pcie *pci = &pcie->pci;
+ struct dw_pcie_rp *port = &pci->pp;
+ u32 val;
+
+ raw_spin_lock(&port->lock);
+ val = pcie_read(pcie, AMD_MDB_TLP_IR_STATUS_MISC);

This register is accessed in the IRQ handler also. So don't you need

raw_spin_lock_irq{save/restore}?

Quoted 1 line

- Thank you for reviewing, In handler I am just reading the status & calling

this irq_mask/irq_unmask API's I don't need to have save/restore spin_lock_irq's here.

Quoted 1 line

Same as above.

Quoted 5 lines
Quoted 5 lines

+ val &= ~BIT(d->hwirq);
+ pcie_write(pcie, val, AMD_MDB_TLP_IR_STATUS_MISC);
+ raw_spin_unlock(&port->lock);

(quoted diff) +2 -0
+}
+

[...]

Quoted 6 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c

Quoted 6 lines

+ for (i = 0; i < ARRAY_SIZE(intr_cause); i++) {

drivers/pci/controller/dwc/pcie-amd-mdb.c new file +5 -0
+         if (!intr_cause[i].str)
+                 continue;
+         irq = irq_create_mapping(pcie->mdb_domain, i);
+         if (!irq) {
+                 dev_err(dev, "Failed to map mdb domain

interrupt\n");

Quoted 3 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c

Quoted 3 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +3 -0
+                 return -ENOMEM;
+         }
+         err = devm_request_irq(dev, irq,

amd_mdb_pcie_intr_handler,

Quoted 4 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c line 377

Quoted 2 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +2 -0
+                                IRQF_SHARED | IRQF_NO_THREAD,
+                                intr_cause[i].sym, pcie);

Aren't these IRQs just part of a single IRQ? I'm wondering why do you need

to represent them individually instead of having a single IRQ handler.

Quoted 3 lines

Btw, you are not disposing these IRQs anywhere. Especially in error paths. Thank you for reviewing. This code is based on the work authored by Marc

Zyngier and Bjorn during the development of our CPM drivers, and it follows the same design principles. The individual IRQ handling is consistent with that approach.

Quoted 6 lines
Quoted 1 line

For reference, you can review the driver here: pcie-xilinx-cpm.c. All of your

comments have been incorporated into this driver as requested.

Quoted 1 line

Ok for the separate IRQ question. But you still need to dispose the IRQs in error path.

Thank you for reviewing, Will dispose all the interrupts in case of errors.

Quoted 29 lines
Quoted 17 lines
Quoted 17 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +16 -0
+         if (err) {
+                 dev_err(dev, "Failed to request IRQ %d\n", irq);
+                 return err;
+         }
+ }
+
+ pcie->intx_irq = irq_create_mapping(pcie->mdb_domain,
+                                     AMD_MDB_PCIE_INTR_INTX);
+ if (!pcie->intx_irq) {
+         dev_err(dev, "Failed to map INTx interrupt\n");
+         return -ENXIO;
+ }
+
+ err = devm_request_irq(dev, pcie->intx_irq,
+                        dw_pcie_rp_intx_flow,
+                        IRQF_SHARED | IRQF_NO_THREAD, NULL, pcie);
Quoted 8 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c

Quoted 8 lines

+ if (err) {

drivers/pci/controller/dwc/pcie-amd-mdb.c new file +7 -0
+         dev_err(dev, "Failed to request INTx IRQ %d\n", irq);
+         return err;
+ }
+
+ /* Plug the main event handler */
+ err = devm_request_irq(dev, pp->irq, amd_mdb_pcie_event_flow,
+                        IRQF_SHARED | IRQF_NO_THREAD, "amd_mdb

pcie_irq",

Quoted 3 lines

Why is this a SHARED IRQ?
Thank you for reviewing. The IRQ is shared because all the events, errors,

Quoted 8 lines

and INTx interrupts are routed through the same IRQ line, so multiple handlers need to be able to respond to the same interrupt.

IIUC, you have a single handler for this IRQ and that handler is invoking other handlers (for events, INTx etc...). So I don't see how this IRQ is shared.

Shared IRQ is only required if multiple handlers are sharing the same IRQ line. But that is not the case here afaics.

Thank you for reviewing, will test this and comeback on this.

Quoted 5 lines

- Mani

--
மணிவண்ணன் சதாசிவம்

#10 lore raw

RE: [PATCH v14 3/3] PCI: amd-mdb: Add AMD MDB Root Port driver

In reply to Manivannan Sadhasivam

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Mani,

[...]

Quoted 23 lines
Quoted 7 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c

Quoted 7 lines

+ for (i = 0; i < ARRAY_SIZE(intr_cause); i++) {

drivers/pci/controller/dwc/pcie-amd-mdb.c new file +5 -0
+         if (!intr_cause[i].str)
+                 continue;
+         irq = irq_create_mapping(pcie->mdb_domain, i);
+         if (!irq) {
+                 dev_err(dev, "Failed to map mdb domain

interrupt\n");

Quoted 3 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c

Quoted 3 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +3 -0
+                 return -ENOMEM;
+         }
+         err = devm_request_irq(dev, irq,

amd_mdb_pcie_intr_handler,

Quoted 4 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c line 377

Quoted 2 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +2 -0
+                                IRQF_SHARED | IRQF_NO_THREAD,
+                                intr_cause[i].sym, pcie);

Aren't these IRQs just part of a single IRQ? I'm wondering why do you need

to represent them individually instead of having a single IRQ handler.

Quoted 3 lines

Btw, you are not disposing these IRQs anywhere. Especially in error paths. Thank you for reviewing. This code is based on the work authored by Marc

Zyngier and Bjorn during the development of our CPM drivers, and it follows the same design principles. The individual IRQ handling is consistent with that approach.

Quoted 6 lines
Quoted 1 line

For reference, you can review the driver here: pcie-xilinx-cpm.c. All of your

comments have been incorporated into this driver as requested.

Quoted 1 line

Ok for the separate IRQ question. But you still need to dispose the IRQs in error path.

Here none of the drivers are disposing explicitly in the error path explicitly. I only See VMD driver is freeing it up explicitly in suspend path so that driver can register irq Handler in the resume. May I know the reason for explicitly need for disposing here.

Quoted 29 lines
Quoted 17 lines
Quoted 17 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +16 -0
+         if (err) {
+                 dev_err(dev, "Failed to request IRQ %d\n", irq);
+                 return err;
+         }
+ }
+
+ pcie->intx_irq = irq_create_mapping(pcie->mdb_domain,
+                                     AMD_MDB_PCIE_INTR_INTX);
+ if (!pcie->intx_irq) {
+         dev_err(dev, "Failed to map INTx interrupt\n");
+         return -ENXIO;
+ }
+
+ err = devm_request_irq(dev, pcie->intx_irq,
+                        dw_pcie_rp_intx_flow,
+                        IRQF_SHARED | IRQF_NO_THREAD, NULL, pcie);
Quoted 8 lines

drivers/pci/controller/dwc/pcie-amd-mdb.c

Quoted 8 lines

+ if (err) {

drivers/pci/controller/dwc/pcie-amd-mdb.c new file +7 -0
+         dev_err(dev, "Failed to request INTx IRQ %d\n", irq);
+         return err;
+ }
+
+ /* Plug the main event handler */
+ err = devm_request_irq(dev, pp->irq, amd_mdb_pcie_event_flow,
+                        IRQF_SHARED | IRQF_NO_THREAD, "amd_mdb

pcie_irq",

Quoted 3 lines

Why is this a SHARED IRQ?
Thank you for reviewing. The IRQ is shared because all the events, errors,

Quoted 8 lines

and INTx interrupts are routed through the same IRQ line, so multiple handlers need to be able to respond to the same interrupt.

IIUC, you have a single handler for this IRQ and that handler is invoking other handlers (for events, INTx etc...). So I don't see how this IRQ is shared.

Shared IRQ is only required if multiple handlers are sharing the same IRQ line. But that is not the case here afaics.

- I have verified this in my driver it works without shared interrupt line. Thanks for reviewing.

Quoted 5 lines

- Mani

--
மணிவண்ணன் சதாசிவம்

#11 lore raw

Re: [PATCH v14 3/3] PCI: amd-mdb: Add AMD MDB Root Port driver

In reply to Thippeswamy Havalige
Quoted 8 lines · Thippeswamy Havalige

Add support for AMD MDB (Multimedia DMA Bridge) IP core as Root Port.

The Versal2 devices include MDB Module. The integrated block for MDB along with the integrated bridge can function as PCIe Root Port controller at Gen5 32-Gb/s operation per lane.

Bridge supports error and legacy interrupts and are handled using platform specific interrupt line in Versal2.

s/legacy/INTx/ (I assume that's what you mean here)

drivers/pci/controller/dwc/Kconfig config PCIE_AL · line 39

Quoted 10 lines
drivers/pci/controller/dwc/Kconfig +10 -0
+config PCIE_AMD_MDB
+	bool "AMD MDB Versal2 PCIe Host controller"
+	depends on OF || COMPILE_TEST
+	depends on PCI && PCI_MSI
+	select PCIE_DW_HOST
+	help
+	  Say Y here if you want to enable PCIe controller support on AMD
+	  Versal2 SoCs. The AMD MDB Versal2 PCIe controller is based on
+	  DesignWare IP and therefore the driver re-uses the Designware core
+	  functions to implement the driver.

s/Designware/DesignWare/

Quoted 5 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +5 -0
+static void amd_mdb_intx_irq_unmask(struct irq_data *data)
+{
+	struct amd_mdb_pcie *pcie = irq_data_get_irq_chip_data(data);
+	struct dw_pcie *pci = &pcie->pci;
+	struct dw_pcie_rp *port = &pci->pp;

drivers/pci/controller/dwc/pcie-amd-mdb.c line 117

Quoted 10 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +10 -0
+	unsigned long flags;
+	u32 val;
+
+	raw_spin_lock_irqsave(&port->lock, flags);
+	val = FIELD_PREP(AMD_MDB_TLP_PCIE_INTX_MASK,
+			 AMD_MDB_PCIE_INTR_INTX_ASSERT(data->hwirq));
+
+	/*
+	 * Writing '1' to a bit in AMD_MDB_TLP_IR_ENABLE_MISC enables that interrupt.
+	 * Writing '0' has no effect.

Wrap to fit in 80 columns like the rest of the file.

Quoted 4 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +4 -0
+	 */
+	pcie_write(pcie, val, AMD_MDB_TLP_IR_ENABLE_MISC);
+	raw_spin_unlock_irqrestore(&port->lock, flags);
+}
#12 lore raw

RE: [PATCH v14 3/3] PCI: amd-mdb: Add AMD MDB Root Port driver

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Bjorn,

Thanks for reviewing, will update all comments in next patch.

Regards,
Thippeswamy H

Quoted 59 lines

-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: Tuesday, February 25, 2025 1:33 AM
To: Havalige, Thippeswamy <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; Gogada, Bharat Kumar <[email protected]>; [email protected]
Subject: Re: [PATCH v14 3/3] PCI: amd-mdb: Add AMD MDB Root Port driver

Quoted 9 lines · Thippeswamy Havalige

Add support for AMD MDB (Multimedia DMA Bridge) IP core as Root Port.

The Versal2 devices include MDB Module. The integrated block for MDB along with the integrated bridge can function as PCIe Root Port controller at
Gen5 32-Gb/s operation per lane.

Bridge supports error and legacy interrupts and are handled using platform specific interrupt line in Versal2.

s/legacy/INTx/ (I assume that's what you mean here)

drivers/pci/controller/dwc/Kconfig config PCIE_AL · line 39

Quoted 10 lines
drivers/pci/controller/dwc/Kconfig +10 -0
+config PCIE_AMD_MDB
+   bool "AMD MDB Versal2 PCIe Host controller"
+   depends on OF || COMPILE_TEST
+   depends on PCI && PCI_MSI
+   select PCIE_DW_HOST
+   help
+     Say Y here if you want to enable PCIe controller support on AMD
+     Versal2 SoCs. The AMD MDB Versal2 PCIe controller is based on
+     DesignWare IP and therefore the driver re-uses the Designware core
+     functions to implement the driver.

s/Designware/DesignWare/

drivers/pci/controller/dwc/pcie-amd-mdb.c

Quoted 13 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +13 -0
+static void amd_mdb_intx_irq_unmask(struct irq_data *data) {
+   struct amd_mdb_pcie *pcie = irq_data_get_irq_chip_data(data);
+   struct dw_pcie *pci = &pcie->pci;
+   struct dw_pcie_rp *port = &pci->pp;
+   unsigned long flags;
+   u32 val;
+
+   raw_spin_lock_irqsave(&port->lock, flags);
+   val = FIELD_PREP(AMD_MDB_TLP_PCIE_INTX_MASK,
+                    AMD_MDB_PCIE_INTR_INTX_ASSERT(data->hwirq));
+
+   /*
+    * Writing '1' to a bit in AMD_MDB_TLP_IR_ENABLE_MISC enables that

interrupt.

Quoted 1 line

+ * Writing '0' has no effect.

Wrap to fit in 80 columns like the rest of the file.

Quoted 3 lines
drivers/pci/controller/dwc/pcie-amd-mdb.c new file +3 -0
+    */
+   pcie_write(pcie, val, AMD_MDB_TLP_IR_ENABLE_MISC);
+   raw_spin_unlock_irqrestore(&port->lock, flags); }
#13 lore raw
In reply to Thippeswamy Havalige
Quoted 3 lines · Thippeswamy Havalige

This series of patch add support for AMD MDB IP as Root Port.

The AMD MDB IP support's 32 bit and 64bit BAR's at Gen5 speed.

Which PCIe controller does not support 64-bit BARs?

Seems like quite a random sentence IMO.

Quoted 1 line

As Root Port it supports MSI and legacy interrupts.

You are not submitting Endpoint mode support for your controller, so it seems a bit weird to talk about "As Root Port ...".

Your patch only includes Root Complex mode, and makes no reference to Endpoint mode anywhere, so perhaps just state that the controller supports MSI and INTx interrupts.

Kind regards,
Niklas