Skip to content

Add tb-ar-shim-dkms: Alpine Ridge suspend fix for the MacBookPro14,1 - #349

Open
orospakr wants to merge 2 commits into
omacom:masterfrom
orospakr:tb-ar-shim-dkms
Open

orospakr wants to merge 2 commits into
omacom:masterfrom
orospakr:tb-ar-shim-dkms

Conversation

@orospakr

@orospakr orospakr commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Adds tb-ar-shim-dkms, a temporary ([FOR-UPSTREAM]) DKMS package fixing suspend/resume of the Alpine Ridge Thunderbolt 3 controller on the Apple MacBookPro14,1, per the investigation in omacom/omarchy#10593.

Shape: the same as qmk-hid / tzupdate — a "source": "local" PKGBUILD that fetches a tag tarball from the module's own public repo, https://github.com/orospakr/linux-apple-alpine-ridge-suspend, with a git_tags upstream provider in package.json so sync-upstream opens the version bumps. What omarchy-pkgs carries is the PKGBUILD and the metadata (~35 lines); the module source, its README, the in-tree drivers/pci/quirks.c patch headed to linux-pci, and the CI that builds the module against Arch linux/linux-lts headers and re-checks the upstream patch against pci-next weekly all live in that repo. (An earlier revision of this PR vendored the C source here; this is the slimmed-down replacement.)

What it fixes: two kernel bugs on this machine, both of which leave Thunderbolt and the USB-C ports dead after every suspend:

  1. deep/S3: the PCI core saves the controller's bridge config space after the thunderbolt driver has already put the chip to sleep, so it saves all-ones and restores garbage on wake — 75–107 s resumes, dead NHI, hot-removed xHCI.
  2. s2idle: the core skips config restore entirely (skip_bus_pm + pm_suspend_no_platform()), but this controller genuinely loses its config space during sleep — dead NHI (-ESHUTDOWN) until module reload.

The module grafts a dev_pm_domain onto the controller's upstream bridge: saves the subtree's config space in suspend_late (while the chip is still readable) and restores it parents-first in resume_noirq. It autoloads by PCI modalias and verifies the on-board controller via Apple's ACPI signature (same trick as the mainline Cactus Ridge quirk), so it exits -ENODEV everywhere else.

Validation: 28/28 suspend cycles on a MacBookPro14,1 across both sleep modes, 1.3–1.4 s resumes; the previous revision of this exact module was installed via pacman, dkms-built, and verified through a cold boot (modalias autoload + suspend). makepkg of this revision verified locally against the v1.0.0 tag tarball; the module source is byte-identical apart from one comment line pointing at the new repo.

Sunset: documented in the upstream repo README — once the quirks land in mainline and every bootable kernel has them, the package is removed with pacman -Rns. The companion install-script/migration PR omacom/omarchy#10758 (gating on the exact DMI model and defaulting the machine to s2idle) depends on this package being published.

🤖 Generated with Claude Code

https://claude.ai/code/session_014SjBV8RAyo6et6LMmurU9W

Temporary [FOR-UPSTREAM] DKMS carry of the tb_ar_shim module, which fixes
suspend/resume of the Alpine Ridge Thunderbolt 3 controller on the Apple
MacBookPro14,1 (omacom/omarchy#10593). Same shape as qmk-hid/tzupdate: a
"source": "local" PKGBUILD fetching the tag tarball from the module's own
repo, https://github.com/orospakr/linux-apple-alpine-ridge-suspend, with a
git_tags upstream provider so sync-upstream opens version bumps. The
module source, README, the drivers/pci/quirks.c patch headed to linux-pci,
and the CI that builds the module against Arch linux/linux-lts headers all
live in that repo; omarchy-pkgs carries only the PKGBUILD and metadata.

Validated on MacBookPro14,1: 28/28 suspend cycles across both sleep modes,
1.3-1.4 s resumes; the module installed via pacman, dkms-built, cold-boot
autoload verified. The companion detector/install script/migration is
omacom/omarchy#10758.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014SjBV8RAyo6et6LMmurU9W
@angellindo

Copy link
Copy Markdown

Data point from a MacBookPro14,3 (dual Alpine Ridge JHL6540, kernel 7.2.5-3-omarchy, s2idle). I have not run this shim. This is about scope and an alternative, not a test result for this package.

  • Same hardware path as the 14,1. Both upstream bridges here are 8086:1578 (04:00.0 behind PEG1, 7a:00.0 behind PEG2). SXFP exists as \_SB.PCI0.PEG1.UPSB.DSB0.NHI0.SXFP and the PEG2 equivalent, in SSDT7 rather than the DSDT. So the shim's device match would likely bind here. The detector in omarchy#10758 limits it to 14,1.
  • Same failure. Stock s2idle on the 14,3 shows your signature. At suspend the switch ports are inaccessible before D3hot. On resume the NHI and xHCI are not ready and tb_cfg returns -108.
  • Alternative for s2idle. Instead of restoring the config that tb_lc_set_sleep() clears, don't set the LC sleep bit on the host router when the target is s2idle. That is patch 0664 in omarchy-pkgs#596. Tested as a kprobe on the stock module, it kept both domains over six sleeps in one boot. It does not cover S3, where this patch leaves the old path.
  • Question. With the LC sleep skipped, noirq resume here is still about 17.5 s: 11.5 s and 12.6 s in pci_pm_resume_noirq on the two upstream bridges, and about 5.5 s per NHI. Your 1.3–1.4 s resumes are much faster. Were they measured with or without the ACPICA fix from omarchy-pkgs#544? And does the pm_domain on the upstream bridge change when that firmware code runs?
  • Test method. Here only the first sleep after a boot tells anything about Thunderbolt. Once one sleep fails, every later one starts with -108.

@angellindo

Copy link
Copy Markdown

Follow-up to my question above about the 17.5 s noirq resume on the MacBookPro14,3. Still not a test of this shim.

That delay was the ACPICA bug fixed by #544. On the 14,3 the PCI_Config regions of both UPSB and their DSB0 were set up during the first resume, while the upstream bridges still read Primary Bus 0. So they were cached at 00:00.0, and UPSB._PS0 polled the host bridge 300,240 times. With the 0771 logic applied as a local kretprobe module, noirq resume went from 17.8 s to 0.53 s, and the upstream bridges from 12.5 s to 0.45 s. That held on the first sleep after boot as well.

This was measured together with 0664 from #596, which skips the LC sleep instead of restoring config. Without 0664 or this shim, Thunderbolt is already gone after the first sleep, so the delay can't be measured. It could explain why your resumes were 1.3–1.4 s if your kernel already had the ACPICA fix; I haven't checked that.

Full list of 14,3 suspend fixes, their dependencies and limits (PC6 never reached, no S3 because of the Radeon SMU, first-sleep-only testing): #596.

@ryanrhughes ryanrhughes added build-approved Maintainer approved this PR to build on the self-hosted pool and removed build-approved Maintainer approved this PR to build on the self-hosted pool labels Sep 28, 2026
@orospakr

orospakr commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the 14,3 data and the follow-up.

ACPICA fix: my 1.3–1.4 s resumes were measured without it. The original 28-cycle validation was on 7.1.9-arch1-2, and my MacBookPro14,1 now runs stock linux-omarchy 7.2.5-3, which does not carry 0771. Today's cycle logged tb_ar_shim: resume_noirq done in 1315 us, and that figure includes the call into the PCI bus type's own resume_noirq.

Why the shim doesn't hit the UPSB._PS0 polling: this is my reading of the code, not a trace. The shim calls pci_save_state() on the upstream bridge and its subtree in suspend_late. pci_pm_suspend_noirq() then sees state_saved already set and skips pci_prepare_to_sleep(), so the bridge stays in D0 and gets skip_bus_pm. On resume, pci_pm_resume_noirq() takes the skip_bus_pm && pm_suspend_no_platform() branch and never calls pci_pm_default_resume_early(), so _PS0 on UPSB is never evaluated and the mis-cached CIOR/CRMW mailbox region is never polled. So the shim sidesteps the ACPICA bug rather than fixing it. 0664 skips tb_lc_set_sleep() but still lets the core move the bridge to D3hot, which would explain why 0664 needs 0771 and the shim doesn't. Happy to be corrected if your trace says otherwise. I don't have data on the pm_domain question.

Scope: agreed, the shim would very likely bind on the 14,3. The match is any 8086:1578 whose ACPI companion has DSB0.NHI0.SXFP under it, which is exactly what you found in SSDT7. The detector in omacom/omarchy#10758 is gated to 14,1 only because that's the only machine it has been run on. If you want to try the module from https://github.com/orospakr/linux-apple-alpine-ridge-suspend on the 14,3, a first-sleep-after-boot result either way would be welcome.

Power: I see the same PC6 result on the 14,1. Over a 3-minute s2idle today the package spent ~100% of the sleep in PC3 (pmc_core package_cstate_show, µs: PC3 +178.8 s, PC10 +54 ms), and slp_s0_residency_usec has been 0 for the life of the boot. A 4 h 47 min lid-closed sleep on 2026-09-20 drew 3.36 W average (battery 100% → 64.5%), so on the 14,1 s2idle costs about 3.4 W, not the 7–13 W you see on the 14,3. Fan read 0 rpm before the sleep and for the first 10 s after wake, so that isn't the draw here.

🤖 Generated with Claude Code

@tcholewa

tcholewa commented Nov 8, 2026

Copy link
Copy Markdown

Independent package/module validation on a MacBookPro14,1 (2017 13-inch, two ports), Omarchy 4.5.0-3, linux-omarchy 7.2.15-1, systemd 262.1, on November 8, 2026.

  • Built the unchanged 1.0.0-1 recipe at PR head f6aa10a. The v1.0.0 archive SHA-256 check passed; no module-source modifications were made.
  • Installed the local archive. DKMS built successfully for 7.2.15-1-omarchy and the second installed kernel, 7.2.11-arch1-1. Only the Omarchy kernel was booted/tested.
  • With s2idle and normal thunderbolt loaded, measured device resume was 0.5456 s with my earlier D3cold guard, 0.5369 s without it, and 0.5322 s on the first suspend after a complete shutdown and power-on without the guard. Both modules autoloaded after boot; the final test had d3cold_allowed=1 throughout the Thunderbolt subtree.
  • All three module cycles used automatic RTC wake, retained the USB controller/hub at 5000M, and logged configuration saved for seven devices without old resume timeout/inaccessible-controller errors. After the cold-boot cycle, the Ethernet download test reported ~925–934 Mbps.

My old controller-removal/Thunderbolt-unload hook and blacklist were inactive during these tests; the remaining local hook handled camera/display only. The device timing covers machine_suspend end to thaw_processes end, not time asleep or network reconnection.

This is three module cycles on one machine, separate from the author's cycle count. No Thunderbolt peripheral, overnight battery drain, hibernation, other model, or second-kernel runtime test was performed. The normal driver logged missing tunneled-native-port device links at initialization. This verifies the module/package on my machine, not the companion Omarchy installer/migration unchanged.

Full comparison and context: omacom/omarchy#10758 (comment). I'm withdrawing my older hook-based proposal omacom/omarchy#9899 in favor of the shim approach.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build-approved Maintainer approved this PR to build on the self-hosted pool new-omarchy-feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants