Skip to content

PCI: apple: acquire port GPIOs and link PWREN at probe time - #4293

Merged
DjDeveloperr merged 1 commit into
mainfrom
fix/pcie-apple-pwren-link-at-probe
Dec 4, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
fix/pcie-apple-pwren-link-at-probe

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

What: Create the pwren-gpios supplier device link at apple_pcie_probe() before any sleep cycle instead of lazily on first suspend. Fixes #4217
Tested: Host unit tests at ad5725a0bd44: 7/7 new pcie-apple device-link tests PASS. Identical patch previously passed in a combined build on J516s M3 Pro (supplier:platform:macsmc-gpio present 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, meaning macsmc-gpio could already be ordered after the PCIe root complex in dpm_list on the first suspend cycle or fail to establish the dependency cleanly at probe time. Calling it during apple_pcie_probe() for ports with pwren-gpios establishes the DL_FLAG_STATELESS supplier link (supplier:platform:macsmc-gpio) deterministically at boot.

Evidence
  • Head commit: ad5725a0bd44 on origin/main (8ae72dc32d5b)
  • Checkpatch: scripts/checkpatch.pl --git HEAD~1..HEAD — 0 errors, 0 warnings
  • Host tests (tools/testing/pcie-apple):
    • test_pwren_link_probe: 7/7 PASS
  • Hardware verification (combined trial build carrying this exact patch on J516s M3 Pro):
    • /sys/bus/platform/devices/*pcie*/supplier:platform:macsmc-gpio verified present immediately after boot
    • 11/11 consecutive deep sleeps (phased resume ~132 ms) + 1/1 s2idle PASS, 0 errors

Tested: J516s M3 Pro at ad5725a (kernel 7.3.0-j516s-s2rab: this PR + #4292 on main d2a4949, pcie-apple.c byte-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

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>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 4, 2026 09:25
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Merge readiness at ad5725a0: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at ad5725a0
Conflicts ok none
PR text ok Risk: two-way · all Macs using pcie-apple (M1, M2, M3, M4, M5 families) · every Mac on a conventional pcie-apple host (T8103 to T8152, including J516s, J773g, J700); deep-sleep resume on T6030/T6041

Areas: area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@github-actions github-actions Bot added blast:all Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) labels Dec 4, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 through direction_output on a line that is already an output. Neo's sleep probe keys off perst_gpio, which is set exactly as before on a cold port. apple_pcie_t8132_port_prepare() reuses perst_gpio when 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_gpio set). Ports with aux resets still take the serial path (new num_aux_resets check).
  • 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 requires reset-gpios and waits for macsmc-gpio before any port is touched, so EPROBE_DEFER still comes before register writes. A GPIO error in the new helper goes through err_teardown like the cold path did. No new parameter, SoC gate or constant (MAX_AUX_PERST only moved).
  • Nit, no change needed: the GPIOD_ASIS -ENOENT fallback and setup_link()'s !reset check can't trigger on these hosts, because apple_pcie_probe_port() already refuses a port without reset-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.)

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J773g (M4 Mac mini, T8132, OS fw 27.2, Stage 2 1.0.0b19-g06c581d1) second-generation non-regression hardware row at exact head ad5725a0bd4417b88c30d48fefb361895eb25717 vs main 8ae72dc32d5b (kit-j773g-c1637-4292-4293-20261204, results/run2/verdict.txt):

  • BASE main 8ae72dc3: PASS
  • VERDICT linux#4293 PASS (J773g arm h4293; base PASS) (7.3.0-j773g-c1637a #1-c1637pwren)
  • Highlights on h4293: identical PCIe GPIO consumers (PWREN, CLKREQ#, PERST# x2) and device links (1cb0000000.pcie -> 490000000.iommu, 492000000.iommu) before and after all 3/3 rtcwake -m mem deep sleeps (0->3, fail 0), all 5 PCI functions (0000:00:00.0, 0000:00:02.0, 0000:01:00.0=brcmfmac, 0000:01:00.1, 0000:02:00.0=tg3) live with drivers and config reads after every wake, Wi-Fi back in 2 s without nudge, 0 bad kernel or firmware-death lines, 62 s hold clean.
  • Results: work/kit-j773g-c1637-4292-4293-20261204/results/run2/verdict.txt

@DjDeveloperr
DjDeveloperr merged commit 7bffbe8 into main Dec 4, 2026
15 of 17 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/pcie-apple-pwren-link-at-probe branch December 4, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pcie-apple: PWREN device link is first created during deep-sleep resume when the bootloader trained the port

1 participant