From 0dc7bdbb18670c42f3f03d59d09e1e9739745621 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 20:04:08 -0500 Subject: [PATCH 1/2] soc: apple: display-gate: t8122: let scanout use the external display DART With firmware 14.7 the display gate enables the external display DART with the device tree window 0x0..0xffffeffff, the one its PIODMA stream uses. Scanout reads framebuffers through stream 0 of the same DART, at the panel's window 0x10000000000..0x10fffffffff. Since commit 7e604265b39b ("iommu/apple-dart: intersect consumer apertures with each stream window") a consumer's window only narrows its DART's. That change took the 1 TiB bit for an alias above a 36-bit DART. The T8122 display DARTs translate 42 bits, so the bit counts, the windows are disjoint and the DART driver refuses the consumer: platform display-subsystem: DMA window 0x10000000000..0x10fffffffff does not overlap stream window 0x0000000000000000..0x0000000ffffeffff of_dma_configure() goes on without an IOMMU after such an error. On a J613 the DART joins the display subsystem, so the whole subsystem, the internal panel included, falls back to direct DMA. The display processor gets the physical addresses of its framebuffers (RAM starts at 0x10000000000), the internal display DART has no translation for them, and the firmware dies: apple-dart 28d304000.iommu: translation fault: status:0x80080004 stream:0 code:0x4 (NO PMD FOR IOVA) at 0x10007000000 apple-dcp 28ec00000.dcp: RTKit: Message (id=1): IOMFB int_handler_gated: failure: axi_rd_err [0x40000600] On a J615 the DART stays out of the subsystem and its fbdma child is the consumer that gets no IOMMU domain. The panel works and the external displays are gone. The device tree's window is right for PIODMA alone: the 14.7 firmware's buffers are mapped there at their own addresses, from 0x800000000. Move it from the DART to the PIODMA child, so each consumer's own window applies. With the 27.2 image the gate already gives both DARTs the panel's window, and that stays. The gate does this rather than the device tree because it picks the windows for the firmware, and because the tree comes with the boot loader and may be older than the kernel. The T8122 cases of the display gate KUnit suite now check where the window ends up. The three 14.7 cases fail without the change. Fixes: 7e604265b39b ("iommu/apple-dart: intersect consumer apertures with each stream window") Fixes: 0a1289fc6015 ("arm64: dts: apple: t8122-j615: keep dcpext display DART unshared and wire fbdma") Link: https://github.com/aurora-silicon/linux/issues/4023 Link: https://github.com/aurora-silicon/linux/issues/4003 Signed-off-by: DjDeveloperr --- drivers/soc/apple/display-gate-test.c | 54 +++++++++++++++++++- drivers/soc/apple/display-gate.c | 71 +++++++++++++++++++-------- 2 files changed, 103 insertions(+), 22 deletions(-) diff --git a/drivers/soc/apple/display-gate-test.c b/drivers/soc/apple/display-gate-test.c index b542bbd79c372..5babb2ffce3f9 100644 --- a/drivers/soc/apple/display-gate-test.c +++ b/drivers/soc/apple/display-gate-test.c @@ -832,12 +832,24 @@ static void __init gt_expect_window(struct kunit *test, const char *path, const KUNIT_EXPECT_EQ_MSG(test, window[1], want[1], "%s size", path); } +/* + * On 14.7 the external display DART keeps no window of its own: it is the + * PIODMA stream's alone, so scanout at the panel's is not disjoint from it. + */ +static void __init gt_expect_piodma_window(struct kunit *test, const u64 want[2]) +{ + KUNIT_EXPECT_FALSE(test, of_property_present(gt_node(test, GT_T8122_DISPEXT_DART), + "apple,dma-range")); + gt_expect_window(test, GT_T8122_DCPEXT "/piodma", want); +} + /* * The panel as gt_expect_enabled() checks it, and the dcpext enabled or not * with all it needs. When enabled, @shared says whether its scanout DART joins * the display subsystem's domain (disabling fbdma) or stays out (leaving fbdma * available for framebuffer mirroring). @window: the window both dcpext DARTs - * must have, NULL for the device tree's own. + * must have, NULL for the device tree's own (the display DART's moved to the + * PIODMA stream when enabled). */ static void __init gt_expect_dcpext_mode(struct kunit *test, bool enabled, bool shared, const u64 *window) @@ -869,7 +881,14 @@ static void __init gt_expect_dcpext_mode(struct kunit *test, bool enabled, bool KUNIT_EXPECT_EQ(test, gt_okay(test, GT_T8122_DCPEXT "/fbdma"), !shared); } gt_expect_window(test, GT_T8122_DCPEXT_DART, window ?: gt_t8122_dcpext_window); - gt_expect_window(test, GT_T8122_DISPEXT_DART, window ?: gt_t8122_dispext_window); + if (enabled && !window) { + gt_expect_piodma_window(test, gt_t8122_dispext_window); + } else { + gt_expect_window(test, GT_T8122_DISPEXT_DART, window ?: gt_t8122_dispext_window); + KUNIT_EXPECT_FALSE(test, of_property_present(gt_node(test, + GT_T8122_DCPEXT "/piodma"), + "apple,dma-range")); + } /* The panel's own window stays as it is. */ gt_expect_window(test, "/t8122-soc/iommu@28d30c000", gt_t8122_panel_window); } @@ -887,6 +906,36 @@ static void __init gate_t8122_dcpext_not_ready(struct kunit *test) gt_expect_dcpext(test, false, NULL); } +/* + * gate_t8122_dcpext_piodma_window() alone: a window the PIODMA stream already + * has stays, and a display DART without one changes nothing. + */ +static void __init gate_t8122_dcpext_piodma_own_window(struct kunit *test) +{ + struct device_node *piodma = gt_node(test, GT_T8122_DCPEXT "/piodma"); + struct device_node *disp_dart = gt_node(test, GT_T8122_DISPEXT_DART); + static const u32 own[4] __initconst = { 0x8, 0x0, 0x7, 0xffff0000 }; + struct gate_test *t = test->priv; + struct of_changeset cs, none; + + gt_set_u32_array(test, GT_T8122_DCPEXT "/piodma", "apple,dma-range", + own, ARRAY_SIZE(own)); + KUNIT_ASSERT_EQ(test, of_changeset_apply(&t->cs), 0); + of_changeset_init(&cs); + KUNIT_ASSERT_EQ(test, gate_t8122_dcpext_piodma_window(&cs, piodma, disp_dart), 0); + KUNIT_ASSERT_EQ(test, of_changeset_apply(&cs), 0); + gt_expect_piodma_window(test, gt_t8122_dcpext_window); + + of_changeset_init(&none); + KUNIT_EXPECT_EQ(test, gate_t8122_dcpext_piodma_window(&none, piodma, disp_dart), 0); + KUNIT_EXPECT_TRUE(test, list_empty(&none.entries)); + of_changeset_destroy(&none); + + KUNIT_EXPECT_EQ(test, of_changeset_revert(&cs), 0); + of_changeset_destroy(&cs); + gt_expect_window(test, GT_T8122_DISPEXT_DART, gt_t8122_dispext_window); +} + /* On 14.7.0 it starts with the device tree's windows. */ static void __init gate_t8122_dcpext_v14_7(struct kunit *test) { @@ -1111,6 +1160,7 @@ static struct kunit_case gate_t8122_cases[] __refdata = { KUNIT_CASE(gate_t8122_not_inherited_on), KUNIT_CASE(gate_t8122_dcpext_not_ready), KUNIT_CASE(gate_t8122_dcpext_v14_7), + KUNIT_CASE(gate_t8122_dcpext_piodma_own_window), KUNIT_CASE(gate_t8122_dcpext_loader_default_marker), KUNIT_CASE(gate_t8122_dcpext_other_marker), KUNIT_CASE(gate_t8122_dcpext_board_mirrors), diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index 6bc8de49503f8..cdeaba0e04326 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -1900,6 +1900,28 @@ static bool __init gate_node_in(struct device_node *const *nodes, int n, return false; } +/* Give @np the DMA window @window, in @cs. */ +static int __init gate_set_window(struct of_changeset *cs, struct device_node *np, + const struct property *window) +{ + /* Kept for good: the live tree refers to it once applied. */ + struct property *prop = kzalloc_obj(*prop); + void *value = kmemdup(window->value, window->length, GFP_KERNEL); + int ret = -ENOMEM; + + if (prop && value) { + prop->name = "apple,dma-range"; + prop->length = window->length; + prop->value = value; + ret = of_changeset_update_property(cs, np, prop); + } + if (ret) { + kfree(prop); + kfree(value); + } + return ret; +} + /* * On the 27.2 image the T8122 external processor and its scanout use the * panel's DMA window (the 1 TiB alias): the display subsystem takes the @@ -1926,30 +1948,37 @@ static int __init gate_t8122_dcpext_alias(struct of_changeset *cs, return -ENODEV; } - for (i = 0; i < ARRAY_SIZE(targets) && !ret; i++) { - /* Kept for good: the live tree refers to it once applied. */ - struct property *prop = kzalloc_obj(*prop); - void *value = kmemdup(window->value, window->length, GFP_KERNEL); - - if (!prop || !value) { - kfree(prop); - kfree(value); - ret = -ENOMEM; - break; - } - prop->name = "apple,dma-range"; - prop->length = window->length; - prop->value = value; - ret = of_changeset_update_property(cs, targets[i], prop); - if (ret) { - kfree(prop); - kfree(value); - } - } + for (i = 0; i < ARRAY_SIZE(targets) && !ret; i++) + ret = gate_set_window(cs, targets[i], window); of_node_put(panel_dart); return ret; } +/* + * On 14.7 the device tree's window of @disp_dart (from 0) is the one its + * PIODMA stream uses. Scanout reads framebuffers through another stream of + * that DART, at the panel's window (the 1 TiB alias). The DART translates 42 + * bits, so the two windows are disjoint, and the DART driver refuses a + * consumer whose window its DART's excludes: the display subsystem, or fbdma + * on a board that keeps the DART out of it, would get no IOMMU domain. Move + * the window to @piodma, so that it binds that stream alone. + */ +static int __init gate_t8122_dcpext_piodma_window(struct of_changeset *cs, + struct device_node *piodma, + struct device_node *disp_dart) +{ + struct property *window = of_find_property(disp_dart, "apple,dma-range", NULL); + int ret = 0; + + if (!window) + return 0; + if (!of_property_present(piodma, "apple,dma-range")) + ret = gate_set_window(cs, piodma, window); + if (!ret) + ret = of_changeset_remove_property(cs, disp_dart, window); + return ret; +} + /* * Does @np's display DART go into the display subsystem's domain? 1 or 0, * or -ENODEV on a board that forbids it and has no @fbdma child to mirror @@ -2077,6 +2106,8 @@ static void __init gate_t8122_dcpext_one(struct device_node *np) ret = gate_add_bool(cs, entry, "apple,defer-startup-ack"); if (!ret && apple_t8122_dcpext_v27_2(np)) ret = gate_t8122_dcpext_alias(cs, dart, disp_dart); + else if (!ret) + ret = gate_t8122_dcpext_piodma_window(cs, piodma, disp_dart); if (!ret) ret = of_changeset_update_prop_string(cs, dart, "status", "okay"); if (!ret) From 8c2e9e5dbd9014048029e23240633d016500d8c5 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 20:04:09 -0500 Subject: [PATCH 2/2] iommu/apple-dart: test the T8122 display windows on a 42-bit DART The consumer window case stood in for the J613 display DARTs with a 36-bit DART. Theirs translate 42 bits: a J613 refuses the 1 TiB scanout window on the external display DART's low one, which a 36-bit mask would accept. Describe that case as the 36-bit one it is, and add the T8122 windows on a 42-bit DART: the low DART window refuses scanout, and a DART without one serves scanout and PIODMA, each in its own window. Link: https://github.com/aurora-silicon/linux/issues/4023 Signed-off-by: DjDeveloperr --- drivers/iommu/apple-dart-test.c | 66 +++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/apple-dart-test.c b/drivers/iommu/apple-dart-test.c index 137b02133bfac..cf91eea7c90b1 100644 --- a/drivers/iommu/apple-dart-test.c +++ b/drivers/iommu/apple-dart-test.c @@ -115,9 +115,10 @@ static void apple_dart_test_consumer_window(struct kunit *test) dev->of_node = &node; /* - * J613's common scanout alias survives both DART defaults, but only - * inside each stream's own window: the external DART excludes its top - * 64 KiB, so the shared aperture must too. + * On a 36-bit DART the 1 TiB scanout alias lies above the translated + * bits. It survives both DART defaults, but only inside each stream's + * own window: the second DART excludes its top 64 KiB, so the shared + * aperture must too. */ for (i = 0; i < 2; i++) { dart->dma_min = i ? 0 : 0x10000000000; @@ -155,6 +156,64 @@ static void apple_dart_test_consumer_window(struct kunit *test) KUNIT_EXPECT_EQ(test, dma_max, (dma_addr_t)0xffffeffff); } +/* + * The T8122 display DARTs translate 42 bits, so the 1 TiB scanout window is no + * alias there: it is disjoint from a low window on the DART, and a DART that + * serves both must have none, with each consumer naming its own. + */ +static void apple_dart_test_t8122_consumer_window(struct kunit *test) +{ + static const struct { + u64 dart_min, dart_max, base, size; + int ret; + u64 min, max; + } windows[] = { + /* Scanout: the panel's DART, the external one with a low window. */ + { 0x10000000000, 0x10fffffffff, 0x10000000000, 0x1000000000, + 0, 0x10000000000, 0x10fffffffff }, + { 0, 0xffffeffff, 0x10000000000, 0x1000000000, -EINVAL }, + /* The external DART without one: scanout, then PIODMA. */ + { 0, DMA_BIT_MASK(42), 0x10000000000, 0x1000000000, + 0, 0x10000000000, 0x10fffffffff }, + { 0, DMA_BIT_MASK(42), 0, 0xfffff0000, 0, 0, 0xffffeffff }, + }; + __be64 value[2]; + struct property property = { + .name = "apple,dma-range", + .length = sizeof(value), + .value = value, + }; + struct device_node node = { .properties = &property }; + struct of_phandle_args args = { .args_count = 1 }; + struct apple_dart *dart; + struct device *dev; + dma_addr_t dma_min, dma_max; + int i; + + dev = kunit_device_register(test, "apple-dart-t8122-window-test"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + dart = kunit_kzalloc(test, sizeof(*dart), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, dart); + dart->ias = 42; + dart->pgsize = SZ_16K; + dev->of_node = &node; + + for (i = 0; i < ARRAY_SIZE(windows); i++) { + value[0] = cpu_to_be64(windows[i].base); + value[1] = cpu_to_be64(windows[i].size); + dart->dma_min = windows[i].dart_min; + dart->dma_max = windows[i].dart_max; + KUNIT_EXPECT_EQ_MSG(test, apple_dart_parse_dma_window(dev, dart, &args, &dma_min, + &dma_max), + windows[i].ret, "window %d", i); + if (windows[i].ret) + continue; + KUNIT_EXPECT_EQ_MSG(test, dma_min, (dma_addr_t)windows[i].min, "window %d", i); + KUNIT_EXPECT_EQ_MSG(test, dma_max, (dma_addr_t)windows[i].max, "window %d", i); + } + dev->of_node = NULL; +} + static void apple_dart_test_disjoint_consumer_window(struct kunit *test) { /* 2 GiB at the 1 TiB alias; its low bits start at 2 GiB. */ @@ -2341,6 +2400,7 @@ static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_topology), KUNIT_CASE(apple_dart_test_iommu_specifiers), KUNIT_CASE(apple_dart_test_consumer_window), + KUNIT_CASE(apple_dart_test_t8122_consumer_window), KUNIT_CASE(apple_dart_test_disjoint_consumer_window), KUNIT_CASE(apple_dart_test_invalid_consumer_window), KUNIT_CASE(apple_dart_test_independent_remap_roots),