1 /* 2 * Copyright (c) 2019 Synopsys. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/device.h> 8 #include <zephyr/init.h> 9 #include <zephyr/kernel.h> 10 #include <zephyr/arch/arc/v2/aux_regs.h> 11 #include <zephyr/arch/arc/v2/mpu/arc_mpu.h> 12 #include <zephyr/arch/arc/v2/mpu/arc_core_mpu.h> 13 #include <zephyr/linker/linker-defs.h> 14 15 #define LOG_LEVEL CONFIG_MPU_LOG_LEVEL 16 #include <zephyr/logging/log.h> 17 LOG_MODULE_REGISTER(mpu); 18 19 /** 20 * @brief Get the number of supported MPU regions 21 * 22 */ get_num_regions(void)23static inline uint8_t get_num_regions(void) 24 { 25 uint32_t num = z_arc_v2_aux_reg_read(_ARC_V2_MPU_BUILD); 26 27 num = (num & 0xFF00U) >> 8U; 28 29 return (uint8_t)num; 30 } 31 32 /** 33 * This internal function is utilized by the MPU driver to parse the intent 34 * type (i.e. THREAD_STACK_REGION) and return the correct parameter set. 35 */ get_region_attr_by_type(uint32_t type)36static inline uint32_t get_region_attr_by_type(uint32_t type) 37 { 38 switch (type) { 39 case THREAD_STACK_USER_REGION: 40 return REGION_RAM_ATTR; 41 case THREAD_STACK_REGION: 42 return AUX_MPU_ATTR_KW | AUX_MPU_ATTR_KR; 43 case THREAD_APP_DATA_REGION: 44 return REGION_RAM_ATTR; 45 case THREAD_STACK_GUARD_REGION: 46 /* no Write and Execute to guard region */ 47 return AUX_MPU_ATTR_UR | AUX_MPU_ATTR_KR; 48 default: 49 /* unknown type */ 50 return 0; 51 } 52 } 53 54 #if (CONFIG_ARC_MPU_VER == 4) || (CONFIG_ARC_MPU_VER == 8) 55 #include "arc_mpu_v4_internal.h" 56 #else 57 #include "arc_mpu_common_internal.h" 58 #endif 59