Repository navigation
drm/apple: m4: expose panel_adaptation sysfs for white-point adaptation - #4297
Conversation
On T8132 (M4) internal panels running firmware 26.6.2, macOS drives True Tone white-point adaptation by sending a 3x3 colour matrix to the DCP with set_matrix (A423) at location 9 (keeping factory calibration at location 8). On Linux, the CRTC KMS CTM property is owned by the compositor for night-light clients, leaving no separate interface for a panel white-point adaptation daemon. Expose a read/write panel_adaptation sysfs attribute on the internal M4 DCP platform device (absent on external DCPs) accepting nine decimal signed S31.32 two's-complement values in row-major order, clamped to [-4.0, +4.0]: - Nothing is sent at boot or on identity/unchanged writes; writing identity clears a previously active adaptation once. - Live writes queue set_matrix (A423) at location 9 on dcp->runtime->wq so userspace ramps can step smoothly without waiting for a swap. - Writes arriving while the display is blanked, power-gated, or suspended never issue an RPC to a stopped coprocessor (avoiding session quarantine); the matrix stays pending and is applied before the first swap on wake, and active adaptations are re-marked pending across blank, power-gate, and system resume. Document the sysfs ABI in Documentation/ABI/testing/sysfs-driver-apple-dcp and add an m4-panel-adaptation host selftest in tools/testing/selftests/drivers/gpu/apple-dcp/. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
There was a problem hiding this comment.
Verdict: REQUEST_CHANGES at 2074dc12b0e597554838b1a8147cb1786a1fedaf
Blockers:
Failure: panel_adaptation_store() at iomfb_m4.c:3738 accepts a malformed matrix with two adjacent coefficients and commits it. For example, 1-2 0 0 4294967296 0 0 0 4294967296 is accepted as nine values with leading coefficients 1 and -2. The whitespace in the scan format can consume zero bytes, as the kernel's vsscanf() specifies. The store also accepts a complete matrix followed by an embedded NUL and trailing bytes, returning the full write count and queuing the matrix. This contradicts the documented rejection of malformed and trailing input. Validate the delimiters and the full write length before storing or queuing an update.
Checked: Replayed the exact store function and checked the kernel scanning rules. The control with visible trailing text returned -EINVAL, and the space-separated control succeeded. Reviewed power-state guards, wake ordering and device-managed attribute lifetime. The delta changes no DT files.
Evidence
Both malformed writes returned the full count and queued an update in the host replay. The delimiter behavior follows the kernel scanner, and the store only uses the write count for its return value.
|
Cross-PR note for whoever merges this or #3262 second: #3262 (KMS CTM / night light on the same M4 internal panel) also sends |
…n_store Replace the sscanf() call in panel_adaptation_store() with an explicit length-bounded decimal parser that rejects embedded NUL bytes anywhere within count, requires at least one ASCII whitespace delimiter between consecutive coefficients, rejects out-of-range s64 values, and rejects any trailing non-whitespace bytes before updating state or queuing work. Expand the m4-panel-adaptation host selftest to cover adjacent signed coefficients, embedded NUL with trailing bytes, hex/overflow/empty inputs, whitespace variations, and S64 boundary clamping. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
|
Addressed the
Offline verification:
|
There was a problem hiding this comment.
Verdict: MERGE at 995f113
This only re-checks the earlier App blockers at 2074dc1. panel_adaptation_store() now uses its own parser instead of sscanf.
Checked:
- Adjacent tokens: from the second coefficient on, at least one whitespace byte is required before each token, so
1-2 ...and1+2 ...(and the same at the last position) return-EINVAL.0x10stops atx, and the parse then fails the delimiter or end check. - Trailing input: after nine values, only whitespace may remain up to
count, and any NUL inside the writtencountbytes is rejected (memchr). Both NUL cases from the earlier finding are now host-test cases. - Overflow:
mag > (limit - d) / 10keepsmag * 10 + d <= limit, withlimit= S64_MAX for positive values and 2^63 for negative ones, so-9223372036854775808parses and ±1 beyond fails. A rejected write leaves stored state untouched (the assertions checkadapt_active/pending/queued/matrix_calls). - The only other change is the host-test harness picking up the new function. I approved the real fork CI runs.
Follow-ups (not blocking):
- As noted on the PR, #3262 also writes
set_matrixlocation 9. Whichever of the two lands second needs one combined sender.
RyanTheTide
left a comment
There was a problem hiding this comment.
ORCH5 merge sweep: passes the six-point gate (CI green at 995f113, independent review approval by aurora-silicon-review[bot], no taint, no Stage 1/LocalPolicy change).
What: Expose a read/write
panel_adaptationsysfs attribute on the internal Apple T8132 (M4) firmware 26.6.2 DCP platform device (/sys/bus/platform/drivers/apple-dcp/*/panel_adaptation, absent on external DCPs) so userspace white-point adaptation daemons (True Tone) can driveset_matrix(A423, location 9) without competing with compositor-owned CRTC KMS CTM (night light):4294967296 0 0 0 4294967296 0 0 0 4294967296is identity), rejects malformed or trailing input with-EINVAL, and clamps each coefficient to[-4.0, +4.0].set_matrix(A423, location 9) ondcp->runtime->wqfor live writes so True Tone ramps step smoothly without waiting for a swap.display_off), power-gated (gated), suspended (powered_off), orquiescing— preventing session quarantine when a daemon ramps while the DCP CPU is stopped. Pending or active adaptations are applied before the first swap on wake (iomfb_m4_present_at()) and re-marked pending acrossdcp_m4_set_power_state(false),iomfb_m4_power_ungate(), andiomfb_m4_resume().Documentation/ABI/testing/sysfs-driver-apple-dcp(registered inMAINTAINERS) and adds them4-panel-adaptationhost selftest intools/testing/selftests/drivers/gpu/apple-dcp/.Tested:
2074dc12b0onorigin/main(8ae72dc32d,git merge-tree --write-treecleana31bd899e251):scripts/checkpatch.pl --strict --no-tree:0errors,0warnings,0checks (569lines checked).tools/testing/selftests/drivers/gpu/apple-dcp/run.py --group m4, Clang 23.1.5,-Wall -Werror -fsanitize=address,undefined):11/11PASSED (includingm4-dpms-retirement, newm4-panel-adaptation, andm4-power-gate).LLVM=1 W=1 KCFLAGS="-Werror"(Clang 18.1.8,CONFIG_DRM_APPLE=m,CONFIG_DRM_APPLE_DCP_T8132=y):CONFIG_PM_SLEEP=y:drivers/gpu/drm/apple/iomfb_m4.o(908536B) —0warnings.CONFIG_PM_SLEEP=n:drivers/gpu/drm/apple/iomfb_m4.o(904640B) —0warnings.panel_adaptationABI and power-gate guard on livelinux-aurora(1.934through1.1699/1.1700):/sys/bus/platform/drivers/apple-dcp/*/panel_adaptationwith0DCP faults.l.18931): writingpanel_adaptationwhile display was off pastpower_gate_ms(both across deep sleep and 25 s blank without sleep) produced0quarantined sessions, panel lit cleanly on wake, and adaptation matrix re-applied.Risk: two-way door · T8132 (M4) internal firmware 26.6.2 DCP only (
!external). External DCPs do not create the sysfs group and return-ENODEV; a desktop that never writespanel_adaptationsends zeroA423RPCs. A plain revert removes the attribute cleanly.Not yet:
origin/main(2074dc12b0) hardware boot and DPMS/deep-sleep run on J604, J713, and J715.#3262(drm/apple: m4: colour matrix (CTM) on the internal panel):#3262also targetsset_matrix(A423) location 9 for the CRTC KMS CTM property. Once#3262merges (or if#3262lands first),panel_adaptationcomposes cleanly on top asout = adaptation * CTM * in(Q32.32 multiply(a >> 16) * (b >> 16)with both matrices clamped to[-4.0, +4.0]) so a compositor's night light and True Tone share location 9 without replacing each other.Details and verification
Scope (
j604/dcp-m4-panel-adaptation, head2074dc12b0onmain8ae72dc32d)drivers/gpu/drm/apple/iomfb_m4.c(+164 / -1):adapt_work,adapt[9],adapt_active,adapt_pending,iomfb_m4_send_adaptation(),panel_adaptationsysfs group registered afteriomfb_m4_release()on!external, pre-swap application iniomfb_m4_present_at(), re-mark across blank/power-gate/resume, andcancel_work_sync()iniomfb_m4_quiesce().Documentation/ABI/testing/sysfs-driver-apple-dcp(+26): sysfs ABI documentation.MAINTAINERS(+1): registersDocumentation/ABI/testing/sysfs-driver-apple-dcpunderAPPLE DCP.tools/testing/selftests/drivers/gpu/apple-dcp/m4.py&run.py(+187 / -7): updatesm4-dpms-retirementandm4-power-gatefor the new fields/helper and addsm4-panel-adaptationcovering boot identity no-op, malformed input-EINVAL,[-4.0, +4.0]clamping, 80-byteA423wire encoding, duplicate rewrite suppression, gated/blanked deferral +P->M->Swake order, firmware status refusal, identity clear, external-ENODEV, and transport failure before swap.Signed-off-by: Dylan Ironside <dylan@dylanironside.io>.Offline Verification
scripts/checkpatch.pl --strict --no-tree:0 errors, 0 warnings, 0 checks(569lines checked).git merge-tree --write-tree origin/main HEAD: clean (a31bd899e251b43705464cdb860633f951a44a11).run.py --group m4, Clang 23.1.5, ASan/UBSan-Wall -Werror):11/11PASSED.LLVM=1 W=1 KCFLAGS="-Werror"(Clang 18.1.8):drivers/gpu/drm/apple/iomfb_m4.o0warnings with bothCONFIG_PM_SLEEP=y(908536B) andCONFIG_PM_SLEEP=n(904640B).