From 8bdb9a5e18b0307b6eb5a89937475ffd76a5482d Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 12 Nov 2026 08:27:12 +0700 Subject: [PATCH 01/68] irqchip/apple-aic: T8142's AIC3 loses its configuration in a deep sleep As on T8132: the SoC's power goes in a suspend-to-RAM, so the AIC needs the firmware-suspend save and restore. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- drivers/irqchip/irq-apple-aic.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c index 109676491214f..4d1f4b608d7dd 100644 --- a/drivers/irqchip/irq-apple-aic.c +++ b/drivers/irqchip/irq-apple-aic.c @@ -371,6 +371,8 @@ static const struct aic_info aic3_t8142_info __initconst = { .fast_ipi = true, .local_fast_ipi = true, .vm_timer_fiq_readonly = true, + /* AIC3 as on T8132: its configuration is lost with the SoC's power in a deep sleep. */ + .fw_suspend = true, }; static const struct of_device_id aic_info_match[] = { From 41b8d32be1431c87c5de653b9799173630ea3ae5 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 12 Nov 2026 08:27:12 +0700 Subject: [PATCH 02/68] pmdomain: apple: pmc: cast the AP's DCS vote again after a deep sleep The sleep commit zeroes the AP agent's whole voter word (T8132, and now T8142), which holds its DCS vote as well as its floors. resume_early only put the floors back. Cast the DCS vote again too; it's a no-op if the word survived. Only after a real commit (pm_resume_via_firmware()). Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- drivers/pmdomain/apple/pmc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/pmdomain/apple/pmc.c b/drivers/pmdomain/apple/pmc.c index 586e3f675db9e..e93dc40bc10c1 100644 --- a/drivers/pmdomain/apple/pmc.c +++ b/drivers/pmdomain/apple/pmc.c @@ -1553,6 +1553,12 @@ static int apple_pmc_resume_early(struct device *dev) ret = ret ?: err; } } + /* + * The AP agent's word also holds its DCS vote, which a deep sleep's commit zeroes + * (apple-sleep, T8132 and T8142). Cast it again: a no-op if it stayed. + */ + if (!(pmc->floor_rails & BIT(pmc->hw->dcs_rail))) + apple_pmc_dcs_vote(pmc); raw_spin_unlock_irqrestore(&pmc->lock, flags); if (ret) dev_err(dev, "state not restored after sleep: %d\n", ret); From 51da40cd103ce7ba949404dc99da8f510f42b777 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 12 Nov 2026 08:27:12 +0700 Subject: [PATCH 03/68] iommu: apple-dart: read a GAPF slice at its first use The slice's boot value was read at probe. A derived slice address (T8142) would then be touched on every boot. Read it before the first write instead, which only a sleep does, and protect it again only once it has been read. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- drivers/iommu/apple-dart.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index b97b0c3378e45..95dea003889db 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -361,7 +361,10 @@ 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 the boot left it, read before the first write (U32_MAX until + * then); a deep sleep resets it to 0 + */ u32 gapf_boot; bool sleep_flushed; /* The firmware 27 display sleep owns it: never replay locked trees. */ @@ -5537,7 +5540,8 @@ static int apple_dart_probe(struct platform_device *pdev) dart->gapf = devm_platform_ioremap_resource_byname(pdev, "gapf"); if (IS_ERR(dart->gapf)) return PTR_ERR(dart->gapf); - dart->gapf_boot = readl(dart->gapf); + /* Read at its first use, a sleep's: a boot without one never touches it. */ + dart->gapf_boot = U32_MAX; } /* T8132's ISP DART names its DAPF page but has no ranges to restore. */ if (platform_get_resource_byname(pdev, IORESOURCE_MEM, "dapf") && @@ -7483,6 +7487,17 @@ int apple_dart_dcp_dispext_state(struct device_node *consumer) EXPORT_SYMBOL_GPL(apple_dart_dcp_dispext_state); #endif +/* The slice as the boot left it is the first value read, before any write. */ +static u32 apple_dart_gapf_read(struct apple_dart *dart) +{ + u32 val = readl(dart->gapf); + + if (dart->gapf_boot == U32_MAX) + dart->gapf_boot = val; + + return val; +} + /* * 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. @@ -7494,7 +7509,7 @@ static int apple_dart_gapf_release(struct apple_dart *dart) if (!dart->gapf) return 0; - val = readl(dart->gapf); + val = apple_dart_gapf_read(dart); 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); @@ -7510,7 +7525,7 @@ static void apple_dart_gapf_protect(struct apple_dart *dart) { u32 val; - if (!dart->gapf || !dart->sleep_flushed) + if (!dart->gapf || !dart->sleep_flushed || dart->gapf_boot == U32_MAX) return; val = readl(dart->gapf); @@ -7523,7 +7538,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 || !(apple_dart_gapf_read(dart) & APPLE_DART_GAPF_PROTECT)) return 0; return apple_dart_gapf_release(dart); From a37064853effc4d95c2bd6befea332fdc158d8b0 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 12 Nov 2026 08:27:13 +0700 Subject: [PATCH 04/68] nvme: apple: T8142 sleep values, behind nvme_apple.sleep_untested T8142 gets T8140's firmware-stop values, as T8132 runs them, untraced. Without nvme_apple.sleep_untested=1 ANS isn't registered with the sleep controller, so a dry run never idles the root disk. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- drivers/nvme/host/apple.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index af32c89ff07be..d743916e99398 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -221,6 +221,8 @@ struct apple_nvme_hw { bool cold_reset; /* Firmware-driven suspend has been traced on this controller. */ bool sleep_traced; + /* ... or derived and never run: only with nvme_apple.sleep_untested */ + bool sleep_untested; /* The last endpoint map reply from that trace */ u32 sleep_epmap_last_mask; /* Higher namespaces are the firmware's, and a Flush to one faults the controller. */ @@ -356,6 +358,15 @@ module_param(flush_interval, uint, 0644); MODULE_PARM_DESC(flush_interval, "Grace period in msecs between flushes (ignored on post-M4 ANS)"); +/* + * Stop ANS for a deep sleep on a controller whose sleep path was never run (T8142). Off by + * default: the root disk stays up through a sleep the SoC refuses. + */ +static bool sleep_untested; +module_param(sleep_untested, bool, 0444); +MODULE_PARM_DESC(sleep_untested, + "Stop ANS for a deep sleep where that path is untested (default 0)"); + static_assert(sizeof(struct nvme_command) == 64); static_assert(sizeof(struct apple_nvmmu_tcb) == 128); @@ -2844,7 +2855,9 @@ static int apple_nvme_probe(struct platform_device *pdev) INIT_DELAYED_WORK(&anv->flush_dwork, apple_nvme_flush_work); - if (anv->hw->sleep_traced) { + if (anv->hw->sleep_traced && (!anv->hw->sleep_untested || sleep_untested)) { + if (anv->hw->sleep_untested) + dev_warn(anv->dev, "firmware stop for sleep enabled, untested on this SoC\n"); anv->sleep_registered = !apple_sleep_coproc_register(anv->dev, anv->mmio_coproc, true, apple_nvme_sleep_last_stop, anv); @@ -3295,6 +3308,12 @@ static const struct apple_nvme_hw apple_nvme_t8142_hw = { .has_separate_nvmmu = true, .needs_ioq_registers = true, .max_queue_depth = 64, + /* T8140's values, as T8132 runs them: never run on T8142. */ + .sleep_traced = true, + .sleep_untested = true, + .sleep_epmap_last_mask = BIT(0), + .sleep_flush_max_nsid = 1, + .sleep_shn = NVME_CC_SHN_MASK, .quirks = NVME_QUIRK_BROKEN_FUA, }; From 9b9377c128865745fcb25d1113d24e593955755e Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 12 Nov 2026 09:02:37 +0700 Subject: [PATCH 05/68] soc: apple: mcc: turn T8142's ways off for a deep sleep AppleT8142MCC (macOS 27.2.1) runs mccEnableCacheMode(0) as its platform sleep action. J815 has no skip-mcc-off-to-s2r; only T8140's J700 does. For each plane it writes way count 0 to 0x2800 (plane stride 0x40000), waits for the data ways (0x2804 [30:24]) and then the tag ways ([14:8]) to reach it, and writes 0x82c = 0. Its platform active action runs mode 1, which puts the way count back the same way. aura's cold-boot enable does that too, with 16 ways. The kext's cacheFlush (0x82c = 1, 0x2844 = 1, poll 0x2844 bit 0 per plane) is the sequence the T8140 path already uses at suspend_noirq. Keep it as the write-back, and then turn the ways off as macOS does before S2R. A timeout there loses nothing, since the flush already wrote everything back. At resume_noirq, if the boot's way count (read at probe) is not what plane 0 reads, put it back and wait for both counts before allocation is enabled again. Without this, the cache would stay off after a real wake. T8132's measured lane/AMCC step in the sleep driver has no counterpart in this kext. Its 0x220400580/0x220800580 blocks are outside J815's MCC window (0x220000000 + 0x140000), so T8142 leaves it out. Derived from the binaries, never run on an M5. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- drivers/soc/apple/mcc.c | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/soc/apple/mcc.c b/drivers/soc/apple/mcc.c index a13f8b85eb4eb..ae15c4ea54e1b 100644 --- a/drivers/soc/apple/mcc.c +++ b/drivers/soc/apple/mcc.c @@ -29,6 +29,7 @@ #define MCC_CACHE_WAYS_ENABLED GENMASK(4, 0) #define MCC_CACHE_POWER 0x2804 #define MCC_CACHE_WAYS_POWERED GENMASK(30, 24) +#define MCC_CACHE_TAGS_POWERED GENMASK(14, 8) #define MCC_CACHE_FLUSH 0x2844 #define MCC_CACHE_FLUSH_BUSY BIT(0) @@ -41,6 +42,12 @@ struct apple_mcc { unsigned int nr_planes; bool enabled; bool retained; + /* + * T8142: a deep sleep also turns the cache's ways off, as AppleT8142MCC's sleep action + * does, and the wake puts the boot's way count back. + */ + bool ways_off; + u32 ways; /* Turned off for a deep sleep, to be turned back on after it. */ bool sleep_disabled; }; @@ -183,6 +190,34 @@ static void apple_mcc_disable_planes(struct apple_mcc *mcc, unsigned int count) dev_err(mcc->dev, "plane %u flush timed out\n", i); } +/* + * AppleT8142MCC's mccEnableCacheMode and aura's cold-boot enable: every plane's way count, + * then each plane's data and tag ways (0x2804 [30:24] and [14:8]) waited for until both + * read it. macOS waits without a limit. + */ +static int apple_mcc_set_ways(struct apple_mcc *mcc, u32 ways) +{ + unsigned int i; + u32 val; + int ret; + + for (i = 0; i < mcc->nr_planes; i++) + apple_mcc_writel(mcc, i, ways, MCC_CACHE_WAYS); + + for (i = 0; i < mcc->nr_planes; i++) { + ret = readl_poll_timeout_atomic(mcc->planes[i] + MCC_CACHE_POWER, val, + FIELD_GET(MCC_CACHE_WAYS_POWERED, val) == ways && + FIELD_GET(MCC_CACHE_TAGS_POWERED, val) == ways, + 10, MCC_FLUSH_TIMEOUT_US); + if (ret) { + dev_err(mcc->dev, "plane %u ways did not reach %u: %#x\n", i, ways, val); + return ret; + } + } + + return 0; +} + static int apple_mcc_enable(struct apple_mcc *mcc) { unsigned int i; @@ -229,6 +264,7 @@ static int apple_mcc_probe(struct platform_device *pdev) mcc->dev = dev; mcc->retained = of_device_is_compatible(dev->of_node, "apple,t8132-mcc"); + mcc->ways_off = of_device_is_compatible(dev->of_node, "apple,t8142-mcc"); while (platform_get_resource(pdev, IORESOURCE_MEM, mcc->nr_planes)) { struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, mcc->nr_planes); @@ -258,6 +294,9 @@ static int apple_mcc_probe(struct platform_device *pdev) return ret; mcc->enabled = true; + if (mcc->ways_off) + mcc->ways = FIELD_GET(MCC_CACHE_WAYS_ENABLED, + readl(mcc->planes[0] + MCC_CACHE_WAYS)); dev_info(dev, "system level cache allocation enabled on %u planes\n", mcc->nr_planes); return 0; } @@ -306,6 +345,14 @@ static int apple_mcc_suspend_noirq(struct device *dev) if (!mcc->enabled) return 0; apple_mcc_quiesce(mcc); + /* + * T8142 has no skip-mcc-off-to-s2r (only T8140's J700 does), so macOS turns the ways + * off before the sleep: way count 0. The flush above (the kext's own cacheFlush) has + * written everything back already, so a timeout here loses nothing and only leaves + * the ways as they were. + */ + if (mcc->ways_off && mcc->ways) + apple_mcc_set_ways(mcc, 0); mcc->sleep_disabled = true; return 0; @@ -319,6 +366,10 @@ static int apple_mcc_resume_noirq(struct device *dev) if (!mcc->sleep_disabled) return 0; mcc->sleep_disabled = false; + /* The way count the boot set, back (it reads 0 after the power loss, or after the above). */ + if (mcc->ways_off && mcc->ways && + FIELD_GET(MCC_CACHE_WAYS_ENABLED, readl(mcc->planes[0] + MCC_CACHE_WAYS)) != mcc->ways) + apple_mcc_set_ways(mcc, mcc->ways); /* Only a performance setting: a cache not ready after the wake stays off. */ ret = mcc->retained ? apple_mcc_enable_t8132(mcc) : apple_mcc_enable(mcc); mcc->enabled = !ret; @@ -335,6 +386,7 @@ static const struct dev_pm_ops apple_mcc_pm_ops = { static const struct of_device_id apple_mcc_of_match[] = { { .compatible = "apple,t8132-mcc" }, { .compatible = "apple,t8140-mcc" }, + { .compatible = "apple,t8142-mcc" }, {} }; MODULE_DEVICE_TABLE(of, apple_mcc_of_match); From 77ed313d6c3c8a2b0b03fc0736096dc32eccc5ee Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 14 Nov 2026 14:35:41 +0700 Subject: [PATCH 06/68] arm64: spin table: the holding pen's deep-sleep WFI after an Apple sleep's commit A core that the SoC restarts at its reset vector after a system sleep's commit comes back through the boot object into secondary_holding_pen and spins there on WFE. Its cluster can't power down with it running, and the SoC's sleep sequencer waits on that with no timeout. Once a sleep has committed, have such a core take the Apple deep-sleep bits and WFI in the pen instead, as macOS's parked cores do. The flag is read with the MMU off, set at spin_table_release_stopped() only where the sleep driver armed it, and cleared before any CPU is started again after the wake. T8142 arms it. From aurora-silicon/linux#1773 (T6050), where the cores a cluster round restarted had to take this WFI before the first engine sequence completed. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- arch/arm64/include/asm/cpu_ops.h | 2 ++ arch/arm64/kernel/head.S | 15 +++++++++++++++ arch/arm64/kernel/smp_spin_table.c | 27 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/arch/arm64/include/asm/cpu_ops.h b/arch/arm64/include/asm/cpu_ops.h index 765f7754cebc5..c42daea9d5263 100644 --- a/arch/arm64/include/asm/cpu_ops.h +++ b/arch/arm64/include/asm/cpu_ops.h @@ -74,6 +74,7 @@ int spin_table_hold_parked(void); void spin_table_unhold_parked(void); int spin_table_stop_parked(void); void spin_table_release_stopped(void); +void spin_table_pen_deep_arm(bool on); void spin_table_stop_finished(void); bool spin_table_cpus_stuck(void); #else @@ -90,6 +91,7 @@ static inline int spin_table_stop_parked(void) } static inline void spin_table_release_stopped(void) {} +static inline void spin_table_pen_deep_arm(bool on) {} static inline void spin_table_stop_finished(void) {} static inline int spin_table_set_power_ops(const struct spin_table_power_ops *ops) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index a596a8d347183..fdb2a852e67df 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -408,11 +408,26 @@ SYM_FUNC_START(secondary_holding_pen) mov_q x1, MPIDR_HWID_BITMASK and x2, x2, x1 adr_l x3, secondary_holding_pen_release + adr_l x6, secondary_pen_deep pen: ldr x4, [x3] cmp x4, x2 b.eq secondary_startup + ldr x5, [x6] + cbnz x5, 1f wfe b pen + /* + * Restarted after a system sleep's commit: the Apple deep-sleep bits, then WFI, as + * macOS's parked cores do. A core spinning here would keep its cluster from powering down. + */ +1: mrs_s x4, sys_reg(3, 5, 15, 6, 2) + orr x4, x4, #1 + orr x4, x4, #0x8000000000000000 + msr_s sys_reg(3, 5, 15, 6, 2), x4 +2: dsb sy + isb + wfi + b 2b SYM_FUNC_END(secondary_holding_pen) /* diff --git a/arch/arm64/kernel/smp_spin_table.c b/arch/arm64/kernel/smp_spin_table.c index a2a08f4e2c1e9..76acaf51c416e 100644 --- a/arch/arm64/kernel/smp_spin_table.c +++ b/arch/arm64/kernel/smp_spin_table.c @@ -24,6 +24,13 @@ extern void secondary_holding_pen(void); volatile unsigned long __section(".mmuoff.data.read") secondary_holding_pen_release = INVALID_HWID; +/* + * Once set, after a sleep's commit, a core that the SoC restarts at its reset vector and that + * comes back to the holding pen takes the deep-sleep WFI there instead of spinning (head.S), + * as macOS's parked cores do. Read with the MMU off. + */ +volatile unsigned long __section(".mmuoff.data.read") secondary_pen_deep; + static phys_addr_t cpu_release_addr[NR_CPUS]; /* @@ -265,10 +272,27 @@ int spin_table_stop_parked(void) return -ETIMEDOUT; } +static bool spin_table_pen_deep_armed; + +void spin_table_pen_deep_arm(bool on) +{ + spin_table_pen_deep_armed = on; +} + +static void spin_table_pen_deep_set(unsigned long on) +{ + void *start = (void *)&secondary_pen_deep; + + secondary_pen_deep = on; + dcache_clean_inval_poc((unsigned long)start, (unsigned long)start + sizeof(secondary_pen_deep)); +} + /* After the commit: the stopped CPUs take their last WFI. */ void spin_table_release_stopped(void) { WRITE_ONCE(spin_table_stop_released, true); + if (spin_table_pen_deep_armed) + spin_table_pen_deep_set(1); dsb(ish); sev(); } @@ -279,6 +303,9 @@ void spin_table_release_stopped(void) */ void spin_table_stop_finished(void) { + /* Before any CPU is started again: the pen must let them boot. */ + if (secondary_pen_deep) + spin_table_pen_deep_set(0); WRITE_ONCE(spin_table_hold_requested, false); WRITE_ONCE(spin_table_stop_requested, false); WRITE_ONCE(spin_table_stop_released, false); From 446bb9927fe2faeca7112440e628dade739d5d9d Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 16 Nov 2026 08:14:37 +0700 Subject: [PATCH 07/68] spmi: apple: recover a failed generation 4 exchange on the M5 Airs too #1963 drains a generation 4 controller's late reply after a failed exchange, on the J714s only. The J813 and J815 (MacBook Air, M5) have the same generation 4 nub-spmi controllers, and their deep sleep writes the PMU on the same queue, so a stray reply there would refuse every later command in the sleep. Take the J714s's recovery on both. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- drivers/spmi/spmi-apple-controller.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index 23bdf68e924e3..c78d6e29e8f24 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -235,14 +235,23 @@ static int apple_spmi_wait_rx_not_empty(struct spmi_controller *ctrl) * late, or the stray one that was read in a reply's place, is read out instead: the bus gets a * command's whole timeout to finish, then the reply FIFO is read until it is empty. Nothing of * an old exchange can then answer a new command. A FIFO that does not empty keeps the failure. - * On the J714s only, the board this is for; on every other generation 4 machine a failed - * exchange refuses the later commands, as before. + * On the J714s, the board this is for, and on the M5 MacBook Airs (J813, J815), whose + * nub-spmi controllers are the same generation 4 and whose deep sleep writes the PMU on the + * same queue; on every other generation 4 machine a failed exchange refuses the later + * commands, as before. */ +static bool apple_spmi_gen4_recovers(void) +{ + return of_machine_is_compatible("apple,j714s") || + of_machine_is_compatible("apple,j813") || + of_machine_is_compatible("apple,j815"); +} + static int apple_spmi_gen4_recover(struct spmi_controller *ctrl, struct apple_spmi *spmi) { unsigned int i; - if (!of_machine_is_compatible("apple,j714s")) + if (!apple_spmi_gen4_recovers()) return -EIO; usleep_range(REG_POLL_TIMEOUT_US, 2 * REG_POLL_TIMEOUT_US); for (i = 0; i < SPMI_GEN4_REPLY_DRAIN_MAX; i++) { From f2bdd2e91ac417cf10bcbafad54edb1f36c25d68 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 16 Nov 2026 08:14:38 +0700 Subject: [PATCH 08/68] usb: typec: tipd: the sleep's SSPS rules on the M5 Airs too macOS 27.2.1's sleep entry on the J815 sends the system power state command (SSPS, S3) to both port controllers over nub-spmi-a0, as on the J714s (26B131 trace: usid 10 and 8; the third port is the debug link). The J813 and J815 SN201202x controllers sit on the same generation 4 SPMI, and their sleep node asks for the command (apple,sleep-ssps), so apply the J714s's rules there as well. Only a firmware-driven sleep sends it. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- drivers/usb/typec/tipd/core.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 9298672c02aa0..d42ced2608c6b 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -353,12 +353,17 @@ static int tps6598x_disconnect(struct tps6598x *tps, u32 status) /* * The sleep's rules for the port controllers' system power state command (the controller is * woken first, the command's end is read at intervals, a failed S3 refuses the sleep, the - * command's limit and its lines) are in force on the board they have run on, the J714s. - * Elsewhere, other boards with the same SoC included, the command is as it was. + * command's limit and its lines) are in force on the board they have run on, the J714s, and on + * the M5 MacBook Airs (J813, J815), whose SN201202x controllers sit on the same generation 4 + * SPMI and whose sleep, like the J714s's, asks for the command (apple,sleep-ssps). Elsewhere, + * other boards with the same SoCs included, the command is as it was. Only a firmware-driven + * sleep sends it. */ static bool tipd_sleep_ssps_rules(void) { - return of_machine_is_compatible("apple,j714s"); + return of_machine_is_compatible("apple,j714s") || + of_machine_is_compatible("apple,j813") || + of_machine_is_compatible("apple,j815"); } /* From d54cebafbcd75f8c795e769f3c61dfcff8acc90d Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 16 Nov 2026 08:41:43 +0700 Subject: [PATCH 09/68] soc: apple: sleep: T8142 (M5 Air), from macOS's own sleep, dry-run gated Add T8142 (J813, J815) to the sleep driver as its own apple_sleep_ops and match data, on #1963's coprocessor stops. The steps follow macOS 27.2.1 (26B131) as two traces of its sleep entry under aura's virtualized SPTM show them: a J815 one (two cores, the whole entry to the S2R timer) and gig3m's J813 one (ten cores, the memory controller hooked). Where both hooked a block, they agree write for write. - lower_io: the RAM clean, ATC0 with T8142's words, the radio's port stopped, then ANS's PCIe block in AppleT8142PCIe's order (APCIECoreRCGen4: PHY_SW before SYS_ST, the AUS5 pair inside an UP-bit window, the PLLs, the AXI enables, the gate loop). - last_mile: AppleT8142PMGR::quiescePerfState (SoC to 3, DCS to 3 through 5), the CPM gates around the AP's PMC vote, the complexes off, the quiesce read, then the memory side as the J813 trace has it, 4.6 to 2.7 ms before the S2R timer: each AMCC plane's +0x28000 word cleared two bits at a time, the six SoC NI tables zeroed, the eight DCS channels' enables stepped down and their lanes strobed, the clock word 0x380038000 <- 0x30000, and the CLLT "sleep hack" (EARLY_WAKEUP_CFG bits 17:16) right before the timer. - SPTM's per-DART PS write-disable bits (/chosen/dart-ps-wr-dis-entries): while one is set, the PMGR drops writes to that DART's power word. The four macOS's SPTM clears during its entry (SEP, centauri, PMP, SIO DMA; the DCP's stays with the DART driver) are cleared, only where set, and reported after the wake. The watchdog's page 2 (+0x2c |= 0x20) before WD2, restored at the wake. - wake: restoreHW, each complex on with its bit-4 wait, pwrgate +0x0/+0x60, the words back, ATC0, SEP, the CPM gates, WD2, ANS's block, and the radio's link trained again as aura trains it at boot. - resume and pre_commit: T8132's (WD2 is at the same address). Generic parts it needs, each a no-op on the other SoCs: - SPMI generation 4's queue on the sleep's bus (status +0x200, FIFOs +0x210/+0x220, notification enable/ack +0x420/+0x620), with bounded drains around a PMU write. - Register blocks a SoC doesn't have: T8142 has no pmc-dcp, clock muxes, PTD, cluster DCS or DVFM blocks. - An untested SoC: deep sleep only with apple_sleep.deep=1, never the default; each sleep a dry run that refuses after every check unless apple_sleep.untested_commit=1; each step noted in PMU scratch (0x8308) for the boot after a reset (apple_sleep_note_sub() for a coprocessor's own steps). - A radio link with no restore (apple,radio-host without trainable port data) refuses a real sleep while its host is bound. The complexes' ACC word 0x40f8, which restoreHW writes, is only written with apple_sleep.acc_wake=1: every Linux access to it has hung a J815 so far. The SoC data test accepts a matched SoC that is untested but gated, and checks the SoC NI and PS write-disable tables. Derived from the binaries, the traces and T8132's measurements; no M5 has gone through a full sleep and wake with it yet. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- drivers/soc/apple/sleep-test.c | 42 +- drivers/soc/apple/sleep.c | 1806 +++++++++++++++++++++++++++++-- include/linux/soc/apple/sleep.h | 8 + 3 files changed, 1782 insertions(+), 74 deletions(-) diff --git a/drivers/soc/apple/sleep-test.c b/drivers/soc/apple/sleep-test.c index bd95d7cc50a7c..9b272bd8b7826 100644 --- a/drivers/soc/apple/sleep-test.c +++ b/drivers/soc/apple/sleep-test.c @@ -5,7 +5,10 @@ */ #include -/* Matched only once its sleep has been tested on hardware. */ +/* + * Matched only once its sleep has been tested on hardware, or with .untested set: then each + * sleep stops before the commit unless apple_sleep.untested_commit=1 (T8142). + */ static const char *const apple_sleep_test_tested[] = { "apple,t8140-sleep", "apple,t8132-sleep", @@ -53,10 +56,17 @@ static void apple_sleep_test_only_tested(struct kunit *test) const struct of_device_id *id; int n = 0; - for (id = apple_sleep_of_match; id->compatible[0]; id++, n++) { - KUNIT_EXPECT_NOT_NULL_MSG(test, id->data, "%s has no data", id->compatible); - KUNIT_ASSERT_LT(test, n, ARRAY_SIZE(apple_sleep_test_tested)); - KUNIT_EXPECT_STREQ(test, id->compatible, apple_sleep_test_tested[n]); + for (id = apple_sleep_of_match; id->compatible[0]; id++) { + const struct apple_sleep_soc *soc = id->data; + bool tested = false; + int i; + + KUNIT_ASSERT_NOT_NULL_MSG(test, soc, "%s has no data", id->compatible); + for (i = 0; i < ARRAY_SIZE(apple_sleep_test_tested); i++) + tested |= !strcmp(id->compatible, apple_sleep_test_tested[i]); + KUNIT_EXPECT_TRUE_MSG(test, tested || soc->untested, + "%s is matched, neither tested nor gated", id->compatible); + n += tested; } KUNIT_EXPECT_EQ(test, n, ARRAY_SIZE(apple_sleep_test_tested)); } @@ -83,9 +93,13 @@ static void apple_sleep_test_words(struct kunit *test) continue; apple_sleep_test_full(test, c, "ps_all", all); apple_sleep_test_full(test, c, "ps_aon_all", aon); + /* 0: a word the SoC doesn't name (a second display, T8142's USB words). */ for (i = 0; i < ARRAY_SIZE(named); i++) - apple_sleep_test_in(test, c, "named", all, named[i]); - apple_sleep_test_in(test, c, "debug switch", aon, soc->ps_aon_debug_switch); + if (named[i]) + apple_sleep_test_in(test, c, "named", all, named[i]); + /* An untested SoC only reads its debug switch, outside the lists. */ + if (!soc->untested) + apple_sleep_test_in(test, c, "debug switch", aon, soc->ps_aon_debug_switch); apple_sleep_test_list_in(test, c, "ps_macos_on", all, &soc->ps_macos_on); apple_sleep_test_list_in(test, c, "ps_macos_off", all, &soc->ps_macos_off); apple_sleep_test_list_in(test, c, "ps_wake_order", all, &soc->ps_wake_order); @@ -184,7 +198,6 @@ static void apple_sleep_test_layout(struct kunit *test) for (id = apple_sleep_of_match; id->compatible[0]; id++) { const struct apple_sleep_soc *soc = id->data; - /* Region-based profiles keep their words in their own tables */ if (soc->regions) continue; KUNIT_EXPECT_GE(test, soc->ncluster_cpu, 1); @@ -192,13 +205,26 @@ static void apple_sleep_test_layout(struct kunit *test) KUNIT_EXPECT_GT(test, soc->cpu_start_stride, 0); KUNIT_EXPECT_LE(test, soc->nclk_mux_parked, SLEEP_CLK_MUX_MAX); KUNIT_EXPECT_LE(test, soc->ncllt, SLEEP_CLLT_MAX); + /* Every SoC steps its memory controller down (T8142: from the J813 trace). */ KUNIT_EXPECT_GE(test, soc->nmcc, 1); KUNIT_EXPECT_LE(test, soc->nmcc, MCC_CHANNELS); KUNIT_EXPECT_LE(test, soc->namcc, SLEEP_AMCC_MAX); + /* Each SoC NI table is mapped 0x80 bytes long (the T8142 sleep node). */ + KUNIT_EXPECT_LE(test, soc->nsocni, SLEEP_SOCNI_MAX); + KUNIT_EXPECT_EQ(test, !!soc->socni_words, !!soc->nsocni); + for (int j = 0; j < soc->nsocni; j++) + KUNIT_EXPECT_LE(test, soc->socni_words[j] * 4, 0x80); KUNIT_EXPECT_GE(test, soc->wake_words, 1); KUNIT_EXPECT_LE(test, soc->wake_words, WAKE_WORDS); KUNIT_EXPECT_GE(test, soc->wake_status, soc->wake_mask + soc->wake_words * 4); KUNIT_EXPECT_LT(test, soc->pmu_usid, 16); + /* PS write-disable words: in "ps" (0x18000 on T8142), aligned, one bit each */ + KUNIT_EXPECT_LE(test, soc->nps_wr_dis, SLEEP_PS_WR_DIS_MAX); + for (int i = 0; i < soc->nps_wr_dis; i++) { + KUNIT_EXPECT_EQ(test, soc->ps_wr_dis[i].offset % 4, 0); + KUNIT_EXPECT_LT(test, soc->ps_wr_dis[i].offset, 0x18000); + KUNIT_EXPECT_LT(test, soc->ps_wr_dis[i].bit, 32); + } } } diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index ebab4c4becf79..aecd5f18961fa 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -146,6 +146,12 @@ struct aura_s2r_mailbox { #define WDT_SUSPEND_SECS 120 #define AON_AP_DEADLINE 0x08 +/* + * T8142: a word of the watchdog's second page (/arm-io/wdt + 0x802c). macOS's entry + * read-modify-writes it from 0 to 0x20 right before WD0's control and WD2 (26B131 trace, + * 11.1 ms before the S2R timer); XNU writes 0x10 there during boot. Meaning unknown. + */ +#define AON_WDT_SLEEP 0x2c /* Wake sources: a mask, so 0 enables. Status words are sticky. Where and how many: the SoC. */ #define WAKE_WORDS 9 @@ -187,10 +193,50 @@ struct aura_s2r_mailbox { #define HPM_CONTRACT_MS 1500 #define HPM_RESET_TRIES 3 +/* + * T8142's controllers are SPMI gen 4 (ADT "gen" = 4 on nub-spmi0, nub-spmi-a0 and the others). + * macOS 27.2.1's AppleSPMI Gen4 class, from its init: status +0x200 (RX empty bit 30), request + * FIFO +0x210, response FIFO +0x220, IRQ enable bank +0x400 and ack bank +0x600, word 8 (the + * notification word) at +0x420/+0x620 as gen 1's at 0x40/0x80. Gen 1's offsets land on other + * registers there: +0x4 is the FIFO flush, and +0x0 never reads RX empty. + */ +#define SPMI4_STATUS 0x200 +#define SPMI4_STATUS_RX_EMPTY BIT(30) +#define SPMI4_CMD 0x210 +#define SPMI4_REPLY 0x220 +#define SPMI4_NOTIFY_ENABLE 0x420 +#define SPMI4_NOTIFY_ACK 0x620 +/* + * Gen 4: the peripheral sources' status words, below the controller's own (write 1 to + * clear). A latched source that is enabled holds the controller's interrupt output, an AP + * wake source, up (T6050, aurora-silicon/linux#1963 commit 24). + */ +#define SPMI4_SRC_STATUS 0x600 +#define SPMI4_SRC_WORDS 8 +/* A FIFO holds a few replies at most; never spin on a status that doesn't change. */ +#define SPMI_DRAIN_MAX 16 + /* A one-byte register write on the sleep's SPMI bus, to the PMU's USID */ #define SPMI_CMD_WRITE (BIT(15) | 0x30) #define SPMI_CMD_USID GENMASK(11, 8) +/* A PMU write: the reply's vector masked, then acknowledged, so none is left raised. */ +static inline void apple_sleep_pmu_write(void __iomem *spmi, u8 usid, u16 reg, u8 val) +{ + u32 status, enable; + + enable = readl(spmi + SPMI_NOTIFY_ENABLE); + writel(enable & ~SPMI_NOTIFY_REPLY, spmi + SPMI_NOTIFY_ENABLE); + writel(((u32)reg << 16) | SPMI_CMD_WRITE | FIELD_PREP(SPMI_CMD_USID, usid), + spmi + SPMI_CMD); + writel(val, spmi + SPMI_CMD); + if (!readl_poll_timeout_atomic(spmi + SPMI_STATUS, status, + !(status & SPMI_STATUS_RX_EMPTY), 1, 1000)) + readl(spmi + SPMI_REPLY); + writel(1, spmi + SPMI_NOTIFY_ACK); + writel(enable, spmi + SPMI_NOTIFY_ENABLE); +} + /* T8132's power words where they aren't T8140's */ #define T8132_PS_ATC0_COMMON 0x378 #define T8132_PS_AON_ATC0_USB_AON 0xb0 @@ -302,6 +348,18 @@ struct aura_s2r_mailbox { /* The coprocessors the last mile stops. Each driver idles its own first. */ #define SLEEP_COPROCS 16 +/* + * T8142 (APCIECoreRCGen4): the two PHY-IP words its _shutdownGen4Phy writes, and the PLL + * control word in pcieclkgen (/arm-io/apcie reg[6]), whose run, off and busy bits are the + * clock generator's above. + */ +#define APCIE_GEN4_PHY_IP_38 0x38 +#define APCIE_GEN4_PHY_IP_38_EN GENMASK(27, 26) +#define APCIE_GEN4_PHY_IP_8C 0x8c +#define APCIE_GEN4_PHY_IP_8C_OV GENMASK(27, 24) +#define APCIE_GEN4_CLK_HOLD GENMASK(4, 3) +#define APCIE_GEN4_CLK_EN BIT(0) + static struct apple_sleep_coproc { struct device *dev; void __iomem *asc; @@ -349,6 +407,7 @@ static struct { #define SLEEP_CLK_MUX_MAX 4 #define SLEEP_CLLT_MAX 4 #define SLEEP_AMCC_MAX 16 +#define SLEEP_SOCNI_MAX 8 /* cpm-dvfm */ #define DVFM_CTL 0x178 @@ -406,6 +465,20 @@ struct apple_sleep_clear { u32 clear; }; +/* + * T8142: a DART's PS write-disable bit (SPTM's /chosen/dart-ps-wr-dis-entries), as an offset + * in "ps" and a bit. While it is set the PMGR drops the AP's writes to that DART's power word, + * so a word lowered with it set stays on with BUSY latched. macOS's SPTM clears each right + * before the domain goes down; without SPTM the sleep clears them itself. + */ +struct apple_sleep_ps_wr_dis { + const char *name; + u32 offset; + u8 bit; +}; + +#define SLEEP_PS_WR_DIS_MAX 8 + /* The power words in "ps" that the sleep drives itself */ struct apple_sleep_domains { /* CPU, front end and system, of the DCP and then of the external DCP */ @@ -426,6 +499,9 @@ struct apple_sleep_domains { u32 apcie_st; u32 apcie_sys_st; u32 apcie_phy_sw; + /* T8142: the shared block's AUS5 pair, the last its gate loop powers */ + u32 apcie_aus5_aon; + u32 apcie_aus5; }; struct apple_sleep; @@ -571,6 +647,11 @@ struct apple_sleep_soc { /* In "cllt": bits cleared before the commit */ struct apple_sleep_clear cllt[SLEEP_CLLT_MAX]; unsigned int ncllt; + /* In "ps": PS write-disable bits cleared after the enclave's stop, before the others' */ + const struct apple_sleep_ps_wr_dis *ps_wr_dis; + unsigned int nps_wr_dis; + /* In "aon-misc": AON_WDT_SLEEP's bits set before WD2 is armed (0: none) */ + u32 aon_wdt_sleep; /* The PMU on the sleep's SPMI bus, and the byte it is told the AP sleeps with */ u8 pmu_usid; u16 pmu_sleep_reg; @@ -580,6 +661,9 @@ struct apple_sleep_soc { /* "mcc0".. and "amcc0"..: how many the SoC has */ unsigned int nmcc; unsigned int namcc; + /* "socni0"..: the SoC NI tables macOS zeroes before the memory goes down, in words */ + const u8 *socni_words; + unsigned int nsocni; /* In "wake": the mask and status words, and how many */ u32 wake_mask; u32 wake_status; @@ -627,6 +711,32 @@ struct apple_sleep_soc { /* The PMC whose cluster vote for the encoders needs the complex up, and its bit */ const char *ave_pmc; u32 ave_pmc_cluster; + /* What macOS reads once after its complex words; reported if still on. */ + struct apple_sleep_words quiesce; + /* Blocks the SoC doesn't have, by reg-name, NULL-terminated: left unmapped. */ + const char *const *regs_absent; + /* The sleep's SPMI bus has gen 4's queue layout (T8142). */ + bool spmi_gen4; + /* + * Derived from the binaries and another SoC's measurements, never through a full sleep and + * wake: deep sleep is offered only with apple_sleep.deep=1 and is never the default, a + * sleep stops before the commit unless apple_sleep.untested_commit=1, and each step is + * noted in PMU scratch for after a reset. + */ + bool untested; + /* + * ANS's PCIe block is T8142's (APCIECoreRCGen4): no clock generator or CIO3 PLL tables, + * and its PHY's control words this far into "phy-block" (0: APCIE_PHY_CTRL). + */ + bool apcie_gen4; + u32 apcie_phy_ctrl; + /* + * The radio's link is the loader's, under a generic ECAM host ("apple,radio-host"): it is + * stopped at the commit and trained again after the wake by this driver. + */ + bool radio_retrain; + /* A core restarted after the commit takes the deep WFI in the holding pen. */ + bool pen_deep; }; struct apple_sleep { @@ -665,6 +775,9 @@ struct apple_sleep { unsigned long *driver_down; void __iomem *clk_mux; void __iomem *mcc[MCC_CHANNELS]; + void __iomem *socni[SLEEP_SOCNI_MAX]; + /* T8142: the clock word macOS writes after the memory controller ("mem-clk") */ + void __iomem *mem_clk; void __iomem *ptd; void __iomem *clk_perf; void __iomem *cluster_dcs; @@ -801,6 +914,53 @@ struct apple_sleep { unsigned int ps_unlatched_count; /* T8132: what macOS polls off after its complex words, still on at that point. */ u32 quiesce_still_on; + /* The sleep bus's queue, by its SPMI generation */ + u32 spmi_status; + u32 spmi_rx_empty; + u32 spmi_cmd; + u32 spmi_reply; + u32 spmi_notify_enable; + u32 spmi_notify_ack; + /* + * Gen 4: nub-spmi0's controller device, whose exchange lock the sleep's own PMU writes + * take (apple_spmi_fifo_trylock()); the PMU's latched sources in its status words, from + * apple,spmi-pmu-sources; the words as read at the entry and at the wake; and how many + * PMU writes found the lock taken. + */ + struct device *pmu_bus; + u32 spmi_pmu_status, spmi_pmu_bits; + u32 spmi_src[2][SPMI4_SRC_WORDS]; + bool spmi_src_read[2]; + unsigned int pmu_busy, pmu_busy_forced; + /* + * T8142: each PS write-disable word as read at the entry and after the wake, and which + * of the SoC's bits the entry cleared; AON_WDT_SLEEP as read before WD2 was armed. + */ + u32 ps_wr_dis_entry[SLEEP_PS_WR_DIS_MAX]; + u32 ps_wr_dis_wake[SLEEP_PS_WR_DIS_MAX]; + u32 ps_wr_dis_cleared; + bool ps_wr_dis_read; + u32 aon_wdt_saved; + bool aon_wdt_marked; + /* T8142: each complex's ACC word 0xe440f8 (optional), and what its steps returned */ + void __iomem *acc_e; + void __iomem *acc_p; + int cluster_p_ret; + int perf_soc_ret; + int perf_dcs_ret; + unsigned int perf_dcs_from; + /* With radio_retrain: the radio's PCIe host, and its port's blocks and tables */ + struct device_node *radio_host_np; + void __iomem *radio_port; + void __iomem *radio_lane; + void __iomem *radio_cfg; + struct apple_tunable *radio_port_tunable; + struct apple_tunable *radio_rc_tunable[3]; + bool radio_trainable; + int radio_train_ret; + /* The radio's port stop at the commit (sleep_radio_port_stop()), and its first timeout */ + int radio_stop_ret; + const char *radio_stop_step; }; static struct apple_sleep *apple_sleep; @@ -848,6 +1008,33 @@ static bool apple_sleep_coproc_ready_node(const struct device_node *np) return false; } +/* + * Untested SoCs (apple_sleep_soc.untested): deep sleep offered at all, and the commit allowed. + * The second is for one sleep at a time: aurora-sleep-test sets it and clears it after. + */ +static bool sleep_deep; +module_param_named(deep, sleep_deep, bool, 0444); +MODULE_PARM_DESC(deep, "Untested SoC: offer deep sleep in mem_sleep (never the default)"); +static bool sleep_untested_commit; +module_param_named(untested_commit, sleep_untested_commit, bool, 0644); +MODULE_PARM_DESC(untested_commit, + "Untested SoC: let a deep sleep through to the commit (else a dry run that refuses)"); + +/* + * Untested SoCs: each step of a sleep in PMU scratch, readable after a reset. J815's ADT + * pmu-main info-scrpad is 0x8000 + 0x2800; aurora-silicon/linux#1664 (T6041) notes its steps + * at 0x8308 too. +0 magic, +1 the last step, +2/+4 the step's own detail, +3 the attempt's + * count this boot. The boot after reads and clears them. + */ +#define PMU_NOTE_BASE 0x8308 +#define PMU_NOTE_MAGIC 0xa5 +static bool sleep_pmu_notes = true; +module_param_named(pmu_notes, sleep_pmu_notes, bool, 0644); +MODULE_PARM_DESC(pmu_notes, "Untested SoC: note each sleep step in PMU scratch, for after a reset"); + +static void sleep_note(struct apple_sleep *s, u8 step); +static void sleep_note_at(struct apple_sleep *s, u8 off, u8 val); + static bool sleep_usb_asleep; void apple_sleep_usb_set_asleep(bool asleep) @@ -1430,6 +1617,9 @@ static void apple_sleep_coproc_stop(struct apple_sleep *s, struct apple_sleep_co s->pcie_ans_stopped |= c->pcie_ans; if (c->stopped) return; + /* +2: the slot being stopped (1-based), +4: its own step (apple_sleep_note_sub). */ + sleep_note_at(s, 2, c - apple_sleep_coprocs + 1); + sleep_note_at(s, 4, 0); c->stop_ret = c->last_stop ? c->last_stop(c->data) : 0; if (s->soc->regions && c->pcie_ans && c->stop_ret) s->ans_m5_wake_error = -EIO; @@ -1788,6 +1978,22 @@ static bool sleep_ps_full(struct apple_sleep *s, u32 offset) return FIELD_GET(PS_ACTUAL, readl(s->ps + offset)) == FIELD_MAX(PS_ACTUAL); } +/* + * A coprocessor CPU's run bit, read only where it can answer: its domain at full power. Below + * that the hardware has idled the block (these words are hardware-managed, PS_AUTO_ENABLE) and + * a read of its registers can stall the bus; at .enter, with interrupts off on the last CPU, + * nothing then runs until WD2 resets the SoC. On J815 every sleep that reached .enter did + * exactly that (b28, boots 5343a2e5 to 03fd8d38; again after the port onto the per-SoC ops, + * boot 14343f67: last PMU note 0x10), while every pm_test step up to core came back. An idled + * CPU isn't running, so below full power this says no. Without a power word nothing says the + * block is powered: no read either. + */ +static bool sleep_asc_running(struct apple_sleep *s, u32 ps, void __iomem *asc) +{ + return ps && asc && sleep_ps_full(s, ps) && + (readl(asc + ASC_CPU_CONTROL) & ASC_CPU_CONTROL_RUN); +} + /* @pd's word in "ps": a power controller node, child of the PMGR that "ps" maps. */ static int sleep_ps_offset(struct apple_sleep *s, struct device_node *pd) { @@ -2062,7 +2268,7 @@ static void apple_sleep_stray_restore(struct apple_sleep *s) s->stray_lowered = 0; } -static int apple_sleep_lower_stray(struct apple_sleep *s) +static int apple_sleep_lower_stray(struct apple_sleep *s, bool dry) { const struct apple_sleep_word *stray = s->soc->stray; int i, ret = 0; @@ -2079,6 +2285,16 @@ static int apple_sleep_lower_stray(struct apple_sleep *s) stray[i].name); continue; } + /* + * A dry run writes no power word. J815's first one with every check passing reset + * the Mac by WD2 (boot 1e652ea3) right after the core step had passed, and this + * lowering, of a domain whose block may still run, was the only write in it. + */ + if (dry) { + dev_info(s->dev, "%s is on at the last step: a real sleep lowers it here\n", + stray[i].name); + continue; + } sleep_ps_lower(s, off); s->stray_lowered |= BIT(i); if (sleep_ps_wait_off(s, off)) { @@ -2213,8 +2429,7 @@ static bool apple_sleep_gate_failed(struct apple_sleep *s) dev_err(s->dev, "%s isn't bound\n", g->name); bad++; /* Nothing will stop it, and a commit over a running CPU resets the SoC. */ - if (g->must_stop && g->asc && g->ps && sleep_ps_full(s, g->ps) && - (readl(g->asc + ASC_CPU_CONTROL) & ASC_CPU_CONTROL_RUN)) { + if (g->must_stop && sleep_asc_running(s, g->ps, g->asc)) { dev_err(s->dev, "%s runs unbound: control %#x status %#x\n", g->name, readl(g->asc + ASC_CPU_CONTROL), readl(g->asc + ASC_CPU_STATUS)); @@ -2224,24 +2439,36 @@ static bool apple_sleep_gate_failed(struct apple_sleep *s) running++; continue; } + if (!g->must_stop) + continue; /* A CPU whose domain is off isn't running, and its registers aren't there. */ if (g->ps && !sleep_ps_on(s, g->ps)) continue; - if (g->must_stop && (!g->asc || - ((readl(g->asc + ASC_CPU_CONTROL) & ASC_CPU_CONTROL_RUN) && - !apple_sleep_coproc_ready_node(g->np) && - !sleep_v27_gate_prepared(g->np)))) { - if (g->allow_unstarted || s->soc->regions) - dev_err(s->dev, "%s didn't stop: control %#x\n", g->name, - g->asc ? readl(g->asc + ASC_CPU_CONTROL) : 0); - else - dev_err(s->dev, "%s didn't stop: control %#x status %#x\n", g->name, - g->asc ? readl(g->asc + ASC_CPU_CONTROL) : 0, - g->asc ? readl(g->asc + ASC_CPU_STATUS) : 0); - bad++; - running++; - } - } + /* Its driver quiesced it: as before, that answers for a run bit, now unread. */ + if (g->asc && apple_sleep_coproc_ready_node(g->np)) + continue; + /* A firmware 27 display whose driver prepared its gate for the late stop. */ + if (g->asc && sleep_v27_gate_prepared(g->np)) + continue; + /* Idled below full power, or stopped: its registers read only at full power. */ + if (g->asc && g->ps && !sleep_asc_running(s, g->ps, g->asc)) + continue; + if (g->asc && g->ps && (g->allow_unstarted || s->soc->regions)) + dev_err(s->dev, "%s didn't stop: control %#x\n", g->name, + readl(g->asc + ASC_CPU_CONTROL)); + else if (g->asc && g->ps) + /* At full power (sleep_asc_running): its registers answer. */ + dev_err(s->dev, "%s didn't stop: control %#x status %#x\n", g->name, + readl(g->asc + ASC_CPU_CONTROL), readl(g->asc + ASC_CPU_STATUS)); + else + dev_err(s->dev, "%s didn't stop: %s\n", g->name, + g->asc ? "no power word says its registers can be read" : + "no CPU registers mapped"); + bad++; + running++; + } + + sleep_note(s, 0x26); for (i = 0; i < s->soc->ngate_off; i++) { const struct apple_sleep_word *w = &s->soc->gate_off[i]; @@ -2297,6 +2524,7 @@ static int apple_sleep_refuse(struct apple_sleep *s) bool refused = false, idled = false; int i; + sleep_note(s, 0x20); for (i = 0; i < SLEEP_COPROCS; i++) { struct apple_sleep_coproc *c = &apple_sleep_coprocs[i]; @@ -2333,6 +2561,21 @@ static int apple_sleep_refuse(struct apple_sleep *s) refused = true; } + sleep_note(s, 0x21); + /* Its first config access after the power loss would hang on the untrained link. */ + if (s->radio_host_np && !s->radio_trainable) { + struct platform_device *host = of_find_device_by_node(s->radio_host_np); + + if (host && READ_ONCE(host->dev.driver)) { + dev_err(s->dev, "refused: %s holds the radio's PCIe link, and its port can't be trained again after a real sleep\n", + dev_name(&host->dev)); + refused = true; + } + if (host) + put_device(&host->dev); + } + + sleep_note(s, 0x22); /* ANS's link needs these after a real power loss. */ if (idled && !s->soc->regions && !s->apcie_phy_tunable) { dev_err(s->dev, "refused: no tunables to bring ANS's PCIe block back\n"); @@ -2345,25 +2588,28 @@ static int apple_sleep_refuse(struct apple_sleep *s) refused = true; } + sleep_note(s, 0x23); /* The engine waits for DISP_CPU with no timeout, so this must never slip. */ for (i = 0; i < s->soc->ndisp; i++) { u32 ps = d->disp[i][0]; - if (s->display[i].bound && sleep_ps_on(s, ps) && - (readl(s->display[i].asc + ASC_CPU_CONTROL) & ASC_CPU_CONTROL_RUN) && + if (s->display[i].bound && sleep_asc_running(s, ps, s->display[i].asc) && (!apple_sleep_v27_late() || sleep_v27_final_check(i))) { dev_err(s->dev, "refused: a bound display coprocessor is still running\n"); refused = true; } } + sleep_note(s, 0x24); if (apple_sleep_gate_failed(s)) refused = true; if (refused) return -EBUSY; - return apple_sleep_lower_stray(s); + sleep_note(s, 0x28); + /* A dry run, which stops right after this, writes no power word (as in b27). */ + return apple_sleep_lower_stray(s, s->soc->untested && !READ_ONCE(sleep_untested_commit)); } static void sleep_wake_arm(struct apple_sleep *s) @@ -2429,14 +2675,14 @@ static int sleep_display_off(struct apple_sleep *s) } } - if (sleep_ps_on(s, domains[i][0]) && asc && - (readl(asc + ASC_CPU_CONTROL) & ASC_CPU_CONTROL_RUN)) { + if (sleep_asc_running(s, domains[i][0], asc)) { writel(0, asc + ASC_CPU_CONTROL); writel(0, asc + ASC_CPU_CONTROL); } /* Reads as a count of the DCPs powered, and macOS ends at 0. */ - writel(n - 1 - j, s->pmc_dcp); + if (s->pmc_dcp) + writel(n - 1 - j, s->pmc_dcp); if (soc->pwrgate_disp[i][0]) { if (readl(s->ps + domains[i][0]) & PS_AUTO_ENABLE) writel(readl(s->ps + domains[i][0]) & @@ -2819,6 +3065,124 @@ static void sleep_apcie_clk_off(struct apple_sleep *s) writel(readl(clk) | APCIE_CLK_OFF2, clk); } +/* The PHY's control words: at the start of "phy-block", or this far in (T8142). */ +static void __iomem *sleep_apcie_ctrl(struct apple_sleep *s) +{ + return s->apcie_phy + (s->soc->apcie_phy_ctrl ?: APCIE_PHY_CTRL); +} + +/* + * APCIECoreRCGen4::_shutdownGen4Phy (AppleT8142PCIe, macOS 27.2.1): T8132's PHY stop with + * the UP bit set first, two PHY-IP words and its delays around it. + */ +static void sleep_apcie_gen4_phy_off(struct apple_sleep *s) +{ + void __iomem *ctrl = sleep_apcie_ctrl(s); + void __iomem *run = ctrl + (APCIE_PHY_RUN - APCIE_PHY_CTRL); + void __iomem *ip = s->apcie_phy_ip; + u32 val; + + writel(readl(ctrl) | APCIE_PHY_CTRL_UP, ctrl); + udelay(10); + writel(readl(ip + APCIE_GEN4_PHY_IP_38) & ~APCIE_GEN4_PHY_IP_38_EN, + ip + APCIE_GEN4_PHY_IP_38); + writel(readl(ip + APCIE_GEN4_PHY_IP_8C) | APCIE_GEN4_PHY_IP_8C_OV, + ip + APCIE_GEN4_PHY_IP_8C); + udelay(5); + writel(readl(ctrl) | APCIE_PHY_CTRL_RESET, ctrl); + udelay(1); + writel(readl(ctrl) & ~APCIE_PHY_CTRL_CLK1REQ, ctrl); + readl_poll_timeout_atomic(ctrl, val, !(val & APCIE_PHY_CTRL_CLK1ACK), 1, APCIE_POLL_US); + udelay(1); + writel(readl(ctrl) & ~APCIE_PHY_CTRL_CLK0REQ, ctrl); + readl_poll_timeout_atomic(ctrl, val, !(val & APCIE_PHY_CTRL_CLK0ACK), 1, APCIE_POLL_US); + udelay(1); + writel(readl(ctrl) & ~APCIE_PHY_CTRL_UP, ctrl); + udelay(10); + writel(readl(run) & ~APCIE_PHY_RUN_EN2, run); + writel(readl(run) & ~APCIE_PHY_RUN_EN, run); +} + +/* + * APCIECoreRCGen4::_shutdownPciePLLs: the only pcieclkgen writes in the kext. Nothing starts + * the PLLs again: they come back with the block's power. + */ +static void sleep_apcie_gen4_pll_off(struct apple_sleep *s) +{ + void __iomem *clk = s->apcie_clkgen + APCIE_CLK_CTRL; + u32 val; + + writel((readl(clk) | APCIE_GEN4_CLK_HOLD) & ~APCIE_CLK_RUN, clk); + writel(readl(clk) | APCIE_CLK_OFF, clk); + writel(readl(clk) & ~APCIE_GEN4_CLK_EN, clk); + readl_poll_timeout_atomic(clk, val, !(val & APCIE_CLK_BUSY), 1, APCIE_POLL_US); + writel(readl(clk) | APCIE_CLK_OFF2, clk); + writel((readl(clk) & ~APCIE_CLK_OFF) | APCIE_GEN4_CLK_EN, clk); +} + +/* + * T8142's, from AppleT8142PCIe (APCIECoreRCGen4's power-down, then its gate loop), with all + * of the block's domains still on: the PHY stopped, the AUS5 domains off inside an UP-bit + * window (only once the PHY's first clock request is down), the PLLs off, the AXI enables + * cleared. Then the gate loop: gates 4 down to 0, SYS_ST, ST, SYS_GP, GP, ANS. PHY_SW is + * left on, as macOS leaves it. The radio's port is stopped first (sleep_radio_port_stop()), + * and its link is trained again after the wake (apple_sleep_radio_train()). + */ +static int sleep_radio_port_stop(struct apple_sleep *s); + +static void apple_sleep_lower_apcie_gen4(struct apple_sleep *s) +{ + const struct apple_sleep_domains *d = &s->soc->ps; + void __iomem *ctrl = sleep_apcie_ctrl(s); + bool on = sleep_ps_on(s, d->apcie_gp) && sleep_ps_on(s, d->apcie_sys_gp) && + sleep_ps_on(s, d->apcie_st) && sleep_ps_on(s, d->apcie_sys_st) && + sleep_ps_on(s, d->apcie_phy_sw); + bool clk0; + + /* The radio's port first: its link runs on this block's PHY. */ + if (s->radio_trainable && on) { + s->radio_stop_ret = sleep_radio_port_stop(s); + } else if (s->radio_trainable) { + s->radio_stop_step = "shared block already off"; + s->radio_stop_ret = -ENOLINK; + } + + if (on && s->apcie_phy && s->apcie_phy_ip && sleep_ps_on(s, d->apcie_aus5_aon) && + sleep_ps_on(s, d->apcie_aus5)) { + udelay(10); + sleep_apcie_gen4_phy_off(s); + clk0 = readl(ctrl) & APCIE_PHY_CTRL_CLK0REQ; + writel(readl(ctrl) | APCIE_PHY_CTRL_UP, ctrl); + udelay(10); + if (!clk0) { + sleep_ps_lower(s, d->apcie_aus5); + sleep_ps_lower(s, d->apcie_aus5_aon); + } + writel(readl(ctrl) & ~APCIE_PHY_CTRL_UP, ctrl); + } else { + sleep_ps_lower(s, d->apcie_aus5); + sleep_ps_lower(s, d->apcie_aus5_aon); + } + if (on && s->apcie_clkgen) + sleep_apcie_gen4_pll_off(s); + if (on && s->apcie_axi) { + writel(readl(s->apcie_axi + APCIE_AXI_EN0) & ~BIT(0), s->apcie_axi + APCIE_AXI_EN0); + writel(readl(s->apcie_axi + APCIE_AXI_EN1) & ~BIT(0), s->apcie_axi + APCIE_AXI_EN1); + } + + /* + * macOS's order on T8142 (26B131 trace, 13.0..12.8 ms before the timer): AUS5, AUS5_AON, + * PHY_SW, SYS_ST, ST, SYS_GP, GP, ANS. apple_sleep_raise_apcie_gen4() brings PHY_SW back + * after SYS_ST. + */ + sleep_ps_lower(s, d->apcie_phy_sw); + sleep_ps_lower(s, d->apcie_sys_st); + sleep_ps_lower(s, d->apcie_st); + sleep_ps_lower(s, d->apcie_sys_gp); + sleep_ps_lower(s, d->apcie_gp); + sleep_ps_lower(s, d->ans); +} + /* * ANS's own link runs on this block, and macOS takes it down with the domains. Its * order, measured on one sleep, in the same microseconds as the power words. A block's @@ -2829,6 +3193,10 @@ static void apple_sleep_lower_apcie(struct apple_sleep *s) const struct apple_sleep_domains *d = &s->soc->ps; u32 val; + if (s->soc->apcie_gen4) { + apple_sleep_lower_apcie_gen4(s); + return; + } sleep_apcie_port_stop_once(s); /* The PHY's registers need both domains on. */ if (s->apcie_phy && sleep_ps_on(s, d->apcie_phy_sw) && sleep_ps_on(s, d->apcie_sys_st)) @@ -2885,6 +3253,294 @@ static void sleep_apcie_phy_ip_apply(struct apple_sleep *s) writel(readl(ctl) & ~APCIE_PHY_IP_PLL_HOLD, ctl); } +/* + * T8142's, as AppleT8142PCIe brings the block up and as aura does at boot, where it trains + * the radio's link after it (j813_n1.c): the domains with the AXI enables the lowering + * cleared, the PHY table and its reference PLL, the PHY's clocks out of reset, its run + * enables around the PLL and lane tables, the AXI tables, then the root complex. No clock + * generator or CIO3 PLL tables. Never run after a sleep. + */ +static int apple_sleep_raise_apcie_gen4(struct apple_sleep *s) +{ + const struct apple_sleep_domains *d = &s->soc->ps; + void __iomem *ctrl = sleep_apcie_ctrl(s); + void __iomem *run = ctrl + (APCIE_PHY_RUN - APCIE_PHY_CTRL); + void __iomem *ready = ctrl + (APCIE_PHY_READY - APCIE_PHY_CTRL); + void __iomem *common = s->apcie_phy + APCIE_PHY_COMMON; + u32 val; + int ret; + + ret = sleep_ps_raise(s, d->ans); + ret |= sleep_ps_raise(s, d->apcie_gp); + ret |= sleep_ps_raise_start(s, d->apcie_sys_gp); + if (!ret) { + writel(readl(s->apcie_axi + APCIE_AXI_EN0) | BIT(0), s->apcie_axi + APCIE_AXI_EN0); + writel(readl(s->apcie_axi + APCIE_AXI_EN1) | BIT(0), s->apcie_axi + APCIE_AXI_EN1); + } + sleep_ps_raise_finish(s, d->apcie_sys_gp); + ret |= sleep_ps_raise(s, d->apcie_st); + ret |= sleep_ps_raise(s, d->apcie_sys_st); + ret |= sleep_ps_raise(s, d->apcie_phy_sw); + /* The gate loop powers all eight in the ADT's order: the AUS5 pair last. */ + ret |= sleep_ps_raise(s, d->apcie_aus5_aon); + ret |= sleep_ps_raise(s, d->apcie_aus5); + if (ret) + return ret; + + /* _apcieGPInit: the PHY table, then its reference PLL's clock-good. */ + apple_tunable_apply(s->apcie_phy, s->apcie_phy_tunable); + ret = readl_poll_timeout_atomic(common, val, val & BIT(31), 1, APCIE_POLL_US); + if (ret) + return ret; + + /* _initializeGen4Phy */ + writel(readl(ctrl) | APCIE_PHY_CTRL_CLK0REQ, ctrl); + ret = readl_poll_timeout_atomic(ctrl, val, val & APCIE_PHY_CTRL_CLK0ACK, 1, APCIE_POLL_US); + if (ret) + return ret; + udelay(1000); + writel(readl(ctrl) | APCIE_PHY_CTRL_CLK1REQ, ctrl); + ret = readl_poll_timeout_atomic(ctrl, val, val & APCIE_PHY_CTRL_CLK1ACK, 1, APCIE_POLL_US); + if (ret) + return ret; + writel(readl(ctrl) & ~APCIE_PHY_CTRL_RESET, ctrl); + udelay(1000); + writel(readl(run) | APCIE_PHY_RUN_EN, run); + sleep_apcie_phy_ip_apply(s); + writel(readl(run) | APCIE_PHY_RUN_EN2, run); + ret = readl_poll_timeout_atomic(ready, val, val & BIT(0), 1, APCIE_POLL_US); + if (ret) + return ret; + writel(readl(common) | BIT(0), common); + writel(readl(ctrl) | APCIE_PHY_CTRL_UP, ctrl); + apple_tunable_apply(s->apcie_axi, s->apcie_axi_tunable); + + /* _enableRootComplex */ + writel(0x140, s->apcie_rc + APCIE_RC_READY_CFG); + writel(readl(s->apcie_rc + APCIE_RC_READY_START) | BIT(0), + s->apcie_rc + APCIE_RC_READY_START); + + return readl_poll_timeout_atomic(s->apcie_rc + APCIE_RC_READY_STAT, val, val & BIT(0), 1, + APCIE_POLL_US); +} + +/* T8142's radio port, as aura trains it at boot (j813_n1.c: APCIECoreRCGen4Port) */ +#define RADIO_PORT_LTSSMCTL 0x80 +#define RADIO_PORT_PIPE_STS 0xa8 +#define RADIO_PORT_LINKSTS 0x208 +#define RADIO_PORT_LINKSTS_UP BIT(0) +#define RADIO_PORT_LINKSTS_BUSY BIT(2) +#define RADIO_PORT_APPCLK 0x800 +#define RADIO_PORT_STATUS 0x804 +#define RADIO_PORT_PERST 0x82c +#define RADIO_LANE_REQ0 BIT(0) +#define RADIO_LANE_REQ1 BIT(1) +#define RADIO_LANE_ACK0 BIT(2) +#define RADIO_LANE_ACK1 BIT(3) +#define RADIO_LANE_HOLD BIT(4) +#define RADIO_LANE_EN0 BIT(9) +#define RADIO_LANE_EN1 BIT(10) +#define RADIO_CFG_BUSES 0x18 +#define RADIO_CFG_RO_WR 0x8bc +#define RADIO_LINK_US 1000000 +#define PIN_MODE GENMASK(3, 1) +#define PIN_MODE_OUT 1 + +/* APCIECoreRCGen4Port::_resetPortHardware */ +static const u32 radio_port_reset[][2] = { + { 0x088, 0x110 }, { 0x148, 0xffffffff }, { 0x210, 0xffffffff }, { 0x084, 0 }, + { 0x104, 0xfffffff0 }, { 0x124, 0x100 }, { 0x16c, 0 }, { 0x13c, 0 }, + { 0x800, 0x100100 }, { 0x808, 0x1001ff }, { 0x82c, 0x10000 }, { 0x130, 0x3020000 }, + { 0x140, 0x10 }, { 0x144, 0x253770 }, { 0x834, 0 }, { 0x83c, 0 }, +}; + +static void sleep_radio_perst(struct apple_sleep *s, bool asserted) +{ + void __iomem *reg = s->pins + PIN_REG(s->radio_perst); + bool high = asserted == !s->radio_perst_low; + + writel((readl(reg) & ~(PIN_MODE | PIN_DATA)) | FIELD_PREP(PIN_MODE, PIN_MODE_OUT) | + (high ? PIN_DATA : 0), reg); +} + +/* + * After the power loss the radio's link is down, and the generic host's first config + * access to it would hang. Trained again as aura does it at boot, after the shared block + * (apple_sleep_raise_apcie_gen4()): the radio held in reset, the port's reset values and + * table, its application clock, the lane's reference clock buffer, PERST# released, the + * root port's tables with its read-only registers opened, then the LTSSM. The SMC's N1 + * reset at boot isn't repeated: the SMC keeps its state across the sleep, as T8140's + * radio keeps its rail. macOS 27.2.1's AppleCentauriManager doesn't repeat it at a wake + * either: its function-reset (SMC gP13) runs at start, at shutdown, and to recover a + * crashed driver or a chip found in ROM, after two tries of function-warm_reset (SMC + * 'bpli'). Never run after a sleep. + */ +static int apple_sleep_radio_train(struct apple_sleep *s) +{ + void __iomem *port = s->radio_port, *lane = s->radio_lane, *cfg = s->radio_cfg; + unsigned int i; + u32 val; + int ret; + + if (!sleep_ps_on(s, s->soc->ps.gpio)) + return -ENODEV; + sleep_radio_perst(s, true); + + for (i = 0; i < ARRAY_SIZE(radio_port_reset); i++) + writel(radio_port_reset[i][1], port + radio_port_reset[i][0]); + apple_tunable_apply(port, s->radio_port_tunable); + writel(readl(port + RADIO_PORT_APPCLK) | BIT(0), port + RADIO_PORT_APPCLK); + + /* APCIECoreRCGen4Port::_initializeRefclkBuffer */ + writel(readl(lane) | RADIO_LANE_REQ0, lane); + ret = readl_poll_timeout_atomic(lane, val, val & RADIO_LANE_ACK0, 1, APCIE_POLL_US); + if (ret) + return ret; + writel(readl(lane) | RADIO_LANE_REQ1, lane); + ret = readl_poll_timeout_atomic(lane, val, val & RADIO_LANE_ACK1, 1, APCIE_POLL_US); + if (ret) + return ret; + writel(readl(lane) & ~RADIO_LANE_HOLD, lane); + udelay(1000); + writel(readl(lane) | RADIO_LANE_EN0, lane); + writel(readl(lane) | RADIO_LANE_EN1, lane); + /* T(refclk-to-PERST#) */ + udelay(1000); + + writel(readl(port + RADIO_PORT_PERST) | BIT(0), port + RADIO_PORT_PERST); + sleep_radio_perst(s, false); + ret = readl_poll_timeout_atomic(port + RADIO_PORT_PIPE_STS, val, val & BIT(0), 1, + APCIE_POLL_US * 2); + if (!ret) + ret = readl_poll_timeout_atomic(port + RADIO_PORT_STATUS, val, val & BIT(0), 1, + APCIE_POLL_US * 5); + if (!ret) + ret = readl_poll_timeout_atomic(port + RADIO_PORT_LINKSTS, val, + !(val & RADIO_PORT_LINKSTS_BUSY), 1, + APCIE_POLL_US * 10); + if (ret) + return ret; + + /* _initializeRootComplex: its tables need the read-only registers open. */ + writel(readl(cfg + RADIO_CFG_RO_WR) | BIT(0), cfg + RADIO_CFG_RO_WR); + for (i = 0; i < ARRAY_SIZE(s->radio_rc_tunable); i++) + apple_tunable_apply(cfg, s->radio_rc_tunable[i]); + writel(readl(cfg + RADIO_CFG_RO_WR) & ~BIT(0), cfg + RADIO_CFG_RO_WR); + writel(1, port + RADIO_PORT_LTSSMCTL); + ret = readl_poll_timeout_atomic(port + RADIO_PORT_LINKSTS, val, + val & RADIO_PORT_LINKSTS_UP, 1, RADIO_LINK_US); + if (ret) + return ret; + + /* The root port's buses as the loader set them; the PCI core restores the rest. */ + writel(0x00010100, cfg + RADIO_CFG_BUSES); + /* PCIe's 100 ms from PERST# release to the first configuration request */ + mdelay(100); + + return 0; +} + +/* + * The radio port's stop: APCIECoreRCGen4Port::disablePortHardware in macOS 27.2.1's + * AppleT8142PCIe, the same class (APCIECoreRCGen4Port.cpp) the M5 Pro's AppleT6050PCIe + * builds and pcie-apple.c's apple_pcie_t6050_port_disable() follows. + */ +#define RADIO_PORT_INTSTAT 0x100 +#define RADIO_PORT_PERST_GUARD 0x13c +#define RADIO_PORT_LINKSTS_PHY_ALL0 BIT(12) +#define RADIO_PORT_OUTS_TRANS 0x820 +#define RADIO_PORT_STATUS_RESET BIT(2) +#define RADIO_LANE_CGEN BIT(31) +#define RADIO_CFG_DEBUG0 0x728 +#define RADIO_CFG_LTSSM GENMASK(5, 0) +#define RADIO_CFG_LTSSM_L1_IDLE 0x14 + +/* One of disablePortHardware's waits: macOS logs a timeout and goes on, and so does this. */ +static int sleep_radio_poll(struct apple_sleep *s, const char *step, void __iomem *reg, + u32 mask, u32 want, unsigned int us) +{ + u32 val; + int ret = readl_poll_timeout_atomic(reg, val, (val & mask) == want, 1, us); + + if (ret && !s->radio_stop_step) + s->radio_stop_step = step; + return ret; +} + +/* + * The reverse of apple_sleep_radio_train(), just before the shared block's PHY stops and its + * power goes, in disablePortHardware's order (27.2.1 AppleT8142PCIe; its timeouts in + * brackets): PORT_STS's link reset flag (10 ms), the outstanding transactions drained + * (10 ms), the PERST# guard bit, the link out of L1 (errata #55), PHY_STATUS_ALL0 (5 ms), + * the lane's PIPE reset status (10 ms), the port's PERST# handshake with LANE_UCTRL_IDLE_ACK + * (2 ms), PERST# asserted in the port, the lane's reference clocks off, the interrupts + * cleared, the application clock off and the port's ready flag gone. Like macOS, a wait + * that times out is only noted, and the rest still runs. Then PERST# on the pin, as macOS + * holds the Neo's radio across a sleep (T8140, measured): in reset, its power and firmware + * kept, until the wake's train releases it. Before this the N1 saw its link vanish with + * PERST# released. Derived from the binary, never run. + */ +static int sleep_radio_port_stop(struct apple_sleep *s) +{ + void __iomem *port = s->radio_port, *lane = s->radio_lane, *cfg = s->radio_cfg; + void __iomem *perst = port + RADIO_PORT_PERST; + u32 val; + int ret = 0, err; + + /* A port the loader never brought up has no link to stop. */ + if (!(readl(port + RADIO_PORT_STATUS) & BIT(0))) { + s->radio_stop_step = "port not ready"; + ret = -ENOLINK; + goto pin; + } + + ret |= sleep_radio_poll(s, "PORT_STS link reset", port + RADIO_PORT_STATUS, + RADIO_PORT_STATUS_RESET, RADIO_PORT_STATUS_RESET, 10000); + err = readl_poll_timeout_atomic(port + RADIO_PORT_OUTS_TRANS, val, + !(val & GENMASK(8, 0)) || !(val & GENMASK(23, 16)), + 1, 10000); + if (err && !s->radio_stop_step) + s->radio_stop_step = "OUTS_TRANS_STS"; + ret |= err; + writel(readl(port + RADIO_PORT_PERST_GUARD) | BIT(8), port + RADIO_PORT_PERST_GUARD); + + err = read_poll_timeout_atomic(readl, val, + FIELD_GET(RADIO_CFG_LTSSM, val) != RADIO_CFG_LTSSM_L1_IDLE, + 5, 5000, false, cfg + RADIO_CFG_DEBUG0); + if (err && !s->radio_stop_step) + s->radio_stop_step = "LTSSM stuck in L1 idle"; + ret |= err; + ret |= sleep_radio_poll(s, "PHY_STATUS_ALL0", port + RADIO_PORT_LINKSTS, + RADIO_PORT_LINKSTS_PHY_ALL0, RADIO_PORT_LINKSTS_PHY_ALL0, 5000); + ret |= sleep_radio_poll(s, "LANE_PIPE_RESET_STATUS", port + RADIO_PORT_PIPE_STS, BIT(0), + BIT(0), 10000); + writel(readl(perst) | BIT(24), perst); + ret |= sleep_radio_poll(s, "LANE_UCTRL_IDLE_ACK", port + RADIO_PORT_PIPE_STS, BIT(16), + BIT(16), 2000); + writel(readl(perst) | BIT(16), perst); + udelay(1); + writel(readl(perst) & ~BIT(0), perst); + udelay(1); + writel(readl(perst) & ~BIT(24), perst); + writel(readl(port + RADIO_PORT_PERST_GUARD) & ~BIT(8), port + RADIO_PORT_PERST_GUARD); + + writel(readl(lane) & ~RADIO_LANE_CGEN, lane); + writel(readl(lane) & ~RADIO_LANE_EN1, lane); + writel(readl(lane) & ~RADIO_LANE_EN0, lane); + writel(readl(lane) | RADIO_LANE_HOLD, lane); + writel(readl(lane) & ~RADIO_LANE_REQ0, lane); + writel(readl(lane) & ~RADIO_LANE_REQ1, lane); + + writel(~0, port + RADIO_PORT_INTSTAT); + writel(readl(port + RADIO_PORT_APPCLK) & ~BIT(0), port + RADIO_PORT_APPCLK); + ret |= sleep_radio_poll(s, "port stop", port + RADIO_PORT_STATUS, BIT(0), 0, 250000); + ret = ret ? -ETIMEDOUT : 0; +pin: + if (sleep_ps_on(s, s->soc->ps.gpio)) + sleep_radio_perst(s, true); + return ret; +} + /* * Brought up from power-off in macOS's order, measured on one sleep: all of it follows * the domains on the waking core, well before ANS runs. Whether ANS needs each step is @@ -2898,6 +3554,9 @@ static int apple_sleep_raise_apcie(struct apple_sleep *s) u32 val; int ret; + if (s->soc->apcie_gen4) + return apple_sleep_raise_apcie_gen4(s); + ret = sleep_ps_raise(s, d->ans); ret |= sleep_ps_raise(s, d->apcie_gp); ret |= sleep_ps_raise_start(s, d->apcie_sys_gp); @@ -3160,39 +3819,166 @@ static void sleep_ps_rewake_report(struct apple_sleep *s) #define T8132_PS_AON_ON_STATE 4 -/* As macOS writes the PMU: the reply's vector masked, then acknowledged, so none is left raised. */ -static void sleep_pmu_write(struct apple_sleep *s, u16 reg, u8 val) +/* + * Gen 4: the SPMI driver's exchange lock, tried. A debug note gives way to an exchange under + * way; a write the sleep needs (@must) goes ahead as before and is counted. Returns whether + * the lock is held (and must be released). + */ +static bool sleep_pmu_lock(struct apple_sleep *s, bool must, bool *skip) +{ + int ret; + + *skip = false; + if (!s->pmu_bus) + return false; + ret = apple_spmi_fifo_trylock(s->pmu_bus); + if (!ret) + return true; + /* -ENODEV: its driver is not bound, and nothing else is on the bus. */ + if (ret == -EBUSY) { + if (must) + s->pmu_busy_forced++; + else + *skip = true; + s->pmu_busy++; + } + return false; +} + +static void sleep_pmu_write_one(struct apple_sleep *s, u16 reg, u8 val, bool must) { u32 status, enable; + bool locked, skip; + int i; - enable = readl(s->spmi + SPMI_NOTIFY_ENABLE); - writel(enable & ~SPMI_NOTIFY_REPLY, s->spmi + SPMI_NOTIFY_ENABLE); + if (!s->soc->spmi_gen4) { + apple_sleep_pmu_write(s->spmi, s->soc->pmu_usid, reg, val); + return; + } + locked = sleep_pmu_lock(s, must, &skip); + if (skip) + return; + + enable = readl(s->spmi + s->spmi_notify_enable); + writel(enable & ~SPMI_NOTIFY_REPLY, s->spmi + s->spmi_notify_enable); + /* + * Gen 4 (T8142): a reply someone else left (aura writes the PMU on this queue at a wake) + * would be taken for ours, and ours left for the SPMI driver's next command. Drain before + * and after, each bounded, as aurora-silicon/linux#1664 does on T6041. + */ + for (i = 0; s->soc->spmi_gen4 && i < SPMI_DRAIN_MAX && + !(readl(s->spmi + s->spmi_status) & s->spmi_rx_empty); i++) + readl(s->spmi + s->spmi_reply); writel(((u32)reg << 16) | SPMI_CMD_WRITE | - FIELD_PREP(SPMI_CMD_USID, s->soc->pmu_usid), s->spmi + SPMI_CMD); - writel(val, s->spmi + SPMI_CMD); - if (!readl_poll_timeout_atomic(s->spmi + SPMI_STATUS, status, - !(status & SPMI_STATUS_RX_EMPTY), 1, 1000)) - readl(s->spmi + SPMI_REPLY); - writel(1, s->spmi + SPMI_NOTIFY_ACK); - writel(enable, s->spmi + SPMI_NOTIFY_ENABLE); + FIELD_PREP(SPMI_CMD_USID, s->soc->pmu_usid), s->spmi + s->spmi_cmd); + writel(val, s->spmi + s->spmi_cmd); + if (!readl_poll_timeout_atomic(s->spmi + s->spmi_status, status, + !(status & s->spmi_rx_empty), 1, 1000)) + readl(s->spmi + s->spmi_reply); + for (i = 0; s->soc->spmi_gen4 && i < SPMI_DRAIN_MAX && + !(readl(s->spmi + s->spmi_status) & s->spmi_rx_empty); i++) + readl(s->spmi + s->spmi_reply); + writel(1, s->spmi + s->spmi_notify_ack); + writel(enable, s->spmi + s->spmi_notify_enable); + if (locked) + apple_spmi_fifo_unlock(s->pmu_bus); +} + +static void sleep_pmu_write(struct apple_sleep *s, u16 reg, u8 val) +{ + sleep_pmu_write_one(s, reg, val, false); } /* - * The DRAM-kept wake writes each of these words and gives its switch 171 us to report closed. - * A domain that went off with BUSY latched holds that poll until WD2 resets the SoC. The PMGR - * driver doesn't clear the latch in a system sleep, so do it here. Returns whether one stayed - * latched; the deep path then cuts their power instead. + * Gen 4: nub-spmi0's peripheral source words, read at the entry (@when 0) and at the wake + * (1), and the PMU's latched sources among them acknowledged where the DT names them. The + * T6050 sleep found that after the first sleep's alarm every later sleep was back within a + * second, the latched alarm holding the controller's output (an AP wake source) up; macOS + * acknowledges it at each wake. T8142's nub-spmi0 is the same generation and its output is + * the same wake source (NUB.SPMI0.SW3). Without the property the words are only read, so + * that a sleep's report shows which bits to name. */ -static bool apple_sleep_ps_unlatch(struct apple_sleep *s) +static void sleep_spmi_sources(struct apple_sleep *s, unsigned int when) { - const struct apple_sleep_words *words = &s->soc->ps_engine_polled; - bool stuck = false; - unsigned int i; + u32 latched; + int i; - s->ps_unlatched_count = 0; - for (i = 0; i < words->count && i < ARRAY_SIZE(s->ps_unlatched); i++) { - void __iomem *reg = s->ps + words->offset[i]; - u32 val = readl(reg), off; + if (!s->soc->spmi_gen4 || s->soc->regions) + return; + for (i = 0; i < SPMI4_SRC_WORDS; i++) + s->spmi_src[when][i] = readl(s->spmi + SPMI4_SRC_STATUS + 4 * i); + s->spmi_src_read[when] = true; + if (!s->spmi_pmu_bits) + return; + latched = s->spmi_src[when][(s->spmi_pmu_status - SPMI4_SRC_STATUS) / 4] & + s->spmi_pmu_bits; + if (latched) + writel(latched, s->spmi + s->spmi_pmu_status); +} + +static void sleep_spmi_sources_report(struct apple_sleep *s) +{ + static const char *const when[] = { "entry", "wake" }; + u32 *w; + int i; + + for (i = 0; i < 2; i++) { + if (!s->spmi_src_read[i]) + continue; + s->spmi_src_read[i] = false; + w = s->spmi_src[i]; + dev_info(s->dev, "nub-spmi0 sources at the %s: %08x %08x %08x %08x %08x %08x %08x %08x%s\n", + when[i], w[0], w[1], w[2], w[3], w[4], w[5], w[6], w[7], + s->spmi_pmu_bits ? ", PMU's acknowledged" : ""); + } + if (s->pmu_busy) + dev_info(s->dev, "PMU writes found the SPMI exchange lock taken %u times (%u went ahead)\n", + s->pmu_busy, s->pmu_busy_forced); + s->pmu_busy = s->pmu_busy_forced = 0; +} + +static bool sleep_notes_on(struct apple_sleep *s) +{ + return s && s->spmi && s->soc->untested && READ_ONCE(sleep_pmu_notes); +} + +/* + * Only where nothing else talks SPMI: from .prepare (every device suspended) to .wake (none + * resumed yet), on the one CPU left or before the others go. + */ +static void sleep_note_at(struct apple_sleep *s, u8 off, u8 val) +{ + if (sleep_notes_on(s)) + sleep_pmu_write(s, PMU_NOTE_BASE + off, val); +} + +static void sleep_note(struct apple_sleep *s, u8 step) +{ + sleep_note_at(s, 1, step); +} + +void apple_sleep_note_sub(u8 step) +{ + sleep_note_at(apple_sleep, 4, step); +} +EXPORT_SYMBOL_GPL(apple_sleep_note_sub); + +/* + * The DRAM-kept wake writes each of these words and gives its switch 171 us to report closed. + * A domain that went off with BUSY latched holds that poll until WD2 resets the SoC. The PMGR + * driver doesn't clear the latch in a system sleep, so do it here. Returns whether one stayed + * latched; the deep path then cuts their power instead. + */ +static bool apple_sleep_ps_unlatch(struct apple_sleep *s) +{ + const struct apple_sleep_words *words = &s->soc->ps_engine_polled; + bool stuck = false; + unsigned int i; + + s->ps_unlatched_count = 0; + for (i = 0; i < words->count && i < ARRAY_SIZE(s->ps_unlatched); i++) { + void __iomem *reg = s->ps + words->offset[i]; + u32 val = readl(reg), off; if (!(val & PS_BUSY) || (val & (PS_ACTUAL | PS_TARGET))) continue; @@ -3219,11 +4005,12 @@ static void apple_sleep_match(struct apple_sleep *s) writel(0, s->wdt + WDT_WD0_COUNT); writel(0, s->wdt + WDT_WD1_COUNT); - sleep_pmu_write(s, soc->pmu_sleep_reg, soc->pmu_sleep_val); + sleep_pmu_write_one(s, soc->pmu_sleep_reg, soc->pmu_sleep_val, true); - s->spmi_saved[0] = readl(s->spmi + SPMI_NOTIFY_ENABLE); + sleep_spmi_sources(s, 0); + s->spmi_saved[0] = readl(s->spmi + s->spmi_notify_enable); s->spmi_saved[1] = readl(s->spmi_a0); - writel(soc->spmi_notify_sleep, s->spmi + SPMI_NOTIFY_ENABLE); + writel(soc->spmi_notify_sleep, s->spmi + s->spmi_notify_enable); writel(soc->spmi_notify_sleep, s->spmi_a0); for (i = 0; i < soc->ps_macos_on.count; i++) { @@ -3327,13 +4114,69 @@ static void apple_sleep_match_undo(struct apple_sleep *s) else if (FIELD_GET(PS_ACTUAL, val) != 0xf) writel(val & ~PS_FLAGS, s->ps + soc->ps_macos_on.offset[i]); } - writel(s->spmi_saved[0], s->spmi + SPMI_NOTIFY_ENABLE); + /* What the PMU sent while the SoC slept (its wake), before the run-time mask */ + sleep_spmi_sources(s, 1); + writel(s->spmi_saved[0], s->spmi + s->spmi_notify_enable); writel(s->spmi_saved[1], s->spmi_a0); } +/* + * After the enclave's stop, with nothing left that refuses: each PS write-disable bit the SoC + * names, cleared where set, so that the coprocessor stops and the lowering below reach their + * words. They are not set again after the wake. Linux never needs them, the drivers' power-ups + * would be dropped if they were, and a deep sleep loses the PMGR's state anyway; the words + * are read again after the wake so the report shows what the PMGR came back with. + */ +static void sleep_ps_wr_dis_clear(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + int i; + + s->ps_wr_dis_cleared = 0; + for (i = 0; i < soc->nps_wr_dis; i++) { + void __iomem *reg = s->ps + soc->ps_wr_dis[i].offset; + u32 val = readl(reg); + + s->ps_wr_dis_entry[i] = val; + if (!(val & BIT(soc->ps_wr_dis[i].bit))) + continue; + writel(val & ~BIT(soc->ps_wr_dis[i].bit), reg); + s->ps_wr_dis_cleared |= BIT(i); + } +} + +static void sleep_ps_wr_dis_woke(struct apple_sleep *s) +{ + int i; + + for (i = 0; i < s->soc->nps_wr_dis; i++) + s->ps_wr_dis_wake[i] = readl(s->ps + s->soc->ps_wr_dis[i].offset); + s->ps_wr_dis_read = s->soc->nps_wr_dis > 0; +} + +static void sleep_ps_wr_dis_report(struct apple_sleep *s) +{ + const struct apple_sleep_ps_wr_dis *e = s->soc->ps_wr_dis; + int i; + + if (!s->ps_wr_dis_read) + return; + s->ps_wr_dis_read = false; + for (i = 0; i < s->soc->nps_wr_dis; i++) + dev_info(s->dev, "PS write-disable %s (ps+%#x bit %u): %#x at the entry%s, %#x after the wake\n", + e[i].name, e[i].offset, e[i].bit, s->ps_wr_dis_entry[i], + s->ps_wr_dis_cleared & BIT(i) ? " (cleared)" : "", + s->ps_wr_dis_wake[i]); +} + /* The safety net, as macOS arms it. */ static void apple_sleep_arm_wd2(struct apple_sleep *s) { + if (s->soc->aon_wdt_sleep) { + s->aon_wdt_saved = readl(s->aon_misc + AON_WDT_SLEEP); + writel(s->aon_wdt_saved | s->soc->aon_wdt_sleep, s->aon_misc + AON_WDT_SLEEP); + s->aon_wdt_marked = true; + } writel(0, s->wdt + WDT_WD0_CTL); apple_sleep_set_wd2(s, WDT_SLEEP_SECS); writel(0, s->aon_misc + AON_AP_DEADLINE); @@ -3463,6 +4306,7 @@ static int apple_sleep_commit(unsigned long unused) * stay coherent until the commit. */ s->siq_cfg = read_sysreg_s(SYS_APL_SIQ_CFG_EL1); + sleep_note(s, 0x60); s->cpus_stop_ret = spin_table_stop_parked(); if (s->soc->ops->commit_regs) { @@ -3735,8 +4579,8 @@ static void t8132_last_mile(struct apple_sleep *s) writel(0, s->cluster + soc->cluster_cpu[i]); s->quiesce_still_on = 0; - for (i = 0; i < ARRAY_SIZE(t8132_quiesce_words); i++) - if (sleep_ps_on(s, t8132_quiesce_words[i])) + for (i = 0; i < soc->quiesce.count; i++) + if (sleep_ps_on(s, soc->quiesce.offset[i])) s->quiesce_still_on |= BIT(i); /* All four read back unchanged on macOS. */ @@ -4097,30 +4941,57 @@ static int apple_sleep_enter(suspend_state_t state) if (s->soc->early_context) return apple_sleep_enter_early(s); + sleep_note(s, 0x10); ret = apple_sleep_refuse(s); - if (ret) + if (ret) { + sleep_note(s, 0x2f); return ret; + } + sleep_note(s, 0x29); + /* + * An untested SoC stops here unless asked: every check has run, the stray words are + * lowered (and come back below), and nothing that can't be undone has. + */ + if (s->soc->untested && !READ_ONCE(sleep_untested_commit)) { + sleep_note(s, 0x31); + apple_sleep_stray_restore(s); + dev_info(s->dev, + "dry run: every check passed; refusing before the commit (untested SoC, apple_sleep.untested_commit=1 lets it through)\n"); + return -EAGAIN; + } + sleep_note(s, 0x40); ret = apple_sleep_cpus_hold(s); /* As on macOS, the display goes off before the GPU. */ - if (!ret) + if (!ret) { + sleep_note(s, 0x41); ret = sleep_display_off(s); - if (!ret) + } + if (!ret) { + sleep_note(s, 0x42); ret = apple_sleep_coprocs_check(s); + } /* Cover the platform's own preparation, after the PM core's early check. */ if (!ret && pm_wakeup_pending()) ret = -EBUSY; - if (!ret) + if (!ret) { + sleep_note(s, 0x43); ret = apple_sleep_enclave_stop(s); + } if (ret) { dev_dbg(s->dev, "refused before any commit coprocessor stop: %d\n", ret); spin_table_unhold_parked(); apple_sleep_stray_restore(s); return ret; } + sleep_note(s, 0x44); + sleep_ps_wr_dis_clear(s); apple_sleep_coprocs_stop(s, true); + sleep_note(s, 0x45); sleep_wake_arm(s); + sleep_note(s, 0x46); apple_sleep_match(s); + sleep_note(s, 0x48); /* Acknowledge a leftover done flag, as the DCS word has none on macOS. */ if (s->soc->ack_cluster_dcs && (readl(s->cluster_dcs) & CLUSTER_UP_DONE)) @@ -4134,13 +5005,16 @@ static int apple_sleep_enter(suspend_state_t state) s->cntkctl = read_sysreg(cntkctl_el1); pm_set_resume_via_firmware(); + sleep_note(s, 0x4a); ret = cpu_suspend(0, apple_sleep_commit); if (ret) panic("Apple committed sleep returned without physical wake: %d", ret); apple_sleep_return(s); + sleep_note(s, 0x50); if (s->deep_once) sleep_slp_ddr_set_deep_once(false); + sleep_ps_wr_dis_woke(s); apple_sleep_match_undo(s); apple_sleep_stray_restore(s); sleep_wake_restore(s); @@ -4473,10 +5347,16 @@ static void apple_sleep_late_scope_finish(void) static int apple_sleep_prepare(void) { struct apple_sleep *s = apple_sleep; + static u8 attempts; int i; /* Every device .suspend has run: no owner registers after this. */ sleep_ans_late_close(); + sleep_note_at(s, 0, PMU_NOTE_MAGIC); + sleep_note_at(s, 2, 0); + sleep_note_at(s, 3, ++attempts); + sleep_note(s, 0x02); + /* With an encoder's domain linked, genpd has it off once the encoders are. */ if (s->soc->has_ave && !s->ave_pd_owned) apple_sleep_ave_off(s); @@ -4530,6 +5410,8 @@ static void apple_sleep_report(void) const struct apple_sleep_wake_name *names = s->soc->wake_names; int i; + /* Back in Linux, before any device resumes: a reset after this is in the resume. */ + sleep_note(s, 0x7e); if (s->soc->ops->finish) s->soc->ops->finish(s); apple_sleep_smc_scope_end(); @@ -4555,8 +5437,11 @@ static void apple_sleep_report(void) if (s->wake_status[id / 32] & BIT(id % 32)) dev_info(s->dev, "wake source: %s\n", names[i].name); } - if (!s->soc->regions) + if (!s->soc->regions) { sleep_ps_rewake_report(s); + sleep_spmi_sources_report(s); + sleep_ps_wr_dis_report(s); + } for (i = 0; i < SLEEP_COPROCS; i++) { struct apple_sleep_coproc *c = &apple_sleep_coprocs[i]; @@ -4565,12 +5450,25 @@ static void apple_sleep_report(void) dev_err(s->dev, "%s stop reported %d; physical sleep completed\n", dev_name(c->dev), c->stop_ret); } - for (i = 0; i < ARRAY_SIZE(t8132_quiesce_words); i++) + for (i = 0; i < s->soc->quiesce.count; i++) if (s->quiesce_still_on & BIT(i)) dev_err(s->dev, "power word %#x was on at the last step\n", - t8132_quiesce_words[i]); + s->soc->quiesce.offset[i]); if (s->cpus_stop_ret) dev_err(s->dev, "other CPUs did not stop: %d\n", s->cpus_stop_ret); + if (s->perf_soc_ret || s->perf_dcs_ret) + dev_warn(s->dev, "sleep perf states: SoC %d, DCS %d (DCS was %u)\n", s->perf_soc_ret, + s->perf_dcs_ret, s->perf_dcs_from); + if (s->cluster_p_ret) + dev_err(s->dev, "P complex did not come back on: %d\n", s->cluster_p_ret); + if (s->radio_trainable && s->radio_stop_ret) + dev_warn(s->dev, "the radio's port stop at the commit: first timeout at %s: %d\n", + s->radio_stop_step ?: "?", s->radio_stop_ret); + if (s->radio_trainable && s->radio_train_ret) + dev_err(s->dev, "the radio's PCIe link did not train after the wake: %d\n", + s->radio_train_ret); + else if (s->radio_trainable) + dev_info(s->dev, "the radio's PCIe link trained again after the wake\n"); if (s->cluster_e_ret || s->cluster_ave_ret || s->cluster_ave_commit_ret) dev_err(s->dev, "cluster power timed out: E %d AVE %d, AVE at the commit %d\n", s->cluster_e_ret, s->cluster_ave_ret, s->cluster_ave_commit_ret); @@ -4583,8 +5481,15 @@ static void apple_sleep_report(void) s->pcie_ans_on_ret); } +static int apple_sleep_valid(suspend_state_t state) +{ + if (state != PM_SUSPEND_MEM) + return 0; + return !apple_sleep || !apple_sleep->soc->untested || READ_ONCE(sleep_deep); +} + static const struct platform_suspend_ops apple_sleep_ops = { - .valid = suspend_valid_only_mem, + .valid = apple_sleep_valid, .begin = apple_sleep_begin, .prepare = apple_sleep_prepare, .enter = apple_sleep_enter, @@ -4712,6 +5617,45 @@ static int apple_sleep_map_numbered(struct apple_sleep *s, const char *prefix, return 0; } +static void apple_sleep_put_device(void *dev) +{ + put_device(dev); +} + +/* + * Gen 4: the controller at this node's "spmi" block (nub-spmi0), as the T6050 profile finds + * it, and the PMU's sources in its status words: apple,spmi-pmu-sources = , the + * word's offset in 0x600..0x61c. Neither is required. + */ +static void sleep_map_pmu_bus(struct apple_sleep *s) +{ + struct resource *own = platform_get_resource_byname(to_platform_device(s->dev), + IORESOURCE_MEM, "spmi"); + struct device_node *np; + struct resource res; + u32 v[2]; + + for_each_compatible_node(np, NULL, "apple,t8142-spmi") { + struct platform_device *bus; + + if (!own || of_address_to_resource(np, 0, &res) || res.start != own->start) + continue; + bus = of_find_device_by_node(np); + if (bus && !devm_add_action_or_reset(s->dev, apple_sleep_put_device, &bus->dev)) + s->pmu_bus = &bus->dev; + of_node_put(np); + break; + } + if (!of_property_read_u32_array(s->dev->of_node, "apple,spmi-pmu-sources", v, 2) && + v[1] && v[0] >= SPMI4_SRC_STATUS && v[0] < SPMI4_NOTIFY_ACK && !(v[0] % 4)) { + s->spmi_pmu_status = v[0]; + s->spmi_pmu_bits = v[1]; + } + dev_info(s->dev, "PMU's SPMI controller %s, latched sources %s\n", + s->pmu_bus ? dev_name(s->pmu_bus) : "not found (writes unlocked)", + s->spmi_pmu_bits ? "acknowledged at entry and wake" : "only reported"); +} + static int apple_sleep_map_regs(struct apple_sleep *s) { int i, ret; @@ -4719,12 +5663,24 @@ static int apple_sleep_map_regs(struct apple_sleep *s) for (i = 0; i < ARRAY_SIZE(apple_sleep_regs); i++) { void __iomem **field = (void __iomem **)((u8 *)s + apple_sleep_regs[i].offset); + if (s->soc->regs_absent && + match_string(s->soc->regs_absent, -1, apple_sleep_regs[i].name) >= 0) + continue; *field = apple_sleep_map(s->dev, apple_sleep_regs[i].name); if (IS_ERR(*field)) return dev_err_probe(s->dev, PTR_ERR(*field), "no %s registers\n", apple_sleep_regs[i].name); } + if (s->soc->spmi_gen4 && !s->soc->regions) + sleep_map_pmu_bus(s); + + /* T8142: each complex's ACC word, used only with apple_sleep.acc_wake */ + s->acc_e = apple_sleep_map(s->dev, "acc-e"); + s->acc_p = apple_sleep_map(s->dev, "acc-p"); + if (IS_ERR(s->acc_e) || IS_ERR(s->acc_p)) + s->acc_e = s->acc_p = NULL; + ret = apple_sleep_map_numbered(s, "mcc", s->mcc, s->soc->nmcc); if (ret) return ret; @@ -4733,6 +5689,14 @@ static int apple_sleep_map_regs(struct apple_sleep *s) if (ret) return ret; + ret = apple_sleep_map_numbered(s, "socni", s->socni, s->soc->nsocni); + if (ret) + return ret; + + s->mem_clk = apple_sleep_map(s->dev, "mem-clk"); + if (IS_ERR(s->mem_clk)) + s->mem_clk = NULL; + /* Lowering an unbound display clears its clock protection first. */ if (s->soc->lower_unbound_displays) { s->ps_prot = apple_sleep_map(s->dev, "ps-prot"); @@ -4832,8 +5796,18 @@ static void apple_sleep_map_apcie(struct apple_sleep *s) &s->apcie_phy_ip_pll); s->apcie_phy_ip_lanes = apple_sleep_apcie_tunable(s, np, "phy-ip", "apple,tunable-phy-ip-auspma"); - if (!s->apcie_axi || !s->apcie_cio3pll || !s->apcie_clkgen || !s->apcie_phy || - !s->apcie_rc || !s->apcie_phy_ip || !s->apcie_phy_ip_lanes) { + /* + * T8142's block has neither table: those steps are skipped. Its clock generator + * (pcieclkgen) is only written at the power-down, with no table. + */ + if (s->soc->apcie_gen4) { + s->apcie_cio3pll = NULL; + s->apcie_cio3pll_tunable = s->apcie_clkgen_tunable = NULL; + s->apcie_clkgen = apple_sleep_apcie_block(s, np, "clkgen", NULL, NULL); + } + if (!s->apcie_axi || !s->apcie_phy || !s->apcie_rc || !s->apcie_phy_ip || + !s->apcie_phy_ip_lanes || + (!s->soc->apcie_gen4 && (!s->apcie_cio3pll || !s->apcie_clkgen))) { dev_info(s->dev, "no PCIe tunables for ANS: suspend-to-RAM with it stopped will be refused\n"); s->apcie_phy_tunable = NULL; @@ -4912,6 +5886,53 @@ static void apple_sleep_map_pins(struct apple_sleep *s) of_node_put(np); } +/* + * T8142's radio port: its blocks with the shared block's ("apple,apcie": radio-port, + * radio-lane and radio-cfg, the root port's configuration space), the loader's tables for + * them, and its PERST# ("apple,radio-perst", on the AP pins). All of it, or the port isn't + * trained again and a real sleep is refused while its host is held. + */ +static void apple_sleep_map_radio(struct apple_sleep *s) +{ + static const char *const rc[] = { + "apple,tunable-radio-rc", "apple,tunable-radio-rc-gen3", "apple,tunable-radio-rc-gen4", + }; + struct device_node *np, *pins; + struct of_phandle_args args; + unsigned int i; + + if (!s->soc->radio_retrain || !s->radio_host_np || !s->pins) + return; + np = of_parse_phandle(s->dev->of_node, "apple,apcie", 0); + if (!np) + return; + s->radio_port = apple_sleep_apcie_block(s, np, "radio-port", "apple,tunable-radio-port", + &s->radio_port_tunable); + s->radio_lane = apple_sleep_apcie_block(s, np, "radio-lane", NULL, NULL); + s->radio_cfg = apple_sleep_apcie_block(s, np, "radio-cfg", NULL, NULL); + for (i = 0; i < ARRAY_SIZE(rc); i++) + s->radio_rc_tunable[i] = apple_sleep_apcie_tunable(s, np, "radio-cfg", rc[i]); + of_node_put(np); + + pins = of_parse_phandle(s->dev->of_node, "apple,pinctrl", 0); + if (!of_parse_phandle_with_args(s->dev->of_node, "apple,radio-perst", "#gpio-cells", 0, + &args)) { + if (args.np == pins && args.args_count >= 2 && args.args[0] < s->npins && + !test_bit(args.args[0], s->pins_skip)) { + s->radio_perst = args.args[0]; + s->radio_perst_low = args.args[1] & GPIO_ACTIVE_LOW; + } + of_node_put(args.np); + } + of_node_put(pins); + + s->radio_trainable = s->radio_port && s->radio_lane && s->radio_cfg && + s->radio_port_tunable && s->radio_rc_tunable[0] && + s->radio_rc_tunable[1] && s->radio_rc_tunable[2] && s->radio_perst >= 0; + if (!s->radio_trainable) + dev_info(s->dev, "the radio's port can't be trained after a sleep: a real sleep is refused while its host is bound\n"); +} + static void apple_sleep_map_debug_port(struct apple_sleep *s) { struct device_node *np = of_parse_phandle(s->dev->of_node, "apple,debug-port", 0); @@ -4919,6 +5940,12 @@ static void apple_sleep_map_debug_port(struct apple_sleep *s) if (!np) return; + /* Its commands are written for the gen 1 layout only. */ + if (s->soc->spmi_gen4) { + dev_warn(s->dev, "apple,debug-port on SPMI gen 4: not driven\n"); + of_node_put(np); + return; + } bus = of_get_parent(np); if (bus && !of_property_read_u32_index(np, "reg", 0, &s->hpm_sid)) s->hpm_spmi = of_iomap(bus, 0); @@ -4935,7 +5962,8 @@ static int apple_sleep_alloc_books(struct apple_sleep *s) struct device *dev = s->dev; /* One bit, and one gate, for each */ - if (soc->nstray > BITS_PER_LONG || soc->ngate_coprocs > ARRAY_SIZE(s->gate)) + if (soc->nstray > BITS_PER_LONG || soc->ngate_coprocs > ARRAY_SIZE(s->gate) || + soc->nps_wr_dis > SLEEP_PS_WR_DIS_MAX) return dev_err_probe(dev, -EINVAL, "the SoC's lists are too long\n"); s->ps_on_saved = devm_kcalloc(dev, soc->ps_macos_on.count, sizeof(u32), GFP_KERNEL); @@ -4962,6 +5990,11 @@ static int apple_sleep_alloc_books(struct apple_sleep *s) return 0; } +static void apple_sleep_put_node(void *np) +{ + of_node_put(np); +} + #include "sleep-t6050.h" /* ANS's sleep owner on T6050: registered at its .suspend, its final stop in the last steps. */ @@ -5298,6 +6331,21 @@ static int apple_sleep_probe(struct platform_device *pdev) s->soc = of_device_get_match_data(dev); if (!s->soc) return -ENODEV; + if (s->soc->spmi_gen4) { + s->spmi_status = SPMI4_STATUS; + s->spmi_rx_empty = SPMI4_STATUS_RX_EMPTY; + s->spmi_cmd = SPMI4_CMD; + s->spmi_reply = SPMI4_REPLY; + s->spmi_notify_enable = SPMI4_NOTIFY_ENABLE; + s->spmi_notify_ack = SPMI4_NOTIFY_ACK; + } else { + s->spmi_status = SPMI_STATUS; + s->spmi_rx_empty = SPMI_STATUS_RX_EMPTY; + s->spmi_cmd = SPMI_CMD; + s->spmi_reply = SPMI_REPLY; + s->spmi_notify_enable = SPMI_NOTIFY_ENABLE; + s->spmi_notify_ack = SPMI_NOTIFY_ACK; + } ret = apple_sleep_profile_check(s); if (ret) @@ -5350,7 +6398,14 @@ static int apple_sleep_probe(struct platform_device *pdev) return ret; if (!s->soc->regions) apple_sleep_map_apcie(s); + if (s->soc->radio_retrain) { + s->radio_host_np = of_parse_phandle(dev->of_node, "apple,radio-host", 0); + if (s->radio_host_np && + devm_add_action_or_reset(dev, apple_sleep_put_node, s->radio_host_np)) + return -ENOMEM; + } apple_sleep_map_pins(s); + apple_sleep_map_radio(s); apple_sleep_map_debug_port(s); platform_set_drvdata(pdev, s); @@ -5359,11 +6414,29 @@ static int apple_sleep_probe(struct platform_device *pdev) &sleep_cpu_power_ops); if (ret) return dev_err_probe(dev, ret, "cannot control CPU power\n"); + if (s->soc->pen_deep) + spin_table_pen_deep_arm(true); /* Last: the exported helpers take it as a probed driver, and a failure frees s. */ apple_sleep = s; /* Deep becomes the default sleep state, unless mem_sleep_default= chose another. */ suspend_set_ops(s->soc->early_context ? &apple_sleep_early_ops : &apple_sleep_ops); + /* Not on a SoC whose data is derived: there it is asked for by name. */ + if (s->soc->untested) { + if (mem_sleep_current == PM_SUSPEND_MEM) + mem_sleep_current = PM_SUSPEND_TO_IDLE; + dev_info(dev, "probe: pwrgate wake %#x %#x cpm %#x %#x, commit %#x, clusters %#x %#x\n", + readl(s->pwrgate + s->soc->pwrgate_wake[0]), + readl(s->pwrgate + s->soc->pwrgate_wake[1]), + readl(s->pwrgate + s->soc->pwrgate_cpm[0]), + readl(s->pwrgate + s->soc->pwrgate_cpm[1]), readl(s->commit), + readl(s->cluster + s->soc->cluster_cpu[0]), + readl(s->cluster + s->soc->cluster_cpu[1])); + dev_warn(dev, "sleep data derived for this SoC, untested: deep sleep is %s, and %s\n", + READ_ONCE(sleep_deep) ? "offered (apple_sleep.deep=1)" : "off (apple_sleep.deep=1 offers it)", + READ_ONCE(sleep_untested_commit) ? "the commit is allowed" : + "a sleep stops before the commit (dry run)"); + } dev_info(dev, "deep sleep %s: boot object resumes %llu\n", mem_sleep_current == PM_SUSPEND_MEM ? "is the default" : @@ -5788,15 +6861,616 @@ static const struct apple_sleep_soc t8132_sleep_soc = { .wake_names = t8132_wake_names, .nwake_names = ARRAY_SIZE(t8132_wake_names), .wake_last_word = GENMASK(20, 0), + .quiesce = SLEEP_WORDS(t8132_quiesce_words), }; /* - * Only SoCs whose sleep was measured and tested. On every other the driver doesn't bind, and - * s2idle stays the only sleep. + * T8142 (M5: MacBook Air J813/J815, MacBook Pro J704). No M5 sleep has been traced: this is + * T8132's sleep with T8142's words, translated by name from the J815 ADT and checked against + * the macOS 27.2.1 kernelcache (26B131) where the code says more: + * - XNU's last-WFI path is the same code for both SoCs. + * - AppleT8142PMGR's sleep entry and restoreHW are T8132's in order. A complex comes on as + * (word | 0xf), then bit 4 clears; restoreHW then sets pwrgate +0x0 and +0x60, the boot + * cores of E and P, read-modify-write. + * - Its quiescePerfState takes the SoC to 3 and DCS to 3, through 5 from 6 and up, before + * the complexes go off, and adds a "sleep hack" right before the S2R timer: + * PMGR_SOC_CLLT.EARLY_WAKEUP_CFG (+0x50) bits 17:16 cleared. Its EVENT_CFG step calls a + * method that is empty on T8142. The S2R timer is T8132's commit word. + * - The wake block has nine mask words (sources 0..267), then nine status words. + * - No clock mux and no memory-controller lane step: AppleT8142MCC turns the cache's ways + * off as its platform sleep action, which mcc.c does at suspend_noirq. + * - Its SPMI controllers are gen 4. + * iBoot leaves the boot core's power-gate enable (+0x60) clear: with it clear the boot core + * never powers off in its last WFI, the P complex stays BUSY, and WD2 resets the SoC after + * the commit. The DT's cluster power gate sets it at boot (apple-cluster-pwrgate.c), as on + * T8132 and T6050. + */ +#define T8142_PS_ATC0_COMMON 0x2c8 +#define T8142_PS_AON_ATC0_USB_AON 0xc8 +#define T8142_PS_AON_ATC0_USB 0xd0 +#define T8142_PMC_VOTER_AP (3 * PMC_VOTER_STRIDE) +#define T8142_CLUSTER_BUSY BIT(4) +/* + * AppleT8142PMGR::setPerfState's words in PMGRCLKGEN_SOC_TOP (/arm-io/pmgr reg[2]): the SoC's + * at 0x24000, DCS's at 0x25000, each like T8132's: [3:0] asks, [11:8] has reached, bit 31 busy. + */ +#define T8142_PERF_REQ GENMASK(3, 0) +#define T8142_DCS_SLEEP_STATE 3 +#define T8142_DCS_STEP_STATE 5 +#define T8142_DCS_STEP_FROM 6 +#define T8142_DCS_MAX_STATE 10 + +/* + * Every Linux access to the complexes' ACC word 0xe440f8 has hung J815 so far: a read at + * probe, an on-demand read, and the one wake that wrote it (the only T8142 sleep that went + * down, then hung on its way back). macOS writes 1 after each complex powers on and at the + * end of restoreHW; here that is only done when asked for. + */ +static bool sleep_acc_wake; +module_param_named(acc_wake, sleep_acc_wake, bool, 0644); +MODULE_PARM_DESC(acc_wake, + "T8142: write ACC 0xe440f8 = 1 per complex at a wake, as restoreHW does (default 0)"); + +static int t8142_perf_request(void __iomem *reg, unsigned int state) +{ + writel((readl(reg) & ~T8142_PERF_REQ) | FIELD_PREP(T8142_PERF_REQ, state), reg); + return sleep_perf_wait(reg, state); +} + +/* + * AppleT8142PMGR::quiescePerfState, the PMGR's first sleep step: the SoC to Vmin (3), then DCS + * to 3, through 5 from 6..10. macOS waits on BUSY with no limit and panics on a DCS state + * above 10; here each wait is bounded, and such a state is left alone. + */ +static void t8142_perf_down(struct apple_sleep *s) +{ + unsigned int state = FIELD_GET(DCS_STATE, readl(s->dcs)); + + s->perf_dcs_from = state; + s->perf_soc_ret = t8142_perf_request(s->clk_perf + CLK_PERF_SOC, SOC_SLEEP_STATE); + if (state > T8142_DCS_MAX_STATE) { + s->perf_dcs_ret = -ERANGE; + return; + } + if (state >= T8142_DCS_STEP_FROM) + t8142_perf_request(s->dcs, T8142_DCS_STEP_STATE); + s->perf_dcs_ret = t8142_perf_request(s->dcs, T8142_DCS_SLEEP_STATE); +} + +/* AppleT8142PMGR vtable 0xfa0: each complex's CPM gate word, read-modify-write. */ +static void t8142_cpm_on(struct apple_sleep *s) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(s->soc->pwrgate_cpm); i++) { + void __iomem *reg = s->pwrgate + s->soc->pwrgate_cpm[i]; + + writel(readl(reg) | PWRGATE_ON, reg); + } +} + +/* T8132's, with T8142's ATC0 words; ANS's PCIe block in AppleT8142PCIe's order. */ +static void t8142_lower_io(struct apple_sleep *s) +{ + sleep_note(s, 0x61); + t8132_clean_ram(); + sleep_note(s, 0x62); + s->atc0_saved[0] = readl(s->ps_aon + T8142_PS_AON_ATC0_USB); + s->atc0_saved[1] = readl(s->ps_aon + T8142_PS_AON_ATC0_USB_AON); + s->atc0_saved[2] = readl(s->ps + T8142_PS_ATC0_COMMON); + t8132_aon_lower(s, T8142_PS_AON_ATC0_USB); + if (!READ_ONCE(sleep_usb_asleep)) + t8132_aon_lower(s, T8142_PS_AON_ATC0_USB_AON); + sleep_ps_lower(s, T8142_PS_ATC0_COMMON); + if (s->pcie_ans_stopped) { + apple_sleep_lower_apcie(s); + s->ans_off_ret = sleep_ps_wait_off(s, s->soc->ps.ans); + } + sleep_note(s, 0x63); +} + +/* + * The last note before the cores' window (0x65): +2 flags, +4 the first armed wake source + * already pending (low 8 bits; 0xff none). Flags: 0x01 a parked CPU didn't stop, 0x02 the SoC + * perf state, 0x04 the DCS state didn't settle, 0x08 an armed wake source is pending, 0x10 it + * is >= 256, 0x20 the commit word read non-zero (it reads 1 from boot on J815). No PMU traffic + * after it: the engine gives the cores 33 ms from the complex words to their WFI. + */ +static void t8142_commit_note(struct apple_sleep *s) +{ + u8 flags = 0, src = 0xff; + int i; + + if (!sleep_notes_on(s)) + return; + if (s->cpus_stop_ret) + flags |= 0x01; + if (s->perf_soc_ret) + flags |= 0x02; + if (s->perf_dcs_ret) + flags |= 0x04; + for (i = 0; i < s->soc->wake_words; i++) { + u32 pend = readl(s->wake + s->soc->wake_status + i * 4) & s->wake_armed[i]; + + if (!pend) + continue; + if (!(flags & 0x08)) { + u32 id = i * 32 + __ffs(pend); + + src = id & 0xff; + if (id > 0xff) + flags |= 0x10; + } + flags |= 0x08; + } + if (readl(s->commit)) + flags |= 0x20; + sleep_note_at(s, 2, flags); + sleep_note_at(s, 4, src); + sleep_note(s, 0x65); +} + +/* + * T8142's memory side, as macOS steps it down 4.6 to 2.7 ms before the S2R timer (J813, 27.2.1, + * all ten cores: gig3m's trace, gist 89aedeca, 2026-11-15; the J815 ADT has the same mcc + * layout). The PMGR words around it match our J815 trace write for write. + * + * - AMCC: each plane's +0x28000 word (mapped as "amcc") holds 0x1fe; macOS clears it two + * bits at a time, in the order below (plane, bit pair), 64-bit read-modify-writes. Whatever + * is left on a plane macOS didn't list (the fourth, on J813) goes the same way, low bit first. + * - SoC NI (mcc reg[2..7], "socni"): each table zeroed from its first word, as many as + * macOS writes. + * - DCS channels (reg[10..17] + 0x580, "mcc"): the enables down a bit at a time, low bit + * first; then two lanes per channel per pass, as T8140's, with +0x680 rewritten before each + * lane and only the lanes that are enabled (J813's fifth channel has lanes 0 and 2). + */ +#define T8142_AMCC_SLEEP_BITS GENMASK_ULL(8, 1) +#define T8142_MCC_LANE_EXTRA 0x100 +#define T8142_MEM_CLK_SLEEP 0x30000 + +static void t8142_amcc_clear(void __iomem *reg, u64 bits) +{ + u64 val = readq(reg); + unsigned int b; + + for_each_set_bit(b, (unsigned long *)&bits, 64) { + if (!(val & BIT_ULL(b))) + continue; + val &= ~BIT_ULL(b); + writeq(val, reg); + val = readq(reg); + } +} + +static void t8142_sleep_mcc_stop(struct apple_sleep *s) +{ + /* (plane, pair): the pair's bits are 2 * pair + 1 and 2 * pair + 2 */ + static const u8 order[][2] = { + { 1, 0 }, { 2, 2 }, { 1, 2 }, { 0, 1 }, { 1, 3 }, { 0, 0 }, + { 1, 1 }, { 2, 3 }, { 0, 3 }, { 2, 1 }, { 0, 2 }, { 2, 0 }, + }; + const struct apple_sleep_soc *soc = s->soc; + int i, plane, ch, pass, n; + + for (i = 0; i < ARRAY_SIZE(order); i++) { + if (order[i][0] >= soc->namcc) + continue; + t8142_amcc_clear(s->amcc[order[i][0]], GENMASK_ULL(2 * order[i][1] + 2, + 2 * order[i][1] + 1)); + } + for (plane = 0; plane < soc->namcc; plane++) + t8142_amcc_clear(s->amcc[plane], T8142_AMCC_SLEEP_BITS); + + for (i = 0; i < soc->nsocni; i++) + for (n = 0; n < soc->socni_words[i]; n++) + writel(0, s->socni[i] + 4 * n); + + for (ch = 0; ch < soc->nmcc; ch++) + t8132_mcc_step_down(s->mcc[ch] + MCC_ENABLES); + + for (pass = 0; pass < 2; pass++) { + for (ch = 0; ch < soc->nmcc; ch++) { + void __iomem *mcc = s->mcc[ch]; + + for (n = 2 * pass; n < 2 * pass + 2; n++) { + if (!(readl(mcc + MCC_LANES) & MCC_LANE(n))) + continue; + writel(readl(mcc + T8142_MCC_LANE_EXTRA), mcc + T8142_MCC_LANE_EXTRA); + writel(readl(mcc + MCC_LANES_MASK), mcc + MCC_LANES_MASK); + writel(readl(mcc + MCC_LANES) | MCC_LANE_STROBE(n), mcc + MCC_LANES); + writel(readl(mcc + MCC_LANES) & ~MCC_LANE(n), mcc + MCC_LANES); + } + } + } + + if (s->mem_clk) + writel(T8142_MEM_CLK_SLEEP, s->mem_clk); +} + +/* + * T8132's order after the cores stopped, ATC0 and ANS lowered and WD2: quiescePerfState, the + * CPM gates around the AP's PMC vote (agent 3, as T8132's), the complexes off, the quiesce + * read, the early wake-up bits off, the words saved. + */ +static void t8142_last_mile(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + int i; + + t8142_perf_down(s); + sleep_note(s, 0x64); + + /* The memory controller, after the SoC and DCS states, as on T8132 (and macOS on J813). */ + t8142_sleep_mcc_stop(s); + sleep_note(s, 0x66); + + t8142_cpm_on(s); + t8142_cpm_on(s); + readl(s->pmc_voters + T8142_PMC_VOTER_AP); + writel(0, s->pmc_voters + T8142_PMC_VOTER_AP); + readl(s->pmc_voters + T8142_PMC_VOTER_AP + 4); + t8142_cpm_on(s); + + t8142_commit_note(s); + + for (i = 0; i < soc->ncluster_cpu; i++) + writel(0, s->cluster + soc->cluster_cpu[i]); + + s->quiesce_still_on = 0; + for (i = 0; i < soc->quiesce.count; i++) + if (sleep_ps_on(s, soc->quiesce.offset[i])) + s->quiesce_still_on |= BIT(i); + + /* "Applying Sleep hacks": the early wake-up bits off, right before the S2R timer. */ + for (i = 0; i < soc->ncllt; i++) + writel(readl(s->cllt + soc->cllt[i].offset) & ~soc->cllt[i].clear, + s->cllt + soc->cllt[i].offset); + + sleep_ps_save(s); +} + +/* + * AppleT8142PMGR's complex power-on: ApplePMGR's cluster method writes (word & ~0xf) | 0xf and + * waits for bit 4 to clear; T8142's override then writes 1 to the complex's ACC word. + */ +static int t8142_cluster_on(struct apple_sleep *s, u32 word, void __iomem *acc) +{ + void __iomem *reg = s->cluster + word; + u32 val; + int ret; + + writel(readl(reg) | CLUSTER_ON, reg); + ret = readl_poll_timeout_atomic(reg, val, !(val & T8142_CLUSTER_BUSY), 1, + CLUSTER_TIMEOUT_US); + if (!ret && acc && READ_ONCE(sleep_acc_wake)) + writel(1, acc); + return ret; +} + +/* + * AppleT8142PMGR::restoreHW: each complex on, pwrgate +0x0 and +0x60 read-modify-written, the + * words back, the CPM gates, the ACC words once more. Its two "early wake hacks" (SEP's ps + * word, map 0x4e's ten words) are gated by flags its constructor clears and nothing sets. + * Then T8132's: ATC0's words, SEP, WD2, ANS's PCIe block and the radio's link. + */ +static void t8142_wake(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + u32 val; + int i; + + s->cluster_e_ret = t8142_cluster_on(s, soc->cluster_cpu[0], s->acc_e); + s->cluster_p_ret = t8142_cluster_on(s, soc->cluster_cpu[1], s->acc_p); + + for (i = 0; i < ARRAY_SIZE(soc->pwrgate_wake); i++) { + void __iomem *reg = s->pwrgate + soc->pwrgate_wake[i]; + + writel(readl(reg) | PWRGATE_ON, reg); + } + + sleep_ps_rewake(s); + /* The commit saved ATC0's words already lowered: reverse of the lowering. */ + sleep_ps_restore(s->ps + T8142_PS_ATC0_COMMON, s->atc0_saved[2]); + sleep_ps_restore(s->ps_aon + T8142_PS_AON_ATC0_USB_AON, s->atc0_saved[1]); + sleep_ps_restore(s->ps_aon + T8142_PS_AON_ATC0_USB, s->atc0_saved[0]); + + s->deep_ran = sleep_ps_woke_on(s, soc->ps.ap_tmm); + + val = readl(s->ps + soc->ps.sep); + if (val & PS_DEV_DISABLE) + writel(val & ~PS_DEV_DISABLE, s->ps + soc->ps.sep); + + t8142_cpm_on(s); + if (READ_ONCE(sleep_acc_wake) && s->acc_e && s->acc_p) { + writel(1, s->acc_e); + writel(1, s->acc_p); + } + + /* macOS's wake is not traced: back to what the entry read, before WD2's re-arm. */ + if (s->aon_wdt_marked) { + writel(s->aon_wdt_saved, s->aon_misc + AON_WDT_SLEEP); + s->aon_wdt_marked = false; + } + apple_sleep_set_wd2(s, WDT_SUSPEND_SECS); + + if (s->pcie_ans_stopped) + s->pcie_ans_on_ret = apple_sleep_raise_apcie(s); + /* Before the PCI core restores the radio's functions, which needs the link. */ + if (s->radio_trainable) + s->radio_train_ret = s->pcie_ans_stopped && !s->pcie_ans_on_ret ? + apple_sleep_radio_train(s) : -ENOLINK; + s->apcie_port_down = true; + s->pins_lost = s->pins_saved_valid; +} + +/* The J815 ADT's /arm-io/pmgr ap-wake-sources, all of them. */ +static const struct apple_sleep_wake_name t8142_wake_names[] = { + { 5, "AOP.CPUWakeupAP" }, { 12, "AOP.GPIO.IRQ4" }, { 14, "AOP.GPIO.IRQ6" }, + { 44, "AOP.OutboxNotEmpty" }, { 63, "AOP.SPMI0.SW3" }, { 67, "AOP.SPMI1.SW3" }, + { 71, "ATC0.CIOWakeup" }, { 72, "ATC0.USBWakeup" }, { 73, "ATC1.CIOWakeup" }, + { 74, "ATC1.USBWakeup" }, { 75, "ATC2.CIOWakeup" }, { 76, "ATC2.USBWakeup" }, + { 77, "ATC3.CIOWakeup" }, { 78, "ATC3.USBWakeup" }, + { 89, "MTP.DOCK.CHANNELS.AP0.IRQ" }, { 108, "MTP.OutboxNotEmpty" }, + { 128, "NUB.APWakeupTime" }, { 129, "PMGR_AON.APWatchdog" }, { 146, "NUB.GPIO.IRQ6" }, + { 152, "NUB.SPMI0.SW3" }, { 157, "NUB.SPMI1.SW3" }, { 163, "NUB.WakeupAP" }, + { 168, "SMC.CPUWakeupAP" }, { 190, "SMC.OutboxNotEmpty" }, + { 237, "AOP.TrustedOutboxNotEmpty" }, { 256, "AOP2.TrustedOutboxNotEmpty" }, + { 261, "AOP2.CPUWakeAP" }, +}; + +/* + * Every word in the J815 ADT's /arm-io/pmgr power states, in "ps" and in "ps-aon". The lists + * after them are T8132's measured ones, each word translated to T8142's by its ADT name; a + * T8132 word with no T8142 namesake is dropped. + */ +/* + * Less DCS0..7 (0x1d8, 0x1e0, 0x1e8, 0x1f0, 0x218, 0x220, 0x228, 0x230): DRAM slices, no_ps in + * the J815 ADT and left to the memory controller. Reading or writing one at .enter stalled J815 + * (boot 45257eaf, DCS5 in the match), so neither the dry run's report, the commit's save nor the + * rewake after a wake touches them. + */ +/* + * Also less the 34 words that are OS-managed on T8132 (or absent there) but no_ps in the J815 + * ADT (PCPM_SRAM, SBR, PMS(_BUSIF), PMGR_SOC_OCLA, PIOGW, the AF* fabrics and AMCC ports, SIO, + * FPWM1, TRACE_FAB, DPTX_PHY, ISP_CPU*, ISP_FE, DISP_SMB*): the rewake after a wake writes back + * any word of this list whose control bits moved, and on T8142 these are firmware's to move + * (rule: t8142_ps_macos_off). + */ +static const u32 t8142_ps_all[] = { + 0x8, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38, 0x40, 0x48, 0x50, + 0x58, 0x110, 0x118, 0x120, 0x138, 0x140, 0x148, 0x150, 0x158, 0x160, + 0x168, 0x170, 0x178, 0x180, 0x190, 0x198, 0x1a0, 0x1a8, 0x1b0, 0x290, + 0x298, 0x2a0, 0x2a8, 0x2b8, 0x2c0, 0x2c8, 0x2d0, 0x2d8, 0x2e0, 0x2e8, + 0x2f0, 0x2f8, 0x300, 0x308, 0x310, 0x318, 0x320, 0x328, 0x330, 0x340, + 0x348, 0x350, 0x358, 0x360, 0x368, 0x370, 0x378, 0x380, 0x388, 0x390, + 0x398, 0x3a0, 0x3a8, 0x3b0, 0x3b8, 0x3c0, 0x3c8, 0x3d0, 0x3d8, 0x3e0, + 0x3e8, 0x3f0, 0x3f8, 0x400, 0x408, 0x410, 0x418, 0x420, 0x428, 0x430, + 0x438, 0x440, 0x448, 0x450, 0x458, 0x460, 0x468, 0x470, 0x478, 0x480, + 0x488, 0x490, 0x498, 0x4a0, 0x4a8, 0x4b0, 0x4b8, 0x4c0, 0x4c8, 0x4d0, + 0x4d8, 0x4e0, 0x4e8, 0x4f0, 0x4f8, 0x500, 0x508, 0x510, 0x518, 0x520, + 0x528, 0x530, 0x538, 0x540, 0x548, 0x550, 0x558, 0x560, 0x568, 0x570, + 0x578, 0x580, 0x598, 0x5a0, 0xc00, 0x4020, 0x4028, 0x4030, 0x4038, 0x4040, + 0x4048, 0x4050, 0x4058, 0x4060, 0x8000, 0x8008, 0x8010, 0x8018, 0x8020, 0xc000, + 0xc008, 0xc010, 0x10000, 0x10008, 0x10010, 0x10018, 0x10020, 0x10028, 0x10030, 0x10038, + 0x10040, 0x10048, 0x10050, 0x10068, 0x10070, 0x10078, +}; + +/* + * Less the 9 AON words T8142 took from the OS (no_ps here, OS-managed or absent on T8132): + * NUB_AON, NUB_OCLA, NUB_FABRIC, NUB_SRAM, DEBUG_SWITCH, AOP_DART, AOP_I2CM3, AOP2_PIODMA, + * AOP2_CPU. Same reason as t8142_ps_all. + */ +static const u32 t8142_ps_aon_all[] = { + 0x58, 0x60, 0x68, 0x70, 0x78, 0x88, 0x98, 0xa0, 0xa8, 0xc8, + 0xd0, 0xd8, 0xe0, 0xe8, 0xf0, 0xf8, 0x100, 0x4000, 0x4008, 0x4010, + 0x4018, 0x4028, 0x4030, 0x4038, 0x4048, 0x4050, 0x4058, 0x4060, 0x4068, 0x4070, + 0x4078, 0x4080, 0x4088, 0x4090, 0x40a0, 0x40a8, 0x40b8, 0x40c0, 0x40c8, 0x40d0, + 0x40d8, 0x40e0, 0x40e8, 0x40f0, 0x40f8, 0x4100, 0x4108, 0x4110, 0x4118, 0x4120, + 0x4128, 0x4130, 0x4138, 0x4140, 0x4148, 0x4150, 0x4158, 0x4160, 0x4168, 0x4170, + 0x4178, 0x4180, 0x4188, 0x8000, 0x8008, 0x8010, 0x8018, 0x8020, 0x8028, 0x8030, + 0x8038, 0x8040, 0x8048, 0x8050, 0x8058, 0x8060, 0x8068, 0x8070, 0x8078, 0x8080, + 0x8088, 0xc000, 0xc008, 0xc010, 0xc018, 0xc020, 0xc028, 0xc030, 0xc038, 0xc040, + 0xc048, 0xc050, 0xc058, 0xc060, +}; + +/* Less DPTX_PHY (0x590): no_ps on T8142 (see t8142_ps_macos_off). */ +static const u32 t8142_ps_wake_order[] = { + 0xc00, 0x118, 0x120, 0x180, 0x390, 0x398, 0x468, 0x470, 0x478, 0x480, + 0x488, 0x598, 0x5a0, 0x300, 0x2f0, 0x408, 0x410, 0x520, 0x560, 0x328, + 0x2a8, 0x320, 0x2b8, 0x3a8, 0x3b8, 0x290, 0x318, 0x10000, 0x308, 0x418, + 0x428, 0x440, 0x360, +}; + +static const u32 t8142_ps_aon_wake_order[] = { + 0xa8, +}; + +/* + * T8132's match raises its AFIMCCNI0/1, FAB_AFC0, AMCC0/1, DCS5 and DCS7 (and DWI). On T8142 every + * one of those, by name or by its split (AFCMCCNI0, AMCC0_P0..P3), is no_ps in the J815 ADT: the + * memory path's words belong to firmware there, and J815 stalled the first time a sleep wrote + * one (DCS5, boot 45257eaf). T8142 raises none; see t8142_ps_macos_off for the rule. + */ + +/* + * T8132's lowered words by name, less those T8142 took out of the OS's hands: ISP_FE, + * ISP_CPU_CORE1/0, ISP_CPU, DPTX_PHY, TRACE_FAB, FPWM1 and AFIAFT are OS-managed on T8132 but + * no_ps in the J815 ADT (FPWM1 next to T8142's own no_ps SMC_FPWM0..3). J815 stalled lowering + * FPWM1 (boot b7f0f04d: PMU note 0x47, phase 5, index 44). The rule for T8142's sleep lists: + * no word the J815 ADT marks no_ps, unless T8132 writes the same no_ps word (its AON audio ones). + */ +static const u32 t8142_ps_macos_off[] = { + 0xc010, 0xc008, 0xc000, 0x8020, 0x8018, 0x8010, 0x8008, 0x8000, 0x510, 0x508, + 0x500, 0x4f8, 0x4f0, 0x4e8, 0x4e0, 0x4d8, 0x460, 0x458, 0x450, 0x448, + 0x440, 0x438, 0x430, 0x400, 0x3f8, 0x3f0, 0x3e8, 0x3e0, 0x3d8, 0x3d0, + 0x3c8, 0x3c0, 0x3a0, 0x368, 0x360, 0x358, 0x350, 0x348, 0x320, 0x310, + 0x2f8, 0x2e8, 0x2e0, 0x2d8, 0x2d0, 0x2c0, 0x2a8, 0x2a0, 0x298, 0x1b0, + 0x198, 0x190, 0x178, 0x170, +}; + +static const u32 t8142_ps_aon_macos_off[] = { + 0x4180, 0x4108, 0x40f8, 0x40d8, 0x40b8, 0x4080, 0x100, 0xf8, 0xf0, 0xe8, + 0xe0, 0xd8, +}; + +static const u32 t8142_ps_aon_macos_on[] = { + 0x40e0, 0x40e8, 0x4118, 0x4138, 0x4148, 0x4150, 0x4158, +}; + +/* + * T8132's quiesce words by name: the ATC commons, the display's and DISPEXT's SYS, ANS, AVD, + * VENC, JPG and APCIE's SYS_GP. GFX's is in its own block here. + */ +static const u32 t8142_quiesce_words[] = { + 0x2c8, 0x2d0, 0x2d8, 0x2e0, 0x290, 0x308, 0x2b8, 0x300, 0x310, 0x298, + 0x2a0, 0x408, +}; +static_assert(ARRAY_SIZE(t8142_quiesce_words) <= 32); + +static const struct apple_sleep_word t8142_stray_words[] = { + { "AVD_SYS", 0x310 }, { "VENC_SYS", 0x298 }, { "JPG", 0x2a0 }, +}; + +static const struct apple_sleep_word t8142_gate_off[] = { + { "ane_sys", 0x2e8 }, { "isp_sys", 0x2f8 }, { "avd_sys", 0x310 }, + { "jpg", 0x2a0 }, { "venc_sys", 0x298 }, +}; + +/* T8142's, from the J815 tree. GFX's word is in its own block, not "ps". */ +static const struct apple_sleep_gate_coproc t8142_gate_coprocs[] = { + { "/soc/dcp@286e00000", true, 0x10000 }, + { "/soc/pmp@380500000", true }, + { "/soc/nvme@4c5cc0000" }, { "/soc/mtp@394600000" }, + { "/soc/aop@390c00000" }, { "/soc/smc@38c600000" }, + { "/soc/sep@30a600000" }, + { "/soc/gpu@582600000", true }, +}; + + +static const struct apple_sleep_ops t8142_sleep_ops = { + /* XNU's last-WFI helper is the same code as T8132's and T8140's. */ + .deep_wfi_arm = t8140_deep_wfi_arm, + .lower_io = t8142_lower_io, + .last_mile = t8142_last_mile, + /* WD2 is at T8132's address (/arm-io/wdt), so the same stub restarts it. */ + .resume = t8132_resume_stub, + .pre_commit = t8132_pre_commit, + .wake = t8142_wake, + .aic_mask_all = aic_sleep_mask_all, + .aic_ack = aic_sleep_ack, + .aic_restore = aic_sleep_restore, +}; + +/* + * The J815 /chosen/dart-ps-wr-dis-entries that macOS's SPTM clears during its entry (26B131 + * trace), but the DCP's (ps+0x17fdc bit 6, which the DART driver owns) and DCPEXT0/1's (no + * external DCP in this tree), in the trace's order. The rest of each word stays set, as on macOS. + */ +static const struct apple_sleep_ps_wr_dis t8142_ps_wr_dis[] = { + { "SEP (InvalidateHmac)", 0x17fe0, 12 }, + { "centauri-beta", 0x17fe8, 10 }, + { "PMP", 0x17ff8, 17 }, + { "SIO DMA", 0x17ff0, 28 }, +}; + +/* mcc reg[2..7]: the words macOS zeroes in each SoC NI table (J813 trace) */ +static const u8 t8142_socni_words[] = { 15, 16, 28, 30, 21, 14 }; + +static const char *const t8142_regs_absent[] = { + "pmc-dcp", "clk-mux", "ptd", "cluster-dcs", "dvfm-e", "dvfm-p", NULL, +}; + +static const struct apple_sleep_soc t8142_sleep_soc = { + .ops = &t8142_sleep_ops, + .untested = true, + .regs_absent = t8142_regs_absent, + .spmi_gen4 = true, + .boot_wfi_delay_ms = 3, + .wake_optional = true, + /* The J815 tree has no external DCP: DISPEXT0/1 are 0x428/0x418/0x308, 0x3b8/0x3a8/0x2b8. */ + .ndisp = 1, + .display_order = { 0 }, + /* E, P (ADT soc-clusters) */ + .cluster_cpu = { 0x0, 0x4 }, + .ncluster_cpu = 2, + /* Six E cores: E bits 0-5, P bits 6-9, the boot core P0. */ + .cpu_start_stride = 6, + .cllt = { { 0x50, GENMASK(17, 16) } }, + .ncllt = 1, + .ps_wr_dis = t8142_ps_wr_dis, + .nps_wr_dis = ARRAY_SIZE(t8142_ps_wr_dis), + /* ADT mcc: amcc-plane-enable-mask 0xf, dcs-count-per-amcc 8, socni-count 6 */ + .namcc = 4, + .nmcc = 8, + .socni_words = t8142_socni_words, + .nsocni = ARRAY_SIZE(t8142_socni_words), + .aon_wdt_sleep = 0x20, + /* The same PMU, and the same boot-stage byte, as T8132 (J815 ADT info-leg_scrpad). */ + .pmu_usid = 0xe, + .pmu_sleep_reg = 0xf801, + .pmu_sleep_val = 0x50, + .spmi_notify_sleep = 0x2000001, + .wake_mask = 0x08, + /* AppleT8142PMGR, 27.2.1: masks at map 0x42 + 0x08..0x28, status 0x2c..0x4c */ + .wake_status = 0x2c, + .wake_words = 9, + .ps = { + .disp = { + { 0x10000, 0x318, 0x290 }, + }, + .sio_cpu = 0x328, + .sep = 0xc00, + .ap_tmm = 0x1b0, + .gpio = 0x120, + .ans = 0x300, + .apcie_gp = 0x2f0, + .apcie_sys_gp = 0x408, + .apcie_st = 0x410, + .apcie_sys_st = 0x520, + .apcie_phy_sw = 0x560, + .apcie_aus5_aon = 0x578, + .apcie_aus5 = 0x580, + }, + .ps_aon_debug_switch = 0xc0, + /* ADT /arm-io/apcie: the PHY-PHY block (reg[3]) is 0x20000 into the PHY's (reg[2]). */ + .apcie_phy_ctrl = 0x20000, + .apcie_gen4 = true, + .radio_retrain = true, + .pen_deep = true, + .pwrgate_wake = { 0x000, 0x060 }, + /* AppleT8142PMGR vtable 0xfa0: 0xa0 + 8 * complex */ + .pwrgate_cpm = { 0x0a0, 0x0a8 }, + /* DISP_CPU's retention words: the J815 pmgr's retention_config_ff/_mem (device 0xb7) */ + .pwrgate_disp = { { 0x11cc, 0x11f0 } }, + .ps_all = SLEEP_WORDS(t8142_ps_all), + .ps_aon_all = SLEEP_WORDS(t8142_ps_aon_all), + .ps_macos_off = SLEEP_WORDS(t8142_ps_macos_off), + .ps_aon_macos_off = SLEEP_WORDS(t8142_ps_aon_macos_off), + .ps_aon_macos_on = SLEEP_WORDS(t8142_ps_aon_macos_on), + .ps_wake_order = SLEEP_WORDS(t8142_ps_wake_order), + .ps_aon_wake_order = SLEEP_WORDS(t8142_ps_aon_wake_order), + .quiesce = SLEEP_WORDS(t8142_quiesce_words), + .stray = t8142_stray_words, + .nstray = ARRAY_SIZE(t8142_stray_words), + .gate_off = t8142_gate_off, + .ngate_off = ARRAY_SIZE(t8142_gate_off), + .gate_coprocs = t8142_gate_coprocs, + .ngate_coprocs = ARRAY_SIZE(t8142_gate_coprocs), + .wake_names = t8142_wake_names, + .nwake_names = ARRAY_SIZE(t8142_wake_names), + /* AppleT8142PMGR's valid-source table: word 8 holds sources 256..267. */ + .wake_last_word = GENMASK(11, 0), +}; + +/* + * SoCs whose sleep was measured and tested, and T8142, whose data is derived and which stops + * at a dry run unless asked otherwise. On every other the driver doesn't bind, and s2idle + * stays the only sleep. */ static const struct of_device_id apple_sleep_of_match[] = { { .compatible = "apple,t8140-sleep", .data = &t8140_sleep_soc }, { .compatible = "apple,t8132-sleep", .data = &t8132_sleep_soc }, + { .compatible = "apple,t8142-sleep", .data = &t8142_sleep_soc }, { .compatible = "apple,t6050-sleep", .data = &t6050_sleep_soc }, { } }; diff --git a/include/linux/soc/apple/sleep.h b/include/linux/soc/apple/sleep.h index b2767f37602dc..7174fc48459f3 100644 --- a/include/linux/soc/apple/sleep.h +++ b/include/linux/soc/apple/sleep.h @@ -108,6 +108,12 @@ bool apple_sleep_coproc_stopped(struct device *dev); */ bool apple_sleep_commit_stops_coprocs(void); +/* + * Untested SoCs: a coprocessor's last stop notes its own step in PMU scratch (kept across a + * WD2 reset), next to the sleep driver's step and the coprocessor's slot. + */ +void apple_sleep_note_sub(u8 step); + /* * The USB host sleeps in place for this sleep, as macOS's does: its always-on domain stays * up through the commit. Its PHY sets it once the controller is in its hibernation state, @@ -300,6 +306,8 @@ static inline bool apple_sleep_coproc_stopped(struct device *dev) return false; } +static inline void apple_sleep_note_sub(u8 step) {} + static inline bool apple_sleep_commit_stops_coprocs(void) { return false; From f5b80629ce259cfeb5601ec9d3f0b32fdbedf9fb Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 12 Nov 2026 21:18:47 +0700 Subject: [PATCH 10/68] drm/asahi: g17: Raise the GPU's domain before stopping it at the commit J815's first real sleep past every check reset the Mac in the first coprocessor stop pass (PMU note 0x44, boot 3c93d5a2), whose only member is the GPU. Its domain read 0x244 at .enter (actual 4: the GPU gates itself between frames, about 95 times a second on J815), and the stop went straight to the RTKit idle poll and the coprocessor's and mailbox's registers, which may not answer below full power; with interrupts off a stalled read ends at WD2. Bring the domain to full power first, as asahi_g17_power_raise() does, keep the word from before for the resume, and touch nothing of the GPU but its domain if the raise times out. Each step is noted in PMU scratch with apple_sleep_note_sub(). Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- drivers/gpu/drm/asahi/g17/sleep.c | 37 +++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/sleep.c b/drivers/gpu/drm/asahi/g17/sleep.c index 7f2d4f6a92591..7b8adb1962ae4 100644 --- a/drivers/gpu/drm/asahi/g17/sleep.c +++ b/drivers/gpu/drm/asahi/g17/sleep.c @@ -359,6 +359,9 @@ struct asahi_g17_commit { u32 saved; u32 lowered; int lower_ret; + /* The domain at the start of the stop, and the raise to full power before any ASC access */ + u32 entry; + int raise_ret; }; /* @@ -374,8 +377,31 @@ static int asahi_g17_commit_stop(void *data) u32 val; c->ran = true; + apple_sleep_note_sub(1); + /* + * The GPU gates itself between frames (~95 times a second on J815), and at the commit its + * domain read 0x244 (actual 4, J815 boot 12505746): its coprocessor's and mailbox's + * registers may not answer there, and with interrupts off a stalled read ends at WD2 (J815 + * boot 3c93d5a2: PMU note 0x44, the first commit stop). Bring it to full power first, as + * asahi_g17_power_raise() does, and keep the word from before for the resume. + */ + c->entry = readl(c->ps); + c->saved = c->entry; + if (FIELD_GET(PS_ACTUAL, c->entry) != PS_ACTIVE) { + writel(asahi_g17_ps_on(c->dev, c->entry, c->entry), c->ps); + c->raise_ret = readl_poll_timeout_atomic(c->ps, val, + FIELD_GET(PS_ACTUAL, val) == PS_ACTIVE, + 10, PS_TIMEOUT_US); + } + apple_sleep_note_sub(2); + if (c->raise_ret) { + /* Its registers can't be trusted to answer: lower the domain only. */ + c->idle[0] = c->raise_ret; + goto lower; + } for (i = 0; i < c->count; i++) c->idle[i] = apple_rtkit_sleep_idle_polled(c->rtk[i], c->cpu[i], &c->idle_us[i]); + apple_sleep_note_sub(3); for (i = 0; i < c->count; i++) { c->status[i] = readl(c->cpu[i] + ASC_CPU_STATUS); apple_rtkit_mailbox_recv_off(c->rtk[i]); @@ -386,10 +412,12 @@ static int asahi_g17_commit_stop(void *data) if (!i && c->bridge) writel(readl(c->gating) | SGX_GATING_HOLD, c->gating); } + apple_sleep_note_sub(4); c->request_ret = c->request ? apple_pmp_report_entry_withdraw_polled(c->request) : 0; + apple_sleep_note_sub(5); - c->saved = readl(c->ps); - writel(c->saved & ~(PS_AUTO_ENABLE | PS_BUSY | PS_FLAGS), c->ps); + /* Off automatic management, still at full power, for the bridge. */ + writel(readl(c->ps) & ~(PS_AUTO_ENABLE | PS_BUSY | PS_FLAGS), c->ps); if (c->bridge) { for (i = 0; i < SGX_BRIDGE_WORDS; i++) c->words[i] = readl(c->bridge + 4 * i); @@ -397,12 +425,15 @@ static int asahi_g17_commit_stop(void *data) for (i = 0; i < SGX_BRIDGE_WORDS; i++) writel(c->words[i] & ~SGX_BRIDGE_ENABLE, c->bridge + 4 * i); } + apple_sleep_note_sub(6); +lower: val = readl(c->ps); writel((val & ~(PS_AUTO_ENABLE | PS_BUSY | PS_FLAGS | PS_TARGET)) | PS_FLAGS, c->ps); c->lower_ret = readl_poll_timeout_atomic(c->ps, c->lowered, !FIELD_GET(PS_ACTUAL, c->lowered) && !(c->lowered & PS_BUSY), 10, PS_TIMEOUT_US); + apple_sleep_note_sub(7); return (c->idle[0] || c->idle[1] || c->request_ret || c->lower_ret) ? 1 : 0; } @@ -672,6 +703,8 @@ bool asahi_g17_commit_finish(struct asahi_g17_commit *c, u32 *saved) c->idle_us[0], c->idle_us[1], c->status[0], c->status[1]); dev_dbg(c->dev, "GPU at the commit: bridge %#x %#x gating %#x, domain %#x now %#x\n", c->words[0], c->words[1], c->words[2], c->saved, c->lowered); + dev_info(c->dev, "GPU domain at the commit stop: %#x, raise to full %d\n", + c->entry, c->raise_ret); *saved = c->saved; } asahi_g17_commit_free(c); From a0a91b99f7162f66cd0d9f129d63345c1233a54a Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 16 Nov 2026 08:42:41 +0700 Subject: [PATCH 11/68] dt-bindings: soc: apple: sleep: Add T8142 T8142 (M5: the J813 and J815 MacBook Airs) has its own sleep controller layout: no pmc-dcp, clock mux, PTD, cluster DCS or DVFM blocks, but the memory side macOS steps down last (four AMCC planes, six SoC NI tables, eight DCS channels and a clock word), the SPMI generation 4 queue, and the complexes' ACC words. Its radio's PCIe link, which the boot loader trains, is trained again after a wake: apple,radio-host and apple,radio-perst name the host and the PERST# GPIO. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- .../bindings/soc/apple/apple,t8140-sleep.yaml | 77 ++++++++++++++++++- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml index bdbe2a5ccadaf..f814d22832130 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml @@ -21,14 +21,15 @@ properties: enum: - apple,t8132-sleep - apple,t8140-sleep + - apple,t8142-sleep reg: minItems: 25 - maxItems: 28 + maxItems: 36 reg-names: minItems: 25 - maxItems: 28 + maxItems: 36 apple,wake-enable: $ref: /schemas/types.yaml#/definitions/uint32-array @@ -60,6 +61,18 @@ properties: description: The USB-C port controller that carries the debug link, stopped for a sleep. + apple,radio-host: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The PCIe host of the radio's link, which the boot loader trained. Its root + port loses its configuration in a deep sleep and is trained again after + the wake. + + apple,radio-perst: + maxItems: 1 + description: + The GPIO that drives the radio's PERST#, held across that retraining. + apple,display-coprocessors: $ref: /schemas/types.yaml#/definitions/phandle-array description: @@ -154,5 +167,65 @@ allOf: - const: clk-perf - const: cluster-dcs - const: ps-prot + - if: + properties: + compatible: + contains: + const: apple,t8142-sleep + then: + required: + - apple,wake-enable + properties: + reg: + minItems: 36 + maxItems: 36 + reg-names: + items: + - const: ps + - const: pwrgate + - const: cpu-start + - const: cllt + - const: cluster + - const: commit + - const: wdt + - const: aon-misc + - const: wake + - const: spmi + - const: ps-aon + - const: spmi-a0 + - const: pmc-voters + - const: clk-perf + - const: dcs + - const: acc-e + - const: acc-p + - const: amcc0 + - const: amcc1 + - const: amcc2 + - const: amcc3 + - const: socni0 + - const: socni1 + - const: socni2 + - const: socni3 + - const: socni4 + - const: socni5 + - const: mcc0 + - const: mcc1 + - const: mcc2 + - const: mcc3 + - const: mcc4 + - const: mcc5 + - const: mcc6 + - const: mcc7 + - const: mem-clk + - if: + not: + properties: + compatible: + contains: + const: apple,t8142-sleep + then: + properties: + apple,radio-host: false + apple,radio-perst: false additionalProperties: false From 4de8bf0cefe51a2e9bd98efd39ed5b2605abd97d Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 16 Nov 2026 08:42:41 +0700 Subject: [PATCH 12/68] arm64: dts: apple: t8142-j813: Describe suspend-to-RAM Add the T8142 sleep controller, the shared PCIe block whose ANS side the wake brings back, and the port controllers' sleep power state, in a dtsi shared by the 13- and 15-inch M5 Airs: their ADTs (27.0) differ only in audio, product and CLPC power-limit properties. J813 includes it; J815 can once its board file describes the display, USB and radio nodes it refers to. The wake sources are the J815 ADT's /arm-io/pmgr ap-wake-sources, the same as T8132's by name. The memory-side regions are the J813 trace's (gig3m), with the same /arm-io/mcc layout on J815. The driver stops every sleep at a dry run unless booted with apple_sleep.untested_commit=1, and uses deep sleep only when asked for. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- .../boot/dts/apple/t8142-j813-j815-sleep.dtsi | 146 ++++++++++++++++++ arch/arm64/boot/dts/apple/t8142-j813.dts | 2 + 2 files changed, 148 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8142-j813-j815-sleep.dtsi diff --git a/arch/arm64/boot/dts/apple/t8142-j813-j815-sleep.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-j815-sleep.dtsi new file mode 100644 index 0000000000000..387c88c66d9a6 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j813-j815-sleep.dtsi @@ -0,0 +1,146 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Suspend-to-RAM on the 13- and 15-inch M5 MacBook Air (J813, J815): the sleep controller, + * the shared PCIe block the wake brings back, and the port controllers' sleep power state. + * Included at the end of each board's device tree, after the nodes it refers to. + * + * The boot core's power gate (cluster_pwrgate) and the DCP DART's PS write-disable bit come + * with the board's own nodes (aurora-silicon/linux#1942, #1941). + */ + +#include + +/* + * Suspend-to-RAM (apple,t8142-sleep): derived from macOS 27.2.1 and T8132's measurements, and + * dry-run gated in the driver (apple_sleep.deep, apple_sleep.untested_commit). The J813 and J815 + * ADTs (27.0) differ only in audio, product and CLPC power-limit properties: every block, wake + * source, GPIO and PCIe window below is the same on both. + */ +&{/soc} { + /* + * Suspend-to-RAM. The blocks are T8132's, at the same J815 ADT indices: /arm-io/pmgr + * reg[32] (ps), [34] (pwrgate), [42] (cpu-start), [45] (cllt; EARLY_WAKEUP_CFG at + * +0x50), [36] (cluster), [40] + 0x4000 (commit), [38] (aon-misc), [4] (wake: nine mask + * and nine status words), [1] (ps-aon), /arm-io/wdt, nub-spmi0, nub-spmi-a0, the + * PMC's voter floors (as &pmc), and the SoC and DCS perf-state words that + * AppleT8142PMGR::setPerfState writes (reg[2] + 0x24000, + 0x25000). + * Derived from macOS 27.2.1 and T8132's measurements, never run on an M5: the driver + * stops each sleep at a dry run unless booted with apple_sleep.untested_commit=1, + * and deep sleep is only used when asked for (mem_sleep). + */ + sleep: sleep-controller@380700000 { + compatible = "apple,t8142-sleep"; + reg = <0x3 0x80700000 0x0 0x18000>, + <0x3 0x80724000 0x0 0x2000>, + <0x3 0x80734000 0x0 0x10>, + <0x3 0x80768000 0x0 0x54>, + <0x3 0x80780000 0x0 0x8>, + <0x3 0x882d4000 0x0 0x4>, + <0x3 0x882b0000 0x0 0x30>, + <0x3 0x882b8000 0x0 0x44>, + <0x3 0x88004000 0x0 0x50>, + /* SPMI gen 4: queue at +0x200..0x220, notify enable/ack +0x420/+0x620 */ + <0x3 0x88714000 0x0 0x1000>, + <0x3 0x88280000 0x0 0x10000>, + /* nub-spmi-a0's notify enable word (gen 4: +0x420; gen 1 had +0x40) */ + <0x3 0x88908420 0x0 0x4>, + <0x3 0x82700000 0x0 0x10000>, + <0x3 0x80024000 0x0 0x4>, + <0x3 0x80025000 0x0 0x4>, + /* + * Each complex's ACC word 0x40f8 (ADT pmgr reg[7] E, reg[18] P, + 0x40f8), + * which AppleT8142PMGR sets to 1 after the complex powers on and at the + * end of restoreHW. + */ + <0x2 0x10e440f8 0x0 0x4>, + <0x2 0x11e440f8 0x0 0x4>, + /* + * The memory side macOS steps down last (J813 trace, same ADT mcc layout + * on J815): each AMCC plane's +0x28000 word (mcc reg[1], planes 0x40000 + * apart), the six SoC NI tables (reg[2..7]), the eight DCS channels' + * words from +0x580 (reg[10..17]) and the clock word 0x380038000. + */ + <0x2 0x20028000 0x0 0x8>, + <0x2 0x20068000 0x0 0x8>, + <0x2 0x200a8000 0x0 0x8>, + <0x2 0x200e8000 0x0 0x8>, + <0x2 0x4f010000 0x0 0x80>, + <0x2 0x50010000 0x0 0x80>, + <0x2 0x51010000 0x0 0x80>, + <0x2 0x52010000 0x0 0x80>, + <0x2 0x53010000 0x0 0x80>, + <0x2 0x54010000 0x0 0x80>, + <0x2 0x21000580 0x0 0x104>, + <0x2 0x21200580 0x0 0x104>, + <0x2 0x21400580 0x0 0x104>, + <0x2 0x21600580 0x0 0x104>, + <0x2 0x21800580 0x0 0x104>, + <0x2 0x21a00580 0x0 0x104>, + <0x2 0x21c00580 0x0 0x104>, + <0x2 0x21e00580 0x0 0x104>, + <0x3 0x80038000 0x0 0x4>; + reg-names = "ps", "pwrgate", "cpu-start", "cllt", "cluster", + "commit", "wdt", "aon-misc", "wake", "spmi", + "ps-aon", "spmi-a0", "pmc-voters", "clk-perf", "dcs", + "acc-e", "acc-p", + "amcc0", "amcc1", "amcc2", "amcc3", + "socni0", "socni1", "socni2", "socni3", "socni4", "socni5", + "mcc0", "mcc1", "mcc2", "mcc3", "mcc4", "mcc5", "mcc6", "mcc7", + "mem-clk"; + /* + * From the J815 ADT's /arm-io/pmgr ap-wake-sources, the same sources + * as T8132's by name: NUB.SPMI0.SW3, ATC0.USBWakeup, SMC.CPUWakeupAP, + * SMC.OutboxNotEmpty, MTP.DOCK.CHANNELS.AP0.IRQ and MTP.OutboxNotEmpty. + */ + apple,wake-enable = <152 72 168 190 89 108>; + apple,display-coprocessors = <&dcp>; + /* ANS's link's shared block, and the radio's link, which only aura trains */ + apple,apcie = <&apcie_shared>; + apple,radio-host = <&pcie0>; + /* ADT pci-bridge0 function-perst: AP GPIO 192 */ + apple,radio-perst = <&pinctrl_ap 192 GPIO_ACTIVE_LOW>; + apple,pinctrl = <&pinctrl_ap>; + /* The ADT's no-restore-gpio-pins: reading pin 78 raises an SError. */ + apple,pinctrl-skip-pins = <78 203>; + }; + + /* + * ANS's side of the shared PCIe block, which the sleep controller brings back after a + * real sleep in AppleT8142PCIe's order (as aura's j813_n1.c at boot): ADT /arm-io/apcie + * reg[1] (rc), [2] (phy-block; its PHY-PHY control words are reg[3], 0x20000 in), [4] + * (phy-ip) and [5] (axi2af, as far as its tables reach). Then the radio's port 0, which + * it trains again after the wake: reg[8] (radio-port), [10] (radio-lane) and the root + * port's configuration space (radio-cfg, the ECAM's first 4 KiB). reg[6] (clkgen, the + * pcieclkgen whose PLLs APCIECoreRCGen4 shuts down before the power goes; AppleT8142PCIe + * maps reg[7] as its AUS5 AON top, unused here). aura copies the ADT's + * apcie-{axi2af,phy,phy-ip-pll,phy-ip-auspma}-tunables and pci-bridge0's + * apcie-config-tunables and pcie-rc{,-gen3-shadow,-gen4-shadow}-tunables here. No + * driver binds it. + */ + apcie_shared: pcie-shared@48c000000 { + reg = <0x4 0x8c000000 0x0 0x4000>, + <0x4 0x8f000000 0x0 0x40000>, + <0x4 0x8f040000 0x0 0x20000>, + <0x4 0x8e000000 0x0 0x24000>, + <0x4 0x88028000 0x0 0x8000>, + <0x4 0x8f010000 0x0 0x4000>, + <0x1c 0xb0000000 0x0 0x1000>, + <0x4 0x8d044000 0x0 0x4000>; + reg-names = "rc", "phy-block", "phy-ip", "axi2af", + "radio-port", "radio-lane", "radio-cfg", "clkgen"; + }; +}; + +/* + * The port controllers' system power state (SSPS 3 before the commit, 0 at the wake), as + * macOS's AppleHPM sends it on the J700 and J714s, measured there on the same SN201202x; + * not traced on an M5 Air. Only a firmware-driven sleep sends it, and a controller that + * does not take S3 refuses the sleep (tipd sleep_s3_refuse). + */ +&hpm0 { + apple,sleep-ssps; +}; + +&hpm1 { + apple,sleep-ssps; +}; diff --git a/arch/arm64/boot/dts/apple/t8142-j813.dts b/arch/arm64/boot/dts/apple/t8142-j813.dts index ed107c1f2c52d..9a3c3d3f515ec 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813.dts +++ b/arch/arm64/boot/dts/apple/t8142-j813.dts @@ -268,3 +268,5 @@ }; /* Unexposed chassis port instances remain described and disabled. */ + +#include "t8142-j813-j815-sleep.dtsi" From 5d6f462704f6479fd213c64e9c9693f2825e40c3 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 07:01:16 +0100 Subject: [PATCH 13/68] drm/apple: iomfb: firmware 27.2: the AP link's release is A550 27.2 moved the unnamed A500 (the AP link's release, which only a firmware sleep sends) to A550, with the IOMFB calls around it: t8142dcp 26B123 compares 'A550' and 'A550' | 1 at 0x1df68c in the dispatch whose 26A428 copy at 0x1de0dc compares 'A500' and 'A501'. Without the entry dcp_s2r_capable() is false on 27.2 and the DCP never stops for a sleep. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/iomfb_v27.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/apple/iomfb_v27.c b/drivers/gpu/drm/apple/iomfb_v27.c index 27e5eef581db2..5902edc7013ee 100644 --- a/drivers/gpu/drm/apple/iomfb_v27.c +++ b/drivers/gpu/drm/apple/iomfb_v27.c @@ -210,6 +210,11 @@ static const struct dcp_method_entry dcp_methods_27_2[dcpep_num_methods] = { IOMFB_METHOD("A529", iomfbep_abort_swaps_dcp), IOMFB_METHOD("A534", dcpep_set_power_state), IOMFB_METHOD("A533", dcpep_register_dfb_surface), + /* + * The AP link's release: t8142dcp 26B123 compares 'A550', then 'A550' | 1, in the + * dispatch where 26A428's compares 'A500' (0x1df68c vs 0x1de0dc, same code). + */ + IOMFB_METHOD("A550", dcpep_unnamed_500), }; /* From 27be95e7fee8112fa2676a36a0c99e61e71ec1e0 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 07:20:45 +0100 Subject: [PATCH 14/68] soc: apple: sleep: T8142: the PMU's RTC alarm after the S2R timer, as macOS sends it macOS 27.2 on the J813 sends the PMU four commands 0.11 to 0.25 ms after the S2R timer (traced under aura's virtualized SPTM, run g01): RTC_CTL read (0x41), the 4-byte compare at 0x2008, 0x200e <- 0, RTC_CTL <- 0x41 -- T6050's post-timer step at the same addresses. The T8142 ops had no post_timer: the timer started (PMU note 0x67) and WD2 reset the SoC. TEST: the compare is now + apple_sleep.t8142_wake_s (default 30), which doubles as a wake source. Signed-off-by: Thomas Glanzmann --- drivers/soc/apple/sleep.c | 74 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index aecd5f18961fa..f821a221ce7dc 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -7010,6 +7010,74 @@ static void t8142_commit_note(struct apple_sleep *s) sleep_note(s, 0x65); } +/* + * The PMU's RTC alarm after the S2R timer, as macOS 27.2 sends it on the J813 (traced + * 2026-11-16, run g01: 0.11 to 0.25 ms after the timer, boot core): read RTC_CTL (0x41), + * the 4-byte compare at 0x2008, 0x200e <- 0, RTC_CTL <- 0x41; 0x43 first if it had fired. + * The same registers and order as T6050's post-timer step (apple,pmu-alarm-rearm 0x43 0x41). + * Without it the SoC never goes down after the timer and WD2 resets it (J813, PMU note 0x67). + * TEST: the compare is now + apple_sleep.t8142_wake_s (0: macOS's own compare as found). + */ +static unsigned int t8142_wake_s = 30; +module_param(t8142_wake_s, uint, 0644); +MODULE_PARM_DESC(t8142_wake_s, "T8142 TEST: PMU RTC alarm this many s after the commit (0: keep the PMU's)"); +static u8 t8142_alarm[4]; +static bool t8142_alarm_ok; +static int t8142_post_ret = -ENODATA; +static u64 t8142_alarm_counter; + +static void t8142_pre_commit(struct apple_sleep *s) +{ + u32 mask = s->soc->spmi_notify_sleep; + u8 ticks[8] = {}; + + t8142_alarm_ok = false; + t8142_post_ret = -ENODATA; + if (s->spmi) { + t6050_sleep_pmu_drain(s); + if (!t6050_sleep_pmu_xfer_post(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_COMPARE, + NULL, t8142_alarm, 4) && + !t6050_sleep_pmu_xfer_post(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_COUNTER, + NULL, ticks, 6)) { + t8142_alarm_counter = get_unaligned_le64(ticks) >> 16; + if (t8142_wake_s) + put_unaligned_le32(t8142_alarm_counter + t8142_wake_s, t8142_alarm); + t8142_alarm_ok = true; + } + } + t8132_pre_commit(s); +} + +static void t8142_post_timer(struct apple_sleep *s) +{ + u32 mask = s->soc->spmi_notify_sleep & ~M5_SPMI_IRQ_DONE; + u8 ctl = 0, v; + int ret; + + if (!t8142_alarm_ok) + return; + ret = t6050_sleep_pmu_xfer_post(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_CTL, NULL, &ctl, 1); + if (!ret && (ctl & T6050_RTC_CTL_FIRED)) { + v = 0x43; + ret = t6050_sleep_pmu_xfer_post(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_CTL, &v, + NULL, 1); + } + if (!ret) + ret = t6050_sleep_pmu_xfer_post(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_COMPARE, + t8142_alarm, NULL, 4); + if (!ret) { + v = 0; + ret = t6050_sleep_pmu_xfer_post(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_MASK, &v, + NULL, 1); + } + if (!ret) { + v = 0x41; + ret = t6050_sleep_pmu_xfer_post(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_CTL, &v, + NULL, 1); + } + t8142_post_ret = ret; +} + /* * T8142's memory side, as macOS steps it down 4.6 to 2.7 ms before the S2R timer (J813, 27.2.1, * all ten cores: gig3m's trace, gist 89aedeca, 2026-11-15; the J815 ADT has the same mcc @@ -7159,6 +7227,9 @@ static void t8142_wake(struct apple_sleep *s) u32 val; int i; + pr_info("apple-sleep: T8142 PMU alarm after the timer: %d (counter %llu, compare %u)\n", + t8142_post_ret, t8142_alarm_counter, get_unaligned_le32(t8142_alarm)); + s->cluster_e_ret = t8142_cluster_on(s, soc->cluster_cpu[0], s->acc_e); s->cluster_p_ret = t8142_cluster_on(s, soc->cluster_cpu[1], s->acc_p); @@ -7354,7 +7425,8 @@ static const struct apple_sleep_ops t8142_sleep_ops = { .last_mile = t8142_last_mile, /* WD2 is at T8132's address (/arm-io/wdt), so the same stub restarts it. */ .resume = t8132_resume_stub, - .pre_commit = t8132_pre_commit, + .pre_commit = t8142_pre_commit, + .post_timer = t8142_post_timer, .wake = t8142_wake, .aic_mask_all = aic_sleep_mask_all, .aic_ack = aic_sleep_ack, From 1a17e2a0946a0ac7d2a2f5b9a130838bfef6c74d Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 08:33:01 +0100 Subject: [PATCH 15/68] soc: apple: sleep: T8142: the PMU commands carry their byte count t6050_sleep_pmu_xfer_post() takes the opcode with the byte count in its low bits, as t6050_sleep_pmu_xfer() builds it (macOS sends 0x33 for the 4-byte compare). The post-timer step passed the bare opcode, so the alarm read before the commit failed and nothing was sent after the timer (J813: PMU note detail 0xc3, -ENODATA). Signed-off-by: Thomas Glanzmann --- drivers/soc/apple/sleep.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index f821a221ce7dc..e7f9bce497d0b 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -7026,6 +7026,13 @@ static bool t8142_alarm_ok; static int t8142_post_ret = -ENODATA; static u64 t8142_alarm_counter; +/* The opcode carries the byte count, as t6050_sleep_pmu_xfer() builds it (macOS: 0x33 for 4). */ +static int t8142_pmu(struct apple_sleep *s, u32 mask, u8 opcode, u16 address, const u8 *wr, u8 *rd, + unsigned int len) +{ + return t6050_sleep_pmu_xfer_post(s, mask, opcode | (len - 1), address, wr, rd, len); +} + static void t8142_pre_commit(struct apple_sleep *s) { u32 mask = s->soc->spmi_notify_sleep; @@ -7035,9 +7042,9 @@ static void t8142_pre_commit(struct apple_sleep *s) t8142_post_ret = -ENODATA; if (s->spmi) { t6050_sleep_pmu_drain(s); - if (!t6050_sleep_pmu_xfer_post(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_COMPARE, + if (!t8142_pmu(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_COMPARE, NULL, t8142_alarm, 4) && - !t6050_sleep_pmu_xfer_post(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_COUNTER, + !t8142_pmu(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_COUNTER, NULL, ticks, 6)) { t8142_alarm_counter = get_unaligned_le64(ticks) >> 16; if (t8142_wake_s) @@ -7056,23 +7063,23 @@ static void t8142_post_timer(struct apple_sleep *s) if (!t8142_alarm_ok) return; - ret = t6050_sleep_pmu_xfer_post(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_CTL, NULL, &ctl, 1); + ret = t8142_pmu(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_CTL, NULL, &ctl, 1); if (!ret && (ctl & T6050_RTC_CTL_FIRED)) { v = 0x43; - ret = t6050_sleep_pmu_xfer_post(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_CTL, &v, + ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_CTL, &v, NULL, 1); } if (!ret) - ret = t6050_sleep_pmu_xfer_post(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_COMPARE, + ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_COMPARE, t8142_alarm, NULL, 4); if (!ret) { v = 0; - ret = t6050_sleep_pmu_xfer_post(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_MASK, &v, + ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_MASK, &v, NULL, 1); } if (!ret) { v = 0x41; - ret = t6050_sleep_pmu_xfer_post(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_CTL, &v, + ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_CTL, &v, NULL, 1); } t8142_post_ret = ret; From c911aeaa6b947f82e7654715ceb8f2632e55fd04 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 10:14:32 +0100 Subject: [PATCH 16/68] soc: apple: sleep: power off PMP after its final T8142 stop The PMP firmware was idled and its RUN bit cleared, but its always-on power domain stayed at target f. macOS lowers the AP-owned PMP domain after the final idle and SRAM backup. PMS_SRAM then gates automatically while retaining target f. Do the same before the final memory and CPU sequence. On the combined J813 test stack this permits a real physical sleep and return, with the boot ID preserved and /sys/power/state returning 0. Device recovery and the other local preparation changes are still under investigation. Signed-off-by: Thomas Glanzmann --- drivers/soc/apple/sleep.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index e7f9bce497d0b..1480076b28e98 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -6966,6 +6966,10 @@ static void t8142_lower_io(struct apple_sleep *s) apple_sleep_lower_apcie(s); s->ans_off_ret = sleep_ps_wait_off(s, s->soc->ps.ans); } + /* PMP's callback has idled the firmware and saved SRAM; RUN is clear. */ + sleep_ps_lower(s, 0x598); + if (sleep_ps_wait_off(s, 0x598)) + dev_warn(s->dev, "PMP power domain did not turn off\n"); sleep_note(s, 0x63); } From 57596beeea415e4abb756a9db5056f60deaa8ef1 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 11:49:45 +0100 Subject: [PATCH 17/68] pinctrl: apple: mask level interrupts before acknowledging them After a J813 deep-sleep wake, headphone GPIO 100 can be in level-low interrupt mode while its Linux IRQ is disabled and marked masked. The generic mask_ack_irq() fallback skips irq_mask() in that state, leaving the asserted input to repeatedly trigger AP GPIO parent IRQ 347. CPU0 can stay in IRQ dispatch and starve I2C completions and resume timers. Provide irq_mask_ack so the pin is always masked in hardware before acknowledging it. A clean-module hardware repeat completed parallel device resume, with CS42L84 and AOP resume succeeding, without the diagnostic interrupt or polling used to investigate the stall. Signed-off-by: Thomas Glanzmann --- drivers/pinctrl/pinctrl-apple-gpio.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c index 3e8ab5a9b933b..2f0c25e38c67f 100644 --- a/drivers/pinctrl/pinctrl-apple-gpio.c +++ b/drivers/pinctrl/pinctrl-apple-gpio.c @@ -315,6 +315,13 @@ static void apple_gpio_irq_mask(struct irq_data *data) gpiochip_disable_irq(gc, data->hwirq); } +static void apple_gpio_irq_mask_ack(struct irq_data *data) +{ + /* Resume can leave the pin enabled while the IRQ core still has it masked. */ + apple_gpio_irq_mask(data); + apple_gpio_irq_ack(data); +} + static void apple_gpio_irq_unmask(struct irq_data *data) { struct gpio_chip *gc = irq_data_get_irq_chip_data(data); @@ -382,6 +389,7 @@ static const struct irq_chip apple_gpio_irqchip = { .name = "Apple-GPIO", .irq_startup = apple_gpio_irq_startup, .irq_ack = apple_gpio_irq_ack, + .irq_mask_ack = apple_gpio_irq_mask_ack, .irq_mask = apple_gpio_irq_mask, .irq_unmask = apple_gpio_irq_unmask, .irq_set_type = apple_gpio_irq_set_type, From eb11acbb0779921c1416b19a36f8d25600dc30a2 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 16 Nov 2026 17:57:11 +0700 Subject: [PATCH 18/68] arm64: spin table: the pen's last WFI at EL1 on request; start a timed-out core again A platform sleep driver can ask for the parked cores' last deep WFI at EL1 (spin_table_pen_deep_el1()), with the MMU off, every exception masked and stage 2 off, instead of at the kernel's EL. A core powered on again after a sleep stays in spin_table_cpus_off until its own cpu_postboot. Before, the bit was cleared before the start, so a core whose start timed out was never pulsed again on the next online attempt. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- arch/arm64/include/asm/cpu_ops.h | 2 ++ arch/arm64/kernel/head.S | 22 ++++++++++++++++++++++ arch/arm64/kernel/smp_spin_table.c | 21 +++++++++++++++------ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/cpu_ops.h b/arch/arm64/include/asm/cpu_ops.h index c42daea9d5263..450c31521b002 100644 --- a/arch/arm64/include/asm/cpu_ops.h +++ b/arch/arm64/include/asm/cpu_ops.h @@ -75,6 +75,7 @@ void spin_table_unhold_parked(void); int spin_table_stop_parked(void); void spin_table_release_stopped(void); void spin_table_pen_deep_arm(bool on); +void spin_table_pen_deep_el1(bool on); void spin_table_stop_finished(void); bool spin_table_cpus_stuck(void); #else @@ -92,6 +93,7 @@ static inline int spin_table_stop_parked(void) static inline void spin_table_release_stopped(void) {} static inline void spin_table_pen_deep_arm(bool on) {} +static inline void spin_table_pen_deep_el1(bool on) {} static inline void spin_table_stop_finished(void) {} static inline int spin_table_set_power_ops(const struct spin_table_power_ops *ops) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index fdb2a852e67df..f1ed960e10530 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -424,6 +424,28 @@ pen: ldr x4, [x3] orr x4, x4, #1 orr x4, x4, #0x8000000000000000 msr_s sys_reg(3, 5, 15, 6, 2), x4 + /* + * 2 = the sleep driver asked for the last WFI at EL1 (apple_sleep.el1_wfi=2): from EL2, + * MMU off (as here), every exception masked, no traps, stage 2 off, fast IPIs acked. + */ + cmp x5, #2 + b.ne 2f + mrs x4, CurrentEL + cmp x4, #CurrentEL_EL2 + b.ne 2f + mov x4, #1 + msr_s sys_reg(3, 5, 15, 1, 1), x4 + mov_q x4, INIT_SCTLR_EL1_MMU_OFF + msr_s SYS_SCTLR_EL12, x4 + isb + mov_q x4, (HCR_RW | HCR_E2H) + msr hcr_el2, x4 + mov x4, #(PSR_MODE_EL1h | PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT) + msr spsr_el2, x4 + adr x4, 2f + msr elr_el2, x4 + isb + eret 2: dsb sy isb wfi diff --git a/arch/arm64/kernel/smp_spin_table.c b/arch/arm64/kernel/smp_spin_table.c index 76acaf51c416e..7db8cc98bd166 100644 --- a/arch/arm64/kernel/smp_spin_table.c +++ b/arch/arm64/kernel/smp_spin_table.c @@ -272,13 +272,19 @@ int spin_table_stop_parked(void) return -ETIMEDOUT; } -static bool spin_table_pen_deep_armed; +static bool spin_table_pen_deep_armed, spin_table_pen_el1_on; void spin_table_pen_deep_arm(bool on) { spin_table_pen_deep_armed = on; } +/* The pen's last WFI at EL1 (2) instead of the kernel's EL (1), for the next release */ +void spin_table_pen_deep_el1(bool on) +{ + spin_table_pen_el1_on = on; +} + static void spin_table_pen_deep_set(unsigned long on) { void *start = (void *)&secondary_pen_deep; @@ -292,7 +298,7 @@ void spin_table_release_stopped(void) { WRITE_ONCE(spin_table_stop_released, true); if (spin_table_pen_deep_armed) - spin_table_pen_deep_set(1); + spin_table_pen_deep_set(spin_table_pen_el1_on ? 2 : 1); dsb(ish); sev(); } @@ -323,12 +329,14 @@ static int smp_rvbar_spin_table_cpu_boot(unsigned int cpu) /* The CPU may run straight into the pen: release it before it starts. */ write_pen_release(mpidr); - if (cpumask_test_and_clear_cpu(cpu, &spin_table_cpus_off)) { + if (cpumask_test_cpu(cpu, &spin_table_cpus_off)) { + /* + * Still off until it runs smp_rvbar_spin_table_postboot(): a start that times out + * leaves it here, so another online attempt pulses it again. + */ ret = spin_table_power->cpu_on(mpidr); - if (ret) { - cpumask_set_cpu(cpu, &spin_table_cpus_off); + if (ret) return ret; - } } else if (cpumask_test_cpu(cpu, &spin_table_cpus_parked)) { cpumask_set_cpu(cpu, &spin_table_cpus_unpark); } @@ -444,6 +452,7 @@ static int smp_rvbar_spin_table_cpu_kill(unsigned int cpu) static void smp_rvbar_spin_table_postboot(void) { + cpumask_clear_cpu(smp_processor_id(), &spin_table_cpus_off); if (READ_ONCE(spin_table_power) && spin_table_power->cpu_restore) spin_table_power->cpu_restore(read_cpuid_mpidr() & MPIDR_HWID_BITMASK); } From b33afb98c0a2a77965afe4e789dfe57b736ccfc2 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 16 Nov 2026 18:25:18 +0700 Subject: [PATCH 19/68] soc: apple: sleep: T8142: from the dry-run gate to a real sleep and wake On J815 (boot e1d118f8) T8142 now goes past the commit, sleeps and comes back through the boot loader's resume entry (boot object resumes 0 -> 1), with the display and NVMe back. Before, every committed sleep ended in a WD2 reset about five seconds after the commit. The work below compared every power word Linux leaves on with macOS's own entry (J815 26B131 trace) and with macOS's state at its commit (J813 end state from Thomas Glanzmann's trace), using the J815 ADT's PMGR parent tree. Entry, what got the sleep engine past the commit: - apple_sleep.dispext (default Y): the external DCPs are lowered with the display, in macOS's order (DISPEXT0, DISPEXT1, DISP). Their DARTs' PS write-disable bits read set on J815 and are cleared first, a running firmware is stopped cold, and the words come back after a refusal and at the wake. An external DCP whose domain is up but which the device tree doesn't list in apple,display-coprocessors refuses the sleep instead of letting the engine wait on it. - apple_sleep.extra_off (default Y): the OS-managed words macOS has off at its commit that no other step lowered (SIO_CPU, left up by iBoot with no driver; GLOBAL_AUX_CTRL0/1; FPWM0; the PCIe OCLAs under APCIE_SYS_GP/ST; ATC2/3; the displays' ADMA words), children first, each only if on, and back at the wake once its parent is on. - apple_sleep.pmp_off (default Y): PMP's domain stays off after its final stop, with its word saved and restored at the wake (Thomas's finding on J813, made switchable). - The PMU's RTC alarm after the S2R timer as a switchable step (apple_sleep.pmu_alarm), XNU's boot-time AUTO_ENABLE words (apple_sleep.boot_auto), the parked cores' deep WFI before the boot core's last mile (apple_sleep.early_wfi), and the clkgen and memory-side restores at the wake (sleep-t8142-mem.h). ps_keep, mem_boot and mem_floor are experiments, mem_boot/mem_floor off by default. Diagnostics: a commit digest in PMU scratch, written only to 0x8308..0x831e (from 0x831f the scratch holds data that isn't Linux's), the dry run's full list of power words on, marked against macOS's commit state, and one line per core start after a wake (apple_sleep.cpu_on_trace). Still open: after the wake only the first core started in each complex comes up; the external DCPs' firmware isn't restarted; the SMC woke this sleep after 0.46 s. Still gated by apple_sleep.untested_commit. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- .../boot/dts/apple/t8142-j813-j815-sleep.dtsi | 32 +- drivers/soc/apple/sleep-t8142-mem.h | 1141 +++++++++ drivers/soc/apple/sleep.c | 2128 +++++++++++++++-- 3 files changed, 3149 insertions(+), 152 deletions(-) create mode 100644 drivers/soc/apple/sleep-t8142-mem.h diff --git a/arch/arm64/boot/dts/apple/t8142-j813-j815-sleep.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-j815-sleep.dtsi index 387c88c66d9a6..08df0f8f46787 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813-j815-sleep.dtsi +++ b/arch/arm64/boot/dts/apple/t8142-j813-j815-sleep.dtsi @@ -64,12 +64,12 @@ <0x2 0x20068000 0x0 0x8>, <0x2 0x200a8000 0x0 0x8>, <0x2 0x200e8000 0x0 0x8>, - <0x2 0x4f010000 0x0 0x80>, - <0x2 0x50010000 0x0 0x80>, - <0x2 0x51010000 0x0 0x80>, - <0x2 0x52010000 0x0 0x80>, - <0x2 0x53010000 0x0 0x80>, - <0x2 0x54010000 0x0 0x80>, + <0x2 0x4f010000 0x0 0x104>, + <0x2 0x50010000 0x0 0x104>, + <0x2 0x51010000 0x0 0x104>, + <0x2 0x52010000 0x0 0x104>, + <0x2 0x53010000 0x0 0x104>, + <0x2 0x54010000 0x0 0x104>, <0x2 0x21000580 0x0 0x104>, <0x2 0x21200580 0x0 0x104>, <0x2 0x21400580 0x0 0x104>, @@ -78,7 +78,18 @@ <0x2 0x21a00580 0x0 0x104>, <0x2 0x21c00580 0x0 0x104>, <0x2 0x21e00580 0x0 0x104>, - <0x3 0x80038000 0x0 0x4>; + <0x3 0x80038000 0x0 0x4>, + /* + * What the deep sleep loses and XNU restores at the wake (J813 ten-core + * trace, 2026-11-16): the PMGR clkgen's 126 slots (0x20 apart from + * 0x380038100) and each AMCC plane's control words (+0x2a000..+0x2e003). + * The SoC NI tables above reach their strobe word at +0x100. + */ + <0x3 0x80038100 0x0 0xfc0>, + <0x2 0x2002a000 0x0 0x4004>, + <0x2 0x2006a000 0x0 0x4004>, + <0x2 0x200aa000 0x0 0x4004>, + <0x2 0x200ea000 0x0 0x4004>; reg-names = "ps", "pwrgate", "cpu-start", "cllt", "cluster", "commit", "wdt", "aon-misc", "wake", "spmi", "ps-aon", "spmi-a0", "pmc-voters", "clk-perf", "dcs", @@ -86,13 +97,18 @@ "amcc0", "amcc1", "amcc2", "amcc3", "socni0", "socni1", "socni2", "socni3", "socni4", "socni5", "mcc0", "mcc1", "mcc2", "mcc3", "mcc4", "mcc5", "mcc6", "mcc7", - "mem-clk"; + "mem-clk", "clk-slots", + "amcc-cfg0", "amcc-cfg1", "amcc-cfg2", "amcc-cfg3"; /* * From the J815 ADT's /arm-io/pmgr ap-wake-sources, the same sources * as T8132's by name: NUB.SPMI0.SW3, ATC0.USBWakeup, SMC.CPUWakeupAP, * SMC.OutboxNotEmpty, MTP.DOCK.CHANNELS.AP0.IRQ and MTP.OutboxNotEmpty. */ apple,wake-enable = <152 72 168 190 89 108>; + /* + * The DCP, then the external DCPs once the tree describes them (dcpext0, dcpext1): + * the sleep lowers them with the display, and refuses while an undescribed one is up. + */ apple,display-coprocessors = <&dcp>; /* ANS's link's shared block, and the radio's link, which only aura trains */ apple,apcie = <&apcie_shared>; diff --git a/drivers/soc/apple/sleep-t8142-mem.h b/drivers/soc/apple/sleep-t8142-mem.h new file mode 100644 index 0000000000000..5b7a51ba8e1a1 --- /dev/null +++ b/drivers/soc/apple/sleep-t8142-mem.h @@ -0,0 +1,1141 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * T8142: XNU's AppleT8142MCC start as macOS 27.2 runs it on the J813 (trace g01, 2026-11-16), + * every memory-side access in its order: op bit 0 write, bit 1 64-bit, bit 4 a read that comes + * before the first write of its word (iBoot's value: the fingerprint). Included by sleep.c. + */ +/* Generated from the J813 trace g01 (XNU's AppleT8142MCC start, -218749 .. -218594 ms): 1120 records */ +static const u64 t8142_mem_pages[] = { + 0x220008000ULL, 0x220028000ULL, 0x22002c000ULL, 0x220068000ULL, + 0x22006c000ULL, 0x2200a8000ULL, 0x2200ac000ULL, 0x2200e8000ULL, + 0x2200ec000ULL, 0x221000000ULL, 0x221004000ULL, 0x221200000ULL, + 0x221204000ULL, 0x221400000ULL, 0x221404000ULL, 0x221600000ULL, + 0x221604000ULL, 0x221800000ULL, 0x221804000ULL, 0x221a00000ULL, + 0x221c00000ULL, 0x221e00000ULL, 0x24f010000ULL, 0x24f014000ULL, + 0x250010000ULL, 0x250014000ULL, 0x251010000ULL, 0x251014000ULL, + 0x252010000ULL, 0x252014000ULL, 0x253010000ULL, 0x253014000ULL, + 0x254010000ULL, 0x254014000ULL, +}; + +static const struct t8142_mem_op t8142_mem_boot[] = { + { 0x221001d50, 0x2400240, 0x0 }, + { 0x221201d50, 0x2400240, 0x0 }, + { 0x221401d50, 0x2400240, 0x0 }, + { 0x221601d50, 0x2400240, 0x0 }, + { 0x221801d50, 0x2400240, 0x0 }, + { 0x221a01d50, 0x2400240, 0x0 }, + { 0x221c01d50, 0x2400240, 0x0 }, + { 0x221e01d50, 0x2400240, 0x0 }, + { 0x22000a034, 0x8, 0x0 }, + { 0x22000a038, 0x10, 0x0 }, + { 0x22000a038, 0x10, 0x0 }, + { 0x22000a03c, 0x20, 0x0 }, + { 0x22000a03c, 0x20, 0x0 }, + { 0x22000a03c, 0x20, 0x0 }, + { 0x22000a008, 0x20, 0x0 }, + { 0x22000a008, 0x20, 0x0 }, + { 0x22000a01c, 0x20, 0x0 }, + { 0x22000a020, 0xa, 0x0 }, + { 0x22000a02c, 0x20, 0x0 }, + { 0x22000a044, 0x10, 0x0 }, + { 0x22000a04c, 0x20, 0x0 }, + { 0x22000a054, 0x20, 0x0 }, + { 0x22000a07c, 0x10, 0x0 }, + { 0x22000a040, 0x10, 0x0 }, + { 0x22000a00c, 0x20, 0x0 }, + { 0x22000a010, 0x20, 0x0 }, + { 0x22000a014, 0x20, 0x0 }, + { 0x22000a018, 0x20, 0x0 }, + { 0x22000a078, 0x20, 0x0 }, + { 0x22000a024, 0x20, 0x0 }, + { 0x22000a030, 0x8, 0x0 }, + { 0x22000a058, 0x20, 0x0 }, + { 0x22000a058, 0x20, 0x0 }, + { 0x22000a058, 0x20, 0x0 }, + { 0x22000a000, 0x20, 0x0 }, + { 0x22000a000, 0x20, 0x0 }, + { 0x22000a000, 0x20, 0x0 }, + { 0x22000a000, 0x20, 0x0 }, + { 0x22000a004, 0x4, 0x0 }, + { 0x22000a004, 0x4, 0x0 }, + { 0x22000a004, 0x4, 0x0 }, + { 0x22000a074, 0x4, 0x0 }, + { 0x22000a060, 0x4, 0x0 }, + { 0x22000a068, 0x4, 0x0 }, + { 0x22000a070, 0x4, 0x0 }, + { 0x22000a050, 0x20, 0x0 }, + { 0x22000a06c, 0x4, 0x0 }, + { 0x22000a05c, 0x4, 0x0 }, + { 0x22000a05c, 0x4, 0x0 }, + { 0x22000a05c, 0x4, 0x0 }, + { 0x22000a05c, 0x4, 0x0 }, + { 0x22000a064, 0x4, 0x0 }, + { 0x22000a064, 0x4, 0x0 }, + { 0x22000a060, 0x4, 0x0 }, + { 0x220069008, 0x0, 0x2 }, + { 0x220068000, 0x0, 0x12 }, + { 0x220068000, 0x2, 0x3 }, + { 0x220069010, 0x0, 0x2 }, + { 0x220068000, 0x2, 0x2 }, + { 0x220068000, 0x6, 0x3 }, + { 0x2200a9028, 0x0, 0x2 }, + { 0x2200a8000, 0x0, 0x12 }, + { 0x2200a8000, 0x20, 0x3 }, + { 0x2200a9030, 0x0, 0x2 }, + { 0x2200a8000, 0x20, 0x2 }, + { 0x2200a8000, 0x60, 0x3 }, + { 0x220069028, 0x0, 0x2 }, + { 0x220068000, 0x6, 0x2 }, + { 0x220068000, 0x26, 0x3 }, + { 0x220069030, 0x0, 0x2 }, + { 0x220068000, 0x26, 0x2 }, + { 0x220068000, 0x66, 0x3 }, + { 0x220029018, 0x0, 0x2 }, + { 0x220028000, 0x0, 0x12 }, + { 0x220028000, 0x8, 0x3 }, + { 0x220029020, 0x0, 0x2 }, + { 0x220028000, 0x8, 0x2 }, + { 0x220028000, 0x18, 0x3 }, + { 0x220069038, 0x0, 0x2 }, + { 0x220068000, 0x66, 0x2 }, + { 0x220068000, 0xe6, 0x3 }, + { 0x220069040, 0x0, 0x2 }, + { 0x220068000, 0xe6, 0x2 }, + { 0x220068000, 0x1e6, 0x3 }, + { 0x220029008, 0x0, 0x2 }, + { 0x220028000, 0x18, 0x2 }, + { 0x220028000, 0x1a, 0x3 }, + { 0x220029010, 0x0, 0x2 }, + { 0x220028000, 0x1a, 0x2 }, + { 0x220028000, 0x1e, 0x3 }, + { 0x220069018, 0x0, 0x2 }, + { 0x220068000, 0x1e6, 0x2 }, + { 0x220068000, 0x1ee, 0x3 }, + { 0x220069020, 0x0, 0x2 }, + { 0x220068000, 0x1ee, 0x2 }, + { 0x220068000, 0x1fe, 0x3 }, + { 0x2200a9038, 0x0, 0x2 }, + { 0x2200a8000, 0x60, 0x2 }, + { 0x2200a8000, 0xe0, 0x3 }, + { 0x2200a9040, 0x0, 0x2 }, + { 0x2200a8000, 0xe0, 0x2 }, + { 0x2200a8000, 0x1e0, 0x3 }, + { 0x220029038, 0x0, 0x2 }, + { 0x220028000, 0x1e, 0x2 }, + { 0x220028000, 0x9e, 0x3 }, + { 0x220029040, 0x0, 0x2 }, + { 0x220028000, 0x9e, 0x2 }, + { 0x220028000, 0x19e, 0x3 }, + { 0x2200a9018, 0x0, 0x2 }, + { 0x2200a8000, 0x1e0, 0x2 }, + { 0x2200a8000, 0x1e8, 0x3 }, + { 0x2200a9020, 0x0, 0x2 }, + { 0x2200a8000, 0x1e8, 0x2 }, + { 0x2200a8000, 0x1f8, 0x3 }, + { 0x220029028, 0x0, 0x2 }, + { 0x220028000, 0x19e, 0x2 }, + { 0x220028000, 0x1be, 0x3 }, + { 0x220029030, 0x0, 0x2 }, + { 0x220028000, 0x1be, 0x2 }, + { 0x220028000, 0x1fe, 0x3 }, + { 0x2200a9008, 0x0, 0x2 }, + { 0x2200a8000, 0x1f8, 0x2 }, + { 0x2200a8000, 0x1fa, 0x3 }, + { 0x2200a9010, 0x0, 0x2 }, + { 0x2200a8000, 0x1fa, 0x2 }, + { 0x2200a8000, 0x1fe, 0x3 }, + { 0x24f014000, 0x0, 0x2 }, + { 0x24f010000, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014008, 0x0, 0x2 }, + { 0x24f010004, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014010, 0x0, 0x2 }, + { 0x24f010008, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014018, 0x0, 0x2 }, + { 0x24f01000c, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014020, 0x0, 0x2 }, + { 0x24f010010, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014028, 0x0, 0x2 }, + { 0x24f010014, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014030, 0x0, 0x2 }, + { 0x24f010018, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014038, 0x0, 0x2 }, + { 0x24f01001c, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014040, 0x0, 0x2 }, + { 0x24f010020, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014048, 0x0, 0x2 }, + { 0x24f010024, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014050, 0x0, 0x2 }, + { 0x24f010028, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014058, 0x0, 0x2 }, + { 0x24f01002c, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014060, 0x0, 0x2 }, + { 0x24f010030, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014068, 0x0, 0x2 }, + { 0x24f010034, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014070, 0x0, 0x2 }, + { 0x24f010038, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x250014000, 0x0, 0x2 }, + { 0x250010000, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014008, 0x0, 0x2 }, + { 0x250010004, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014010, 0x0, 0x2 }, + { 0x250010008, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014018, 0x0, 0x2 }, + { 0x25001000c, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014020, 0x0, 0x2 }, + { 0x250010010, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014028, 0x0, 0x2 }, + { 0x250010014, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014030, 0x0, 0x2 }, + { 0x250010018, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014038, 0x0, 0x2 }, + { 0x25001001c, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014040, 0x0, 0x2 }, + { 0x250010020, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014048, 0x0, 0x2 }, + { 0x250010024, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014050, 0x0, 0x2 }, + { 0x250010028, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014058, 0x0, 0x2 }, + { 0x25001002c, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014060, 0x0, 0x2 }, + { 0x250010030, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014068, 0x0, 0x2 }, + { 0x250010034, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014070, 0x0, 0x2 }, + { 0x250010038, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014078, 0x0, 0x2 }, + { 0x25001003c, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x251014000, 0x0, 0x2 }, + { 0x251010000, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014008, 0x0, 0x2 }, + { 0x251010004, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014010, 0x0, 0x2 }, + { 0x251010008, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014018, 0x0, 0x2 }, + { 0x25101000c, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014020, 0x0, 0x2 }, + { 0x251010010, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014028, 0x0, 0x2 }, + { 0x251010014, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014030, 0x0, 0x2 }, + { 0x251010018, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014038, 0x0, 0x2 }, + { 0x25101001c, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014040, 0x0, 0x2 }, + { 0x251010020, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014048, 0x0, 0x2 }, + { 0x251010024, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014050, 0x0, 0x2 }, + { 0x251010028, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014058, 0x0, 0x2 }, + { 0x25101002c, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014060, 0x0, 0x2 }, + { 0x251010030, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014068, 0x0, 0x2 }, + { 0x251010034, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014070, 0x0, 0x2 }, + { 0x251010038, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014078, 0x0, 0x2 }, + { 0x25101003c, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014080, 0x0, 0x2 }, + { 0x251010040, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014088, 0x0, 0x2 }, + { 0x251010044, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014090, 0x0, 0x2 }, + { 0x251010048, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014098, 0x0, 0x2 }, + { 0x25101004c, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140a0, 0x0, 0x2 }, + { 0x251010050, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140a8, 0x0, 0x2 }, + { 0x251010054, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140b0, 0x0, 0x2 }, + { 0x251010058, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140b8, 0x0, 0x2 }, + { 0x25101005c, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140c0, 0x0, 0x2 }, + { 0x251010060, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140c8, 0x0, 0x2 }, + { 0x251010064, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140d0, 0x0, 0x2 }, + { 0x251010068, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140d8, 0x0, 0x2 }, + { 0x25101006c, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x252014000, 0x0, 0x2 }, + { 0x252010000, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014008, 0x0, 0x2 }, + { 0x252010004, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014010, 0x0, 0x2 }, + { 0x252010008, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014018, 0x0, 0x2 }, + { 0x25201000c, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014020, 0x0, 0x2 }, + { 0x252010010, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014028, 0x0, 0x2 }, + { 0x252010014, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014030, 0x0, 0x2 }, + { 0x252010018, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014038, 0x0, 0x2 }, + { 0x25201001c, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014040, 0x0, 0x2 }, + { 0x252010020, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014048, 0x0, 0x2 }, + { 0x252010024, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014050, 0x0, 0x2 }, + { 0x252010028, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014058, 0x0, 0x2 }, + { 0x25201002c, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014060, 0x0, 0x2 }, + { 0x252010030, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014068, 0x0, 0x2 }, + { 0x252010034, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014070, 0x0, 0x2 }, + { 0x252010038, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014078, 0x0, 0x2 }, + { 0x25201003c, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014080, 0x0, 0x2 }, + { 0x252010040, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014088, 0x0, 0x2 }, + { 0x252010044, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014090, 0x0, 0x2 }, + { 0x252010048, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014098, 0x0, 0x2 }, + { 0x25201004c, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140a0, 0x0, 0x2 }, + { 0x252010050, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140a8, 0x0, 0x2 }, + { 0x252010054, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140b0, 0x0, 0x2 }, + { 0x252010058, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140b8, 0x0, 0x2 }, + { 0x25201005c, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140c0, 0x0, 0x2 }, + { 0x252010060, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140c8, 0x0, 0x2 }, + { 0x252010064, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140d0, 0x0, 0x2 }, + { 0x252010068, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140d8, 0x0, 0x2 }, + { 0x25201006c, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140e0, 0x0, 0x2 }, + { 0x252010070, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140e8, 0x0, 0x2 }, + { 0x252010074, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x253014000, 0x0, 0x2 }, + { 0x253010000, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014008, 0x0, 0x2 }, + { 0x253010004, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014010, 0x0, 0x2 }, + { 0x253010008, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014018, 0x0, 0x2 }, + { 0x25301000c, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014020, 0x0, 0x2 }, + { 0x253010010, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014028, 0x0, 0x2 }, + { 0x253010014, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014030, 0x0, 0x2 }, + { 0x253010018, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014038, 0x0, 0x2 }, + { 0x25301001c, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014040, 0x0, 0x2 }, + { 0x253010020, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014048, 0x0, 0x2 }, + { 0x253010024, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014050, 0x0, 0x2 }, + { 0x253010028, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014058, 0x0, 0x2 }, + { 0x25301002c, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014060, 0x0, 0x2 }, + { 0x253010030, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014068, 0x0, 0x2 }, + { 0x253010034, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014070, 0x0, 0x2 }, + { 0x253010038, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014078, 0x0, 0x2 }, + { 0x25301003c, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014080, 0x0, 0x2 }, + { 0x253010040, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014088, 0x0, 0x2 }, + { 0x253010044, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014090, 0x0, 0x2 }, + { 0x253010048, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014098, 0x0, 0x2 }, + { 0x25301004c, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x2530140a0, 0x0, 0x2 }, + { 0x253010050, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x254014000, 0x0, 0x2 }, + { 0x254010000, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014008, 0x0, 0x2 }, + { 0x254010004, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014010, 0x0, 0x2 }, + { 0x254010008, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014018, 0x0, 0x2 }, + { 0x25401000c, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014020, 0x0, 0x2 }, + { 0x254010010, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014028, 0x0, 0x2 }, + { 0x254010014, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014030, 0x0, 0x2 }, + { 0x254010018, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014038, 0x0, 0x2 }, + { 0x25401001c, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014040, 0x0, 0x2 }, + { 0x254010020, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014048, 0x0, 0x2 }, + { 0x254010024, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014050, 0x0, 0x2 }, + { 0x254010028, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014058, 0x0, 0x2 }, + { 0x25401002c, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014060, 0x0, 0x2 }, + { 0x254010030, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014068, 0x0, 0x2 }, + { 0x254010034, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x221000590, 0x3ff001a, 0x1 }, + { 0x221000594, 0x0, 0x1 }, + { 0x221000598, 0x33, 0x1 }, + { 0x22100059c, 0x0, 0x1 }, + { 0x2210005a0, 0x0, 0x1 }, + { 0x2210005a4, 0x1ff, 0x1 }, + { 0x221004000, 0x0, 0x2 }, + { 0x221000580, 0x0, 0x10 }, + { 0x221000580, 0x11, 0x1 }, + { 0x221000584, 0x0, 0x10 }, + { 0x221000584, 0x1, 0x1 }, + { 0x2210005a8, 0x3ff001a, 0x1 }, + { 0x2210005ac, 0x0, 0x1 }, + { 0x2210005b0, 0x31, 0x1 }, + { 0x2210005b4, 0x0, 0x1 }, + { 0x2210005b8, 0x0, 0x1 }, + { 0x2210005bc, 0x1ff, 0x1 }, + { 0x221004008, 0x0, 0x2 }, + { 0x221000580, 0x11, 0x0 }, + { 0x221000580, 0x31, 0x1 }, + { 0x221000584, 0x1, 0x0 }, + { 0x221000584, 0x3, 0x1 }, + { 0x2210005c0, 0x3ff001a, 0x1 }, + { 0x2210005c4, 0x0, 0x1 }, + { 0x2210005c8, 0x31, 0x1 }, + { 0x2210005cc, 0x0, 0x1 }, + { 0x2210005d0, 0x0, 0x1 }, + { 0x2210005d4, 0x2, 0x1 }, + { 0x221004010, 0x0, 0x2 }, + { 0x221000580, 0x31, 0x0 }, + { 0x221000580, 0x71, 0x1 }, + { 0x221000584, 0x3, 0x0 }, + { 0x221000584, 0x7, 0x1 }, + { 0x2210005d8, 0x3ff001a, 0x1 }, + { 0x2210005dc, 0x0, 0x1 }, + { 0x2210005e0, 0x31, 0x1 }, + { 0x2210005e4, 0x0, 0x1 }, + { 0x2210005e8, 0x0, 0x1 }, + { 0x2210005ec, 0x4, 0x1 }, + { 0x221004018, 0x0, 0x2 }, + { 0x221000580, 0x71, 0x0 }, + { 0x221000580, 0xf1, 0x1 }, + { 0x221000584, 0x7, 0x0 }, + { 0x221000584, 0xf, 0x1 }, + { 0x2210005f0, 0x3ff001a, 0x1 }, + { 0x2210005f4, 0x0, 0x1 }, + { 0x2210005f8, 0x31, 0x1 }, + { 0x2210005fc, 0x0, 0x1 }, + { 0x221000600, 0x0, 0x1 }, + { 0x221000604, 0x8, 0x1 }, + { 0x221004020, 0x0, 0x2 }, + { 0x221000580, 0xf1, 0x0 }, + { 0x221000580, 0x1f1, 0x1 }, + { 0x221000584, 0xf, 0x0 }, + { 0x221000584, 0x1f, 0x1 }, + { 0x221000608, 0x3ff001a, 0x1 }, + { 0x22100060c, 0x0, 0x1 }, + { 0x221000610, 0x31, 0x1 }, + { 0x221000614, 0x0, 0x1 }, + { 0x221000618, 0x0, 0x1 }, + { 0x22100061c, 0x10, 0x1 }, + { 0x221004028, 0x0, 0x2 }, + { 0x221000580, 0x1f1, 0x0 }, + { 0x221000580, 0x3f1, 0x1 }, + { 0x221000584, 0x1f, 0x0 }, + { 0x221000584, 0x3f, 0x1 }, + { 0x221000620, 0x3ff001a, 0x1 }, + { 0x221000624, 0x0, 0x1 }, + { 0x221000628, 0x31, 0x1 }, + { 0x22100062c, 0x0, 0x1 }, + { 0x221000630, 0x0, 0x1 }, + { 0x221000634, 0x20, 0x1 }, + { 0x221004030, 0x0, 0x2 }, + { 0x221000580, 0x3f1, 0x0 }, + { 0x221000580, 0x7f1, 0x1 }, + { 0x221000584, 0x3f, 0x0 }, + { 0x221000584, 0x7f, 0x1 }, + { 0x221000638, 0x3ff001a, 0x1 }, + { 0x22100063c, 0x0, 0x1 }, + { 0x221000640, 0x31, 0x1 }, + { 0x221000644, 0x0, 0x1 }, + { 0x221000648, 0x0, 0x1 }, + { 0x22100064c, 0x40, 0x1 }, + { 0x221004038, 0x0, 0x2 }, + { 0x221000580, 0x7f1, 0x0 }, + { 0x221000580, 0xff1, 0x1 }, + { 0x221000584, 0x7f, 0x0 }, + { 0x221000584, 0xff, 0x1 }, + { 0x221000650, 0x3ff001a, 0x1 }, + { 0x221000654, 0x0, 0x1 }, + { 0x221000658, 0x31, 0x1 }, + { 0x22100065c, 0x0, 0x1 }, + { 0x221000660, 0x0, 0x1 }, + { 0x221000664, 0x80, 0x1 }, + { 0x221004040, 0x0, 0x2 }, + { 0x221000580, 0xff1, 0x0 }, + { 0x221000580, 0x1ff1, 0x1 }, + { 0x221000584, 0xff, 0x0 }, + { 0x221000584, 0x1ff, 0x1 }, + { 0x221000668, 0x3ff001a, 0x1 }, + { 0x22100066c, 0x0, 0x1 }, + { 0x221000670, 0x31, 0x1 }, + { 0x221000674, 0x0, 0x1 }, + { 0x221000678, 0x0, 0x1 }, + { 0x22100067c, 0x100, 0x1 }, + { 0x221004048, 0x0, 0x2 }, + { 0x221000580, 0x1ff1, 0x0 }, + { 0x221000580, 0x3ff1, 0x1 }, + { 0x221000584, 0x1ff, 0x0 }, + { 0x221000584, 0x3ff, 0x1 }, + { 0x221200590, 0x3ff001a, 0x1 }, + { 0x221200594, 0x0, 0x1 }, + { 0x221200598, 0x32, 0x1 }, + { 0x22120059c, 0x0, 0x1 }, + { 0x2212005a0, 0x0, 0x1 }, + { 0x2212005a4, 0x1ff, 0x1 }, + { 0x221204000, 0x0, 0x2 }, + { 0x221200580, 0x0, 0x10 }, + { 0x221200580, 0x11, 0x1 }, + { 0x221200584, 0x0, 0x10 }, + { 0x221200584, 0x1, 0x1 }, + { 0x2212005a8, 0x3ff001a, 0x1 }, + { 0x2212005ac, 0x0, 0x1 }, + { 0x2212005b0, 0x32, 0x1 }, + { 0x2212005b4, 0x0, 0x1 }, + { 0x2212005b8, 0x0, 0x1 }, + { 0x2212005bc, 0x2, 0x1 }, + { 0x221204008, 0x0, 0x2 }, + { 0x221200580, 0x11, 0x0 }, + { 0x221200580, 0x31, 0x1 }, + { 0x221200584, 0x1, 0x0 }, + { 0x221200584, 0x3, 0x1 }, + { 0x2212005c0, 0x3ff001a, 0x1 }, + { 0x2212005c4, 0x0, 0x1 }, + { 0x2212005c8, 0x32, 0x1 }, + { 0x2212005cc, 0x0, 0x1 }, + { 0x2212005d0, 0x0, 0x1 }, + { 0x2212005d4, 0x4, 0x1 }, + { 0x221204010, 0x0, 0x2 }, + { 0x221200580, 0x31, 0x0 }, + { 0x221200580, 0x71, 0x1 }, + { 0x221200584, 0x3, 0x0 }, + { 0x221200584, 0x7, 0x1 }, + { 0x2212005d8, 0x3ff001a, 0x1 }, + { 0x2212005dc, 0x0, 0x1 }, + { 0x2212005e0, 0x32, 0x1 }, + { 0x2212005e4, 0x0, 0x1 }, + { 0x2212005e8, 0x0, 0x1 }, + { 0x2212005ec, 0x8, 0x1 }, + { 0x221204018, 0x0, 0x2 }, + { 0x221200580, 0x71, 0x0 }, + { 0x221200580, 0xf1, 0x1 }, + { 0x221200584, 0x7, 0x0 }, + { 0x221200584, 0xf, 0x1 }, + { 0x2212005f0, 0x3ff001a, 0x1 }, + { 0x2212005f4, 0x0, 0x1 }, + { 0x2212005f8, 0x32, 0x1 }, + { 0x2212005fc, 0x0, 0x1 }, + { 0x221200600, 0x0, 0x1 }, + { 0x221200604, 0x10, 0x1 }, + { 0x221204020, 0x0, 0x2 }, + { 0x221200580, 0xf1, 0x0 }, + { 0x221200580, 0x1f1, 0x1 }, + { 0x221200584, 0xf, 0x0 }, + { 0x221200584, 0x1f, 0x1 }, + { 0x221200608, 0x3ff001a, 0x1 }, + { 0x22120060c, 0x0, 0x1 }, + { 0x221200610, 0x32, 0x1 }, + { 0x221200614, 0x0, 0x1 }, + { 0x221200618, 0x0, 0x1 }, + { 0x22120061c, 0x20, 0x1 }, + { 0x221204028, 0x0, 0x2 }, + { 0x221200580, 0x1f1, 0x0 }, + { 0x221200580, 0x3f1, 0x1 }, + { 0x221200584, 0x1f, 0x0 }, + { 0x221200584, 0x3f, 0x1 }, + { 0x221200620, 0x3ff001a, 0x1 }, + { 0x221200624, 0x0, 0x1 }, + { 0x221200628, 0x32, 0x1 }, + { 0x22120062c, 0x0, 0x1 }, + { 0x221200630, 0x0, 0x1 }, + { 0x221200634, 0x40, 0x1 }, + { 0x221204030, 0x0, 0x2 }, + { 0x221200580, 0x3f1, 0x0 }, + { 0x221200580, 0x7f1, 0x1 }, + { 0x221200584, 0x3f, 0x0 }, + { 0x221200584, 0x7f, 0x1 }, + { 0x221200638, 0x3ff001a, 0x1 }, + { 0x22120063c, 0x0, 0x1 }, + { 0x221200640, 0x32, 0x1 }, + { 0x221200644, 0x0, 0x1 }, + { 0x221200648, 0x0, 0x1 }, + { 0x22120064c, 0x80, 0x1 }, + { 0x221204038, 0x0, 0x2 }, + { 0x221200580, 0x7f1, 0x0 }, + { 0x221200580, 0xff1, 0x1 }, + { 0x221200584, 0x7f, 0x0 }, + { 0x221200584, 0xff, 0x1 }, + { 0x221200650, 0x3ff001a, 0x1 }, + { 0x221200654, 0x0, 0x1 }, + { 0x221200658, 0x32, 0x1 }, + { 0x22120065c, 0x0, 0x1 }, + { 0x221200660, 0x0, 0x1 }, + { 0x221200664, 0x100, 0x1 }, + { 0x221204040, 0x0, 0x2 }, + { 0x221200580, 0xff1, 0x0 }, + { 0x221200580, 0x1ff1, 0x1 }, + { 0x221200584, 0xff, 0x0 }, + { 0x221200584, 0x1ff, 0x1 }, + { 0x221200668, 0x3ff0039, 0x1 }, + { 0x22120066c, 0x0, 0x1 }, + { 0x221200670, 0x33, 0x1 }, + { 0x221200674, 0x0, 0x1 }, + { 0x221200678, 0x0, 0x1 }, + { 0x22120067c, 0x1ff, 0x1 }, + { 0x221204048, 0x0, 0x2 }, + { 0x221200580, 0x1ff1, 0x0 }, + { 0x221200580, 0x3ff1, 0x1 }, + { 0x221200584, 0x1ff, 0x0 }, + { 0x221200584, 0x3ff, 0x1 }, + { 0x221400590, 0x3ff0039, 0x1 }, + { 0x221400594, 0x0, 0x1 }, + { 0x221400598, 0x33, 0x1 }, + { 0x22140059c, 0x0, 0x1 }, + { 0x2214005a0, 0x0, 0x1 }, + { 0x2214005a4, 0x2, 0x1 }, + { 0x221404000, 0x0, 0x2 }, + { 0x221400580, 0x0, 0x10 }, + { 0x221400580, 0x11, 0x1 }, + { 0x221400584, 0x0, 0x10 }, + { 0x221400584, 0x1, 0x1 }, + { 0x2214005a8, 0x3ff0039, 0x1 }, + { 0x2214005ac, 0x0, 0x1 }, + { 0x2214005b0, 0x33, 0x1 }, + { 0x2214005b4, 0x0, 0x1 }, + { 0x2214005b8, 0x0, 0x1 }, + { 0x2214005bc, 0x4, 0x1 }, + { 0x221404008, 0x0, 0x2 }, + { 0x221400580, 0x11, 0x0 }, + { 0x221400580, 0x31, 0x1 }, + { 0x221400584, 0x1, 0x0 }, + { 0x221400584, 0x3, 0x1 }, + { 0x2214005c0, 0x3ff0039, 0x1 }, + { 0x2214005c4, 0x0, 0x1 }, + { 0x2214005c8, 0x33, 0x1 }, + { 0x2214005cc, 0x0, 0x1 }, + { 0x2214005d0, 0x0, 0x1 }, + { 0x2214005d4, 0x8, 0x1 }, + { 0x221404010, 0x0, 0x2 }, + { 0x221400580, 0x31, 0x0 }, + { 0x221400580, 0x71, 0x1 }, + { 0x221400584, 0x3, 0x0 }, + { 0x221400584, 0x7, 0x1 }, + { 0x2214005d8, 0x3ff0039, 0x1 }, + { 0x2214005dc, 0x0, 0x1 }, + { 0x2214005e0, 0x33, 0x1 }, + { 0x2214005e4, 0x0, 0x1 }, + { 0x2214005e8, 0x0, 0x1 }, + { 0x2214005ec, 0x10, 0x1 }, + { 0x221404018, 0x0, 0x2 }, + { 0x221400580, 0x71, 0x0 }, + { 0x221400580, 0xf1, 0x1 }, + { 0x221400584, 0x7, 0x0 }, + { 0x221400584, 0xf, 0x1 }, + { 0x2214005f0, 0x3ff0039, 0x1 }, + { 0x2214005f4, 0x0, 0x1 }, + { 0x2214005f8, 0x33, 0x1 }, + { 0x2214005fc, 0x0, 0x1 }, + { 0x221400600, 0x0, 0x1 }, + { 0x221400604, 0x20, 0x1 }, + { 0x221404020, 0x0, 0x2 }, + { 0x221400580, 0xf1, 0x0 }, + { 0x221400580, 0x1f1, 0x1 }, + { 0x221400584, 0xf, 0x0 }, + { 0x221400584, 0x1f, 0x1 }, + { 0x221400608, 0x3ff0039, 0x1 }, + { 0x22140060c, 0x0, 0x1 }, + { 0x221400610, 0x33, 0x1 }, + { 0x221400614, 0x0, 0x1 }, + { 0x221400618, 0x0, 0x1 }, + { 0x22140061c, 0x40, 0x1 }, + { 0x221404028, 0x0, 0x2 }, + { 0x221400580, 0x1f1, 0x0 }, + { 0x221400580, 0x3f1, 0x1 }, + { 0x221400584, 0x1f, 0x0 }, + { 0x221400584, 0x3f, 0x1 }, + { 0x221400620, 0x3ff0039, 0x1 }, + { 0x221400624, 0x0, 0x1 }, + { 0x221400628, 0x33, 0x1 }, + { 0x22140062c, 0x0, 0x1 }, + { 0x221400630, 0x0, 0x1 }, + { 0x221400634, 0x80, 0x1 }, + { 0x221404030, 0x0, 0x2 }, + { 0x221400580, 0x3f1, 0x0 }, + { 0x221400580, 0x7f1, 0x1 }, + { 0x221400584, 0x3f, 0x0 }, + { 0x221400584, 0x7f, 0x1 }, + { 0x221400638, 0x3ff0039, 0x1 }, + { 0x22140063c, 0x0, 0x1 }, + { 0x221400640, 0x33, 0x1 }, + { 0x221400644, 0x0, 0x1 }, + { 0x221400648, 0x0, 0x1 }, + { 0x22140064c, 0x100, 0x1 }, + { 0x221404038, 0x0, 0x2 }, + { 0x221400580, 0x7f1, 0x0 }, + { 0x221400580, 0xff1, 0x1 }, + { 0x221400584, 0x7f, 0x0 }, + { 0x221400584, 0xff, 0x1 }, + { 0x221400650, 0x3ff003a, 0x1 }, + { 0x221400654, 0x0, 0x1 }, + { 0x221400658, 0x33, 0x1 }, + { 0x22140065c, 0x0, 0x1 }, + { 0x221400660, 0x0, 0x1 }, + { 0x221400664, 0x1ff, 0x1 }, + { 0x221404040, 0x0, 0x2 }, + { 0x221400580, 0xff1, 0x0 }, + { 0x221400580, 0x1ff1, 0x1 }, + { 0x221400584, 0xff, 0x0 }, + { 0x221400584, 0x1ff, 0x1 }, + { 0x221400668, 0x3ff003a, 0x1 }, + { 0x22140066c, 0x0, 0x1 }, + { 0x221400670, 0x33, 0x1 }, + { 0x221400674, 0x0, 0x1 }, + { 0x221400678, 0x0, 0x1 }, + { 0x22140067c, 0x2, 0x1 }, + { 0x221404048, 0x0, 0x2 }, + { 0x221400580, 0x1ff1, 0x0 }, + { 0x221400580, 0x3ff1, 0x1 }, + { 0x221400584, 0x1ff, 0x0 }, + { 0x221400584, 0x3ff, 0x1 }, + { 0x221600590, 0x3ff003a, 0x1 }, + { 0x221600594, 0x0, 0x1 }, + { 0x221600598, 0x33, 0x1 }, + { 0x22160059c, 0x0, 0x1 }, + { 0x2216005a0, 0x0, 0x1 }, + { 0x2216005a4, 0x4, 0x1 }, + { 0x221604000, 0x0, 0x2 }, + { 0x221600580, 0x0, 0x10 }, + { 0x221600580, 0x11, 0x1 }, + { 0x221600584, 0x0, 0x10 }, + { 0x221600584, 0x1, 0x1 }, + { 0x2216005a8, 0x3ff003a, 0x1 }, + { 0x2216005ac, 0x0, 0x1 }, + { 0x2216005b0, 0x33, 0x1 }, + { 0x2216005b4, 0x0, 0x1 }, + { 0x2216005b8, 0x0, 0x1 }, + { 0x2216005bc, 0x8, 0x1 }, + { 0x221604008, 0x0, 0x2 }, + { 0x221600580, 0x11, 0x0 }, + { 0x221600580, 0x31, 0x1 }, + { 0x221600584, 0x1, 0x0 }, + { 0x221600584, 0x3, 0x1 }, + { 0x2216005c0, 0x3ff003a, 0x1 }, + { 0x2216005c4, 0x0, 0x1 }, + { 0x2216005c8, 0x33, 0x1 }, + { 0x2216005cc, 0x0, 0x1 }, + { 0x2216005d0, 0x0, 0x1 }, + { 0x2216005d4, 0x10, 0x1 }, + { 0x221604010, 0x0, 0x2 }, + { 0x221600580, 0x31, 0x0 }, + { 0x221600580, 0x71, 0x1 }, + { 0x221600584, 0x3, 0x0 }, + { 0x221600584, 0x7, 0x1 }, + { 0x2216005d8, 0x3ff003a, 0x1 }, + { 0x2216005dc, 0x0, 0x1 }, + { 0x2216005e0, 0x33, 0x1 }, + { 0x2216005e4, 0x0, 0x1 }, + { 0x2216005e8, 0x0, 0x1 }, + { 0x2216005ec, 0x20, 0x1 }, + { 0x221604018, 0x0, 0x2 }, + { 0x221600580, 0x71, 0x0 }, + { 0x221600580, 0xf1, 0x1 }, + { 0x221600584, 0x7, 0x0 }, + { 0x221600584, 0xf, 0x1 }, + { 0x2216005f0, 0x3ff003a, 0x1 }, + { 0x2216005f4, 0x0, 0x1 }, + { 0x2216005f8, 0x33, 0x1 }, + { 0x2216005fc, 0x0, 0x1 }, + { 0x221600600, 0x0, 0x1 }, + { 0x221600604, 0x40, 0x1 }, + { 0x221604020, 0x0, 0x2 }, + { 0x221600580, 0xf1, 0x0 }, + { 0x221600580, 0x1f1, 0x1 }, + { 0x221600584, 0xf, 0x0 }, + { 0x221600584, 0x1f, 0x1 }, + { 0x221600608, 0x3ff003a, 0x1 }, + { 0x22160060c, 0x0, 0x1 }, + { 0x221600610, 0x33, 0x1 }, + { 0x221600614, 0x0, 0x1 }, + { 0x221600618, 0x0, 0x1 }, + { 0x22160061c, 0x80, 0x1 }, + { 0x221604028, 0x0, 0x2 }, + { 0x221600580, 0x1f1, 0x0 }, + { 0x221600580, 0x3f1, 0x1 }, + { 0x221600584, 0x1f, 0x0 }, + { 0x221600584, 0x3f, 0x1 }, + { 0x221600620, 0x3ff003a, 0x1 }, + { 0x221600624, 0x0, 0x1 }, + { 0x221600628, 0x33, 0x1 }, + { 0x22160062c, 0x0, 0x1 }, + { 0x221600630, 0x0, 0x1 }, + { 0x221600634, 0x100, 0x1 }, + { 0x221604030, 0x0, 0x2 }, + { 0x221600580, 0x3f1, 0x0 }, + { 0x221600580, 0x7f1, 0x1 }, + { 0x221600584, 0x3f, 0x0 }, + { 0x221600584, 0x7f, 0x1 }, + { 0x221600638, 0x3ff0013, 0x1 }, + { 0x22160063c, 0x0, 0x1 }, + { 0x221600640, 0x0, 0x1 }, + { 0x221600644, 0x0, 0x1 }, + { 0x221600648, 0x0, 0x1 }, + { 0x22160064c, 0x1ff, 0x1 }, + { 0x221604038, 0x0, 0x2 }, + { 0x221600580, 0x7f1, 0x0 }, + { 0x221600580, 0xff1, 0x1 }, + { 0x221600584, 0x7f, 0x0 }, + { 0x221600584, 0xff, 0x1 }, + { 0x221600650, 0x3ff0016, 0x1 }, + { 0x221600654, 0x0, 0x1 }, + { 0x221600658, 0x0, 0x1 }, + { 0x22160065c, 0x0, 0x1 }, + { 0x221600660, 0x0, 0x1 }, + { 0x221600664, 0x1ff, 0x1 }, + { 0x221604040, 0x0, 0x2 }, + { 0x221600580, 0xff1, 0x0 }, + { 0x221600580, 0x1ff1, 0x1 }, + { 0x221600584, 0xff, 0x0 }, + { 0x221600584, 0x1ff, 0x1 }, + { 0x221004050, 0x0, 0x2 }, + { 0x221000680, 0x1010101, 0x10 }, + { 0x221000680, 0x1010101, 0x1 }, + { 0x22100058c, 0xffffffff, 0x10 }, + { 0x22100058c, 0xffffffff, 0x1 }, + { 0x221000588, 0x0, 0x10 }, + { 0x221000588, 0x10000, 0x1 }, + { 0x221000588, 0x0, 0x0 }, + { 0x221000588, 0x1, 0x1 }, + { 0x221004058, 0x0, 0x2 }, + { 0x221000680, 0x1010101, 0x0 }, + { 0x221000680, 0x1010001, 0x1 }, + { 0x22100058c, 0xffffffff, 0x0 }, + { 0x22100058c, 0xffff02ff, 0x1 }, + { 0x221000588, 0x1, 0x0 }, + { 0x221000588, 0x100001, 0x1 }, + { 0x221000588, 0x1, 0x0 }, + { 0x221000588, 0x11, 0x1 }, + { 0x221204050, 0x0, 0x2 }, + { 0x221200680, 0x1010101, 0x10 }, + { 0x221200680, 0x1010100, 0x1 }, + { 0x22120058c, 0xffffffff, 0x10 }, + { 0x22120058c, 0xffffff04, 0x1 }, + { 0x221200588, 0x0, 0x10 }, + { 0x221200588, 0x10000, 0x1 }, + { 0x221200588, 0x0, 0x0 }, + { 0x221200588, 0x1, 0x1 }, + { 0x221204058, 0x0, 0x2 }, + { 0x221200680, 0x1010100, 0x0 }, + { 0x221200680, 0x1010000, 0x1 }, + { 0x22120058c, 0xffffff04, 0x0 }, + { 0x22120058c, 0xffff0804, 0x1 }, + { 0x221200588, 0x1, 0x0 }, + { 0x221200588, 0x100001, 0x1 }, + { 0x221200588, 0x1, 0x0 }, + { 0x221200588, 0x11, 0x1 }, + { 0x221404050, 0x0, 0x2 }, + { 0x221400680, 0x1010101, 0x10 }, + { 0x221400680, 0x1010100, 0x1 }, + { 0x22140058c, 0xffffffff, 0x10 }, + { 0x22140058c, 0xffffff10, 0x1 }, + { 0x221400588, 0x0, 0x10 }, + { 0x221400588, 0x10000, 0x1 }, + { 0x221400588, 0x0, 0x0 }, + { 0x221400588, 0x1, 0x1 }, + { 0x221404058, 0x0, 0x2 }, + { 0x221400680, 0x1010100, 0x0 }, + { 0x221400680, 0x1010000, 0x1 }, + { 0x22140058c, 0xffffff10, 0x0 }, + { 0x22140058c, 0xffff2010, 0x1 }, + { 0x221400588, 0x1, 0x0 }, + { 0x221400588, 0x100001, 0x1 }, + { 0x221400588, 0x1, 0x0 }, + { 0x221400588, 0x11, 0x1 }, + { 0x221604050, 0x0, 0x2 }, + { 0x221600680, 0x1010101, 0x10 }, + { 0x221600680, 0x1010100, 0x1 }, + { 0x22160058c, 0xffffffff, 0x10 }, + { 0x22160058c, 0xffffff40, 0x1 }, + { 0x221600588, 0x0, 0x10 }, + { 0x221600588, 0x10000, 0x1 }, + { 0x221600588, 0x0, 0x0 }, + { 0x221600588, 0x1, 0x1 }, + { 0x221604058, 0x0, 0x2 }, + { 0x221600680, 0x1010100, 0x0 }, + { 0x221600680, 0x1010000, 0x1 }, + { 0x22160058c, 0xffffff40, 0x0 }, + { 0x22160058c, 0xffff8040, 0x1 }, + { 0x221600588, 0x1, 0x0 }, + { 0x221600588, 0x100001, 0x1 }, + { 0x221600588, 0x1, 0x0 }, + { 0x221600588, 0x11, 0x1 }, + { 0x221804050, 0x0, 0x2 }, + { 0x221800680, 0x1010101, 0x10 }, + { 0x221800680, 0x1010101, 0x1 }, + { 0x22180058c, 0xffffffff, 0x10 }, + { 0x22180058c, 0xffffff00, 0x1 }, + { 0x221800588, 0x0, 0x10 }, + { 0x221800588, 0x10000, 0x1 }, + { 0x221800588, 0x0, 0x0 }, + { 0x221800588, 0x1, 0x1 }, + { 0x221004060, 0x0, 0x2 }, + { 0x221000680, 0x1010001, 0x0 }, + { 0x221000680, 0x1010001, 0x1 }, + { 0x22100058c, 0xffff02ff, 0x0 }, + { 0x22100058c, 0xffff02ff, 0x1 }, + { 0x221000588, 0x11, 0x0 }, + { 0x221000588, 0x1000011, 0x1 }, + { 0x221000588, 0x11, 0x0 }, + { 0x221000588, 0x111, 0x1 }, + { 0x221004068, 0x0, 0x2 }, + { 0x221000680, 0x1010001, 0x0 }, + { 0x221000680, 0x10001, 0x1 }, + { 0x22100058c, 0xffff02ff, 0x0 }, + { 0x22100058c, 0x2ff02ff, 0x1 }, + { 0x221000588, 0x111, 0x0 }, + { 0x221000588, 0x10000111, 0x1 }, + { 0x221000588, 0x111, 0x0 }, + { 0x221000588, 0x1111, 0x1 }, + { 0x221204060, 0x0, 0x2 }, + { 0x221200680, 0x1010000, 0x0 }, + { 0x221200680, 0x1000000, 0x1 }, + { 0x22120058c, 0xffff0804, 0x0 }, + { 0x22120058c, 0xff040804, 0x1 }, + { 0x221200588, 0x11, 0x0 }, + { 0x221200588, 0x1000011, 0x1 }, + { 0x221200588, 0x11, 0x0 }, + { 0x221200588, 0x111, 0x1 }, + { 0x221204068, 0x0, 0x2 }, + { 0x221200680, 0x1000000, 0x0 }, + { 0x221200680, 0x0, 0x1 }, + { 0x22120058c, 0xff040804, 0x0 }, + { 0x22120058c, 0x8040804, 0x1 }, + { 0x221200588, 0x111, 0x0 }, + { 0x221200588, 0x10000111, 0x1 }, + { 0x221200588, 0x111, 0x0 }, + { 0x221200588, 0x1111, 0x1 }, + { 0x221404060, 0x0, 0x2 }, + { 0x221400680, 0x1010000, 0x0 }, + { 0x221400680, 0x1000000, 0x1 }, + { 0x22140058c, 0xffff2010, 0x0 }, + { 0x22140058c, 0xff102010, 0x1 }, + { 0x221400588, 0x11, 0x0 }, + { 0x221400588, 0x1000011, 0x1 }, + { 0x221400588, 0x11, 0x0 }, + { 0x221400588, 0x111, 0x1 }, + { 0x221404068, 0x0, 0x2 }, + { 0x221400680, 0x1000000, 0x0 }, + { 0x221400680, 0x0, 0x1 }, + { 0x22140058c, 0xff102010, 0x0 }, + { 0x22140058c, 0x20102010, 0x1 }, + { 0x221400588, 0x111, 0x0 }, + { 0x221400588, 0x10000111, 0x1 }, + { 0x221400588, 0x111, 0x0 }, + { 0x221400588, 0x1111, 0x1 }, + { 0x221604060, 0x0, 0x2 }, + { 0x221600680, 0x1010000, 0x0 }, + { 0x221600680, 0x1000000, 0x1 }, + { 0x22160058c, 0xffff8040, 0x0 }, + { 0x22160058c, 0xff408040, 0x1 }, + { 0x221600588, 0x11, 0x0 }, + { 0x221600588, 0x1000011, 0x1 }, + { 0x221600588, 0x11, 0x0 }, + { 0x221600588, 0x111, 0x1 }, + { 0x221604068, 0x0, 0x2 }, + { 0x221600680, 0x1000000, 0x0 }, + { 0x221600680, 0x0, 0x1 }, + { 0x22160058c, 0xff408040, 0x0 }, + { 0x22160058c, 0x80408040, 0x1 }, + { 0x221600588, 0x111, 0x0 }, + { 0x221600588, 0x10000111, 0x1 }, + { 0x221600588, 0x111, 0x0 }, + { 0x221600588, 0x1111, 0x1 }, + { 0x221804060, 0x0, 0x2 }, + { 0x221800680, 0x1010101, 0x0 }, + { 0x221800680, 0x1010101, 0x1 }, + { 0x22180058c, 0xffffff00, 0x0 }, + { 0x22180058c, 0xff00ff00, 0x1 }, + { 0x221800588, 0x1, 0x0 }, + { 0x221800588, 0x1000001, 0x1 }, + { 0x221800588, 0x1, 0x0 }, + { 0x221800588, 0x101, 0x1 }, + { 0x22002a058, 0x0, 0x2 }, + { 0x22002a060, 0x0, 0x2 }, + { 0x22002a010, 0x10000000, 0x3 }, + { 0x22002e000, 0x100, 0x1 }, + { 0x22002a008, 0x300, 0x3 }, + { 0x22002a000, 0x11, 0x3 }, + { 0x22006e000, 0x100, 0x1 }, + { 0x22006a008, 0x308, 0x3 }, + { 0x22006a000, 0x1, 0x3 }, + { 0x2200ae000, 0x100, 0x1 }, + { 0x2200aa008, 0x310, 0x3 }, + { 0x2200aa000, 0x1, 0x3 }, + { 0x2200ee000, 0x100, 0x1 }, + { 0x2200ea008, 0x318, 0x3 }, + { 0x2200ea000, 0x1, 0x3 }, + { 0x221000024, 0x7000100, 0x10 }, + { 0x221000024, 0x7001100, 0x1 }, + { 0x221200024, 0x7000100, 0x10 }, + { 0x221200024, 0x7001100, 0x1 }, + { 0x221400024, 0x7000100, 0x10 }, + { 0x221400024, 0x7001100, 0x1 }, + { 0x221600024, 0x7000100, 0x10 }, + { 0x221600024, 0x7001100, 0x1 }, + { 0x221800024, 0x7000100, 0x10 }, + { 0x221800024, 0x7001100, 0x1 }, + { 0x221a00024, 0x7000100, 0x10 }, + { 0x221a00024, 0x7001100, 0x1 }, + { 0x221c00024, 0x7000100, 0x10 }, + { 0x221c00024, 0x7001100, 0x1 }, + { 0x221e00024, 0x7000100, 0x10 }, + { 0x221e00024, 0x7001100, 0x1 }, +}; diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index 1480076b28e98..f512ea452feaf 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -428,6 +428,19 @@ struct apple_sleep_word { u32 offset; }; +#define T8142_PS_ATC0_COMMON 0x2c8 +#define T8142_PS_PMP 0x598 +#define T8142_PS_AON_ATC0_USB_AON 0xc8 +#define T8142_PS_AON_ATC0_USB 0xd0 + +/* A power word the match leaves alone when its group's bit is set in apple_sleep.ps_keep */ +struct apple_sleep_ps_keep { + const char *name; + u32 offset; + bool aon; + u8 group; +}; + /* Power words by their offsets */ struct apple_sleep_words { const u32 *offset; @@ -537,6 +550,14 @@ static int sleep_v27_final_stop(struct apple_sleep *s); * way. The refusals, the coprocessor stops, macOS's power words, the mailbox and the commit * word are shared, and run around these. */ +struct apple_sleep_extra_off { + const char *name; + u32 offset; + u32 parent; +}; + +#define SLEEP_EXTRA_OFF_MAX 16 + struct apple_sleep_ops { /* What makes a core's last WFI end in a reset, after its timers are masked */ void (*deep_wfi_arm)(void); @@ -594,6 +615,8 @@ struct apple_sleep_ops { int (*check)(struct apple_sleep *s); /* Optional traffic strictly after timer, before AIC/release/DEEP. */ void (*post_timer)(struct apple_sleep *s); + /* The dry run's list: does macOS have this ps word off at its commit? */ + bool (*macos_off_at_commit)(u32 offset); }; /* @@ -609,6 +632,21 @@ struct apple_sleep_soc { bool wake_optional; unsigned int ndisp; bool lower_unbound_displays; + /* + * apple_sleep.dispext: the external displays (index 1 and up) are lowered only with it on, + * and a missing phandle for one is no error. Each one's PS write-disable bit (offset, bit; + * offset 0 = none) is cleared before its lowering, as macOS's SPTM leaves it. + */ + bool dispext_optional; + u32 disp_wr_dis[SLEEP_DISPLAYS_MAX][2]; + /* + * apple_sleep.extra_off: each display's ADMA word (a child of its SYS word; 0 = none), + * lowered before the display's own, and the words lower_io lowers first, children before + * parents, each restored at the wake only once its parent (0 = root) is on. + */ + u32 disp_adma[SLEEP_DISPLAYS_MAX]; + const struct apple_sleep_extra_off *extra_off; + unsigned int nextra_off; /* The clock-protection slice guarding each display's CPU word, 0 if none needs clearing. */ u8 disp_prot_slice[SLEEP_DISPLAYS_MAX]; /* Which display to lower next, in macOS's order: index into ps.disp. */ @@ -693,9 +731,17 @@ struct apple_sleep_soc { struct apple_sleep_words ps_still_on; /* The wake's timed power-gate polls: off with BUSY clear at the commit, on macOS */ struct apple_sleep_words ps_engine_polled; + /* Put under AUTO_ENABLE by XNU's PMGR start at boot, iBoot leaving them on without it */ + struct apple_sleep_words ps_boot_auto; + struct apple_sleep_words ps_aon_boot_auto; + /* T8142: replay XNU's memory-controller start at the entry (apple_sleep.mem_boot) */ + bool mem_boot; /* Lowered at the last step if still on, with no user left */ const struct apple_sleep_word *stray; unsigned int nstray; + /* Words the match leaves as they are, by group (apple_sleep.ps_keep) */ + const struct apple_sleep_ps_keep *ps_keep; + unsigned int nps_keep; /* Off on macOS by the last step: one still on only warns. */ const struct apple_sleep_word *gate_off; unsigned int ngate_off; @@ -737,6 +783,11 @@ struct apple_sleep_soc { bool radio_retrain; /* A core restarted after the commit takes the deep WFI in the holding pen. */ bool pen_deep; + /* + * The stopped cores take their deep WFI before the boot core's last mile, not after + * the commit (apple_sleep.early_wfi): XNU's order (T8142, J813 ten-core trace). + */ + bool early_cpu_wfi; }; struct apple_sleep { @@ -787,6 +838,32 @@ struct apple_sleep { u32 *ps_aon_saved; u32 *ps_aon_on_saved; u32 *ps_aon_auto_saved; + /* apple_sleep.ps_keep as the match took it, for its undo and lower_io */ + unsigned int ps_keep_mask; + /* apple_sleep.boot_auto: the words it put on AUTO_ENABLE (ps first, then ps-aon) */ + u64 boot_auto_set; + u32 boot_auto_saved[64]; + /* Of those, how many read AUTO_ENABLE back right after the write */ + unsigned int boot_auto_nset, boot_auto_stuck; + /* apple_sleep.mem_boot: the pages, the fingerprint's mismatches, whether it ran */ + void __iomem *mem_boot_page[40]; + unsigned int mem_boot_mismatch; + bool mem_boot_done, mem_floor_done; + /* apple_sleep.pmp_off: PMP's word as lower_io found it, and whether it went off */ + u32 pmp_saved; + bool pmp_lowered; + int pmp_off_ret; + /* apple_sleep.dispext: each external display's CPU, FE, SYS words before the lowering */ + u32 dispext_saved[SLEEP_DISPLAYS_MAX][3]; + u8 dispext_lowered; + u8 dispext_note; + /* apple_sleep.extra_off */ + u32 disp_adma_saved[SLEEP_DISPLAYS_MAX]; + u8 disp_adma_lowered; + u32 extra_saved[SLEEP_EXTRA_OFF_MAX]; + u16 extra_lowered; + /* bits 0-15 extra_off's words, bit 31 a display's ADMA */ + u32 extra_stuck; /* For each word of ps_all and ps_aon_all: at the commit, as the wake found it, late */ u32 *ps_commit; u32 *ps_aon_commit; @@ -824,6 +901,22 @@ struct apple_sleep { u64 resumes_after; /* T8132: ATC0's words as they were before the commit path lowered them. */ u32 atc0_saved[3]; + /* + * T8142: what the deep sleep loses and XNU puts back at the wake (J813 ten-core trace, + * 2026-11-16): the memory side as it was before the entry's stop (amcc, socni, mcc, + * "amcc-cfg"), the clock word and the PMGR clkgen slots ("clk-slots"). + */ + void __iomem *amcc_cfg[SLEEP_AMCC_MAX]; + void __iomem *clk_slots; + u64 amcc_saved[SLEEP_AMCC_MAX]; + u64 amcc_cfg_saved[SLEEP_AMCC_MAX][3]; + u32 amcc_ctl_saved[SLEEP_AMCC_MAX]; + u32 socni_saved[SLEEP_SOCNI_MAX][32]; + u32 mcc_saved[MCC_CHANNELS][65]; + u32 clk_slot_saved[126][2]; + u32 mem_clk_saved; + bool mem_saved, clk_saved; + int mem_restore_ret; int cluster_e_ret; int cluster_ave_ret; /* The AVE complex, as the parent domain of the encoders' enabled domains */ @@ -1034,6 +1127,7 @@ MODULE_PARM_DESC(pmu_notes, "Untested SoC: note each sleep step in PMU scratch, static void sleep_note(struct apple_sleep *s, u8 step); static void sleep_note_at(struct apple_sleep *s, u8 off, u8 val); +static int sleep_ps_restore(void __iomem *reg, u32 saved); static bool sleep_usb_asleep; @@ -1809,6 +1903,413 @@ static void t8140_deep_wfi_arm(void) sysreg_clear_set_s(SYS_APL_DEEP_SLEEP, 0, DEEP_SLEEP_ENABLE); } +/* + * T8142 (M5): the core's power-down control, S3_5_C15_C1_6 (#1963's M5_C1_6 on T6050). XNU's + * per-core init sets its bits 28:26 (26B131 kernelcache +0x4ed4098: orr #0x1c000000) and a + * kext programs the rest; iBoot leaves them clear. #1963 measured on the M5 Pro that a core + * running at EL2 without them stays powered in its last WFI, so its cluster never goes down and + * WD2 resets the SoC ~5 s after the commit: the J815's signature on every committing sleep (note + * 0x65, P complex BUSY). Set right before each core's last deep WFI, never for idle (a core that + * powered off in Linux's idle would not come back); a reset follows, so nothing restores it. + * apple_sleep.m5_pwrdn=0 leaves it alone (A/B). + */ +#define SLEEP_M5_C1_6 sys_reg(3, 5, 15, 1, 6) +#define SLEEP_M5_C1_6_PWRDN GENMASK_ULL(28, 26) +static bool sleep_m5_pwrdn = true; +module_param_named(m5_pwrdn, sleep_m5_pwrdn, bool, 0644); +MODULE_PARM_DESC(m5_pwrdn, "T8142: set S3_5_C15_C1_6[28:26] before each core's last deep WFI"); + +/* Probe: each core's value as the boot left it (E cores powered off in b45, the boot core's P complex did not). */ +static void t8142_c1_6_read(void *info) +{ + ((u64 *)info)[smp_processor_id()] = read_sysreg_s(SLEEP_M5_C1_6); +} + +static void t8142_c1_6_report(struct device *dev) +{ + u64 *v = kcalloc(nr_cpu_ids, sizeof(*v), GFP_KERNEL); + char line[256]; + int cpu, n = 0; + + if (!v) + return; + on_each_cpu(t8142_c1_6_read, v, 1); + for_each_online_cpu(cpu) { + n += scnprintf(line + n, sizeof(line) - n, " %d:%llx", cpu, v[cpu]); + } + dev_info(dev, "probe: S3_5_C15_C1_6 per cpu (boot cpu%d; bits 28:26 = 0x1c000000 set before each last WFI: %s):%s\n", + raw_smp_processor_id(), READ_ONCE(sleep_m5_pwrdn) ? "yes" : "no, m5_pwrdn=0", line); + kfree(v); +} + +/* + * T8142: each core's CoreSight external debug block (J815 ADT cpuN coresight-reg 0x210010000 + + * cluster * 0x1000000 + core * 0x100000, the T6040 layout). XNU's ml_arm_sleep (26B131 kc + * +0x4ed7470) unlocks it (EDLAR := 0xc5acce55) and writes EDPRCR := 0 on every core, boot and + * secondary, right before arm64_prepare_for_sleep(1); with EDPRCR.CORENPDRQ left set a core only + * emulates its power-down. apple_sleep.ed_release=0 leaves it alone (A/B). + */ +#define T8142_ED_BASE_PA 0x210010000ULL +#define T8142_ED_CLUSTER_STRIDE 0x1000000ULL +#define T8142_ED_CORE_STRIDE 0x100000ULL +#define T8142_ED_EDPRCR 0x310 +#define T8142_ED_EDPRSR 0x314 +#define T8142_ED_EDLAR 0xfb0 +#define T8142_ED_KEY 0xc5acce55 +#define T8142_ED_CLUSTERS 2 +#define T8142_ED_CORES 6 +static void __iomem *t8142_ed[T8142_ED_CLUSTERS][T8142_ED_CORES]; +static bool sleep_ed_release = true; +module_param_named(ed_release, sleep_ed_release, bool, 0644); +MODULE_PARM_DESC(ed_release, "T8142: EDLAR unlock + EDPRCR := 0 before each core's last deep WFI"); + +static void t8142_ed_unmap(void *p) +{ + iounmap((void __iomem *)p); +} + +static void t8142_ed_map(struct device *dev) +{ + unsigned int cpu, n = 0; + + for_each_possible_cpu(cpu) { + u64 mpidr = cpu_logical_map(cpu); + unsigned int c = MPIDR_AFFINITY_LEVEL(mpidr, 2), k = MPIDR_AFFINITY_LEVEL(mpidr, 0); + void __iomem *ed; + + if (c >= T8142_ED_CLUSTERS || k >= T8142_ED_CORES || t8142_ed[c][k]) + continue; + ed = ioremap_np(T8142_ED_BASE_PA + c * T8142_ED_CLUSTER_STRIDE + + k * T8142_ED_CORE_STRIDE, 0x1000); + if (!ed || devm_add_action_or_reset(dev, t8142_ed_unmap, (void __force *)ed)) + continue; + t8142_ed[c][k] = ed; + n++; + } + dev_info(dev, "probe: %u external debug windows mapped (EDPRCR := 0 before each last WFI: %s)\n", + n, READ_ONCE(sleep_ed_release) ? "yes" : "no, ed_release=0"); +} + +/* The dry run: every core's EDPRCR/EDPRSR, read from the boot core while all are up and held */ +static void t8142_ed_report(struct device *dev) +{ + char line[256]; + unsigned int cpu, n = 0; + + for_each_possible_cpu(cpu) { + u64 mpidr = cpu_logical_map(cpu); + unsigned int c = MPIDR_AFFINITY_LEVEL(mpidr, 2), k = MPIDR_AFFINITY_LEVEL(mpidr, 0); + void __iomem *ed = (c < T8142_ED_CLUSTERS && k < T8142_ED_CORES) ? t8142_ed[c][k] : NULL; + + if (ed) + n += scnprintf(line + n, sizeof(line) - n, " %d:%x/%x", cpu, + readl_relaxed(ed + T8142_ED_EDPRCR), + readl_relaxed(ed + T8142_ED_EDPRSR)); + } + dev_info(dev, "dry run: EDPRCR/EDPRSR per cpu (CORENPDRQ = EDPRCR bit 0):%s\n", line); +} + +static void t8142_ed_release(void) +{ + u64 mpidr = read_cpuid_mpidr(); + unsigned int c = MPIDR_AFFINITY_LEVEL(mpidr, 2), k = MPIDR_AFFINITY_LEVEL(mpidr, 0); + void __iomem *ed; + + if (!READ_ONCE(sleep_ed_release) || c >= T8142_ED_CLUSTERS || k >= T8142_ED_CORES) + return; + ed = t8142_ed[c][k]; + if (!ed) + return; + writel_relaxed(T8142_ED_KEY, ed + T8142_ED_EDLAR); + writel_relaxed(0, ed + T8142_ED_EDPRCR); +} + +/* + * The core's own FIQ sources, quiet before its last WFI (a pending one ends the WFI, masked or + * not). With VHE, sleep_deep_wfi_arm's cntp/cntv_ctl_el0 reach the EL2 timers only; the EL1 + * pair (_EL02) is what macOS masks (per-core init: cntp_ctl = 2). XNU's core-offline path + * (26B131 kc +0x4ed69d4) also stops the core PMU (PMCR0 := 0) before its deep WFI. + * apple_sleep.m5_quiet=0 leaves them alone (A/B). + */ +#define T8142_PMCR0 sys_reg(3, 1, 15, 0, 0) +#define T8142_UPMCR0 sys_reg(3, 7, 15, 0, 4) +#define T8142_UPMSR sys_reg(3, 7, 15, 6, 4) +#define T8142_VM_TMR_FIQ_ENA sys_reg(3, 5, 15, 1, 3) +#define T8142_CLPC_C5_0 sys_reg(3, 7, 15, 5, 0) +static bool sleep_m5_quiet = true; +module_param_named(m5_quiet, sleep_m5_quiet, bool, 0644); +MODULE_PARM_DESC(m5_quiet, "T8142: mask the EL1 timers and stop the core PMU before each core's last deep WFI"); + +/* + * The last WFI at EL1, not EL2. Under aura on J815 (kit v10, 2026-11-16), macOS's own sleep + * completed when its cores took their last WFI natively at EL1 (sleep-go-keep) and reset on WD2 + * when aura took the same WFI at EL2 for them (sleep-go-el2): Linux's signature (note 0x65, + * E complex off, P complex asked off but BUSY, the boot core's WFI held: b45 observer 0x98). + * Linux runs at EL2 (VHE), so each core drops to EL1h, MMU off, every exception masked, stage 2 + * off, no traps, and loops on WFI there. Nothing returns: a reset or the wake (RVBAR) follows. + * apple_sleep.el1_wfi: 0 = at EL2 (default), 1 = the boot core only, 2 = every core. + */ +/* + * The dry run's register readouts (IMPDEF sysregs, every core's ED block, the C1_6 write test): + * never booted before 2026-11-16, and a dry-run report has reset the Mac before (b32), so they + * only run when asked: echo 1 > /sys/module/apple_sleep/parameters/dry_regs. + */ +static bool sleep_dry_regs; +module_param_named(dry_regs, sleep_dry_regs, bool, 0644); +MODULE_PARM_DESC(dry_regs, "T8142: print the core register readouts at each dry run (off by default)"); + +/* + * Default 0 again since 2026-11-16 14:4x: with 2, the E complex stayed BUSY 2 s after the commit + * (note 0x67, boot 475520fe); with 0 it powered off, in either release order (fe1573cb, 2335a7e7). + */ +static unsigned int sleep_el1_wfi; +module_param_named(el1_wfi, sleep_el1_wfi, uint, 0644); +MODULE_PARM_DESC(el1_wfi, "T8142: take the last WFI at EL1: 0 no, 1 boot core, 2 every core"); + +/* + * Where the stopped cores take their deep WFI. XNU (ml_arm_sleep): each other core writes its + * stop bit, waits for the boot core's flag, then takes its deep WFI; the boot core clears the + * flag and only then runs the platform quiesce actions, the PMGR's last mile and the S2R + * timer among them. Thomas's J813 trace (all ten cores, 27.2, 2026-11-16) has it so: the nine + * stop bits at -6.7..-6.06 ms, the boot core's first PCIe word at -5.79 ms, the timer at 0. + * Linux held them in WFE through the memory stop and the clusters' off words and released + * them after the timer (#1963's T6050 order). 1 (default): XNU's order, the cores in their + * deep WFI before the last mile; 0: after the commit, as before. + */ +static bool sleep_early_wfi = true; +module_param_named(early_wfi, sleep_early_wfi, bool, 0644); +MODULE_PARM_DESC(early_wfi, "T8142: stopped cores take their deep WFI before the last mile (XNU's order), not after the commit"); +#define SLEEP_EARLY_WFI_SETTLE_US 300 + +/* + * T8142 DIAGNOSTIC, b45's observer back on the current tree (2026-11-16 14:4x): E core 0 does not + * take its last WFI; it waits for the boot core's, samples at +20 ms, +300 ms and +observer_ms, + * writes note 0x6a (one flag byte per sample: bit 0 commit word nonzero, 1/2 complex E/P asked + * on, 3/4 E/P busy, 5 the boot core's WFI came back, 6 an armed wake source pending, 7 the boot + * core reached its WFI), then takes its own last WFI, so the sleep can still complete. It answers + * what the post-commit probe can't: does complex P power down once the boot core is in its WFI. + * 0: off (default). + */ +static unsigned int sleep_observer_ms; +module_param_named(observer_ms, sleep_observer_ms, uint, 0644); +MODULE_PARM_DESC(observer_ms, "T8142 DIAGNOSTIC: E core 0 watches complex P for this many ms after the boot core's last WFI (note 0x6a), then sleeps (0 = off)"); +static u32 t8142_obs_boot_wfi, t8142_obs_wfi_back; + +/* + * T8142 DIAGNOSTIC (b43's post_commit_note, back on the current tree, 2026-11-16): after the + * commit and the other cores' release, the boot core spins this many ms instead of taking its + * WFI, writes note 0x66 (what the engine left: the commit word, both complexes, a pending armed + * wake, the perf states, the PMC voters), then takes its WFI, so the sleep can still go down. + * The one J815 run that slept and ran the engine's wake program (b43 run 32535966) was such a + * probe. 0: off (default). The SPMI writes come after the S2R timer, as macOS's own do. + */ +static unsigned int sleep_post_commit_ms; +module_param_named(post_commit_ms, sleep_post_commit_ms, uint, 0644); +MODULE_PARM_DESC(post_commit_ms, "T8142 DIAGNOSTIC: the boot core notes the engine's state this many ms after the commit, then takes its WFI (0 = off)"); +/* + * With post_commit_ms: after note 0x66, every core's EDPRSR through its external debug window + * (bit 0 PU = the core is powered, bit 1 SPD = it powered down since the last read), note 0x67. + * A read that hangs leaves 0x66 in the PMU. 0 skips it. + */ +/* Off by default: in boot 475520fe it read PU 0 for every core, the running boot core too. */ +static bool sleep_post_commit_ed; +module_param_named(post_commit_ed, sleep_post_commit_ed, bool, 0644); +MODULE_PARM_DESC(post_commit_ed, "T8142 DIAGNOSTIC: with post_commit_ms, also note each core's EDPRSR power status (note 0x67)"); + +/* + * T8142: words the T8132-derived lists lower but macOS 27.2 leaves on at the commit (J813 trace + * g01, 2026-11-16). Bit 0: PMS_C1PPT, SOC_RC. Bit 1: I2C0/2/4, SPI0/1/3/5. macOS raises both + * groups with AUTO_ENABLE at boot and at each wake and writes neither before any of the run's + * three committed sleeps; none has a node in the J815 DT, so only this match touches them. + * Bit 2: ATC1_COMMON, ATC1_USB(_AON). Bit 3: ATC0_USB(_AON), ATC0_COMMON at + * lower_io. Both ATC ports were hidden from that guest, so bits 2 and 3 have no evidence + * behind them yet and are off by default. + */ +/* + * T8142: XNU's PMGR start puts 54 power words under AUTO_ENABLE at boot (J813 trace g01: read, + * the value with its flags cleared, then the same | AUTO_ENABLE), the same 22 + 4 as at each + * wake and 28 more. iBoot leaves them on with AUTO_ENABLE clear, and on J815 Linux leaves them + * so (dry run: PMS_C1PPT 0x2ff, I2C0 0xff): T6050's seq-boot does the same for its own words + * ("so none can gate"). This does it at the deep entry, right after the dry-run gate, for the + * words that are on without it; a refusal before the commit takes it back. + */ +static bool sleep_boot_auto_on = true; +module_param_named(boot_auto, sleep_boot_auto_on, bool, 0644); +MODULE_PARM_DESC(boot_auto, "T8142: put XNU's boot list of power words under AUTO_ENABLE at the deep entry (default Y)"); +/* + * T8142: XNU's AppleT8142MCC start (J813 trace g01: ~1120 accesses in the first ms of XNU, 677 + * writes): DCS channels' +0x580/+0x584 enables bit by bit, their lanes (+0x588 strobe/enable with + * +0x680/+0x58c), the group words, every channel's +0x24 bit 12, the AMCC planes' sleep bits 1..8 + * and config, the SoC NI tables with their +0x100 strobe. iBoot leaves all of it at reset values + * and no Linux driver does it, so J815's memory side reads 0 where macOS has 0x3ff1, 0x11, ... + * Replayed at the deep entry after the last refusal point, only if the 34 words XNU reads before + * its first write hold exactly what they hold on the J813 (iBoot's values). J813 constants on + * J815's memory controller: default off. + */ +static bool sleep_mem_boot; +module_param_named(mem_boot, sleep_mem_boot, bool, 0644); +MODULE_PARM_DESC(mem_boot, "T8142 EXPERIMENT: replay XNU's memory-controller start at the deep entry if iBoot's fingerprint matches (default N)"); +/* + * T8142: T6050's memory performance floor (its voter 1: 2, 1 at 9 ms, then 0 before the memory + * stop; "the value read back stays 0"). No T8142 evidence: J813's trace didn't hook the voters. + */ +/* + * T8142: PMP's power domain off after its firmware's final stop (Thomas Glanzmann, + * m0d16l14n1/linux#4 e754b17c, 2026-11-16): the PMP is idled and RUN cleared, but its domain + * stayed at target f; macOS lowers it (J813 g01: 0x598 0x0f0f00ff -> 0x0f0f03f0 at -12.2 ms), + * and PMS_SRAM then gates by itself. On J813 the first real sleep and return came with it. + */ +static bool sleep_pmp_off = true; +module_param_named(pmp_off, sleep_pmp_off, bool, 0644); +MODULE_PARM_DESC(pmp_off, "T8142: power the PMP's domain off after its final stop, as macOS (default Y)"); + +/* + * J815 macOS 26B131 (notes/sleep-trace/t8142-j815-26B131-entry.md): DISPEXT0, then DISPEXT1, + * then DISP, each SYS/FE up, the CPU word down in four steps, SYS/FE down, 159-137 ms before + * the S2R timer; all six DISPEXT words are off at macOS's commit. Linux's T8142 profile only + * lowered the internal DCP, while both external DCPs are bound here and their FE/SYS words read + * 0x20ff in the dry run. + */ +static bool sleep_dispext = true; +module_param_named(dispext, sleep_dispext, bool, 0644); +MODULE_PARM_DESC(dispext, "T8142: lower the external DCPs' domains with the display, as macOS (default Y)"); + +/* + * The OS-managed words (not no_ps in the J815 ADT) that macOS has off at its commit (J813 g01 + * end state) and no other step of Linux's sleep lowers: SIO_CPU (on from iBoot, no driver on + * J815; macOS lowers it 53 ms before the timer, Thomas's "inactive SIO CPU domain"), FPWM0 (the + * keyboard backlight), GLOBAL_AUX_CTRL0/1, the PCIe OCLAs (children of APCIE_SYS_GP/ST, which + * lower_io lowers) and the displays' ADMA words (children of their SYS words). Each only if on. + */ +static bool sleep_extra_off = true; +module_param_named(extra_off, sleep_extra_off, bool, 0644); +MODULE_PARM_DESC(extra_off, "T8142: lower the words macOS has off at its commit that nothing else lowers (default Y)"); + +static bool sleep_mem_floor; +module_param_named(mem_floor, sleep_mem_floor, bool, 0644); +MODULE_PARM_DESC(mem_floor, "T8142 EXPERIMENT: step PMC voter 1 down (2, 1, 0) as T6050 does (default N)"); + +static bool sleep_boot_auto_dry = true; +module_param_named(boot_auto_dry, sleep_boot_auto_dry, bool, 0644); +MODULE_PARM_DESC(boot_auto_dry, "T8142: a dry run also does boot_auto's writes, reads them back and undoes them (default Y)"); + +static unsigned int sleep_ps_keep = 0x3; +module_param_named(ps_keep, sleep_ps_keep, uint, 0644); +MODULE_PARM_DESC(ps_keep, "T8142: power words left as they are at the match, by group (bit 0 PMS_C1PPT/SOC_RC, 1 I2C/SPI, 2 ATC1, 3 ATC0 at lower_io; default 0x3)"); + +/* The T8142 wake's own restores (J813 trace), each switchable for an A/B. */ +static bool sleep_mem_restore = true; +module_param_named(mem_restore, sleep_mem_restore, bool, 0644); +MODULE_PARM_DESC(mem_restore, "T8142: put the memory side (AMCC, SoC NI, DCS) back at the wake as XNU does"); +static bool sleep_clk_restore = true; +module_param_named(clk_restore, sleep_clk_restore, bool, 0644); +MODULE_PARM_DESC(clk_restore, "T8142: put the 126 PMGR clkgen slots and the memory clock word back at the wake as XNU does"); +static bool sleep_perf_down = true; +module_param_named(perf_down, sleep_perf_down, bool, 0644); +MODULE_PARM_DESC(perf_down, "T8142: SoC/DCS perf states down before the memory stop (macOS on J813 never writes them; A/B)"); +static u64 t8142_boot_mpidr = ~0ULL; + +extern char t8142_el1_wfi_stub[], t8142_el1_wfi_stub_end[]; +asm(".pushsection .text, \"ax\"\n" + ".balign 64\n" + ".global t8142_el1_wfi_stub\n" + "t8142_el1_wfi_stub:\n" + "1: dsb sy\n" + " isb\n" + " wfi\n" + " b 1b\n" + ".global t8142_el1_wfi_stub_end\n" + "t8142_el1_wfi_stub_end:\n" + ".popsection\n"); + +static void __noreturn t8142_el1_wfi(void) +{ + write_sysreg_s(INIT_SCTLR_EL1_MMU_OFF, SYS_SCTLR_EL12); + isb(); + write_sysreg(HCR_RW | HCR_E2H, hcr_el2); + write_sysreg(PSR_MODE_EL1h | PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT, spsr_el2); + write_sysreg(__pa_symbol(t8142_el1_wfi_stub), elr_el2); + /* The EL1 loop acks nothing: no fast IPI may be left pending to end its WFI. */ + write_sysreg_s(IPI_SR_PENDING, SYS_APL_IPI_SR_EL1); + isb(); + asm volatile("eret" ::: "memory"); + unreachable(); +} + +static bool t8142_el1_wfi_here(void) +{ + unsigned int mode = READ_ONCE(sleep_el1_wfi); + + if (!is_kernel_in_hyp_mode() || !mode) + return false; + return mode >= 2 || (read_cpuid_mpidr() & MPIDR_HWID_BITMASK) == READ_ONCE(t8142_boot_mpidr); +} + +static void t8142_deep_wfi_arm(void) +{ + if (READ_ONCE(sleep_m5_pwrdn) && is_kernel_in_hyp_mode()) + sysreg_clear_set_s(SLEEP_M5_C1_6, 0, SLEEP_M5_C1_6_PWRDN); + if (READ_ONCE(sleep_m5_quiet)) { + if (is_kernel_in_hyp_mode()) { + write_sysreg_s(ARCH_TIMER_CTRL_IT_MASK, SYS_CNTP_CTL_EL02); + write_sysreg_s(ARCH_TIMER_CTRL_IT_MASK, SYS_CNTV_CTL_EL02); + } + write_sysreg_s(0, T8142_PMCR0); + isb(); + } + t8142_ed_release(); + t8140_deep_wfi_arm(); + if (t8142_el1_wfi_here()) { + dsb(sy); + t8142_el1_wfi(); + } +} + +static u8 t8142_fiq_sources(void) +{ + u8 m = 0; +#define FIRING(v) (((v) & (ARCH_TIMER_CTRL_ENABLE | ARCH_TIMER_CTRL_IT_MASK | ARCH_TIMER_CTRL_IT_STAT)) == \ + (ARCH_TIMER_CTRL_ENABLE | ARCH_TIMER_CTRL_IT_STAT)) + if (FIRING(read_sysreg(cntp_ctl_el0))) + m |= 0x01; + if (FIRING(read_sysreg(cntv_ctl_el0))) + m |= 0x02; + if (is_kernel_in_hyp_mode()) { + if (FIRING(read_sysreg_s(SYS_CNTP_CTL_EL02))) + m |= 0x04; + if (FIRING(read_sysreg_s(SYS_CNTV_CTL_EL02))) + m |= 0x08; + } +#undef FIRING + if (read_sysreg_s(T8142_PMCR0) & BIT(11)) + m |= 0x10; + if (read_sysreg_s(SYS_APL_IPI_SR_EL1) & IPI_SR_PENDING) + m |= 0x20; + if (read_sysreg_s(T8142_UPMSR) & BIT(0)) + m |= 0x40; + return m; +} + +/* + * The boot core's last WFI (at EL2) returned while it should be powered off: note 0x6c once, 100 ms + * into the loop (past the engine's 33 ms window, so no SPMI traffic while the sleep can still + * go through): +2 0x80 | ISR_EL1's A/I/F (bits 2/1/0), +4 the core's own FIQ sources still + * firing (0x01 CNTP/EL2, 0x02 CNTV/EL2, 0x04 CNTP_EL02, 0x08 CNTV_EL02, 0x10 PMC, 0x20 IPI, + * 0x40 UPMC). The next boot reads 0x6c (it woke over and over) or 0x65 (it sat in WFI). + */ +static void t8142_wfi_returned(struct apple_sleep *s, u64 t0, bool *noted) +{ + u64 isr; + + if (*noted || read_sysreg(cntpct_el0) - t0 < arch_timer_get_cntfrq() / 10) + return; + *noted = true; + isr = read_sysreg(isr_el1); + sleep_note_at(s, 2, 0x80 | ((isr >> 6) & 7)); + sleep_note_at(s, 4, t8142_fiq_sources()); + sleep_note(s, 0x6c); +} + static void sleep_deep_wfi_arm(void) { /* A timer left running ends the WFI, and costs power until reset. */ @@ -1838,8 +2339,67 @@ static void sleep_cpu_stop(u64 mpidr) dsb(sy); } +static u8 t8142_obs_sample(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + u32 e = readl(s->cluster + soc->cluster_cpu[0]); + u32 p = readl(s->cluster + soc->cluster_cpu[1]); + u8 f = 0; + int i; + + if (readl(s->commit)) + f |= BIT(0); + if (e & CLUSTER_ON) + f |= BIT(1); + if (p & CLUSTER_ON) + f |= BIT(2); + if (e & BIT(4)) + f |= BIT(3); + if (p & BIT(4)) + f |= BIT(4); + if (READ_ONCE(t8142_obs_wfi_back)) + f |= BIT(5); + for (i = 0; i < soc->wake_words; i++) + if (readl(s->wake + soc->wake_status + 4 * i) & s->wake_armed[i]) + f |= BIT(6); + if (READ_ONCE(t8142_obs_boot_wfi)) + f |= BIT(7); + return f; +} + +/* E core 0 with apple_sleep.observer_ms: see sleep_observer_ms. */ +static void t8142_observe(struct apple_sleep *s, unsigned int ms) +{ + u64 freq = arch_timer_get_cntfrq(), t0 = read_sysreg(cntpct_el0); + static const unsigned int at_ms[2] = { 20, 300 }; + u8 b[3]; + int i; + + /* At most 30 s for the boot core to get there (a hang before it ends at WD2 anyway). */ + while (!READ_ONCE(t8142_obs_boot_wfi) && read_sysreg(cntpct_el0) - t0 < 30 * freq) + cpu_relax(); + t0 = read_sysreg(cntpct_el0); + for (i = 0; i < 3; i++) { + u64 wait = (i < 2 ? at_ms[i] : max(ms, 301U)) * freq / 1000; + + while (read_sysreg(cntpct_el0) - t0 < wait) + cpu_relax(); + b[i] = t8142_obs_sample(s); + } + sleep_note_at(s, 2, b[0]); + sleep_note_at(s, 3, b[1]); + sleep_note_at(s, 4, b[2]); + sleep_note(s, 0x6a); +} + static void sleep_cpu_off(u64 mpidr) { + struct apple_sleep *s = apple_sleep; + unsigned int ms = READ_ONCE(sleep_observer_ms); + + if (ms && s && s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm && + (mpidr & MPIDR_HWID_BITMASK) == 0) + t8142_observe(s, ms); sleep_deep_wfi(); } @@ -1851,13 +2411,91 @@ static void sleep_cpu_down_off(u64 mpidr) sleep_deep_wfi(); } +/* + * apple_sleep.cpu_on_trace: after a sleep, one line per core start. aura's spin-table slot is + * { mpidr, flag, target, ... } with cpu-release-addr = &target, and aura bumps flag as the core + * enters its reset path: "flag a -> b" tells a core that never left reset from one that ran + * and stopped later (in the kernel's pen or its bring-up). Also the cpu-start words before and + * after, the core's power and power-gate words and its EDPRSR (bit 0 PU). + */ +static bool sleep_cpu_on_trace = true; +module_param_named(cpu_on_trace, sleep_cpu_on_trace, bool, 0644); +MODULE_PARM_DESC(cpu_on_trace, "Report each core start after a sleep (aura slot flag, cpu-start words, EDPRSR)"); + +static void __iomem *sleep_cpu_slot[NR_CPUS]; + +static void __iomem *sleep_cpu_slot_map(int cpu) +{ + struct device_node *np; + u64 rel; + + if (cpu < 0 || cpu >= NR_CPUS) + return NULL; + if (sleep_cpu_slot[cpu]) + return sleep_cpu_slot[cpu]; + np = of_get_cpu_node(cpu, NULL); + if (!np) + return NULL; + if (!of_property_read_u64(np, "cpu-release-addr", &rel) && rel >= 16) + sleep_cpu_slot[cpu] = ioremap_cache(rel - 16, 24); + of_node_put(np); + return sleep_cpu_slot[cpu]; +} + +static u64 sleep_cpu_slot_read(void __iomem *slot, unsigned int off) +{ + dcache_inval_poc((unsigned long)slot + off, (unsigned long)slot + off + 8); + return readq(slot + off); +} + +static void sleep_cpu_start_words(struct apple_sleep *s, u32 *w) +{ + w[0] = readl(s->cpu_start + CPU_START_STOP); + w[1] = readl(s->cpu_start + CPU_START_SYS); + w[2] = readl(s->cpu_start + CPU_START_CLUSTER(0)); + w[3] = readl(s->cpu_start + CPU_START_CLUSTER(1)); +} + static int sleep_cpu_on(u64 mpidr) { struct apple_sleep *s = apple_sleep; - unsigned int cluster = sleep_cpu_cluster(s, mpidr); + unsigned int cluster = sleep_cpu_cluster(s, mpidr), core = sleep_cpu_core(mpidr); + bool trace = READ_ONCE(sleep_cpu_on_trace) && s->soc->cpu_clusters >= 2; + int cpu = get_logical_index(mpidr & MPIDR_HWID_BITMASK); + void __iomem *slot = trace ? sleep_cpu_slot_map(cpu) : NULL; + u32 before[4], after[4], ps = 0, gate = 0, edprsr = ~0U; + u64 flag0 = 0, flag1 = 0; + unsigned int us = 0; + + if (trace) { + sleep_cpu_start_words(s, before); + if (slot) + flag0 = sleep_cpu_slot_read(slot, 8); + } writel(sleep_cpu_start_bit(s, mpidr), s->cpu_start + CPU_START_SYS); - writel(BIT(sleep_cpu_core(mpidr)), s->cpu_start + CPU_START_CLUSTER(cluster)); + writel(BIT(core), s->cpu_start + CPU_START_CLUSTER(cluster)); + + if (!trace) + return 0; + /* Up to 20 ms for aura's entry to count it; the kernel's own wait is 5 s. */ + for (us = 0; slot && us < 20000; us += 20) { + flag1 = sleep_cpu_slot_read(slot, 8); + if (flag1 != flag0) + break; + udelay(20); + } + sleep_cpu_start_words(s, after); + if (s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm) { + /* T8142 core words: E k at 8k, P k at 0x30 + 8k; power gates at a 0x10 stride */ + ps = readl(s->ps + (cluster ? 0x30 : 0) + 8 * core); + gate = readl(s->pwrgate + (cluster ? 0x60 : 0) + 0x10 * core); + if (cluster < T8142_ED_CLUSTERS && core < T8142_ED_CORES && t8142_ed[cluster][core]) + edprsr = readl_relaxed(t8142_ed[cluster][core] + T8142_ED_EDPRSR); + } + pr_info("apple-sleep: cpu%d start %#llx: stop/sys/e/p %x/%x/%x/%x -> %x/%x/%x/%x; aura slot %s flag %llu -> %llu after %u us; ps %#x pwrgate %#x edprsr %#x\n", + cpu, mpidr, before[0], before[1], before[2], before[3], after[0], after[1], + after[2], after[3], slot ? "mapped" : "UNMAPPED", flag0, flag1, us, ps, gate, edprsr); return 0; } @@ -2593,6 +3231,24 @@ static int apple_sleep_refuse(struct apple_sleep *s) for (i = 0; i < s->soc->ndisp; i++) { u32 ps = d->disp[i][0]; + /* + * T8142's external DCPs have no sleep stop in their driver (no s2r_ext, not + * T6050's late stop): with apple_sleep.dispext the display's lowering stops each + * one's CPU cold, as for an unbound DCP, so a running one is no refusal. + */ + if (i != 0 && s->soc->dispext_optional) { + /* + * Undescribed (no phandle), it can't be stopped here, and iBoot leaves its + * firmware running with the domain up: the engine would wait on it. + */ + if (READ_ONCE(sleep_dispext) && !s->display[i].np && sleep_ps_on(s, ps)) { + dev_err(s->dev, + "refused: external display coprocessor %d is on (%#x: %#x) and not in apple,display-coprocessors\n", + i - 1, ps, readl(sleep_power_reg(s, ps))); + refused = true; + } + continue; + } if (s->display[i].bound && sleep_asc_running(s, ps, s->display[i].asc) && (!apple_sleep_v27_late() || sleep_v27_final_check(i))) { dev_err(s->dev, "refused: a bound display coprocessor is still running\n"); @@ -2647,18 +3303,62 @@ static void sleep_wake_restore(struct apple_sleep *s) * writes. The coprocessors' secure mailboxes are not used here. Whether that * holds is open. */ +static bool sleep_dispext_skip(struct apple_sleep *s, int i) +{ + return i != 0 && s->soc->dispext_optional && + (!READ_ONCE(sleep_dispext) || !s->display[i].np); +} + +/* + * apple_sleep.dispext: an external display's words back as the lowering found them, parents + * first (SYS, FE, CPU), after a refusal or at the wake (the commit saw them off, so the rewake + * leaves them). Its firmware was stopped cold; its driver's resume starts it again. + */ +static void sleep_dispext_restore(struct apple_sleep *s) +{ + const u32 (*domains)[3] = s->soc->ps.disp; + int i, k; + + for (i = 1; i < s->soc->ndisp; i++) { + if (!(s->dispext_lowered & BIT(i))) + continue; + for (k = 2; k >= 0; k--) + if (FIELD_GET(PS_TARGET, s->dispext_saved[i][k])) + sleep_ps_restore(s->ps + domains[i][k], s->dispext_saved[i][k]); + } + s->dispext_lowered = 0; + /* + * An external display's ADMA once its SYS word is up again. The internal display's stays + * off: no Linux driver uses it, and its SYS word comes back with the DCP's own resume. + */ + for (i = 1; i < s->soc->ndisp; i++) { + if (!(s->disp_adma_lowered & BIT(i))) + continue; + if (FIELD_GET(PS_ACTUAL, readl(s->ps + domains[i][2]))) + sleep_ps_restore(sleep_power_reg(s, s->soc->disp_adma[i]), + s->disp_adma_saved[i]); + s->disp_adma_lowered &= ~BIT(i); + } +} + static int sleep_display_off(struct apple_sleep *s) { const struct apple_sleep_soc *soc = s->soc; const u32 (*domains)[3] = soc->ps.disp; int n = soc->ndisp, j, i, ret = 0; + s->dispext_lowered = 0; + s->disp_adma_lowered = 0; + s->extra_stuck = 0; + s->dispext_note = soc->dispext_optional && READ_ONCE(sleep_dispext) ? 1 : 0; for (j = 0; j < n; j++) { void __iomem *asc; i = soc->display_order[j]; asc = s->display[i].asc; + if (sleep_dispext_skip(s, i)) + continue; /* * T8140's engine doesn't wait for its external display. On T8132 macOS has them * all off. @@ -2674,6 +3374,43 @@ static int sleep_display_off(struct apple_sleep *s) writel(readl(slice) & ~PS_PROT_SLICE_ON, slice); } } + if (i != 0 && soc->dispext_optional) { + int k; + + for (k = 0; k < 3; k++) + s->dispext_saved[i][k] = readl(s->ps + domains[i][k]); + s->dispext_lowered |= BIT(i); + /* +22 bits 1/2 (DISPEXT0) and 3/4 (DISPEXT1): CPU on, FE or SYS on */ + if (i <= 2 && FIELD_GET(PS_ACTUAL, s->dispext_saved[i][0])) + s->dispext_note |= BIT(2 * i - 1); + if (i <= 2 && (FIELD_GET(PS_ACTUAL, s->dispext_saved[i][1]) || + FIELD_GET(PS_ACTUAL, s->dispext_saved[i][2]))) + s->dispext_note |= BIT(2 * i); + if (sleep_asc_running(s, domains[i][0], asc)) + s->dispext_note |= 0x20; + if (soc->disp_wr_dis[i][0]) { + void __iomem *wr = s->ps + soc->disp_wr_dis[i][0]; + u32 bit = BIT(soc->disp_wr_dis[i][1]); + + if (readl(wr) & bit) { + writel(readl(wr) & ~bit, wr); + s->dispext_note |= 0x40; + } + } + } + + /* apple_sleep.extra_off: the display's ADMA, a child of its SYS word, first */ + if (soc->disp_adma[i] && READ_ONCE(sleep_extra_off)) { + u32 a = soc->disp_adma[i], v = readl(sleep_power_reg(s, a)); + + s->disp_adma_saved[i] = v; + if (FIELD_GET(PS_ACTUAL, v)) { + sleep_ps_lower(s, a); + s->disp_adma_lowered |= BIT(i); + if (sleep_ps_wait_off(s, a)) + s->extra_stuck |= BIT(31); + } + } if (sleep_asc_running(s, domains[i][0], asc)) { writel(0, asc + ASC_CPU_CONTROL); @@ -2698,6 +3435,8 @@ static int sleep_display_off(struct apple_sleep *s) for (i = 0; i < n; i++) { int err; + if (sleep_dispext_skip(s, i)) + continue; if (i != 0 && !s->display[i].bound && !s->soc->lower_unbound_displays) continue; @@ -2706,9 +3445,13 @@ static int sleep_display_off(struct apple_sleep *s) if (err) { dev_err(s->dev, "refused: display domain %#x stayed on: %#x\n", domains[i][0], readl(s->ps + domains[i][0])); + if (i != 0 && soc->dispext_optional) + s->dispext_note |= 0x80; ret = err; } } + if (soc->dispext_optional) + sleep_note_at(s, 22, s->dispext_note); return ret; } @@ -3998,55 +4741,232 @@ static bool apple_sleep_ps_unlatch(struct apple_sleep *s) return stuck; } -static void apple_sleep_match(struct apple_sleep *s) +struct t8142_mem_op { + u64 pa; + u64 val; + u8 op; +}; +#define T8142_MEM_WRITE BIT(0) +#define T8142_MEM_64 BIT(1) +#define T8142_MEM_FP BIT(4) +#include "sleep-t8142-mem.h" + +static void t8142_mem_map(struct apple_sleep *s) { - const struct apple_sleep_soc *soc = s->soc; - int i, raised = 0, lowered = 0, failed = 0; + unsigned int i; - writel(0, s->wdt + WDT_WD0_COUNT); - writel(0, s->wdt + WDT_WD1_COUNT); - sleep_pmu_write_one(s, soc->pmu_sleep_reg, soc->pmu_sleep_val, true); + BUILD_BUG_ON(ARRAY_SIZE(t8142_mem_pages) > ARRAY_SIZE(s->mem_boot_page)); + for (i = 0; i < ARRAY_SIZE(t8142_mem_pages); i++) + s->mem_boot_page[i] = devm_ioremap(s->dev, t8142_mem_pages[i], SZ_16K); +} - sleep_spmi_sources(s, 0); - s->spmi_saved[0] = readl(s->spmi + s->spmi_notify_enable); - s->spmi_saved[1] = readl(s->spmi_a0); - writel(soc->spmi_notify_sleep, s->spmi + s->spmi_notify_enable); - writel(soc->spmi_notify_sleep, s->spmi_a0); +static void __iomem *t8142_mem_va(struct apple_sleep *s, u64 pa) +{ + unsigned int i; - for (i = 0; i < soc->ps_macos_on.count; i++) { - u32 offset = soc->ps_macos_on.offset[i]; + for (i = 0; i < ARRAY_SIZE(t8142_mem_pages); i++) + if ((pa & ~(u64)(SZ_16K - 1)) == t8142_mem_pages[i]) + return s->mem_boot_page[i] ? s->mem_boot_page[i] + (pa & (SZ_16K - 1)) : NULL; + return NULL; +} - s->ps_on_saved[i] = readl(sleep_power_reg(s, offset)); - /* State 4 reads as on, and macOS has these at f. */ - if (FIELD_GET(PS_ACTUAL, s->ps_on_saved[i]) == 0xf) - continue; - /* Measured at the commit with AUTO_ENABLE clear, unlike after a wake. */ - if (sleep_ps_raise_start(s, offset)) - failed++; - raised++; - } - for (i = 0; i < soc->ps_macos_off.count; i++) { - u32 offset = soc->ps_macos_off.offset[i]; +/* The words XNU reads before its first write, against J813's (iBoot's) values: mismatches. */ +static unsigned int t8142_mem_fingerprint(struct apple_sleep *s, u64 *pa, u64 *got, u64 *want) +{ + unsigned int i, bad = 0; - s->ps_off_saved[i] = readl(sleep_power_reg(s, offset)); - if (!sleep_ps_on(s, offset)) + *pa = 0; + for (i = 0; i < ARRAY_SIZE(t8142_mem_boot); i++) { + const struct t8142_mem_op *o = &t8142_mem_boot[i]; + void __iomem *va; + u64 v; + + if (!(o->op & T8142_MEM_FP)) continue; - sleep_ps_lower(s, offset); - lowered++; + va = t8142_mem_va(s, o->pa); + if (!va) { + bad++; + continue; + } + v = (o->op & T8142_MEM_64) ? readq(va) : readl(va); + if (v == o->val) + continue; + if (!bad++) { + *pa = o->pa; + *got = v; + *want = o->val; + } } - for (i = 0; i < soc->ps_aon_macos_off.count; i++) { - void __iomem *reg = s->ps_aon + soc->ps_aon_macos_off.offset[i]; - u32 val = readl(reg); + return bad; +} - s->ps_aon_saved[i] = val; - if (!FIELD_GET(PS_ACTUAL, val)) +/* XNU's accesses in its order: the writes as it wrote them, the reads done and dropped. */ +static void t8142_mem_replay(struct apple_sleep *s) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(t8142_mem_boot); i++) { + const struct t8142_mem_op *o = &t8142_mem_boot[i]; + void __iomem *va = t8142_mem_va(s, o->pa); + + if (!va) continue; - if (val & PS_AUTO_ENABLE) { - val &= ~(PS_AUTO_ENABLE | PS_FLAGS); - writel(val, reg); + if (o->op & T8142_MEM_WRITE) { + if (o->op & T8142_MEM_64) + writeq(o->val, va); + else + writel(o->val, va); + } else if (o->op & T8142_MEM_64) { + readq(va); + } else { + readl(va); } - writel((val & ~PS_TARGET) | PS_FLAGS, reg); - lowered++; + } +} + +static void t8142_mem_boot_entry(struct apple_sleep *s) +{ + u64 pa, got, want; + + s->mem_boot_done = false; + s->mem_boot_mismatch = 0; + if (!s->soc->mem_boot || !READ_ONCE(sleep_mem_boot)) + return; + s->mem_boot_mismatch = t8142_mem_fingerprint(s, &pa, &got, &want); + if (s->mem_boot_mismatch) + return; + t8142_mem_replay(s); + s->mem_boot_done = true; +} + +static void __iomem *sleep_boot_auto_reg(struct apple_sleep *s, unsigned int i) +{ + unsigned int n = s->soc->ps_boot_auto.count; + + return i < n ? s->ps + s->soc->ps_boot_auto.offset[i] : + s->ps_aon + s->soc->ps_aon_boot_auto.offset[i - n]; +} + +static unsigned int sleep_boot_auto_count(struct apple_sleep *s) +{ + return min_t(unsigned int, s->soc->ps_boot_auto.count + s->soc->ps_aon_boot_auto.count, + ARRAY_SIZE(s->boot_auto_saved)); +} + +/* As XNU's PMGR start: the value with its flags cleared, then AUTO_ENABLE. On words that are on. */ +static int sleep_boot_auto(struct apple_sleep *s) +{ + unsigned int i, n = sleep_boot_auto_count(s); + int set = 0; + + s->boot_auto_set = 0; + s->boot_auto_nset = s->boot_auto_stuck = 0; + if (!READ_ONCE(sleep_boot_auto_on)) + return 0; + for (i = 0; i < n; i++) { + void __iomem *reg = sleep_boot_auto_reg(s, i); + u32 v = readl(reg); + + if ((v & PS_AUTO_ENABLE) || !FIELD_GET(PS_TARGET, v) || !FIELD_GET(PS_ACTUAL, v)) + continue; + s->boot_auto_saved[i] = v; + s->boot_auto_set |= BIT_ULL(i); + writel(v & ~PS_FLAGS, reg); + readl(reg); + writel((v & ~PS_FLAGS) | PS_AUTO_ENABLE, reg); + set++; + if (readl(reg) & PS_AUTO_ENABLE) + s->boot_auto_stuck++; + } + s->boot_auto_nset = set; + return set; +} + +/* A refusal before the commit: AUTO_ENABLE off again where this set it, the target as it was. */ +static void sleep_boot_auto_undo(struct apple_sleep *s) +{ + unsigned int i, n = sleep_boot_auto_count(s); + + for (i = 0; i < n; i++) + if (s->boot_auto_set & BIT_ULL(i)) + writel(s->boot_auto_saved[i] & ~PS_FLAGS, sleep_boot_auto_reg(s, i)); + s->boot_auto_set = 0; +} + +/* Whether the match leaves this word as it is (apple_sleep.ps_keep, as the match took it) */ +static bool sleep_ps_kept(struct apple_sleep *s, u32 offset, bool aon) +{ + unsigned int i; + + for (i = 0; i < s->soc->nps_keep; i++) { + const struct apple_sleep_ps_keep *k = &s->soc->ps_keep[i]; + + if (k->offset == offset && k->aon == aon) + return s->ps_keep_mask & BIT(k->group); + } + + return false; +} + +static void apple_sleep_match(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + int i, raised = 0, lowered = 0, failed = 0, kept = 0; + + s->ps_keep_mask = READ_ONCE(sleep_ps_keep); + + writel(0, s->wdt + WDT_WD0_COUNT); + writel(0, s->wdt + WDT_WD1_COUNT); + sleep_pmu_write_one(s, soc->pmu_sleep_reg, soc->pmu_sleep_val, true); + + sleep_spmi_sources(s, 0); + s->spmi_saved[0] = readl(s->spmi + s->spmi_notify_enable); + s->spmi_saved[1] = readl(s->spmi_a0); + writel(soc->spmi_notify_sleep, s->spmi + s->spmi_notify_enable); + writel(soc->spmi_notify_sleep, s->spmi_a0); + + for (i = 0; i < soc->ps_macos_on.count; i++) { + u32 offset = soc->ps_macos_on.offset[i]; + + s->ps_on_saved[i] = readl(sleep_power_reg(s, offset)); + /* State 4 reads as on, and macOS has these at f. */ + if (FIELD_GET(PS_ACTUAL, s->ps_on_saved[i]) == 0xf) + continue; + /* Measured at the commit with AUTO_ENABLE clear, unlike after a wake. */ + if (sleep_ps_raise_start(s, offset)) + failed++; + raised++; + } + for (i = 0; i < soc->ps_macos_off.count; i++) { + u32 offset = soc->ps_macos_off.offset[i]; + + s->ps_off_saved[i] = readl(sleep_power_reg(s, offset)); + if (!sleep_ps_on(s, offset)) + continue; + if (sleep_ps_kept(s, offset, false)) { + kept++; + continue; + } + sleep_ps_lower(s, offset); + lowered++; + } + for (i = 0; i < soc->ps_aon_macos_off.count; i++) { + void __iomem *reg = s->ps_aon + soc->ps_aon_macos_off.offset[i]; + u32 val = readl(reg); + + s->ps_aon_saved[i] = val; + if (!FIELD_GET(PS_ACTUAL, val)) + continue; + if (sleep_ps_kept(s, soc->ps_aon_macos_off.offset[i], true)) { + kept++; + continue; + } + if (val & PS_AUTO_ENABLE) { + val &= ~(PS_AUTO_ENABLE | PS_FLAGS); + writel(val, reg); + } + writel((val & ~PS_TARGET) | PS_FLAGS, reg); + lowered++; } for (i = 0; i < soc->ps_aon_macos_no_auto.count; i++) { void __iomem *reg = s->ps_aon + soc->ps_aon_macos_no_auto.offset[i]; @@ -4075,12 +4995,14 @@ static void apple_sleep_match(struct apple_sleep *s) for (i = 0; i < soc->ps_macos_off.count; i++) { u32 offset = soc->ps_macos_off.offset[i]; + if (sleep_ps_kept(s, offset, false)) + continue; if (sleep_ps_wait_off(s, offset)) dev_dbg(s->dev, "still on, macOS has it off: %x = %x\n", offset, readl(sleep_power_reg(s, offset))); } - dev_dbg(s->dev, "macOS's power words: raised %d, %d of them failed, lowered %d\n", - raised, failed, lowered); + dev_dbg(s->dev, "macOS's power words: raised %d, %d of them failed, lowered %d, kept on %d\n", + raised, failed, lowered, kept); } /* Back as they were, after a refusal past the match or a real wake. */ @@ -4100,11 +5022,13 @@ static void apple_sleep_match_undo(struct apple_sleep *s) writel(s->ps_aon_auto_saved[i] & ~PS_FLAGS, s->ps_aon + soc->ps_aon_macos_no_auto.offset[i]); for (i = soc->ps_aon_macos_off.count - 1; i >= 0; i--) - if (FIELD_GET(PS_ACTUAL, s->ps_aon_saved[i])) + if (FIELD_GET(PS_ACTUAL, s->ps_aon_saved[i]) && + !sleep_ps_kept(s, soc->ps_aon_macos_off.offset[i], true)) writel(s->ps_aon_saved[i] & ~PS_FLAGS, s->ps_aon + soc->ps_aon_macos_off.offset[i]); for (i = soc->ps_macos_off.count - 1; i >= 0; i--) - if (FIELD_GET(PS_ACTUAL, s->ps_off_saved[i])) + if (FIELD_GET(PS_ACTUAL, s->ps_off_saved[i]) && + !sleep_ps_kept(s, soc->ps_macos_off.offset[i], false)) sleep_ps_raise(s, soc->ps_macos_off.offset[i]); for (i = soc->ps_macos_on.count - 1; i >= 0; i--) { u32 val = s->ps_on_saved[i]; @@ -4260,12 +5184,25 @@ static void apple_sleep_dcs_down(struct apple_sleep *s) /* The boot core's last WFI. An event that ends it is taken, and the WFI taken again. */ static void __noreturn sleep_boot_wfi(struct apple_sleep *s) { + bool t8142 = s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm, noted = false; + bool observed = t8142 && READ_ONCE(sleep_observer_ms); + u64 t0; + + if (observed) { + WRITE_ONCE(t8142_obs_boot_wfi, 1); + dsb(sy); + } sleep_deep_wfi_arm(); + t0 = read_sysreg(cntpct_el0); while (true) { dsb(sy); isb(); wfi(); + if (observed) + WRITE_ONCE(t8142_obs_wfi_back, READ_ONCE(t8142_obs_wfi_back) + 1); + else if (t8142) + t8142_wfi_returned(s, t0, ¬ed); s->soc->ops->aic_ack(); write_sysreg_s(IPI_SR_PENDING, SYS_APL_IPI_SR_EL1); } @@ -4293,10 +5230,13 @@ static void apple_sleep_wait_still_on(struct apple_sleep *s) * before this, with no SPMI traffic near the engine. */ static bool sleep_v27_selected_for(struct apple_sleep *s); +static void t8142_last_mile(struct apple_sleep *s); +static void t8142_post_commit_probe(struct apple_sleep *s, unsigned int ms); static int apple_sleep_commit(unsigned long unused) { struct apple_sleep *s = apple_sleep; + bool early; if (s->soc->ops->commit_begin) s->soc->ops->commit_begin(s); @@ -4306,8 +5246,20 @@ static int apple_sleep_commit(unsigned long unused) * stay coherent until the commit. */ s->siq_cfg = read_sysreg_s(SYS_APL_SIQ_CFG_EL1); + WRITE_ONCE(t8142_boot_mpidr, read_cpuid_mpidr() & MPIDR_HWID_BITMASK); sleep_note(s, 0x60); + WRITE_ONCE(t8142_obs_boot_wfi, 0); + WRITE_ONCE(t8142_obs_wfi_back, 0); + early = s->soc->early_cpu_wfi && READ_ONCE(sleep_early_wfi); + if (early) { + /* Released before the stop: each core goes from its stop bit to its deep WFI. */ + spin_table_pen_deep_el1(s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm && + is_kernel_in_hyp_mode() && READ_ONCE(sleep_el1_wfi) >= 2); + spin_table_release_stopped(); + } s->cpus_stop_ret = spin_table_stop_parked(); + if (early) + udelay(SLEEP_EARLY_WFI_SETTLE_US); if (s->soc->ops->commit_regs) { /* A SoC whose irreversible steps share nothing with the ones below. */ @@ -4343,9 +5295,15 @@ static int apple_sleep_commit(unsigned long unused) s->soc->ops->post_timer(s); /* Each core's deep WFI comes after the commit, this one last. No SPMI from here on. */ - spin_table_release_stopped(); + if (!early) { + spin_table_pen_deep_el1(s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm && + is_kernel_in_hyp_mode() && READ_ONCE(sleep_el1_wfi) >= 2); + spin_table_release_stopped(); + } if (s->soc->boot_wfi_delay_ms) mdelay(s->soc->boot_wfi_delay_ms); + if (s->soc->ops->last_mile == t8142_last_mile && READ_ONCE(sleep_post_commit_ms)) + t8142_post_commit_probe(s, READ_ONCE(sleep_post_commit_ms)); sleep_boot_wfi(s); } @@ -4933,6 +5891,9 @@ static int apple_sleep_enter_early(struct apple_sleep *s) return ret; } +static void t8142_mem_save(struct apple_sleep *s); +static void t8142_clk_save(struct apple_sleep *s); + static int apple_sleep_enter(suspend_state_t state) { struct apple_sleep *s = apple_sleep; @@ -4955,10 +5916,256 @@ static int apple_sleep_enter(suspend_state_t state) if (s->soc->untested && !READ_ONCE(sleep_untested_commit)) { sleep_note(s, 0x31); apple_sleep_stray_restore(s); + /* nub-spmi0's latched sources as a sleep would find them, for apple,spmi-pmu-sources: + * read only while the DT names no bits (then this acknowledges them, as the entry does). + */ + sleep_spmi_sources(s, 0); + sleep_spmi_sources_report(s); + /* The boot core's power controls here, to diff against macOS's at its commit (aura's + * R.* ring markers). Reads only: interrupts are off and the secondaries are held. + */ + if (READ_ONCE(sleep_dry_regs) && s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm && is_kernel_in_hyp_mode()) + dev_info(s->dev, "dry run: boot cpu%d C1_6 %#llx C6_2 %#llx C5_0 %#llx C10_4 %#llx C7_4 %#llx C1_1 %#llx\n", + raw_smp_processor_id(), read_sysreg_s(SLEEP_M5_C1_6), + read_sysreg_s(sys_reg(3, 5, 15, 6, 2)), read_sysreg_s(sys_reg(3, 5, 15, 5, 0)), + read_sysreg_s(sys_reg(3, 4, 15, 10, 4)), read_sysreg_s(sys_reg(3, 1, 15, 7, 4)), + read_sysreg_s(sys_reg(3, 5, 15, 1, 1))); + /* What XNU's per-core init (26B131 kc +0x4ed3d3c) writes on every core: c1_5 = 0, + * c14_6 = 3, c10_4 = 0, c9_6 |= ..|0xf, c0_5 = 1, c13_4 = 2; cntkctl |= 3. + */ + if (READ_ONCE(sleep_dry_regs) && s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm && is_kernel_in_hyp_mode()) + dev_info(s->dev, "dry run: boot cpu XNU-init regs: s3_1_c15_c1_5 %#llx s3_4_c15_c14_6 %#llx s3_4_c15_c9_6 %#llx s3_1_c15_c0_5 %#llx s3_1_c15_c13_4 %#llx cntkctl %#llx\n", + read_sysreg_s(sys_reg(3, 1, 15, 1, 5)), read_sysreg_s(sys_reg(3, 4, 15, 14, 6)), + read_sysreg_s(sys_reg(3, 4, 15, 9, 6)), read_sysreg_s(sys_reg(3, 1, 15, 0, 5)), + read_sysreg_s(sys_reg(3, 1, 15, 13, 4)), read_sysreg(cntkctl_el1)); + if (READ_ONCE(sleep_dry_regs) && s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm) { + dev_info(s->dev, "dry run: boot cpu FIQ sources: PMCR0 %#llx UPMCR0 %#llx UPMSR %#llx IPI_SR %#llx cntp/cntv_el0 %#llx/%#llx cntp/cntv_el02 %#llx/%#llx VM_TMR_FIQ_ENA %#llx ISR %#llx CLPC C5_0 %#llx; still firing %#x\n", + read_sysreg_s(T8142_PMCR0), read_sysreg_s(T8142_UPMCR0), read_sysreg_s(T8142_UPMSR), + read_sysreg_s(SYS_APL_IPI_SR_EL1), read_sysreg(cntp_ctl_el0), read_sysreg(cntv_ctl_el0), + is_kernel_in_hyp_mode() ? read_sysreg_s(SYS_CNTP_CTL_EL02) : 0, + is_kernel_in_hyp_mode() ? read_sysreg_s(SYS_CNTV_CTL_EL02) : 0, + is_kernel_in_hyp_mode() ? read_sysreg_s(T8142_VM_TMR_FIQ_ENA) : 0, + read_sysreg(isr_el1), read_sysreg_s(T8142_CLPC_C5_0), t8142_fiq_sources()); + t8142_ed_report(s->dev); + if (is_kernel_in_hyp_mode()) { + u64 o = read_sysreg_s(SLEEP_M5_C1_6), w; + + write_sysreg_s(o | SLEEP_M5_C1_6_PWRDN, SLEEP_M5_C1_6); + isb(); + w = read_sysreg_s(SLEEP_M5_C1_6); + write_sysreg_s(o, SLEEP_M5_C1_6); + isb(); + dev_info(s->dev, "dry run: C1_6 write test: %#llx | 0x1c000000 reads back %#llx (%s)\n", + o, w, (w & SLEEP_M5_C1_6_PWRDN) == SLEEP_M5_C1_6_PWRDN ? "sticks" : "IGNORED"); + } + } + /* The wake restores' reads, here too, so a read that hangs shows in the ladder. */ + if (s->soc->ops->last_mile == t8142_last_mile) { + t8142_mem_save(s); + t8142_clk_save(s); + dev_info(s->dev, "dry run: wake saves: mem %d (amcc0 %#llx cfg0 %#llx ch0 %#x/%#x/%#x) clk %d (slot0 %#x:%#x) early_wfi %d\n", + s->mem_saved, s->amcc_saved[0], s->amcc_cfg_saved[0][0], + s->mcc_saved[0][0], s->mcc_saved[0][MCC_ENABLES / 4], + s->mcc_saved[0][MCC_LANES / 4], s->clk_saved, + s->clk_slot_saved[0][1], s->clk_slot_saved[0][0], + s->soc->early_cpu_wfi && READ_ONCE(sleep_early_wfi)); + s->mem_saved = s->clk_saved = false; + } + /* Read-only: what the match would find in the words macOS leaves on (ps_keep). */ + if (s->soc->nps_keep) { + char line[400]; + int i, n = 0; + + for (i = 0; i < s->soc->nps_keep; i++) { + const struct apple_sleep_ps_keep *k = &s->soc->ps_keep[i]; + + n += scnprintf(line + n, sizeof(line) - n, " %s %#x", k->name, + readl((k->aon ? s->ps_aon : s->ps) + k->offset)); + } + n += scnprintf(line + n, sizeof(line) - n, " ATC0_COMMON %#x ATC0_USB_AON %#x ATC0_USB %#x", + readl(s->ps + T8142_PS_ATC0_COMMON), + readl(s->ps_aon + T8142_PS_AON_ATC0_USB_AON), + readl(s->ps_aon + T8142_PS_AON_ATC0_USB)); + dev_info(s->dev, "dry run: ps_keep %#x, the words:%s\n", + READ_ONCE(sleep_ps_keep), line); + } + /* Read-only: XNU's boot AUTO_ENABLE list as Linux has it (apple_sleep.boot_auto) */ + if (sleep_boot_auto_count(s)) { + char line[700]; + unsigned int i, n = 0, missing = 0, autoed = 0, off_words = 0; + u32 v; + + for (i = 0; i < sleep_boot_auto_count(s); i++) { + bool aon = i >= s->soc->ps_boot_auto.count; + u32 off = aon ? s->soc->ps_aon_boot_auto.offset[i - s->soc->ps_boot_auto.count] : + s->soc->ps_boot_auto.offset[i]; + + v = readl(sleep_boot_auto_reg(s, i)); + if (v & PS_AUTO_ENABLE) { + autoed++; + } else if (FIELD_GET(PS_TARGET, v) && FIELD_GET(PS_ACTUAL, v)) { + missing++; + n += scnprintf(line + n, sizeof(line) - n, " %s%x=%x", + aon ? "a" : "", off, v); + } else { + off_words++; + } + } + dev_info(s->dev, "dry run: boot_auto %d: of XNU's %u AUTO_ENABLE words %u already have it, %u are off, %u on without it:%s\n", + READ_ONCE(sleep_boot_auto_on), sleep_boot_auto_count(s), autoed, + off_words, missing, line); + /* + * The one power-word write a dry run makes (apple_sleep.boot_auto_dry): XNU's + * boot write on those words, each read back at once and 1 ms later, then undone. + */ + if (READ_ONCE(sleep_boot_auto_on) && READ_ONCE(sleep_boot_auto_dry)) { + u32 now[64]; + unsigned int set; + + sleep_note(s, 0x3d); + set = sleep_boot_auto(s); + mdelay(1); + n = 0; + for (i = 0; i < sleep_boot_auto_count(s); i++) { + bool aon = i >= s->soc->ps_boot_auto.count; + u32 off = aon ? s->soc->ps_aon_boot_auto.offset[i - s->soc->ps_boot_auto.count] : + s->soc->ps_boot_auto.offset[i]; + + if (!(s->boot_auto_set & BIT_ULL(i))) + continue; + now[i] = readl(sleep_boot_auto_reg(s, i)); + n += scnprintf(line + n, sizeof(line) - n, " %s%x=%x", aon ? "a" : "", + off, now[i]); + } + sleep_boot_auto_undo(s); + dev_info(s->dev, "dry run: boot_auto write test: %u set, %u read AUTO_ENABLE back at once; 1 ms later:%s (undone)\n", + set, s->boot_auto_stuck, line); + } + } + /* Read-only: the memory-controller start's fingerprint and the PMC's four voters */ + if (s->soc->mem_boot) { + u64 pa = 0, got = 0, want = 0; + unsigned int bad = t8142_mem_fingerprint(s, &pa, &got, &want); + + dev_info(s->dev, "dry run: mem_boot %d mem_floor %d: fingerprint %u of 34 differ (first %#llx: %#llx, J813 %#llx); PMC voters +0/+4: %#x/%#x %#x/%#x %#x/%#x %#x/%#x\n", + READ_ONCE(sleep_mem_boot), READ_ONCE(sleep_mem_floor), bad, pa, got, want, + readl(s->pmc_voters), readl(s->pmc_voters + 4), + readl(s->pmc_voters + PMC_VOTER_STRIDE), + readl(s->pmc_voters + PMC_VOTER_STRIDE + 4), + readl(s->pmc_voters + 2 * PMC_VOTER_STRIDE), + readl(s->pmc_voters + 2 * PMC_VOTER_STRIDE + 4), + readl(s->pmc_voters + 3 * PMC_VOTER_STRIDE), + readl(s->pmc_voters + 3 * PMC_VOTER_STRIDE + 4)); + } + /* Read-only: every word of the match's off lists that reads on, i.e. that it lowers. */ + if (s->soc->ps_macos_off.count || s->soc->ps_aon_macos_off.count) { + const struct apple_sleep_words *off = &s->soc->ps_macos_off; + const struct apple_sleep_words *aoff = &s->soc->ps_aon_macos_off; + char line[800]; + int i, n = 0; + u32 v; + + for (i = 0; i < off->count; i++) { + v = readl(sleep_power_reg(s, off->offset[i])); + if (FIELD_GET(PS_ACTUAL, v)) + n += scnprintf(line + n, sizeof(line) - n, " %x=%x", + off->offset[i], v); + } + n += scnprintf(line + n, sizeof(line) - n, " | aon"); + for (i = 0; i < aoff->count; i++) { + v = readl(s->ps_aon + aoff->offset[i]); + if (FIELD_GET(PS_ACTUAL, v)) + n += scnprintf(line + n, sizeof(line) - n, " %x=%x", + aoff->offset[i], v); + } + dev_info(s->dev, "dry run: macos_off words on now (the match lowers them unless kept):%s\n", + line); + } + /* Read-only: what apple_sleep.dispext lowers (T8142's external DCPs). */ + if (s->soc->dispext_optional) { + char line[400]; + int i, k, n = 0; + + for (i = 1; i < s->soc->ndisp; i++) { + n += scnprintf(line + n, sizeof(line) - n, " | ext%d %s:", i - 1, + !s->display[i].np ? "no node" : + s->display[i].bound ? "bound" : "unbound"); + for (k = 0; k < 3; k++) + n += scnprintf(line + n, sizeof(line) - n, " %x=%x", + s->soc->ps.disp[i][k], + readl(s->ps + s->soc->ps.disp[i][k])); + n += scnprintf(line + n, sizeof(line) - n, " run %d", + sleep_asc_running(s, s->soc->ps.disp[i][0], + s->display[i].asc)); + if (s->soc->disp_wr_dis[i][0]) + n += scnprintf(line + n, sizeof(line) - n, " wr-dis %d", + !!(readl(s->ps + s->soc->disp_wr_dis[i][0]) & + BIT(s->soc->disp_wr_dis[i][1]))); + } + dev_info(s->dev, "dry run: dispext %d:%s\n", READ_ONCE(sleep_dispext), line); + } + /* Read-only: what apple_sleep.extra_off would lower (only those on). */ + if (s->soc->nextra_off) { + static char line[900]; + int i, n = 0; + + for (i = 0; i < s->soc->nextra_off; i++) + n += scnprintf(line + n, sizeof(line) - n, " %s %x=%x", + s->soc->extra_off[i].name, s->soc->extra_off[i].offset, + readl(sleep_power_reg(s, s->soc->extra_off[i].offset))); + for (i = 0; i < s->soc->ndisp; i++) + if (s->soc->disp_adma[i]) + n += scnprintf(line + n, sizeof(line) - n, " adma%d %x=%x", i, + s->soc->disp_adma[i], + readl(sleep_power_reg(s, s->soc->disp_adma[i]))); + dev_info(s->dev, "dry run: extra_off %d:%s\n", READ_ONCE(sleep_extra_off), line); + } + /* + * Read-only, before the display, coprocessor and match steps: every ps word on + * (index:offset=value; * = macOS has it off at its commit), the list the commit's PMU + * digest can only count; aon: every word on without AUTO_ENABLE. + */ + if (s->soc->ops->macos_off_at_commit) { + const struct apple_sleep_words *all = &s->soc->ps_all; + const struct apple_sleep_words *aon = &s->soc->ps_aon_all; + /* Interrupts are off here: no allocation. */ + static char line[1024]; + int i, n = 0; + u32 v; + + line[0] = 0; + for (i = 0; i < all->count; i++) { + v = readl(s->ps + all->offset[i]); + if (!FIELD_GET(PS_ACTUAL, v)) + continue; + n += scnprintf(line + n, 1024 - n, " %d:%x=%x%s", i, all->offset[i], v, + s->soc->ops->macos_off_at_commit(all->offset[i]) ? "*" : ""); + /* printk would cut a long line: a new one every 24 words */ + if (n > 400) { + dev_info(s->dev, "dry run: ps on (* = off at macOS's commit):%s\n", + line); + n = 0; + line[0] = 0; + } + } + dev_info(s->dev, "dry run: ps on (* = off at macOS's commit):%s\n", line); + line[0] = 0; + for (i = 0, n = 0; i < aon->count; i++) { + v = readl(s->ps_aon + aon->offset[i]); + if (!FIELD_GET(PS_ACTUAL, v) || (v & PS_AUTO_ENABLE)) + continue; + n += scnprintf(line + n, 1024 - n, " %d:%x=%x", i, aon->offset[i], v); + } + dev_info(s->dev, "dry run: aon on without AUTO:%s\n", line); + } dev_info(s->dev, "dry run: every check passed; refusing before the commit (untested SoC, apple_sleep.untested_commit=1 lets it through)\n"); return -EAGAIN; } + if (sleep_boot_auto_count(s)) { + sleep_note(s, 0x3e); + sleep_note_at(s, 2, min(sleep_boot_auto(s), 255)); + } sleep_note(s, 0x40); ret = apple_sleep_cpus_hold(s); /* As on macOS, the display goes off before the GPU. */ @@ -4980,12 +6187,28 @@ static int apple_sleep_enter(suspend_state_t state) if (ret) { dev_dbg(s->dev, "refused before any commit coprocessor stop: %d\n", ret); spin_table_unhold_parked(); + sleep_dispext_restore(s); + sleep_boot_auto_undo(s); apple_sleep_stray_restore(s); return ret; } sleep_note(s, 0x44); sleep_ps_wr_dis_clear(s); apple_sleep_coprocs_stop(s, true); + if (s->soc->mem_boot && READ_ONCE(sleep_mem_boot)) { + sleep_note(s, 0x4c); + t8142_mem_boot_entry(s); + } + s->mem_floor_done = false; + if (s->soc->mem_boot && READ_ONCE(sleep_mem_floor)) { + /* T6050's stage: the floor's voter stepped down 2, then 1, 9 ms apart */ + sleep_note(s, 0x4d); + writel(2, s->pmc_voters + PMC_VOTER_STRIDE * 1); + mdelay(9); + writel(1, s->pmc_voters + PMC_VOTER_STRIDE * 1); + mdelay(9); + s->mem_floor_done = true; + } sleep_note(s, 0x45); sleep_wake_arm(s); @@ -5536,6 +6759,10 @@ static int apple_sleep_map_displays(struct apple_sleep *s) int index; np = of_parse_phandle(s->dev->of_node, "apple,display-coprocessors", i); + if (!np && i != 0 && s->soc->dispext_optional) { + dev_info(s->dev, "no external display coprocessor %d: not lowered\n", i); + continue; + } if (!np) return dev_err_probe(s->dev, -ENODEV, "no display coprocessor %d\n", i); s->display[i].np = np; @@ -5697,6 +6924,23 @@ static int apple_sleep_map_regs(struct apple_sleep *s) if (IS_ERR(s->mem_clk)) s->mem_clk = NULL; + /* T8142's memory-controller start, mapped page by page (shared with nothing that binds) */ + if (s->soc->mem_boot) + t8142_mem_map(s); + + /* T8142's wake restores (optional: a tree without them skips that restore). */ + s->clk_slots = apple_sleep_map(s->dev, "clk-slots"); + if (IS_ERR(s->clk_slots)) + s->clk_slots = NULL; + for (i = 0; i < s->soc->namcc; i++) { + char name[16]; + + snprintf(name, sizeof(name), "amcc-cfg%d", i); + s->amcc_cfg[i] = apple_sleep_map(s->dev, name); + if (IS_ERR(s->amcc_cfg[i])) + s->amcc_cfg[i] = NULL; + } + /* Lowering an unbound display clears its clock protection first. */ if (s->soc->lower_unbound_displays) { s->ps_prot = apple_sleep_map(s->dev, "ps-prot"); @@ -6425,6 +7669,17 @@ static int apple_sleep_probe(struct platform_device *pdev) if (s->soc->untested) { if (mem_sleep_current == PM_SUSPEND_MEM) mem_sleep_current = PM_SUSPEND_TO_IDLE; + if (s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm && is_kernel_in_hyp_mode()) + t8142_c1_6_report(dev); + if (s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm) { + t8142_ed_map(dev); + dcache_clean_poc((unsigned long)t8142_el1_wfi_stub, + (unsigned long)t8142_el1_wfi_stub_end); + dev_info(dev, "probe: last WFI at %s (stub at PA %pa)\n", + !is_kernel_in_hyp_mode() || !READ_ONCE(sleep_el1_wfi) ? "the kernel's EL" : + READ_ONCE(sleep_el1_wfi) >= 2 ? "EL1 on every core" : "EL1 on the boot core", + &(phys_addr_t){ __pa_symbol(t8142_el1_wfi_stub) }); + } dev_info(dev, "probe: pwrgate wake %#x %#x cpm %#x %#x, commit %#x, clusters %#x %#x\n", readl(s->pwrgate + s->soc->pwrgate_wake[0]), readl(s->pwrgate + s->soc->pwrgate_wake[1]), @@ -6885,9 +8140,6 @@ static const struct apple_sleep_soc t8132_sleep_soc = { * the commit. The DT's cluster power gate sets it at boot (apple-cluster-pwrgate.c), as on * T8132 and T6050. */ -#define T8142_PS_ATC0_COMMON 0x2c8 -#define T8142_PS_AON_ATC0_USB_AON 0xc8 -#define T8142_PS_AON_ATC0_USB 0xd0 #define T8142_PMC_VOTER_AP (3 * PMC_VOTER_STRIDE) #define T8142_CLUSTER_BUSY BIT(4) /* @@ -6949,27 +8201,80 @@ static void t8142_cpm_on(struct apple_sleep *s) } } +/* + * apple_sleep.extra_off, after every coprocessor's last stop and before ATC0/PCIe/PMP: each listed + * word that is on, in the list's order (children first), waited off; one that stays on is noted, + * not refused (past the last refusal point). + */ +static void t8142_extra_lower(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + unsigned int i; + + s->extra_lowered = 0; + if (!READ_ONCE(sleep_extra_off)) + return; + for (i = 0; i < min_t(unsigned int, soc->nextra_off, SLEEP_EXTRA_OFF_MAX); i++) { + u32 off = soc->extra_off[i].offset, v = readl(sleep_power_reg(s, off)); + + s->extra_saved[i] = v; + if (!FIELD_GET(PS_ACTUAL, v)) + continue; + sleep_ps_lower(s, off); + s->extra_lowered |= BIT(i); + if (sleep_ps_wait_off(s, off)) + s->extra_stuck |= BIT(i); + } +} + +/* At the wake, parents first: each lowered word back once its parent reads on. */ +static void t8142_extra_restore(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + int i; + + for (i = min_t(unsigned int, soc->nextra_off, SLEEP_EXTRA_OFF_MAX) - 1; i >= 0; i--) { + u32 parent = soc->extra_off[i].parent; + + if (!(s->extra_lowered & BIT(i))) + continue; + if (!parent || FIELD_GET(PS_ACTUAL, readl(sleep_power_reg(s, parent)))) + sleep_ps_restore(sleep_power_reg(s, soc->extra_off[i].offset), + s->extra_saved[i]); + } + s->extra_lowered = 0; +} + /* T8132's, with T8142's ATC0 words; ANS's PCIe block in AppleT8142PCIe's order. */ static void t8142_lower_io(struct apple_sleep *s) { sleep_note(s, 0x61); t8132_clean_ram(); sleep_note(s, 0x62); + t8142_extra_lower(s); s->atc0_saved[0] = readl(s->ps_aon + T8142_PS_AON_ATC0_USB); s->atc0_saved[1] = readl(s->ps_aon + T8142_PS_AON_ATC0_USB_AON); s->atc0_saved[2] = readl(s->ps + T8142_PS_ATC0_COMMON); - t8132_aon_lower(s, T8142_PS_AON_ATC0_USB); - if (!READ_ONCE(sleep_usb_asleep)) - t8132_aon_lower(s, T8142_PS_AON_ATC0_USB_AON); - sleep_ps_lower(s, T8142_PS_ATC0_COMMON); + /* apple_sleep.ps_keep bit 3: as macOS would, if its ports weren't hidden in the trace */ + if (!(s->ps_keep_mask & BIT(3))) { + t8132_aon_lower(s, T8142_PS_AON_ATC0_USB); + if (!READ_ONCE(sleep_usb_asleep)) + t8132_aon_lower(s, T8142_PS_AON_ATC0_USB_AON); + sleep_ps_lower(s, T8142_PS_ATC0_COMMON); + } if (s->pcie_ans_stopped) { apple_sleep_lower_apcie(s); s->ans_off_ret = sleep_ps_wait_off(s, s->soc->ps.ans); } - /* PMP's callback has idled the firmware and saved SRAM; RUN is clear. */ - sleep_ps_lower(s, 0x598); - if (sleep_ps_wait_off(s, 0x598)) - dev_warn(s->dev, "PMP power domain did not turn off\n"); + /* PMP's final stop has idled its firmware and saved its SRAM; RUN is clear (#4). */ + s->pmp_lowered = false; + s->pmp_off_ret = 0; + if (READ_ONCE(sleep_pmp_off) && sleep_ps_on(s, T8142_PS_PMP)) { + s->pmp_saved = readl(s->ps + T8142_PS_PMP); + sleep_ps_lower(s, T8142_PS_PMP); + s->pmp_lowered = true; + s->pmp_off_ret = sleep_ps_wait_off(s, T8142_PS_PMP); + } sleep_note(s, 0x63); } @@ -6980,83 +8285,51 @@ static void t8142_lower_io(struct apple_sleep *s) * is >= 256, 0x20 the commit word read non-zero (it reads 1 from boot on J815). No PMU traffic * after it: the engine gives the cores 33 ms from the complex words to their WFI. */ -static void t8142_commit_note(struct apple_sleep *s) -{ - u8 flags = 0, src = 0xff; - int i; - - if (!sleep_notes_on(s)) - return; - if (s->cpus_stop_ret) - flags |= 0x01; - if (s->perf_soc_ret) - flags |= 0x02; - if (s->perf_dcs_ret) - flags |= 0x04; - for (i = 0; i < s->soc->wake_words; i++) { - u32 pend = readl(s->wake + s->soc->wake_status + i * 4) & s->wake_armed[i]; - - if (!pend) - continue; - if (!(flags & 0x08)) { - u32 id = i * 32 + __ffs(pend); - - src = id & 0xff; - if (id > 0xff) - flags |= 0x10; - } - flags |= 0x08; - } - if (readl(s->commit)) - flags |= 0x20; - sleep_note_at(s, 2, flags); - sleep_note_at(s, 4, src); - sleep_note(s, 0x65); -} - /* - * The PMU's RTC alarm after the S2R timer, as macOS 27.2 sends it on the J813 (traced - * 2026-11-16, run g01: 0.11 to 0.25 ms after the timer, boot core): read RTC_CTL (0x41), - * the 4-byte compare at 0x2008, 0x200e <- 0, RTC_CTL <- 0x41; 0x43 first if it had fired. - * The same registers and order as T6050's post-timer step (apple,pmu-alarm-rearm 0x43 0x41). - * Without it the SoC never goes down after the timer and WD2 resets it (J813, PMU note 0x67). - * TEST: the compare is now + apple_sleep.t8142_wake_s (0: macOS's own compare as found). + * The PMU's RTC alarm after the S2R timer, as macOS 27.2 sends it on the J813 (Thomas + * Glanzmann, m0d16l14n1/linux#3, from trace g01: 0.11 to 0.25 ms after the timer, boot core): + * read RTC_CTL, 0x43 if it had fired, the 4-byte compare at 0x2008, 0x200e <- 0, RTC_CTL <- + * 0x41. T6050's post-timer step at the same addresses (apple,pmu-alarm-rearm 0x43 0x41). The + * opcode carries the byte count (his follow-up fix). The compare and the counter are read here, + * before the cores' window, with the notes; the compare is now + apple_sleep.t8142_wake_s + * (0 keeps the PMU's own), which is also a wake source: J815 has no RTC device under Linux. + * J813 still resets with it (PMU took all four commands), so this is parity, not the fix. */ +static bool sleep_pmu_alarm = true; +module_param_named(pmu_alarm, sleep_pmu_alarm, bool, 0644); +MODULE_PARM_DESC(pmu_alarm, "T8142: send the PMU's RTC alarm after the S2R timer, as macOS does (default Y)"); static unsigned int t8142_wake_s = 30; module_param(t8142_wake_s, uint, 0644); -MODULE_PARM_DESC(t8142_wake_s, "T8142 TEST: PMU RTC alarm this many s after the commit (0: keep the PMU's)"); +MODULE_PARM_DESC(t8142_wake_s, "T8142: the PMU RTC alarm this many s after the commit (0: keep the PMU's)"); static u8 t8142_alarm[4]; static bool t8142_alarm_ok; static int t8142_post_ret = -ENODATA; static u64 t8142_alarm_counter; -/* The opcode carries the byte count, as t6050_sleep_pmu_xfer() builds it (macOS: 0x33 for 4). */ -static int t8142_pmu(struct apple_sleep *s, u32 mask, u8 opcode, u16 address, const u8 *wr, u8 *rd, - unsigned int len) +static int t8142_pmu(struct apple_sleep *s, u32 mask, u8 opcode, u16 address, const u8 *wr, + u8 *rd, unsigned int len) { return t6050_sleep_pmu_xfer_post(s, mask, opcode | (len - 1), address, wr, rd, len); } -static void t8142_pre_commit(struct apple_sleep *s) +static void t8142_alarm_prepare(struct apple_sleep *s) { u32 mask = s->soc->spmi_notify_sleep; u8 ticks[8] = {}; t8142_alarm_ok = false; t8142_post_ret = -ENODATA; - if (s->spmi) { - t6050_sleep_pmu_drain(s); - if (!t8142_pmu(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_COMPARE, - NULL, t8142_alarm, 4) && - !t8142_pmu(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_COUNTER, - NULL, ticks, 6)) { - t8142_alarm_counter = get_unaligned_le64(ticks) >> 16; - if (t8142_wake_s) - put_unaligned_le32(t8142_alarm_counter + t8142_wake_s, t8142_alarm); - t8142_alarm_ok = true; - } + if (!s->spmi || !READ_ONCE(sleep_pmu_alarm)) + return; + t6050_sleep_pmu_drain(s); + if (!t8142_pmu(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_COMPARE, NULL, t8142_alarm, 4) && + !t8142_pmu(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_COUNTER, NULL, ticks, 6)) { + t8142_alarm_counter = get_unaligned_le64(ticks) >> 16; + if (READ_ONCE(t8142_wake_s)) + put_unaligned_le32(t8142_alarm_counter + READ_ONCE(t8142_wake_s), t8142_alarm); + t8142_alarm_ok = true; } - t8132_pre_commit(s); + t6050_sleep_pmu_drain(s); } static void t8142_post_timer(struct apple_sleep *s) @@ -7070,25 +8343,191 @@ static void t8142_post_timer(struct apple_sleep *s) ret = t8142_pmu(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_CTL, NULL, &ctl, 1); if (!ret && (ctl & T6050_RTC_CTL_FIRED)) { v = 0x43; - ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_CTL, &v, - NULL, 1); + ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_CTL, &v, NULL, 1); } if (!ret) - ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_COMPARE, - t8142_alarm, NULL, 4); + ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_COMPARE, t8142_alarm, NULL, 4); if (!ret) { v = 0; - ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_MASK, &v, - NULL, 1); + ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_MASK, &v, NULL, 1); } if (!ret) { v = 0x41; - ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_CTL, &v, - NULL, 1); + ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_CTL, &v, NULL, 1); } t8142_post_ret = ret; } +/* + * What survives the reset, at 0x8310.. (J813's #4 used the same bytes): the power words as the + * commit has them. +8 ps_all words on without AUTO_ENABLE, +9 ps_all words on that macOS has off, + * +10/+11 ps_all words on that macOS never touched (past the CPUs) and the first one's index + * (0xff none), +12 ps_aon_all words on + * without it, +13 the first such index, +14/+15 the SEP word's bits 7:0 and 31:24 (macOS: 0x0f, + * 0x10), +5..+7 and +16..+19 the first seven of +9's. PMU scratch from 0x831f up holds data + * that isn't Linux's (the same on every boot): nothing is written there. + */ +#define T8142_PS_SEP 0xc00 +/* + * The ps_all words macOS has OFF (actual state 0) at its commit: the last value each had in the + * J813 g01 end state (notes/sleep-trace/macos-ps-endstate-g01-sleep1.txt). Of t8142_ps_all's + * 156: 66 off, 38 on, 52 never touched in the trace (unknown). By actual state only: a written + * 0x100000ff reads back without AUTO_ENABLE on macOS too, so that bit can't be compared. + */ +static bool t8142_macos_off_at_commit(u32 offset) +{ + static const u32 off[] = { + 0x190, 0x198, 0x1a0, 0x1a8, 0x1b0, 0x290, 0x298, 0x2a0, 0x2a8, 0x2b8, + 0x2c0, 0x2e8, 0x2f0, 0x2f8, 0x300, 0x308, 0x310, 0x318, 0x320, 0x328, + 0x330, 0x350, 0x360, 0x3a0, 0x3a8, 0x3b0, 0x3b8, 0x3c0, 0x3c8, 0x3d0, + 0x3d8, 0x3e0, 0x408, 0x410, 0x418, 0x420, 0x428, 0x440, 0x450, 0x460, + 0x4d8, 0x4e0, 0x4e8, 0x4f0, 0x518, 0x520, 0x560, 0x568, 0x578, 0x580, + 0x598, 0xc00, 0x4020, 0x4030, 0x4048, 0x4050, 0x8000, 0x8008, 0x8010, 0x8018, + 0x8020, 0xc000, 0xc008, 0xc010, 0x10000, 0x10068, + }; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(off); i++) + if (off[i] == offset) + return true; + return false; +} + +/* The 38 ps_all words macOS has ON at its commit (same end state, actual state != 0) */ +static bool t8142_macos_on_at_commit(u32 offset) +{ + static const u32 on[] = { + 0x110, 0x118, 0x120, 0x138, 0x140, 0x148, 0x150, 0x158, 0x160, 0x168, + 0x170, 0x178, 0x180, 0x2c8, 0x2d0, 0x340, 0x348, 0x358, 0x368, 0x370, + 0x378, 0x380, 0x388, 0x390, 0x398, 0x430, 0x438, 0x448, 0x458, 0x468, + 0x470, 0x478, 0x480, 0x488, 0x490, 0x498, 0x4a0, 0x5a0, + }; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(on); i++) + if (on[i] == offset) + return true; + return false; +} + +/* + * Neither: never touched in macOS's trace. Past the CPU words (< 0x60), all but ATC2/3 are no_ps + * children of the displays and ISP, which their firmware lowers, not the AP: one left on by a + * cold-stopped DCP keeps its FE word up. + */ +static bool t8142_macos_untraced(u32 offset) +{ + return offset >= 0x60 && !t8142_macos_on_at_commit(offset) && + !t8142_macos_off_at_commit(offset); +} + +static void t8142_commit_digest(struct apple_sleep *s) +{ + const struct apple_sleep_words *all = &s->soc->ps_all, *aon = &s->soc->ps_aon_all; + u8 noauto = 0, untraced = 0, first[1] = { 0xff }, aon_noauto = 0, aon_first = 0xff; + unsigned int i; + u32 v; + + for (i = 0; i < all->count; i++) { + v = readl(s->ps + all->offset[i]); + if (!FIELD_GET(PS_ACTUAL, v)) + continue; + /* +10/+11: untraced words on (count, first index): see t8142_macos_untraced */ + if (t8142_macos_untraced(all->offset[i])) { + if (!untraced) + first[0] = min(i, 254U); + untraced += untraced < 255; + } + if (v & PS_AUTO_ENABLE) + continue; + noauto += noauto < 255; + } + for (i = 0; i < aon->count; i++) { + v = readl(s->ps_aon + aon->offset[i]); + if (!FIELD_GET(PS_ACTUAL, v) || (v & PS_AUTO_ENABLE)) + continue; + if (!aon_noauto) + aon_first = min(i, 254U); + aon_noauto += aon_noauto < 255; + } + v = readl(s->ps + T8142_PS_SEP); + sleep_note_at(s, 8, noauto); + sleep_note_at(s, 10, untraced); + sleep_note_at(s, 11, first[0]); + sleep_note_at(s, 12, aon_noauto); + sleep_note_at(s, 13, aon_first); + sleep_note_at(s, 14, v & 0xff); + sleep_note_at(s, 15, v >> 24); + + /* + * +5..+7, +16..+19: the first seven ps_all indices on here (actual state, AUTO_ENABLE or + * not) that macOS has off at its commit (t8142_macos_off_at_commit); 0xff = none. +9 their + * count (replaces the AUTO count). The full list is the dry run's. + */ + { + static const u8 slot[] = { 5, 6, 7, 16, 17, 18, 19 }; + unsigned int nodd = 0; + + for (i = 0; i < all->count; i++) { + v = readl(s->ps + all->offset[i]); + if (!FIELD_GET(PS_ACTUAL, v) || !t8142_macos_off_at_commit(all->offset[i])) + continue; + if (nodd < ARRAY_SIZE(slot)) + sleep_note_at(s, slot[nodd], min(i, 254U)); + nodd++; + } + for (i = nodd; i < ARRAY_SIZE(slot); i++) + sleep_note_at(s, slot[i], 0xff); + sleep_note_at(s, 9, min(nodd, 255U)); + } +} + +static void t8142_commit_note(struct apple_sleep *s) +{ + u8 flags = 0, src = 0xff; + int i; + + if (!sleep_notes_on(s)) + return; + if (s->cpus_stop_ret) + flags |= 0x01; + if (s->perf_soc_ret) + flags |= 0x02; + if (s->perf_dcs_ret) + flags |= 0x04; + for (i = 0; i < s->soc->wake_words; i++) { + u32 pend = readl(s->wake + s->soc->wake_status + i * 4) & s->wake_armed[i]; + + if (!pend) + continue; + if (!(flags & 0x08)) { + u32 id = i * 32 + __ffs(pend); + + src = id & 0xff; + if (id > 0xff) + flags |= 0x10; + } + flags |= 0x08; + } + if (readl(s->commit)) + flags |= 0x20; + t8142_commit_digest(s); + t8142_alarm_prepare(s); + /* +20: the alarm read (1 = ready, 0 = off or failed) */ + sleep_note_at(s, 20, t8142_alarm_ok); + /* +21: mem_boot (bit 0 asked, bit 1 replayed, bit 2 floor stepped), +22 fingerprint mismatches */ + sleep_note_at(s, 21, (READ_ONCE(sleep_mem_boot) ? 1 : 0) | (s->mem_boot_done ? 2 : 0) | + (s->mem_floor_done ? 4 : 0) | (s->pmp_lowered ? 8 : 0) | + (s->pmp_off_ret ? 0x10 : 0) | + (READ_ONCE(sleep_extra_off) ? 0x20 : 0) | + (s->extra_lowered || s->disp_adma_lowered ? 0x40 : 0) | + (s->extra_stuck ? 0x80 : 0)); + /* +22: dispext (sleep_display_off) */ + sleep_note_at(s, 2, flags); + sleep_note_at(s, 4, src); + sleep_note(s, 0x65); +} + /* * T8142's memory side, as macOS steps it down 4.6 to 2.7 ms before the S2R timer (J813, 27.2.1, * all ten cores: gig3m's trace, gist 89aedeca, 2026-11-15; the J815 ADT has the same mcc @@ -7107,6 +8546,225 @@ static void t8142_post_timer(struct apple_sleep *s) #define T8142_MCC_LANE_EXTRA 0x100 #define T8142_MEM_CLK_SLEEP 0x30000 +/* + * What T8142's deep sleep loses and XNU writes back at the wake, before the AMCC/MCC and + * clkgen drivers' state is used again (Thomas's J813 trace, 27.2, all ten cores, 2026-11-16; + * the J815 ADT has the same mcc and clkgen layout). Every one of the 411 memory-side words + * XNU writes at the wake ends at the value it held before the entry's stop, and the clkgen + * slots at the values it read 3.2 ms before the timer: so this saves J815's own values and + * replays them in XNU's order. Nothing here is a J813 constant but the clkgen slot commands. + */ +/* + * The AMCC sleep bits by (plane, pair), the pair's bits being 2 * pair + 1 and 2 * pair + 2: + * the order XNU clears them in at the entry and sets them again at the wake. + */ +static const u8 t8142_amcc_order[][2] = { + { 1, 0 }, { 2, 2 }, { 1, 2 }, { 0, 1 }, { 1, 3 }, { 0, 0 }, + { 1, 1 }, { 2, 3 }, { 0, 3 }, { 2, 1 }, { 0, 2 }, { 2, 0 }, +}; + +#define T8142_CLK_SLOTS 126 +#define T8142_CLK_SLOT(n) ((n) * 0x20) +#define T8142_CLK_SLOT_LO 0x10 +#define T8142_CLK_SLOT_HI 0x14 +/* The command XNU writes to each slot's +0x0 after its value (4, or 5 for these 48 slots). */ +static const u64 t8142_clk_slot_cmd5[2] = { 0x54aaaaaaaa000000ULL, 0x02aaaaaaa9555555ULL }; +/* Per DCS channel ("mcc" = +0x580): +0x0 enables, +0x4 groups, +0x10.. six words a group */ +#define T8142_MCC_SAVE_WORDS 65 +#define T8142_MCC_GROUPS 10 +#define T8142_MCC_GROUP(k) (0x10 + (k) * 0x18) +/* Per AMCC plane ("amcc-cfg" = plane + 0x2a000): 64-bit +0x0, +0x8, +0x10; 32-bit +0x4000 */ +#define T8142_AMCC_CFG_CTL 0x4000 +#define T8142_SOCNI_STROBE 0x100 + +static void t8142_mem_save(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + int i, n; + + s->mem_saved = false; + if (!READ_ONCE(sleep_mem_restore)) + return; + for (i = 0; i < soc->namcc; i++) { + s->amcc_saved[i] = readq(s->amcc[i]); + if (!s->amcc_cfg[i]) + continue; + for (n = 0; n < 3; n++) + s->amcc_cfg_saved[i][n] = readq(s->amcc_cfg[i] + 8 * n); + s->amcc_ctl_saved[i] = readl(s->amcc_cfg[i] + T8142_AMCC_CFG_CTL); + } + for (i = 0; i < soc->nsocni; i++) + for (n = 0; n < soc->socni_words[i] && n < ARRAY_SIZE(s->socni_saved[0]); n++) + s->socni_saved[i][n] = readl(s->socni[i] + 4 * n); + for (i = 0; i < soc->nmcc; i++) + for (n = 0; n < T8142_MCC_SAVE_WORDS; n++) + s->mcc_saved[i][n] = readl(s->mcc[i] + 4 * n); + s->mem_saved = true; +} + +static void t8142_clk_save(struct apple_sleep *s) +{ + int i; + + s->clk_saved = false; + if (!s->clk_slots || !READ_ONCE(sleep_clk_restore)) + return; + for (i = 0; i < T8142_CLK_SLOTS; i++) { + void __iomem *slot = s->clk_slots + T8142_CLK_SLOT(i); + u32 hi, lo; + int tries = 4; + + /* As XNU reads them: high, low, high again (bounded: interrupts are off). */ + do { + hi = readl(slot + T8142_CLK_SLOT_HI); + lo = readl(slot + T8142_CLK_SLOT_LO); + } while (readl(slot + T8142_CLK_SLOT_HI) != hi && --tries); + s->clk_slot_saved[i][0] = lo; + s->clk_slot_saved[i][1] = hi; + } + s->clk_saved = true; +} + +/* XNU's wake at +4.6..8.8 ms: each slot's value, then its command; then the memory clock word. */ +static void t8142_clk_restore(struct apple_sleep *s) +{ + int i; + + if (s->clk_saved) { + for (i = 0; i < T8142_CLK_SLOTS; i++) { + void __iomem *slot = s->clk_slots + T8142_CLK_SLOT(i); + bool five = t8142_clk_slot_cmd5[i / 64] & BIT_ULL(i % 64); + + writel(s->clk_slot_saved[i][0], slot + T8142_CLK_SLOT_LO); + writel(s->clk_slot_saved[i][1], slot + T8142_CLK_SLOT_HI); + writel(five ? 5 : 4, slot); + } + s->clk_saved = false; + } + if (s->mem_clk && s->mem_clk_saved && READ_ONCE(sleep_clk_restore)) + writel(s->mem_clk_saved, s->mem_clk); +} + +/* One bit at a time, low first, as XNU raises each AMCC pair back. */ +static void t8142_amcc_set(void __iomem *reg, u64 bits) +{ + u64 val = readq(reg); + unsigned int b; + + for_each_set_bit(b, (unsigned long *)&bits, 64) { + if (val & BIT_ULL(b)) + continue; + val |= BIT_ULL(b); + writeq(val, reg); + val = readq(reg); + } +} + +/* Byte @n of @reg back to its saved value, as XNU does before each lane comes up. */ +static void t8142_byte_restore(void __iomem *reg, u32 saved, int n) +{ + u32 mask = GENMASK(8 * n + 7, 8 * n); + + writel((readl(reg) & ~mask) | (saved & mask), reg); +} + +/* + * XNU's wake from +9.06 ms, in its order: the AMCC planes' sleep bits back in the entry's pair + * order; each SoC NI table word with its strobe; each DCS channel's region groups, each + * followed by its enable bits; the lanes, two per channel per pass; the AMCC planes' control + * words. Skipped: XNU's read-and-rewrite of each channel's +0x24 (outside the DT's map). + */ +static int t8142_mem_restore(struct apple_sleep *s, const u8 (*order)[2], int norder) +{ + const struct apple_sleep_soc *soc = s->soc; + int i, n, ch, pass, k; + + if (!s->mem_saved) + return -ENODATA; + + for (i = 0; i < norder; i++) { + int plane = order[i][0]; + + if (plane >= soc->namcc) + continue; + t8142_amcc_set(s->amcc[plane], s->amcc_saved[plane] & + GENMASK_ULL(2 * order[i][1] + 2, 2 * order[i][1] + 1)); + } + for (i = 0; i < soc->namcc; i++) + t8142_amcc_set(s->amcc[i], s->amcc_saved[i] & T8142_AMCC_SLEEP_BITS); + + for (i = 0; i < soc->nsocni; i++) + for (n = 0; n < soc->socni_words[i] && n < ARRAY_SIZE(s->socni_saved[0]); n++) { + writel(s->socni_saved[i][n], s->socni[i] + 4 * n); + writel(1, s->socni[i] + T8142_SOCNI_STROBE); + } + + for (ch = 0; ch < soc->nmcc; ch++) { + void __iomem *mcc = s->mcc[ch]; + const u32 *sv = s->mcc_saved[ch]; + u32 en = 0, groups = 0; + + for (k = 0; k < T8142_MCC_GROUPS; k++) { + if (!(sv[MCC_ENABLES / 4] & BIT(k))) + continue; + for (n = 0; n < 6; n++) + writel(sv[(T8142_MCC_GROUP(k) + 4 * n) / 4], + mcc + T8142_MCC_GROUP(k) + 4 * n); + en |= GENMASK(3, 0) | BIT(4 + k); + groups |= BIT(k); + writel(readl(mcc) | (sv[0] & en), mcc); + writel(readl(mcc + MCC_ENABLES) | (sv[MCC_ENABLES / 4] & groups), + mcc + MCC_ENABLES); + } + /* Whatever else was on, as XNU's last group leaves the words at their old values. */ + if (readl(mcc) != sv[0]) + writel(sv[0], mcc); + if (readl(mcc + MCC_ENABLES) != sv[MCC_ENABLES / 4]) + writel(sv[MCC_ENABLES / 4], mcc + MCC_ENABLES); + } + + for (pass = 0; pass < 2; pass++) { + for (ch = 0; ch < soc->nmcc; ch++) { + void __iomem *mcc = s->mcc[ch]; + const u32 *sv = s->mcc_saved[ch]; + + for (n = 2 * pass; n < 2 * pass + 2; n++) { + if (!(sv[MCC_LANES / 4] & MCC_LANE(n))) + continue; + t8142_byte_restore(mcc + T8142_MCC_LANE_EXTRA, + sv[T8142_MCC_LANE_EXTRA / 4], n); + t8142_byte_restore(mcc + MCC_LANES_MASK, sv[MCC_LANES_MASK / 4], n); + writel(readl(mcc + MCC_LANES) | MCC_LANE_STROBE(n), mcc + MCC_LANES); + writel(readl(mcc + MCC_LANES) | MCC_LANE(n), mcc + MCC_LANES); + } + } + } + for (ch = 0; ch < soc->nmcc; ch++) { + void __iomem *mcc = s->mcc[ch]; + const u32 *sv = s->mcc_saved[ch]; + + if (readl(mcc + T8142_MCC_LANE_EXTRA) != sv[T8142_MCC_LANE_EXTRA / 4]) + writel(sv[T8142_MCC_LANE_EXTRA / 4], mcc + T8142_MCC_LANE_EXTRA); + if (readl(mcc + MCC_LANES_MASK) != sv[MCC_LANES_MASK / 4]) + writel(sv[MCC_LANES_MASK / 4], mcc + MCC_LANES_MASK); + } + + /* +14.56 ms: plane 0's +0x10, then each plane's +0x4000, +0x8, +0x0. */ + for (i = 0; i < soc->namcc; i++) { + void __iomem *cfg = s->amcc_cfg[i]; + + if (!cfg) + continue; + if (i == 0) + writeq(s->amcc_cfg_saved[i][2], cfg + 0x10); + writel(s->amcc_ctl_saved[i], cfg + T8142_AMCC_CFG_CTL); + writeq(s->amcc_cfg_saved[i][1], cfg + 0x8); + writeq(s->amcc_cfg_saved[i][0], cfg); + } + s->mem_saved = false; + return 0; +} + static void t8142_amcc_clear(void __iomem *reg, u64 bits) { u64 val = readq(reg); @@ -7123,15 +8781,14 @@ static void t8142_amcc_clear(void __iomem *reg, u64 bits) static void t8142_sleep_mcc_stop(struct apple_sleep *s) { - /* (plane, pair): the pair's bits are 2 * pair + 1 and 2 * pair + 2 */ - static const u8 order[][2] = { - { 1, 0 }, { 2, 2 }, { 1, 2 }, { 0, 1 }, { 1, 3 }, { 0, 0 }, - { 1, 1 }, { 2, 3 }, { 0, 3 }, { 2, 1 }, { 0, 2 }, { 2, 0 }, - }; + const u8 (*order)[2] = t8142_amcc_order; const struct apple_sleep_soc *soc = s->soc; int i, plane, ch, pass, n; - for (i = 0; i < ARRAY_SIZE(order); i++) { + /* What the wake puts back (t8142_mem_restore), before anything here changes it. */ + t8142_mem_save(s); + + for (i = 0; i < ARRAY_SIZE(t8142_amcc_order); i++) { if (order[i][0] >= soc->namcc) continue; t8142_amcc_clear(s->amcc[order[i][0]], GENMASK_ULL(2 * order[i][1] + 2, @@ -7162,8 +8819,12 @@ static void t8142_sleep_mcc_stop(struct apple_sleep *s) } } - if (s->mem_clk) + if (s->mem_clk) { + s->mem_clk_saved = readl(s->mem_clk); writel(T8142_MEM_CLK_SLEEP, s->mem_clk); + } + /* macOS reads the clkgen slots right after the clock word (-3.2 ms). */ + t8142_clk_save(s); } /* @@ -7176,9 +8837,14 @@ static void t8142_last_mile(struct apple_sleep *s) const struct apple_sleep_soc *soc = s->soc; int i; - t8142_perf_down(s); + /* Not in macOS's J813 entry (its perf-state page is untouched in the whole trace): A/B. */ + if (READ_ONCE(sleep_perf_down)) + t8142_perf_down(s); sleep_note(s, 0x64); + /* T6050's commit window: the floor's voter to 0, not read, right before the memory stop */ + if (s->mem_floor_done) + writel(0, s->pmc_voters + PMC_VOTER_STRIDE * 1); /* The memory controller, after the SoC and DCS states, as on T8132 (and macOS on J813). */ t8142_sleep_mcc_stop(s); sleep_note(s, 0x66); @@ -7208,6 +8874,95 @@ static void t8142_last_mile(struct apple_sleep *s) sleep_ps_save(s); } +/* + * Note 0x67 (replaces 0x66 once every read came back): +2 E cores' PU bits [5:0], bit 6 complex + * E busy, bit 7 complex P busy; +3 P cores' PU bits [3:0], bit 4 commit word nonzero, bit 5 an + * armed wake pending, bit 6 E asked on, bit 7 P asked on; +4 E cores' SPD bits [5:0], bit 6 any + * P core's SPD, bit 7 a window read all-ones (no answer). Unmapped windows read as PU 1. + */ +static void t8142_post_commit_ed(u8 b2_0x66) +{ + u8 b2 = 0, b3 = 0, b4 = 0; + int k; + + for (k = 0; k < T8142_ED_CORES; k++) { + u32 v; + + if (k < 6) { + v = t8142_ed[0][k] ? readl_relaxed(t8142_ed[0][k] + T8142_ED_EDPRSR) : 1; + if (v == ~0U) + b4 |= BIT(7); + if (v & BIT(0)) + b2 |= BIT(k); + if (v & BIT(1)) + b4 |= BIT(k); + } + if (k < 4) { + v = t8142_ed[1][k] ? readl_relaxed(t8142_ed[1][k] + T8142_ED_EDPRSR) : 1; + if (v == ~0U) + b4 |= BIT(7); + if (v & BIT(0)) + b3 |= BIT(k); + if (v & BIT(1)) + b4 |= BIT(6); + } + } + b2 |= (b2_0x66 & BIT(3) ? BIT(6) : 0) | (b2_0x66 & BIT(4) ? BIT(7) : 0); + b3 |= (b2_0x66 & BIT(0) ? BIT(4) : 0) | (b2_0x66 & BIT(5) ? BIT(5) : 0) | + (b2_0x66 & BIT(1) ? BIT(6) : 0) | (b2_0x66 & BIT(2) ? BIT(7) : 0); + sleep_note_at(apple_sleep, 2, b2); + sleep_note_at(apple_sleep, 3, b3); + sleep_note_at(apple_sleep, 4, b4); + sleep_note(apple_sleep, 0x67); +} + +/* + * apple_sleep.post_commit_ms: note 0x66, decoded by aurora-bootlog as b43's was. + * +2: bit 0 commit word nonzero, 1/2 complex E/P asked on, 3/4 E/P busy, 5 an armed wake source + * pending. +3: SoC perf state [3:0], bit 4 DCS busy, bit 5 SoC busy. +4: DCS state [3:0], + * bits 4..7 PMC voters PMP/CLPC/GFX/AP nonzero. + */ +static void t8142_post_commit_probe(struct apple_sleep *s, unsigned int ms) +{ + const struct apple_sleep_soc *soc = s->soc; + u32 e, p, soc_perf = 0, dcs = 0; + u8 b2 = 0, b3, b4; + int i; + + mdelay(ms); + e = readl(s->cluster + soc->cluster_cpu[0]); + p = readl(s->cluster + soc->cluster_cpu[1]); + if (readl(s->commit)) + b2 |= BIT(0); + if (e & CLUSTER_ON) + b2 |= BIT(1); + if (p & CLUSTER_ON) + b2 |= BIT(2); + if (e & T8142_CLUSTER_BUSY) + b2 |= BIT(3); + if (p & T8142_CLUSTER_BUSY) + b2 |= BIT(4); + for (i = 0; i < soc->wake_words; i++) + if (readl(s->wake + soc->wake_status + 4 * i) & s->wake_armed[i]) + b2 |= BIT(5); + if (s->clk_perf) + soc_perf = readl(s->clk_perf + CLK_PERF_SOC); + if (s->dcs) + dcs = readl(s->dcs); + b3 = FIELD_GET(DCS_STATE, soc_perf) | (dcs & DCS_BUSY ? BIT(4) : 0) | + (soc_perf & DCS_BUSY ? BIT(5) : 0); + b4 = FIELD_GET(DCS_STATE, dcs); + for (i = 0; s->pmc_voters && i < 4; i++) + if (readl(s->pmc_voters + i * PMC_VOTER_STRIDE)) + b4 |= BIT(4 + i); + sleep_note_at(s, 2, b2); + sleep_note_at(s, 3, b3); + sleep_note_at(s, 4, b4); + sleep_note(s, 0x66); + if (READ_ONCE(sleep_post_commit_ed)) + t8142_post_commit_ed(b2); +} + /* * AppleT8142PMGR's complex power-on: ApplePMGR's cluster method writes (word & ~0xf) | 0xf and * waits for bit 4 to clear; T8142's override then writes 1 to the complex's ACC word. @@ -7234,13 +8989,14 @@ static int t8142_cluster_on(struct apple_sleep *s, u32 word, void __iomem *acc) */ static void t8142_wake(struct apple_sleep *s) { + if (t8142_alarm_ok) + pr_info("apple-sleep: T8142 PMU alarm after the timer: %d (counter %llu, compare %u)\n", + t8142_post_ret, t8142_alarm_counter, get_unaligned_le32(t8142_alarm)); + const struct apple_sleep_soc *soc = s->soc; u32 val; int i; - pr_info("apple-sleep: T8142 PMU alarm after the timer: %d (counter %llu, compare %u)\n", - t8142_post_ret, t8142_alarm_counter, get_unaligned_le32(t8142_alarm)); - s->cluster_e_ret = t8142_cluster_on(s, soc->cluster_cpu[0], s->acc_e); s->cluster_p_ret = t8142_cluster_on(s, soc->cluster_cpu[1], s->acc_p); @@ -7251,6 +9007,14 @@ static void t8142_wake(struct apple_sleep *s) } sleep_ps_rewake(s); + /* Off at the commit by pmp_off, so the rewake left it: back as lower_io found it. */ + if (s->pmp_lowered) { + s->pmp_lowered = false; + sleep_ps_restore(s->ps + T8142_PS_PMP, s->pmp_saved); + } + /* Off at the commit by dispext, likewise: back before the display drivers resume. */ + sleep_dispext_restore(s); + t8142_extra_restore(s); /* The commit saved ATC0's words already lowered: reverse of the lowering. */ sleep_ps_restore(s->ps + T8142_PS_ATC0_COMMON, s->atc0_saved[2]); sleep_ps_restore(s->ps_aon + T8142_PS_AON_ATC0_USB_AON, s->atc0_saved[1]); @@ -7262,7 +9026,10 @@ static void t8142_wake(struct apple_sleep *s) if (val & PS_DEV_DISABLE) writel(val & ~PS_DEV_DISABLE, s->ps + soc->ps.sep); + /* XNU's order: the clkgen slots and the memory clock, the CPM gates, the memory side. */ + t8142_clk_restore(s); t8142_cpm_on(s); + s->mem_restore_ret = t8142_mem_restore(s, t8142_amcc_order, ARRAY_SIZE(t8142_amcc_order)); if (READ_ONCE(sleep_acc_wake) && s->acc_e && s->acc_p) { writel(1, s->acc_e); writel(1, s->acc_p); @@ -7355,16 +9122,36 @@ static const u32 t8142_ps_aon_all[] = { 0xc048, 0xc050, 0xc058, 0xc060, }; -/* Less DPTX_PHY (0x590): no_ps on T8142 (see t8142_ps_macos_off). */ +/* + * XNU's own wake order on T8142 (J813 27.2 trace, 2026-11-16: the 22 words it raises with + * AUTO_ENABLE right after the clusters and SEP), then the rest of the T8132-derived list. A + * word is only raised if Linux had it on at the commit (sleep_ps_rewake). + */ static const u32 t8142_ps_wake_order[] = { - 0xc00, 0x118, 0x120, 0x180, 0x390, 0x398, 0x468, 0x470, 0x478, 0x480, - 0x488, 0x598, 0x5a0, 0x300, 0x2f0, 0x408, 0x410, 0x520, 0x560, 0x328, - 0x2a8, 0x320, 0x2b8, 0x3a8, 0x3b8, 0x290, 0x318, 0x10000, 0x308, 0x418, - 0x428, 0x440, 0x360, + 0xc00, 0x118, 0x120, 0x138, 0x170, 0x178, 0x180, 0x348, 0x358, 0x368, + 0x390, 0x398, 0x430, 0x438, 0x448, 0x458, 0x468, 0x470, 0x478, 0x480, + 0x488, 0x5a0, + 0x598, 0x300, 0x2f0, 0x408, 0x410, 0x520, 0x560, 0x328, 0x2a8, 0x320, + 0x2b8, 0x3a8, 0x3b8, 0x290, 0x318, 0x10000, 0x308, 0x418, 0x428, 0x440, + 0x360, +}; + +/* XNU's PMGR start at boot (J813 trace g01, -218649 ms): put on AUTO_ENABLE, in its order */ +static const u32 t8142_ps_boot_auto[] = { + 0x118, 0x120, 0x138, 0x140, 0x170, 0x178, 0x180, 0x290, 0x2b8, 0x2c8, + 0x2d0, 0x2f0, 0x300, 0x308, 0x328, 0x348, 0x350, 0x358, 0x360, 0x368, + 0x390, 0x398, 0x3a0, 0x3a8, 0x410, 0x418, 0x430, 0x438, 0x440, 0x448, + 0x450, 0x458, 0x460, 0x468, 0x470, 0x478, 0x480, 0x488, 0x578, 0x598, + 0x5a0, +}; + +static const u32 t8142_ps_aon_boot_auto[] = { + 0x58, 0x60, 0x68, 0x70, 0x78, 0x88, 0x98, 0xa0, 0xa8, 0xc8, + 0xd0, 0xd8, 0xe0, }; static const u32 t8142_ps_aon_wake_order[] = { - 0xa8, + 0x88, 0x98, 0xa0, 0xa8, }; /* @@ -7409,6 +9196,17 @@ static const u32 t8142_quiesce_words[] = { }; static_assert(ARRAY_SIZE(t8142_quiesce_words) <= 32); +/* In t8142_ps_macos_off / t8142_ps_aon_macos_off, but on at macOS 27.2's commit (apple_sleep.ps_keep) */ +static const struct apple_sleep_ps_keep t8142_ps_keep[] = { + { "PMS_C1PPT", 0x170, false, 0 }, { "SOC_RC", 0x178, false, 0 }, + { "I2C0", 0x348, false, 1 }, { "I2C2", 0x358, false, 1 }, + { "I2C4", 0x368, false, 1 }, { "SPI0", 0x430, false, 1 }, + { "SPI1", 0x438, false, 1 }, { "SPI3", 0x448, false, 1 }, + { "SPI5", 0x458, false, 1 }, + { "ATC1_COMMON", 0x2d0, false, 2 }, { "ATC1_USB_AON", 0xd8, true, 2 }, + { "ATC1_USB", 0xe0, true, 2 }, +}; + static const struct apple_sleep_word t8142_stray_words[] = { { "AVD_SYS", 0x310 }, { "VENC_SYS", 0x298 }, { "JPG", 0x2a0 }, }; @@ -7430,14 +9228,15 @@ static const struct apple_sleep_gate_coproc t8142_gate_coprocs[] = { static const struct apple_sleep_ops t8142_sleep_ops = { - /* XNU's last-WFI helper is the same code as T8132's and T8140's. */ - .deep_wfi_arm = t8140_deep_wfi_arm, + /* XNU's last-WFI helper is the same code as T8132's and T8140's; plus M5's power-down bits. */ + .deep_wfi_arm = t8142_deep_wfi_arm, .lower_io = t8142_lower_io, .last_mile = t8142_last_mile, /* WD2 is at T8132's address (/arm-io/wdt), so the same stub restarts it. */ .resume = t8132_resume_stub, - .pre_commit = t8142_pre_commit, + .pre_commit = t8132_pre_commit, .post_timer = t8142_post_timer, + .macos_off_at_commit = t8142_macos_off_at_commit, .wake = t8142_wake, .aic_mask_all = aic_sleep_mask_all, .aic_ack = aic_sleep_ack, @@ -7463,6 +9262,27 @@ static const char *const t8142_regs_absent[] = { "pmc-dcp", "clk-mux", "ptd", "cluster-dcs", "dvfm-e", "dvfm-p", NULL, }; +/* Children before parents (J815 ADT pmgr devices: parent ids) */ +static const struct apple_sleep_extra_off t8142_extra_off[] = { + { "SYS_GP_OCLA", 0x518, 0x408 }, /* parent APCIE_SYS_GP */ + { "SYS_ST_OCLA", 0x568, 0x520 }, /* parent APCIE_SYS_ST */ + { "GLOBAL_AUX_CTRL0", 0x1a0, 0 }, + { "GLOBAL_AUX_CTRL1", 0x1a8, 0 }, + { "FPWM0", 0x330, 0x2b0 }, /* parent SIO */ + { "SIO_CPU", 0x328, 0x2b0 }, /* parent SIO; macOS -53 ms */ + /* ATC2/3: no port on the Airs, never touched by macOS; lowered only if on */ + { "ATC2_CIO_PCIE", 0x4f8, 0x3f0 }, + { "ATC2_CIO_USB", 0x500, 0x3f0 }, + { "ATC2_PCIE", 0x3e8, 0x2d8 }, + { "ATC2_CIO", 0x3f0, 0x2d8 }, + { "ATC2_COMMON", 0x2d8, 0 }, + { "ATC3_CIO_PCIE", 0x508, 0x400 }, + { "ATC3_CIO_USB", 0x510, 0x400 }, + { "ATC3_PCIE", 0x3f8, 0x2e0 }, + { "ATC3_CIO", 0x400, 0x2e0 }, + { "ATC3_COMMON", 0x2e0, 0 }, +}; + static const struct apple_sleep_soc t8142_sleep_soc = { .ops = &t8142_sleep_ops, .untested = true, @@ -7470,9 +9290,21 @@ static const struct apple_sleep_soc t8142_sleep_soc = { .spmi_gen4 = true, .boot_wfi_delay_ms = 3, .wake_optional = true, - /* The J815 tree has no external DCP: DISPEXT0/1 are 0x428/0x418/0x308, 0x3b8/0x3a8/0x2b8. */ - .ndisp = 1, - .display_order = { 0 }, + /* + * DCP, DISPEXT0 (0x428/0x418/0x308), DISPEXT1 (0x3b8/0x3a8/0x2b8), lowered in macOS's order + * (J815 26B131: DISPEXT0, DISPEXT1, DISP). Both external DCPs are bound on J813/J815 now; + * apple_sleep.dispext=0 leaves them as before. macOS writes no pwrgate word for them. Their + * DARTs' PS write-disable bits (trace pmgr-soc-ps+0x3fe8 bit 15, +0x3fec bit 31) are clear + * at macOS's commit. + */ + .ndisp = 3, + .display_order = { 1, 2, 0 }, + .dispext_optional = true, + .disp_wr_dis = { { 0 }, { 0x17fe8, 15 }, { 0x17fec, 31 } }, + /* DISP_ADMA (pmgr base 1 +0x68), DISPEXT0_ADMA, DISPEXT1_ADMA */ + .disp_adma = { 0x10068, 0x420, 0x3b0 }, + .extra_off = t8142_extra_off, + .nextra_off = ARRAY_SIZE(t8142_extra_off), /* E, P (ADT soc-clusters) */ .cluster_cpu = { 0x0, 0x4 }, .ncluster_cpu = 2, @@ -7500,6 +9332,8 @@ static const struct apple_sleep_soc t8142_sleep_soc = { .ps = { .disp = { { 0x10000, 0x318, 0x290 }, + { 0x428, 0x418, 0x308 }, + { 0x3b8, 0x3a8, 0x2b8 }, }, .sio_cpu = 0x328, .sep = 0xc00, @@ -7520,6 +9354,7 @@ static const struct apple_sleep_soc t8142_sleep_soc = { .apcie_gen4 = true, .radio_retrain = true, .pen_deep = true, + .early_cpu_wfi = true, .pwrgate_wake = { 0x000, 0x060 }, /* AppleT8142PMGR vtable 0xfa0: 0xa0 + 8 * complex */ .pwrgate_cpm = { 0x0a0, 0x0a8 }, @@ -7532,9 +9367,14 @@ static const struct apple_sleep_soc t8142_sleep_soc = { .ps_aon_macos_on = SLEEP_WORDS(t8142_ps_aon_macos_on), .ps_wake_order = SLEEP_WORDS(t8142_ps_wake_order), .ps_aon_wake_order = SLEEP_WORDS(t8142_ps_aon_wake_order), + .ps_boot_auto = SLEEP_WORDS(t8142_ps_boot_auto), + .ps_aon_boot_auto = SLEEP_WORDS(t8142_ps_aon_boot_auto), + .mem_boot = true, .quiesce = SLEEP_WORDS(t8142_quiesce_words), .stray = t8142_stray_words, .nstray = ARRAY_SIZE(t8142_stray_words), + .ps_keep = t8142_ps_keep, + .nps_keep = ARRAY_SIZE(t8142_ps_keep), .gate_off = t8142_gate_off, .ngate_off = ARRAY_SIZE(t8142_gate_off), .gate_coprocs = t8142_gate_coprocs, From 6178a7c40c3851876c902239079ac3a57ae7f51c Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 14 Nov 2026 15:18:00 -0600 Subject: [PATCH 20/68] drm/apple: T8142: stop the DCP firmware on DPMS off (firmware 27.0) 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); - firmware 27.0's sleep calls: set_power_state and the AP link release, which 27.0 still dispatches as A500, and D572 (powerUpDART). A build whose table has no tag for the release (27.2 and later moved it) is not offered the stop, and T8142 is offered it on firmware 27.0 only; - 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). This is a screen-off (DPMS) power saving. No firmware-driven system sleep has run on T8142, and a SoC behind appledrm.s2r_untested does not take the stop's system sleep path. Tested on a J813 (MacBook Air 13" M5, firmware 27.0) on this series, with and without appledrm.s2r_untested=1: 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. 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 | 223 ++++++++++++++++++------- drivers/gpu/drm/apple/iomfb_template.c | 7 +- drivers/gpu/drm/apple/iomfb_v27.c | 28 +++- drivers/gpu/drm/apple/iomfb_v27.h | 2 + 5 files changed, 221 insertions(+), 66 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 97b0db066bb93..0c32b0fa8f4be 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -226,6 +226,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 @@ -296,6 +314,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 d9c1759989781..e2d5d61ecc5e5 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -288,13 +288,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", @@ -305,6 +308,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) @@ -467,6 +472,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 (default 0)"); + bool dcp_t6041_ext_enabled(void) { return t6041_dcpext; @@ -6734,6 +6749,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 + * firmware 27.0, 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); @@ -7596,9 +7619,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) @@ -7645,13 +7702,37 @@ 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; + /* + * Firmware 27.2 and 27.3 run as V_27_0 with their own tables, which have no tag for the + * AP link's release (27.2 moved it to A550): 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 27.0, under their own tags (A484, A500, ...): 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) @@ -7708,7 +7789,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; @@ -7733,7 +7814,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; @@ -7806,7 +7887,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) @@ -7975,7 +8057,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); @@ -8078,40 +8160,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); @@ -8129,34 +8226,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); @@ -8254,7 +8346,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); @@ -8395,7 +8488,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); @@ -8450,7 +8544,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; @@ -8698,7 +8792,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"); @@ -8887,7 +8981,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. */ @@ -9082,6 +9177,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. */ @@ -9107,6 +9203,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 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 2ae38159ab065..059386fb2369c 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -623,7 +623,8 @@ 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 27.0 too, which still dispatches it as A500; the sleep checks the build has it. */ +#if DCP_FW_VER <= DCP_FW_VERSION(27, 0, 0) DCP_THUNK_IN(dcp_unnamed_500, dcpep_unnamed_500, u32); #endif #endif @@ -2577,8 +2578,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..b54cdac4591de 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), }; /* @@ -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 24f123cafda9572e162687a50e4325ef33fcfb1a Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 12 Nov 2026 23:35:23 +0700 Subject: [PATCH 21/68] drm/apple: Admit the T8142 external display processors dcpext0 and dcpext1 of the T8142 (MacBook Air M5: one per USB-C display, J704: HDMI) run the internal DCP's firmware 27 image; iBoot leaves them running idle and the boot loader hands them over. Give them the T6050 external profile's shape: adopt the live session, one DPTX port, EDID from the sink metadata. A processor that fails to probe or bind joins as an unusable pipe and the internal panel goes on. Not booted. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick (cherry picked from commit 066390882f78df710183c15d756c0d0d8621b1fb) --- drivers/gpu/drm/apple/dcp.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index e2d5d61ecc5e5..2856f7118dc49 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -6237,7 +6237,7 @@ static void dcp_ext_give_up(struct apple_dcp *dcp, int err, const char *when); /* * The external processors whose failure must not take the DRM device down: - * T8122's, T6041's and T6050's dcpext. One that fails to probe or bind joins + * T8122's, T6041's, T6050's and T8142's dcpext. One that fails to probe or bind joins * as an unusable pipe (ext_dead), and the other displays go on without it. * With every processor failed the DRM device has no pipe and does not bind. */ @@ -6245,7 +6245,8 @@ static bool dcp_ext_is_failsafe(struct device_node *np) { return of_device_is_compatible(np, "apple,t8122-dcpext") || of_device_is_compatible(np, "apple,t6041-dcpext") || - of_device_is_compatible(np, "apple,t6050-dcpext"); + of_device_is_compatible(np, "apple,t6050-dcpext") || + of_device_is_compatible(np, "apple,t8142-dcpext"); } /* @@ -9288,7 +9289,20 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t6050_dcpext = { .link_report = true, }; +/* + * T8142's external processors (dcpext0/1: the Airs' two USB-C ports, the + * J704's HDMI) run the internal DCP's firmware 27 image and are left running + * idle by iBoot, like T6050's. One DPTX port each, behind an ATC PHY. + */ +static const struct apple_dcp_hw_data apple_dcp_hw_t8142_dcpext = { + .num_dptx_ports = 1, + .adopt_live_session = true, + .firmware_compat = DCP_FIRMWARE_V_27_0, + .sink_metadata_edid = true, +}; + static const struct of_device_id of_match[] = { + { .compatible = "apple,t8142-dcpext", .data = &apple_dcp_hw_t8142_dcpext }, { .compatible = "apple,t6041-dcp", .data = &apple_dcp_hw_t6041, }, { .compatible = "apple,t6041-dcpext", .data = &apple_dcp_hw_t6041_dcpext, }, { .compatible = "apple,t6050-dcp", .data = &apple_dcp_hw_t6050 }, From 2dc580ee202cc6dffefc441eff79ca0624503687 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 14 Nov 2026 11:22:24 +0700 Subject: [PATCH 22/68] drm/apple: T8142 dcpext: open the DPTX controller, and the ports on DPTX_ENDPOINT On a J813 the external processors booted, then timed out waiting for the DPTX port ("DPTX transport ready but port 0 service not announced", -110), and every connect found no port service. The T8142 dcpext had the T6050 external profile, which opens firmware 27's DPTX_ENDPOINT_V2 (0x2c) and no DPTX controller. macOS 27.2 on a J815 (IORegistry under iop-dcpext0/1-nub, RTBuddy EndpointN = 0x1f + N) binds, per external processor: - AppleDCPDPTXController (dcpav-controller-epic, dcpdp-controller-epic, units 0 and 1) on 0x24, DPTX_CONTROLLER_ENDPOINT; - AppleDCPDPTXRemotePort (dcpdptx-port-epic, units 0 and 1) on 0x2a, DPTX_ENDPOINT; 0x2c has no service; - dcpdptx-hdcp-interface on 0x2b. dmitzsaz's J704 tree opens the same: the controller first, the ports on DPTX_ENDPOINT with firmware 27, two ports. Add two hardware data fields, dptx_endpoint and dptx_controller, and set them for the T8142 dcpext with two DPTX ports (Type-C still uses port 0). The controller endpoint speaks the same wire as the port, so it now takes the OPEN handshake on firmware 27 too; for the H17P externals, the only ones that opened it before, nothing changes. Not booted yet. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick (cherry picked from commit 002bae87a9be995fdf4d66a375af9637a15646b0) --- drivers/gpu/drm/apple/dcp-internal.h | 11 +++++++++++ drivers/gpu/drm/apple/dcp.c | 13 ++++++++++--- drivers/gpu/drm/apple/dptxep.c | 6 ++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 0c32b0fa8f4be..9265aeab32297 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -302,6 +302,17 @@ struct apple_dcp_hw_data { * every board but the one it has run on (dcp.c, dcp_j714s_ext()). */ bool link_report; + /* + * The endpoint the DPTX port services are announced on, where it is not + * the firmware's default (DPTX_ENDPOINT_V2 on firmware 27): the T8142 + * dcpext announces them on DPTX_ENDPOINT. 0: the default. + */ + u8 dptx_endpoint; + /* + * Open the DPTX controller endpoint before the ports, as for H17P + * externals: the T8142 dcpext announces AppleDCPDPTXController there. + */ + bool dptx_controller; /* * With H17P firmware: a firmware-driven system sleep stops the internal processor's * firmware and powers it down, as DPMS off does, then restarts it warm, see diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 2856f7118dc49..9543e743c5add 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -4459,7 +4459,7 @@ int dcp_start(struct platform_device *pdev) ret); if (dcp->hw.iomfb_method_profile == - DCP_IOMFB_METHODS_H17P_EXTERNAL) { + DCP_IOMFB_METHODS_H17P_EXTERNAL || dcp->hw.dptx_controller) { ret = dptx_controller_init(dcp); if (ret) return dev_err_probe(dcp->dev, ret, @@ -9292,13 +9292,20 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t6050_dcpext = { /* * T8142's external processors (dcpext0/1: the Airs' two USB-C ports, the * J704's HDMI) run the internal DCP's firmware 27 image and are left running - * idle by iBoot, like T6050's. One DPTX port each, behind an ATC PHY. + * idle by iBoot, like T6050's. Their services sit where macOS 27.2 binds + * them on a J815 (IORegistry under iop-dcpextN-nub): AppleDCPDPTXController + * (dcpav-/dcpdp-controller-epic, units 0 and 1) on DPTX_CONTROLLER_ENDPOINT, + * and AppleDCPDPTXRemotePort (dcpdptx-port-epic, units 0 and 1) on + * DPTX_ENDPOINT, not on firmware 27's DPTX_ENDPOINT_V2. The J704's tree + * (dmitzsaz) opens the same ones. Type-C uses port 0. */ static const struct apple_dcp_hw_data apple_dcp_hw_t8142_dcpext = { - .num_dptx_ports = 1, + .num_dptx_ports = 2, .adopt_live_session = true, .firmware_compat = DCP_FIRMWARE_V_27_0, .sink_metadata_edid = true, + .dptx_endpoint = DPTX_ENDPOINT, + .dptx_controller = true, }; static const struct of_device_id of_match[] = { diff --git a/drivers/gpu/drm/apple/dptxep.c b/drivers/gpu/drm/apple/dptxep.c index 2d4102410dc9d..89084d233c6ac 100644 --- a/drivers/gpu/drm/apple/dptxep.c +++ b/drivers/gpu/drm/apple/dptxep.c @@ -1411,7 +1411,8 @@ int dptx_controller_init(struct apple_dcp *dcp) if (IS_ERR(ep)) return PTR_ERR(ep); /* Controller interfaces require the same OPEN handshake as the port. */ - ep->wire_v2 = dcp->hw.iomfb_method_profile == + ep->wire_v2 = dcp->fw_compat == DCP_FIRMWARE_V_27_0 || + dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17P_EXTERNAL; dcp->dptx_controller_ep = ep; @@ -1440,7 +1441,8 @@ int dptxep_init(struct apple_dcp *dcp) init_completion(&dcp->dptxport[0].linkcfg_completion); init_completion(&dcp->dptxport[1].linkcfg_completion); - ep = afk_init(dcp, wire_v2 ? DPTX_ENDPOINT_V2 : DPTX_ENDPOINT, dptxep_ops); + ep = afk_init(dcp, dcp->hw.dptx_endpoint ?: + (wire_v2 ? DPTX_ENDPOINT_V2 : DPTX_ENDPOINT), dptxep_ops); if (IS_ERR(ep)) return PTR_ERR(ep); ep->wire_v2 = wire_v2; From 1466f848ff475ff26672af17153ca8e54ff5c2e6 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 09:56:52 +0100 Subject: [PATCH 23/68] TEST ONLY: J813: stop both external display processors for sleep Adopt the working external display DT and use the firmware 27.2 link release before RTKit idle. Give each external processor its own power layout and include both in the sleep controller. Both warm restarts pass a dry run; real sleep still resets, with all external power states now matching macOS. Signed-off-by: Thomas Glanzmann --- .../boot/dts/apple/t8142-j813-dcpext.dtsi | 317 ++++++++++++++++++ arch/arm64/boot/dts/apple/t8142-j813.dts | 2 + drivers/gpu/drm/apple/dcp.c | 46 ++- drivers/soc/apple/sleep.c | 2 + 4 files changed, 362 insertions(+), 5 deletions(-) create mode 100644 arch/arm64/boot/dts/apple/t8142-j813-dcpext.dtsi diff --git a/arch/arm64/boot/dts/apple/t8142-j813-dcpext.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-dcpext.dtsi new file mode 100644 index 0000000000000..4c39012638201 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j813-dcpext.dtsi @@ -0,0 +1,317 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * External displays of the T8142 MacBook Airs (J813, J815): DisplayPort alt + * mode on the two USB-C ports. + * + * iBoot preloads both external display processors with the internal DCP's + * image and leaves them running idle. The boot loader checks each one and + * hands it over: it reserves the firmware, publishes its version and enables + * the processor, its mailbox, its DARTs and its Type-C route together. Until + * then everything here stays disabled and the ports are plain USB. + * + * dcpext0 serves the front port (ATC0), dcpext1 the rear port (ATC1): one + * processor per port, so two displays need no arbitration. Crossbar source + * numbers are twice the ADT dp-switch-ufp-endpoint (dcpext0 1, dcpext1 2). + * Addresses and interrupts are from the J815AP ADT (the J813AP 27.0 ADT is + * identical in every node used here); the bandwidth scratch + * slots are the /arm-io/pmgr bwr-agent indexes of DISP_EXT0 (3) and DISP_EXT1 + * (4) at 0x20000 + n * 0x4000. The T8142 topology follows the J704's. + */ + +/ { + aliases { + dcpext0 = &dcpext0; + dcpext1 = &dcpext1; + }; +}; + +&{/soc} { + pmgr_dcpext0: power-management@38272c000 { + reg = <3 0x8272c000 0 0x8>, <3 0x827b0000 0 0x4>; + reg-names = "dcp-bw-scratch", "dcp-bw-doorbell"; + #apple,bw-scratch-cells = <3>; + #apple,bw-doorbell-cells = <2>; + }; + + pmgr_dcpext1: power-management@382730000 { + reg = <3 0x82730000 0 0x8>, <3 0x827b4000 0 0x4>; + reg-names = "dcp-bw-scratch", "dcp-bw-doorbell"; + #apple,bw-scratch-cells = <3>; + #apple,bw-doorbell-cells = <2>; + }; + + dcpext0_mbox: mailbox@506e08000 { + compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <5 0x06e08000 0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + status = "disabled"; + }; + + dcpext0: dcp@506e00000 { + compatible = "apple,t8142-dcpext", "apple,dcpext"; + reg = <5 0x06e00000 0 0x4000>, + <5 0x04000000 0 0xb1c000>, + <5 0x06240000 0 0x10000>, + <5 0x063ac000 0 0x4000>, + <5 0x06800000 0 0x800000>, + <3 0x82700000 0 0x114000>, + <5 0x06850000 0 0x4000>; + reg-names = "coproc", "disp-0", "disp-1", "disp-2", + "disp-3", "disp-4", "iop-vbar"; + mboxes = <&dcpext0_mbox>; + mbox-names = "mbox"; + iommus = <&dcpext0_dart 23>; + /* The firmware's clocks: /arm-io/dispext0 clock-ids, as on disp0. */ + apple,clock-ids = <369 432>; + clocks = <&clkref>, <&dcpext_fw_clk369>, <&dcpext_fw_clk432>; + clock-names = "clock-154", "firmware-0", "firmware-1"; + apple,bw-scratch = <&pmgr_dcpext0 0 5 0>; + apple,bw-doorbell = <&pmgr_dcpext0 1 6>; + apple,iomfb-surfaces = <0 0 1 0>; + apple,dcp-index = <1>; + apple,connector-type = "USB-C"; + apple,typec-dptx-phys = <0>; + apple,typec-mux-indices = <2>; + phys = <&atcphy0 PHY_TYPE_DP>; + phy-names = "typec0"; + mux-controls = <&dpxbar0 0>; + mux-control-names = "typec0"; + /* Enabled by the boot loader once it has checked the session. */ + status = "disabled"; + #address-cells = <2>; + #size-cells = <2>; + + piodma { + iommus = <&dispext0_dart 16>; + }; + + typec-routes { + #address-cells = <1>; + #size-cells = <0>; + + route@0 { + reg = <0>; + mode-switch; + status = "disabled"; + + port { + dcpext0_typec0: endpoint { + remote-endpoint = <&typec0_display>; + }; + }; + }; + }; + }; + + dcpext1_mbox: mailbox@3aae08000 { + compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <3 0xaae08000 0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + status = "disabled"; + }; + + dcpext1: dcp@3aae00000 { + compatible = "apple,t8142-dcpext", "apple,dcpext"; + reg = <3 0xaae00000 0 0x4000>, + <3 0xa8000000 0 0xb1c000>, + <3 0xaa240000 0 0x10000>, + <3 0xaa3ac000 0 0x4000>, + <3 0xaa800000 0 0x800000>, + <3 0x82700000 0 0x114000>, + <3 0xaa850000 0 0x4000>; + reg-names = "coproc", "disp-0", "disp-1", "disp-2", + "disp-3", "disp-4", "iop-vbar"; + mboxes = <&dcpext1_mbox>; + mbox-names = "mbox"; + iommus = <&dcpext1_dart 23>; + /* The firmware's clocks: /arm-io/dispext1 clock-ids, as on disp0. */ + apple,clock-ids = <372 433>; + clocks = <&clkref>, <&dcpext_fw_clk372>, <&dcpext_fw_clk433>; + clock-names = "clock-154", "firmware-0", "firmware-1"; + apple,bw-scratch = <&pmgr_dcpext1 0 5 0>; + apple,bw-doorbell = <&pmgr_dcpext1 1 6>; + apple,iomfb-surfaces = <0 0 1 0>; + apple,dcp-index = <2>; + apple,connector-type = "USB-C"; + apple,typec-dptx-phys = <1>; + apple,typec-mux-indices = <4>; + phys = <&atcphy1 PHY_TYPE_DP>; + phy-names = "typec0"; + mux-controls = <&dpxbar1 0>; + mux-control-names = "typec0"; + /* Enabled by the boot loader once it has checked the session. */ + status = "disabled"; + #address-cells = <2>; + #size-cells = <2>; + + piodma { + iommus = <&dispext1_dart 16>; + }; + + typec-routes { + #address-cells = <1>; + #size-cells = <0>; + + route@0 { + reg = <0>; + mode-switch; + status = "disabled"; + + port { + dcpext1_typec1: endpoint { + remote-endpoint = <&typec1_display>; + }; + }; + }; + }; + }; + + /* Each ATC's display crossbar sits behind its PHY's core window. */ + dpxbar0: mux-controller@40304c000 { + compatible = "apple,t8142-display-crossbar"; + reg = <4 0x0304c000 0 0x4000>; + #mux-control-cells = <1>; + power-domains = <&ps_atc0_usb>; + }; + + dpxbar1: mux-controller@40b04c000 { + compatible = "apple,t8142-display-crossbar"; + reg = <4 0x0b04c000 0 0x4000>; + #mux-control-cells = <1>; + power-domains = <&ps_atc1_usb>; + }; +}; + +/* + * DisplayPort needs the LIOA bank (in the AXI2AF window) for the calibration + * the boot loader copies from the ADT. Without both, the PHY stays USB only. + */ +&atcphy0 { + reg = <4 0x03000000 0 0x4c000>, + <4 0x03050000 0 0x8000>, + <4 0x00000000 0 0x8000>, + <4 0x02a90000 0 0x4000>, + <4 0x02a84000 0 0x4000>, + <4 0x00020000 0 0x4000>; + reg-names = "core", "lpdptx", "axi2af", "usb2phy", "pipehandler", "lioa"; +}; + +&atcphy1 { + reg = <4 0x0b000000 0 0x4c000>, + <4 0x0b050000 0 0x8000>, + <4 0x08000000 0 0x8000>, + <4 0x0aa90000 0 0x4000>, + <4 0x0aa84000 0 0x4000>, + <4 0x08020000 0 0x4000>; + reg-names = "core", "lpdptx", "axi2af", "usb2phy", "pipehandler", "lioa"; +}; + +&typec0 { + ports { + port@3 { + reg = <3>; + + typec0_display: endpoint { + remote-endpoint = <&dcpext0_typec0>; + }; + }; + }; +}; + +&typec1 { + ports { + port@3 { + reg = <3>; + + typec1_display: endpoint { + remote-endpoint = <&dcpext1_typec1>; + }; + }; + }; +}; + +/* Scanout and PIODMA share the first register window, as on disp0. */ +&dispext0_dart { + reg = <5 0x06300000 0 0xc000>; + apple,dma-range = <0x100 0x0 0x10 0x0>; +}; + +&dcpext0_dart { + apple,dma-range = <0x100 0x0 0x10 0x0>; +}; + +&dispext1_dart { + reg = <3 0xaa300000 0 0xc000>; + apple,dma-range = <0x100 0x0 0x10 0x0>; +}; + +&dcpext1_dart { + apple,dma-range = <0x100 0x0 0x10 0x0>; +}; + +/ { + /* + * The external DCP firmware's clocks (/arm-io/dispext0 clock-ids 369 and + * 432, dispext1 372 and 433; the same on the J813 and the J815). Their + * rates are /arm-io clock-frequencies entries 0x71 and 0x74 (ids 0x100 + * up), as 712 MHz is entry 0x49 for disp0's 585: 300 MHz and + * 468.75 MHz. 432 and 433 have no entry, as disp0's 431 has none. + * Firmware 27 reads only the first one (see dcp_fw_clk585). + */ + dcpext_fw_clk369: clock-dcpext-firmware-369 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <300000000>; + clock-output-names = "dcpext_firmware_369"; + }; + + dcpext_fw_clk432: clock-dcpext-firmware-432 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <0>; + clock-output-names = "dcpext_firmware_432"; + }; + + dcpext_fw_clk372: clock-dcpext-firmware-372 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <468750000>; + clock-output-names = "dcpext_firmware_372"; + }; + + dcpext_fw_clk433: clock-dcpext-firmware-433 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <0>; + clock-output-names = "dcpext_firmware_433"; + }; +}; + +/* TEST: full firmware shutdown for J813 suspend-to-RAM. */ +&dcpext0 { apple,display-power = <&dcp_power>; }; +&dcpext1 { apple,display-power = <&dcp_power>; }; +&dcpext0_dart { + reg = <5 0x06340000 0 0x20000>, <3 0x80717fe8 0 4>; + reg-names = "dart", "ps-wr-dis"; + apple,ps-wr-dis-bit = <15>; +}; +&dcpext1_dart { + reg = <3 0xaa340000 0 0x20000>, <3 0x80717fec 0 4>; + reg-names = "dart", "ps-wr-dis"; + apple,ps-wr-dis-bit = <31>; +}; +&{/soc/sleep-controller@380700000} { + apple,display-coprocessors = <&dcp &dcpext0 &dcpext1>; +}; diff --git a/arch/arm64/boot/dts/apple/t8142-j813.dts b/arch/arm64/boot/dts/apple/t8142-j813.dts index 9a3c3d3f515ec..d6fc1298a133f 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813.dts +++ b/arch/arm64/boot/dts/apple/t8142-j813.dts @@ -270,3 +270,5 @@ /* Unexposed chassis port instances remain described and disabled. */ #include "t8142-j813-j815-sleep.dtsi" + +#include "t8142-j813-dcpext.dtsi" diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 9543e743c5add..ab0762dc138d6 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -6782,6 +6782,9 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) dcp->fixed_connector_type = dcp_connector_type_from_dt(dev->of_node); dcp->connector_type = dcp->fixed_connector_type; of_property_read_u32(dev->of_node, "apple,dcp-index", &dcp->index); + if (of_device_is_compatible(dev->of_node, "apple,t8142-dcpext") && + (dcp->index < 1 || dcp->index > 2)) + return dev_err_probe(dev, -EINVAL, "invalid external display index\n"); of_property_read_u32(dev->of_node, "apple,dcp-endpoint", &dcp->peer_endpoint); if (of_property_read_bool(dev->of_node, "apple,typec-hybrid-first")) dcp_typec_hybrid_first_dt(); @@ -7653,8 +7656,23 @@ static const struct dcp_s2r_layout dcp_s2r_t8142 = { .pmc_dcp = false, }; +/* TEST: J813 external processors, ADT DISPEXT0/1 power words. */ +static const struct dcp_s2r_layout dcp_s2r_t8142_ext[] = { + { .disp_cpu = 0x428, .disp_fe = 0x418, .disp_sys = 0x308, + .dcp_streams = BIT(23) | BIT(24), .disp_streams = BIT(0) | BIT(16) }, + { .disp_cpu = 0x3b8, .disp_fe = 0x3a8, .disp_sys = 0x2b8, + .dcp_streams = BIT(23) | BIT(24), .disp_streams = BIT(0) | BIT(16) }, +}; + +static bool dcp_s2r_is_t8142_ext(struct apple_dcp *dcp) +{ + return of_device_is_compatible(dcp->dev->of_node, "apple,t8142-dcpext"); +} + 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; } #define DCP_PS_MIN GENMASK(19, 16) @@ -7924,6 +7942,9 @@ static int dcp_s2r_stop_firmware(struct apple_dcp *dcp) */ static bool dcp_s2r_ext_capable(struct apple_dcp *dcp) { + if (dcp->fw_compat == DCP_FIRMWARE_V_27_0) + return dcp->hw.s2r_ext && s2r_untested && dcp->v27_methods && + dcp->v27_methods[dcpep_unnamed_500].tag[0]; return dcp->fw_compat == DCP_FIRMWARE_H17P && dcp->hw.s2r_ext; } @@ -8198,8 +8219,10 @@ static int dcp_s2r_domains_off(struct apple_dcp *dcp) val = readl(ps + l->disp_cpu); if (val & BIT(28)) writel(val & ~(BIT(28) | GENMASK(9, 8)), ps + l->disp_cpu); - writel(3, pwrgate + l->ret_ff); - writel(0, pwrgate + l->ret_mem); + if (l->ret_ff) { + 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); @@ -8243,8 +8266,10 @@ static int dcp_s2r_domains_on(struct apple_dcp *dcp) 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); + if (l->ret_ff) { + 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); @@ -8278,6 +8303,9 @@ static int dcp_s2r_ext_domains_on(struct apple_dcp *dcp) u32 val; int i, ret = -ENODEV; + if (dcp_s2r_is_t8142_ext(dcp)) + return dcp_s2r_domains_on(dcp); + np = of_parse_phandle(dcp->dev->of_node, "apple,display-power", 0); if (!np) return -ENODEV; @@ -8372,6 +8400,9 @@ static int dcp_s2r_ext_domains_off(struct apple_dcp *dcp) int i, ret = -ENODEV; u32 val; + if (dcp_s2r_is_t8142_ext(dcp)) + return dcp_s2r_domains_off(dcp); + np = of_parse_phandle(dcp->dev->of_node, "apple,display-power", 0); if (!np) return -ENODEV; @@ -8428,7 +8459,8 @@ static bool dcp_s2r_ext_cpu_on(struct apple_dcp *dcp) of_node_put(np); if (!ps) return false; - on = FIELD_GET(GENMASK(7, 4), readl(ps + 0x328)); + on = FIELD_GET(GENMASK(7, 4), readl(ps + (dcp_s2r_is_t8142_ext(dcp) ? + dcp_s2r_layout(dcp)->disp_cpu : 0x328))); iounmap(ps); return on; @@ -9306,6 +9338,10 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t8142_dcpext = { .sink_metadata_edid = true, .dptx_endpoint = DPTX_ENDPOINT, .dptx_controller = true, + /* TEST: firmware 27.2 link release, gated by appledrm.s2r_untested. */ + .s2r_ext = true, + .s2r_no_secure_port = true, + .s2r_layout = &dcp_s2r_t8142_ext[0], }; static const struct of_device_id of_match[] = { diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index f512ea452feaf..293ec983e1b40 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -9219,6 +9219,8 @@ static const struct apple_sleep_word t8142_gate_off[] = { /* T8142's, from the J815 tree. GFX's word is in its own block, not "ps". */ static const struct apple_sleep_gate_coproc t8142_gate_coprocs[] = { { "/soc/dcp@286e00000", true, 0x10000 }, + { "/soc/dcp@506e00000", true, 0x428 }, + { "/soc/dcp@3aae00000", true, 0x3b8 }, { "/soc/pmp@380500000", true }, { "/soc/nvme@4c5cc0000" }, { "/soc/mtp@394600000" }, { "/soc/aop@390c00000" }, { "/soc/smc@38c600000" }, From 2be8563e2e45a1f7f6d0c2e8f246f81d3770e8d7 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 12:25:32 +0100 Subject: [PATCH 24/68] drm/apple: retain T8142 external DCP CPUs while idle after wake The J813 external display processors complete the warm RTKit handshake after deep sleep, but lose CPU_CONTROL.RUN within 20 ms. The next suspend queues an AP-link release that the stopped processor cannot answer. Set PS_MIN to 4 before raising the external CPU domain and enabling its automatic power management. This matches the measured J813 macOS wake sequence and the existing T8140 external DCP path. On J813, both processors now retain RUN after wake and answer the next suspend's link-release request. The second full sleep still needs further debugging; this fixes the display processor retention failure. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/dcp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index ab0762dc138d6..84bfa99e56961 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -8265,6 +8265,11 @@ static int dcp_s2r_domains_on(struct apple_dcp *dcp) 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)); + if (dcp_s2r_is_t8142_ext(dcp)) { + /* Retain the CPU when idle, as in the measured J813 wake sequence. */ + val = (val & ~DCP_PS_MIN) | FIELD_PREP(DCP_PS_MIN, 4); + writel(val, ps + l->disp_cpu); + } writel(val | 0xf, ps + l->disp_cpu); if (l->ret_ff) { writel(0, pwrgate + l->ret_ff); From dd8857e97fc36fd7f9409b40e7af39aa66640ec0 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 14 Nov 2026 15:18:00 -0600 Subject: [PATCH 25/68] 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 | 41 +++++++++++++++---- 2 files changed, 45 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 95dea003889db..4bb6491eedb8c 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -363,9 +363,15 @@ struct apple_dart { void __iomem *gapf; /* * The GAPF slice as the boot left it, read before the first write (U32_MAX until - * then); a deep sleep resets it to 0 + * then); 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; @@ -5542,6 +5548,24 @@ static int apple_dart_probe(struct platform_device *pdev) return PTR_ERR(dart->gapf); /* Read at its first use, a sleep's: a boot without one never touches it. */ dart->gapf_boot = U32_MAX; + 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") && @@ -7499,8 +7523,9 @@ static u32 apple_dart_gapf_read(struct apple_dart *dart) } /* - * 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) { @@ -7510,9 +7535,9 @@ static int apple_dart_gapf_release(struct apple_dart *dart) return 0; val = apple_dart_gapf_read(dart); - 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)); @@ -7529,7 +7554,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)); } @@ -7538,7 +7563,7 @@ int apple_dart_gapf_ready(struct device *dev) { struct apple_dart *dart = dev_get_drvdata(dev); - if (!dart->gapf || !(apple_dart_gapf_read(dart) & APPLE_DART_GAPF_PROTECT)) + if (!dart->gapf || !(apple_dart_gapf_read(dart) & dart->gapf_protect)) return 0; return apple_dart_gapf_release(dart); From 9c39e08ec32e0d8b90e5d37d660ec348f9dd2012 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 14 Nov 2026 15:18:00 -0600 Subject: [PATCH 26/68] 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 e62083e7ae0e43123da249571d9c38688867dcfc Mon Sep 17 00:00:00 2001 From: Kyle Arrington Date: Sat, 14 Nov 2026 15:18:00 -0600 Subject: [PATCH 27/68] 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 | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t8142-j813-display.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-display.dtsi index 812b558be0ee6..563fd78c2e43a 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813-display.dtsi +++ b/arch/arm64/boot/dts/apple/t8142-j813-display.dtsi @@ -53,9 +53,34 @@ status = "disabled"; }; + /* + * 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"; + }; + + /* + * 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: iommu@286340000 { compatible = "apple,t8142-dart", "apple,t8110-dart"; - reg = <2 0x86340000 0 0x20000>; + reg = <2 0x86340000 0 0x20000>, + <3 0x80717fdc 0 0x4>; + reg-names = "dart", "ps-wr-dis"; + apple,ps-wr-dis-bit = <6>; interrupts = ; #iommu-cells = <1>; apple,dma-range = <0x100 0x0 0x10 0x0>; @@ -77,6 +102,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>; /* From adc54e175523934a4603beb9f0410e074e7210cc Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 12 Nov 2026 12:57:21 +0100 Subject: [PATCH 28/68] drm/apple: dcp: T8142: Drive the macOS 27.2 firmware On a macOS 27.2 (26B123) stub, the J813 refuses its DCP's apple,firmware-compat of 27.2.0. It then drives the DCP with the H17P interface, and the 27.2 DCP firmware crashes on the first call ("ap_link: rpc_callee_gated: link_rpc_lookup callback not found: 'A427'"). The firmware 27.2 method table (iomfb_v27_methods("27.2.0")) drives the J813's 27.2 DCP: with it the DCP boots, the panel comes up at 2560x1600 and sway presents on it. Admit 27.2.0 on T8142 as firmware 27, so that probe picks that table. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/dcp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 84bfa99e56961..efade9c1cde18 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -5531,11 +5531,12 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) * T8142 (J813) on macOS 27.0: the H17P interface written for its 26.x * firmware makes the 27.0 DCP firmware panic right after the first * hotplug ("ap_link: callback failed with: 0x5"). It runs the T6050's - * firmware-27 generation. + * firmware-27 generation, and so does 27.2, with the 27.2 method table. */ if (of_device_is_compatible(dev->of_node, "apple,t8142-dcp")) { ret = dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); - if (ret >= 0 && !strcmp(compat_str, "27.0.0")) + if (ret >= 0 && (!strcmp(compat_str, "27.0.0") || + !strcmp(compat_str, "27.2.0"))) return DCP_FIRMWARE_V_27_0; } From 55f133d2b1b8c35116387ef8f0756fa4974ca34a Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 13:02:52 +0100 Subject: [PATCH 29/68] dt-bindings: soc: apple: describe the PMU sleep interrupt sources Describe the status word and source mask that the sleep driver owns on the Gen4 SPMI controller. T8142 needs the corresponding peripheral interrupt enabled as well as the RTC alarm programmed to wake the AP. Signed-off-by: Thomas Glanzmann --- .../bindings/soc/apple/apple,t8140-sleep.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml index f814d22832130..dfbeede4111a6 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml @@ -37,6 +37,20 @@ properties: The wake source IDs left enabled across suspend-to-RAM. Every other source is masked. + apple,spmi-pmu-sources: + $ref: /schemas/types.yaml#/definitions/uint32-array + items: + - minimum: 0x600 + maximum: 0x61c + multipleOf: 4 + - minimum: 1 + description: | + Offset of a Gen4 SPMI peripheral interrupt status word and the mask of + PMU sources owned by the sleep controller. Only these latched sources + are acknowledged at entry and wake. On T8142 they are enabled after + programming the RTC alarm, with their prior enable state restored on + return. Other peripheral interrupt sources are left unchanged. + apple,apcie: $ref: /schemas/types.yaml#/definitions/phandle description: From 70c04198ff312a24b38e89c6772d74c8d9c42909 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 13:02:52 +0100 Subject: [PATCH 30/68] soc: apple: sleep: route the T8142 PMU alarm to the wake controller Programming the RTC compare is insufficient when the Gen4 SPMI peripheral source remains masked. J813 reached PMU stage 0x68 on its second sleep; RTC_CTL showed FIRED, but the fresh aura entry marker never changed. Enabling peripheral source 2 manually allowed a second physical resume, with NUB.SPMI0.SW3 reported and the boot ID preserved. After successfully programming the next alarm, acknowledge only the DT- owned stale sources and enable their route. Restore their previous enable state during wake, preserving other sources. This avoids using an old latched alarm as the next wake event. Signed-off-by: Thomas Glanzmann --- drivers/soc/apple/sleep.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index 293ec983e1b40..f96b90a384fe0 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -211,6 +211,7 @@ struct aura_s2r_mailbox { * clear). A latched source that is enabled holds the controller's interrupt output, an AP * wake source, up (T6050, aurora-silicon/linux#1963 commit 24). */ +#define SPMI4_SRC_ENABLE 0x400 #define SPMI4_SRC_STATUS 0x600 #define SPMI4_SRC_WORDS 8 /* A FIFO holds a few replies at most; never spin on a status that doesn't change. */ @@ -1022,6 +1023,8 @@ struct apple_sleep { */ struct device *pmu_bus; u32 spmi_pmu_status, spmi_pmu_bits; + u32 spmi_pmu_enable_saved; + bool spmi_pmu_wake_armed; u32 spmi_src[2][SPMI4_SRC_WORDS]; bool spmi_src_read[2]; unsigned int pmu_busy, pmu_busy_forced; @@ -4632,6 +4635,29 @@ static void sleep_pmu_write(struct apple_sleep *s, u16 reg, u8 val) sleep_pmu_write_one(s, reg, val, false); } +/* + * The PMU alarm also needs its peripheral interrupt routed by nub-spmi0. + * Arm only the DT-owned sources, after the old RTC event has been cleared and + * the next compare programmed. A latched event from the previous alarm must + * not turn this sleep into an immediate wake. + */ +static void sleep_spmi_alarm_wake_arm(struct apple_sleep *s) +{ + void __iomem *enable; + u32 latched, val; + + if (!s->spmi_pmu_bits) + return; + enable = s->spmi + SPMI4_SRC_ENABLE + s->spmi_pmu_status - SPMI4_SRC_STATUS; + latched = readl(s->spmi + s->spmi_pmu_status) & s->spmi_pmu_bits; + if (latched) + writel(latched, s->spmi + s->spmi_pmu_status); + val = readl(enable); + s->spmi_pmu_enable_saved = val & s->spmi_pmu_bits; + s->spmi_pmu_wake_armed = true; + writel(val | s->spmi_pmu_bits, enable); +} + /* * Gen 4: nub-spmi0's peripheral source words, read at the entry (@when 0) and at the wake * (1), and the PMU's latched sources among them acknowledged where the DT names them. The @@ -4657,6 +4683,14 @@ static void sleep_spmi_sources(struct apple_sleep *s, unsigned int when) s->spmi_pmu_bits; if (latched) writel(latched, s->spmi + s->spmi_pmu_status); + if (when && s->spmi_pmu_wake_armed) { + void __iomem *enable = s->spmi + SPMI4_SRC_ENABLE + + s->spmi_pmu_status - SPMI4_SRC_STATUS; + + writel((readl(enable) & ~s->spmi_pmu_bits) | s->spmi_pmu_enable_saved, + enable); + s->spmi_pmu_wake_armed = false; + } } static void sleep_spmi_sources_report(struct apple_sleep *s) @@ -8355,6 +8389,8 @@ static void t8142_post_timer(struct apple_sleep *s) v = 0x41; ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_CTL, &v, NULL, 1); } + if (!ret) + sleep_spmi_alarm_wake_arm(s); t8142_post_ret = ret; } From 728db041fb9092a92a3328a46911a55fecd4b8d8 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 13:02:52 +0100 Subject: [PATCH 31/68] arm64: dts: apple: j813: identify the PMU RTC wake source The J813 ADT assigns PMU peripheral interrupt 2 to the RTC path. macOS enables it at nub-spmi0 offset 0x400 and acknowledges it at 0x600. Describe that source for the sleep driver. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8142-j813.dts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8142-j813.dts b/arch/arm64/boot/dts/apple/t8142-j813.dts index d6fc1298a133f..3d9e69c9760c2 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813.dts +++ b/arch/arm64/boot/dts/apple/t8142-j813.dts @@ -272,3 +272,8 @@ #include "t8142-j813-j815-sleep.dtsi" #include "t8142-j813-dcpext.dtsi" + +&sleep { + /* PMU RTC: peripheral source 2, routed through NUB.SPMI0.SW3. */ + apple,spmi-pmu-sources = <0x600 0x4>; +}; From edfdbcafdfa5fdb1fb73ae7b44318e60471ad8ae Mon Sep 17 00:00:00 2001 From: Kyle Arrington Date: Sat, 14 Nov 2026 16:10:19 -0600 Subject: [PATCH 32/68] dt-bindings: soc: apple,cluster-pwrgate: Add T8142 T8142 has the same per-cluster power-gate enable words as T8132 and T8140. Assisted-by: Claude Fable 5.2 Signed-off-by: Kyle Arrington --- .../devicetree/bindings/soc/apple/apple,cluster-pwrgate.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,cluster-pwrgate.yaml b/Documentation/devicetree/bindings/soc/apple/apple,cluster-pwrgate.yaml index d9d39a5432022..43539cc51a6a3 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,cluster-pwrgate.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,cluster-pwrgate.yaml @@ -23,6 +23,7 @@ properties: - apple,t6050-cluster-pwrgate - apple,t8132-cluster-pwrgate - apple,t8140-cluster-pwrgate + - apple,t8142-cluster-pwrgate - const: apple,cluster-pwrgate reg: From c58ab8cecaf96c07b25391df57ecb8296c2bd213 Mon Sep 17 00:00:00 2001 From: Kyle Arrington Date: Sat, 14 Nov 2026 16:10:37 -0600 Subject: [PATCH 33/68] arm64: dts: apple: t8142-j813: Add the cluster power gates iBoot leaves the boot core's power-gate enable (P core 0, /arm-io/pmgr reg[34] + 0x60) clear on T8142, so the boot core never powers down in WFI. The node lists the E and P clusters' first words, which apple-cluster-pwrgate sets early in boot. T8132 and T8140 describe the same words; there they are enabled for deep sleep, here for idle power. Tested on a J813 (MacBook Air 13" M5, firmware 27.0), same kernel with and without the node, on battery, SMC PSTR: - PCPU_0's power state word reads off in idle with the node, on without it; - screen off, idle: 2.72 W without, 2.54 W with (12 samples each); - screen on, idle: 3.93 W without, 3.83 W with (3 samples each). All 10 cores come up and the system runs as before. The register layout is from m0d16l14n1's J815 sleep work (m0d16l14n1/linux#1). Assisted-by: Claude Fable 5.2 Signed-off-by: Kyle Arrington --- arch/arm64/boot/dts/apple/t8142-j813.dts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8142-j813.dts b/arch/arm64/boot/dts/apple/t8142-j813.dts index 3d9e69c9760c2..d010fb88720c5 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813.dts +++ b/arch/arm64/boot/dts/apple/t8142-j813.dts @@ -226,6 +226,20 @@ }; }; +&{/soc} { + /* + * The CPU clusters' power-gate enables, in /arm-io/pmgr reg[34]: E at + * +0x0 and P at +0x60, the offsets T8132 has and the two words + * AppleT8142PMGR's restoreHW sets. iBoot leaves P's clear, and the + * boot core (P core 0) then never powers down in WFI. + */ + cluster_pwrgate: power-gate@380724000 { + compatible = "apple,t8142-cluster-pwrgate", "apple,cluster-pwrgate"; + reg = <0x3 0x80724000 0x0 0x4>, + <0x3 0x80724060 0x0 0x4>; + }; +}; + /* * The video encoder, its two DARTs and the VENC power tree. The J813 ADT has * the same ave and dart-ave as the J815. The boot loader hands over iBoot's From 5f983e28d869b6e743efba4abc4a9904648780aa Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 14:22:24 +0100 Subject: [PATCH 34/68] PCI: apple-msi: restore port interrupt routing after deep sleep The T8142 platform wake retrains the radio port with its reset values. The MSI doorbell address and enable bit programmed at probe are then lost, while the PCI core only restores the endpoint MSI capability. Keep the mapped ports and replay their MSI routing during noirq resume after a firmware-driven sleep. Signed-off-by: Thomas Glanzmann --- drivers/pci/controller/pcie-apple-msi.c | 44 ++++++++++++++++++++----- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/drivers/pci/controller/pcie-apple-msi.c b/drivers/pci/controller/pcie-apple-msi.c index d3757b6aa8704..02809d9e26c7a 100644 --- a/drivers/pci/controller/pcie-apple-msi.c +++ b/drivers/pci/controller/pcie-apple-msi.c @@ -22,6 +22,7 @@ #include #include #include +#include #define PORT_MSICFG 0x0124 #define PORT_MSICFG_EN BIT(0) @@ -35,6 +36,8 @@ struct apple_msi { struct mutex lock; struct irq_fwspec fwspec; unsigned long *bitmap; + void __iomem **ports; + unsigned int nports; u32 nvecs; }; @@ -114,6 +117,33 @@ static const struct msi_parent_ops apple_msi_parent_ops = { .init_dev_msi_info = msi_lib_init_dev_msi_info, }; +/* On every port, MSI data N goes to the Nth interrupt of msi-ranges. */ +static void apple_msi_hw_init(struct apple_msi *msi) +{ + unsigned int p, i; + + for (p = 0; p < msi->nports; p++) { + void __iomem *port = msi->ports[p]; + + writel(lower_32_bits(DOORBELL_ADDR), port + PORT_MSIADDR); + for (i = 0; i < msi->nvecs; i++) + writel(PORT_MSIMAP_ENABLE | i, port + PORT_MSIMAP + 4 * i); + writel(readl(port + PORT_MSICFG) | PORT_MSICFG_EN, port + PORT_MSICFG); + } +} + +/* The platform wake has brought the port back before device noirq resume. */ +static int apple_msi_resume_noirq(struct device *dev) +{ + if (pm_resume_via_firmware()) + apple_msi_hw_init(dev_get_drvdata(dev)); + return 0; +} + +static const struct dev_pm_ops apple_msi_pm_ops = { + .resume_noirq = apple_msi_resume_noirq, +}; + static int apple_msi_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -171,15 +201,10 @@ static int apple_msi_probe(struct platform_device *pdev) info.size = msi->nvecs; info.host_data = msi; - /* On every port, MSI data N goes to the Nth interrupt of msi-ranges. */ - while (nports--) { - void __iomem *port = ports[nports]; - - writel(lower_32_bits(DOORBELL_ADDR), port + PORT_MSIADDR); - for (i = 0; i < msi->nvecs; i++) - writel(PORT_MSIMAP_ENABLE | i, port + PORT_MSIMAP + 4 * i); - writel(readl(port + PORT_MSICFG) | PORT_MSICFG_EN, port + PORT_MSICFG); - } + msi->ports = ports; + msi->nports = nports; + platform_set_drvdata(pdev, msi); + apple_msi_hw_init(msi); if (!msi_create_parent_irq_domain(&info, &apple_msi_parent_ops)) return -ENOMEM; @@ -198,6 +223,7 @@ static struct platform_driver apple_msi_driver = { .name = "pcie-apple-msi", .of_match_table = apple_msi_of_match, .suppress_bind_attrs = true, + .pm = &apple_msi_pm_ops, }, }; builtin_platform_driver(apple_msi_driver); From 507c53d46cf260fe7b80a4be2ecf56eddec57242 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 15:47:04 +0100 Subject: [PATCH 35/68] Bluetooth: btcentauri: quiesce the J813 transport across deep sleep Pause ring doorbells, request ACIPC host sleep and require its shared-memory acknowledgment before the link goes away. Wait for the wake acknowledgment before restarting polling, and unwind a refused entry. Restore the DMA-backed endpoint MSI capability after PERST; it is programmed outside the PCI core's allocated-vector state. The native 26B123 AirshipDK protocol is verified with the installed J813 firmware. Enable the handshake on J813 only; other boards need qualification. --- drivers/bluetooth/btcentauri.c | 121 ++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 3 deletions(-) diff --git a/drivers/bluetooth/btcentauri.c b/drivers/bluetooth/btcentauri.c index 84f9789f9a2bf..11bbc9d0cc6d1 100644 --- a/drivers/bluetooth/btcentauri.c +++ b/drivers/bluetooth/btcentauri.c @@ -137,6 +137,14 @@ struct cen_bt { u32 hrb_connection_events; u8 hrb_last_link_type; u32 scan_dup_rewritten, accept_list_hidden; + bool transport_paused, transport_sleep_sent; + /* MSI backed by a DMA buffer, outside the PCI core's IRQ allocation. */ + struct { + u32 lo, hi; + u16 flags, data; + u8 cap; + bool saved; + } sleep_msi; }; static u16 cen_tail(struct cen_bt *bt, u16 ring) @@ -539,7 +547,7 @@ static void cen_poll(struct work_struct *work) int budget = CEN_RX_SLOTS; mutex_lock(&bt->lock); - if (!bt->running) + if (!bt->running || bt->transport_paused) goto unlock; if (readl(bt->bar + 0x18) != 2 || readl(bt->bar) != 2) { /* Preserve already completed diagnostics after abort, without posting @@ -913,6 +921,11 @@ static int cen_status_show(struct seq_file *s, void *unused) readl(bt->bar + 0x18), readl(bt->bar), bt->running, bt->tx_head, cen_tail(bt, 1), bt->rx_head, cen_tail(bt, 7), skb_queue_len(&bt->txq)); + seq_printf(s, "peripheral_exec=%u peripheral_ipc=%u sleep_status=%u transport_paused=%u\n", + le32_to_cpu(READ_ONCE(*(__le32 *)(bt->arena + 0x68))), + le32_to_cpu(READ_ONCE(*(__le32 *)(bt->arena + 0x6c))), + le32_to_cpu(READ_ONCE(*(__le32 *)(bt->arena + 0x70))), + bt->transport_paused); seq_printf(s, "commands=%u events=%u tx_bytes=%u rx_bytes=%u tx_errors=%u rx_errors=%u\n", bt->hdev->stat.cmd_tx, bt->hdev->stat.evt_rx, bt->hdev->stat.byte_tx, bt->hdev->stat.byte_rx, @@ -1104,27 +1117,129 @@ static void cen_remove(struct pci_dev *pdev) * bus mastering off, and the next poll stopped the transport for good) and * the PCIe host powered. Polling pauses across the sleep. */ +/* + * 26B123 AirshipDK: Beta sleep_control is BAR0 + 0x1078. Host sleep + * writes 3 and waits for peripheral_info.sleep_status == 3; wake writes + * 0 and waits for status 0 (active) or 1 (device sleep). The peripheral + * info block is at context + 0x68, with sleep_status at +8. + * + * Qualified on J813 with the installed Linux firmware. + * All ring doorbells must stay paused until the wake acknowledgment. + */ +static u32 cen_sleep_status(struct cen_bt *bt) +{ + return le32_to_cpu(READ_ONCE(*(__le32 *)(bt->arena + 0x70))); +} + +static int cen_transport_state(struct cen_bt *bt, bool asleep) +{ + u32 status; + int ret; + + if (readl(bt->bar + 0x18) != 2 || readl(bt->bar) != 2) + return -EIO; + dma_wmb(); + writel(asleep ? 3 : 0, bt->bar + 0x1078); + ret = read_poll_timeout(cen_sleep_status, status, + asleep ? status == 3 : status <= 1, + 100, 2000000, false, bt); + dma_rmb(); + dev_dbg(&bt->pdev->dev, + "ACIPC host %s: ret=%d status=%u exec=%u ipc=%u\n", + asleep ? "sleep" : "wake", ret, status, + readl(bt->bar + 0x18), readl(bt->bar)); + return ret; +} + +static int cen_resume(struct device *dev); + static int cen_suspend(struct device *dev) { struct cen_bt *bt = pci_get_drvdata(to_pci_dev(dev)); + struct pci_dev *pdev = bt->pdev; + u16 flags; + int cap, ret; + mutex_lock(&bt->lock); + bt->transport_paused = true; + mutex_unlock(&bt->lock); cancel_delayed_work_sync(&bt->poll); + if (of_machine_is_compatible("apple,j813") && bt->ipc_requested) { + bt->transport_sleep_sent = true; + ret = cen_transport_state(bt, true); + if (ret) + goto undo; + } + bt->sleep_msi.saved = false; + cap = pci_find_capability(pdev, PCI_CAP_ID_MSI); + if (cap && !pdev->msi_enabled && + !pci_read_config_word(pdev, cap + PCI_MSI_FLAGS, &flags) && + (flags & PCI_MSI_FLAGS_ENABLE) && (flags & PCI_MSI_FLAGS_64BIT)) { + bt->sleep_msi.cap = cap; + bt->sleep_msi.flags = flags; + bt->sleep_msi.saved = + !pci_read_config_dword(pdev, cap + PCI_MSI_ADDRESS_LO, &bt->sleep_msi.lo) && + !pci_read_config_dword(pdev, cap + PCI_MSI_ADDRESS_HI, &bt->sleep_msi.hi) && + !pci_read_config_word(pdev, cap + PCI_MSI_DATA_64, &bt->sleep_msi.data); + } + dev_dbg(dev, "Beta suspend exec=%x ipc=%x fallback MSI saved=%d\n", + readl(bt->bar + 0x18), readl(bt->bar), bt->sleep_msi.saved); device_set_awake_path(dev); - return pci_save_state(to_pci_dev(dev)); + ret = pci_save_state(pdev); + if (!ret) + return 0; +undo: + cen_resume(dev); + return ret; +} + +static int cen_resume_noirq(struct device *dev) +{ + struct cen_bt *bt = pci_get_drvdata(to_pci_dev(dev)); + struct pci_dev *pdev = bt->pdev; + int cap = bt->sleep_msi.cap; + + dev_dbg(dev, "Beta noirq exec=%x ipc=%x fallback MSI saved=%d\n", + readl(bt->bar + 0x18), readl(bt->bar), bt->sleep_msi.saved); + /* + * PERST clears MSI. The PCI core only restores vectors it allocated; + * Centauri's DMA-backed MSI mailbox is programmed directly by the + * Control driver. Restore it before interrupts and polling resume. + */ + if (bt->sleep_msi.saved && !pdev->msi_enabled) { + pci_write_config_word(pdev, cap + PCI_MSI_FLAGS, + bt->sleep_msi.flags & ~PCI_MSI_FLAGS_ENABLE); + pci_write_config_dword(pdev, cap + PCI_MSI_ADDRESS_LO, bt->sleep_msi.lo); + pci_write_config_dword(pdev, cap + PCI_MSI_ADDRESS_HI, bt->sleep_msi.hi); + pci_write_config_word(pdev, cap + PCI_MSI_DATA_64, bt->sleep_msi.data); + pci_write_config_word(pdev, cap + PCI_MSI_FLAGS, bt->sleep_msi.flags); + } + return 0; } static int cen_resume(struct device *dev) { struct cen_bt *bt = pci_get_drvdata(to_pci_dev(dev)); + int ret; + if (bt->transport_sleep_sent) { + ret = cen_transport_state(bt, false); + if (ret) + return ret; + bt->transport_sleep_sent = false; + } mutex_lock(&bt->lock); + bt->transport_paused = false; if (bt->running) schedule_delayed_work(&bt->poll, 0); mutex_unlock(&bt->lock); return 0; } -static DEFINE_SIMPLE_DEV_PM_OPS(cen_pm_ops, cen_suspend, cen_resume); +static const struct dev_pm_ops cen_pm_ops = { + SYSTEM_SLEEP_PM_OPS(cen_suspend, cen_resume) + NOIRQ_SYSTEM_SLEEP_PM_OPS(NULL, cen_resume_noirq) +}; static const struct pci_device_id cen_ids[] = { { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x1903) }, From 9cad4b53f28cf2677eb15420e97a24b6c20aa61e Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 09:04:35 +0100 Subject: [PATCH 36/68] TEST: arm64: apple: enable J813 SEP with its high DMA window Describe the J813 SEP, mailbox and power domains, publish its alias for aura's firmware/manifests handoff, and admit J813 to the T8142 profile. Leave sep_dart disabled until the SEP module enables it. Describe the ADT's SID0 DMA aperture directly with no DART offset. The profile fallback gives the DMA API a low address and adds BIT(40) only to the page-table mapping; the SEP consumed that registration without replying. The explicit high window matches the existing J813 Touch ID work (70035185bd9c) and the macOS s05 registration trace. On J813, fresh attach with xart_writes=0 provision_keybag=0 trusted_keys=0 filevault_api=0 changes from zero replies at IOVA 0xfffc0000 to all 12 endpoints ready at IOVA 0x100fff80000. The key store opens and hwrng registers. The sleep dry run passes with eight coprocessors; a real commit still resets with no aura wake marker. This is sleep bring-up, not Touch ID or suspend/resume qualification. Signed-off-by: Thomas Glanzmann (cherry picked from commit c1a20482ecda19048e9fc2dc78cb1577a18b0b40) --- arch/arm64/boot/dts/apple/t8142-j813-sep.dtsi | 69 +++++++++++++++++++ arch/arm64/boot/dts/apple/t8142-j813.dts | 1 + drivers/soc/apple/profile.rs | 5 +- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 arch/arm64/boot/dts/apple/t8142-j813-sep.dtsi diff --git a/arch/arm64/boot/dts/apple/t8142-j813-sep.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-sep.dtsi new file mode 100644 index 0000000000000..3429ee9661d60 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j813-sep.dtsi @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * The J813's Secure Enclave, for the sleep: only its driver can ask it to sleep, which it + * has to before the SoC goes down (at macOS's commit its domain reads DEV_DISABLE, actual 0). + * From the J813 ADT: /arm-io/sep 0xfa600000 (+0x210000000), ascwrap v6, IRQs 445-448, + * dart-sep; PMGR SEP word +0xc00 (always on, the enclave gates it itself), GPIO +0x120. + */ + +/ { + aliases { + /* aura's dt_set_sep(): sepfw reserved, the boot-object manifests published */ + sep = &sep; + }; +}; + +&pmgr { + ps_gpio: power-controller@120 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x120 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "gpio"; + apple,always-on; + }; + + ps_sep: power-controller@c00 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xc00 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "sep"; + apple,always-on; + }; +}; + +&{/soc} { + sep: sep@30a600000 { + compatible = "apple,sep"; + reg = <0x3 0x0a600000 0x0 0x88000>; + mboxes = <&sep_mbox>; + mbox-names = "mbox"; + iommus = <&sep_dart 0>; + power-domains = <&ps_sep>, <&ps_gpio>; + }; + + sep_mbox: mailbox@30a608000 { + compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x3 0x0a608000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; +}; + +/* + * The SEP consumes the high IOVA on the wire, as in the ADT's vm-base-0. + * An offset on a low DMA window moves only the DART mapping, not the address + * sent in the shared-memory registration. Leave the DART disabled until + * apple-sep enables it (dt.rs), with this window already described. + */ +&sep_dart { + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,dma-offset = /bits/ 64 <0x0>; +}; diff --git a/arch/arm64/boot/dts/apple/t8142-j813.dts b/arch/arm64/boot/dts/apple/t8142-j813.dts index d010fb88720c5..023733ea9a646 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813.dts +++ b/arch/arm64/boot/dts/apple/t8142-j813.dts @@ -283,6 +283,7 @@ /* Unexposed chassis port instances remain described and disabled. */ +#include "t8142-j813-sep.dtsi" #include "t8142-j813-j815-sleep.dtsi" #include "t8142-j813-dcpext.dtsi" diff --git a/drivers/soc/apple/profile.rs b/drivers/soc/apple/profile.rs index c87d46f44eb9f..7301ffdda0636 100644 --- a/drivers/soc/apple/profile.rs +++ b/drivers/soc/apple/profile.rs @@ -710,8 +710,9 @@ fn select( if has(b"apple,t8132") && (has(b"apple,j713") || has(b"apple,j715")) { return Ok(&T8132); } - // Only the J815, whose ADT was read; the J813's sensor bus is unchecked. - if has(b"apple,t8142") && has(b"apple,j815") { + // The J815 and the J813, whose ADTs were read: both have the sensor (mesa) on spi2 + // at 0x3a5108000. + if has(b"apple,t8142") && (has(b"apple,j815") || has(b"apple,j813")) { return Ok(&T8142); } Err(ENODEV) From 2411904bc8df8a8cd212972e1bdcacc85303ee46 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 12 Nov 2026 11:21:06 +0100 Subject: [PATCH 37/68] arm64: dts: apple: t8142-j813: Describe the GPU firmware TEXT The J813 GPU driver is about to identify the firmware build iBoot loaded before it starts it, as the M5 Pro and Max do: it measures both roles' __TEXT, which iBoot loads back to back (ADT gfx-asc and gfx1-asc segment-ranges, 0x50000 + 0x4c000 bytes). Add the region as fw-text. Like fw-data, it is fixed at the address iBoot uses under macOS 27.0 (26A428), 0x100_00e4_4000, until the boot loader fills it in. Under 27.2 (26B123) iBoot loads the TEXT 64 KiB higher, at 0x100_00e5_4000, and the DATA at 0x100_0245_8000, so a 27.2 boot needs a loader that fills both. Signed-off-by: Thomas Glanzmann (cherry picked from commit 1fadec2c1671266405e900b0d549c59e475082fd) --- arch/arm64/boot/dts/apple/t8142-j813-gpu.dtsi | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8142-j813-gpu.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-gpu.dtsi index 763125bfe4ec7..abc977fab1898 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813-gpu.dtsi +++ b/arch/arm64/boot/dts/apple/t8142-j813-gpu.dtsi @@ -33,6 +33,18 @@ reg = <0x100 0x02444000 0x0 0x184000>; }; + /* + * Both roles' __TEXT, contiguous (ADT gfx-asc and gfx1-asc segment-ranges), + * which the driver identifies before it starts the firmware. Fixed at the + * macOS 27.0 address like fw-data, until the bootloader fills it in; under + * 27.2 (26B123) iBoot loads it at 0x100_00e5_4000 and the DATA at + * 0x100_0245_8000. + */ + gpu_fw_text: fw-text { + reg = <0x100 0x00e44000 0x0 0x9c000>; + no-map; + }; + uat_handoff: uat-handoff { reg = <0 0 0 0>; }; @@ -105,9 +117,10 @@ power-domains = <&ps_gfx>; memory-region = <&uat_ttbs>, <&uat_pagetables>, <&uat_handoff>, <&uat_l2_pagetables>, <&gfx_data>, <&gfx1_data>, - <&gpu_fw_data>; + <&gpu_fw_data>, <&gpu_fw_text>; memory-region-names = "ttbs", "pagetables", "handoff", - "shared-l2", "gfx-data", "gfx1-data", "fw-data"; + "shared-l2", "gfx-data", "gfx1-data", "fw-data", + "fw-text"; operating-points-v2 = <&gpu_opp>; /* Holds the DCS and fabric floor while GPU work is in flight. */ apple,clpc = <&clpc>; From b70bc802d47bebacaf652915dd4b67fca43755c5 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 12 Nov 2026 11:21:06 +0100 Subject: [PATCH 38/68] drm/asahi: g17: M5: InitData for the macOS 27.2 (26B123) common firmware The J813 runs the common 26A428 InitData graph, the J873's interface. macOS 27.2 (26B123) ships a new G17G build (RTKit 3514.41.1), which never acknowledges that graph: the secondary's InitData times out. The 26B123 interface differs from 26A428 in three places, the same three as the J873's G18G build of this release: - both roles expect the InitData root version word with bit 45 set, 0x0c8b_6339_83a0_04c0; - the policy grows by 0x60 and the status config by 8; the other 22 allocations keep their sizes. Everything after the policy in the shared cluster moves by 0x80; the page total and the private cluster (0x6d8 still packs to 0x700) stay as they are; - policy fields +0x2f0c..+0x2f17 move by 0x10 and +0x2fb4..+0x6d9f by 0x18, with a new word at +0x2f28; status-config fields +0x59c..+0x5b3 move by 4 and +0x5b4 to the end by 8, with a new word at +0x5b8 and +0x59c left zero. The new words carry a new accelerator power-controller field, which the generic power and performance setup sets to 5000 and the G17G one leaves alone. The HW data, the roots, the main configs, status B and region C keep their field offsets. Add the 26B123 profile and graph. The 26A428 encoders run unchanged and their policy and status config are moved in place by bands; a nonzero byte no band carries is refused. Compile-time checks keep the bands ascending and inside the new sizes. The board for it is J813_26B123; no configuration selects it yet, and the 26A428 encoding is unchanged. Signed-off-by: Thomas Glanzmann (cherry picked from commit 2bb41c80b733c03df1216e7abd2bf766071ec7d3) --- drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs | 314 ++++++++++++++++++-- drivers/gpu/drm/asahi/g17/initdata/m5.rs | 2 +- 2 files changed, 284 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs b/drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs index b5e8ce3cebc27..fa59271630930 100644 --- a/drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs +++ b/drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs @@ -36,6 +36,11 @@ pub(crate) enum RootProfile { J873G18G26A428, J714G17S26A428, + + /// The common interface of macOS 27.2 (26B123, RTKit 3514.41.1): the + /// [`Self::J873G18G26A428`] graph with a longer policy and status config + /// ([`COMMON26B123_LAYOUTS`]). The J813's G17G build runs it as the J873's G18G one does. + J873G18G26B123, } impl RootProfile { @@ -44,13 +49,28 @@ impl RootProfile { Self::J700G17P => INITDATA_VERSION_WORD, Self::J813G17G25G76 => 0x0c8a_a322_039e_04c0, Self::J873G18G26A428 => COMMON26_INITDATA_VERSION_WORD, + Self::J873G18G26B123 => COMMON26B123_INITDATA_VERSION_WORD, Self::J714G17S26A428 => M5_INITDATA_VERSION_WORD, } } + /// Either common-interface build, 26A428 or 26B123. + pub(crate) const fn is_common26(self) -> bool { + matches!(self, Self::J873G18G26A428 | Self::J873G18G26B123) + } + + /// The shared, private and per-object layouts of a common-interface build. + pub(crate) const fn common26_layouts(self) -> Option<&'static Common26Layouts> { + match self { + Self::J873G18G26A428 => Some(&COMMON26_LAYOUTS), + Self::J873G18G26B123 => Some(&COMMON26B123_LAYOUTS), + Self::J700G17P | Self::J813G17G25G76 | Self::J714G17S26A428 => None, + } + } + pub(crate) const fn root_size(self, role: InstanceRole) -> usize { match self { - Self::J873G18G26A428 => COMMON26_ROOT_SIZE, + Self::J873G18G26A428 | Self::J873G18G26B123 => COMMON26_ROOT_SIZE, Self::J714G17S26A428 => M5_ROOT_SIZE, Self::J700G17P | Self::J813G17G25G76 => root_size(role), } @@ -58,10 +78,10 @@ impl RootProfile { pub(crate) const fn control_opening_opcode(self, role: InstanceRole) -> u32 { match (self, role) { - (Self::J873G18G26A428, InstanceRole::Primary) => { + (Self::J873G18G26A428 | Self::J873G18G26B123, InstanceRole::Primary) => { COMMON26_CONTROL_OPENING_OPCODE_PRIMARY } - (Self::J873G18G26A428, InstanceRole::Secondary) => { + (Self::J873G18G26A428 | Self::J873G18G26B123, InstanceRole::Secondary) => { COMMON26_CONTROL_OPENING_OPCODE_SECONDARY } (Self::J714G17S26A428, InstanceRole::Primary) => M5_CONTROL_OPENING_OPCODE_PRIMARY, @@ -75,7 +95,7 @@ impl RootProfile { pub(crate) const fn control_register_opcode(self) -> Option { match self { - Self::J873G18G26A428 | Self::J714G17S26A428 => None, + Self::J873G18G26A428 | Self::J873G18G26B123 | Self::J714G17S26A428 => None, Self::J700G17P | Self::J813G17G25G76 => Some(CONTROL_OPENING_PRIMARY_REGISTER_OPCODE), } } @@ -83,6 +103,7 @@ impl RootProfile { pub(crate) const fn bundle_view_offsets(self) -> [usize; 5] { match self { Self::J873G18G26A428 => COMMON26_BUNDLE_VIEW_OFFSETS, + Self::J873G18G26B123 => COMMON26B123_BUNDLE_VIEW_OFFSETS, Self::J714G17S26A428 => M5_BUNDLE_VIEW_OFFSETS, Self::J700G17P | Self::J813G17G25G76 => BUNDLE_VIEW_OFFSETS, } @@ -90,7 +111,8 @@ impl RootProfile { pub(crate) const fn bundle_view_extents(self) -> [usize; 5] { match self { - Self::J873G18G26A428 => COMMON26_BUNDLE_VIEW_EXTENTS, + // 26B123 grows only the policy and the status config; the five views keep their sizes. + Self::J873G18G26A428 | Self::J873G18G26B123 => COMMON26_BUNDLE_VIEW_EXTENTS, Self::J714G17S26A428 => M5_BUNDLE_VIEW_EXTENTS, Self::J700G17P | Self::J813G17G25G76 => BUNDLE_VIEW_EXTENTS, } @@ -99,7 +121,7 @@ impl RootProfile { /// The GPU-visible aliases of the firmware's own tables the main config names. pub(crate) const fn region_view_low_addrs(self) -> [u64; 2] { match self { - Self::J873G18G26A428 => COMMON26_REGION_VIEW_LOW_ADDRS, + Self::J873G18G26A428 | Self::J873G18G26B123 => COMMON26_REGION_VIEW_LOW_ADDRS, Self::J714G17S26A428 | Self::J700G17P | Self::J813G17G25G76 => REGION_VIEW_LOW_ADDRS, } } @@ -107,6 +129,7 @@ impl RootProfile { pub(crate) const fn repeated_region_bundle_offset(self) -> usize { match self { Self::J873G18G26A428 => COMMON26_SHARED_LAYOUT.block_88, + Self::J873G18G26B123 => COMMON26B123_SHARED_LAYOUT.block_88, Self::J714G17S26A428 => M5_SHARED_LAYOUT.block_88, Self::J700G17P | Self::J813G17G25G76 => MAIN_REPEATED_REGION_BUNDLE_OFFSET, } @@ -115,6 +138,7 @@ impl RootProfile { pub(crate) const fn work_ring_bundle_offsets(self) -> [usize; WORK_CHANNEL_COUNT] { match self { Self::J873G18G26A428 => COMMON26_WORK_RING_BUNDLE_OFFSETS, + Self::J873G18G26B123 => COMMON26B123_WORK_RING_BUNDLE_OFFSETS, Self::J714G17S26A428 => M5_WORK_RING_BUNDLE_OFFSETS, Self::J700G17P | Self::J813G17G25G76 => WORK_RING_BUNDLE_OFFSETS, } @@ -876,18 +900,17 @@ pub(crate) fn encode_main_config_for_profile( RootProfile::J700G17P => MAIN_SECONDARY_KIND_VALUE, RootProfile::J813G17G25G76 => 0xc, - RootProfile::J873G18G26A428 | RootProfile::J714G17S26A428 => { - COMMON26_MAIN_SECONDARY_KIND - } + RootProfile::J873G18G26A428 | RootProfile::J873G18G26B123 + | RootProfile::J714G17S26A428 => COMMON26_MAIN_SECONDARY_KIND, }); if profile == RootProfile::J714G17S26A428 { put_u64(out, COMMON26_MAIN_SECONDARY_POLICY_PTR, bundle + M5_SHARED_LAYOUT.policy as u64); - } else if profile == RootProfile::J873G18G26A428 { + } else if let Some(layouts) = profile.common26_layouts() { put_u64(out, COMMON26_MAIN_SECONDARY_POLICY_PTR, - bundle + COMMON26_SHARED_LAYOUT.policy as u64); + bundle + layouts.shared.policy as u64); } else { let extra = bundle @@ -909,7 +932,7 @@ pub(crate) fn encode_region_c_for_profile( if out.len() != REGION_C_SIZE { return Err(InitdataError::BufferSize); } - if profile == RootProfile::J873G18G26A428 { + if profile.is_common26() { return encode_common26_region_c(out); } @@ -976,7 +999,7 @@ pub(crate) fn encode_secondary_root_extra_1_for_profile( out.fill(0); write_runs(out, SECONDARY_ROOT_EXTRA_1_RUNS); - if matches!(profile, RootProfile::J813G17G25G76 | RootProfile::J873G18G26A428) { + if profile == RootProfile::J813G17G25G76 || profile.is_common26() { put_u32(out, 0x10, 2); } Ok(()) @@ -1904,16 +1927,213 @@ const _: () = { <= COMMON26_STATUS_B_SPAN); }; +// --- The common interface of macOS 27.2 (26B123, RTKit 3514.41.1) ------------------------------- +// +// Against 26A428, the same changes as the J873's G18G build of this release: +// +// - Both roles expect the InitData root version word with bit 45 set. +// - The policy grows by 0x60 (0x7168 -> 0x71c8 for G17G; 0x7800 -> 0x7860 in the common table) +// and the status config by 8 (0x6d0 -> 0x6d8); the other 22 allocations keep their sizes. +// - Policy and status-config fields move as the bands below describe. The new words carry a new +// accelerator power-controller field (accel +0x1122c), which the generic power and performance +// setup sets to 5000 and the G17G one leaves alone. +// - Every other InitData object keeps its field offsets. + +/// FW_PROVEN 26B123: u16 {0x04c0, 0x83a0, 0x6339, 0x0c8b}. +pub(crate) const COMMON26B123_INITDATA_VERSION_WORD: u64 = 0x0c8b_6339_83a0_04c0; + +/// The common 26A428 table with the 26B123 policy and status config. +pub(crate) const ABI_ALLOCATION_SIZES_26B123: [usize; 24] = [ + 0x2848, 0x0c18, 0x1048, 0x0e10, 0x7860, 0x0068, 0x0800, 0x0088, 0x1800, 0x04c0, 0x4000, 0x0030, + 0xe730, 0x06d8, 0x0020, 0x01b0, 0x4800, 0x28800, 0x79800, 0x9000, 0x0060, 0x0008, 0x0e80, 0x00e4, +]; + +/// Everything after the policy in the shared cluster moves by 0x80 (64-byte packing); the page +/// total is unchanged. +pub(crate) const COMMON26B123_SHARED_LAYOUT: SharedClusterLayout = + shared_cluster_layout(&ABI_ALLOCATION_SIZES_26B123); +/// 0x6d8 packs to the 0x700 that 0x6d0 took: the private cluster is the 26A428 one. +pub(crate) const COMMON26B123_PRIVATE_LAYOUT: PrivateClusterLayout = + private_cluster_layout(&ABI_ALLOCATION_SIZES_26B123); + +pub(crate) const COMMON26B123_BUNDLE_VIEW_OFFSETS: [usize; 5] = [ + COMMON26B123_SHARED_LAYOUT.block_c18, + COMMON26B123_SHARED_LAYOUT.block_1048, + COMMON26B123_SHARED_LAYOUT.block_e10, + COMMON26B123_SHARED_LAYOUT.block_68, + COMMON26B123_SHARED_LAYOUT.block_800, +]; + +pub(crate) const COMMON26B123_WORK_RING_BUNDLE_OFFSETS: [usize; WORK_CHANNEL_COUNT] = + work_ring_offsets(&COMMON26B123_SHARED_LAYOUT); + +/// Policy 26A428 -> 26B123. +/// +/// - +0x2f08 stays; the accelerator's power-controller words at +0x2f0c..+0x2f17 move by 0x10 +/// and the new field is the u32 at +0x2f28. +/// - +0x2f18..+0x2fb3 holds nothing the host writes in either build. +/// - From +0x2fb4 to the last 26A428 store (+0x6d98, u64) everything moves by 0x18, among them +/// the policy state pointer, the AON PTD pointer and the boot timestamp. The host writes +/// nothing past +0x6da0. +const COMMON26B123_POLICY_BANDS: &[LayoutBand] = &[ + band(0x0000, 0x2f0c, 0, Evidence::ProducerChecked), + band(0x2f0c, 0x2f18, 0x10, Evidence::ProducerChecked), + band(0x2fb4, 0x6da0, 0x18, Evidence::ProducerChecked), +]; +const COMMON26B123_POLICY_NEW_WORDS: &[(usize, u32)] = &[(0x2f28, 5000)]; + +/// Status config 26A428 -> 26B123: +0x59c..+0x5b3 move by 4 and +0x5b4 to the end by 8 (the +/// link word and pointer among them). The new +0x59c stays zero (only the zeroing of +/// +0x590..+0x59f covers it); +0x5b8 is the new accelerator field. +const COMMON26B123_STATUS_CONFIG_BANDS: &[LayoutBand] = &[ + band(0x000, 0x59c, 0, Evidence::ProducerChecked), + band(0x59c, 0x5b4, 4, Evidence::ProducerChecked), + band(0x5b4, 0x6d0, 8, Evidence::ProducerChecked), +]; +const COMMON26B123_STATUS_CONFIG_NEW_WORDS: &[(usize, u32)] = &[(0x5b8, 5000)]; + +/// How a later build moves the blocks the 26A428 encoders produce. +pub(crate) struct Common26Relayout { + policy_bands: &'static [LayoutBand], + policy_new_words: &'static [(usize, u32)], + status_config_bands: &'static [LayoutBand], + status_config_new_words: &'static [(usize, u32)], +} + +/// The layouts of one common-interface build. +pub(crate) struct Common26Layouts { + pub(crate) shared: SharedClusterLayout, + pub(crate) private: PrivateClusterLayout, + pub(crate) policy_size: usize, + pub(crate) status_config_size: usize, + /// None for 26A428, which the encoders produce directly. + relayout: Option, +} + +pub(crate) const COMMON26_LAYOUTS: Common26Layouts = Common26Layouts { + shared: COMMON26_SHARED_LAYOUT, + private: COMMON26_PRIVATE_LAYOUT, + policy_size: COMMON26_POLICY_SIZE, + status_config_size: COMMON26_STATUS_CONFIG_SIZE, + relayout: None, +}; + +pub(crate) const COMMON26B123_LAYOUTS: Common26Layouts = Common26Layouts { + shared: COMMON26B123_SHARED_LAYOUT, + private: COMMON26B123_PRIVATE_LAYOUT, + policy_size: ABI_ALLOCATION_SIZES_26B123[ALLOC_POLICY], + status_config_size: ABI_ALLOCATION_SIZES_26B123[ALLOC_STATUS_CONFIG], + relayout: Some(Common26Relayout { + policy_bands: COMMON26B123_POLICY_BANDS, + policy_new_words: COMMON26B123_POLICY_NEW_WORDS, + status_config_bands: COMMON26B123_STATUS_CONFIG_BANDS, + status_config_new_words: COMMON26B123_STATUS_CONFIG_NEW_WORDS, + }), +}; + +/// The common 26B123 build (macOS 27.2; the J813). +pub(crate) const COMMON26B123_GRAPH: Graph = Graph { + profile: RootProfile::J873G18G26B123, + private: COMMON26B123_PRIVATE_LAYOUT, + shared: COMMON26B123_SHARED_LAYOUT, + policy_size: COMMON26B123_LAYOUTS.policy_size, + bundle_view_offsets: COMMON26B123_BUNDLE_VIEW_OFFSETS, + bundle_view_extents: COMMON26_BUNDLE_VIEW_EXTENTS, + work_ring_offsets: COMMON26B123_WORK_RING_BUNDLE_OFFSETS, + state_grids: state_grids(&COMMON26B123_PRIVATE_LAYOUT), + power_assert_tally: COMMON26_GRAPH.power_assert_tally, +}; + +const _: () = { + let (old, new) = (COMMON26_SHARED_LAYOUT, COMMON26B123_SHARED_LAYOUT); + assert!(new.total == old.total && new.policy == old.policy); + assert!(new.block_68 == old.block_68 + 0x80 && new.main_config[0] == old.main_config[0] + 0x80); + assert!(COMMON26B123_PRIVATE_LAYOUT.total == COMMON26_PRIVATE_LAYOUT.total); + assert!(COMMON26B123_PRIVATE_LAYOUT.status_config == COMMON26_PRIVATE_LAYOUT.status_config); + assert!(COMMON26B123_PRIVATE_LAYOUT.roles[0].status_a == COMMON26_PRIVATE_LAYOUT.roles[0].status_a); + assert!(COMMON26B123_PRIVATE_LAYOUT.policy_state == COMMON26_PRIVATE_LAYOUT.policy_state); + assert!(COMMON26_STATUS_CONFIG_IN_STATUS_B + COMMON26B123_LAYOUTS.status_config_size + <= COMMON26_STATUS_B_SPAN); + assert!(bands_fit(COMMON26B123_POLICY_BANDS, COMMON26_POLICY_SIZE, + COMMON26B123_LAYOUTS.policy_size)); + assert!(bands_fit(COMMON26B123_STATUS_CONFIG_BANDS, COMMON26_STATUS_CONFIG_SIZE, + COMMON26B123_LAYOUTS.status_config_size)); +}; + +/// Whether `bands` are ascending, move no byte down, keep their order once moved and land +/// inside `new_size`, so [`relayout_by_bands`] can move them in place. +const fn bands_fit(bands: &[LayoutBand], old_size: usize, new_size: usize) -> bool { + let mut index = 0; + while index < bands.len() { + let band = bands[index]; + if band.delta < 0 || band.start >= band.end || band.end > old_size + || band.end + band.delta as usize > new_size { + return false; + } + if index > 0 { + let previous = bands[index - 1]; + if previous.end > band.start + || previous.end + previous.delta as usize > band.start + band.delta as usize { + return false; + } + } + index += 1; + } + true +} + +/// Move a block encoded in the 26A428 layout (the first `old_size` bytes of `out`) to the layout +/// `bands` describe, in place, and zero what the bands leave behind. A nonzero byte no band +/// carries has no place in the new layout and is refused. +fn relayout_by_bands(bands: &[LayoutBand], old_size: usize, out: &mut [u8]) + -> Result<(), InitdataError> { + let old = out.get(..old_size).ok_or(InitdataError::BufferSize)?; + if old.iter().enumerate().any(|(offset, byte)| { + *byte != 0 && relocate_by_bands(bands, offset).is_none() + }) { + return Err(InitdataError::InterfaceMismatch); + } + for band in bands.iter().rev() { + let delta = band.delta as usize; + if delta == 0 { + continue; + } + let target = band.start + delta; + if target + (band.end - band.start) > out.len() { + return Err(InitdataError::BufferSize); + } + out.copy_within(band.start..band.end, target); + out[band.start..band.end.min(target)].fill(0); + } + Ok(()) +} + +/// Bring a block the 26A428 encoder produced to the build's layout and set the words the build +/// added. +fn relayout_common26( + bands: &[LayoutBand], + new_words: &[(usize, u32)], + old_size: usize, + out: &mut [u8], +) -> Result<(), InitdataError> { + relayout_by_bands(bands, old_size, out)?; + for &(offset, value) in new_words { + put_u32(out, offset, value); + } + Ok(()) +} + impl Graph { pub(crate) fn is_common26(&self) -> bool { - self.profile == RootProfile::J873G18G26A428 + self.profile.is_common26() } } -/// Encode the common 26A428 primary status-B span: status B, status config and the gap to -/// status A. The status config carries the board's 25G76 words relocated, the fields 26A428 -/// added and its new cross-link to status B. +/// Encode the common primary status-B span: status B, status config and the gap to status A. The +/// status config carries the board's 25G76 words relocated, the fields 26A428 added and its new +/// cross-link to status B, moved to the layout of the build `layouts` describes. fn encode_common26_primary_status_b( + layouts: &Common26Layouts, fwctl_state: u64, fwctl_ring: u64, status_b: u64, @@ -1926,15 +2146,24 @@ fn encode_common26_primary_status_b( required_address(fwctl_ring)?; required_address(status_b)?; let config = COMMON26_STATUS_CONFIG_IN_STATUS_B; + // Where the build keeps the status config's half of the cross-link. + let link_word = match &layouts.relayout { + Some(relayout) => relocate_by_bands(relayout.status_config_bands, + COMMON26_STATUS_CONFIG_LINK_WORD) + .ok_or(InitdataError::InterfaceMismatch)?, + None => COMMON26_STATUS_CONFIG_LINK_WORD, + }; out.fill(0); encode_status_block(&mut out[..STATUS_BLOCK_SIZE])?; put_u64(out, COMMON26_STATUS_B_FWCTL_STATE, fwctl_state); put_u64(out, COMMON26_STATUS_B_FWCTL_RING, fwctl_ring); put_u32(out, COMMON26_STATUS_B_CONFIG_HEADER, 1); put_u32(out, COMMON26_STATUS_B_LINK_WORD, 0); - put_u64(out, COMMON26_STATUS_B_LINK_PTR, - status_b + (config + COMMON26_STATUS_CONFIG_LINK_WORD) as u64); - let status_config = &mut out[config..config + COMMON26_STATUS_CONFIG_SIZE]; + put_u64(out, COMMON26_STATUS_B_LINK_PTR, status_b + (config + link_word) as u64); + // The 26A428 encoding fills the first COMMON26_STATUS_CONFIG_SIZE bytes; a later build's + // layout is made from it below. + let status_config = out.get_mut(config..config + layouts.status_config_size) + .ok_or(InitdataError::BufferSize)?; write_relocated_words(M5_25G76_STATUS_CONFIG_WORDS, 0, COMMON26_STATUS_CONFIG_BANDS, status_config)?; for (offset, value) in COMMON26_STATUS_CONFIG_NEW_WORDS { @@ -1964,18 +2193,24 @@ fn encode_common26_primary_status_b( put_u32(status_config, COMMON26_STATUS_CONFIG_LINK_WORD, 1); put_u64(status_config, COMMON26_STATUS_CONFIG_LINK_PTR, status_b + COMMON26_STATUS_B_LINK_WORD as u64); + if let Some(relayout) = &layouts.relayout { + relayout_common26(relayout.status_config_bands, relayout.status_config_new_words, + COMMON26_STATUS_CONFIG_SIZE, status_config)?; + } Ok(()) } -/// Encode the common 26A428 private cluster mapped at `private_base`: the status-B span, both -/// status A blocks, the secondary root's 0x60 object and one opening-producer entry per control -/// channel. +/// Encode the private cluster of the common build `profile` mapped at `private_base`: the +/// status-B span, both status A blocks, the secondary root's 0x60 object and one opening-producer +/// entry per control channel. pub(crate) fn encode_common26_private_cluster( + profile: RootProfile, private_base: u64, fwctl_state: u64, out: &mut [u8], ) -> Result<(), InitdataError> { - let layout = COMMON26_PRIVATE_LAYOUT; + let layouts = profile.common26_layouts().ok_or(InitdataError::InterfaceMismatch)?; + let layout = layouts.private; if out.len() != layout.total { return Err(InitdataError::BufferSize); } @@ -1995,13 +2230,14 @@ pub(crate) fn encode_common26_private_cluster( out.fill(0); let status_b = layout.status_b; let status_a = layout.roles[0].status_a; - encode_common26_primary_status_b(fwctl_state, fwctl_ring, private_base + status_b as u64, + encode_common26_primary_status_b(layouts, fwctl_state, fwctl_ring, + private_base + status_b as u64, &mut out[status_b..status_a])?; for role in layout.roles { encode_status_block(&mut out[role.status_a..role.status_a + STATUS_BLOCK_SIZE])?; } let extra = layout.secondary_extra_1; - encode_secondary_root_extra_1_for_profile(RootProfile::J873G18G26A428, + encode_secondary_root_extra_1_for_profile(profile, &mut out[extra..extra + STATUS_BLOCK_SIZE])?; put_u32(out, layout.control_state + CHANNEL_STATE_PRODUCER * CHANNEL_STATE_SPACING, CONTROL_OPENING_PRIMARY_PRODUCER); @@ -2010,15 +2246,18 @@ pub(crate) fn encode_common26_private_cluster( Ok(()) } -/// Encode the six common 26A428 blocks after the HW data (0xc18, 0x1048, 0xe10, perf/policy, -/// 0x68, 0x800): the board's 25G76 policy words relocated, the fields 26A428 added and the owned -/// pointers. Preserves the HW data and everything from the BRN table on. +/// Encode the six common blocks after the HW data (0xc18, 0x1048, 0xe10, perf/policy, 0x68, +/// 0x800): the board's 25G76 policy words relocated, the fields 26A428 added and the owned +/// pointers, in the layout of the board's build. Preserves the HW data and everything from the +/// BRN table on. pub(crate) fn encode_common26_bundle_policy( board: &Board, bindings: M5PolicyBindings, out: &mut [u8], ) -> Result<(), InitdataError> { - let layout = COMMON26_SHARED_LAYOUT; + let layouts = board.graph.profile.common26_layouts() + .ok_or(InitdataError::InterfaceMismatch)?; + let layout = layouts.shared; if out.len() < layout.brn_table { return Err(InitdataError::BufferSize); } @@ -2043,7 +2282,10 @@ pub(crate) fn encode_common26_bundle_policy( return Err(InitdataError::BufferSize); } } - let policy = &mut out[layout.policy..layout.policy + COMMON26_POLICY_SIZE]; + // The 26A428 encoding fills the first COMMON26_POLICY_SIZE bytes; a later build's layout is + // made from it below. + let policy = out.get_mut(layout.policy..layout.policy + layouts.policy_size) + .ok_or(InitdataError::BufferSize)?; for &(offset, value) in M5_25G76_POLICY_WORDS { if (m5.policy..m5_policy_end).contains(&offset) { write_relocated_words(&[(offset, value)], m5.policy, COMMON26_POLICY_BANDS, policy)?; @@ -2067,6 +2309,10 @@ pub(crate) fn encode_common26_bundle_policy( put_u64(policy, COMMON26_POLICY_STATE_PTR, bindings.state); put_u64(policy, COMMON26_POLICY_AON_PTD_PTR, bindings.aon_ptd); put_u64(policy, COMMON26_POLICY_BOOT_TIMESTAMP, bindings.boot_timestamp); + if let Some(relayout) = &layouts.relayout { + relayout_common26(relayout.policy_bands, relayout.policy_new_words, COMMON26_POLICY_SIZE, + policy)?; + } Ok(()) } @@ -2304,6 +2550,12 @@ pub(crate) const J813: Board = Board { completion_inputs: false, }; +/// The J813 on its macOS 27.2 (26B123) firmware: the same board on the common 26B123 graph. +pub(crate) const J813_26B123: Board = Board { + graph: &COMMON26B123_GRAPH, + ..J813 +}; + const _: () = { use super::target::min_parameter_buffer_pages; assert!(J714.min_parameter_buffer as u64 == min_parameter_buffer_pages(J714.clusters) << 15); diff --git a/drivers/gpu/drm/asahi/g17/initdata/m5.rs b/drivers/gpu/drm/asahi/g17/initdata/m5.rs index cf6f8e3f8650b..7b641965cdc70 100644 --- a/drivers/gpu/drm/asahi/g17/initdata/m5.rs +++ b/drivers/gpu/drm/asahi/g17/initdata/m5.rs @@ -205,7 +205,7 @@ impl InitData { m::encode_common26_board_region_c( &mut self.object_mut(self.region_c)?.bytes_mut()[..m::REGION_C_SIZE]) .map_err(|_| EINVAL)?; - m::encode_common26_private_cluster(PRIVATE, FWCTL, + m::encode_common26_private_cluster(board.graph.profile, PRIVATE, FWCTL, &mut self.object_mut(self.cluster)?.bytes_mut()[..private.total]) .map_err(|_| EINVAL)?; } else { From f68394bb0c183cd6bd61b89f2eba1af62931c2b9 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 12 Nov 2026 11:21:13 +0100 Subject: [PATCH 39/68] drm/asahi: t8142: Identify the J813 GPU firmware and admit macOS 27.2 The J813 ran a fixed variant: it started whatever firmware iBoot had loaded on the 26A428 graph. Under the macOS 27.2 stub that is the 26B123 build, which needs its own graph. Identify the loaded build as the M5 Pro and Max do, from the fw-text region: both roles' TEXT (G17G c000, then c010), with the entropy records and the ranges iBoot fills zeroed (the image header's load fields, the boot arguments before each role's GKTS record and the records from it). The 26A428 build keeps the J813 configuration; the 26B123 build runs the board on the 26B123 graph. Both digests reproduce from the stock images in the IPSWs with the same ranges zeroed and were measured on 27.0 (two boots) and 27.2 boots. An unknown build is refused before anything is written to the GPU. Tested on a J813 under the macOS 27.2 stub, with fw-text and fw-data at the 27.2 addresses: both roles acknowledge the 26B123 InitData, the render node registers, and Mesa runs GLES2 16955/0, GLES3 44379/1 (an order-dependent texture-units case that passes alone) and GLES31 37339/0, matching the 27.0 results. Signed-off-by: Thomas Glanzmann (cherry picked from commit 349d61e0d426533d9d7225a91e8301f60a3cf162) --- drivers/gpu/drm/asahi/fwid.rs | 28 +++++++++++ drivers/gpu/drm/asahi/hw/t8142.rs | 77 ++++++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/asahi/fwid.rs b/drivers/gpu/drm/asahi/fwid.rs index c7d2e84797cfb..df20d3c406626 100644 --- a/drivers/gpu/drm/asahi/fwid.rs +++ b/drivers/gpu/drm/asahi/fwid.rs @@ -590,4 +590,32 @@ mod tests { assert!(admit(t, d, &e[..1], h).is_none()); } } + + #[test] + fn t8142_identifies_each_build() { + use crate::g17::fw::m5::initdata::RootProfile; + let crate::g17::fw::variant::Firmware::Identified(builds) = crate::hw::t8142::CONFIG.firmware + else { + panic!("the J813 must identify its loaded firmware"); + }; + assert_eq!(builds.len(), 2); + // Same TEXT and DATA sizes for both builds, so each is told apart by its digest at its + // own record offsets. + t6050_admits_only(builds); + let [a428, b123] = [&builds[0].images[0], &builds[1].images[0]]; + for (image, other) in [(a428, builds[1].images), (b123, builds[0].images)] { + assert!(lookup(other, image.text_size, image.data_size, |_| { + Some(image.text_sha256) + }) + .is_none()); + } + // 26A428 runs the board as probed; 26B123 runs it on the 26B123 graph. + assert!(builds[0].config.is_none()); + let config = builds[1].config.unwrap(); + assert_eq!(config.m5.unwrap().graph.profile, RootProfile::J873G18G26B123); + assert_eq!( + crate::hw::t8142::CONFIG.m5.unwrap().graph.profile, + RootProfile::J873G18G26A428 + ); + } } diff --git a/drivers/gpu/drm/asahi/hw/t8142.rs b/drivers/gpu/drm/asahi/hw/t8142.rs index 26fe2e49abcdb..eae2960d74fab 100644 --- a/drivers/gpu/drm/asahi/hw/t8142.rs +++ b/drivers/gpu/drm/asahi/hw/t8142.rs @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT -//! M5 (T8142, MacBook Air J813) on the macOS 27.0 (26A428) GPU firmware. +//! M5 (T8142, MacBook Air J813) on the macOS 27.0 (26A428) and 27.2 (26B123) GPU firmware. //! //! Bring-up only: the M5 graph ([`crate::g17::fw::m5::initdata`]) has no J813 board yet, so //! [`PROBE`] stops at the identity check, after `get_g17_id` has logged the ID registers and @@ -57,8 +57,15 @@ pub(crate) const PROBE: Config = Config { }, }; -/// The J813 on the M5 graph: [`PROBE`] with the GPU's identity and the J813 board. +/// The J813 on the M5 graph: [`PROBE`] with the GPU's identity and the J813 board. It runs +/// either firmware build of [`BUILDS`]; 26B123 runs [`CONFIG_26B123`]. pub(crate) const CONFIG: Config = Config { + firmware: crate::g17::fw::variant::Firmware::Identified(&BUILDS), + ..BASE +}; + +/// The J813 board and identity, before a firmware build is chosen. +const BASE: Config = Config { identity: Identity { family: 0xb, variant: 2, @@ -79,6 +86,72 @@ pub(crate) const CONFIG: Config = Config { ..PROBE }; +/// The J813 on the 27.2 firmware: the board on the common 26B123 graph. +pub(crate) const CONFIG_26B123: Config = Config { + m5: Some(&crate::g17::fw::m5::initdata::J813_26B123), + firmware: crate::g17::fw::variant::Firmware::Identified(&[BUILD_26B123]), + ..BASE +}; + +/// The firmware in `fw-text` must be one of these builds. iBoot loads the G17G c000 image of the +/// primary (TEXT 0x50000) and the c010 image of the secondary (0x4c000) back to back. The digest +/// is that of both TEXTs with the entropy records and the ranges iBoot fills zeroed (the image +/// header's load fields at +0x224 and +0x23c, the 0x740 bytes of boot arguments before each +/// role's GKTS record and the 0x231 bytes of records from it); it is that of the stock images +/// in the IPSW with the same ranges zeroed, and was measured on two 27.0 boots and one 27.2 boot. +const BUILDS: [crate::g17::fw::variant::Build; 2] = [ + BUILD_26A428, + crate::g17::fw::variant::Build { + config: Some(&CONFIG_26B123), + ..BUILD_26B123 + }, +]; + +const BUILD_26A428: crate::g17::fw::variant::Build = crate::g17::fw::variant::Build { + os_version: [27, 0, 0], + name: "27.0 (26A428), G17G", + images: &[crate::fwid::FirmwareBuild { + name: "26A428 for T8142 G17G, primary then secondary", + text_size: 0x9c000, + data_size: 0x184000, + entropy: &[[0x49d10, 0x49df3], [0x997d0, 0x998b3]], + boot_filled: &[ + (0x224, 4), (0x23c, 8), (0x495d0, 0x740), (0x49d10, 0x231), + (0x50224, 4), (0x5023c, 8), (0x99090, 0x740), (0x997d0, 0x231), + ], + text_sha256: [ + 0xec, 0xff, 0x40, 0xe3, 0xad, 0xb8, 0x9c, 0x90, 0x62, 0xe9, 0x1d, 0xb6, 0x3f, + 0x31, 0xba, 0xaf, 0x75, 0xeb, 0x5d, 0x3f, 0x97, 0x22, 0xe3, 0x06, 0x95, 0x45, + 0x3f, 0xad, 0x02, 0xfc, 0xf5, 0x0c, + ], + }], + variant: &crate::g17::fw::variant::V26A428_M5, + config: None, +}; + +/// RTKit 3514.41.1: the 26A428 protocol on the 26B123 InitData graph. +const BUILD_26B123: crate::g17::fw::variant::Build = crate::g17::fw::variant::Build { + os_version: [27, 2, 0], + name: "27.2 (26B123), G17G", + images: &[crate::fwid::FirmwareBuild { + name: "26B123 for T8142 G17G, primary then secondary", + text_size: 0x9c000, + data_size: 0x184000, + entropy: &[[0x49d54, 0x49e37], [0x997e4, 0x998c7]], + boot_filled: &[ + (0x224, 4), (0x23c, 8), (0x49614, 0x740), (0x49d54, 0x231), + (0x50224, 4), (0x5023c, 8), (0x990a4, 0x740), (0x997e4, 0x231), + ], + text_sha256: [ + 0xe3, 0xab, 0x32, 0x7b, 0x73, 0x1b, 0xf2, 0xf1, 0x74, 0x9b, 0x04, 0x44, 0x1f, + 0x5c, 0xb5, 0xab, 0xfc, 0x23, 0xf3, 0x41, 0xc3, 0x99, 0x72, 0x8e, 0x2c, 0xb4, + 0x6f, 0x68, 0xb1, 0x7a, 0x39, 0xb9, + ], + }], + variant: &crate::g17::fw::variant::V26A428_M5, + config: None, +}; + // Each compute operand bank holds 6 KiB per core slot of the board. const _: () = assert!( CONFIG.core_layout.operand_state.bank_bytes() From 274ca16653ede34436783a330130c4fc0ef1fc41 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 06:44:16 +0100 Subject: [PATCH 40/68] TEST ONLY: drm/asahi: t8142: J813: sleep_restart, as T8140 (commit stops, wake restarts) Signed-off-by: Thomas Glanzmann (cherry picked from commit 0367ba80c4d76a890556b2fba867fccfa0b8db14) --- drivers/gpu/drm/asahi/hw/t8142.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/asahi/hw/t8142.rs b/drivers/gpu/drm/asahi/hw/t8142.rs index eae2960d74fab..9bc380afce9a7 100644 --- a/drivers/gpu/drm/asahi/hw/t8142.rs +++ b/drivers/gpu/drm/asahi/hw/t8142.rs @@ -83,6 +83,9 @@ const BASE: Config = Config { deflake: crate::g17::fw::render::Deflake::ONE_CLUSTER, compute_blocks: crate::g17::fw::freelist::COMPUTE_BLOCKS, }, + // TEST: the sleep's commit stops the firmware and a real wake restarts it warm, as on + // T8140. Not yet run through a real sleep on the J813. + sleep_restart: true, ..PROBE }; From 6f565e2098962d84ccfd7967a1b6ecf638f0a7ab Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 12 Nov 2026 13:35:53 +0100 Subject: [PATCH 41/68] drm/apple: dcp: Give firmware 27.2 its dfb_ready_query The firmware 27.2 table has no ID for dfb_ready_query, so boot_5() skips the query on 27.2. The 27.3 trace sends it at A385, one above its 27.0 ID, as 27.2 moved set_create_DFB and vi_set_temperature_hint up by one. Give the 27.2 table A385, so 27.2 boots with the same sequence as 27.0. The J813 ran with this table on 27.2: boot_done() acknowledges the DCP's boot callback only after the query's reply, and the DCP booted and the panel came up. Signed-off-by: Thomas Glanzmann (cherry picked from commit 801cec0abfc48ffbf6203322a32255e4ebda9ceb) --- drivers/gpu/drm/apple/iomfb_v27.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/apple/iomfb_v27.c b/drivers/gpu/drm/apple/iomfb_v27.c index b54cdac4591de..a1ccdb537d54f 100644 --- a/drivers/gpu/drm/apple/iomfb_v27.c +++ b/drivers/gpu/drm/apple/iomfb_v27.c @@ -171,9 +171,9 @@ static const struct dcp_method_entry dcp_methods_27_0[dcpep_num_methods] = { * A400/A401, so IOMobileFramebufferAP moved up by 50 (start_signal A451, * get_color_remap_mode A477), and set_create_DFB and vi_set_temperature_hint * up by one. The UPPipe A0xx and A1xx IDs are unchanged. The firmware rejects - * an unknown tag with a panic ("link_rpc_lookup callback not found"), so - * dfb_ready_query, whose 27.2 tag has not been seen in a call, has no entry - * here and is not sent to this build (boot_5()). + * an unknown tag with a panic ("link_rpc_lookup callback not found"). + * dfb_ready_query is A385, one above its 27.0 ID: the 27.3 trace sends it + * there, and the J813's DCP answers it at A385 on 27.2. */ static const struct dcp_method_entry dcp_methods_27_2[dcpep_num_methods] = { IOMFB_METHOD("A000", dcpep_late_init_signal), @@ -199,6 +199,7 @@ static const struct dcp_method_entry dcp_methods_27_2[dcpep_num_methods] = { IOMFB_METHOD("A104", dcpep_set_dfb_dimensions), IOMFB_METHOD("A105", dcpep_commit_dfb_info), IOMFB_METHOD("A035", dcpep_dfb_query), + IOMFB_METHOD("A385", dcpep_dfb_ready_query), IOMFB_METHOD("A353", dcpep_pipe_query_353), IOMFB_METHOD("A352", dcpep_pipe_set_352), IOMFB_METHOD("A465", dcpep_pipe_cfg_415), From 3f0cb7172ce3e0dfb2e2fa4aae489918e395edcf Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 12 Nov 2026 14:25:21 +0100 Subject: [PATCH 42/68] drm/apple: afk: T8142: Bind powerlog-service on firmware 27 The M5's DCP announces powerlog-service on ep:20 with only ep-has-desc-mgr and interface-id. AFK matches such a service by its announced name, but only for the H17G method profile, and a T8142 on firmware 27 runs the default profile. So on 27.0 and 27.2 the service is never bound ("AFK[ep:20]: failed to extract init props: -2"), and the mNits reports it carries, the loader-level hint that dcp_backlight_takeover() takes on firmware 27, could never arrive. Fall back to the announced name for a T8142 on firmware 27 as well: the H17P-generation processor (hw.firmware_compat) that probe admits as firmware 27. The service-rebind host test's apple_dcp gets that field. On 27.2 the service now binds on channel 1. That firmware sent no report in the first minutes after boot, so the backlight still starts from the fallback level there. Signed-off-by: Thomas Glanzmann (cherry picked from commit 0e76ef5980276399afc61e0a482688b3e12ab21a) --- drivers/gpu/drm/apple/afk.c | 14 +++++++++----- .../selftests/drivers/gpu/apple-dcp/edid.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index c08084877a151..c2744a823f67e 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -1713,14 +1713,18 @@ static void afk_recv_handle_init(struct apple_dcp_afkep *ep, u32 channel, ep->dcp->fw_compat == DCP_FIRMWARE_V_27_0); if (ret == -ENOENT && (ep->dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17G || + (ep->dcp->fw_compat == DCP_FIRMWARE_V_27_0 && + ep->dcp->hw.firmware_compat == DCP_FIRMWARE_H17P) || ep->dcp->v27_j714s)) { /* * M5 (H17G) announces powerlog-service with only - * ep-has-desc-mgr and interface-id, and firmware 27 - * its descriptor manager (md-manager) without EPIC - * keys; match them by the announced name, as for - * props-less announces. The second on the J714s only, - * where its endpoints are started. + * ep-has-desc-mgr and interface-id, on 26.x and on + * firmware 27 alike (the T8142, an H17P-generation + * processor, is the one that runs firmware 27), and + * firmware 27 its descriptor manager (md-manager) + * without EPIC keys; match them by the announced name, + * as for props-less announces. The md-manager on the + * J714s only, where its endpoints are started. */ epic_name = NULL; epic_class = NULL; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py index ebd1d39c250ff..758a33a5ae4dd 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py @@ -100,7 +100,7 @@ def function(file,signature): struct apple_dcp { void *dev;int fw_compat;struct apple_dcp_afkep *dcpavservep;struct apple_connector *connector; bool external_physically_absent,hpd_mutex,quiescing,typec_cable_connected;u64 typec_generation;unsigned int nr_modes; - struct { int iomfb_method_profile; bool fw_14_7_endpoints; unsigned int num_dptx_ports; } hw; bool ext_dead,external_native; + struct { int iomfb_method_profile,firmware_compat; bool fw_14_7_endpoints; unsigned int num_dptx_ports; } hw; bool ext_dead,external_native; struct { bool lock,enabled;u64 epoch;int enable_completion;struct apple_epic_service *service,*opened; u64 opened_epoch,close_gen,terminated_epoch,close_epoch;bool opening;struct work_struct close_wq; } dcpavserv; /* A J714s firmware 27 processor's: this one is not. */ From 7706aff33d1e35fa5992a82346b1ab3d6828bffd Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 12 Nov 2026 14:28:33 +0100 Subject: [PATCH 43/68] drm/apple: dcp: Send a present without a surface at the completed level On firmware 27 the first present of a new KMS client (modetest, kmscube) fails with "present dropped: backlight prepare -61" and "swap failed!", and modetest -v then sees no page flip. With the panel backlight active, iomfb_apply_backlight_h17p() drops every present that dcp_backlight_prepare() refuses. dcp_bl_prepare() refuses a present without a surface with -ENODATA, because such a present cannot apply a new level, so the whole present is dropped rather than only the level. Treat a present without a surface as one with nothing to reserve: it carries the last completed level and is sent, and a pending level waits, still dirty, for the next present with a surface. Only the H17P/firmware 27 path asks without a surface; the M4 and 14.7 callers always pass one. Signed-off-by: Thomas Glanzmann (cherry picked from commit f99c37aee0a917f38e2431c45231904930fc2b79) --- drivers/gpu/drm/apple/dcp_backlight.c | 11 ++++++++-- .../drm/apple/iomfb_v14_7_backlight_test.c | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp_backlight.c b/drivers/gpu/drm/apple/dcp_backlight.c index 7432513a7ba25..17047f04fd2e0 100644 --- a/drivers/gpu/drm/apple/dcp_backlight.c +++ b/drivers/gpu/drm/apple/dcp_backlight.c @@ -435,9 +435,16 @@ int dcp_backlight_prepare(struct apple_dcp *dcp, bool have_surface, spin_lock_irqsave(&dcp->backlight.lock, flags); ret = dcp_bl_prepare(&dcp->backlight.state, have_surface, present); - /* No reservation: carry the last completed level on an ordinary present. */ - if (ret == -EALREADY) + /* + * No reservation: carry the last completed level on an ordinary + * present, and on one without a surface, which cannot apply a new + * level. A pending level waits for the next present with a surface. + */ + if (ret == -EALREADY || + (ret == -ENODATA && !have_surface && dcp->backlight.state.ready)) { present->nits = dcp->backlight.state.actual; + ret = -EALREADY; + } spin_unlock_irqrestore(&dcp->backlight.lock, flags); return ret; } diff --git a/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c b/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c index 3c1fc2f45d534..a84e45338793e 100644 --- a/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c +++ b/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c @@ -554,6 +554,25 @@ static void v14_bl_t6030_work(struct kunit *test) KUNIT_EXPECT_TRUE(test, dcp_backlight_pending(f.dcp)); } +/* + * A present without a surface cannot apply a new level: it carries the last + * completed one and reserves nothing, so it is still sent, and the request + * waits for the next present with a surface. + */ +static void v14_bl_surfaceless_present(struct kunit *test) +{ + struct v14_bl_fixture f = v14_bl_fixture(test, &dcp_v14_board_t6030, true); + struct dcp_backlight_present p = { .nits = U32_MAX }; + + v14_bl_request(test, f.dcp, 250); + KUNIT_EXPECT_EQ(test, dcp_backlight_prepare(f.dcp, false, &p), -EALREADY); + KUNIT_EXPECT_EQ(test, p.nits, DCP_V14_NITS_DEFAULT); + KUNIT_EXPECT_TRUE(test, f.dcp->backlight.state.dirty); + KUNIT_EXPECT_FALSE(test, f.dcp->backlight.state.in_flight); + KUNIT_ASSERT_EQ(test, dcp_backlight_prepare(f.dcp, true, &p), 0); + KUNIT_EXPECT_EQ(test, p.nits, 250U); +} + static struct kunit_case v14_backlight_cases[] = { KUNIT_CASE(v14_bl_binary64), KUNIT_CASE(v14_bl_level_block), @@ -562,6 +581,7 @@ static struct kunit_case v14_backlight_cases[] = { KUNIT_CASE(v14_bl_gate_transitions), KUNIT_CASE(v14_bl_plan), KUNIT_CASE(v14_bl_policy), + KUNIT_CASE(v14_bl_surfaceless_present), KUNIT_CASE(v14_bl_other_boards_untouched), KUNIT_CASE(v14_bl_external_untouched), KUNIT_CASE(v14_bl_t6030_swap_levels), From bddf7524ca2766acd1aa6c43fe369afe675cc5c2 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 08:59:36 +0100 Subject: [PATCH 44/68] TEST ONLY: soc: apple: sleep: leave T8142 AON audio domains to firmware Port the audio power policy from the successful J813 experimental stack: do not apply T8132's forced state-4 list to these no_ps domains. Keep the updated sleep branch's own PMU diagnostics. The old diagnostic hunk is omitted because it uses the same scratch bytes differently. This prerequisite has not been isolated as the cause of a failure. Signed-off-by: Thomas Glanzmann (cherry picked from commit 8dd86e470d2087d60fc4a9405604bf4cabe1accc) --- drivers/soc/apple/sleep.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index f96b90a384fe0..4a92376829020 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -9218,9 +9218,11 @@ static const u32 t8142_ps_aon_macos_off[] = { 0xe0, 0xd8, }; -static const u32 t8142_ps_aon_macos_on[] = { - 0x40e0, 0x40e8, 0x4118, 0x4138, 0x4148, 0x4150, 0x4158, -}; +/* + * T8142 has no ps_aon_macos_on list. These audio domains are no_ps in its + * ADT and remain at actual/target zero in the J813 macOS sleep snapshot; + * the traced AP never accesses them. The T8132 state-4 rule does not apply. + */ /* * T8132's quiesce words by name: the ATC commons, the display's and DISPEXT's SYS, ANS, AVD, @@ -9402,7 +9404,6 @@ static const struct apple_sleep_soc t8142_sleep_soc = { .ps_aon_all = SLEEP_WORDS(t8142_ps_aon_all), .ps_macos_off = SLEEP_WORDS(t8142_ps_macos_off), .ps_aon_macos_off = SLEEP_WORDS(t8142_ps_aon_macos_off), - .ps_aon_macos_on = SLEEP_WORDS(t8142_ps_aon_macos_on), .ps_wake_order = SLEEP_WORDS(t8142_ps_wake_order), .ps_aon_wake_order = SLEEP_WORDS(t8142_ps_aon_wake_order), .ps_boot_auto = SLEEP_WORDS(t8142_ps_boot_auto), From b29e3c73048fc3c14ab797c418bd5746f6ff5ef3 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 16:11:55 +0100 Subject: [PATCH 45/68] drm/apple: dcp: stop the J813 firmware during system suspend The system-suspend callback skipped every s2r_untested instance even after probe admitted J813 through appledrm.s2r_untested. With the panel active, the DCP kept RUN and the sleep controller refused entry. Use the existing qualified DCP quiesce and restart path on J813 during system sleep. Preserve the explicit opt-in and all existing readiness checks; other unqualified boards keep their prior behavior. Validated active-panel sleeps with and without fbcon bound, followed by three systemctl suspend cycles. The panel, GPU rendering and Bluetooth recovered each time. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/dcp.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index efade9c1cde18..0915ff0e0dbc0 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -290,7 +290,7 @@ static int dcp_secure_port_init(struct apple_dcp *dcp) * 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 only. + * appledrm.s2r_untested stops its firmware for DPMS off and J813 system sleep. */ static void dcp_s2r_check_dt(struct apple_dcp *dcp) { @@ -309,7 +309,7 @@ static void dcp_s2r_check_dt(struct apple_dcp *dcp) 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"); + dev_info(dcp->dev, "firmware stop enabled (appledrm.s2r_untested)\n"); } static void dcp_release_rtkit(void *data) @@ -474,13 +474,13 @@ static bool dcp_j714s_ext(struct device *dev) /* * 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. + * tree instead of measured (T8142). J813 supports DPMS off and system sleep with this + * opt-in. 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 (default 0)"); + "Stop the DCP firmware on DPMS off and J813 system sleep using derived T8142 power words (default 0)"); bool dcp_t6041_ext_enabled(void) { @@ -9020,8 +9020,13 @@ static int dcp_platform_suspend(struct device *dev) if (pm_suspend_via_firmware() && dcp_v27_sleep_selected(dcp)) return dcp_v27_sleep_suspend(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) { + /* + * 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. + */ + if (pm_suspend_via_firmware() && dcp_s2r_capable(dcp) && + (!dcp->hw.s2r_untested || of_machine_is_compatible("apple,j813"))) { int ret = dcp_s2r_suspend(dcp); /* Lit by the last resume with its CRTC off: the next resume finds it off by DPMS. */ From f1aa5a53ac77d0197f1eae31b581a0df0300c3a5 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 18:24:16 +0100 Subject: [PATCH 46/68] soc: apple: sleep: send J813's final SMC notice after peer stops After a battery lid suspend on J813, ANS failed its IOP IDLE handshake and SMC faulted at the ANS mailbox. Linux resumed, but ANS could not restart and DCP power-on timed out. The matching native trace idles ANS before the final SMC MBSE/AP IDLE sequence. Defer that sequence until the peer stops have finished. Reserve the existing bounded SMC transport before IRQ shutdown and check ownership before irreversible stops. Release it at platform wake, retaining AP IDLE until macsmc resume_noirq so the original wake-notice timing is preserved. Earlier tests with AP ON in platform wake had Alpha Wi-Fi aborts; preserve the established ordering without claiming that the timing change alone explains those failures. Keep the J813-only diagnostic switch, command sequence and delay floors. Three RTC and two battery lid wakes completed on the candidate stack. The resulting source tree is identical to tested candidate 651007bc8138. Signed-off-by: Thomas Glanzmann --- drivers/mfd/macsmc.c | 70 +++++++++++++++++++++++++++++++-- drivers/soc/apple/sleep.c | 46 +++++++++++++++++++--- include/linux/soc/apple/sleep.h | 3 ++ 3 files changed, 110 insertions(+), 9 deletions(-) diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c index 1a4f9c2da8cfc..32823667e5a6f 100644 --- a/drivers/mfd/macsmc.c +++ b/drivers/mfd/macsmc.c @@ -650,6 +650,9 @@ static int apple_smc_probe(struct platform_device *pdev) of_device_is_compatible(dev->of_node, "apple,t6050-smc"); if (smc->saved_enabled) smc->wake_reasons = apple_smc_j714s_wake_reasons; + /* J813's late notice needs the bounded, IRQ-independent transport too. */ + if (of_machine_is_compatible("apple,j813")) + smc->saved_enabled = true; smc->sram_base = devm_platform_get_and_ioremap_resource(pdev, 1, &smc->sram); if (IS_ERR(smc->sram_base)) return dev_err_probe(dev, PTR_ERR(smc->sram_base), "Failed to map SRAM region"); @@ -1130,7 +1133,8 @@ static int apple_smc_sleep_saved_begin(void *data) struct apple_smc *smc = data; int ret; - if (!smc->saved_enabled || !smc->sleep_policy) + if (!smc->saved_enabled || + (!smc->sleep_policy && !apple_sleep_smc_defer_notice())) return -EOPNOTSUPP; if (!mutex_trylock(&smc->mutex)) return -EBUSY; @@ -1182,7 +1186,7 @@ static int apple_smc_sleep_saved_begin(void *data) return ret; } -static int apple_smc_sleep_saved_end(void *data) +static int apple_smc_sleep_saved_release(void *data, bool wake_ap) { struct apple_smc *smc = data; int ret, restore = 0; @@ -1195,7 +1199,7 @@ static int apple_smc_sleep_saved_end(void *data) /* Bounded reconciliation; never release pending ownership on timeout. */ if (!ret && smc->saved_pending) ret = apple_smc_saved_wait_reply(smc); - if (smc->ap_notified) { + if (wake_ap && smc->ap_notified) { restore = apple_rtkit_m5_saved_ap_power(smc->rtk, true, NULL, NULL); if (!restore) { smc->ap_notified = false; @@ -1217,6 +1221,23 @@ static int apple_smc_sleep_saved_end(void *data) return ret; } +static int apple_smc_sleep_saved_end(void *data) +{ + return apple_smc_sleep_saved_release(data, true); +} + +/* + * J813's ordinary wake notice belongs in macsmc's resume_noirq, after the + * device dependencies have resumed. Platform wake precedes every noirq + * device callback; an AP ON there can wake the radio before its DMA path. + * Release the bounded transport here, retaining ap_notified for the usual + * noirq wake callback. A refused entry never posted AP IDLE. + */ +static int apple_smc_j813_saved_end(void *data) +{ + return apple_smc_sleep_saved_release(data, false); +} + /* Readiness is a returning operation BEFORE SEP/ANS/PMP stop. A drained * notification remains retained and can cancel only on this side of the boundary. */ @@ -1336,6 +1357,42 @@ static const struct apple_sleep_smc_saved_ops apple_smc_saved_ops = { .pmvc = apple_smc_sleep_saved_pmvc, }; +/* + * J813 retains its existing MBSE/AP sequence and delay floors. The transport + * is the saved lane: no scheduler, jiffies, IRQ worker or SRAM reuse is needed + * after the peer stops. Unrelated notifications are retained until resume. + */ +static int apple_smc_sleep_after_peers(void *data, u64 *sent, u64 *ack) +{ + struct apple_smc *smc = data; + int ret; + + lockdep_assert_held(&smc->mutex); + *sent = *ack = 0; + if (!irqs_disabled() || !smc->saved_scope || !smc->sleep_warned || + smc->ap_notified) + return -EINVAL; + + smc->saved_committed = true; + ret = apple_smc_saved_write_u32(smc, SMC_KEY(MBSE), SMC_KEY(slpa)); + if (ret) + goto out; + mdelay(SMC_SLEEP_ARM_MS); + smc->ap_notified = true; + ret = apple_rtkit_m5_saved_ap_power(smc->rtk, false, sent, ack); + if (!ret) + mdelay(SMC_SLEEP_IDLE_MS); +out: + smc->saved_notice_error = ret; + return ret; +} + +static const struct apple_sleep_smc_saved_ops apple_smc_j813_saved_ops = { + .begin = apple_smc_sleep_saved_begin, + .late_notice = apple_smc_sleep_after_peers, + .end = apple_smc_j813_saved_end, +}; + static int apple_smc_prepare_policy(struct apple_smc *smc) { const struct apple_sleep_smc_policy *p = smc->sleep_policy; @@ -1401,6 +1458,8 @@ static int apple_smc_sleep_prepare(struct apple_smc *smc) else apple_smc_sleep_warn(smc); + if (apple_sleep_smc_defer_notice()) + return apple_sleep_smc_register_saved(smc->dev, &apple_smc_j813_saved_ops, smc); return 0; } @@ -1514,6 +1573,9 @@ static int apple_smc_sleep_enter(struct apple_smc *smc) apple_smc_outbox_poll(smc, "late sleep warning", SMC_SLEEP_WARN_MS, 0); } + /* Warning and debug-link handling stay in noirq; only the notice moves. */ + if (apple_sleep_smc_defer_notice()) + return 0; return apple_smc_sleep_commit(smc); } @@ -1541,7 +1603,7 @@ static int apple_smc_resume_noirq(struct device *dev) if (smc->saved_enabled && (smc->saved_recovery || smc->saved_pending || smc->saved_fault)) return smc->saved_restore_error ?: smc->saved_fault ?: -EBUSY; - if (smc->saved_enabled && smc->sleep_policy) { + if (smc->saved_enabled && (smc->sleep_policy || smc->saved_wake)) { if (smc->saved_wake) { apple_smc_set_polled(smc, true); apple_smc_sleep_wake(smc); diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index 4a92376829020..5a16e6f7accf2 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -1757,6 +1757,18 @@ const struct apple_sleep_smc_policy *apple_sleep_smc_policy(void) } EXPORT_SYMBOL_GPL(apple_sleep_smc_policy); +static bool sleep_j813_smc_late = true; +module_param_named(j813_smc_late, sleep_j813_smc_late, bool, 0444); +MODULE_PARM_DESC(j813_smc_late, + "TEST ONLY: J813 final SMC sleep notice after peer stops"); + +bool apple_sleep_smc_defer_notice(void) +{ + return apple_sleep && READ_ONCE(sleep_j813_smc_late) && + of_machine_is_compatible("apple,j813") && pm_suspend_via_firmware(); +} +EXPORT_SYMBOL_GPL(apple_sleep_smc_defer_notice); + int apple_sleep_smc_register(struct device *dev, int (*late_notice)(void *data, u64 *sent, u64 *ack), void *data) { @@ -1781,8 +1793,8 @@ int apple_sleep_smc_register_saved(struct device *dev, struct apple_sleep *s = apple_sleep; guard(mutex)(&apple_sleep_smc_lock); - if (!s || !s->soc->early_context || !s->soc->smc_policy || - !pm_suspend_via_firmware()) + if (!s || ((!s->soc->early_context || !s->soc->smc_policy) && + !apple_sleep_smc_defer_notice()) || !pm_suspend_via_firmware()) return -EOPNOTSUPP; if (!ops || !ops->begin || !ops->late_notice || !ops->end || s->smc.dev) return -EBUSY; @@ -5743,11 +5755,12 @@ static void t8132_wake(struct apple_sleep *s) static int apple_sleep_smc_late_notice(struct apple_sleep *s) { - if (!s->soc->smc_policy) + if (!s->soc->smc_policy && !apple_sleep_smc_defer_notice()) return 0; if (!s->smc.dev || !s->smc.late_notice) return -ENODEV; - if (s->soc->early_context && (!s->smc.saved_ops || !s->smc.held)) + if ((s->soc->early_context || apple_sleep_smc_defer_notice()) && + (!s->smc.saved_ops || !s->smc.held)) return -EBUSY; return s->smc.late_notice(s->smc.data, &s->smc_idle_sent, &s->smc_idle_ack); } @@ -5936,6 +5949,14 @@ static int apple_sleep_enter(suspend_state_t state) if (s->soc->early_context) return apple_sleep_enter_early(s); + /* Refuse while all peer stops are still reversible. */ + if (apple_sleep_smc_defer_notice()) { + if (!s->smc.dev || !s->smc.late_notice) + return -ENODEV; + if (!s->smc.saved_ops || !s->smc.held) + return -EBUSY; + } + sleep_note(s, 0x10); ret = apple_sleep_refuse(s); if (ret) { @@ -6254,6 +6275,18 @@ static int apple_sleep_enter(suspend_state_t state) if (s->soc->ack_cluster_dcs && (readl(s->cluster_dcs) & CLUSTER_UP_DONE)) writel(readl(s->cluster_dcs), s->cluster_dcs); apple_sleep_coprocs_stop(s, false); + /* + * J813 native trace: ANS idle completes before SMC slpa/AP IDLE. + * In the battery failure SMC faulted at ANS + 0xc110 after ANS's + * idle ACK was missed. Keep its final notice behind the peer stops + * and ahead of the domain power-down in the last mile. + */ + if (apple_sleep_smc_defer_notice()) { + ret = apple_sleep_smc_late_notice(s); + dev_info(s->dev, "TEST: SMC notice after peer stops: %d\n", ret); + if (ret) + panic("J813 SMC notice failed after peer stops: %d", ret); + } /* Done by now unless no SMC driver is bound. */ apple_sleep_usb_down(s); s->deep_once = READ_ONCE(sleep_deep_requested); @@ -6529,7 +6562,8 @@ static int apple_sleep_smc_scope_begin(void) struct apple_sleep *s = apple_sleep; int ret = 0; - if (!s->soc->early_context || !s->soc->smc_policy) + if ((!s->soc->early_context || !s->soc->smc_policy) && + !apple_sleep_smc_defer_notice()) return 0; mutex_lock(&apple_sleep_smc_lock); if (!s->smc.saved_ops || !s->smc.dev) { @@ -6749,6 +6783,8 @@ static const struct platform_suspend_ops apple_sleep_ops = { .valid = apple_sleep_valid, .begin = apple_sleep_begin, .prepare = apple_sleep_prepare, + .prepare_late = apple_sleep_smc_scope_begin, + .finish = apple_sleep_smc_scope_end, .enter = apple_sleep_enter, .wake = apple_sleep_report, .end = apple_sleep_end, diff --git a/include/linux/soc/apple/sleep.h b/include/linux/soc/apple/sleep.h index 7174fc48459f3..cec1e88452676 100644 --- a/include/linux/soc/apple/sleep.h +++ b/include/linux/soc/apple/sleep.h @@ -38,6 +38,8 @@ struct apple_sleep_smc_saved_ops { #if IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) const struct apple_sleep_smc_policy *apple_sleep_smc_policy(void); +/* J813 experiment: send the final SMC notice after the peer idle handshakes. */ +bool apple_sleep_smc_defer_notice(void); int apple_sleep_smc_register(struct device *dev, int (*late_notice)(void *data, u64 *sent, u64 *ack), void *data); int apple_sleep_smc_register_saved(struct device *dev, @@ -241,6 +243,7 @@ void apple_sleep_restore_pins(void); int apple_sleep_engine_reset(struct device *dev); #else static inline const struct apple_sleep_smc_policy *apple_sleep_smc_policy(void) { return NULL; } +static inline bool apple_sleep_smc_defer_notice(void) { return false; } static inline int apple_sleep_smc_register(struct device *dev, int (*late_notice)(void *data, u64 *sent, u64 *ack), void *data) { return -EOPNOTSUPP; } static inline int apple_sleep_smc_register_saved(struct device *dev, From ebf68509039d8f8335575e1054f0df67bbc489c5 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 19:20:24 +0100 Subject: [PATCH 47/68] phy: apple: atc: restore T8142 PHY state after deep sleep T8142 loses its common PHY and PIPE state across a physical sleep outside genpd's normal transitions. Mark that loss at resume and use the existing baseline/mode restoration path before another controller or Type-C operation. Keep the dummy PHY enabled when parking so the next PIPE handoff has a producer after the boot state is lost. On J813, hot-plug after battery lid wakes timed out in PIPE parking and blocked later suspend during device prepare. With this change the hub and RTL8153 enumerate at USB3 speed after an empty-port deep sleep, establish Ethernet SSH, and pass another suspend preflight. A hub left attached across sleep also re-enumerates. Alpha Wi-Fi still aborts across some physical sleeps; this change does not address that failure. Signed-off-by: Thomas Glanzmann --- drivers/phy/apple/atc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index e8be316134872..4f52465ada959 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -7293,8 +7293,9 @@ static int atcphy_suspend_noirq(struct device *dev) */ static void atcphy_sleep_lost_common(struct apple_atcphy *atcphy) { - if (!atcphy->hw->has_t8140_dp || !atcphy->hw->restore_after_pd_off || - !pm_resume_via_firmware()) + if ((!atcphy->hw->has_t8140_dp && + !of_device_is_compatible(atcphy->np, "apple,t8142-atcphy")) || + !atcphy->hw->restore_after_pd_off || !pm_resume_via_firmware()) return; WRITE_ONCE(atcphy->pd_was_off, true); dev_dbg(atcphy->dev, "mode %d lost in the sleep: setting it up again\n", atcphy->mode); @@ -7870,6 +7871,8 @@ static const struct atcphy_hw atcphy_hw_t8142 = { .pipe_mux_clk = PIPEHANDLER_MUX_CTRL_CLK_T8142, .pipe_mux_data = PIPEHANDLER_MUX_CTRL_DATA_T8142, .has_usb4 = true, + .park_dummy_phy = true, + .restore_after_pd_off = true, }; static const struct of_device_id atcphy_match[] = { From 4cca392085a93e00dc7a334b6547458d9af1d97d Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 19:47:51 +0100 Subject: [PATCH 48/68] wifi: apple: centauri: quiesce Alpha for J813 system sleep J813 can resume with Alpha aborted and an immediate wifibt wake while the other devices recover. Send the disconnected host-power request before ACIPC host sleep, and restore ACIPC before the awake request. Match the installed firmware's event-filter limits. Pause ring traffic and background work across the transition and require acknowledgments before restarting producers. Keep the bring-up path behind apple_centauri.alpha_sleep_untested=1. Three cancelled preflights and four physical RTC cycles across two boots passed with active panel, M5 GPU, Bluetooth, Wi-Fi-bound traffic, USB Ethernet, CPUs and direct storage reads. The second boot never initialized the firmware logger. The complete source tree matches candidate 53e28baf350d. Signed-off-by: Thomas Glanzmann --- .../net/wireless/apple/centauri/centauri.h | 2 + .../wireless/apple/centauri/centauri_pci.c | 19 +- .../wireless/apple/centauri/centauri_wifi.c | 212 +++++++++++++++++- 3 files changed, 225 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/apple/centauri/centauri.h b/drivers/net/wireless/apple/centauri/centauri.h index 2ea9c2f7923b9..fa937c1c4e2e3 100644 --- a/drivers/net/wireless/apple/centauri/centauri.h +++ b/drivers/net/wireless/apple/centauri/centauri.h @@ -99,5 +99,7 @@ int centauri_alpha_resources(struct centauri *c, struct cen_alpha_resources *res int centauri_alpha_log_buffer(struct centauri *c, void **cpu, dma_addr_t *dma, size_t *size); int centauri_wifi_register(struct centauri *c); void centauri_wifi_unregister(struct centauri *c); +int centauri_wifi_suspend(struct centauri *c); +int centauri_wifi_resume(struct centauri *c); void centauri_wifi_kick(struct centauri *c); #endif diff --git a/drivers/net/wireless/apple/centauri/centauri_pci.c b/drivers/net/wireless/apple/centauri/centauri_pci.c index c44e22717f0b5..598671387565a 100644 --- a/drivers/net/wireless/apple/centauri/centauri_pci.c +++ b/drivers/net/wireless/apple/centauri/centauri_pci.c @@ -261,11 +261,26 @@ static void centauri_remove(struct pci_dev *pdev) */ static int centauri_suspend(struct device *dev) { + struct pci_dev *pdev = to_pci_dev(dev); + struct centauri *c = pci_get_drvdata(pdev); + int ret; + + ret = centauri_wifi_suspend(c); + if (ret) + return ret; device_set_awake_path(dev); - return pci_save_state(to_pci_dev(dev)); + ret = pci_save_state(pdev); + if (ret) + centauri_wifi_resume(c); + return ret; +} + +static int centauri_resume(struct device *dev) +{ + return centauri_wifi_resume(pci_get_drvdata(to_pci_dev(dev))); } -static DEFINE_SIMPLE_DEV_PM_OPS(centauri_pm_ops, centauri_suspend, NULL); +static DEFINE_SIMPLE_DEV_PM_OPS(centauri_pm_ops, centauri_suspend, centauri_resume); /* 0x1903 is the Beta (Bluetooth) function: btcentauri claims it. This driver needs functions * 0 and 1 (1 is enabled here, its BAR is used by the Wi-Fi code) and reaches function 2 only diff --git a/drivers/net/wireless/apple/centauri/centauri_wifi.c b/drivers/net/wireless/apple/centauri/centauri_wifi.c index 1246675e50e38..48d1deca69ab2 100644 --- a/drivers/net/wireless/apple/centauri/centauri_wifi.c +++ b/drivers/net/wireless/apple/centauri/centauri_wifi.c @@ -85,6 +85,10 @@ static bool station_link_addresses; module_param(station_link_addresses, bool, 0400); MODULE_PARM_DESC(station_link_addresses, "Diagnostic: use the netdev address for each firmware link in this single-link WPA2 client"); +static bool alpha_sleep_untested; +module_param(alpha_sleep_untested, bool, 0600); +MODULE_PARM_DESC(alpha_sleep_untested, "TEST ONLY: J813 Alpha host-power and ACIPC sleep handshake"); + struct centauri_rx_snapshot { __le32 version, count; struct { @@ -117,6 +121,7 @@ struct centauri_wifi { u32 reply_command, channels_seen, scans_done, beacons_seen; bool reply_valid, registered, configured; bool stopping; + bool transport_paused, transport_sleep_sent, host_sleep_sent; bool connecting, connected, connect_event, disconnect_event; bool associated, pmk_seen, pmk_matches; u8 expected_pmk[32]; @@ -217,6 +222,8 @@ static int alpha_message(struct centauri_wifi *wifi, const void *message, size_t u8 *descriptor; unsigned long deadline = jiffies + msecs_to_jiffies(2000); + if (READ_ONCE(wifi->transport_paused)) + return -EBUSY; if (head >= 15 || size > 512) return -ENOSPC; memcpy(wifi->a.messages + (head + 1) * 512, message, size); @@ -542,11 +549,13 @@ static void drain_data_tx(struct centauri_wifi *wifi) netif_wake_queue(wifi->netdev); } -static void drain(struct centauri_wifi *wifi) +static void drain_control(struct centauri_wifi *wifi, bool pm_command) { unsigned int ring; bool posted = false; + if (READ_ONCE(wifi->transport_paused) && !pm_command) + return; for (ring = 2; ring <= 4; ring++) { unsigned int budget = ring_size[ring]; @@ -714,16 +723,26 @@ static void drain(struct centauri_wifi *wifi) completions(wifi); if (posted) writel(1, wifi->a.bar + 0x1004); - drain_data_rx(wifi); - drain_data_tx(wifi); + if (!READ_ONCE(wifi->transport_paused)) { + drain_data_rx(wifi); + drain_data_tx(wifi); + } } -static int command(struct centauri_wifi *wifi, u32 id, const void *payload, size_t size) +static void drain(struct centauri_wifi *wifi) +{ + drain_control(wifi, false); +} + +static int command_control(struct centauri_wifi *wifi, u32 id, const void *payload, + size_t size, bool pm_command) { u16 slot = wifi->command_head, sequence = ++wifi->sequence; u8 *packet, *descriptor; unsigned long deadline = jiffies + msecs_to_jiffies(1500); + if (READ_ONCE(wifi->transport_paused) && !pm_command) + return -EBUSY; if (size + 24 > BUFFER_SIZE) return -EMSGSIZE; if ((slot + 1) % ring_size[1] == index_read(wifi, 1, 1)) @@ -746,7 +765,7 @@ static int command(struct centauri_wifi *wifi, u32 id, const void *payload, size dma_wmb(); writel(1, wifi->a.bar + 0x1004); do { - drain(wifi); + drain_control(wifi, pm_command); if (readl(wifi->a.bar + 8) != 2) return -EIO; /* Bit 30 is more-data-pending, not part of the command identity. @@ -766,6 +785,11 @@ static int command(struct centauri_wifi *wifi, u32 id, const void *payload, size return -ETIMEDOUT; } +static int command(struct centauri_wifi *wifi, u32 id, const void *payload, size_t size) +{ + return command_control(wifi, id, payload, size, false); +} + static int radio_start(struct centauri_wifi *wifi) { u8 start[5 + 4 + 3 * ETH_ALEN] = { 0, 0x0b, 0, 0, 0 }; @@ -1324,6 +1348,10 @@ static void link_worker(struct work_struct *work) bool disconnected; mutex_lock(&wifi->lock); + if (wifi->transport_paused) { + mutex_unlock(&wifi->lock); + return; + } drain(wifi); disconnected = wifi->disconnect_event || READ_ONCE(wifi->stopping) || readl(wifi->a.bar + 8) != 2; @@ -1345,7 +1373,8 @@ void centauri_wifi_kick(struct centauri *c) { struct centauri_wifi *wifi = READ_ONCE(c->wifi); - if (wifi && READ_ONCE(wifi->connected) && !READ_ONCE(wifi->stopping)) + if (wifi && READ_ONCE(wifi->connected) && !READ_ONCE(wifi->stopping) && + !READ_ONCE(wifi->transport_paused)) mod_delayed_work(system_percpu_wq, &wifi->link_work, 0); } @@ -1538,6 +1567,10 @@ static netdev_tx_t net_transmit(struct sk_buff *skb, struct net_device *netdev) { struct centauri_wifi *wifi = *(struct centauri_wifi **)netdev_priv(netdev); + if (READ_ONCE(wifi->transport_paused)) { + netif_stop_queue(netdev); + return NETDEV_TX_BUSY; + } if (READ_ONCE(wifi->stopping) || !READ_ONCE(wifi->connected) || skb->len < ETH_HLEN || skb->len > BUFFER_SIZE) { netdev->stats.tx_dropped++; @@ -1684,6 +1717,10 @@ static ssize_t fwlog_ack_write(struct file *file, const char __user *input, if (ret) return ret; mutex_lock(&wifi->fwlog_lock); + if (READ_ONCE(wifi->transport_paused)) { + ret = -EBUSY; + goto out; + } if (!wifi->fwlog_ready || readl(wifi->a.bar + 8) != 2) { ret = -ENETDOWN; goto out; @@ -1889,6 +1926,8 @@ static int transmit_eapol_start(struct centauri_wifi *wifi) u64 metadata = 0; unsigned int attempt; + if (READ_ONCE(wifi->transport_paused)) + return -EBUSY; if (readl(wifi->a.bar + 8) != 2 || !(wifi->data_probe_done & BIT(3))) return -ENETDOWN; /* Eight independent buffers bound the probe without ring reuse. */ @@ -2559,6 +2598,167 @@ int centauri_wifi_register(struct centauri *c) return ret; } +/* + * 26B123 t2026-CentauriAlpha uses BAR0 + 0x1024 for sleep_control. + * AirshipDK's ACIPC host-sleep handshake writes 3 and waits for status 3; + * wake writes 0 and waits for status 0 or 1. The peripheral-info block + * starts at context + 0x68, with sleep_status at +8, as on Beta. + * Stop every ring producer before requesting host sleep. Keep them stopped + * until the wake acknowledgment, including when suspend entry is refused. + */ +static u32 alpha_sleep_status(struct centauri_wifi *wifi) +{ + return le32_to_cpu(READ_ONCE(*(__le32 *)(wifi->a.context + 0x70))); +} + +static int alpha_transport_state(struct centauri_wifi *wifi, bool asleep) +{ + u32 status; + int ret; + + lockdep_assert_held(&wifi->lock); + if (readl(wifi->a.bar + 8) != 2 || readl(wifi->a.bar + 0xc) != 2) + return -EIO; + dma_wmb(); + writel(asleep ? 3 : 0, wifi->a.bar + 0x1024); + ret = read_poll_timeout(alpha_sleep_status, status, + (asleep ? status == 3 : status <= 1) || + readl(wifi->a.bar + 8) != 2, + 100, 2000000, false, wifi); + dma_rmb(); + if (readl(wifi->a.bar + 8) != 2) + ret = -EIO; + dev_info(&wifi->control->pdev->dev, + "TEST: Alpha ACIPC host %s: ret=%d status=%u exec=%u ipc=%u\n", + asleep ? "sleep" : "wake", ret, status, + readl(wifi->a.bar + 8), readl(wifi->a.bar + 0xc)); + return ret; +} + +/* + * WLANACIAdapter sends command 6 before ACIPC host sleep. For an interface + * already disconnected by cfg80211, its LPNA mode is firmware state 3. + * The first fields are le16 state and u8 hint. Native sleep also includes + * TLV 303 (value 1) and TLV 280 (the filtered event list); wake restores all + * events. Installed Alpha 48ef6696 rejects TLV 280 lengths >= 87 and + * event counts >= 86, so use its 85 events rather than 26B123's 91. + * The data-ring producers stay paused while this control command + * and its response use the command/management rings. + */ +static int alpha_host_power(struct centauri_wifi *wifi, bool asleep) +{ + static const u8 sleep_events[] = { 24, 26, 27, 15, 51, 8, 9, 10, 84 }; + u8 payload[98] = {}, events[86] = {}, sleep_option = 1; + size_t size = 3; + int i, ret; + + lockdep_assert_held(&wifi->lock); + if (readl(wifi->a.bar + 8) != 2) + return -EIO; + if (asleep) { + put_unaligned_le16(3, payload); + payload[2] = 3; + append_tlv(payload, &size, 303, &sleep_option, sizeof(sleep_option)); + events[0] = ARRAY_SIZE(sleep_events); + memcpy(events + 1, sleep_events, sizeof(sleep_events)); + } else { + events[0] = sizeof(events) - 1; + for (i = 0; i < events[0]; i++) + events[i + 1] = i; + } + append_tlv(payload, &size, 280, events, sizeof(events)); + ret = command_control(wifi, 6, payload, size, true); + dev_info(&wifi->control->pdev->dev, + "TEST: Alpha firmware host %s: ret=%d status=%u exec=%u\n", + asleep ? "LPNA" : "awake", ret, wifi->reply_status, + readl(wifi->a.bar + 8)); + return ret; +} + +static int alpha_resume_locked(struct centauri_wifi *wifi) +{ + int ret; + + lockdep_assert_held(&wifi->lock); + if (!wifi->transport_sleep_sent && !wifi->host_sleep_sent) + return 0; + if (wifi->transport_sleep_sent) { + ret = alpha_transport_state(wifi, false); + if (ret) + return ret; + wifi->transport_sleep_sent = false; + } + if (wifi->host_sleep_sent) { + ret = alpha_host_power(wifi, false); + if (ret) + return ret; + wifi->host_sleep_sent = false; + } + mutex_lock(&wifi->fwlog_lock); + WRITE_ONCE(wifi->transport_paused, false); + mutex_unlock(&wifi->fwlog_lock); + if (wifi->connected && !READ_ONCE(wifi->stopping)) { + if (netif_running(wifi->netdev)) + netif_wake_queue(wifi->netdev); + mod_delayed_work(system_percpu_wq, &wifi->link_work, 0); + } + return 0; +} + +int centauri_wifi_resume(struct centauri *c) +{ + struct centauri_wifi *wifi = c->wifi; + int ret; + + if (!wifi || !of_machine_is_compatible("apple,j813")) + return 0; + mutex_lock(&wifi->lock); + ret = alpha_resume_locked(wifi); + mutex_unlock(&wifi->lock); + return ret; +} + +int centauri_wifi_suspend(struct centauri *c) +{ + struct centauri_wifi *wifi = c->wifi; + int ret, restore; + + if (!wifi || !of_machine_is_compatible("apple,j813") || + !READ_ONCE(alpha_sleep_untested)) + return 0; + mutex_lock(&wifi->lock); + if (wifi->transport_paused || wifi->connected || wifi->connecting || wifi->scan_request || + READ_ONCE(wifi->stopping)) { + mutex_unlock(&wifi->lock); + return -EBUSY; + } + mutex_lock(&wifi->fwlog_lock); + WRITE_ONCE(wifi->transport_paused, true); + mutex_unlock(&wifi->fwlog_lock); + mutex_unlock(&wifi->lock); + netif_tx_disable(wifi->netdev); + cancel_work_sync(&wifi->scan_work); + cancel_work_sync(&wifi->connect_work); + cancel_delayed_work_sync(&wifi->link_work); + + mutex_lock(&wifi->lock); + wifi->host_sleep_sent = true; + ret = alpha_host_power(wifi, true); + if (!ret) { + wifi->transport_sleep_sent = true; + ret = alpha_transport_state(wifi, true); + } + if (ret) { + restore = alpha_resume_locked(wifi); + if (restore) + dev_err(&c->pdev->dev, + "Alpha transport remains paused after refused sleep: %d\n", + restore); + } + mutex_unlock(&wifi->lock); + return ret; +} + void centauri_wifi_unregister(struct centauri *c) { struct centauri_wifi *wifi = c->wifi; From c7a1f02cdca52a668940090b112028227e4e939e Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Thu, 5 Nov 2026 14:18:20 +0200 Subject: [PATCH 49/68] phy: apple: Enable the T8142 DisplayPort sequence Run the T8122 AUX, AUSPLL and lane sequences for T8142. Apply loader-supplied LIOA and common-configuration calibration before AUX, using separately claimed resources. Refuse DP without the complete calibration bundle. Serialize lane validation with Type-C mux setup so DCP sees lanes only after AUX is ready. No board identity or out-of-resource MMIO mapping is needed. Signed-off-by: Dmitriy (cherry picked from commit df6cd4a325ce5ee72820bf25432c9152e284bab4 in dmitzsaz/linux) Signed-off-by: Nick (cherry picked from commit 4e47750bab3edeb243b2d5f5a57b6e1897954591) --- drivers/phy/apple/atc.c | 64 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 4f52465ada959..cbce73d9c0d5c 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -688,6 +688,7 @@ struct apple_atcphy; * generation has none) and the SuperSpeed tunables; USB2 * still works without the latter * @park_pipe_unlocked: A stopped controller may park without a PIPE handshake + * @dp_banked_tunables: DisplayPort requires separate LIOA/common calibration * @dp_t8122: DisplayPort runs the T8122 AUX, AUSPLL and lane sequences * @park_dummy_phy: Enable the dummy PIPE backend whenever the PIPE is parked on * it; the lock handshake that starts the next PIPE change is @@ -715,6 +716,7 @@ struct atcphy_hw { bool optional_tunables; bool has_t8140_dp; bool dp_t8122; + bool dp_banked_tunables; bool park_pipe_unlocked; bool park_dummy_phy; bool restore_after_pd_off; @@ -865,6 +867,8 @@ struct apple_atcphy { struct apple_tunable *lane_usb4[2]; struct apple_tunable *usb2phy_reg_dflt; struct apple_tunable *usb3_dp; + struct apple_tunable *dp_lioa; + struct apple_tunable *dp_common_config; struct apple_tunable *dp_common_pre; struct apple_tunable *dp_lpdptx; struct apple_tunable *dp_common_post; @@ -977,11 +981,13 @@ struct apple_atcphy { void __iomem *pipehandler; void __iomem *lpdptx; void __iomem *pwrctl; + void __iomem *lioa; } regs; struct { struct resource *core; struct resource *lpdptx; + struct resource *lioa; struct resource *axi2af; struct resource *usb2phy_reg; } res; @@ -4176,7 +4182,8 @@ static int atcphy_configure(struct apple_atcphy *atcphy, enum atcphy_mode mode) if (ret) return ret; } - if (atcphy->hw->has_t8140_dp && atcphy_modes[mode].enable_dp_aux && + if ((atcphy->hw->has_t8140_dp || atcphy->hw->dp_banked_tunables) && + atcphy_modes[mode].enable_dp_aux && !atcphy->dp_tunables) return -EOPNOTSUPP; if (atcphy->hw->has_t8140_dp && @@ -4247,6 +4254,10 @@ static int atcphy_configure(struct apple_atcphy *atcphy, enum atcphy_mode mode) } atcphy_apply_tunables(atcphy, mode); + if (atcphy->hw->dp_banked_tunables && atcphy_modes[mode].enable_dp_aux) { + apple_tunable_apply(atcphy->regs.lioa, atcphy->tunables.dp_lioa); + apple_tunable_apply(atcphy->regs.lpdptx, atcphy->tunables.dp_common_config); + } atcphy->hw->configure_post_tunable(atcphy, mode); /* Setup AUX channel if DP altmode is requested */ @@ -4839,6 +4850,14 @@ static int atcphy_dpphy_validate(struct phy *phy, enum phy_mode mode, int submod if (submode != 0 && !atcphy_t8132_dp_on(atcphy)) return -EINVAL; + /* The Type-C mux owns lane setup; validate observes its completed epoch. */ + guard(mutex)(&atcphy->lock); + if (atcphy->hw->dp_t8122 && + (atcphy->mode_dirty || !atcphy->dp_t8122.aux)) { + opts->lanes = 0; + return 0; + } + switch (atcphy->mode) { case APPLE_ATCPHY_MODE_USB3_DP: opts->lanes = 2; @@ -6287,6 +6306,31 @@ static int atcphy_load_t8132_tunables(struct apple_atcphy *atcphy) return 0; } +static int atcphy_load_dp_banks(struct apple_atcphy *atcphy) +{ + struct apple_tunable *lioa, *common; + + lioa = devm_apple_tunable_parse(atcphy->dev, atcphy->np, + "apple,tunable-dp-lioa", atcphy->res.lioa); + common = devm_apple_tunable_parse(atcphy->dev, atcphy->np, + "apple,tunable-dp-common-config", atcphy->res.lpdptx); + if (IS_ERR(lioa) || IS_ERR(common)) { + int ret = IS_ERR(lioa) ? PTR_ERR(lioa) : PTR_ERR(common); + + if ((IS_ERR(lioa) && PTR_ERR(lioa) != -ENOENT) || + (IS_ERR(common) && PTR_ERR(common) != -ENOENT)) + return ret == -ENOENT ? PTR_ERR(common) : ret; + atcphy->dp_tunables = false; + dev_warn(atcphy->dev, "DisplayPort bank calibration missing; DP disabled\n"); + return 0; + } + if (!lioa->sz || !common->sz) + return -EINVAL; + atcphy->tunables.dp_lioa = lioa; + atcphy->tunables.dp_common_config = common; + return 0; +} + static int atcphy_load_tunables(struct apple_atcphy *atcphy) { size_t tunable_count; @@ -6399,6 +6443,12 @@ static int atcphy_load_tunables(struct apple_atcphy *atcphy) atcphy->ss_tunables = !ss_missing; if (atcphy->hw->dp_t8122) atcphy->dp_tunables = !common_missing; + if (atcphy->hw->dp_banked_tunables) { + int ret = atcphy_load_dp_banks(atcphy); + + if (ret) + return ret; + } if (atcphy->dp_only && !atcphy->dp_tunables) dev_warn(atcphy->dev, "Calibration tunables missing, DisplayPort disabled\n"); else if (ss_missing && atcphy->dp_tunables && !atcphy->dp_only) @@ -6484,6 +6534,16 @@ static int atcphy_map_resources(struct platform_device *pdev, struct apple_atcph *resources[i].res = res; } + if (atcphy->hw->dp_banked_tunables) { + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lioa"); + addr = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(addr)) + return dev_err_probe(atcphy->dev, PTR_ERR(addr), + "Unable to map LIOA bank\n"); + atcphy->res.lioa = res; + atcphy->regs.lioa = addr; + } + if (atcphy->hw->has_usb2phy_reg) { res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "usb2phy-reg"); addr = devm_ioremap_resource(&pdev->dev, res); @@ -7871,6 +7931,8 @@ static const struct atcphy_hw atcphy_hw_t8142 = { .pipe_mux_clk = PIPEHANDLER_MUX_CTRL_CLK_T8142, .pipe_mux_data = PIPEHANDLER_MUX_CTRL_DATA_T8142, .has_usb4 = true, + .dp_t8122 = true, + .dp_banked_tunables = true, .park_dummy_phy = true, .restore_after_pd_off = true, }; From b9d9d0981cfd014637e13125a0c884dc9b994d17 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Thu, 5 Nov 2026 14:18:20 +0200 Subject: [PATCH 50/68] phy: apple: Release the T8142 PIPE boot hold A port left at reset by the loader retains bit 16 of the nonselected PIPE override. The dummy backend cannot acknowledge its lock while this hold is asserted. Clear it before enabling that backend on T8142, including ports which the loader did not initialize. Signed-off-by: Dmitriy (cherry picked from commit def4169f38158d1a92640b69f672f35df5e1d180 in dmitzsaz/linux) Signed-off-by: Nick (cherry picked from commit 0db8f3786d6fbfba3896c36fff5d4742f08c6b67) --- drivers/phy/apple/atc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index cbce73d9c0d5c..7960077820129 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -531,6 +531,8 @@ enum atcphy_lane_mode { #define PIPEHANDLER_NONSELECTED_OVERRIDE 0x20 #define PIPEHANDLER_NATIVE_RESET BIT(12) #define PIPEHANDLER_DUMMY_PHY_EN BIT(15) +/* Boot-owned PIPE hold, released before selecting the dummy backend. */ +#define PIPEHANDLER_NONSELECTED_BOOT_HOLD BIT(16) #define PIPEHANDLER_NATIVE_POWER_DOWN GENMASK(3, 0) #define PIPEHANDLER_LOCK_ACK_TIMEOUT_US 1000 @@ -688,6 +690,7 @@ struct apple_atcphy; * generation has none) and the SuperSpeed tunables; USB2 * still works without the latter * @park_pipe_unlocked: A stopped controller may park without a PIPE handshake + * @clear_boot_hold: Release the boot PIPE hold before dummy backend selection * @dp_banked_tunables: DisplayPort requires separate LIOA/common calibration * @dp_t8122: DisplayPort runs the T8122 AUX, AUSPLL and lane sequences * @park_dummy_phy: Enable the dummy PIPE backend whenever the PIPE is parked on @@ -719,6 +722,7 @@ struct atcphy_hw { bool dp_banked_tunables; bool park_pipe_unlocked; bool park_dummy_phy; + bool clear_boot_hold; bool restore_after_pd_off; bool idle_power_off; }; @@ -1828,6 +1832,9 @@ static int atcphy_configure_pipehandler_usb4(struct apple_atcphy *atcphy) */ static void atcphy_enable_dummy_phy(struct apple_atcphy *atcphy) { + if (atcphy->hw->clear_boot_hold) + clear32(atcphy->regs.pipehandler + PIPEHANDLER_NONSELECTED_OVERRIDE, + PIPEHANDLER_NONSELECTED_BOOT_HOLD); set32(atcphy->regs.pipehandler + PIPEHANDLER_NONSELECTED_OVERRIDE, PIPEHANDLER_DUMMY_PHY_EN); } @@ -7935,6 +7942,7 @@ static const struct atcphy_hw atcphy_hw_t8142 = { .dp_banked_tunables = true, .park_dummy_phy = true, .restore_after_pd_off = true, + .clear_boot_hold = true, }; static const struct of_device_id atcphy_match[] = { From 333e620e59f935b5f90e173c106dfc5fcc7544f4 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 12 Nov 2026 23:34:32 +0700 Subject: [PATCH 51/68] phy: apple: atc: T8142: Keep USB without the DisplayPort LIOA bank A device tree written before DisplayPort was described has no "lioa" window. Probe as before then and leave DisplayPort off, instead of failing the probe and taking USB down with it. Signed-off-by: Nick (cherry picked from commit 7292f7d32db6af2168eaace726008b807bfdb15b) --- drivers/phy/apple/atc.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 7960077820129..e3d067addbaca 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -6317,6 +6317,11 @@ static int atcphy_load_dp_banks(struct apple_atcphy *atcphy) { struct apple_tunable *lioa, *common; + if (!atcphy->res.lioa) { + atcphy->dp_tunables = false; + return 0; + } + lioa = devm_apple_tunable_parse(atcphy->dev, atcphy->np, "apple,tunable-dp-lioa", atcphy->res.lioa); common = devm_apple_tunable_parse(atcphy->dev, atcphy->np, @@ -6541,8 +6546,13 @@ static int atcphy_map_resources(struct platform_device *pdev, struct apple_atcph *resources[i].res = res; } - if (atcphy->hw->dp_banked_tunables) { - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lioa"); + /* + * Device trees written before DisplayPort was supported have no LIOA + * bank: the PHY then serves USB as before, without DisplayPort. + */ + res = atcphy->hw->dp_banked_tunables ? + platform_get_resource_byname(pdev, IORESOURCE_MEM, "lioa") : NULL; + if (res) { addr = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(addr)) return dev_err_probe(atcphy->dev, PTR_ERR(addr), From a9e4d232d43ae40abf082d9b4813c4f866b94321 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 15 Nov 2026 21:06:50 +0100 Subject: [PATCH 52/68] phy: apple: atc: T8142: Serve a DP Alt Mode partner's USB without the DisplayPort calibration On T8142 the mode switch refuses every mode with DP AUX while the boot loader's LIOA and common configuration banks are missing ("DisplayPort bank calibration missing; DP disabled"). A partner in DP Alt Mode then loses its USB as well: on a J813 with a dock in pin assignment D, under a loader without the bank export, the PHY init fails with -EOPNOTSUPP and the port's dwc3 never probes, where the kernel before the T8142 DisplayPort sequence ran the dock's hub at 10 Gb/s. Map the DP modes to the USB the partner keeps, as T8132 does: USB2 next to four DP lanes (pin assignments C and E), USB3 next to two (D). Signed-off-by: Thomas Glanzmann (cherry picked from commit ca7da9d114f79b533e2bf33834876dbcf982d7c9) --- drivers/phy/apple/atc.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index e3d067addbaca..d1e36bbc48f96 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -5780,6 +5780,26 @@ static enum atcphy_mode atcphy_typec_target_mode(struct apple_atcphy *atcphy, } } + /* + * T8142 runs DisplayPort only with the boot loader's LIOA and common + * configuration banks, and the mode switch refuses a DP mode without + * them. Serve a DP Alt Mode partner's USB then, as on T8132: USB2 next + * to four DP lanes, USB3 next to two. + */ + if (atcphy->hw->dp_banked_tunables && !atcphy->dp_tunables) { + enum atcphy_mode usb_mode = target_mode; + + if (target_mode == APPLE_ATCPHY_MODE_DP) + usb_mode = APPLE_ATCPHY_MODE_USB2; + else if (target_mode == APPLE_ATCPHY_MODE_USB3_DP) + usb_mode = APPLE_ATCPHY_MODE_USB3; + if (usb_mode != target_mode) { + dev_warn(atcphy->dev, + "DisplayPort calibration missing: serving the partner's USB only\n"); + target_mode = usb_mode; + } + } + if (atcphy->hw->usb2_only && (!atcphy->t8132_ss || !atcphy->ss_tunables) && (target_mode == APPLE_ATCPHY_MODE_USB3 || target_mode == APPLE_ATCPHY_MODE_USB3_DP)) From 84a38495e97e2697bf45d5cf75caf2d0601348ac Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 20:13:34 +0100 Subject: [PATCH 53/68] phy: apple: align restored DisplayPort configuration Signed-off-by: Thomas Glanzmann --- drivers/phy/apple/atc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index d1e36bbc48f96..60611d22a1be4 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -4190,7 +4190,7 @@ static int atcphy_configure(struct apple_atcphy *atcphy, enum atcphy_mode mode) return ret; } if ((atcphy->hw->has_t8140_dp || atcphy->hw->dp_banked_tunables) && - atcphy_modes[mode].enable_dp_aux && + atcphy_modes[mode].enable_dp_aux && !atcphy->dp_tunables) return -EOPNOTSUPP; if (atcphy->hw->has_t8140_dp && @@ -6343,9 +6343,9 @@ static int atcphy_load_dp_banks(struct apple_atcphy *atcphy) } lioa = devm_apple_tunable_parse(atcphy->dev, atcphy->np, - "apple,tunable-dp-lioa", atcphy->res.lioa); + "apple,tunable-dp-lioa", atcphy->res.lioa); common = devm_apple_tunable_parse(atcphy->dev, atcphy->np, - "apple,tunable-dp-common-config", atcphy->res.lpdptx); + "apple,tunable-dp-common-config", atcphy->res.lpdptx); if (IS_ERR(lioa) || IS_ERR(common)) { int ret = IS_ERR(lioa) ? PTR_ERR(lioa) : PTR_ERR(common); From 0bd8665c033ae0cbb3b19e2dc25043c9e13c495a Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Thu, 5 Nov 2026 14:30:53 +0200 Subject: [PATCH 54/68] drm/apple: Order T8142 DPTX after Type-C PHY configuration Run a T8142 external processor's route admission in the fallible Type-C finish phase, after every supplier has applied its hardware state. DCP then observes completed AUX and lane setup without polling for PHY readiness. Release an unasserted DP-alt owner and leave a pin assignment with no sink unallocated, so the pipe can serve a display on another port. T8142's Type-C PHYs are of the T8122 generation and report no link configuration: give the crossbar their fixed pixel clock (PCLK1, 8b/10b) when DCP brings a link up. Based on dmitzsaz's J704 commit 3829b86b2749 ("drm/apple: Order T8142 DPTX after Type-C PHY configuration") and the crossbar clock of his dcp_direct_crossbar_link(), limited here to apple,t8142-dcpext so that the T6050 firmware 27 routes keep their order. Signed-off-by: Dmitriy Signed-off-by: Nick (cherry picked from commit 6973576e773f3866ff62868c3414709926e6acb1) --- drivers/gpu/drm/apple/dcp-fabric.c | 59 +++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index 824df5f341022..7d70a244bddb7 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.c +++ b/drivers/gpu/drm/apple/dcp-fabric.c @@ -1848,13 +1848,31 @@ static int dcp_typec_route_prepare(struct typec_mux_dev *mux, return 0; } +/* + * A T8142 external processor (firmware 27) behind a Type-C PHY of the T8122 + * generation: the firmware probes AUX as soon as its route is offered, so the + * route is applied only once the PHY has finished its own mode change. + */ +static bool dcp_t8142_ext(struct apple_dcp *dcp) +{ + return dcp->fw_compat == DCP_FIRMWARE_V_27_0 && + of_device_is_compatible(dcp->dev->of_node, "apple,t8142-dcpext"); +} + +static int dcp_typec_route_apply(struct typec_mux_dev *mux, + struct typec_mux_state *state); + static int dcp_typec_route_finish(struct typec_mux_dev *mux, struct typec_mux_state *state) { - struct apple_dcp_typec_port *port = - ((struct apple_dcp_typec_route *)typec_mux_get_drvdata(mux))->port; + struct apple_dcp_typec_route *route = typec_mux_get_drvdata(mux); + struct apple_dcp_typec_port *port = route->port; int ret; + /* Every provider's set phase (including the PHY) has completed. */ + if (dcp_t8142_ext(route->dcp) && state->mode != TYPEC_STATE_SAFE) + return dcp_typec_route_apply(mux, state); + guard(mutex)(&dcp_typec_fabric_lock); if (state->mode != TYPEC_STATE_SAFE || !port->safe_pending || port->safe_finish_ready) @@ -1911,7 +1929,7 @@ static int dcp_typec_port_busy(struct apple_dcp_typec_port *port, return -ENOSPC; } -static int dcp_typec_route_set(struct typec_mux_dev *mux, +static int dcp_typec_route_apply(struct typec_mux_dev *mux, struct typec_mux_state *state) { struct apple_dcp_typec_route *route = typec_mux_get_drvdata(mux); @@ -1997,7 +2015,8 @@ static int dcp_typec_route_set(struct typec_mux_dev *mux, * another port is refused as busy. The route is taken again * when HPD returns. */ - if (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP) { + if (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP || + dcp_t8142_ext(dcp)) { port->preferred_route = port->owner; port->hpd = false; /* @@ -2122,7 +2141,8 @@ static int dcp_typec_route_set(struct typec_mux_dev *mux, * would otherwise hold it against the port that has one. */ if (!port->owner && !hpd && - route->dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP) { + (route->dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP || + dcp_t8142_ext(route->dcp))) { port->applied_valid = true; return 0; } @@ -2190,6 +2210,16 @@ static int dcp_typec_route_set(struct typec_mux_dev *mux, return 0; } +static int dcp_typec_route_set(struct typec_mux_dev *mux, + struct typec_mux_state *state) +{ + struct apple_dcp_typec_route *route = typec_mux_get_drvdata(mux); + + if (dcp_t8142_ext(route->dcp) && state->mode != TYPEC_STATE_SAFE) + return 0; + return dcp_typec_route_apply(mux, state); +} + /* The T8142-layout crossbar (one per ATC on T6050) */ static bool dcp_xbar_t8142(struct mux_control *mux) { @@ -2535,6 +2565,25 @@ static int dcp_direct_crossbar_link_t6050(struct apple_dcp *dcp, bool up) * output's mux (or NULL on a Type-C-only pipeline). */ xbar = dcp->active_typec_route ? dcp->active_typec_route->active_xbar : dcp->xbar; + /* + * T8142's Type-C PHYs are of the T8122 generation and have no link + * report: they always drive PCLK1 with 8b/10b coding (as on the J704). + */ + if (dcp_t8142_ext(dcp)) { + if (dcp->dptx_tunnel || !xbar) + return 0; + if (!up) + return dcp_dpxbar_link(xbar, false); + configure = symbol_get(apple_dpxbar_link_configure); + if (!configure) + return -ENODEV; + ret = configure(xbar, 1, false); + symbol_put(apple_dpxbar_link_configure); + /* A link that is already up keeps its configuration. */ + if (ret == -EBUSY) + return 0; + return ret ? ret : dcp_dpxbar_link(xbar, true); + } if (dcp->dptx_tunnel || !dcp->phy || !xbar) return 0; get_config = symbol_get(apple_dp_phy_link_config); From 09ee6cfbf3ecf9ed04f99e274b6717f3abf8c3c5 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 15 Nov 2026 21:55:05 +0100 Subject: [PATCH 55/68] drm: apple: time the relink window from a Type-C CRTC's first enable A USB-C monitor plugged in while the outputs are off (a compositor's idle blanking) gets its link trained only when its CRTC is first enabled, possibly minutes later. On a J813, an EIZO EV2780 attached that way lost the link at that mode set: DCP logged "IOAVVideoInterface prepareLink() failed with 0xe0114100" and dropped the sink, which still asserted HPD and stayed attached in DP Alt Mode. The relink window had been opened at the attachment, 137 s earlier, and the CRTC had never been powered off, so the DPMS wake path did not open it again either. The display stayed dark until the cable was replugged; a replug with the outputs on brought it up at once. Time the window from that first enable as well, as dcp_dptx_connect() does for the attachment. Unlike a DPMS wake, it keeps the attachment's retries. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/dcp-fabric-test.c | 27 +++++++++++++++++++++++++ drivers/gpu/drm/apple/dcp.c | 12 +++++++++++ 2 files changed, 39 insertions(+) diff --git a/drivers/gpu/drm/apple/dcp-fabric-test.c b/drivers/gpu/drm/apple/dcp-fabric-test.c index c10c4a0e1e500..254b1bb74358d 100644 --- a/drivers/gpu/drm/apple/dcp-fabric-test.c +++ b/drivers/gpu/drm/apple/dcp-fabric-test.c @@ -2447,6 +2447,32 @@ static void relink_unplug_test(struct kunit *test) KUNIT_EXPECT_TRUE(test, dcp_relink_unplug(&s, 7, relink_ms(t, 62000))); } +/* + * A sink attached while the outputs were off gets its link trained at the + * CRTC's first enable, minutes later: the window starts there, and the + * attachment keeps its retries. + */ +static void relink_first_enable_test(struct kunit *test) +{ + unsigned long t = 100000; + struct dcp_relink_state s; + unsigned int i; + + relink_fresh(&s, 5, t); + KUNIT_EXPECT_FALSE(test, dcp_relink_unplug(&s, 5, relink_ms(t, 137000))); + dcp_relink_link_up(&s, 5, relink_ms(t, 135000)); + KUNIT_EXPECT_TRUE(test, dcp_relink_unplug(&s, 5, relink_ms(t, 137000))); + dcp_relink_end(&s); + + /* no fresh budget: unlike a DPMS wake, the enable does not reset it */ + for (i = s.tries; i < DCP_RELINK_RETRIES; i++) { + KUNIT_EXPECT_TRUE(test, dcp_relink_unplug(&s, 5, relink_ms(t, 137000))); + dcp_relink_end(&s); + } + dcp_relink_link_up(&s, 5, relink_ms(t, 200000)); + KUNIT_EXPECT_FALSE(test, dcp_relink_unplug(&s, 5, relink_ms(t, 201000))); +} + /* One relink at a time; the replay keeps the retries of its attachment. */ static void relink_running_test(struct kunit *test) { @@ -2623,6 +2649,7 @@ static struct kunit_case fabric_tests[] = { KUNIT_CASE(fabric_t8132_clock_refused_test), KUNIT_CASE(fabric_t6050_merged_limit_test), KUNIT_CASE(relink_unplug_test), + KUNIT_CASE(relink_first_enable_test), KUNIT_CASE(relink_running_test), KUNIT_CASE(relink_budget_test), KUNIT_CASE(relink_disabled_test), diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 0915ff0e0dbc0..0195b1ff547a6 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -4852,6 +4852,18 @@ void dcp_poweron(struct platform_device *pdev) dcp_relink_wake(&dcp->relink, READ_ONCE(dcp->typec_generation), jiffies); spin_unlock_irqrestore(&dcp->relink_lock, flags); + } else if (READ_ONCE(dcp->typec_cable_connected)) { + unsigned long flags; + + /* + * The first enable for a sink that was attached while the + * outputs were off: DCP trains its link only now. Time the + * relink window from here, keeping the attachment's retries. + */ + spin_lock_irqsave(&dcp->relink_lock, flags); + dcp_relink_link_up(&dcp->relink, + READ_ONCE(dcp->typec_generation), jiffies); + spin_unlock_irqrestore(&dcp->relink_lock, flags); } /* From 72300a29ff82fcc45f6c9a58b610269155e1ca09 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 15 Nov 2026 22:50:01 +0100 Subject: [PATCH 56/68] drm: apple: no bad link for the HPD of a Type-C CRTC enable A DPMS off of a Type-C output releases its DPTX session; the enable that follows reconnects it in dcp_poweron() before the mode set of the same commit. The HPD the firmware answers that reconnect with runs the hotplug worker while the mode is not set yet, and the worker reported the link bad and replayed the CRTC. wlroots answers a bad link by destroying the output, which disables the CRTC it was enabling; the next enable does the same, forever. On a J813 with an EIZO EV2780 on USB-C, every DPMS off and on ended in that loop: about three cycles a second ("connector DP-2: Bad link detected", "Destroying output 'DP-2'"), the display dark and the desktop sluggish, until the output was disabled or the cable pulled. Mark the CRTC enable as pending from dcp_poweron() until its mode set has run, and let the worker report a bad link, or replay the CRTC, only when no such enable and no mode set is in flight. A mode set that fails still ends in a bad link once the enable is done. Signed-off-by: Thomas Glanzmann (cherry picked from commit e6e28269f2a1ba9f75d688c0559574b05718c45a) --- drivers/gpu/drm/apple/apple_drv.c | 5 +++++ drivers/gpu/drm/apple/dcp-internal.h | 2 ++ drivers/gpu/drm/apple/iomfb.c | 9 +++++++++ 3 files changed, 16 insertions(+) diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index bd57a279537cb..b4f1c6f310c3e 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -393,6 +393,8 @@ static void apple_crtc_atomic_enable(struct drm_crtc *crtc, } if (crtc_state->active && (crtc_state->active_changed || dcp_crtc_needs_route_start(dcp))) { + /* The HPD of the link dcp_poweron() reconnects precedes our mode set. */ + WRITE_ONCE(dcp->typec_enable_pending, true); dcp_poweron(apple_crtc->dcp); crtc_state->color_mgmt_changed = true; } else if (crtc_state->active && drm_atomic_crtc_needs_modeset(crtc_state)) { @@ -404,6 +406,8 @@ static void apple_crtc_atomic_enable(struct drm_crtc *crtc, if (ret) dcp_drm_crtc_error(apple_crtc, crtc_state, ret); } + /* The mode set of the enable has run: a sink still without one has a bad link. */ + WRITE_ONCE(dcp->typec_enable_pending, false); dcp_typec_follow_done(locked); return; @@ -414,6 +418,7 @@ static void apple_crtc_atomic_enable(struct drm_crtc *crtc, dev_err(dcp->dev, "CRTC route unavailable (%d); modeset deferred\n", ret); /* Flush completes any pending flip without issuing a firmware swap. */ schedule_work(&dcp->vblank_wq); + WRITE_ONCE(dcp->typec_enable_pending, false); if (dcp->connector) dcp_route_failure_notify(dcp->connector); dcp_typec_follow_done(locked); diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 9265aeab32297..08f911d9122f3 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -986,6 +986,8 @@ struct apple_dcp { u64 typec_follow_gen; /* dcp_poweron() reconnects DPTX; its own modeset follows the HPD */ bool typec_poweron_hpd; + /* A Type-C CRTC enable runs: its own mode set follows, the link is not bad */ + bool typec_enable_pending; /* IOMFB reports its video interface ready after DPTX link training. */ struct completion typec_iomfb_hpd_ready; struct delayed_work typec_reconnect_wq; diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 3b41359bba82e..20dba0bc030d8 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -1964,6 +1964,15 @@ void dcp_hotplug(struct work_struct *work) * again, and that wake does the same, forever. */ !READ_ONCE(dcp->typec_crtc_off) && + /* + * Nor while a Type-C CRTC enable runs: dcp_poweron() reconnects + * the link, and the HPD that answers it comes before the mode + * set of that enable, not after a failed one. A bad link there + * makes wlroots destroy the output it is enabling, which + * disables the CRTC, and the next enable does the same, forever. + */ + !READ_ONCE(dcp->typec_enable_pending) && + !READ_ONCE(dcp->mode_state.changing) && (!dcp_uses_t6020_tunnel_flow(dcp) || dcp->tunnel_power_cycles < DCP_TUNNEL_POWER_CYCLES)) { bool power_cycle = dcp_uses_t6020_tunnel_flow(dcp); From f643266a089bcdf3f433bd70a8ee10eff330e59b Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 20:25:00 +0100 Subject: [PATCH 57/68] drm/apple: align restored Type-C route declaration Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/dcp-fabric.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index 7d70a244bddb7..1d728692af959 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.c +++ b/drivers/gpu/drm/apple/dcp-fabric.c @@ -1930,7 +1930,7 @@ static int dcp_typec_port_busy(struct apple_dcp_typec_port *port, } static int dcp_typec_route_apply(struct typec_mux_dev *mux, - struct typec_mux_state *state) + struct typec_mux_state *state) { struct apple_dcp_typec_route *route = typec_mux_get_drvdata(mux); struct apple_dcp_typec_port *port = route->port; From 70c324a8c1d03277ab6cddab680364424d1810c6 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 20:33:11 +0100 Subject: [PATCH 58/68] selftests: apple-dcp: accommodate the restored T8142 DP path Carry banked calibration fields in the PHY fixtures, observe the two calibration-bank dispatches in the existing profile test, and keep route transaction tests on the complete production apply body. Supply the opaque sleep-layout pointer used by the resource-profile fixture. All 88 host groups pass. Signed-off-by: Thomas Glanzmann --- .../drivers/gpu/apple-dcp/dwc3/mocks.c | 15 +++++++++-- .../drivers/gpu/apple-dcp/lifecycle.py | 3 +++ .../selftests/drivers/gpu/apple-dcp/phy.py | 25 +++++++++++++------ .../drivers/gpu/apple-dcp/quiesce.py | 4 +++ .../drivers/gpu/apple-dcp/transaction.py | 9 ++++++- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c index d7563f0a4e12f..3be2f84033008 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c @@ -8,11 +8,13 @@ struct apple_atcphy { struct { bool prepared; } cio_sleep; - struct { void *usb3_dp; } tunables; + struct { + void *usb3_dp, *dp_lioa, *dp_common_config; + } tunables; const struct atcphy_hw *hw; struct { - unsigned char *core, *lpdptx, *pipehandler, *usb2phy; + unsigned char *core, *lpdptx, *lioa, *pipehandler, *usb2phy; } regs; struct reset_controller_dev rcdev; void *dev; @@ -260,6 +262,15 @@ static void atcphy_usb2_power_on(struct apple_atcphy *p) { (void)p; } + +/* This teardown fixture never selects T8142 DP calibration. */ +static void apple_tunable_apply(void *base, void *tunable) +{ + (void)base; + (void)tunable; + assert(!"unexpected banked DP calibration"); +} + static void atcphy_apply_tunables(struct apple_atcphy *p, enum atcphy_mode m) { (void)p; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py index 9158eefe767f8..e6b520616ad9f 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py @@ -1221,7 +1221,10 @@ 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)) +/* Resource-profile tests carry, but never dereference, the sleep layout. */ +static const unsigned dcp_s2r_t8140; struct apple_dcp_hw_data { + const void *s2r_layout; unsigned num_dptx_ports; bool adopt_live_session; int iomfb_method_profile,firmware_compat; const struct resource *firmware_clock; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py b/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py index 7998abe4b8ac9..26c0f62dabb25 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py @@ -37,12 +37,12 @@ def function(source, name): bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; /* A CIO sleep is T8132's too, covered by tools/asahi/atc-cio-sleep-tests.py. */ struct { bool prepared; } cio_sleep; - struct { void *usb3_dp; } tunables; + struct { void *usb3_dp, *dp_lioa, *dp_common_config; } tunables; /* A sleep took the USB host's domains down; never set here. */ bool sleep_dead; const struct atcphy_hw *hw; - struct { unsigned char *core, *lpdptx, *pipehandler, *usb2phy; } regs; + struct { unsigned char *core, *lpdptx, *lioa, *pipehandler, *usb2phy; } regs; struct reset_controller_dev rcdev; void *dev; int lock, dp_link_rate; @@ -135,6 +135,10 @@ def function(source, name): #define readl_poll_timeout readl_poll_timeout_atomic /* Observation is read-only and separately tested; retain production caller control flow. */ static void atcphy_usb2_power_on(struct apple_atcphy *p) { (void)p; usb2_on++; } +/* Calibration writes are leaves; the profile test checks their dispatch. */ +static unsigned int dp_bank_writes; +static void apple_tunable_apply(void *base, void *tunable) +{ (void)base; (void)tunable; dp_bank_writes++; } static void atcphy_apply_tunables(struct apple_atcphy *p, enum atcphy_mode mode) { (void)p; (void)mode; } static void atc_tunnel_stop_t8103(struct apple_atcphy *p) { (void)p; } @@ -1237,13 +1241,15 @@ def adverse(root): for (unsigned int m=0; mdp_banked_tunables && atcphy_modes[modes[m]].enable_dp_aux ? 2U : 0U)); for (unsigned int i=before; i=1; - if(gen==1 && !usb3) assert(p.dp_t8122.aux && atc_t8122_dp_aux_is_on(p.regs.core)); + if(p.hw->dp_t8122 && !usb3) assert(p.dp_t8122.aux && atc_t8122_dp_aux_is_on(p.regs.core)); assert(rcal==wake); assert(!!(registers[AUS_COMMON_SHIM_BLK_BIAS_REG/4]&AUS_COMMON_SHIM_BLK_BIAS_REG_BGBIAS_OV)==wake); assert(!!(registers[ACIOPHY_SLEEP_CTRL/4]&ACIOPHY_SLEEP_CTRL_TX_CLAMP_OV)==(gen==0)); @@ -1933,7 +1939,7 @@ def function(name): bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; /* A CIO sleep is T8132's too, covered by tools/asahi/atc-cio-sleep-tests.py. */ struct { bool prepared; } cio_sleep; - struct { void *usb3_dp; } tunables; + struct { void *usb3_dp, *dp_lioa, *dp_common_config; } tunables; bool dp_only, pd_was_off, tunnel_clock_on; unsigned int tunnel_rate, tunnel_users; @@ -2333,13 +2339,13 @@ def function(source, name): bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; /* A CIO sleep is T8132's too, covered by tools/asahi/atc-cio-sleep-tests.py. */ struct { bool prepared; } cio_sleep; - struct { void *usb3_dp; } tunables; + struct { void *usb3_dp, *dp_lioa, *dp_common_config; } tunables; bool dp_only, pd_was_off, tunnel_clock_on; unsigned int tunnel_rate, tunnel_users; struct { bool aux, pll; unsigned int pairs, rate; } dp_t8122; const struct atcphy_hw *hw; - struct { unsigned char *core, *lpdptx; } regs; + struct { unsigned char *core, *lpdptx, *lioa; } regs; void *dev; int lock, dp_link_rate; bool fixed_usb2, host_active, swap_lanes, ss_tunables, dp_tunables; @@ -2394,6 +2400,9 @@ def function(source, name): polls == fail_poll || !(condition) ? -ETIMEDOUT : 0; }) #define readl_poll_timeout readl_poll_timeout_atomic static void atcphy_usb2_power_on(struct apple_atcphy *p) { (void)p; usb2_on++; } +/* These ownership fixtures have no T8142 DP calibration banks. */ +static void apple_tunable_apply(void *base, void *tunable) +{ (void)base; (void)tunable; assert(!"unexpected banked DP calibration"); } static void atcphy_apply_tunables(struct apple_atcphy *p, enum atcphy_mode mode) { (void)p; (void)mode; } static void atc_tunnel_stop_t8103(struct apple_atcphy *p) { (void)p; } @@ -2655,7 +2664,7 @@ def aux(root): bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; /* A CIO sleep is T8132's too, covered by tools/asahi/atc-cio-sleep-tests.py. */ struct { bool prepared; } cio_sleep; - struct { void *usb3_dp; } tunables; + struct { void *usb3_dp, *dp_lioa, *dp_common_config; } tunables; bool dp_only, pd_was_off, tunnel_clock_on; unsigned int tunnel_rate, tunnel_users; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py b/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py index b36cb733ddd2e..1e76f00a37f63 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py @@ -77,6 +77,10 @@ def make_unit(source, parent=False, reference=None): static void ordinary_initial(void); static void ordinary_usb2_check(void); static void event(char c) { assert(count+1external; } static int dcp_dptx_disconnect_oob(void *dev,u32 index) { (void)dev;assert(index==0);event('Q');stops++;if(power_error){display.external_error=power_error;return power_error;}display.external_cable=false;display.external_stopped=true;display.dptxport[0].connected=false;display.typec_cable_connected=false;connector.connected=false;return 0; } static struct drm_device *dcp_typec_drm(void) { return NULL; } diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py b/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py index 999c47798d776..a9e39ff314acb 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py @@ -163,7 +163,14 @@ def check(name, unit, cases=((),), negative=False, flags=()): pos=actual.index('static struct typec_mux_dev phy_provider') # route_set asks whether a tunnel holds any of the port's slots: the real helper. tunneled='#ifndef ARRAY_SIZE\n#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))\n#endif\n'+apple_function(ROOT,'dcp_typec_port_tunneled') - actual=actual[:pos]+tunneled+block(dcp,'static bool dcp_typec_route_is_dp(')+'\n'+block(dcp,'static int dcp_typec_route_set(')+'\n'+actual[pos:] + route_apply=apple_function(ROOT,'dcp_typec_route_apply') + if route_apply: + # The ordinary SAFE fixture supplies a leaf for the T8142-only finish + # path. Here set must execute the complete production apply body too. + stub=block(actual,'static int dcp_typec_route_apply(') + actual=actual.replace(stub, 'static int dcp_typec_route_apply(struct typec_mux_dev *,struct typec_mux_state *);', 1) + pos=actual.index('static struct typec_mux_dev phy_provider') + actual=actual[:pos]+tunneled+block(dcp,'static bool dcp_typec_route_is_dp(')+'\n'+route_apply+block(dcp,'static int dcp_typec_route_set(')+'\n'+actual[pos:] actual=actual.replace(block(actual,'static int display_set('),'''static int display_set(struct typec_mux_dev *m,struct typec_mux_state *s) { event('S');return dcp_typec_route_set(m,s); }''',1) actual=actual.replace("(void)m;assert(s->mode==TYPEC_STATE_SAFE);event('L');", "(void)m;(void)s;event('L');",1) actual=actual.replace('connector=(struct connector){.connected=true};','connector=(struct connector){.connected=true};',1) From 03403eb0144a1defbc88c71c767807aec57d8096 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 21:19:38 +0100 Subject: [PATCH 59/68] phy: apple: restore USB2 when restarting beside DisplayPort Reset assertion stops the USB2 PHY even when USB3 shutdown preserves an active DisplayPort mode. If suspend is refused before the power domain cycles, USB2 init sees that mode still active and skips configuration. The controller then starts without its USB2 PHY clock and xHCI reset times out, losing both of a monitor's USB hubs. Restore USB2 during init when its control register says it is stopped. Leave an already running PHY alone and preserve the DP/common state and the existing host role. Exercise the production teardown and restart functions with retained DP. The regression checks USB2 running again, unchanged DP AUX/PLL/common state and host role, and repeated-init idempotence. Removing the restore makes its RUN assertion fail. Update the quiesce fixture's MMIO stubs. On J813 with an EIZO attached, an immediate suspend after loading SEP reproduces the early -EBUSY refusal. Both hubs now return without xHCI timeouts. The subsequent no-commit preflight and 8 s / 20 s physical sleeps retain both displays, USB, GPU, Wi-Fi, Bluetooth and storage. LLVM 22 build, all 88 display host groups and strict checkpatch pass. Signed-off-by: Thomas Glanzmann --- drivers/phy/apple/atc.c | 8 ++++ .../drivers/gpu/apple-dcp/dwc3/cases.c | 37 +++++++++++++++++++ .../drivers/gpu/apple-dcp/dwc3/mocks.c | 6 ++- .../drivers/gpu/apple-dcp/quiesce.py | 7 ++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 60611d22a1be4..34d3aa12b8f4c 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -4554,6 +4554,14 @@ static int atcphy_usb2_init(struct phy *phy) if (!atcphy->fixed_usb2) { if (atcphy->mode == APPLE_ATCPHY_MODE_OFF || atcphy->mode_dirty) return atcphy_configure(atcphy, atcphy->typec_mode); + /* + * Reset assertion stops USB2 even when a DisplayPort mode keeps + * the common block running. An aborted suspend need not produce + * a new mux event: restore USB2 without disturbing the DP link. + */ + if ((readl(atcphy->regs.usb2phy + USB2PHY_USBCTL) & + USB2PHY_USBCTL_USB_MODE) != USB2PHY_USBCTL_RUN) + atcphy_usb2_power_on(atcphy); return 0; } diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/cases.c b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/cases.c index 00f670245e7a5..70cd7d36bd211 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/cases.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/cases.c @@ -473,6 +473,42 @@ static void legacy_restore(void) } puts("PASS: M1/M2/J700 aborted shutdown blocks PIPE and restores saved lane mode"); } + +/* A cancelled sleep restarts USB beside a DP link that never powered down. */ +static void retained_dp_restart(void) +{ + struct fixture f; + u32 power; + unsigned int before; + + initial(&f, 1, false, false); + f.atc.mode = APPLE_ATCPHY_MODE_USB3_DP; + f.atc.typec_mode = APPLE_ATCPHY_MODE_USB3_DP; + f.atc.dp_t8122.aux = true; + f.atc.dp_t8122.pll = true; + usb2_regs[USB2PHY_USBCTL / 4] = USB2PHY_USBCTL_RUN; + usb2_regs[USB2PHY_SIG / 4] = USB2PHY_SIG_HOST; + power = core_regs[ATCPHY_POWER_CTRL / 4]; + before = usb2_starts; + + assert(exit_apple(&f) == 0); + assert(f.atc.mode == APPLE_ATCPHY_MODE_USB3_DP); + assert(!(usb2_regs[USB2PHY_USBCTL / 4] & USB2PHY_USBCTL_RUN)); + assert(core_regs[ATCPHY_POWER_CTRL / 4] == power); + assert(role(&f, USB_ROLE_HOST) == 0); + assert(usb2_regs[USB2PHY_USBCTL / 4] == USB2PHY_USBCTL_RUN); + assert(usb2_starts == before + 1); + assert(usb2_regs[USB2PHY_SIG / 4] == USB2PHY_SIG_HOST); + assert(f.atc.mode == APPLE_ATCPHY_MODE_USB3_DP); + assert(f.atc.dp_t8122.aux && f.atc.dp_t8122.pll); + assert(core_regs[ATCPHY_POWER_CTRL / 4] == power); + assert(atcphy_usb2_init(&f.p2) == 0 && usb2_starts == before + 1); + assert(exit_apple(&f) == 0); + assert(!f.p2.init_count && !f.p2.power_count); + assert(!f.p3.init_count && !f.p3.power_count); + puts("PASS: USB2 returns beside retained DisplayPort without a mux event"); +} + static void removal_and_generic(void) { struct fixture f; @@ -532,6 +568,7 @@ int main(int argc, char **argv) partial_release(); init_failures(); legacy_restore(); + retained_dp_restart(); removal_and_generic(); tunnel_role(); puts("PASS: Apple teardown actual-function qualification"); diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c index 3be2f84033008..2461f130fa7f1 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c @@ -257,10 +257,12 @@ static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8132( { (void)p; assert(false); return -EOPNOTSUPP; } -/* USB2 power-on is outside this teardown/recovery control. */ +/* Model the USB2 power-on boundary's running state. */ +static unsigned int usb2_starts; static void atcphy_usb2_power_on(struct apple_atcphy *p) { - (void)p; + usb2_starts++; + writel(USB2PHY_USBCTL_RUN, p->regs.usb2phy + USB2PHY_USBCTL); } /* This teardown fixture never selects T8142 DP calibration. */ diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py b/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py index 1e76f00a37f63..46c5bf457d02f 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py @@ -168,6 +168,9 @@ def make_unit(source, parent=False, reference=None): #define phy_get_drvdata(p) ((p)->data) #define USB2PHY_SIG 0 #define USB2PHY_SIG_HOST 1 +USB2_RUN_DEFINES +/* Retained USB2 power is exercised by dwc3-teardown, not these role removals. */ +static u32 readl(void *p) { (void)p;assert(false);return 0; } static struct { enum atcphy_pipehandler_state pipehandler_state; bool enable_dp_aux; } atcphy_modes[7]; static struct apple_atcphy ordinary_phy; static struct phy usb_phy={.data=&ordinary_phy}; @@ -204,6 +207,10 @@ def make_unit(source, parent=False, reference=None): ''' # The ordinary port is the T8122 profile unless a case selects the T8103 # generation, whose live legacy PIPE park the mux switch now consults. + ordinary_phy=ordinary_phy.replace('USB2_RUN_DEFINES', '\n'.join( + line for line in atc.splitlines() + if line.startswith(('#define USB2PHY_USBCTL ', '#define USB2PHY_USBCTL_USB_MODE ', + '#define USB2PHY_USBCTL_RUN ')))) generation='enum atcphy_generation {' in atc ordinary_phy=ordinary_phy.replace('GENERATION_ENUM\n',block(atc,'enum atcphy_generation {')+';\n' if generation else '',1) ordinary_phy=ordinary_phy.replace('GENERATION_FIELD ','enum atcphy_generation gen; ' if generation else '',1) From 23fd8932fd7ddd6804edd840d25e9d4eff63daaa Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 21:36:17 +0100 Subject: [PATCH 60/68] usb: dwc3: apple: keep the T8142 USB3 PHY awake in host mode The EIZO's USB3 hub enumerates on J813, then fails its first runtime resume: usbfs open returns -ENODEV and the hub disconnects and gets a new device number. Repeating the access reproduces it; preventing autosuspend for the newly enumerated hub avoids the failure. Apply the existing T8132 host policy to T8142: allow SUSPHY during the PIPE setup, then keep the PHY out of P3 while the host runs. USB runtime autosuspend remains enabled, including the hub's normal zero-delay policy. Host teardown restores the DT SUSPHY setting before returning the PIPE, and deep sleep still stops the controller. With this change, five idle/resume rounds observe the hub suspended and then successfully read its descriptor, configuration and status, without re-enumeration. Both USB hubs and DP-2 come up automatically at boot. Immediate SEP refusal, full preflight, and 8 s / 20 s deep sleep cycles preserve both displays, USB control transfers, GPU, Wi-Fi, Bluetooth and storage. LLVM 22 and all 88 display host groups pass; strict checkpatch is clean. Signed-off-by: Thomas Glanzmann --- drivers/usb/dwc3/dwc3-apple.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index 7b1004854107a..ff7bc15356c7c 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -953,10 +953,11 @@ static int dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_stat } dev_warn(appledwc->dev, "USB3 PHY setup failed, USB2 only, err=%d\n", ret); } else if (host && appledwc->usb3_phy && - of_device_is_compatible(appledwc->dev->of_node, "apple,t8132-dwc3")) { + (of_device_is_compatible(appledwc->dev->of_node, "apple,t8132-dwc3") || + of_device_is_compatible(appledwc->dev->of_node, "apple,t8142-dwc3"))) { /* - * The T8132 PHY does not bring a SuperSpeed link back from U3 once - * the core has suspended it: keep it out of P3 from here on. + * These PHYs do not bring a SuperSpeed link back from U3 once + * the core has suspended them: keep them out of P3 from here on. */ appledwc->dwc.dis_u3_susphy_quirk = true; dwc3_enable_susphy(&appledwc->dwc, true); From 5d575d2d8544649bbd2dbd2fa2ac8f94a4f35631 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 21:56:02 +0100 Subject: [PATCH 61/68] dt-bindings: display: apple,dcp: describe T8142 external clocks The J813 external display nodes use apple,t8142-dcpext with the generic apple,dcpext fallback. Like the internal T8142 DCP, they supply the two firmware provider clocks after clock-154. Describe the compatible and apply the T8142 clock constraints to both controllers. The binding example and the J813/J815 device trees pass focused schema validation. This changes documentation only. Signed-off-by: Thomas Glanzmann --- Documentation/devicetree/bindings/display/apple,dcp.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index 680fc93ef2e5d..5a0af16a2ba99 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp.yaml @@ -36,6 +36,7 @@ properties: - apple,t6020-dcpext - apple,t6041-dcpext - apple,t6050-dcpext + - apple,t8142-dcpext - const: apple,dcpext - items: - const: apple,t8140-dcpext @@ -604,7 +605,8 @@ allOf: properties: compatible: contains: - enum: ['apple,t6050-dcp', 'apple,t6050-dcpext', 'apple,t8142-dcp'] + enum: ['apple,t6050-dcp', 'apple,t6050-dcpext', + 'apple,t8142-dcp', 'apple,t8142-dcpext'] then: properties: clocks: @@ -622,7 +624,7 @@ allOf: properties: compatible: contains: - const: apple,t8142-dcp + enum: ['apple,t8142-dcp', 'apple,t8142-dcpext'] then: properties: clocks: From 55deafc108977fa2557ed97e13fd7deb6423bc14 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 21:56:03 +0100 Subject: [PATCH 62/68] dt-bindings: soc: apple: complete the T8142 sleep resources The T8142 sleep nodes gained the PMGR clock slots and four AMCC control windows for wake restoration, but the schema still stopped at the old 36 registers. Describe the five trailing resources while preserving the older minimum, matching the driver's optional mapping of them. Give apple,radio-perst an explicit phandle-array type and describe its GPIO specifier. Its name does not use the standard GPIO suffix from which the schema tooling could infer the type. Binding checks and focused validation of J813/J815 pass without diagnostics. This changes documentation only. Signed-off-by: Thomas Glanzmann --- .../bindings/soc/apple/apple,t8140-sleep.yaml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml index dfbeede4111a6..25228d7c80251 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml @@ -25,11 +25,11 @@ properties: reg: minItems: 25 - maxItems: 36 + maxItems: 41 reg-names: minItems: 25 - maxItems: 36 + maxItems: 41 apple,wake-enable: $ref: /schemas/types.yaml#/definitions/uint32-array @@ -83,7 +83,12 @@ properties: the wake. apple,radio-perst: - maxItems: 1 + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + - items: + - description: Phandle of the radio GPIO controller. + - description: Pin number. + - description: GPIO flags. description: The GPIO that drives the radio's PERST#, held across that retraining. @@ -192,8 +197,9 @@ allOf: properties: reg: minItems: 36 - maxItems: 36 + maxItems: 41 reg-names: + minItems: 36 items: - const: ps - const: pwrgate @@ -231,6 +237,11 @@ allOf: - const: mcc6 - const: mcc7 - const: mem-clk + - const: clk-slots + - const: amcc-cfg0 + - const: amcc-cfg1 + - const: amcc-cfg2 + - const: amcc-cfg3 - if: not: properties: From 3e9921638c734edf92fde988f64fe60be933daf5 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 22:02:46 +0100 Subject: [PATCH 63/68] dt-bindings: phy: apple,atcphy: describe T8142 DisplayPort banks The T8142 DisplayPort path adds a LIOA resource after the original five PHY banks and consumes separate LIOA and common-configuration tunables. Describe that layout and both calibration properties. Keep the original five-bank USB-only layout valid, require at least those five banks on T8142, and retain the other SoCs' resource limits. The binding examples and the J813/J815 PHY nodes pass schema validation. The new properties also validate in the bootloader-populated live tree. This changes documentation only. Signed-off-by: Thomas Glanzmann --- .../devicetree/bindings/phy/apple,atcphy.yaml | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Documentation/devicetree/bindings/phy/apple,atcphy.yaml b/Documentation/devicetree/bindings/phy/apple,atcphy.yaml index 6aeff7fff911e..41ecaccc8a0ae 100644 --- a/Documentation/devicetree/bindings/phy/apple,atcphy.yaml +++ b/Documentation/devicetree/bindings/phy/apple,atcphy.yaml @@ -36,6 +36,10 @@ description: > display crossbar is not part of the PHY resource. SuperSpeed calibration is supplied in banked lists so that no list spans that crossbar. + The T8142 variant adds an optional LIOA bank for DisplayPort calibration. + DisplayPort also requires separate bootloader-provided calibration lists + for that bank and the common configuration in the lpdptx region. + allOf: - $ref: /schemas/usb/usb-switch.yaml# - if: @@ -46,6 +50,7 @@ allOf: - apple,t8122-atcphy - apple,t6030-atcphy - apple,t6031-atcphy + - apple,t8142-atcphy then: properties: reg: @@ -56,6 +61,7 @@ allOf: - description: AXI to Apple Fabric interface - description: USB2 PHY - description: USB3 PIPE interface + - description: Local IO address translation controls (T8142) reg-names: minItems: 1 items: @@ -64,6 +70,7 @@ allOf: - const: axi2af - const: usb2phy - const: pipehandler + - const: lioa oneOf: - properties: reg: @@ -141,6 +148,23 @@ allOf: - const: pwrctl required: - power-domains + - if: + properties: + compatible: + contains: + const: apple,t8142-atcphy + then: + properties: + reg: + minItems: 5 + maxItems: 6 + reg-names: + minItems: 5 + maxItems: 6 + else: + properties: + apple,tunable-dp-lioa: false + apple,tunable-dp-common-config: false - if: properties: compatible: @@ -168,6 +192,7 @@ allOf: enum: - apple,t8132-atcphy - apple,t8140-atcphy + - apple,t8142-atcphy then: properties: reg: @@ -429,6 +454,18 @@ properties: Note that lane here refers to a USB RX and TX pair re-used for DisplayPort and not to an individual DisplayPort differential lane. + apple,tunable-dp-lioa: + $ref: "#/$defs/apple,tunable" + description: > + T8142 DisplayPort calibration for the lioa register region. Applied + after the common and lane tunables, before common configuration. + + apple,tunable-dp-common-config: + $ref: "#/$defs/apple,tunable" + description: > + T8142 DisplayPort common configuration for the lpdptx register region, + applied after the LIOA list. Both lists are required for DisplayPort. + apple,tunable-dp-common-pre: $ref: "#/$defs/apple,tunable" maxItems: 5461 From 28a6afcba0701163e3822094e68f64b742d50593 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Thu, 12 Nov 2026 10:45:12 -0500 Subject: [PATCH 64/68] arm64: dts: apple: t8142-j813: add N1 factory address targets Add the N1 control/Wi-Fi/Bluetooth PCI functions and wifi0/bluetooth0 aliases already used by J815, so the loader can populate the factory addresses on J813. Keep the change board-local and omit the untested SEP alias. Do not change Bluetooth experimental module options. Based on the patch and owner report by @gig3m in linux#1532 comment 6828183980. The supplied block is carried exactly; its PCI topology matches J815. Symbolic source checks preserve all307 original nodes and properties and add only the four PCI nodes/two aliases. This is not a new compiled-DTB or whole integrated hardware qualification. The owner reports five boots/daily use of the 97f14725 feature on a 2b05915f composition with this block/local display patch, firmware26.6.2. GPU and SEP remain untested; Bluetooth pairing required opt-in flags. The independent Aura165 alias qualification/adoption gate remains. Assisted-by: LLM Link: https://github.com/m0d16l14n1/linux/commit/223d7d72fac4ed23473223c6deaa3c5f06a40ad0 Keep the existing t8142-peripherals.dtsi include when applying this to the consolidated J813 tree. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8142-j813.dts | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8142-j813.dts b/arch/arm64/boot/dts/apple/t8142-j813.dts index 023733ea9a646..477e0c12415a0 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813.dts +++ b/arch/arm64/boot/dts/apple/t8142-j813.dts @@ -220,6 +220,49 @@ #include "t8142-peripherals.dtsi" +/* + * N1 functions behind apcie port 0 (0000:00:00.0 -> 01:00.{0,1,2}), so the + * loader has somewhere to put the factory addresses: it copies ADT /chosen + * mac-address-wifi0 and mac-address-bluetooth0 into the wifi0/bluetooth0 + * alias targets. Same nodes as t8142-j815.dts (same N1, same PCI IDs). + */ +/ { + aliases { + wifi0 = &n1_alpha; + bluetooth0 = &n1_beta; + }; +}; + +&pcie0 { + n1_port: pci@0,0 { + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + bus-range = <1 1>; + #address-cells = <3>; + #size-cells = <2>; + ranges; + + n1_control: control@0,0 { + compatible = "apple,t8142-centauri-control", "pci106b,1900"; + reg = <0x10000 0x0 0x0 0x0 0x0>; + }; + + n1_alpha: wifi@0,1 { + compatible = "pci106b,1902"; + reg = <0x10100 0x0 0x0 0x0 0x0>; + /* Filled by the loader */ + local-mac-address = [00 00 00 00 00 00]; + }; + + n1_beta: bluetooth@0,2 { + compatible = "pci106b,1903"; + reg = <0x10200 0x0 0x0 0x0 0x0>; + /* Filled by the loader */ + local-bd-address = [00 00 00 00 00 00]; + }; + }; +}; + &mtp_hid { multi-touch { firmware-name = "apple/tpmtfw-j813.bin"; From 80324c1b072090680caa6c6f056fcf386ff10ec7 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 10:39:33 +0100 Subject: [PATCH 65/68] selftests: apple: Update ATCPHY fixture for T8142 flags The current USB3 host fixture extracts production functions that now read clear_boot_hold and dp_banked_tunables. Add the two fields at its mocked hardware boundary so it builds after merging the T8142 display work. The existing earlier-generation cases leave both flags clear. The 38 production cases pass under ASan/UBSan, and all 55 mutation controls still fail at their intended assertions. Signed-off-by: Thomas Glanzmann --- tools/asahi/atc-usb3-tests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/asahi/atc-usb3-tests.py b/tools/asahi/atc-usb3-tests.py index 6d92c105c45be..3a7955197c9f9 100644 --- a/tools/asahi/atc-usb3-tests.py +++ b/tools/asahi/atc-usb3-tests.py @@ -77,7 +77,8 @@ def block(source, marker): STUBS = r''' struct atcphy_hw { enum atcphy_generation gen; - bool has_t8140_dp, dp_t8122, has_usb4, park_pipe_unlocked, park_dummy_phy, usb2_only; }; + bool has_t8140_dp, dp_t8122, has_usb4, park_pipe_unlocked, park_dummy_phy, usb2_only; + bool clear_boot_hold, dp_banked_tunables; }; struct device_node { const char *const *compatible; unsigned int count; }; static bool of_device_is_compatible(const struct device_node *root, const char *compatible) { if (!root) return false; From ae8aa4199b4780808d33eab045ff7502ea5fda3f Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 10:39:33 +0100 Subject: [PATCH 66/68] dt-bindings: net: apple: Describe T8142 Centauri control The J813 factory-address nodes use the T8142 control compatible followed by its PCI ID. That backend selects firmware and platform data from its board table, while the T6050 backend requires the boot-provided properties. Admit the existing T8142 compatible pair and keep all three firmware properties required for the plain PCI compatibles used by T6050. This changes only the binding, preserving the hardware-tested device tree. All 137 Apple DTBs have the same warnings as the integration base. Enabled T6050 fixtures still reject each missing firmware property and an incorrect protocol, and T8142 rejects an incorrect PCI fallback. Signed-off-by: Thomas Glanzmann --- .../bindings/net/wireless/apple,centauri.yaml | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Documentation/devicetree/bindings/net/wireless/apple,centauri.yaml b/Documentation/devicetree/bindings/net/wireless/apple,centauri.yaml index f73dd9afceca1..86d1d743115f1 100644 --- a/Documentation/devicetree/bindings/net/wireless/apple,centauri.yaml +++ b/Documentation/devicetree/bindings/net/wireless/apple,centauri.yaml @@ -17,11 +17,18 @@ description: | bootstrap. This binding does not authorize adopting an existing live firmware session or releasing another owner's retained DART streams. + T8142 uses its board-selected firmware and platform ID instead of the + firmware properties supplied to the T6050 control driver. + properties: compatible: - enum: - - pci106b,1900 - - pci106b,1901 + oneOf: + - enum: + - pci106b,1900 + - pci106b,1901 + - items: + - const: apple,t8142-centauri-control + - const: pci106b,1900 reg: maxItems: 1 @@ -43,8 +50,18 @@ properties: required: - compatible - reg - - firmware-name - - apple,centauri-platform-id - - apple,centauri-protocol + +allOf: + - if: + properties: + compatible: + not: + contains: + const: apple,t8142-centauri-control + then: + required: + - firmware-name + - apple,centauri-platform-id + - apple,centauri-protocol additionalProperties: false From ce6b4e14b9a577f0e3b5bd5b6f1f7a510145b146 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 10:52:27 +0100 Subject: [PATCH 67/68] selftests: apple: Stub first-enable relink in the backlight fixture The first-enable relink change makes the extracted dcp_poweron function reference dcp_relink_link_up. The cold-boot backlight fixture models panel power-on and already stubs the external relink boundary. Add the missing stub so its existing normal and negative controls compile again. No production code or test assertions change. Signed-off-by: Thomas Glanzmann --- tools/asahi/backlight-coldboot-tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/asahi/backlight-coldboot-tests.py b/tools/asahi/backlight-coldboot-tests.py index e08f7f3ce9cd3..dfb9a57f1e820 100644 --- a/tools/asahi/backlight-coldboot-tests.py +++ b/tools/asahi/backlight-coldboot-tests.py @@ -115,6 +115,7 @@ def function(source, name): static void cancel_work_sync(struct work_struct *p) { (void)p; } static int dcp_external_start_locked(struct apple_dcp *p) { (void)p;return 0; } static void dcp_relink_wake(int *r,unsigned g,unsigned long j) { (void)r;(void)g;(void)j; } +static void dcp_relink_link_up(int *r,unsigned g,unsigned long j) { (void)r;(void)g;(void)j; } static int dcp_dptx_connect(struct apple_dcp *p,int n) { (void)p;(void)n;return 0; } static void dcp_queue_typec_reconnect(struct apple_dcp *p,int n) { (void)p;(void)n; } static unsigned long wait_for_completion_timeout(int *p,unsigned long n) { (void)p;return n; } From 628803be54f78b079505a38399c15822ea9217ba Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Tue, 17 Nov 2026 14:42:38 -0500 Subject: [PATCH 68/68] selftests: apple-dcp: update native26 fixtures for T8142 callbacks Model the Type-C enable pending flag and the separate hardware firmware profile used by the extracted production functions. Exercise pending publication before power-on and clearing on both native enable exits. Signed-off-by: Diljit Singh --- tools/asahi/dcpext26-modeset-tests.py | 11 ++++++----- tools/asahi/dcpext26-startup-tests.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/asahi/dcpext26-modeset-tests.py b/tools/asahi/dcpext26-modeset-tests.py index 0a3862e20a048..b18d0c2e32c2d 100644 --- a/tools/asahi/dcpext26-modeset-tests.py +++ b/tools/asahi/dcpext26-modeset-tests.py @@ -66,10 +66,11 @@ #include #define dev_warn(...) ((void)0) #define dev_err(...) ((void)0) +#define WRITE_ONCE(x, v) ((x) = (v)) struct drm_crtc {int unused;}; struct drm_crtc_state {bool active,active_changed,color_mgmt_changed;}; struct drm_atomic_commit {struct drm_crtc_state *state;unsigned failed_routes;}; -struct apple_dcp {void *dev;bool native,main_display;int mode_state,vblank_wq;void *connector;}; +struct apple_dcp {void *dev;bool native,main_display,typec_enable_pending;int mode_state,vblank_wq;void *connector;}; struct apple_crtc {struct apple_dcp *dcp;bool fabric_held;}; static struct apple_crtc owner; static struct apple_crtc *to_apple_crtc(struct drm_crtc *c){return &owner;} @@ -88,7 +89,7 @@ static bool dcp_crtc_needs_route_start(struct apple_dcp *d){return false;} static int dcp_typec_prepare_route(struct apple_dcp *d){return 0;} static int apple_drm_fabric_hold(void){return 0;} -static void dcp_poweron(struct apple_dcp *d){powered++;} +static void dcp_poweron(struct apple_dcp *d){assert(d->typec_enable_pending);powered++;} static void dcp_external_recover(struct apple_dcp *d){} static bool drm_atomic_crtc_needs_modeset(struct drm_crtc_state *s){return true;} static int dcp_crtc_atomic_modeset(struct drm_crtc *c,struct drm_atomic_commit *a){programmed++;return mode_error;} @@ -104,13 +105,13 @@ for(unsigned i=0;i<4;i++){ done=woken=notified=invalidated=powered=programmed=0;mode_error=errors[i];d.mode_state=1; apple_crtc_atomic_enable(&crtc,&commit); - assert(done==1&&woken==1&¬ified==1&&invalidated==1&&programmed==1&&powered==1&&!d.mode_state); + assert(done==1&&woken==1&¬ified==1&&invalidated==1&&programmed==1&&powered==1&&!d.mode_state&&!d.typec_enable_pending); } done=woken=notified=invalidated=0;mode_error=0; - apple_crtc_atomic_enable(&crtc,&commit);assert(done==1&&!woken&&!notified&&!invalidated); + apple_crtc_atomic_enable(&crtc,&commit);assert(done==1&&!woken&&!notified&&!invalidated&&!d.typec_enable_pending); // Existing non-native error policy is preserved. d.native=false;done=woken=notified=invalidated=0;mode_error=-EIO; - apple_crtc_atomic_enable(&crtc,&commit);assert(done==1&&!woken&&!notified&&!invalidated&&classic_errors==1); + apple_crtc_atomic_enable(&crtc,&commit);assert(done==1&&!woken&&!notified&&!invalidated&&classic_errors==1&&!d.typec_enable_pending); } ''' with tempfile.TemporaryDirectory() as t: diff --git a/tools/asahi/dcpext26-startup-tests.py b/tools/asahi/dcpext26-startup-tests.py index 2774f4086a990..2ecdb2cc0fc4c 100644 --- a/tools/asahi/dcpext26-startup-tests.py +++ b/tools/asahi/dcpext26-startup-tests.py @@ -93,7 +93,7 @@ def run(name,code,reject=False): struct apple_epic_service_ops {const char *name;bool reusable,optional,open_later;int (*prepare)(struct apple_epic_service *,const char *,const char *,s64);int (*revalidate)(struct apple_epic_service *,const char *,const char *,s64);void (*init)(struct apple_epic_service *,const char *,const char *,s64);void (*teardown)(struct apple_epic_service *);void (*init_props)(struct apple_epic_service *,s64,const void *,size_t);}; struct apple_epic_service {struct apple_dcp_afkep *ep;const struct apple_epic_service_ops *ops;bool enabled,torndown,pending_open,defer_start;unsigned users;int lock;u32 channel;void *cookie;const char *pending_name,*pending_class;s64 pending_unit;int cmd_map[1];}; struct dptx_port {struct apple_epic_service *service;s64 unit;bool enabled,connected;int enable_completion;}; -struct apple_dcp {const void *push_out_prefill;bool native,ext26_services_open,v27_j714s;int fw_compat,index,dptx_controller_ready;struct {unsigned num_dptx_ports;int iomfb_method_profile;} hw;struct dptx_port dptxport[2];void *dev;struct apple_dcp_afkep *systemep,*ibootep,*dptx_controller_ep,*dcpavservep,*dptxep,*ext26_aux[3];}; +struct apple_dcp {const void *push_out_prefill;bool native,ext26_services_open,v27_j714s;int fw_compat,index,dptx_controller_ready;struct {unsigned num_dptx_ports;int iomfb_method_profile,firmware_compat;} hw;struct dptx_port dptxport[2];void *dev;struct apple_dcp_afkep *systemep,*ibootep,*dptx_controller_ep,*dcpavservep,*dptxep,*ext26_aux[3];}; struct apple_dcp_afkep {struct apple_dcp *dcp;u32 endpoint,num_channels;bool wire_v2,stopping,match_epic_name,compact;int lock;void *wq,*service_work;const struct apple_epic_service_ops *ops;struct apple_epic_service services[AFK_MAX_CHANNEL];}; static bool dcp_is_ext26(struct apple_dcp *d){return d->native;} static bool dcp_fail_stop(struct apple_dcp *d){return d->native;}