soc: apple: mailbox: keep enable_irq() balanced when a send times out - #599
Open
brentkearney wants to merge 39 commits into
Open
soc: apple: mailbox: keep enable_irq() balanced when a send times out#599brentkearney wants to merge 39 commits into
brentkearney wants to merge 39 commits into
Conversation
Apple M2 devices expose the multi-touch device over the HID over DockChannel transport, which we represent as the HOST bus type. The report format is the same, except the legacy mouse header is gone and there is no enable request needed. Signed-off-by: Hector Martin <marcan@marcan.st>
The trackpad has to request multi touch reports during resume. Signed-off-by: Janne Grunau <j@jannau.net>
On at least some SPI devices (e.g. recent Apple Silicon machines), the Broadcom touch controller is prone to crashing. When this happens, the STM eventually notices and resets it. It then notifies the driver via HID report 0x60, and the driver needs to re-enable MT mode to make things work again. This poses an additional issue: the hidinput core will close the low-level transport while the device is closed, which can cause us to miss a reset notification. To fix this, override the input open/close callbacks and send the MT enable every time the HID device is opened, instead of only once on probe. This should increase general robustness, even if the reset mechanism doesn't work for some reason, so it's worth doing it for USB devices too. MTP devices are exempt since they do not require the MT enable at all. Signed-off-by: Hector Martin <marcan@marcan.st>
For SPI/MTP trackpads, query the dimensions via HID report instead of hardcoding values. TODO: Does this work for the USB/BT devices? Maybe we can get rid of the hardcoded sizes everywhere? Signed-off-by: Hector Martin <marcan@marcan.st>
Keyboard and trackpad of Apple Sillicon SoCs (M1, M1 Pro/Max) laptops are are HID devices connected via SPI. This is the same protocol as implemented by applespi.c. It was not noticed that protocol is a transport for HID. Adding support for ACPI based Intel MacBooks will be done in a separate commit. How HID is mapped in this protocol is not yet fully understood. Microsoft has a specification for HID over SPI [1] incompatible with the transport protocol used by Apple. [1] https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/hid-over-spi Contains "HID: transport: spi: apple: Increase receive buffer size" The SPI receive buffer is passed directly to hid_input_report() if it contains a complete report. It is then passed to hid_report_raw_event() which computes the expected report size and memsets the "missing trailing data up to HID_MAX_BUFFER_SIZE (16K) or hid_ll_driver.max_buffer_size (if set) to zero. Co-developed-by: Hector Martin <marcan@marcan.st> Signed-off-by: Hector Martin <marcan@marcan.st> Signed-off-by: Janne Grunau <j@jannau.net>
DockChannel is a simple FIFO interface used to communicate between SoC blocks. Add a driver that represents the shared interrupt controller for the DockChannel block, and then exposes probe and data transfer functions that child device drivers can use to instantiate individual FIFOs. Signed-off-by: Hector Martin <marcan@marcan.st>
Apple M2 devices have an MTP coprocessor embedded in the SoC that handles HID for the integrated touchpad/keyboard, and communicates over the DockChannel interface. This driver implements this new interface. Signed-off-by: Hector Martin <marcan@marcan.st>
This driver can be used for coprocessors that do some background task or communicate out-of-band, and do not do any mailbox I/O beyond the standard RTKit initialization. Signed-off-by: Hector Martin <marcan@marcan.st>
Certain Broadcom bluetooth chips (bcm4377/bcm4378/bcm438) need ACL streams carrying audio to be set as "high priority" using a vendor specific command to prevent 10-ish second-long dropouts whenever something does a device scan. This patch sends the command when the socket priority is set to TC_PRIO_INTERACTIVE, as BlueZ does for audio. Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
The current approach of silently disabling all rust drivers if the toolchain is missing results in users that try to compile their own kernels getting a "successful" build and then being confused about where did their drivers go. In comparison, missing openssl results in a build failure, not a disappearance of everything that depends on it. This also means that allyesconfig will depend on rust, but since the rust experiment concluded with "rust is here to stay", i believe that allyesconfig should be building rust drivers too. Signed-off-by: Sasha Finkelstein <k@chaosmail.tech>
Signed-off-by: Janne Grunau <j@jannau.net>
Apple M3 Pro and Max devices are using 'gp00' keys for GPIO in addition to 'gP00' keys. Add a second compatible to handle this keys with an additional macsmc-gpio instance. Signed-off-by: Janne Grunau <j@jannau.net>
Add support for SMC GPIO keys with a lower letter 'p' via the "apple,smc-low-gpio" compatible. This adds support for a second macsmc-gpio controller using 'gp00' keys. These keys are used on Apple M3 Pro and Max MacBooks in the controller for keyboard and trackpad and for the built-in DisplayPort to HDMI converter. Signed-off-by: Janne Grunau <j@jannau.net>
Apple M3 Pro and Max devices are using 'gp00' keys for GPIO in addition to 'gP00' keys. These keys are handled by an additional macsmc-gpio instance using the "apple,smc-low-gpio" compatible. Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
…fails apple_mbox_send() enables irq_send_empty and waits for the coprocessor to drain the A2I FIFO. Only the interrupt handler disables that interrupt again, so when the wait does not complete -- the FIFO stays full for APPLE_MBOX_TX_TIMEOUT, or the wait is interrupted by a signal -- the interrupt is left enabled and its disable depth is off by one. The next send that finds the FIFO full then calls enable_irq() on an already-enabled interrupt, which warns and underflows the depth counter: Unbalanced enable for IRQ 57 WARNING: kernel/irq/manage.c:774 at __enable_irq+0x4c/0x80, CPU#0 Call trace: __enable_irq+0x4c/0x80 (P) enable_irq+0x74/0xe4 apple_mbox_send+0xb4/0x1b8 Observed on an M1 Pro (apple,t6000) after SEPOS stopped draining its mailbox: of eight consecutive sends that timed out, the last seven each warned with a full backtrace. Track whether the interrupt is enabled in struct apple_mbox under tx_lock and disable it on the failure paths. The flag also settles the race with the handler running just after the wait expired: whichever side takes tx_lock first performs the single disable, and the stale completion is cleared by the reinit_completion() before the next wait. Signed-off-by: Brent <1550934+brentkearney@users.noreply.github.com>
This was referenced Sep 4, 2026
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Balance the send-empty interrupt enable in
apple_mbox_send(), so a send whose wait times out or takes a signal no longer leaves the interrupt enabled. Fixes #598.Problem
apple_mbox_send()enablesirq_send_emptybefore waiting for the A2I FIFO to drain; onlyapple_mbox_send_empty_irq()disables it again.enable_irq()on an already-enabled interrupt, so__enable_irq()warns and underflows the depth counter. Every further stalled send warns again with a backtrace.sep,dcp,dcpext,aop,isp, andnvme.Changes
tx_irq_enabledtostruct apple_mbox, guarded bytx_lock.disable_irq_nosync().Notes for reviewers
tx_lockfirst performs the single disable.reinit_completion()before the next wait, so no send returns early on a stale completion.tx_lock, so it callsdisable_irq_nosync();disable_irq()can sleep.Testing
Runtime-tested on a MacBook Pro 16-inch 2021 (
apple,j316s/apple,t6000, M1 Pro). The stall must be provoked from a healthy SEP: the message that makes SEPOS stop draining only has that effect early in a boot. Later SEPOS reaches a state where it stops answering but keeps draining, so the FIFO never fills and the timeout path is never taken.7.1.6-1-4-ARCH: eight sends timed out and the last seven each printedUnbalanced enable for IRQ 57with a backtrace throughapple_mbox_send+0xb4/0x1b8. Only the first timed-out send is silent, matching the analysis.7.1.6-1-5-ARCH: eight sends filled the A2I FIFO and the next 56 timed out, with zeroUnbalanced enableWARNs.WARNINGline anywhere in the boot, and taint stayed at 4 (arm64Sbaseline,Wclear).