2017-08-15 06:20:42 +02:00
|
|
|
/*
|
2019-03-05 03:29:16 +01:00
|
|
|
* Copyright (c) 2019 Synopsys.
|
2017-08-15 06:20:42 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2022-05-06 10:49:15 +02:00
|
|
|
#include <zephyr/device.h>
|
|
|
|
#include <zephyr/init.h>
|
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/arch/arc/v2/aux_regs.h>
|
|
|
|
#include <zephyr/arch/arc/v2/mpu/arc_mpu.h>
|
|
|
|
#include <zephyr/arch/arc/v2/mpu/arc_core_mpu.h>
|
|
|
|
#include <zephyr/linker/linker-defs.h>
|
2017-08-15 06:20:42 +02:00
|
|
|
|
2018-09-17 16:56:20 +02:00
|
|
|
#define LOG_LEVEL CONFIG_MPU_LOG_LEVEL
|
2022-05-06 10:49:15 +02:00
|
|
|
#include <zephyr/logging/log.h>
|
2019-03-05 03:29:16 +01:00
|
|
|
LOG_MODULE_REGISTER(mpu);
|
2017-11-29 10:42:00 +01:00
|
|
|
|
2017-08-15 06:20:42 +02:00
|
|
|
/**
|
2017-12-20 09:48:45 +01:00
|
|
|
* @brief Get the number of supported MPU regions
|
2017-08-15 06:20:42 +02:00
|
|
|
*
|
|
|
|
*/
|
2020-05-27 18:26:57 +02:00
|
|
|
static inline uint8_t get_num_regions(void)
|
2017-08-15 06:20:42 +02:00
|
|
|
{
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t num = z_arc_v2_aux_reg_read(_ARC_V2_MPU_BUILD);
|
2017-08-15 06:20:42 +02:00
|
|
|
|
2019-02-26 19:03:24 +01:00
|
|
|
num = (num & 0xFF00U) >> 8U;
|
2017-08-15 06:20:42 +02:00
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
return (uint8_t)num;
|
2017-08-15 06:20:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This internal function is utilized by the MPU driver to parse the intent
|
|
|
|
* type (i.e. THREAD_STACK_REGION) and return the correct parameter set.
|
|
|
|
*/
|
2020-05-27 18:26:57 +02:00
|
|
|
static inline uint32_t get_region_attr_by_type(uint32_t type)
|
2017-08-15 06:20:42 +02:00
|
|
|
{
|
|
|
|
switch (type) {
|
arch: arc: add user space support for arc
* add the implementation of syscall
* based on 'trap_s' intruction, id = 3
* add the privilege stack
* the privilege stack is allocted with thread stack
* for the kernel thread, the privilege stack is also a
part of thread stack, the start of stack can be configured
as stack guard
* for the user thread, no stack guard, when the user stack is
overflow, it will fall into kernel memory area which requires
kernel privilege, privilege violation will be raised
* modify the linker template and add MPU_ADDR_ALIGN
* add user space corresponding codes in mpu
* the user sp aux reg will be part of thread context
* When user thread is interruptted for the 1st time, the context is
saved in user stack (U bit of IRQ_CTLR is set to 1). When nest
interrupt comes, the context is saved in thread's privilege stack
* the arc_mpu_regions.c is moved to board folder, as it's board
specific
* the above codes have been tested through tests/kernel/mem_protect/
userspace for MPU version 2
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-01-23 10:13:09 +01:00
|
|
|
case THREAD_STACK_USER_REGION:
|
|
|
|
return REGION_RAM_ATTR;
|
2017-08-15 06:20:42 +02:00
|
|
|
case THREAD_STACK_REGION:
|
2019-03-05 03:29:16 +01:00
|
|
|
return AUX_MPU_ATTR_KW | AUX_MPU_ATTR_KR;
|
arch: arc: add user space support for arc
* add the implementation of syscall
* based on 'trap_s' intruction, id = 3
* add the privilege stack
* the privilege stack is allocted with thread stack
* for the kernel thread, the privilege stack is also a
part of thread stack, the start of stack can be configured
as stack guard
* for the user thread, no stack guard, when the user stack is
overflow, it will fall into kernel memory area which requires
kernel privilege, privilege violation will be raised
* modify the linker template and add MPU_ADDR_ALIGN
* add user space corresponding codes in mpu
* the user sp aux reg will be part of thread context
* When user thread is interruptted for the 1st time, the context is
saved in user stack (U bit of IRQ_CTLR is set to 1). When nest
interrupt comes, the context is saved in thread's privilege stack
* the arc_mpu_regions.c is moved to board folder, as it's board
specific
* the above codes have been tested through tests/kernel/mem_protect/
userspace for MPU version 2
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-01-23 10:13:09 +01:00
|
|
|
case THREAD_APP_DATA_REGION:
|
|
|
|
return REGION_RAM_ATTR;
|
2017-08-15 06:20:42 +02:00
|
|
|
case THREAD_STACK_GUARD_REGION:
|
2019-02-06 19:17:40 +01:00
|
|
|
/* no Write and Execute to guard region */
|
2019-03-05 03:29:16 +01:00
|
|
|
return AUX_MPU_ATTR_UR | AUX_MPU_ATTR_KR;
|
2017-12-20 09:48:45 +01:00
|
|
|
default:
|
2019-03-05 03:29:16 +01:00
|
|
|
/* unknown type */
|
2017-12-20 09:48:45 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-15 14:37:58 +01:00
|
|
|
#if (CONFIG_ARC_MPU_VER == 4) || (CONFIG_ARC_MPU_VER == 8)
|
2021-02-23 08:10:14 +01:00
|
|
|
#include "arc_mpu_v4_internal.h"
|
2021-08-24 14:42:46 +02:00
|
|
|
#else
|
|
|
|
#include "arc_mpu_common_internal.h"
|
2017-11-29 10:42:00 +01:00
|
|
|
#endif
|