Repository navigation
Conversation
<linux/suspend.h> was included twice. apple_smc_freeze() tested the driver data for NULL, but PM callbacks run only on a bound device, whose probe has set it. No functional change. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
apple_smc_restore() is a PM callback, not a probe: dev_err_probe() there would record a deferral reason against a bound device, and its five messages had no trailing newline. Print them with dev_err() and the error code, and return the error as before. No functional change beyond the log text. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The hibernation callbacks, the PM notifier and its registration sat in three #ifdef CONFIG_HIBERNATION blocks, with forward declarations only because the notifier was defined after probe. Define the notifier before probe, register it under IS_ENABLED(CONFIG_HIBERNATION), and set the callbacks with pm_sleep_ptr() like the others, so that every configuration compiles the same code. Without CONFIG_HIBERNATION the PM core never calls .freeze, .thaw, .poweroff or .restore, and pm_hibernate_is_restored() is false there. With it the object code is unchanged. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
Every power-off and reboot printed its progress at KERN_EMERG, and the reboot notifier added a line about the PMU flag cell. Print the request at info level again, a refused off1 attempt as a warning, the final failure as an error and the accepted off1 at debug level, and drop the PMU flag line. An accepted off1 that does not cut the power still ends in the WARN after 5 s. Only log calls change. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
aic_sleep_init() returns before register_syscore() when the IRQ_CFG buffer could not be allocated, so the test of that buffer guarding the registration was always true, and the same test in aic_syscore_suspend() never so. The comment on the registration also claimed a resume from disk resyncs the masks on every SoC, while the syscore is registered only where the sleep save is set up. Drop both tests and the comment. The registration and the save are unchanged. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
Five comments told the wake's writes step by step. Say what the block needs instead: the global word has to be back before the pins, a pin takes its word in three writes after a power loss, and a block that loses every pin is saved whole except the reserved pins. Comments only, no functional change. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The comment over apple_spmi_restore_early() walked through how the missing interrupts were found. Say what happens instead: genpd keeps the noirq restore from running, the IRQ core does not rewrite the masks, so a device whose driver the boot kernel did not load stays masked unless the early restore rewrites them. Comment only, no functional change. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The restore callback sat in an #ifdef CONFIG_HIBERNATION block, with an #else that pointed .restore_noirq at the resume callback. Without CONFIG_HIBERNATION the PM core never calls .restore_noirq, so the #else was dead. Build the callback unconditionally and set it with pm_sleep_ptr() like the others. With CONFIG_HIBERNATION the object code is unchanged. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
sio_restart() runs from the restore callback, not from probe: dev_err_probe() there would record a deferral reason against a bound device. Print the six failures with dev_err() and return the error as before. Report the restart and a firmware that kept running, which happen on every resume from disk, at debug level. Only log calls change. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
Every resume from a sleep that powered the block down printed up to three info lines per block (the global word, the pins put back, the pins Linux had not set up), and every resume from disk one more per block. That is per-cycle detail, and the resume of a configured pin count was debug level before. Print all four at debug level. Only log calls change. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The early restore printed an info line on every resume from disk where it rewrote the masks. Print it at debug level. Only a log call changes. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The bitmap of restored pins that Linux had not set up existed only for a debug message; a pin of a restore-all block is put back whether Linux set it up or not. The buffer of saved words is allocated for every block since probe fails without it, so the suspend and resume tests for it were never true. pm_sleep_ptr() keeps the early restore referenced in every configuration, so it needs no __maybe_unused. Drop all three. What is saved, written back and when is unchanged. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The two restore callbacks sat in an #ifdef CONFIG_HIBERNATION block, with an #else in the dev_pm_ops that pointed .restore_noirq at the resume callback. Without CONFIG_HIBERNATION the PM core never calls the restore callbacks, and pm_hibernate_is_restored() is false there, so the restore callback falls back to the resume one by itself. Build both 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>
The T6040 sleep prompt carried a "(refusal-first)" tag that the help text explains anyway, and its help named a check before the sleep instead of what has to be off. The aura hibernation help had a line past 80 columns. Drop the tag, say which display power states have to be off, and rewrap both paragraphs. Text only; symbols and dependencies are unchanged. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
A kernel that attached the enclave refuses to load a hibernation image over it: its PM_RESTORE_PREPARE notifier returns NOTIFY_BAD. The PM core then sends PM_POST_RESTORE to the notifiers that ran before the one that refused, not to that one. The notifier had already marked a sleep as held before it asked the driver, and nothing took the mark back: diag/sleep read "held" for the rest of that boot, or until a later sleep ended, although the boot went on with the enclave in use. Mark the sleep only once the restore is accepted. The host test runs the notifier now: a refused restore leaves nothing held, an accepted one is released by PM_POST_RESTORE, and a mutation that marks the sleep before the refusal is caught. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
A resume from disk goes through a boot, and the PMU's alarm does not come back as the image left it. The kernel that loads the image stops an alarm that is no longer ahead when it binds this driver, and the boot firmware leaves the comparator close to the end of its range when it has no wake of its own. An alarm whose time passed with the machine off had its event acknowledged there. The restored kernel's RTC core still counted the alarm as set: its time stayed in wakealarm, a new alarm was refused as busy, and an alarm still ahead never fired. After a real restore, have the RTC core go through its timers: an alarm that is due is reported, a later one is written to the PMU again, and with none the PMU's alarm is stopped. The power-off callback does not cover this. Only a hibernation that powers off through platform hibernation ops calls it, and no Apple machine has those: the power-off or reboot after the image leaves the alarm armed. Say so where the callback and the prepare comment claimed otherwise. The host test covers the restore, with two mutations. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
… disk After a resume from disk the block holds what the boot loader and the kernel that loaded the image set up, while the register cache of the restored kernel still holds the words of the image. The early restore wrote back only the pins set up as interrupts and left the others to their consumers. A consumer does not reach the pin either: its write goes through regmap_update_bits(), which compares with the cache and skips a word the cache already has. An output set again to the level it had before the hibernation, and a pin function selected once at probe, stayed as the boot left them. Compare every pin this driver has written with the block, and write the cached word back where they differ. The write is the one the resume from a suspend that cut the block's power uses: the configuration first, the input enable in a write of its own, the lock last, and a locked pin left alone. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
While Linux is away the queue keeps being used: aura's wake path and
the platform's sleep code write the PMU through it. Every command the
driver sent was answered before the suspend, so a reply still waiting
at the resume is someone else's, and the next command takes it as its
own. On the M4 Max that was the RTC's acknowledge of the alarm that
woke the machine ("unexpected SPMI response 0x8b30"), after which the
RTC refused every later suspend.
Read such replies out at resume_noirq after a firmware-driven suspend.
Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
After a resume from disk the controller holds the masks and the pending interrupts of the kernel that loaded the image. The driver rewrote them in the noirq restore and, for a controller in a PM domain, in the early restore, with a flag to keep the two apart: for a device in a domain genpd calls the driver's noirq resume, not its noirq restore. The early restore runs for every controller, in a domain or not, and still before any device on the bus is restored. There the rewrite can also take the command lock, so that no reply is acknowledged away under a command. Do the rewrite there only: the noirq restore becomes the noirq resume, as genpd already made it for the controllers in a domain, and the flag goes. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The sleep commit writes the WKTP key ahead of 'slpa', and the wake writes it again once it is a full one. That is what the T6041's SMC needs: without the second write it goes on treating the time awake as a dark wake, keeps its own fan policy against a manual request and asks for a sleep under thermal load. The writes sat in the commit path every SoC shares, so the T8140's sleep sequence, which was established without the key, gained two commands that have not been run there. Key the writes on match data, set for apple,t6041-smc. Every other SMC gets the sequence it had. The KUnit cases run the sleep order and the refused commit for both kinds of SMC. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
After a suspend that cut a block's power a T6041 pin takes its word in steps: the configuration, the input enable in a write of its own, the lock last. Written whole, the pin reads 0 for good. The helper that does this replaced the single write for every block, the uncached T8140 blocks included: the single write is what has been run there, and the helper also leaves alone a pin that reads locked. Select the stepwise write through match data, set for apple,t6041-pinctrl. Every other block gets its word whole again. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
Two module parameters chose what the sleep commit and the full wake write to WKTP while the values were being established. They are: 2 at the sleep request, 0 once the wake is a full one. Nothing sets the parameters to anything else, and a value written from user space into the sleep sequence is no interface to keep. Remove sleep_wktp and wake_wktp and write the two values. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The T6041's AIC is the AICv3 of the T8140 and loses the same state when a firmware-driven suspend cuts its power. It was admitted to the save and restore by a helper that looked for the T6040 sleep controller in the device tree and for its driver in the configuration, next to the fw_suspend flag the T8140 entry carries for the same purpose. Give apple,t6041-aic3 an entry of its own with fw_suspend set and drop the helper. The save runs only under a firmware-driven suspend, so a board without the sleep controller does nothing more than keep an unused array. A kernel built without the T6040 sleep driver gains something: the syscore, and with it the mask resync after a resume from disk, used to be registered only with that driver configured, so such a kernel came back from hibernation with the masks of the kernel that loaded the image. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The masks are rewritten from the IRQ core's books on every syscore resume that did not follow a firmware-driven suspend, on the grounds that a resume from disk is the only other one that loses them. The resume that follows the snapshot of a hibernation, in the kernel that goes on to write the image, got the same rewrite with the values already there. Ask the PM core whether this kernel was restored from an image, and rewrite the masks only then. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
A kernel restored from a hibernation image finds in the AIC the masks of the kernel that loaded the image: that one masked every IRQ at its init and unmasked what it used itself. This does not depend on the SoC or on the AIC's version, but the syscore that puts the masks back was registered only for the SoCs with a firmware-driven suspend. Register it whenever hibernation is built in. The save and restore around a firmware-driven suspend stay with the SoCs that have one: the array for it is allocated only there, and the suspend callback returns at once anywhere else. On a machine that never resumes from disk nothing changes: the resume callback writes only in a restored kernel. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
After a resume from disk the driver repeats what probe does with a freshly woken SMC: start the endpoint, send the initialization, wait for it, check the boot stage and read the key count. The restore had its own copy of the five steps. Put them in one function. Probe now initializes the completions, the driver data and the notifier head before the handshake instead of in the middle of it, and the restore resets the completions before the endpoint starts instead of after; none of that reaches the SMC, which sees the same messages in the same order. The messages of a failed handshake are the same at probe and at restore now, each with its error code. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
Probe masks every interrupt and drops what is latched before it sets the controller up, and the restore after a hibernation starts with the same loop. Give the loop a function. No functional change: the same writes in the same order. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The wake reads the lid's state for the display after it has told the SMC that the wake was taken, at every wake. The sleep order test still counted the commands of a wake without that read and has failed on its count since. Expect the read where it comes: after 'waka', before the key that ends the wake. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
A T6040 dry run of level 2 took the sleep up to the commit point with the steps counted as "can still be taken back", the SMC's sleep commit among them: the WKTP key, MBSE = slpa and the AP idle notice. It then refused, and the resume sent the SMC what a wake sends. That does not bring the SMC back. On a J616s every sensor the SMC reports stood still after such a run, the CPU die temperature at one value under load, until the next suspend that really lost power had woken; then the reports were live at once. A suspend to idle did not change it either way. So the commit belongs with the stops that only a power cycle undoes, which a dry run leaves out. Send it only when the suspend goes on to the power loss. A dry run of either level then warns the SMC and takes the warning back, as level 1 always did. apple_sleep_last_steps() had this one user and goes. A real sleep sends what it sent, in the same place. What a real sleep can still meet after the commit, a refusal at the commit point or a wake event before it, is not changed by this. The KUnit case runs a sleep that ends short of the power loss. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…ifier After a resume from disk the boot loader has cold-restarted the GPU firmware and the PMP. The PM_POST_HIBERNATION notifier re-booted the firmware against the restored host state with the device mutex held, and that includes waiting for the PMP to run again, about two seconds after its restore. The notifier, and hibernate() with it, returned only after the whole re-boot (2.5 s measured on the M4 Pro). Run the re-boot in a work item instead and let the notifier return at once. Userspace is already thawed when the notifier runs, so the mutex alone cannot keep the cold firmware out of sight once the notifier drops it. Give the device lock a restore barrier: the notifier closes it with the mutex held, and the lock does not return while it is closed (it waits on a condition variable, which releases the mutex). Only the restore work takes the mutex past the barrier; it opens the barrier with the mutex held when the re-boot ends, on success and on failure, and the end of the thaw (destroying queues the cold firmware never knew, reopening publication, or losing the device) then runs as before. Every locker (admission, the event worker, runtime PM, sysfs and debugfs readers) waits for the re-boot exactly as it waited for the mutex before. A new sleep, freeze or image restore waits for the restore work first (its PM_*_PREPARE notifiers flush it), and so does device shutdown, which also opens a barrier left by a restore cancelled before it ran and loses the device. The statistics epoch the PM_POST_HIBERNATION notifier ends is ended by the restore work while it runs. The barrier is closed only on the cold path: a firmware that kept running (aborted hibernation, failed image write) is still thawed in the notifier, and an image restore does not thaw at all. Hardware test: with vkcube and a Vulkan compute loop running, hibernate and resume; dmesg shows "GPU firmware cold after resume; re-booting it" and the PM core's "hibernation exit" before "GPU firmware republished after resume in N ms", both clients continue, and reads of /sys/bus/platform/devices/28a600000.gpu/agx_stats during the first two seconds return once the re-boot ends. Then hibernate again through systemd right after a resume (it starts about 15 s later), and suspend to RAM once: both start only after the republish line and resume with the clients running. Open: a hibernation requested while the re-boot still runs (within about 2.5 s of the resume, which the systemd path does not reach) waits for the restore work as intended, but that re-boot then fails with -EBUSY and the device is lost. Fixed by "drm/asahi: g17: take the compute channel claim through the preparation gate" later in this series. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…tion A republish of the GPU firmware after a resume from disk that fails loses the device with one line, "GPU firmware republish after resume failed: Error(16)", and nothing says which of its steps returned the error. Several of them can return EBUSY. Log the step that failed: the mailbox and shared-content resets, the fabric bridge, the coprocessor start, the kernel-window relink, the opening handshake, and the compute, render and closed-context resets of the live work. No functional change. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…n gate A compute command whose owner's channel is already bound and installed is claimed in the scheduler's readiness check under the channel's own lock only. Every other builder and publisher enters the preparation gate first, which a hibernation freeze and a firmware recovery close and join. After a resume from disk the gate stays closed until the cold firmware has been republished, but this claim ignored it: a client that prepared a command in that window claimed its channel, and the cold reset of the compute queues then refused the claimed queue with -EBUSY, losing the device. It showed with a Vulkan compute client running while a second hibernation was requested right after the first resume: GPU republish: compute queue reset failed: Error(16) Take the claim under a preparation lease (Gate::admit_claim): a closed gate refuses it, and the command waits for the reopen as on the slow path; a freeze that closes the gate while a claim is being taken joins it before it checks that the queues are quiescent. Add KUnit cases for the claim admission. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The ISP's suspend decided whether its resident firmware loses power from pm_suspend_via_firmware(). A dry run of the sleep controller goes through the same firmware-driven path but keeps the power, so the ISP stopped its firmware for nothing and could not restart it. Ask apple_sleep_power_loss(), which is false in a dry run. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…rmware
The tools/asahi/run-host-tests.py part of "Bluetooth: hci_bcm4377:
restart the transport of a chip a sleep left without firmware", which
goes with the ANE changes; the rest of that commit is with the PCIe,
storage and radio changes.
On a J616s the BCM4388 comes back from a suspend to RAM without its
firmware: the function's private configuration windows read their reset
values (window 1 0x19328000 where the driver had set 0x18002000) and,
once the windows are written again, the boot stage reads 0. The resume
wrote UNQUIESCE through the wrong window and sent its HCI commands to a
controller that could not answer. Each timed out after 2 s
("hci0: command 0x0c01 tx timeout"), the driver was rebound, and the
resume of devices took 2 to 4 s longer.
Read window 1 at resume. If it was reset, write the windows again and
read the boot stage and the RTI status. Without a running firmware
nothing is sent: the send callback fails, which ends a pending command
at once, the transport is marked for its hardware reset, and the
recovery that a command timeout starts on the J493 (close and open of
the transport, function reset, firmware boot, calibration, address) is
queued from the resume itself, without the timeout. The J616s joins that
recovery; hci0 stays registered.
A function that a resume found cold stays cold until its reset has
booted it, also when a later resume finds the windows as the first one
wrote them (a suspend that fenced the queued recovery and did not reset
the function). A cold resume queues a setup retry the suspend held back,
as a warm one does: the retry's open resets the function.
tools/asahi: bcm4377-resume-tests models the configuration windows, the
two status words and the send callback and gains the cold cases with
their mutations; bcm4377-id-tests admits the BCM4388 on a J616s next to
the BCM4378 on a J493.
J616s, suspend to RAM: the driver's resume takes 0.1 to 0.5 ms (2023 and
4022 ms before) and "hardware reset recovery completed successfully"
follows 0.42 to 0.47 s after the end of the resume. Six suspends, two of
them after a hibernation, the last three with the function's WAKE#
interrupt armed (wake-gpios), where the suspend writes no QUIESCE:
controller powered after each, the same hci0.
Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The tools/asahi/run-host-tests.py part of "Bluetooth: hci_bcm4377: resume the core after a cold function's reset", which goes with the ANE changes; the rest of that commit is with the PCIe, storage and radio changes. A BCM4388 that a suspend to RAM left without its firmware cannot answer a command until the function was reset and the firmware booted. The resume still called hci_resume_dev() on it: the core sent the commands of its resume, the send callback refused each one, and every wake logged them at error level before the transport was restarted: Bluetooth: hci0: sending frame failed (-19) Bluetooth: hci0: Opcode 0x0c01 failed: -19 Bluetooth: hci0: sending frame failed (-19) Bluetooth: hci0: Opcode 0x0c1a failed: -19 hci_bcm4377 0000:01:00.1: transport needs hardware reset on next open A controller with a scan filter, advertising or a discovery to restore gets more of these. The restart is a close and an open of the transport, and the open programs all of that again, so nothing was lost; but the commands were sent to a function that was known not to answer, and a wake that worked as designed read like a failure. The core's resume cannot simply be left out. It is what clears the core's suspended state, which a close and an open do not touch: without it the controller comes back with page scan, advertising and discovery paused for good. So the resume of a cold function now only queues the reset and leaves the core suspended. The open that booted the firmware queues the core's resume, which then finds a controller that answers: the event mask and the scan state are written once, to a running firmware. This holds for any open: after a reset that failed, or a power-off between the wake and the queued reset, the core resumes behind the next open that succeeds. The next suspend fences that work like the recovery itself. A cold function without a queued reset (a controller that was not powered) is resumed at once, as before; the core does nothing for it. The close of that restart no longer warns that the transport needs a hardware reset: the driver has just said why it restarts it. The core's own PM notifier calls hci_resume_dev() as well, once tasks are thawed. The queued reset is thawed with them and normally holds the request lock by then: the notifier waits for the open or finds the controller down, and either way the core resumes only once the firmware answers. Should the notifier run first, its commands fail as before. tools/asahi: the fixture models the core's suspended mark, the cold cases hold that no frame reaches a cold function, and new cases and mutations cover the resume behind the open, the failed reset, the power-off in between and both fences. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
Once the firmware is up, each sleep of a polled wait is armed with the channel IRQ and bounded by the polled cadence: 20 us in the first 5 ms of a wait, 250 us up to 50 ms, 1 ms after that. debugfs counts how each sleep ended, irq_wakeups for the IRQ and irq_timeouts for the bound. The second name reads as interrupts that never came. It is not that: a reply that takes longer than one sleep runs several of them out before its IRQ fires. On a J616s an EXECUTE reply arrives 90 to 150 us after the doorbell, so three to six 20 us sleeps expire first, and a LOAD or a program replay after a system sleep waits for milliseconds at that cadence. One boot with ten EXECUTEs and nine cold restarts after a sleep read irq_wakeups 74 and irq_timeouts 408, with 76 interrupts counted on the line, every result exact and no recovery: the interrupt is delivered and ends the sleep it falls into. Name the count for what it is, timer_wakeups, and say next to the two counters that it grows in normal operation. No change to the waits. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The platform data describes three cases with two flags: no sleep path, a sleep that keeps the firmware (sleep_warm) and a sleep that cycles the engine cold (sleep_cold, when sleep_warm is off). The H16 backend asked for the cold cycle as "!sleep_warm" in the prepare step, in the resume step and in the notifier, where the local "cold" was also true for a platform without any sleep path and was only right because that case returns first. Ask it in one place, ane_h16_sleep_cold(): sleep_cold and not sleep_warm. The only platform that reaches this backend is the H16 one (sleep_cold set, sleep_warm clear), for which every changed condition evaluates as before; the engine's power and register accesses and their order are unchanged. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
apple_isp_suspend() stops resident firmware before a suspend that takes the power. It asked apple_sleep_power_loss() for that, which differs from pm_suspend_via_firmware() only in a dry run of the T6040 sleep controller. Only the T8140 and T8142 tables have resident firmware; the T6040 ISP starts its firmware again from the data segment and is powered down between streams, so the condition is always false on the one SoC where the two calls can differ. Go back to pm_suspend_via_firmware() and drop the include. No ISP register access changes on any SoC. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
Three comments of the H16 backend named a firmware class with a quoted test, a workload and a bring-up observation. Say what the firmware does with the queued-request flag, what the program window has to hold and why an engine quarantined at its start must not refuse a sleep. An engine quarantined at its start is powered off by the first sleep and stays off; say so once, not at every later sleep. No change to how the engine is handled. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The tools/asahi/run-host-tests.py part of "soc: apple: sep: hold no sleep for a restore the notifier refuses", which goes with the ANE changes; the rest of that commit is with the sleep controller changes. A kernel that attached the enclave refuses to load a hibernation image over it: its PM_RESTORE_PREPARE notifier returns NOTIFY_BAD. The PM core then sends PM_POST_RESTORE to the notifiers that ran before the one that refused, not to that one. The notifier had already marked a sleep as held before it asked the driver, and nothing took the mark back: diag/sleep read "held" for the rest of that boot, or until a later sleep ended, although the boot went on with the enclave in use. Mark the sleep only once the restore is accepted. The host test runs the notifier now: a refused restore leaves nothing held, an accepted one is released by PM_POST_RESTORE, and a mutation that marks the sleep before the refusal is caught. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The tools/asahi/run-host-tests.py part of "rtc: apple-pmu: have the alarm set again after a resume from disk", which goes with the ANE changes; the rest of that commit is with the sleep controller changes. A resume from disk goes through a boot, and the PMU's alarm does not come back as the image left it. The kernel that loads the image stops an alarm that is no longer ahead when it binds this driver, and the boot firmware leaves the comparator close to the end of its range when it has no wake of its own. An alarm whose time passed with the machine off had its event acknowledged there. The restored kernel's RTC core still counted the alarm as set: its time stayed in wakealarm, a new alarm was refused as busy, and an alarm still ahead never fired. After a real restore, have the RTC core go through its timers: an alarm that is due is reported, a later one is written to the PMU again, and with none the PMU's alarm is stopped. The power-off callback does not cover this. Only a hibernation that powers off through platform hibernation ops calls it, and no Apple machine has those: the power-off or reboot after the image leaves the alarm armed. Say so where the callback and the prepare comment claimed otherwise. The host test covers the restore, with two mutations. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The tools/asahi/run-host-tests.py part of "soc: apple: sep: learn a cold resume from the PM core, not from the PMP", which goes with the ANE changes; the rest of that commit is with the sleep controller changes. iBoot boots sepOS anew on every boot and the SEP has no run bit the AP can read, so its resume from disk asked the PMP: the PMP's restore counted the resumes that found the PMP halted, and the SEP's notifier, one priority below the PMP's, compared the count taken at registration and at each hibernation's prepare and end. That tied the SEP to the PMP driver (a Kconfig dependency, a count, an export and a call from the PMP's restore) and to the order of two notifiers. pm_hibernate_restored_cold() answers the same question in the one place that knows it: whether another boot loaded the image. The notifier asks it where it compared the counts. Not restored (aborted hibernation, wake of a hybrid sleep): warm, as before. Restored and loaded by another boot: the cold path, the session is dropped and the device probed again. Restored by the kernel that wrote the image (test_resume): warm; the PMP found itself running there too. No record: the session is dropped without a probe, which is what a missing PMP count did. On the J616s the boot that loads an image always restarts the PMP, so the two signals agree on a resume, a test resume and an aborted hibernation. They differ where a boot that loaded an image did not restart the firmware (a kexec-style resume), and for a machine without a bound PMP, which can now tell. The PMP's own restore is unchanged: it still reads the ASC run bit and only stops reporting a count. The host test now drives the end of a hibernation through the notifier for an aborted hibernation, a resume after another boot, a test resume and a missing record, with three mutations that each fail it. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…ernation The tools/asahi/run-host-tests.py part of "soc: apple: drop the restore callbacks' checks for an abandoned hibernation", which goes with the ANE 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>
The H16G HWX that Apple's compiler writes carries one LC_NOTE (0x31) command, owner "src model info", which names the source model and the compiler component. The validator refused the container on the unknown command. Accept one note as an annotation with no authority over mappings. The compiler stores the payload inside the command, right after the 40-byte note header, and counts the offset from the start of the command. Require exactly that: a terminated owner name, a payload that starts after the header and ends inside the command, and zero bytes after it. A KUnit case covers the accepted note (the region table is unchanged) and the refusals: payload past the command, overlapping the header, wrapping length, nonzero padding and an unterminated or empty owner. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The validator tied the __TEXT segment flags to the scratch: SG_NORELOC (0x4) with a __DATA scratch, 0 without one. That is one compiler's habit, not a property of the program. Apple's compiler sets SG_NORELOC when the task stream has no relocations: its add [1,1,128,128] program has no scratch and flags 0x4, and its Parakeet encoder has a scratch, 1596 relocations and flags 0. The flag only says that a loader relocates nothing in the segment. The validator checks every relocation of the task stream itself and no mapping depends on the flag, so accept 0 or SG_NORELOC on __TEXT in every form. Other segments keep their exact flags. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
Apple's compiler appends STAB entries to the symbol table of an H16G HWX: N_LSYM (0x80) descriptions of the element types (float16, int8, ...) and one N_GSYM (0x20) per tensor with its array type. They have section 0 and value 0 and describe the source, not the image; their names repeat the tensor names. The validator required every entry to be a defined section symbol and refused the container. Skip entries with any N_STAB bit (type & 0xe0) after bounding their name offset by the string table, and leave them out of the duplicate-name check. Section symbols keep every existing check, and a STAB entry never stands in for a surface symbol. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
A whole-model H16G HWX names every kernel blob in its symbol table. The Parakeet encoder that Apple's compiler writes has 24809 entries (24783 section symbols, 26 STAB entries) and 1.77 MB of names, against a limit of 4096 entries and 256 KiB. The duplicate-name check also compared every pair, about 3e8 string compares for that table, and the validator runs several times per LOAD. Raise the bounds to 64K entries and 8 MiB of names, which covers a kernel region at the 1 GiB segment limit at the encoder's density, and find duplicate names by sorting the section symbol names and comparing neighbours. The table and its strings stay bounded by the file and must not overlap any other file range, as before. A KUnit case builds 30000 constant symbols, accepts them, and refuses two equal names far apart, a constant that reuses a surface name and a count above the bound. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
A large H16G model does not fit its kernel data in one __KERN_0 segment. The compiler splits it into __KERN_0, __KERN_1, ... of at most 128 MiB each (the Parakeet encoder: four segments, 390 MiB). The segments are contiguous in VM and in the file, each holds one section __kern_n, the program descriptor lists every section base after the surface bases, and the task stream addresses each section through its own BAR: relocations name the section's ordinal and carry an offset into that section. Accept up to 16 kernel segments in order. Each further segment must start where the previous one ends, in VM and in the file, and follow a wholly file-backed one, so that together they form one kernel region that maps exactly like the file and stays within the segment limit. The validated info keeps every kernel section, and @kernel spans them all with the ordinal of __kern_0. The base records of the descriptor must be the surface bases, then every kernel section base, then zero. Relocations may name any kernel section and are bounded by it. The section, segment and file-range tables grow with the kernel segments; the region table does not. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
A buffer reference (load command 0x40) names its surface in the bytes after +0x18. With names of up to seven bytes the command is 32 bytes long; Apple's compiler writes 0x28-byte commands with a 16-byte field for longer names such as "attention_mask" and "encoder_hidden". The validator took only 32-byte references and compared at most eight bytes of the name. Accept references of 32 bytes up to a 32-byte name field, with the name terminated inside the command and zero after it. A surface pairs with the tensor whose whole short name equals the reference's name, and the surface keeps names of up to 31 bytes. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The engine reads every BAR at the base the operation section gives it, and the firmware programs a BAR only from those (slot, tag) pairs. Tag 1007 names what LOAD slot 1 carries: the __KERN_0 section of a program that has one, otherwise __TEXT,__const, the constants that every program places at BAR slot 1 of its descriptor. One slot gives one base. Apple's whole-model programs need more: the Parakeet encoder reads its 38 MB of constants through BAR 1 and its kernel data through BARs 9 to 12, one per __kern_n section, with offsets into that section. No slot assignment of the kernel and the constants gives five distinct bases. Bind such a program the way a scratch is bound: the generic section lists every kernel section after the surfaces and the scratch, typed as a read-only input of the section size (up to its 16 KiB pages), each with its own ID, and the operation section binds every kernel base to that ID. EXECUTE then carries one buffer per kernel section at its place in the one kernel region mapping. LOAD slot 1 carries the constants at their address in the __TEXT mapping, as for a program without kernel data, and 1007 binds BAR slot 1. A program whose generic section has no kernel entries keeps the existing form: slot 1 carries its one kernel section, which it must bind through 1007. That form refuses more than one kernel section. In every form a 1007 pair must name the resource slot 1 really carries, so the constants base binds to 1007 only when slot 1 holds them. KUnit covers both forms: the slot table and EXECUTE descriptors of a four-section program with a scratch, the refusal of four sections in the slot-1 form, unbound or mismatched kernel IDs, kernel entry sizes, types and duplicate IDs, and which base 1007 may name. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The load planner capped the sum of all mapped regions of one program at 512M, although each segment may map 1G. Apple's Parakeet encoder maps 488M (390M of kernel data in one region, 37M of __TEXT, a 59M scratch, 1.2M of surfaces): it fits with 24M to spare, and a slightly larger model or a longer input would fail the plan with -E2BIG while every one of its segments is far below its own limit. Raise the sum to 2G, twice the segment limit. The bound stays: every region is rounded to the 16K mapping size and added with an overflow check before any memory is taken, and a program beyond it is refused before any firmware-visible mapping exists. The test plans 1.5G, exactly 2G and one page more, and checks that a segment above its own limit still refuses. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
Teach the host section builder the forms the driver now takes: - kernel segments __KERN_0..__KERN_n in order; - BAR slot 1 at __TEXT,__const binds index 1007, which names the constants whenever LOAD slot 1 carries them (no kernel section, or kernel sections bound as buffers). A program without kernel data used to leave that slot unbound; --no-constants-ref keeps that behaviour for comparison; - a program with several kernel sections, or with a kernel section and a constant operand, lists each kernel section in the generic section after the surfaces and the scratch, as an input of the section size with the next input ID, and binds every kernel base to its ID. Buffer references with names longer than seven bytes already parse. The sections of the add-128 fixture, the conv/relu program and Apple's add [1,1,128,128] program are byte-identical to before. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
Describe what the H16 validator now takes from Apple's compiler: the provenance note, STAB entries, SG_NORELOC on __TEXT, longer buffer reference names and kernel data split over __KERN_0..__KERN_15, with the aperture records and relocations that go with them. Describe what index 1007 names, the kernel-buffer form of a program with split kernel data or constants next to kernel data, and the 2 GiB budget, and say that the buffer form has not been run on hardware. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…ller The H16 firmware checks every EXECUTE buffer descriptor against the buffer size the program's generic section declared at LOAD, like H17 does: a descriptor smaller than the declared buffer makes the firmware refuse the request, and the engine hangs until it is booted again. H16 descriptors carry the HWX section size. That covers programs whose surface section spans the whole buffer, but Apple-compiled HWX keep only the tensor in the section: a [1, 512] add has a 0x400 section in a 0x4000 buffer, and the Parakeet encoder mask has 0x1780 of 0x4000. Both hung on every EXECUTE. Send the larger of the declared size and the section size on H16. A section that already covers the declared buffer sends the same size as before; the declared size never exceeds the mapping, which LOAD checked. With the sections grown to the buffer size in the file, the [1, 512] add and the whole encoder run on the J616s, so the size is the only change they need. The test sends a section holding only the span and expects the declared size. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
fbalazsy
force-pushed
the
j616s/split-ane
branch
from
November 14, 2026 18:46
9f4b5d4 to
90cf680
Compare
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 9/9 of the split of #1477 into smaller pull requests. Depends on #1915: GitHub cannot stack pull requests from a fork, so this one also carries the commits of #1903, #1904, #1909, #1910, #1911, #1912, #1913, #1914, #1915; its own are the last 22, from d601491 on (16 files changed, 1412 insertions(+), 234 deletions(-)).
The H16 ANE: the cold sleep cycle, the firmware described by what it does, and the program loader for whole models (the provenance note,
SG_NORELOCon__TEXT, the symbol table's debugging entries, kernel data split over__KERN_0..n, long surface names, the declared buffer size). The ISP asks the sleep controller whether its power was lost. The host-test runner's list of mutations for the tests of the earlier parts is here, at the top of the stack.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.