From 9c1115c6554d6c5af95d6ddded5fb014e8d96d27 Mon Sep 17 00:00:00 2001 From: Jaxson Han Date: Mon, 19 Jul 2021 17:54:18 +0800 Subject: [PATCH] include: arm64: Refine the K_MEM_PARTITION_ defs The defination of K_MEM_PARTITION_* marcos denpens on wheather it is mmu or mpu, so I move those definations for mmu into arm_mmu.h and create mpu relevant ones in arm_mpu.h Signed-off-by: Jaxson Han --- include/arch/arm64/arch.h | 32 +-------------------------- include/arch/arm64/arm_mmu.h | 24 ++++++++++++++++++++ include/arch/arm64/cortex_r/arm_mpu.h | 11 +++++++++ 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/include/arch/arm64/arch.h b/include/arch/arm64/arch.h index 6c2203a3d4e..1f69cb33ed8 100644 --- a/include/arch/arm64/arch.h +++ b/include/arch/arm64/arch.h @@ -29,9 +29,7 @@ #include #include #include -#ifdef CONFIG_ARM_MMU -#include -#endif +#include #include #include #include @@ -45,34 +43,6 @@ extern "C" { #include -/* Kernel macros for memory attribution - * (access permissions and cache-ability). - * - * The macros are to be stored in k_mem_partition_attr_t - * objects. The format of a k_mem_partition_attr_t object - * is an uint32_t composed by permission and attribute flags - * located in include/arch/arm64/arm_mmu.h - */ - -/* Read-Write access permission attributes */ -#define K_MEM_PARTITION_P_RW_U_RW ((k_mem_partition_attr_t) \ - {MT_P_RW_U_RW}) -#define K_MEM_PARTITION_P_RW_U_NA ((k_mem_partition_attr_t) \ - {MT_P_RW_U_NA}) -#define K_MEM_PARTITION_P_RO_U_RO ((k_mem_partition_attr_t) \ - {MT_P_RO_U_RO}) -#define K_MEM_PARTITION_P_RO_U_NA ((k_mem_partition_attr_t) \ - {MT_P_RO_U_NA}) - -/* Execution-allowed attributes */ -#define K_MEM_PARTITION_P_RX_U_RX ((k_mem_partition_attr_t) \ - {MT_P_RX_U_RX}) - -/* Typedef for the k_mem_partition attribute */ -typedef struct { - uint32_t attrs; -} k_mem_partition_attr_t; - struct arch_mem_domain { #ifdef CONFIG_ARM_MMU struct arm_mmu_ptables ptables; diff --git a/include/arch/arm64/arm_mmu.h b/include/arch/arm64/arm_mmu.h index 12ac5e19673..edadb0e7359 100644 --- a/include/arch/arm64/arm_mmu.h +++ b/include/arch/arm64/arm_mmu.h @@ -186,6 +186,30 @@ struct arm_mmu_ptables { #define MMU_REGION_FLAT_ENTRY(name, adr, sz, attrs) \ MMU_REGION_ENTRY(name, adr, adr, sz, attrs) +/* Kernel macros for memory attribution + * (access permissions and cache-ability). + * + * The macros are to be stored in k_mem_partition_attr_t + * objects. The format of a k_mem_partition_attr_t object + * is an uint32_t composed by permission and attribute flags + * located in include/arch/arm64/arm_mmu.h + */ + +/* Read-Write access permission attributes */ +#define K_MEM_PARTITION_P_RW_U_RW ((k_mem_partition_attr_t) \ + {MT_P_RW_U_RW}) +#define K_MEM_PARTITION_P_RW_U_NA ((k_mem_partition_attr_t) \ + {MT_P_RW_U_NA}) +#define K_MEM_PARTITION_P_RO_U_RO ((k_mem_partition_attr_t) \ + {MT_P_RO_U_RO}) +#define K_MEM_PARTITION_P_RO_U_NA ((k_mem_partition_attr_t) \ + {MT_P_RO_U_NA}) +/* Execution-allowed attributes */ +#define K_MEM_PARTITION_P_RX_U_RX ((k_mem_partition_attr_t) \ + {MT_P_RX_U_RX}) +/* Typedef for the k_mem_partition attribute */ +typedef struct { uint32_t attrs; } k_mem_partition_attr_t; + /* Reference to the MMU configuration. * * This struct is defined and populated for each SoC (in the SoC definition), diff --git a/include/arch/arm64/cortex_r/arm_mpu.h b/include/arch/arm64/cortex_r/arm_mpu.h index 23b22932a09..708be6f1e51 100644 --- a/include/arch/arm64/cortex_r/arm_mpu.h +++ b/include/arch/arm64/cortex_r/arm_mpu.h @@ -219,6 +219,17 @@ struct arm_mpu_config { .attr = _attr, \ } +#define K_MEM_PARTITION_P_RW_U_RW ((k_mem_partition_attr_t) \ + {(P_RW_U_RW_Msk), MPU_MAIR_INDEX_SRAM}) +#define K_MEM_PARTITION_P_RW_U_NA ((k_mem_partition_attr_t) \ + {(P_RW_U_NA_Msk), MPU_MAIR_INDEX_SRAM}) +#define K_MEM_PARTITION_P_RO_U_RO ((k_mem_partition_attr_t) \ + {(P_RO_U_RO_Msk), MPU_MAIR_INDEX_SRAM}) +#define K_MEM_PARTITION_P_RO_U_NA ((k_mem_partition_attr_t) \ + {(P_RO_U_NA_Msk), MPU_MAIR_INDEX_SRAM}) + +typedef struct arm_mpu_region_attr k_mem_partition_attr_t; + /* Reference to the MPU configuration. * * This struct is defined and populated for each SoC (in the SoC definition),