Skip to content

Phase 1: stop user-facing headers pulling in kernel-only headers - #11330

Merged
lgirdwood merged 10 commits into
thesofproject:mainfrom
lgirdwood:kernel-user/phase1
Oct 22, 2026
Merged

lgirdwood merged 10 commits into
thesofproject:mainfrom
lgirdwood:kernel-user/phase1

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Phase 1 of #11306 (kernel / user-space partition), first part: header hygiene. User-facing headers stop pulling in kernel-only headers they don't need. No functional change.

Each patch either removes an include that isn't used, or moves a definition to a smaller header, so that its users no longer get the rest of a kernel-only header. When a file did use something it only got transitively, it now includes the header directly. That makes the remaining kernel dependencies of user-space code explicit.

Patches

  • sof/trace/trace.h: no longer includes the platform trace header; only the sof-logger backend needs it, and that backend already includes it.

  • struct perf_cnt_data: moved to sof/lib/perf_cnt_data.h, so rtos/task.h no longer pulls in rtos/timer.h.

  • rtos/userspace_data.h (new): the APP_TASK_*/APP_SYSUSER_* data placement attributes, split out of rtos/userspace_helper.h (zephyr and posix).

  • component.h:

    • drops rtos/idc.h and rtos/userspace_helper.h;
    • drops sof/lib/dai.h and sof/schedule/schedule.h, using forward declarations instead.

    component_ext.h keeps the IDC, DAI and scheduler includes, because its cross-core and DAI helpers use them. They are marked as kernel dependencies to move out later.

  • pipeline.h: drops the unused sof/lib/mailbox.h; the mailbox users include it directly.

  • sof/ipc/topology.h: drops the unused sof/platform.h and sof/lib/memory.h.

  • audio_stream_sync_to_hw(): moved to sof/audio/audio_stream_hw.h, so audio_stream.h no longer includes sof/lib/dma.h and the Zephyr DMA API.

  • Unused includes: a few kernel-only includes removed from audio and IPC sources.

  • scripts/kernel_user_partition.txt: rtos/init.h (SOF_MODULE_INIT()) is no longer reported as kernel-only.

Effect, measured with scripts/check_kernel_includes.py on PTL (number of user-space sources including each header):

Header Before After
zephyr/drivers/dma.h, sof/lib/io.h 145 27
sof/lib/mailbox.h 141 20
rtos/timer.h 139 10
rtos/userspace_helper.h 136 10
rtos/idc.h 135 26

Not in this PR (Phase 1 continued)

  • Memory map, and the platform.h/clock headers behind it: rtos/alloc.h includes sof/lib/memory.h only for PLATFORM_DCACHE_ALIGN, but that pulls in the platform memory map and, through it, sof/platform.h and the clock headers. That accounts for most of what the checker still reports. Fixing it needs a small user-safe alignment header per platform, because the values differ (32, 64, 128 or DCACHE_LINE_SIZE).
  • Mixed headers: split component_ext.h (cross-core IDC helpers), sof/lib/dma.h, dai-zephyr.h and the scheduler headers.
  • Real kernel dependencies in user-space code:
    • IRQ locking in the pipeline and copier;
    • wallclock / cycle counter;
    • system agent;
    • KCPS clock manager;
    • KPB power management;
    • PLATFORM_MAX_CHANNELS;
    • DMIC constants.

Testing

  • Per commit: every commit was built on tgl, tgl-h, mtl, lnl, ptl, wcl, nvl, imx8, imx8x, imx8m, imx8m_cm7, imx8ulp, imx95 and qemu_xtensa. Every object file and LLEXT module has identical non-debug sections to the previous commit. The one exception is the audio_stream_sync_to_hw() move: on qemu_xtensa, the only one of these with assertions enabled, the file name and line in its assertions change in host-zephyr.c and dai-zephyr.c.
  • Host: the host library and cmocka build and pass on each commit.
  • Extra configurations, per commit: the native_sim IPC3 and IPC4 stub builds (stub_build_all_ipc*.conf), the imx93 64-bit build, and PTL with the userspace_overlay.conf and ll_userspace_overlay.conf overlays all build on each commit.
  • At the tip:
    • Firmware: all 14 platforms that build on main have identical firmware apart from that assertion text, and the LLEXT modules are identical.
    • Host tools: testbench, tools and all cmocka configurations pass.
    • Platforms that already fail on main (acp_6_0, acp_7_0, acp_7_x, mt8186, mt8188, mt8195, mt8196, mt8365): their error sets are unchanged. acp_7_0 now needs an acp_dmic_dma devicetree node that the pinned Zephyr does not have.

All of the above was run on 7ea6847 (current main).

🤖 Generated with Claude Code

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.

🟡 Changes recommended

The application-mode DP scheduler needs direct helper and scheduler includes to preserve compilation after the header cleanup.

1 open issue
What changed in this PR

