Skip to content

J616s (M4 Pro) sleep, 2/9: hibernation core under aura (PM, arm64, RTKit handoff) - #1909

Closed
fbalazsy wants to merge 49 commits into
aurora-silicon:integration/aurorafrom
fbalazsy:j616s/split-pmcore
Closed

fbalazsy wants to merge 49 commits into
aurora-silicon:integration/aurorafrom
fbalazsy:j616s/split-pmcore

Conversation

@fbalazsy

@fbalazsy fbalazsy commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Part 2/9 of the split of #1477 into smaller pull requests. Depends on #1904: GitHub cannot stack pull requests from a fork, so this one also carries the commits of #1903, #1904; its own are the last 27, from c44d77b on (25 files changed, 2097 insertions(+), 72 deletions(-)).

Hibernation at EL2 under aura, the parts outside the drivers:

Area What
PM: hibernate Drivers can tell a restored image from a failed one and that an image is being loaded; a platform hook can refuse hibernation or give a fixed layout; the architecture can clean the pages of a loaded image; devices are recovered when no image was created
arm64 Hibernation and spin-table CPUs at EL2 on M4 Pro (T6040), the boot layout computed once on restore, platform facts taken from a hook; apple_pmuv3_traps boot parameter dropped
soc: apple: aura-hibernate Keeps aura's fixed reserved layout (/chosen/aura,hibernate-layout) out of the image, refuses hibernation without it
soc: apple: rtkit, rtkit-helper RTKit coprocessor handoff across hibernation, an AP idle notice usable with interrupts off
KVM: arm64 Guests keep their counters when the physical counter starts again after a sleep

Without the next pull requests nothing on other machines changes: the hook is only set on the T6040 boards.

Tested: the stack as a whole on the J616s (hibernation and suspend-to-RAM; results in #1477, whose tree is the tree at the top of this stack). Each part of the stack was built on its own (asahi config, LLVM, Rust) for the directories the series touches, and runs the host tests, KUnit and the other checks here. The commits are those of #1477 restricted to this part's files, in the same order; where a commit of #1477 spanned parts, each piece says in its message which commit it comes from.

Not tested: this part on hardware without the parts above it in the stack; T8140 and the other SoCs whose paths these commits share; a dock on the current base; the KVM guest across the sleeps; a USB4/Thunderbolt device.

fbalazsy and others added 30 commits November 14, 2026 17:41
A "does not match any of the regexes" message lists every pattern the
schema allows, vendor-prefixes.yaml included. A change that adds a vendor
prefix lengthens that list, so each such warning the base already has is
reported once as removed and once as new, and the check fails although no
device tree changed. Mask the list the way phandle values already are.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
… audio and USB4 properties

Describe what the J616s (M4 Pro, T6040) sleep and restore paths read from the
device tree: the T6040 sleep controller node, the T6041 ProRes compatible, the
PCIe and ATC PHY properties used after a power loss, the DP audio and USB4 ACIO
additions, nonposted-mmio on a PMGR block and the pin controller's
apple,resume-restore-all.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
… audio

Describe the T6040 sleep controller and enable ProRes, JPEG and DP audio on the
J616s.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The T6040 ACIO driver starts a router only over its port's Type-C PHY in
CIO mode and refuses to probe without apple,atc-phy, but the routers'
nodes never named their PHY. With the J616s left back port's router
enabled, ACIO0 failed to probe ("Missing apple,atc-phy"), and the
three of them would on any board that enables them.

Name atcphy0..2, the PHY at the same port as the router (ADT acioN
atc-phy-parent), and make the property required for the T6040 router.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The arch/arm64/boot/dts/apple/t604x.dtsi part of "pinctrl: apple: put
every AP pin back after a T6040 S2R", which goes with the device tree
changes; the rest of that commit is with the sleep controller changes.

The AP GPIO block needs the saved configuration of every pin back on
the system wake, except the pins the ADT lists in
no-restore-gpio-pins (190-192 on J616s). Linux put back
only the pins it set up itself. A sleep that cuts the block's power then
left the pins the boot loader set up for others at their reset values,
among them the chip select of the internal panel's TCON bus; after the
wake the display firmware powered the panel's rails and never saw it
come up ("No device added after powering on the rails. HPD=0").

Mark the AP block apple,resume-restore-all with the ADT's no-restore
list, snapshot every readable pin from the hardware at suspend_noirq
and write back the ones that changed at resume_noirq, logging the pins
that were not Linux's.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The arch/arm64/boot/dts/apple/t6040.dtsi part of "soc: apple:
t6040-sleep: name the T8140 driver instead of its pull request", which
goes with the device tree changes; the rest of that commit is with the
sleep controller changes.

Comments in the T6040 sleep code, the display driver and the T6040
device tree pointed at the T8140 sleep driver by a pull request number.
Name the driver (sleep.c) or the T8140 instead, and drop the
"currently unreachable" note on the sleep controller node.

No functional change.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The arch/arm64/boot/dts/apple/t6040-j616s.dts,
arch/arm64/boot/dts/apple/t6040.dtsi part of "arm64: dts: apple: t6040:
enable the sleep controller per board", which goes with the device tree
changes; the rest of that commit is with the sleep controller changes.

The T6040 sleep controller's node is in the SoC's file, so every T6040
board has it, while its sleep has been run on the J616s alone. It maps
fixed T6040 blocks and installs suspend operations that make deep the
default state and then refuse it without t6040_sleep.allow_entry, which
is of no use on a board nobody has tested, and distribution kernels
build the controller.

Disable the node in t6040.dtsi and enable it in t6040-j616s.dts. On the
J614s and the J773s the controller no longer binds: suspend-to-idle
stays their sleep, and the debugfs preflight file is gone there.

The interrupt controller saved its configuration for a sleep on every
apple,t6041-aic3 whenever the controller was built. Key that on the
enabled node as well, so that the other machines with this AIC keep
their suspend and hibernation paths as they were.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…e,apcie

The description spoke of what a driver does with the node. Say what the
node is: the blocks an operating system at EL2 drives itself to suspend
the T6040 to RAM, and the display power states that have to be off
before it.

The boot loader adds apple,apcie to the node, the PCIe host whose shared
registers and tunables the storage controller's link needs after a
sleep, as on the T8140. The binding did not allow it. The pipe list also
lacked the description a vendor property needs, which the binding check
reported.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The MAINTAINERS part of "soc: apple: sleep: describe the T6040 part as
it is", which goes with the device tree changes; the rest of that commit
is with the sleep controller changes.

The file's opening comment still explained why the T6040 controller was
a driver of its own next to the generic one, and several comments named
functions the generic driver no longer has. Describe the part as it is
now, with suspend-to-RAM offered only to a system booted with
t6040_sleep.allow_entry=1, name the generic driver's functions, and say
in sleep.c that a SoC may bring a part.

List the private header next to the driver's sources.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The T6041 display coprocessors (apple,t6041-dcp, apple,t6041-dcpext)
name an apple,display-power node whose "ps" and "pmc-dcp" windows hold
the power-state words their driver lowers after it stops the firmware
for a suspend-to-RAM and raises on the wake, and the display PMC word
that counts the powered coprocessors. The boot loader publishes it with
the compatible apple,t6041-display-power: one node over the east power
manager block for the internal coprocessor, one over the west block
that both external coprocessors name. Describe it, as
apple,t8140-display-power.yaml does for T8140.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The comment on the sleep controller's storage link described how the
boot loader's publish behaves and recalled what a static property had
done on a J616s. Say what the tree has to give and what the boot loader
adds: apple,apcie and the PCIe host's windows and tunables come from
the boot loader, which leaves a node that has apple,apcie alone, so
the tree gives neither.

Comment only; the DTBs are unchanged.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The sleep controller has registers but its node had no unit address,
which dtc reports (unit_address_vs_reg). Name it after its first
register block, as the T8140 tree does. The boot loader and the kernel
find the node by its compatible, not by its path.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The T6040 sleep controller binding sat under power/, the T8140 one
under soc/apple/, for the same kind of block. Move it next to the
T8140 one, give apple,check-ps-b4-sleep-names its string-array type,
and list the file under the Apple SoC entry in MAINTAINERS.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The boot object publishes /chosen/aurora,s2r-mailbox, and the arm64
CPU ops, the spin-table hibernation and the Apple sleep driver read
it, but no binding described it. Document what its presence means and
the layout of the mailbox it points at.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
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: František Balázsy <frantisekbalazsy@gmail.com>
The sleep controller cannot enter a suspend or undo one without any of its
eleven register blocks, and every T6040 board lists all of them. Make reg
and reg-names required with all eleven entries instead of accepting a node
with only the first two, and give the example the node it describes.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The soc-east and soc-ps windows are the SOC-East and SOC power word pages,
which the driver reads and writes as one range each: 0xd000 and 0x9000
bytes. Describe them as the pages they are, so that one mapping of each
serves every power word in them.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
Give the soc-east and soc-ps windows of the sleep controller the extent of
the SOC-East (0x502280000) and SOC (0x502800000) power word pages, 0xd000
and 0x9000 bytes, instead of the first 0x1000 of each. The addresses are
unchanged.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The T6040, T8132 and T8140 sleep controllers do the same job and were
described by two schemas that named the same blocks differently. Describe
them in apple,sleep.yaml, with the register names per compatible, and give
the blocks the T6040 shares with the T8140 the T8140's names: cluster for
the CPU complexes' control words, pwrgate for the power-gate and voter
block, spmi for the PMU's SPMI controller and wake for the AOP block with
the wake masks.

The schema keeps what each SoC requires and refuses: the T6040 needs all
eleven of its register blocks, the SOC-East and SOC pages sized as the
driver maps them, and the display power-state table; the T8140 needs its
28 blocks, the wake sources and the display coprocessors; the T8132 its
25 blocks, the clock protection page as an optional 26th, and the display
coprocessors. The controllers are listed in MAINTAINERS under the one file.

The T6040 device tree and driver follow in the next two patches.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…8140's

Give the register blocks of the T6040 sleep controller that the T8140's
controller has too the names the schema uses for both: cluster, pwrgate,
spmi and wake. The addresses, sizes and order are unchanged; the compiled
tree differs only in those four names.

The driver looks the blocks up by these names and follows in the next
patch.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The T6040 USB4 router runs only over its port's Type-C PHY and tells
the PHY when it starts and stops. The PHY was named in a vendor phandle,
which the router resolved to a device node and looked up by hand for
each call.

Describe it with the standard phys property and the "cio" name the T8132
routers already use for the same PHY, so the PHY framework resolves it
and orders the router after the PHY. The T6040 routers require both.

Not run on a USB4/Thunderbolt device.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
Name each router's Type-C PHY with phys, as the binding now describes,
instead of the vendor phandle. The routers stay disabled here, so no
default board changes. The built J616s device tree passes the router
schema.

Not run on a USB4/Thunderbolt device.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…llow a platform-fixed layout

Drivers that hand a coprocessor over across hibernation need to know, in their
restore callbacks, whether the image was really restored or the PM core is
unwinding an aborted hibernation. Add pm_hibernate_is_restored() (with a Rust
helper) and let a boot chain that keeps the memory layout fixed (aura hib=1)
admit hibernation where the platform would otherwise be refused.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
With Linux at EL2 under aura, secondary CPUs come up from a spin table and the
boot CPU has no enable-method. Let the spin-table CPUs be parked and released
again across hibernation and suspend-to-RAM (a pen in the kernel image the
locked RVBAR relay returns to), restore the EL2 state the hibernation resume
needs, and keep the T6040 errata on the restored CPUs.

An offlined RVBAR spin-table CPU waits in the kernel's own text, so
spin_table_cpus_stuck() refuses kexec and hibernation for it. For a hibernation
the pen is what takes those CPUs out of the memory the restore overwrites: a
kernel that has it (KEXEC_CORE, for cpu_soft_restart()) is not stuck there, and
swsusp_arch_suspend() asks spin_table_hibernate_cpus_stuck() instead. kexec
keeps the check.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…or handoff

aura-hibernate reads the fixed boot layout aura publishes (hib=1) and refuses
hibernation without it. RTKit gains a cold-restart/re-adopt path for a
coprocessor the restored kernel finds running (or halted) under it, used by
the DCP, AOP, SEP, ANE and SMC drivers after S4 and S2R.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…s again in a sleep

A guest's virtual and physical counters are the host's physical counter
minus an offset that is fixed when the VM is created. A resume from disk
is a cold boot: the physical counter has started again, and with the old
offsets the guests' counters read less than before the hibernation. A
Linux guest takes a clocksource that went backwards for no time passed.
It still gets its timer interrupts, but its clock stands still until the
host's counter has caught up with the old value, which takes as long as
the host had been up.

J616s, a guest with two vCPUs that prints its uptime every second, host
up for an hour, hibernation and resume: the guest's CVAL went from
0x2076a3246c to 0xfffffce7b9ce8d2f, the guest took a timer interrupt
every half second and printed nothing more.

Keep the counter's value in a syscore suspend callback. If it reads less
in the resume, move every VM's virtual and physical offset by the
difference: the guests' counters go on from the value they had when the
system went down, as for a VM that was stopped for that long. The time
the machine was off is not shown to the guests. A counter that keeps
running through a sleep is left alone, and the guests see that sleep as
time that passed, as before.

The same guest with this change: "the counter started again in the
sleep (446875224457 -> 92491224896): the counters of 1 VM(s) kept", and
the guest prints on after the resume with its uptime continuous. A
suspend to RAM before and one after that hibernation leave it running
too; the counter runs through those and the guest's uptime steps by the
25 s of the sleep.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The arch/arm64/configs/asahi.config part of "soc: apple: share the sleep
registry so one kernel builds both controllers", which goes with the
hibernation core changes; the rest of that commit is with the sleep
controller changes.

The T8140 sleep driver (sleep.c) and the T6040 one (t6040-sleep.c) each
defined the coprocessor and enclave registry that drivers reach through
<linux/soc/apple/sleep.h>, so the two exported the same nine symbols and
APPLE_T6040_SLEEP had to depend on !APPLE_SOC_SLEEP. The universal
config sets APPLE_SOC_SLEEP, so it never built the T6040 controller.

Move the registry into sleep-registry.c behind a hidden
APPLE_SLEEP_REGISTRY that both options select. The table holds six
entries and the superset of the two records. Each controller binds to
the registry in its probe with two answers of its own: whether this
sleep's commit stops the registered coprocessors, and whether an
enclave registration is taken. Both keep their earlier rules: T8140
answers from its own state and pm_suspend_via_firmware() and takes an
enclave only when its commit stops coprocessors; T6040 answers as
before and takes every enclave. With no controller bound the commit
stops nothing and an enclave registration is refused. The controllers
bind only to their own compatibles (apple,t8140-sleep,
apple,t6040-sleep), so at most one is bound and installs suspend_ops.

Drop the dependency, give the registry prototypes their own guard in
sleep.h so every combination compiles, and enable APPLE_T6040_SLEEP in
asahi.config.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
create_image() sets hibernate_restored inside if (!in_suspend), which
is reached only in a kernel restored from an image: there the arch
code has cleared in_suspend and swsusp_arch_suspend() returned 0. So
!error is always true at that point; store true.

No functional change.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The comment that explains what hibernate_boot_layout() covers sat above
hibernate_mix_span(), directly on top of that function's own comment.
Move it to hibernate_boot_layout().

Comment move only, no functional change.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The comment over the parking spin table said that CPU hotplug fails
until a platform driver provides the power ops. Since the parked CPU
comes back through cpu_soft_restart(), only stopping the parked CPUs
for a suspend needs them (spin_table_hold_parked() refuses without);
hotplug needs KEXEC_CORE. Say so, and rejoin a line break in the pen
comment.

Comments only, no functional change.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The comment cited the error code a test had seen when MTP was started
again after a quiesce. Say what the firmware does instead: it does not
answer the endpoint discovery of the next start.

Comment only, no functional change.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
arch_hibernation_header_restore() computed hibernate_boot_layout() a
second time to print it on a mismatch, and on a match printed the
value the hibernating kernel had already logged. Compute it once, and
drop the line on a match.

The comparison and its outcome are unchanged.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
spin_table_hibernate_pen_begin() passed a compound literal to pr_err()
to print the physical address of swapper_pg_dir. Keep the address in a
local, compare against it and print it from there.

No functional change.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The restore callback reported its failures with dev_err_probe(), which
belongs to probe and records a deferral reason against a bound device.
Print them with dev_err() and return the error as before. The hand-over
and the take-over of a session, which happen on every resume from disk
that has them, go to debug level.

Only log calls change.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The hibernation callbacks sat in an #ifdef CONFIG_HIBERNATION block,
with a second freeze callback for the other configuration, and .thaw
and .restore were set under the same condition. On arm64 the PM core
calls .freeze, .poweroff, .thaw and .restore only with
CONFIG_HIBERNATION, so the second freeze callback was never called.
Drop it, build the callbacks unconditionally and set them with
pm_sleep_ptr().

With CONFIG_HIBERNATION the object code is unchanged.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
An adopted MTP session keeps the buffers it negotiated with the boot
stage that started it, so on boards where the firmware cannot give them
up a request for a buffer the inventory does not list is refused. Probe
decides that for a session with an inventory, for T8132, and for the
J614s MTP. The restore after a hibernation adopts the session of the
resume boot the same way but decided again with a copy of the rule that
lacked the J614s: there a session adopted with an empty inventory
refused new buffers after probe and granted them after a resume from
disk, replacing storage the firmware still uses.

Take the decision in one helper, and in the restore make it before the
new session's receive path starts, as probe does.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The parameter turned on the implementation defined PMUv3 traps for KVM
guests on the T6040 cores, which are not in apple_cpus, until the
traps are verified there. They have not been, the parameter is off by
default, and a boot parameter is no place for a test switch: once the
traps are verified, the two MIDRs belong in apple_cpus.

Remove the parameter and its documentation. The file is again as it
was before the parameter: guests on these cores see no PMU.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The helper that reads the ASC's CPU run bit came with the hibernation
callbacks, while the hand-off check and the removal read the same bit
with a copy of the expression. Move the helper up and use it there.

The three tests that read the bit with readl() are left as they are.

No functional change: every path reads the bit as often and at the
same point as before. With five users the compiler no longer inlines
the helper.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
apple_rtkit_ap_power_noirq() polls the mailbox, but it waits with
usleep_range() and jiffies and takes the acknowledgment from the
receive work. None of that is to be had at a sleep controller's commit,
where interrupts are off, one CPU is up and timekeeping is suspended.

apple_rtkit_sleep_idle_polled() already sends the AP and IOP idle
notices there for a coprocessor that is then stopped: it polls a bounded
number of times with udelay() and takes the acknowledgments in the
poll. Add apple_rtkit_ap_idle_polled() for a coprocessor that stays up
and is only told that the AP goes idle, as the SMC is. It shares the
start of the polled idle (what is waiting is taken first, an owed OSLOG
counter is echoed) and sends the AP notice alone.

Such a coprocessor's client still has traffic on its own endpoints: a
reply to a command it sent just before, or an event. While the notice
is polled for, a message for an application endpoint therefore goes to
recv_message_early as usual, and one that is not taken there is queued
for the receive work, which runs again after the wake. Everything else
is handled as in the polled idle.

Compiled only: its first user is the SMC's sleep commit in the next
patch, which has not run on hardware yet.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The drivers/soc/apple/aura-hibernate.c part of "soc: apple: sep: probe
again through the aura reprobe helper", which goes with the hibernation
core changes; the rest of that commit is with the coprocessor changes.

After a resume from disk on a cold boot the SEP is unbound and probed
again once the tasks are thawed, to register with the restarted
enclave. The driver carried its own work item, spinlock, pending-device
pointer and a module-exit guard to cancel the work.

aura_hibernate_reprobe_after_thaw() does the same unbind and probe from
the freezable workqueue, which the restore finds frozen, so the probe
cannot start before every device's restore has completed. The helper is
built in, so a module going away in the meantime leaves no work behind
and needs no cancel.

The registration marker is still removed before the probe is queued,
and only once a cold boot is established, as before. A probe that
leaves the device without a driver is not reported by device_reprobe();
the helper now logs that case too, as the SEP's own work item did.

Without CONFIG_APPLE_AURA_HIBERNATE the probe is not queued and the
driver says so, as the AOP does.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…rt from an error

A co-processor may acknowledge the idle request of its IOP side with a
power state other than idle (the low byte 1 or 2): it is asleep with its
firmware and memory kept, which is what the caller wants after the AP
side has idled. apple_rtkit_idle() returned -EINVAL for it, the same
value as a bad argument or a stale state, and the display driver had to
accept -EINVAL as success.

Return APPLE_RTKIT_IDLE_RETAINED (-EALREADY) for exactly that
acknowledgment. Timeouts and failures of the AP side are returned as
before. Every other caller of apple_rtkit_idle(), apple_rtkit_idle_with()
and apple_rtkit_sleep_stop() treats any non-zero value as a failure and
only forwards or prints it, so for them only the printed number changes.
The display driver now accepts the new value instead of -EINVAL and fails
on any other error, -EINVAL from the transport included.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The arch/arm64/configs/asahi.config part of "soc: apple: sleep: build
every sleep controller and drop two symbols", which goes with the
hibernation core changes; the rest of that commit is with the sleep
controller changes.

APPLE_SLEEP_REGISTRY has only one selector, APPLE_SOC_SLEEP, and the
registry is linked into the same object as the controller, so the symbol
selects nothing a user could choose. APPLE_T6040_SLEEP exists for the
dependency of the T6040 sleep on the SMC driver and for MFD_SYSCON, but a
board that has no T6040 sleep controller already gets none: the node's
status in the device tree is the switch.

Link the registry into apple-sleep, build the T6040 sleep wherever the SMC
driver is built in, as before, and select MFD_SYSCON in that case. The
T6040 documentation moves to APPLE_SOC_SLEEP. A kernel with APPLE_SOC_SLEEP
and the SMC driver as a module still builds the T8140 sleep alone; with
both built in it now also carries the T6040 sleep. The asahi config
fragment no longer sets the removed symbol.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
A driver that must treat the kernel loading a hibernation image
differently from a kernel that freezes for an image of its own has no
way to ask: the freeze callbacks run the same in both. The SMC driver
and the RTKit hand-off each registered a PM notifier that sets a flag on
PM_RESTORE_PREPARE and clears it on PM_POST_RESTORE, and the hand-off
copy is read by two more drivers.

Keep the flag in the PM core, next to the restored flag, and have the
two notifier helpers set it around the PM_RESTORE_PREPARE and
PM_POST_RESTORE notifications, whether the load starts from the resume
path or from the snapshot device. pm_hibernate_is_loading() reads it.
It is true from before the first notifier runs (the copies became true
only when their own notifier was reached) until PM_POST_RESTORE has been
delivered, and it is cleared again when a notifier refuses the load,
where the copies of the notifiers not reached never became true. It is
saved in an image as false, like the notifier copies, so the restored
kernel reads false.

The SMC driver reads the core flag in its freeze callback and drops its
notifier, which also removes the registration at probe. The RTKit
hand-off keeps apple_rtkit_hib_restoring() for its callers and answers
it from the core flag.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
swsusp cleans every page of a loaded image to the point of coherency
before the jump into it, for devices that read memory without snooping
the CPU caches, and does so under #ifdef CONFIG_ARM64 in the generic
snapshot code, with the justification of one SoC family in its comment.

Keep the walk over the image's page frames in snapshot.c and ask the
architecture, per frame, through arch_hibernate_clean_image_page(),
enabled by ARCH_HIBERNATION_CLEAN_IMAGE. arm64 sets the symbol and
provides the function with the body the walk had: a frame that is not in
the boot kernel's linear map is left to the restore_pblist copy, any
other frame is cleaned and invalidated to the PoC. The frames, their
order, the cond_resched() cadence and the clean operations are the same
as before; the generated arm64 code matches the removed loop body.
Other architectures compile the walk out, as they did.

The comment of the copy loop in hibernate-asm.S no longer names a SoC.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
hibernation_available() asked of_machine_is_compatible("apple,arm-platform")
and aura_hibernate_layout_fixed() in the generic hibernation code, and the
log line carried the reason of one platform.

Add hibernation_set_platform_check(): platform code registers a function
that is true while hibernation must stay refused, with the reason that is
logged at the end of the boot when it is. hibernation_available() asks it
where it asked the two Apple conditions. The aura hibernation code
registers aura_hibernate_blocked(), which is the same expression
(Apple platform and no fixed layout), evaluated at the same moments, and
the same reason text; the explanation of why the machines refuse moves
with it.

The check is registered from the init of that code on every boot of a
kernel that has it, where the Apple condition used to be compiled into the
core unconditionally. To keep that fail-closed, APPLE_AURA_HIBERNATE is no
longer a prompt: it is always on with ARCH_APPLE and HIBERNATION, as the
refusal belongs to it. Nothing registers before that init runs, which
precedes the first possible hibernation (the resume check is a later
initcall level and user space starts after all of them).

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
arm64's hibernation code read aura's /chosen properties, called aura's
nosave functions and kept aura's layout rules in the boot layout check
that is stored with an image and compared before it is restored.

Add struct arm64_hibernate_platform with two hooks, registered once at
boot: pfn_nosave(), asked by pfn_is_nosave(), and layout(), which adds
the platform's facts to the layout cookie. The part of the check that
belongs to every arm64 machine stays: the CPU release addresses (as
offsets from a base the platform may name, together with whether the
platform keeps the page out of the image) and the memory map less the
ranges the platform names. The aura hibernation code registers the hooks
and carries the rest: the /chosen properties, the S2R mailbox and the
split of aura's layout around the exec window, moved as they were, with
the comment that explains them. arm64_hibernate_layout_mix() is the
mixing function, made visible for the hook.

The nosave ranges stay a table in aura-hibernate.c and are not handed to
register_nosave_region(): that function allocates from memblock and runs
at setup_arch() time, and the table is filled from a late initcall. The
aura functions that nothing outside the file calls any more become
static, and aura_hibernate_layout_fixed() is dropped.

The cookie is bit for bit the same: the old function and the new pair were
compiled against the same stubbed device tree and memblock in 200000
randomised boots (properties present or absent, mailbox, window, nosave
tables, CPUs with and without release addresses, memory maps); every
cookie is identical, and a change of one mixed value in the new code is
caught. The set of pages kept out of the image is the table's, asked at
the same place.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
A driver whose device does not survive a boot cannot tell, in the kernel
restored from a hibernation image, whether the machine went through one.
pm_hibernate_is_restored() is also true after a test_resume, where the
kernel that wrote the image loads it itself and nothing rebooted, and
drivers fell back on hardware side channels to tell the two apart.

The kernel that loads an image now leaves a record for the restored
kernel just before the jump: whether it is the kernel that wrote the
image, which is the case only when hibernate() loads the image it has
just written for test_resume, or one that was started to resume it. The
record lives in the no-save section, which the image neither saves nor
overwrites, and carries a magic and its own physical address, so a record
from a kernel loaded elsewhere, or none, reads as absent. It is the same
requirement that in_suspend and other no-save hand-offs already have: both
kernels are the same build at the same physical address. The restored
kernel copies it where it sets the restored flag, and
pm_hibernate_restored_cold() returns 1 when another boot loaded the image,
0 when this kernel did (or was not restored) and -ENODATA when no record
was found. The record is cleared when it is read and when a restore fails,
and the value has the lifetime of pm_hibernate_is_restored().

The flag says that the machine booted, not that a given device lost its
state: a kexec-style resume would read as another boot with firmware that
kept running, and a device that needs more than the boot has to check it
itself. Nothing uses it yet.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
When hibernation is abandoned before the image exists, hibernation_snapshot()
and create_image() resume the frozen devices with PMSG_RESTORE, the event of
a kernel restored from an image: in_suspend is clear in both cases, and
only the creating kernel with an image sets it. The cases are a device that
fails to freeze, a wakeup event, the pm_test levels devices, platform and
core, and a failure in the noirq phase before in_suspend is set. The
hardware did not boot in any of them, but the drivers get their restore
callbacks, run them for a state they cannot have, and some have to be told
by pm_hibernate_is_restored() that nothing happened.

Pick the event in one function: in_suspend set keeps what it was (PMSG_THAW,
PMSG_RECOVER after an error); in_suspend clear is PMSG_RESTORE only when
pm_hibernate_is_restored() says this kernel was restored, and PMSG_RECOVER
otherwise, which is what the PM core sends after every other failed freeze
(dpm_prepare() failing here, dpm_suspend_start()/end() through
resume_event()). The restored flag is reset at the start of every
hibernation_snapshot() and set right where the restored kernel leaves
swsusp_arch_suspend(), before either resume call.

What changes: only the calls of an abandoned hibernation, from the restore
callbacks to the thaw callbacks (pm_op() maps PM_EVENT_RECOVER to the thaw
callbacks as PM_EVENT_THAW), and, for a device with
DPM_FLAG_MAY_SKIP_RESUME, dev_pm_skip_resume() now follows must_resume as it
does for every other failed freeze. pm_hibernate_is_recovering() is now true
there as well, as its documentation says. Nothing changes for a created
image, a restored kernel or a test_resume, nor after a failed power-off in
platform mode (PMSG_RESTORE from hibernation_platform_enter(); only ACPI sets
platform hibernation ops).

For the Apple drivers the abandoned case was already a thaw: every restore
callback that checks the flag returns or forwards to its thaw (macsmc, the
RTKit helper, apple-dart, sn201202x, DCP, NVMe, PCIe, cs42l84) or does
nothing where there is no thaw (AOP, t6040 USB2 PHY, RTC, GPIO and SPMI
early restores); PCIe's restore_noirq and thaw_noirq agree on the ports.
So they now get the thaw directly. The checks in those callbacks stay for
now.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…d hibernation

The drivers/soc/apple/rtkit-helper.c part of "soc: apple: drop the
restore callbacks' checks for an abandoned hibernation", which goes with
the hibernation core changes; the rest of that commit is with the sleep
controller changes.

An abandoned hibernation resumed its devices with PMSG_RESTORE, so every
restore callback that must not act on a state it never lost began with a
pm_hibernate_is_restored() check, and most forwarded to their thaw. The PM
core now sends PMSG_RECOVER there, which reaches the thaw callbacks, so the
check and the forward go from macsmc, the RTKit helper, apple-dart, the
sn201202x Type-C controller, the SPMI, GPIO and NVMe restore paths, both
PCIe restore callbacks, the DCP and AOP restores, the t6040 USB2 PHY's two
and the RTC; cs42l84's restore passes that the codec lost its state.

Each callback runs for a restored kernel exactly as before. For an abandoned
hibernation the old path was already the thaw or nothing, and the thaw now
runs on its own: macsmc, the RTKit helper, apple-dart, sn201202x, NVMe and
cs42l84 forwarded to the same function (cs42l84's resume asks
pm_resume_via_firmware(), which hibernation_snapshot() has cleared); PCIe's
restore_noirq did for a bridge without hibernation tunnelling what its
thaw_noirq does, and the same call with it; the AOP, t6040, RTC, GPIO and SPMI
restores did nothing and have no thaw. DCP keeps its power-off-failed branch
(PMSG_RESTORE after a failed platform power-off, which only a platform with
hibernation ops reaches) and loses the abandoned one, whose only other
effect was a log line.

One path changes: macsmc's thaw, after the SMC was handed over and the image
could not be entered, calls apple_smc_restore() to start a new session, and
its own check sent that back to the thaw, which did nothing. It now
starts the session as the comment says it should.

The flag keeps its other users, which are not restore callbacks: the AIC
syscore resume, the dockchannel receive interrupt, the SEP's PM notifier.

Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
@fbalazsy

Copy link
Copy Markdown
Contributor Author

Closing: this stack is based on integration/aurora from 2026-11-14 and now conflicts with the sleep and spin-table work that landed since. I will rework the J616s (T6040) support on top of the current tree and open a new, smaller series.

@fbalazsy fbalazsy closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants