Skip to content

Commit

Permalink
xtensa: add MPU support for kernel mode
Browse files Browse the repository at this point in the history
This enables support for MPU on Xtensa. Currently this is
for kernel mode only.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
  • Loading branch information
dcpleung committed Jan 23, 2024
1 parent 72b3c3e commit 76e71a8
Show file tree
Hide file tree
Showing 7 changed files with 2,177 additions and 0 deletions.
150 changes: 150 additions & 0 deletions arch/xtensa/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,154 @@ config XTENSA_INSECURE_USERSPACE

endif # CPU_HAS_MMU

if CPU_HAS_MPU

menuconfig XTENSA_MPU
bool "Xtensa MPU Support"
select MPU
select SRAM_REGION_PERMISSIONS
select XTENSA_SMALL_VECTOR_TABLE_ENTRY
select EXPERIMENTAL
# FIXME: the target the MPU code developed on does not have
# cache or SMP capability. Need to verify functionalities
# with targets supporting these.
depends on !CACHE && !SMP
help
Enable support for Xtensa Memory Protection Unit.

if XTENSA_MPU

menuconfig XTENSA_MPU_CUSTOM_MEMFLAGS
bool "Override Default Memory Flags for MPU Regions"
help
Default memory flags for MPU regions is of type non-cacheable memory,
interruptible, non-bufferable, non-shareable, and no cache allocations.
These flags are used for memory of Zephyr image.

Enable this to override the default flags. Says N if unsure.

if XTENSA_MPU_CUSTOM_MEMFLAGS

choice XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE
prompt "System Type"
default XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE_NCM
help
Default MPU memory system type.

config XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE_DEVICE
bool "Device"
help
Default system type is Device.

config XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE_NCM
bool "Non-Cacheable Memory"
help
Default system type is Non-Cacheable Memory.

config XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE_CM
bool "Cacheable Memory"
help
Default system type is Cacheable Memory.

endchoice

config XTENSA_MPU_CUSTOM_MEMFLAGS_BUFFERABLE
bool "Bufferable"
depends on !XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE_CM
help
Memory is bufferable. Only valid for device and non-cacheable memory.

config XTENSA_MPU_CUSTOM_MEMFLAGS_INTERRUPTIBLE
bool "Interruptible"
depends on XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE_DEVICE
help
Memory is interruptible. Only valid for device memory.

config XTENSA_MPU_CUSTOM_MEMFLAGS_SHAREABLE
bool "Shareable"
depends on XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE_NCM
help
Memory is shareable. Only valid for non-cacheable memory.

choice
prompt "Shareable"
default XTENSA_MPU_CUSTOM_MEMFLAGS_INNER_SHAREABLE
depends on XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE_CM

config XTENSA_MPU_CUSTOM_MEMFLAGS_INNER_SHAREABLE
bool "Inner Shareable"
help
Memory is inner shareable. Only valid for cacheable memory.

config XTENSA_MPU_CUSTOM_MEMFLAGS_OUTER_SHAREABLE
bool "Outer Shareable"
help
Memory is outer shareable. Only valid for cacheable memory.

endchoice

choice
prompt "Cache type (bus)"
depends on XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE_CM
default XTENSA_MPU_CUSTOM_MEMFLAGS_BUS_WRITETHRU

config XTENSA_MPU_CUSTOM_MEMFLAGS_BUS_WRITEBACK
bool "Write-back"
help
Memory is write-back on bus transactions.

config XTENSA_MPU_CUSTOM_MEMFLAGS_BUS_WRITETHRU
bool "Write-through"
help
Memory is write-through on bus transactions.

endchoice

config XTENSA_MPU_CUSTOM_MEMFLAGS_BUS_READ_ALLOC
bool "Cache Allocate on Read (bus)"
depends on XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE_CM
help
Cache is to allocate on read during bus transactions.

config XTENSA_MPU_CUSTOM_MEMFLAGS_BUS_WRITE_ALLOC
bool "Cache Allocate on Write (bus)"
depends on XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE_CM
help
Cache is to allocate on write during bus transactions.

choice
prompt "Cache type (processor local)"
depends on !XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE_DEVICE
default XTENSA_MPU_CUSTOM_MEMFLAGS_LOCAL_WRITETHRU

config XTENSA_MPU_CUSTOM_MEMFLAGS_LOCAL_WRITEBACK
bool "Write-back"
help
Processor local cache is write-back.

config XTENSA_MPU_CUSTOM_MEMFLAGS_LOCAL_WRITETHRU
bool "Write-through"
help
Processor local cacheeis write-through.

endchoice

config XTENSA_MPU_CUSTOM_MEMFLAGS_LOCAL_READ_ALLOC
bool "Cache Allocate on Read (processor local)"
depends on !XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE_DEVICE
help
Processor local cache is to allocate on read.

config XTENSA_MPU_CUSTOM_MEMFLAGS_LOCAL_WRITE_ALLOC
bool "Cache Allocate on Write (processor local)"
depends on !XTENSA_MPU_CUSTOM_MEMFLAGS_TYPE_DEVICE
help
Processor local Cache is to allocate on write.

endif # XTENSA_MPU_CUSTOM_MEMFLAGS

endif # XTENSA_MPU

endif # CPU_HAS_MPU

endmenu
1 change: 1 addition & 0 deletions arch/xtensa/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ zephyr_library_sources_ifdef(CONFIG_USERSPACE userspace.S)
zephyr_library_sources_ifdef(CONFIG_XTENSA_SYSCALL_USE_HELPER syscall_helper.c)
zephyr_library_sources_ifdef(CONFIG_LLEXT elf.c)
zephyr_library_sources_ifdef(CONFIG_SMP smp.c)
zephyr_library_sources_ifdef(CONFIG_XTENSA_MPU mpu.c)

zephyr_library_sources_ifdef(
CONFIG_KERNEL_VM_USE_CUSTOM_MEM_RANGE_CHECK
Expand Down

0 comments on commit 76e71a8

Please sign in to comment.