Skip to content

smp, pmgr: fix T6020 S2R wake path - #639

Merged
RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
patatman:fix/t6020-s2r-wake
Dec 2, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
patatman:fix/t6020-s2r-wake

Conversation

@patatman

@patatman patatman commented Dec 1, 2026 •

Copy link
Copy Markdown

What: Fix the Aura hardware deep-sleep (SLP_S2R) wake path for Apple T6020 (M2 Pro) by power-gating /arm-io/apcie in reverse ADT order before pcie_reinit_after_sleep(), skipping /arm-io/ans on T6020, rewriting unlocked secondary CPU RVBARs back to _vectors_start, and restoring HCR_EL2 (API|APK|E2H|RW) alongside SCTLR_EL2 before returning to the OS. Ref aurora-silicon/linux#3336
Tested: J414s M2 Pro (T6020, 10-core, system-fw 26.6.2 / os-fw 13.5) at ae08762a: 4 consecutive hardware SLP_S2R deep sleeps (including a 13h49m overnight sleep at ~0.28 W, 95% -> 90%) and full desktop wakes (~0.48 s wake, 0 failed units); second J414s wake confirmed by @JJRPF; J414c M2 Max (T6021) boot + s2idle confirmed at ae08762a by @muness.
Risk: two-way door · T6020 (apcie/ANS wake branch) and unlocked-RVBAR / EL2 Macs (secondary RVBAR rewrite + HCR_EL2 restore on smp_s2r_return_to_os())
Not yet: T6021/T6022 hardware SLP_S2R wake path (no T6021/T6022 apple_sleep provider on linux@main yet).

Details
  1. Reverse-order /arm-io/apcie power-gate (pmgr_adt_power_off_reverse()) + 2 ms settle: On T6020, power-gating /arm-io/apcie in reverse ADT order before pcie_reinit_after_sleep() ensures the PCIe complex reinitializes cleanly after a power cut.
  2. Skip pmgr_adt_power_enable("/arm-io/ans") on T6020: Calling pmgr_adt_power_enable("/arm-io/ans") during Aura's wake path failed/blocked wake on T6020; Linux's nvme-apple driver handles ANS2 reset and cold start on resume.
  3. Rewrite secondary RVBARs when cpu_features->apple_sysregs_unlocked: Hardware SLP_S2R resets secondary CPU RVBARs to their power-on defaults on unlocked-RVBAR SoCs; pointing them back to _vectors_start lets Linux bring all secondary CPUs online cleanly.
  4. Restore HCR_EL2 (API | APK | E2H | RW) alongside SCTLR_EL2: Ensures Linux cpu_resume enters EL2h with PAC enabled cleanly without faulting.

Thanks to @JJRPF for reviewing and verifying on a second J414s, and @muness for the J414c (T6021) hardware check.

Evidence
  • J414s (10-core M2 Pro, Omarchy Linux, 7.3.0-t6020s2r+, apple_sleep.deep=1):
    • 4 consecutive hardware SLP_S2R cycles (boot object resumes 0 -> 4), including a 13h49m overnight sleep (18:12:23 -> 08:01:22, 95% -> 90%, ~284 mW sleep draw, keyboard wake MBSE 0x10030).
    • All 10 CPUs (clusters E 0xf P0 0xf P1 0xf), 194/252 AP GPIO pins, internal 13.5 DCP (3024x1964@120Hz + backlight), G14S GPU, NVMe ANS2, Wi-Fi, Bluetooth, SD, and MCA/TAS2764 audio return cleanly in ~0.48 s.
  • Independent J414s C50/C57 wake confirmation by @JJRPF (review above).
  • J414c (T6021) boot + 16 s s2idle row at ae08762a by @muness (comment above).
  • CI: 8/8 checks passing at ae08762a.

On Apple T6020 (M2 Pro, verified on J414s / system-fw 26.6.2, os-fw 13.5),
returning from hardware SLP_S2R via Aura requires four fixes:

1. Power-gate /arm-io/apcie domains in reverse ADT order (plus a 2 ms
   settle delay) before pcie_reinit_after_sleep() so the PCIe complex
   reinitializes cleanly after a power cut.
2. Skip pmgr_adt_power_enable("/arm-io/ans") on T6020; Linux's
   nvme-apple driver handles ANS2 reset and cold start on resume.
3. On unlocked-RVBAR SoCs (apple_sysregs_unlocked), rewrite secondary
   CPU RVBARs back to _vectors_start before returning to the OS, since
   SLP_S2R resets secondary RVBARs to their power-on defaults.
4. Restore clean HCR_EL2 (API | APK | E2H | RW) alongside SCTLR_EL2
   before jumping to the OS resume entry so Linux cpu_resume does not
   fault on PAC/EL2 handoff.

Tested end-to-end on J414s (M2 Pro 10-core) with full Linux desktop
deep sleep and wake (aurora-silicon/linux#3336).

Signed-off-by: Pim Jeursen <pim@green-dna.nl>
@patatman
patatman requested review from a team as code owners December 1, 2026 16:35
@patatman
patatman requested review from Acelogic and maralcbr December 1, 2026 16:35
@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks required sections (bot) labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Merge readiness at ae08762a: ready to merge

Check Detail
CI at head ok 8 checks passed
Review ok approved by satchlj
Requested changes ok none
Hardware row at head ok in the PR body at ae08762a
Conflicts ok none
PR text ok Risk: two-way · T6020 (apcie/ANS wake branch) and unlocked-RVBAR / EL2 Macs (secondary RVBAR rewrite + HCREL2 restore on smps2rreturntoos())

Areas: none matched in CODEOWNERS
Merge: gh pr merge 639 --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.

@JJRPF JJRPF 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 the diff (src/pmgr.c, src/pmgr.h, src/smp.c) and tested ae08762a on a second J414s (10-core M2 Pro, apple_sleep.deep=1 driver route):

  • pmgr_adt_power_off_reverse("/arm-io/apcie") + 2 ms delay, skipping pmgr_adt_power_enable("/arm-io/ans") on T6020, rewriting unlocked secondary RVBARs to _vectors_start, and restoring HCR_EL2 (API|APK|E2H|RW) alongside SCTLR_EL2 all look clean and match what Aura 130 needed on T6020.
  • In our C50 RAM-root test (ae08762a + apple_pmp.defer_commit=0), the J414s woke out of SLP_S2R and resumed cleanly through Aura into Linux apple_sleep_report() (0x7e, all 10 CPUs online, dpm_resume_noirq + dpm_resume_early complete) before hitting an older-branch nvme-apple resume issue in dpm_resume().
  • We are rebasing our kernel onto main + linux#3811 next and will follow up with a full Tested: verification row once WAKE_S=240 and 3x wakes pass end-to-end.

@muness

muness commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

J414c M2 Max (T6021) at ae08762a, as Stage 2 (Aura 1.0.0b18-gae08762a) with linux#3811's head (eef84285) and its t6021-j414c.dtb: booted to the desktop on -46 userspace, reported system firmware 27.2 / OS firmware 13.5, and went through an s2idle sleep of 16 s and back with 0 failed units. The wake path this PR changes didn't run: the apcie/ANS branch is T6020 only, and main has no T602x deep sleep to return through smp_s2r_return_to_os(). So this row covers boot on T6021, not the wake fixes.

@github-actions github-actions Bot added blast:m2 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks required sections (bot) labels Dec 2, 2026

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict: MERGE

Blockers: none (code clean, 8/8 CI checks passed, 0 conflicts, and exact-head hardware rows on two independent J414s M2 Pro machines plus J414c boot/s2idle regression check).

Checked:

  • src/pmgr.{c,h}: pmgr_adt_power_off_reverse() walks ADT devices in reverse order safely (handles n_devices == 0, skips missing/protected devices while propagating -1, power-gates each valid domain).
  • src/smp.c (smp_s2r_pcie_reinit()): on T6020, power-gates /arm-io/apcie in reverse ADT order with a 2 ms settle before pcie_reinit_after_sleep() and skips /arm-io/ans (handled by nvme-apple on resume), leaving other SoCs unchanged.
  • src/smp.c (smp_s2r_return_to_os()): rewrites unlocked secondary RVBARs (!(read64(cpu->impl_reg) & RVBAR_LOCK)) back to _vectors_start with dsb sy, and restores clean EL2h HCR_EL2 (API | APK | E2H | RW, clearing TGE | TEA | AMO | IMO | FMO set by exception_initialize()) alongside SCTLR_EL2 before returning to the OS.
Evidence
  • Head audited: ae08762a3b0e (mergeable=true, 0 conflicts).
  • CI at head: 8/8 checks passed (readiness ok).
  • Hardware rows at ae08762a: J414s M2 Pro (T6020) 4x consecutive hardware SLP_S2R deep sleeps (including 13h49m overnight ~284 mW) and full wakes (~0.48 s); independent second J414s confirmation by @JJRPF; J414c (T6021) boot + s2idle confirmation by @muness.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 2, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Status at ae08762a: local checks pass on the merge with current main (format, rustfmt, Stage 1/ESP size gates with gcc and clang, tests/run-*.sh, pytest). Hosted CI never ran, because the fork's workflows are waiting at action_required.

What's left before merge is one second-generation hardware row. The HCR_EL2 write at src/smp.c:712 isn't gated, so every EL2 S2R wake on every generation now resumes with TEA/TGE/AMO/IMO/FMO cleared. The J414s rows cover T6020, and the J414c row is s2idle only, which never reaches this path. We're running a J700 (T8140) hardware S2R cycle through the Aura mailbox at this head: all CPUs back online, no SError/undef/panic, 0 failed units. We merge once it passes.

Small one: line 712 could use the HCR_* macros instead of raw BIT() numbers.

@JJRPF

JJRPF commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

J414s MacBook Pro 14" M2 Pro (T6020) hardware row at ae08762a (Stage 2 1.0.0b18-gae08762a), paired with linux@main + linux#3811 + T6020 apple_sleep provider (apple_sleep.deep=1):

  • Sleep / wake: 7h 52m (28,400.8 s) genuine SLP_S2R sleep and clean wake (rc=0, boot object resumes 0 -> 1, T6020: macOS-off words on 4 before the pass, 0 after; coprocessors halted 0x8, AFR lowered, PCIe RC torn down).
  • CPUs & coprocessors: all 10 CPUs back online (0-9), apple_pmp resumed in 18.6 ms, apple_sep resumed in 9.2 ms, zero SError/undef.
  • Storage: NVMe 64 MiB direct read passed at 2.9 GB/s (0.0235 s).

(Tested on RAM-root usbtest with aurora GPU unbound; full desktop UKI row with GPU/display/camera next.)

@DjDeveloperr

Copy link
Copy Markdown
Contributor

J700 (MacBook Neo, T8140) S2R row for aura at exact head ae08762a3b0e: PASS

  • What booted: aura Stage 2 built at exact head ae08762a3b0e5c5a39041be722922b8abe5b9faf as 1.0.0b18-gae08762a. It used the fedora-aurora package's ESP Stage 2 flags (BUILDSTD=1 RELEASE=1 CHAINLOADING=1 ESP_STAGE2=1 USE_CLANG=1 BUILTIN_LOGO=aurora), and aura.bin has SHA-256 787d52254a8ef9496ecbb080b32d98140118732c76dd7d0f17c5a031844b6264. It went into a copy of the configured Stage 2 in place of its aura binary; the J700 DTB, gzip U-Boot and option lines are byte-identical to the live image. It booted once through aura Stage 1's aura-try marker as m1n1/j700-aura639-ae08762a.bin (SHA-256 ca094348e057fbd5217c43bb24d13fa4b1a99e11622d1110f91c2cf7ae376f44), with the stock kernel 7.3.0-41.fc44.aurora.aarch64 and its stock initramfs and BLS entry. Boot e7de4839-3665-489d-a450-a837b4c31c28, 2026-12-02T13:03:45Z.
  • The sleep: one RTC-armed rtcwake -m mem -s 30. On the J700, deep is apple-sleep's hardware sleep. Its wake resets the boot core into the boot object, and the Stage 2's RVBAR forward sends it to this aura. aura's smp_s2r_return_to_os() takes resume_pa from the S2R mailbox, counts it in resumes, restores SCTLR_EL2 and now HCR_EL2 (smp.c:712), and returns to cpu_resume. The kernel's back from sleep, boot object resumes N -> N+1 line is that counter. Automatic sleep stayed off (neo-no-idle-sleep.service).
  • Checks:
Check Result Detail
trial_stage2_running pass /chosen/aurora,trial m1n1/j700-aura639-ae08762a.bin, running Stage 2 1.0.0b18-gae08762a (expected 1.0.0b18-gae08762a; stock control ran 1.0.0b13-g5dcf62d0), image on the ESP as armed: yes
cpus_online_at_boot pass online 0-5 of possible 0-5 (nproc 6); stock 0-5
stock_control_sleep_via_mailbox pass stock Stage 2 1.0.0b13-g5dcf62d0: entry (deep), boot object resumes 0 -> 1, success 0->1, fail 0->0
s2r_resume_via_aura_mailbox pass rtcwake -m mem (s2idle [deep]): entry (deep), exit True, boot object resumes 0 -> 1 (aura smp_s2r_return_to_os), mailbox /chosen/aurora,s2r-mailbox 0000010005215440, success 0->1, fail 0->0, deep path False, wake NUB.SPMI0.SW3, wall 30.673 s
cpus_online_after_wake pass online after 0-5 (nproc 6); CPUn is up for [1, 2, 3, 4, 5], expected [1, 2, 3, 4, 5]
no_serror_undef_panic pass 0 line(s) this boot (stock control 0)
no_warn_bug_oops pass 0 line(s) this boot (stock control 0)
failed_units_zero pass 0 after the wake (stock control 0)
no_new_errors_vs_stock_sleep pass 12 err-level kernel line(s) this boot, 0 not in the stock control boot with its test sleep
  • Stock Stage 2 control on the same Mac (taken just before arming, same cycle):
Stock Stage 2 aura ae08762a3b0e
Stage 2 1.0.0b13-g5dcf62d0 1.0.0b18-gae08762a
/chosen/aurora,s2r-mailbox 00000100068f0240 0000010005215440
CPUs possible 0-5 0-5
online before 0-5 0-5
online after 0-5 0-5
mem_sleep s2idle [deep] s2idle [deep]
suspend entry (deep) (deep)
boot object resumes 0 -> 1 0 -> 1
deep path line False False
wake source NUB.SPMI0.SW3 NUB.SPMI0.SW3
CPUn is up 1, 2, 3, 4, 5 1, 2, 3, 4, 5
wall s 30.616 30.673
  • Return: the next reboot ran the configured Stage 2 again (marker spent, no /chosen/aurora,trial). s2-trial.sh remove then reported restored: m1n1/boot-ctxr.bin sha256 71a44f37ee04ab671e5042e7333f04c678a0b466496c2b8c4c1d4c3db21e17a1 (byte-identical to before), marker none, m1n1/j700-aura639-ae08762a.bin removed, neo-s2-trial-fallback removed.

@JJRPF

JJRPF commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

J414s (MacBook Pro 14" M2 Pro, T6020) update at ae08762a (boot-test.bin.port6 8cd452070cb8f128), paired with linux@main (t6020-s2r-main b97dc3fa63a8):

  • C65 (3x back-to-back SLP_S2R): 3/3 cycles PASS (21.24 s, 24.53 s, 23.90 s, rc=0, all 10 CPUs 0-9 online, WARN=0, NVMe 2.9–3.2 GB/s).
  • C66 (100% zero-unbind SLP_S2R): PASS (wall=31.5195 s, rc=0, online 0-9, WARN=0, NVMe 3.0 GB/s) with G14S GPU (aurora 406400000.gpu warm restart kick Ok(())), PCIe Wi-Fi (brcmfmac), BT (hci_bcm4377), SDHCI (sdhci-pci), and #3660 ISP DART all remaining bound across sleep.

Full desktop UKI + camera verification is next.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at ae08762a3b0e (B2 merge train, 12-01 merge bar). Approval at this head: satchlj. Row: T6020 S2R wake row in the PR body at ae08762 (patatman). CI: hosted CI 8/8 green + local aura train A10 (gcc normal+ESP_STAGE2 pass, CI-gcc 13.3 esp-stage2 headroom 4760 B >= 4096 floor, pytest 1823/0 pass). Revert: git revert -m 1 <merge commit>.

@RyanTheTide
RyanTheTide merged commit fd17182 into aurora-silicon:main Dec 2, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blast:m2 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.

6 participants