Skip to contentSkip to conversation

PCI: dwc: Use cfg0_base as iMSI-RX target address to support 32-bit MSI devices

PATCH Applied Shawn Lin 2 participants 2 messages Dec 24, 2025 – Dec 29, 2025

Subsystems (3)
lore
Share & tools
lore

Shawn Lin

author
#0 lore raw

PATCH v2 1/1 PCI: dwc: Use cfg0_base as iMSI-RX target address to support 32-bit MSI devices

commit f3a296405b6e ("PCI: dwc: Strengthen the MSI address allocation logic") strengthened the iMSI-RX target address allocation logic to handle 64-bit addresses for platforms without 32-bit DMA addresses. However, it still left 32-bit MSI capable endpoints (EPs) non-functional on such platforms.

Per DWC databook r5.10a, section 3.8.2.2, it states:
"The iMSI-RX is programmed with an address (MSI_CTRL_ADDR_OFF and MSI_CTRL_UPPER_ADDR_OFF) that is used as the system MSI address. When an inbound MWr request is passed to the AXI bridge and matches this address as well as the conditions specified for an MSI memory write request, an MSI interrupt is detected. When this MWr is about to be driven onto the AXI bridge master interface1, it is dropped and never appears on the AXI bus."

It's also confirmed by DWC databook r6.21a, section 3.10.2.3. So this behaviour should be the same for all DWC based iMSI-RX block. Since iMSI-RX is a pure virtual address that doesn't require actual system memory mapping, we can assign any 32-bit address that won't conflict with system memory allocations. Assign cfg0_base to the iMSI-RX target address as the first option if it's a 32-bit address, which satisfies this requirement. Otherwise, we still fallback to the original approach.

Tested on a Rockchip platform lacking 32-bit DMA addresses with an ASM1062 SATA controller that only supports 32-bit MSI. The device functions correctly using 43-bit DMA addressing via the board_ahci_43bit_dma flag in ahci_configure_dma_masks(). The config space address for this host controller is located on 0x21000000, which is assigned to EP's MSI target address comfirmed by lspci output.

  root@linaro-alip:/# lspci -vvv
  03:00.0 SATA controller: ASMedia Technology Inc. ASM1062 Serial ATA Controller (rev 01) (prog-if 01 [AHCI 1.0])
	  Subsystem: ASMedia Technology Inc. ASM1061/ASM1062 Serial ATA Controller
  	  Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
	  Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	  Latency: 0
	  Interrupt: pin A routed to IRQ 121
	  Region 0: I/O ports at 1020 [size=8]
	  Region 1: I/O ports at 1030 [size=4]
	  Region 2: I/O ports at 1028 [size=8]
	  Region 3: I/O ports at 1034 [size=4]
	  Region 4: I/O ports at 1000 [size=32]
	  Region 5: Memory at 21210000 (32-bit, non-prefetchable) [size=512]
	  Expansion ROM at 21200000 [virtual] [disabled] [size=64K]
	  Capabilities: [50] MSI: Enable+ Count=1/1 Maskable- 64bit-
			Address: 0x21000000  Data: 0003

MSI interrupt counts increase during I/O operations, confirming proper SATA controller functionality.

  root@linaro-alip:/# cat /proc/interrupts | grep PCI-MSI
  117:    0      0     0     0      0     0    0     0   PCI-MSI       0 Edge      PCIe PME
  121:    90     0     0     0      0     0    0     0   PCI-MSI 1572864 Edge      ahci[0000:03:00.0]
  root@linaro-alip:/# dd if=/dev/sda1 of=/dev/null bs=1M count=10
  10+0 records in
  10+0 records out
  10485760 bytes (10 MB, 10 MiB) copied, 0.0227659 s, 461 MB/s
  root@linaro-alip:/# cat /proc/interrupts | grep PCI-MSI
  117:    0      0     0     0      0     0    0     0   PCI-MSI       0 Edge      PCIe PME
  121:   101     0     0     0      0     0    0     0   PCI-MSI 1572864 Edge      ahci[0000:03:00.0]
cc Ajay Agarwal <[email protected]>
cc Will McVicker <[email protected]>

---

Changes in v2:
- use cfg0_base as first option if it's a 32-bit address(Mani)
- Add reference from databook and rework the code comment and commit message

 drivers/pci/controller/dwc/pcie-designware-host.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +13 -3
index f116591..c88db99 100644
@@ -356,10 +356,20 @@ int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)
 	 * order not to miss MSI TLPs from those devices the MSI target
 	 * address has to be within the lowest 4GB.
 	 *
-	 * Note until there is a better alternative found the reservation is
-	 * done by allocating from the artificially limited DMA-coherent
-	 * memory.
+	 * Per DWC databook r6.21a, section 3.10.2.3, the incoming MWr TLP
+	 * targeting the MSI_CTRL_ADDR is terminated by the iMSI-RX and
+	 * never appears on the AXI bus. Since iMSI-RX monitors a virtual
+	 * address space that doesn't require physical memory mapping, and
+	 * most of the platforms provide 32-bit config space address, we
+	 * use cfg0_base as the first option for the MSI target address if
+	 * it's a 32-bit address. Otherwise, try 32-bit and 64-bit coherent
+	 * memory allocation one by one.
 	 */
+	if (!(pp->cfg0_base & GENMASK_ULL(63, 32))) {
+		pp->msi_data = pp->cfg0_base;
+		return 0;
+	}
+
 	ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
 	if (!ret)
 		msi_vaddr = dmam_alloc_coherent(dev, sizeof(u64), &pp->msi_data,
Signature · 1 line
2.7.4
#1 lore raw
Quoted 14 lines · Shawn Lin

commit f3a296405b6e ("PCI: dwc: Strengthen the MSI address allocation logic") strengthened the iMSI-RX target address allocation logic to handle 64-bit addresses for platforms without 32-bit DMA addresses. However, it still left 32-bit MSI capable endpoints (EPs) non-functional on such platforms.

Per DWC databook r5.10a, section 3.8.2.2, it states:
"The iMSI-RX is programmed with an address (MSI_CTRL_ADDR_OFF and MSI_CTRL_UPPER_ADDR_OFF) that is used as the system MSI address. When an inbound MWr request is passed to the AXI bridge and matches this address as well as the conditions specified for an MSI memory write request, an MSI interrupt is detected. When this MWr is about to be driven onto the AXI bridge master interface1, it is dropped and never appears on the AXI bus."

Quoted 1 line

[...]

Applied, thanks!

[1/1] PCI: dwc: Use cfg0_base as iMSI-RX target address to support 32-bit MSI devices

      commit: 68ac85fb42cfeb081cf029acdd8aace55ed375a2

Best regards,

Signature · 1 line
Manivannan Sadhasivam <[email protected]>