From e2747137a0d0f826f1d592e7bbdf70b7a2398444 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Wed, 4 Nov 2026 12:06:01 +0000 Subject: [PATCH 01/12] library_manager: move src/library_manager to src/kernel/library_manager The library manager loads and links library and LLEXT modules and holds the kernel half of the lib_manager_free_module() system call. None of it runs in a user thread. Move it to src/kernel/library_manager, where it is built into the sof_kernel library. Source its Kconfig from src/kernel/Kconfig instead of src/Kconfig; the option values are unchanged. In the user-space README, list it with the kernel-only directories and update the path in the system call table. Only Zephyr builds the library manager, so the host builds are not affected. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/Kconfig | 2 -- src/include/sof/userspace/README.md | 6 +++--- src/kernel/CMakeLists.txt | 1 + src/kernel/Kconfig | 2 ++ src/{ => kernel}/library_manager/CMakeLists.txt | 0 src/{ => kernel}/library_manager/Kconfig | 0 src/{ => kernel}/library_manager/lib_manager.c | 0 src/{ => kernel}/library_manager/lib_notification.c | 0 src/{ => kernel}/library_manager/llext_manager.c | 0 src/{ => kernel}/library_manager/llext_manager_dram.c | 0 zephyr/CMakeLists.txt | 1 - 11 files changed, 6 insertions(+), 6 deletions(-) rename src/{ => kernel}/library_manager/CMakeLists.txt (100%) rename src/{ => kernel}/library_manager/Kconfig (100%) rename src/{ => kernel}/library_manager/lib_manager.c (100%) rename src/{ => kernel}/library_manager/lib_notification.c (100%) rename src/{ => kernel}/library_manager/llext_manager.c (100%) rename src/{ => kernel}/library_manager/llext_manager_dram.c (100%) diff --git a/src/Kconfig b/src/Kconfig index 75abdaa6c096..3022dfbff479 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -23,8 +23,6 @@ rsource "ipc/Kconfig" rsource "math/Kconfig" -rsource "library_manager/Kconfig" - rsource "debug/telemetry/Kconfig" rsource "debug/debug_stream/Kconfig" diff --git a/src/include/sof/userspace/README.md b/src/include/sof/userspace/README.md index ac26aa07ab6d..b9ba4a9169dc 100644 --- a/src/include/sof/userspace/README.md +++ b/src/include/sof/userspace/README.md @@ -74,8 +74,8 @@ its subdirectories span all tiers. | Tier | Meaning | Directories | |------|---------|-------------| -| **Kernel-only** | OS integration, HAL, boot, inter-core. Never executes in a user thread. Must not be reached directly from user code — only via a syscall. | `kernel/` (`kernel/idc/`, `kernel/init/`), `arch/`, `drivers/`, `platform/`, `probe/` *, `logging/` *, `trace/` * | -| **Boundary / bridge** | Owns the syscalls and the thread / memory-domain setup. Split internally: some translation units run kernel-side, some user-side (e.g. `handler-kernel.c` vs `handler-user.c`, `zephyr_ll.c` vs `zephyr_ll_user.c`). | `schedule/`, `ipc/`, `library_manager/` *, `debug/debug_stream/` *, and (in the Zephyr integration tree) `zephyr/syscall/` | +| **Kernel-only** | OS integration, HAL, boot, inter-core. Never executes in a user thread. Must not be reached directly from user code — only via a syscall. | `kernel/` (`kernel/idc/`, `kernel/init/`, `kernel/library_manager/`), `arch/`, `drivers/`, `platform/`, `probe/` *, `logging/` *, `trace/` * | +| **Boundary / bridge** | Owns the syscalls and the thread / memory-domain setup. Split internally: some translation units run kernel-side, some user-side (e.g. `handler-kernel.c` vs `handler-user.c`, `zephyr_ll.c` vs `zephyr_ll_user.c`). | `schedule/`, `ipc/`, `debug/debug_stream/` *, and (in the Zephyr integration tree) `zephyr/syscall/` | | **Application** | Audio pipeline / component logic that runs in user threads under userspace configs. | `audio/` | | **Shared library** | Context-agnostic code linked into whichever context calls it. Must stay "user-safe": no privileged operations (no direct MMIO, no spinlocks held across syscalls, no raw kernel object access) so it is safe when pulled into a user build. | `math/`, `module/` | | **Mixed** | A directory whose files span more than one tier; see its own README for per-file classification. | `lib/` | @@ -123,7 +123,7 @@ syscall by subsystem: | DAI | `dai_get_device` | `sof/lib/dai-zephyr.h` | `zephyr/syscall/dai.c` / `lib/dai.c` | | CPU | `cpu_get_id` | `sof/lib/cpu.h` | `zephyr/syscall/cpu.c` / `zephyr/lib/cpu.c` | | Module management | `mod_balloc_align`, `mod_alloc_ext`, `mod_free`, `mod_free_all`, `mod_data_blob_handler_new`, `mod_fast_get` | `sof/audio/module_adapter/module/generic.h` | scattered: `audio/module_adapter/module/generic.c` | -| Library manager | `lib_manager_free_module` | `sof/lib_manager.h` | scattered: `library_manager/lib_manager.c` | +| Library manager | `lib_manager_free_module` | `sof/lib_manager.h` | scattered: `kernel/library_manager/lib_manager.c` | | Scheduling | `zephyr_ll_task_sem_alloc`, `zephyr_ll_task_sem_free`, `scheduler_dp_internal_free`, `scheduler_dp_ll_tick` | `sof/schedule/ll_schedule_domain.h`, `sof/schedule/dp_schedule.h` | scattered: `schedule/zephyr_ll.c`, `schedule/zephyr_dp_schedule*.c` | | Debug | `debug_stream_slot_send_record` | `user/debug_stream_slot.h` | scattered: `debug/debug_stream/debug_stream_slot.c` | diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 1cd295617aad..d1737be47521 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -12,3 +12,4 @@ endif() add_subdirectory(idc) add_subdirectory(init) +add_subdirectory(library_manager) diff --git a/src/kernel/Kconfig b/src/kernel/Kconfig index 4378b4d74d0b..b61161f9d34d 100644 --- a/src/kernel/Kconfig +++ b/src/kernel/Kconfig @@ -3,3 +3,5 @@ # Code that only runs in kernel mode, see scripts/kernel_user_partition.txt. rsource "idc/Kconfig" + +rsource "library_manager/Kconfig" diff --git a/src/library_manager/CMakeLists.txt b/src/kernel/library_manager/CMakeLists.txt similarity index 100% rename from src/library_manager/CMakeLists.txt rename to src/kernel/library_manager/CMakeLists.txt diff --git a/src/library_manager/Kconfig b/src/kernel/library_manager/Kconfig similarity index 100% rename from src/library_manager/Kconfig rename to src/kernel/library_manager/Kconfig diff --git a/src/library_manager/lib_manager.c b/src/kernel/library_manager/lib_manager.c similarity index 100% rename from src/library_manager/lib_manager.c rename to src/kernel/library_manager/lib_manager.c diff --git a/src/library_manager/lib_notification.c b/src/kernel/library_manager/lib_notification.c similarity index 100% rename from src/library_manager/lib_notification.c rename to src/kernel/library_manager/lib_notification.c diff --git a/src/library_manager/llext_manager.c b/src/kernel/library_manager/llext_manager.c similarity index 100% rename from src/library_manager/llext_manager.c rename to src/kernel/library_manager/llext_manager.c diff --git a/src/library_manager/llext_manager_dram.c b/src/kernel/library_manager/llext_manager_dram.c similarity index 100% rename from src/library_manager/llext_manager_dram.c rename to src/kernel/library_manager/llext_manager_dram.c diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index f471aea8e0b7..0597a89912bb 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -240,7 +240,6 @@ add_subdirectory(../src/debug/ debug_unused_install/) add_subdirectory(../src/ipc/ ipc_unused_install/) add_subdirectory(../src/kernel/ kernel_unused_install/) add_subdirectory(../src/lib/ lib_unused_install/) -add_subdirectory(../src/library_manager/ library_manager_unused_install/) add_subdirectory(../src/logging/ logging_unused_install/) add_subdirectory(../src/probe/ probes_unused_install/) add_subdirectory(../src/samples/ samples_unused_install/) From f50b77018680dbe7c2365d856a25c51dfd637d0f Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Fri, 6 Nov 2026 12:43:53 +0000 Subject: [PATCH 02/12] kernel: add a README for src/kernel Describe src/kernel: what belongs there, that moved code keeps its path below src/kernel, and that Zephyr builds it into the sof_kernel library. The README carries the "Runs in: Kernel-only" banner, so moved directories without a README of their own are covered by it. Point the user-space README's directory table at it instead of listing each kernel subdirectory. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/include/sof/userspace/README.md | 2 +- src/kernel/README.md | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/kernel/README.md diff --git a/src/include/sof/userspace/README.md b/src/include/sof/userspace/README.md index b9ba4a9169dc..679d48c8a303 100644 --- a/src/include/sof/userspace/README.md +++ b/src/include/sof/userspace/README.md @@ -74,7 +74,7 @@ its subdirectories span all tiers. | Tier | Meaning | Directories | |------|---------|-------------| -| **Kernel-only** | OS integration, HAL, boot, inter-core. Never executes in a user thread. Must not be reached directly from user code — only via a syscall. | `kernel/` (`kernel/idc/`, `kernel/init/`, `kernel/library_manager/`), `arch/`, `drivers/`, `platform/`, `probe/` *, `logging/` *, `trace/` * | +| **Kernel-only** | OS integration, HAL, boot, inter-core. Never executes in a user thread. Must not be reached directly from user code — only via a syscall. | `kernel/` (see [its README](../../../kernel/README.md)), `arch/`, `drivers/`, `platform/`, `probe/` *, `logging/` *, `trace/` * | | **Boundary / bridge** | Owns the syscalls and the thread / memory-domain setup. Split internally: some translation units run kernel-side, some user-side (e.g. `handler-kernel.c` vs `handler-user.c`, `zephyr_ll.c` vs `zephyr_ll_user.c`). | `schedule/`, `ipc/`, `debug/debug_stream/` *, and (in the Zephyr integration tree) `zephyr/syscall/` | | **Application** | Audio pipeline / component logic that runs in user threads under userspace configs. | `audio/` | | **Shared library** | Context-agnostic code linked into whichever context calls it. Must stay "user-safe": no privileged operations (no direct MMIO, no spinlocks held across syscalls, no raw kernel object access) so it is safe when pulled into a user build. | `math/`, `module/` | diff --git a/src/kernel/README.md b/src/kernel/README.md new file mode 100644 index 000000000000..fd92a6369716 --- /dev/null +++ b/src/kernel/README.md @@ -0,0 +1,28 @@ +# Kernel-only code (`src/kernel`) + +> **Runs in:** Kernel-only — everything here runs in supervisor context and never executes in +> a user thread. User code reaches it only through system calls. See +> [User/kernel split](../include/sof/userspace/README.md). + +This directory collects the SOF code that only runs in kernel mode: OS, hardware and +memory-domain facing code such as boot and initialization, inter-core communication and +module loading. Kernel-only code elsewhere in `src/` moves here one subsystem at a time as part +of the kernel / user-space partition. + +## Layout + +Each subdirectory keeps the path the code had under `src/`, so `src/` moves to +`src/kernel/`. For example `src/audio/base_fw.c` becomes `src/kernel/audio/base_fw.c`. +When only some files of a directory are kernel-only, only those files move, and the rest of +the directory stays where it is. + +## Build + +Zephyr builds everything below this directory into the `sof_kernel` library instead of +`modules_sof`. [`CMakeLists.txt`](CMakeLists.txt) makes `sof_kernel` the current Zephyr +library for this directory tree, so the CMake files of moved directories do not change. Their +Kconfig files are sourced from [`Kconfig`](Kconfig). + +Code here may use kernel-only headers. User-space code must not call into it directly; the +checker in `scripts/check_kernel_includes.py` reports kernel-only includes from user-space +sources. From 7d188e8825d0741ed6e83221227c7b567c9a6918 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Fri, 6 Nov 2026 12:44:11 +0000 Subject: [PATCH 03/12] logging: move src/logging to src/kernel/logging The SOF probe log backend registers a Zephyr logging backend and runs in kernel mode. Move it to src/kernel/logging, where it is built into the sof_kernel library, and drop it from the not-yet-moved kernel-only directories in the docs. Only Zephyr builds it. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- AGENTS.md | 2 +- src/include/sof/userspace/README.md | 2 +- src/kernel/CMakeLists.txt | 1 + src/{ => kernel}/logging/CMakeLists.txt | 0 src/{ => kernel}/logging/log_backend_probe.c | 0 zephyr/CMakeLists.txt | 1 - 6 files changed, 3 insertions(+), 3 deletions(-) rename src/{ => kernel}/logging/CMakeLists.txt (100%) rename src/{ => kernel}/logging/log_backend_probe.c (100%) diff --git a/AGENTS.md b/AGENTS.md index 3b16ba4d7ac1..8d167bd80067 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -31,7 +31,7 @@ moving code, follow it: * **Place code in the right tier.** OS/HAL/boot/inter-core → a kernel-only directory (`kernel/`, which is built into the `sof_kernel` library, and the directories not yet - moved there: `arch/`, `drivers/`, `platform/`, `probe/`, `logging/`, `trace/`); audio + moved there: `arch/`, `drivers/`, `platform/`, `probe/`, `trace/`); audio application logic → `audio/`; reusable pure code → a shared-library directory (`lib/`, `math/`, `module/`) kept free of privileged operations. Each top-level directory's `README.md` states its tier in a "Runs in:" banner — keep it accurate. diff --git a/src/include/sof/userspace/README.md b/src/include/sof/userspace/README.md index 679d48c8a303..8a0346238cd3 100644 --- a/src/include/sof/userspace/README.md +++ b/src/include/sof/userspace/README.md @@ -74,7 +74,7 @@ its subdirectories span all tiers. | Tier | Meaning | Directories | |------|---------|-------------| -| **Kernel-only** | OS integration, HAL, boot, inter-core. Never executes in a user thread. Must not be reached directly from user code — only via a syscall. | `kernel/` (see [its README](../../../kernel/README.md)), `arch/`, `drivers/`, `platform/`, `probe/` *, `logging/` *, `trace/` * | +| **Kernel-only** | OS integration, HAL, boot, inter-core. Never executes in a user thread. Must not be reached directly from user code — only via a syscall. | `kernel/` (see [its README](../../../kernel/README.md)), `arch/`, `drivers/`, `platform/`, `probe/` *, `trace/` * | | **Boundary / bridge** | Owns the syscalls and the thread / memory-domain setup. Split internally: some translation units run kernel-side, some user-side (e.g. `handler-kernel.c` vs `handler-user.c`, `zephyr_ll.c` vs `zephyr_ll_user.c`). | `schedule/`, `ipc/`, `debug/debug_stream/` *, and (in the Zephyr integration tree) `zephyr/syscall/` | | **Application** | Audio pipeline / component logic that runs in user threads under userspace configs. | `audio/` | | **Shared library** | Context-agnostic code linked into whichever context calls it. Must stay "user-safe": no privileged operations (no direct MMIO, no spinlocks held across syscalls, no raw kernel object access) so it is safe when pulled into a user build. | `math/`, `module/` | diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index d1737be47521..1ad38f07148a 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -13,3 +13,4 @@ endif() add_subdirectory(idc) add_subdirectory(init) add_subdirectory(library_manager) +add_subdirectory(logging) diff --git a/src/logging/CMakeLists.txt b/src/kernel/logging/CMakeLists.txt similarity index 100% rename from src/logging/CMakeLists.txt rename to src/kernel/logging/CMakeLists.txt diff --git a/src/logging/log_backend_probe.c b/src/kernel/logging/log_backend_probe.c similarity index 100% rename from src/logging/log_backend_probe.c rename to src/kernel/logging/log_backend_probe.c diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 0597a89912bb..2578dd1f779c 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -240,7 +240,6 @@ add_subdirectory(../src/debug/ debug_unused_install/) add_subdirectory(../src/ipc/ ipc_unused_install/) add_subdirectory(../src/kernel/ kernel_unused_install/) add_subdirectory(../src/lib/ lib_unused_install/) -add_subdirectory(../src/logging/ logging_unused_install/) add_subdirectory(../src/probe/ probes_unused_install/) add_subdirectory(../src/samples/ samples_unused_install/) add_subdirectory(../src/schedule/ schedule_unused_install/) From c74d1879b0ffa2e4bde65c45b743f65cb0eb298a Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Fri, 6 Nov 2026 12:44:34 +0000 Subject: [PATCH 04/12] probe: move src/probe to src/kernel/probe The probe component drives DMA directly and runs in kernel mode. Move it to src/kernel/probe, where it is built into the sof_kernel library, or as before as an LLEXT module when CONFIG_PROBE=m. Its Kconfig is sourced from src/kernel/Kconfig instead of src/Kconfig; the option values are unchanged. Drop it from the not-yet-moved kernel-only directories in the docs. Only Zephyr builds it. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- AGENTS.md | 2 +- src/Kconfig | 2 -- src/include/sof/userspace/README.md | 2 +- src/kernel/CMakeLists.txt | 1 + src/kernel/Kconfig | 2 ++ src/{ => kernel}/probe/CMakeLists.txt | 0 src/{ => kernel}/probe/Kconfig | 0 src/{ => kernel}/probe/llext/CMakeLists.txt | 0 src/{ => kernel}/probe/llext/llext.toml.h | 0 src/{ => kernel}/probe/probe.c | 0 src/{ => kernel}/probe/probe.toml | 0 tools/rimage/config/lnl.toml.h | 2 +- tools/rimage/config/mtl.toml.h | 2 +- tools/rimage/config/nvl.toml.h | 2 +- tools/rimage/config/ptl.toml.h | 2 +- tools/rimage/config/tgl-h.toml.h | 2 +- tools/rimage/config/tgl.toml.h | 2 +- tools/rimage/config/wcl.toml.h | 2 +- zephyr/CMakeLists.txt | 1 - 19 files changed, 12 insertions(+), 12 deletions(-) rename src/{ => kernel}/probe/CMakeLists.txt (100%) rename src/{ => kernel}/probe/Kconfig (100%) rename src/{ => kernel}/probe/llext/CMakeLists.txt (100%) rename src/{ => kernel}/probe/llext/llext.toml.h (100%) rename src/{ => kernel}/probe/probe.c (100%) rename src/{ => kernel}/probe/probe.toml (100%) diff --git a/AGENTS.md b/AGENTS.md index 8d167bd80067..095ec828115f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -31,7 +31,7 @@ moving code, follow it: * **Place code in the right tier.** OS/HAL/boot/inter-core → a kernel-only directory (`kernel/`, which is built into the `sof_kernel` library, and the directories not yet - moved there: `arch/`, `drivers/`, `platform/`, `probe/`, `trace/`); audio + moved there: `arch/`, `drivers/`, `platform/`, `trace/`); audio application logic → `audio/`; reusable pure code → a shared-library directory (`lib/`, `math/`, `module/`) kept free of privileged operations. Each top-level directory's `README.md` states its tier in a "Runs in:" banner — keep it accurate. diff --git a/src/Kconfig b/src/Kconfig index 3022dfbff479..08e4ce55df05 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -10,8 +10,6 @@ rsource "audio/Kconfig" rsource "trace/Kconfig" -rsource "probe/Kconfig" - rsource "samples/Kconfig" rsource "schedule/Kconfig" diff --git a/src/include/sof/userspace/README.md b/src/include/sof/userspace/README.md index 8a0346238cd3..a5320d241a16 100644 --- a/src/include/sof/userspace/README.md +++ b/src/include/sof/userspace/README.md @@ -74,7 +74,7 @@ its subdirectories span all tiers. | Tier | Meaning | Directories | |------|---------|-------------| -| **Kernel-only** | OS integration, HAL, boot, inter-core. Never executes in a user thread. Must not be reached directly from user code — only via a syscall. | `kernel/` (see [its README](../../../kernel/README.md)), `arch/`, `drivers/`, `platform/`, `probe/` *, `trace/` * | +| **Kernel-only** | OS integration, HAL, boot, inter-core. Never executes in a user thread. Must not be reached directly from user code — only via a syscall. | `kernel/` (see [its README](../../../kernel/README.md)), `arch/`, `drivers/`, `platform/`, `trace/` * | | **Boundary / bridge** | Owns the syscalls and the thread / memory-domain setup. Split internally: some translation units run kernel-side, some user-side (e.g. `handler-kernel.c` vs `handler-user.c`, `zephyr_ll.c` vs `zephyr_ll_user.c`). | `schedule/`, `ipc/`, `debug/debug_stream/` *, and (in the Zephyr integration tree) `zephyr/syscall/` | | **Application** | Audio pipeline / component logic that runs in user threads under userspace configs. | `audio/` | | **Shared library** | Context-agnostic code linked into whichever context calls it. Must stay "user-safe": no privileged operations (no direct MMIO, no spinlocks held across syscalls, no raw kernel object access) so it is safe when pulled into a user build. | `math/`, `module/` | diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 1ad38f07148a..d31623db7f01 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -14,3 +14,4 @@ add_subdirectory(idc) add_subdirectory(init) add_subdirectory(library_manager) add_subdirectory(logging) +add_subdirectory(probe) diff --git a/src/kernel/Kconfig b/src/kernel/Kconfig index b61161f9d34d..7a10b8cf1b35 100644 --- a/src/kernel/Kconfig +++ b/src/kernel/Kconfig @@ -5,3 +5,5 @@ rsource "idc/Kconfig" rsource "library_manager/Kconfig" + +rsource "probe/Kconfig" diff --git a/src/probe/CMakeLists.txt b/src/kernel/probe/CMakeLists.txt similarity index 100% rename from src/probe/CMakeLists.txt rename to src/kernel/probe/CMakeLists.txt diff --git a/src/probe/Kconfig b/src/kernel/probe/Kconfig similarity index 100% rename from src/probe/Kconfig rename to src/kernel/probe/Kconfig diff --git a/src/probe/llext/CMakeLists.txt b/src/kernel/probe/llext/CMakeLists.txt similarity index 100% rename from src/probe/llext/CMakeLists.txt rename to src/kernel/probe/llext/CMakeLists.txt diff --git a/src/probe/llext/llext.toml.h b/src/kernel/probe/llext/llext.toml.h similarity index 100% rename from src/probe/llext/llext.toml.h rename to src/kernel/probe/llext/llext.toml.h diff --git a/src/probe/probe.c b/src/kernel/probe/probe.c similarity index 100% rename from src/probe/probe.c rename to src/kernel/probe/probe.c diff --git a/src/probe/probe.toml b/src/kernel/probe/probe.toml similarity index 100% rename from src/probe/probe.toml rename to src/kernel/probe/probe.toml diff --git a/tools/rimage/config/lnl.toml.h b/tools/rimage/config/lnl.toml.h index 96da2153a5a7..daca48653857 100644 --- a/tools/rimage/config/lnl.toml.h +++ b/tools/rimage/config/lnl.toml.h @@ -75,7 +75,7 @@ #endif #ifdef CONFIG_PROBE -#include +#include #endif #if defined(CONFIG_COMP_MUX) || defined(LLEXT_FORCE_ALL_MODULAR) diff --git a/tools/rimage/config/mtl.toml.h b/tools/rimage/config/mtl.toml.h index 119dbf7ffe6a..c0a0b363bfb4 100644 --- a/tools/rimage/config/mtl.toml.h +++ b/tools/rimage/config/mtl.toml.h @@ -71,7 +71,7 @@ #endif #ifdef CONFIG_PROBE -#include +#include #endif #if defined(CONFIG_COMP_MUX) || defined(LLEXT_FORCE_ALL_MODULAR) diff --git a/tools/rimage/config/nvl.toml.h b/tools/rimage/config/nvl.toml.h index e7ae339bbf81..e1f4ebfb6336 100644 --- a/tools/rimage/config/nvl.toml.h +++ b/tools/rimage/config/nvl.toml.h @@ -75,7 +75,7 @@ index = __COUNTER__ #endif #ifdef CONFIG_PROBE -#include +#include #endif #if defined(CONFIG_COMP_MUX) || defined(LLEXT_FORCE_ALL_MODULAR) diff --git a/tools/rimage/config/ptl.toml.h b/tools/rimage/config/ptl.toml.h index 59a4a8fd4515..88e4a153797e 100644 --- a/tools/rimage/config/ptl.toml.h +++ b/tools/rimage/config/ptl.toml.h @@ -75,7 +75,7 @@ index = __COUNTER__ #endif #ifdef CONFIG_PROBE -#include +#include #endif #if defined(CONFIG_COMP_MUX) || defined(LLEXT_FORCE_ALL_MODULAR) diff --git a/tools/rimage/config/tgl-h.toml.h b/tools/rimage/config/tgl-h.toml.h index e4a717bbe351..6ad16122ca6e 100644 --- a/tools/rimage/config/tgl-h.toml.h +++ b/tools/rimage/config/tgl-h.toml.h @@ -37,7 +37,7 @@ #endif #ifdef CONFIG_PROBE -#include +#include #endif #if defined(CONFIG_COMP_SRC) || defined(LLEXT_FORCE_ALL_MODULAR) diff --git a/tools/rimage/config/tgl.toml.h b/tools/rimage/config/tgl.toml.h index 8c434e8bf5c3..765be13cc1d3 100644 --- a/tools/rimage/config/tgl.toml.h +++ b/tools/rimage/config/tgl.toml.h @@ -37,7 +37,7 @@ #endif #ifdef CONFIG_PROBE -#include +#include #endif #if defined(CONFIG_COMP_SRC) || defined(LLEXT_FORCE_ALL_MODULAR) diff --git a/tools/rimage/config/wcl.toml.h b/tools/rimage/config/wcl.toml.h index 9a715ba4b2d2..dfedda2a6f8c 100644 --- a/tools/rimage/config/wcl.toml.h +++ b/tools/rimage/config/wcl.toml.h @@ -75,7 +75,7 @@ index = __COUNTER__ #endif #ifdef CONFIG_PROBE -#include +#include #endif #if defined(CONFIG_COMP_MUX) || defined(LLEXT_FORCE_ALL_MODULAR) diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 2578dd1f779c..ea8f312f435b 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -240,7 +240,6 @@ add_subdirectory(../src/debug/ debug_unused_install/) add_subdirectory(../src/ipc/ ipc_unused_install/) add_subdirectory(../src/kernel/ kernel_unused_install/) add_subdirectory(../src/lib/ lib_unused_install/) -add_subdirectory(../src/probe/ probes_unused_install/) add_subdirectory(../src/samples/ samples_unused_install/) add_subdirectory(../src/schedule/ schedule_unused_install/) add_subdirectory(../src/trace/ trace_unused_install/) From a886620174d51d835799b3b457e12aace998338f Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Fri, 6 Nov 2026 12:45:29 +0000 Subject: [PATCH 05/12] audio: move base_fw.c and base_fw_intel.c to src/kernel/audio The IPC4 base firmware module reports firmware and hardware configuration, manages DSP state and reads the memory windows. It runs in kernel mode. Move it to src/kernel/audio, where it is built into the sof_kernel library, and drop the files from the kernel exceptions in the include checker's manifest, which only lists user-space directories. base_fw_intel.c includes the copier's private copier_gain.h by a path relative to src/audio; it now uses a path relative to its new location. The base firmware module is not built for the host library. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- scripts/kernel_user_partition.txt | 2 -- src/audio/CMakeLists.txt | 5 ----- src/kernel/CMakeLists.txt | 1 + src/kernel/audio/CMakeLists.txt | 6 ++++++ src/{ => kernel}/audio/base_fw.c | 0 src/{ => kernel}/audio/base_fw_intel.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 src/kernel/audio/CMakeLists.txt rename src/{ => kernel}/audio/base_fw.c (100%) rename src/{ => kernel}/audio/base_fw_intel.c (99%) diff --git a/scripts/kernel_user_partition.txt b/scripts/kernel_user_partition.txt index cf913dd07713..2d4d77a83c29 100644 --- a/scripts/kernel_user_partition.txt +++ b/scripts/kernel_user_partition.txt @@ -28,8 +28,6 @@ src/lib/objpool.c # Kernel sources inside the directories above. [not-user-sources] -src/audio/base_fw.c -src/audio/base_fw_intel.c src/audio/dai-legacy.c src/audio/host-legacy.c src/audio/intel_uaol.c diff --git a/src/audio/CMakeLists.txt b/src/audio/CMakeLists.txt index e975a61c7a06..3d298590745e 100644 --- a/src/audio/CMakeLists.txt +++ b/src/audio/CMakeLists.txt @@ -16,11 +16,6 @@ add_subdirectory(buffers) add_subdirectory(pcm_converter) add_subdirectory(pipeline) -if(CONFIG_COMP_BASEFW_IPC4 AND NOT CONFIG_LIBRARY) - add_local_sources(sof base_fw.c) -endif() -add_local_sources_ifdef(CONFIG_IPC4_BASE_FW_INTEL sof base_fw_intel.c) - # directories and files included conditionally (alphabetical order) if(CONFIG_COMP_ARIA) add_subdirectory(aria) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index d31623db7f01..b375c2b524ba 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -10,6 +10,7 @@ if(zephyr) set(ZEPHYR_CURRENT_LIBRARY sof_kernel) endif() +add_subdirectory(audio) add_subdirectory(idc) add_subdirectory(init) add_subdirectory(library_manager) diff --git a/src/kernel/audio/CMakeLists.txt b/src/kernel/audio/CMakeLists.txt new file mode 100644 index 000000000000..3ca6156f69a3 --- /dev/null +++ b/src/kernel/audio/CMakeLists.txt @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: BSD-3-Clause + +if(CONFIG_COMP_BASEFW_IPC4 AND NOT CONFIG_LIBRARY) + add_local_sources(sof base_fw.c) +endif() +add_local_sources_ifdef(CONFIG_IPC4_BASE_FW_INTEL sof base_fw_intel.c) diff --git a/src/audio/base_fw.c b/src/kernel/audio/base_fw.c similarity index 100% rename from src/audio/base_fw.c rename to src/kernel/audio/base_fw.c diff --git a/src/audio/base_fw_intel.c b/src/kernel/audio/base_fw_intel.c similarity index 99% rename from src/audio/base_fw_intel.c rename to src/kernel/audio/base_fw_intel.c index 0d302e7c3fab..3d25f89dbd18 100644 --- a/src/audio/base_fw_intel.c +++ b/src/kernel/audio/base_fw_intel.c @@ -28,7 +28,7 @@ #include #include #include -#include "copier/copier_gain.h" +#include "../../audio/copier/copier_gain.h" #if CONFIG_INTEL_ADSP_MIC_PRIVACY #include From 42bd8d582a7c8c890543416e5c08615cf165013e Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Fri, 6 Nov 2026 12:45:44 +0000 Subject: [PATCH 06/12] audio: move mic_privacy_manager to src/kernel/audio The microphone privacy manager handles the privacy interrupt and programs the DMIC and gateway hardware, and runs in kernel mode. Move it to src/kernel/audio/mic_privacy_manager, where it is built into the sof_kernel library, and drop it from the kernel exceptions in the include checker's manifest. Only Zephyr builds it. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- scripts/kernel_user_partition.txt | 1 - src/audio/CMakeLists.txt | 3 --- src/kernel/audio/CMakeLists.txt | 3 +++ src/{ => kernel}/audio/mic_privacy_manager/CMakeLists.txt | 0 src/{ => kernel}/audio/mic_privacy_manager/README.md | 0 .../audio/mic_privacy_manager/mic_privacy_manager_intel.c | 0 6 files changed, 3 insertions(+), 4 deletions(-) rename src/{ => kernel}/audio/mic_privacy_manager/CMakeLists.txt (100%) rename src/{ => kernel}/audio/mic_privacy_manager/README.md (100%) rename src/{ => kernel}/audio/mic_privacy_manager/mic_privacy_manager_intel.c (100%) diff --git a/scripts/kernel_user_partition.txt b/scripts/kernel_user_partition.txt index 2d4d77a83c29..6a1ca1844519 100644 --- a/scripts/kernel_user_partition.txt +++ b/scripts/kernel_user_partition.txt @@ -31,7 +31,6 @@ src/lib/objpool.c src/audio/dai-legacy.c src/audio/host-legacy.c src/audio/intel_uaol.c -src/audio/mic_privacy_manager/* src/audio/module_adapter/library/userspace_proxy.c # SOF headers that only kernel code may include. diff --git a/src/audio/CMakeLists.txt b/src/audio/CMakeLists.txt index 3d298590745e..0ca532950f5c 100644 --- a/src/audio/CMakeLists.txt +++ b/src/audio/CMakeLists.txt @@ -138,9 +138,6 @@ if(CONFIG_COMP_KPB AND NOT CONFIG_LIBRARY) kpb.c ) endif() -if(CONFIG_INTEL_ADSP_MIC_PRIVACY) - add_subdirectory(mic_privacy_manager) -endif() if(CONFIG_COMP_TONE) add_subdirectory(tone) endif() diff --git a/src/kernel/audio/CMakeLists.txt b/src/kernel/audio/CMakeLists.txt index 3ca6156f69a3..6c0f3802fdee 100644 --- a/src/kernel/audio/CMakeLists.txt +++ b/src/kernel/audio/CMakeLists.txt @@ -4,3 +4,6 @@ if(CONFIG_COMP_BASEFW_IPC4 AND NOT CONFIG_LIBRARY) add_local_sources(sof base_fw.c) endif() add_local_sources_ifdef(CONFIG_IPC4_BASE_FW_INTEL sof base_fw_intel.c) +if(CONFIG_INTEL_ADSP_MIC_PRIVACY) + add_subdirectory(mic_privacy_manager) +endif() diff --git a/src/audio/mic_privacy_manager/CMakeLists.txt b/src/kernel/audio/mic_privacy_manager/CMakeLists.txt similarity index 100% rename from src/audio/mic_privacy_manager/CMakeLists.txt rename to src/kernel/audio/mic_privacy_manager/CMakeLists.txt diff --git a/src/audio/mic_privacy_manager/README.md b/src/kernel/audio/mic_privacy_manager/README.md similarity index 100% rename from src/audio/mic_privacy_manager/README.md rename to src/kernel/audio/mic_privacy_manager/README.md diff --git a/src/audio/mic_privacy_manager/mic_privacy_manager_intel.c b/src/kernel/audio/mic_privacy_manager/mic_privacy_manager_intel.c similarity index 100% rename from src/audio/mic_privacy_manager/mic_privacy_manager_intel.c rename to src/kernel/audio/mic_privacy_manager/mic_privacy_manager_intel.c From 591fe1d652861b7b5ebfb77ac0244afe96b0b28d Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Fri, 6 Nov 2026 12:46:09 +0000 Subject: [PATCH 07/12] module_adapter: move userspace_proxy.c to src/kernel/audio The user-space proxy is split in two: userspace_proxy_user.c runs in the user thread, and userspace_proxy.c creates that thread, its memory domain and object grants, and forwards the module calls to it from the kernel. Move the kernel half to src/kernel/audio/module_adapter/library, where it is built into the sof_kernel library. Drop it from the kernel exceptions in the include checker's manifest and update the module adapter README. Only Zephyr builds it. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- scripts/kernel_user_partition.txt | 1 - src/audio/module_adapter/CMakeLists.txt | 1 - src/audio/module_adapter/README.md | 3 ++- src/kernel/audio/CMakeLists.txt | 7 +++++++ .../audio/module_adapter/library/userspace_proxy.c | 0 5 files changed, 9 insertions(+), 3 deletions(-) rename src/{ => kernel}/audio/module_adapter/library/userspace_proxy.c (100%) diff --git a/scripts/kernel_user_partition.txt b/scripts/kernel_user_partition.txt index 6a1ca1844519..b5d6cda1c33f 100644 --- a/scripts/kernel_user_partition.txt +++ b/scripts/kernel_user_partition.txt @@ -31,7 +31,6 @@ src/lib/objpool.c src/audio/dai-legacy.c src/audio/host-legacy.c src/audio/intel_uaol.c -src/audio/module_adapter/library/userspace_proxy.c # SOF headers that only kernel code may include. # Not listed on purpose: rtos/init.h, which only provides the diff --git a/src/audio/module_adapter/CMakeLists.txt b/src/audio/module_adapter/CMakeLists.txt index bc22ae348b6c..50d35c17ea01 100644 --- a/src/audio/module_adapter/CMakeLists.txt +++ b/src/audio/module_adapter/CMakeLists.txt @@ -84,7 +84,6 @@ endif() endif() zephyr_library_sources_ifdef(CONFIG_SOF_USERSPACE_PROXY - library/userspace_proxy.c library/userspace_proxy_user.c ) diff --git a/src/audio/module_adapter/README.md b/src/audio/module_adapter/README.md index 9a58bbf956fc..9bc4f2b01695 100644 --- a/src/audio/module_adapter/README.md +++ b/src/audio/module_adapter/README.md @@ -1,7 +1,8 @@ # Module Adapter Architecture > **Runs in:** Boundary / bridge — the module adapter is the container that runs audio modules -> in **user** threads (DP threads, or the userspace proxy in `library/userspace_proxy.c`) while +> in **user** threads (DP threads, or the userspace proxy in `library/userspace_proxy_user.c`, +> whose kernel half is `src/kernel/audio/module_adapter/library/userspace_proxy.c`) while > being driven from the **kernel** pipeline. It hosts the `mod_*` allocation syscalls and sets > up per-module memory domains and object grants. See > [User/kernel split](../../include/sof/userspace/README.md). diff --git a/src/kernel/audio/CMakeLists.txt b/src/kernel/audio/CMakeLists.txt index 6c0f3802fdee..e310aa2585a3 100644 --- a/src/kernel/audio/CMakeLists.txt +++ b/src/kernel/audio/CMakeLists.txt @@ -7,3 +7,10 @@ add_local_sources_ifdef(CONFIG_IPC4_BASE_FW_INTEL sof base_fw_intel.c) if(CONFIG_INTEL_ADSP_MIC_PRIVACY) add_subdirectory(mic_privacy_manager) endif() + +is_zephyr(zephyr) +if(zephyr) + zephyr_library_sources_ifdef(CONFIG_SOF_USERSPACE_PROXY + module_adapter/library/userspace_proxy.c + ) +endif() diff --git a/src/audio/module_adapter/library/userspace_proxy.c b/src/kernel/audio/module_adapter/library/userspace_proxy.c similarity index 100% rename from src/audio/module_adapter/library/userspace_proxy.c rename to src/kernel/audio/module_adapter/library/userspace_proxy.c From 089f9154a0b4c2312a775ae7cee70b3dcdd06651 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Fri, 6 Nov 2026 12:46:34 +0000 Subject: [PATCH 08/12] ipc: move ipc-zephyr.c to src/kernel/ipc ipc-zephyr.c is the Intel ADSP IPC transport: it handles the host IPC interrupt and mailbox and the power state transitions requested over IPC, and runs in kernel mode. Move it to src/kernel/ipc, where it is built into the sof_kernel library. Only Zephyr builds it. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/ipc/CMakeLists.txt | 6 ------ src/kernel/CMakeLists.txt | 1 + src/kernel/ipc/CMakeLists.txt | 8 ++++++++ src/{ => kernel}/ipc/ipc-zephyr.c | 0 4 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 src/kernel/ipc/CMakeLists.txt rename src/{ => kernel}/ipc/ipc-zephyr.c (100%) diff --git a/src/ipc/CMakeLists.txt b/src/ipc/CMakeLists.txt index 15fab54b3c30..47ee898b7be2 100644 --- a/src/ipc/CMakeLists.txt +++ b/src/ipc/CMakeLists.txt @@ -19,12 +19,6 @@ if(zephyr) ### Zephyr ### # dma-copy only used for dma-trace zephyr_library_sources_ifdef(CONFIG_TRACE dma-copy.c) -if (CONFIG_SOC_SERIES_INTEL_CAVS_V25 OR CONFIG_SOC_SERIES_INTEL_ADSP_ACE) - zephyr_library_sources( - ipc-zephyr.c - ) -endif() - else() ### Not Zephyr ### if (CONFIG_TRACE) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index b375c2b524ba..5a90d1cbfd2a 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -13,6 +13,7 @@ endif() add_subdirectory(audio) add_subdirectory(idc) add_subdirectory(init) +add_subdirectory(ipc) add_subdirectory(library_manager) add_subdirectory(logging) add_subdirectory(probe) diff --git a/src/kernel/ipc/CMakeLists.txt b/src/kernel/ipc/CMakeLists.txt new file mode 100644 index 000000000000..8f22a80cc2f4 --- /dev/null +++ b/src/kernel/ipc/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: BSD-3-Clause + +is_zephyr(zephyr) +if(zephyr) + if (CONFIG_SOC_SERIES_INTEL_CAVS_V25 OR CONFIG_SOC_SERIES_INTEL_ADSP_ACE) + zephyr_library_sources(ipc-zephyr.c) + endif() +endif() diff --git a/src/ipc/ipc-zephyr.c b/src/kernel/ipc/ipc-zephyr.c similarity index 100% rename from src/ipc/ipc-zephyr.c rename to src/kernel/ipc/ipc-zephyr.c From 8d1bf80dd7672045c16384d8113eac022cedb7c1 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Fri, 6 Nov 2026 12:47:53 +0000 Subject: [PATCH 09/12] lib: move clk.c, cpu-clk-manager.c and ams.c to src/kernel/lib The clock code takes spinlocks and calls the platform clock drivers, the KCPS manager requests clock changes from the platform, and the AMS messaging service disables interrupts and sends IDC messages to other cores. All three run in kernel mode. Move them to src/kernel/lib, where they are built into the sof_kernel library. The src/lib README listed ams.c among the context-agnostic helpers; correct that and point to the new location. None of these files is built for the host library. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/kernel/CMakeLists.txt | 1 + src/kernel/lib/CMakeLists.txt | 18 ++++++++++++++++++ src/{ => kernel}/lib/ams.c | 0 src/{ => kernel}/lib/clk.c | 0 src/{ => kernel}/lib/cpu-clk-manager.c | 0 src/lib/CMakeLists.txt | 12 ------------ src/lib/README.md | 8 ++++---- src/platform/posix/include/platform/lib/clk.h | 2 +- 8 files changed, 24 insertions(+), 17 deletions(-) create mode 100644 src/kernel/lib/CMakeLists.txt rename src/{ => kernel}/lib/ams.c (100%) rename src/{ => kernel}/lib/clk.c (100%) rename src/{ => kernel}/lib/cpu-clk-manager.c (100%) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 5a90d1cbfd2a..0f23a3f26ce6 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -14,6 +14,7 @@ add_subdirectory(audio) add_subdirectory(idc) add_subdirectory(init) add_subdirectory(ipc) +add_subdirectory(lib) add_subdirectory(library_manager) add_subdirectory(logging) add_subdirectory(probe) diff --git a/src/kernel/lib/CMakeLists.txt b/src/kernel/lib/CMakeLists.txt new file mode 100644 index 000000000000..6f9861ed59f0 --- /dev/null +++ b/src/kernel/lib/CMakeLists.txt @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: BSD-3-Clause + +if(CONFIG_AMS) + add_local_sources(sof ams.c) +endif() + +if(CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL) + add_local_sources(sof cpu-clk-manager.c) +endif() + +is_zephyr(zephyr) +if(zephyr) ### Zephyr ### + + if(NOT CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK) + add_local_sources(sof clk.c) + endif() + +endif() diff --git a/src/lib/ams.c b/src/kernel/lib/ams.c similarity index 100% rename from src/lib/ams.c rename to src/kernel/lib/ams.c diff --git a/src/lib/clk.c b/src/kernel/lib/clk.c similarity index 100% rename from src/lib/clk.c rename to src/kernel/lib/clk.c diff --git a/src/lib/cpu-clk-manager.c b/src/kernel/lib/cpu-clk-manager.c similarity index 100% rename from src/lib/cpu-clk-manager.c rename to src/kernel/lib/cpu-clk-manager.c diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 707753635f69..f92e467d970f 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -15,21 +15,9 @@ if(CONFIG_HAVE_AGENT) add_local_sources(sof agent.c) endif() -if(CONFIG_AMS) - add_local_sources(sof ams.c) -endif() - -if(CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL) - add_local_sources(sof cpu-clk-manager.c) -endif() - is_zephyr(zephyr) if(zephyr) ### Zephyr ### add_local_sources(sof ${common_files}) - if(NOT CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK) - add_local_sources(sof clk.c) - endif() - endif() diff --git a/src/lib/README.md b/src/lib/README.md index 21e76ee840e9..6c986bdffafc 100644 --- a/src/lib/README.md +++ b/src/lib/README.md @@ -3,10 +3,10 @@ > **Runs in:** Mixed — this directory contains code in more than one tier. `dma.c` and `dai.c` > host the kernel-side implementations (`z_impl_sof_dma_get/put`, `z_impl_dai_get_device`) of > syscalls whose validators live in `zephyr/syscall/`; treat them as boundary/kernel code. -> Several other files (`clk.c`, `notifier.c`, `cpu-clk-manager.c`) take Zephyr spinlocks or -> perform privileged platform callbacks and are similarly restricted to kernel context. Truly -> context-agnostic helpers (`lib.c`, `objpool.c`, `ams.c`) can safely be linked into user -> builds. See [User/kernel split](../include/sof/userspace/README.md). +> `notifier.c` takes Zephyr spinlocks and is similarly restricted to kernel context. The clock, +> KCPS and AMS code (`clk.c`, `cpu-clk-manager.c`, `ams.c`) is kernel-only and lives in +> `src/kernel/lib`. Truly context-agnostic helpers (`lib.c`, `objpool.c`) can safely be linked +> into user builds. See [User/kernel split](../include/sof/userspace/README.md). This directory collects cross-cutting helpers that don't belong to a single subsystem. When adding code here, decide first which tier it belongs to: a pure helper (no locks, no diff --git a/src/platform/posix/include/platform/lib/clk.h b/src/platform/posix/include/platform/lib/clk.h index a5d8066a027c..4e246ca29b01 100644 --- a/src/platform/posix/include/platform/lib/clk.h +++ b/src/platform/posix/include/platform/lib/clk.h @@ -7,7 +7,7 @@ #define CPU_LPRO_FREQ_IDX 0 #define CPU_LOWEST_FREQ_IDX CPU_LPRO_FREQ_IDX -/* This is not a platform function, it's defined in src/lib/clk.c. +/* This is not a platform function, it's defined in src/kernel/lib/clk.c. * But the declaration has historically been in the platform layer, so * it's repeated here. */ From 4935763949ed7e85db23494101f45a348463d4ed Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Fri, 6 Nov 2026 12:48:19 +0000 Subject: [PATCH 10/12] debug: move telemetry to src/kernel/debug/telemetry The telemetry code writes the performance and I/O measurements to the debug memory window and runs in kernel mode; components report to it through function calls, which is why user-space LL builds disable it for now. Move it to src/kernel/debug/telemetry, where it is built into the sof_kernel library. Its Kconfig is sourced from src/kernel/Kconfig instead of src/Kconfig; the option values are unchanged. Only Zephyr builds it. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/Kconfig | 2 -- src/debug/CMakeLists.txt | 1 - src/kernel/CMakeLists.txt | 1 + src/kernel/Kconfig | 2 ++ src/kernel/debug/CMakeLists.txt | 8 ++++++++ src/{ => kernel}/debug/telemetry/CMakeLists.txt | 0 src/{ => kernel}/debug/telemetry/Kconfig | 0 src/{ => kernel}/debug/telemetry/README.md | 0 src/{ => kernel}/debug/telemetry/performance_monitor.c | 0 src/{ => kernel}/debug/telemetry/telemetry.c | 0 10 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 src/kernel/debug/CMakeLists.txt rename src/{ => kernel}/debug/telemetry/CMakeLists.txt (100%) rename src/{ => kernel}/debug/telemetry/Kconfig (100%) rename src/{ => kernel}/debug/telemetry/README.md (100%) rename src/{ => kernel}/debug/telemetry/performance_monitor.c (100%) rename src/{ => kernel}/debug/telemetry/telemetry.c (100%) diff --git a/src/Kconfig b/src/Kconfig index 08e4ce55df05..f7d5dbbb64bc 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -21,8 +21,6 @@ rsource "ipc/Kconfig" rsource "math/Kconfig" -rsource "debug/telemetry/Kconfig" - rsource "debug/debug_stream/Kconfig" rsource "debug/tester/Kconfig" diff --git a/src/debug/CMakeLists.txt b/src/debug/CMakeLists.txt index d91bd79234e8..4fcb315f662e 100644 --- a/src/debug/CMakeLists.txt +++ b/src/debug/CMakeLists.txt @@ -6,7 +6,6 @@ is_zephyr(zephyr) if(zephyr) ### Zephyr ### add_subdirectory(debug_stream) -add_subdirectory(telemetry) zephyr_library_sources_ifdef(CONFIG_COLD_STORE_EXECUTE_DEBUG dram.c) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 0f23a3f26ce6..1abeb2951396 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -11,6 +11,7 @@ if(zephyr) endif() add_subdirectory(audio) +add_subdirectory(debug) add_subdirectory(idc) add_subdirectory(init) add_subdirectory(ipc) diff --git a/src/kernel/Kconfig b/src/kernel/Kconfig index 7a10b8cf1b35..5a8920dd9b1f 100644 --- a/src/kernel/Kconfig +++ b/src/kernel/Kconfig @@ -2,6 +2,8 @@ # Code that only runs in kernel mode, see scripts/kernel_user_partition.txt. +rsource "debug/telemetry/Kconfig" + rsource "idc/Kconfig" rsource "library_manager/Kconfig" diff --git a/src/kernel/debug/CMakeLists.txt b/src/kernel/debug/CMakeLists.txt new file mode 100644 index 000000000000..d2105775116b --- /dev/null +++ b/src/kernel/debug/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: BSD-3-Clause + +is_zephyr(zephyr) +if(zephyr) ### Zephyr ### + +add_subdirectory(telemetry) + +endif() # Zephyr diff --git a/src/debug/telemetry/CMakeLists.txt b/src/kernel/debug/telemetry/CMakeLists.txt similarity index 100% rename from src/debug/telemetry/CMakeLists.txt rename to src/kernel/debug/telemetry/CMakeLists.txt diff --git a/src/debug/telemetry/Kconfig b/src/kernel/debug/telemetry/Kconfig similarity index 100% rename from src/debug/telemetry/Kconfig rename to src/kernel/debug/telemetry/Kconfig diff --git a/src/debug/telemetry/README.md b/src/kernel/debug/telemetry/README.md similarity index 100% rename from src/debug/telemetry/README.md rename to src/kernel/debug/telemetry/README.md diff --git a/src/debug/telemetry/performance_monitor.c b/src/kernel/debug/telemetry/performance_monitor.c similarity index 100% rename from src/debug/telemetry/performance_monitor.c rename to src/kernel/debug/telemetry/performance_monitor.c diff --git a/src/debug/telemetry/telemetry.c b/src/kernel/debug/telemetry/telemetry.c similarity index 100% rename from src/debug/telemetry/telemetry.c rename to src/kernel/debug/telemetry/telemetry.c From 480d021a4d783787701b25083cfbc5cff4900559 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Fri, 6 Nov 2026 12:48:38 +0000 Subject: [PATCH 11/12] debug: move dram.c to src/kernel/debug dram.c is the CONFIG_COLD_STORE_EXECUTE_DEBUG checker that tracks hot and cold code paths under a spinlock, and runs in kernel mode; user-space LL builds disable it for now. Move it to src/kernel/debug, where it is built into the sof_kernel library. Only Zephyr builds it. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/debug/CMakeLists.txt | 2 -- src/kernel/debug/CMakeLists.txt | 2 ++ src/{ => kernel}/debug/dram.c | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/{ => kernel}/debug/dram.c (100%) diff --git a/src/debug/CMakeLists.txt b/src/debug/CMakeLists.txt index 4fcb315f662e..78a2a0c7b22b 100644 --- a/src/debug/CMakeLists.txt +++ b/src/debug/CMakeLists.txt @@ -7,6 +7,4 @@ if(zephyr) ### Zephyr ### add_subdirectory(debug_stream) -zephyr_library_sources_ifdef(CONFIG_COLD_STORE_EXECUTE_DEBUG dram.c) - endif() # Zephyr diff --git a/src/kernel/debug/CMakeLists.txt b/src/kernel/debug/CMakeLists.txt index d2105775116b..e364c4233063 100644 --- a/src/kernel/debug/CMakeLists.txt +++ b/src/kernel/debug/CMakeLists.txt @@ -5,4 +5,6 @@ if(zephyr) ### Zephyr ### add_subdirectory(telemetry) +zephyr_library_sources_ifdef(CONFIG_COLD_STORE_EXECUTE_DEBUG dram.c) + endif() # Zephyr diff --git a/src/debug/dram.c b/src/kernel/debug/dram.c similarity index 100% rename from src/debug/dram.c rename to src/kernel/debug/dram.c From 45c04781c8037ec3cf481bda3e991603e6da53fb Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Fri, 6 Nov 2026 12:50:21 +0000 Subject: [PATCH 12/12] schedule: move zephyr_ll_user.c to src/kernel/schedule zephyr_ll_user.c creates the memory domain and heap of the user-space LL scheduler thread and checks the heap pointers passed to the heap system calls. Despite its name it runs in kernel mode. Move it to src/kernel/schedule, where it is built into the sof_kernel library. Update the schedule and user-space READMEs, and stop giving it as an example of a user-side file. Only Zephyr builds it, for CONFIG_SOF_USERSPACE_LL. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/include/sof/userspace/README.md | 4 ++-- src/kernel/CMakeLists.txt | 1 + src/kernel/schedule/CMakeLists.txt | 8 ++++++++ src/{ => kernel}/schedule/zephyr_ll_user.c | 0 src/schedule/CMakeLists.txt | 4 ---- src/schedule/README.md | 4 ++-- 6 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 src/kernel/schedule/CMakeLists.txt rename src/{ => kernel}/schedule/zephyr_ll_user.c (100%) diff --git a/src/include/sof/userspace/README.md b/src/include/sof/userspace/README.md index a5320d241a16..52396658f742 100644 --- a/src/include/sof/userspace/README.md +++ b/src/include/sof/userspace/README.md @@ -75,7 +75,7 @@ its subdirectories span all tiers. | Tier | Meaning | Directories | |------|---------|-------------| | **Kernel-only** | OS integration, HAL, boot, inter-core. Never executes in a user thread. Must not be reached directly from user code — only via a syscall. | `kernel/` (see [its README](../../../kernel/README.md)), `arch/`, `drivers/`, `platform/`, `trace/` * | -| **Boundary / bridge** | Owns the syscalls and the thread / memory-domain setup. Split internally: some translation units run kernel-side, some user-side (e.g. `handler-kernel.c` vs `handler-user.c`, `zephyr_ll.c` vs `zephyr_ll_user.c`). | `schedule/`, `ipc/`, `debug/debug_stream/` *, and (in the Zephyr integration tree) `zephyr/syscall/` | +| **Boundary / bridge** | Owns the syscalls and the thread / memory-domain setup. Split internally: some translation units run kernel-side, some user-side (e.g. `handler-kernel.c` vs `handler-user.c`). | `schedule/`, `ipc/`, `debug/debug_stream/` *, and (in the Zephyr integration tree) `zephyr/syscall/` | | **Application** | Audio pipeline / component logic that runs in user threads under userspace configs. | `audio/` | | **Shared library** | Context-agnostic code linked into whichever context calls it. Must stay "user-safe": no privileged operations (no direct MMIO, no spinlocks held across syscalls, no raw kernel object access) so it is safe when pulled into a user build. | `math/`, `module/` | | **Mixed** | A directory whose files span more than one tier; see its own README for per-file classification. | `lib/` | @@ -152,7 +152,7 @@ marker at its declaration site.* Conversely, marked data is **user-writable**, s must never trust it — re-validate on every use. DP modules running under `SOF_USERSPACE_APPLICATION` access data through their per-module memory domain set up by the proxy or DP thread infrastructure, not through `APP_TASK_*` / `APP_SYSUSER_*` markers. See -[`schedule/zephyr_ll_user.c`](../../../schedule/zephyr_ll_user.c): `zephyr_ll_user_heap()` +[`kernel/schedule/zephyr_ll_user.c`](../../../kernel/schedule/zephyr_ll_user.c): `zephyr_ll_user_heap()` returns the address of the kernel-only heap object rather than a pointer stored in user-writable memory, and `zephyr_ll_user_heap_verify()` checks the heap pointer that user threads pass to the heap system calls. diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 1abeb2951396..da1df9328654 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -19,3 +19,4 @@ add_subdirectory(lib) add_subdirectory(library_manager) add_subdirectory(logging) add_subdirectory(probe) +add_subdirectory(schedule) diff --git a/src/kernel/schedule/CMakeLists.txt b/src/kernel/schedule/CMakeLists.txt new file mode 100644 index 000000000000..277378449165 --- /dev/null +++ b/src/kernel/schedule/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: BSD-3-Clause + +is_zephyr(zephyr) +if(zephyr) + zephyr_library_sources_ifdef(CONFIG_SOF_USERSPACE_LL + zephyr_ll_user.c + ) +endif() diff --git a/src/schedule/zephyr_ll_user.c b/src/kernel/schedule/zephyr_ll_user.c similarity index 100% rename from src/schedule/zephyr_ll_user.c rename to src/kernel/schedule/zephyr_ll_user.c diff --git a/src/schedule/CMakeLists.txt b/src/schedule/CMakeLists.txt index 622b75e46888..bc14c6ecff46 100644 --- a/src/schedule/CMakeLists.txt +++ b/src/schedule/CMakeLists.txt @@ -54,8 +54,4 @@ zephyr_library_sources_ifdef(CONFIG_ZEPHYR_TWB_SCHEDULER zephyr_twb_schedule.c ) -zephyr_library_sources_ifdef(CONFIG_SOF_USERSPACE_LL - zephyr_ll_user.c -) - endif() diff --git a/src/schedule/README.md b/src/schedule/README.md index 9d53cfd1fdfe..0bef23248837 100644 --- a/src/schedule/README.md +++ b/src/schedule/README.md @@ -1,8 +1,8 @@ # SOF Scheduling Architecture > **Runs in:** Boundary / bridge — this directory owns the LL/DP schedulers and their thread + -> memory-domain setup. `zephyr_ll.c` and `zephyr_domain.c` are kernel-side; `zephyr_ll_user.c` -> sets up the LL user memory domain (kernel-executed) and supports the LL user thread. +> memory-domain setup. `zephyr_ll.c` and `zephyr_domain.c` are kernel-side; the LL user memory +> domain and heap are set up by `src/kernel/schedule/zephyr_ll_user.c`. > `zephyr_dp_schedule_thread.c` is boundary code that can create and manage both kernel and > `K_USER` DP threads depending on configuration; `zephyr_dp_schedule_application.c` is the > DP application-mode path. This directory hosts the `zephyr_ll_task_sem_*` and