Skip to content

kernel/user partition, Phase 4 part 3: untangle the DMA, timer and LL domain headers - #11470

Merged
kv2019i merged 5 commits into
thesofproject:mainfrom
lgirdwood:kernel-user/phase4c
Nov 17, 2026
Merged

kv2019i merged 5 commits into
thesofproject:mainfrom
lgirdwood:kernel-user/phase4c

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Phase 4 of #11306 (kernel / user-space partition), third part: three headers that user-space code needs stop including kernel-only headers they do not use. The DMA headers are reclassified, and the leak baseline shrinks from 39 to 29 sources.

What changes

  • sof/lib/dma.h no longer includes sof/lib/io.h (register access) or the platform memory map. It brought both into every user-space source that uses the DMA API.
  • rtos/timer.h no longer includes sof/platform.h. It brought the platform definitions and clock headers into every user-space source that reads the cycle counter.
  • ll_schedule_domain.h includes rtos/clk.h only in the host builds. That is the only place where domain_init() uses it.
  • zephyr/drivers/dma.h is no longer a kernel-only header for the checker.
    • The sof_dma_*() system calls take Zephyr's struct dma_config and struct dma_status, so user-space code needs the header for their arguments and constants.
    • Zephyr's header cannot be split, and it has no system calls of its own.
    • What user-space code must not do is call the dma_*() driver functions directly. The include check cannot catch that, so the manifest says so. Today no user-space source does: the user-space DMA code only uses the sof_dma_*() calls.

In the CI configurations, sof/platform.h, sof/lib/io.h and the i.MX sof/drivers/mu.h no longer reach any user-space source, and rtos/clk.h only reaches the two pipeline sources that include it directly. Not counting the reclassified Zephyr header, the (user-space source, kernel-only header) pairs go from 671 to 300.

Patches

  1. lib: dma: drop sof/lib/io.h and the memory map from sof/lib/dma.h. Three kernel sources got them through it and now include them:
    • zephyr/wrapper.c takes the register helpers and the memory map. It included the platform memory header directly, which only works after sof/lib/memory.h.
    • zephyr/lib/cpu.c and ipc3/host-page-table.c take the memory map.
    • dma-legacy.h, which sof/lib/dma.h includes for builds without the Zephyr native drivers, takes the register helpers. Among the platforms that build, only acp_6_0 uses it.
  2. rtos: timer: drop sof/platform.h. base_fw_intel.c, zephyr/lib/alloc.c and zephyr/lib/cpu.c used HOST_PAGE_SIZE and platform_boot_complete() through it and now include it.
    • dai-zephyr.c also got the memory map this way, for local_to_host(). It defines local_to_host() as a no-op when the platform doesn't, so without the include it still built but lost the imx8ulp address translation. The object comparison caught this, and dai-zephyr.c now includes sof/lib/memory.h. No other object changed.
  3. schedule: ll_schedule_domain: include rtos/clk.h only when not building for Zephyr. On Zephyr, domain_init() uses k_ms_to_cyc_ceil64(). The native_sim platform code used the clock definitions through this header and now includes rtos/clk.h.
  4. scripts: kernel_user_partition: allow zephyr/drivers/dma.h, as described above.
  5. Baseline: remove the ten sources that are now clean: ASRC, chain DMA, copier DAI and gain, UAOL, the DMA and DAI library code, the user-space IPC code, and the DP scheduler thread and application code.

What is left

The 29 remaining sources use kernel APIs, not just kernel headers:

  • Mailbox writes and layout constants (copier, volume, DAI, host, pipeline and IPC code; 13 sources). Through the platform mailbox headers, this also brings in most of the remaining memory map leaks.
  • Timestamps: the platform timestamp functions and the cycle counter from rtos/timer.h (11 sources).
  • IRQ locking: irq_local_disable()/irq_local_enable() (7 sources).
  • IADK: the user-space helper partitions in the IADK sources.
  • Single uses: the remaining kernel-only headers each reach one or a few sources: perf_cnt.h, agent.h, cpu-clk-manager.h, watchdog.h and pm_runtime.h.

Functional change

None.

Testing

  • Include checker: with --strict, it passes for each of the 12 CI build configurations, built locally as CI does (repro-build.conf, -Werror), and for every other configuration below. Across all of them, exactly the 29 baseline sources leak.
  • Per commit:
    • Builds: tgl, tgl-h, mtl, lnl, ptl, wcl, nvl, imx8, imx8x, imx8m, imx8m_cm7, imx8ulp, imx95 and qemu_xtensa, and the extra CI configurations:
      • native_sim IPC3/IPC4 stub builds;
      • imx93 64-bit;
      • PTL with each userspace overlay;
      • PTL with CONFIG_SOF_USERSPACE_PROXY=n;
      • PTL and MTL with os_linux_overlay.conf;llext_relocatable.conf;
      • PTL and TGL with app/debug_stream_overlay.conf, and PTL with that overlay and user-space LL.
    • Comparisons: objects, LLEXT modules and firmware images (sections, symbols, SYS_INIT() order), and the per-function disassembly. No object changes at any commit. The only image difference is sof_init() on imx8m_cm7, imx93 and imx95, which embeds the git hash.
    • Signing: rimage runs for every Intel platform, and the generated configs are unchanged.
    • Cadence xt-clang (RI-2022.10): MTL, PTL and NVL compile.
    • ZTest: the unit tests pass, run as in CI (18 of 18 configurations).
    • Host: the host library and the cmocka unit tests build and pass.
  • At the tip:
    • the testbench and the tools pass;
    • the host library and the cmocka unit tests pass for all nine defconfigs and the library config;
    • the platforms that already fail on main (acp_6_0, acp_7_0, acp_7_x, mt8186, mt8188, mt8195, mt8196, mt8365) have unchanged error sets. That check found the dma-legacy.h dependency; none of the other configurations includes that header, so the other results are unaffected by the fix.