This PR prepares SOF’s kernel/userspace separation by reducing kernel-header dependencies in user-facing APIs without intended functional changes.

Changes:

  • Extract data-placement attributes, performance-counter data, and DMA stream helpers into separate headers.
  • Replace transitive dependencies with direct includes where needed.
  • Remove unused includes and update kernel-header classification.
File Description
zephyr/​lib/​cpu.c Adds direct DAI dependency.
zephyr/​include/​rtos/​userspace_helper.h Uses extracted placement attributes.
zephyr/​include/​rtos/​userspace_data.h Defines Zephyr placement attributes.
zephyr/​include/​rtos/​task.h Includes counter data without timer helpers.
zephyr/​edf_schedule.c Adds direct scheduler dependency.
tools/​testbench/​utils.c Adds direct scheduler dependency.
tools/​testbench/​file.c Adds direct DAI dependency.
src/​schedule/​zephyr_dp_schedule.c Adds direct scheduler dependency.
src/​schedule/​zephyr_dp_schedule_thread.c Adds helper and scheduler dependencies.
src/​schedule/​schedule.c Adds direct CPU dependency.
src/​platform/​mtk/​platform.c Adds direct DMA dependency.
src/​platform/​library/​schedule/​schedule.c Adds direct scheduler dependency.
src/​platform/​library/​schedule/​edf_schedule.c Adds direct scheduler dependency.
src/​platform/​intel/​ace/​platform.c Adds IDC and DMA dependencies.
src/​platform/​imx95/​platform.c Adds direct mailbox dependency.
src/​platform/​imx8m_cm7/​platform.c Adds direct mailbox dependency.
src/​platform/​imx8/​platform.c Adds mailbox and platform dependencies.
src/​library_manager/​lib_manager.c Adds direct timer dependency.
src/​ipc/​ipc4/​dai.c Adds mailbox and timer dependencies.
src/​ipc/​ipc3/​dai.c Adds direct mailbox dependency.
src/​ipc/​ipc-helper.c Removes unused driver include.
src/​include/​sof/​trace/​trace.h Removes platform trace dependency.
src/​include/​sof/​lib/​perf_cnt.h Uses extracted counter structure.
src/​include/​sof/​lib/​perf_cnt_data.h Defines standalone counter data.
src/​include/​sof/​ipc/​topology.h Removes unnecessary kernel includes.
src/​include/​sof/​audio/​pipeline.h Removes mailbox dependency.
src/​include/​sof/​audio/​component.h Reduces transitive kernel dependencies.
src/​include/​sof/​audio/​component_ext.h Keeps dependencies needed by extended helpers.
src/​include/​sof/​audio/​audio_stream.h Removes DMA dependency and hardware helper.
src/​include/​sof/​audio/​audio_stream_hw.h Houses DMA stream synchronization helper.
src/​drivers/​amd/​rembrandt/​acp_hs_dai.c Adds direct register dependency.
src/​audio/​volume/​volume.h Adds direct mailbox dependency.
src/​audio/​pipeline/​pipeline-xrun.c Adds mailbox and timer dependencies.
src/​audio/​pipeline/​pipeline-params.c Removes unused heap include.
src/​audio/​pipeline/​pipeline-graph.c Adds direct mailbox dependency.
src/​audio/​module_adapter/​module/​generic.c Adds direct scheduler dependency.
src/​audio/​module_adapter/​module/​dolby/​dax.h Adds direct atomic dependency.
src/​audio/​module_adapter/​module_adapter.c Adds scheduler include; removes interrupt include.
src/​audio/​module_adapter/​library/​userspace_proxy.c Adds direct mailbox dependency.
src/​audio/​host-zephyr.c Includes relocated DMA stream helper.
src/​audio/​data_blob.c Adds direct mailbox dependency.
src/​audio/​dai-zephyr.c Includes relocated DMA stream helper.
src/​audio/​copier/​copier.c Adds direct mailbox dependency.
src/​audio/​copier/​copier_ipcgtw.c Replaces unused initialization include with mailbox include.
src/​audio/​copier/​copier_host.c Adds direct mailbox dependency.
src/​audio/​component.c Explicitly includes counter helpers.
src/​audio/​buffers/​comp_buffer.c Removes unused interrupt include.
src/​audio/​base_fw.c Makes kernel dependencies explicit.
src/​audio/​base_fw_intel.c Adds direct timer dependency.
src/​audio/​asrc/​asrc.c Adds direct DAI dependency.
src/​audio/​asrc/​asrc_farrow.c Removes unused platform include.
scripts/​kernel_user_partition.txt Stops classifying initialization header as kernel-only.
posix/​include/​rtos/​userspace_helper.h Uses extracted placement attributes.
posix/​include/​rtos/​userspace_data.h Defines no-op POSIX placement attributes.

Review effort: Balanced

Comment thread src/include/sof/audio/component.h

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues

Review effort: Lite

