Skip to content

soc: apple: T6040 (M4 Pro, J616s) hibernation - #2977

Open
fbalazsy wants to merge 145 commits into
aurora-silicon:mainfrom
fbalazsy:t6040-hibernation
Open

fbalazsy wants to merge 145 commits into
aurora-silicon:mainfrom
fbalazsy:t6040-hibernation

Conversation

@fbalazsy

@fbalazsy fbalazsy commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What: hibernation (suspend-to-disk) on the T6040 (M4 Pro, J616s), on top of the suspend-to-RAM work in #2215 (merged in): the PM core and arm64 restore path, a reset backstop the platform provides for the time the machine is off, and the Apple co-processors, display, GPU, radios and USB brought back after a restore. Current main is merged in.

Tested: J616s (T6040) at c06cbf3db847 (one cycle after the fourth main merge: rc 0, 40.9 s, compositor kept, three displays back, no oops), e5528b627c5b (rc 0, 40.7 s), c80d78247f3d, ee3faca0f8c0 and 1c1f3522ce39 (same tree but the last commit), 8d5d52f55c0d (two cycles in a row) and 5f4a9facdab3, Stage 2 from aurora-silicon/aura#653 at 32ad0c30 and f3e85867 with this head's DTB, a full power-off cycle (systemctl hibernate, power-off, cold boot, image load): the restore completed (rc 0, 37.9 s from the hibernate call to the restored desktop), the backstop disarmed after the restore and the normal watchdog running, no oops, the SIO firmware booted again (DP and HDMI audio play), OpenGL renders, Wi-Fi, wired network, Bluetooth and the three displays (panel, HDMI, DP over Type-C) back, USB camera frames before and after. The SIO and r8152 changes were also run at the head before the history cleanup (same tree for them). Builds without new warnings, checkpatch.pl --strict clean on the kernel commits, dt_binding_check and dtbs_check clean for the watchdog binding and the T604x boards, the host tests fail only where main fails on the same toolchain.

Risk: one-way (adds DT bindings and properties) · M4 Pro; the shared parts (PM core hibernation, arm64 hibernate, RTKit, DART, DCP, SIO, GPU, brcmfmac, hci_bcm4377, xhci, the Apple watchdog) run on all Macs. The Apple watchdog's T6041/T6050/T8142 match-data fallback for the reconfig and deadline registers is gone: they now come only from the DT, so a DT without them keeps the old watchdog behaviour and has no hibernation backstop. The SIO firmware comes back after a restore only when the boot that loads the image did not bind the SIO (it has no users there); otherwise the SIO stays off until the next boot, with one warning.

Not yet:

  • other Macs (none here with these blocks).
Details

PM core / arm64.

  • durable image signature handling; drivers are told whether a restore went through; platform code can veto hibernation;
  • the loaded image and the copied pages are cleaned to the PoC for non-coherent masters, page by page while the loader waits for the next one (the single pass after the load took 0.54 s on one CPU for an 8.5 GB image);
  • platform hooks for nosave ranges and a boot-layout cookie in the image header (a restore under another layout is refused);
  • spin-table secondaries that cannot be powered off wait in a nosave pen outside the image;
  • after a suspend-to-RAM the boot CPU comes back confined to the CTXR execute window; the exit code now runs from a page-aligned nosave page in the kernel image while a window is active (before, a restore after a suspend-to-RAM stopped in the jump to a get_safe_page() trampoline);
  • PM: hibernate: take the reset backstop from the platform: a platform driver registers arm/disarm callbacks for a reset backstop that covers the power-off and the image load; arming failures are logged and the hibernation continues;
  • image write and read times are reported; test_resume clears a latched wakeup before the restore and frees the image's swap pages when a restore fails;
  • the image's swap pages are released on an error path only after the signature is durably cleared; if that fails they stay reserved until the next boot, so no later boot resumes an image whose pages were reused (host test with injected read, write and flush errors).

Watchdog (restore backstop). The Apple watchdog provides the backstop: before the image is written it programs the SMC AP deadline (150 s), which resets the machine if the restored kernel never comes back, and disarms it after the restore. The reconfig and deadline registers are described in the DT (reg-names "reconfig" and "deadline" in apple,wdt, set in t604x.dtsi) instead of per-SoC match data; the deadline is used only with the reconfig register present. The backstop is kept running only across .freeze/.poweroff; a suspend-to-RAM stops the watchdog as before.

Apple SoC. A fixed boot layout under aura (DT binding aura,hibernate); RTKit sessions handed over or re-adopted after a resume; PMP, DART locked roots, SMC, macsmc-reboot, RTC, cpufreq, ANS NVMe, ANE, AOP (started again after a resume from disk).

Display (DCP). DRM state suspended for hibernation, in-place firmware restart, bounded retrains, T604x displays taken down for hibernation, PHY state kept in a restore without power loss; a DCP's DART restore is deferred to its firmware restart.

GPU and SIO. The GPU firmware is started again by the restored kernel. On T6040 (hib_keep_clients) the client VMs carry over that cold boot: only the firmware-side context slots and queue records are dropped, and each queue is rebuilt on its VM, with its original QUEUE_CREATE arguments, before its next submit. Running clients such as the compositor carry on without seeing a lost device. Other SoCs still report a lost device. The SIO firmware boots after a restore only when the boot loader staged it and left it halted: a firmware that the loading kernel started does not take a second boot, so that kernel idles it before the jump and leaves its run bit set, and the restored kernel then leaves the SIO off. The kernel-window tables are copied in one pass after the restore.

