Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | /* * Copyright (c) 2017 Linaro Limited. * * SPDX-License-Identifier: Apache-2.0 */ #include <device.h> #include <init.h> #include <kernel.h> #include <soc.h> #include <arch/arm/cortex_m/cmsis.h> #include <arch/arm/cortex_m/mpu/arm_core_mpu.h> #include <logging/sys_log.h> #if defined(CONFIG_MPU_STACK_GUARD) /* * @brief Configure MPU stack guard * * This function configures per thread stack guards reprogramming the MPU. * The functionality is meant to be used during context switch. * * @param thread thread info data structure. */ void configure_mpu_stack_guard(struct k_thread *thread) { u32_t guard_size = MPU_GUARD_ALIGN_AND_SIZE; #if defined(CONFIG_USERSPACE) u32_t guard_start = thread->arch.priv_stack_start ? (u32_t)thread->arch.priv_stack_start : (u32_t)thread->stack_obj; #else u32_t guard_start = thread->stack_info.start; #endif arm_core_mpu_disable(); arm_core_mpu_configure(THREAD_STACK_GUARD_REGION, guard_start, guard_size); arm_core_mpu_enable(); } #endif #if defined(CONFIG_USERSPACE) /* * @brief Configure MPU user context * * This function configures the thread's user context. * The functionality is meant to be used during context switch. * * @param thread thread info data structure. */ void configure_mpu_user_context(struct k_thread *thread) { SYS_LOG_DBG("configure user thread %p's context", thread); arm_core_mpu_disable(); arm_core_mpu_configure_user_context(thread); arm_core_mpu_enable(); } /* * @brief Configure MPU memory domain * * This function configures per thread memory domain reprogramming the MPU. * The functionality is meant to be used during context switch. * * @param thread thread info data structure. */ void configure_mpu_mem_domain(struct k_thread *thread) { SYS_LOG_DBG("configure thread %p's domain", thread); arm_core_mpu_disable(); arm_core_mpu_configure_mem_domain(thread->mem_domain_info.mem_domain); arm_core_mpu_enable(); } void _arch_mem_domain_configure(struct k_thread *thread) { configure_mpu_mem_domain(thread); } int _arch_mem_domain_max_partitions_get(void) { return arm_core_mpu_get_max_domain_partition_regions(); } /* * Reset MPU region for a single memory partition */ void _arch_mem_domain_partition_remove(struct k_mem_domain *domain, u32_t partition_id) { ARG_UNUSED(domain); arm_core_mpu_disable(); arm_core_mpu_mem_partition_remove(partition_id); arm_core_mpu_enable(); } /* * Destroy MPU regions for the mem domain */ 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(); } /* * Validate the given buffer is user accessible or not */ int _arch_buffer_validate(void *addr, size_t size, int write) { return arm_core_mpu_buffer_validate(addr, size, write); } #endif |