From 65e3300cb31f2f246538ff993f5e858935f3ab02 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 22:59:24 +1100 Subject: [PATCH 01/25] arm64: dts: apple: t8132: give the internal DCP its realtime bandwidth slot The firmware-27 DCP backend asks for apple,bw-scratch before it binds ("Incompatible devicetree!" without it). The T8132 internal DCP's slot is in the PMC window it already has as disp-4: bandwidth agent 0, the one the ADT's /arm-io/disp0 bw_req interrupt (BIRQ 0x35) names in the PMGR bwr-agent table, 0x20000 into the window; agents are 0x4000 apart, which puts the dcpexts' agents 3 and 4 at the pmgr_dcpext slots this tree already has. Describe it the way the dcpexts' slots are described, inside display window 4. The M4 26.6.2 backend reads the same property and has run the internal panel without a mailbox; keep it that way by taking the mailbox for an external processor only, so nothing changes on 26.6.2. Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t8132-dcp.dtsi | 13 +++++++++++++ drivers/gpu/drm/apple/iomfb_m4.c | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t8132-dcp.dtsi b/arch/arm64/boot/dts/apple/t8132-dcp.dtsi index b4383741a15fb..b50f371e31fb9 100644 --- a/arch/arm64/boot/dts/apple/t8132-dcp.dtsi +++ b/arch/arm64/boot/dts/apple/t8132-dcp.dtsi @@ -70,6 +70,7 @@ iommus = <&dcp_dart 23>; power-domains = <&ps_disp_cpu>; dma-noncoherent; + apple,bw-scratch = <&pmgr_dcp 0 4 0>; status = "disabled"; disp0_piodma: piodma { @@ -79,6 +80,18 @@ }; }; + /* + * The internal pipe's realtime bandwidth request slot in the PMC, 0x20000 + * into the window the DCP has as disp-4: bandwidth agent 0, the one the + * ADT's disp0 bw_req interrupt names (agents are 0x4000 apart from + * 0x20000; the dcpexts' agents 3 and 4 are pmgr_dcpext's slots). + */ + pmgr_dcp: power-management@382820000 { + reg = <0x3 0x82820000 0x0 0x8>; + reg-names = "dcp-bw-scratch"; + #apple,bw-scratch-cells = <3>; + }; + /* The scanout frontend; it has no registers of its own. */ display: display-subsystem { compatible = "apple,t8132-display-subsystem", "apple,t8132-display-diagnostics"; diff --git a/drivers/gpu/drm/apple/iomfb_m4.c b/drivers/gpu/drm/apple/iomfb_m4.c index 1d61f083ff60f..eb2523c95c8d5 100644 --- a/drivers/gpu/drm/apple/iomfb_m4.c +++ b/drivers/gpu/drm/apple/iomfb_m4.c @@ -2695,7 +2695,12 @@ int iomfb_m4_init(struct apple_dcp *owner) return -ENOMEM; dcp->owner = owner; dcp->dev = dev; - dcp->bw_mailbox = dcp_m4_bw_mailbox(dev); + /* + * The 26.6.2 panel path runs without the realtime bandwidth mailbox; + * the slot the DT gives the internal DCP is the firmware-27 backend's. + */ + if (external) + dcp->bw_mailbox = dcp_m4_bw_mailbox(dev); mutex_init(&dcp->lock); mutex_init(&dcp->ext_modes_lock); spin_lock_init(&dcp->state_lock); From 58477fdd2f1af3c94d6a724e7d05f58084480e5c Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 22:59:25 +1100 Subject: [PATCH 02/25] drm/apple: dcp: run the T8132 internal DCP on firmware 27.2 with the 27.2 table On the macOS 27.2 stub the M4 MacBook Air's (J713) internal display processor runs the 26B123 image the J773g's processors run (UUID B3BA603C), and the M4 backend refuses it ("unqualified firmware 26.6.2 handoff"), so the panel stays on simpledrm. Admit an internal T8132 DCP that the boot loader handed over with that image (firmware version and compatibility 27.2.0) and with the firmware-27 clock metadata (apple,clock-ids, from /arm-io/disp0) to the firmware-27 backend with the 27.2 method table, before the M4 hw data is looked at. Requiring the clocks keeps out a main DCP that a boot loader leaves running idle without a handoff, as on the Mac mini. It gets apple_dcp_hw_t8132_v27: 41-bit firmware DMA (apple,dma-range <0x100 0 0x10 0> ends at 1 TiB + 64 GiB), no DPTX port service, and adoption of the live session iBoot leaves running. No sleep support. That the T8132 26B123 image numbers its IOMFB methods as the T6041 and T8142 26B123 images do is the assumption the J773g dcpext admission makes too. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 34 +++++++++++++++++++++++++++++++ include/linux/soc/apple/display.h | 14 +++++++++++++ 2 files changed, 48 insertions(+) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index f44e79ad32660..b5d03469575e8 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -6027,6 +6027,20 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) * 27.2 driving the mini's dcpext0 has to confirm the A4xx/A5xx IDs * before this is relied on. */ + /* + * The T8132 internal panel's processor on the macOS 27.2 stub, handed + * over by the boot loader with the 26B123 image (see + * apple_t8132_dcp_v27_2()): the firmware-27 backend with the 27.2 + * method table. That this image numbers its IOMFB methods as the + * T6041 and T8142 26B123 images do is the same assumption the J773g + * dcpext case below makes. + */ + if (apple_t8132_dcp_v27_2(dev->of_node)) { + /* Checked by apple_t8132_dcp_v27_2(). */ + dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); + return dcp_v27_method_table(dev, compat_str); + } + if (apple_t8132_dcpext_v27_2(dev->of_node)) { /* Checked by apple_t8132_dcpext_v27_2(). */ dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); @@ -7218,6 +7232,23 @@ static int dcp_s2r_pm_register(struct apple_dcp *dcp); * No sleep support: neither a firmware-27 sleep nor a link release has run * on this processor. */ +/* + * T8132 internal display processor on firmware 27.2, admitted by + * dcp_check_firmware_version(), whatever hw data its compatible matched: + * - firmware_dma_bits 41: its firmware DART's window (apple,dma-range + * <0x100 0 0x10 0>, 1 TiB + 64 GiB) takes 41 bits, as the dcpext's does. + * - num_dptx_ports 0: it drives the panel only. + * - adopt_live_session: iBoot leaves it running with the 27.2 image and the + * panel lit; Linux never starts its CPU. + * No sleep support: no firmware-27 sleep has run on this processor. + */ +static const struct apple_dcp_hw_data apple_dcp_hw_t8132_v27 = { + .firmware_dma_bits = 41, + .num_dptx_ports = 0, + .adopt_live_session = true, + .firmware_compat = DCP_FIRMWARE_V_27_0, +}; + static const struct apple_dcp_hw_data apple_dcp_hw_t8132_dcpext_v27 = { .firmware_dma_bits = 41, .num_dptx_ports = 2, @@ -7429,6 +7460,9 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) if (fw_compat == DCP_FIRMWARE_V_27_0 && of_device_is_compatible(dev->of_node, "apple,t8132-dcpext")) dcp->hw = apple_dcp_hw_t8132_dcpext_v27; + if (fw_compat == DCP_FIRMWARE_V_27_0 && + of_device_is_compatible(dev->of_node, "apple,t8132-dcp")) + dcp->hw = apple_dcp_hw_t8132_v27; /* * A SoC with derived power words is offered the stop only when asked for, and only on * firmware 27.0, whose calls are the ones that ran with them. diff --git a/include/linux/soc/apple/display.h b/include/linux/soc/apple/display.h index f6264be746ca9..7ff30067ddc30 100644 --- a/include/linux/soc/apple/display.h +++ b/include/linux/soc/apple/display.h @@ -50,6 +50,20 @@ static inline bool apple_dcp_image_v27_2(const struct device_node *np, compat[0] == 27 && compat[1] == 2 && compat[2] == 0; } +/* + * A T8132 internal display processor that the boot loader handed over with + * the 27.2 (26B123) image and the firmware-27 clock metadata (apple,clock-ids + * from the ADT's /arm-io/disp0): the firmware-27 backend's, not the M4 + * 26.6.2 one's. Keyed on the processor, the image and the handoff, so a main + * DCP a boot loader leaves running idle (a Mac mini's) is never adopted. + */ +static inline bool apple_t8132_dcp_v27_2(const struct device_node *np) +{ + return apple_dcp_image_v27_2(np, "apple,t8132-dcp", + APPLE_T8132_DCP_26B123_UUID) && + of_property_present(np, "apple,clock-ids"); +} + static inline bool apple_t6041_dcp_any_v27_2(const struct device_node *np, const char *compat_name) { From 5df68cfa2f7ecd9c9abc7407a4acc356d294ceb4 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 23:10:22 +1100 Subject: [PATCH 03/25] selftests: apple-dcp: boot: the T8132 internal DCP's 27.2 admission Build the real apple_t8132_dcp_v27_2() into the t6041-v27-admission unit (of_property_present() mocked for apple,clock-ids) and check that the internal processor handed over with the T8132 26B123 image and its firmware-27 clocks runs the 27.2 table on either firmware path, and that without the clocks, with the T6041 image, a missing UUID or another release it is the M4 backend's on its path and nobody's off it. Signed-off-by: Ryan Murray --- .../selftests/drivers/gpu/apple-dcp/boot.py | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py index 543e5be169698..f05a1c835a3b7 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py @@ -204,7 +204,7 @@ def t6041_v27_admission(root): assert len(uuid_defines) == 3 helper = '\n'.join((*uuid_defines, *( block(display_h, 'static inline bool ' + name + '(') for name in ( - 'apple_dcp_image_v27_2', + 'apple_dcp_image_v27_2', 'apple_t8132_dcp_v27_2', 'apple_t6041_dcp_any_v27_2', 'apple_t6041_dcp_v27_2', 'apple_t6041_dcpext_v27_2', 'apple_t8122_dcp_v27_2')))) iomfb_h = (root / 'drivers/gpu/drm/apple/iomfb.h').read_text() @@ -247,6 +247,7 @@ def t6041_v27_admission(root): int fw_cells; u32 compat[3]; int compat_cells; + bool clock_ids; }; struct device { struct device_node *of_node; @@ -256,6 +257,11 @@ def t6041_v27_admission(root): { return np && np->compatible && !strcmp(np->compatible, s); } +static bool of_property_present(const struct device_node *np, const char *name) +{ + assert(!strcmp(name, "apple,clock-ids")); + return np && np->clock_ids; +} static int of_property_count_strings(const struct device_node *np, const char *name) { assert(!strcmp(name, "apple,firmware-uuid")); @@ -486,10 +492,46 @@ def t6041_v27_admission(root): node.compat[1] = 2; node.fw[2] = 1; assert(!apple_t8132_dcpext_v27_2(&node)); node.fw[2] = 0; assert(apple_t8132_dcpext_v27_2(&node)); + /* + * The internal DCP handed over with the T8132 27.2 image and its + * firmware-27 clocks (the M4 Air's on the 27.2 stub) runs the 27.2 + * table on any board and either firmware path; without the clocks it is + * the M4 backend's on its path and nobody's off it, as above. + */ + reset_t6041_26b123(false); + node.compatible = "apple,t8132-dcp"; + node.uuid = APPLE_T8132_DCP_26B123_UUID; + node.clock_ids = true; + for (unsigned path = 0; path < 2; path++) { + t8132_firmware_path = path; + assert(apple_t8132_dcp_v27_2(&node)); + assert(!apple_t8132_dcpext_v27_2(&node)); + assert(!apple_t6041_dcp_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_V_27_0); + node.clock_ids = false; + assert(!apple_t8132_dcp_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == (path ? DCP_FIRMWARE_M4 : DCP_FIRMWARE_UNKNOWN)); + node.clock_ids = true; + } + t8132_firmware_path = true; + /* Not on a dcpext, nor with the T6041 image, a missing UUID or another release. */ + node.compatible = "apple,t8132-dcpext"; assert(!apple_t8132_dcp_v27_2(&node)); + node.compatible = "apple,t8132-dcp"; + node.uuid = APPLE_T6041_DCP_26B123_UUID; assert(!apple_t8132_dcp_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_M4); + node.uuid = APPLE_T8132_DCP_26B123_UUID; + node.uuid_count = 0; assert(!apple_t8132_dcp_v27_2(&node)); + node.uuid_count = 1; + node.compat[1] = 0; assert(!apple_t8132_dcp_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_M4); + node.compat[1] = 2; assert(apple_t8132_dcp_v27_2(&node)); + t8132_firmware_path = false; + dev.hw = &hw_t6041; puts("PASS T6041 26B123 v27.2 internal/external admission, refusal controls, and desktop 26.x preservation"); puts("PASS T8122 internal DCP on its 27.2 image alone runs the 27.2 table"); puts("PASS T8132 M4 backend only on its firmware path; a T8132 dcpext on the 27.2 image runs the 27.2 table on any board"); + puts("PASS T8132 internal DCP with the 27.2 image and its firmware-27 clocks runs the 27.2 table; without them nothing changes"); return 0; } ''' From 8ef008a54e20e5346f48a153851cd52e7646f13c Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 01:59:06 +1100 Subject: [PATCH 04/25] iommu: apple-dart: keep a 27.2 J713 internal display DART's locked roots like T6041's On the macOS 27.2 stub the M4 MacBook Air's internal display processor runs the 26B123 image and the firmware-27 backend. That backend DMAs through ordinary IOMMU domains: RTKit and IOMFB shared memory on SID23, PIODMA maps on SID16, scan-out on SID0. The borrowed J713 display path cannot serve it. It admits only the 26.6.2 layout, so the DCP is left without any IOMMU domain, and it reserves the whole SID23 window from generic DMA for the M4 backend's own allocators. When the internal DCP was handed over with the 27.2 image and its firmware-27 clocks (apple_t8132_dcp_v27_2()), do not borrow its two display DARTs. Give them the locked-root handling T6041's display DARTs get on firmware 27 (fw_mirror): the firmware's live slots are kept and Linux's mappings go into the rest. Refuse the DART if it is not locked as expected. Nothing changes for a DCP on its 26.6.2 handoff, or for a 27.2 one without the firmware-27 clocks (the default Stage 2 hands it over without them). Signed-off-by: Ryan Murray --- drivers/iommu/apple-dart.c | 24 ++++++++++++++++++++++-- include/linux/soc/apple/t8132.h | 17 +++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 33a29ce9beb04..e4efde6868029 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -5361,7 +5361,7 @@ static int apple_dart_probe(struct platform_device *pdev) bool tunneled = dev->of_node->parent && of_node_name_prefix(dev->of_node->parent, "usb4-pcie-tunnel-"); - bool j713_display, j713_dcpext, j713_dispext, j713_radio; + bool j713_display, j713_dcpext, j713_dispext, j713_radio, j713_display_v27 = false; /* * The M4 internal display DARTs are live: DCP firmware (SID23) @@ -5372,6 +5372,18 @@ static int apple_dart_probe(struct platform_device *pdev) j713_display = res && !tunneled && apple_t8132_firmware_path() && of_device_is_compatible(dev->of_node, "apple,t8132-dart") && (res->start == 0x30a300000ULL || res->start == 0x30a340000ULL); + /* + * The internal DCP handed over with the 27.2 image runs the firmware-27 + * backend, which DMAs through ordinary domains (RTKit and IOMFB shared + * memory, PIODMA maps) as on T6041. Its two display DARTs are then not + * borrowed: they keep their firmware's locked roots the way T6041's do + * (fw_mirror below). The borrowed path admits only the 26.6.2 layout + * and reserves its whole SID23 window from generic DMA. + */ + if (j713_display && apple_t8132_internal_dcp_v27_2()) { + j713_display = false; + j713_display_v27 = true; + } /* The external DCP firmware DARTs (SID23) of dcpext0 and dcpext1. */ j713_dcpext = res && !tunneled && apple_t8132_firmware_path() && of_device_is_compatible(dev->of_node, "apple,t8132-dart") && @@ -5889,7 +5901,15 @@ static int apple_dart_probe(struct platform_device *pdev) (of_device_is_compatible(dev->of_node, "apple,t6041-dart") || of_device_is_compatible(dev->of_node, "apple,t6050-dart") || of_device_is_compatible(dev->of_node, "apple,t8140-dart") || - of_device_is_compatible(dev->of_node, "apple,t8142-dart")); + of_device_is_compatible(dev->of_node, "apple,t8142-dart") || + j713_display_v27); + if (j713_display_v27) + dev_info(dev, "J713 internal display DART on the 27.2 image: locked roots kept (%s)\n", + dart->fw_mirror ? "mirror" : "NOT locked: refusing"); + if (j713_display_v27 && !dart->fw_mirror) { + ret = -EINVAL; + goto err_clk_disable; + } /* * J614s may arrive with the MTP live after the boot keyboard used it. * Do not reset its DART unless there is no advertised handoff. diff --git a/include/linux/soc/apple/t8132.h b/include/linux/soc/apple/t8132.h index 72ece899b148a..d47cfe0a13e13 100644 --- a/include/linux/soc/apple/t8132.h +++ b/include/linux/soc/apple/t8132.h @@ -55,6 +55,23 @@ static inline bool apple_t8132_firmware_path(void) return apple_t8132_air() || apple_t8132_qualified_firmware(); } +/* + * The available internal display processor was handed over with the 27.2 + * image and its firmware-27 clocks (apple_t8132_dcp_v27_2()): it runs the + * firmware-27 backend, whose DMA needs ordinary IOMMU domains. + */ +static inline bool apple_t8132_internal_dcp_v27_2(void) +{ + struct device_node *np; + bool v27 = false; + + for_each_compatible_node(np, NULL, "apple,t8132-dcp") { + if (of_device_is_available(np) && apple_t8132_dcp_v27_2(np)) + v27 = true; + } + return v27; +} + /* * A T8132 external display processor handed over with the 27.2 image * (first on the Mac mini, J773g): it runs the firmware-27 backend From 8644419127e6d3272698de4ebeebbe7e2caab53c Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 02:23:14 +1100 Subject: [PATCH 05/25] iommu: apple-dart: map a 27.2 J713 display DART's firmware segments as its leaves do On the J713's 27.2 handoff the internal display DARTs keep their firmware's locked roots (fw_mirror). A Linux table in a slot the firmware holds must then mirror the firmware's leaves exactly, protection included (apple_dart_fw_slot_mirrors()). The boot loader re-exports the firmware's own segments as iommu-addresses, and the core maps those read-write, and uncached for this non-coherent DCP. The live leaves differ: the firmware's text is read-only, and all of its segments are cacheable (SID23 dump on the 27.2 stub: __TEXT flags 0x5, __DATA and the four other segments 0x1). As it stood, the DCP's attach would refuse every segment and leave the processor without a domain. For such a DART, give each translated region the protection the live leaves give every one of its pages. A region whose pages are not mapped there, map elsewhere or disagree keeps its protection, and the attach then refuses it as before. Signed-off-by: Ryan Murray --- drivers/iommu/apple-dart.c | 94 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index e4efde6868029..2745ab0b96a5a 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -426,6 +426,8 @@ struct apple_dart { u32 sleep_gated : 1; /* Locked roots may hold firmware slots that mirror Linux mappings. */ u32 fw_mirror : 1; + /* A J713 internal display DART on the 27.2 image (fw_mirror, not borrowed). */ + u32 j713_v27 : 1; /* * fw_mirror's four-level locked roots hold firmware's own subtrees, which * are recorded and reserved (apple_dart_snapshot_fw_tree()). Set only for @@ -4562,6 +4564,96 @@ static void apple_dart_get_fw_resv_regions(struct device *dev, } } +/* + * A J713 internal display DART on the 27.2 image (fw_mirror): the boot loader + * re-exports the firmware's own segments as iommu-addresses, which the core + * maps read-write, and uncached for this non-coherent DCP. The firmware's + * leaves say what those pages are: its text read-only, all of it cacheable. + * A Linux table in a slot the firmware holds must mirror its leaves exactly + * (apple_dart_fw_slot_mirrors()), so give each such region the protection the + * live leaves give every one of its pages. A region whose pages are not mapped + * there, map elsewhere or disagree keeps its protection, and the attach then + * refuses it as before. + */ +static void apple_dart_j713_v27_fw_prot(struct device *dev, struct list_head *head) +{ + struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev); + const int mask = IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE; + struct iommu_resv_region *region; + struct apple_dart *dart; + size_t entries; + u64 *root; + u32 ttbr; + int sid; + + if (!cfg || !cfg->stream_maps[0].dart || cfg->stream_maps[1].dart) + return; + dart = cfg->stream_maps[0].dart; + if (!dart->j713_v27 || !dart->locked || dart->hw->fmt != APPLE_DART2) + return; + entries = dart->pgsize / sizeof(u64); + sid = find_first_bit(cfg->stream_maps[0].sidmap, dart->num_streams); + if (sid >= dart->num_streams || + bitmap_weight(cfg->stream_maps[0].sidmap, dart->num_streams) != 1) + return; + if (pm_runtime_resume_and_get(dart->dev) < 0) + return; + ttbr = apple_dart_readl(dart, DART_TTBR(dart, sid, 0)); + pm_runtime_put(dart->dev); + if (!(ttbr & dart->hw->ttbr_valid) || + (dart->hw->tcr_4level && + (apple_dart_readl(dart, DART_TCR(dart, sid)) & dart->hw->tcr_4level))) + return; + ttbr &= ~dart->hw->ttbr_valid; + if (dart->hw->ttbr_addr_field_shift) + ttbr >>= dart->hw->ttbr_addr_field_shift; + root = memremap(((phys_addr_t)ttbr) << dart->hw->ttbr_shift, dart->pgsize, MEMREMAP_WB); + if (!root) + return; + + list_for_each_entry(region, head, list) { + u64 *leaf = NULL; + size_t mapped_slot = entries; + int prot = -1; + + if (region->type != IOMMU_RESV_TRANSLATED || !region->length || + !IS_ALIGNED(region->dva | region->start | region->length, dart->pgsize)) + continue; + for (u64 off = 0; off < region->length; off += dart->pgsize) { + u64 dva = region->dva + off; /* bits 14..35: the 1 TiB base drops out */ + size_t slot = (dva >> (ilog2(dart->pgsize) + ilog2(entries))) & (entries - 1); + size_t idx = (dva >> ilog2(dart->pgsize)) & (entries - 1); + u64 entry = READ_ONCE(root[slot]); + phys_addr_t phys; + int page_prot; + + if (slot != mapped_slot) { + if (leaf) + memunmap(leaf); + leaf = (entry & APPLE_DART_PTE_VALID) ? + memremap(apple_dart_pte_to_paddr(dart, entry), dart->pgsize, + MEMREMAP_WB) : NULL; + mapped_slot = slot; + } + if (!leaf || + !apple_dart_fw_leaf_decode(READ_ONCE(leaf[idx]), 0, &phys, &page_prot) || + phys != region->start + off || (prot >= 0 && page_prot != prot)) { + prot = -1; + break; + } + prot = page_prot; + } + if (leaf) + memunmap(leaf); + if (prot >= 0 && (region->prot & mask) != (prot & mask)) { + dev_info(dev, "firmware segment %pad+%#zx: protection %#x as its live leaves (asked %#x)\n", + ®ion->dva, region->length, prot & mask, region->prot & mask); + region->prot = (region->prot & ~mask) | (prot & mask); + } + } + memunmap(root); +} + static void apple_dart_get_resv_regions(struct device *dev, struct list_head *head) { @@ -4591,6 +4683,7 @@ static void apple_dart_get_resv_regions(struct device *dev, /* Keep the translated-domain requirement and inherited translations. */ iommu_dma_get_resv_regions(dev, head); + apple_dart_j713_v27_fw_prot(dev, head); apple_dart_get_fw_resv_regions(dev, head); } @@ -5906,6 +5999,7 @@ static int apple_dart_probe(struct platform_device *pdev) if (j713_display_v27) dev_info(dev, "J713 internal display DART on the 27.2 image: locked roots kept (%s)\n", dart->fw_mirror ? "mirror" : "NOT locked: refusing"); + dart->j713_v27 = j713_display_v27; if (j713_display_v27 && !dart->fw_mirror) { ret = -EINVAL; goto err_clk_disable; From e7ae9f620403069df052bd25c1c4cfbc243af117 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 03:51:17 +1100 Subject: [PATCH 06/25] arm64: dts: apple: t8132-j713: describe the internal panel The firmware-27 DCP backend takes the internal connector type (eDP) and the backlight range from the DCP's apple,panel child. The M4 26.6.2 backend never needed one, so the J713 has none, and on the 27.2 stub its panel comes up as an 'Unknown' connector without a backlight device. Describe the panel as on the other Airs: 2560x1664 at 224 ppi, 64 notch rows above the desktop, and the published 500 nits maximum. Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t8132-j713.dts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8132-j713.dts b/arch/arm64/boot/dts/apple/t8132-j713.dts index 440ecff14d4a1..e445896854733 100644 --- a/arch/arm64/boot/dts/apple/t8132-j713.dts +++ b/arch/arm64/boot/dts/apple/t8132-j713.dts @@ -195,6 +195,15 @@ &dcp { apple,pmc-interface = <&pmc_disp0>; + + panel: panel { + compatible = "apple,panel-j713", "apple,panel"; + /* 2560x1664 at 224 ppi; 64 notch rows above the desktop. */ + width-mm = <290>; + height-mm = <189>; + adj-height-mm = <181>; + apple,max-brightness = <500>; + }; }; /* From 0a33a0855d1386724d9dbd93e395105968fbc2f0 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 04:31:10 +1100 Subject: [PATCH 07/25] iommu: apple-dart: test the 27.2 J713 firmware segment protection Split the region walk from its device lookup and test it on a fake locked root: read-only text pages and read-write data pages take the protection of the leaves that map them (cacheable), a region whose leaf maps another page keeps what it asked for, and nothing changes on a DART that is not a 27.2 J713 display DART. Signed-off-by: Ryan Murray --- drivers/iommu/apple-dart-test.c | 73 +++++++++++++++++++++++++++++++++ drivers/iommu/apple-dart.c | 9 +++- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/apple-dart-test.c b/drivers/iommu/apple-dart-test.c index 0c474454ee82a..2c4096903db0f 100644 --- a/drivers/iommu/apple-dart-test.c +++ b/drivers/iommu/apple-dart-test.c @@ -1326,6 +1326,78 @@ static void apple_dart_test_host_power_tables(struct kunit *test) } #endif +/* + * A 27.2 J713 display DART: re-exported firmware segments take the protection + * of the live leaves that map them (read-only text, cacheable data); a region + * whose leaf maps another page keeps what it asked for. + */ +static void apple_dart_test_j713_v27_fw_prot(struct kunit *test) +{ + const u64 fields = GENMASK_ULL(51, 40) | BIT_ULL(0); + const phys_addr_t text_pa = 0x80000000ULL, data_pa = 0x80100000ULL; + const u64 dva = 0x10000000000ULL + (3ULL << 25); + struct iommu_resv_region text = {}, data = {}, moved = {}; + struct apple_dart_master_cfg master = {}; + struct apple_dart *dart; + LIST_HEAD(head); + u64 *root, *leaf; + void *regs; + + if (PAGE_SIZE < SZ_16K) + kunit_skip(test, "needs kernel pages of at least 16 KiB"); + dart = kunit_kzalloc(test, sizeof(*dart), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, dart); + dart->dev = kunit_device_register(test, "apple-dart-j713-v27-test"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dart->dev); + regs = vzalloc(APPLE_DART_TEST_REGS_SIZE); + KUNIT_ASSERT_NOT_NULL(test, regs); + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, apple_dart_test_vfree, regs), 0); + dart->regs = (__force void __iomem *)regs; + dart->hw = &apple_dart_hw_t8110; + dart->pgsize = SZ_16K; + dart->num_streams = 32; + dart->locked = true; + dart->fw_mirror = true; + dart->j713_v27 = true; + root = kunit_kzalloc(test, SZ_16K, GFP_KERNEL); + leaf = kunit_kzalloc(test, SZ_16K, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, root); + KUNIT_ASSERT_NOT_NULL(test, leaf); + KUNIT_ASSERT_TRUE(test, IS_ALIGNED(virt_to_phys(root) | virt_to_phys(leaf), SZ_16K)); + writel(((virt_to_phys(root) >> dart->hw->ttbr_shift) << dart->hw->ttbr_addr_field_shift) | + dart->hw->ttbr_valid, dart->regs + DART_TTBR(dart, 23, 0)); + root[3] = (virt_to_phys(leaf) >> 4) | BIT_ULL(0); + /* Text: two read-only pages; data: one read-write page; all cacheable. */ + leaf[0] = fields | (text_pa >> 4) | BIT_ULL(2); + leaf[1] = fields | ((text_pa + SZ_16K) >> 4) | BIT_ULL(2); + leaf[2] = fields | (data_pa >> 4); + text = (struct iommu_resv_region){ .start = text_pa, .dva = dva, .length = SZ_32K, + .prot = IOMMU_READ | IOMMU_WRITE, .type = IOMMU_RESV_TRANSLATED }; + data = (struct iommu_resv_region){ .start = data_pa, .dva = dva + SZ_32K, .length = SZ_16K, + .prot = IOMMU_READ | IOMMU_WRITE, .type = IOMMU_RESV_TRANSLATED }; + moved = (struct iommu_resv_region){ .start = data_pa + SZ_16K, .dva = dva + SZ_32K, + .length = SZ_16K, .prot = IOMMU_READ | IOMMU_WRITE, .type = IOMMU_RESV_TRANSLATED }; + list_add_tail(&text.list, &head); + list_add_tail(&data.list, &head); + list_add_tail(&moved.list, &head); + master.stream_maps[0].dart = dart; + __set_bit(23, master.stream_maps[0].sidmap); + pm_runtime_set_active(dart->dev); + pm_runtime_enable(dart->dev); + + __apple_dart_j713_v27_fw_prot(&master, dart->dev, &head); + KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_CACHE); + KUNIT_EXPECT_EQ(test, data.prot, IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE); + KUNIT_EXPECT_EQ(test, moved.prot, IOMMU_READ | IOMMU_WRITE); + + /* Not a 27.2 J713 display DART: nothing changes. */ + text.prot = IOMMU_READ | IOMMU_WRITE; + dart->j713_v27 = false; + __apple_dart_j713_v27_fw_prot(&master, dart->dev, &head); + KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); + pm_runtime_disable(dart->dev); +} + static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_strict_engines), KUNIT_CASE(apple_dart_test_topology), @@ -1335,6 +1407,7 @@ static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_locked_handoff), KUNIT_CASE(apple_dart_test_sync_unknown_roots), KUNIT_CASE(apple_dart_test_firmware_roots), + KUNIT_CASE(apple_dart_test_j713_v27_fw_prot), KUNIT_CASE(apple_dart_test_unmap_flush_after_publish_failure), KUNIT_CASE(apple_dart_test_gated_commands), KUNIT_CASE(apple_dart_test_resume_commands_failure), diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 2745ab0b96a5a..fef15eeb7da57 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -4575,9 +4575,9 @@ static void apple_dart_get_fw_resv_regions(struct device *dev, * there, map elsewhere or disagree keeps its protection, and the attach then * refuses it as before. */ -static void apple_dart_j713_v27_fw_prot(struct device *dev, struct list_head *head) +static void __apple_dart_j713_v27_fw_prot(struct apple_dart_master_cfg *cfg, struct device *dev, + struct list_head *head) { - struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev); const int mask = IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE; struct iommu_resv_region *region; struct apple_dart *dart; @@ -4654,6 +4654,11 @@ static void apple_dart_j713_v27_fw_prot(struct device *dev, struct list_head *he memunmap(root); } +static void apple_dart_j713_v27_fw_prot(struct device *dev, struct list_head *head) +{ + __apple_dart_j713_v27_fw_prot(dev_iommu_priv_get(dev), dev, head); +} + static void apple_dart_get_resv_regions(struct device *dev, struct list_head *head) { From a50a201754a2b67cf0a16be65d231c47d12c2c42 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 22:43:46 +1100 Subject: [PATCH 08/25] iommu: apple-dart: read a 27.2 J713 DART's firmware leaves only from its tables, in its window The live-leaf protection for a 27.2 J713 internal display DART's firmware segments memremaps the stream's root straight from TTBR, and each leaf table straight from its root entry, write-back. The rest of the driver maps a firmware table only after apple_dart_fw_table_decode() has checked it: a table entry with no stray bits, naming reserved RAM. An entry that named a device's registers would get a Normal write-back mapping here. The leaf slot also comes from DVA bits 14..35 alone, so a region outside the stream's 64 GiB window aliases into it. The physical address match made that harmless, but the region should not be looked up at all. Map the root only when it is a firmware table in reserved RAM, decode each leaf table entry with apple_dart_fw_table_decode(), and skip a region that does not lie inside the stream's window (locked_window, the DART's apple,dma-range until a domain attaches: 64 GiB at 1 TiB on the display DARTs). A skipped region keeps the protection it asked for, and the attach refuses it as before. KUnit: the tables are now reserved pages; new cases for a region whose two pages have different protections, a region 64 GiB above the window, and a leaf table outside reserved RAM. All three stay unchanged. Signed-off-by: Ryan Murray --- drivers/iommu/apple-dart-test.c | 50 +++++++++++++++++++++++++++++---- drivers/iommu/apple-dart.c | 21 ++++++++++---- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/apple-dart-test.c b/drivers/iommu/apple-dart-test.c index 2c4096903db0f..6ebc214842b2c 100644 --- a/drivers/iommu/apple-dart-test.c +++ b/drivers/iommu/apple-dart-test.c @@ -1326,6 +1326,26 @@ static void apple_dart_test_host_power_tables(struct kunit *test) } #endif +/* A zeroed 16 KiB page marked reserved, as the firmware's tables are. */ +static void apple_dart_test_free_reserved(void *data) +{ + struct page *page = data; + + ClearPageReserved(page); + __free_pages(page, get_order(SZ_16K)); +} + +static u64 *apple_dart_test_reserved_table(struct kunit *test) +{ + struct page *page = alloc_pages(GFP_KERNEL | __GFP_ZERO, get_order(SZ_16K)); + + KUNIT_ASSERT_NOT_NULL(test, page); + SetPageReserved(page); + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, apple_dart_test_free_reserved, page), + 0); + return page_address(page); +} + /* * A 27.2 J713 display DART: re-exported firmware segments take the protection * of the live leaves that map them (read-only text, cacheable data); a region @@ -1336,7 +1356,7 @@ static void apple_dart_test_j713_v27_fw_prot(struct kunit *test) const u64 fields = GENMASK_ULL(51, 40) | BIT_ULL(0); const phys_addr_t text_pa = 0x80000000ULL, data_pa = 0x80100000ULL; const u64 dva = 0x10000000000ULL + (3ULL << 25); - struct iommu_resv_region text = {}, data = {}, moved = {}; + struct iommu_resv_region text = {}, data = {}, moved = {}, mixed = {}, outside = {}; struct apple_dart_master_cfg master = {}; struct apple_dart *dart; LIST_HEAD(head); @@ -1356,13 +1376,14 @@ static void apple_dart_test_j713_v27_fw_prot(struct kunit *test) dart->hw = &apple_dart_hw_t8110; dart->pgsize = SZ_16K; dart->num_streams = 32; + dart->oas = 42; dart->locked = true; dart->fw_mirror = true; dart->j713_v27 = true; - root = kunit_kzalloc(test, SZ_16K, GFP_KERNEL); - leaf = kunit_kzalloc(test, SZ_16K, GFP_KERNEL); - KUNIT_ASSERT_NOT_NULL(test, root); - KUNIT_ASSERT_NOT_NULL(test, leaf); + /* The display DARTs' window: 64 GiB at 1 TiB. */ + dart->locked_window[23] = 0x10000000000ULL; + root = apple_dart_test_reserved_table(test); + leaf = apple_dart_test_reserved_table(test); KUNIT_ASSERT_TRUE(test, IS_ALIGNED(virt_to_phys(root) | virt_to_phys(leaf), SZ_16K)); writel(((virt_to_phys(root) >> dart->hw->ttbr_shift) << dart->hw->ttbr_addr_field_shift) | dart->hw->ttbr_valid, dart->regs + DART_TTBR(dart, 23, 0)); @@ -1371,15 +1392,25 @@ static void apple_dart_test_j713_v27_fw_prot(struct kunit *test) leaf[0] = fields | (text_pa >> 4) | BIT_ULL(2); leaf[1] = fields | ((text_pa + SZ_16K) >> 4) | BIT_ULL(2); leaf[2] = fields | (data_pa >> 4); + /* Two pages that disagree: one read-only, one read-write. */ + leaf[4] = fields | ((data_pa + SZ_32K) >> 4) | BIT_ULL(2); + leaf[5] = fields | ((data_pa + SZ_32K + SZ_16K) >> 4); text = (struct iommu_resv_region){ .start = text_pa, .dva = dva, .length = SZ_32K, .prot = IOMMU_READ | IOMMU_WRITE, .type = IOMMU_RESV_TRANSLATED }; data = (struct iommu_resv_region){ .start = data_pa, .dva = dva + SZ_32K, .length = SZ_16K, .prot = IOMMU_READ | IOMMU_WRITE, .type = IOMMU_RESV_TRANSLATED }; moved = (struct iommu_resv_region){ .start = data_pa + SZ_16K, .dva = dva + SZ_32K, .length = SZ_16K, .prot = IOMMU_READ | IOMMU_WRITE, .type = IOMMU_RESV_TRANSLATED }; + mixed = (struct iommu_resv_region){ .start = data_pa + SZ_32K, .dva = dva + SZ_64K, + .length = SZ_32K, .prot = IOMMU_READ | IOMMU_WRITE, .type = IOMMU_RESV_TRANSLATED }; + /* 64 GiB higher: the same slot bits, outside the window. */ + outside = (struct iommu_resv_region){ .start = text_pa, .dva = dva + SZ_64G, + .length = SZ_32K, .prot = IOMMU_READ | IOMMU_WRITE, .type = IOMMU_RESV_TRANSLATED }; list_add_tail(&text.list, &head); list_add_tail(&data.list, &head); list_add_tail(&moved.list, &head); + list_add_tail(&mixed.list, &head); + list_add_tail(&outside.list, &head); master.stream_maps[0].dart = dart; __set_bit(23, master.stream_maps[0].sidmap); pm_runtime_set_active(dart->dev); @@ -1389,6 +1420,15 @@ static void apple_dart_test_j713_v27_fw_prot(struct kunit *test) KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_CACHE); KUNIT_EXPECT_EQ(test, data.prot, IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE); KUNIT_EXPECT_EQ(test, moved.prot, IOMMU_READ | IOMMU_WRITE); + KUNIT_EXPECT_EQ(test, mixed.prot, IOMMU_READ | IOMMU_WRITE); + KUNIT_EXPECT_EQ(test, outside.prot, IOMMU_READ | IOMMU_WRITE); + + /* A leaf table outside reserved RAM is never mapped: nothing changes. */ + text.prot = IOMMU_READ | IOMMU_WRITE; + ClearPageReserved(virt_to_page(leaf)); + __apple_dart_j713_v27_fw_prot(&master, dart->dev, &head); + SetPageReserved(virt_to_page(leaf)); + KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); /* Not a 27.2 J713 display DART: nothing changes. */ text.prot = IOMMU_READ | IOMMU_WRITE; diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index fef15eeb7da57..bf2c7a2d3c68e 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -4581,8 +4581,9 @@ static void __apple_dart_j713_v27_fw_prot(struct apple_dart_master_cfg *cfg, str const int mask = IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE; struct iommu_resv_region *region; struct apple_dart *dart; + phys_addr_t table; + u64 *root, span, base; size_t entries; - u64 *root; u32 ttbr; int sid; @@ -4607,9 +4608,16 @@ static void __apple_dart_j713_v27_fw_prot(struct apple_dart_master_cfg *cfg, str ttbr &= ~dart->hw->ttbr_valid; if (dart->hw->ttbr_addr_field_shift) ttbr >>= dart->hw->ttbr_addr_field_shift; - root = memremap(((phys_addr_t)ttbr) << dart->hw->ttbr_shift, dart->pgsize, MEMREMAP_WB); + table = ((phys_addr_t)ttbr) << dart->hw->ttbr_shift; + /* Only a firmware table in reserved RAM is mapped write-back, as elsewhere. */ + if (!apple_dart_fw_table_ram(dart, table)) + return; + root = memremap(table, dart->pgsize, MEMREMAP_WB); if (!root) return; + /* A three-level root walks one span of the stream's window (DVA bits 14..35). */ + span = BIT_ULL(ilog2(dart->pgsize) + 2 * ilog2(entries)); + base = READ_ONCE(dart->locked_window[sid]) & ~(span - 1); list_for_each_entry(region, head, list) { u64 *leaf = NULL; @@ -4619,6 +4627,10 @@ static void __apple_dart_j713_v27_fw_prot(struct apple_dart_master_cfg *cfg, str if (region->type != IOMMU_RESV_TRANSLATED || !region->length || !IS_ALIGNED(region->dva | region->start | region->length, dart->pgsize)) continue; + /* Outside the window the slot bits would alias another region's leaves. */ + if (region->dva < base || region->length > span || + region->dva - base > span - region->length) + continue; for (u64 off = 0; off < region->length; off += dart->pgsize) { u64 dva = region->dva + off; /* bits 14..35: the 1 TiB base drops out */ size_t slot = (dva >> (ilog2(dart->pgsize) + ilog2(entries))) & (entries - 1); @@ -4630,9 +4642,8 @@ static void __apple_dart_j713_v27_fw_prot(struct apple_dart_master_cfg *cfg, str if (slot != mapped_slot) { if (leaf) memunmap(leaf); - leaf = (entry & APPLE_DART_PTE_VALID) ? - memremap(apple_dart_pte_to_paddr(dart, entry), dart->pgsize, - MEMREMAP_WB) : NULL; + leaf = apple_dart_fw_table_decode(dart, entry, &table) ? + memremap(table, dart->pgsize, MEMREMAP_WB) : NULL; mapped_slot = slot; } if (!leaf || From fb8640635285e3d9bbd9ec90a767760bddf59d0c Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 22:43:47 +1100 Subject: [PATCH 09/25] iommu: apple-dart: log a refused 27.2 J713 display DART as an error A 27.2 J713 internal display DART that the boot loader did not leave locked is refused (-EINVAL), but the line saying so was logged with dev_info() as one of two cases of the same message. Log the refusal with dev_err() on its own. Signed-off-by: Ryan Murray --- drivers/iommu/apple-dart.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index bf2c7a2d3c68e..4b8623e238816 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -6012,9 +6012,10 @@ static int apple_dart_probe(struct platform_device *pdev) of_device_is_compatible(dev->of_node, "apple,t8140-dart") || of_device_is_compatible(dev->of_node, "apple,t8142-dart") || j713_display_v27); - if (j713_display_v27) - dev_info(dev, "J713 internal display DART on the 27.2 image: locked roots kept (%s)\n", - dart->fw_mirror ? "mirror" : "NOT locked: refusing"); + if (j713_display_v27 && dart->fw_mirror) + dev_info(dev, "J713 internal display DART on the 27.2 image: locked roots kept (mirror)\n"); + else if (j713_display_v27) + dev_err(dev, "J713 internal display DART on the 27.2 image: NOT locked: refusing\n"); dart->j713_v27 = j713_display_v27; if (j713_display_v27 && !dart->fw_mirror) { ret = -EINVAL; From 8469fa3e58d28b3b83aff7dd579f9231a7a8f722 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 22:43:47 +1100 Subject: [PATCH 10/25] drm/apple: dcp: keep the J773g dcpext comment next to its code The T8132 internal DCP's 27.2 case in dcp_check_firmware_version() sat between the J773g dcpext comment ("ASSUMED, NOT TRACED") and the code that comment describes. Move it below that code; the two predicates match different compatibles, so the order changes nothing. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index b5d03469575e8..e2c96564e6763 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -6027,13 +6027,19 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) * 27.2 driving the mini's dcpext0 has to confirm the A4xx/A5xx IDs * before this is relied on. */ + if (apple_t8132_dcpext_v27_2(dev->of_node)) { + /* Checked by apple_t8132_dcpext_v27_2(). */ + dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); + return dcp_v27_method_table(dev, compat_str); + } + /* * The T8132 internal panel's processor on the macOS 27.2 stub, handed * over by the boot loader with the 26B123 image (see * apple_t8132_dcp_v27_2()): the firmware-27 backend with the 27.2 * method table. That this image numbers its IOMFB methods as the * T6041 and T8142 26B123 images do is the same assumption the J773g - * dcpext case below makes. + * dcpext case above makes. */ if (apple_t8132_dcp_v27_2(dev->of_node)) { /* Checked by apple_t8132_dcp_v27_2(). */ @@ -6041,12 +6047,6 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) return dcp_v27_method_table(dev, compat_str); } - if (apple_t8132_dcpext_v27_2(dev->of_node)) { - /* Checked by apple_t8132_dcpext_v27_2(). */ - dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); - return dcp_v27_method_table(dev, compat_str); - } - if (hw->firmware_compat == DCP_FIRMWARE_V_27_0) { ret = dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); if (ret < 0) { From cd2c258d81592ca17d0a91d1f05f56ced56a0f71 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 23:58:01 +1100 Subject: [PATCH 11/25] iommu: apple-dart: key a 27.2 internal display DART on its processor's handoff A T8132 DART took the firmware-27 path for the internal display when it sat at one of the two J713 internal display DART addresses on the M4 firmware path and any available internal DCP anywhere was handed over with the 27.2 image (apple_t8132_internal_dcp_v27_2(), a global scan). The address list and the scan say nothing about whether this DART belongs to that processor. Ask the DART's own user instead: a T8132 DART is a 27.2 internal display DART when an available apple,t8132-dcp that the boot loader handed over with the 27.2 image (apple_t8132_dcp_v27_2(): image, firmware version and its firmware-27 clocks) names it, in its own iommus (the firmware DART) or in a child's (the PIODMA's display DART). Such a DART also skips the "leave it untouched off the qualified firmware" refusal, which is keyed on the same addresses: its processor was handed over. On the J713 the same two DARTs qualify as before. Another M4 whose internal DCP is handed over with the 27.2 image and its clocks now gets its DARTs on the same path instead of the backend running on DARTs left on the borrowed path. The 26.6.2 path and its address keys are unchanged. apple_t8132_internal_dcp_v27_2() has no users left. Link: https://github.com/aurora-silicon/linux/issues/2621 Signed-off-by: Ryan Murray --- drivers/iommu/apple-dart.c | 52 +++++++++++++++++++++++++++++---- include/linux/soc/apple/t8132.h | 17 ----------- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 4b8623e238816..34e169ec0c26f 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -5458,6 +5458,46 @@ static bool apple_dart_is_available(struct device_node *np) return false; } +/* Whether @consumer names @dart_np in its iommus. */ +static bool apple_dart_np_is_iommu_of(const struct device_node *consumer, + const struct device_node *dart_np) +{ + struct of_phandle_args args; + + for (int i = 0; !of_parse_phandle_with_args(consumer, "iommus", "#iommu-cells", i, &args); + i++) { + bool match = args.np == dart_np; + + of_node_put(args.np); + if (match) + return true; + } + return false; +} + +/* + * Whether @dart_np serves an available T8132 internal display processor the + * boot loader handed over with the 27.2 image (apple_t8132_dcp_v27_2()): its + * firmware DART (the processor's iommus) or its display DART (its PIODMA's). + * The DART is keyed on the handoff of the processor that uses it, not on its + * address or on the board. + */ +static bool apple_dart_serves_t8132_dcp_v27(const struct device_node *dart_np) +{ + struct device_node *np, *child; + bool serves = false; + + for_each_compatible_node(np, NULL, "apple,t8132-dcp") { + if (serves || !of_device_is_available(np) || !apple_t8132_dcp_v27_2(np)) + continue; + serves = apple_dart_np_is_iommu_of(np, dart_np); + for_each_child_of_node(np, child) + if (!serves && apple_dart_np_is_iommu_of(child, dart_np)) + serves = true; + } + return serves; +} + static int apple_dart_probe(struct platform_device *pdev) { int ret, sid; @@ -5489,10 +5529,11 @@ static int apple_dart_probe(struct platform_device *pdev) * (fw_mirror below). The borrowed path admits only the 26.6.2 layout * and reserves its whole SID23 window from generic DMA. */ - if (j713_display && apple_t8132_internal_dcp_v27_2()) { + j713_display_v27 = res && !tunneled && + of_device_is_compatible(dev->of_node, "apple,t8132-dart") && + apple_dart_serves_t8132_dcp_v27(dev->of_node); + if (j713_display_v27) j713_display = false; - j713_display_v27 = true; - } /* The external DCP firmware DARTs (SID23) of dcpext0 and dcpext1. */ j713_dcpext = res && !tunneled && apple_t8132_firmware_path() && of_device_is_compatible(dev->of_node, "apple,t8132-dart") && @@ -5508,9 +5549,10 @@ static int apple_dart_probe(struct platform_device *pdev) res->start == 0x490000000ULL; /* * Off the qualified firmware nothing hands the internal display DARTs - * over, but the running DCP still uses them: never reset them. + * over, but the running DCP still uses them: never reset them. A DART + * whose processor was handed over with the 27.2 image is handed over. */ - if (res && !tunneled && !apple_t8132_firmware_path() && + if (res && !tunneled && !j713_display_v27 && !apple_t8132_firmware_path() && of_machine_is_compatible("apple,t8132") && of_device_is_compatible(dev->of_node, "apple,t8132-dart") && (res->start == 0x30a300000ULL || res->start == 0x30a340000ULL)) { diff --git a/include/linux/soc/apple/t8132.h b/include/linux/soc/apple/t8132.h index d47cfe0a13e13..72ece899b148a 100644 --- a/include/linux/soc/apple/t8132.h +++ b/include/linux/soc/apple/t8132.h @@ -55,23 +55,6 @@ static inline bool apple_t8132_firmware_path(void) return apple_t8132_air() || apple_t8132_qualified_firmware(); } -/* - * The available internal display processor was handed over with the 27.2 - * image and its firmware-27 clocks (apple_t8132_dcp_v27_2()): it runs the - * firmware-27 backend, whose DMA needs ordinary IOMMU domains. - */ -static inline bool apple_t8132_internal_dcp_v27_2(void) -{ - struct device_node *np; - bool v27 = false; - - for_each_compatible_node(np, NULL, "apple,t8132-dcp") { - if (of_device_is_available(np) && apple_t8132_dcp_v27_2(np)) - v27 = true; - } - return v27; -} - /* * A T8132 external display processor handed over with the 27.2 image * (first on the Mac mini, J773g): it runs the firmware-27 backend From a912b89b3c469d92a3dd00c9a812533fd053fa42 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sun, 22 Nov 2026 04:53:07 +1100 Subject: [PATCH 12/25] drm/apple: let a 27.2 T8132 internal DCP join the DRM device on any board dcp_check_firmware_version() runs a T8132 internal DCP that the boot loader handed over with the 27.2 image and its firmware-27 clocks on the firmware-27 backend wherever it is (apple_t8132_dcp_v27_2(): processor, image and handoff). apple_dcp_usable() still kept every apple,t8132-dcp out of the component match unless apple_t8132_firmware_path() held, which off 26.6.2 is true only for the J713/J715 board names. An M4 MacBook Pro handed over the same way would have probed and never bound. Admit it on the same handoff predicate. Nothing changes on the Airs (already on the path), on 26.6.2, or for a DCP without the 27.2 image or its clocks (a Mac mini's parked main DCP stays out). The t6041-v27-admission host unit now runs apple_dcp_usable() for the T8132 internal DCP and dcpext on both paths and asserts it names no machine; the readiness unit stubs the new helper as unreachable. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/apple_drv.c | 8 +++-- .../selftests/drivers/gpu/apple-dcp/boot.py | 34 ++++++++++++++++++- .../drivers/gpu/apple-dcp/lifecycle.py | 2 ++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index de0dbb7a59765..b7ed049c04c64 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -1502,11 +1502,13 @@ static bool apple_dcp_usable(struct device_node *np) (!of_device_is_compatible(np, "apple,t6041-dcpext") || dcp_t6041_ext_enabled()) && /* - * The T8132 main DCP is the M4 backend's, on its 26.6.2 - * firmware path only (see dcp_check_firmware_version()). + * The T8132 main DCP is the M4 backend's on its 26.6.2 + * firmware path, and the firmware-27 backend's wherever the + * boot loader handed it over with the 27.2 image and its + * clocks, on any board (see dcp_check_firmware_version()). */ (!of_device_is_compatible(np, "apple,t8132-dcp") || - apple_t8132_firmware_path()) && + apple_t8132_firmware_path() || apple_t8132_dcp_v27_2(np)) && /* * A T8132 dcpext the M4 backend adopts is no component: its * outputs are t8132_ext_drm.c's. One on the 27.2 image is a pipe. diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py index f05a1c835a3b7..a4e244caf8f28 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py @@ -224,6 +224,11 @@ def t6041_v27_admission(root): t8132_h = (root / 'include/linux/soc/apple/t8132.h').read_text() t8132_admission = block(t8132_h, 'static inline bool apple_t8132_dcpext_v27_2(') assert 'of_machine_is_compatible' not in t8132_admission + # Which processors join the DRM device: the T8132 internal DCP on the 27.2 image joins + # off the M4 backend's firmware path too, decided by the same handoff, not the board. + drv_c = (root / 'drivers/gpu/drm/apple/apple_drv.c').read_text() + usable = block(drv_c, 'static bool apple_dcp_usable(') + assert 'of_machine_is_compatible' not in usable return r''' #include #include @@ -257,6 +262,17 @@ def t6041_v27_admission(root): { return np && np->compatible && !strcmp(np->compatible, s); } +static bool of_device_is_available(const struct device_node *np) +{ + return np != NULL; +} +/* apple_dcp_usable()'s other processors: never reached by a T8132 node. */ +static bool dcp_t6030_ext_native(struct device_node *np) +{ (void)np; assert(!"T6030 dcpext in a T8132 scenario"); return false; } +static bool dcp_h17p_external_supported(struct device_node *np) +{ (void)np; assert(!"T8140 dcpext in a T8132 scenario"); return false; } +static bool dcp_t6041_ext_enabled(void) +{ assert(!"T6041 dcpext in a T8132 scenario"); return false; } static bool of_property_present(const struct device_node *np, const char *name) { assert(!strcmp(name, "apple,clock-ids")); @@ -333,7 +349,7 @@ def t6041_v27_admission(root): snprintf(out, DCP_FW_VERSION_STR_LEN, "%u.%u.%u", v[0], v[1], v[2]); return 3; } -''' + helper + '\n' + methods_decl + '\n' + v27_tables + '\n' + t8132_admission + '\n' + method_table + '\n' + selector + r''' +''' + helper + '\n' + methods_decl + '\n' + v27_tables + '\n' + t8132_admission + '\n' + method_table + '\n' + selector + '\n' + usable + r''' static struct device_node node; static struct apple_dcp_hw_data hw_t6041; static struct device dev = { .of_node = &node, .hw = &hw_t6041 }; @@ -508,9 +524,11 @@ def t6041_v27_admission(root): assert(!apple_t8132_dcpext_v27_2(&node)); assert(!apple_t6041_dcp_v27_2(&node)); assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_V_27_0); + assert(apple_dcp_usable(&node)); node.clock_ids = false; assert(!apple_t8132_dcp_v27_2(&node)); assert(dcp_check_firmware_version(&dev) == (path ? DCP_FIRMWARE_M4 : DCP_FIRMWARE_UNKNOWN)); + assert(apple_dcp_usable(&node) == path); node.clock_ids = true; } t8132_firmware_path = true; @@ -526,12 +544,26 @@ def t6041_v27_admission(root): assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_M4); node.compat[1] = 2; assert(apple_t8132_dcp_v27_2(&node)); t8132_firmware_path = false; + /* Off the M4 path another release keeps the internal DCP out of the DRM device. */ + node.compat[1] = 0; assert(!apple_dcp_usable(&node)); + node.compat[1] = 2; assert(apple_dcp_usable(&node)); + /* A T8132 dcpext joins only on the 27.2 image, on either path. */ + node.compatible = "apple,t8132-dcpext"; + for (unsigned path = 0; path < 2; path++) { + t8132_firmware_path = path; + assert(apple_dcp_usable(&node)); + node.uuid = APPLE_T6041_DCP_26B123_UUID; + assert(!apple_dcp_usable(&node)); + node.uuid = APPLE_T8132_DCP_26B123_UUID; + } + t8132_firmware_path = false; dev.hw = &hw_t6041; puts("PASS T6041 26B123 v27.2 internal/external admission, refusal controls, and desktop 26.x preservation"); puts("PASS T8122 internal DCP on its 27.2 image alone runs the 27.2 table"); puts("PASS T8132 M4 backend only on its firmware path; a T8132 dcpext on the 27.2 image runs the 27.2 table on any board"); puts("PASS T8132 internal DCP with the 27.2 image and its firmware-27 clocks runs the 27.2 table; without them nothing changes"); + puts("PASS T8132 internal DCP on the 27.2 image joins the DRM device on any board; off the M4 path nothing else does"); return 0; } ''' diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py index 02fdb3eff477f..6d56ed6835e41 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py @@ -1584,6 +1584,8 @@ def function(source, marker): { assert(!"T8132 DCP in a J700 scenario"); return false; } static bool __attribute__((unused)) apple_t8132_dcpext_v27_2(const struct device_node *n) { (void)n; assert(!"T8132 dcpext in a J700 scenario"); return false; } +static bool __attribute__((unused)) apple_t8132_dcp_v27_2(const struct device_node *n) +{ (void)n; assert(!"T8132 DCP in a J700 scenario"); return false; } static void __attribute__((unused)) iomfb_v14_7_external_refuse(struct apple_dcp *d, const char *why) { (void)d; (void)why; assert(!"T6030 external processor in a J700 scenario"); } struct drm_device { int unused; }; From 3bd2f90d721c5a43339cb6a7b73412e65a85ec0c Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 11:46:10 +1100 Subject: [PATCH 13/25] iommu: apple-dart: report the streams a display DART has enabled A DCP whose device tree names its display power words but not its DART streams stops the streams its DARTs have enabled before its first power-down and enables them again at power-up. Let it read them: the first 32 streams of a T8110 DART, read while its domain is up. Signed-off-by: Ryan Murray --- drivers/iommu/apple-dart.c | 14 ++++++++++++++ include/linux/soc/apple/dart.h | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 34e169ec0c26f..02133837431c9 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -7931,6 +7931,20 @@ int apple_dart_display_streams(struct device *dev, u32 streams, bool on, bool fl } EXPORT_SYMBOL_GPL(apple_dart_display_streams); +/* + * The streams 0 to 31 a T8110 display DART has enabled, read while its domain is up: what + * a DCP whose device tree names no streams stops and enables again around its power cycle. + */ +u32 apple_dart_enabled_streams(struct device *dev) +{ + struct apple_dart *dart = dev_get_drvdata(dev); + + if (!dart || dart->hw->type != DART_T8110) + return 0; + return readl(dart->regs + DART_T8110_ENABLE_STREAMS); +} +EXPORT_SYMBOL_GPL(apple_dart_enabled_streams); + /* * A DART whose domain goes off with its consumer's, at runtime, while other users still map * into it: dark, maps reach memory only and their invalidations wait; lit, those run. Its diff --git a/include/linux/soc/apple/dart.h b/include/linux/soc/apple/dart.h index 0a7925025e628..1c263ff4e561e 100644 --- a/include/linux/soc/apple/dart.h +++ b/include/linux/soc/apple/dart.h @@ -187,6 +187,8 @@ int apple_dart_sleep_prepare(struct device *dev); void apple_dart_sleep_restore(struct device *dev); /* A display DART's streams around a display power cycle, see the DART driver. */ int apple_dart_display_streams(struct device *dev, u32 streams, bool on, bool flush); +/* The streams 0 to 31 a display DART has enabled. */ +u32 apple_dart_enabled_streams(struct device *dev); /* A GAPF slice released before its coprocessor's CPU domain comes up after a wake. */ int apple_dart_gapf_ready(struct device *dev); /* A display DART whose domain goes off at runtime while others still map into it. */ @@ -221,6 +223,11 @@ static inline int apple_dart_display_streams(struct device *dev, u32 streams, bo return -ENODEV; } +static inline u32 apple_dart_enabled_streams(struct device *dev) +{ + return 0; +} + static inline int apple_dart_gapf_ready(struct device *dev) { return 0; From 77e0841e6e69f5c74cfbe7d523054a2a0e15c757 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 11:46:10 +1100 Subject: [PATCH 14/25] drm/apple: dcp: stop a DCP for a deep sleep with its panel lit on every hw.s2r SoC The system-sleep stop ran with an active panel only where the power words are measured, or on the J813, so another SoC's internal DCP stayed running into a deep sleep unless DPMS had turned its panel off first, and the sleep was refused. A derived layout only survives probe with appledrm.s2r_untested set, which already decides it: drop the board check. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index e2c96564e6763..3addf5c97caf4 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -9854,12 +9854,11 @@ static int dcp_platform_suspend(struct device *dev) return dcp_v27_sleep_suspend(dcp); /* - * J813 uses the same qualified stop as DPMS off. Probe already gates - * its derived power layout on appledrm.s2r_untested; without this - * system-suspend path an active panel leaves the DCP running. + * The same stop as DPMS off; without this system-suspend path an active + * panel leaves the DCP running. Probe already gates a derived power + * layout (T8142) on appledrm.s2r_untested. */ - if (pm_suspend_via_firmware() && dcp_s2r_capable(dcp) && - (!dcp->hw.s2r_untested || of_machine_is_compatible("apple,j813"))) { + if (pm_suspend_via_firmware() && dcp_s2r_capable(dcp)) { int ret = dcp_s2r_suspend(dcp); /* Lit by the last resume with its CRTC off: the next resume finds it off by DPMS. */ From 5ff9c1c5891bd7fa7c5ddb7c79fe6fcfe09ec829 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 11:46:24 +1100 Subject: [PATCH 15/25] drm/apple: dcp: stop the T8132 internal DCP's 27.2 firmware, with its power words from the device tree The M4 MacBook Air's internal DCP runs the firmware-27 backend on macOS 27.2 but has no firmware stop, so a deep sleep is refused with the processor still running, and DPMS off only darkens the backlight. Give it the hw.s2r stop the T8142 runs on 27.2: set_power_state(0), D572, the AP link's release (A550 in the 27.2 table), RTKit idle and the CPU stop, then the DCP DART's streams. It has no secure mailbox. Its power words are not a per-SoC table: a hw.s2r DCP without a layout in its hw data takes them from its device tree, the ones its deep sleep lowers. DISP_CPU is the first state of its power-domains, DISP_FE that state's parent and DISP_SYS theirs; the retention words are DISP_CPU's apple,retention-workaround, of which only the masked bits are written, the off value at power-off and the value read at probe at power-on; pmc-dcp counts it where the display-power node has that word; and the DART streams are the ones its DARTs have enabled before the first stop. Without those properties the firmware keeps running, as before. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp-internal.h | 10 ++ drivers/gpu/drm/apple/dcp.c | 131 +++++++++++++++++++++++++-- 2 files changed, 134 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 2042e257f5525..8fc4e23c37947 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -250,6 +250,13 @@ struct dcp_s2r_layout { u32 disp_streams; /* "pmc-dcp" counts the powered DCPs: T8132 and T8140 only */ bool pmc_dcp; + /* + * From the device tree (dcp_s2r_layout_from_dt()): only the @*_mask bits of a + * retention word are written, @*_off while off and the value read at probe back on. + * Zero masks: the whole words, as above. + */ + u32 ret_ff_mask, ret_ff_off, ret_ff_on; + u32 ret_mem_mask, ret_mem_off, ret_mem_on; }; /* @@ -889,6 +896,9 @@ struct apple_dcp { struct completion s2r_dart_done; struct device *s2r_disp_dart; struct device *s2r_dcp_dart; + /* hw.s2r without a layout in its hw data: the device tree's, see dcp_s2r_layout_from_dt() */ + struct dcp_s2r_layout s2r_dt_layout; + bool s2r_dt_layout_ok; /* eDP display without DP-HDMI conversion */ bool main_display; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 3addf5c97caf4..5c66f233648ec 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -297,6 +297,92 @@ static int dcp_secure_port_init(struct apple_dcp *dcp) * without a secure mailbox says so (hw.s2r_no_secure_port), and one behind * appledrm.s2r_untested stops its firmware for DPMS off and J813 system sleep. */ +/* + * hw.s2r without a layout in its hw data takes its words from the device tree, the ones its + * deep sleep lowers: DISP_CPU is the first state of the DCP's power-domains, DISP_FE that + * state's parent and DISP_SYS theirs, each at its reg in the power manager whose block the + * display-power node's "ps" starts. The retention words are DISP_CPU's two + * apple,retention-workaround entries (power manager offset, mask, value while off), in the + * node's "pwrgate" block, and the value each reads now, with the DCP running, is the one it + * gets back at power-on. It counts in pmc-dcp where the node has that word. The DART streams + * are the ones its DARTs have enabled at the first stop, see dcp_s2r_find_darts(). + */ +static int dcp_s2r_layout_from_dt(struct apple_dcp *dcp) +{ + struct dcp_s2r_layout *l = &dcp->s2r_dt_layout; + struct device_node *power, *pmgr = NULL, *ps[3] = {}; + struct resource ps_res, gate_res, pmgr_res; + u32 off[3], ret[6]; + void __iomem *gate; + int i, err = -EINVAL; + + power = of_parse_phandle(dcp->dev->of_node, "apple,display-power", 0); + if (!power) + return -ENODEV; + if (of_address_to_resource(power, of_property_match_string(power, "reg-names", "ps"), + &ps_res) || + of_address_to_resource(power, of_property_match_string(power, "reg-names", "pwrgate"), + &gate_res)) + goto out; + ps[0] = of_parse_phandle(dcp->dev->of_node, "power-domains", 0); + for (i = 1; i < 3 && ps[i - 1]; i++) + ps[i] = of_parse_phandle(ps[i - 1], "power-domains", 0); + if (!ps[2]) + goto out; + pmgr = of_get_parent(ps[0]); + if (!pmgr || of_address_to_resource(pmgr, 0, &pmgr_res) || pmgr_res.start != ps_res.start) + goto out; + for (i = 0; i < 3; i++) { + struct device_node *parent = of_get_parent(ps[i]); + + of_node_put(parent); + if (parent != pmgr || of_property_read_u32(ps[i], "reg", &off[i]) || + off[i] > resource_size(&ps_res) - 4) + goto out; + } + if (of_property_read_u32_array(ps[0], "apple,retention-workaround", ret, 6) || + of_property_count_u32_elems(ps[0], "apple,retention-workaround") != 6) + goto out; + for (i = 0; i < 6; i += 3) { + u64 at = pmgr_res.start + ret[i]; + + if (at <= gate_res.start || at + 4 > gate_res.end + 1 || at % 4 || !ret[i + 1] || + ret[i + 2] & ~ret[i + 1]) + goto out; + } + gate = ioremap(gate_res.start, resource_size(&gate_res)); + if (!gate) { + err = -ENOMEM; + goto out; + } + *l = (struct dcp_s2r_layout){ + .disp_cpu = off[0], + .disp_fe = off[1], + .disp_sys = off[2], + .ret_ff = pmgr_res.start + ret[0] - gate_res.start, + .ret_ff_mask = ret[1], + .ret_ff_off = ret[2], + .ret_mem = pmgr_res.start + ret[3] - gate_res.start, + .ret_mem_mask = ret[4], + .ret_mem_off = ret[5], + .pmc_dcp = of_property_match_string(power, "reg-names", "pmc-dcp") >= 0, + }; + l->ret_ff_on = readl(gate + l->ret_ff); + l->ret_mem_on = readl(gate + l->ret_mem); + iounmap(gate); + dcp->s2r_dt_layout_ok = true; + dev_dbg(dcp->dev, "display power from the device tree: CPU %#x FE %#x SYS %#x, retention %#x/%#x on %#x/%#x\n", + l->disp_cpu, l->disp_fe, l->disp_sys, l->ret_ff, l->ret_mem, l->ret_ff_on, + l->ret_mem_on); + err = 0; +out: + for (i = 0; i < 3; i++) + of_node_put(ps[i]); + of_node_put(pmgr); + of_node_put(power); + return err; +} + static void dcp_s2r_check_dt(struct apple_dcp *dcp) { struct device_node *np = dcp->dev->of_node; @@ -309,6 +395,15 @@ static void dcp_s2r_check_dt(struct apple_dcp *dcp) !power ? "apple,display-power" : "secure mailbox"); dcp->hw.s2r = false; } + if (dcp->hw.s2r && !dcp->hw.s2r_layout) { + int ret = dcp_s2r_layout_from_dt(dcp); + + if (ret) { + dev_info(dcp->dev, "display power words not in the device tree (%d), the firmware keeps running\n", + ret); + dcp->hw.s2r = false; + } + } if (dcp->hw.s2r_ext && !power) { dev_info(dcp->dev, "no apple,display-power in the device tree, the firmware keeps running\n"); dcp->hw.s2r_ext = false; @@ -7240,13 +7335,17 @@ static int dcp_s2r_pm_register(struct apple_dcp *dcp); * - num_dptx_ports 0: it drives the panel only. * - adopt_live_session: iBoot leaves it running with the 27.2 image and the * panel lit; Linux never starts its CPU. - * No sleep support: no firmware-27 sleep has run on this processor. + * - s2r: the firmware-27 stop (iomfb_v27.c) for DPMS off and deep sleep, + * with the 27.2 table's calls and the power words its device tree names + * (dcp_s2r_layout_from_dt()). It has no secure mailbox. */ static const struct apple_dcp_hw_data apple_dcp_hw_t8132_v27 = { .firmware_dma_bits = 41, .num_dptx_ports = 0, .adopt_live_session = true, .firmware_compat = DCP_FIRMWARE_V_27_0, + .s2r = true, + .s2r_no_secure_port = true, }; static const struct apple_dcp_hw_data apple_dcp_hw_t8132_dcpext_v27 = { @@ -7467,7 +7566,8 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) * A SoC with derived power words is offered the stop only when asked for, and only on * firmware 27.0, whose calls are the ones that ran with them. */ - if (dcp->hw.s2r && (!dcp->hw.s2r_layout || + if (dcp->hw.s2r && ((!dcp->hw.s2r_layout && + !of_property_present(dev->of_node, "apple,display-power")) || (dcp->hw.s2r_untested && (!s2r_untested || fw_compat != DCP_FIRMWARE_V_27_0)))) dcp->hw.s2r = false; @@ -8444,7 +8544,9 @@ static const struct dcp_s2r_layout *dcp_s2r_layout(struct apple_dcp *dcp) { if (dcp_s2r_is_t8142_ext(dcp)) return &dcp_s2r_t8142_ext[dcp->index - 1]; - return dcp->hw.s2r_layout ?: &dcp_s2r_t8140; + if (dcp->hw.s2r_layout) + return dcp->hw.s2r_layout; + return dcp->s2r_dt_layout_ok ? &dcp->s2r_dt_layout : &dcp_s2r_t8140; } #define DCP_PS_MIN GENMASK(19, 16) @@ -8484,6 +8586,15 @@ static void dcp_s2r_find_darts(struct apple_dcp *dcp) dcp->s2r_disp_dart = dcp_s2r_find_dart(piodma); of_node_put(piodma); } + /* A device-tree layout's streams: what its DARTs have on before the first stop. */ + if (dcp->s2r_dt_layout_ok && !dcp->s2r_dt_layout.dcp_streams && dcp->s2r_dcp_dart) { + dcp->s2r_dt_layout.dcp_streams = apple_dart_enabled_streams(dcp->s2r_dcp_dart); + if (dcp->s2r_disp_dart) + dcp->s2r_dt_layout.disp_streams = + apple_dart_enabled_streams(dcp->s2r_disp_dart); + dev_dbg(dcp->dev, "DART streams for the stop: DCP %#x, display %#x\n", + dcp->s2r_dt_layout.dcp_streams, dcp->s2r_dt_layout.disp_streams); + } } void dcp_s2r_dart_power(struct apple_dcp *dcp, u32 on) @@ -8953,6 +9064,12 @@ static void dcp_s2r_ps_lower(void __iomem *reg) writel((val & ~GENMASK(3, 0)) | GENMASK(9, 8), reg); } +/* A retention word: the whole of it from a hw-data layout, only its masked bits from the DT's. */ +static void dcp_s2r_ret_write(void __iomem *reg, u32 mask, u32 val, u32 word) +{ + writel(mask ? (readl(reg) & ~mask) | (val & mask) : word, reg); +} + /* Its display-power words, pmc-dcp only where the layout has one. */ static int dcp_s2r_map_power(struct apple_dcp *dcp, void __iomem **ps, void __iomem **pwrgate, void __iomem **pmc) @@ -8991,8 +9108,8 @@ static int dcp_s2r_domains_off(struct apple_dcp *dcp) if (val & BIT(28)) writel(val & ~(BIT(28) | GENMASK(9, 8)), ps + l->disp_cpu); if (l->ret_ff) { - writel(3, pwrgate + l->ret_ff); - writel(0, pwrgate + l->ret_mem); + dcp_s2r_ret_write(pwrgate + l->ret_ff, l->ret_ff_mask, l->ret_ff_off, 3); + dcp_s2r_ret_write(pwrgate + l->ret_mem, l->ret_mem_mask, l->ret_mem_off, 0); } dcp_s2r_ps_lower(ps + l->disp_cpu); dcp_s2r_ps_lower(ps + l->disp_fe); @@ -9043,8 +9160,8 @@ static int dcp_s2r_domains_on(struct apple_dcp *dcp) } writel(val | 0xf, ps + l->disp_cpu); if (l->ret_ff) { - writel(0, pwrgate + l->ret_ff); - writel(1, pwrgate + l->ret_mem); + dcp_s2r_ret_write(pwrgate + l->ret_ff, l->ret_ff_mask, l->ret_ff_on, 0); + dcp_s2r_ret_write(pwrgate + l->ret_mem, l->ret_mem_mask, l->ret_mem_on, 1); } writel(val | 0xf | BIT(28), ps + l->disp_cpu); if (pmc) From 2d60e9ca527799c44779753fd9a2875f25e11640 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 11:58:52 +1100 Subject: [PATCH 16/25] dt-bindings: display: apple,t8140-display-power: add the T8132 The T8132's words are T8140's: pmc-dcp, the power manager's power states and its power gate block. Signed-off-by: Ryan Murray --- .../bindings/display/apple,t8140-display-power.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml index 7d15745134267..89c84ca242d4e 100644 --- a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml +++ b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/display/apple,t8140-display-power.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Apple T8140 and T8142 display power words +title: Apple T8132, T8140 and T8142 display power words maintainers: - Diljit Singh @@ -18,6 +18,7 @@ description: properties: compatible: enum: + - apple,t8132-display-power - apple,t8140-display-power - apple,t8142-display-power @@ -38,7 +39,9 @@ allOf: - if: properties: compatible: - const: apple,t8140-display-power + enum: + - apple,t8132-display-power + - apple,t8140-display-power then: properties: reg: From c9ec13a853c484c7cf4994a75c744ae617f2f8ec Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 11:58:52 +1100 Subject: [PATCH 17/25] arm64: dts: apple: t8132-j713: the internal DCP's display power words Name the power manager blocks the internal DCP's firmware-27 stop writes, the ones the deep sleep lowers (pmc-dcp, the power states and the power gate block), and the DCP DART's clock-protection slice (42 in the ADT's dart-dcp) as its gapf word: the stop clears it after the DART's power-down flush so that DISP_CPU's power state can be written. Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t8132-j713.dts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8132-j713.dts b/arch/arm64/boot/dts/apple/t8132-j713.dts index e445896854733..8037c760a8f08 100644 --- a/arch/arm64/boot/dts/apple/t8132-j713.dts +++ b/arch/arm64/boot/dts/apple/t8132-j713.dts @@ -193,8 +193,31 @@ apple,clock-protection = <&ps_prot 8>; }; +/* + * The words the firmware-27 stop of the internal DCP writes (appledrm.s2r_untested), + * the same ones the deep sleep lowers: pmc-dcp, the PMGR power states and its power + * gate block. + */ +&soc { + dcp_power: display-power@3828a9c14 { + compatible = "apple,t8132-display-power"; + reg = <0x3 0x828a9c14 0x0 0x4>, + <0x3 0x80700000 0x0 0x14000>, + <0x3 0x80724000 0x0 0x2000>; + reg-names = "pmc-dcp", "ps", "pwrgate"; + }; +}; + +/* Clock-protection slice 42 (ADT dart-dcp): it guards DISP_CPU's power state. */ +&dcp_dart { + reg = <0x3 0x0a340000 0x0 0x20000>, + <0x3 0x8079cb80 0x0 0x4>; + reg-names = "dart", "gapf"; +}; + &dcp { apple,pmc-interface = <&pmc_disp0>; + apple,display-power = <&dcp_power>; panel: panel { compatible = "apple,panel-j713", "apple,panel"; From b42f40fd8980c9b6236ad44eeda084e9e17d3d3e Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sun, 22 Nov 2026 08:58:02 +1100 Subject: [PATCH 18/25] drm/apple: dcp, iommu: apple-dart: take a DT layout's DART streams at probe, and only all of them Review points on the device-tree power layout: - Its DART streams were read at the first stop, with dcp_streams == 0 standing for "not read yet". A first read of 0 would have had later stops and power-ons read the DART again, maybe with DISP_CPU still lowered, and the restart would enable no streams. Now the streams are read once at probe, with the firmware running. A DCP DART that reads none refuses the layout, and the firmware keeps running as with no power words. - apple_dart_enabled_streams() read only the first enable word. If a stream above 31 is enabled, the 32-bit mask can't describe the DART, so it now reads every word up to num_streams, warns once, and reports 0 in that case. - Comments still described the stop as behind appledrm.s2r_untested or J813-only. The device tree's words stop the firmware by default; only a SoC whose static words are merely derived (T8142) needs the parameter. The same holds for the layout added in "drm/apple: dcp: stop a DCP for a deep sleep with its panel lit on every hw.s2r SoC", whose message says otherwise. Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t8132-j713.dts | 6 +-- drivers/gpu/drm/apple/dcp.c | 57 +++++++++++++++++------- drivers/iommu/apple-dart.c | 13 +++++- include/linux/soc/apple/dart.h | 2 +- 4 files changed, 57 insertions(+), 21 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8132-j713.dts b/arch/arm64/boot/dts/apple/t8132-j713.dts index 8037c760a8f08..57c761674b0b4 100644 --- a/arch/arm64/boot/dts/apple/t8132-j713.dts +++ b/arch/arm64/boot/dts/apple/t8132-j713.dts @@ -194,9 +194,9 @@ }; /* - * The words the firmware-27 stop of the internal DCP writes (appledrm.s2r_untested), - * the same ones the deep sleep lowers: pmc-dcp, the PMGR power states and its power - * gate block. + * The words the firmware-27 stop of the internal DCP writes (by default, see + * dcp_s2r_layout_from_dt()), the same ones the deep sleep lowers: pmc-dcp, the PMGR + * power states and its power gate block. */ &soc { dcp_power: display-power@3828a9c14 { diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 5c66f233648ec..e174f7803a47f 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -294,8 +294,9 @@ static int dcp_secure_port_init(struct apple_dcp *dcp) * display domains through apple,display-power, and the internal DCP only takes IOP idle * once its secure port has gone idle. A device tree without those keeps the firmware * running: DPMS is the backlight alone and the display stays up across a sleep. A SoC - * without a secure mailbox says so (hw.s2r_no_secure_port), and one behind - * appledrm.s2r_untested stops its firmware for DPMS off and J813 system sleep. + * without a secure mailbox says so (hw.s2r_no_secure_port). Power words from the device + * tree stop the firmware by default; a SoC whose static words are only derived (T8142) does + * so only with appledrm.s2r_untested. */ /* * hw.s2r without a layout in its hw data takes its words from the device tree, the ones its @@ -383,6 +384,38 @@ static int dcp_s2r_layout_from_dt(struct apple_dcp *dcp) return err; } +static struct device *dcp_s2r_find_dart(struct device_node *np); + +/* + * A device-tree layout's DART streams: the ones its DARTs have enabled at probe, with the + * firmware running. A DCP DART that reads none leaves nothing for the stop to restore. + */ +static int dcp_s2r_layout_streams(struct apple_dcp *dcp) +{ + struct device_node *piodma; + struct device *dart; + + dart = dcp_s2r_find_dart(dcp->dev->of_node); + if (!dart) + return -ENODEV; + dcp->s2r_dt_layout.dcp_streams = apple_dart_enabled_streams(dart); + put_device(dart); + if (!dcp->s2r_dt_layout.dcp_streams) + return -ENODATA; + piodma = of_get_child_by_name(dcp->dev->of_node, "piodma"); + if (piodma) { + dart = dcp_s2r_find_dart(piodma); + of_node_put(piodma); + if (dart) { + dcp->s2r_dt_layout.disp_streams = apple_dart_enabled_streams(dart); + put_device(dart); + } + } + dev_dbg(dcp->dev, "DART streams for the stop: DCP %#x, display %#x\n", + dcp->s2r_dt_layout.dcp_streams, dcp->s2r_dt_layout.disp_streams); + return 0; +} + static void dcp_s2r_check_dt(struct apple_dcp *dcp) { struct device_node *np = dcp->dev->of_node; @@ -396,11 +429,12 @@ static void dcp_s2r_check_dt(struct apple_dcp *dcp) dcp->hw.s2r = false; } if (dcp->hw.s2r && !dcp->hw.s2r_layout) { - int ret = dcp_s2r_layout_from_dt(dcp); + int ret = dcp_s2r_layout_from_dt(dcp) ?: dcp_s2r_layout_streams(dcp); if (ret) { - dev_info(dcp->dev, "display power words not in the device tree (%d), the firmware keeps running\n", + dev_info(dcp->dev, "no display power layout (%d), the firmware keeps running\n", ret); + dcp->s2r_dt_layout_ok = false; dcp->hw.s2r = false; } } @@ -580,7 +614,7 @@ static bool dcp_j714s_ext(struct device *dev) static bool s2r_untested; module_param(s2r_untested, bool, 0444); MODULE_PARM_DESC(s2r_untested, - "Stop the DCP firmware on DPMS off and J813 system sleep using derived T8142 power words (default 0)"); + "Stop the DCP firmware on DPMS off and system sleep using derived T8142 power words (default 0)"); bool dcp_t6041_ext_enabled(void) { @@ -7563,7 +7597,9 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) of_device_is_compatible(dev->of_node, "apple,t8132-dcp")) dcp->hw = apple_dcp_hw_t8132_v27; /* - * A SoC with derived power words is offered the stop only when asked for, and only on + * A stop needs power words: a static layout, or the device tree's (see + * dcp_s2r_layout_from_dt(), offered by default). A SoC whose static words are only + * derived (hw.s2r_untested, T8142) is offered it only when asked for, and only on * firmware 27.0, whose calls are the ones that ran with them. */ if (dcp->hw.s2r && ((!dcp->hw.s2r_layout && @@ -8586,15 +8622,6 @@ static void dcp_s2r_find_darts(struct apple_dcp *dcp) dcp->s2r_disp_dart = dcp_s2r_find_dart(piodma); of_node_put(piodma); } - /* A device-tree layout's streams: what its DARTs have on before the first stop. */ - if (dcp->s2r_dt_layout_ok && !dcp->s2r_dt_layout.dcp_streams && dcp->s2r_dcp_dart) { - dcp->s2r_dt_layout.dcp_streams = apple_dart_enabled_streams(dcp->s2r_dcp_dart); - if (dcp->s2r_disp_dart) - dcp->s2r_dt_layout.disp_streams = - apple_dart_enabled_streams(dcp->s2r_disp_dart); - dev_dbg(dcp->dev, "DART streams for the stop: DCP %#x, display %#x\n", - dcp->s2r_dt_layout.dcp_streams, dcp->s2r_dt_layout.disp_streams); - } } void dcp_s2r_dart_power(struct apple_dcp *dcp, u32 on) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 02133837431c9..628c3cc14d7a4 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -7932,15 +7932,24 @@ int apple_dart_display_streams(struct device *dev, u32 streams, bool on, bool fl EXPORT_SYMBOL_GPL(apple_dart_display_streams); /* - * The streams 0 to 31 a T8110 display DART has enabled, read while its domain is up: what - * a DCP whose device tree names no streams stops and enables again around its power cycle. + * The streams a T8110 display DART has enabled, read while its domain is up: what a DCP + * whose device tree names no streams stops and enables again around its power cycle. The + * mask holds streams 0 to 31; a DART with any stream above them enabled can't be described + * by it and reads 0, which its caller takes as no streams to stop. */ u32 apple_dart_enabled_streams(struct device *dev) { struct apple_dart *dart = dev_get_drvdata(dev); + unsigned int i; if (!dart || dart->hw->type != DART_T8110) return 0; + for (i = 1; i < DIV_ROUND_UP(dart->num_streams, 32); i++) { + if (readl(dart->regs + DART_T8110_ENABLE_STREAMS + 4 * i)) { + dev_warn_once(dart->dev, "streams above 31 enabled: not reported\n"); + return 0; + } + } return readl(dart->regs + DART_T8110_ENABLE_STREAMS); } EXPORT_SYMBOL_GPL(apple_dart_enabled_streams); diff --git a/include/linux/soc/apple/dart.h b/include/linux/soc/apple/dart.h index 1c263ff4e561e..03b09d4932170 100644 --- a/include/linux/soc/apple/dart.h +++ b/include/linux/soc/apple/dart.h @@ -187,7 +187,7 @@ int apple_dart_sleep_prepare(struct device *dev); void apple_dart_sleep_restore(struct device *dev); /* A display DART's streams around a display power cycle, see the DART driver. */ int apple_dart_display_streams(struct device *dev, u32 streams, bool on, bool flush); -/* The streams 0 to 31 a display DART has enabled. */ +/* The streams 0 to 31 a display DART has enabled; 0 if any stream above 31 is on. */ u32 apple_dart_enabled_streams(struct device *dev); /* A GAPF slice released before its coprocessor's CPU domain comes up after a wake. */ int apple_dart_gapf_ready(struct device *dev); From 888805b87936b04d41f3fcea35beade5f84f6f26 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sun, 22 Nov 2026 19:32:05 +1100 Subject: [PATCH 19/25] drm/apple: dcp: refuse a DT layout without its display DART streams, and check power word alignment A DCP with a piodma child restores the display DART's streams at power-on from the layout. If that DART is not found, or reads no streams (none enabled, or streams above 31 that the 32-bit mask cannot describe), the layout kept disp_streams = 0 and power-on would have enabled none. Refuse the layout then, like a DCP DART that reads none: the firmware keeps running. The DISP_CPU/FE/SYS offsets are checked against the "ps" block without underflowing on a block shorter than a word, and must be word aligned like the retention offsets. The overview comment named the old first-stop stream read; point it at dcp_s2r_layout_streams(). Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index e174f7803a47f..3dd7118362197 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -306,7 +306,7 @@ static int dcp_secure_port_init(struct apple_dcp *dcp) * apple,retention-workaround entries (power manager offset, mask, value while off), in the * node's "pwrgate" block, and the value each reads now, with the DCP running, is the one it * gets back at power-on. It counts in pmc-dcp where the node has that word. The DART streams - * are the ones its DARTs have enabled at the first stop, see dcp_s2r_find_darts(). + * are the ones its DARTs have enabled at probe, see dcp_s2r_layout_streams(). */ static int dcp_s2r_layout_from_dt(struct apple_dcp *dcp) { @@ -338,7 +338,8 @@ static int dcp_s2r_layout_from_dt(struct apple_dcp *dcp) of_node_put(parent); if (parent != pmgr || of_property_read_u32(ps[i], "reg", &off[i]) || - off[i] > resource_size(&ps_res) - 4) + resource_size(&ps_res) < 4 || off[i] > resource_size(&ps_res) - 4 || + off[i] % 4) goto out; } if (of_property_read_u32_array(ps[0], "apple,retention-workaround", ret, 6) || @@ -388,7 +389,8 @@ static struct device *dcp_s2r_find_dart(struct device_node *np); /* * A device-tree layout's DART streams: the ones its DARTs have enabled at probe, with the - * firmware running. A DCP DART that reads none leaves nothing for the stop to restore. + * firmware running. A DCP DART, or a piodma DART where the DCP has a piodma node, that is + * missing or reads none leaves nothing for the stop to restore, so the layout is refused. */ static int dcp_s2r_layout_streams(struct apple_dcp *dcp) { @@ -406,10 +408,12 @@ static int dcp_s2r_layout_streams(struct apple_dcp *dcp) if (piodma) { dart = dcp_s2r_find_dart(piodma); of_node_put(piodma); - if (dart) { - dcp->s2r_dt_layout.disp_streams = apple_dart_enabled_streams(dart); - put_device(dart); - } + if (!dart) + return -ENODEV; + dcp->s2r_dt_layout.disp_streams = apple_dart_enabled_streams(dart); + put_device(dart); + if (!dcp->s2r_dt_layout.disp_streams) + return -ENODATA; } dev_dbg(dcp->dev, "DART streams for the stop: DCP %#x, display %#x\n", dcp->s2r_dt_layout.dcp_streams, dcp->s2r_dt_layout.disp_streams); From c9f24a4f51bc1c6bce4f6e85c610b706915d9371 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 03:25:18 +1100 Subject: [PATCH 20/25] iommu: apple-dart: read a 27.2 display DART's TCR before dropping its PM reference __apple_dart_j713_v27_fw_prot() took a runtime-PM reference, read the stream's TTBR, dropped the reference and only then read DART_TCR for the four-level check. apple_dart_probe() drops its own probe reference for these DARTs, so the TCR read could hit a suspended DART. Read TTBR and TCR while the reference is held, then put it. The KUnit case now also checks that a stream whose TCR says four-level is left as it asked. Signed-off-by: Ryan Murray --- drivers/iommu/apple-dart-test.c | 7 +++++++ drivers/iommu/apple-dart.c | 9 +++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/apple-dart-test.c b/drivers/iommu/apple-dart-test.c index 6ebc214842b2c..71c1bfa7a3a2d 100644 --- a/drivers/iommu/apple-dart-test.c +++ b/drivers/iommu/apple-dart-test.c @@ -1430,6 +1430,13 @@ static void apple_dart_test_j713_v27_fw_prot(struct kunit *test) SetPageReserved(virt_to_page(leaf)); KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); + /* A four-level root is not walked: nothing changes. */ + text.prot = IOMMU_READ | IOMMU_WRITE; + writel(dart->hw->tcr_4level, dart->regs + DART_TCR(dart, 23)); + __apple_dart_j713_v27_fw_prot(&master, dart->dev, &head); + writel(0, dart->regs + DART_TCR(dart, 23)); + KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); + /* Not a 27.2 J713 display DART: nothing changes. */ text.prot = IOMMU_READ | IOMMU_WRITE; dart->j713_v27 = false; diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 34e169ec0c26f..b435a989ad1f8 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -4584,7 +4584,7 @@ static void __apple_dart_j713_v27_fw_prot(struct apple_dart_master_cfg *cfg, str phys_addr_t table; u64 *root, span, base; size_t entries; - u32 ttbr; + u32 ttbr, tcr = 0; int sid; if (!cfg || !cfg->stream_maps[0].dart || cfg->stream_maps[1].dart) @@ -4599,11 +4599,12 @@ static void __apple_dart_j713_v27_fw_prot(struct apple_dart_master_cfg *cfg, str return; if (pm_runtime_resume_and_get(dart->dev) < 0) return; + /* Read both registers while the DART is held powered. */ ttbr = apple_dart_readl(dart, DART_TTBR(dart, sid, 0)); + if (dart->hw->tcr_4level) + tcr = apple_dart_readl(dart, DART_TCR(dart, sid)); pm_runtime_put(dart->dev); - if (!(ttbr & dart->hw->ttbr_valid) || - (dart->hw->tcr_4level && - (apple_dart_readl(dart, DART_TCR(dart, sid)) & dart->hw->tcr_4level))) + if (!(ttbr & dart->hw->ttbr_valid) || (tcr & dart->hw->tcr_4level)) return; ttbr &= ~dart->hw->ttbr_valid; if (dart->hw->ttbr_addr_field_shift) From 76c6464014c36d02049ca0c3cbdc1385b7a16289 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 03:25:55 +1100 Subject: [PATCH 21/25] iommu: apple-dart: name the 27.2 internal display DART after its handoff Since "iommu: apple-dart: key a 27.2 internal display DART on its processor's handoff" no board decides which DARTs take this path: any T8132 internal display DART whose DCP the boot loader handed over on the 27.2 image does. The flag, its helpers and the probe log still said J713, so an M4 MacBook Pro would log as one. Rename j713_v27 to t8132_dcp_v27 (and the helpers and the KUnit case with it) and log "T8132 internal display DART". No functional change. Signed-off-by: Ryan Murray --- drivers/iommu/apple-dart-test.c | 26 ++++++++++----------- drivers/iommu/apple-dart.c | 40 ++++++++++++++++----------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/drivers/iommu/apple-dart-test.c b/drivers/iommu/apple-dart-test.c index 71c1bfa7a3a2d..920097ea03f70 100644 --- a/drivers/iommu/apple-dart-test.c +++ b/drivers/iommu/apple-dart-test.c @@ -1347,11 +1347,11 @@ static u64 *apple_dart_test_reserved_table(struct kunit *test) } /* - * A 27.2 J713 display DART: re-exported firmware segments take the protection - * of the live leaves that map them (read-only text, cacheable data); a region - * whose leaf maps another page keeps what it asked for. + * A 27.2 T8132 internal display DART: re-exported firmware segments take the + * protection of the live leaves that map them (read-only text, cacheable + * data); a region whose leaf maps another page keeps what it asked for. */ -static void apple_dart_test_j713_v27_fw_prot(struct kunit *test) +static void apple_dart_test_t8132_dcp_v27_fw_prot(struct kunit *test) { const u64 fields = GENMASK_ULL(51, 40) | BIT_ULL(0); const phys_addr_t text_pa = 0x80000000ULL, data_pa = 0x80100000ULL; @@ -1367,7 +1367,7 @@ static void apple_dart_test_j713_v27_fw_prot(struct kunit *test) kunit_skip(test, "needs kernel pages of at least 16 KiB"); dart = kunit_kzalloc(test, sizeof(*dart), GFP_KERNEL); KUNIT_ASSERT_NOT_NULL(test, dart); - dart->dev = kunit_device_register(test, "apple-dart-j713-v27-test"); + dart->dev = kunit_device_register(test, "apple-dart-t8132-dcp-v27-test"); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dart->dev); regs = vzalloc(APPLE_DART_TEST_REGS_SIZE); KUNIT_ASSERT_NOT_NULL(test, regs); @@ -1379,7 +1379,7 @@ static void apple_dart_test_j713_v27_fw_prot(struct kunit *test) dart->oas = 42; dart->locked = true; dart->fw_mirror = true; - dart->j713_v27 = true; + dart->t8132_dcp_v27 = true; /* The display DARTs' window: 64 GiB at 1 TiB. */ dart->locked_window[23] = 0x10000000000ULL; root = apple_dart_test_reserved_table(test); @@ -1416,7 +1416,7 @@ static void apple_dart_test_j713_v27_fw_prot(struct kunit *test) pm_runtime_set_active(dart->dev); pm_runtime_enable(dart->dev); - __apple_dart_j713_v27_fw_prot(&master, dart->dev, &head); + __apple_dart_t8132_dcp_v27_fw_prot(&master, dart->dev, &head); KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_CACHE); KUNIT_EXPECT_EQ(test, data.prot, IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE); KUNIT_EXPECT_EQ(test, moved.prot, IOMMU_READ | IOMMU_WRITE); @@ -1426,21 +1426,21 @@ static void apple_dart_test_j713_v27_fw_prot(struct kunit *test) /* A leaf table outside reserved RAM is never mapped: nothing changes. */ text.prot = IOMMU_READ | IOMMU_WRITE; ClearPageReserved(virt_to_page(leaf)); - __apple_dart_j713_v27_fw_prot(&master, dart->dev, &head); + __apple_dart_t8132_dcp_v27_fw_prot(&master, dart->dev, &head); SetPageReserved(virt_to_page(leaf)); KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); /* A four-level root is not walked: nothing changes. */ text.prot = IOMMU_READ | IOMMU_WRITE; writel(dart->hw->tcr_4level, dart->regs + DART_TCR(dart, 23)); - __apple_dart_j713_v27_fw_prot(&master, dart->dev, &head); + __apple_dart_t8132_dcp_v27_fw_prot(&master, dart->dev, &head); writel(0, dart->regs + DART_TCR(dart, 23)); KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); - /* Not a 27.2 J713 display DART: nothing changes. */ + /* Not a 27.2 T8132 internal display DART: nothing changes. */ text.prot = IOMMU_READ | IOMMU_WRITE; - dart->j713_v27 = false; - __apple_dart_j713_v27_fw_prot(&master, dart->dev, &head); + dart->t8132_dcp_v27 = false; + __apple_dart_t8132_dcp_v27_fw_prot(&master, dart->dev, &head); KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); pm_runtime_disable(dart->dev); } @@ -1454,7 +1454,7 @@ static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_locked_handoff), KUNIT_CASE(apple_dart_test_sync_unknown_roots), KUNIT_CASE(apple_dart_test_firmware_roots), - KUNIT_CASE(apple_dart_test_j713_v27_fw_prot), + KUNIT_CASE(apple_dart_test_t8132_dcp_v27_fw_prot), KUNIT_CASE(apple_dart_test_unmap_flush_after_publish_failure), KUNIT_CASE(apple_dart_test_gated_commands), KUNIT_CASE(apple_dart_test_resume_commands_failure), diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index b435a989ad1f8..f5c6bcc6f2b33 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -426,8 +426,8 @@ struct apple_dart { u32 sleep_gated : 1; /* Locked roots may hold firmware slots that mirror Linux mappings. */ u32 fw_mirror : 1; - /* A J713 internal display DART on the 27.2 image (fw_mirror, not borrowed). */ - u32 j713_v27 : 1; + /* A T8132 internal display DART on the 27.2 image (fw_mirror, not borrowed). */ + u32 t8132_dcp_v27 : 1; /* * fw_mirror's four-level locked roots hold firmware's own subtrees, which * are recorded and reserved (apple_dart_snapshot_fw_tree()). Set only for @@ -4565,7 +4565,7 @@ static void apple_dart_get_fw_resv_regions(struct device *dev, } /* - * A J713 internal display DART on the 27.2 image (fw_mirror): the boot loader + * A T8132 internal display DART on the 27.2 image (fw_mirror): the boot loader * re-exports the firmware's own segments as iommu-addresses, which the core * maps read-write, and uncached for this non-coherent DCP. The firmware's * leaves say what those pages are: its text read-only, all of it cacheable. @@ -4575,8 +4575,8 @@ static void apple_dart_get_fw_resv_regions(struct device *dev, * there, map elsewhere or disagree keeps its protection, and the attach then * refuses it as before. */ -static void __apple_dart_j713_v27_fw_prot(struct apple_dart_master_cfg *cfg, struct device *dev, - struct list_head *head) +static void __apple_dart_t8132_dcp_v27_fw_prot(struct apple_dart_master_cfg *cfg, + struct device *dev, struct list_head *head) { const int mask = IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE; struct iommu_resv_region *region; @@ -4590,7 +4590,7 @@ static void __apple_dart_j713_v27_fw_prot(struct apple_dart_master_cfg *cfg, str if (!cfg || !cfg->stream_maps[0].dart || cfg->stream_maps[1].dart) return; dart = cfg->stream_maps[0].dart; - if (!dart->j713_v27 || !dart->locked || dart->hw->fmt != APPLE_DART2) + if (!dart->t8132_dcp_v27 || !dart->locked || dart->hw->fmt != APPLE_DART2) return; entries = dart->pgsize / sizeof(u64); sid = find_first_bit(cfg->stream_maps[0].sidmap, dart->num_streams); @@ -4666,9 +4666,9 @@ static void __apple_dart_j713_v27_fw_prot(struct apple_dart_master_cfg *cfg, str memunmap(root); } -static void apple_dart_j713_v27_fw_prot(struct device *dev, struct list_head *head) +static void apple_dart_t8132_dcp_v27_fw_prot(struct device *dev, struct list_head *head) { - __apple_dart_j713_v27_fw_prot(dev_iommu_priv_get(dev), dev, head); + __apple_dart_t8132_dcp_v27_fw_prot(dev_iommu_priv_get(dev), dev, head); } static void apple_dart_get_resv_regions(struct device *dev, @@ -4700,7 +4700,7 @@ static void apple_dart_get_resv_regions(struct device *dev, /* Keep the translated-domain requirement and inherited translations. */ iommu_dma_get_resv_regions(dev, head); - apple_dart_j713_v27_fw_prot(dev, head); + apple_dart_t8132_dcp_v27_fw_prot(dev, head); apple_dart_get_fw_resv_regions(dev, head); } @@ -5511,7 +5511,7 @@ static int apple_dart_probe(struct platform_device *pdev) bool tunneled = dev->of_node->parent && of_node_name_prefix(dev->of_node->parent, "usb4-pcie-tunnel-"); - bool j713_display, j713_dcpext, j713_dispext, j713_radio, j713_display_v27 = false; + bool j713_display, j713_dcpext, j713_dispext, j713_radio, t8132_display_v27 = false; /* * The M4 internal display DARTs are live: DCP firmware (SID23) @@ -5530,10 +5530,10 @@ static int apple_dart_probe(struct platform_device *pdev) * (fw_mirror below). The borrowed path admits only the 26.6.2 layout * and reserves its whole SID23 window from generic DMA. */ - j713_display_v27 = res && !tunneled && + t8132_display_v27 = res && !tunneled && of_device_is_compatible(dev->of_node, "apple,t8132-dart") && apple_dart_serves_t8132_dcp_v27(dev->of_node); - if (j713_display_v27) + if (t8132_display_v27) j713_display = false; /* The external DCP firmware DARTs (SID23) of dcpext0 and dcpext1. */ j713_dcpext = res && !tunneled && apple_t8132_firmware_path() && @@ -5553,7 +5553,7 @@ static int apple_dart_probe(struct platform_device *pdev) * over, but the running DCP still uses them: never reset them. A DART * whose processor was handed over with the 27.2 image is handed over. */ - if (res && !tunneled && !j713_display_v27 && !apple_t8132_firmware_path() && + if (res && !tunneled && !t8132_display_v27 && !apple_t8132_firmware_path() && of_machine_is_compatible("apple,t8132") && of_device_is_compatible(dev->of_node, "apple,t8132-dart") && (res->start == 0x30a300000ULL || res->start == 0x30a340000ULL)) { @@ -6054,13 +6054,13 @@ static int apple_dart_probe(struct platform_device *pdev) of_device_is_compatible(dev->of_node, "apple,t6050-dart") || of_device_is_compatible(dev->of_node, "apple,t8140-dart") || of_device_is_compatible(dev->of_node, "apple,t8142-dart") || - j713_display_v27); - if (j713_display_v27 && dart->fw_mirror) - dev_info(dev, "J713 internal display DART on the 27.2 image: locked roots kept (mirror)\n"); - else if (j713_display_v27) - dev_err(dev, "J713 internal display DART on the 27.2 image: NOT locked: refusing\n"); - dart->j713_v27 = j713_display_v27; - if (j713_display_v27 && !dart->fw_mirror) { + t8132_display_v27); + if (t8132_display_v27 && dart->fw_mirror) + dev_info(dev, "T8132 internal display DART on the 27.2 image: locked roots kept (mirror)\n"); + else if (t8132_display_v27) + dev_err(dev, "T8132 internal display DART on the 27.2 image: NOT locked: refusing\n"); + dart->t8132_dcp_v27 = t8132_display_v27; + if (t8132_display_v27 && !dart->fw_mirror) { ret = -EINVAL; goto err_clk_disable; } From 97085f262267b008040816395792d4b58fc36421 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 03:26:08 +1100 Subject: [PATCH 22/25] iommu: apple-dart: say why a 27.2 internal display DART is refused fw_mirror needs the DART locked and no reserved-table handoff. A 27.2 T8132 internal display DART without fw_mirror was always logged as "NOT locked", also when it was locked and its boot loader had handed over reserved tables as well. Keep refusing both (the firmware-27 backend runs on the locked roots only), but log the reserved-table case as what it is. Signed-off-by: Ryan Murray --- drivers/iommu/apple-dart.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index f5c6bcc6f2b33..bc582e3facb51 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -6055,10 +6055,17 @@ static int apple_dart_probe(struct platform_device *pdev) of_device_is_compatible(dev->of_node, "apple,t8140-dart") || of_device_is_compatible(dev->of_node, "apple,t8142-dart") || t8132_display_v27); + /* + * The firmware-27 backend runs on the locked roots alone: a DART that + * is not locked, or whose boot loader also handed over reserved tables, + * is not the handoff it was written for. Refuse either, saying which. + */ if (t8132_display_v27 && dart->fw_mirror) dev_info(dev, "T8132 internal display DART on the 27.2 image: locked roots kept (mirror)\n"); - else if (t8132_display_v27) + else if (t8132_display_v27 && !dart->locked) dev_err(dev, "T8132 internal display DART on the 27.2 image: NOT locked: refusing\n"); + else if (t8132_display_v27) + dev_err(dev, "T8132 internal display DART on the 27.2 image: locked with a reserved-table handoff: refusing\n"); dart->t8132_dcp_v27 = t8132_display_v27; if (t8132_display_v27 && !dart->fw_mirror) { ret = -EINVAL; From df2748e9d323bea27aa55ce938ae261ae3cd99e1 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 03:26:28 +1100 Subject: [PATCH 23/25] drm/apple: dcp: give the J773g dcpext hw data its comment back The T8132 internal DCP's 27.2 hw data and its comment went in between the J773g dcpext comment and apple_dcp_hw_t8132_dcpext_v27, so the dcpext struct read as undocumented and the dcpext comment sat on the wrong struct. Put the internal one after the dcpext struct. No functional change. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index e2c96564e6763..1b88efc7e8aac 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -7232,6 +7232,14 @@ static int dcp_s2r_pm_register(struct apple_dcp *dcp); * No sleep support: neither a firmware-27 sleep nor a link release has run * on this processor. */ +static const struct apple_dcp_hw_data apple_dcp_hw_t8132_dcpext_v27 = { + .firmware_dma_bits = 41, + .num_dptx_ports = 2, + .adopt_live_session = true, + .firmware_compat = DCP_FIRMWARE_V_27_0, + .sink_metadata_edid = true, +}; + /* * T8132 internal display processor on firmware 27.2, admitted by * dcp_check_firmware_version(), whatever hw data its compatible matched: @@ -7249,14 +7257,6 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t8132_v27 = { .firmware_compat = DCP_FIRMWARE_V_27_0, }; -static const struct apple_dcp_hw_data apple_dcp_hw_t8132_dcpext_v27 = { - .firmware_dma_bits = 41, - .num_dptx_ports = 2, - .adopt_live_session = true, - .firmware_compat = DCP_FIRMWARE_V_27_0, - .sink_metadata_edid = true, -}; - static int dcp_platform_probe_pipe(struct platform_device *pdev) { const struct apple_dcp_hw_data *hw = of_device_get_match_data(&pdev->dev); From 046908542bcd5b6aaf4f8f78e5ac8ec2453fb43a Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 25 Nov 2026 10:01:24 +1100 Subject: [PATCH 24/25] iommu: apple-dart: select a T8132 display DART's fw_mirror from its state fw_mirror for a T8132 internal display DART was keyed on apple_t8132_dcp_v27_2(): the 27.2.0 version and compat, the 26B123 image UUID and apple,clock-ids on the DCP that names the DART. That is a firmware-build gate. Any later 27.x image would lose fw_mirror, the DART would be refused, and the internal panel would not attach, though nothing about the DART or its handoff changed. What fw_mirror needs is the DART's own state, as on T6041, T6050, T8140 and T8142: locked, no reserved-table handoff (fw_handoff), and no display driver borrowing its live roots (preserve_display). Put that in one place, apple_dart_selects_fw_mirror(), and use it for every SoC. Which T8132 DARTs may take it is still decided by what uses them, now without the build: a DART is a candidate when an available apple,t8132-dcp names it (the DCP's iommus, or its PIODMA child's) and the boot loader handed that DCP over with its firmware clocks (apple,clock-ids). The clocks are what the firmware-27 backend needs and what tells its handoff from the M4 26.6.2 one, whose DARTs are borrowed; the loader publishes them from the ADT on any firmware-27 image, so no build or board is listed. Other locked T8132 DARTs keep the retained-root path they have today. On T6041 every locked DART takes fw_mirror, including the PMP's at 0x500300000, which T604x boot logs show locked. T8132 is not widened the same way: its PMP DART (0x380300000) is locked too (PROTECT 0x1e7 on J713), and moving it to fw_mirror would change how the PMP's DMA is mapped on a SoC where that has never run. No apple,t8132-dcp names it, and the external display DARTs are named by apple,t8132-dcpext, so neither is selected. A Mac mini's idle main DCP is not handed over and gets no apple,clock-ids, so its DARTs stay untouched as before. A candidate DART that is not locked, or that also has reserved tables, is still refused, with the same two messages. They no longer say "on the 27.2 image". Add a KUnit case for the selection: a locked candidate mirrors; a locked DART that no DCP names (the PMP's), an unlocked one, one with fw_handoff and a borrowed one do not. Signed-off-by: Ryan Murray --- drivers/iommu/apple-dart-test.c | 24 +++++++++ drivers/iommu/apple-dart.c | 88 ++++++++++++++++++++------------- 2 files changed, 78 insertions(+), 34 deletions(-) diff --git a/drivers/iommu/apple-dart-test.c b/drivers/iommu/apple-dart-test.c index 920097ea03f70..0b6dbac31e155 100644 --- a/drivers/iommu/apple-dart-test.c +++ b/drivers/iommu/apple-dart-test.c @@ -1346,6 +1346,29 @@ static u64 *apple_dart_test_reserved_table(struct kunit *test) return page_address(page); } +/* + * fw_mirror from the DART's own state: a T8132 DART its handed-over internal + * DCP names mirrors when locked without reserved tables and not borrowed; any + * other locked T8132 DART (the PMP's) keeps the retained-root path. + */ +static void apple_dart_test_t8132_fw_mirror_selection(struct kunit *test) +{ + struct apple_dart dart = { .locked = true }; + + KUNIT_EXPECT_TRUE(test, apple_dart_selects_fw_mirror(&dart, NULL, true)); + /* A locked T8132 DART no display processor names: the PMP's. */ + KUNIT_EXPECT_FALSE(test, apple_dart_selects_fw_mirror(&dart, NULL, false)); + + dart.locked = false; + KUNIT_EXPECT_FALSE(test, apple_dart_selects_fw_mirror(&dart, NULL, true)); + dart.locked = true; + dart.fw_handoff = true; + KUNIT_EXPECT_FALSE(test, apple_dart_selects_fw_mirror(&dart, NULL, true)); + dart.fw_handoff = false; + dart.preserve_display = true; + KUNIT_EXPECT_FALSE(test, apple_dart_selects_fw_mirror(&dart, NULL, true)); +} + /* * A 27.2 T8132 internal display DART: re-exported firmware segments take the * protection of the live leaves that map them (read-only text, cacheable @@ -1454,6 +1477,7 @@ static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_locked_handoff), KUNIT_CASE(apple_dart_test_sync_unknown_roots), KUNIT_CASE(apple_dart_test_firmware_roots), + KUNIT_CASE(apple_dart_test_t8132_fw_mirror_selection), KUNIT_CASE(apple_dart_test_t8132_dcp_v27_fw_prot), KUNIT_CASE(apple_dart_test_unmap_flush_after_publish_failure), KUNIT_CASE(apple_dart_test_gated_commands), diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index bc582e3facb51..7ad0abc6ad2ee 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -426,7 +426,7 @@ struct apple_dart { u32 sleep_gated : 1; /* Locked roots may hold firmware slots that mirror Linux mappings. */ u32 fw_mirror : 1; - /* A T8132 internal display DART on the 27.2 image (fw_mirror, not borrowed). */ + /* A T8132 internal display DART of a handed-over DCP (fw_mirror, not borrowed). */ u32 t8132_dcp_v27 : 1; /* * fw_mirror's four-level locked roots hold firmware's own subtrees, which @@ -5477,19 +5477,23 @@ static bool apple_dart_np_is_iommu_of(const struct device_node *consumer, } /* - * Whether @dart_np serves an available T8132 internal display processor the - * boot loader handed over with the 27.2 image (apple_t8132_dcp_v27_2()): its - * firmware DART (the processor's iommus) or its display DART (its PIODMA's). - * The DART is keyed on the handoff of the processor that uses it, not on its - * address or on the board. + * Whether @dart_np serves an available T8132 internal display processor that + * the boot loader handed over with its firmware clocks (apple,clock-ids, from + * the ADT's /arm-io/disp0): its firmware DART (the processor's iommus) or its + * display DART (its PIODMA's). Those clocks are what the firmware-27 backend + * needs and what tells its handoff from the M4 26.6.2 one, whose DARTs are + * borrowed. The DART is keyed on what uses it, not on its address, the board + * or the firmware build: a PMP or external display DART is never named here, + * and an idle main DCP (a Mac mini's) is not handed over. */ -static bool apple_dart_serves_t8132_dcp_v27(const struct device_node *dart_np) +static bool apple_dart_serves_t8132_dcp(const struct device_node *dart_np) { struct device_node *np, *child; bool serves = false; for_each_compatible_node(np, NULL, "apple,t8132-dcp") { - if (serves || !of_device_is_available(np) || !apple_t8132_dcp_v27_2(np)) + if (serves || !of_device_is_available(np) || + !of_property_present(np, "apple,clock-ids")) continue; serves = apple_dart_np_is_iommu_of(np, dart_np); for_each_child_of_node(np, child) @@ -5499,6 +5503,27 @@ static bool apple_dart_serves_t8132_dcp_v27(const struct device_node *dart_np) return serves; } +/* + * Whether a locked DART keeps its firmware's roots and mirrors Linux mappings + * into them (fw_mirror): it is locked, its boot loader handed over no reserved + * tables (fw_handoff), and no display driver borrows its live roots + * (preserve_display). That is the DART's own state; which DARTs take it is the + * SoC's (T6041, T6050, T8140, T8142: every one) or, on T8132, the DARTs of its + * handed-over internal display processor (@t8132_dcp). Other locked T8132 + * DARTs, the PMP's among them, keep the retained-root path they always had. + */ +static bool apple_dart_selects_fw_mirror(const struct apple_dart *dart, + const struct device_node *np, bool t8132_dcp) +{ + if (!dart->locked || dart->fw_handoff || dart->preserve_display) + return false; + return of_device_is_compatible(np, "apple,t6041-dart") || + of_device_is_compatible(np, "apple,t6050-dart") || + of_device_is_compatible(np, "apple,t8140-dart") || + of_device_is_compatible(np, "apple,t8142-dart") || + t8132_dcp; +} + static int apple_dart_probe(struct platform_device *pdev) { int ret, sid; @@ -5511,7 +5536,7 @@ static int apple_dart_probe(struct platform_device *pdev) bool tunneled = dev->of_node->parent && of_node_name_prefix(dev->of_node->parent, "usb4-pcie-tunnel-"); - bool j713_display, j713_dcpext, j713_dispext, j713_radio, t8132_display_v27 = false; + bool j713_display, j713_dcpext, j713_dispext, j713_radio, t8132_dcp = false; /* * The M4 internal display DARTs are live: DCP firmware (SID23) @@ -5523,17 +5548,17 @@ static int apple_dart_probe(struct platform_device *pdev) of_device_is_compatible(dev->of_node, "apple,t8132-dart") && (res->start == 0x30a300000ULL || res->start == 0x30a340000ULL); /* - * The internal DCP handed over with the 27.2 image runs the firmware-27 - * backend, which DMAs through ordinary domains (RTKit and IOMFB shared - * memory, PIODMA maps) as on T6041. Its two display DARTs are then not - * borrowed: they keep their firmware's locked roots the way T6041's do - * (fw_mirror below). The borrowed path admits only the 26.6.2 layout - * and reserves its whole SID23 window from generic DMA. + * An internal DCP handed over with its firmware clocks runs the + * firmware-27 backend, which DMAs through ordinary domains (RTKit and + * IOMFB shared memory, PIODMA maps) as on T6041. Its two display DARTs + * are then not borrowed: they keep their firmware's locked roots the way + * T6041's do (fw_mirror below). The borrowed path admits only the 26.6.2 + * layout and reserves its whole SID23 window from generic DMA. */ - t8132_display_v27 = res && !tunneled && + t8132_dcp = res && !tunneled && of_device_is_compatible(dev->of_node, "apple,t8132-dart") && - apple_dart_serves_t8132_dcp_v27(dev->of_node); - if (t8132_display_v27) + apple_dart_serves_t8132_dcp(dev->of_node); + if (t8132_dcp) j713_display = false; /* The external DCP firmware DARTs (SID23) of dcpext0 and dcpext1. */ j713_dcpext = res && !tunneled && apple_t8132_firmware_path() && @@ -5551,9 +5576,9 @@ static int apple_dart_probe(struct platform_device *pdev) /* * Off the qualified firmware nothing hands the internal display DARTs * over, but the running DCP still uses them: never reset them. A DART - * whose processor was handed over with the 27.2 image is handed over. + * whose processor was handed over with its firmware clocks is handed over. */ - if (res && !tunneled && !t8132_display_v27 && !apple_t8132_firmware_path() && + if (res && !tunneled && !t8132_dcp && !apple_t8132_firmware_path() && of_machine_is_compatible("apple,t8132") && of_device_is_compatible(dev->of_node, "apple,t8132-dart") && (res->start == 0x30a300000ULL || res->start == 0x30a340000ULL)) { @@ -6049,25 +6074,20 @@ static int apple_dart_probe(struct platform_device *pdev) * T6050's boot loader leaves every display DART locked on four-level * roots of its own (dart-dcpextN SID 23, dart-dispextN SIDs 0 and 16). */ - dart->fw_mirror = dart->locked && !dart->fw_handoff && - (of_device_is_compatible(dev->of_node, "apple,t6041-dart") || - of_device_is_compatible(dev->of_node, "apple,t6050-dart") || - of_device_is_compatible(dev->of_node, "apple,t8140-dart") || - of_device_is_compatible(dev->of_node, "apple,t8142-dart") || - t8132_display_v27); + dart->fw_mirror = apple_dart_selects_fw_mirror(dart, dev->of_node, t8132_dcp); /* * The firmware-27 backend runs on the locked roots alone: a DART that * is not locked, or whose boot loader also handed over reserved tables, * is not the handoff it was written for. Refuse either, saying which. */ - if (t8132_display_v27 && dart->fw_mirror) - dev_info(dev, "T8132 internal display DART on the 27.2 image: locked roots kept (mirror)\n"); - else if (t8132_display_v27 && !dart->locked) - dev_err(dev, "T8132 internal display DART on the 27.2 image: NOT locked: refusing\n"); - else if (t8132_display_v27) - dev_err(dev, "T8132 internal display DART on the 27.2 image: locked with a reserved-table handoff: refusing\n"); - dart->t8132_dcp_v27 = t8132_display_v27; - if (t8132_display_v27 && !dart->fw_mirror) { + if (t8132_dcp && dart->fw_mirror) + dev_info(dev, "T8132 internal display DART: locked roots kept (mirror)\n"); + else if (t8132_dcp && !dart->locked) + dev_err(dev, "T8132 internal display DART: NOT locked: refusing\n"); + else if (t8132_dcp) + dev_err(dev, "T8132 internal display DART: locked with a reserved-table handoff: refusing\n"); + dart->t8132_dcp_v27 = t8132_dcp; + if (t8132_dcp && !dart->fw_mirror) { ret = -EINVAL; goto err_clk_disable; } From ef48113b7930c1d7a7d3950aee6d243ef203de3c Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 25 Nov 2026 10:02:20 +1100 Subject: [PATCH 25/25] iommu: apple-dart: give any fw_mirror DART's firmware segments their leaves' protection The hook that maps re-exported firmware segments with the protection of the firmware's live leaves ran only on DARTs flagged t8132_dcp_v27, a flag set for one SoC's internal display DARTs on one firmware image. Every other fw_mirror DART still mapped such a segment read-write and uncached, which apple_dart_check_fw_map() refuses in a slot the firmware holds, so a boot loader re-exporting the same segments for another processor or image would need yet another opt-in. The hook does not need to know which DART it is. What makes it correct is the DART's own state and tables: fw_mirror (locked, no reserved-table handoff, not borrowed), a three-level root in reserved RAM, and live leaves that map every page of the region to exactly its physical address with one protection. Key it on that, drop the flag, and name the hook after fw_mirror. This cannot widen what a client gets: the protection comes from the firmware's own leaves, and it is changed only when it differs from what the region asked for. In that case the page sits in a firmware-held slot whose leaf maps it already, and apple_dart_check_fw_map() requires an exact match there, so the attach was being refused. Where an attach succeeds today the hook changes nothing. DARTs that are not fw_mirror are not touched, which is every locked T8132 DART except the internal display ones, the PMP's (0x380300000) included, and every borrowed DART (those return before the hook). Extend the KUnit case: a DART that is not fw_mirror, one with fw_handoff and an unlocked one keep the asked protection; the same DART back on fw_mirror takes the leaves' again. Signed-off-by: Ryan Murray --- drivers/iommu/apple-dart-test.c | 42 +++++++++++++++++++++++---------- drivers/iommu/apple-dart.c | 32 ++++++++++++------------- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/drivers/iommu/apple-dart-test.c b/drivers/iommu/apple-dart-test.c index 0b6dbac31e155..e98f7d4af4708 100644 --- a/drivers/iommu/apple-dart-test.c +++ b/drivers/iommu/apple-dart-test.c @@ -1370,11 +1370,12 @@ static void apple_dart_test_t8132_fw_mirror_selection(struct kunit *test) } /* - * A 27.2 T8132 internal display DART: re-exported firmware segments take the - * protection of the live leaves that map them (read-only text, cacheable - * data); a region whose leaf maps another page keeps what it asked for. + * A fw_mirror DART (here a T8132 internal display DART's layout): re-exported + * firmware segments take the protection of the live leaves that map them + * (read-only text, cacheable data); a region whose leaf maps another page + * keeps what it asked for. Any DART that is not fw_mirror is left alone. */ -static void apple_dart_test_t8132_dcp_v27_fw_prot(struct kunit *test) +static void apple_dart_test_fw_mirror_prot(struct kunit *test) { const u64 fields = GENMASK_ULL(51, 40) | BIT_ULL(0); const phys_addr_t text_pa = 0x80000000ULL, data_pa = 0x80100000ULL; @@ -1390,7 +1391,7 @@ static void apple_dart_test_t8132_dcp_v27_fw_prot(struct kunit *test) kunit_skip(test, "needs kernel pages of at least 16 KiB"); dart = kunit_kzalloc(test, sizeof(*dart), GFP_KERNEL); KUNIT_ASSERT_NOT_NULL(test, dart); - dart->dev = kunit_device_register(test, "apple-dart-t8132-dcp-v27-test"); + dart->dev = kunit_device_register(test, "apple-dart-fw-mirror-prot-test"); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dart->dev); regs = vzalloc(APPLE_DART_TEST_REGS_SIZE); KUNIT_ASSERT_NOT_NULL(test, regs); @@ -1402,7 +1403,6 @@ static void apple_dart_test_t8132_dcp_v27_fw_prot(struct kunit *test) dart->oas = 42; dart->locked = true; dart->fw_mirror = true; - dart->t8132_dcp_v27 = true; /* The display DARTs' window: 64 GiB at 1 TiB. */ dart->locked_window[23] = 0x10000000000ULL; root = apple_dart_test_reserved_table(test); @@ -1439,7 +1439,7 @@ static void apple_dart_test_t8132_dcp_v27_fw_prot(struct kunit *test) pm_runtime_set_active(dart->dev); pm_runtime_enable(dart->dev); - __apple_dart_t8132_dcp_v27_fw_prot(&master, dart->dev, &head); + __apple_dart_fw_mirror_prot(&master, dart->dev, &head); KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_CACHE); KUNIT_EXPECT_EQ(test, data.prot, IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE); KUNIT_EXPECT_EQ(test, moved.prot, IOMMU_READ | IOMMU_WRITE); @@ -1449,22 +1449,38 @@ static void apple_dart_test_t8132_dcp_v27_fw_prot(struct kunit *test) /* A leaf table outside reserved RAM is never mapped: nothing changes. */ text.prot = IOMMU_READ | IOMMU_WRITE; ClearPageReserved(virt_to_page(leaf)); - __apple_dart_t8132_dcp_v27_fw_prot(&master, dart->dev, &head); + __apple_dart_fw_mirror_prot(&master, dart->dev, &head); SetPageReserved(virt_to_page(leaf)); KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); /* A four-level root is not walked: nothing changes. */ text.prot = IOMMU_READ | IOMMU_WRITE; writel(dart->hw->tcr_4level, dart->regs + DART_TCR(dart, 23)); - __apple_dart_t8132_dcp_v27_fw_prot(&master, dart->dev, &head); + __apple_dart_fw_mirror_prot(&master, dart->dev, &head); writel(0, dart->regs + DART_TCR(dart, 23)); KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); - /* Not a 27.2 T8132 internal display DART: nothing changes. */ + /* + * Not fw_mirror (a locked DART on the retained-root path, such as the + * T8132 PMP's), with reserved tables, or unlocked: nothing changes. + */ text.prot = IOMMU_READ | IOMMU_WRITE; - dart->t8132_dcp_v27 = false; - __apple_dart_t8132_dcp_v27_fw_prot(&master, dart->dev, &head); + dart->fw_mirror = false; + __apple_dart_fw_mirror_prot(&master, dart->dev, &head); KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); + dart->fw_mirror = true; + dart->fw_handoff = true; + __apple_dart_fw_mirror_prot(&master, dart->dev, &head); + KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); + dart->fw_handoff = false; + dart->locked = false; + __apple_dart_fw_mirror_prot(&master, dart->dev, &head); + KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); + dart->locked = true; + + /* The same DART back on fw_mirror takes the leaves' protection again. */ + __apple_dart_fw_mirror_prot(&master, dart->dev, &head); + KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_CACHE); pm_runtime_disable(dart->dev); } @@ -1478,7 +1494,7 @@ static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_sync_unknown_roots), KUNIT_CASE(apple_dart_test_firmware_roots), KUNIT_CASE(apple_dart_test_t8132_fw_mirror_selection), - KUNIT_CASE(apple_dart_test_t8132_dcp_v27_fw_prot), + KUNIT_CASE(apple_dart_test_fw_mirror_prot), KUNIT_CASE(apple_dart_test_unmap_flush_after_publish_failure), KUNIT_CASE(apple_dart_test_gated_commands), KUNIT_CASE(apple_dart_test_resume_commands_failure), diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 7ad0abc6ad2ee..504ac45133273 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -426,8 +426,6 @@ struct apple_dart { u32 sleep_gated : 1; /* Locked roots may hold firmware slots that mirror Linux mappings. */ u32 fw_mirror : 1; - /* A T8132 internal display DART of a handed-over DCP (fw_mirror, not borrowed). */ - u32 t8132_dcp_v27 : 1; /* * fw_mirror's four-level locked roots hold firmware's own subtrees, which * are recorded and reserved (apple_dart_snapshot_fw_tree()). Set only for @@ -4565,18 +4563,20 @@ static void apple_dart_get_fw_resv_regions(struct device *dev, } /* - * A T8132 internal display DART on the 27.2 image (fw_mirror): the boot loader - * re-exports the firmware's own segments as iommu-addresses, which the core - * maps read-write, and uncached for this non-coherent DCP. The firmware's - * leaves say what those pages are: its text read-only, all of it cacheable. - * A Linux table in a slot the firmware holds must mirror its leaves exactly - * (apple_dart_fw_slot_mirrors()), so give each such region the protection the + * A fw_mirror DART (locked, no reserved-table handoff, not borrowed) on a + * three-level root: a boot loader may re-export the firmware's own segments + * as iommu-addresses, which the core maps read-write, and uncached for a + * non-coherent client such as a DCP. The firmware's leaves say what those + * pages are: its text read-only, all of it cacheable. A Linux table in a slot + * the firmware holds must mirror its leaves exactly (apple_dart_fw_slot_mirrors(), + * apple_dart_check_fw_map()), so give each such region the protection the * live leaves give every one of its pages. A region whose pages are not mapped * there, map elsewhere or disagree keeps its protection, and the attach then - * refuses it as before. + * refuses it as before. A region whose protection already matches is left + * alone, so this changes only a mapping the attach would otherwise refuse. */ -static void __apple_dart_t8132_dcp_v27_fw_prot(struct apple_dart_master_cfg *cfg, - struct device *dev, struct list_head *head) +static void __apple_dart_fw_mirror_prot(struct apple_dart_master_cfg *cfg, + struct device *dev, struct list_head *head) { const int mask = IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE; struct iommu_resv_region *region; @@ -4590,7 +4590,8 @@ static void __apple_dart_t8132_dcp_v27_fw_prot(struct apple_dart_master_cfg *cfg if (!cfg || !cfg->stream_maps[0].dart || cfg->stream_maps[1].dart) return; dart = cfg->stream_maps[0].dart; - if (!dart->t8132_dcp_v27 || !dart->locked || dart->hw->fmt != APPLE_DART2) + if (!dart->fw_mirror || dart->fw_handoff || !dart->locked || + dart->hw->fmt != APPLE_DART2) return; entries = dart->pgsize / sizeof(u64); sid = find_first_bit(cfg->stream_maps[0].sidmap, dart->num_streams); @@ -4666,9 +4667,9 @@ static void __apple_dart_t8132_dcp_v27_fw_prot(struct apple_dart_master_cfg *cfg memunmap(root); } -static void apple_dart_t8132_dcp_v27_fw_prot(struct device *dev, struct list_head *head) +static void apple_dart_fw_mirror_prot(struct device *dev, struct list_head *head) { - __apple_dart_t8132_dcp_v27_fw_prot(dev_iommu_priv_get(dev), dev, head); + __apple_dart_fw_mirror_prot(dev_iommu_priv_get(dev), dev, head); } static void apple_dart_get_resv_regions(struct device *dev, @@ -4700,7 +4701,7 @@ static void apple_dart_get_resv_regions(struct device *dev, /* Keep the translated-domain requirement and inherited translations. */ iommu_dma_get_resv_regions(dev, head); - apple_dart_t8132_dcp_v27_fw_prot(dev, head); + apple_dart_fw_mirror_prot(dev, head); apple_dart_get_fw_resv_regions(dev, head); } @@ -6086,7 +6087,6 @@ static int apple_dart_probe(struct platform_device *pdev) dev_err(dev, "T8132 internal display DART: NOT locked: refusing\n"); else if (t8132_dcp) dev_err(dev, "T8132 internal display DART: locked with a reserved-table handoff: refusing\n"); - dart->t8132_dcp_v27 = t8132_dcp; if (t8132_dcp && !dart->fw_mirror) { ret = -EINVAL; goto err_clk_disable;