Camera (ISP). A firmware that can restart (apple,dapf-ranges on its DART) is no longer marked dead by hibernation; the text CRC of the resident firmware is recorded at the freeze and the restore starts it again unless the loading boot left different firmware text there.

Sleep after a restore. aura's S2R mailbox moves with the boot object on every boot; after a resume from disk the sleep driver takes the running boot's mailbox from aura's DT, or refuses deep sleep until the next boot.

Radios and USB. brcmfmac PCIe keeps the D3 handshake on freeze and probes the chip again on restore; hci_bcm4377 quiesces and rebinds; r8152 stops resubmitting rx on -ESHUTDOWN; xhci skips the ep0 max-packet check while a slot is only enabled (the invalid context state for evaluate context command WARN on every restore is gone).

Merges of main. main is merged in four times. The second merge had one conflict, in the display26 host test, where both sides' new assertions are kept. The third had conflicts in clk-apple-nco (the hibernation save/restore now uses main's register helpers), tas2764, hci_bcm4377, DCP, asahi mmu/pgtable and three host tests, all keeping both sides. The fourth had one conflict, in the g17 init data build, where the branch's split of the graph build is kept and main's coarse base OPP flag from active_effort() is taken.

Since the last push.

  • dmaengine: apple-sio: boot the firmware after a restore only if staged (see above);
  • net: usb: r8152: treat -ESHUTDOWN like -ENODEV on tx and interrupt resubmission: no more failed tx_urb -108 and can't resubmit intr floods when the hosts stop for the image;
  • from soc: apple: T8142 (M5, J815/J813) hibernation support #4187 by @m0d16l14n1, cherry-picked with his authorship: the DockChannel IRQ mask restore and receive guard after a restore, and the RTKit mailbox hardware enables restored on reinit;
  • a host-test stub for the RTKit change.
  • usb: hub: stop resetting a port once its host controller is gone (no cannot reset (err = -108) bursts when the hosts stop for the image);
  • HID: dockchannel: resynchronise the receive ring after a restore from disk (no Receive ring failed: -71 after a restore).
  • from soc: apple: T8142 (M5, J815/J813) hibernation support #4187 by @m0d16l14n1, cherry-picked with his authorship: AIC global config, cluster power gates and MCC, DVFS and charge limit, I2C/SPI/PWM, apple-msi, Thunderbolt keep-alive quirks, SEP rebind only on a cold restore, ADMAC, NCO, DCP freeze pause and the poweroff double-suspend fix, ANE H17, tipd sn201202x, PMC voters, codec/amp, MCA and the PMP report replay (the last three with small conflict resolutions).

Known. Touch ID matching is unavailable after a restore as after any cold boot on this branch (it is not a hibernation change). A UAS disk on a Type-C port logs Synchronize Cache(10) failed: ... DID_ERROR (info level) when the hosts stop for the image, as for a cable unplug of that disk.

This series includes #2215 and the commits from #1664 by @AxxzyWasTaken and the PHY commit by @RyanTheTide that #2215 carries, with their original authorship.

Evidence (earlier rows, test_resume).

Case Result
Fresh boot, test_resume 3/3 + 3/3 + 1/1
test_resume after S2R (with the CTXR fix) 2/2: after one S2R, and in a run of 4 S2R, 3 aborted restores, a full restore and 2 more S2R
xhci WARN on restore was on every restore, now 0
#2215 S2R regression check (8e9af804) 5/5
Camera after test_resume (6cf6a028) 5/5 frames
S2R after test_resume (6cf6a028) 1/1, no HPD drop, three displays, network and camera back
test_resume, S2R 5/5, test_resume again (718c3ceb) all passed, no new errors

@RyanTheTide

Copy link
Copy Markdown
Contributor

@fbalazsy checking open drafts today. To come out of draft, this still needs:

  • It conflicts with main. Merge main in or rebase (no force push needed: a merge commit is fine).
  • Then a test run at the final head on a Mac with the hardware it touches, and mark it ready for review.

If it's no longer needed, say so here and we'll close it. Otherwise it stays open as a draft until these are done.

@fbalazsy

Copy link
Copy Markdown
Contributor Author

Merged forward without a force push, as suggested: #2215 at 48a9c70 (which carries main) and then main at 00fbe80 are merged in. The merge commit lists the conflicts and how each was resolved. Since then main has moved by 6 commits (t6050 DisplayPort audio DT, macsmc restart priority); they merge without conflicts.

f43d634 adapts eight host-test harnesses that stopped compiling because of new hibernation calls and fields (DCP hibernation gates, the in-place IOMFB restart arena, __bcm4377_suspend(), the DART locked-root fields, the PMP restore notifier, PM_SUSPEND_ON in the PMU RTC). Where the harness can check the new path, it does (arena reused and cleared, notifier registered and dropped, alarm not refusing hibernation). No driver change.

Local results at f43d634:

  • Host tests: everything this series touches passes. The only remaining failures, g15 and sep-suspend-errors, are a Rust toolchain and link problem on my runner and fail the same way on main 00fbe80.
  • arm64 KUnit: ane-boot 304/304, ane-pm 20/20, DCP fabric 117/117, DCP topology 208 passed + 1 skipped, DCP display 168 + 1 skipped, macsmc 40 + 1 skipped, ISP 59/59, Apple SoC sleep 18 + 1 skipped.