Comment thread src/include/sof/audio/audio_stream_hw.h
lrgirdwo and others added 10 commits October 22, 2026 14:51
<platform/trace/trace.h> only provides platform_trace_point(), which is
used by the trace_point() macro of the sof-logger backend. That backend
(trace-soflogger.h) already includes the platform header itself, and
without CONFIG_TRACE trace_point() is a no-op defined in trace.h.

Including it from trace.h made every user of the logging API depend on
the platform headers, and through them on the platform memory map and
mailbox. Drop the include. No functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
struct task embeds struct perf_cnt_data, so zephyr's rtos/task.h
included sof/lib/perf_cnt.h, and with it rtos/timer.h and the platform
timer headers. Every user of the scheduler or component API therefore
depended on the timer driver headers.

Move the plain data structure to sof/lib/perf_cnt_data.h, include that
from rtos/task.h, and include sof/lib/perf_cnt.h directly where the
counter helpers are used. 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/userspace_helper.h mixes two things: the APP_TASK_* and APP_SYSUSER_*
attributes that place data in the memory partitions user-space threads
can access, and the kernel helpers that create heaps, stacks and memory
domain grants. User-space code needs the former and must not depend on
the latter.

Move the placement attributes to a new rtos/userspace_data.h, for both
the zephyr and posix RTOS layers, and include it from
rtos/userspace_helper.h so existing users are unaffected. No functional
change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
component.h included rtos/idc.h and rtos/userspace_helper.h, which made
every component depend on the IDC and memory domain headers. Components
only need the user data placement attributes, so include
rtos/userspace_data.h instead.

The only user of the IDC definitions in the component API is
component_ext.h, whose cross-core helpers build and send IDC messages;
include rtos/idc.h there instead, marked as a kernel dependency to be
moved out of the component API later. Include rtos/idc.h and
rtos/userspace_helper.h directly in the kernel files that relied on
component.h for them. No functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
pipeline.h does not use anything from sof/lib/mailbox.h, but including it
made every user of the pipeline or component API depend on the platform
mailbox and memory map definitions.

Drop the include and include sof/lib/mailbox.h directly in the files that
access the mailbox, host box or software registers. No functional
change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
sof/ipc/topology.h uses nothing from sof/platform.h or sof/lib/memory.h,
but including them made most of the audio code depend on the platform
headers. Drop them and include sof/platform.h and sof/lib/mailbox.h
directly in the i.MX8 platform code, which relied on them. No functional
change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
audio_stream_sync_to_hw() reads a Zephyr struct dma_status, so
audio_stream.h included sof/lib/dma.h and with it the Zephyr DMA driver
API and the SOF DMA definitions. Only the host and DAI components use
this helper.

Move it to sof/audio/audio_stream_hw.h, still only defined for Zephyr
builds as before, include that from host-zephyr.c and dai-zephyr.c, and
drop sof/lib/dma.h from audio_stream.h. The only change in the generated
code is the file name and line reported by the helper's assertions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
component.h only needs struct dai_data and struct task as opaque types,
but it included sof/lib/dai.h and sof/schedule/schedule.h, and with them
the Zephyr DAI and DMA driver APIs and the scheduler internals. Every
component and module therefore depended on them.

Forward declare the two structures instead. component_ext.h does call
dai_config() and schedule_task(), so it includes the two headers itself,
and the files that relied on component.h for the DAI, DMA or scheduler
definitions now include them directly. Also include rtos/atomic.h in the
Dolby DAX module header, which uses atomic_t. No functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Drop includes of kernel-only headers that the files do not use:
rtos/interrupt.h in comp_buffer.c and module_adapter.c, rtos/init.h in
copier_ipcgtw.c, sof/lib/mm_heap.h in pipeline-params.c, sof/platform.h
in asrc_farrow.c and sof/ipc/driver.h in ipc-helper.c. 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/init.h only provides SOF_MODULE_INIT(), the hook every audio module
uses to register its driver. It is part of the module API rather than a
kernel-only interface, so stop reporting it as a kernel-only include.

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

Copy link
Copy Markdown

PR 11330: test results

Run date: 2026-10-22 15:53 UTC

Tested commit: 5a7b58a05d9963717330110ffc32b8c96f791130

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

@lgirdwood

Copy link
Copy Markdown
Member Author

The earlier simple-IPC-fuzz_sh (4) failure on 5a7b58a is not caused by this PR. The crash input it produced (crash-57c17c09...) fails with the same ASSERTION FAIL [!dsp_write_err] in mailbox.h when replayed against an unmodified main build. That is the IPC4 large-config reply-size bug fixed by #11239. The fuzzer starts from random inputs, so it hits this only intermittently; the re-run passed.

@lgirdwood
lgirdwood merged commit be494ec into thesofproject:main Oct 22, 2026
45 of 46 checks passed
@lgirdwood
lgirdwood deleted the kernel-user/phase1 branch October 22, 2026 17:47
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.

4 participants