Commit Graph

475 Commits

Author SHA1 Message Date
Alberto Escolar Piedras 95e06e8663 cmake: Fix uses of old SOC path
In quite a few places in the cmake files
${SOC_DIR}/${ARCH}/${SOC_PATH}
was used to get to something in the soc folder,
but these are only defined for soc_v1.
socv2 defines a full SOC_V2_DIR.
Let's define a common variable for the full path which
can be used in other cmake files,
and correct the current uses.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-03-01 15:49:58 +01:00
Maciej Kusio 352b50bfc9 xtensa: add support for cores without NMI
Some Xtensa cores do not support NMI, so XCHAL_HAVE_NMI=0 and
XCHAL_NMILEVEL won't be defined at all causing
arch/xtensa/include/xtensa-asm2-s.h to throw compilation error.

Fixes: #67855

Signed-off-by: Maciej Kusio <maciejkusio@meta.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-02-28 17:35:54 +00:00
Flavio Ceolin b30d088d37 xtensa: irq: Remove CURR_CPU
Use _current_cpu->id instead of CURR_CPU since that works
with/without multicore and contains additional checks.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-02-08 09:05:14 +01:00
Anas Nashif d7678f1694 xtensa: move to use system cache API support for coherency
Remove custom implementation and use system cache interface instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-02-03 13:42:33 -05:00
Daniel Leung 02baa658d2 xtensa: remove unneeded addi in xtensa_userspace_enter
There is no need to do a addi to a1 because it is
immediately overwritten anyway.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-02-01 13:09:53 -06:00
Daniel Leung 39d9d0a2fc xtensa: remove ARG_UNUSED from arch_syscall_oops
ssf is being passed to xtensa_arch_kernel_oops() so there is
no need to mark ssf with ARG_UNUSED.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-02-01 13:09:53 -06:00
Daniel Leung 5d8b43feff xtensa: only need ZSR_FLUSH if CONFIG_KERNEL_COHERENCE
The ZSR_FLUSH scratch register is only needed if kconfig
CONFIG_KERNEL_COHERENCE is enabled. So update gen_zsr.py
for that.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-02-01 13:09:53 -06:00
Daniel Leung 545cf8cd2f xtensa: print THREADPTR when dumping stack
Print THREADPTR when dumping stack just like other registers.
There is no need to guard that behind CONFIG_USERSPACE.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-02-01 13:09:53 -06:00
Flavio Ceolin 2590ea280c xtensa: mmu: Optimize autorefill invalidation
There is no need to sync in every xtlb invalidation. Sync only
after all tlb autofill ways invalidation.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-01-19 13:50:02 +01:00
Peter Mitsis 5c18a00d37 arch: xtensa: Use wsr.lowercase over wsr.UPPERCASE
wsr.UPPERCASE can lead to compiler errors when UPPERCASE matches
a macro defined in the special register header file.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2024-01-17 09:55:57 +01:00
Peter Mitsis 2075a1b770 arch: xtensa: Use rsr.lowercase over rsr.UPPERCASE
rsr.UPPERCASE can lead to compiler errors when UPPERCASE matches
a macro defined in the special register header file.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2024-01-17 09:55:57 +01:00
Flavio Ceolin 8356ec21e5 xtensa: mmu: Fix mmu initialization
The constant used to calculate TLB entries for the way six was wrong
and causing an integer overflow. Consequently only the first 512MB where
being unmapped from the TLB.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-01-11 10:05:22 +01:00
Daniel Leung fa25c0b0b8 xtensa: mmu: invalidate mem domain TLBs during page table swap
This adds a kconfig to enable invalidating the TLBs related to
the incoming thread's memory domain during page table swaps.
It provides a workaround, if needed, to clear out stale TLB
entries used by the thread being swapped out. Those stale
entries may contain incorrect permissions and rings.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-27 15:59:05 +00:00
Johan Hedberg 3fbf12487c kernel: Introduce a way to specify minimum system heap size
There are several subsystems and boards which require a relatively large
system heap (used by k_malloc()) to function properly. This became even
more notable with the recent introduction of the ACPICA library, which
causes ACPI-using boards to require a system heap of up to several
megabytes in size.

Until now, subsystems and boards have tried to solve this by having
Kconfig overlays which modify the default value of HEAP_MEM_POOL_SIZE.
This works ok, except when applications start explicitly setting values
in their prj.conf files:

$ git grep CONFIG_HEAP_MEM_POOL_SIZE= tests samples|wc -l
     157

The vast majority of values set by current sample or test applications
is much too small for subsystems like ACPI, which results in the
application not being able to run on such boards.

To solve this situation, we introduce support for subsystems to specify
their own custom system heap size requirement. Subsystems do
this by defining Kconfig options with the prefix HEAP_MEM_POOL_ADD_SIZE_.
The final value of the system heap is the sum of the custom
minimum requirements, or the value existing HEAP_MEM_POOL_SIZE option,
whichever is greater.

We also introduce a new HEAP_MEM_POOL_IGNORE_MIN Kconfig option which
applications can use to force a lower value than what subsystems have
specficied, however this behavior is disabled by default.

Whenever the minimum is greater than the requested value a CMake warning
will be issued in the build output.

This patch ends up modifying several places outside of kernel code,
since the presence of the system heap is no longer detected using a
non-zero CONFIG_HEAP_MEM_POOL_SIZE value, rather it's now detected using
a new K_HEAP_MEM_POOL_SIZE value that's evaluated at build.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2023-12-20 11:01:42 +01:00
Luca Burelli 4d86162989 llext: merge llext_mem and llext_section enums
The only difference in the two enums are some entries related to
relocation sections. However, these entries are not used in the
code, so they can be safely removed, along with the mapping function.

Use LLEXT_MEM_* to avoid confusion with low-level "section" names.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2023-12-14 19:06:55 +00:00
Anas Nashif e25f31ab78 arch: guard more code with CONFIG_EXCEPTION_DEBUG
It should be possible to disable exception debug, which is enabled by
default to reduce image size. Add missing guards now that the option is
cross architecture.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-12-14 09:32:27 +01:00
Anas Nashif a7e8391e31 debug: coredump: handle xtensa coredump like everyone else
There should not be any special handling for coredump with xtensa.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-12-14 09:32:27 +01:00
Daniel Leung 0636e52eff xtensa: rename xtensa_asm2.c to vector_handlers.c
Rename xtensa_asm2.c to have a more meaningful name to actually
reflect the content of the file. This file is mostly about
handling interrupts and exceptions (via the predefined vectors
in Xtensa core).

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung b2f20d65b3 xtensa: remove z_arch_get_next_switch_handle
Fold z_arch_get_next_switch_handle() into return_to(). This is
not exactly an arch interface, and is simple enough to be
moved into return_to().

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung a819bfb2d5 xtensa: rename z_xtensa to simply xtensa
Rename the remaining z_xtensa stuff as these are (mostly)
under arch/xtensa.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung 6d5e0c25a6 xtensa: rename z_xtensa_irq to simple xtensa_irq
This gets rid of the z_ prefix.

Note that z_xt_*() are being used by the HAL so they cannot be
renamed.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung 8bf20ee975 xtensa: mmu: rename prefix z_xtensa to xtensa_mmu
This follows the idea to remove any z_ prefix. Since MMU has
a large number of these, separate out these changes into one
commit to ease review effort.

Since these are no longer have z_, these need proper doxygen
doc. So add them too.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung 711622cbba xtensa: remove get_sreg macro from fatal.c
There is no in-file user. So remove it.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung 004e68ccea xtensa: move exception handling func to arch internal header
z_xtensa_dump_stack() and z_xtensa_exccause() are both arch
internal functions that should not be exposed in public API.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung 43b0b48de7 xtensa: move files under core/include/ into include/
Header files under arch/xtensa/include are considered internal
to architecture. There is really no need for two places to
house architecture internal header files.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung d9b34c6108 xtensa: move irq management stuff into irq_manage.c...
... from xtensa_asm2.c. Other architectures have
z_irq_spurious() and *_irq_is_enabled() test in irq_manage.c.
So follow the trend here.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung 264391fe88 xtensa: refactor thread related stuff into its own file...
... from xtensa_asm2.c.

Everything has been stuffed inside xtensa_asm2.c where
they are all mangled together. So extract thread related
stuff into its own file.

Note that arch_float_*() may not be thread related but
most other architectures put them into thread.c. So we
also do it here.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung aa64b1f98e xtensa: move arch_spin_relax into smp.c
arch_spin_relax() does not really fit into the scheme of
xtensa_asm2.c as it is mainly about handling interrupts
and exceptions. So move it into smp.c, similar to other
architectures which arch_spin_relax() defined.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung 106061b307 xtensa: rename files with hyphens to underscores
Simply to provide some consistencies on file naming under
arch/xtensa.

These are all internally used files and are not public.
So there is no need to provide a deprecation path for
them.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung 43990d1c0e xtensa: remove xtensa-asm2.h
xtensa-asm2.h only contains the function declaration of
xtensa_init_stack() which is only used in one file. So
make the actual implementation a static function in that
file. Also there is really no need to expose stack init
function as arch public API. So remove xtensa-asm2.h.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung 6694390ac8 xtensa: cleanup Kconfig file
* Wording on CONFIG_SIMULATOR_XTENSA
* Remove "default n" as default is no anyway.
* Remove some tabs as we almost never indent inside a if block
  in Zephyr.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung fc7ef47ed5 xtensa: remove CONFIG_XTENSA_NO_IPC
There is no in-tree user. Also, it is misleading as we use
SCOMPARE1 for spinlock too, not just IPC.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Daniel Leung d17524b86c xtensa: remove CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC from arch
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC should be defined at the SoC
or the board level since Xtensa cores are high configurable.
The default is just for ISS (Instruction Set Simulator). So
remove it from the arch level.

