Skip to content

power: supply: macsmc: gate AC ONLINE on battery status - #505

Closed
joshuaswarren wants to merge 1910 commits into
omacom:integration/aurorafrom
joshuaswarren:macsmc-ac-online-phantom
Closed

joshuaswarren wants to merge 1910 commits into
omacom:integration/aurorafrom
joshuaswarren:macsmc-ac-online-phantom

Conversation

@joshuaswarren

Copy link
Copy Markdown

power: supply: macsmc: gate AC ONLINE on battery status

M5 ask be46547c64 (handoff note from w7C:
~/scratch/w7C/macsmc-ac-online-handoff.patch, CT).

Symptom

On the 14-inch M2 Pro ("sn201202x"): macsmc_ac ONLINE=1 with
hwmon AC input power 15-17 W, battery current 0 A holding 97%.
The battery neither charged nor discharged; the machine actually ran
on battery. A port1 PD source left CHIS set without feeding the
battery — a phantom "online".

Change

macsmc_ac_get_property(POWER_SUPPLY_PROP_ONLINE) no longer reports
CHIS alone. It now gates on macsmc_battery_get_status():

  • DISCHARGING → ONLINE 0
  • NOT_CHARGING and B0AC (battery current) <= 0 mA → ONLINE 0
  • otherwise → CHIS as before (charging / full-limited systems keep
    their online marker)

Error reads fall through to the previous CHIS behaviour (fail-open,
same as before the change).

Review note carried from the handoff

sn201202x/tps6598x_psy_get_online should be reviewed for the
same phantom when a PD source negotiates without VBUS — separate
patch, not covered here.

Test plan

  • CI builds the driver.
  • Runtime check on the lab laptops (16-inch M1 Max lab kernel
    7.1.12-2-20261103.2-lab-ARCH): unplug-with-PD-source case →
    ONLINE must drop to 0 while AC-n/AC-i keep reading; normal charge →
    ONLINE 1 unchanged. Runtime rows are queued on the w73 lane and
    will be attached as receipts.

RyanTheTide and others added 30 commits September 28, 2026 01:26
The PMP publishes status and control values in a register region it
shares with the application processors, as an array of 16-byte entries,
and takes the power state of the blocks it accounts for through the
same region.  The M1 Pro/Max/Ultra, M2 Pro/Max/Ultra and M2 device trees
already describe it, with one child power domain per reported block,
but there is no binding.

Add one, covering the A18 Pro (T8140) too.  Its region has no reported
blocks yet; its CPU clusters read their die-temperature effort from one
of its entries.

List Sasha Finkelstein, who wrote the pmp-report driver, as a
maintainer.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit b8a2e2ff49bbaa42b4f554ee170e1d7294d296bc)
On the A18 Pro the PMP runs a fast control loop on the die temperature
and publishes, per CPU cluster, an 8-bit effort in its report region: 0
requests no limit, and the effort rises towards 255 as the die exceeds
the firmware's target.  Measured on the J700, the value is refreshed
about every 5 ms, while the SMC temperature sensors lag the die by about
a second.

Add an optional property that points a cluster at its effort: the report
region and the cluster's lane in the PMP's fast die-temperature report.
Where that report lies in the region is firmware layout that is fixed
for each SoC, so it is implied by the report region's compatible rather
than described here.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit 4a001e2768600e8b52ffdc190b67e5f04122d6cc)
The T8140 PMP DART translates a 42-bit address space, and the DMA window
it offers starts at 1 TiB.  With the default 32-bit mask the IOMMU DMA
allocator finds no usable IOVA in that window, so the first firmware
buffer request fails with -ENOMEM and the probe times out waiting for
the firmware.

Add per-SoC match data, and on T8140 set the mask to the DART's 42 bits
before anything is allocated, as the AOP driver does.  The other SoCs
keep the default mask: their PMP DART windows start at 0, where it works,
and a wider mask would move their firmware's buffers to IOVAs above
4 GiB, which has not been tested there.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit cd55d8be48271f1ae69d58e27d759ad7cb65663d)
The Apple device tree of the T8140 (A18 Pro) describes a PMP report
region like those of the other SoCs, which nothing binds to yet.  Add
its offsets, derived from the report layout in the Apple device tree the
same way as those of the other SoCs: the power state request, its
acknowledgment and the PMP status are the 16-byte entries 0x188, 0x18c
and 0x1 of the read window, at 0x1880, 0x18c0 and 0x10, and the request
is written through the update window at 0x10000 plus half its read
offset, 0x10c40.

The Apple device tree gives a 0x10000-byte read window followed by a
0x4000-byte update window.  Only the start of the read window holds
entries (the last one listed is 0x1ed), and a scan well beyond them,
from past +0x2000 of the read window towards +0x20000, hung the bus.
The three read offsets lie among the listed entries and the write
offset in the update window.  The driver only accesses them on behalf
of child report entries, and the T8140 device tree has none yet, so the
region binds without touching the hardware.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit 869a2787a27f41499268589a56541ca07d36aad5)
On the T8140 (A18 Pro) the PMP runs a fast control loop on its own
die-temperature sensors and publishes an 8-bit effort for each CPU
cluster in report entry 0x1c1, one byte per cluster.  cpufreq needs the
effort to limit the clusters, and the PMP status to know whether the
effort is valid: a stopped PMP reads 0, which would mean no limit.

Rather than have cpufreq map a word of this region itself, with the
entry's position encoded in its device tree node, let the region's
driver read it.  Add the entry to the T8140 match data and export
apple_pmp_report_fast_die_effort(), which checks the PMP status and
reads a cluster's effort through the driver's own mapping.  It can be
called in any context, including timers: it finds the region in an RCU
list of bound regions, and returns -EPROBE_DEFER while the region is
not bound, so that the caller can treat that like a PMP that is not
running and ask again later.  Regions are never removed from the list,
so the driver no longer allows unbinding through sysfs, which already
left its child power domains using an unmapped region.

Entry 0x1c1 is the first entry of the Apple device tree's FAST-DIE-CE
report range.  On the J700 its byte 1 was observed to rise and fall
with P-cluster load.  Byte 0 is assigned to the E cluster from the
ordering of the Apple device tree's fast-die-ctrl-ce-map; it was not
observed to change, since the E cluster never reached the firmware's
target in testing.  The range's second entry, 0x1c2, read 0 throughout
and is not used.  Both bytes are read as part of an aligned 32-bit
word, the access width used in testing.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit fd6ad0760fca6dc651db4375a5bca4ba9e99a7c4)
…egion

Describe the Power Management Processor as on the M2 (T8112), from the
Apple device tree:

- the PMP itself, with its memory at 0x300500000 and its ASC control
  registers at 0x300e00000, disabled: the bootloader adds the board and
  firmware configuration and enables it through the pmp alias;
- its mailbox at 0x300e08000 (AIC 823-826);
- its DART at 0x300300000 (AIC 827).  The register window is the full
  0xc000 from the Apple device tree, since the DART driver reads the
  exception registers at 0x4000 and 0x8000 on this DART generation.
  The DMA window starts at 1 TiB and is 0xbff00000 bytes long;
- its report region at 0x3003c0000: the 0x10000-byte read window
  followed by the 0x4000-byte update window, as the Apple device tree
  gives them.  Only the start of the read window holds entries, and a
  scan well beyond them, from past +0x2000 towards +0x20000, hung the
  bus, so a comment records that only the entries and the update window
  may be accessed.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit 4d1316cf68360a616b106ba9b76a445843a1eda6)
Add the pmp alias the bootloader uses to find the PMP node, which it
enables once it has added the board and firmware configuration, and
enable the PMP mailbox and DART.

The M1 Pro/Max/Ultra, M2 Pro/Max/Ultra and M2 device trees only add the
alias when APPLE_USE_PMP is defined, which it is not by default.  The
J700 enables it unconditionally because its CPU temperature limit is to
depend on the PMP: the PMP's fast die-temperature effort is the only
limit that acts faster than the SMC sensors, and the cpufreq limit that
follows holds the CPU clusters at a conservative fallback limit for as
long as the PMP is not running.  None of the J700's power domains is
routed through the PMP report, so enabling it changes nothing else.

The cost is the one the other SoCs accept when they opt in: the PMP
firmware is started once per boot and never stopped, so after a kexec
it keeps running and keeps using DMA buffers in memory that the next
kernel may reuse.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit bdeba2481d354bde6ef72831374d1b7588930fb1)
…fort

The A18 Pro has no autonomous CPU temperature limit below its hardware
alarm.  Its PMP runs a fast control loop on its own die-temperature
sensors instead, and publishes an 8-bit effort per CPU cluster: 0
requests no limit, and the effort rises as the die exceeds the
firmware's target.  Measured on the J700, the effort is refreshed about
every 5 ms, and when nothing acts on it, it reaches its maximum of 255
within about 170 ms.  The SMC temperature sensors lag the die by about
a second: under an all-core load the effort starts to rise while the SMC
still reads about 60 C.  A thermal zone on the SMC sensors alone
therefore has to run far below the die's limit.

The firmware requests a limit and the OS enforces it, so follow
scmi-cpufreq's handling of SCMI performance limits: when the cluster's
DT node has an apple,fast-die-effort property, add a FREQ_QOS_MAX
request to the policy and update it from process context.  The cpufreq
core then applies the limit to the governor and reports it to the
scheduler as cpufreq pressure; the driver's ->target_index() is left
alone.  The effort is read through the PMP report driver, which owns
the region and knows where the effort lies on each SoC.

apple_fast_die_limit() maps the effort to the limit: the fastest state
whose power fits (255 - effort) / 255 of the fastest state's power, from
the OPP table's opp-microwatt, or the frequency when the OPPs carry no
power.  This mapping is a design choice, not a description of the
firmware: the PMP's loop is closed on the die temperature, so any
mapping that lowers the limit monotonically as the effort rises
converges, and power is the natural axis for the output of a
temperature controller.  It was validated closed-loop under Linux on
the J700.

The limit fails safe.  A stopped PMP reads an effort of 0, and the PMP
may never start, for instance when its driver is not loaded or the
bootloader did not prepare it.  Until the PMP status in the report
region says that the PMP is running, or while the report region is not
bound, each cluster is held at a fallback limit: the fastest state whose
power is at most a third of the fastest state's (2688 MHz for the P
cluster and 1140 MHz for the E cluster of the J700).  The fallback is
released as soon as the PMP reports running.  If it has not done so 30 s
after the limit was set up, one warning says that the fast limit is
unavailable and that the fallback stays.  A misdescribed property keeps
the fallback too, rather than failing the policy.