f43d634 J616s (M4 Pro, T6040), test kernel built from d9b8558 (the same kernel tree; f43d634 only changes test files): cold boot, then 2 suspend/wake cycles, both rc=0 with no new warnings. eDP, DP and HDMI were connected and enabled after each wake, the USB tree was unchanged and dock Ethernet came back. The hibernation pm_test levels freezer, devices, platform, processors and core all returned 0, with the outputs and Ethernet back after each one. The devices level logged -71 reset errors on one dock hub port and the usual "not suspended yet" hub notes.

Not tested at this head: a real hibernation image (power-off cycle or test_resume). The boot loader on this machine does not currently publish /chosen/aura,hibernate-layout (aura#66 is not in current aura), so the kernel refuses to create an image. This stays a draft until a full cycle has run at the final head with that boot loader support in place.

@fbalazsy

fbalazsy commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Status, still a draft.

Head ad8e3b8d is #2215's current head (0f47f270, which carries main at ed00bd11) merged in, then main again (no changes). Plain merge commits, no force push. The conflicts are gone: it was CONFLICTING against main, and the merge with main 4ffd63af and the one with #2215 c2c9e3da before it were clean. ed00bd11 brought a conflict in the T6040 PHY recovery counts, which I resolved on #2215 first (its merge commit says how).

Build and tests at this head

  • KUnit (arm64, LLVM): T6040 USB2 PHY + ATC PHY + sleep + hibernation config, 96 passed, 1 skipped. At the previous head 8d753604 also: ane-boot 307/307, ane-pm 20/20, dcp-fabric 117/117, topology 209 (+1 skipped), display 168 (+1 skipped), macsmc 40 (+1 skipped), isp 59/59.
  • Host tests at 8d753604: the same 26 failures as main and the soc: apple: sleep: T6040 (M4 Pro, J616s) suspend-to-RAM #2215 head on this machine (environment, not this series).

Hardware (J616s, T6040, 8d753604 built, booted one-shot)

  • Boot with the boot loader's hib=1 layout (aura#148, already in the installed aura): /chosen/aura,hibernate-layout and aura,hibernate-dt are published, the fixed layout is accepted ("38 reserved ranges kept out of the image"), and disk appears in /sys/power/state.
  • pm_test dry runs freezer, devices, platform, processors, core: all pass with hib=1, run one by one and as one sequence, displays (eDP/DP/HDMI) and Ethernet stay up. One earlier run reset the machine at the platform level; I could not reproduce it in two further runs of all five levels and have no log of it, so I count it as an open flake rather than a pass.
  • Deep S2R, 2 cycles with hib=1: pass, 3 displays and network back.

Correction to the first version of this comment: I wrote that hibernation stays blocked. That is only so without the fixed layout. With hib=1 the platform check lets it through (disk lists shutdown reboot suspend test_resume), and the dry runs above ran that way. The real image write, the restore (test_resume, and a reboot-mode cycle through the boot chain) and the power-off cycle are being run on this head next; the results follow in a comment here. aura#66 is closed and superseded by #148, so no new boot loader is needed for the layout.

It stays a draft. Next: the full cycles on this head, then the lab row.

The kernel hibernates on Apple silicon only where the boot object says,
in /chosen, that it keeps the same memory layout on every boot, and it
reads the device tree of the resuming boot at the address the boot
object gives there. Neither property had a binding, and their prefix
was not a registered one.

Register the prefix and describe the two properties. The prefix is the
name of the boot loader that defined them, as u-boot's is: its released
versions publish the properties under this name, so a kernel that
looked for another one would not hibernate with any of them.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit c2119e1)
A REQ_SYNC write can sit in a volatile device cache, so the signature
reset at resume and the end of the image are not on the medium when the
write completes. A power loss after the restore then resumes the same
image again, or the image is incomplete.

Write the signature reset with FUA, flush the image in
swap_writer_finish() and fail the hibernation (dropping the signature)
when the flush fails. Once the image is in memory, clear the signature
again before the devices are restored, so a restore that hangs cannot be
resumed into a second time.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit faaf017)
The devices of a kernel restored from an image get PMSG_RESTORE whether
the image was loaded by another boot (the firmware and the boot loader
reset the hardware) or by the kernel that wrote it (test_resume: the
hardware kept its state). Drivers of devices that a boot resets need to
tell the two apart.

The kernel that loads an image leaves a record in the no-save section,
which the image neither saves nor overwrites, and the restored kernel
reads it: pm_hibernate_restored_cold() returns 1 after a load by another
boot, 0 after a load of the own image. pm_hibernate_is_restored() says
whether the kernel was restored at all, and pm_hibernate_is_loading()
whether this kernel is loading an image, so freeze callbacks can tell a
quiesce for the jump into an image from a freeze for an image of their
own. A hibernation aborted before the image exists resumes the devices
with PMSG_RECOVER.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 394d4a1)
Hibernation is refused on every Apple platform, because the drivers of
their co-processors have no path to rebuild their state after the cold
boot of a restore. Add hibernation_set_platform_check() so platform code
can tell when that is handled for the running boot. Without a registered
check Apple platforms keep refusing images as before.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 3891bc4)
Most image pages are loaded straight into their original frames through
the cacheable linear map, not through the copy loop. Add an architecture
hook, called for every valid image frame once the whole image is loaded
and while the list of those frames is still intact, and implement it on
arm64 by cleaning and invalidating the page to the PoC. Frames outside
the boot kernel's linear map are left to the copy, which cleans them.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 7089f48)
swsusp_arch_suspend_exit() cleans every copied page to the PoU, which is
enough for instruction fetch but not for DMA masters that do not snoop
the CPU caches. A later eviction of a dirty line can then overwrite what
such a device wrote since the restore. Clean to the PoC instead.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit d98e601)
…ayout

The image restores every page to the frame it came from, so the boot
that resumes it must give the kernel what the boot that wrote it did:
the same RAM, the same CPUs started the same way, and any fixed layout
of the boot loader. The kernel build check of the image header cannot
see these.

Let one platform register hooks: pfn_nosave() keeps ranges that the boot
owns out of the image, and layout() mixes the platform's boot facts into
a boot layout cookie that is stored in the image header next to the
memory regions and the spin-table release addresses. A restore under
another layout is refused.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 54d9b8e)
…ernation

Spin-table CPUs cannot be powered off; a parked CPU spins in kernel text
that the boot kernel overwrites while it loads an image. Let them wait in
a small pen outside the image instead, entered with the image's page
tables, and have the restored kernel release them from it. A boot CPU
whose node has no enable-method is treated as one that can leave the
kernel.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit b6838fb)
… sleep

A guest's counters are the physical counter minus an offset fixed when
the VM is made. The physical counter starts again across a resume from
disk, which is a cold boot, so the guest's counters fall back and its
clock stands still until the counter has caught up.

Record the counter at syscore suspend and, if it went backwards at
resume, move the offsets of every VM by what it lost, so the guest's
counters continue as for a VM that was stopped that long. A counter that
keeps running through the sleep is left alone.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit ac2fa3d)
A co-processor that stays up across a resume from disk keeps the shared
buffers of its session, which the restored kernel has to adopt. Add
apple_rtkit_describe_buffers() and a small hand-over area in the no-save
section in which the boot kernel leaves, per tagged session, what the
restored kernel needs to take it over.

Also let the polled power-state exchange used with interrupts off put the
co-processor to idle for clients that stay up, and add
apple_rtkit_reinit() to the Rust bindings.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit f986895)
The boot kernel of a resume from disk holds RX of an adopted session and
hands it over with its buffers; the restored kernel adopts it again in
.restore. A self-started session is left for a reload, and a
co-processor that the boot left halted is released without a handshake.
Add .thaw and .restore callbacks and apple_rtkit_helper_readopted().

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit c8d3761)
aura publishes /chosen/aura,hibernate-layout on a boot whose memory
layout below Linux is the same on every boot, and copies the device tree
of each boot to the slot named by /chosen/aura,hibernate-dt.

On such a boot, keep every /memreserve/ and non-reusable /reserved-memory
range except the kernel image out of the image, add the layout and the
boot facts of /chosen to the boot layout cookie, and let hibernation
through. Without the property hibernation and resume stay refused on
Apple platforms. Also provide this boot's /chosen values and a deferred
re-probe for drivers whose co-processor the resuming boot left halted.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 74accee)
After a resume from disk through a boot the boot loader has cold-restarted
the PMP (its image resident in SRAM, the co-processor halted) and nothing
replays the probe-time bring-up, so the firmware stays down: the display
gate and cpufreq wait for a PMP that never reports running. The module
cannot be reloaded, since the power-vote bridge is retained until reboot.

Rebuild the session in place on PM_POST_HIBERNATION, the event the
restored kernel sends (PM_POST_RESTORE only reaches the loading kernel when
it fails to restore), from a notifier registered ahead of every consumer's
restore notifier (ANE, DCP, GPU). The decision follows the co-processor's
run bit, the state the loading kernel or the boot left: a running firmware
(restored by the kernel that wrote the image, or an aborted hibernation)
is left alone; a halted one gets its RTKit session reinitialised, its SRAM
boot arguments patched again and the boot handshake driven as at probe.

The notifier is registered outside pmp_lock, since the notifier chain lock
is taken around the callback, which takes pmp_lock. The revocable MMIO
guards are held only around the register accesses: they hold an RCU
read-side lock, which must not be kept across the sleeping RTKit
handshake.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 0833903)
…m disk

A resume from disk through a boot finds every locked DART locked again by
the boot loader with fresh firmware-owned roots, while the restored kernel
still describes the roots of the image (their mapping, their firmware
snapshot and the slots it had published). Every publication then fails
with -EBUSY, and with it every DMA mapping through the DART; on the M4 Pro
the PMP and every DCP failed their buffer requests with -ENOMEM.

Remember the physical address of each mapped locked root and the page
table configuration last published into each locked stream. In .restore,
read the live roots back: a root that moved is re-imported the way attach
maps it, in two passes as attach does (every stream's roots are re-read
and snapshotted before any of them is republished, so a root shared by
several streams is snapshotted before Linux slots enter it), then the
stream's page tables are published into it again. A root that did not
move, as when the kernel that wrote the image loads it, is the one the
image describes and is kept. Firmware-owned memory is never written: the
old roots' published slots are forgotten, not retired. A failed stream is
logged and does not fail the whole restore.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit b7fa3a1)
After a resume from disk the RTKit session the restored driver describes
is not the one the SMC is in, and every SMC command times out (battery,
keyboard and trackpad preflight, power-off).

The kernel that loads the image binds this driver like any boot and holds
a live session when it jumps into the image; the restored kernel then asks
the firmware to start and waits for a HELLO that a firmware already in a
session never sends. Following Documentation/driver-api/pm/devices.rst,
leave the restored kernel a defined state:

- the loading kernel (pm_hibernate_is_loading()) quiesces the SMC in
  .freeze, the state the normal teardown leaves it in, from which a wake
  starts a new session. A failed quiesce still enters the image, whose
  signature is already gone; its restore tries a new session;
- .restore reinitialises the RTKit transport, replays probe's bring-up
  handshake, re-reads the key count and re-arms the notification flag,
  the same whether the loading kernel wrote the image or was booted;
- .thaw after a hand-over that could not enter the image starts a new
  session the same way.

Probe's handshake and key count read move into helpers both use.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 216072f)
…effect

The next power-off handler is PSCI SYSTEM_OFF. Under a boot monitor
without a power-off path it resets the machine instead, so a slow or
refused off1 must not fall through after only 100 ms: the image written
for hibernation would be resumed at once, or the machine would reboot
instead of powering off.

Retry a refused off1 up to three times, and give an accepted one five
seconds before warning and falling through.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 6ea1f04)
The prepare callback refuses every transition that is neither
suspend-to-idle nor a firmware-driven suspend, because only those keep
a way to bring the alarm back. Hibernation runs the same callback for
its freeze, but with no suspend target set, so it is refused as well:
on the M4 Pro (J616s) a hibernation pm_test run stops at this device
("apple_pmu_rtc_prepare returns -16") before any device is frozen.

A hibernated machine comes back through a cold boot, which needs
nothing from the alarm. Refuse only a suspend state that cannot keep
the alarm, and let a transition without a suspend target through.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 0c1fbf5)
…P stops

A resume from disk restarts the PMP after it had run. The fast
die-temperature wait then reported the PMP as late, measured from the
first boot. Start the wait, and its warning, over when the PMP stops.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 0148e6b)
On post-M4 ANS a resume from disk through a boot is a cold boot: the boot
firmware restarted ANS, the boot stages kept it running, and the loading
kernel adopted that session to read the image. In the restored kernel
anv->rtk describes a firmware instance that no longer exists, and the live
session on the mailbox has never been adopted by this kernel.

Give the driver explicit hibernation callbacks: freeze and poweroff
disable the controller and keep the session like suspend, thaw resumes.
A .restore through a boot (pm_hibernate_restored_cold()) stops the
controller first (until CC.EN is clear the firmware may fetch from the
loading kernel's queues), releases the stale session without a shutdown
handshake (the new instance would receive it), checks that a running,
booted, enabled-off controller is there and adopts it, as probe adopts
the boot loader's session, before the usual resume. A failure
quarantines the controller. A .restore from the kernel that wrote the
image finds the controller as its .freeze left it and resumes.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 594d672)
An H16 engine whose firmware has been started refuses hibernation and
restore from its PM notifier, even on a platform that sleeps it cold.
On the M4 Pro (J616s) that refusal is the first thing that stops a
hibernation pm_test run, before the freezer level is reached.

The cold cycle leaves nothing of the old firmware behind: the engine is
powered off with nothing in flight, and after the transition the
firmware boots again from the preload and every open program is
replayed. Across suspend this already runs on the J616s ("powered down
for system sleep", then "resume ok: cold" after every wake). An image
needs no more than that, so on a platform without a warm sleep map
PM_HIBERNATION_PREPARE and PM_RESTORE_PREPARE to the suspend prepare
step and PM_POST_HIBERNATION and PM_POST_RESTORE to the wake step.

A platform that sleeps the engine warm keeps firmware state across the
transition that an image cannot carry; there both stay refused.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 78dac96)
The DCPs freeze and thaw through their system sleep callbacks, but the
DRM device had only .suspend and .resume. A hibernation freeze therefore
stopped the display firmware under an active mode configuration: the
HDMI link of the external DCP went down in .freeze, the CRTC was never
committed again on .thaw, and the HDMI output stayed disconnected until
the next suspend and resume.

Use the system sleep callbacks for the hibernation phases as well, so
the DRM state is saved before the DCPs stop and committed again after
they restart, as for suspend to RAM.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 1d4dbc5)
Only the H17P handler marked a buffer mapped for piodma. On desktop 26.x
the mark was never set, so neither a release nor the session drop after a
resume from disk took the translation down, and the second resume from
disk in one boot failed every piodma mapping with -EEXIST: no picture on
the internal panel. Mark it there too, and refuse an unmap of a buffer
that is not mapped, as on H17P, instead of reaching the page table.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit dbbd96e)
…ttached

Without a sink the firmware's probing of a DP port fails by design, which
logged a warning on every external processor start, including each
restart after a resume from disk. Log those at debug level and keep the
warning when a sink is attached.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 4e27f7d)
…from disk

A resume from disk is a cold boot: the boot loader restarts the DCP
firmware and lights the panel with its boot framebuffer, while the
restored driver still holds the session of the previous firmware
instance. Until now the driver had no hibernation callbacks, and the
display was lost until a reboot.

Rebuild the session in place, the way probe builds it, for the desktop
26.x internal DCP and for the T6041 external display processors:

- prepare (hibernation only): stop the link work and the HDMI HPD
  interrupt, stop a merged dual pipe as a pair, and give the external
  display link and the DP PHYs back as at a runtime unplug, since the
  cold boot resets the PHY and the image must record it off;
- freeze: hold RTKit receive, so whatever the new firmware sends before
  .restore stays in the mailbox instead of reaching the old session;
- restore_early/restore: drop the old session on the host side (mode
  invalid, endpoints quiesced, IOMFB channels, firmware mappings, retained
  framebuffers and pending flips released; DMA only after the DARTs are
  restored). From here the DRM entry points leave the firmware alone and a
  flip completes without a swap; a shown external display is reported
  gone so that its return is a hotplug;
- PM_POST_HIBERNATION, after the PMP is rebuilt and before the GPU drain,
  in a work item: run the co-processor, reinitialise RTKit and start the
  firmware as probe does, power the pipe on and commit the current DRM
  state. External processors with a display wait until every external
  processor runs, so a display wider than one pipe finds its peer, and
  then connect their link through the runtime hotplug path; the HDMI
  converter is powered again when the link comes back.

Every devm allocation, the DMA arena (cleaned to the PoC before the
restart), the IOMMU mappings, clocks and registers are reused; no probe
primitive runs again. The old endpoint objects stay allocated until unbind
(a bounded leak per resume) because their services may still be
referenced. Any failing step falls back to the previous behaviour: IOMFB
traffic stopped, display left to the boot loader, until the reboot. The
teardown at the hibernation power-off is skipped, since the firmware's own
power sequence may crash the DCP; the panel keeps the last frame until the
machine powers off. If the hibernation fails, PM_POST_HIBERNATION replays
the external links once every DCP is thawed.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 0dfc337)
A sink that drops its link and raises IRQ_HPD after every training (seen
with a dual-pipe monitor after a modeset from the kernel console during a
hibernation entry) turns each hotplug into a retrain and each retrain into
a hotplug, every 0.4-1.2 s, until the Type-C controller gives up on the
cable.

Retrain at most DCP_HOTPLUG_RETRAIN_MAX times in a
DCP_HOTPLUG_RETRAIN_WINDOW that starts with the first retrain and is not
extended by refused requests; at the end of the window one more retrain
is tried. A real replug resets the bound. Past the limit the link status
stays as it is and userspace still gets the hotplug events.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 1836402)
Hibernation restored the display firmware with a new handshake only, which
assumes the boot loader started it anew. A restore by the kernel that wrote
the image (test_resume) finds the firmware still in the session it ran on
after the image was taken, and the handshake times out on every DCP:

  RTKit: endpoint discovery failed: -62
  hibernation restore: firmware restart failed at start (-62)

Per Documentation/driver-api/pm/devices.rst, .restore has to cope with
whatever state the loading kernel left. Stop the display firmware at
.freeze with the stop the suspend-to-RAM path already uses on the T604x
display complex (dcp_t6041_s2r_all(), selected by the apple,display-power
node), so the image holds it stopped by Linux, and keep it stopped through
the image write, as amdgpu's .thaw does: .thaw brings it back only when
the hibernation failed (pm_hibernate_is_recovering()) or the machine
suspends instead (pm_hibernation_mode_is_suspend()), and
PM_POST_HIBERNATION does when this kernel goes on after anything else.
The firmware then is in exactly the state the image describes:

 - a .restore by the kernel that wrote the image (test_resume), or after
   a failed power-off, takes the sleep's warm return;
 - a .restore through a boot (pm_hibernate_restored_cold()) powers the
   domains and DARTs the same way, then gives the firmware the boot loader
   started the new handshake after PM_POST_HIBERNATION.

A thaw that restarted the firmware for the image write left it in a
newer session than the image: the restored kernel's warm return then
crashed all three DCPs with ASSERT afk_messenger_common.c:67.

The link release at hibernation prepare is not needed then, as the stop
takes the external links down itself. Factor the host-side session drop
into dcp_hib_drop_session() for both restore paths.

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 223277a)
A test_resume load restores the image in the kernel that wrote it: the
SoC was not powered down and the PHY, its coprocessor and the DP and USB
sides its consumers kept are as the image records them. Resetting that
state, as after a resume through a boot, made the DP side of a Type-C
display look down while the display controller still held it, and the
next mode set of that display failed.

Only reset the state, and the coprocessor's RTKit session, when
pm_hibernate_restored_cold() says the restore went through a boot (or
cannot tell), as a resume from a sleep does only after the firmware took
the SoC down (pm_resume_via_firmware()).

Signed-off-by: fbalazsy <frantisekbalazsy@gmail.com>
(cherry picked from commit 2786460)
@RyanTheTide

Copy link
Copy Markdown
Contributor

The App approval at e5528b62 stands, and the J616s row is in the body. GitHub now reports a conflict with main. Could you merge main into the branch (a normal merge commit, no force push)? After that it only needs a counted Core review to land.

Conflict in drivers/gpu/drm/asahi/g17/initdata.rs: keep the branch's
build_graph() split (env passed by reference, reuse accounting) and take
main's (active_effort, coarse_base_opp) pair from active_effort().
@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Dec 4, 2026
@fbalazsy

fbalazsy commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@RyanTheTide Done: main is merged in with a normal merge commit at c06cbf3db847 (no force push), and the PR is mergeable again. The one conflict was in g17/initdata.rs. I kept the branch's split of the graph build and took main's coarse base OPP flag from active_effort(). The build adds no new warnings, checkpatch.pl --strict is clean, and the host tests fail only where main fails. Because the merge touches the GPU init path that runs again after a restore, I ran one more J616s cycle at this head: rc 0, 40.9 s, compositor kept, three displays and OpenGL back, no oops. The Tested line and the merge note in the body are updated.

