Skip to content

spi: apple-qspi: runtime suspend controllers in a power domain, holding power while NVRAM writes are armed - #4197

Merged
DjDeveloperr merged 2 commits into
mainfrom
feat/qspi-runtime-pm
Dec 3, 2026
Merged

DjDeveloperr merged 2 commits into
mainfrom
feat/qspi-runtime-pm

Conversation

@satchlj

@satchlj satchlj commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

What: Rebase of #2824 (carrying Ryan Murray's two commits onto current main past the #2817 spi-apple-qspi-policy.h qualification refactor):

  • spi: apple-qspi: keep a controller powered while NVRAM writes are armed: hold a runtime-PM reference on every write-candidate controller while read_only=0 so 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-only runtime_pm flag and enable runtime PM whenever dev->pm_domain is present, so T8122, T8132, and T604x QSPIMC controllers gate qspi when idle instead of holding it permanently on.

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.
  • J613 (13-inch M3 MacBook Air, T8122, macOS 27.2 26B123) at f93f80c923e6: PASS (Linux 7.3.0, clang 23.1.5 module build, default kernel command line):
    • All 4 MTD partitions (/dev/mtd0ro–/dev/mtd3ro, including adt and nvram) read back byte-identical SHA-256; 2a1118000.spi drops cleanly to suspended and qspi drops to off-0 in pm_genpd_summary.
    • Arming read_only=0 holds 2a1118000.spi active (qspi on) across a 600 ms idle gap (>100 ms autosuspend); disarming read_only=1 returns to suspended (qspi off-0).
    • aurora-bless --get-boot succeeds and returns qspi to off-0.
    • Hardware deep sleep (mem via /dev/rtc1): qspi stays off-0 after wake, all 4 MTD partitions read back byte-identical SHA-256, and qspi returns to off-0; zero kernel errors or DART faults.
  • Earlier read-only rows from spi: apple-qspi: runtime suspend QSPIMC controllers in a power domain, powered while NVRAM writes are armed #2824/M3 Air 15 (J615): read NVRAM from the QSPIMC NOR #2593 also passed on J615 (T8122), J713 (T8132), and J616C (T6041, comment on spi: apple-qspi: runtime suspend QSPIMC controllers in a power domain, powered while NVRAM writes are armed #2824).

Not yet:

  • Live NVRAM write round trips (aurora-bless --set-boot with >100 ms gap between erase and program, verifying qspi stays on while 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.

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>
@satchlj
satchlj requested review from a team and DjDeveloperr as code owners December 3, 2026 13:27
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:neo Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merge readiness at f93f80c9: ready to merge

Check Detail
CI at head ok 4 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at f93f80c9
Conflicts ok none
PR text ok Risk: two-way · QSPIMC runtime PM only. Default startup stays readonly=1; armed writes keep the controller powered throughout the session, and a plain revert restores the previous T8140-only runtime-PM gating.

Areas: area:gpu
Merge: gh pr merge 4197 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_only setter 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=0 the 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, as main does for every SoC but T8140. Every QSPIMC node in the tree has one power-domains entry, 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-bless opens read_only only 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 to f46dffad91fd.

Needed before the merge

  1. Ryan's OK for the carry. I asked on #2824.
  2. Hardware lines at this head. Please put f93f80c9 on 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-bless normally 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 see qspi on 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");

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 3, 2026
@satchlj

satchlj commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Updated the J613 PASS line with exact head f93f80c923e6 (the live module build and run were at this exact head). Thanks for the review!

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

On main ebfc4f60bdd1 merged with f93f80c923e6 (tree 1e31c42347a2), python3 tools/asahi/qspi-nvram-tests.py passed all 46 checks, including idle, armed hold, disarm and failure unwind. The remaining hardware evidence is the T8132 J773g read-only row already in progress: a bound QSPIMC, idle gating, successful wake and matching readback.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

J773g (Apple Mac mini M4, T8132, G16G B0, os-fw 27.2, 24 GB RAM) no-write QSPI hardware row for head f93f80c923e6d53f658c7e659e400445ed2de0b0 (work/m4rows-b8818ae1-j773g-20261203, kernel 7.3.0-j773g-r1480, local merge b8818ae173f0 on main c43014f079f5, vmlinux build ID ff1e987389e53799e752ac3fc62c843fdb77f70d, boot 5812289d-cae8-43c5-bc9c-0e56c002cce0):

  • Judge line: linux#4197: PASS: runtime suspended/qspi off-0 at idle, active/on while armed, 3 sha PASS incl. after one deep sleep, no fault line
  • Q4197 rc=0 serror=0 irqbar=0 pmperr=0 gpu=0 warn=0 brcmerr=0; end runtime=suspended qspi=off-0 spi_p=on ro=Y.
  • Stock 7.3.0-j773g-main3685+ cleanly restored (boot beaa437c-6c1c-44f0-87be-9a073461f45d).

Verdict: PASS (no-write QSPI row).

@DjDeveloperr
DjDeveloperr merged commit dc68a27 into main Dec 3, 2026
7 checks passed
@DjDeveloperr
DjDeveloperr deleted the feat/qspi-runtime-pm branch December 3, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:neo Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants