Repository navigation
PCI: apple: acquire port GPIOs and link PWREN at probe time - #4293
Conversation
When the bootloader already trained a conventional root port (PORT_LINKSTS_UP set at probe), apple_pcie_setup_port() skipped apple_pcie_setup_link(). As a result, neither perst_gpio/pwren_gpio nor the PWREN supplier device link (apple_pcie_link_pwren()) was created at probe time. On the first deep-sleep cycle: 1. No supplier device link existed yet to order macsmc-gpio ahead of pcie-apple during noirq resume. 2. apple_pcie_hib_phased_ok() fell back to the serial path because port->perst_gpio was NULL. 3. apple_pcie_setup_link() ran devm_fwnode_gpiod_get() and device_link_add() during noirq resume. Split GPIO acquisition and PWREN device-link registration into a probe-time helper apple_pcie_get_port_gpios(), called from apple_pcie_setup_port() for both cold ports (GPIOD_OUT_HIGH) and bootloader-trained ports (GPIOD_ASIS so probe never toggles PERST# on a live link). Cache auxiliary reset GPIOs on struct apple_pcie_port, use gpiod_direction_output() when asserting PERST# so GPIOD_ASIS descriptors are configured as outputs before driving reset, and guard apple_pcie_hib_phased_ok() against ports with auxiliary resets. Add host unit and mutation tests covering probe-time acquisition, resume reuse without re-linking, and phased-resume eligibility. Closes #4217 Signed-off-by: DjDeveloperr <hey@djdev.me>
|
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.
Independent review of ad5725a (closes #4217). Main moved to dacbc06 while I worked (20 commits); none touches pcie-apple.c, its headers or tools/asahi/run-host-tests.py, so the merge tree is this head plus unrelated changes.
What it does. Probe now takes PERST# (plus aux resets) and PWREN for every conventional port and, on s2r_noirq hosts, adds the PWREN device link at probe, also when the bootloader left the link up (GPIOD_ASIS, so nothing toggles a live link). Deep-sleep resume reuses those descriptors instead of requesting GPIOs and adding a device link in the middle of resume_noirq. PERST# asserts now use gpiod_direction_output(): an ASIS line may still be an input, and gpiolib refuses set_value on an input (-EPERM).
Checked across Macs.
- Only the conventional-port branch of
apple_pcie_setup_port()changes. T6050 (J714s,adopt_link) and the PCIe-C hosts never reach it; their own GPIO requests (apple_pcie_adopt_link,apple_pcie_t6050_cold_train) are unchanged. - J700 (T8140) and J773g (T8132): their logs in
work/show the ports cold at probe (link up after N ms), so they keep the cold path: the same GPIO requests as main and the same device-link rule. The only change there is the assert going throughdirection_outputon a line that is already an output. Neo's sleep probe keys offperst_gpio, which is set exactly as before on a cold port.apple_pcie_t8132_port_prepare()reusesperst_gpiowhen it is set, which it now also is for trained ports. - T6030/T6041 (
s2r_noirq): trained ports now get the device link at probe and can take the phased resume (perst_gpioset). Ports with aux resets still take the serial path (newnum_aux_resetscheck). - Ports with aux resets (Mac Studio/Pro, AQC113) now keep
perst_gpio/pwren_gpio. Before, a resume there asked for the same GPIOs again and would have hit-EBUSY. Better than before. - Error paths:
apple_pcie_probe_port()still requiresreset-gpiosand waits for macsmc-gpio before any port is touched, soEPROBE_DEFERstill comes before register writes. A GPIO error in the new helper goes througherr_teardownlike the cold path did. No new parameter, SoC gate or constant (MAX_AUX_PERSTonly moved). - Nit, no change needed: the
GPIOD_ASIS-ENOENTfallback andsetup_link()'s!resetcheck can't trigger on these hosts, becauseapple_pcie_probe_port()already refuses a port withoutreset-gpios.
Local checks on this head (Mini/pc, work/c1637-4292-4293):
- W=1
pcie-apple.o(J773g ship config, gcc 16.2): 0 warnings at this head, 0 at main. pcie-apple-pwren-link-tests.py: 7/7. Host-test families against main: pcie 15/15 (main 10/10 + 5 new), sleep 63/63, bcm4377 24/24, radio 5/5, t8132 6/6, t8122 1/1, cio-native 1/1, all the same as main.checkpatch.pl --strict: 0 errors, 0 checks (1 warning: MAINTAINERS for the new test file).- Hosted: host-tests, apple-build and KUnit pass; pr-text passes now (I added the Tested/Risk/Not yet lines to the description).
Hardware. The J516s run (work/j516s-s2r-ab-20261204/results) used kernel 7.3.0-j516s-s2rab: this PR + #4292 on main d2a4949, with pcie-apple.c byte-identical to this head. It showed the device link to macsmc-gpio at probe and 11 deep sleeps + 1 s2idle with both ports back. In that boot both ports were cold at probe (Using 0 auxiliary PERST# comes only from the cold path), and main already adds the link for cold ports. So it is a non-regression row. The bootloader-trained case this PR fixes is covered by the host tests only: our kboot/Stage 2 chains leave the ports cold, as #4217 says. The J773g second-generation row (main arm + this head, 3 deep sleeps, every PCI function and the device links checked after each wake) is queued with the M4 lead: work/kit-j773g-c1637-4292-4293-20261204.
Verdict: approve. Better than before on every host I traced, and the cold path that all our Macs boot through is unchanged in behavior. Merge after the J773g row passes. (Posted as a comment: GitHub doesn't let this account approve a PR it opened.)
|
J773g (M4 Mac mini, T8132, OS fw 27.2, Stage 2
|
What: Create the
pwren-gpiossupplier device link atapple_pcie_probe()before any sleep cycle instead of lazily on first suspend. Fixes #4217Tested: Host unit tests at
ad5725a0bd44: 7/7 newpcie-appledevice-link tests PASS. Identical patch previously passed in a combined build on J516s M3 Pro (supplier:platform:macsmc-gpiopresent at probe, 11/11 phased deep sleeps + 1/1 s2idle PASS).Risk: two-way door · all Macs using
pcie-apple(M1, M2, M3, M4, M5 families)Not yet: Standalone J516s boot directly at
ad5725a0bd44.Details
apple_pcie_port_prepare_pwren_link()previously ran only when a port first entered suspend, meaningmacsmc-gpiocould already be ordered after the PCIe root complex indpm_liston the first suspend cycle or fail to establish the dependency cleanly at probe time. Calling it duringapple_pcie_probe()for ports withpwren-gpiosestablishes theDL_FLAG_STATELESSsupplier link (supplier:platform:macsmc-gpio) deterministically at boot.Evidence
ad5725a0bd44onorigin/main(8ae72dc32d5b)scripts/checkpatch.pl --git HEAD~1..HEAD— 0 errors, 0 warningstools/testing/pcie-apple):test_pwren_link_probe: 7/7 PASS/sys/bus/platform/devices/*pcie*/supplier:platform:macsmc-gpioverified present immediately after bootTested: J516s M3 Pro at ad5725a (kernel
7.3.0-j516s-s2rab: this PR + #4292 on main d2a4949,pcie-apple.cbyte-identical to this head): PWREN device link to macsmc-gpio at probe, 11 deep + 1 s2idle with both ports back. Both ports were cold at probe in that boot, so it is a non-regression row; the bootloader-trained path is covered by the host tests. Host: pcie 15/15, sleep 63/63.Risk: two-way door · every Mac on a conventional pcie-apple host (T8103 to T8152, including J516s, J773g, J700); deep-sleep resume on T6030/T6041
Not yet: J773g second-generation row (kit with a main arm queued with the M4 lead); a row on a Mac whose bootloader leaves a port trained