No interrupt is known to signal a new effort under Linux: the clpc
interrupt of the Apple device tree (AIC 840) never fired under Linux,
idle or under load with the effort changing, and what arms it is
unknown.  So the effort is sampled.  While the limit is at the maximum,
each CPU of the cluster reads it from a pinned, deferrable timer once a
tick, and the first CPU to run in a tick takes the sample; idle CPUs are
never woken for it.  Once the limit is below the maximum, or while
waiting for the PMP, a per-cluster soft hrtimer samples instead, every
5 ms (100 ms while waiting for the PMP, 1 s after the warning), whether
the cluster is busy or not, until the limit is back at the maximum.
Otherwise an idle cluster could keep a stale low limit, which the
scheduler sees as low capacity, so it would keep the work that could
release the limit away from the cluster.  A nohz_full CPU can run a task
with its tick stopped, so a cluster with nohz_full CPUs samples from the
hrtimer all the time.

Only when the limit changes is a work item queued, on the system
workqueue like the cpufreq core's own policy update that it triggers.
If the update fails, the next sample queues it again.  A CPU hotplug
state, set up only when some cluster has the property, stops and
restarts the per-CPU timers as CPUs go offline and online; without it
the hrtimer samples all the time.

The limit keeps its own copy of the cluster's CPUs: ->init() sets up the
timers, and the core fills policy->related_cpus only after ->init()
returns and may call ->exit() before it does.  ->exit() keeps the
update work from arming the hrtimer again, stops the per-CPU timers,
which can arm it too, then the hrtimer, waits for a queued update and
then removes the request.

Tested on the J700 with the whole series and the PMP running, sampling
the SMC die sensors, the cluster clocks and the P-cluster effort every
0.25 s:

- one P core, integer, 75 s: 4044 MHz throughout, the effort at most 5,
  the SMC at 102.9 C on average and 104.7 C at peak;
- one P core, floating point, 60 s: the effort averaged 127 and held the
  P cluster at 2990 MHz on average (2196-3648 MHz), with the SMC at
  98.9 C;
- all cores, floating point, 90 s: the effort averaged 198 and held the
  P cluster at 1776 MHz on average (744-2916 MHz), with the E cluster at
  2424 MHz and the SMC at 104.1 C;
- both P cores, 3 s burst: 3780 MHz on average with the effort at 0, and
  the SMC peaking at 99.9 C.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit 289a6e1ae688768fd8a5507a4b18de07984e0e1b)
The PMP publishes a fast die-temperature effort for each CPU cluster in
its report region.  Point each cluster at its lane: lane 1 for the P
cluster and lane 0 for the E cluster.

On the J700, lane 1 was observed to rise and fall with P-cluster load.
Lane 0 is assigned to the E cluster from the ordering of the Apple
device tree's fast-die-ctrl-ce-map, but it was not observed to change:
the E cluster never reached the firmware's target in testing.  The E
cluster draws about a watt at most, and the thermal zones limit it
whatever this lane holds.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit ceca22aa557838dcbf0fc954ed4e9f6fc926ecaa)
With the fast die-temperature limit in cpufreq, the PMP's loop reacts
to the die hot spot within milliseconds, and cpufreq holds each cluster
at a fallback limit, a third of its peak power, whenever the PMP is not
running.  The thermal zones no longer have to guard the die on their
own from the SMC's delayed readings; they become the slow outer loop
that settles a sustained load.

Move the control trip from 95 C to 105 C and the critical trip from
110 C to 115 C, between the control trip and the 125 C hardware alarm,
and raise sustainable-power from 1500 to 4200 mW, about the steady CPU
rail power (SMC PP0b + PPbb + PPab) of a sustained all-core load at the
control temperature.  The switch-on trip stays at 58 C, above the idle
temperature, so the governor's gains become 89/179/18 mW per C; larger
gains, from a narrower switch-on gap, oscillated in testing.

Measured on the J700 with both loops, on the SMC die sensors sampled
every 0.25 s:

- all cores, integer, 600 s: the fast loop stopped acting after the
  first minute and the zones settled the load.  Over the last five
  minutes the P cluster ran at 2760 MHz on average (2472-2916 MHz) and
  the E cluster at 2424 MHz, the CPU rails drew 4.1 W, and the sensors
  read 102.8 C on average (98.5-105.9 C);
- all cores, integer, 75 s: P cluster at 2942 MHz on average
  (2916-3144 MHz), E cluster at 2424 MHz; 103.5 C on average, 106.4 C
  at peak;
- all cores, floating point, 90 s: P cluster at 1776 MHz on average,
  between 744 and 2916 MHz, E cluster at 2424 MHz; 104.1 C on average;
- one P core, integer, 75 s: 4044 MHz throughout, 102.9 C on average;
- one P core, floating point, 60 s: 2990 MHz on average;
- both P cores, 3 s burst: 3780 MHz on average, peaking at 99.9 C.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit 0777e3420a31c12b19d2b996233e250733ff723e)
Most Apple SoCs with two CPU types in this tree (T8015, T8103, T8112,
T8122 and the T600x, T602x and T603x families) describe the relative
performance of those types, but T8140 did not, so the scheduler treated
the E and P cores as equal (cpu_capacity 1024 everywhere) and
energy-aware scheduling stayed off: single-threaded work could land on
an E core, and light work was not steered to the more efficient
cluster.

