From 17609048e8733a585067673828945335c955de98 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 14 Nov 2026 15:18:00 -0600 Subject: [PATCH 1/5] iommu: apple-dart: T8142: use the DCP DART's PS write-disable bit T8142 has no GAPF slice for the DCP DART. Its SPTM (27.2.1) keeps a bit per DART in a shared PS write-disable register instead (/chosen/dart-ps-wr-dis-entries): set, the fabric rejects writes to the power word of the coprocessor CPU behind the DART. The driver clears that bit where it clears GAPF bit 4 on T8140, for a DCP firmware stop, and sets it again after. Only this DART's bit of the register is changed. A GAPF slice is handled as before. Nothing of the shared register's boot value is written back, only this DART's bit. From m0d16l14n1's J815 sleep work (m0d16l14n1/linux#1, 192a56c3baf6), taken out on its own for the DPMS firmware stop. Assisted-by: Claude Opus 5.5 Assisted-by: Claude Fable 5.2 Signed-off-by: Kyle Arrington --- .../devicetree/bindings/iommu/apple,dart.yaml | 14 +++++- drivers/iommu/apple-dart.c | 43 +++++++++++++++---- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 0cc59590ce0ed..6e7fdf9af5fdd 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -85,13 +85,15 @@ properties: Address filter (DAPF) registers, which restrict the physical addresses the DART lets its masters reach, or the slice of the fabric filter (GAPF) that protects the power state of the - coprocessor CPU behind this DART, cleared to power that CPU down + coprocessor CPU behind this DART, cleared to power that CPU down, + or the shared PS write-disable register that holds this DART's + bit for the same purpose (T8142) reg-names: minItems: 1 items: - const: dart - - enum: [dapf, gapf, auxiliary] + - enum: [dapf, gapf, ps-wr-dis, auxiliary] interrupts: maxItems: 1 @@ -234,6 +236,14 @@ properties: present and the word reads one of the two; otherwise it refuses the sleep. Set by the boot loader. + apple,ps-wr-dis-bit: + $ref: /schemas/types.yaml#/definitions/uint32 + maximum: 31 + description: > + This DART's bit in the ps-wr-dis register: set, the fabric rejects + writes to the power state of the coprocessor CPU behind it. Required + with a ps-wr-dis register; only that bit of the register is changed. + apple,manual-availability: type: boolean description: > diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index b97b0c3378e45..2b3ed6b1c4734 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -361,8 +361,16 @@ struct apple_dart { void __iomem *regs; void __iomem *gapf; - /* The GAPF slice as it read at probe; a deep sleep resets it to 0 */ + /* + * The GAPF slice as it read at probe; a deep sleep resets it to 0. Stays 0 for a + * shared PS write-disable register, of which only gapf_protect is ever written. + */ u32 gapf_boot; + /* + * The bit that protects the coprocessor's power state: bit 4 of a GAPF slice, or + * this DART's bit in a shared PS write-disable register (T8142) + */ + u32 gapf_protect; bool sleep_flushed; /* The firmware 27 display sleep owns it: never replay locked trees. */ struct device *m5_sleep_owner; @@ -5538,6 +5546,24 @@ static int apple_dart_probe(struct platform_device *pdev) if (IS_ERR(dart->gapf)) return PTR_ERR(dart->gapf); dart->gapf_boot = readl(dart->gapf); + dart->gapf_protect = APPLE_DART_GAPF_PROTECT; + } else if (platform_get_resource_byname(pdev, IORESOURCE_MEM, "ps-wr-dis")) { + u32 bit; + + /* + * T8142: the SPTM's dart-ps-wr-dis-entries give each DART a bit in a register + * of a PSWRDIS block instead of a GAPF slice. The register is shared, so + * only this DART's bit is ever changed: nothing of the boot value is put + * back (gapf_boot stays 0). + */ + ret = of_property_read_u32(dev->of_node, "apple,ps-wr-dis-bit", &bit); + if (ret || bit > 31) + return dev_err_probe(dev, ret ?: -EINVAL, + "ps-wr-dis needs apple,ps-wr-dis-bit\n"); + dart->gapf = devm_platform_ioremap_resource_byname(pdev, "ps-wr-dis"); + if (IS_ERR(dart->gapf)) + return PTR_ERR(dart->gapf); + dart->gapf_protect = BIT(bit); } /* T8132's ISP DART names its DAPF page but has no ranges to restore. */ if (platform_get_resource_byname(pdev, IORESOURCE_MEM, "dapf") && @@ -7484,8 +7510,9 @@ EXPORT_SYMBOL_GPL(apple_dart_dcp_dispext_state); #endif /* - * Bit 4 of this DART's GAPF slice makes the fabric reject writes to its coprocessor's - * CPU power state. It's clear from the flush until the streams come back on. + * Bit 4 of this DART's GAPF slice (or its PS write-disable bit) makes the fabric reject + * writes to its coprocessor's CPU power state. It's clear from the flush until the + * streams come back on. */ static int apple_dart_gapf_release(struct apple_dart *dart) { @@ -7495,9 +7522,9 @@ static int apple_dart_gapf_release(struct apple_dart *dart) return 0; val = readl(dart->gapf); - writel(val & ~APPLE_DART_GAPF_PROTECT, dart->gapf); - if (readl(dart->gapf) & APPLE_DART_GAPF_PROTECT) { - dev_err(dart->dev, "GAPF slice stayed protected: %#x\n", val); + writel(val & ~dart->gapf_protect, dart->gapf); + if (readl(dart->gapf) & dart->gapf_protect) { + dev_err(dart->dev, "power state write protection stayed set: %#x\n", val); return -EIO; } dev_dbg(dart->dev, "GAPF slice %#x -> %#x\n", val, readl(dart->gapf)); @@ -7514,7 +7541,7 @@ static void apple_dart_gapf_protect(struct apple_dart *dart) return; val = readl(dart->gapf); - writel(val | dart->gapf_boot | APPLE_DART_GAPF_PROTECT, dart->gapf); + writel(val | dart->gapf_boot | dart->gapf_protect, dart->gapf); dev_dbg(dart->dev, "GAPF slice %#x -> %#x\n", val, readl(dart->gapf)); } @@ -7523,7 +7550,7 @@ int apple_dart_gapf_ready(struct device *dev) { struct apple_dart *dart = dev_get_drvdata(dev); - if (!dart->gapf || !(readl(dart->gapf) & APPLE_DART_GAPF_PROTECT)) + if (!dart->gapf || !(readl(dart->gapf) & dart->gapf_protect)) return 0; return apple_dart_gapf_release(dart); From b8f8cb787de82ae897a1f17a0957eb1f3fcd00bd Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 14 Nov 2026 15:18:00 -0600 Subject: [PATCH 2/5] dt-bindings: display: apple,t8140-display-power: Add T8142 T8142's display power node has the power gate and power state words only: its PMC keeps no count of the powered coprocessors, so there is no pmc-dcp word. From m0d16l14n1's J815 sleep work (m0d16l14n1/linux#1, 192a56c3baf6). Assisted-by: Claude Opus 5.5 Assisted-by: Claude Fable 5.2 Signed-off-by: Kyle Arrington --- .../display/apple,t8140-display-power.yaml | 64 ++++++++++++++++--- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml index 41bd5586820f2..7d15745134267 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 display power words +title: Apple T8140 and T8142 display power words maintainers: - Diljit Singh @@ -17,25 +17,56 @@ description: properties: compatible: - const: apple,t8140-display-power + enum: + - apple,t8140-display-power + - apple,t8142-display-power reg: - items: - - description: the display PMC word that counts the powered coprocessors - - description: the power manager's power state words - - description: the power manager's power gate words + minItems: 2 + maxItems: 3 reg-names: - items: - - const: pmc-dcp - - const: ps - - const: pwrgate + minItems: 2 + maxItems: 3 required: - compatible - reg - reg-names +allOf: + - if: + properties: + compatible: + const: apple,t8140-display-power + then: + properties: + reg: + items: + - description: the display PMC word that counts the powered coprocessors + - description: the power manager's power state words + - description: the power manager's power gate words + reg-names: + items: + - const: pmc-dcp + - const: ps + - const: pwrgate + - if: + properties: + compatible: + const: apple,t8142-display-power + then: + # T8142's PMC keeps no count of the powered coprocessors: no pmc-dcp word. + properties: + reg: + items: + - description: the power manager's power gate words + - description: the power manager's power state words + reg-names: + items: + - const: pwrgate + - const: ps + additionalProperties: false examples: @@ -52,3 +83,16 @@ examples: reg-names = "pmc-dcp", "ps", "pwrgate"; }; }; + + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + display-power@380724000 { + compatible = "apple,t8142-display-power"; + reg = <0x3 0x80724000 0x0 0x2000>, + <0x3 0x80700000 0x0 0x14000>; + reg-names = "pwrgate", "ps"; + }; + }; From 27002e5ad6abfc9497ef039c0228152239b9beb2 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 14 Nov 2026 15:18:00 -0600 Subject: [PATCH 3/5] drm/apple: T8142: stop the DCP firmware on DPMS off (firmware 27.2) hw.s2r stops the internal DCP's firmware and powers its domains off when the display is turned off, and restarts it warm on DPMS on. Only T8140 had the data for it. This adds what T8142 needs: - the power words and DART streams become a per-SoC layout (dcp_s2r_layout), with T8140's values unchanged and T8142's derived from the macOS 27.2.1 device tree and PMGR (DISP_SYS at 0x290, retention words 0x11cc/0x11f0, no exclave streams, no pmc-dcp); - the firmware 27 sleep calls: set_power_state, D572 (powerUpDART) and the AP link's release, which 27.0 dispatches as A500 and 27.2 as A550 (#2063). A build whose table has no tag for the release (27.3 so far) is not offered the stop; - T8142 has no DCP secure mailbox (no dcp-exclave-mailbox in the 27.0 or the 27.2.1 device tree of a J813), so the stop no longer requires one on this SoC (s2r_no_secure_port). The stop stays off by default on T8142 (appledrm.s2r_untested=1 enables it). On firmware 27.2 it also needs the DCP to run the firmware 27 interface there, which #1683 ("drm/apple: dcp: T8142: Drive the macOS 27.2 firmware") adds; without it a 27.2 J813 runs H17P and the stop is not offered. This is a screen-off (DPMS) power saving. A SoC behind appledrm.s2r_untested does not take the stop's system sleep path. Tested on a J813 (MacBook Air 13" M5) with appledrm.s2r_untested=1: - firmware 27.0, on this series with and without the option: DPMS off stops the firmware, DPMS on restarts it ("RTKit: Initializing") and the panel comes back at its brightness, 6 of 6 cycles. System power with the screen off (SMC PSTR, on battery, 12 and 15 samples): 2.72 W without the stop, 1.81 W with it. - firmware 27.2 (t8142dcp 26B123), with the A550 entry: DPMS off logs "IOMFB: power on -> off" and "power_down_M3: disabling M3", DPMS on restarts the firmware ("RTKit: Initializing") and the panel comes back at its brightness, 3 of 3 cycles. Screen-off system power (SMC PSTR, on AC at the charge limit, 8 samples per cycle, 3 cycles each, the same boot setup with appledrm.s2r_untested=0 for the other side): 4.84 W without the stop, 3.91 W with it. m0d16l14n1 ran it on a J815 on firmware 27.2 with the A550 entry: 4 DPMS cycles over 3 boots, the firmware stopped and restarted each time. The driver part is from m0d16l14n1's J815 sleep work (m0d16l14n1/linux#1, 192a56c3baf6), without its hibernation and deep sleep pieces; the secure mailbox change and the J813 test are new. Assisted-by: Claude Opus 5.5 Assisted-by: Claude Fable 5.2 Signed-off-by: Kyle Arrington --- drivers/gpu/drm/apple/dcp-internal.h | 27 +++ drivers/gpu/drm/apple/dcp.c | 224 ++++++++++++++++++------- drivers/gpu/drm/apple/iomfb_template.c | 9 +- drivers/gpu/drm/apple/iomfb_v27.c | 36 +++- drivers/gpu/drm/apple/iomfb_v27.h | 2 + 5 files changed, 228 insertions(+), 70 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index d9243c90d5797..11a2d9da14ec1 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -227,6 +227,24 @@ struct dcp_panel { const struct dcp_color_space *color_target; }; +/* + * The internal display's power words for hw.s2r, see dcp_s2r_domains_off(): its domains' + * offsets in "ps", its retention controls in "pwrgate" (the PMGR's per-device "retention" + * words: flip-flops 3 off / 0 on, memories 0 off / 1 on), and the DART streams its firmware + * and scanout use. + */ +struct dcp_s2r_layout { + u32 disp_cpu; + u32 disp_fe; + u32 disp_sys; + u32 ret_ff; + u32 ret_mem; + u32 dcp_streams; + u32 disp_streams; + /* "pmc-dcp" counts the powered DCPs: T8132 and T8140 only */ + bool pmc_dcp; +}; + /* * Identity of a fixed internal panel, for the EDID published on its * connector. Any processor with an internal panel allocates it; the boot @@ -298,6 +316,15 @@ struct apple_dcp_hw_data { /* A firmware 27 sleep in progress, and how it ended */ bool v27_sleep_protocol; bool v27_sleep_recovery; + /* Required with @s2r */ + const struct dcp_s2r_layout *s2r_layout; + /* @s2r with derived power words: off unless appledrm.s2r_untested is set */ + bool s2r_untested; + /* + * @s2r without a secure mailbox: the SoC's ADT has no dcp-exclave-mailbox (T8142, on + * firmware 27.0 and 27.2.1), so there is no secure port to idle before the IOP. + */ + bool s2r_no_secure_port; }; enum dcp_test_point { diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index db703c822352c..fe9ead123e533 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -290,13 +290,16 @@ static int dcp_secure_port_init(struct apple_dcp *dcp) * Stopping the firmware (DPMS off and system sleep with hw.s2r or hw.s2r_ext) powers the * 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. + * 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 only. */ static void dcp_s2r_check_dt(struct apple_dcp *dcp) { struct device_node *np = dcp->dev->of_node; bool power = of_property_present(np, "apple,display-power"); - bool secure = of_property_match_string(np, "mbox-names", "secure") >= 0; + bool secure = dcp->hw.s2r_no_secure_port || + of_property_match_string(np, "mbox-names", "secure") >= 0; if (dcp->hw.s2r && (!power || !secure)) { dev_info(dcp->dev, "no %s in the device tree, the firmware keeps running\n", @@ -307,6 +310,8 @@ static void dcp_s2r_check_dt(struct apple_dcp *dcp) dev_info(dcp->dev, "no apple,display-power in the device tree, the firmware keeps running\n"); dcp->hw.s2r_ext = false; } + if (dcp->hw.s2r && dcp->hw.s2r_untested) + dev_info(dcp->dev, "firmware stop on DPMS off enabled (appledrm.s2r_untested)\n"); } static void dcp_release_rtkit(void *data) @@ -469,6 +474,16 @@ static bool dcp_j714s_ext(struct device *dev) of_device_is_compatible(dev->of_node, "apple,t6050-dcpext"); } +/* + * The firmware stop on a SoC whose display power words were derived from its macOS device + * tree instead of measured (T8142). There it has only run for DPMS off, on a J813; no + * firmware-driven system sleep has. Off by default: such a DCP keeps its firmware running. + */ +static bool s2r_untested; +module_param(s2r_untested, bool, 0444); +MODULE_PARM_DESC(s2r_untested, + "Stop the DCP firmware on DPMS off on SoCs whose power words are derived, not measured: T8142 on firmware 27.0 and 27.2 (default 0)"); + bool dcp_t6041_ext_enabled(void) { return t6041_dcpext; @@ -7020,6 +7035,14 @@ 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,t8142-dcp")) dcp->hw.iomfb_method_profile = DCP_IOMFB_METHODS_DEFAULT; + /* + * A SoC with derived power words is offered the stop only when asked for, and only on + * the firmware 27 builds (27.0, 27.2), whose calls are the ones that ran with them. + */ + if (dcp->hw.s2r && (!dcp->hw.s2r_layout || + (dcp->hw.s2r_untested && + (!s2r_untested || fw_compat != DCP_FIRMWARE_V_27_0)))) + dcp->hw.s2r = false; /* The display such a processor finds at boot is its first sink. */ if (dcp_sink_metadata(dcp)) dcp_desktop_metadata_new_sink(dcp); @@ -7922,9 +7945,43 @@ static void dcp_platform_complete(struct device *dev) * The firmware takes IOP idle only with its secure mailbox answered, see * dcp_s2r_answer_secure_port(). */ -#define DCP_S2R_DISP_STREAMS (BIT(0) | BIT(3) | BIT(4) | BIT(16)) -#define DCP_S2R_DCP_STREAMS (BIT(23) | BIT(24)) #define DCP_S2R_D572_TIMEOUT_MS 1000 /* macOS: about 170 ms after A473(0) */ + +/* T8140's, measured. Its DCPEXT uses the same DCP streams. */ +static const struct dcp_s2r_layout dcp_s2r_t8140 = { + .disp_cpu = 0x10000, + .disp_fe = 0x318, + .disp_sys = 0x280, + .ret_ff = 0xc8c, + .ret_mem = 0xcd0, + .dcp_streams = BIT(23) | BIT(24), + .disp_streams = BIT(0) | BIT(3) | BIT(4) | BIT(16), + .pmc_dcp = true, +}; + +/* + * T8142's, derived from macOS 27.2.1 and run for DPMS off on a J813: the domains + * from the ADT's PMGR devices (DISP_SYS moved to 0x290), the retention words from the + * pmgr's retention_config_ff/_mem for DISP_CPU (device 0xb7), which ApplePMGR's + * _setPwrGateRetention writes into PMGR_SOC_PWRGATE with the same values T8140 measured, + * and the streams from dart-dcp's sid 23 + vm-base-24 and dart-disp0's sids 0 and 16 (no + * exclave streams). AppleT8142PMC has no count of powered DCPs: no pmc-dcp. + */ +static const struct dcp_s2r_layout dcp_s2r_t8142 = { + .disp_cpu = 0x10000, + .disp_fe = 0x318, + .disp_sys = 0x290, + .ret_ff = 0x11cc, + .ret_mem = 0x11f0, + .dcp_streams = BIT(23) | BIT(24), + .disp_streams = BIT(0) | BIT(16), + .pmc_dcp = false, +}; + +static const struct dcp_s2r_layout *dcp_s2r_layout(struct apple_dcp *dcp) +{ + return dcp->hw.s2r_layout ?: &dcp_s2r_t8140; +} #define DCP_PS_MIN GENMASK(19, 16) static struct device *dcp_s2r_find_dart(struct device_node *np) @@ -7971,13 +8028,38 @@ void dcp_s2r_dart_power(struct apple_dcp *dcp, u32 on) return; if (dcp->s2r_disp_dart) - apple_dart_display_streams(dcp->s2r_disp_dart, DCP_S2R_DISP_STREAMS, on, false); + apple_dart_display_streams(dcp->s2r_disp_dart, dcp_s2r_layout(dcp)->disp_streams, + on, false); complete(&dcp->s2r_dart_done); } static bool dcp_s2r_capable(struct apple_dcp *dcp) { - return dcp->fw_compat == DCP_FIRMWARE_H17P && dcp->hw.s2r; + /* + * The firmware 27 builds run as V_27_0, each with its own table. The AP link's release + * is A500 on 27.0 and A550 on 27.2; a table with no tag for it (27.3 so far) is not + * offered the stop: an empty tag panics the firmware. + */ + if (dcp->fw_compat == DCP_FIRMWARE_V_27_0 && + (!dcp->v27_methods || !dcp->v27_methods[dcpep_unnamed_500].tag[0])) + return false; + return (dcp->fw_compat == DCP_FIRMWARE_H17P || dcp->fw_compat == DCP_FIRMWARE_V_27_0) && + dcp->hw.s2r; +} + +/* The same calls on firmware 27, under each build's own tags: iomfb_v27.c. */ +static int dcp_s2r_power(struct apple_dcp *dcp, bool on, bool named_calls, bool oob) +{ + if (dcp->fw_compat == DCP_FIRMWARE_V_27_0) + return iomfb_s2r_power_v27(dcp, on, named_calls, oob); + return iomfb_s2r_power_h17p(dcp, on, named_calls, oob); +} + +static int dcp_s2r_500(struct apple_dcp *dcp) +{ + if (dcp->fw_compat == DCP_FIRMWARE_V_27_0) + return iomfb_s2r_500_v27(dcp); + return iomfb_s2r_500_h17p(dcp); } static void dcp_s2r_cpu_stop(struct apple_dcp *dcp) @@ -8034,7 +8116,7 @@ static int dcp_s2r_quiesce(struct apple_dcp *dcp, u32 *status) } /* In band, 3 of 3 on macOS. */ - ret = iomfb_s2r_power_h17p(dcp, false, true, false); + ret = dcp_s2r_power(dcp, false, true, false); if (ret) { dev_err(dcp->dev, "no reply to set_power_state(0): %d\n", ret); goto err; @@ -8059,7 +8141,7 @@ static int dcp_s2r_quiesce(struct apple_dcp *dcp, u32 *status) if (read_poll_timeout(iomfb_channels_idle, idle, idle, 1000, 100000, false, dcp)) dev_warn(dcp->dev, "firmware calls still in flight before A500\n"); - ret = iomfb_s2r_500_h17p(dcp); + ret = dcp_s2r_500(dcp); if (ret) { dev_err(dcp->dev, "no reply to A500: %d\n", ret); goto err; @@ -8132,7 +8214,8 @@ static int dcp_s2r_stop_streams(struct apple_dcp *dcp) if (!dcp->s2r_dcp_dart) return -ENODEV; - return apple_dart_display_streams(dcp->s2r_dcp_dart, DCP_S2R_DCP_STREAMS, false, true); + return apple_dart_display_streams(dcp->s2r_dcp_dart, dcp_s2r_layout(dcp)->dcp_streams, + false, true); } static int dcp_s2r_stop_firmware(struct apple_dcp *dcp) @@ -8301,7 +8384,7 @@ static int dcp_s2r_ext_suspend(struct apple_dcp *dcp) /* The display's link went above: its crossbar output follows, as on macOS. */ dcp_typec_route_park(dcp); - ret = iomfb_s2r_500_h17p(dcp); + ret = dcp_s2r_500(dcp); if (ret) { dev_err(dcp->dev, "no reply to A500: %d\n", ret); WRITE_ONCE(dcp->crashed, true); @@ -8404,40 +8487,55 @@ static void dcp_s2r_ps_lower(void __iomem *reg) writel((val & ~GENMASK(3, 0)) | GENMASK(9, 8), reg); } -/* macOS's power-off, measured 3 of 3. The firmware is stopped and its DARTs are off. */ -static int dcp_s2r_domains_off(struct apple_dcp *dcp) +/* 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) { struct device_node *np; - void __iomem *ps = NULL, *pwrgate = NULL, *pmc = NULL; - u32 val; - int ret = -ENODEV; - dcp->s2r_domains_up = false; + *ps = *pwrgate = *pmc = NULL; np = of_parse_phandle(dcp->dev->of_node, "apple,display-power", 0); if (!np) return -ENODEV; - ps = of_iomap(np, of_property_match_string(np, "reg-names", "ps")); - pwrgate = of_iomap(np, of_property_match_string(np, "reg-names", "pwrgate")); - pmc = of_iomap(np, of_property_match_string(np, "reg-names", "pmc-dcp")); + *ps = of_iomap(np, of_property_match_string(np, "reg-names", "ps")); + *pwrgate = of_iomap(np, of_property_match_string(np, "reg-names", "pwrgate")); + if (dcp_s2r_layout(dcp)->pmc_dcp) + *pmc = of_iomap(np, of_property_match_string(np, "reg-names", "pmc-dcp")); of_node_put(np); - if (!ps || !pwrgate || !pmc) + + return *ps && *pwrgate && (*pmc || !dcp_s2r_layout(dcp)->pmc_dcp) ? 0 : -ENODEV; +} + +/* macOS's power-off, measured 3 of 3 on T8140. The firmware is stopped and its DARTs are off. */ +static int dcp_s2r_domains_off(struct apple_dcp *dcp) +{ + const struct dcp_s2r_layout *l = dcp_s2r_layout(dcp); + void __iomem *ps, *pwrgate, *pmc; + u32 val; + int ret; + + dcp->s2r_domains_up = false; + ret = dcp_s2r_map_power(dcp, &ps, &pwrgate, &pmc); + if (ret) goto out; - dcp_pmc_set(dcp, pmc, false); - val = readl(ps + 0x10000); + if (pmc) + dcp_pmc_set(dcp, pmc, false); + val = readl(ps + l->disp_cpu); if (val & BIT(28)) - writel(val & ~(BIT(28) | GENMASK(9, 8)), ps + 0x10000); - writel(3, pwrgate + 0xc8c); - writel(0, pwrgate + 0xcd0); - dcp_s2r_ps_lower(ps + 0x10000); - dcp_s2r_ps_lower(ps + 0x318); - dcp_s2r_ps_lower(ps + 0x280); - - ret = readl_poll_timeout(ps + 0x10000, val, !FIELD_GET(GENMASK(7, 4), val), 100, 50000); + writel(val & ~(BIT(28) | GENMASK(9, 8)), ps + l->disp_cpu); + writel(3, pwrgate + l->ret_ff); + writel(0, pwrgate + l->ret_mem); + dcp_s2r_ps_lower(ps + l->disp_cpu); + dcp_s2r_ps_lower(ps + l->disp_fe); + dcp_s2r_ps_lower(ps + l->disp_sys); + + ret = readl_poll_timeout(ps + l->disp_cpu, val, !FIELD_GET(GENMASK(7, 4), val), 100, + 50000); if (ret) dev_err(dcp->dev, "DISP_CPU did not power off: %#x\n", val); - dev_dbg(dcp->dev, "display domains off: CPU %#x FE %#x SYS %#x\n", readl(ps + 0x10000), - readl(ps + 0x318), readl(ps + 0x280)); + dev_dbg(dcp->dev, "display domains off: CPU %#x FE %#x SYS %#x\n", + readl(ps + l->disp_cpu), readl(ps + l->disp_fe), readl(ps + l->disp_sys)); out: if (ps) iounmap(ps); @@ -8455,34 +8553,29 @@ static int dcp_s2r_domains_off(struct apple_dcp *dcp) */ static int dcp_s2r_domains_on(struct apple_dcp *dcp) { - struct device_node *np; - void __iomem *ps = NULL, *pwrgate = NULL, *pmc = NULL; + const struct dcp_s2r_layout *l = dcp_s2r_layout(dcp); + void __iomem *ps, *pwrgate, *pmc; u32 val; - int ret = -ENODEV; + int ret; - np = of_parse_phandle(dcp->dev->of_node, "apple,display-power", 0); - if (!np) - return -ENODEV; - ps = of_iomap(np, of_property_match_string(np, "reg-names", "ps")); - pwrgate = of_iomap(np, of_property_match_string(np, "reg-names", "pwrgate")); - pmc = of_iomap(np, of_property_match_string(np, "reg-names", "pmc-dcp")); - of_node_put(np); - if (!ps || !pwrgate || !pmc) + ret = dcp_s2r_map_power(dcp, &ps, &pwrgate, &pmc); + if (ret) goto out; - val = readl(ps + 0x280) & ~(GENMASK(9, 8) | GENMASK(3, 0) | BIT(28)); - writel(val | 0xf, ps + 0x280); - writel(val | 0xf | BIT(28), ps + 0x280); - val = readl(ps + 0x318) & ~(GENMASK(9, 8) | GENMASK(3, 0)); - writel(val | 0xf, ps + 0x318); - val = readl(ps + 0x10000) & ~(GENMASK(9, 8) | GENMASK(3, 0) | BIT(28)); - writel(val | 0xf, ps + 0x10000); - writel(0, pwrgate + 0xc8c); - writel(1, pwrgate + 0xcd0); - writel(val | 0xf | BIT(28), ps + 0x10000); - dcp_pmc_set(dcp, pmc, true); - - ret = readl_poll_timeout(ps + 0x10000, val, FIELD_GET(GENMASK(7, 4), val) == 0xf, + val = readl(ps + l->disp_sys) & ~(GENMASK(9, 8) | GENMASK(3, 0) | BIT(28)); + writel(val | 0xf, ps + l->disp_sys); + writel(val | 0xf | BIT(28), ps + l->disp_sys); + val = readl(ps + l->disp_fe) & ~(GENMASK(9, 8) | GENMASK(3, 0)); + writel(val | 0xf, ps + l->disp_fe); + val = readl(ps + l->disp_cpu) & ~(GENMASK(9, 8) | GENMASK(3, 0) | BIT(28)); + writel(val | 0xf, ps + l->disp_cpu); + writel(0, pwrgate + l->ret_ff); + writel(1, pwrgate + l->ret_mem); + writel(val | 0xf | BIT(28), ps + l->disp_cpu); + if (pmc) + dcp_pmc_set(dcp, pmc, true); + + ret = readl_poll_timeout(ps + l->disp_cpu, val, FIELD_GET(GENMASK(7, 4), val) == 0xf, 100, 50000); if (ret) dev_err(dcp->dev, "DISP_CPU did not power on: %#x\n", val); @@ -8580,7 +8673,8 @@ static int dcp_s2r_ext_start(struct apple_dcp *dcp, bool cycled) if (ret) return ret; /* After the domains, whose writes it would reject, the DART protects them again. */ - apple_dart_display_streams(dcp->s2r_dcp_dart, DCP_S2R_DCP_STREAMS, true, false); + apple_dart_display_streams(dcp->s2r_dcp_dart, dcp_s2r_layout(dcp)->dcp_streams, true, + false); if (!cycled) return apple_rtkit_sleep_return(dcp->rtk, control); @@ -8721,7 +8815,8 @@ static int dcp_s2r_warm_restart(struct apple_dcp *dcp) /* After the domains, whose writes it would reject, the DART protects them again. */ if (dcp->s2r_dcp_dart) - apple_dart_display_streams(dcp->s2r_dcp_dart, DCP_S2R_DCP_STREAMS, true, false); + apple_dart_display_streams(dcp->s2r_dcp_dart, dcp_s2r_layout(dcp)->dcp_streams, + true, false); if (dcp->secure_rtk) { dcp_secure_poll_stop(dcp); @@ -8776,7 +8871,7 @@ static int dcp_s2r_display_on(struct apple_dcp *dcp) WRITE_ONCE(dcp->s2r_active, true); /* Out of band; either channel answered on macOS. */ - ret = iomfb_s2r_power_h17p(dcp, true, true, true); + ret = dcp_s2r_power(dcp, true, true, true); if (ret) { dev_err(dcp->dev, "no reply to set_power_state(1): %d\n", ret); goto out; @@ -9024,7 +9119,7 @@ static void dcp_s2r_light_running(struct apple_dcp *dcp) dcp_s2r_find_darts(dcp); reinit_completion(&dcp->s2r_dart_done); WRITE_ONCE(dcp->s2r_active, true); - ret = iomfb_s2r_power_h17p(dcp, true, true, true); + ret = dcp_s2r_power(dcp, true, true, true); if (!ret && !wait_for_completion_timeout(&dcp->s2r_dart_done, msecs_to_jiffies(DCP_S2R_D572_TIMEOUT_MS))) dev_warn(dcp->dev, "no D572 after set_power_state(1), scanout DART left off\n"); @@ -9213,7 +9308,8 @@ static int dcp_platform_suspend(struct device *dev) if (pm_suspend_via_firmware() && dcp_v27_sleep_selected(dcp)) return dcp_v27_sleep_suspend(dcp); - if (pm_suspend_via_firmware() && dcp_s2r_capable(dcp)) { + /* Derived power words have only run for DPMS off: no firmware-driven sleep with them. */ + if (pm_suspend_via_firmware() && dcp_s2r_capable(dcp) && !dcp->hw.s2r_untested) { int ret = dcp_s2r_suspend(dcp); /* Lit by the last resume with its CRTC off: the next resume finds it off by DPMS. */ @@ -9434,6 +9530,7 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t8140 = { .firmware_scratch = 0x20000, .firmware_request = 0x68000, .s2r = true, + .s2r_layout = &dcp_s2r_t8140, }; /* Separate from the established internal-panel H17P profile. */ @@ -9459,6 +9556,11 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t8142 = { .iomfb_method_profile = DCP_IOMFB_METHODS_H17G, .adopt_live_session = true, .firmware_compat = DCP_FIRMWARE_H17P, + /* Firmware 27.0's and 27.2's sleep calls (iomfb_v27.c): only with appledrm.s2r_untested */ + .s2r = true, + .s2r_untested = true, + .s2r_no_secure_port = true, + .s2r_layout = &dcp_s2r_t8142, }; static const struct apple_dcp_hw_data apple_dcp_hw_dcp = { diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index 8a4812678d164..ef1d28ced9788 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -638,7 +638,10 @@ DCP_THUNK_INOUT(dcp_pipe_cfg_414, dcpep_pipe_cfg_414, u64, u64); DCP_THUNK_OUT(dcp_pipe_query_478, dcpep_pipe_query_478, u32); DCP_THUNK_OUT(dcp_pipe_query_474, dcpep_pipe_query_474, u32); DCP_THUNK_IN(dcp_pipe_set_476, dcpep_pipe_set_476, u32); -#if DCP_FW_VER < DCP_FW_VERSION(27, 0, 0) +/* Built for firmware 27 too, under the build's tag (27.0's A500, 27.2's A550); the stop + * checks the build has one. + */ +#if DCP_FW_VER <= DCP_FW_VERSION(27, 0, 0) DCP_THUNK_IN(dcp_unnamed_500, dcpep_unnamed_500, u32); #endif #endif @@ -2644,8 +2647,8 @@ static void complete_set_powerstate(struct apple_dcp *dcp, void *out, } } -/* V27 shares the h17p template prefix, but does not own its sleep RPCs. */ -#if DCP_FW_H17(DCP_FW_VER) && DCP_FW_VER < DCP_FW_VERSION(27, 0, 0) +/* V27 shares the h17p template prefix; iomfb_v27.c renames these two to their _v27 names. */ +#if DCP_FW_H17(DCP_FW_VER) /* * set_power_state around a firmware-driven suspend. What macOS sends before it in * either direction: A414(0), A478 twice, A476(1), A478, A412. All are named in diff --git a/drivers/gpu/drm/apple/iomfb_v27.c b/drivers/gpu/drm/apple/iomfb_v27.c index 5902edc7013ee..1a1ec059414cb 100644 --- a/drivers/gpu/drm/apple/iomfb_v27.c +++ b/drivers/gpu/drm/apple/iomfb_v27.c @@ -158,6 +158,12 @@ static const struct dcp_method_entry dcp_methods_27_0[dcpep_num_methods] = { IOMFB_METHOD("A479", iomfbep_abort_swaps_dcp), IOMFB_METHOD("A484", dcpep_set_power_state), IOMFB_METHOD("A483", dcpep_register_dfb_surface), + /* + * The AP link's release, unnamed: H17P's and 26.6's A500, (0x4, 0). The 27.0 firmware + * still dispatches it as A500 (t8142dcp 1317.1.1: cmp 'A500', then 'A500' | 1), unlike + * the IOMFB calls around it; 27.2 moved both to A550/A551. + */ + IOMFB_METHOD("A500", dcpep_unnamed_500), }; /* @@ -264,10 +270,10 @@ const struct dcp_method_entry *iomfb_v27_methods(const char *compat) /* * The 27.0 table for the J714s, the board the firmware 27 sleep has run on (dcp->v27_j714s): a - * copy with the sleep's A500 added. The shared table keeps the methods it had, so every other - * machine sends what it sent, and a 27.2 or 27.3 build is judged against the same list as - * before (iomfb_v27_missing_method()). NULL if @methods is not the 27.0 table or the copy - * cannot be made. + * copy with the sleep's A500 set. The shared table names A500 too, for T8142's DPMS stop; only + * a firmware stop sends it, and iomfb_v27_missing_method() skips it, so a 27.2 or 27.3 build + * is judged against the same list as before. NULL if @methods is not the 27.0 table or the + * copy cannot be made. */ const struct dcp_method_entry *iomfb_v27_methods_j714s(struct device *dev, const struct dcp_method_entry *methods) @@ -302,8 +308,9 @@ const char *iomfb_v27_missing_method(const struct dcp_method_entry *methods, *count = 0; for (i = 0; i < dcpep_num_methods; i++) { + /* Only a firmware sleep sends unnamed_500, and it checks the build's table. */ if (!dcp_methods_27_0[i].tag[0] || methods[i].tag[0] || - i == dcpep_dfb_ready_query) + i == dcpep_dfb_ready_query || i == dcpep_unnamed_500) continue; if (!first) first = dcp_methods_27_0[i].name; @@ -323,6 +330,8 @@ const char *iomfb_v27_missing_method(const struct dcp_method_entry *methods, #define iomfb_shutdown_h17p iomfb_shutdown_v27 #define iomfb_present_backlight_h17p iomfb_present_backlight_v27 #define iomfb_present_matrix_h17p iomfb_present_matrix_v27 +#define iomfb_s2r_500_h17p iomfb_s2r_500_v27 +#define iomfb_s2r_power_h17p iomfb_s2r_power_v27 #define DCP_FW h17p #define DCP_FW_VER DCP_FW_VERSION(27, 0, 0) @@ -357,6 +366,21 @@ static bool trampoline_get_frequency_v27(struct apple_dcp *dcp, int tag, return true; } +/* + * D572, as on H17P: the firmware powers the display DART's streams with it, 0 when it's done + * with the display. Only a sleep's stop acts on it (dcp_s2r_dart_power()). + */ +static bool trampoline_dart_power_v27(struct apple_dcp *dcp, int tag, + void *out, void *in) +{ + const struct dcp_packet_header *header = in - sizeof(*header); + + if (header->in_len >= sizeof(u32)) + dcp_s2r_dart_power(dcp, get_unaligned_le32(in)); + + return trampoline_zero(dcp, tag, out, in); +} + static bool trampoline_hotplug_h17p(struct apple_dcp *dcp, int tag, void *out, void *in) { @@ -669,7 +693,7 @@ static const iomfb_cb_handler cb_handlers[IOMFB_MAX_CB] = { [565] = trampoline_true, [567] = trampoline_true, [569] = trampoline_set_boolean_property_v27, - [572] = trampoline_zero, + [572] = trampoline_dart_power_v27, /* powerUpDART */ [574] = iomfbep_cb_video_range_h17p, [575] = trampoline_hotplug_h17p, [576] = trampoline_nop, diff --git a/drivers/gpu/drm/apple/iomfb_v27.h b/drivers/gpu/drm/apple/iomfb_v27.h index 915de53c68bf5..d6978e36a49d3 100644 --- a/drivers/gpu/drm/apple/iomfb_v27.h +++ b/drivers/gpu/drm/apple/iomfb_v27.h @@ -145,5 +145,7 @@ void iomfb_poweroff_v27(struct apple_dcp *dcp); void iomfb_sleep_v27(struct apple_dcp *dcp); void iomfb_present_backlight_v27(struct apple_dcp *dcp); void iomfb_present_matrix_v27(struct apple_dcp *dcp); +int iomfb_s2r_500_v27(struct apple_dcp *dcp); +int iomfb_s2r_power_v27(struct apple_dcp *dcp, bool on, bool named_calls, bool oob); #endif From 479a29eb974897c1e490161641df0480c4da22fe Mon Sep 17 00:00:00 2001 From: Kyle Arrington Date: Sat, 14 Nov 2026 15:18:00 -0600 Subject: [PATCH 4/5] arm64: dts: apple: t8142-j813: describe the display power words The power gate and power state words a DCP firmware stop writes, and the DCP DART's PS write-disable bit that protects DISP_CPU's power word (ADT dart-dcp clock-protection-wr-dis-id 0x1f: pmgr reg[1] + 0x3fdc, bit 6). Assisted-by: Claude Fable 5.2 Signed-off-by: Kyle Arrington --- .../boot/dts/apple/t8142-j813-display.dtsi | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8142-j813-display.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-display.dtsi index d7bd35ad68a00..31d2a2589cefa 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813-display.dtsi +++ b/arch/arm64/boot/dts/apple/t8142-j813-display.dtsi @@ -50,6 +50,20 @@ #mbox-cells = <0>; }; + /* + * The internal display's power words for a DCP firmware stop (DPMS off): + * /arm-io/pmgr reg[34] (pwrgate: DISP_CPU's retention words 0x11cc and + * 0x11f0, the pmgr's retention_config_ff/_mem) and reg[32] (ps: DISP_CPU + * 0x10000, DISP_FE 0x318, DISP_SYS 0x290). T8142's PMC keeps no count of + * powered DCPs, so there is no pmc-dcp word. + */ + dcp_power: display-power@380724000 { + compatible = "apple,t8142-display-power"; + reg = <3 0x80724000 0 0x2000>, + <3 0x80700000 0 0x14000>; + reg-names = "pwrgate", "ps"; + }; + dcp: dcp@286e00000 { compatible = "apple,t8142-dcp", "apple,dcp"; mboxes = <&dcp_mbox>; @@ -66,6 +80,7 @@ <2 0x86850000 0 0x4000>; apple,bw-scratch = <&pmgr_dcp 0 5 0>; apple,bw-doorbell = <&pmgr_dcp 1 6>; + apple,display-power = <&dcp_power>; /* Scan out the primary plane on IOMFB surface 2. */ apple,iomfb-surfaces = <0 0 1 0>; /* @@ -108,7 +123,19 @@ apple,dma-range = <0x100 0x0 0x10 0x0>; }; +/* + * ps-wr-dis: the DCP DART's PS write-disable bit, which T8142 has instead + * of T8140's GAPF slice. ADT dart-dcp clock-protection-wr-dis-id + * <0x1f 0xff>, /chosen/dart-ps-wr-dis-entries[0x1f] = offset 0x3fdc in + * /arm-io/pmgr reg[1] (0x380714000), bit 6. Set, the fabric rejects writes + * to DISP_CPU's power word; the DART driver clears it while the DCP is + * stopped. + */ &dcp_dart { + reg = <2 0x86340000 0 0x20000>, + <3 0x80717fdc 0 0x4>; + reg-names = "dart", "ps-wr-dis"; + apple,ps-wr-dis-bit = <6>; apple,dma-range = <0x100 0x0 0x10 0x0>; status = "okay"; }; From 58d40fd0a9db567e5403ead01ab0a2668a7884df Mon Sep 17 00:00:00 2001 From: Kyle Arrington Date: Sun, 15 Nov 2026 08:40:12 -0600 Subject: [PATCH 5/5] selftests: apple-dcp: resource-profile: declare the firmware-stop layout The T8140 profile now names its firmware-stop layout. Give the unit's copy of apple_dcp_hw_data the pointer and an opaque layout so the extracted profiles compile; the unit does not read it. Assisted-by: Claude Fable 5.2 Signed-off-by: Kyle Arrington --- tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py index 709b01ec2fb32..34a09db787739 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py @@ -1221,12 +1221,16 @@ def block(marker): struct device { struct device_node *of_node; }; struct platform_device { struct device dev; int num_resources; struct resource resources[10]; }; #define to_platform_device(d) ((struct platform_device *)(d)) +/* The profiles name their firmware-stop layout; this unit does not read it. */ +struct dcp_s2r_layout { int unused; }; +static const struct dcp_s2r_layout dcp_s2r_t8140; struct apple_dcp_hw_data { unsigned num_dptx_ports; bool adopt_live_session; int iomfb_method_profile,firmware_compat; const struct resource *firmware_clock; u32 firmware_display_windows,firmware_scratch,firmware_request; bool s2r,s2r_ext; + const struct dcp_s2r_layout *s2r_layout; }; struct apple_dcp { struct device *dev; struct apple_dcp_hw_data hw;