-
Notifications
You must be signed in to change notification settings - Fork 15
/
mpu.h
84 lines (71 loc) · 2.29 KB
/
mpu.h
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
// SPDX-License-Identifier: GPL-2.0-only
/*
* mpu.h: Arm Memory Protection Unit definitions.
*/
#ifndef __ARM32_MPU_H__
#define __ARM32_MPU_H__
#ifndef __ASSEMBLY__
/* Hypervisor Protection Region Base Address Register */
typedef union {
struct {
unsigned int xn:1; /* Execute-Never */
unsigned int ap:2; /* Acess Permission */
unsigned int sh:2; /* Sharebility */
unsigned int res0:1; /* Reserved as 0 */
unsigned int base:26; /* Base Address */
} reg;
uint32_t bits;
} prbar_t;
/* Hypervisor Protection Region Limit Address Register */
typedef union {
struct {
unsigned int en:1; /* Region enable */
unsigned int ai:3; /* Memory Attribute Index */
/*
* There is no actual ns bit in hardware. It is used here for
* compatibility with Armr64 code. Thus, we are reusing a res0 bit for ns.
*/
unsigned int ns:1; /* Reserved 0 by hardware */
unsigned int res0:1; /* Reserved 0 by hardware */
unsigned int base:26; /* Limit Address */
} reg;
uint32_t bits;
} prlar_t;
/* Protection Region */
typedef struct {
prbar_t base;
prlar_t limit;
uint64_t p2m_type; /* Used to store p2m types. */
} pr_t;
#define XN_P2M_ENABLED XN_ENABLED
/*
* Access to get base address of MPU protection region.
* The base address shall be zero extended.
*/
#define pr_get_base(pr) ({ \
pr_t* _pr = pr; \
(uint32_t)_pr->base.reg.base << MPU_REGION_SHIFT; \
})
/*
* Access to get limit address of MPU protection region.
* The limit address shall be concatenated with 0x3f.
*/
#define pr_get_limit(pr) ({ \
pr_t* _pr = pr; \
(uint32_t)((_pr->limit.reg.base << MPU_REGION_SHIFT) | 0x3f); \
})
static inline uint64_t p2m_get_region_type(pr_t *region)
{
return region->p2m_type;
}
static inline void p2m_set_region_type(pr_t *region, uint64_t type)
{
region->p2m_type = type;
}
static inline uint32_t generate_vsctlr(uint16_t vmid)
{
return ((uint32_t)vmid << 16);
}
extern void set_boot_mpumap(u32 len, pr_t *table);
#endif /* __ASSEMBLY__ */
#endif /* __ARM32_MPU_H__ */