kernel: expose k_mem_partition_attr_t outside User mode
This commit exposes k_mem_partition_attr_t outside User Mode, so we can use struct k_mem_partition for defining memory partitions outside the scope of user space (for example, to describe thread stack guards or no-cacheable MPU regions). A requirement is that the Zephyr build supports Memory protection. To signify this, a new hidden, all-architecture Kconfig symbol is defined (MPU). In the wake of exposing k_mem_partition_attr_t, the commit exposes the MPU architecture-specific access permission attribute macros outside the User space context (for all ARCHs), so they can be used in a more generic way. Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit is contained in:
parent
ccf813c22a
commit
39bf24a9bd
10 changed files with 18 additions and 13 deletions
|
@ -393,6 +393,14 @@ config CPU_HAS_MPU
|
|||
help
|
||||
This option is enabled when the CPU has a Memory Protection Unit (MPU).
|
||||
|
||||
config MEMORY_PROTECTION
|
||||
bool
|
||||
# Omit prompt to signify "hidden" option
|
||||
help
|
||||
This option is enabled when Memory Protection features are supported.
|
||||
Memory protection support is currently available on ARC, ARM, and x86
|
||||
architectures.
|
||||
|
||||
config MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
|
||||
bool
|
||||
# Omit prompt to signify "hidden" option
|
||||
|
|
|
@ -31,6 +31,7 @@ config ARC_MPU
|
|||
depends on CPU_HAS_MPU
|
||||
select ARC_CORE_MPU
|
||||
select THREAD_STACK_INFO
|
||||
select MEMORY_PROTECTION
|
||||
select MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT if ARC_MPU_VER = 2
|
||||
help
|
||||
Target has ARC MPU (currently only works for EMSK 2.2/2.3 ARCEM7D)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
config ARM_MPU
|
||||
bool "ARM MPU Support"
|
||||
depends on CPU_HAS_MPU
|
||||
select MEMORY_PROTECTION
|
||||
select THREAD_STACK_INFO
|
||||
select ARCH_HAS_EXECUTABLE_PAGE_BIT
|
||||
select MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT if !(CPU_HAS_NXP_MPU || ARMV8_M_BASELINE || ARMV8_M_MAINLINE)
|
||||
|
|
|
@ -64,6 +64,7 @@ config X86_IAMCU
|
|||
menu "Memory Management"
|
||||
config X86_MMU
|
||||
bool "Enable Memory Management Unit"
|
||||
select MEMORY_PROTECTION
|
||||
help
|
||||
This options enables the memory management unit present in x86. Enabling
|
||||
this will create boot time page table structure.
|
||||
|
|
|
@ -243,7 +243,7 @@
|
|||
|
||||
#endif /* CONFIG_X86_PAE_MODE */
|
||||
|
||||
#ifdef CONFIG_X86_USERSPACE
|
||||
#ifdef CONFIG_X86_MMU
|
||||
|
||||
/* Flags which are only available for PAE mode page tables */
|
||||
#ifdef CONFIG_X86_PAE_MODE
|
||||
|
@ -297,7 +297,7 @@
|
|||
|
||||
#endif /* CONFIG_X86_PAE_MODE */
|
||||
|
||||
#endif /* CONFIG_X86_USERSPACE */
|
||||
#endif /* CONFIG_X86_MMU */
|
||||
|
||||
#ifndef _ASMLANGUAGE
|
||||
#include <zephyr/types.h>
|
||||
|
|
|
@ -155,7 +155,6 @@ extern "C" {
|
|||
#endif /* CONFIG_USERSPACE */
|
||||
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
#ifdef CONFIG_ARC_MPU
|
||||
#ifndef _ASMLANGUAGE
|
||||
#include <arch/arc/v2/mpu/arc_mpu.h>
|
||||
|
@ -217,7 +216,6 @@ extern "C" {
|
|||
"start address of the partition must align with 32.")
|
||||
#endif
|
||||
#endif /* CONFIG_ARC_MPU*/
|
||||
#endif /* CONFIG_USERSPACE */
|
||||
|
||||
#ifndef _ASMLANGUAGE
|
||||
/* Typedef for the k_mem_partition attribute*/
|
||||
|
|
|
@ -252,7 +252,7 @@ extern "C" {
|
|||
#define _ARCH_THREAD_STACK_BUFFER(sym) \
|
||||
((char *)(sym) + MPU_GUARD_ALIGN_AND_SIZE)
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
#ifdef CONFIG_ARM_MPU
|
||||
#ifdef CONFIG_CPU_HAS_ARM_MPU
|
||||
#ifndef _ASMLANGUAGE
|
||||
#include <arch/arm/cortex_m/mpu/arm_mpu.h>
|
||||
|
@ -323,8 +323,8 @@ extern "C" {
|
|||
" and greater than or equal to minimum MPU region size." \
|
||||
"start address of the partition must align with minimum MPU \
|
||||
region size.")
|
||||
#endif /* CONFIG_CPU_HAS_ARM_MPU */
|
||||
#endif /* CONFIG_USERSPACE */
|
||||
#endif /* CONFIG_CPU_HAS_NXP_MPU */
|
||||
#endif /* CONFIG_ARM_MPU */
|
||||
|
||||
#ifndef _ASMLANGUAGE
|
||||
/* Typedef for the k_mem_partition attribute*/
|
||||
|
|
|
@ -129,7 +129,6 @@ struct arm_mpu_region_attr {
|
|||
|
||||
typedef struct arm_mpu_region_attr arm_mpu_region_attr_t;
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
#ifndef _ASMLANGUAGE
|
||||
/* Read-Write access permission attributes */
|
||||
#define K_MEM_PARTITION_P_NA_U_NA (NO_ACCESS_Msk | NOT_EXEC)
|
||||
|
@ -162,4 +161,3 @@ typedef struct arm_mpu_region_attr arm_mpu_region_attr_t;
|
|||
#define K_MEM_PARTITION_IS_EXECUTABLE(attr) \
|
||||
(!((attr) & (NOT_EXEC)))
|
||||
#endif /* _ASMLANGUAGE */
|
||||
#endif /* USERSPACE */
|
||||
|
|
|
@ -139,7 +139,6 @@ struct arm_mpu_region_attr {
|
|||
|
||||
typedef struct arm_mpu_region_attr arm_mpu_region_attr_t;
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
#ifndef _ASMLANGUAGE
|
||||
/* Read-Write access permission attributes */
|
||||
#define K_MEM_PARTITION_P_RW_U_RW (P_RW_U_RW_Msk | NOT_EXEC)
|
||||
|
@ -168,4 +167,3 @@ struct arm_mpu_region_attr {
|
|||
#define K_MEM_PARTITION_IS_EXECUTABLE(attr) \
|
||||
(!((attr) & (NOT_EXEC)))
|
||||
#endif /* _ASMLANGUAGE */
|
||||
#endif /* USERSPACE */
|
||||
|
|
|
@ -4781,10 +4781,10 @@ struct k_mem_partition {
|
|||
u32_t start;
|
||||
/* size of memory partition */
|
||||
u32_t size;
|
||||
#ifdef CONFIG_USERSPACE
|
||||
#if defined(CONFIG_MEMORY_PROTECTION)
|
||||
/* attribute of memory partition */
|
||||
k_mem_partition_attr_t attr;
|
||||
#endif /* CONFIG_USERSPACE */
|
||||
#endif /* CONFIG_MEMORY_PROTECTION */
|
||||
};
|
||||
|
||||
/* memory domain
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue