Skip to content

soc: apple: clpc: link without the SMC driver (r2) - #2846

Merged
RyanTheTide merged 2 commits into
integration/aurorafrom
fix/clpc-link-without-smc-r2-20261123
Nov 22, 2026
Merged

RyanTheTide merged 2 commits into
integration/aurorafrom
fix/clpc-link-without-smc-r2-20261123

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Problem. APPLE_CLPC treats the SMC as optional (depends on MFD_MACSMC || !MFD_MACSMC), but the PHPC package-power read and the zETM High Power mode record call apple_smc_read()/apple_smc_write(), which have no stubs. A kernel with APPLE_CLPC=y and MFD_MACSMC unset fails to link. That includes the driver's own drivers/soc/apple/clpc.kunitconfig, so the CLPC KUnit suite does not build on integration/aurora (it blocks #2821).

Change. Same two commits as #2693, rebased on integration/aurora f5fae3c (279 commits on, incl. #2784 and #2816), plus Dj's review of #2693:

  • apple_clpc_read_power() and apple_clpc_send_high_power() test IS_ENABLED(CONFIG_MFD_MACSMC) first, so the SMC calls drop out at compile time.
  • New: probe takes the apple,smc phandle only when the SMC driver is built. Without it clpc->high_power stays false, so writing performance switches the profile like any other instead of failing with -ENODEV and leaving the low-power ceiling in place.
  • Second Fixes: for f04da7c, which added apple_smc_write().
  • The host test models the SMC driver being built.

No new gate: the guard is the Kconfig symbol of the optional dependency. Kernels with the SMC driver (all our distro and fleet configs) are unchanged.

Testing.

  • KUnit, arm64 qemu: stock clpc.kunitconfig (no SMC) links and passes 11/11; with MFD_MACSMC=y 13 pass, 1 skip (needs UCLAMP_TASK).
  • clpc.o built with the fleet config (RUST off for the one-object build): with MFD_MACSMC=y, tip and this head give the same normalized objdump -d (0 lines of diff, text 22025 bytes both). With MFD_MACSMC=n and ACPI_PLATFORM_PROFILE=y, tip has undefined apple_smc_read/apple_smc_write and still parses apple,smc; this head has neither.
  • tools/asahi/clpc-high-power-cleanup-tests.py and clpc-gpu-demand-tests.py pass; checkpatch --strict clean.

Still to run. Nothing on hardware: with the SMC driver the code is byte-for-byte the same.

Supersedes #2693 (fresh branch instead of a force push).

Review points from #2693 and where they went
  1. Blocker: performance fails with -ENODEV on a High Power machine when MFD_MACSMC=n. Fixed in apple_clpc_probe(): if (IS_ENABLED(CONFIG_MFD_MACSMC)) clpc->smc_np = of_parse_phandle(...), so clpc->high_power = clpc->smc_np && high_power is false. apple_clpc_profile_set() then never calls apple_clpc_send_high_power(), updates profile and clears low_power, and debugfs prints no smc high power line. The compile-time guards in both callers stay.
  2. Nit: second Fixes: f04da7cf87ff ("soc: apple: clpc: J714s: tell the SMC about High Power mode") added.
  3. Nit: fleet-config codegen proof: objdump comparison above (MFD_MACSMC=y: identical).

Objects (sha256 prefix, text, undefined SMC symbols, apple,smc strings):

smc-y-tip  e632a79aa3265c88 text=22025 undef=apple_smc_read,apple_smc_write strings=1
smc-y-head 11759455be9b7d80 text=22025 undef=apple_smc_read,apple_smc_write strings=1
smc-n-tip  e632a79aa3265c88 text=22025 undef=apple_smc_read,apple_smc_write strings=1
smc-n-head 89d1961683c3a673 text=20393 undef=(none)                         strings=0

(smc-y-head differs from smc-y-tip only in line-number data; the disassembly is the same.)

Assisted-by: LLM (Claude:Opus 5.5)

APPLE_CLPC treats the SMC as optional ("depends on MFD_MACSMC ||
!MFD_MACSMC"), but the PHPC package-power read and the zETM High Power
mode record call apple_smc_read()/apple_smc_write(), which have no
stubs. A kernel with APPLE_CLPC=y and MFD_MACSMC unset fails to link:

  clpc.c: undefined reference to `apple_smc_write'
  clpc.c: undefined reference to `apple_smc_read'

That includes the driver's own clpc.kunitconfig, which does not enable
the SMC.

Test IS_ENABLED(CONFIG_MFD_MACSMC) before looking the SMC up, so both
paths return -ENODEV and the calls drop out at compile time. Probe does
not take the apple,smc phandle either in such a kernel, so High Power
mode stays off and the performance profile switches like any other
(without that, a machine with apple,high-power-mode would fail every
write of "performance" with -ENODEV). The low-power profile then has only
its frequency ceiling, as it already does when the node has no apple,smc
phandle. Kernels with the SMC driver are unchanged.

Fixes: f04da7c ("soc: apple: clpc: J714s: tell the SMC about High Power mode")
Fixes: bdd3bc3 ("soc: apple: clpc: T6050 platform profiles after macOS's power modes")
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
apple_clpc_send_high_power() now tests IS_ENABLED(CONFIG_MFD_MACSMC)
before it talks to the SMC. The host test compiles the extracted
function against its own prelude, which had neither macro, so it
stopped building. Define both, with the SMC driver built in, so the
test keeps exercising the SMC path it checks.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at 69bc2c3.

Right fix. With depends on MFD_MACSMC || !MFD_MACSMC, MFD_MACSMC=m already forces APPLE_CLPC to m, so IS_ENABLED() (true for y and m) is the correct test, and the only configuration that changes is MFD_MACSMC=n. There the two apple_smc_*() callers fold away at compile time, and apple_clpc_smc() is still referenced, so no unused-function warning. Skipping the apple,smc phandle in probe is the important part: without it, high_power would stay true and performance would fail with -ENODEV and keep the low-power ceiling. Same object code with MFD_MACSMC=y, as the body shows, so no row is owed on the Macs. Trailers are human-only.

Not this PR: clpc->hw->high_power_machine ("apple,j714s") is still a board compatible deciding whether High Power mode exists. It's worth moving to a DT/ADT property the loader copies, like the Low Power ceiling.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial pre-PR checklist review (§1–§6) at 69bc2c322912755ce6d54dbd3437fe702cbba139 (APPROVE).

Checklist Summary

  • §1 (No model gating): Pass — guards strictly on IS_ENABLED(CONFIG_MFD_MACSMC) for the optional Kconfig dependency.
  • §2 (Production-ready / default cmdline): Pass — no cmdline parameters, hacks, or workarounds.
  • §3 (Safety & Kconfig link correctness): Pass — verified every SMC touchpoint in drivers/soc/apple/clpc.c:
    • drivers/soc/apple/Kconfig:320 (depends on MFD_MACSMC || !MFD_MACSMC) forbids APPLE_CLPC=y with MFD_MACSMC=m, so IS_ENABLED(CONFIG_MFD_MACSMC) matches every valid build configuration.
    • Both apple_smc_*() call sites (apple_smc_read_u32() at clpc.c:828 and apple_smc_write() at clpc.c:1315) sit behind !IS_ENABLED(CONFIG_MFD_MACSMC) and fold out at compile time when MFD_MACSMC=n, while apple_clpc_smc() remains referenced (no unused-function warning) and uses only OF/driver-core APIs.
    • The #2693 blocker is cleanly fixed in apple_clpc_probe() (clpc.c:1545-1547): gating of_parse_phandle(dev->of_node, "apple,smc", 0) on IS_ENABLED(CONFIG_MFD_MACSMC) keeps clpc->smc_np = NULL and clpc->high_power = false when MFD_MACSMC=n, so High-Power-only machines skip registering "apple-smc", machines with low_power_khz switch performance without -ENODEV, debugfs omits the SMC High Power line, and apple_clpc_stop() skips the SMC write (of_node_put(NULL) is a safe no-op).
    • tools/asahi/clpc-high-power-cleanup-tests.py defines CONFIG_MFD_MACSMC and IS_ENABLED() so the host test continues exercising the SMC path.
  • §4 (Clean-room & attribution): Pass — both commits (a4c4da52403e, 69bc2c322912) carry human author/committer and human Signed-off-by: only, include both Fixes: tags (f04da7cf87ff, bdd3bc3f17b4), and supersede #2693 on a fresh branch without force-pushing; PR body includes Assisted-by:.
  • §5 (Evidence): Pass — KUnit passes with stock clpc.kunitconfig (unblocking #2821) and with MFD_MACSMC=y, fleet-config objdump -d shows identical codegen when MFD_MACSMC=y (no hardware row owed), and all 7 CI checks (host-tests, source, rust-build, kunit, and all 3 DWC3/ATC build matrices) are green.
  • §6 (Naming): Pass — touches only existing in-tree paths.

Clean replacement for #2693; ready to unblock #2821 and queue for merge.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merge-train adversarial review (MERGETRAIN-LINUX4) at 69bc2c3: no blockers. Merges clean on integration/aurora 000ab96.

Full review

VERDICT: NO BLOCKERS

Blockers: none.

What I checked:

  • (a) Link matrix. Kconfig: depends on MFD_MACSMC || !MFD_MACSMC (drivers/soc/apple/Kconfig:320), so MFD_MACSMC=m forces APPLE_CLPC<=m. Valid combinations:
    • SMC=y with CLPC=y/m, and SMC=m with CLPC=m: IS_ENABLED()=1, apple_smc_read/apple_smc_write are EXPORT_SYMBOL (drivers/mfd/macsmc.c:306,317), and the code is the same as before.
    • SMC=n with CLPC=y/m: the only apple_smc_* references in clpc.c are clpc.c:828 (apple_smc_read_u32, an inline in macsmc.h:292 that calls apple_smc_read) and clpc.c:1315 (apple_smc_write). Both sit behind !IS_ENABLED(CONFIG_MFD_MACSMC) || with a constant 0, so they fold out. apple_clpc_smc() only uses OF/driver-core calls, and SMC_KEY/struct apple_smc come from the header with no config guard.
    • Kbuild builds only clpc.o for CLPC (Makefile:68). The other apple_smc_* user in drivers/soc/apple, sensor_shim.c, is not part of it.
    • SMC=m with CLPC=y is not allowed by Kconfig.
  • (b) Kernels with the SMC driver behave the same. All three new conditions are compile-time true when MFD_MACSMC is y or m, so the PHPC read, the zETM write and the apple,smc phandle parse are unchanged on every clpc Mac (J616s, J713, Neo, J616c, M5) in fleet-style SMC=y/m kernels. I traced every use of smc_np (clpc.c:808-809 lazy lookup, 1233 of_node_put, 1546-1547 probe): the phandle is used only for the lazy of_find_device_by_node + device_is_bound + device_link_add in apple_clpc_smc(). Probe never deferred on the SMC, before or after this PR: it only parses the phandle, and the device link is made on first use. So with SMC=m loaded later, probe and deferral work as before. drivers/of/property.c has no fw_devlink parser for apple,smc, so no implicit supplier link changes either.
  • With SMC=n, high_power is false. Machines that only have High Power mode get no platform profile (clpc.c:1550). Machines with a low-power ceiling get "apple-clpc" with the ceiling only, and the PHPC read returns -ENODEV, which is ignored (mw >= 0). Stop skips the SMC write, and of_node_put(NULL) is safe. Without the probe guard, performance would return -ENODEV. The probe guard fixes this, as the earlier review said.
  • (c) Range-diff soc: apple: clpc: link without the SMC driver #2693 (da9e3bb) -> soc: apple: clpc: link without the SMC driver (r2) #2846 (69bc2c3): patch 1 adds only the probe hunk, the new Fixes: f04da7c and the reworded message. Patch 2 is identical. The context lines match the post-soc: apple: clpc: take High Power mode from the device tree #2784/soc: apple: clpc: Take the Low Power mode ceiling from the DT (rebased on #2784) #2816 code (apple,high-power-mode DT property, apple,low-power-frequency-max-mhz), so the rebase lost nothing. Both Fixes SHAs exist in the tip and introduced the two unguarded calls.
  • (d) Host test. I ran tools/asahi/clpc-high-power-cleanup-tests.py from a git archive of the PR head: it passes. With CONFIG_MFD_MACSMC 0 it still compiles and fails exactly the performance assertion. So the guard is real, and the =1 prelude models an SMC=y/m kernel correctly (IS_ENABLED(x) -> x matches the kernel macro for a value of 1). The extra defines do no harm in --old-ref mode, where old sources don't use IS_ENABLED.
  • Rules: no chip, board or firmware gates, params or knobs added. The only new condition is a Kconfig symbol. Author, committer and Signed-off-by are Ryan, with no agent trailers.

Nits:

  1. Bisect: on a4c4da5 alone, the host test fails to build because its prelude has no IS_ENABLED. 69bc2c3 fixes that. The kernel build is fine at both commits. The two commits could be squashed. This does not block.
  2. The host test covers only SMC=y. The SMC=n probe path (smc_np stays NULL, so high_power is false, so no profile or only the ceiling) is not exercised anywhere: probe is not extracted. Optional.
  3. Pre-existing, not this PR (the earlier review also noted it): hw->high_power_machine ("apple,j714s") is still a board-compatible fallback.

Missing rows: none owed. Codegen is unchanged when SMC=y/m, which follows from the source. I did not re-run the author's objdump. The CI kunit job (stock clpc.kunitconfig, SMC=n) is green, and that covers the link case.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide
RyanTheTide merged commit 440c19c into integration/aurora Nov 22, 2026
7 checks passed
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.

2 participants