mcruz.me
← All writing

Bringing the M5 MacBook Air’s Internal Display Up on Linux

How Linux joined a running display coprocessor, shared its address tables, and kept presenting frames after the panel powered back on.

On this page

The 13-inch M5 MacBook Air can already show a picture when Linux starts. Apple's boot firmware has powered the panel, chosen a mode, and left a framebuffer for the next stage. A console can draw into that buffer. The harder milestone was getting Linux to present a new frame through the display coprocessor, receive confirmation that the frame went on screen, and do it again after turning the panel off and on. My patch for the J813 MacBook Air targeted that sequence on the M5's T8142 chip and the H17-generation display firmware supplied with macOS 26. It builds on DjDeveloperr's H17 work. Native M5 Air display patch and hardware report.

Attaching to a display already in motion

The display coprocessor, abbreviated DCP, runs firmware independently of the main CPU. By the time the Linux driver probes it, iBoot has left that firmware running. Its memory mappings are live and some of its translation tables are locked. Restarting the processor would discard the session Linux is supposed to join. I gave the T8142 driver an explicit setting for adopting a live session. It reads the coprocessor's control register and requires the run bit to be set. If that precondition fails, probing ends with an error. Otherwise the driver initializes the RTKit mailbox transport and negotiates with the running firmware. Run-state check. RTKit wake sequence.

The board description says which hardware participates in that conversation. It gives DCP a mailbox with interrupts for send and receive events. It identifies separate DART address translators for the coprocessor and the display subsystem. It also assigns the primary scanout plane to IOMFB surface 2. The loader has aliases for the DCP, display, and display DMA nodes so it can attach the correct memory reservations to each. The DCP and display DART nodes begin disabled in the board file. The loader enables them after preparing the handoff. The presence of the hardware and readiness for Linux to drive it are two different facts in that device tree. J813 display topology.

Agreeing on which memory a device address means

A DART translates an address issued by a device into a physical memory address. The loader has to describe the memory the display firmware already occupies so that Linux keeps it reserved. One firmware segment can span noncontiguous physical pages, and two addresses can refer to the same physical page. The companion m1n1 change walks the inherited translations page by page. Memory already inside a reserved carveout needs its device address recorded. Other pages also need a physical reservation. On the J813 tests, the loader report counted seven regions and fifteen mappings and found that the exported reservations matched the live translations on every boot it checked. Loader change and reservation checks.

There is a second agreement to make inside the kernel. Imagine a firmware page table that maps device pages A and B to physical pages P and Q. Linux prepares a table describing A as P. The tables occupy different memory and Linux's table says nothing about B. Both nevertheless give the same answer for the page Linux needs. The new DART check walks each valid Linux leaf entry and asks whether the firmware entry is valid and points to the same physical page. If every such entry matches, the hardware can keep walking its original table. The extra firmware mapping for B remains available to its owner. Comparing Linux and firmware leaf entries.

Now suppose Linux later requests B as R. A comparison made only at attach time would miss that disagreement. The map path checks each affected page in a firmware-owned slot before accepting a new mapping and returns -EBUSY when the physical addresses differ. It can publish Linux translations into vacant root slots and track which slots Linux installed. It also consults the firmware mappings when asked to translate a shared device address that its own table cannot resolve. Those rules let a live coprocessor and a new kernel refer to the same buffers through the whole session. Checking later mappings and resolving shared addresses.

Giving the firmware a surface to present

After RTKit connects, the display protocol still has to establish a framebuffer surface. H17 asks the host to create its default surface through a callback. The host must make a nested registration call with the surface description, provide room for the firmware's four-byte reply, and then acknowledge the original request. An acknowledgment sent before registration would leave the display engine without a valid surface base. The source documents the resulting DMA fault. The driver also obtains the framebuffer dimensions from the firmware, checks that both fit the supported bounds, and sends the dimensions back before committing the description. The board file therefore needs no table of panel timings copied from another machine. Surface-registration callback. Firmware dimension exchange.

The timing generator presents a different problem. The standard call to program the digital output mode fails on this live H17 panel. The driver source records the firmware error and the consequence. Without a running timing generator, the host receives neither the vertical blank event nor confirmation that a frame swap completed. The H17 path inherits the mode programmed at boot. The panel reports 2560 by 1664 pixels. With the 64-pixel notch region hidden, Linux exposes 2560 by 1600 at 60 Hz. That figure describes the configured display mode. It supplies no measurement of the rate at which a particular application produces new frames. Inherited mode handling. Reported panel geometry and mode.

Why the second power-on needs its own test

Turning the display back on makes the firmware report its modes again. The parser sets a variable-refresh flag when a mode supplies the corresponding information. The old allocator left the mode array uninitialized, so a fixed-refresh mode could inherit a nonzero flag from memory previously used for something else. The result was a plausible-looking mode object that asked the driver to issue the wrong kind of swap. A desktop that had been presenting frames could stall after the display powered back up. The fix allocates a zeroed array. A mode starts with variable refresh off, and the parser turns it on only when it reads the relevant evidence. It applies to the shared parser across chips. Variable-refresh conditions. Mode allocation and parsing.

The hardware results in the pull request are tied to a RAM-booted J813 using public m1n1 and U-Boot with their companion changes. Five fresh boots of the final kernel source reached DCP startup and registered appledrmfb as the console, with no reported DART faults or warnings. A sixth attempt stopped at the preflight before Linux because DCP had not yet settled. Three display power-off and power-on cycles completed with page flips continuing. KDE Plasma 6.6 then provided a Wayland desktop on the internal panel with the built-in keyboard and trackpad. Software rendering produced its frames. The evidence from that series covers internal scanout, power cycling, and interactive desktop use. GPU acceleration, brightness control, a separate cursor plane, external displays, and system suspend remained outside its validation. Test conditions and results from the merged patch.