Skip to content

[follow-up to #50] PCI: apple: retain preinitialized tunnels when cold init is disabled - #195

Merged
RyanTheTide merged 20 commits into
fix/j414s-dual-dock-dpfrom
fix/pr50-review
Oct 8, 2026
Merged

RyanTheTide merged 20 commits into
fix/j414s-dual-dock-dpfrom
fix/pr50-review

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

The board property permits experimental kernel cold initialization, but
must not reject an existing successful m1n1 handoff. Admit the explicit
preinit certificate in both the population gate and preparation helper
without touching cold-init registers.

Keep receiver ownership reserved until teardown finishes. A competing
initialization must return EBUSY instead of overwriting the callback and
cookie, and must not stop the mailbox owned by the existing receiver.

Follow-up to #50; original contributor commits are preserved. These fixes are based on public Linux/PR source and Linux-side tests.

Validation: targeted arm64 driver build passed (object checks only); strict checkpatch passed for the final code changes with only the required Assisted-by trailer diagnostic excluded.

Hardware qualification on aurora-edge is pending. No boot, suspend, fault-injection or firmware recovery pass is claimed. The publication gate is separate from runtime acceptance.

Any outstanding contributor certification on the original PR remains outstanding; no contributor sign-off was added by this follow-up.

🤖 Generated with Claude Code

rryan and others added 20 commits September 27, 2026 13:26
J416c (16" M2 Max, T6021) shares the T602x ATC PHY, display crossbar,
USB4 NHI and the dcpext0/dcpext1 layout with J414s; only the board
gates differ. Treat J416c like J414s: two connectors per Type-C port,
DPIN0 -> dcpext0 and DPIN1 -> dcpext1, direct DP-alt displays prefer
dcpext1 so dcpext0 stays free for a dock tunnel, and allow the ATC
tunnel clock.

Tested on J416c with a CalDigit USB-C Pro Dock (Thunderbolt 3): two
3840x2160@60 displays through the dock plus the internal panel at
120 Hz, on hotplug and with the dock connected at boot.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: RJ Skerry-Ryan <[email protected]>
The per-port Type-C connectors carry DisplayPort (DP alt mode or a
Thunderbolt/USB4 DP tunnel), but were registered as
DRM_MODE_CONNECTOR_USB, which DRM reserves for USB display adapters
(gud, appletbdrm). Userspace keys on the type: systemd-logind only
counts VGA/DVI/DP/HDMI/TV connectors as external displays, so a
docked lid close suspended the machine instead of honoring
HandleLidSwitchDocked=ignore.

Register them as DisplayPort. The driver's internal "is Type-C" checks
use dcp->connector_type / fixed_connector_type and are unaffected.
Connectors are now named DP-N instead of USB-N.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: RJ Skerry-Ryan <[email protected]>
PCIe-C root ports behind a USB4 router must be cold-initialized before
use. Today the kernel only accepts ports the bootloader initialized and
reported through "apple,pciec-preinit-status", which no m1n1 does.

Add a boolean for PCIe-C nodes that tells the OS to do the cold init
itself when the USB4 PCIe tunnel comes up.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: RJ Skerry-Ryan <[email protected]>
PCIe-C tunnel support requires m1n1 to cold-initialize the port and
report "apple,pciec-preinit-status" = 1, but no m1n1 does so. On
J414/J416 the tunnel is therefore always disabled and PCIe devices
behind Thunderbolt 3 docks (whose USB is an xHCI behind the tunnel)
never appear.

m1n1 already copies the PCIe-C tunables into the DT and the driver has
the port enable sequence. For ports marked "apple,pciec-kernel-init",
let the kernel do the cold init, as #8 does for
t8103:

- apple_pcie_tunnel_cold_init() follows the enablePortHardware()
  baseline of apple_pcie_tunnel_start(): debug/fabric tunables, port
  reset table and tunables, PERST off and APPCLK on, wait for RUN, and
  only then the root-complex (config space) tunables. Touching config
  space while APPCLK is still off hard-resets a J416c.
- apple_pcie_tunnel_prepare() runs it on transient mappings before the
  tunnel children are populated, since the DART never completes an
  invalidation while APPCLK is gated. A port that is already running is
  left alone.
- The Thunderbolt glue and the host bridge accept kernel-init ports in
  place of the m1n1 handoff.

As the sequence is new on T602x, it is gated behind
pcie_apple.tunnel_kernel_init (default off), checked before the first
PCIe-C MMIO access. pcie_apple.tunnel_kernel_init_trace_ms logs each
step and pauses after it, for locating failures with a persistent log.

Tested on J416c with a CalDigit USB-C Pro Dock (Thunderbolt 3, Titan
Ridge xHCI 8086:15f0): the dock's hubs, keyboard, audio, SD reader,
webcam and Ethernet work, including after unplug and replug.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: RJ Skerry-Ryan <[email protected]>
No m1n1 performs the PCIe-C preinit handoff on these machines. Mark
apciec0-2 "apple,pciec-kernel-init" so the kernel cold-initializes the
Thunderbolt PCIe tunnel ports itself.

The tunneled DART driver also requires "apple,tunable", but iBoot adds
the corresponding "dart-tunables-instance-0" to the ADT only at boot and
m1n1 does not copy it for dart-apciec*. Without it the DART fails to
probe and devices behind the tunnel time out. Add the values from the
live J416c ADT (macOS ioreg), identical for all three ports; the same
decoding reproduces entry for entry the apciec tunables m1n1 already
copies into the DT.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: RJ Skerry-Ryan <[email protected]>
A Type-C port's encoder spans every pipeline that can drive the port, and
routing narrows its possible_crtcs to the pipeline actually chosen,
relying on userspace to re-read them on the following hotplug.
Compositors that read possible_crtcs once when the connector appears
(aquamarine, used by Hyprland) never see that. With a USB4 dock carrying
two streams, whichever connector connects first takes the lowest free
CRTC. When that is the DPIN1 connector, it gets dcpext0's CRTC while the
stream is routed to dcpext1, every modeset fails the atomic check with
-EINVAL, and both dock displays stay dark until the dock is replugged
and happens to connect in the other order.

possible_crtcs is meant to be static. On the dual-stream machines
(J414s, J416c):

- Fix the DPIN1 connector to the lowest-indexed Type-C-only pipeline
  (dcpext1), where DPIN1 is always routed, and route DPIN1 only within
  the connector's possible_crtcs.
- Leave the primary connector spanning all its pipelines and stop
  narrowing or restoring possible_crtcs at runtime.
- Route direct DP-alt displays to the lowest free CRTC, which is what a
  compositor picks from the port's fixed possible_crtcs, instead of
  steering them away from dcpext0.

A direct DP-alt display now takes dcpext0 when it is free, so a
single-stream dock on another port lands on the next free pipeline.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: RJ Skerry-Ryan <[email protected]>
PCIe-C is populated from delayed work queued when the PCIe tunnel is
activated. If the cable bounces, the tunnel can be deactivated before
that work runs; pcie_tunnel_requested stays set, so the work then
cold-initializes and starts PCIe-C against a tunnel that no longer
exists. On J416c the port then never links again ("link didn't come
up") until reboot, even after replugging or power-cycling the dock.

Clear the request and cancel the pending work on tunnel deactivation.
The work already re-checks the request under pcie_tunnel_lock, so a run
that is in progress either completes before the teardown takes the
lock, and is quiesced by it, or does nothing.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: RJ Skerry-Ryan <[email protected]>
When the USB4 router disappears during suspend (e.g. a Thunderbolt 3
dock under s2idle), the NHI's resume tears the PCIe tunnel down and
quiesces this host before PCIe-C's own resume_noirq runs. That resume
then starts the ports anyway, training against a tunnel that no longer
exists; on J416c the port is afterwards unable to link on every later
connect until reboot.

Skip restarting the ports when the host has been quiesced. They are
started again by apple_pcie_tunnel_restore(), or cold-initialized by a
fresh populate, once a new tunnel is up.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: RJ Skerry-Ryan <[email protected]>
DCP tears its EPIC services down when an external display disconnects
and announces them again on fresh channels when it reconnects; it never
reuses a channel. On the j416s DPAVSERV endpoint (0x28), every
compositor off/on or replug of the display tears down
dcpav-service-epic (the service EDID is read through) and
dcpdp-service-epic, and announces both again: channels 1/3 at boot, then
5/7, 9/11 and so on. afk_recv_handle_init() handed out slots append-only
(ch_idx = num_channels++), and teardown only disables a service, so its
slot was never given back. After boot plus seven reconnects all
AFK_MAX_CHANNEL (16) slots were used, and the next reconnect failed:

  AFK[ep:28]: too many enabled services!
  AFK[ep:28]: expected announce but got 0xc0 on channel 33

The re-announced dcpav-service-epic then had no slot, so dcpavserv
stayed disabled and dcp_get_modes() skipped the EDID read without
logging anything. The connector's EDID stayed empty for the rest of the
boot, and a physical replug did not bring it back, since the endpoint is
never restarted.

Reuse a slot whose service was torn down, is disabled and has no
command pending. Pending commands keep their buffers in the slot until
the firmware acks them, so such a slot is left alone. The slot lock is
initialised once, when the slot is first used. Add debug messages for
teardown and slot reuse, since a normal teardown was not logged at all.

Confirmed on hardware: M2 Pro (j416s), BenQ 1440p through a USB4 hub,
fresh boot, 10 compositor off/on toggles. Each cycle logs teardown of
dcpdp-service-epic and dcpav-service-epic, then "reusing slot 0" and
"reusing slot 1" as the two services come back, with channels reaching
43 and no "too many enabled services". The EDID read back as 256
bytes after every toggle and Hyprland kept identifying the display.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Signed-off-by: Oliver Lukschander <[email protected]>
(cherry picked from commit 6fdc8fe)
Signed-off-by: RJ Skerry-Ryan <[email protected]>
The send-empty interrupt is requested with IRQF_NO_AUTOEN.
apple_mbox_send() enables it when the A2I FIFO is full and it has to
wait, and the interrupt handler disables it again when it fires. When
the wait times out or is interrupted by a signal, apple_mbox_send()
returns with the interrupt still enabled, so the next send that has to
wait calls enable_irq() on a line that is already enabled. The IRQ core
warns about the unbalanced enable, and from then on the enable state no
longer tracks whether a sender is waiting. On T8140 this shows up as
"Unbalanced enable for IRQ" warnings from the SEP hwrng thread, whose
sends can wait longer than the 500 ms timeout.

Track whether the interrupt is unmasked in struct apple_mbox, protected
by tx_lock. The sender enables it only while it is masked, the handler
disables it only while it is unmasked, and a sender whose wait failed
disables it unless a late interrupt already has. Disabling it
unconditionally on the error path would not work: the handler may
already be waiting for tx_lock and would then disable it a second time.

Fixes: 6e1457f ("soc: apple: mailbox: Add ASC/M3 mailbox driver")
Assisted-by: LLM checkpatch sparse
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
(cherry picked from commit 7a155e3)
Signed-off-by: RJ Skerry-Ryan <[email protected]>
apple_rtkit_free() and apple_rtkit_reinit() stopped the mailbox and
destroyed or flushed the workqueue, but left the mailbox's rx callback
and cookie pointing at the instance the whole time. A message popped by
a concurrent apple_rtkit_poll() or a work item queued just before the
stop could still reach the consumer's callbacks while its state was
being torn down, and apple_rtkit_init() left a dangling receiver behind
when the workqueue allocation failed.

Make the receiver an explicit ownership: claim the mailbox rx callback
under rx_lock once the workqueue exists, detach it (with the interrupt
already disabled by apple_mbox_stop()) before draining the queue, drop
messages that arrive or were queued once teardown has started, and
release the cookie only after all host state is gone.
apple_rtkit_reinit() re-arms the receiver under the lock and detaches
again if the mailbox fails to start. A mailbox poll with no receiver
attached returns without touching the FIFO; the entries are drained
once a receiver is attached again.

Claiming a mailbox that already has a receiver keeps the previous
behaviour of taking it over, now with a warning, so existing consumers
that never free their instance can still rebind.

Assisted-by: LLM checkpatch sparse
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
(cherry picked from commit 692a3c6)
Signed-off-by: RJ Skerry-Ryan <[email protected]>
apple_dart_hw_map_locked_ttbr() maps the L1 table of a locked DART
stream with devm_memremap() and checks the result for NULL, but
devm_memremap() never returns NULL: it returns ERR_PTR(-ENOMEM) or
ERR_PTR(-ENXIO) on failure. A failed mapping was therefore stored as
the table pointer, and apple_dart_hw_sync_locked() then wrote the
page-table entries through it and apple_dart_hw_unmap_locked_ttbr()
passed it to memset().

The NULL check was added together with the locked-DART page-table code
by commit 0d4ec07 ("iommu/dart: Add iommu_ops for locked DARTs"),
and became reachable once locked DARTs were allowed to probe.

Check the result with IS_ERR() and return the error, so that no error
pointer is ever stored.

Fixes: 85322eb ("iommu/dart: Support locked DARTs")
Assisted-by: LLM checkpatch sparse
Signed-off-by: Ryan Murray <[email protected]>
(cherry picked from commit 162b646)
Signed-off-by: RJ Skerry-Ryan <[email protected]>
commit d87cb88 upstream.

apple_soc_cpufreq_init() adds OPP tables from firmware, but
some failure paths do not remove them. The driver also uses
dev_pm_opp_remove_all_dynamic(), which is not the right cleanup
helper for OPP tables loaded from firmware.

Use the cpumask OPP helper after the policy CPU mask has been
populated. Pair it with the matching cpumask remove helper on
failure paths and in apple_soc_cpufreq_exit(). This also removes
the separate dev_pm_opp_set_sharing_cpus() call, as the cpumask
helper loads the DT OPP tables for all CPUs in the policy.

Fixes: 6286bbb ("cpufreq: apple-soc: Add new driver to control Apple SoC CPU P-states")
Cc: [email protected]
Signed-off-by: Haoxiang Li <[email protected]>
Signed-off-by: Viresh Kumar <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
(cherry picked from commit eb346c1)
Signed-off-by: RJ Skerry-Ryan <[email protected]>
apple_soc_cpufreq_exit() drops the static OPP tables with
dev_pm_opp_of_cpumask_remove_table(policy->cpus), but policy->cpus is
always empty by then. __cpufreq_offline() clears the outgoing CPU from
the mask first and calls ->exit() only once the last CPU of the policy
has gone, and unbinding the driver takes the same path. The call
removes nothing, so every time a cluster goes fully offline and comes
back, or the driver is rebound, the OPP table of each of its CPUs is
left with one more reference and is never freed.

Remove the tables of policy->related_cpus instead, which still lists
every CPU the policy covered, as qcom-cpufreq-hw does. The error path
of apple_soc_cpufreq_init() keeps using policy->cpus, because the core
fills in related_cpus only after ->init() has succeeded.

Fixes: d87cb88 ("cpufreq: apple-soc: Fix OPP table cleanup")
Assisted-by: LLM checkpatch sparse
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
(cherry picked from commit 6559da7)
Signed-off-by: RJ Skerry-Ryan <[email protected]>
commit f61c934 upstream.

apple_nvme_init_queue() initializes queue state and then marks the queue
enabled. The interrupt and request paths check enabled before using that
queue state.

The old wmb() after WRITE_ONCE(enabled, true) does not publish the
earlier initialization before enabled becomes visible. Use a release store
when enabling the queue and acquire loads when testing it.

Although the shutdown-side enabled accesses are not used for publishing
queue initialization, use helpers for them as well for consistency.

Fixes: 5bd2927 ("nvme-apple: Add initial Apple SoC NVMe driver")
Signed-off-by: Gui-Dong Han <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Keith Busch <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
(cherry picked from commit 8d4657c)
Signed-off-by: RJ Skerry-Ryan <[email protected]>
apple_pmp_report_probe() allocates the report with devm_kzalloc() but
never initializes rep->lock. The first apple_pmp_report_set_state() from
a child entry's probe then takes an uninitialized spinlock; with lockdep
this is reported as a non-static key and lockdep turns itself off for the
rest of the boot:

  INFO: trying to register non-static key.
  ...
   _raw_spin_lock_irqsave
   apple_pmp_report_set_state
   apple_pmp_report_entry_probe

Initialize the lock before of_platform_populate() creates the entries.

Tested on j416s (M2 Pro) with PROVE_LOCKING: the report is gone and
lockdep stays enabled.

Fixes: e5f8c27 ("pmdomain: apple: Add PMP reporting interface")
Signed-off-by: Oliver Lukschander <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 583b9fa)
Signed-off-by: RJ Skerry-Ryan <[email protected]>
Commit c300d1b ("soc: apple: pmgr: Add force-disable/force-reset")
changed the transition poll in apple_pmgr_ps_set() to read into cur,
but left the timeout message printing reg, which now holds the value
that was written. Since then the "now:" field shows what was requested
rather than the state the domain is stuck in.

Print both the value written and the last value read back. On T8140,
audio_leap_mca occasionally misses the 100 us poll window, and the
read-back value (0xa4f: BUSY set, ACTUAL clock-gated, TARGET active) is
what tells a slow transition from a failed one.

Fixes: c300d1b ("soc: apple: pmgr: Add force-disable/force-reset")
Assisted-by: LLM checkpatch sparse
Signed-off-by: Ryan Murray <[email protected]>
(cherry picked from commit 2768025)
Signed-off-by: RJ Skerry-Ryan <[email protected]>
apple_pmgr_ps_set() builds the words it writes from a read of the power
state register. It clears the WAS_CLKGATED and WAS_PWRGATED flags but
not BUSY (bit 11), which the hardware reports while a transition is
still in progress: on T8140 audio_leap_mca reads back 0xa4f, with BUSY
set, after missing the 100 us poll window. A value read in that state
was written back with BUSY set. Clear BUSY in the DEV_DISABLE/PS_RESET
write that precedes a power-down and in the target state write, which
the auto-enable write reuses. This changes the value written on every
SoC that uses this driver.
No failure attributable to writing BUSY back was observed; the change
is precautionary, as the bit is hardware-owned.

The error messages in apple_pmgr_ps_set() and in the reset assert and
deassert paths are printed from genpd and reset callbacks that
consumers retry, so a domain that keeps missing its poll window, as
audio_leap_mca does on T8140, repeats the same message on every
attempt. Ratelimit them; their text is unchanged.

Assisted-by: LLM checkpatch sparse
Co-authored-by: Claude Fable 5.1 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
(cherry picked from commit afe19ef)
Signed-off-by: RJ Skerry-Ryan <[email protected]>
The board property permits experimental kernel cold initialization, but
must not reject an existing successful m1n1 handoff. Admit the explicit
preinit certificate in both the population gate and preparation helper
without touching cold-init registers.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Keep receiver ownership reserved until teardown finishes. A competing
initialization must return EBUSY instead of overwriting the callback and
cookie, and must not stop the mailbox owned by the existing receiver.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide merged commit 2530a2c into fix/j414s-dual-dock-dp Oct 8, 2026
@RyanTheTide
RyanTheTide deleted the fix/pr50-review branch October 8, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants