Skip to content

Commit 6ebecce

Browse files
ref(arch/mpu): change mpu driver to comply with new vmpu
Removed the complexity from the MPU driver related to the merge of regions, which was moved to the vMPU level. Removed the creation of MPU entries during boot. Signed-off-by: Miguel Silva <[email protected]>
1 parent 00541f3 commit 6ebecce

File tree

8 files changed

+158
-623
lines changed

8 files changed

+158
-623
lines changed

src/arch/armv8/aarch32/inc/arch/subarch/sysregs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ SYSREG_GEN_ACCESSORS(ich_hcr_el2, 4, c12, c11, 0)
115115
SYSREG_GEN_ACCESSORS_64(icc_sgi1r_el1, 0, c12)
116116

117117
SYSREG_GEN_ACCESSORS(vsctlr_el2, 4, c2, c0, 0)
118+
SYSREG_GEN_ACCESSORS(sctlr_el2, 4, c1, c0, 0)
118119

119120
#define SYSREG_GEN_GIC_LR(n, crn1, crn2, op2) \
120121
SYSREG_GEN_ACCESSORS(ich_lr##n, 4, c12, crn1, op2) \

src/arch/armv8/aarch64/inc/arch/subarch/sysregs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ SYSREG_GEN_ACCESSORS(vttbr_el2)
8787
SYSREG_GEN_ACCESSORS(id_aa64mmfr0_el1)
8888
SYSREG_GEN_ACCESSORS(tpidr_el2)
8989
SYSREG_GEN_ACCESSORS(vsctlr_el2)
90+
SYSREG_GEN_ACCESSORS(sctlr_el2)
9091
SYSREG_GEN_ACCESSORS(mpuir_el2)
9192
SYSREG_GEN_ACCESSORS(prselr_el2)
9293
SYSREG_GEN_ACCESSORS(prbar_el2)

src/arch/armv8/armv8-r/aarch32/boot.S

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -50,68 +50,8 @@ boot_arch_profile_init:
5050
/* r4 contains the id of the MPU entry being used */
5151
mov r4, #(-1)
5252

53-
/**
54-
* Map loadable image (and possibly unloadable)
55-
* If the vm image section is used and has built-in vm images, we need to map the loadble and
56-
* non-loadble region of the image separately. Otherwise we can map it as a single region.
57-
*/
58-
add r4, r4, #1
59-
mcr p15, 4, r4, c6, c2, 1 // HPRSELR
60-
ldr r3, =_image_start
61-
and r3, r3, #PRBAR_BASE_MSK
62-
orr r3, r3, #PRBAR_SH_IS
63-
orr r3, r3, #PRBAR_AP_RW_EL2
64-
mcr p15, 4, r3, c6, c3, 0 // HPRBAR
65-
ldr r10, =_image_load_end
66-
ldr r11, =_image_noload_start
67-
cmp r10, r11
68-
ldreq r3, =_image_end
69-
ldrne r3, =_image_load_end
70-
sub r3, r3, #1
71-
and r3, r3, #PRLAR_LIMIT_MSK
72-
orr r3, r3, #(PRLAR_ATTR(1) | PRLAR_EN)
73-
mcr p15, 4, r3, c6, c3, 1 // HPRLAR
74-
75-
/* Map Image Non-loadable if needed */
76-
ldr r10, =_image_load_end
77-
ldr r11, =_image_noload_start
78-
cmp r10, r11
79-
beq skip_non_loadable
80-
add r4, r4, #1
81-
mcr p15, 4, r4, c6, c2, 1 // HPRSELR
82-
ldr r3, =_image_noload_start
83-
and r3, r3, #PRBAR_BASE_MSK
84-
orr r3, r3, #PRBAR_SH_IS
85-
orr r3, r3, #PRBAR_AP_RW_EL2
86-
mcr p15, 4, r3, c6, c3, 0 // HPRBAR
87-
ldr r3, =_image_end
88-
sub r3, r3, #1
89-
and r3, r3, #PRLAR_LIMIT_MSK
90-
orr r3, r3, #(PRLAR_ATTR(1) | PRLAR_EN)
91-
mcr p15, 4, r3, c6, c3, 1 // HPRLAR
92-
93-
skip_non_loadable:
94-
95-
/* Region 2 - CPU */
96-
add r4, r4, #1
97-
mcr p15, 4, r4, c6, c2, 1 // HPRSELR
98-
mrc p15, 4, r3, c13, c0, 2 // HTPIDR (read CPU base addr)
99-
and r3, r3, #PRBAR_BASE_MSK
100-
orr r3, r3, #PRBAR_SH_IS
101-
orr r3, r3, #PRBAR_AP_RW_EL2
102-
mcr p15, 4, r3, c6, c3, 0 // HPRBAR
103-
mrc p15, 4, r3, c13, c0, 2 // HTPIDR (read CPU base addr)
104-
add r3, r3, #CPU_SIZE
105-
sub r3, r3, #1
106-
and r3, r3, #PRLAR_LIMIT_MSK
107-
orr r3, #(PRLAR_ATTR(1) | PRLAR_EN)
108-
mcr p15, 4, r3, c6, c3, 1 // HPRLAR
109-
110-
dsb
111-
isb
112-
11353
/* Enable caches and MPU */
114-
ldr r4, =(SCTLR_RES1_AARCH32 | SCTLR_C | SCTLR_I | SCTLR_M)
54+
ldr r4, =(SCTLR_RES1_AARCH32 | SCTLR_C | SCTLR_I)
11555
mcr p15, 4, r4, c1, c0, 0 // HSCTLR
11656

11757
dsb

src/arch/armv8/armv8-r/aarch64/boot.S

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -45,76 +45,10 @@ boot_arch_profile_init:
4545
ldr x3, =MAIR_EL2_DFLT
4646
msr MAIR_EL2, x3
4747

48-
/* x4 contains the id of the MPU entry being used */
49-
mov x4, 0
50-
51-
/**
52-
* Map loadable image (and possibly unloadable)
53-
* If the vm image section is used and has built-in vm images, we need to map the loadble and
54-
* non-loadble region of the image separately. Otherwise we can map it as a single region.
55-
*/
56-
msr prselr_el2, x4
57-
isb
58-
ldr x3, =_image_start
59-
and x3, x3, PRBAR_BASE_MSK
60-
orr x3, x3, (PRBAR_SH_IS | PRBAR_AP_RW_EL2)
61-
msr prbar_el2, x3
62-
ldr x10, =_image_load_end
63-
ldr x11, =_image_noload_start
64-
cmp x10, x11
65-
bne 1f
66-
ldr x3, =_image_end
67-
b 2f
68-
1:
69-
ldr x3, =_image_load_end
70-
2:
71-
sub x3, x3, 1
72-
and x3, x3, PRLAR_LIMIT_MSK
73-
orr x3, x3, (PRLAR_ATTR(1) | PRLAR_EN)
74-
msr prlar_el2, x3
75-
76-
/* Map Image Non-loadable if needed */
77-
ldr x10, =_image_load_end
78-
ldr x11, =_image_noload_start
79-
cmp x10, x11
80-
beq skip_non_loadable
81-
82-
add x4, x4, 1
83-
msr prselr_el2, x4
84-
ldr x3, =_image_noload_start
85-
and x3, x3, PRBAR_BASE_MSK
86-
orr x3, x3, PRBAR_SH_IS
87-
add x3, x3, PRBAR_AP_RW_EL2
88-
msr prbar_el2, x3
89-
isb
90-
ldr x3, =_image_end
91-
sub x3, x3, 1
92-
and x3, x3, PRLAR_LIMIT_MSK
93-
orr x3, x3, (PRLAR_ATTR(1) | PRLAR_EN)
94-
msr prlar_el2, x3
95-
96-
skip_non_loadable:
97-
98-
/* Region 2 - CPU */
99-
add x4, x4, 1
100-
msr prselr_el2, x4
101-
isb
102-
mrs x3, tpidr_el2
103-
and x3, x3, PRBAR_BASE_MSK
104-
orr x3, x3, (PRBAR_SH_IS | PRBAR_AP_RW_EL2)
105-
msr prbar_el2, x3
106-
mrs x3, tpidr_el2
107-
ldr x5, =CPU_SIZE
108-
add x3, x3, x5
109-
sub x3, x3, 1
110-
and x3, x3, PRLAR_LIMIT_MSK
111-
orr x3, x3, (PRLAR_ATTR(1) | PRLAR_EN)
112-
msr prlar_el2, x3
113-
11448
isb
11549

11650
/* Enable caches and MPU */
117-
ldr x4, =(SCTLR_RES1 | SCTLR_C | SCTLR_I | SCTLR_M)
51+
ldr x4, =(SCTLR_RES1 | SCTLR_C | SCTLR_I)
11852
msr sctlr_el2, x4
11953

12054
dsb nsh
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright (c) Bao Project and Contributors. All rights reserved.
4+
*/
5+
6+
#ifndef __ARCH_MPU_H__
7+
#define __ARCH_MPU_H__
8+
9+
#include <bao.h>
10+
#include <arch/sysregs.h>
11+
#include <bitmap.h>
12+
#include <mem.h>
13+
14+
struct mpu_arch {
15+
BITMAP_ALLOC(allocated_entries, MPU_ARCH_MAX_NUM_ENTRIES);
16+
BITMAP_ALLOC(locked_entries, MPU_ARCH_MAX_NUM_ENTRIES);
17+
};
18+
19+
bool mpu_perms_compatible(unsigned long perms1, unsigned long perms2);
20+
21+
#endif /* __ARCH_MPU_H__ */

src/arch/armv8/armv8-r/inc/arch/profile/cpu.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,14 @@
88

99
#include <bao.h>
1010
#include <arch/sysregs.h>
11+
#include <arch/mpu.h>
1112
#include <bitmap.h>
1213
#include <list.h>
1314
#include <mem.h>
1415
#include <list.h>
1516

1617
struct cpu_arch_profile {
17-
struct {
18-
BITMAP_ALLOC(bitmap, MPU_ARCH_MAX_NUM_ENTRIES);
19-
/**
20-
* A locked region means that it can never be removed from the MPU. For example,
21-
*/
22-
BITMAP_ALLOC(locked, MPU_ARCH_MAX_NUM_ENTRIES);
23-
struct mpu_perms {
24-
perms_t el2;
25-
perms_t el1;
26-
} perms[MPU_ARCH_MAX_NUM_ENTRIES];
27-
/**
28-
* We maintain an ordered list of the regions currently in the mpu to simplify the merging
29-
* algorithm when mapping an overllaping region.
30-
*/
31-
struct {
32-
struct list list;
33-
struct mpu_node {
34-
node_t node;
35-
mpid_t mpid;
36-
} node[MPU_ARCH_MAX_NUM_ENTRIES];
37-
} order;
38-
} mpu;
18+
struct mpu_arch mpu;
3919
};
4020

4121
static inline struct cpu* cpu(void)

0 commit comments

Comments
 (0)