The xt-sim board is the only one in tree that is targeting
the ISS, so add it there.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-12-13 09:41:24 +01:00
Anas Nashif 8e5c3ce616 arch: xtensa: check for xt-clang instead of xcc-clang
Check against new variant name. xcc-clang usage is deprecated.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-12-12 18:48:14 +00:00
Flavio Ceolin 0a7251e365 xtensa: mmu: Fix tlb shootdown
Fix the way we read the current l1 page table set in the mmu.
We use it check if the current page table is different from the
running thread.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-12-12 10:58:03 +01:00
Flavio Ceolin a19d415c35 xtensa: mmu: Fix xtensa_ptevaddr_get
We use ptevaddr_get to know the address the page table is set.
It happens that for this use, we should just use the ptebase field
of ptevaddr register.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-12-12 10:58:03 +01:00
Flavio Ceolin 7382d7052b xtensa: mmu: Fix partition permission
The ring field in the pte mapping a memory partition should
be based in the partition attribute and not in the domain
asid that is used only to set the ASID (in RASID) position for
user ring.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-12-12 10:57:57 +01:00
Guennadi Liakhovetski 03519afb84 llext: xtensa: add support for local symbol relocations
Add support for relocating local symbols, as specified in the
.rela.dyn section.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2023-12-01 10:08:12 -05:00
Flavio Ceolin 683accaef0 xtensa: mmu: Include missing header
This file uses inline functions declared in cache.h and consequently
has to include that file.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-11-27 19:57:46 +01:00
Flavio Ceolin c47880af0d arch/xtensa: Add new MMU layer
Andy Ross re-implementation of MMU layer with some subtle changes,
like re-using existent macros, fix page table cache property when
direct mapping it in TLB.

From Andy's original commit message:

This is a reworked MMU layer, sitting cleanly below the page table
handling in the OS.  Notable differences from the original work:

+ Significantly smaller code and simpler API (just three functions to
  be called from the OS/userspace/ptable layer).

+ Big README-MMU document containing my learnings over the process, so
  hopefully fewer people need to go through this in the future.

+ No TLB flushing needed.  Clean separation of ASIDs, just requires
  that the upper levels match the ASID to the L1 page table page
  consistently.

+ Vector mapping is done with a 4k page and not a 4M page, leading to
  much more flexibility with hardware memory layout.  The original
  scheme required that the 4M region containing vecbase be mapped
  virtually to a location other than the hardware address, which makes
  confusing linkage with call0 and difficult initialization
  constraints where the exception vectors run at different addresses
  before and after MMU setup (effectively forcing them to be PIC
  code).

+ More provably correct initialization, all MMU changes happen in a
  single asm block with no memory accesses which would generate a
  refill.

Signed-off-by: Andy Ross <andyross@google.com>
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-11-21 15:49:48 +01:00
Flavio Ceolin 8dd84bc181 arch: xtensa: Rename xtensa_mmu.c to ptables.c
Initial work to split page table manipulation from
mmu hardware interaction.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-11-21 15:49:48 +01:00
Andy Ross e7e8f6655c arch/xtensa: #include cleanup
This file doesn't need the asm2 header, and the preprocessor logic
around whether to include the backtrace header is needless (all it
does is declare functions).

Signed-off-by: Andy Ross <andyross@google.com>
2023-11-21 15:49:48 +01:00
Flavio Ceolin b7d96ab42a xtensa: userspace: Warning about impl security
Add a Kconfig option (and build warning) alerting about the problem
of the kernel spilling register in behave of the userspace.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-11-21 15:49:48 +01:00
Flavio Ceolin dd36389879 arch: xtensa: Not use TLS to store current thread
Xtensa clears out threadptr durint ISR when userspace
is enabled.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-11-21 15:49:48 +01:00
Flavio Ceolin 1247f8465c xtensa: userspace: Supports tls on userspace
Use thread local storage to check whether or not a thread is running
in user mode. This allows to use threadptr to properly support tls.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-11-21 15:49:48 +01:00
Daniel Leung 0d79481540 xtensa: userspace: only write 0xAA to stack if INIT_STACKS
Only clear the user stack to 0xAA if CONFIG_INIT_STACKS is
enabled. Otherwise, write 0x00 as if the stack is in BSS.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-11-21 15:49:48 +01:00
Daniel Leung 0e7def1977 xtensa: selectively init interrupt stack at boot
During arch_kernel_init(), the interrupt stack is being
initialized. However, if the current in-use stack is
the interrupt stack, it would wipe all the data up to
that point in stack, and might result in crash. So skip
initializing the interrupt stack if the current stack
pointer is within the boundary of interrupt stack.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-11-21 15:49:48 +01:00
Daniel Leung 6252fcfccf xtensa: userspace: simplify syscall helper
Consolidate all syscall helpers into one functions.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-11-21 15:49:48 +01:00
Daniel Leung d9f643d007 xtensa: mmu: do not map heap if not using heap
Do not map the heap area by default if we are not using
heap at all.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-11-21 15:49:48 +01:00
Flavio Ceolin 9a33c400a1 xtensa: mmu: Fix possible race condition on tlb shootdown
We need to use the mmu spin lock when invalidating the cache during
tlb shootdown, otherwise it is possible that this happens when another
thread is updating the page tables.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-21 15:49:48 +01:00