mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] riscv: dts: spacemit: k1: give each PCIe port its own DMA window
@ 2026-11-13  2:31 Vlad Banea
  2026-11-13  8:40 ` Troy Mitchell
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Vlad Banea @ 2026-11-13  2:31 UTC (permalink / raw)
  To: Yixun Lan
  Cc: troy.mitchell, wangruikang, guodong.xu, jyc0019, robh, krzk+dt,
	conor+dt, pjw, palmer, aou, alex, devicetree, linux-riscv,
	spacemit, linux-kernel

On K1 a PCIe master only sees DDR: bus addresses 0-2 GB map to CPU
0-2 GB and bus 2-16 GB to CPU 4-18 GB. A root port does not forward
upstream an inbound access that falls inside its own memory window, so
dma-ranges must skip each port's own outbound window; the other ports'
windows reach memory.

The shared pcie-bus skips all three windows, bus 0x8000_0000-0xb7ff_ffff,
which leaves CPU addresses 0x1_0000_0000-0x1_37ff_ffff unreachable from
every port. Give each port its own bus that skips only its own window.
On boards with more than 2 GB of RAM, each port can then reach another
512-640 MB without SWIOTLB bouncing.

Signed-off-by: Vlad Banea <montrealtango@gmail.com>
---

Notes:
    Changes in v2:
    - describe the K1 PCIe address map instead of citing the vendor DT (Troy)
    - "more than 2 GB" instead of 4 GB (Troy)
    - drop the RFC tag
    - RFC: https://lore.kernel.org/all/20261112015148.3911178-1-montrealtango@gmail.com/
    
    Tested on an OrangePi R2S (8 GB, RTL8125B on pcie1 and pcie2): SWIOTLB
    use under load went from up to 87 slots to none.

 arch/riscv/boot/dts/spacemit/k1.dtsi | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/boot/dts/spacemit/k1.dtsi b/arch/riscv/boot/dts/spacemit/k1.dtsi
index 3fabfd34114b..949843bb7789 100644
--- a/arch/riscv/boot/dts/spacemit/k1.dtsi
+++ b/arch/riscv/boot/dts/spacemit/k1.dtsi
@@ -1152,13 +1152,14 @@ eth1: ethernet@cac81000 {
 			};
 		};
 
-		pcie-bus {
+		pcie0-bus {
 			compatible = "simple-bus";
 			ranges;
 			#address-cells = <2>;
 			#size-cells = <2>;
+			/* skips pcie0's own window, bus 0x8000_0000-0x8fff_ffff */
 			dma-ranges = <0x0 0x00000000 0x0 0x00000000 0x0 0x80000000>,
-				     <0x0 0xb8000000 0x1 0x38000000 0x3 0x48000000>;
+				     <0x0 0x90000000 0x1 0x10000000 0x3 0x70000000>;
 
 			pcie0: pcie@ca000000 {
 				device_type = "pci";
@@ -1203,6 +1204,17 @@ pcie0_port: pcie@0 {
 					ranges;
 				};
 			};
+		};
+
+		pcie1-bus {
+			compatible = "simple-bus";
+			ranges;
+			#address-cells = <2>;
+			#size-cells = <2>;
+			/* skips pcie1's own window, bus 0x9000_0000-0x9fff_ffff */
+			dma-ranges = <0x0 0x00000000 0x0 0x00000000 0x0 0x80000000>,
+				     <0x0 0x80000000 0x1 0x00000000 0x0 0x10000000>,
+				     <0x0 0xa0000000 0x1 0x20000000 0x3 0x60000000>;
 
 			pcie1: pcie@ca400000 {
 				device_type = "pci";
@@ -1247,6 +1259,17 @@ pcie1_port: pcie@0 {
 					ranges;
 				};
 			};
+		};
+
+		pcie2-bus {
+			compatible = "simple-bus";
+			ranges;
+			#address-cells = <2>;
+			#size-cells = <2>;
+			/* skips pcie2's own window, bus 0xa000_0000-0xb7ff_ffff */
+			dma-ranges = <0x0 0x00000000 0x0 0x00000000 0x0 0x80000000>,
+				     <0x0 0x80000000 0x1 0x00000000 0x0 0x20000000>,
+				     <0x0 0xb8000000 0x1 0x38000000 0x3 0x48000000>;
 
 			pcie2: pcie@ca800000 {
 				device_type = "pci";

base-commit: d05c6236496071916e19012cda7149465f15e66e
-- 
2.53.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] riscv: dts: spacemit: k1: give each PCIe port its own DMA window
  2026-11-13  2:31 [PATCH v2] riscv: dts: spacemit: k1: give each PCIe port its own DMA window Vlad Banea
@ 2026-11-13  8:40 ` Troy Mitchell
  2026-11-14  1:44 ` Yixun Lan
  2026-11-17  8:49 ` Frédéric Mahé
  2 siblings, 0 replies; 5+ messages in thread
From: Troy Mitchell @ 2026-11-13  8:40 UTC (permalink / raw)
  To: Vlad Banea, Yixun Lan
  Cc: troy.mitchell, wangruikang, guodong.xu, jyc0019, robh, krzk+dt,
	conor+dt, pjw, palmer, aou, alex, devicetree, linux-riscv,
	spacemit, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 859 bytes --]

On Fri Nov 13, 2026 at 2:31 AM GMT, Vlad Banea wrote:
> On K1 a PCIe master only sees DDR: bus addresses 0-2 GB map to CPU
> 0-2 GB and bus 2-16 GB to CPU 4-18 GB. A root port does not forward
> upstream an inbound access that falls inside its own memory window, so
> dma-ranges must skip each port's own outbound window; the other ports'
> windows reach memory.
>
> The shared pcie-bus skips all three windows, bus 0x8000_0000-0xb7ff_ffff,
> which leaves CPU addresses 0x1_0000_0000-0x1_37ff_ffff unreachable from
> every port. Give each port its own bus that skips only its own window.
> On boards with more than 2 GB of RAM, each port can then reach another
> 512-640 MB without SWIOTLB bouncing.
>
> Signed-off-by: Vlad Banea <montrealtango@gmail.com>
Reviewed-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>


-- 
Troy Mitchell


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 273 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] riscv: dts: spacemit: k1: give each PCIe port its own DMA window
  2026-11-13  2:31 [PATCH v2] riscv: dts: spacemit: k1: give each PCIe port its own DMA window Vlad Banea
  2026-11-13  8:40 ` Troy Mitchell
@ 2026-11-14  1:44 ` Yixun Lan
  2026-11-17  8:49 ` Frédéric Mahé
  2 siblings, 0 replies; 5+ messages in thread
From: Yixun Lan @ 2026-11-14  1:44 UTC (permalink / raw)
  To: Vlad Banea
  Cc: troy.mitchell, wangruikang, guodong.xu, jyc0019, robh, krzk+dt,
	conor+dt, pjw, palmer, aou, alex, devicetree, linux-riscv,
	spacemit, linux-kernel

Hi Vlad Banea,

On 21:31 Thu 12 Nov     , Vlad Banea wrote:
> On K1 a PCIe master only sees DDR: bus addresses 0-2 GB map to CPU
> 0-2 GB and bus 2-16 GB to CPU 4-18 GB. A root port does not forward
> upstream an inbound access that falls inside its own memory window, so
> dma-ranges must skip each port's own outbound window; the other ports'
> windows reach memory.
> 
> The shared pcie-bus skips all three windows, bus 0x8000_0000-0xb7ff_ffff,
> which leaves CPU addresses 0x1_0000_0000-0x1_37ff_ffff unreachable from
> every port. Give each port its own bus that skips only its own window.
> On boards with more than 2 GB of RAM, each port can then reach another
> 512-640 MB without SWIOTLB bouncing.
> 
> Signed-off-by: Vlad Banea <montrealtango@gmail.com>
> ---
> 
> Notes:
>     Changes in v2:
>     - describe the K1 PCIe address map instead of citing the vendor DT (Troy)
>     - "more than 2 GB" instead of 4 GB (Troy)
>     - drop the RFC tag
>     - RFC: https://lore.kernel.org/all/20261112015148.3911178-1-montrealtango@gmail.com/
>     
>     Tested on an OrangePi R2S (8 GB, RTL8125B on pcie1 and pcie2): SWIOTLB
>     use under load went from up to 87 slots to none.
> 
>  arch/riscv/boot/dts/spacemit/k1.dtsi | 27 +++++++++++++++++++++++++--
>  1 file changed, 25 insertions(+), 2 deletions(-)
> 
Reviewed-by: Yixun Lan <dlan@kernel.org>

-- 
Yixun Lan (dlan)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] riscv: dts: spacemit: k1: give each PCIe port its own DMA window
  2026-11-13  2:31 [PATCH v2] riscv: dts: spacemit: k1: give each PCIe port its own DMA window Vlad Banea
  2026-11-13  8:40 ` Troy Mitchell
  2026-11-14  1:44 ` Yixun Lan
@ 2026-11-17  8:49 ` Frédéric Mahé
  2026-11-17  9:51   ` Frédéric Mahé
  2 siblings, 1 reply; 5+ messages in thread
From: Frédéric Mahé @ 2026-11-17  8:49 UTC (permalink / raw)
  To: Vlad Banea
  Cc: Frédéric Mahé,
	Yixun Lan, troy.mitchell, wangruikang, guodong.xu, jyc0019, robh,
	krzk+dt, conor+dt, pjw, palmer, aou, alex, devicetree,
	linux-riscv, spacemit, linux-kernel

On Thu, Nov 12, 2026 at 09:31:58PM -0500, Vlad Banea wrote:
> The shared pcie-bus skips all three windows, bus 0x8000_0000-0xb7ff_ffff,
> which leaves CPU addresses 0x1_0000_0000-0x1_37ff_ffff unreachable from
> every port. Give each port its own bus that skips only its own window.

Tested on a Banana Pi BPI-F3 (16 GB) with an NVMe SSD on pcie1, on
v7.4-rc1 plus "PCI: spacemit: Ignore PERST# input in RC mode on K1".

For pages at known physical addresses (from /proc/self/pagemap), I did
one 4 KiB O_DIRECT write and read per page and counted swiotlb_bounced
events:

  CPU range                    without        with this patch
  0x1_0000_0000-0x1_0fff_ffff  1439/1439 bounced  0/864 bounced
  0x1_1000_0000-0x1_1fff_ffff  all bounced        all bounced (pcie1's own window)

Every page read back correctly in both cases, so DMA through bus
0x8000_0000 works. fio with crc32c verify (16 GiB direct, 8 GiB
buffered) also passed with both DTs.

Tested-by: Frédéric Mahé <frederic.mahe@cirad.fr>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] riscv: dts: spacemit: k1: give each PCIe port its own DMA window
  2026-11-17  8:49 ` Frédéric Mahé
