* [PATCH v2 0/2] iommu: apple-dart: device specific DMA aperture support
@ 2026-08-31 13:46 Janne Grunau
2026-08-31 13:46 ` [PATCH v2 1/2] dt-bindings: iommu: dart: Support specifying the DMA aperture Janne Grunau
2026-08-31 13:46 ` [PATCH v2 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT Janne Grunau
0 siblings, 2 replies; 6+ messages in thread
From: Janne Grunau @ 2026-08-31 13:46 UTC (permalink / raw)
To: Sven Peter, Neal Gompa, Joerg Roedel (AMD), Will Deacon,
Robin Murphy, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, iommu, devicetree, linux-kernel,
Janne Grunau, Hector Martin
Apple DARTs are often connected directly to devices that expect only a
portion of their address space to be used for DMA (for example, because
other ranges are mapped directly to something else).
The USB4 native host controller on M2 Pro/Max/Ultra devices expected to
be sent by Sven after v7.3-rc1 requires this. In the Asahi downstream
kernel the display controller and ISP require a specified DMA aperture
as well.
The downstream kernel uses a "apple,dma-range" property in the iommu
node to specify the aperture. This is not a good way to describe the
aperture as it is not property of the iommu itself but of its connected
device. iommu.txt describes this use case as DMA window in its
"#iommu-cells = <4>" example.
Implement this for DART allowing additionally 5 iommu-cells specifying a
64-bit aperture start and length. 0x100_0000_0000 is a commonly used
aperture start and the aperture often spans a 36-bit address space.
This range *can* be outside of the DART's IAS. In that case, it is
assumed that the hardware truncates addresses and the page tables will
only map the lower bits of the address. However, the specified range
cannot straddle an IAS boundary (you cannot cover more than IAS worth
of address space nor wrap).
This corresponds to the vm-base and vm-size properties on the Apple
device tree side of things.
Signed-off-by: Janne Grunau <j@jannau.net>
---
Changes in v2:
- validation of the DTS supplied aperture: page size alignment and
overflow checks
- actually add `64BIT` to the COMPILE_TEST depends
- Link to v1: https://lore.kernel.org/r/20260819-iommu-apple-dart-aperture-v1-0-252703f381aa@jannau.net
---
Janne Grunau (2):
dt-bindings: iommu: dart: Support specifying the DMA aperture
iommu: apple-dart: Support specifying the DMA aperture in the DT
.../devicetree/bindings/iommu/apple,dart.yaml | 12 ++--
drivers/iommu/apple-dart.c | 74 +++++++++++++++++++---
2 files changed, 72 insertions(+), 14 deletions(-)
---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260819-iommu-apple-dart-aperture-c3b9cc79d7e1
Best regards,
--
Janne Grunau <j@jannau.net>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] dt-bindings: iommu: dart: Support specifying the DMA aperture
2026-08-31 13:46 [PATCH v2 0/2] iommu: apple-dart: device specific DMA aperture support Janne Grunau
@ 2026-08-31 13:46 ` Janne Grunau
2026-08-31 13:46 ` [PATCH v2 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT Janne Grunau
1 sibling, 0 replies; 6+ messages in thread
From: Janne Grunau @ 2026-08-31 13:46 UTC (permalink / raw)
To: Sven Peter, Neal Gompa, Joerg Roedel (AMD), Will Deacon,
Robin Murphy, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, iommu, devicetree, linux-kernel,
Janne Grunau
Apple DARTs are often connected directly to devices that expect only a
portion of their address space to be used for DMA (for example, because
other ranges are mapped directly to something else).
Follow the "#iommu-cells = <4>" example from iommu.txt and allow
specifying the DMA aperture via additional cells. Since DART is used on
64-bit Apple silicon systems use two cells to specify the start and
length of the aperture. A common aperture starts at 0x100_0000_0000
and spans a 36-bit address space.
This corresponds to the vm-base and vm-size properties on the Apple
device tree side of things.
As not all devices require this and to keep compatibility with existing
device trees allow 1 and 5 as values for #iommu-cells.
Signed-off-by: Janne Grunau <j@jannau.net>
---
Documentation/devicetree/bindings/iommu/apple,dart.yaml | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml
index 47ec7fa52c3a..6efbe732b4ce 100644
--- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml
+++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml
@@ -44,10 +44,12 @@ properties:
Optional since not all IOMMUs are attached to a clock gate.
'#iommu-cells':
- const: 1
+ enum: [ 1, 5 ]
description:
- Has to be one. The single cell describes the stream id emitted by
- a master to the IOMMU.
+ Has to be one or five. The first cell describes the stream id emitted by
+ a master to the IOMMU. The optional second and third cell describe the
+ aperture start of a master's DMA window and fourth and fifth cell describe
+ the size of DMA window.
power-domains:
maxItems: 1
@@ -66,11 +68,11 @@ examples:
compatible = "apple,t8103-dart";
reg = <0x82f80000 0x4000>;
interrupts = <1 781 4>;
- #iommu-cells = <1>;
+ #iommu-cells = <5>;
};
master1 {
- iommus = <&dart1 0>;
+ iommus = <&dart1 0 0x100 0x0 0x10 0x0>;
};
- |+
--
2.55.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT
2026-08-31 13:46 [PATCH v2 0/2] iommu: apple-dart: device specific DMA aperture support Janne Grunau
2026-08-31 13:46 ` [PATCH v2 1/2] dt-bindings: iommu: dart: Support specifying the DMA aperture Janne Grunau
@ 2026-08-31 13:46 ` Janne Grunau
2026-08-31 16:29 ` sashiko-bot
2026-09-01 20:45 ` Sven Peter
1 sibling, 2 replies; 6+ messages in thread
From: Janne Grunau @ 2026-08-31 13:46 UTC (permalink / raw)
To: Sven Peter, Neal Gompa, Joerg Roedel (AMD), Will Deacon,
Robin Murphy, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, iommu, devicetree, linux-kernel,
Janne Grunau, Hector Martin
Apple DARTs are often connected directly to devices that expect only a
portion of their address space to be used for DMA (for example, because
other ranges are mapped directly to something else). Devices can specify
the start and end of the aperture via "iommus" args if the DART device
node specifies "#iommu-cells = <5>. Aperture start and length are 64-bit
values as apertures above and larger than 4GB are used.
Limit compile testing to 64-bit architectures to avoid warnings in the
calculation of 64-bit dma_addr_t values.
This range *can* be outside of the DART's IAS. In that case, it is
assumed that the hardware truncates addresses and the page tables will
only map the lower bits of the address. However, the specified range
cannot straddle an IAS boundary (you cannot cover more than IAS worth
of address space nor wrap).
This corresponds to the vm-base and vm-size properties on the Apple
device tree side of things.
Co-developed-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Janne Grunau <j@jannau.net>
---
drivers/iommu/apple-dart.c | 74 ++++++++++++++++++++++++++++++++++++++++------
1 file changed, 65 insertions(+), 9 deletions(-)
diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
index b160fb464c5f..ebf4547d32b4 100644
--- a/drivers/iommu/apple-dart.c
+++ b/drivers/iommu/apple-dart.c
@@ -21,6 +21,7 @@
#include <linux/io-pgtable.h>
#include <linux/iommu.h>
#include <linux/iopoll.h>
+#include <linux/minmax.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_address.h>
@@ -267,6 +268,7 @@ struct apple_dart_domain {
struct io_pgtable_ops *pgtbl_ops;
bool finalized;
+ u64 mask;
struct mutex init_lock;
struct apple_dart_atomic_stream_map stream_maps[MAX_DARTS_PER_DEVICE];
@@ -285,6 +287,13 @@ struct apple_dart_master_cfg {
/* Intersection of DART capabilitles */
u32 supports_bypass : 1;
+ /*
+ * DMA aperture start and end to be overridden by "iommus"' phandle
+ * args. By default determined by DART's ias but may be outside of it.
+ */
+ dma_addr_t dma_min;
+ dma_addr_t dma_max;
+
struct apple_dart_stream_map stream_maps[MAX_DARTS_PER_DEVICE];
};
@@ -537,7 +546,7 @@ static phys_addr_t apple_dart_iova_to_phys(struct iommu_domain *domain,
if (!ops)
return 0;
- return ops->iova_to_phys(ops, iova);
+ return ops->iova_to_phys(ops, iova & dart_domain->mask);
}
static int apple_dart_map_pages(struct iommu_domain *domain, unsigned long iova,
@@ -551,8 +560,8 @@ static int apple_dart_map_pages(struct iommu_domain *domain, unsigned long iova,
if (!ops)
return -ENODEV;
- return ops->map_pages(ops, iova, paddr, pgsize, pgcount, prot, gfp,
- mapped);
+ return ops->map_pages(ops, iova & dart_domain->mask, paddr, pgsize,
+ pgcount, prot, gfp, mapped);
}
static size_t apple_dart_unmap_pages(struct iommu_domain *domain,
@@ -563,7 +572,8 @@ static size_t apple_dart_unmap_pages(struct iommu_domain *domain,
struct apple_dart_domain *dart_domain = to_dart_domain(domain);
struct io_pgtable_ops *ops = dart_domain->pgtbl_ops;
- return ops->unmap_pages(ops, iova, pgsize, pgcount, gather);
+ return ops->unmap_pages(ops, iova & dart_domain->mask, pgsize, pgcount,
+ gather);
}
static void
@@ -590,6 +600,7 @@ static int apple_dart_finalize_domain(struct apple_dart_domain *dart_domain,
{
struct apple_dart *dart = cfg->stream_maps[0].dart;
struct io_pgtable_cfg pgtbl_cfg;
+ u32 ias = min_t(u32, dart->ias, fls64(cfg->dma_max));
int ret = 0;
int i, j;
@@ -610,7 +621,7 @@ static int apple_dart_finalize_domain(struct apple_dart_domain *dart_domain,
pgtbl_cfg = (struct io_pgtable_cfg){
.pgsize_bitmap = dart->pgsize,
- .ias = dart->ias,
+ .ias = ias,
.oas = dart->oas,
.coherent_walk = 1,
.iommu_dev = dart->dev,
@@ -623,10 +634,10 @@ static int apple_dart_finalize_domain(struct apple_dart_domain *dart_domain,
goto done;
}
+ dart_domain->mask = DMA_BIT_MASK(pgtbl_cfg.ias);
dart_domain->domain.pgsize_bitmap = pgtbl_cfg.pgsize_bitmap;
- dart_domain->domain.geometry.aperture_start = 0;
- dart_domain->domain.geometry.aperture_end =
- (dma_addr_t)DMA_BIT_MASK(pgtbl_cfg.ias);
+ dart_domain->domain.geometry.aperture_start = cfg->dma_min;
+ dart_domain->domain.geometry.aperture_end = cfg->dma_max;
dart_domain->domain.geometry.force_aperture = true;
dart_domain->finalized = true;
@@ -803,20 +814,65 @@ static int apple_dart_of_xlate(struct device *dev,
struct platform_device *iommu_pdev = of_find_device_by_node(args->np);
struct apple_dart *dart = platform_get_drvdata(iommu_pdev);
struct apple_dart *cfg_dart;
+ dma_addr_t dma_max = DMA_BIT_MASK(dart->ias);
+ dma_addr_t dma_min = 0;
int i, sid;
put_device(&iommu_pdev->dev);
- if (args->args_count != 1)
+ if (args->args_count != 1 && args->args_count != 5)
return -EINVAL;
+
sid = args->args[0];
+ if (args->args_count == 5) {
+ dma_addr_t length = ((dma_addr_t)args->args[3] << 32) | args->args[4];
+
+ if (!length)
+ return -EINVAL;
+
+ dma_min = ((dma_addr_t)args->args[1] << 32) | args->args[2];
+
+ if (!IS_ALIGNED(dma_min, dart->pgsize) ||
+ !IS_ALIGNED(length, dart->pgsize)) {
+ dev_err(dev, "Unaligned DMA window %pad, %pad (0x%x)\n",
+ &dma_min, &length, dart->pgsize);
+ return -EINVAL;
+ }
+ if (check_add_overflow(dma_min, length - 1, &dma_max)) {
+ dev_err(dev, "DMA window length (%pad) overflows range for start %pad\n",
+ &length, &dma_min);
+ return -EINVAL;
+ }
+
+ /*
+ * Ensure that the DMA window does not exceed the DART's ias.
+ */
+ if ((dma_min ^ dma_max) & ~DMA_BIT_MASK(dart->ias)) {
+ dev_err(dev, "Invalid DMA window for ias=%d\n",
+ dart->ias);
+ return -EINVAL;
+ }
+ }
+
if (!cfg) {
cfg = kzalloc_obj(*cfg);
if (!cfg)
return -ENOMEM;
/* Will be ANDed with DART capabilities */
cfg->supports_bypass = true;
+ /* Will be merged with other DARTs to the common range. */
+ cfg->dma_min = dma_min;
+ cfg->dma_max = dma_max;
+ } else {
+ if (dma_min >= cfg->dma_max || cfg->dma_min >= dma_max) {
+ dev_err(dev, "non-overlapping DMA windows: %pad..%pad, %pad..%pad\n",
+ &dma_min, &dma_max,
+ &cfg->dma_min, &cfg->dma_max);
+ return -EINVAL;
+ }
+ cfg->dma_min = max(dma_min, cfg->dma_min);
+ cfg->dma_max = min(dma_max, cfg->dma_max);
}
dev_iommu_priv_set(dev, cfg);
--
2.55.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT
2026-08-31 13:46 ` [PATCH v2 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT Janne Grunau
@ 2026-08-31 16:29 ` sashiko-bot
2026-09-01 20:45 ` Sven Peter
1 sibling, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-08-31 16:29 UTC (permalink / raw)
To: Janne Grunau; +Cc: robh, conor+dt, devicetree
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Missing Kconfig restriction for 64-bit architectures causes build warnings and undefined behavior on 32-bit compile tests
--
commit 366b6e1b688b18466f157e2752afc68e1389b902
Author: Janne Grunau <j@jannau.net>
iommu: apple-dart: Support specifying the DMA aperture in the DT
This commit adds support for parsing the "iommus" DT property to specify
the start and end of the DMA aperture. It intends to restrict compile
testing to 64-bit architectures to prevent warnings when calculating
64-bit dma_addr_t values.
> diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
> index b160fb464c5fb..ebf4547d32b41 100644
> --- a/drivers/iommu/apple-dart.c
> +++ b/drivers/iommu/apple-dart.c
[ ... ]
> @@ -803,20 +814,65 @@ static int apple_dart_of_xlate(struct device *dev,
> struct platform_device *iommu_pdev = of_find_device_by_node(args->np);
> struct apple_dart *dart = platform_get_drvdata(iommu_pdev);
> struct apple_dart *cfg_dart;
> + dma_addr_t dma_max = DMA_BIT_MASK(dart->ias);
> + dma_addr_t dma_min = 0;
> int i, sid;
>
> put_device(&iommu_pdev->dev);
>
> - if (args->args_count != 1)
> + if (args->args_count != 1 && args->args_count != 5)
> return -EINVAL;
> +
> sid = args->args[0];
>
> + if (args->args_count == 5) {
> + dma_addr_t length = ((dma_addr_t)args->args[3] << 32) | args->args[4];
[Severity: Low]
The commit message states "Limit compile testing to 64-bit architectures to
avoid warnings in the calculation of 64-bit dma_addr_t values", but there are
no changes to drivers/iommu/Kconfig in this patch.
When building this driver on a 32-bit architecture with CONFIG_COMPILE_TEST=y
and without CONFIG_ARCH_DMA_ADDR_T_64BIT, doesn't shifting a 32-bit dma_addr_t
by 32 bits here trigger undefined behavior and compiler warnings like
-Wshift-count-overflow?
> +
> + if (!length)
> + return -EINVAL;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260831-iommu-apple-dart-aperture-v2-0-d16ce3770299@jannau.net?part=2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT
2026-08-31 13:46 ` [PATCH v2 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT Janne Grunau
2026-08-31 16:29 ` sashiko-bot
@ 2026-09-01 20:45 ` Sven Peter
2026-09-02 19:17 ` Janne Grunau
1 sibling, 1 reply; 6+ messages in thread
From: Sven Peter @ 2026-09-01 20:45 UTC (permalink / raw)
To: Janne Grunau, Neal Gompa, Joerg Roedel (AMD), Will Deacon,
Robin Murphy, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, iommu, devicetree, linux-kernel,
Hector Martin
Hi,
On 8/31/26 15:46, Janne Grunau wrote:
> Apple DARTs are often connected directly to devices that expect only a
> portion of their address space to be used for DMA (for example, because
> other ranges are mapped directly to something else). Devices can specify
> the start and end of the aperture via "iommus" args if the DART device
> node specifies "#iommu-cells = <5>. Aperture start and length are 64-bit
> values as apertures above and larger than 4GB are used.
> Limit compile testing to 64-bit architectures to avoid warnings in the
> calculation of 64-bit dma_addr_t values.
I don't see any Kconfig hunk below, did you drop it by accident?
Otherwise:
Reviewed-by: Sven Peter <sven@kernel.org>
Sven
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT
2026-09-01 20:45 ` Sven Peter
@ 2026-09-02 19:17 ` Janne Grunau
0 siblings, 0 replies; 6+ messages in thread
From: Janne Grunau @ 2026-09-02 19:17 UTC (permalink / raw)
To: Sven Peter
Cc: Neal Gompa, Joerg Roedel (AMD), Will Deacon, Robin Murphy,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, asahi,
linux-arm-kernel, iommu, devicetree, linux-kernel, Hector Martin
On Tue, Sep 01, 2026 at 10:45:52PM +0200, Sven Peter wrote:
> Hi,
>
> On 8/31/26 15:46, Janne Grunau wrote:
> > Apple DARTs are often connected directly to devices that expect only a
> > portion of their address space to be used for DMA (for example, because
> > other ranges are mapped directly to something else). Devices can specify
> > the start and end of the aperture via "iommus" args if the DART device
> > node specifies "#iommu-cells = <5>. Aperture start and length are 64-bit
> > values as apertures above and larger than 4GB are used.
> > Limit compile testing to 64-bit architectures to avoid warnings in the
> > calculation of 64-bit dma_addr_t values.
>
> I don't see any Kconfig hunk below, did you drop it by accident?
yes, I accidentally removed the Kconfig change and then confused myself
with the `b4 prep --compare-to v1` into thinking I added it.
> Otherwise:
>
> Reviewed-by: Sven Peter <sven@kernel.org>
thanks
Janne
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-09-02 19:17 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-31 13:46 [PATCH v2 0/2] iommu: apple-dart: device specific DMA aperture support Janne Grunau
2026-08-31 13:46 ` [PATCH v2 1/2] dt-bindings: iommu: dart: Support specifying the DMA aperture Janne Grunau
2026-08-31 13:46 ` [PATCH v2 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT Janne Grunau
2026-08-31 16:29 ` sashiko-bot
2026-09-01 20:45 ` Sven Peter
2026-09-02 19:17 ` Janne Grunau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox