Commit graph

6,247 commits

Author SHA1 Message Date
Alberto Escolar Piedras
6f427044dd arch: posix: cmake: Remove unnecessary line
This variable is not set to anything.
This line has always been just bogus.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-01-03 10:20:34 +01:00
Alberto Escolar Piedras
a2f45762f1 arch posix: cleanup NATIVE_APPLICATION support remnants
NO_POSIX_CHEATS was a macro used to avoid including the content of a
header (`posix_cheats.h`) which allowed building applications in the
POSIX architecture without the native simulator, avoiding collisions
between some embedded symbols and those from the host C library.

Support for this way of building, and this header and macro were
removed in e150ffb92c, but these users
were forgotten. This was harmless, but let's just clean it up now.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-01-03 10:19:34 +01:00
Guennadi Liakhovetski
8c200c0f2f xtensa: mmu: (cosmetic) clean up pointer types
Use void * cleanly: avoid needless type-casts and use void * for
generic pointers instead of uint8_t *.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2025-12-19 07:53:07 -06:00
Sylvio Alves
f8d2e00a0e includes: remove duplicated entries in zephyr-tree
Remove duplicated #include directives within the same
preprocessor scope across the Zephyr tree.

Duplicates inside different #ifdef branches are preserved
as they may be intentional.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-12-17 13:57:38 -05:00
Lucien Zhao
9e42f9fc34 arch: arm: mpu: Add Kconfig options for SRAM Write-Through cache policy
- CONFIG_ARM_MPU_SRAM_WRITE_THROUGH: enables Write-Through cache policy
  for SRAM regions instead of default Write-Back

Includes corresponding MPU attribute macros for ARMv7-M and ARMv8-M
architectures. Maintains backward compatibility with existing
configurations.

Signed-off-by: Lucien Zhao <lucien.zhao@nxp.com>
2025-12-17 14:35:50 +02:00
Mathieu Choplain
dc5e85a8d0 kernel/arch: remove zephyr,ccm initialization code
doc: dts: api: remove documentation of chosen `zephyr,ccm`

The `zephyr,ccm` chosen was an ST-specific property which has been replaced
by the generic `zephyr,dtcm`. Remove region initialization code from the
common arch init code (+ BSS zeroing from common XIP init code).

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2025-12-09 14:54:36 -05:00
Daniel Leung
701cbfbc23 xtensa: mmu: may need to copy entries during L2 table dup
During L2 page table duplication, there are cases where we
should copy the table over instead of restoring the PTEs.
Add the ability to copy the table over.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00
Daniel Leung
8d0103b4ad xtensa: mmu: spin lock for counter manipulation
This adds a spinlock to guard page table counter updates.
For some reasons, without this, xt-clang generated code would
result in incorrect counter update possibly due to memory
access ordering (though GCC generated code works fine without
the spin lock).

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00
Daniel Leung
3e33978078 cache: deprecate CONFIG_DOUBLEMAP
Use CONFIG_CACHE_HAS_MIRRORED_MEMORY_REGIONS instead.
The new kconfig reflects more correctly on what is going on
in hardware. Also, this is not enabled by default if CPU
cache is not coherent. CPU cache can be incoherent and yet
there are no mirrored memory regions. Those relying on this
deprecated default behavior has their config adding
CONFIG_CACHE_HAS_MIRRORED_MEMORY_REGIONS separately.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00
Daniel Leung
0540d274c0 xtensa: remove CONFIG_XTENSA_RPO_CACHE
This removes the following kconfigs:

() CONFIG_XTENSA_RPO_CACHE
() CONFIG_XTENSA_CACHED_REGION
() CONFIG_XTENSA_UNCACHED_REGION

The associated feature is actually SoC specific and not general
architecture feature. Since the only user of these have its own
implementation, we can now safely remove these.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00
Daniel Leung
a82a09a314 soc: intel_adsp: SoC specific cached/uncached regions support
This re-implements the CONFIG_XTENSA_RPO_CACHE and its cached
and uncached region support in the SoC layer. This is in
preparation for removing RPO cache in the architecture layer
as this is a SoC feature and not an architecture feature.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00
Daniel Leung
a8c1df6b80 cache: adds CONFIG_SOC_CACHE
This allows SoC to define their custom cache related functions
and are used by sys_cache_*() functions.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00
Daniel Leung
169304813a cache: move arch_mem_coherent() into cache subsys
arch_mem_coherent() is cache related so it is better to move it
under cache subsys. It is renamed to sys_cache_is_mem_coherent()
to reflect this change.

The only user of arch_mem_coherent() is Xtensa. However, it is
not an architecture feature. That's why it is moved to the cache
subsys.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00
Daniel Leung
301abd8630 xtensa: imply CONFIG_ARCH_HAS_RESERVED_PAGE_FRAMES if MMU
The Zephyr linker script usually puts something before
z_mapped_start (where .text is), for example, vecbase vectors.
So we need to reserve those space or else k_mem_map() would be
mapping those which may result in faults.

To avoid mapping there, CONFIG_ARCH_HAS_RESERVED_PAGE_FRAMES
needs to be used. Since it is common when MMU is enabled, we
should enable it by default using imply. All current Xtensa
MMU SoCs all have this selected anyway. Using 'imply' instead
of 'select' is to allow it to be disabled if so desired.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00
Daniel Leung
48537aeb1f xtensa: CONFIG_ARCH_HAS_USERSPACE should be in arch layer
CONFIG_ARCH_HAS_USERSPACE should be in arch layer as MMU and MPU
support both in the arch layer.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00
Daniel Leung
27b1c3138f xtensa: mmu: remove CONFIG_XTENSA_MMU_DOUBLE_MAP
This removes CONFIG_XTENSA_MMU_DOUBLE_MAP and its associated
code. The double mapping of a page into both cached and
uncached memory regions should be done in SoC and application,
as it gives finer control on what actually is being mapped.
For example, if a page only needs to mapped in cached region,
there is no need to map it in the uncached region. This may
save the need to allocate a L2 page table for it, and saves
some memory.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00
Daniel Leung
1bc72e68c6 xtensa: mmu: allow SoC to override default mappings
Adds kconfig CONFIG_XTENSA_MMU_USE_DEFAULT_MAPPINGS for arch
code to initialize the page tables with a few default mappings
covering text, data, BSS and RODATA. Disabling this allows
the SoC to customize and fine-tune the mappings if needed.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00
Daniel Leung
04dd427bf1 xtensa: cleanup crt1.S
Removes some unused macros.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00
Firas Sammoura
7dc9e87f6c riscv: pmp: Add API to change region permissions at runtime
The new function 'z_riscv_pmp_change_permissions' provides a mechanism
to modify the Read, Write, and Execute (R/W/X) permissions of an
existing PMP region based on its memory attribute index.

Signed-off-by: Firas Sammoura <fsammoura@google.com>
2025-12-08 15:01:37 -05:00
Alberto Escolar Piedras
8c194648e4 arch/posix: Support cross-compiling
Support cross-compiling from one Linux host for another Linux target.
This is done by allowing users to set NATIVE_TARGET_HOST for cmake
which will override the automatic detection.
At the same time, add support for building for 32bit arm targets.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-12-05 13:38:48 +02:00
Adrian Warecki
6cd7cfa104 xtensa: mmu: ptables: Set PPN in region_map_update to fix memory mapping
Set PPN (Physical Page Number) in L2 entry in the region_map_update
function to ensure correct mapping for memory that was not previously
mapped based on xtensa_soc_mmu_ranges.

When a new memory domain is created, the arch_mem_domain_init function
allocates new ptables using the dup_table function. This function only
copies original L2 entries created from xtensa_soc_mmu_ranges with
OPTION_SAVE_ATTRS. Entries added later by arch_mem_map are replaced with
XTENSA_MMU_PTE_L2_ILLEGAL and have PPN (Physical Page Number) set to zero.

When adding a new partition to a memory domain, the update_region function
is used. It sets new access attributes in the L2 table without setting the
PPN value. As a result, it does not work correctly for memory that was not
previously mapped based on xtensa_soc_mmu_ranges.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
2025-12-01 11:09:09 +01:00
Adrian Warecki
942b1e8571 xtensa: mmu: ptables: Introduce PTE_PPN_SET macro
Add macro PTE_PPN_SET to simplify setting the physical page
number assigned in the page table entry.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
2025-12-01 11:09:09 +01:00
Adrian Warecki
f5f56113fe xtensa: mmu: ptables: Introduce PTE_PPN_GET macro
Add macro PTE_PPN_GET to simplify retrieval of the physical page
number assigned to a page table entry.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
2025-12-01 11:09:09 +01:00
Jisheng Zhang
2c1e1ad7c9 arch: arm: dwt: use DCB instead of CoreDebug
commit a763207962 ("arch: arm: dwt: use the cmsis_6 macro
unconditionally") use cmsis_6 macro unconditionally, we can use DCB
instead of CoreDebug macro unconditionally.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
2025-12-01 08:26:46 +01:00
Sudan Landge
9962bc12cf arch: arm: fix start of the privileged stack
Make sure that arch.mode is set with appropriate flags before setting up
the privileged stack start.

Fixes #99895

Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2025-11-28 20:57:53 -05:00
Firas Sammoura
e0f2b4e354 riscv: pmp: Add support for unlocked global PMP entries
Adds the Kconfig option PMP_NO_LOCK_GLOBAL to remove the PMP Lock bit
usage. The global entry is an internal detail of the driver
implementation and should not be reflected in the user interface. This
allows the application to dynamically reconfigure the PMP entries
without requiring hard reset. This is essential for firmware that
performs an RO-to-RW jump. By keeping these system entries unlocked,
higher-privileged M-mode code can dynamically reconfigure memory
permissions during the secure handover process, which is not possible if
the entries are permanently locked during early boot.

Signed-off-by: Firas Sammoura <fsammoura@google.com>
2025-11-28 09:49:50 +00:00
Sudan Landge
1f030c303a boards: fvp_aemv8r_aarch32: fix sample.bindesc
Make sure bindesc are placed right after the vector table and fix ci
failure with sample.bindesc for fvp_baser_aemv8r/fvp_aemv8r_aarch32.
Without this change the bindesc are placed at a location that is not
mapped leading to a data abort while running the sample.

Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2025-11-27 16:01:27 +01:00
Sudan Landge
c1ded6b9b6 arch: arm64: fix definition of ARCH_HAS_STACKWALK
Move ARCH_HAS_STACKWALK under CPU_CORTEX_A section since only Cortex-A
implements arch_stack_walk(), while Cortex-R does not.

Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2025-11-27 16:01:27 +01:00
Anas Nashif
5f91f5fb38 doc: fix reference to kernel.h
Fix reference to kernel.h and add zephyr namespace where it was missing.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-11-26 12:11:27 -05:00
Daniel Leung
a6fe6a8f7d xtensa: fix unused func warning on l2_page_tables_counter_inc
xt-clang complains about l2_page_tables_counter_inc() being
unused but not GCC. So fix that by using it somewhere else.

Fixes #99753

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-11-25 20:22:54 -05:00
Appana Durga Kedareswara rao
4e8cafe641 arch: arm64: mmu: Call k_panic() when translation tables exhausted
When CONFIG_MAX_XLAT_TABLES is too small and new_table() cannot allocate
a translation table, the system must halt rather than continue with
undefined behavior.

This change ensures k_panic() is called after reporting the error,
preventing the system from proceeding when it runs out of translation
tables. Additionally, adds printk() fallback for configurations where
CONFIG_LOG is disabled to ensure the error is always visible.

Signed-off-by: Appana Durga Kedareswara rao <appana.durga.kedareswara.rao@amd.com>
2025-11-24 14:57:25 -05:00
Peter van der Perk
7d9e8923cc arch: arm: cortex_m: Allow VTOR to be relocated to TCM
Allows you to relocate the vector table from Flash to ITCM/DTCM to
minimize interrupt latency. TCM offers single-cycle access compared to
multi-cycle SRAM reads and even slower flash reads. This improves exception
handling speed for real-time workloads.

Signed-off-by: Peter van der Perk <peter.vanderperk@nxp.com>
2025-11-24 08:47:28 +01:00
Carles Cufi
db0c34d836 c standard: Default to C17 as the minimum required C standard
C99 has been the minimum required C standard version for Zephyr since
its inception. After multiple attempts and discussions, a decision has
been made to upgrade to C17 going forward.
This commits replaces the default C standard from C99 to C17 in the
configuration and build system, and deprecates support for the older
standards.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2025-11-20 09:04:46 -05:00
Mykyta Poturai
f3b9d18711 xen: Add support for changing Xen Sysctl interface version
Add a new Kconfig option CONFIG_XEN_SYSCTL_INTERFACE_VERSION that allows
to change the version of the Sysctl interface used by Zephyr to issue
sysctl hypercalls.
For now versions 0x15 is supported.

Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
Signed-off-by: Dmytro Firsov <dmytro_firsov@epam.com>
2025-11-20 09:01:06 -05:00
Mykyta Poturai
4f6fb8989a xen: Add support for changing Xen Domctl interface version
Add a new Kconfig option CONFIG_XEN_DOMCTL_INTERFACE_VERSION that allows
to change the version of the Domctl interface used by Zephyr to issue
domctl hypercalls. Add compile-time checks to enable or disable certain
Domctl operations based on the selected Domctl interface version.
For now versions 0x15, 0x16, and 0x17 are supported.

Also it required to correctly guard domctl call that were not supported
prior to specified version.

Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
Signed-off-by: Dmytro Firsov <dmytro_firsov@epam.com>
2025-11-20 09:01:06 -05:00
Dmytro Semenets
f131d5f3ed drivers: xen: dom0: add Xen sysctl hypercall
This hypercall can be used get some information about physical machine
and running guests:

- sysctl hypercall "xen_sysctl_getphysinfo" allows read information about
physical machine: number CPUs, memory sizes, hardware capabilities, etc.

- sysctl hypercall "xen_sysctl_getdomaininfolist" returns array of domain
info structures that provide information about particular domain(s).

Signed-off-by: Dmytro Semenets <dmytro_semenets@epam.com>
Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
Signed-off-by: Dmytro Firsov <dmytro_firsov@epam.com>
2025-11-20 09:01:06 -05:00
Dmytro Semenets
eaaa5400dc drivers: xen: add xen version hypercall
Xen API contains hypercall, which allows domains to identify Xen
version, that is currently used on the system. It can be used to check
if current version is supported by Zephyr or to change behavior of the
drivers or services.

Signed-off-by: Dmytro Semenets <dmytro_semenets@epam.com>
Signed-off-by: Dmytro Firsov <dmytro_firsov@epam.com>
2025-11-20 09:01:06 -05:00
TOKITA Hiroshi
571f5b92a0 drivers: xen: add DMOP hypercall wrappers
Add wrappers for following XEN_DMOP_* hypercalls.
These enables Xen device model control path:
dm_op provides operations to create/manage the ioreq server
so guest MMIO accesses are trapped and handled by the hypervisor.
These are guarded by CONFIG_XEN_DMOP.

- dmop
  - dmop_create_ioreq_server
    XEN_DMOP_create_ioreq_server
  - dmop_map_io_range_to_ioreq_server
    XEN_DMOP_map_io_range_to_ioreq_server
  - dmop_set_ioreq_server_state
    XEN_DMOP_set_ioreq_server_state
  - dmop_nr_vcpus
    XEN_DMOP_nr_vcpus
  - dmop_set_irq_level:
    XEN_DMOP_set_irq_level

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
2025-11-20 06:06:43 -05:00
Chris Friedt
27180d2fc5 arch: riscv + xtensa + x86: workaround needed for LLVM linker
Due to slight differences in the way that LLVM and GNU linkers work,
the call to `z_stack_space_get()` is not dead-stripped when linking
with `lld` but it is dead-stripped when linking with GNU `ld`.

The `z_stack_space_get()` function is only available when
`CONFIG_INIT_STACKS` and `CONFIG_THREAD_STACK_INFO` are defined.

The issue is reproducible (although requires building LLVM and
setting up some environment variables) and goes away with the proposed
workaround.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-11-18 19:53:10 -05:00
Nicolas Pitre
106d3db360 arch: arm64: Increase MAX_XLAT_TABLES for userspace tests
Memory protection and userspace tests require more MMU translation
tables than the default. Without this increase, tests fail with:

  E: CONFIG_MAX_XLAT_TABLES too small
  ASSERTION FAIL [ret == 0] @ arch/arm64/core/mmu.c:1244
	privatize_page_range() returned -12

Increase defaults when both USERSPACE and TEST are enabled:
- 32 tables for SMP configurations
- 24 tables for non-SMP configurations

This fixes:
- sample.kernel.memory_protection.shared_mem (all platforms)
- rtio.api.userspace (v8a, v9a)
- rtio.api.userspace.submit_sem (v8a, v9a)
- portability.posix.common.userspace

Consequently the demand paging test needed adjustment to its
qemu_cortex_a53 configs to keep working as this test is highly
sensitive to the amount of available free memory.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2025-11-18 17:49:40 -05:00
Nicolas Pitre
425af7ad06 arch: arm64: Increase stack sizes for userspace with FPU
Increase ARM64 stack sizes to accommodate deeper call stacks in
userspace and SMP configurations when FPU_SHARING is enabled:

- PRIVILEGED_STACK_SIZE: 1024 → 4096 bytes (with FPU_SHARING)
- TEST_EXTRA_STACK_SIZE: 2048 → 4096 bytes (with FPU_SHARING)

The default 1KB privileged stack is insufficient for ARM64 userspace
syscalls when FPU context switching is enabled.

Symptom: Userspace tests crash with Data Abort (EC 0x24) near stack
boundaries during syscalls, particularly on SMP configurations where
multiple threads exercise FPU lazy switching.

Fixes previously failing CI test on fvp_base_revc_2xaem SMP variants:
- kernel.threads.dynamic
- Multiple userspace tests with FPU_SHARING enabled

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2025-11-18 17:49:40 -05:00
Nicolas Pitre
ffd08f5385 arch: arm64: Implement SVE context switching for ARMv9-A
Implement Scalable Vector Extension (SVE) context switching support,
enabling threads to use SVE and SVE2 instructions with lazy context
preservation across task switches.

The implementation is incremental: if only FPU instructions are used
then only the NEON access is granted and preserved to minimize context
switching overhead. If SVE is used then the NEON context is upgraded to
SVE and then full SVE access is granted and preserved from that point
onwards.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2025-11-18 17:49:40 -05:00
Nicolas Pitre
051623c808 boards: arm: fvp: Add Cortex-A320 board variant support
Add Cortex-A320 support to the unified FVP board structure with ARMv9.2-A
specific configuration parameters.

New board target:
- fvp_base_revc_2xaem/a320

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2025-11-18 17:49:40 -05:00
Nicolas Pitre
2aef4fbe5b arch: arm64: Add ARMv9-A architecture and Cortex-A510 CPU support
Add ARMv9-A architecture support with Cortex-A510 CPU as the default
processor for generic ARMv9-A targets.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2025-11-18 17:49:40 -05:00
Yong Cong Sin
3c5807f6ec arch: riscv: stacktrace: support stacktrace in early system init
Add support for stacktrace in dummy thread which is used to run
the early system initialization code before the kernel switches
to the main thread.

On RISC-V, the dummy thread will be running temporarily on the
interrupt stack, but currently we do not initialize the stack
info for the dummy thread, hence check the address against the
interrupt stack.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2025-11-18 17:38:22 -05:00
Daniel Leung
2bfb7e403d x86: ruff format on gen_mmu.py
Format gen_mmu.py via ruff.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-11-18 11:22:46 +01:00
Daniel Leung
39ed039155 x86: fix ruff issues on gen_mmu.py
Fixes issues found by ruff on gen_mmu.py.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-11-18 11:22:46 +01:00
Daniel Leung
c19ff1c199 x86: ruff format on gen_idt.py
Format gen_idt.py via ruff.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-11-18 11:22:46 +01:00
Daniel Leung
b52b6716f6 x86: fix ruff issues on gen_idt.py
Fixes issues found by ruff on gen_idt.py.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-11-18 11:22:46 +01:00
Daniel Leung
6b0ac6e30b x86: ruff format on gen_gdt.py
Format gen_gdt.py via ruff.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-11-18 11:22:46 +01:00