@github-actions github-actions Bot added merge-conflict Conflicts with the base branch (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Dec 4, 2026
Conflict in drivers/soc/apple/sep.rs: keep the branch's hibernation
endpoint fields (hibe_rx, hibe_wq, hibernating, sep_unusable) and take
main's /dev/sep-pnon fields (pnon_serial, pnon_dev, pnon_open, pnon_txn,
pnon_signed, pnon_owner).
@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Dec 4, 2026
@fbalazsy

fbalazsy commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@RyanTheTide Done: main is merged in with a normal merge commit at ebfde6543da1e (no force push). The one conflict was in drivers/soc/apple/sep.rs. I kept the branch's hibernation endpoint fields (hibe_rx, hibe_wq, hibernating, sep_unusable) and took main's /dev/sep-pnon fields (pnon_serial, pnon_dev, pnon_open, pnon_txn, pnon_signed, pnon_owner). The build succeeds with no warnings from that file, checkpatch.pl --strict is clean on the resolution, and the hibernation signature host tests pass (6/6).

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-up check at ebfde654: the only hand-resolved file is drivers/soc/apple/sep.rs, against #4279 (/dev/sep-pnon). Both SepData field sets are kept, in the struct and in the pin-init list: the pnon_serial/dev/open/txn/signed/owner fields from main and this branch's hibe_rx/hibe_wq/hibernating/sep_unusable. Every other file in the merge matches the automatic merge. CI is green at this head. The App approval at e5528b62 still covers the branch's own code. Still needed: a hardware row at ebfde654 and a counted Core review. One follow-up for after merge: /dev/sep-pnon requests don't check sep_unusable after a hibernation resume yet.

@fbalazsy

fbalazsy commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@RyanTheTide Thanks for the merge-up check. Agreed on the follow-up: pnon_call() does not consult sep_unusable, so after a hibernation resume whose enclave re-boot did not finish, /dev/sep-pnon can still send a request and wait out the timeout. I'll take that after merge. A hardware row at ebfde654 is still outstanding.

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Dec 4, 2026
@fbalazsy

fbalazsy commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@RyanTheTide Hardware row at ebfde654: J616s (T6040), a kernel built from exactly this commit (clean tree, no local patches), Stage 2 from aurora-silicon/aura#653 at 32ad0c30 with this head's DTB (the merge changes no T604x device tree), one full cycle through the boot chain (image written, restart, image load).

  • The restore completed with rc 0, 33.3 s from the hibernate call to the restored desktop. The backstop was disarmed after the restore (SMC AP deadline disarmed, WD1 running).
  • Image signature: the swap header held no image signature before the write and none after the resume. The boot before the write logged Image not found, and there is no signature or swap error in the log.
  • SEP: after the resume the enclave was started again and the driver bound again. It was ready in 3121 ms with 12 endpoints and the key store open; 0 unhandled messages, 0 xART failures, 0 malformed records, hwrng registered again, and sep_unusable was not set. The fingerprint sensor does not attach on this build, before and after alike, as at the previous heads.
  • GPU: the compositor kept its PID and was not in safe mode. The SIO firmware and the GPU firmware booted again (GPU in 26 ms, application contexts cleared before the firmware started). OpenGL renders (2/2, before and after a fork/memory stress with 0 bad rounds) and audio plays.
  • Displays and network: eDP, DP and HDMI are connected and enabled, 3/3 DCP bound, Wi-Fi was back at once and the wired network too.
  • dmesg: 0 oops or BUG. Six warning lines, all in the resume window: the block-device cache sync, the hwrng ENODEV while the enclave restarts, the Bluetooth LE coded PHY note, two block-size notes, and one keyboard output report timeout right after the resume (also logged at earlier heads of this series).

@github-actions github-actions Bot added merge-conflict Conflicts with the base branch (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Dec 4, 2026
Two files conflicted, both only because each side added code at the
same spot; both sides are kept unchanged.

drivers/gpu/drm/apple/dcp.c: this branch adds dcp_coproc_assert_run()
after dcp_ext26_start_resident() and main adds dcp_read_notch() there
(M4 notch rows). Both functions are kept, one after the other. Main's
no_fw27_panel_pq flag in the T6030 hardware data merged cleanly into
the table's new place on this branch.

tools/testing/selftests/drivers/gpu/apple-dcp/boot.py: the test's
apple_dcp_hw_data stub gains ready_timeout_ms here and no_fw27_panel_pq
on main; both fields are kept.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) merge-conflict Conflicts with the base branch (bot) labels Dec 4, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

Forward-merge of current main (3ee509d) into this branch. New head: 1d642b9 (plain merge commit, no rebase, normal fast-forward push).

