Repository navigation
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
Draft
RyanTheTide wants to merge 2 commits into
RyanTheTide wants to merge 2 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.drivers/spi/spi-apple-qspi.oand the policy KUnit object, W=1, clang 22 (fleet79 config), no warnings. checkpatch --strict is clean on both commits.suspended,qspi/spi_poff; each read powers them on, and they are off again 3 s later (3/3); NVRAM sha256 identical; asahi-bless works; s2idle 2/2.qspigates between accesses; nvram/adt/log partitions identical across all arms;aurora-bless --get-bootworks.Still to run
aurora-bless --set-bootround trip with idle gaps longer than 100 ms between erase and program; read back and verify; expect nowrite_fault/"NVRAM write fault" line. Also one s2idle followed by a read, the genpdqspistate when armed (on) and when disarmed (gating), and 0 AVC, 0 failed units, 0 new kernel errors.Detail
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.pm_runtime_force_suspend()still gates an armed controller, andforce_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)