From 2c63310e00f64390441d02933e6da9fbe45eae2f Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 11:46:10 +1100 Subject: [PATCH 1/7] 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 7d96ad49b0190..2427bb35bffbe 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -7761,6 +7761,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 d81cf764e45e42fe96270834c56e9cd62546e5c0 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 11:46:10 +1100 Subject: [PATCH 2/7] 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 26107506fb9f1..8de276ad5623a 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -9629,12 +9629,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 c2696ec02a2b41546de43bc675715e9efffa402a Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 11:46:24 +1100 Subject: [PATCH 3/7] 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 06578d9ede42a..b852e28fce9e9 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -243,6 +243,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; }; /* @@ -861,6 +868,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 8de276ad5623a..1bc04fe052ef8 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -296,6 +296,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; @@ -308,6 +394,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; @@ -7122,13 +7217,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 = { @@ -7313,7 +7412,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; @@ -8282,7 +8382,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) @@ -8322,6 +8424,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) @@ -8791,6 +8902,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) @@ -8829,8 +8946,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); @@ -8881,8 +8998,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 6ece675665934e6c4d715e371cbe91a405d38121 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 11:58:52 +1100 Subject: [PATCH 4/7] 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 2218023c37e100941f010001c662c3214f8186ac Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 21 Nov 2026 11:58:52 +1100 Subject: [PATCH 5/7] 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 634fbb2d2029ee140cc916ca4f4dabe6226f5df0 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sun, 22 Nov 2026 08:58:02 +1100 Subject: [PATCH 6/7] 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 1bc04fe052ef8..83e5cfe0cd594 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -293,8 +293,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 @@ -382,6 +383,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; @@ -395,11 +428,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; } } @@ -579,7 +613,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) { @@ -7409,7 +7443,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 && @@ -8424,15 +8460,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 2427bb35bffbe..5d1e9a53f0fd1 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -7762,15 +7762,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 48789bf2a42f41713426f702a902f7a8ec9f53de Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sun, 22 Nov 2026 19:32:05 +1100 Subject: [PATCH 7/7] 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 83e5cfe0cd594..3c8a5ff7cf074 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -305,7 +305,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) { @@ -337,7 +337,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) || @@ -387,7 +388,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) { @@ -405,10 +407,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);