Repository navigation
Conversation
…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>
The recovery of the PHY's coprocessor wants the mailbox's power domain off, and waits for whoever keeps the mailbox active, six looks over 62 to 72 ms, before it settles for a normal start of the firmware. When the PHY itself is still in use it is the one that keeps it active, and no wait ends that. pm_runtime_force_suspend() runs the PHY's suspend callback, but leaves a device with an active child or another user a consumer of its suppliers, and the mailbox is this PHY's supplier with a runtime PM device link. Every phy that is powered on is an active child: USB2, which a start of the host powers before USB3, and the phy whose power-on runs the recovery. On a J616s the recovery ended this way each time it ran: USB2 host sequence complete USB3: phymxwrap suspend failed: -11 USB3 PHY bring-up failed (-11), USB2 only Look once in that case, and go on to the normal start if the mailbox is held: the wait was dead time in every start of a host after a stop that was not clean. A PHY that the PM core did suspend has given its hold up, and waits for the mailbox's other users as before. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
A port keeps its host through a sleep when fifteen conditions hold. The line that reports a host that stops instead showed nine of the values behind them, so a port that was refused for one of the others (the controller in reset, the mode, a sleep it is still down or in reset from, the PIPE on the USB4 router, a router that runs, DisplayPort's pin assignment) could not be told from one that should have been kept. On a J616s with a display on the port: the host stops for the sleep: USB2 1, USB3 0, PIPE 0, DP 1/1, CIO 0, lent 1, failed 0/0 Name every condition that fails, as the Type-C PHY of the older SoCs does for its own list: here "because: dp_up dp_four_lanes usb3_lent". The line that refuses a sleep for a port that changed after the prepare gets the same names. KUnit: each condition alone gives its name and stops the host, a port that sleeps in place has none, and all of them fit into the buffer. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
When the PHY's coprocessor does not start or does not tune the PHY for USB4/Thunderbolt, the bring-up stops the coprocessor and puts the CFG block back into its boot state, and nothing else. By then both lanes' receivers are powered by override and the transmitters and the common block are released to the coprocessor. The teardown of a CIO session takes all of that down first, both TX lanes and the common block, then the receivers, and waits 200 us before the coprocessor stops; so did this error exit before the bring-up was rewritten for the USB4 router. The port then goes back to USB3, whose bring-up releases the overrides of the plug's lane only. Run the teardown's steps on the error exit again, so that a failed CIO attempt leaves the PHY as an ended CIO session does. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The PHY's coprocessor runs the same firmware for USB4/Thunderbolt as for USB3, and the driver's recovery belongs to the coprocessor, not to a mode: a power cycle of its domains before the start that follows a stop that was not clean, one more start when one does not tune the PHY, and the pending state ended by a start that does. The CIO bring-up had all three until it was rewritten for the USB4 router, and has had none since: - a CIO bring-up over a pending power cycle went ahead as if nothing was pending, and its clean start did not end that state, so the next USB3 bring-up still ran the recovery; - a start that failed once was final, and the port stayed out of USB4/Thunderbolt until the next attach. Run the recovery around the firmware start again, the way the USB3 bring-up does. A bring-up that works at once, with nothing pending, goes through no step it did not go through before. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
DP's power-on waits for the wake of a host that was kept through a sleep, from the PHY's early resume on. A sleep that is abandoned while devices still suspend, after the controller's glue has taken the port down, has no early resume phase: the devices that had suspended get their resume callback and nothing else. The host's resume brings the port back all the same, but a display that was reported before it found the port down and got no link, where it should have waited. Arm the wait in the resume callback as well. The PHY is a supplier of the controller, so this runs before the host's resume. After a sleep that was not abandoned it finds the port as the early phase left it and changes nothing. The wait is not armed earlier, when the port goes down, on purpose: while the system still suspends no wake is coming, and DP's power-on would stall for the whole 2 s. A sleep that is abandoned between the glue's suspend and the PHY's own gives the PHY no callback at all, and stays as it was. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
DP's power-on can wait up to 2 s for the wake of a host that was kept through a sleep. Nothing said in which context that wait runs, and a device's resume callback that waited there would hold the whole resume up for as long. It doesn't come to that. The display's driver powers a port's DP phy on from its link work. After a sleep it queues that work from its resume on a workqueue that is not frozen, so it can run while devices still resume, and that is the wait's one customer. The Type-C controller reports a display from works that are frozen until every device has resumed, the host included, and then nothing is left to wait for. Write it down next to the wait. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…hey do Eight comments of the USB4 and sleep code described what the PIPE handler and the tunnel clocks do by software mode numbers for USB3 and by the order in which code runs. Say what the hardware needs instead: where the PIPE goes and with which handshake, that the tunnel clocks go down first in the PHY's shutdown of mode 2, that the pixel clock index is the display controller's, and that the PHY's firmware can save its state for a sleep. No code changes. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
A host that is not kept through a sleep is reported with the core's mark register: "host lost its state in the sleep (-5, GUID 0)". When the PHY answered with an error, or the core was not set up again after the PHY had released its reset, the register is not read at all, and the line still showed a GUID of 0 next to the PHY's answer, as if the mark had been read and found gone. Say for that case that the host was not set up again, with what the PHY said. The line for a mark that was read and is gone stays as it is. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
Every wake of a T6040 Type-C port whose host was kept through the sleep
logged "host kept through the sleep: core and PHY set up again, xHCI
starts over" for each port, next to the PHY's own line for the same wake
("PHY back after the sleep with the host kept, USB3 up"). The two lines
for a fixed hub's host, in the same switch, are at the debug level: put
this one there as well.
Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The CIO bring-up stored the plug orientation it had programmed in cio_flip, and nothing ever read it: the teardown of mode 2 is the same for both orientations, and the next bring-up takes the orientation from the Type-C switch again. Drop the field and its one store. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The PHY's tunable tables are applied by their position in one list, and three places depended on positions written out as numbers: the AUSPLL table that USB3 applies once more (7), the lane tables that DP writes again after each link power-up (4 and 5), and the generic tables DP starts with (the first 6). A static_assert checked that the last two agree with each other, not that the list has those tables at those positions. Name the positions in an enum and build the list with designated initialisers, so that a table that moves takes its users with it. The generated code doesn't change. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
checkpatch --strict: "multiple assignments should be avoided" for the two DP tunnel rates that a restore from disk clears. Clear them one by one. The generated code doesn't change. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The teardown of a CIO session and the error exit of the CIO bring-up run the same shutdown: both TX lanes and the common block down, the two receivers powered down, 200 us, the coprocessor stopped, the CFG block back in its boot state. Put it into one function for both. The register accesses of either path and their order are as before. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
When a write of the USB2 power-down sequence does not read back, the PHY marks itself failed and refuses every later operation: no power cycle of a PHY in an unknown state. A port that goes down for a sleep with its host kept logs that and lets the sleep go on, which is right, as the sleep powers the SoC down and the USB2 PHY with it. But the mark outlived the sleep. The wake refused to bring USB2 up on a PHY that had just been through its reset, the host was restarted, its stop failed on the same mark, and from then on the stop of that host failed before every sleep, which refuses the sleep: one write that did not land, and the machine did not sleep again until it was rebooted. A restore from disk already drops the mark, as the PHY comes back cold. A sleep that powers the SoC down is the same for the PHY: drop the mark there too, next to the coprocessor's pending power cycle, in one helper for both. After a sleep that left the SoC powered the mark stays, and the wake reports the port as before. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…idle A suspend-to-idle leaves a USB host running: xHCI keeps going so that a device can wake the system, and the controller's glue keeps the controller's power domain on by being a syscore device. On T8132 the Type-C PHY shares that domain. On T6040 it does not: the PHY sits in atcN_common_dp, below atcN_phymxwrap, which powers the PHY's coprocessor and its mailbox, and in the noirq phase of every system sleep the PM domain core powers off the domain of each device that has suspended. So a suspend-to-idle took the power from a coprocessor whose firmware ran, and the driver went on taking it for running. The next stop of USB3 then asked a coprocessor that was no longer there: RTKit: AP idle not acknowledged: -62 USB3: PHY coprocessor idle failed: -62 USB3: no asynchronous Power Down acknowledge On a J616s this came with the first deep sleep after one suspend-to-idle of 15 s, on both ports with USB3 up at once, and with no sleep of a boot that had no suspend-to-idle before it. Keep the domain on for as long as the firmware runs: refuse the power-off in the domain's notifier while the coprocessor is between its start and the end of its stop. The mailbox's domain stays with it, as the parent of a domain that is on. A host that goes down for a deep sleep stops the coprocessor first, and so do CIO's teardown for every sleep and the recovery before its power cycle: none of them is held up. The other way, to stop the coprocessor for the suspend-to-idle and to start it again after it, would have the firmware tune the PHY once more under a link that is up, with devices that are only suspended. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The glue device has a suspend callback and no resume callback, and was not marked asynchronous. Its xHCI child is, but an asynchronous device starts to resume only once the PM core has reached it in the list, and the core gets past the glue device only in list order. On a J616s wake from suspend-to-RAM the main PM thread waited 522 ms in a synchronous device ahead of the glue (an rfkill device behind the Wi-Fi function's restart), and both USB hosts with a dock's hub tree below them started only then. On the way in the two glue devices' suspends ran one after the other, 120 and 68 ms. Mark the glue asynchronous. What it depends on is given by its parent and its device links (PHY, DARTs, power domains), which the PM core keeps for asynchronous devices too. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
t6040_usb3_tunables() carried a private copy of the nine fixed DPTX tunable writes that the DP path already keeps in t6040_dptx_tunables[]. Move that table and its writer above the USB3 tunables and use them from both places, so the two paths cannot drift apart. The writes and their order are unchanged: the object code of the USB3 bring-up now calls the shared writer at the same point, between the tunable lists and the AUSPLL tunable, and the duplicate table is gone from the object. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
After a sleep in place, dwc3_apple_core_reinit() resets the PIPE only if the controller is a T6040 one. The phy_down argument is already set only when the PHY reports that it held the core in reset for the sleep, and only the T6040 USB2 PHY ever does so; the other Type-C PHY never returns that result. So the compatible check adds nothing: drop it and key the PIPE reset on what the PHY reported. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…s own The drivers/phy/apple/t6040-usb2.c, include/linux/soc/apple/dp-tunnel.h part of "phy: apple: t6040: give the DP tunnel pixel clock a symbol of its own", which goes with the USB, Type-C and USB4 changes; the rest of that commit is with the display changes. The T6040 PHY exported its tunnel pixel clock as apple_atc_dp_tunnel_rate() only when phy-apple-atc is not built. With both PHY drivers in one kernel the T6040 tunnel had no provider: the ATC driver's symbol refuses a PHY that is not its own, so the clock of a Thunderbolt DisplayPort tunnel was never started. Export apple_t6040_dp_tunnel_rate() unconditionally, as for T6050, and let the display fabric call it on T6040 and T6041 for the clock, and for the stop of a split tunnel. The rate call starts everything there, so the separate "open" step is left out on those SoCs. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
typec_altmode_update_active() takes a reference on the module of the bound driver when a partner or plug mode becomes active and puts it back when the mode becomes inactive. A mode that the port controller activates before its driver has bound (typec_displayport is loaded by the uevent of the altmode device) takes no reference, but the put on the next deactivation still runs. The module's count then falls to zero while it is in use (lsmod shows -1), and the next activation, at the next plug of the display, fails try_module_get() and warns: WARNING: at typec_altmode_update_active+0xfc [typec] cd321x_update_work+0x32c [tps6598x_core] Remember in struct altmode whether the reference is held. Put it back only when it is held, take it when the driver binds a mode that is already active, and never take it twice. Seen on the J616s, whose Type-C controller activates the DisplayPort partner mode itself: count -1 after the first DisplayPort plug of a boot, the warning at the following replug. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
A role the port controller asks for while the controller is stopped for a sleep, or kept through one, was turned into the state to come back in by two helpers: one mapped the role directly, the other additionally refused device mode on a host-only port, as a running controller does. The stopped case missed the host-only rule, so a device role asked for during a sleep would have started device mode on a T6040 port after the wake, where the live path stays off. Use one helper that takes host_only for both cases and a single branch in the role switch. A host-only port now stays off after a sleep it was stopped for, as it does when running; the other cases are unchanged. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The controller's glue asked the ATC PHY driver first and the T6040 PHY driver second, each call chained on -EOPNOTSUPP, and every provider needed an inline stub for a kernel that does not build it. Both drivers now export the ops of their USB2 PHY, and the glue's helpers choose the provider by comparing the PHY's ops, as the providers do when they look their own state up. A PHY of neither driver gets the answers it got from the chain: -EOPNOTSUPP where an answer is needed, nothing to do otherwise. The stubs go, since a provider that is not built is never selected. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The probe and the restore after a resume from disk both put the controller into system power state S0, check that application firmware runs and load the patch if the controller waits for one. The restore repeated the probe's sequence step by step. Move the sequence into one helper that both call. The order of the steps, their error returns and what the probe does with the mode it found are unchanged. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
The router called the T6040 Type-C PHY through four exported functions that took the PHY's device node, found the platform device by that node on every call and kept the driver bound with the device lock. Nothing ordered the router's probe or power management after the PHY. Get the PHY at probe with devm_phy_get() from the router's phys property and pass the struct phy to the same four calls, as the USB controller does for its sleep steps. The PHY framework links the router to the PHY as its consumer, and a router whose PHY is not bound yet defers its probe instead of failing its first start. The PHY side checks that the PHY is a T6040 Type-C PHY by its ops, takes its lock and runs the same steps. The check for an enabled router in the PHY driver reads the same property. Not run on a USB4/Thunderbolt device. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
…ndoned hibernation The drivers/phy/apple/t6040-usb2.c, drivers/usb/typec/tipd/spmi.c part of "soc: apple: drop the restore callbacks' checks for an abandoned hibernation", which goes with the USB, Type-C and USB4 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>
DP IN 1 of a Thunderbolt tunnel runs on PCLK2, and on T6030 and T8132 its video stops unless PCLK1 runs as well, at the same rate when DP IN 0 does not use it. The T6040 tunnel clock enabled PCLK2 alone for DP IN 1, so the second stream of a two-stream display (a tiled one) got no video. Enable PCLK1 whenever either adapter runs, and write DP IN 1's rate into the PCLK1 select while DP IN 0 is off. Hold clock switch 1 for it, and release the switch and the enable when DP IN 1 stops, or hand PCLK1 over to DP IN 1's rate when DP IN 0 stops first. A stop of the whole tunnel releases the held switch. Not run on a Thunderbolt display; this follows the two SoCs where the requirement was measured. Signed-off-by: František Balázsy <frantisekbalazsy@gmail.com>
fbalazsy
force-pushed
the
j616s/split-usb
branch
from
November 14, 2026 18:46
c89b0d9 to
346a417
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 6/9 of the split of #1477 into smaller pull requests. Depends on #1912: GitHub cannot stack pull requests from a fork, so this one also carries the commits of #1903, #1904, #1909, #1910, #1911, #1912; its own are the last 58, from 4dcdbe8 on (26 files changed, 3636 insertions(+), 469 deletions(-)).
USB, Type-C and USB4 on the J616s across hibernation and suspend-to-RAM:
phy: apple: t6040usb: dwc3: appleusb: typec: tipdthunderbolt: applestruct phyTested: 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.