All of the above was run on 607d0a9 (current main).

🤖 Generated with Claude Code

lrgirdwo and others added 5 commits November 16, 2026 20:04
sof/lib/dma.h uses neither the register access helpers of
sof/lib/io.h nor the platform memory map, but it brings both into the
user-space host, DAI, copier, chain DMA, ASRC and pipeline sources
that use the DMA API. Drop the includes.

Three kernel sources got them through this header, so they include
what they use: zephyr/wrapper.c the register helpers and the memory
map, which it included as platform/lib/memory.h instead of through
sof/lib/memory.h, zephyr/lib/cpu.c and ipc3/host-page-table.c the
memory map. So does dma-legacy.h, which sof/lib/dma.h includes for the
builds without the Zephyr native drivers: it uses the register
helpers.

No functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
rtos/timer.h uses nothing from sof/platform.h, which brings the
platform definitions and clock headers into every user-space source
that reads the cycle counter or the stream timestamps. Drop the
include.

base_fw_intel.c, zephyr/lib/alloc.c and zephyr/lib/cpu.c used
HOST_PAGE_SIZE and platform_boot_complete() through this header, so
they include sof/platform.h.

dai-zephyr.c got the memory map through this header too, and it uses
local_to_host() from it. It defines local_to_host() as a no-op if the
platform doesn't, so without the include the code still built but lost
the imx8ulp address translation. Include sof/lib/memory.h there.

No functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
domain_init() only uses clock_ms_to_ticks() from rtos/clk.h in the
builds without Zephyr. The Zephyr builds compute the ticks with
k_ms_to_cyc_ceil64(), but still include the clock header, and with it
the platform clock headers, into the user-space scheduler and IPC
sources. Only include it when not building for Zephyr.

The native_sim platform code used the clock definitions through this
header, so it includes rtos/clk.h.

No functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
The sof_dma_*() system calls in sof/lib/sof_dma.h take Zephyr's
struct dma_config and struct dma_status, and their callers use the
Zephyr DMA constants, so user-space code needs zephyr/drivers/dma.h.
The header has no system calls itself, and Zephyr's own header cannot
be split.

Remove it from the kernel-only headers, with a note that user-space
code must not call its dma_*() driver functions directly, which the
include check cannot catch. None does today: the user-space DMA code
only uses the sof_dma_*() calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Ten sources no longer include kernel-only headers in any
configuration: the ASRC, chain DMA, copier DAI and gain, UAOL, DMA and
DAI library sources, the user-space IPC code and the DP scheduler
thread and application code. Remove them from the leak baseline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>

Copilot AI 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.

🟢 Approval recommended

No active review issues block the header-dependency cleanup supporting kernel/user-space separation.

No open issues 🎉

What changed in this PR

This PR advances the kernel/user-space partition in #11306 by removing unnecessary kernel-header dependencies from shared DMA, timer, and low-latency scheduling headers, with no intended functional change.

Changes:

  • Removes transitive kernel includes and adds explicit dependencies where needed.
  • Allows the Zephyr DMA header for syscall argument types while documenting that direct driver calls remain prohibited.
  • Reduces the include-checker leak baseline from 39 sources to 29.
File Description
zephyr/​wrapper.c Explicitly includes register helpers and the SOF memory-map wrapper.
zephyr/​lib/​cpu.c Adds explicit memory-map and platform dependencies.
zephyr/​lib/​alloc.c Adds an explicit platform dependency.
zephyr/​include/​sof/​lib/​dma.h Removes register-access and memory-map includes.
zephyr/​include/​sof/​lib/​dma-legacy.h Includes register helpers for legacy DMA.
zephyr/​include/​rtos/​timer.h Removes the platform-header dependency.
src/​kernel/​platform/​posix/​posix.c Explicitly includes clock definitions.
src/​kernel/​ipc/​ipc3/​host-page-table.c Explicitly includes the memory map.
src/​kernel/​audio/​base_fw_intel.c Adds an explicit platform dependency.
src/​include/​sof/​schedule/​ll_schedule_domain.h Limits the clock include to non-Zephyr builds.
src/​audio/​dai-zephyr.c Explicitly includes memory definitions to preserve address translation.
scripts/​kernel_user_partition.txt Reclassifies the Zephyr DMA header and removes ten baseline entries.

Review effort: Balanced

@intel-sofci

intel-sofci commented Nov 16, 2026 •

Copy link
Copy Markdown

PR 11470: test results

Run date: 2026-11-17 11:24 UTC

Tested commit: 3caff134522bcc5026aa710db1b127fd05be2d53

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

@kv2019i
kv2019i merged commit a615eda into thesofproject:main Nov 17, 2026
45 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.

5 participants