Two files conflicted. In both, each side had added code at the same spot, and both sides are kept unchanged:

  • drivers/gpu/drm/apple/dcp.c: this branch adds dcp_coproc_assert_run() right after dcp_ext26_start_resident(), and main (drm/apple: m4: read the notch rows of the M4 panel too #3926) adds dcp_read_notch() there for the M4 notch rows. Both functions are kept, one after the other. Main's new no_fw27_panel_pq flag for the T6030 hardware data merged cleanly into the table's new location on this branch. I also reverse-applied main's dcp.c changes since the merge base against the result to confirm that all of them are present.
  • tools/testing/selftests/drivers/gpu/apple-dcp/boot.py: the apple_dcp_hw_data stub gains ready_timeout_ms on this branch and no_fw27_panel_pq on main. Both fields are kept.

Checks run on 1d642b9:

  • boot.py passes py_compile. The full apple-dcp host suite (run.py) gives 103/103 ok.
  • arm64 LLVM=1 build with the fleet config (aurora_defconfig + asahi.config, patched bindgen from tools/aurora-bindgen/build.py): the Image and all 5917 modules build, including drivers/gpu/drm/apple/ and drivers/soc/apple/, with no errors or warnings in the Apple code.
  • One exception, which this merge did not cause: drivers/accel/ane/ane_fw_cold_test.c does not compile when CONFIG_DRM_ACCEL_ANE_FW_KUNIT_TEST is set. The test added on this branch uses struct ane_fw_cold_soc and ane_fw_cold_sleep_event(), but both are private to ane_fw_cold.c, and the test is built as its own object. drivers/accel/ane/ is identical at ebfde65 and 1d642b9. I turned that one option off to finish the Image and module build. The KUnit jobs at ebfde65 already failed on this and on other branch-side build errors (DCP_S2R_PLUG_MS undeclared in dcp.c under the KUnit config, apple-dart-test.c calls with 3 arguments where 4 are expected). Those need fixing on the branch before KUnit can go green.

Hardware row: the J616s row at ebfde65 does not carry over. Of the files this PR changes against main, 18 also changed in this merge (git diff ebfde65 1d642b9). They include drivers/gpu/drm/apple/{dcp.c,dcp-internal.h,dptxep.c,iomfb.c}, drivers/gpu/drm/asahi/{g16/sleep.rs,g17/mod.rs,g17/port.rs,g17/queue/render.rs,g17/runtime.rs}, drivers/soc/apple/{sep.rs,mcc.c,diag_shim.c,shim.h}, include/linux/soc/apple/dart.h, drivers/pmdomain/apple/pmp-report.c and brcmfmac/pcie.c. A new J616s hibernation row at 1d642b9 is needed.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 4, 2026
a9e2f46 ("soc: apple-sep: Start the diag attach and ready times again
at each bind") resets attach_ns and ready_ns with atomic64_set(), but
the host shim in test_diag_sensor.py only defines atomic64_read and
atomic64_cmpxchg, so the hosted SEP source diagnostics fail to compile
diag_shim.c. Add atomic64_set next to atomic64_read.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Pushed f489a2fc0063 (normal push on top of 1d642b97). The hosted SEP source diagnostics job failed because a9e2f46 resets the diag times with atomic64_set(), and the host shim in tools/aurora-sep/tests/test_diag_sensor.py had no definition for it. This commit adds the one-line define. test_diag_sensor.py, test_diag_policy.py and test_trusted_refused.py pass locally (12/12). The KUnit build errors listed in my earlier comment are still open.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@fbalazsy This branch now conflicts with main (1da341136110) in:

  • include/linux/soc/apple/rtkit.h
  • sound/soc/codecs/cs42l84.c
  • tools/asahi/bcm4377-resume-tests.py

Could you forward-merge main into this branch (normal git merge, no rebase/force-push)? If you haven't had a chance within 24 hours, a maintainer can forward-merge main on top for you.

@github-actions github-actions Bot added merge-conflict Conflicts with the base branch (bot) needs-hw-row No hardware row at the PR head (bot) labels Dec 5, 2026
Three conflicts with main f02bd68:
- include/linux/soc/apple/rtkit.h: keep main's IOReport size/snapshot
  declarations and this branch's buffer description, readopt and
  hibernation hand-off declarations.
- sound/soc/codecs/cs42l84.c: main gates the codec power-down on a
  firmware sleep or suspend-to-idle; this branch splits the power-down
  into cs42l84_power_down() (also used for hibernation freeze/poweroff)
  behind a cs42l84_suspend() gate. Move main's eligibility check into
  that gate so system sleep follows main and hibernation always powers
  the codec down.
- tools/asahi/bcm4377-resume-tests.py: extract both main's
  bcm4377_check_sleep_rom and this branch's __bcm4377_suspend.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Merged main (f02bd68a) again, at 1f68426e (plain merge, no force push). There were three conflicts:

  • include/linux/soc/apple/rtkit.h: kept main's IOReport size/snapshot declarations together with this branch's buffer description, readopt and hibernation hand-off declarations.
  • sound/soc/codecs/cs42l84.c: main now also powers the codec down for suspend-to-idle. That check moved into this branch's cs42l84_suspend() gate, so cs42l84_power_down() stays unconditional for hibernation freeze/poweroff.
  • tools/asahi/bcm4377-resume-tests.py: the list extracts both main's bcm4377_check_sleep_rom and this branch's __bcm4377_suspend.

Checks run: cs42l84.o and rtkit.o build clean (arm64, aurora_defconfig). bcm4377-resume-tests.py: 63 production controls passed. SEP diag host tests: 12/12. The J616s row at this head is still queued.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:bringup Area from CODEOWNERS (bot) area:display Area from CODEOWNERS (bot) area:gpu Area from CODEOWNERS (bot) area:media Area from CODEOWNERS (bot) area:platform Area from CODEOWNERS (bot) area:power Area from CODEOWNERS (bot) area:usb Area from CODEOWNERS (bot) area:wireless Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:one-way Revertible or not, from Merge risk (bot) merge-conflict Conflicts with the base branch (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants