From e4548c1c7da45728e6dd05de8777103ba2c0f416 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Mon, 9 Nov 2026 18:23:54 -0500 Subject: [PATCH 1/2] iommu: apple-dart: restore T8140's ISP DART at every power-up After a sleep that kept DRAM up, the camera failed to start until the next deep sleep: the ISP firmware booted, its first command timed out, and the ISP DART logged a fault on the firmware's read of 0x300704048, the PMGR window of the first entry of its address filter (DAPF). The ISP DART keeps Linux's values through such a wake, in which the sleep engine runs the ISP through it. They read back as before the sleep, so resume took the "state retained" path: a TLB flush, no reset, no restore, and no DAPF write, since entry 0's range still matched. After a deep wake its TTBR reads back as the engine's, so the same resume did the full reset and restore, and the camera worked. macOS's SPTM (its t8110dart powerup) restores the ISP's DARTs in full at every power-up and never tests whether the values survived: tunables, then each stream's TCR and TTBR, a TLB invalidate, every DAPF entry with its streams before its config word, the error mask, and the stream enables last. Do the same for a DART marked apple,restore-on-power-up: always take the full reset and restore at resume, and write the DAPF back even where its first range still reads back. Write each DAPF entry's stream word before its config word, as macOS does, for every DART. Mark the ISP's first DART, the one that keeps its state and holds the filter. Signed-off-by: Diljit Singh --- .../devicetree/bindings/iommu/apple,dart.yaml | 9 +++++++ arch/arm64/boot/dts/apple/t8140.dtsi | 6 +++++ drivers/iommu/apple-dart.c | 27 +++++++++++++------ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 5419053e2cf91..d98bf0d86011d 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -136,6 +136,15 @@ properties: The last word of each filter entry, one per range in apple,dapf-ranges. 1 where absent. + apple,restore-on-power-up: + type: boolean + description: + Reset and restore the DART, and write its address filter back, every + time it powers up, even where its registers still read as they were + left. For a DART that keeps its values through a sleep in which the + SoC's sleep engine runs its consumer, but whose address filter only + takes effect once written again. + apple,sleep-prepare: $ref: /schemas/types.yaml#/definitions/uint32-matrix items: diff --git a/arch/arm64/boot/dts/apple/t8140.dtsi b/arch/arm64/boot/dts/apple/t8140.dtsi index 6247d9c31aa47..c94ea06ad6081 100644 --- a/arch/arm64/boot/dts/apple/t8140.dtsi +++ b/arch/arm64/boot/dts/apple/t8140.dtsi @@ -2055,6 +2055,12 @@ interrupt-parent = <&aic>; interrupts = ; power-domains = <&ps_isp_sys>; + /* + * It keeps Linux's values through a wake that kept DRAM up, + * where the sleep engine runs the ISP through it, but its + * address filter works again only once written. + */ + apple,restore-on-power-up; /* * 3-level tables (ias <= 36) as iBoot and the native host * ran them: the ISP fetches at vm-base 0x10000000000 and the diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index b491462c74516..02187b82ba4da 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -378,6 +378,8 @@ struct apple_dart { u32 tunnel_state_restored : 1; /* Clocked by its host's port: the host resumes it after a real sleep. */ u32 host_resumes : 1; + /* Reset and restored, its address filter written, at every power-up. */ + u32 restore_on_power_up : 1; bool commands_gated; /* Resume restored the translations, but the last steps of its reset failed. */ bool reset_incomplete; @@ -4475,16 +4477,17 @@ static bool apple_dart_dapf_holds(struct apple_dart *dart) } /* - * After a power-off, before any consumer's firmware starts. Not while it's kept, and not - * while it's locked. + * After a power-off, before any consumer's firmware starts. Not while it's kept, unless + * @always, and not while it's locked. Each entry's config word goes last, after its + * streams, as macOS writes it. */ -static void apple_dart_dapf_replay(struct apple_dart *dart) +static void apple_dart_dapf_replay(struct apple_dart *dart, bool always) { unsigned int i; if (!dart->dapf_count) return; - if (apple_dart_dapf_holds(dart)) + if (!always && apple_dart_dapf_holds(dart)) return; if (readl(dart->regs + DART_DAPF_LOCK) & DART_DAPF_LOCKED) { dev_warn(dart->dev, "DAPF locked after the sleep: not replayed\n"); @@ -4497,8 +4500,8 @@ static void apple_dart_dapf_replay(struct apple_dart *dart) writel(0, entry + 0x04); writeq(dart->dapf_ranges[2 * i], entry + 0x08); writeq(dart->dapf_ranges[2 * i + 1], entry + 0x10); - writel(DART_DAPF_CONFIG, entry + 0x00); writel(dart->dapf_r20[i], entry + 0x20); + writel(DART_DAPF_CONFIG, entry + 0x00); } /* Its consumer's firmware faults on its first access without it: say so plainly. */ if (!apple_dart_dapf_holds(dart)) { @@ -4763,6 +4766,8 @@ static int apple_dart_probe(struct platform_device *pdev) if (ret) return ret; } + dart->restore_on_power_up = of_property_read_bool(dev->of_node, + "apple,restore-on-power-up"); if (tunneled) { dart->tunables = devm_apple_tunable_parse(dev, dev->of_node, "apple,tunable", res); @@ -5882,7 +5887,13 @@ static __maybe_unused int apple_dart_resume(struct device *dev) if (dart->locked) return 0; - if (apple_dart_state_retained(dart)) { + /* + * Not for a DART restored at every power-up, as macOS's SPTM does (its + * t8110dart powerup): T8140's ISP DART keeps Linux's values through a wake + * that kept DRAM up, but its address filter takes effect only once written + * again, and the firmware's first access through it faults. + */ + if (!dart->restore_on_power_up && apple_dart_state_retained(dart)) { /* Nothing was lost, only drop what the TLBs may still hold. */ if (!dart->reset_incomplete) return apple_dart_invalidate_each_stream(dart); @@ -5920,7 +5931,7 @@ static __maybe_unused int apple_dart_resume(struct device *dev) } /* The address filter went with the same power-off, and so may these. */ - apple_dart_dapf_replay(dart); + apple_dart_dapf_replay(dart, dart->restore_on_power_up); if (dart->resume_tunables) { unsigned int changed = apple_dart_apply_tunables(dart, dart->resume_tunables); @@ -5967,7 +5978,7 @@ static __maybe_unused int apple_dart_resume_noirq(struct device *dev) dev_dbg(dev, "restored after sleep\n"); } if (pm_resume_via_firmware()) - apple_dart_dapf_replay(dart); + apple_dart_dapf_replay(dart, false); return ret; } From c21212e26930ca64bad8877752b4e4fa42f9faed Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Mon, 9 Nov 2026 18:28:17 -0500 Subject: [PATCH 2/2] media: apple: isp, soc: apple: sleep: keep DRAM up after a camera start again The camera failed after a DRAM-kept (SLP_DDR) wake because Linux left the ISP DART's address filter as the sleep had left it; the previous commit restores the DART at every power-up as macOS does. So the sleep after an ISP start no longer has to take the deep path, and the USB host's vote for keeping DRAM up holds again whatever the camera did. Drop apple_sleep_next_deep() and its readiness flag, which had no other user. Signed-off-by: Diljit Singh --- drivers/media/platform/apple/isp/isp-fw.c | 3 -- drivers/soc/apple/sleep.c | 49 ++++------------------- include/linux/soc/apple/sleep.h | 7 ---- 3 files changed, 7 insertions(+), 52 deletions(-) diff --git a/drivers/media/platform/apple/isp/isp-fw.c b/drivers/media/platform/apple/isp/isp-fw.c index 144c2a4ae3883..98125b804a7ef 100644 --- a/drivers/media/platform/apple/isp/isp-fw.c +++ b/drivers/media/platform/apple/isp/isp-fw.c @@ -1282,9 +1282,6 @@ int apple_isp_firmware_boot(struct apple_isp *isp) return -EIO; } - /* A SLP_DDR wake after the ISP ran stalls, even after a failed start; a deep one doesn't. */ - apple_sleep_next_deep(isp->dev); - /* The firmware starts with new rings. */ isp->ipc_stale = NULL; isp->ipc_failed = false; diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index 0041ab2476a55..f1c847eb5c315 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -558,8 +558,8 @@ struct apple_sleep { int radio_perst; bool radio_perst_low; bool returned; - /* This return was the first from the deep path: later sleeps keep DRAM up. */ - bool slp_ddr_now_ready; + /* This wake came back down the deep path, not the DRAM-kept one. */ + bool deep_ran; /* This sleep's wake came from the SMC's sources alone. */ bool smc_woke_alone; }; @@ -616,13 +616,6 @@ static DEFINE_SPINLOCK(sleep_slp_ddr_lock); static bool sleep_slp_ddr_usb; static void __iomem *sleep_slp_ddr_word; -/* - * The SLP_DDR wake runs on the SoC-side state the system left. The first one of a boot used to - * stall in the sleep engine, which came from the ISP's firmware boot at probe (see the ISP - * driver). Cleared while a deep path is owed, and set again by a wake that shows it ran. - */ -static bool sleep_slp_ddr_ready = true; - /* * A coprocessor that runs through a sleep crashed. The AOP is the always-on master SLP_DDR keeps * DRAM up for: after its firmware crashed, the next SLP_DDR wake stalled in the sleep engine, @@ -638,7 +631,7 @@ static void sleep_slp_ddr_write(void) if (!sleep_slp_ddr_word) return; val = readl(sleep_slp_ddr_word) & ~WAKE_SLP_DDR_USB; - if (sleep_slp_ddr_usb && sleep_slp_ddr_ready && !sleep_slp_ddr_crashed) + if (sleep_slp_ddr_usb && !sleep_slp_ddr_crashed) val |= WAKE_SLP_DDR_USB; writel(val, sleep_slp_ddr_word); } @@ -671,26 +664,6 @@ void apple_sleep_coproc_crashed(struct device *dev) } EXPORT_SYMBOL_GPL(apple_sleep_coproc_crashed); -/* - * T8140's camera firmware doesn't start again after any SLP_DDR wake until a deep sleep: it - * boots, but its first command never completes. So from an ISP start, even a failed one, the - * next sleep takes the deep path: a camera used before a sleep works after it, and one that - * failed after a SLP_DDR wake works after the next sleep. - */ -void apple_sleep_next_deep(struct device *dev) -{ - if (!apple_sleep) - return; - scoped_guard(spinlock_irqsave, &sleep_slp_ddr_lock) { - if (!sleep_slp_ddr_ready) - return; - sleep_slp_ddr_ready = false; - sleep_slp_ddr_write(); - } - dev_info(apple_sleep->dev, "%s ran: the next sleep takes the deep path\n", dev_name(dev)); -} -EXPORT_SYMBOL_GPL(apple_sleep_next_deep); - static bool sleep_debug_link_cut; /* Only the debug port's controller took the cold reset. */ @@ -2722,14 +2695,8 @@ static void apple_sleep_return(struct apple_sleep *s) sleep_ps_rewake(s); - /* Only C2S turns AP_TMM on: the deep path ran, so the held vote applies from now on. */ - if (!sleep_slp_ddr_ready && sleep_ps_woke_on(s, s->soc->ps.ap_tmm)) { - scoped_guard(spinlock_irqsave, &sleep_slp_ddr_lock) { - sleep_slp_ddr_ready = true; - sleep_slp_ddr_write(); - } - s->slp_ddr_now_ready = true; - } + /* Only C2S turns AP_TMM on. */ + s->deep_ran = sleep_ps_woke_on(s, s->soc->ps.ap_tmm); val = readl(s->ps + s->soc->ps.sep); if (val & PS_DEV_DISABLE) @@ -2915,10 +2882,8 @@ static void apple_sleep_report(void) dev_info(s->dev, "back from sleep, boot object resumes %llu -> %llu\n", s->resumes_before, s->resumes_after); - if (s->slp_ddr_now_ready) { - s->slp_ddr_now_ready = false; - dev_info(s->dev, "the deep path ran: later sleeps keep DRAM up for the USB host\n"); - } + if (s->deep_ran) + dev_info(s->dev, "the deep path ran\n"); for (i = 0; i < s->soc->nwake_names; i++) { u32 id = names[i].id; diff --git a/include/linux/soc/apple/sleep.h b/include/linux/soc/apple/sleep.h index 1766f865b64d2..887f25bf5b221 100644 --- a/include/linux/soc/apple/sleep.h +++ b/include/linux/soc/apple/sleep.h @@ -121,9 +121,6 @@ void apple_sleep_radio_port_up(void); /* From RTKit: this coprocessor's firmware crashed. */ void apple_sleep_coproc_crashed(struct device *dev); -/* This device ran: the next sleep takes the deep path, as the first of a boot does. */ -void apple_sleep_next_deep(struct device *dev); - /* After a deep sleep, put back the pins it reset. ANS's driver calls it before the run bit. */ void apple_sleep_restore_pins(void); @@ -239,10 +236,6 @@ static inline void apple_sleep_coproc_crashed(struct device *dev) { } -static inline void apple_sleep_next_deep(struct device *dev) -{ -} - static inline void apple_sleep_restore_pins(void) { }