From 7add3cdd82376a481d3660476f1aeae9f06b0636 Mon Sep 17 00:00:00 2001 From: Adithya Baglody Date: Fri, 6 Oct 2017 15:43:11 +0530 Subject: [PATCH] ARM: MPU: Arch specific memory domain APIs Added architecture specific support for memory domain destroy and remove partition for arm and nxp. An optimized version of remove partition was also added. Signed-off-by: Adithya Baglody --- arch/arm/core/cortex_m/mpu/arm_core_mpu.c | 33 +++++++++++++++++++++++ arch/arm/core/cortex_m/mpu/arm_mpu.c | 17 ++++++++++++ arch/arm/core/cortex_m/mpu/nxp_mpu.c | 18 +++++++++++++ 3 files changed, 68 insertions(+) diff --git a/arch/arm/core/cortex_m/mpu/arm_core_mpu.c b/arch/arm/core/cortex_m/mpu/arm_core_mpu.c index c58a3b5571c..b5de59604a5 100644 --- a/arch/arm/core/cortex_m/mpu/arm_core_mpu.c +++ b/arch/arm/core/cortex_m/mpu/arm_core_mpu.c @@ -52,4 +52,37 @@ int _arch_mem_domain_max_partitions_get(void) { return arm_core_mpu_get_max_domain_partition_regions(); } + +/** + * @brief Reset MPU region for a single memory partition + * + * @param domain The memory domain structure + * @param part_index memory partition index + */ +void _arch_mem_domain_remove_partition(struct k_mem_domain *domain, + u32_t partition_id) +{ + ARG_UNUSED(domain); + + arm_core_mpu_disable(); + arm_core_mpu_remove_mem_partition(partition_id); + arm_core_mpu_enable(); + +} + +/** + * @brief Destroy MPU regions for the mem domain + * + * @param domain The memory domain structure + * @param part_index memory partition index + */ +void _arch_mem_domain_destroy(struct k_mem_domain *domain) +{ + ARG_UNUSED(domain); + + arm_core_mpu_disable(); + arm_core_mpu_configure_mem_domain(NULL); + arm_core_mpu_enable(); +} + #endif diff --git a/arch/arm/core/cortex_m/mpu/arm_mpu.c b/arch/arm/core/cortex_m/mpu/arm_mpu.c index 92aedadcc20..e70ab7e3a21 100644 --- a/arch/arm/core/cortex_m/mpu/arm_mpu.c +++ b/arch/arm/core/cortex_m/mpu/arm_mpu.c @@ -262,6 +262,23 @@ void arm_core_mpu_configure_mem_partition(u32_t part_index, } } +/** + * @brief Reset MPU region for a single memory partition + * + * @param part_index memory partition index + */ +void arm_core_mpu_remove_mem_partition(u32_t part_index) +{ + u32_t region_index = + _get_region_index_by_type(THREAD_DOMAIN_PARTITION_REGION); + + SYS_LOG_DBG("disable region 0x%x", region_index + part_index); + /* Disable region */ + ARM_MPU_DEV->rnr = region_index + part_index; + ARM_MPU_DEV->rbar = 0; + ARM_MPU_DEV->rasr = 0; +} + /** * @brief get the maximum number of free regions for memory domain partitions */ diff --git a/arch/arm/core/cortex_m/mpu/nxp_mpu.c b/arch/arm/core/cortex_m/mpu/nxp_mpu.c index 602c3e212de..ae2b4a5ec8b 100644 --- a/arch/arm/core/cortex_m/mpu/nxp_mpu.c +++ b/arch/arm/core/cortex_m/mpu/nxp_mpu.c @@ -289,6 +289,24 @@ void arm_core_mpu_configure_mem_partition(u32_t part_index, } } +/** + * @brief Reset MPU region for a single memory partition + * + * @param part_index memory partition index + */ +void arm_core_mpu_remove_mem_partition(u32_t part_index) +{ + u32_t region_index = + _get_region_index_by_type(THREAD_DOMAIN_PARTITION_REGION); + + SYS_LOG_DBG("disable region 0x%x", region_index); + /* Disable region */ + SYSMPU->WORD[region_index + part_index][0] = 0; + SYSMPU->WORD[region_index + part_index][1] = 0; + SYSMPU->WORD[region_index + part_index][2] = 0; + SYSMPU->WORD[region_index + part_index][3] = 0; +} + /** * @brief get the maximum number of free regions for memory domain partitions */