Skip to content

zephyr: call the Zephyr cache API directly in kernel-only code - #11571

Open
lgirdwood wants to merge 1 commit into
thesofproject:mainfrom
lgirdwood:topic/zn-rtos-cache-kernel
Open

lgirdwood wants to merge 1 commit into
thesofproject:mainfrom
lgirdwood:topic/zn-rtos-cache-kernel

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Call the Zephyr cache API directly in the code that only Zephyr builds. Part of #11517 (step 2, "Kernel-only code: switch to Zephyr APIs directly").

Changes

dcache_writeback_region(), dcache_invalidate_region() and icache_invalidate_region() are inline wrappers of sys_cache_data_flush_range(), sys_cache_data_invd_range() and sys_cache_instr_invd_range(). Their callers in Zephyr-only code now call the Zephyr functions directly:

  • the library and LLEXT managers;
  • the probes;
  • firmware init (lp_sram_unpack());
  • the cAVS IMR layout update;
  • the L3 heap save;
  • fast-get.

The callers used to cast to __sparse_cache only to match the wrapper prototypes. Pointers that really are __sparse_cache keep a __sparse_force cast, integer addresses get a plain (void *) cast, and other pointers are passed as they are.

Not in this PR

  • Shared code (coherent.h, audio_stream.h, the buffers, the mailbox, IPC): it also builds on the host, so it keeps the wrappers until the host has a <zephyr/cache.h> stub.
  • uncache_to_cache(), cache_to_uncache() and is_uncached(): cAVS uses its own address alias arithmetic for these, so they need a Zephyr change and a TGL test first.

Functional change

None. With one inline function less, GCC allocates registers and lays out branches differently in a few of the callers, such as the probe buffer copies and fast_get().

Testing

  • Builds: tested with the other three PRs of this series (zephyr: use the Zephyr time and delay calls directly #11570, zephyr: use the Zephyr assert and panic macros in kernel-only code #11572 and zephyr: remove unused interrupt and debug linkage stubs #11573) stacked on main (7cff357), each commit built incrementally and the tip from scratch, and compared with main: tgl, tgl-h, mtl, lnl, ptl, wcl, nvl, nvl-s, imx8, imx8x, imx8m, imx8m_cm7, imx8ulp, imx93, imx95, qemu_xtensa, qemu_xtensa_mmu, native_sim, and the PTL userspace, LL-userspace and LLEXT, MTL LLEXT, TGL/PTL debug-stream and TGL/MTL/LNL/PTL CI overlay configurations.
  • Objects: every object hashed with the debug sections stripped. The changed objects are the edited files above, plus the objects that embed the git version; their disassembly was compared function by function.
  • Platforms that already fail on main (acp_6_0, acp_7_0, acp_7_x, mt8186, mt8188, mt8195, mt8196, mt8365, phyboard): same error sets.
  • Cadence xt-clang: MTL, PTL and NVL compile.
  • ZTest: 37 of 37 configurations pass, run as in CI.
  • Host: the host library builds.

🤖 Generated with Claude Code

dcache_writeback_region(), dcache_invalidate_region() and
icache_invalidate_region() are inline wrappers of
sys_cache_data_flush_range(), sys_cache_data_invd_range() and
sys_cache_instr_invd_range(). Call the Zephyr functions directly in the
code that only Zephyr builds: the library and LLEXT managers, the
probes, firmware init, the cAVS IMR layout update, the L3 heap save and
fast-get.

The callers used to cast their pointers to __sparse_cache only to match
the wrapper prototypes. Pointers that really are __sparse_cache keep a
__sparse_force cast, integer addresses get a plain (void *) cast, and
other pointers are passed as they are.

The shared code also builds on the host, so it keeps the wrappers until
the host has a <zephyr/cache.h> stub.

No functional change. With one inline function less, GCC allocates
registers and lays out branches differently in a few of the callers,
such as the probe buffer copies and fast_get().

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 remain for the migration to native Zephyr cache APIs.

No open issues 🎉

What changed in this PR

This PR advances #11517’s migration to native Zephyr APIs by replacing SOF cache wrappers in Zephyr-only code. Shared, host-built code retains the wrappers; no functional change is intended.

Changes:

  • Replace cache writeback and invalidation wrappers with direct Zephyr cache calls.
  • Simplify pointer casts while preserving required sparse address-space conversions.
  • Add Zephyr cache headers where needed.
File Description
zephyr/​lib/​fast-get.c Use direct cache calls for fast-memory access and copies.
zephyr/​lib/​alloc.c Flush saved L3 heap state through Zephyr.
src/​kernel/​probe/​probe.c Use Zephyr cache calls for probe buffers and headers.
src/​kernel/​platform/​intel/​cavs/​platform.c Use Zephyr cache calls when updating the IMR layout.
src/​kernel/​library_manager/​llext_manager.c Replace data and instruction cache wrappers during extension loading.
src/​kernel/​library_manager/​llext_manager_dram.c Flush saved library state through Zephyr.
src/​kernel/​library_manager/​lib_manager.c Use direct cache flushes when loading and storing libraries.
src/​kernel/​init/​init.c Flush unpacked LP SRAM data through Zephyr.

Review effort: Balanced

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.

3 participants