Repository navigation
spi: apple-qspi: runtime suspend controllers in a power domain, holding power while NVRAM writes are armed - #4197
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> Signed-off-by: Satya Benson <satya@benson.earth>
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> Signed-off-by: Satya Benson <satya@benson.earth>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Reviewed at f93f80c923e6. The code is fine: it is better than main and I found nothing it breaks. Two things are still needed before the merge, listed at the end.
Compared with #2824 (4936033f3144). The driver changes are line for line the same. The only difference is how one line of the test script is wrapped, because #2817 put new code next to it. Ryan Murray is still the author of both commits, both keep the Signed-off-by, and yours is added. This PR is the one to land. #2824 conflicts with main and can close once Ryan is fine with the carry.
What I checked in the code
- The power reference is balanced on every path: arm, arm twice, disarm, disarm twice, a failed arm with two controllers, a write fault, unbind while armed, every probe error, and a controller with no runtime PM.
pm_runtime_resume_and_get()drops its own count on failure, and the probe error paths drop the probe's count after the hold is gone. - Locks: the
read_onlysetter takes the policy lock and may resume the controller under it. The resume path never takes the policy lock, and release is asynchronous, so there is no deadlock with the MTD operations. - Erase and then a gate: while
read_only=0the reference is held, so runtime PM cannot gate between an erase and its programs. A controller that binds while armed takes its reference before probe drops its own. A tool that dies in the middle leaves it armed, so it stays on. - System sleep while armed: the block still gates in sleep and comes back with the count intact, and after a failed resume the next access tries again with the hold still in place. An erase is complete and read back as blank before the call returns, so this is the same as on
main. - No
pm_domain: runtime PM stays off and system resume resets the controller, asmaindoes for every SoC but T8140. Every QSPIMC node in the tree has onepower-domainsentry, so no board loses runtime PM it had. - What changes: T8122, T8132 and T6040/T6041. T6050, T8142 and T8152 fall back to the T8140 entry and already had it. T6030 and T6031 do not bind this driver. The flash supply is an always-on regulator, so only the controller gates.
aurora-blessopensread_onlyonly around its own write and sets it back, so the hold lasts only for the write. That answers the open question from the review on #2824.
Checks on this head over main f46dffad91fd (the three files involved are the same there as at your base, so the merge is clean)
python3 tools/asahi/qspi-nvram-tests.py: 46/46 pass.spi-apple-qspi.o, arm64, clang 23.1.3,W=1: no warnings. Built as an external module on a warm tree whose spi-mem, spi, runtime PM and power domain sources are identical tof46dffad91fd.
Needed before the merge
- Ryan's OK for the carry. I asked on #2824.
- Hardware lines at this head. Please put
f93f80c9on the J613 line in the body if that run was on exactly this head (the readiness bot looks for it). A second generation without any write, on a T8132 Mac, is prepared on our side.
Not blocking
- The write round trips. The first write after a power gate has not run on T8122, T8132 or T604x yet. Every write checks that WREN took before it sends the program or erase,
aurora-blessnormally appends a record without erasing, and when it does erase it is the next bank, with the old one still valid. So I would not hold the merge for it, but one run by someone on their own Mac is worth having: setting the boot volume to the one already set is a real write (it appends a new record), and is enough to seeqspion while armed and no write fault. - A follow-up could say in the parameter text that arming keeps the controller on:
-MODULE_PARM_DESC(read_only, "Default true; root runtime opt-in for bounded NVRAM writes in the nvram partition of a known part");
+MODULE_PARM_DESC(read_only, "Default true; root runtime opt-in for bounded NVRAM writes in the nvram partition of a known part. The controller stays powered until it is set back");|
Updated the J613 PASS line with exact head |
|
On main |
|
J773g (Apple Mac mini M4, T8132, G16G B0, os-fw 27.2, 24 GB RAM) no-write QSPI hardware row for head
Verdict: PASS (no-write QSPI row). |
What: Rebase of #2824 (carrying Ryan Murray's two commits onto current
mainpast the #2817spi-apple-qspi-policy.hqualification refactor):spi: apple-qspi: keep a controller powered while NVRAM writes are armed: hold a runtime-PM reference on every write-candidate controller whileread_only=0so multi-op erase/program/verify sequences stay in one power session, releasing on disarm, write fault, or unbind (all-or-none arming).spi: apple-qspi: runtime suspend any controller in a power domain: drop the T8140-onlyruntime_pmflag and enable runtime PM wheneverdev->pm_domainis present, so T8122, T8132, and T604x QSPIMC controllers gateqspiwhen idle instead of holding it permanentlyon.Tested:
python3 tools/asahi/qspi-nvram-tests.py: 46/46 pass on Linux (including armed power-hold across erase/idle gaps/16 page programs, disarm/fault/failed-resume release, and all changed-guard controls).scripts/checkpatch.pl --strict --git origin/main..HEAD: 0 errors, 0 warnings, 0 checks on both commits.26B123) atf93f80c923e6: PASS (Linux 7.3.0,clang 23.1.5module build, default kernel command line):/dev/mtd0ro–/dev/mtd3ro, includingadtandnvram) read back byte-identical SHA-256;2a1118000.spidrops cleanly tosuspendedandqspidrops tooff-0inpm_genpd_summary.read_only=0holds2a1118000.spiactive(qspi on) across a 600 ms idle gap (>100 ms autosuspend); disarmingread_only=1returns tosuspended(qspi off-0).aurora-bless --get-bootsucceeds and returnsqspitooff-0.memvia/dev/rtc1):qspistaysoff-0after wake, all 4 MTD partitions read back byte-identical SHA-256, andqspireturns tooff-0; zero kernel errors or DART faults.Not yet:
aurora-bless --set-bootwith >100 ms gap between erase and program, verifyingqspistaysonwhile armed and no write fault latches) on J713, J616s, and J700 — none of the tests above wrote the NOR.Risk: two-way · QSPIMC runtime PM only. Default startup stays
read_only=1; armed writes keep the controller powered throughout the session, and a plain revert restores the previous T8140-only runtime-PM gating.