From 8beb1b8c0e1678c439421def3a2ec3506e3af4cd Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Wed, 18 Nov 2026 14:50:23 +0000 Subject: [PATCH 1/5] debug: remove the unused panic.c src/debug/panic.c is the XTOS panic handler. Its build rules went with the XTOS support in commit e68dfe9df ("build: remove XTOS-specific sections from cmake lists"), and the host library has its own panic.c, so nothing builds it. Remove it. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/debug/panic.c | 150 ---------------------------------------------- 1 file changed, 150 deletions(-) delete mode 100644 src/debug/panic.c diff --git a/src/debug/panic.c b/src/debug/panic.c deleted file mode 100644 index 6ec6ea4eafb6..000000000000 --- a/src/debug/panic.c +++ /dev/null @@ -1,150 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2018 Intel Corporation. All rights reserved. -// -// Author: Liam Girdwood - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -void dump_panicinfo(void *addr, struct sof_ipc_panic_info *panic_info) -{ - int ret; - - if (!panic_info) - return; - ret = memcpy_s(addr, sizeof(struct sof_ipc_panic_info), panic_info, - sizeof(struct sof_ipc_panic_info)); - /* TODO are asserts even safe in this context? */ - assert(!ret); - dcache_writeback_region(addr, sizeof(struct sof_ipc_panic_info)); -} - -/** Dumps stack as part of panic. - * - * \return SOF_IPC_PANIC_STACK if offset is off the stack_limit, - * unchanged 'p' panic code input otherwise. - */ -static uint32_t dump_stack(uint32_t p, void *addr, size_t offset, - size_t limit, uintptr_t *stack_ptr) -{ - uintptr_t stack_limit = (uintptr_t)arch_get_stack_entry(); - uintptr_t stack_bottom = stack_limit + arch_get_stack_size() - - sizeof(void *); - uintptr_t stack_top = (uintptr_t)arch_get_stack_ptr() + offset; - size_t size = stack_bottom - stack_top; - int ret; - - *stack_ptr = stack_top; - - /* is stack smashed ? */ - if (stack_top - offset <= stack_limit) { - p = SOF_IPC_PANIC_STACK; - return p; - } - - /* make sure stack size won't overflow dump area */ - if (size > limit) - size = limit; - - /* copy stack contents and writeback */ - ret = memcpy_s(addr, limit, (void *)stack_top, size - sizeof(void *)); - assert(!ret); - dcache_writeback_region(addr, size - sizeof(void *)); - - return p; -} - -/** Copy registers, panic_info and current stack to mailbox exception - * window. Opaque 'data' (e.g.: optional epc1) is passed to - * arch_dump_regs(). - */ -void panic_dump(uint32_t p, struct sof_ipc_panic_info *panic_info, - uintptr_t *data) -{ - char *ext_offset; - size_t avail; - uintptr_t stack_ptr; - - /* disable all IRQs */ - interrupt_global_disable(); - - /* ARCH_OOPS_SIZE is platform-dependent */ - ext_offset = (char *)mailbox_get_exception_base() + ARCH_OOPS_SIZE; - - /* dump panic info, filename and linenum */ - dump_panicinfo(ext_offset, panic_info); - ext_offset += sizeof(struct sof_ipc_panic_info); - - /* Dump stack frames and override panic code 'p' if ext_offset is - * off stack_limit. Find stack_ptr. - */ - avail = MAILBOX_EXCEPTION_SIZE - - (size_t)(ext_offset - (char *)mailbox_get_exception_base()); - p = dump_stack(p, ext_offset, 0, avail, &stack_ptr); - - /* Write oops.arch_hdr and oops.plat_hdr headers and dump DSP core - * registers. After arch_dump_regs() use only inline funcs if - * needed. - */ - arch_dump_regs((void *)mailbox_get_exception_base(), stack_ptr, data); - - /* panic - send IPC oops message to host */ - platform_panic(p); - - /* and loop forever */ - while (1) - ; -} - -void __panic(uint32_t panic_code, const char *filename, uint32_t linenum) -{ - struct sof_ipc_panic_info panicinfo = { .linenum = linenum }; - const unsigned int length_max = sizeof(panicinfo.filename); - int mem_len; - int ret; - - /* including the ending '\0' */ - mem_len = rstrlen(filename) + 1; - - if (mem_len > length_max) { - /* copy those last bytes only */ - ret = memcpy_s(panicinfo.filename, - length_max, - filename + mem_len - length_max, - length_max); - /* TODO are asserts safe in this context? */ - assert(!ret); - - /* prefixing with "..." */ - ret = memcpy_s(panicinfo.filename, length_max, "...", 3); - assert(!ret); - } else { - ret = memcpy_s(panicinfo.filename, length_max, filename, mem_len); - assert(!ret); - } - - /* To distinguish regular panic() calls from exceptions, we will - * set a reserved value for the exception cause (63) so the - * coredumper tool could distinguish between the situations. - */ -#if !__clang_analyzer__ - __asm__ __volatile__("movi a3, 63\n\t" - "wsr.exccause a3\n\t" - "esync" : : : - "a3", "memory"); -#endif - - panic_dump(panic_code, &panicinfo, NULL); -} From 7030835fe0d0301b4ed364b857205734fe73328f Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Thu, 19 Nov 2026 16:17:30 +0000 Subject: [PATCH 2/5] debug: remove the panic declarations left unused by panic.c With the XTOS panic handler gone, nothing includes sof/debug/backtrace.h or the host arch/debug/backtrace.h it wraps, nothing calls the host arch_dump_regs() in arch/debug/panic.h, and dump_panicinfo() and panic_dump(), declared in the host rtos/panic.h, have no definition. Remove them. The host library keeps __panic() and the assertions. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- posix/include/rtos/panic.h | 4 -- src/include/sof/debug/backtrace.h | 11 ----- .../arch/host/include/arch/debug/backtrace.h | 45 ------------------- .../arch/host/include/arch/debug/panic.h | 24 ---------- 4 files changed, 84 deletions(-) delete mode 100644 src/include/sof/debug/backtrace.h delete mode 100644 src/kernel/arch/host/include/arch/debug/backtrace.h delete mode 100644 src/kernel/arch/host/include/arch/debug/panic.h diff --git a/posix/include/rtos/panic.h b/posix/include/rtos/panic.h index ca0578c51fa9..4ae6a716a05c 100644 --- a/posix/include/rtos/panic.h +++ b/posix/include/rtos/panic.h @@ -11,7 +11,6 @@ #include #include -#include #ifdef __ZEPHYR__ #error "This file should only be included in XTOS builds." @@ -30,9 +29,6 @@ "Add it to CMake's target with sof_append_relative_path_definitions." #endif -void dump_panicinfo(void *addr, struct sof_ipc_panic_info *panic_info); -void panic_dump(uint32_t p, struct sof_ipc_panic_info *panic_info, - uintptr_t *data) SOF_NORETURN; void __panic(uint32_t p, const char *filename, uint32_t linenum) SOF_NORETURN; /** panic dump filename and linenumber of the call diff --git a/src/include/sof/debug/backtrace.h b/src/include/sof/debug/backtrace.h deleted file mode 100644 index d0f67161c3fb..000000000000 --- a/src/include/sof/debug/backtrace.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright(c) 2020 Intel Corporation. All rights reserved. - */ - -#ifndef __SOF_DEBUG_BACKTRACE_H__ -#define __SOF_DEBUG_BACKTRACE_H__ - -#include - -#endif diff --git a/src/kernel/arch/host/include/arch/debug/backtrace.h b/src/kernel/arch/host/include/arch/debug/backtrace.h deleted file mode 100644 index e9abe3de0471..000000000000 --- a/src/kernel/arch/host/include/arch/debug/backtrace.h +++ /dev/null @@ -1,45 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright(c) 2020 Intel Corporation. All rights reserved. - */ - -#ifdef __SOF_DEBUG_BACKTRACE_H__ - -#ifndef __ARCH_DEBUG_BACKTRACE_H__ -#define __ARCH_DEBUG_BACKTRACE_H__ - -#include -#include -#include -#include - -/* architecture specific stack frames to dump */ -#define ARCH_STACK_DUMP_FRAMES 32 - -static inline void *arch_get_stack_ptr(void) -{ - void *frames[ARCH_STACK_DUMP_FRAMES]; - size_t frame_count; - size_t i; - char **symbols; - - frame_count = backtrace(frames, ARCH_STACK_DUMP_FRAMES); - symbols = backtrace_symbols(frames, frame_count); - - fprintf(stderr, "Dumping %zd stack frames.\n", frame_count); - - for (i = 0; i < frame_count; i++) - fprintf(stderr, "\t%s\n", symbols[i]); - - free(symbols); - - return NULL; -} - -#endif /* __ARCH_DEBUG_BACKTRACE_H__ */ - -#else - -#error "This file shouldn't be included from outside of sof/debug/backtrace.h" - -#endif /* __SOF_DEBUG_BACKTRACE_H__ */ diff --git a/src/kernel/arch/host/include/arch/debug/panic.h b/src/kernel/arch/host/include/arch/debug/panic.h deleted file mode 100644 index 85f47a5ecbbc..000000000000 --- a/src/kernel/arch/host/include/arch/debug/panic.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright(c) 2019 Intel Corporation. All rights reserved. - * - * Author: Tomasz Lauda - */ - -#ifdef __POSIX_RTOS_PANIC_H__ - -#ifndef __ARCH_DEBUG_PANIC_H__ -#define __ARCH_DEBUG_PANIC_H__ - -#include - -static inline void arch_dump_regs(void *dump_buf, uintptr_t stack_ptr, - uintptr_t *epc1) { } - -#endif /* __ARCH_DEBUG_PANIC_H__ */ - -#else - -#error "This file shouldn't be included from outside of XTOS's rtos/panic.h" - -#endif /* __POSIX_RTOS_PANIC_H__ */ From 011547b8378d33e0733be8d543c2b65fc6f9c840 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Wed, 18 Nov 2026 14:50:36 +0000 Subject: [PATCH 3/5] scripts: kernel_user_partition: classify the legacy LL domains as kernel The DMA single and multi channel and the Zephyr DMA LL scheduling domains, and the XTOS LL scheduler that ACP 6.0 still builds, set up interrupts and timers and include sof/kernel/platform.h. Like the legacy host and DAI drivers, they are kernel code that goes when the remaining platforms move to the Zephyr native drivers. Classify them as kernel sources. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- scripts/kernel_user_partition.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/kernel_user_partition.txt b/scripts/kernel_user_partition.txt index e857a20acc21..f2520a96faf4 100644 --- a/scripts/kernel_user_partition.txt +++ b/scripts/kernel_user_partition.txt @@ -19,11 +19,16 @@ [user-sources] src/* -# Kernel sources inside src/: src/kernel/ and the legacy drivers. +# Kernel sources inside src/: src/kernel/, and the legacy drivers and LL +# scheduling domains, which go with the legacy drivers. [not-user-sources] src/kernel/* src/audio/dai-legacy.c src/audio/host-legacy.c +src/schedule/dma_multi_chan_domain.c +src/schedule/dma_single_chan_domain.c +src/schedule/ll_schedule_xtos.c +src/schedule/zephyr_dma_domain.c # SOF headers that only kernel code may include. # Not listed on purpose: rtos/init.h, which only provides the From ca8837af24b7a9f73f5c19cab937d890dbb171f7 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Wed, 18 Nov 2026 14:50:59 +0000 Subject: [PATCH 4/5] scripts: check_kernel_includes: check the sources for kernel headers The kernel-only headers are moving to src/kernel/include, included as . Add a --sources mode that checks the source tree, without build directories, for such includes in user-space sources and headers. The headers are listed in the new [user-headers] manifest section: everything in src/ and zephyr/include, apart from the kernel sources and the kernel-only headers, that is over 600 headers today, including the ones local to modules that no CI configuration builds. This is the "no Signed-off-by: Liam Girdwood --- scripts/check_kernel_includes.py | 68 ++++++++++++++++++++++++++++++- scripts/kernel_user_partition.txt | 7 ++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/scripts/check_kernel_includes.py b/scripts/check_kernel_includes.py index d4e9a639043e..16eb9e22050b 100755 --- a/scripts/check_kernel_includes.py +++ b/scripts/check_kernel_includes.py @@ -24,13 +24,20 @@ checked builds are reported, so that they can be dropped from the list once they are clean in every configuration. +With --sources it checks the source tree instead of build directories: +kernel-only headers in src/kernel/include are included as +, and no user-space source or header may include one. +This covers code that no checked build compiles, and has no baseline. + Usage: check_kernel_includes.py [--strict] [--summary] [...] + check_kernel_includes.py --sources [--strict] """ import argparse import fnmatch import os +import re import subprocess import sys from collections import defaultdict @@ -122,9 +129,52 @@ def check_build(build_dir, manifest, sof_root, zephyr_base): return leaks, built +KERNEL_INCLUDE = re.compile(r'^\s*#\s*include\s*[<"](sof/kernel/[^>"]+)[>"]', re.M) + + +def source_files(sof_root): + """Return the files of the SOF source tree, relative to it.""" + try: + out = subprocess.run(['git', '-C', sof_root, 'ls-files'], + check=True, capture_output=True, text=True).stdout + return out.splitlines() + except (OSError, subprocess.CalledProcessError): + files = [] + for top, dirs, names in os.walk(sof_root): + dirs[:] = [d for d in dirs if d != '.git' and not d.startswith('build')] + files += [os.path.relpath(os.path.join(top, n), sof_root).replace(os.sep, '/') + for n in names] + return files + + +def check_sources(manifest, sof_root): + """Return {user-space file: [kernel header includes]} from the source tree.""" + user_src = manifest['user-sources'] + not_user = manifest['not-user-sources'] + user_hdr = manifest['user-headers'] + kernel_hdr = manifest['kernel-headers'] + + found = {} + for rel in source_files(sof_root): + if rel.endswith(SOURCE_EXTS): + if not matches(rel, user_src) or matches(rel, not_user): + continue + elif not (rel.endswith(('.h', '.hpp')) and matches(rel, user_hdr)) or \ + matches(rel, not_user) or matches(rel, kernel_hdr): + continue + path = os.path.join(sof_root, rel) + if not os.path.isfile(path): + continue + with open(path, encoding='utf-8', errors='replace') as f: + incs = KERNEL_INCLUDE.findall(f.read()) + if incs: + found[rel] = incs + return found + + def main(): parser = argparse.ArgumentParser(description=__doc__.split('\n', 1)[0]) - parser.add_argument('build_dirs', nargs='+', metavar='build-dir') + parser.add_argument('build_dirs', nargs='*', metavar='build-dir') parser.add_argument('--manifest', default=DEFAULT_MANIFEST) parser.add_argument('--sof-root', default=SOF_ROOT, help='SOF source directory the build directories were built from') @@ -135,9 +185,25 @@ def main(): 'includes a kernel-only header') parser.add_argument('--summary', action='store_true', help='only print per-header counts, not every source file') + parser.add_argument('--sources', action='store_true', + help='check the source tree for includes from ' + 'user-space code instead of build directories') args = parser.parse_args() manifest = parse_manifest(args.manifest) + + if args.sources: + if args.build_dirs: + parser.error('--sources cannot be combined with build directories') + found = check_sources(manifest, args.sof_root) + for src in sorted(found): + print(f'{src}:') + for inc in found[src]: + print(f'\t{inc}') + print(f'{len(found)} user-space files include headers from src/kernel/include') + return 1 if args.strict and found else 0 + if not args.build_dirs: + parser.error('build directories or --sources are required') zephyr_base = args.zephyr_base if os.path.isdir(args.zephyr_base) else None leaks = defaultdict(set) diff --git a/scripts/kernel_user_partition.txt b/scripts/kernel_user_partition.txt index f2520a96faf4..b8246ad9d479 100644 --- a/scripts/kernel_user_partition.txt +++ b/scripts/kernel_user_partition.txt @@ -30,6 +30,13 @@ src/schedule/dma_single_chan_domain.c src/schedule/ll_schedule_xtos.c src/schedule/zephyr_dma_domain.c +# Headers that user-space code may include, checked with --sources: they +# must not include headers from src/kernel/include. The kernel sources +# above and the [kernel-headers] below are excluded. +[user-headers] +src/* +zephyr/include/* + # SOF headers that only kernel code may include. # Not listed on purpose: rtos/init.h, which only provides the # SOF_MODULE_INIT() registration hook used by every module, and From 6094409f9b8f02ecdcdb7a28df157d3e29b5ff53 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Wed, 18 Nov 2026 14:51:37 +0000 Subject: [PATCH 5/5] ci: codestyle: fail on kernel-only includes from user-space code Run the include checker on the source tree in the codestyle workflow, so that a pull request that includes a header from src/kernel/include in user-space code fails without waiting for the firmware builds, and also when no CI configuration compiles the file. Describe it in the src/kernel README. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- .github/workflows/codestyle.yml | 11 +++++++++++ src/kernel/README.md | 3 +++ 2 files changed, 14 insertions(+) diff --git a/.github/workflows/codestyle.yml b/.github/workflows/codestyle.yml index fefa263e04a5..62251271221c 100644 --- a/.github/workflows/codestyle.yml +++ b/.github/workflows/codestyle.yml @@ -38,3 +38,14 @@ jobs: run: yamllint -f parsable -d "$yamllint_config" --strict .github/workflows/*.yml *.yml + + kernel-includes: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + filter: 'tree:0' + + - name: no kernel-only headers in user-space code + # see scripts/check_kernel_includes.py + run: python3 scripts/check_kernel_includes.py --sources --strict diff --git a/src/kernel/README.md b/src/kernel/README.md index 8e44f25d8462..f5ad04f9daa6 100644 --- a/src/kernel/README.md +++ b/src/kernel/README.md @@ -30,6 +30,9 @@ Kernel-only headers are in [`include/sof/kernel`](include/sof/kernel) and are in ``. The directory is on the include path of the firmware, the host library and the testbench, but not of LLEXT modules. Kernel-only headers that the host builds replace with their own versions, such as the `rtos/` headers, have not moved yet. +User-space code must not include anything from here: the `codestyle` CI workflow runs +`scripts/check_kernel_includes.py --sources --strict`, which fails when a user-space source or +header includes ``. 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