Commit graph zephyr/arch/xtensa
Author SHA1 Message Date
Daniel Leung
f5b63a674a xtensa: check BSA bounds before printing fatal exception
print_fatal_exception() read bsa->exccause before checking whether the
BSA lies within stack bounds, and the out-of-bounds branch then read
bsa->excvaddr anyway. Either access can fault again while reporting
the original fault.

Do the bounds check first. When the BSA is invalid, print only the CPU
id and the BSA and stack pointer values, then drain the hook and return
as before. The EXCCAUSE line is printed after the check.

Assisted-by: Claude:claude-sonnet-5.5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-29 19:44:22 -04:00
Daniel Leung
cf290917dc xtensa: harden stack bound checks in fault reporting
xtensa_backtrace_get_next_frame() only checked that the stack pointer
was within the stack, but then read the 16-byte base save area below
it, which could lie outside the stack.

xtensa_is_outside_stack_bounds() computed addr + sz without checking
for wrap-around, so a range near the top of the address space could be
reported as within the stack.

Check the base save area itself in the backtrace, and treat a wrapping
addr + sz as out of bounds. The latter also rejects a stack pointer
below 16 in the backtrace, where sp - 16 wraps.

Assisted-by: Claude:claude-sonnet-5.5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-29 19:44:22 -04:00
Anas Nashif
ff883873f8 arch: xtensa: use k_thread_is_user_thread()
Replace the open-coded tests of K_USER in a thread's user_options with
k_thread_is_user_thread(). No functional change.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-10-29 17:34:11 -04:00
Daniel Leung
2cffdb3d97 xtensa: mpu: add and fix doxygen
Document the stack permission function and the boot region tables.
Add missing parameter and return value descriptions, and drop the
non-existent access_rights parameter from the mpu_map_region_restore()
documentation. No functional change.

Assisted-by: Copilot:claude-opus-5.5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-28 22:46:15 -04:00
Daniel Leung
8cd6563ac9 xtensa: mmu: add and fix doxygen in page table code
Document missing doxygen doc for functions, fixing missing
parameter name, and fixing incorrect return value doc.
No functional change.

Assisted-by: Copilot:claude-opus-5.5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-28 22:46:15 -04:00
Daniel Leung
25ab0a0003 xtensa: add doxygen to debug support code
Document the coredump, GDB stub, backtrace and semihosting functions,
and add the missing return value description of
get_gdb_exception_reason(). No functional change.

Assisted-by: Copilot:claude-opus-5.5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-28 22:46:15 -04:00
Daniel Leung
0523e5e165 xtensa: add doxygen to exception handling
Document the vector handler and fatal error functions.
No functional change.

Assisted-by: Copilot:claude-opus-5.5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-28 22:46:15 -04:00
Daniel Leung
9dca5e6aba xtensa: add doxygen to thread support code
Document the initial stack frame setup and xtensa_hifi_disown()
stub. No functional change.

Assisted-by: Copilot:claude-opus-5.5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-28 22:46:15 -04:00
Tahsin Mutlugun
03b808b11c arch: xtensa: Drop hard requirement for unsigned load/store emulation
Unsigned load/store emulation does not support exceptions caused by
Very Long Instruction Words (VLIW), so it requires VLIW generation to
be disabled.

However, applications may still benefit from VLIW instructions when
they can guarantee that no such exceptions will occur. Drop the hard
requirement so applications can override this behavior when appropriate.

Signed-off-by: Tahsin Mutlugun <Tahsin.Mutlugun@analog.com>
2026-10-28 22:40:47 -04:00
Aditya Ganesh
01d1af8524 arch: xtensa: core: Flush l2 tables in dup_l2_tables
This change flushes the l2 page table in dup_l2_table
instead of dup_l2_table_if_needed to avoid a scenario
where the l2 page table is modified but not flushed

Signed-off-by: Aditya Ganesh <aditya.ganesh@intel.com>
2026-10-28 22:39:51 -04:00
Benjamin Cabé
a513c5d929 arch: xtensa: disable lazy HiFi on interrupt-driven switch
With CONFIG_XTENSA_LAZY_HIFI_SHARING, xtensa_switch() clears the HiFi
bit in CPENABLE so that the incoming thread traps on its first HiFi
instruction and gets its own registers loaded.

A switch done on interrupt return does not go through xtensa_switch()
and left CPENABLE as it was. A thread preempting the HiFi owner could
then execute HiFi instructions without trapping, overwriting the
registers of the owner, which later resumed with the other thread's
values.

Clear the HiFi bit in return_to() when the interrupt returns to a
different thread.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-10-28 22:34:49 -04:00
Mark Inderhees
0b4ebc0ff0 xtensa: honor CONFIG_SKIP_BSS_CLEAR during startup
Platforms that initialize BSS before entering Zephyr can select
CONFIG_SKIP_BSS_CLEAR, but the Xtensa core startup still clears it.

Guard the startup clearing block with CONFIG_SKIP_BSS_CLEAR so those
platforms can preserve their initialized BSS contents. Normal startup
continues to clear BSS by default.

Validated normal clearing and BSS preservation on qemu_xtensa/dc233c.
The hello_world smoke test also passed.

Assisted-by: Codex:gpt-6
Signed-off-by: Mark Inderhees <markind@meta.com>
2026-10-28 21:51:15 -04:00
Kai Vehmanen
f619c179fc arch: xtensa: mmu: skip unmapped L1 entries in region_map_update()
When the last page mapped in an L2 table is unmapped,
l2_page_table_unmap() releases the L2 table and marks the L1 entry
illegal, in the kernel page tables and in all memory domains. If a
memory domain partition covering that range is removed afterwards,
region_map_update() takes the PPN of the illegal L1 entry as an L2
table pointer and operates on it while holding the MMU spinlocks.
This corrupts memory and leaves the CPU dead without any fatal error
report.

There is nothing mapped in such a range, so there is nothing to
update. Skip pages whose L1 entry is illegal, as l2_page_table_unmap()
already does.

Seen on NVL-S with SOF, where unloading the last LLEXT module in the
library region unmaps its memory before removing its partitions from
the LL user memory domain.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
2026-10-22 18:24:45 +02:00
Sylvio Alves
979e655d46 xtensa: mask interrupts before leaving the cross-stack call
After the interrupt handler returns, the cross-stack call goes
back to the interrupted frame and switches A1 to the context
handle while still at the handler's interrupt level. A nested
interrupt taken there either builds its save area on top of
the outer one or spills the interrupted function's caller
registers relative to the handle, so the thread later resumes
from corrupted state.

Raise the interrupt level before returning from the handler
call in all builds, as userspace builds already did, and drop
the now redundant masking in the caller.

Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-10-21 11:41:50 +02:00
Daniel Leung
8fefdcc4e5 xtensa: export symbol xtensa_is_user_context()
xtensa_is_user_context() needs to be exported for used with
LLEXT if the SoC does not have hardware thread pointer
register.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-19 10:22:28 +02:00
Benjamin Cabé
16592affe2 arch: xtensa: save the boolean register
Floating-point compares write their result to the BR register, which
the interrupt and context switch code did not save, so a thread
preempted between a compare and the branch on its result could take
the wrong branch. Save and restore BR with the other special registers
on cores with the boolean option.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5.5
2026-10-16 15:20:38 -05:00
Pisit Sawangvonganan
692c2fd825 arch: {arm, common, sparc, x86, xtensa}: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within:
- `arch/arm`
- `arch/common`
- `arch/sparc`
- `arch/x86`
- `arch/xtensa`

Assisted-by: Claude:claude-sonnet-5-5 codespell
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2026-10-06 22:39:13 +02:00
Liam Girdwood
f43453290d xtensa: add generic triple fault breadcrumb API
When a double exception escalates to a triple fault, the Xtensa CPU
escapes into an unrecoverable spin loop.

Add a weak xtensa_triple_fault_breadcrumb symbol, called via CALL0 from
the shared _TripleFault handler in xtensa_asm2_util.S before entering the
spin loop. The default is a no-op ret; an SoC family that wants to record
triple fault state links in its own strong override.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
2026-09-28 07:35:28 -04:00
Liam Girdwood
1e2b3bc58f xtensa: add generic fatal exception breadcrumb API
When a fatal exception is taken on Xtensa, crash diagnostics are lost
if no console or mtrace output is available.

Add a generic architecture-level fatal exception breadcrumb API:
- xtensa_fatal_breadcrumb() provides a weak no-op default.
- XTENSA_RECORD_FATAL_BREADCRUMB() macro hooks into the default
  exception switch in vector_handlers.c.
- An SoC family that supports breadcrumbs provides a strong override
  to record the faulting PC, exception cause, and virtual address into
  its own diagnostic storage.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
2026-09-28 07:35:28 -04:00
Sylvio Alves
699c613f07 arch: xtensa: carry backtrace mask and cause in the frame
The window-increment mask and the exception cause were kept in
file-scope statics written only by xtensa_backtrace_print(). Two
cores panicking at once clobbered each other's values, and a
direct caller of the public xtensa_backtrace_get_next_frame() ran
with a stale mask and got wrong PCs.

Move both into struct xtensa_backtrace_frame_t and pass them to
the PC fixup, making it a pure function. Output is unchanged.

Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-09-24 09:57:04 +02:00
Jamie McCrae
1909f76910 kconfig: Correctly have EXPERIMENTAL prompt
Fixes various issues with Kconfigs, including:
  - Using the wrong indentation
  - Not having [EXPERIMENTAL] in the prompt, or not having it at
    the end
  - Wrongly stating the CONFIG_EXPERIMENTAL is needed to enable
    an experimental Kconfig

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-09-21 16:27:52 -04:00
Daniel Leung
2756f2c863 xtensa: mmu: simplify TLB shootdown
Since we are caching all the necessary register values to be
used when switching page tables, we can now remove the extra
bits inside xtensa_mmu_tlb_shootdown() originally used to
prevent re-computing all those register values. We can now
simply call xtensa_mmu_set_paging().

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-09-13 17:59:42 -04:00
Daniel Leung
60c9284620 xtensa: mmu: no TLB shootdown if not needed during thread add
Inside arch_mem_domain_thread_add(), if the thread is not
running on other CPUs and it is not migrating between domains,
there is no need to send TLB shootdown to other CPUs. Next time
the thread is scheduled, the new page tables will be used.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-09-13 17:59:42 -04:00
Daniel Leung
c546cb235f xtensa: mmu: memory mappings to return error value not panic
This changes the error handling of the call chain of both
arch_mem_map() and arch_mem_unmap() in Xtensa to return errors
if possible when actions fail, instead of simply causing
kernel panic. This allows the error code to be propagated to
the caller so it can be handled properly.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-09-11 05:23:20 -04:00
Daniel Leung
c21850fdd6 arch: change arch_mem_unmap() to return an error code
Mirror the arch_mem_map() change and give arch_mem_unmap() the same
treatment: change the prototype to return int instead of void, so
architecture code has a consistent way to report unmapping failures.

Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-09-11 05:23:20 -04:00
Daniel Leung
aec25bce22 arch: change arch_mem_map() to return an error code
Previously arch_mem_map() was a void function, so architecture
code had no consistent way to report mapping failures to callers
other than panicking or asserting. Change arch_mem_map() to
return int.

Note that this mostly maintains the k_panic() calls unless
the error is easy to handle (like invalid arguments). Each
architecture will need to be amended in the future to properly
handle the error conditions. Also some of the users are
converted to do k_panic() after failure. This is to keep
the signature change commit easier to review.

Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-09-11 05:23:20 -04:00
Kai Vehmanen
c770d5c5d1 xtensa: initialize ptables to NULL for new threads
Initialize ptables for newly created threads if CONFIG_XTENSA_MMU is
enabled. This is required as as arch_mem_domain_thread_add() uses a
non-NULL arch.ptables to detect that the thread is migrating from a
previous memory domain and reset its stack there. For a brand new thread
- in particular a dynamically allocated one (k_object_alloc()), whose
backing memory is not zeroed - this field would otherwise hold garbage
and the "migration" would walk a bogus page table.

Issue found when debugging DSP panics on Intel ADSPs (EXCAUSE 13) with
SOF user threads running on secondary cores.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
2026-09-09 18:14:29 -04:00
Benjamin Cabé
3910c807e2 arch: xtensa: only save EXCVADDR in the level 1 vector
EXCVADDR describes exceptions, not interrupts, and only the level 1
vector serves exceptions. The frames built by interrupt-only vectors
never have their excvaddr slot read (the C interrupt handlers do not
look at it, and nothing restores it on exit), so stop saving it
there. Fatal errors raised from ISRs still get a proper EXCVADDR:
they trap through the level 1 exception vector, which keeps the save.

Benchmarks on qemu_xtensa/dc233c (QEMU icount shift=6, 1 insn = 1
cycle) and ESP32-S3 (m5stack_stamps3 at 240 MHz), exercising a
level 3 software interrupt:

* thread_metric interrupt (higher is better):
  - qemu_xtensa/dc233c: 759968 -> 762439 (+0.3%)
  - ESP32-S3: 9281007 -> 9304992 (+0.3%)
* latency_measure: unchanged within +/-1 cycle alignment noise (its
  ISR metrics start timing inside the ISR, after vector entry)
* code size: unchanged (vector slots are fixed-size)

Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-08-23 14:43:05 -04:00
Jyri Sarha
8ab6cd9190 arch: xtensa: mmu: defer TLB flush on ASID free using dirty bitmap
Previously, every asid_free() immediately flushed TLB autorefill
entries on all cores via IPI. This is expensive for workloads that
rapidly create and destroy memory domains (e.g. SOF DP tasks), since
every domain teardown triggers a system-wide TLB invalidation even
when freed ASIDs may never be reused before fresh ones are available.

Add a second bitarray (asid_dirty) where freed ASIDs are placed
without touching the TLB. asid_alloc() uses sys_bitarray_alloc() on
asid_used to find a free ASID; when none remain, performs a single
TLB flush and XORs dirty bits back into asid_used (clearing the
in-use bits for reclaimed ASIDs), amortizing the flush cost across
many alloc/free cycles.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
2026-08-13 16:20:15 -07:00
Jyri Sarha
3590f4b45b arch: xtensa: mmu: add PTEVADDR 0x60000000 option, cap ASID range
Add CONFIG_XTENSA_MMU_PTEVADDR_60000000 as a new PTEVADDR base address
choice in the Kconfig.

The PTEVADDR auto-refill mechanism places a self-referencing entry in
each memory domain's L1 page table at position:

  (CONFIG_XTENSA_MMU_PTEVADDR >> 22) + ASID

With the default of 0x20000000 (L1 base position 128), ASIDs above 127
place the self-reference at L1 positions 256+, which on platforms like
intel_adsp collides with the uncached memory alias region at VA
0x40000000 (L1 position 256).

Add ASID_PTEVADDR_MAX = 256 - (PTEVADDR >> 22) - 1 and define
ASID_LAST_USER as MIN(XTENSA_MMU_SHARED_ASID - 1, ASID_PTEVADDR_MAX).
ASIDs beyond this limit are marked in-use during bitmap initialization.

Setting PTEVADDR to 0x60000000 (L1 base position 384) places all
possible self-reference entries at L1 positions 384-639, avoiding
collisions with both the uncached alias region (L1 256-383) and cached
SRAM (L1 640+).

For PTEVADDR 0x20000000: max usable ASID = 127.
For PTEVADDR 0x60000000: max usable ASID = 254 (no cap).

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
2026-08-13 16:20:15 -07:00
Jyri Sarha
cf244b983d arch: xtensa: mmu: add ASID recycling for memory domains
Previously, ASIDs were allocated monotonically and never reused. When a
memory domain was destroyed in arch_mem_domain_deinit(), its ASID was
lost. On platforms where short-lived memory domains are created
frequently (e.g. SOF DP tasks that each get their own domain), the
8-bit ASID space would eventually be exhausted.

Replace the monotonic counter with a bitmap-based allocator using
sys_bitarray covering the full 256-entry ASID space. Bit indices map
directly to ASID values with no translation: set bit (1) = in use or
reserved, clear bit (0) = free. Reserved ASIDs (0-3 and 255) are
marked in-use during initialization so they can never be allocated.

asid_alloc() uses sys_bitarray_alloc() to find a free ASID.
asid_free() releases the ASID and invalidates TLB autorefill entries
on all cores to prevent stale mappings from the previous holder.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
2026-08-13 16:20:15 -07:00
Daniel Leung
78ca43befc xtensa: skip mmu/mpu swapping if same memory domain
When switching between threads in xtensa_switch, if incoming
and outgoing threads share the same memory domain, there is
no need to swap the page tables or MPU entries as they are
the same.

For MMU, CONFIG_XTENSA_MMU_FLUSH_AUTOREFILL_DTLBS_ON_SWAP must
be enabled to skip the swapping, as flushing of data TLBs is
quite expensive. Without the need to flush data TLBs, the page
table swapping is done via the macro SWAP_PAGE_TABLE which is
relatively lightweight. So there is no need to all the extra
checking code.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-08-12 10:03:08 -04:00
Daniel Leung
54a45000c0 xtensa: move CONFIG_ARCH_HAS_DIRECTED_IPIS to SoC
Xtensa architecture does not have native inter-processor
interrupts and must rely on mechanism on SoC or board to do
that. Because of this, the architecture should not select
CONFIG_ARCH_HAS_DIRECTED_IPIS and should let SoC or board
layer to do that, where CONFIG_SCHED_IPI_SUPPORTED is also
being selected.

Note that CONFIG_XTENSA_LAZY_HIFI_SHARING is now dependent
on CONFIG_ARCH_HAS_DIRECTED_IPIS as it uses directed IPI.
Due to that it keeps sending IPI under the other has saved
HIFI state, it is not really appopriate to broadcast IPIs.
That's why it can only be enabled when directed IPI is
supported.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-08-07 16:26:21 -04:00
Hongquan Li
d9db3de0d4 arch: xtensa: fix arch_user_string_nlen() reading past maxsize
The Xtensa implementation validated the whole maxsize range with
arch_buffer_validate() before calling strnlen(), which breaks the
k_usermode_string_nlen() contract in two ways:

- With maxsize == 0 the string must not be touched at all, but the
  validation probed the MPU/MMU region containing the pointer anyway
  (alignment rounds a zero size up to a full region), wrongly
  failing with -1 for inaccessible addresses.

- The validation required user mode accessibility, while the API
  contract explicitly does not guarantee it: user access is checked
  by the syscall marshalling layer via K_SYSCALL_MEMORY_READ() once
  the length is known. Kernel mode callers measuring kernel strings
  (e.g. a buffer on the kernel stack) were wrongly rejected.

Return early for maxsize == 0, and check kernel mode readability
with the new xtensa_buffer_is_kernel_readable() (MPU and MMU
variants) instead of arch_buffer_validate().

On the MMU side, extract a shared mem_buffer_validate() that takes a
ring parameter, so arch_buffer_validate() and the new
xtensa_buffer_is_kernel_readable() share the same logic without
duplication.

Fixes zephyrproject-rtos/zephyr#113722

Signed-off-by: Hongquan Li <hongquan.li@processmission.com>
2026-08-07 06:47:54 -04:00
Daniel Leung
7d6f33b716 xtensa: mmu: panic if arch_mem_map fails
When __arch_mem_map() fails to map a page, arch_mem_map() should
panic instead of continuing mapping the remaining pages.
Otherwise, there would be hole in the memory map which results
in confusing errors.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-07-27 14:41:33 +02:00
Mike J. Chen
3177dd4fb5 xtensa: change how XTENSA_ENABLE_BACKTRACE is enabled
Instead of every new xtensa core having to modify xtensa_backtrace.c
and provide a header file with custom functions needed by the common
xtensa backtrace functions to validate stack and code addresses, now
xtensa_backtrace.c uses default weak functions that the soc can replace
with their own implementations.

Modify the current in-tree instances that used to have custom helper
functions to provide the standardize weak replacements.

Signed-off-by: Mike J. Chen <mjchen@google.com>
Co-authored-by: Filip Kokosinski <fkokosinski@antmicro.com>
Signed-off-by: Filip Kokosinski <fkokosinski@antmicro.com>
2026-07-27 14:41:22 +02:00
Lauren Murphy
21a30f3f9a llext: correct got entry reads in xtensa elf
Re-routes remaining GOT entry reads through
read_got_entry. Missed in #108528.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2026-07-22 17:09:10 -04:00
Anas Nashif
eec6a8f52a arch: x86, xtensa: support the idle-hook CPU load backend
Both architectures wait for the interrupt with interrupts enabled (x86
"sti; hlt", Xtensa "waiti 0"), so the wake-up ISR runs before the
idle-exit hook and can reschedule away from the idle thread. The CPU load
module therefore closes the idle window at ISR entry instead, which means
these architectures need to emit sys_trace_isr_enter().

- x86: the ia32 interrupt stub already emits the hook, but only under
  CONFIG_TRACING_ISR. Emit it under CONFIG_SYS_IDLE_HOOKS as well. Also
  restore the idle-exit hook after the halt as a fallback for a wake-up
  that ran no ISR; closing the window is idempotent, so it is a no-op in
  the common case. Only ia32 is enabled: intel64 has no ISR entry hook.
- Xtensa: the interrupt entry had no hook at all. Emit
  sys_trace_isr_enter() from the common C interrupt handler, which also
  gives Xtensa the ISR tracing it was missing.

Select ARCH_HAS_CPU_IDLE_HOOKS from both, and document in the capability's
help text the two ways an architecture can close the idle window.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-07-17 11:55:28 -04:00
Anas Nashif
25d08114e9 arch: gate idle notification hooks on SYS_IDLE_HOOKS
The architecture idle paths call sys_trace_idle() and
sys_trace_idle_exit() to notify subscribers when the CPU enters and
leaves the idle state. These calls were guarded by CONFIG_TRACING,
which tied idle-time accounting to the tracing subsystem even though
no tracing backend is required to service the hooks.

Introduce a hidden Kconfig symbol, SYS_IDLE_HOOKS, that any subsystem
needing these notifications can select, and have TRACING select it.
Switch the idle-path guards in every architecture and SoC that emits
the hooks from CONFIG_TRACING to CONFIG_SYS_IDLE_HOOKS. Because
TRACING selects the new symbol, existing tracing behaviour is
unchanged; the change only lets non-tracing consumers receive the
hooks.

This is a prerequisite for building the CPU load module without the
tracing subsystem.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-07-17 11:55:28 -04:00
Lauren Murphy
6e245d5d37 lib/sys: add sys prefix to word granular access functions
Adds sys_ prefix to functions and typedef of the
word granular access library, as it is a sys API.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2026-07-15 19:04:01 -04:00
Daniel Leung
439718a598 xtensa: remove CPU mask pin only special code path
This removes all the extra code path when pin only CPU mask
and kernel coherence are both enabled. The original idea was
that with CPU pinning only, we could skip all the stack
manipulation since threads are not going to migreate between
CPUs until they get pinned to another CPUs. However, this
creates an issue where a thread is created on one CPU and
its stack being populated for startup at this CPU. Then it
gets pinned to another CPU. The other CPU does not know that
it is first starting the thread and will need to invalidate
the cache to grab the new stack content. This problem also
applies to migration between CPUs as there is no code to
manipulate the cache on stack. To support the skipping of
cache manipulation with pin only CPU mask would require
some invasive changes to kernel. At this point, the only
Xtensa SoCs requiring kernel coherence are not using pin
only CPU mask. So we are safe to remove the special code
path, and also we unify stack coherence operations to
minimize differences.

Fixes #112850

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-07-15 19:02:55 -04:00
Anas Nashif
e7893844b7 xtensa: remove dead z_arch_irq_connect_dynamic
arch/xtensa/core/irq_manage.c still defines the dynamic IRQ connect
routine under its pre-2019 z_arch_ name, which nothing references
since the z_arch_* to arch_* interface rename. The __weak
arch_irq_connect_dynamic() fallback in arch/common/dynamic_isr.c
silently took over, so the multi-level variant that routes to
z_soc_irq_connect_dynamic() never runs, and the only implementation
of that SoC hook (intel_adsp cavs) has had no caller ever since.

The common weak fallback is functionally equivalent on cavs: the
cavs intc driver registers IRQ_PARENT_ENTRY_DEFINE and
CAVS_ISR_TBL_OFFSET defaults to 2ND_LVL_ISR_TBL_OFFSET, so the
generic z_get_sw_isr_table_idx() computes the same table slot the
hand-rolled SoC hook did. Reviving the routing would also break
other multi-level Xtensa SoCs (ace, mt8xxx, imx8 DSPs) that never
provided the hook. Remove the dead functions, the hook declaration
and its cavs implementation instead.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-07-14 20:08:55 -04:00
Lauren Murphy
5295cb345b llext: support word granular access instr mem for xtensa
Adds LLEXT support for executing out of word granular
access instruction memory on Xtensa. This is achieved by
copying the text region onto the instruction heap
(assumed in instruction memory) but saving the
ELF address for use as the base address in
calculating relocation rel_addr (the location of the
relocation). Any rel_addr landing in the text region
is recalculated using the heap address instead.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
Signed-off-by: Anthony Giardina <anthony.giardina@intel.com>
2026-07-08 17:10:58 +01:00
Lauren Murphy
7a2c4bc9d9 arch: instr mem api
Adds arch-level instruction memory API with functions
for memcpying / memsetting and determining whether a
region is in instruction memory. Implement API for
Xtensa and ESP32, with support for word granular access.
Adds definitions for instruction memory to
Xtensa ESP32 platforms.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2026-07-08 17:10:58 +01:00
Mike J. Chen
ba8bb9a20f arch: xtensa: change backtrace to use EXCEPTION_DUMP
The backtrace code was either calling the arch exception dump
hook or printk based on the value of its own config called
CONFIG_XTENSA_BACKTRACE_EXCEPTION_DUMP.

However, this made fault output inconsistent when CONFIG_LOG is enabled
because other output (like xtensa_dump_stack()) would use the macro
EXCEPTION_DUMP(), which would use LOG_ERR instead of printk. Fault output
would be a mix of log lines for register dumps and printk lines for
backtrace (no domains, timestamps, etc).

This commit changes backtrace to use the EXCEPTION_DUMP() macro so output
now is consistent. It also fixes an issue where if printk was going to
the logging subsystem (CONFIG_LOG_PRINTK=y), because the printk calls in
backtrace had no '\n' termination, the output would be lost in the log
format buffer.

Signed-off-by: Mike J. Chen <mjchen@google.com>
2026-06-30 11:53:23 -04:00
Hiren Virapara
bc594b461c arch: xtensa: extend syscall helper to invoke levels 0-3
CONFIG_XTENSA_SYSCALL_USE_HELPER currently only routes the 4/5/6-argument
syscall invocations through out-of-line helper functions. Toolchains that
reject inline-asm fixed-register operands in inlinable functions still
fail to build the 0-3 argument variants.

Add xtensa_syscall_helper_args_0..3 and route arch_syscall_invoke0..3
through them, gated behind a new opt-in
CONFIG_XTENSA_SYSCALL_USE_HELPER_ALL (default n, depends on
XTENSA_SYSCALL_USE_HELPER). This keeps the default behaviour unchanged -
the 0-3 argument syscalls stay on the inline fast path - and only routes
the low-argument variants through the helpers for toolchains that need
it, so there is no performance impact unless the option is explicitly
enabled. The inline-asm fast path is preserved under the #else branch.

Signed-off-by: Hiren Virapara <Hiren.Virapara@amd.com>
2026-06-29 11:28:50 +02:00
Daniel Leung
1704f47ac6 xtensa: mpu: fix idx_e may be used uninitialized
Complier complains that idx_e may be used uninitialized.
So set the default as 0 so that the for loop where it can be
used uninitialized would be an no-op.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-06-23 17:41:00 -04:00
Daniel Leung
8801f171ac xtensa: mpu: rework region add function
Some issues found with previous region add mechanism:

() Previous mechanism cannot add new entry before the first
   enabled entry.
() There are some cases where inserting a region would not
   preserve access rights and memory type correctly.

This reworks the mechanism to fix these issue. Also remove
assertion within mpu_map_region_add() and let the caller
decide what to do.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-06-23 09:11:38 -04:00
Daniel Leung
0963a24416 xtensa: mpu: replace 0xFFFFFFFFU with #define END_OF_MEMORY_ADDR
Simply to get rid of magic numbers with a more meaningful name.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-06-23 09:11:38 -04:00
Daniel Leung
f99b7dd0f4 xtensa: mpu: remove CONFIG_XTENSA_MPU_DEFAULT_MEM_TYPE
With the xtensa_mpu_mem_type_ranges[] array, the SoC or board
should be the one dictating memory types of various memory
regions. There is no need for this kconfig to be there and
we can use the defaults for the architecture.

Note that the previous P_NA_U_NA access rights are replaced
with the default one, as it should reflect the background map
where it is be used.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-06-23 09:11:38 -04:00