Pip
Architecture-dependent parts of Pip: MAL, IAL and boot
armv7/boot/include/mmu.h
Go to the documentation of this file.
1 /*******************************************************************************/
2 /* © Université de Lille, The Pip Development Team (2015-2021) */
3 /* */
4 /* This software is a computer program whose purpose is to run a minimal, */
5 /* hypervisor relying on proven properties such as memory isolation. */
6 /* */
7 /* This software is governed by the CeCILL license under French law and */
8 /* abiding by the rules of distribution of free software. You can use, */
9 /* modify and/ or redistribute the software under the terms of the CeCILL */
10 /* license as circulated by CEA, CNRS and INRIA at the following URL */
11 /* "http://www.cecill.info". */
12 /* */
13 /* As a counterpart to the access to the source code and rights to copy, */
14 /* modify and redistribute granted by the license, users are provided only */
15 /* with a limited warranty and the software's author, the holder of the */
16 /* economic rights, and the successive licensors have only limited */
17 /* liability. */
18 /* */
19 /* In this respect, the user's attention is drawn to the risks associated */
20 /* with loading, using, modifying and/or developing or reproducing the */
21 /* software by the user in light of its specific status of free software, */
22 /* that may mean that it is complicated to manipulate, and that also */
23 /* therefore means that it is reserved for developers and experienced */
24 /* professionals having in-depth computer knowledge. Users are therefore */
25 /* encouraged to load and test the software's suitability as regards their */
26 /* requirements in conditions enabling the security of their systems and/or */
27 /* data to be ensured and, more generally, to use and operate it in the */
28 /* same conditions as regards security. */
29 /* */
30 /* The fact that you are presently reading this means that you have had */
31 /* knowledge of the CeCILL license and that you accept its terms. */
32 /*******************************************************************************/
33 
34 #ifndef DEF_MMU_H
35 #define DEF_MMU_H
36 
37 #include "types.h"
38 
39 /* Truncated L1 translation table */
40 #define MMU_TTBR0_ENT_COUNT 0x400
41 
42 /* Full translation table */
43 #define MMU_TTBR1_ENT_COUNT 0x1000
44 
45 /* Use 1/4 of the translation table */
46 #define MMU_L1_ENT_COUNT 0x400
47 /* Use the whole L2 table */
48 #define MMU_L2_ENT_COUNT 0x100
49 
50 typedef enum mmu_rgn_e {
55 } mmu_rgn_t;
56 
57 /* B3-1326: Short-descriptor page table (level 1) */
58 typedef union mmu_sd_pt_s {
59  unsigned aslong;
60  struct {
61  unsigned one:2; /* Must be 1 for a page table */
62  unsigned pxn:1; /* Privileged execute-never */
63  unsigned ns:1; /* Non-secure */
64  unsigned zero:1; /* SBZ */
65  unsigned domain:4; /* B3.7.3 Domains, Short-descriptor format only */
66  unsigned unk:1; /* Implementation defined */
67  unsigned ptbaddr:22;
68  };
69 } mmu_sd_pt_t ;
70 
71 /* Short-format section */
72 typedef union mmu_sd_sec_s {
73  unsigned aslong;
74  struct {
75  unsigned pxn:1; /* Privileged execute-never */
76  unsigned one:1; /* Must be 1 for a section */
77  unsigned B:1; /* B3.8.2 : memory attributes */
78  unsigned C:1; /* B3.8.2 */
79  unsigned xn:1; /* eXecute Never */
80  unsigned domain:4; /* B3.7.3 Domains, Short-descriptor format only */
81  unsigned unk:1;
82  unsigned AP0:1; /* Access permission bit 0 */
83  unsigned AP1:1; /* Access permission bit 1 */
84  unsigned TEX:3; /* B3.8.2 */
85  unsigned AP2:1; /* Access permission bit 2 */
86  unsigned S:1; /* B3-1366 : Shareable */
87  unsigned nG:1; /* B3-1378 : not Global */
88  unsigned zero:1; /* Must be zero for a section */
89  unsigned ns:1; /* Non-secure */
90  unsigned secbaddr:12; /* paddr of section (1MB) */
91  };
92 } mmu_sd_sec_t ;
93 
94 /* Short-format supersection */
95 typedef union mmu_sd_ssec_s {
96  unsigned aslong;
97  struct {
98  unsigned pxn:1; /* Privileged execute-never */
99  unsigned one1:1; /* Must be 1 for a supersection */
100  unsigned B:1; /* B3.8.2 : memory attributes */
101  unsigned C:1; /* B3.8.2 */
102  unsigned xn:1; /* eXecute Never */
103  unsigned PA2:4; /* Extended base address, PA[39:36] */
104  unsigned unk:1;
105  unsigned AP0:1; /* Access permission bit 0 */
106  unsigned AP1:1; /* Access permission bit 1 */
107  unsigned TEX:3; /* B3.8.2 */
108  unsigned AP2:1; /* Access permission bit 2 */
109  unsigned S:1; /* B3-1366 : Shareable */
110  unsigned nG:1; /* B3-1378 : not Global */
111  unsigned one2:1; /* Must be one for a supersection */
112  unsigned ns:1; /* Non-secure */
113  unsigned PA1:4; /* Extended base address, PA[39:36] */
114  unsigned secbaddr:8; /* PA[31:24] of supersection (16MB) */
115  };
116 } mmu_sd_ssec_t ;
117 
118 
119 /* B3-1327: Short-descriptor small page descriptor (level 2)
120  * B3-1366: Memory attributes in the Short-descriptor translation table format descriptors */
121 typedef union mmu_sd_sp_s {
122  unsigned aslong;
123  struct {
124  unsigned xn:1; /* eXecute Never*/
125  unsigned one:1; /* Must be 1 for a small page */
126  unsigned B:1; /* B3.8.2 : memory attributes */
127  unsigned C:1; /* B3.8.2 */
128  unsigned AP0:1; /* Access permission bit 0 */
129  unsigned AP1:1; /* Access permission bit 1 */
130  unsigned TEX:3; /* B3.8.2 */
131  unsigned AP2:1; /* Access permission bit 2 */
132  unsigned S:1; /* B3-1366 : Shareable */
133  unsigned nG:1; /* B3-1378 : not Global (
134  0: Global, page is available for all processes
135  1: not Global, page availability depends on ASID */
136  unsigned spbaddr:20;/* paddr of small page (4KB) */
137  };
138 } mmu_sd_sp_t ;
139 
141  void *ptbaddr /* Full address of aligned(12) small page */
142 );
143 
145  void *spbaddr /* Full address of aligned(12) small page */
146  , bool_t user /* User accessible */
147  , bool_t ro /* Read only */
148  , bool_t xn /* eXecute never */
149  , bool_t device
150  , bool_t global
151 );
152 
153 /* B4.1.154 TTBR0, Translation Table Base Register 0
154  * Build translation table register */
155 unsigned mmu_make_ttbr (
156  void * base,
157  mmu_rgn_t irgn, /* Cache inner attributes */
158  mmu_rgn_t rgn, /* Cache outer attributes */
159  bool_t shareable,
160  bool_t not_outer_shareable
161 );
162 
163 void mmu_map_small_page(
164  unsigned int *tt /* Translation table addr*/
165  , void *pa, void *va /* Virtual & Physical addresses */
166  , bool_t user /* PL0 & PL1 accessible */
167  , bool_t ro /* Read only */
168  , bool_t xn /* eXecute never (FIXME: not applied to kernel ? */
169  , bool_t device /* Set memory as shareable device */
170  , bool_t global
171 );
172 
173 void mmu_map_anysection(
174  unsigned int *tt, /* Translation table addr*/
175  void *pa, void *va, /* Virtual & Physical addresses */
176  bool_t user, /* PL0 & PL1 accessible */
177  bool_t ro, /* Read only */
178  bool_t xn, /* eXecute never */
179  bool_t device, /* Set memory as shareable device */
180  bool_t global, /* Mark memory as global */
181  int super
182 );
183 
184 #define mmu_map_section(tt, pa, va, user, ro, xn, device, global) \
185  mmu_map_anysection(tt, pa, va, user, ro, xn, device, global, 0)
186 
187 #define mmu_map_supersection(tt, pa, va, user, ro, xn, device, global) \
188  mmu_map_anysection(tt, pa, va, user, ro, xn, device, global, 1)
189 
190 void mmu_init(void);
191 void mmu_debug(unsigned*tt);
192 mmu_sd_sp_t mmu_virt_to_sp(unsigned pd, unsigned va);
193 unsigned mmu_virt_to_phys(unsigned pd, unsigned va);
194 void cache_and_mmu_disable();
195 void cache_and_mmu_enable();
196 
197 #endif
void mmu_init(void)
Definition: armv7/boot/mmu.c:430
unsigned mmu_make_ttbr(void *base, mmu_rgn_t irgn, mmu_rgn_t rgn, bool_t shareable, bool_t not_outer_shareable)
Definition: armv7/boot/mmu.c:198
unsigned AP0
Definition: armv7/boot/include/mmu.h:82
Definition: armv7/boot/include/mmu.h:54
unsigned int base
Base address.
Definition: gdt.h:97
unsigned B
Definition: armv7/boot/include/mmu.h:77
unsigned TEX
Definition: armv7/boot/include/mmu.h:130
unsigned zero
Definition: armv7/boot/include/mmu.h:88
unsigned AP1
Definition: armv7/boot/include/mmu.h:106
void cache_and_mmu_disable()
unsigned nG
Definition: armv7/boot/include/mmu.h:133
unsigned xn
Definition: armv7/boot/include/mmu.h:79
Definition: armv7/boot/include/mmu.h:72
unsigned char bool_t
Definition: types.h:37
unsigned B
Definition: armv7/boot/include/mmu.h:126
unsigned unk
Definition: armv7/boot/include/mmu.h:66
unsigned ptbaddr
Definition: armv7/boot/include/mmu.h:67
unsigned TEX
Definition: armv7/boot/include/mmu.h:84
void mmu_debug(unsigned *tt)
Definition: armv7/boot/mmu.c:267
unsigned one
Definition: armv7/boot/include/mmu.h:125
unsigned nG
Definition: armv7/boot/include/mmu.h:87
unsigned S
Definition: armv7/boot/include/mmu.h:132
unsigned S
Definition: armv7/boot/include/mmu.h:86
unsigned C
Definition: armv7/boot/include/mmu.h:101
void cache_and_mmu_enable()
union mmu_sd_sec_s mmu_sd_sec_t
unsigned TEX
Definition: armv7/boot/include/mmu.h:107
enum mmu_rgn_e mmu_rgn_t
unsigned AP2
Definition: armv7/boot/include/mmu.h:85
unsigned domain
Definition: armv7/boot/include/mmu.h:65
unsigned pxn
Definition: armv7/boot/include/mmu.h:75
unsigned one
Definition: armv7/boot/include/mmu.h:61
unsigned spbaddr
Definition: armv7/boot/include/mmu.h:136
unsigned AP0
Definition: armv7/boot/include/mmu.h:105
unsigned one
Definition: armv7/boot/include/mmu.h:76
mmu_sd_sp_t mmu_make_small_page(void *spbaddr, bool_t user, bool_t ro, bool_t xn, bool_t device, bool_t global)
Definition: armv7/boot/mmu.c:226
unsigned unk
Definition: armv7/boot/include/mmu.h:104
mmu_sd_sp_t mmu_virt_to_sp(unsigned pd, unsigned va)
Definition: armv7/boot/mmu.c:303
unsigned mmu_virt_to_phys(unsigned pd, unsigned va)
Definition: armv7/boot/mmu.c:333
Definition: armv7/boot/include/mmu.h:95
Definition: armv7/boot/include/mmu.h:51
union mmu_sd_ssec_s mmu_sd_ssec_t
Definition: armv7/boot/include/mmu.h:121
union mmu_sd_sp_s mmu_sd_sp_t
Definition: armv7/boot/include/mmu.h:58
unsigned ns
Definition: armv7/boot/include/mmu.h:89
unsigned secbaddr
Definition: armv7/boot/include/mmu.h:90
unsigned zero
Definition: armv7/boot/include/mmu.h:64
unsigned aslong
Definition: armv7/boot/include/mmu.h:96
unsigned AP0
Definition: armv7/boot/include/mmu.h:128
unsigned nG
Definition: armv7/boot/include/mmu.h:110
unsigned one2
Definition: armv7/boot/include/mmu.h:111
unsigned aslong
Definition: armv7/boot/include/mmu.h:73
unsigned aslong
Definition: armv7/boot/include/mmu.h:122
Definition: armv7/boot/include/mmu.h:53
mmu_rgn_e
Definition: armv7/boot/include/mmu.h:50
unsigned PA1
Definition: armv7/boot/include/mmu.h:113
unsigned domain
Definition: armv7/boot/include/mmu.h:80
unsigned xn
Definition: armv7/boot/include/mmu.h:102
unsigned AP1
Definition: armv7/boot/include/mmu.h:83
unsigned ns
Definition: armv7/boot/include/mmu.h:63
unsigned AP1
Definition: armv7/boot/include/mmu.h:129
unsigned pxn
Definition: armv7/boot/include/mmu.h:62
unsigned unk
Definition: armv7/boot/include/mmu.h:81
mmu_sd_pt_t mmu_make_page_table(void *ptbaddr)
Definition: armv7/boot/mmu.c:256
unsigned xn
Definition: armv7/boot/include/mmu.h:124
unsigned PA2
Definition: armv7/boot/include/mmu.h:103
unsigned ns
Definition: armv7/boot/include/mmu.h:112
unsigned C
Definition: armv7/boot/include/mmu.h:78
unsigned one1
Definition: armv7/boot/include/mmu.h:99
unsigned S
Definition: armv7/boot/include/mmu.h:109
unsigned AP2
Definition: armv7/boot/include/mmu.h:108
union mmu_sd_pt_s mmu_sd_pt_t
void mmu_map_anysection(unsigned int *tt, void *pa, void *va, bool_t user, bool_t ro, bool_t xn, bool_t device, bool_t global, int super)
Definition: armv7/boot/mmu.c:387
void mmu_map_small_page(unsigned int *tt, void *pa, void *va, bool_t user, bool_t ro, bool_t xn, bool_t device, bool_t global)
Definition: armv7/boot/mmu.c:351
unsigned C
Definition: armv7/boot/include/mmu.h:127
unsigned B
Definition: armv7/boot/include/mmu.h:100
unsigned AP2
Definition: armv7/boot/include/mmu.h:131
unsigned aslong
Definition: armv7/boot/include/mmu.h:59
unsigned pxn
Definition: armv7/boot/include/mmu.h:98
unsigned secbaddr
Definition: armv7/boot/include/mmu.h:114
Definition: armv7/boot/include/mmu.h:52