Skip to content

Phase 1 (part 2): stop user-space code depending on the platform memory map and headers - #11345

Draft
lgirdwood wants to merge 6 commits into
thesofproject:mainfrom
lgirdwood:kernel-user/phase1b
Draft

lgirdwood wants to merge 6 commits into
thesofproject:mainfrom
lgirdwood:kernel-user/phase1b

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Phase 1 of #11306 (kernel / user-space partition), second part: stop most user-space code depending on the platform memory map and platform headers. Follows #11330.

Two platform definitions that user-space code needs no longer come from the platform headers:

  • PLATFORM_DCACHE_ALIGN is now defined once in rtos/cache.h from Zephyr's data cache line size (CONFIG_DCACHE_LINE_SIZE).
  • PLATFORM_MAX_CHANNELS is now the Kconfig option CONFIG_PLATFORM_MAX_CHANNELS, with defaults equal to today's values.

Patches

  • sof/lib/cold.h (new): __cold, __cold_rodata and the cold/hot path checks move out of sof/lib/memory.h. The four identical ACE copies of the DRAM section definition become one.
  • PLATFORM_DCACHE_ALIGN from Zephyr: defined in rtos/cache.h from DCACHE_LINE_SIZE, and the per-platform definitions are dropped (the host library keeps its own).
  • CONFIG_PLATFORM_MAX_CHANNELS (new): 4 for the i.MX and MediaTek Zephyr builds, 8 otherwise, and 8 for the host library and unit tests. All users switch to it, except log messages, which keep their text.
  • rtos/alloc.h and rtos/sof.h: include rtos/cache.h instead of the platform memory map.
  • sof/ipc/msg.h: drops its unused sof/platform.h and sof/lib/memory.h includes.
  • Audio code: drops sof/platform.h from the components and headers that no longer use anything from it.

Files that still use something from the headers they no longer get indirectly now include those headers themselves. That covers IDC, the scheduler, logging, PM, the i.MX MU, and copier_dai.c for ACE_VERSION.

Functional change

PLATFORM_DCACHE_ALIGN changes on two sets of platforms; everywhere else it already matched Zephyr's cache line size:

  • i.MX8, i.MX8X, i.MX8M and i.MX8ULP: 32 becomes 128, the cache line size their Zephyr configuration already uses. In these builds the only user is the IPC3 buffer allocation in buffer_new(), which is now 128-byte aligned.
  • qemu_xtensa: sizeof(void *) becomes 32. Nothing in that build uses it.

Apart from this, every patch leaves the generated code unchanged.

Effect

Measured with scripts/check_kernel_includes.py on PTL, as the number of user-space sources including each header:

Header Before After
sof/platform.h 130 15
Platform clock headers / rtos/clk.h 130 20

sof/lib/memory.h is still included by 141 user-space sources, now through sof/coherent.h. coherent.h needs the cached/uncached address helpers, which today are defined per platform. Moving them to the Zephyr cache API would change is_uncached() on platforms without uncached aliases (i.MX, AMD, MTK), where it returns 0 today, so that is left for a separate change.

Testing

  • Per commit: each commit was built on tgl, tgl-h, mtl, lnl, ptl, wcl, nvl, imx8, imx8x, imx8m, imx8m_cm7, imx8ulp, imx95 and qemu_xtensa. It was also built in the extra CI configurations: native_sim IPC3/IPC4 stub builds, imx93 64-bit, and PTL with each userspace overlay. Every object file and LLEXT module was compared with the previous commit. The only differences are the four i.MX8 ipc-helper.c objects described above. The host library and cmocka also build and pass on each commit.
  • At the tip:
    • All cmocka configurations, the testbench and the tools pass.
    • 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.

The per-commit and tip testing was done on 5c4e82e. The branch was then rebased onto cb7af80 (current main, adding the Cadence sink/source rework) and rebuilt in all of the above configurations, plus the host library, cmocka and testbench.

🤖 Generated with Claude Code

lrgirdwo and others added 6 commits October 23, 2026 12:55
__cold, __cold_rodata and the cold/hot path checks are used by most of
the audio code, but they were only available through sof/lib/memory.h,
which also pulls in the whole platform memory map. The DRAM section
variant was defined separately, and identically, in the four ACE
platform memory headers.

Move all of it to a new sof/lib/cold.h for the zephyr and posix RTOS
layers, based on CONFIG_COLD_STORE_EXECUTE_DRAM as before, and include it
from sof/lib/memory.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>
PLATFORM_DCACHE_ALIGN was defined by every platform memory header, so
any code that needed to cache-align a buffer had to include the
platform memory map. Zephyr already describes the data cache line size
with CONFIG_DCACHE_LINE_SIZE, which rtos/cache.h exposes as
DCACHE_LINE_SIZE.

Define PLATFORM_DCACHE_ALIGN once in rtos/cache.h from DCACHE_LINE_SIZE
and drop the per-platform definitions of the Zephyr platforms. The host
library keeps its own definition.

This is the same value on all platforms except:
 - i.MX8, i.MX8X, i.MX8M and i.MX8ULP, which used 32 while their Zephyr
   configuration has a 128 byte cache line. The only user in these
   builds is the IPC3 buffer allocation, which is now 128 byte aligned.
 - qemu_xtensa, which used sizeof(void *) and now uses its 32 byte
   cache line; nothing in that build depends on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
PLATFORM_MAX_CHANNELS is mostly used by audio processing code to size
per-channel state, but it was defined in every platform header, so that
code depended on sof/platform.h and through it on the platform drivers
and memory map.

Add CONFIG_PLATFORM_MAX_CHANNELS with defaults that match the existing
values (4 for the i.MX and MediaTek Zephyr builds, 8 otherwise, and 8
for the host library and unit tests, which used the library platform),
use it everywhere and drop the per-platform definitions. Log messages
keep their text. 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/alloc.h and rtos/sof.h only need PLATFORM_DCACHE_ALIGN, but they
got it from sof/lib/memory.h together with the whole platform memory
map, which made almost all code depend on the platform headers. Include
rtos/cache.h, which now provides it, instead.

Include sof/lib/memory.h, sof/lib/cold.h or sof/lib/cpu.h directly in
the IDC, scheduler, logging, power management and i.MX MU code that
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>
sof/ipc/msg.h uses nothing from sof/platform.h or sof/lib/memory.h, but
including them made most audio code depend on the platform headers.
Drop them.

copier_dai.c relied on msg.h for ACE_VERSION, which selects how ALH
gateways are configured; without it the ACE 2.0+ path would silently
be compiled out. Include sof/platform.h there directly. No functional
change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Most audio components and headers only included sof/platform.h for
PLATFORM_MAX_CHANNELS, which is now CONFIG_PLATFORM_MAX_CHANNELS. Drop
the include from the files that use nothing else from it, so that they
no longer depend on the platform drivers, clocks and memory map. Files
that still use a platform definition (PLATFORM_MAX_STREAMS,
PLATFORM_PRIMARY_CORE_ID, ACE_VERSION, ...) keep it. No functional
change.

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.

🟡 Changes recommended

The unrestricted channel-limit option permits configurations that fail compilation or overrun fixed-size volume arrays.

1 open issue
What changed in this PR

Continues the kernel/user-space separation from #11306 and #11330 by reducing audio code’s dependence on platform headers and memory maps.

Changes:

  • Separates cold-code attributes into dedicated headers and centralizes Zephyr cache alignment.
  • Migrates channel limits to CONFIG_PLATFORM_MAX_CHANNELS, retaining existing platform defaults.
  • Removes unnecessary platform includes and adds explicit dependencies where still needed.
File Description
zephyr/​lib/​pm_runtime.c Adds explicit CPU dependency.
zephyr/​include/​sof/​lib/​memory.h Delegates cache and cold attributes.
zephyr/​include/​sof/​lib/​cold.h Centralizes cold attributes and path checks.
zephyr/​include/​rtos/​sof.h Uses cache header instead of memory map.
zephyr/​include/​rtos/​cache.h Defines platform cache alignment centrally.
zephyr/​include/​rtos/​alloc.h Uses cache header instead of memory map.
tools/​testbench/​utils_ipc4.c Migrates control channel limits.
test/​cmocka/​src/​audio/​mux/​mux_get_processing_function.c Migrates test channel limits.
test/​cmocka/​src/​audio/​mux/​mux_copy.c Migrates mux test arrays and loops.
test/​cmocka/​src/​audio/​mux/​demux_copy.c Migrates demux test arrays and loops.
test/​cmocka/​src/​audio/​dcblock/​dcblock_process.c Migrates filter test channel limits.
src/​schedule/​schedule.c Adds explicit cold-header dependency.
src/​samples/​audio/​smart_amp_test_ipc3.c Migrates channel validation.
src/​platform/​tigerlake/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​qemu_xtensa/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​qemu_xtensa/​include/​platform/​lib/​memory.h Removes local cache alignment.
src/​platform/​posix/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​posix/​include/​platform/​lib/​memory.h Removes local cache alignment.
src/​platform/​novalake/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​novalake/​include/​platform/​lib/​memory.h Removes duplicated cold attributes.
src/​platform/​mtk/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​mtk/​include/​platform/​lib/​memory.h Uses central alignment for cache assertion.
src/​platform/​meteorlake/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​meteorlake/​include/​platform/​lib/​memory.h Removes duplicated cold attributes.
src/​platform/​lunarlake/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​lunarlake/​include/​platform/​lib/​memory.h Removes duplicated cold attributes.
src/​platform/​library/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​Kconfig Defines channel-limit option and defaults.
src/​platform/​intel/​cavs/​include/​cavs/​lib/​memory.h Removes local cache alignment.
src/​platform/​intel/​ace/​include/​ace/​lib/​memory.h Removes local cache alignment.
src/​platform/​imx95/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​imx95/​include/​platform/​lib/​memory.h Removes local cache alignment.
src/​platform/​imx93_a55/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​imx93_a55/​include/​platform/​lib/​memory.h Removes local cache alignment.
src/​platform/​imx8ulp/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​imx8ulp/​include/​platform/​lib/​memory.h Defers alignment to Zephyr cache size.
src/​platform/​imx8m/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​imx8m/​include/​platform/​lib/​memory.h Defers alignment to Zephyr cache size.
src/​platform/​imx8m_cm7/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​imx8m_cm7/​include/​platform/​lib/​memory.h Removes local cache alignment.
src/​platform/​imx8/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​imx8/​include/​platform/​lib/​memory.h Defers alignment to Zephyr cache size.
src/​platform/​amd/​rembrandt/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​amd/​rembrandt/​include/​platform/​lib/​memory.h Removes local cache alignment.
src/​platform/​amd/​acp_7_x/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​amd/​acp_7_x/​include/​platform/​lib/​memory.h Removes local cache alignment.
src/​platform/​amd/​acp_7_0/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​amd/​acp_7_0/​include/​platform/​lib/​memory.h Removes local cache alignment.
src/​platform/​ace30/​include/​platform/​platform.h Removes local channel limit.
src/​platform/​ace30/​include/​platform/​lib/​memory.h Removes duplicated cold attributes.
src/​ipc/​ipc4/​logging.c Adds explicit CPU dependency.
src/​ipc/​ipc-helper.c Removes unnecessary platform include.
src/​include/​user/​smart_amp.h Migrates channel-map dimensions.
src/​include/​user/​eq.h Updates channel-limit names in comments only.
src/​include/​sof/​samples/​audio/​smart_amp_test.h Migrates sample channel-map dimensions.
src/​include/​sof/​ipc/​msg.h Removes unused platform and memory includes.
src/​include/​sof/​drivers/​mu.h Adds explicit memory-map dependency.
src/​include/​sof/​audio/​smart_amp/​smart_amp.h Removes unnecessary platform include.
src/​include/​sof/​audio/​rtnr/​rtnr.h Removes unnecessary platform include.
src/​include/​sof/​audio/​igo_nr/​igo_nr_comp.h Removes unnecessary platform include.
src/​idc/​zephyr_idc.c Adds explicit CPU and memory dependencies.
src/​audio/​volume/​volume.c Migrates reset limit and removes include.
src/​audio/​volume/​volume_riscv.c Migrates temporary channel-array size.
src/​audio/​volume/​volume_riscv_with_peakvol.c Migrates temporary channel-array size.
src/​audio/​volume/​volume_ipc4.c Removes unnecessary platform include.
src/​audio/​volume/​volume_ipc3.c Migrates volume initialization limits.
src/​audio/​volume/​volume_arm.c Migrates temporary channel-array size.
src/​audio/​volume/​volume_arm_with_peakvol.c Migrates temporary channel-array size.
src/​audio/​tone/​tone.h Migrates tone-state array size.
src/​audio/​tone/​tone.c Removes unnecessary platform include.
src/​audio/​tone/​tone-ipc4.c Migrates initialization and reset limits.
src/​audio/​tone/​tone-ipc3.c Migrates channel loops and validation.
src/​audio/​tensorflow/​tflm-classify.c Removes unnecessary platform include.
src/​audio/​template/​template.h Migrates channel-map size.
src/​audio/​tdfb/​tdfb.h Migrates microphone limit.
src/​audio/​tdfb/​tdfb.c Migrates channel validation and state loops.
src/​audio/​tdfb/​tdfb_comp.h Migrates buffers and direction-state arrays.
src/​audio/​stft_process/​stft_process.h Migrates per-channel state dimensions.
src/​audio/​src/​src.c Migrates delay-size limits.
src/​audio/​src/​src_lite.c Migrates delay-size limits.
src/​audio/​src/​src_ipc4.c Removes unnecessary platform include.
src/​audio/​src/​src_ipc3.c Removes unnecessary platform include.
src/​audio/​src/​src_common.c Migrates channel validation.
src/​audio/​sound_dose/​sound_dose.h Migrates per-channel state dimensions.
src/​audio/​rtnr/​rtnr.c Removes unnecessary platform include.
src/​audio/​phase_vocoder/​phase_vocoder.h Migrates per-channel state dimensions.
src/​audio/​mux/​mux.h Migrates lookup and channel-mask dimensions.
src/​audio/​mux/​mux.c Migrates mixing-validation loops.
src/​audio/​mux/​mux_ipc4.c Migrates channel-count validation.
src/​audio/​mux/​mux_ipc3.c Migrates channel-mask loops.
src/​audio/​mux/​mux_generic.c Migrates lookup-generation limits.
src/​audio/​multiband_drc/​multiband_drc.h Migrates per-channel filter state.
src/​audio/​multiband_drc/​multiband_drc.c Migrates reset loops and validation.
src/​audio/​multiband_drc/​multiband_drc_generic.c Migrates buffer sizes and channel strides.
src/​audio/​module_adapter/​module_adapter_ipc4.c Migrates host channel-count validation.
src/​audio/​module_adapter/​module_adapter_ipc3.c Removes unnecessary platform include.
src/​audio/​mixin_mixout/​mixin_mixout.h Removes unnecessary platform include.
src/​audio/​mixin_mixout/​mixin_mixout.c Removes unnecessary platform include.
src/​audio/​mixer/​mixer.h Removes unnecessary platform include.
src/​audio/​mixer/​mixer_hifi3.c Migrates source-pointer array sizes.
src/​audio/​mixer/​mixer_generic.c Migrates source-pointer array sizes.
src/​audio/​mixer/​mixer_arm.c Migrates source-pointer array sizes.
src/​audio/​mfcc/​mfcc.c Removes unnecessary platform include.
src/​audio/​igo_nr/​igo_nr.c Removes unnecessary platform include.
src/​audio/​eq_iir/​eq_iir.h Migrates filter-state array size.
src/​audio/​eq_iir/​eq_iir.c Migrates validation and state-loop limits.
src/​audio/​eq_iir/​eq_iir_riscv.c Removes unnecessary platform include.
src/​audio/​eq_iir/​eq_iir_ipc4.c Removes unnecessary platform include.
src/​audio/​eq_iir/​eq_iir_ipc3.c Removes unnecessary platform include.
src/​audio/​eq_iir/​eq_iir_generic.c Removes unnecessary platform include.
src/​audio/​eq_iir/​eq_iir_arm.c Removes unnecessary platform include.
src/​audio/​eq_fir/​eq_fir.h Migrates filter-state array size.
src/​audio/​eq_fir/​eq_fir.c Migrates validation and state-loop limits.
src/​audio/​drc/​drc.h Migrates per-channel delay-pointer array.
src/​audio/​drc/​drc.c Migrates reset-loop limit.
src/​audio/​drc/​drc_algorithm.h Removes unnecessary platform include.
src/​audio/​dcblock/​dcblock.h Migrates state and coefficient arrays.
src/​audio/​dcblock/​dcblock.c Migrates coefficient initialization limit.
src/​audio/​crossover/​crossover.h Migrates filter-state array size.
src/​audio/​crossover/​crossover.c Migrates reset and validation limits.
src/​audio/​copier/​copier_dai.c Adds explicit platform dependency for ACE_VERSION.
src/​audio/​asrc/​asrc.h Migrates channel-pointer array sizes.
src/​audio/​asrc/​asrc.c Removes unnecessary platform include.
posix/​include/​sof/​lib/​memory.h Delegates cold attributes to dedicated header.
posix/​include/​sof/​lib/​cold.h Separates host cold-attribute stubs.

Review effort: Balanced

Comment thread src/platform/Kconfig
endif # !ZEPHYR_SOF_MODULE

config PLATFORM_MAX_CHANNELS
int "Maximum number of audio channels"
@harajend

Copy link
Copy Markdown

CI failure analysis for build ptl release signed (run https://github.com/intel-innersource/drivers.audio.ci.sof/actions/runs/39953073653/job/120412305455):

Compile fails with 4 errors in src/schedule/zephyr_dp_schedule_application.c:

src/schedule/zephyr_dp_schedule_application.c:661:58: error: use of undeclared identifier 'MAILBOX_HOSTBOX_BASE'
src/schedule/zephyr_dp_schedule_application.c:662:11: error: use of undeclared identifier 'MAILBOX_HOSTBOX_SIZE'
src/schedule/zephyr_dp_schedule_application.c:666:23: error: use of undeclared identifier 'MAILBOX_HOSTBOX_BASE'
src/schedule/zephyr_dp_schedule_application.c:667:11: error: use of undeclared identifier 'MAILBOX_HOSTBOX_SIZE'
4 errors generated.

Build target: ptl (Panther Lake, ACE 3.0) - west build --board intel_adsp/ace30/ptl ... -DEXTRA_CONF_FILE=os_linux_overlay.conf;llext_relocatable.conf.

MAILBOX_HOSTBOX_BASE/MAILBOX_HOSTBOX_SIZE aren't declared/visible for this build config - likely a missing include for the header defining them, or a conditional guard in zephyr_dp_schedule_application.c that doesn't cover the ptl/ACE 3.0 platform path. Other platforms (mtl/lnl/etc.) built successfully in the same run, so this looks specific to ptl.

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