@ 2026-11-17  9:51   ` Frédéric Mahé
  0 siblings, 0 replies; 5+ messages in thread
From: Frédéric Mahé @ 2026-11-17  9:51 UTC (permalink / raw)
  To: Vlad Banea
  Cc: Frédéric Mahé,
	Yixun Lan, troy.mitchell, wangruikang, guodong.xu, jyc0019, robh,
	krzk+dt, conor+dt, pjw, palmer, aou, alex, devicetree,
	linux-riscv, spacemit, linux-kernel

A follow-up question on the hole that remains for each port.

On the BPI-F3 the remaining pcie1 hole (CPU 0x1_1000_0000-0x1_1fff_ffff)
still costs a lot: anonymous pages often come from the low end of
ZONE_NORMAL, and when fio's buffers land there, 4k random reads lose
about half their IOPS to SWIOTLB bouncing.

The port only uses a small part of its 256 MB window here:

  pci 0001:00:00.0: BAR 0 [mem 0x90000000-0x900fffff]: assigned
  pci 0001:00:00.0: BAR 1 [mem 0x90100000-0x901fffff]: assigned
  pci 0001:00:00.0: bridge window [mem 0x90200000-0x902fffff]: assigned

So I tried a test DT that excludes only bus 0x9000_0000-0x903f_ffff
from pcie1's dma-ranges (the root port BARs and the bridge window, plus
margin), on top of your v2:

  dma-ranges = <0x0 0x00000000 0x0 0x00000000 0x0 0x80000000>,
               <0x0 0x80000000 0x1 0x00000000 0x0 0x10000000>,
               <0x0 0x90400000 0x1 0x10400000 0x0 0x0fc00000>,
               <0x0 0xa0000000 0x1 0x20000000 0x3 0x60000000>;

Results (v7.4-rc1, 16 GB, NVMe on pcie1):

- 15529 pages in CPU 0x1_1040_0000-0x1_1fff_ffff: 4 KiB O_DIRECT write
  and read per page, no bounce, every page read back correctly
- fio crc32c verify (16 GiB direct, 8 GiB buffered) OK, no AER
- 4k random read, IOPS (1 job QD32 / 4 jobs QD32 / 8 jobs QD16):
  v2 27.5k / 86k / 137k, test DT 47.5k / 185k / 193k
  (same as booting with mem=2G, where nothing bounces)

I did not try DMA into the bridge window itself, as that would target
the drive's own BAR.

So it looks like the root port only claims its programmed BARs and
bridge window, not the whole 256 MB aperture. Troy, is that how the K1
root port works? If so, would a smaller aperture for pcie1 (the M.2
slot on most boards, e.g. 16 MB), with a matching smaller hole, be
acceptable? The other ports could keep large windows.

Thanks,
Frédéric

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-17  9:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-13  2:31 [PATCH v2] riscv: dts: spacemit: k1: give each PCIe port its own DMA window Vlad Banea
2026-11-13  8:40 ` Troy Mitchell
2026-11-14  1:44 ` Yixun Lan
2026-11-17  8:49 ` Frédéric Mahé
2026-11-17  9:51   ` Frédéric Mahé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®