Repository navigation
soc: apple: sleep: T8122: PCIe ports past port 0, PD controllers on I2C - #4162
Conversation
The MacBook Pro 14-inch (J504) and the iMacs (J433, J434) have the same M3 as the MacBook Airs, with their USB-C port controllers on I2C instead of SPMI, and with PCIe ports past port 0. Let their sleep node leave out the port controllers' SPMI bus, which those boards do not have, and name the registers and the PHY lane of each port past port 0. Signed-off-by: DjDeveloperr <hey@djdev.me>
The T8122 path was written on the MacBook Airs: USB-C port controllers on SPMI, and Wi-Fi on PCIe port 0 as the only port. The J504 and the iMacs (J433, J434) have neither: their port controllers are on I2C, so the second SPMI bus is not there to touch, and the SD reader, Ethernet and USB controller are on ports 1 and 2. Take the SPMI bus only where the node names it. Shut the ports past port 0 down as port 0, after their setup and their PHY lane's words are saved, and bring their clocks and that state back with port 0's. Their DART needs that first, and then the PCIe host, which trains their link again as it does port 0's. The saved words are the running ones, so no board's tuning is in here. A board that enables a port whose registers the node does not name has deep sleep refused before anything is suspended, as the wake would find its DART behind a stopped clock. s2idle is not affected. The register accesses on a board with port 0 alone are the same as before. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Row: bd8d92d + J615 (MacBook Air 15" M3, T8122, macOS 27.2 / 26B123 stub) + default cmdline + PASS
|
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Reviewed bd8d92d347ed. The deep-sleep admission hook refuses enabled extra ports whose resources are missing, and s2idle bypasses that hook. J615 covers the port-0/SPMI path.
The new extra-port wake loop ignores the return from sleep_apcie_port_clock(). The helper stops short when a PHY clock fails to ack. Please show that a dependent DART stays gated on that failure, or handle it before the DART restore can read a stopped port. The existing shared wake path records the return per port. The positive result needs the matching follow-up DTB on a J504 for port 1 or a J434 for ports 1 and 2, with actual deep sleep and the attached endpoints working after wake.
Check PHY clock acknowledgements before restoring extra-port registers. If a clock or port fails to return, fence its DART and disconnect that port before the PCI hierarchy resumes. Keep the port 0 MMIO sequence. Signed-off-by: DjDeveloperr <hey@djdev.me>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Pushed dd1b845ee44a on top of bd8d92d347ed. The extra-port wake checks PHY clocks before it restores port registers. A timeout leaves the DART gated and the failed PCI subtree disconnected, with its config accesses and IRQ still blocked. The port-0 register sequence is unchanged.
The exact-head t8122-apcie-wake-tests.py passed the PHY, port-ready and shared root-complex timeout cases, including the healthy sibling and config access checks. ARCH=arm64 LLVM=1 make W=1 drivers/soc/apple/sleep.o drivers/pci/controller/pcie-apple.o drivers/iommu/apple-dart.o passed. Checkpatch found zero errors and checks, with the usual new-file MAINTAINERS warning. The J504/J434 row remains due.
The sleep entry skips the PCIe shutdown when a power domain does not come up, and skips a port whose PHY lane is off. Its setup is then not saved, and the wake left such a port alone: its DART would restore behind a stopped clock. Treat it as a port that failed to wake. Also repair the host tests: the new entry split the m3-sleep-steps one and stopped run-host-tests.py with a syntax error, and pciec-policy-tests.py lacked what apple_pcie_prepare() now reads. Test both refusals. Signed-off-by: DjDeveloperr <hey@djdev.me>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Reviewed dd1b845ee44a fresh and pushed one small fix, 7f7570581725. That makes me a pusher at this head.
Fixed in 7f7570581725:
tools/asahi/run-host-tests.py: the new entry was inserted in the middle of them3-sleep-steps-tests.pyexpression. That is a syntax error, so the whole host-test runner stopped. Moved it below.sleep-t8122.h,t8122_extra_ports_wake(): a port with registers that the entry did not take down was skipped at wake, with its DART left ungated. That happens when the APCIe raise int8122_apcie_down()fails, or when the lane read as off. The DART's noirq restore could then read behind a stopped clock. Such a port now takes the failed path (DART gated, port disconnected, next sleep refused).pciec-policy-tests.pydid not build against the newapple_pcie_prepare(). It now builds, and it tests that the -EIO refusal applies to the T8122 host only.
The rest reads right to me. The PHY clocks are checked before the port is touched, and on a timeout the DART is gated in the wake, before its noirq resume. The root port and subtree are disconnected in the host's noirq resume. Config access is blocked by slot, IRQs stay masked, and enable_device is refused. A second sleep is refused at .begin and at prepare. A reboot clears all of it. Other SoCs: every hook returns early unless the host is apple,t8122-pcie and the failed mask is non-zero. Port 0 is unchanged: on the J613 and J615 the new paths return before any register access. So the J615 row at bd8d92d347ed still covers port 0 at this head. One note, not blocking: after a failed port, prepare also refuses s2idle, not only deep.
Ran at 7f7570581725 on an x86 build box:
- arm64
LLVM=1 W=1build ofsleep.o,pcie-apple.oandapple-dart.o: clean (clang 23.1.3). t8122-apcie-wake-tests.py,pciec-policy-tests.pyand the sleep, DART and PCIe host tests: all pass.- Full runner: 1032/1040. The other 8 fail the same way at base, because that box is missing
fdtgetand rustup 1.93.1.
linux#4067 (731c7e362763) merges with this head without conflicts. Both add DART helpers, but different ones: apple_dart_is_host_resumed() there, apple_dart_host_wake_failed() here. The merged runner and T8122 test pass. Nothing here needs changing once #4067 lands.
Still owed: a J504 (port 1) or J434 (ports 1 and 2) deep-sleep row on this head with #4166's DT, with the endpoints back after each wake.
DjDeveloperr
left a comment
There was a problem hiding this comment.
Reviewed dd1b845ee44a fresh and pushed one small fix, 7f7570581725. That makes me a pusher at this head.
Fixed in 7f7570581725:
tools/asahi/run-host-tests.py: the new entry was inserted in the middle of them3-sleep-steps-tests.pyexpression. That is a syntax error, so the whole host-test runner stopped. Moved it below.sleep-t8122.h,t8122_extra_ports_wake(): a port with registers that the entry did not take down was skipped at wake, with its DART left ungated. That happens when the APCIe raise int8122_apcie_down()fails, or when the lane read as off. The DART's noirq restore could then read behind a stopped clock. Such a port now takes the failed path (DART gated, port disconnected, next sleep refused).pciec-policy-tests.pydid not build against the newapple_pcie_prepare(). It now builds, and it tests that the -EIO refusal applies to the T8122 host only.
The rest reads right to me. The PHY clocks are checked before the port is touched, and on a timeout the DART is gated in the wake, before its noirq resume. The root port and subtree are disconnected in the host's noirq resume. Config access is blocked by slot, IRQs stay masked, and enable_device is refused. A second sleep is refused at .begin and at prepare. A reboot clears all of it. Other SoCs: every hook returns early unless the host is apple,t8122-pcie and the failed mask is non-zero. Port 0 is unchanged: on the J613 and J615 the new paths return before any register access. So the J615 row at bd8d92d347ed still covers port 0 at this head. One note, not blocking: after a failed port, prepare also refuses s2idle, not only deep.
Ran at 7f7570581725 on an x86 build box:
- arm64
LLVM=1 W=1build ofsleep.o,pcie-apple.oandapple-dart.o: clean (clang 23.1.3). t8122-apcie-wake-tests.py,pciec-policy-tests.pyand the sleep, DART and PCIe host tests: all pass.- Full runner: 1032/1040. The other 8 fail the same way at base, because that box is missing
fdtgetand rustup 1.93.1.
linux#4067 (731c7e362763) merges with this head without conflicts. Both add DART helpers, but different ones: apple_dart_is_host_resumed() there, apple_dart_host_wake_failed() here. The merged runner and T8122 test pass. Nothing here needs changing once #4067 lands.
Still owed: a J504 (port 1) or J434 (ports 1 and 2) deep-sleep row on this head with #4166's DT, with the endpoints back after each wake.
linux#4162 peer row: J504 or J434 deep sleep with ports past port 0Head to test: linux#4162 Who: anyone with a J504 (MacBook Pro 14" M3: SD reader on port 1) or a J434 (iMac M3 4-port: Ethernet on git fetch origin 7f7570581725 a536cabbadaf
git switch -c row4162 7f7570581725
git cherry-pick bd8d92d347ed..a536cabbadaf # #4166's 5 DT commits
make ARCH=arm64 LLVM=1 Image modules dtbs # your usual config with CONFIG_APPLE_SOC_SLEEP=y
# boot it once (non-default entry) with t8122-j504.dtb / t8122-j434.dtb and, on the command line:
# apple_sleep.deep=1 apple_sleep.untested_commit=1
# J504 only: #2392 (SEP alias, MagSafe, Touch ID) must be in too, or deep sleep is refused.Before the sleeps, note the endpoints: cat /sys/power/mem_sleep # must offer [deep]
for i in 1 2; do echo deep > /sys/power/mem_sleep; rtcwake -m mem -s 20; sleep 15; done
journalctl -k -b | grep -E 'PCIe port .* failed to wake|refused|DART|Oops|WARN|S2R'
cat /sys/power/suspend_stats/fail # 0PASS line: FAIL to report: any |
satchlj
left a comment
There was a problem hiding this comment.
Reviewed head 7f7570581725 (non-pusher code review; no J504/J433/J434 hardware here, CI still running):
- DT binding (
apple,t8140-sleep.yaml):oneOfkeeps the 21–22 item SPMI layout unchanged for J613/J615 and cleanly models the I2C-PD layout (21–25 items with optionalapcie-port1/phy1/port2/phy2). - Port-0 invariance: When
t8122_extra_ports()is 0,t8122.apcie_port[1..2].portremain NULL, sot8122_apcie_down(),t8122_raise_apcie(),t8122_port0_wake(), andt8122_extra_ports_wake()preserve the exact port-0 MMIO sequence. - Admission & refcounting:
t8122_sleep_begin()refuses deep sleep unless every enabled extra port has mapped registers and a bound DART device held viadevm_add_action_or_reset(s->dev, apple_sleep_put_device, &pdev->dev), withof_node_put(iommu.np),__free(device_node), andput_device()on the!drvdataerror path all leak-free. - Failure isolation:
apple_dart_host_wake_failed()gates DART commands underdart->lockwith no MMIO and no sleeping;t8122_extra_ports_wake()handles root-complex timeout, unsaved ports (failed power-domain raise or off lane on entry), PHY clock timeout before touching port registers, and port-ready timeout;pcie-apple.cblocks config space from the root port down, disconnects the root/subordinate bus inresume_noirq, skips resume/enable/disable/IRQ re-enable, and refuses subsequent sleeps with-EIO. - Host tests:
t8122-apcie-wake-tests.pyandpciec-policy-tests.pyexercise the extracted kernel functions directly across all four failure modes.
Two tiny non-blocking notes for when J504/J433/J434 run on hardware:
t8122_phy_ip_wordshas0x9280twice (0xccccccccbefore0x9000, then0xccc8ccc1after);t8122_port_save()captures the running post-init value for both slots, so worth watching on the first port-1/2 hardware wake whether lane 1/2 needs the initial0xcccccccctransition before0x9000.- In
t8122_raise_apcie(), theapcie_axi + 0x600restore loop writes the samet8122.apcie_axi_portsword twice when both ports 1 and 2 are saved (harmless/idempotent; abreak;would suffice).
What: Let the T8122 (M3) deep sleep path run on the boards that are not MacBook Airs: USB-C port controllers on I2C (no second SPMI bus) and PCIe ports past port 0. A board that enables a PCIe port whose registers the sleep node does not name has deep sleep refused at
.begin, with s2idle unchanged. Nothing changes on the J613 and J615. First of two: the J504/J433/J434 devicetree follows on top.Tested: J615 (T8122, 27.2 stub, default command line) at bd8d92d: PASS, 3 committed deep sleeps and 1 s2idle, panel, GPU, Wi-Fi and audio back after each wake, 0 GPU faults (row). Later commits change only code that returns before any register access on a board with port 0 alone, so that row still covers the J613/J615 path. At 7f75705: arm64
LLVM=1 W=1build ofsleep.o,pcie-apple.oandapple-dart.oclean (clang 23);t8122-apcie-wake-tests.py(PHY, port-ready and shared root-complex timeouts, and a port the entry left alone) andpciec-policy-tests.pypass; fullrun-host-tests.py1032/1040, with the other 8 failing the same way at base (tools missing on the build box);checkpatch --strict0/0/0 on the new commits. At bd8d92d:dt_binding_checkofapple,t8140-sleep.yamlclean. The PCIe down, wake and port-0 functions of base 8ec8740 and of bd8d92d were run against a fake register file: with port 0 alone all 240 accesses are the same, in the same order. With port 1 added, only port 1's and lane 1's blocks and the AXI bridge's word differ.Risk: two-way door · M3 (T8122). J613 and J615 have port 0 alone and
spmi-hpmin their node, so they run the same register sequence. J504, J433 and J434 have no enabled sleep node on main.Not yet: Ports 1 and 2 have not run on any board.
Details
spmi-hpm(0x2e4908000) is the SPMI bus of the Airs' port controllers. The J504, J433 and J434 ADTs (27.2) have nonub-spmi-a0; theirhpm*are underi2c0. The driver mapped it unconditionally and wrote its notify enable..resume, as it does port 0 today.apple,t8122-pciehost past port 0 whoseapcie-portN/apcie-phyNis missing.