Per-MHz throughput was measured on the J700 with each cluster pinned to
nearby operating points (P 1944/2472 MHz, E 1788/2424 MHz) across three
single-threaded kernels: an integer/L1 loop (E/P 0.981), four independent
integer chains (0.822-0.824) and a dependent floating-point chain
(0.866-0.883). Run-to-run spread was under 0.4%. The geometric mean is
0.891, giving 912 for the E cores relative to 1024 for the P cores.

The values of the recent Apple SoCs were derived differently, from
CoreMark on each core at its maximum frequency.  The three kernels above
are latency- or ALU-bound, which can hide the P core's width, branch
prediction and cache advantages, so 912 may be on the high side; it
does fit the trend of the other SoCs' E-core values.

With this, cpu_capacity reads 1024 for the P cores and 546 for the
E cores, and sched_energy_aware turns on.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit 3b76fbb895d3806cac80918c6abff0c4a3773ef1)
Distributions ship firmware compressed (Fedora uses xz), so without
FW_LOADER_COMPRESS the kernel cannot load it: on the J700 the RTL8153B
USB Ethernet adapter logged "Direct firmware load for
rtl_nic/rtl8153b-2.fw failed" until these options were enabled.

USB Attached SCSI lets SuperSpeed storage that offers it (for example
an ASUS ROG Strix Arion S500 on the J700's rear port) use command
queueing instead of the bulk-only transport.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit 76e85c995c2f7d0a8b3f797feab3b9b222112bc7)
(cherry picked from commit 96f31a3f5f2582d9a31a1689f63975a19321ec31)
Lab-only, not for review: minimal DT for the T8140 QSPIMC controller and
the J700 boot NOR's NVRAM partition, taken from DjDeveloperr's
linux-aurora nvram-qspi commit 2dcf39e and reduced to these nodes
(its other context belongs to the older hybrid DT), so that asahi-bless
can select the next boot volume from Linux.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit 43c4d38ec23835ba03ae212a54dcf7e43fb5163e)
The RX threshold interrupt does not fire on T8140, so the one-jiffy wait
in the completion fallback drained one 256-byte FIFO per tick: 34 kB/s,
55 s for the 1.9 MB NVRAM partition. Poll every 10-30 us instead; the
1 s deadline is unchanged.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
(cherry picked from commit 409e6d14314b28a16dda58e291e10d891736b2fc)
Keep the requested QSPI controller, clock, power domains and NVRAM partition authoritative in the base DT. Remove the equivalent overlay nodes and the diagnostic-only syscfg partitions so NVRAM is the sole partition. Preserve all unrelated hybrid devices.

Assisted-by: LLM

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Log each early receiver setup failure at its source and retry EINVAL before
starting either ASC. Defer probe if the bounded attempts do not succeed.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Use the compact EPIC receive layout for the H17P system endpoint so service
publishes and power reports reach their handlers without changing DCP INIT or
transmit behavior. Keep unmatched early reports at debug level.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Report the number of unexpected messages before returning EINVAL from the
G17P session guard.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Eight native snapshots agree on the target scalars and float32 table bits. Production encoder parity leaves only the unresolved native-owned pointer. Full build and stage12 hardware replay passed RTKit/initdata acknowledgements; opening retirement still faults at 0x58000bc08. This does not claim GPU rendering support.
Keep the hybrid-only PMC power provider unbound while the PMP firmware boots. The clean PMP kernel has no provider for this domain, and no J700 DT consumer references it. This isolates a firmware-owned power-state change for hardware validation.

Assisted-by: LLM

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Correct the remaining M5-derived inputs using both roles from four native 26A428 captures. Preserve runtime-owned pointers and timestamps. Full kernel build and normalized encoder parity pass. One cold Linux run completes both opening commands, idle policy, and 60 seconds without a firmware crash; PMP, DART, thermal and capped-clock gates pass. GPU rendering remains unqualified.
Since the system endpoint decodes the compact H17P receive header, the
powerlog service's mNits reports reach powerlog_report(), which stores
them in brightness.nits.  On H17P that field is the level the driver
requests -- the step of the backlight fade that the next swap carries --
so every report was sent straight back to the firmware with the next
swap that had an update pending, and restarted the fade from wherever
the report said.  The daily kernel logged the result as bursts of
"DCP reports brightness 0.000 / 466 / 509 nits" within 100 ms.

Ignore the reports on H17P; the level the firmware drives is already
logged from set_frame_sync_props.  Other firmwares keep using them.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The H17P backlight level travels inside a swap.  With the CRTC active the
backlight device pushes it by committing the primary plane's current
state, but once the CRTC is off the ACTIVE_ONLY plane pass of
commit_tail_rpm() skips its flush, so the commit never reaches the
firmware.  On the 2026-09-28 daily, after GNOME's idle blank turned the
CRTC off (and the H17P power-off kept the pipe scanning, as it must),
writes to apple-panel-bl changed sysfs while SMC PBwo stayed at 5.2 W.

Keep a copy of the last swap that put a surface on the panel, taken in
iomfb_flush() before the timestamps, the backlight block and the wire
fix-up, and add iomfb_present_brightness(), which re-presents it with
the current level.  The surface's framebuffer is still bound or retained
since its unbinding commit; the re-present does not arm the retained
entries, so it cannot release the buffer it shows.  The timestamp block
of iomfb_flush() moves into a helper both paths use.

Nothing calls it yet.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Every real power-off path panics the H17P firmware, so a DPMS off keeps
the pipe scanning the last frame -- and, until now, at the level the
session left it.  gnome-shell undims to the saved level when it blanks
the screen, so an idle-blanked greeter kept the panel lit at 509 nits
and SMC PBwo at 5.2 W (macOS login window: 0.33 W), and nothing the
session wrote to apple-panel-bl afterwards reached the firmware.

Let the backlight stand in for the power-off.  On DPMS off, remember the
level asked for last and step to blank_nits (0 by default); the ramp
worker sends it by re-presenting the surface on the panel, the only way
a level reaches the firmware while the CRTC is off.  Requests that
arrive while blanked only update the level to restore, and
actual_brightness reports that level, so a session that reads it back
cannot save the blank level as the user's.  DPMS on restores the level
with the enable commit's first swap.  With the CRTC off, the worker
pushes every step itself instead of waiting for a frame, and a busy
command channel retries.  Firmware enable-backlight callbacks go through
the worker too.

appledrm.blank_nits=-1 keeps the panel lit through DPMS off as before;
the levels written while off then still apply through the re-present.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The scatterlist tail currently reserves PRP list pointers using a KiB-sized transfer cap as bytes. A command above 2 MiB can need more PRP list pages than this reserves. Put three pointers in the request data, enough for the existing 4 MiB driver cap including a partial first PRP and chained list entries. Keep the scatterlist allocation within one page.

Assisted-by: LLM

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
A 1 MiB direct I/O can cover 256 noncontiguous 4 KiB pages. The old 127-segment limit forces such a request into multiple NVMe commands even when the controller advertises a 1 MiB MDTS. With PRP list pointers in request data, grow the scatterlist to 256 entries and reserve eight buffers in the allocation pool. The max_segments parameter allows a boot-time 127-versus-256 comparison without changing the hardware transfer cap.

Assisted-by: LLM

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Avoid clearing a fresh completion notification after its ring has already been drained. Record the failed connect phase and elapsed time before retirement so an initial -ETIMEDOUT can be attributed to discovery, association or calibration.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
RyanTheTide and others added 29 commits October 6, 2026 21:52
The H17P swap record is 0x588 bytes. The driver modelled it as 0x58a and
compensated before every A408 by dropping two bytes from each surface
header and shifting the request tail down by two. As a result the
surface's is_premultiplied byte (record 0x58a) carried is_tiled, and the
fix-up was not idempotent.

Shrink h17p_tail by two bytes, keep the common surface header, and add
the two trailing pad bytes to the request instead. The fix-up no longer
moves memory. It now only sets the swap flag words and counters, and it
clears is_tearing_allowed and is_premultiplied. That keeps every byte on
the wire identical to the previous layout for the linear surfaces we
build.

Blend-CRC measurements on J700 (A106 read_blend_crc, AR24 colour bars
on VT3) identify byte 0x58a as the premultiplied switch:

  alpha 0xff: 0xa5a3645b with and without it
  alpha 0x00: 0x1c53614d (black) with and without it
  alpha 0x80: 0x1894275d straight, 0xd0088649 premultiplied

Premultiplied blending still turns an alpha 0x00 pixel into the
background. It is therefore not an opaque mode for XRGB8888, and the
H17P primary plane keeps withholding XRGB8888.

test-h17p-swap-layout.py compiles both the previous and the new
structures and fix-ups. It checks that 2000 randomised records serialise
to identical 0xe9c-byte requests, including debug pokes, and that the
new fix-up is idempotent.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The swap-complete callback pushed the blend-CRC read (A106), the
pipe-CRC read (A030), a runtime property set (A200/A201) and the dither
request (A448) back to back without waiting for replies. Setting a
runtime property while blend_crc_reads was active pushed A200 straight
after A106, and the DCP firmware panicked:

  crashlog: ap_link: rpc_callee_gated: payload size mismatch: 16 != 24
  crashlog: panic(app): app NMI, pidx: 1

The display pipe stays dead until the next reboot.

Push at most one diagnostic call per completion. One-shot property and
dither requests go first. The CRC reads keep their remaining count and
continue on the following swaps.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The rtp debug knob sent runtime properties through A200/A201
(PropRelay setBool/setInt). No reply from either has ever been seen,
and the first A200 it sent, rtp=b:49=0, ended in a DCP firmware panic:

  crashlog: ap_link: rpc_callee_gated: payload size mismatch: 16 != 24

Send the request through A352 {u32 prop, u32 value} -> u32 instead,
which the driver already declares with that (0x8, 0x4) shape. It is
answered with status 0 on J700 (rtp=49=1, 49=0). The knob's format
becomes rtp="<prop>=<val>" (hex). Remove the A200/A201 methods and their
request structs.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The swap_complete callback (RTKit receive worker) pushed the rtp A352
property sets and the A106/A030/A448 diagnostic calls onto the command
channel, while dcp_flush() pushes A406 swap_start from the atomic commit
thread. Nothing orders the two. If the callback's push lands between
flush's busy check and its own push, dcp_call_context() sees the command
channel busy and sends A406 as a nested call on the callback context.
The DCP firmware then panics, and the panel stays dead until reboot:

  crashlog: ap_link: rpc_callee_gated: payload size mismatch: 36 != 16

36 and 16 are the A406 and A106 records. An earlier crash ("16 != 24")
had the same cause: a property set landed behind an in-flight A106.
Allowing one call per completion did not close the window.

Issue at most one pending call from the flush path instead: do_swap()
pushes it and starts the swap from its reply callback, the same pattern
the A428 pre-swap call uses. swap_complete no longer pushes anything.
CRC reads now report the CRC of the last completed swap.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…e off

The H17P pipe has no 8-bit RGB layout without alpha, so it blends the
fourth byte of XRGB8888/XBGR8888 as alpha. Where a producer leaves that
byte 0, the frame shows black. The earlier DCP driver handled this by
flagging X formats is_premultiplied (premultiplied over the black
background leaves the colour as is). On H17P that flag alone did not
help: an X = 00 frame still blended to black, because the pipe's GP
alpha divide (runtime property 0x49, on by default) un-premultiplies
first.

Blend-output CRCs (A106) of kmspat colour bars on J700 with alpha 00, 80
and ff:

  straight alpha            1c53614d 1894275d a5a3645b
  premultiplied             1c53614d d0088649 a5a3645b
  premultiplied, 0x49 = 0   a5a3645b a5a3645b a5a3645b  (= opaque)
  straight alpha, 0x49 = 0  1c53614d 1894275d a5a3645b  (unchanged)

So on H17P, keep the is_premultiplied value plane.c chooses (set only
for X formats) instead of forcing it to 0. Turn the GP alpha divide off
with A352 once per full power-on, after the first swap has completed. It
goes out as the pre-swap call of the next flush, so it never races a
swap. Straight-alpha surfaces do not depend on 0x49. Other firmware
keeps today's straight alpha. The layout test now also checks that H17P
passes is_premultiplied through.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
This reverts commit fe296cc
("drm/apple: withhold opaque XR24 primary scanout on H17P").

Withholding XRGB8888 made opaque 8-bit clients compose instead of being
scanned out directly. That worked around the band, whose cause was the X
byte being blended as straight alpha. The previous commit fixes that
cause by scanning X formats out premultiplied with the GP alpha divide
off, so an XRGB8888 buffer shows the same pixels whatever its X byte
holds. XBGR8888 had the same defect and is fixed by the same change.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…fusals

Settle corrected guilty ownership rather than firmware lowest-slot blame. Inspect spared render retirement without quarantining a pair while firmware still owns it, and report cancelled work on its own error fence.

Retire native context registry entries at actual deferred GEM unmap. Identify post-unbind view-0 refusals before publication under the mapping pin and keep their ENOENT accounting separate from ordinary submit failures.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Exercise the production service with linked, retired, guilty and successor ownership, preserving actual completions and rejecting cancellation without a witness. Pin corrected-blame settlement and deferred context registry ordering.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Return the complete recovery classification in the isolation-disabled branch. Extend the existing production deferral harness to error results and refresh its optional diagnostics and work-state stubs.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Treat an unbound canonical context view as a refusal during initialization as well as teardown. Preserve an internal reason across a race between submit preflight and alias validation, then expose ENOENT at ioctl and completion boundaries without recording a VM error. Other missing views and unrelated ENOENT errors retain ordinary accounting.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The kernel Rust error module exposes a subset of Linux error constants. Use its checked constructor with the generated ESHUTDOWN binding for the private context-refusal reason.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Integrate aurora/j700 b9e17d4 with the newer G17 queue and firmware resource lifetime implementation. Preserve J873 resource ABI, guard mappings, telemetry limits and M5/G18 runtime adapters.

Build validation: arm64 Image, modules and device trees pass with LLVM21 and the pinned corrected bindgen0.73.2; all bindgen layout fixtures pass. Hardware qualification remains pending on the new kernel.
Restore D16, two-sample and wide tile profiles from the qualified J873 kernel. Add native layer-aware target allocation and preserve shared PMP DART streams and runtime power lifetime. Linux598-r4 builds with95564 matching source inputs and qualifies98 original CTS cases with Mesa598 on J873.
Keep both pool owners until the full firmware binding becomes observable within the existing bounded completion wait. Preserve timeout, recovery and final verification. Candidate603 passes 229 original CTS cases with 133 pending-binding observations and no recovery.
Accept version 2 compute metadata with actual shared byte footprints for
correctly lowered G18 shaders. Preserve version 1's fourfold footprint for
older userspace and precompiled kernels. Keep alignment, checked arithmetic,
the 32 KiB limit and rejection of unknown versions, flags and reserved words.

Paired original hardware CTS replay: 746 qualified Pass from 755 cases,
including the 16,392-byte shared-struct and 32,768-byte shared-max cases.
All 744 previous controls remain passing; nine existing failures remain.
125 payload replays match 15 saved-native resource demands; 17 invalid payloads
remain rejected. Full 95,564-file kernel source parity and hardware retirement
evidence are retained in j873/hv/private/shared-metadata-625-20261008.
Accept the sixteen-byte sample layout for four-sample colour arrays within existing dimension and backing bounds. Keep layered depth/stencil restrictions. Real UAPI/native register checks and original 755-case hardware CTS qualification pass with the paired Mesa change.
Use stable native target reservations sized for layered workloads, reject incompatible retained mappings, and admit witnessed two-sample layered color commands. Kernel673 build and 520 physical sample/layer readbacks pass; full GL46 CTS qualification remains incomplete.
Decode G18 sub-page ZLS strides and independently validate complete
layered data and metadata extents. Retain all four native strides and
compressed stencil transfers for the admitted one-sample layered path.
Keep legacy translation and single-layer restrictions unchanged.

Validated on physical M6 with 24 independent oracle cases and the two
original layered framebuffer depth/stencil CTS cases. Exact readbacks,
admission and recorded GPU retirement pass.
Bring the asahi driver to the exact sources of module 1104, the module
that carried the GL 4.6 R5/R8/R15 trials. Relative to module683 (the
previous tip) it:

- admits single-sample, single-layer 32x32 renders with 48..128-byte
  samples in steps of 16 (up to 128 KiB), the native RGBA32 MRT
  footprint of capture 1044;
- checks layered D16 depth planes with two-byte extents, so the
  native 128-byte 8x8 layer stride of capture 1060 is accepted
  (module 0be3e3f4); compressed D16 stays rejected;
- adds DRM_ASAHI_FEATURE_G18_GRAPHICS_SCRATCH (bit 8) and the
  DRM_ASAHI_RENDER_G18_RESOURCES render suffix: the G18 adapter sizes
  per-render vertex/fragment scratch from the suffix, within the
  owned native pool, behind g18_admit_graphics_scratch (default 0)
  (module 4d66c104, R8);
- adds g18_kick_log (default 0): after G18_DRM_READY the per-kick,
  frame-pass and per-job resource lines are printed only on request;
  fault, recovery, refusal, wait, stall and admission lines always
  are (module 1104).

asahi.ko 531dc4cd90b4cfb80b3b02a7400c40c830daeef15f9409ab53718b55c1f52745,
GNU build-id a31cf8ef5c81bebca60341657de2bd34ca5dcb7a,
vermagic 7.1.12-aurora-j873-g18 (run stack-1104).

Hardware on J873: on boot 182f0edf (canary 13/13) R8 trial 1110
passed 23/23 with Mesa 1099, and R15 trial 1111 passed 823/823 with
Mesa 1104. On boot 0b4ffbc2, R5 trial 1116 passed
color_depth_attachments with 0 refusals. The image_op_*_sh GPU
recovery reproduced on this module (1112, 1116); the next commit
fixes it.

Checkpoint: the tree is the builder's kernel tree, dc7b5b9
(95,564 tracked files verified against the run-683 manifest), plus
the 19 overlay files of the run-1104 receipt, so it is the source tree
the module was built from. Each file matches the receipt's sha256.
The firmware's busy-bit-only progress path for the vertex stage (TA)
recovers any TA busy for about ten one-tick scans, about 12.8 ms after
the kick. Single-invocation vertex and geometry image_op work runs
about 11 ms, so every run of those cases was a race against a false
GPU recovery (run 1113; reproduced in H2 1119). Program progress
policy 0x232 unconditionally: TA also takes mode 2, which enters the
detailed sampler instead of the busy-bit-only path. Mode 2 still
recovered a real TA hang (about 32 ms). 3D and all timeout bounds are
unchanged.

Make the qualification parameters the defaults: g18_initdata_test=10,
g18_admit_compute=1, g18_admit_msaa4=1, g18_admit_graphics_scratch=1
and g18_sma_minimum=1. A plain "modprobe asahi" now gives the same
value for all 101 module parameters as module 1104 loaded with the
qualification line.

asahi.ko f2b27ddab59a40e624ecf3ddb629b54fc855c2ad1d9f790d12d57b9fb9be1f4a,
GNU build-id 0a23a334716c8f4a2eaf667b1429efeaef06172d (run 1120).

Hardware on J873: H1 1124 ran the image_op cases 24/24 with 0
recoveries. gl46-main, 19,714 IDs (1125 + 1129, Mesa 1109/1121, no
bring-up environment): 15,357 Pass, 4,356 NotSupported,
1 CompatibilityWarning, 0 Fail, 0 GPU recoveries. With Mesa 1128: S02
in 1132 (0 recoveries) and S01 in 1135.

Checkpoint: the tree is dc7b5b9 plus the 19 overlay files of the
run-1120 receipt (sha256 per file).
Capture 1121 shows the native driver using 40-, 56- and 72-byte
samples in single-sample 32x32 tiles (req2-clear, impl0-clear,
impl17-clear). translate_g18_render_command admitted only 48..128-byte
samples in steps of 16 (or tiles of at most 32 KiB), so it refused
those renders and Mesa could not use the native layouts.

Under the unchanged guard (one sample, one layer, 32x32 utiles) also
admit exactly 40, 56 and 72 bytes, and advertise it to userspace as
DRM_ASAHI_FEATURE_G18_NATIVE_TILE_SAMPLES (bit 9; bits 6 and 7 are
reserved for other clients and bit 8 is graphics scratch). The bit is
unconditional on the G18 adapter: the admission has no parameter. The
G17 translator and the shared translator are byte-identical.

asahi.ko af4d1c94dcdc223fe8a6ec9f1a73f14d2f4209c1375e9ea2ad1caba5e101da05,
GNU build-id d99383f0d323905fa870f18e952158d29c3e0453,
5,395,776 bytes (run 1134).

Hardware on J873, cycle 1142 boot (canary 13/13), with Mesa 1139
cand02 and then cand04: trial 1139 (S01 1,324/1,325), 1144 (all 40
draw_buffers_indexed.random IDs), findLSB H3 1140, and final regression
1145 (207 batches, 0 Fail): S01 1,325/1,325 Pass; gl46-main 15,357
Pass, 4,356 NotSupported, 1 CompatibilityWarning; S02 30,960 Pass, 288
NotSupported. This is the final GL 4.6 module.

Checkpoint: the tree is dc7b5b9 plus the 19 overlay files of the
run-1134 receipt (sha256 per file).
…trol stream (default 48)

The G18 adapter admits one dispatch, 48 bytes (G18_COMPUTE_STREAM_BYTES, imported from the M5 profile). On the M6 (T8152, G18G) every MLX compute submit was refused: the kernel log of boot fc862744 shows seven 'G18 compute admission rejected ... stream_bytes=N (profile admits one dispatch, 48)' lines, N = 180 once, 136 once, 92 five times, all with flags=0x4, no sampler heap, no samplers.

The limit moves into g18_compute_stream.rs (pure, host-tested) and becomes the module parameter g18_compute_stream_bytes: default 48, which keeps today's behaviour and log text exactly; 48 to 4096 accepted; anything else refuses to bind before MMIO. This is admission only. What the firmware does with a longer stream is not shown by this change and is proven on hardware, step by step (92, 136, 180). The sizes read as 44*k+4 bytes (k dispatch records and a terminator); that is an inference from the three sizes, noted in the module, and nothing here counts dispatches.

Tests: tests/test_g18_compute_stream.py builds the module with rustc --test (5 unit tests) and checks the wiring. Not built here as a kernel module on the CT; see the PR text for the build check.
has_wfxt() keeps ARM64_HAS_WFXT off the parts in
apple_wfxt_loses_state, but the HWCAP2_WFXT bit userspace sees is
matched from the raw ID_AA64ISAR2_EL1 field and stays advertised on
those parts. Give the WFxT hwcap entry the same has_wfxt match via
the existing HWCAP_CAP_MATCH_ID helper, so the one list drives both
levels.

What changes for user space is only the ELF-visible HWCAP2_WFXT bit
and the wfxt line in /proc/cpuinfo; the ID_AA64ISAR2_EL1 field read
through MRS emulation is untouched, and the kernel-side WFIT/WFET
paths were already gated by has_wfxt() before this patch. WFET is
not trapped at EL0 on this tree: INIT_SCTLR_EL1_MMU_ON sets
SCTLR_EL1_nTWE (sysreg.h), so EL0 can execute WFET regardless of
the hwcap. The patch removes the discovery signal; it does not
trap WFET.

Also spell the four raw MIDR part numbers with their cputype.h
constants so the list reads without the hex table.

Measured on T8152: with the gate, wfxt is absent from /proc/cpuinfo
across two independent pushed boots (no arm64.nowfxt argument); with
only the capability rule it is listed on all 12 CPUs. Memory and
module-fingerprint checks stayed clean across the same boots, and a
stock control boot between them confirmed the firmware path.

Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
has_wfxt() keeps ARM64_HAS_WFXT off the parts in
apple_wfxt_loses_state, but the HWCAP2_WFXT bit userspace sees is
matched from the raw ID_AA64ISAR2_EL1 field and stays advertised on
those parts. Give the WFxT hwcap entry the same has_wfxt match via
the existing HWCAP_CAP_MATCH_ID helper, so the one list drives both
levels.

What changes for user space is only the ELF-visible HWCAP2_WFXT bit
and the wfxt line in /proc/cpuinfo; the ID_AA64ISAR2_EL1 field read
through MRS emulation is untouched, and the kernel-side WFIT/WFET
paths were already gated by has_wfxt() before this patch. WFET is
not trapped at EL0 on this tree: INIT_SCTLR_EL1_MMU_ON sets
SCTLR_EL1_nTWE (sysreg.h), so EL0 can execute WFET regardless of
the hwcap. The patch removes the discovery signal; it does not
trap WFET.

Also spell the four raw MIDR part numbers with their cputype.h
constants so the list reads without the hex table.

Measured on T8152: with the gate, wfxt is absent from /proc/cpuinfo
across two independent pushed boots (no arm64.nowfxt argument); with
only the capability rule it is listed on all 12 CPUs. Memory and
module-fingerprint checks stayed clean across the same boots, and a
stock control boot between them confirmed the firmware path.

Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
A co-processor that leaves the crashlog endpoint out of its map and owns
its crash buffer reports a crash with a buffer that has no CPU mapping.
The crash handler validated the log header before it reached the
firmware-owned case, so apple_rtkit_memcpy() copied from a NULL pointer
in the receive work and the oops left the rtkit workqueue stuck.

Check the header only when the buffer is mapped. The firmware-owned case
then logs the buffer's DVA and size and tells the client.
CHIS can read online while the battery neither charges nor discharges:
on sn201202x a port1 PD source set CHIS with 0 A into the battery
holding at 97 percent, so every AC consumer claimed online while the
system ran on battery (M5 ask be46547c64).

Report ONLINE 0 when macsmc_battery_get_status() says DISCHARGING, or
when it says NOT_CHARGING and B0AC (battery current) is <= 0 mA.
Otherwise report CHIS as before. SMC read errors keep the old
fail-open behaviour.

Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
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.

6 participants