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; } 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) { }