Skip to content

Commit a1c2159

Browse files
Wayne Renandrewboie
authored andcommitted
arch: arc: refactor the ARC MPU driver
* separate the ARC MPU driver into 2 parts * arc_mpu_v2_internal.h for ARC MPUv2 * arc_mpu_v3_internal.h for ARC MPUv3 * For ARC MPUv2, keep the main design, but update and optimize the code * For ARC MPUv3, implement mpu region split to supprt MPU region overlap * misc updates and bug fixes Signed-off-by: Wayne Ren <[email protected]>
1 parent ea5d54c commit a1c2159

File tree

10 files changed

+1249
-965
lines changed

10 files changed

+1249
-965
lines changed

arch/arc/core/mpu/arc_core_mpu.c

Lines changed: 6 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@
77
#include <device.h>
88
#include <init.h>
99
#include <kernel.h>
10-
#include <kernel_structs.h>
1110
#include <soc.h>
1211
#include <arch/arc/v2/mpu/arc_core_mpu.h>
1312

14-
#define LOG_LEVEL CONFIG_MPU_LOG_LEVEL
15-
#include <logging/log.h>
16-
LOG_MODULE_REGISTER(mpu);
17-
1813
/*
1914
* @brief Configure MPU for the thread
2015
*
@@ -25,84 +20,11 @@ LOG_MODULE_REGISTER(mpu);
2520
void configure_mpu_thread(struct k_thread *thread)
2621
{
2722
arc_core_mpu_disable();
28-
#if defined(CONFIG_MPU_STACK_GUARD)
29-
configure_mpu_stack_guard(thread);
30-
#endif
31-
32-
#if defined(CONFIG_USERSPACE)
33-
configure_mpu_user_context(thread);
34-
configure_mpu_mem_domain(thread);
35-
#endif
23+
arc_core_mpu_configure_thread(thread);
3624
arc_core_mpu_enable();
3725
}
3826

39-
#if defined(CONFIG_MPU_STACK_GUARD)
40-
/*
41-
* @brief Configure MPU stack guard
42-
*
43-
* This function configures per thread stack guards reprogramming the MPU.
44-
* The functionality is meant to be used during context switch.
45-
*
46-
* @param thread thread info data structure.
47-
*/
48-
void configure_mpu_stack_guard(struct k_thread *thread)
49-
{
50-
#if defined(CONFIG_USERSPACE)
51-
if ((thread->thread_base.user_options & K_USER) != 0) {
52-
/* the areas before and after the user stack of thread is
53-
* kernel only. These area can be used as stack guard.
54-
* -----------------------
55-
* | kernel only area |
56-
* |---------------------|
57-
* | user stack |
58-
* |---------------------|
59-
* |privilege stack guard|
60-
* |---------------------|
61-
* | privilege stack |
62-
* -----------------------
63-
*/
64-
arc_core_mpu_configure(THREAD_STACK_GUARD_REGION,
65-
thread->arch.priv_stack_start - STACK_GUARD_SIZE,
66-
STACK_GUARD_SIZE);
67-
return;
68-
}
69-
#endif
70-
arc_core_mpu_configure(THREAD_STACK_GUARD_REGION,
71-
thread->stack_info.start - STACK_GUARD_SIZE,
72-
STACK_GUARD_SIZE);
73-
74-
}
75-
#endif
76-
7727
#if defined(CONFIG_USERSPACE)
78-
/*
79-
* @brief Configure MPU user context
80-
*
81-
* This function configures the thread's user context.
82-
* The functionality is meant to be used during context switch.
83-
*
84-
* @param thread thread info data structure.
85-
*/
86-
void configure_mpu_user_context(struct k_thread *thread)
87-
{
88-
LOG_DBG("configure user thread %p's context", thread);
89-
arc_core_mpu_configure_user_context(thread);
90-
}
91-
92-
93-
/*
94-
* @brief Configure MPU memory domain
95-
*
96-
* This function configures per thread memory domain reprogramming the MPU.
97-
* The functionality is meant to be used during context switch.
98-
*
99-
* @param thread thread info data structure.
100-
*/
101-
void configure_mpu_mem_domain(struct k_thread *thread)
102-
{
103-
LOG_DBG("configure thread %p's domain", thread);
104-
arc_core_mpu_configure_mem_domain(thread);
105-
}
10628

10729
int z_arch_mem_domain_max_partitions_get(void)
10830
{
@@ -115,31 +37,28 @@ int z_arch_mem_domain_max_partitions_get(void)
11537
void z_arch_mem_domain_partition_remove(struct k_mem_domain *domain,
11638
u32_t partition_id)
11739
{
118-
ARG_UNUSED(domain);
119-
12040
arc_core_mpu_disable();
121-
arc_core_mpu_mem_partition_remove(partition_id);
41+
arc_core_mpu_remove_mem_partition(domain, partition_id);
12242
arc_core_mpu_enable();
123-
12443
}
12544

12645
/*
12746
* Configure MPU memory domain
12847
*/
12948
void z_arch_mem_domain_configure(struct k_thread *thread)
13049
{
131-
configure_mpu_mem_domain(thread);
50+
arc_core_mpu_disable();
51+
arc_core_mpu_configure_mem_domain(thread);
52+
arc_core_mpu_enable();
13253
}
13354

13455
/*
13556
* Destroy MPU regions for the mem domain
13657
*/
13758
void z_arch_mem_domain_destroy(struct k_mem_domain *domain)
13859
{
139-
ARG_UNUSED(domain);
140-
14160
arc_core_mpu_disable();
142-
arc_core_mpu_configure_mem_domain(NULL);
61+
arc_core_mpu_remove_mem_domain(domain);
14362
arc_core_mpu_enable();
14463
}
14564

0 commit comments

Comments
 (0)