Skip to content

spi: apple-qspi: runtime suspend QSPIMC controllers in a power domain, powered while NVRAM writes are armed - #2824

Draft
RyanTheTide wants to merge 2 commits into
integration/aurorafrom
prfix2/qspi-runtime-pm-20261123
Draft

RyanTheTide wants to merge 2 commits into
integration/aurorafrom
prfix2/qspi-runtime-pm-20261123

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Problem

spi-apple-qspi enables runtime PM only for T8140, by a per-SoC flag, so every other QSPIMC controller (T8122, T8132, T6041/T6040) holds its power domain on while the driver is bound. This was the third commit of #2593, split out after review there.

Turning it on for those controllers exposes a write-safety gap that T8140 already has today: spi-nor erases a sector and programs it back as separate spi-mem operations, each dropping its runtime-PM reference. A bless (MEMERASE, then write) can leave more than the 100 ms autosuspend delay between them, so the block can gate after the erase and the programs run on a controller that resume rebuilt from its reset state. If a program then fails verify, the sector stays erased and the write fault latches read-only until reboot.

Change

  • spi: apple-qspi: keep a controller powered while NVRAM writes are armed: while root has writes armed (read_only=0), every write-candidate controller holds a runtime-PM reference, so the erase and the programs after it run in one power session. The reference is dropped when writes are disarmed, when a write fault latches, or on unbind. A controller that binds while writes are armed takes one at probe. Arming is all or none: if a controller can't resume, arming fails and the driver stays read-only. Reads can still gate between accesses.
  • spi: apple-qspi: runtime suspend any controller in a power domain: the change from M3 Air 15 (J615): read NVRAM from the QSPIMC NOR #2593 (7127d73), with a corrected message. The flag goes, and runtime PM is enabled for any controller whose node puts it in a power domain. The message no longer claims a J615 blank-idle saving, because the J615 measured 3.46 W with and without it.

Testing

  • tools/asahi/qspi-nvram-tests.py: 31/31 pass, at both commits. A new case models spi-mem's per-operation reference and genpd gating: with writes armed, an erase, idle gaps and 16 page programs see no gate; disarming, a write fault and a failed resume each drop the reference. Three new changed-guard controls fail as they should: no hold on arming, no release on a fault, and partial arming.
  • Build: drivers/spi/spi-apple-qspi.o and the policy KUnit object, W=1, clang 22 (fleet79 config), no warnings. checkpatch --strict is clean on both commits.
  • Hardware, runtime-PM commit only (from M3 Air 15 (J615): read NVRAM from the QSPIMC NOR #2593's thread; neither row wrote the NOR):

Still to run

  • J713 (T8132) and J616s (T6041) NVRAM write rows on this head. Each one: arm writes, then do an aurora-bless --set-boot round trip with idle gaps longer than 100 ms between erase and program; read back and verify; expect no write_fault/"NVRAM write fault" line. Also one s2idle followed by a read, the genpd qspi state when armed (on) and when disarmed (gating), and 0 AVC, 0 failed units, 0 new kernel errors.
  • J700 (T8140, already runtime-suspending): one bless round trip, to confirm the write hold changes nothing there.
Detail
  • Base: integration/aurora 00cbc67. Independent of M3 Air 15 (J615): read NVRAM from the QSPIMC NOR #2593: on the J615 the controller only gates once M3 Air 15 (J615): read NVRAM from the QSPIMC NOR #2593's DT describes the NOR, and the code doesn't depend on it.
  • Why not just hold a reference inside apple_qspi_nvram_modify(): spi-mem already holds one for each call, which covers the erase or the program plus its own status poll and verify. The gap is between calls, and only the armed state spans it.
  • System sleep is not changed by this: pm_runtime_force_suspend() still gates an armed controller, and force_resume() brings it back with the reference intact. A write sequence split by s2idle runs on a re-initialised controller, the same as without runtime PM, where system resume also resets the block.

Assisted-by: LLM (Claude:Opus 5.5)

spi-nor erases a sector and programs it back as separate spi-mem
operations. Each one takes and drops its own runtime-PM reference, and
a userspace bless (MEMERASE, then write) can leave more than the 100 ms
autosuspend delay between them. A runtime-suspended controller (T8140
today) can then gate its power domain after the erase, and the programs
run on a controller that resume rebuilt from its reset state rather
than the one the erase ran on. If a program then fails its verify, the
sector stays erased and the write fault latches read-only until reboot.

While root has writes armed (read_only=0), hold a runtime-PM reference
on every write-candidate controller, so an erase and the programs that
follow it run in one power session. The reference goes when writes are
disarmed, when a write fault latches, or when the controller unbinds; a
controller bound while writes are armed takes one at probe. Arming is
all or none: if a controller cannot resume, it fails with that error
and the driver stays read-only. Reads still let the block gate between
accesses. Controllers without runtime PM are unchanged.

tools/asahi/qspi-nvram-tests.py models the gap: an erase, idle gaps and
16 page programs see no gate while armed; disarming, a write fault or a
failed resume drop the reference; three changed-guard controls (no hold
on arming, no release on a fault, partial arming) fail.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Runtime PM is enabled only for the T8140 controller, by a per-SoC flag.
Every other QSPIMC controller (T8122, T8132, T6041/T6040) holds its
power domain on for as long as the driver is bound, although its node
already puts it in one.

The runtime suspend and resume paths already restore what a gated block
loses: the reset helper re-applies timing, FIFO thresholds and
interrupt state, and mode, divider and descriptors are set per
operation. Use them for every controller whose node puts it in a power
domain, instead of the per-SoC flag. While NVRAM writes are armed the
controller stays powered (previous commit), so only reads run across a
gate.

On a J615 (T8122) with its NOR on QSPIMC, the controller now suspends
between accesses with the qspi and spi_p domains off, powers both for
each NVRAM read and gates them again afterwards; the NVRAM reads back
identically, asahi-bless works with the domains gated, and s2idle
passes. On a J713 (T8132, spi_p always-on) the qspi domain gates
between accesses and the nvram, adt and log partitions read back
identically to a driver without this change. Neither test wrote the
NOR. Blank idle power on the J615 did not change measurably.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant