Skip to content

PCI: apple: power the J604's empty SD card reader down, as macOS does - #1998

Open
IronsideXXVI wants to merge 9 commits into
aurora-silicon:mainfrom
IronsideXXVI:j604-sd-reader-off
Open

IronsideXXVI wants to merge 9 commits into
aurora-silicon:mainfrom
IronsideXXVI:j604-sd-reader-off

Conversation

@IronsideXXVI

@IronsideXXVI IronsideXXVI commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What: Power the J604 (M4, T8132) SD card reader down while its slot is empty, as macOS does, and bring it back when a card arrives. The card detect comes from an SMC input (line 9) through new macsmc GPIO interrupts. Only the last commit (the t8132-j604 DT node) turns this on. Commits 1-8 change nothing on any machine without card-detect-gpios on a port and an SMC node marked interrupt-controller. On Aurora's J604 tree this follows #1962.

Tested: No hardware result for this head (ace5394) yet. Checked on base 5b596e6: each of the 9 commits builds pcie-apple.o and gpio-macsmc.o with clang 18.1.3 and W=1 (0 warnings, 0 errors), t8132-j604.dtb builds with card-detect-gpios, the host tests macsmc-gpio-irq-tests (8) and pcie-sd-off-tests (6) pass at every commit, and each mutation is caught. The branch also merges cleanly onto integration/aurora 70a00e5.

Risk: two-way · J604 (M4 MacBook Pro 14"). No J713 or other node has card-detect-gpios or an SMC interrupt-controller.

Not yet: The J604 run on the 4eb05ee tree (slot-empty boot, unbind/bind with the port down, 3 deep sleeps, kernel-error count against base) is to be posted, then repeated on this head. Not run at all: a card inserted while the port is off, the card-detect level with a card in, and a card across a system sleep. Ryan's J604 row (10 boots, insert/read/write/remove/reinsert, insert across deep sleep, 0 AVC denials, failed units or new kernel errors) comes after that.

Full description

On the MacBook Pro 14" M4 (J604, T8132), macOS keeps the SD card reader off while its slot is empty. Its root port and endpoint read all ones. macOS still sees a card through the SMC's card detect, which the Apple device tree routes to an SMC input (line 9). Linux keeps the reader powered with the link up. This series makes Linux do the same, in this order:

  1. gpio: macsmc: the SMC's input interrupts (event 0x7202, ack command 5). They are enabled only for a node marked interrupt-controller, so no other Mac changes.
  2. dt-bindings: gpio: apple,smc-gpio: allow interrupt-controller and #interrupt-cells on the SMC GPIO node.
  3. dt-bindings: pci: apple,pcie: a port's card-detect-gpios.
  4. PCI: apple: power a card reader port down while its slot is empty. A card brings the rail back, resets the endpoint, trains the link as probe does and rescans. A failed rail, reset or link puts the port back exactly as the power-down leaves it (apple_pcie_sd_port_off()), and the next card event tries again. Only a port with card-detect-gpios is touched. There is no module parameter.
  5. Keep an off reader's root port out of runtime PM. Without this it logs "Unable to change power state ... device inaccessible".
  6. Put the root port's config back when the reader powers up. Without this the rescan finds the bridge at its reset values, and every BAR read of the reader returns all ones.
  7. Hold the reader port's DART while the reader is off. Removing the endpoint drops the DART's last runtime PM reference, and the DART's runtime suspend then reads the stream registers of a port that is already stopped. If the DART cannot be held, the power-down stops before it removes the endpoint: the root port's hold is released and the reader stays powered.
  8. Decide the reader's power after the bus scan instead of 10 s after probe, and fix the teardown and sleep order:
    • The card-detect interrupt is requested disabled. Probe enables it and reads the slot once the scan has enumerated the reader, under the sleep notifier's lock. A port that probe starts during a system sleep keeps the interrupt off until the notifier's POST step.
    • The action that cancels the port's work is registered before the interrupt.
    • remove() takes the port off the notifier's list, disables the interrupt and cancels the work, then powers an off port back up and releases the root port and DART holds itself, before it removes the root bus. If that power-up fails, the DART keeps its runtime PM reference for good, so it never saves its state against a port in reset.
    • The sleep notifier disables the card-detect interrupt before it cancels the work and powers an off port up, and enables it again after the sleep before it reads the slot.
    • A card-detect provider that is not there yet defers the host probe together with the other port dependencies.
  9. arm64: dts: apple: t8132-j604: the reader's card detect on SMC line 9 and its interrupt. This commit turns the power-down on for the J604. Before it, commits 4-8 change nothing on any machine.

Commit 7 comes before the J604 node on purpose. Without it, our own kernels with this code on sometimes froze at boot. The panic records of two such boots point at the DART's TCR at 0x492001000 (dart-apcie2), read from apple_dart_save_state on the PM workqueue about 11 s into boot, the moment the reader powered down. On our 1.926, which carries the DART hold, ten reboots in a row with the slot empty gave no freeze of this kind; before the hold there were 2 such freezes in about 7 boots (2026-11-15). Ten boots are evidence, not proof. Those boots used the 10 s timer that commit 8 removes, so the reader now goes down earlier in boot, and that timing has not been booted yet.

Changed in this revision (review of 2026-11-23 22:06):

  • The old commits 10-12 are folded: 10 into 4, 11 and 12 into 8. The J604 node is now the last commit, so no commit before it turns the power-down on.
  • Probe vs PM_SUSPEND_PREPARE: apple_pcie_sd_start() now runs under apple_pcie_sd_lock. The notifier sets a flag under the same lock from PREPARE to POST, and a port started inside that window keeps its interrupt off (sd_asleep), so POST turns it on and reads the slot.
  • DART hold: apple_pcie_sd_hold_dart() returns an error, and apple_pcie_sd_power_down() stops before it removes the endpoint when the hold fails. A host without an iommu-map has no DART, and that is not an error.
  • The folded tree is byte-equal to the old head 4eb05ee plus these two fixes: git diff between the folded head and that linear branch is empty.

Not tested on hardware yet:

  • this head as a whole. The kernel for our J604 run was cut from 4eb05ee's tree. The code difference to this head is the two fixes above: the lock around probe's start, and the early return when the DART cannot be held. The run covers a boot with the slot empty, one unbind/bind with the port down, 3 deep sleeps with the slot empty, and the kernel-error count against the base kernel. I'll post it here, then repeat the boot and sleep rows on this head.
  • a card inserted while the port is off (the slot was empty in every run so far);
  • the card-detect level with a card in (active high follows the Apple device tree's polarity of 1);
  • a card across a system sleep.

The J604 row Ryan listed will go here: 10 boots with the slot empty, insert/read/write/remove/reinsert with the port off, one insert across a deep sleep, one unbind with the port down, and 0 AVC denials, failed units or new kernel errors.

For the J713 tree: nothing here runs without card-detect-gpios on a port, and the SMC irqchip only exists for a node marked interrupt-controller. No J713 node has either.

Order: on Aurora's J604 tree, port 2 stays disabled under the managed contract until #1962 admits it, so this follows #1962.

Checked on base 5b596e6 (this branch ace5394), 2026-11-23. The branch also merges cleanly onto the current integration/aurora tip 70a00e5.

  • Every commit builds pcie-apple.o and gpio-macsmc.o with LLVM (clang 18.1.3) and W=1: 0 warnings, 0 errors at each of the 9 commits.
  • t8132-j604.dtb builds and carries card-detect-gpios.
  • Host tests at every commit: macsmc-gpio-irq-tests 8 cases and pcie-sd-off-tests 6 cases pass, and each pcie-sd-off-tests mutation is caught. They cover the slot decision, not the remove or sleep paths.
  • checkpatch --strict: the only warnings are the ones already there (new test files and MAINTAINERS in commits 1 and 4, a quoted kernel log line in commit 5).

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Rebased onto integration/aurora c92ed85. One conflict, the include lines in pcie-apple.c; the changed lines of all nine commits are identical to what runs on the J604 in linux-aurora 1.1125. All 137 Apple DTBs build with 0 warnings and the 136 other than t8132-j604 are byte-identical to the base; pcie-apple.o and gpio-macsmc.o build with W=1 and 0 warnings; the two host tests pass (8 and 10 cases).

Back to draft: the series still has two module parameters (t8132_sd_port_off, t8132_sd_restore_root). The next revision drops them and keeps the shipped behaviour as the only one.

@IronsideXXVI
IronsideXXVI marked this pull request as draft November 20, 2026 14:07
@IronsideXXVI
IronsideXXVI force-pushed the j604-sd-reader-off branch 2 times, most recently from 8d43691 to 3bce9ab Compare November 20, 2026 17:46
@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Reworked with no module parameters. t8132_sd_port_off and t8132_sd_restore_root are gone, and so is the commit that flipped the default. A port with card-detect-gpios now goes down whenever its slot is empty, which is the path our kernels have run by default on the J604. The J604 DT commit is now last, so nothing changes on any machine before it, and the DART hold comes before it.

Rebased onto df62a8c. Each commit builds with W=1 and no warnings. The 137 Apple DTBs other than the J604's are byte-identical to the base. The host test now checks the decision without a parameter (6 cases, 3 mutations caught). The details are in the description.

Still not tested: a card inserted while the port is off. I'll post the result here. Marking this ready for review.

@IronsideXXVI
IronsideXXVI marked this pull request as ready for review November 20, 2026 17:46
@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

The host-tests failure on 3bce9ab was mine, two things:

  • tools/asahi/run-host-tests.py still asked pcie-sd-off-tests.py for the param-ignored mutation, which went away with the parameter. It now runs the three the test has: cd-inverted, empty-kept-up, read-error.
  • The macsmc-j713 selftest compiles struct macsmc_gpio against its own stubs, and the new interrupt fields needed u8 and struct notifier_block there.

Both are folded into the commits that caused them. The code is unchanged. 9345589 is green on all checks.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for dropping both parameters and putting the DART hold ahead of the DT commit; the series is much easier to follow now.

Blocking:

  1. Binding. In apple,pcie.yaml, the new card-detect-gpios is inserted between clkreq-gpios' description and its maxItems: 1. After the patch, clkreq-gpios has no maxItems and card-detect-gpios has taken it. Each needs its own maxItems: 1.
  2. The main path hasn't run. A card inserted while the port is off is still untested, and the J604 DT commit turns the power-down on. Before merge, please post a row:
    • insert a card with the port off;
    • read and write a file;
    • remove it and insert it again;
    • one insert across a deep sleep.
  3. Inert on our tree. On Aurora's J604 tree, port02 is still disabled under the managed contract (see my note on #1962). As merged, only the SMC interrupt controller would be live, and the PCI side would never run. That ties this to the #1962 decision, and I'd sequence it after that rather than merge code our own tree doesn't exercise.

Smaller:

  • APPLE_PCIE_T8132_EXP 0x70 hard-codes the root port's PCIe capability offset for a log line. pcie_capability_read_word() on the held root port (or pci_find_capability()) avoids both the constant and the SoC name in generic code.

The gpio-macsmc interrupt support looks right to me:

  • it's only enabled for a node with interrupt-controller;
  • the lines are nested threaded IRQs fed from the SMC notifier chain;
  • mode and enable are written in bus_sync_unlock;
  • the ack comes after the handler.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Thanks. I'll fix the binding so clkreq-gpios and card-detect-gpios each keep their own maxItems: 1, replace the 0x70 constant with pcie_capability_read_word(), and post the card rows you listed (insert with the port off, read and write a file, remove and reinsert, one insert across a deep sleep). I'll come back on the ordering once #1962 is settled.

The SMC can watch an input and report its configured level or edge as an
event of type 0x7202, with the line number in bits 15:8; it holds the next
event for that line until the line is acknowledged with command 5. The
driver defined the commands (IRQ enable 4, ack 5, mode 6) but never used
them, so no SMC input could be an interrupt. The earlier Asahi Linux
version of this driver had the support; this brings it back in the
current driver's shape:

- Only a node marked interrupt-controller gets an irqchip, so no other
  Mac changes. Lines whose IRQ mode reads back at probe are the ones that
  can interrupt.
- Events come from the SMC's notifier chain in process context, so the
  lines are nested threaded interrupts. Every handled event is
  acknowledged on its own key, whether or not a consumer mapped the line,
  or the SMC would hold the next one.
- The irqchip callbacks only record the wanted mode and enable; the bus
  unlock writes each of them only when it differs from what the SMC was
  last given, and a failed write is retried at the next unlock. The
  earlier version copied the mode the wrong way after a write, which wrote
  it again at every unlock.
- The chip is immutable and uses the gpiolib resource helpers.

tools/asahi/macsmc-gpio-irq-tests.py builds the event handler and the
irqchip callbacks from this file against a fixture that records every SMC
write and nested interrupt (8 cases), and kills three mutations: no ack,
the earlier mode bookkeeping, and an unchecked event type.

Signed-off-by: Dylan Ironside <[email protected]>
The SMC reports the inputs it watches as events, one line number per
event, and holds the next one for a line until it is acknowledged. Let a
node offer them as interrupts, with two cells (line, type).

The Apple device tree of the MacBook Pro 14-inch (M4, J604) describes the
SD reader's card detect this way: the reader node's interrupt-parent is the
SMC PMU and its interrupt is line 9, so the card can be detected while the
reader's PCIe port is powered down.

Signed-off-by: Dylan Ironside <[email protected]>
A card reader behind a root port can have its card detect wired to an
input that still reports while the reader is powered down. Describe it
on the port as card-detect-gpios, so the port can be powered down while
the slot is empty. The MacBook Pro 14-inch (M4, J604) wires its SD
reader's card detect to an SMC input this way.

Signed-off-by: Dylan Ironside <[email protected]>
@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Pushed 1ea0914, rebased onto 5b596e6. clkreq-gpios and card-detect-gpios each have their own maxItems: 1 now, and the log line reads the link status with pcie_capability_read_word() on the root port, so APPLE_PCIE_T8132_EXP is gone. The series' own host tests pass and every changed commit builds with W=1 without warnings. The card rows (insert with the port off, read and write a file, remove and reinsert, one insert across a deep sleep) need me at the Mac with a card; I'll post them here. Agreed on the order: this follows #1962.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 3.

  1. drivers/pci/controller/pcie-apple.c:3018 and :3292: APPLE_PCIE_SD_BOOT_DELAY_MS (10 s) delays the first look at the slot "until the reader's driver has settled". That is a fixed wait over a probe race, and the freeze you describe happened at that same 11 s mark. Make the first decision at port setup instead, before the endpoint is enumerated: read card detect in apple_pcie_sd_init() and, with the slot empty, leave the port down instead of training it. Or trigger the decision from the bus scan completing. Do not rely on a timer.

  2. pcie-apple.c:3272 / :3287 and :6773: teardown can run sd_work against a removed bus. The devm action apple_pcie_sd_remove is registered after the IRQ, so it runs first. Between its cancel_delayed_work_sync() and the IRQ being freed, a card-detect edge can queue sd_work again. On top of that, apple_pcie_remove() (:6755) calls pci_remove_root_bus() before any devm action runs, while a queued sd_work (up to 10 s at boot) still dereferences bridge->bus in apple_pcie_sd_power_down()/_power_up(). The driver has a .remove and is a module, so rmmod reaches this, and so does a later port failing probe. Fix: register the remove action before devm_request_threaded_irq(), and in apple_pcie_remove() disable the card-detect IRQ and cancel sd_work before the root bus goes.

  3. Commits: all eight carry an Assisted-by: LLM trailer. Drop it from the commits and put Assisted-by: LLM (<Vendor>:<Model>) as the last line of the description.

  4. Not blocking: pcie-apple.c:3261-3267: -EPROBE_DEFER from devm_fwnode_gpiod_get() (SMC GPIO not bound yet) is reported as "no card-detect interrupt, reader stays powered". So whether the power-down is active depends on probe order. Either defer the port (or the feature) and retry once the SMC GPIO provider appears, or at least log deferral separately so a missing power-down can be told apart from a missing line.

The gpio-macsmc part and the binding fix were covered in the earlier review; I have nothing to add there.

HW row: J604 on this head with the J604 DT commit, default command line: boot with the slot empty (reader down, no DART fault, 10 boots); insert a card with the port off, read and write a file, remove and reinsert; one insert across a deep sleep; one rmmod pcie_apple or unbind with the port down; 0 AVC denials, 0 failed units, 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Agreed on all four. This is more than I can fold into a quick respin, so here is what is changing; the push follows with the HW row.

  1. The 10 s timer goes. The first decision moves to port setup, before the endpoint is enumerated: apple_pcie_sd_init() reads card detect, and with the slot empty the port stays down instead of being trained. If card detect turns out not to be readable that early on the J604, I'll take your second option and decide when the bus scan completes. Either way there is no timer left.
  2. Teardown: the apple_pcie_sd_remove action gets registered before devm_request_threaded_irq(), and apple_pcie_remove() disables the card-detect IRQ and cancels sd_work before pci_remove_root_bus().
  3. The trailers come off the commits and the description gets the Assisted-by line. I'm leaving the vendor/model part off for now and will come back on that separately.
  4. -EPROBE_DEFER from devm_fwnode_gpiod_get() will defer the port rather than read as "no card-detect interrupt".

The HW row will be on the new head over integration/aurora 5b596e6 with the J604 DT commit: the 10 empty-slot boots, insert/read/write/remove/reinsert, the insert across a deep sleep, and the unbind with the port down.

@RyanTheTide

Copy link
Copy Markdown
Contributor

This still applies cleanly to the current integration/aurora tip 110861f, and nothing equivalent is on the tip: there's no card-detect handling in pcie-apple.c and no SMC GPIO interrupt support. The head 1ea0914 predates the respin agreed on 11-21. That respin removes the 10 s boot timer in favour of a decision at port setup, and fixes the teardown order of sd_work and the card-detect IRQ against pci_remove_root_bus(). The card rows are also still open: insert with the port off, read and write, remove and reinsert, one insert across a deep sleep. As agreed in review, this follows #1962, which is still a draft.

Build check of 110861f plus this change (arm64, LLVM=1, Image, dtbs and every directory it touches, Fedora config plus asahi.config): builds, no warnings in the files it touches; CHECK_DTBS over every Apple DTB: no new warnings against the tip. Host tests (tools/asahi/run-host-tests.py --only) on 110861f plus this change: macsmc-gpio-irq-tests passes (4/4); pcie-sd-off-tests passes (4/4).

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

@RyanTheTide the respin is a119be7 on integration/aurora 5b596e6 (it also merges cleanly onto 377060f). The branch here moves to it next. Your four points are covered by one new commit, "PCI: apple: decide a card reader port's power after the bus scan", which goes in before the J604 DT commit:

  1. Timer. APPLE_PCIE_SD_BOOT_DELAY_MS is gone. The card-detect interrupt is requested with IRQF_NO_AUTOEN. Probe enables it and queues the first look at the slot right after pci_host_common_init() returns, once the scan has enumerated the reader. I took your second option rather than deciding at port setup: the power-up path restores the root port state saved at the power-down, and a port that never trained has no saved state, so its first power-up would rescan behind a bridge at reset values. That is the bug commit 6 fixes.
  2. Teardown. apple_pcie_sd_remove is now registered before devm_request_threaded_irq(), so devres frees the interrupt first and the cancel is final. apple_pcie_remove() now calls apple_pcie_sd_stop() before it takes the rescan lock and removes the root bus. That disables the card-detect interrupt, takes the port off the sleep notifier's list and cancels sd_work. I also moved the PM notifier's register and unregister out from under apple_pcie_sd_lock, because the notifier takes that lock with the chain held.
  3. Trailers. They're off all nine commits, and the description ends with the Assisted-by line.
  4. -EPROBE_DEFER. apple_pcie_probe_port() now also gets the card-detect line and its interrupt. If either one defers, the host probe defers before any port is touched, so whether the power-down is active no longer depends on probe order. A deferral seen later in apple_pcie_sd_init() gets its own warning instead of "no card-detect interrupt".

Checked on the host: pcie-apple.o and gpio-macsmc.o build with W=1 and no warnings; t8132-j604.dtb builds; macsmc-gpio-irq-tests passes 5/5 and pcie-sd-off-tests 4/4; checkpatch --strict is clean on the new commit.

None of this head has run on the J604 yet. That includes the new decision point (the reader now goes down right after the scan, not at ~11 s), the unbind and the deferral. Your HW row is next on this head: 10 boots with the slot empty, insert/read/write/remove/reinsert with the port off, one insert across a deep sleep, one unbind with the port down, and 0 AVC denials, failed units or new kernel errors. I'll post it here. This still follows #1962.

@DjDeveloperr DjDeveloperr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Formal Pre-PR Checklist Re-Review (§1–§6) — REQUEST_CHANGES

Re-reviewed at verified live head a119be75d54e6bc073250e028208cd0b490ada9d (IronsideXXVI:j604-sd-reader-off → aurora-silicon/linux:integration/aurora). Live CI: all 9 check runs (host-tests, dt-checks, kunit ×2, rust-build, source, DWC3/ATC ×3) = success; merge state CLEAN.

Progress Since Prior Reviews

  • Documentation/devicetree/bindings/pci/apple,pcie.yaml: clkreq-gpios and card-detect-gpios each have their own maxItems: 1.
  • APPLE_PCIE_T8132_EXP replaced with pcie_capability_read_word(rp, PCI_EXP_LNKSTA, &lnksta).
  • Commit 8 (4fb7b294f224) removes APPLE_PCIE_SD_BOOT_DELAY_MS (10 s fixed timer), moves probe deferral to apple_pcie_probe_port(), registers apple_pcie_sd_remove before devm_request_threaded_irq(), and calls apple_pcie_sd_stop() in apple_pcie_remove().
  • All 9 commits now carry human author/committer (Dylan Ironside) and human Signed-off-by: only, with zero AI trailers in commits.

Blockers

  1. §2/§3 Safety — apple_pcie_remove() / unbind drops DART runtime PM hold while the port is still powered down (drivers/pci/controller/pcie-apple.c:3298-3310, 3369-3383, 6851-6874):
    • Commit 7 (e2cd4a124f5e) established that letting dart-apcie2 runtime-suspend (apple_dart_save_state()) while the SD reader port is stopped and in reset causes a synchronous external abort / SError panic.
    • In apple_pcie_remove(), apple_pcie_sd_stop() disables the card-detect IRQ and cancels sd_work, intentionally leaving the port powered down (port->sd_off == true, link stopped, endpoint in reset) while pci_stop_root_bus() and pci_remove_root_bus() run. Immediately afterwards, devres runs apple_pcie_sd_remove() → apple_pcie_sd_release_rp(), which calls pm_runtime_put(dart) while the port is still stopped and in reset (re-exposing the exact apple_dart_save_state() SError hazard from Commit 7) and calls pm_runtime_put(&rp->dev) on a pci_dev already removed from the root bus.
    • Fix: Power the port back up (matching PM_SUSPEND_PREPARE) and release sd_rp_held/sd_dart in apple_pcie_sd_stop() before pci_stop_root_bus(), or otherwise guarantee the root port and DART cannot runtime-suspend against a stopped port or after root-bus removal.
  2. §2 Concurrency bug — PM_SUSPEND_PREPARE vs card-detect IRQ / sd_work race (drivers/pci/controller/pcie-apple.c:3209-3250):
    • apple_pcie_sd_pm_notify() runs at PM_SUSPEND_PREPARE (before freezable workqueues are frozen) and calls cancel_delayed_work_sync(&port->sd_work) while port->sd_irq is still enabled.
    • Because apple_pcie_sd_power_up() sleeps >100 ms and releases pcie->lock before pci_rescan_bus() and apple_pcie_sd_release_rp(), a card-detect IRQ arriving after cancel_delayed_work_sync() can re-queue and run apple_pcie_sd_work() concurrently with apple_pcie_sd_power_up(), racing on port->sd_off, port->sd_rp_held, port->sd_dart, and pci_rescan_bus(), or powering the port back down right before system suspend.
    • Fix: Disable port->sd_irq (or serialize sd_work and apple_pcie_sd_pm_notify() with a per-port mutex and suspend state, re-enabling in PM_POST_SUSPEND/PM_POST_HIBERNATION) before cancelling sd_work and calling apple_pcie_sd_power_up().
  3. §2 Error-path state leak — apple_pcie_sd_power_up() leaves pwren_gpio on after failure (drivers/pci/controller/pcie-apple.c:3136-3173):
    • If apple_pcie_port_reset_endpoint() or link training fails after gpiod_set_value_cansleep(port->pwren_gpio, 1), the error path returns with port->sd_off = true while leaving pwren_gpio asserted (and PERST# deasserted if reset succeeded). Re-assert PERST# and drop pwren_gpio on failure so hardware state matches port->sd_off == true.
  4. §5 Evidence — Live head a119be75d54e and core card-insert/power-up path untested on hardware:
    • As acknowledged in the PR body, live head a119be75d54e has not been booted on J604 yet (including the post-scan decision point, unbind/remove with the port down, probe deferral, card-detect active-high polarity confirmation with a card inserted, insert/read/write/remove/reinsert from the powered-down state, and insert across deep sleep), and has no §5 regression tuple (0 AVC/SELinux denials, 0 failed units, 0 new kernel errors) on this head.
  5. Sequencing dependency — #1962 still OPEN and DRAFT (de49b8097bd3):
    • On integration/aurora, &port02 in t8132-j604.dts remains disabled until #1962 lands; this series remains inert on Aurora's J604 tree until #1962 is merged.

Pre-PR Checklist Summary (§1–§6)

  • §1 No model gating: PASS — gated on DT card-detect-gpios and interrupt-controller.
  • §2 Production-ready, no hacks: FAIL — PM_SUSPEND_PREPARE vs IRQ/work race, remove/unbind DART & root-port teardown order, and power-up failure rail leak.
  • §3 Safety: FAIL — remove/unbind path drops DART runtime PM ref while port 2 is still stopped/in reset.
  • §4 Clean-room & attribution: PASS — all 9 commits carry human author/committer (Dylan Ironside) and human Signed-off-by: only, zero AI trailers in commits.
  • §5 Evidence: FAIL — live head a119be75d54e unbooted, card-insert/power-up path never exercised on hardware, missing §5 regression tuple; blocked behind draft #1962.
  • §6 Naming: PASS.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

@DjDeveloperr thanks, you were right on 1 to 3. The branch is now 4eb05ee, three commits on top of a119be7, no force-push.

  1. remove() and the DART hold: a8adca8. apple_pcie_sd_stop() now powers an off port back up, the same way PM_SUSPEND_PREPARE does, and releases sd_rp_held and sd_dart itself. That happens before pci_stop_root_bus(), so devres no longer drops the DART reference against a port in reset or puts a root port that has left the bus. If that power-up fails, the port keeps its DART runtime reference for good and logs "reader stays down, its DART stays active". A DART that never suspends is better than an SError. One note on reach: in this tree the driver is built in and sets suppress_bind_attrs, so this path runs only on a module build or with unbind allowed. We test it with a test-only commit that allows unbind.
  2. The notifier race: 4eb05ee. PREPARE now disables the card-detect interrupt of each started port, then cancels sd_work, then powers the port up. POST_SUSPEND and POST_HIBERNATION enable the interrupt again and queue the work, which reads the slot. A new sd_asleep flag lets apple_pcie_sd_stop() skip a second disable_irq(). apple_pcie_sd_kick_all() is gone. I went with the interrupt instead of a per-port mutex because apple_pcie_sd_power_up() already takes pcie->lock and then the rescan lock. An outer lock would have to be ordered against both in the work item, the notifier and remove(), and it would be held across the rail delay and the link training poll. With the interrupt off and the work cancelled, nothing else can start a power change while the notifier runs.
  3. Failed power-up: 9adb0c2. Power-down and the power-up error path now share apple_pcie_sd_port_off(). It stops the LTSSM, asserts PERST# and drops pwren, so the hardware matches sd_off.
  4. Evidence: nothing has run on this head yet. The no-hands part is queued on our J604: a boot with the slot empty, one unbind/bind with the port down, 3 deep sleeps with the slot empty, and the kernel-error count against the base kernel. I'll post those numbers here. The card legs (insert with the port off, read/write, remove and reinsert, insert across a deep sleep, the card-detect level with a card in) need a card in the slot and come in a separate sitting. On AVC: our J604 runs Arch without SELinux, so there are no denials to count. The row will report failed units and new kernel errors.
  5. PCI: apple: radio: take the radio SIDs from apple,managed-sids and admit port 2 #1962: agreed, this follows it. PCI: apple: radio: take the radio SIDs from apple,managed-sids and admit port 2 #1962 is still a draft and waits on its own hardware row.

Commits 10-12 sit after the J604 node because I'm only moving the branch forward during review. I can fold them into 4 and 8 before merge if you'd rather.

Checks on this head: LLVM and GCC W=1 clean on pcie-apple.o, checkpatch --strict clean on the three commits, host tests pass (8 and 6 cases, every mutation caught), and it merges cleanly onto 70a00e5.

@DjDeveloperr DjDeveloperr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Formal §1–§6 pre-PR re-review at live head 4eb05ee09c48f287c7e14f6e502fba664b3c96bb (12 commits; base integration/aurora 377060f3688a, merges cleanly onto 70a00e583b03; not superseded; live CI: all 9 checks PASS, MERGEABLE/CLEAN).

Progress Verified Since Prior Review

  • Commit 10 (9adb0c2e5e9c): apple_pcie_sd_port_off() cleanly consolidates the power-down hardware sequence and prevents apple_pcie_sd_power_up() failure paths from leaving pwren_gpio on or PERST# deasserted while sd_off == true.
  • Commit 11 (a8adca8b1750): apple_pcie_sd_stop() now powers an off port back up and releases sd_rp_held/sd_dart before pci_stop_root_bus(), and intentionally keeps the DART runtime PM reference if power-up fails so apple_dart_save_state() cannot abort against a port in reset.
  • Commit 12 (4eb05ee09c48): PM_SUSPEND_PREPARE/PM_HIBERNATION_PREPARE now disables port->sd_irq (tracked via sd_asleep) before cancel_delayed_work_sync() and re-enables in PM_POST_SUSPEND/PM_POST_HIBERNATION, and apple_pcie_sd_stop() unlists the port before touching sd_irq, closing the PM_SUSPEND_PREPARE vs card-detect IRQ/work race and stop() vs notifier race.
  • §4 Attribution: All 12 commits carry human author/committer (Dylan Ironside <[email protected]>) and human Signed-off-by: only, zero AI commit trailers; PR body carries Assisted-by:.

Blockers Remaining

  1. §5 Hardware Evidence — live head 4eb05ee09c48 and core card-insert/power-up path still untested on hardware:
    • As acknowledged in the PR body/comment, zero hardware tests have run on 4eb05ee09c48 yet (post-scan decision point, unbind/remove with port down, probe deferral, deep sleep with empty slot), and the core card-insert / power-up path (active-high card-detect polarity confirmation with a card inserted, insert while powered down, file read/write, remove & reinsert, insert across deep sleep) has never been exercised on J604 hardware, with no §5 regression tuple (0 SELinux denials or N/A, 0 failed units, 0 new kernel errors) on this head.
  2. Sequencing dependency — #1962 is still OPEN and DRAFT (de49b8097bd3):
    • On integration/aurora, &port02 in arch/arm64/boot/dts/apple/t8132-j604.dts remains disabled until #1962 lands; this PCIe path stays inert on Aurora's tree until #1962 merges.
  3. §2/§3 Residual code & bisectability fixes for the next respin:
    • Probe vs PM_SUSPEND_PREPARE lock gap (drivers/pci/controller/pcie-apple.c apple_pcie_sd_start()): apple_pcie_sd_init() adds port to apple_pcie_sd_ports before apple_pcie_sd_start() runs, but apple_pcie_sd_start() writes port->sd_started = true, calls enable_irq(port->sd_irq), and queues sd_work without holding apple_pcie_sd_lock. A concurrent PM_SUSPEND_PREPARE can observe sd_started == false (skipping disable_irq()/sd_asleep) immediately before apple_pcie_sd_start() enables the IRQ and queues sd_work, or interleave between sd_started = true and enable_irq(). Hold apple_pcie_sd_lock around the sd_started/enable_irq()/mod_delayed_work() update (or register the port on apple_pcie_sd_ports in apple_pcie_sd_start()).
    • Fail-safe DART hold on power-down (apple_pcie_sd_hold_dart() / apple_pcie_sd_power_down()): If apple_pcie_sd_hold_dart() fails (e.g., pm_runtime_resume_and_get(&pdev->dev) < 0 or of_map_iommu_id() fails), it logs a warning and returns void, and apple_pcie_sd_power_down() proceeds to remove the endpoint and stop/reset the port without holding the DART — re-exposing the Commit 7 apple_dart_save_state() SError hazard. Return an error from apple_pcie_sd_hold_dart() and abort power-down (releasing sd_rp_held and leaving the port powered) when the DART cannot be held.
    • Bisectability: Please fold commits 10–12 into commits 4 and 8 (ahead of commit 9 t8132-j604.dts), as offered, so no intermediate commit turns on J604 power-down with the known rail-leak, remove-SError, and suspend-race bugs exposed.

§1–§6 Checklist

  • §1 No model gating: PASS — gated on DT card-detect-gpios and interrupt-controller.
  • §2 Production-ready, no hacks: REQUEST_CHANGES — close the apple_pcie_sd_start() vs PM_SUSPEND_PREPARE lock gap and fold commits 10–12 ahead of the J604 DTS commit.
  • §3 Safety: REQUEST_CHANGES — abort apple_pcie_sd_power_down() if apple_pcie_sd_hold_dart() fails rather than stopping the port with an unheld DART.
  • §4 Clean-room & attribution: PASS.
  • §5 Evidence: FAIL (blocking) — live head 4eb05ee09c48 unbooted, card-insert/power-up path untested on hardware, missing §5 health tuple, and sequenced behind draft #1962.
  • §6 Naming: PASS.

On the MacBook Pro 14-inch (M4, J604) macOS keeps the SD reader's link
off while no card is in: its root port and endpoint read all ones and the
reader reports its link as off. The Apple device tree routes the slot's
card detect to an SMC input (the reader's interrupt-parent is the SMC
PMU, line 9), so the card is seen while the reader has no power. Linux
keeps the reader powered and its link up with the slot empty.

Do the same for a port whose node has card-detect-gpios:

- An empty slot removes the reader from the bus, blocks the port's
  downstream access, holds the endpoint in reset and cuts its rail
  (pwren-gpios).
- A card (the card-detect interrupt, both edges, 200 ms debounce) brings
  the rail back, resets the endpoint, trains the link as probe does with
  probe's endpoint-reset retries, and rescans, so the reader's driver
  probes it as a new device. A failed rail, reset or link puts the port
  back exactly as the power-down leaves it (apple_pcie_sd_port_off()),
  and the next card event tries again.
- The APCIe block, the port's registers and its DART stay powered, as on
  macOS: only the endpoint loses power.
- Before a system sleep the port is powered up, and the slot is checked
  again after it, so the sleep and resume paths only see a port as probe
  left it.
- The first look at the slot waits 10 s after probe. Without the line
  or its interrupt the port is left as it is.

There is no switch: a port without card-detect-gpios is not touched.
The last commit of this series gives the J604's SD reader port the
property; until then nothing changes on any machine.

tools/asahi/pcie-sd-off-tests.py runs the decision (card, state) over
every combination and kills three mutations: an empty slot left
powered, the card detect inverted, an unreadable line taken as empty.

Signed-off-by: Dylan Ironside <[email protected]>
With its slot empty the J604's SD reader is powered down and the root
port's config space reads all ones, as macOS also reads it. The port is
then childless, so the PCI core runtime-suspends it, and each D-state
change finds no PMCSR to write:

  pcieport 0000:00:02.0: Unable to change power state from D0 to D3hot, device inaccessible
  pcieport 0000:00:02.0: Unable to change power state from D3cold to D0, device inaccessible

(the second when a config read, lspci here, resumed it).

Take a runtime PM reference on the root port before the reader goes
down, while the port still answers, and drop it once the reader is back
and rescanned, or when the port goes away. The port then stays as probe
left it while the reader is off, and no D-state change is attempted on
a port that cannot take one.

Signed-off-by: Dylan Ironside <[email protected]>
With the slot empty the J604's SD card reader is powered down, its port
reset with it, and that reset takes the root port's configuration too.
When the reader is powered up again (a card, or every system sleep,
which powers it up first), the root port reads its reset values: bus
numbers 0, no memory window, memory decoding off. The rescan renumbers
the bus but sets up no window behind a bridge that is already enabled,
so every read of the reader's BAR came back all ones and sdhci logged
"Reset 0x1 never completed" with an all-ones register dump, before and
after each sleep.

Save the root port's state at the power-down, while it still answers,
and restore it after the link is back and before the rescan, as the
radio's Neo path does before its own link.

Signed-off-by: Dylan Ironside <[email protected]>
An empty slot takes the J604's SD reader off the bus, stops its port's
link and holds the endpoint in reset, ten seconds after probe on a boot.
Removing the endpoint drops the last runtime PM reference on the port's
DART, and the DART's runtime suspend, which reads every stream's TCR and
TTBRs to save them, runs later from the PM workqueue. When it lands
after the port is stopped the read ends in a synchronous external abort
and an SError, and with kernel.panic=0 the boot stops until the watchdog
resets the Mac about a minute later.

The panic records of two such resets on the J604 show it. One was an
SError on CPU 2 after a data abort (EC 0x25, DFSC 0x10, a read) at
apple_dart_save_state+0x44, and the FAR was in dart-apcie2
(0x492000000). The other was an SError on CPU 1 with the L2C latching
0x492001000, dart-apcie2's TCR block. The boot crumb of the first one
stopped at 11 s, which is when the reader goes down. Both reset loops
happened on two kernels with this code.

Take a runtime PM reference on the port's DART, found through the
host's iommu-map, before the endpoint is removed. Drop it after the
reader is back and rescanned, when its own streams hold the DART
again, or when the port goes away. The DART then saves nothing while
its port is down. Its power domain stays on either way, with the
radio's DART in it.

If the DART cannot be held (no root port or secondary bus, no DART
device behind the iommu-map entry, or its runtime resume fails), the
power-down stops before it removes the endpoint: the root port's hold
is released, the reader stays powered and the next card event tries
again. A host without an iommu-map has no DART to hold.

Signed-off-by: Dylan Ironside <[email protected]>
The first look at an SD reader port's slot waited a fixed 10 s after
probe, and the card-detect interrupt was live from port setup. A fixed
wait over a probe race is not a decision point, and nothing stopped the
work from running against a bus that remove() had already taken down.

- The card-detect interrupt is requested disabled. Probe enables it and
  reads the slot once the bus scan has enumerated the reader, so the
  first decision follows the scan instead of a timer.
- The devres action that cancels the port's work is registered before
  the interrupt, so devres frees the interrupt first and nothing can
  queue the work after it is cancelled.
- remove() disables the card-detect interrupt, takes the port off the
  sleep notifier's list and cancels its work before it takes the rescan
  lock and removes the root bus.
- The sleep notifier is registered and unregistered outside the lock the
  notifier itself takes.
- A card-detect line whose provider (or the provider's interrupts) is not
  there yet defers the host probe with the other port dependencies,
  before any port is touched, so whether the port can power down no
  longer depends on probe order.
- remove() powers a port that is down for an empty slot back up, as
  the sleep notifier does, and releases the root port and DART holds
  itself, while the port is up and before the root bus goes. If that
  power-up fails the port stays in reset and the DART keeps its
  runtime PM reference for good, so it never saves its state against
  the port.
- The sleep notifier disables the card-detect interrupt before it
  cancels the port's work and powers the port up, and enables it again
  after the sleep, before it checks the slot. With the interrupt off
  and the work cancelled nothing else can start a power change while
  the notifier runs. sd_asleep records which ports it turned off.
  remove() takes the port off the notifier's list before it touches
  the interrupt.
- Probe turns the interrupt on under the notifier's lock. A port that
  probe starts between a PREPARE and its POST keeps the interrupt off,
  and the POST turns it on and reads the slot.

The decision is not moved ahead of training: the power-up path puts back
the root port state saved at the power-down, and a port that never
trained has none to put back.

Signed-off-by: Dylan Ironside <[email protected]>
The J604's SD reader reports its card detect through the SMC's gP09
(Apple device tree pcie-sdreader: interrupt-parent smc-pmu, interrupts
<9>, card-detect-polarity 1). Describe it on the reader's root port and
let the SMC GPIO node offer interrupts. With it the PCIe driver powers the
reader's port down while the slot is empty, as macOS does.

The level read with a card in and out is to be confirmed on the machine;
active high follows the Apple device tree's polarity of 1.

Signed-off-by: Dylan Ironside <[email protected]>
@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Thanks. Respun as ace5394, 9 commits.

  1. Probe vs PM_SUSPEND_PREPARE: apple_pcie_sd_start() now holds apple_pcie_sd_lock around sd_started, enable_irq() and the first mod_delayed_work(). The notifier sets apple_pcie_sd_sleeping under the same lock at PREPARE and clears it at POST. A port that probe starts inside that window gets sd_asleep = true and its interrupt stays off, so POST enables it and reads the slot. PREPARE now sees a port either not started or started with its interrupt on, nothing in between.
  2. DART hold on power-down: apple_pcie_sd_hold_dart() returns an error now: no root port or secondary bus, an of_map_iommu_id() error, no DART device, or a failed pm_runtime_resume_and_get(). apple_pcie_sd_power_down() then stops before it removes the endpoint. It releases the root port hold and leaves the reader powered, with sd_off still false, so the next card event tries again. A host without an iommu-map returns 0, because it has no DART to hold.
  3. Bisectability: folded. 10 went into 4 and 11 and 12 went into 8. The two fixes above went into 7 and 8. The J604 node is now the last commit. The folded tree is byte-equal to 4eb05ee plus the two fixes: git diff against that linear branch is empty. Every commit builds with LLVM W=1 with 0 warnings and passes the host tests. Commits 1-3 are unchanged.
  4. §5: still owed, and I'm not claiming it. The kernel for our J604 run was cut from 4eb05ee's tree. The only code difference to this head is the two fixes above, and the second one only runs when the DART hold fails. That run covers the slot-empty boot, unbind/bind with the port down, 3 deep sleeps with the slot empty, and the error count. I'll post it here, then repeat the boot and sleep rows on this head with the health tuple. The card-insert rows need a card in the slot, so they come with Ryan's full row.
  5. PCI: apple: radio: take the radio SIDs from apple,managed-sids and admit port 2 #1962: agreed. This stays behind it, and the body says so.

@github-actions github-actions Bot added area:bringup Area from CODEOWNERS (bot) area:gpu Area from CODEOWNERS (bot) area:platform Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (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 Nov 24, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: HOLD at ace53941c515
Blockers:

  1. PR body (§4 — AI attribution): Remove the AI attribution line at the bottom of the PR description; under the updated §4 policy, commits, PR titles, PR bodies, comments, and reviews must carry zero AI attribution.
  2. PR body & §5 evidence (J604 + second-Mac regression at ace53941c515): No hardware rows have run on ace53941c515 yet, and the core card-insert/power-up path has not been exercised on hardware. Post exact-head rows at ace53941c515 covering:
    • J604 (default cmdline): 10 empty-slot boots (reader powered down, no DART fault), card-detect active-high polarity confirmation with card inserted, insert while powered down, file read/write, remove and reinsert, insert across deep sleep, unbind/remove with port down, plus the §5 health tuple (0 SELinux/AVC denials or N/A if SELinux is absent, 0 failed units, 0 new kernel errors).
    • One other PCIe/SMC Mac (regression row for shared drivers/pci/controller/pcie-apple.c and drivers/gpio/gpio-macsmc.c): boots at ace53941c515 with 0 SELinux denials, 0 failed units, 0 new kernel errors.
    • Add Tested: (Macs at head SHA + result) and Risk: (one-way door due to new DT bindings + affected Macs) lines to the PR body.
  3. Sequencing dependency (#1962): aurora-silicon/linux#1962 (de49b8097bd3) is still open and draft; on main, &port02 in arch/arm64/boot/dts/apple/t8132-j604.dts stays disabled until #1962 lands, so this remains held behind #1962.

Checked: §1–§6 pre-PR checklist, exact interdiff 4eb05ee09c48 → ace53941c515, full 9-commit diff, PR metadata/body, and live CI (9/9 green). All code, safety, and bisectability blockers from 4eb05ee09c48 are resolved.

Evidence
  • Interdiff 4eb05ee09c48 → ace53941c515: 9 of 10 touched files are byte-identical; only drivers/pci/controller/pcie-apple.c changed:
    • Fixed: apple_pcie_sd_start() now locks apple_pcie_sd_lock and checks apple_pcie_sd_sleeping (set across PM_SUSPEND_PREPARE/PM_HIBERNATION_PREPARE to PM_POST_SUSPEND/PM_POST_HIBERNATION), closing the probe vs suspend-prepare lock gap.
    • Fixed: apple_pcie_sd_hold_dart() now returns an int error (returning 0 only when already held, held via pm_runtime_resume_and_get(), or when of_map_iommu_id() returns 0 with !args.np), and apple_pcie_sd_power_down() aborts before removing the endpoint and releases sd_rp_held on failure, closing the unheld-DART SError hazard.
    • Fixed: old commits 10–12 are folded into commits 4 (2df03e12dc64) and 8 (679fa9dc6dff), with the two new fixes in commits 7 (54305a16b1a6) and 8 (679fa9dc6dff); arch/arm64/boot/dts/apple/t8132-j604.dts (ace53941c515) is last so every intermediate commit is bisectable.
  • Checklist summary at ace53941c515:
    • §1 No model gating: PASS — gated on DT interrupt-controller (drivers/gpio/gpio-macsmc.c:634) and card-detect-gpios (drivers/pci/controller/pcie-apple.c:3343), with per-line IRQ capability probed via CMD_IRQ_MODE.
    • §2 Production-ready, no hacks: PASS — no cmdline/module parameters, no boot-delay timer, probe deferral handled in apple_pcie_probe_port().
    • §3 Safety: PASS (code) — fail-safe DART hold, apple_pcie_sd_stop() powers up before pci_stop_root_bus() and retains DART PM ref on failure, apple_pcie_sd_power_up() error path restores apple_pcie_sd_port_off().
    • §4 Clean-room & attribution: Commits 1–9 PASS (all human author/committer Dylan Ironside and human Signed-off-by: only, zero AI commit trailers); PR body FAILS due to the trailing AI attribution line.
    • §5 Evidence: BLOCKED — no hardware rows at ace53941c515 yet, card-insert/power-up path untested on J604, missing second-Mac regression row, missing Tested:/Risk: in PR body, and held behind draft #1962.
    • §6 Naming: PASS.
  • Live CI on ace53941c515881c8f7fa1276581838a561355f2: 9/9 green (dt-checks, host-tests, kunit ×2, rust-build, source, DWC3/ATC ×3); mergeable: MERGEABLE, mergeStateStatus: BLOCKED.
  • Non-blocking nit: In drivers/pci/controller/pcie-apple.c:3302-3316 (apple_pcie_sd_unlist()), if the last port unlists between PM_SUSPEND_PREPARE and PM_POST_SUSPEND, unregister_pm_notifier() stops PM_POST_SUSPEND from clearing apple_pcie_sd_sleeping; resetting apple_pcie_sd_sleeping = false when last is true under apple_pcie_sd_lock avoids stale state on a later re-probe.

@github-actions github-actions Bot added blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at ace53941: not ready yet

Check Detail
CI at head ok 9 checks passed
Review ok approved by DjDeveloperr, satchlj
Requested changes ok none
Hardware row at head no no line with the head SHA ace53941, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · J604 (M4 MacBook Pro 14"). No J713 or other node has card-detect-gpios or an SMC interrupt-controller.

Areas: area:bringup, area:gpu, area:platform

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

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Thanks. The footer is gone; the description is now the What / Tested / Risk / Not yet form with nothing else at the bottom.

The exact-head rows on ace5394 aren't in yet. The empty-slot boots, the unbind with the port down and the health tuple run without me; the card insert, remove/reinsert and insert-across-sleep rows need a card in hand, so they go in one sitting. I'll post them here together, plus the second-Mac row if I can get one, or say plainly that I couldn't.

@satchlj satchlj left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Requesting changes at ace53941c515 after a full code and DT architecture audit. In addition to the pending J604 card-insert / power-up hardware verification and #1962 sequencing already noted on this PR, there are four technical defects / non-gating issues in the driver and DT changes:

  1. Stuck apple_pcie_sd_sleeping latch when the last SD port unlists during a sleep window (drivers/pci/controller/pcie-apple.c):

    • apple_pcie_sd_pm_notify() sets the module-global apple_pcie_sd_sleeping = true on PM_SUSPEND_PREPARE / PM_HIBERNATION_PREPARE and only clears it in PM_POST_SUSPEND / PM_POST_HIBERNATION.
    • If the sole SD-managed port is removed via apple_pcie_sd_unlist() during that window (for example, a probe failure after apple_pcie_sd_init() unwinding through apple_pcie_sd_remove()), apple_pcie_sd_unlist() sees last == true and calls unregister_pm_notifier(&apple_pcie_sd_pm_nb).
    • Because the notifier is now unregistered, PM_POST_SUSPEND never clears apple_pcie_sd_sleeping; a subsequent re-probe sees apple_pcie_sd_sleeping == true in apple_pcie_sd_start(), sets port->sd_asleep = true, and leaves card-detect permanently disabled until another suspend/resume cycle fires PM_POST_SUSPEND.
    • Keeping the PM notifier registered for the module lifetime (or clearing/re-syncing sleep state safely rather than unregistering mid-sleep) avoids stranding apple_pcie_sd_sleeping.
  2. Silent root-port runtime-PM / config-save failure in apple_pcie_sd_power_down() (drivers/pci/controller/pcie-apple.c):

    • While apple_pcie_sd_hold_dart() failure cleanly aborts power-down before removing the endpoint, a failure of pm_runtime_resume_and_get(&rp->dev) (or pci_save_state()) is silently ignored: port->sd_rp_held remains NULL, yet apple_pcie_sd_power_down() proceeds to remove the endpoint and cut power anyway.
    • As commits 5 and 6 note, powering down without holding the root port active and saving its config state leaves the PCI core to runtime-suspend an all-ones root port and causes apple_pcie_sd_power_up() to skip pci_restore_state(), leaving the bridge at reset defaults (bus 0, no memory window, BARs reading 0xffffffff).
    • Treat root-port RPM acquisition and pci_save_state() failure the same way as apple_pcie_sd_hold_dart() failure and abort power-down cleanly before touching the endpoint or rail.
  3. Ignored apple_pcie_sd_power_up() failure in PM_SUSPEND_PREPARE (drivers/pci/controller/pcie-apple.c):

    • apple_pcie_sd_pm_notify() calls apple_pcie_sd_power_up(port->pcie, port) without checking its return value and always returns NOTIFY_OK. If power-up fails before sleep, system suspend proceeds into apple_pcie_suspend_noirq() with port->sd_off == true and both sd_rp_held and sd_dart still held active. Return notifier_from_errno(ret) (or explicitly handle failure) rather than silently continuing suspend in a half-recovered state.
  4. SMC GPIO event matching & SoC-wide vs board-gated interrupt-controller (drivers/gpio/gpio-macsmc.c, arch/arm64/boot/dts/apple/t8132-j604.dts):

    • macsmc_gpio_of_table binds both "apple,smc-gpio" (gP) and "apple,smc-low-gpio" (gp) to macsmc_gpio_probe(), and macsmc_gpio_event() matches (event >> 16) == SMC_EV_GPIO (0x7202) without distinguishing base_key (or restricting macsmc_gpio_init_irq() to gP / "apple,smc-gpio"). If a gp node is ever marked interrupt-controller, both instances will consume 0x7202 and send CMD_IRQ_ACK to gpXX keys.
    • In DT, &smc_gpio is defined in the shared t8132.dtsi, and macsmc_gpio_init_irq() already dynamically probes which lines the SMC firmware supports via CMD_IRQ_MODE. Putting interrupt-controller / #interrupt-cells = <2> only in t8132-j604.dts needlessly gates SMC GPIO interrupts to J604 instead of enabling the controller capability in t8132.dtsi (while keeping per-port opt-in on board-specific card-detect-gpios).

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: FINISH, then merge at ace53941c515: the code is ready; it needs only a row at this head.

Blockers: none in the code. Missing row: one J604 boot at this head with the empty SD reader powered down (as macOS does) and a card inserted later still working. I removed the attribution line from the body. Thanks.

Because gpio-macsmc.c and pcie-apple.c run on every Mac, it also needs one boot at this head on another generation with PCIe devices and SMC GPIOs unchanged before it merges.

Checked: no Apple material, no board gates. CI green.

@DjDeveloperr
DjDeveloperr dismissed stale reviews from themself November 25, 2026 05:52

Superseded by the review at ace5394

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict: MERGE at ace53941c515881c8f7fa1276581838a561355f2

Blockers: none

Checked:

  • Read again at this head; nothing shows a path that breaks a working Mac on the default command line. Host tests and mutation checks pass at every commit, and CI is green.
  • My four earlier points are error and edge paths nobody has hit, so they move to follow-ups: keep the PM notifier registered so apple_pcie_sd_sleeping cannot stick; abort power-down when the root port RPM get or pci_save_state() fails; act on a failed power-up in PM_SUSPEND_PREPARE; separate gp and gP events in gpio-macsmc.
  • Still for the merge gate: the J604 row at this head (empty-slot boot, card inserted later), and one boot on another generation with PCIe devices and SMC GPIOs unchanged.
Evidence

No commits since my last review.

@github-actions github-actions Bot removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 1, 2026

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

area:bringup Area from CODEOWNERS (bot) area:gpu Area from CODEOWNERS (bot) area:platform Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants