Pip
Architecture-dependent parts of Pip: MAL, IAL and boot
cache.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_CACHE_H_
35 #define DEF_CACHE_H_
36 
37 #include "coproc.h"
38 
39 /* B2.2.6 About ARMv7 cache and branch predictor maintenance functionality */
40 
41 /* B4.2.1 Cache and branch predictor maintenance operations, VMSA */
42 
43 /* branch_pred_enable: Enable branch predictor */
44 static inline void branch_pred_enable(void)
45 {
46  unsigned reg;
47 
48  READ_CP(reg, ID_SCTLR);
49  /* Set branch predictor bit in SCTLR*/
50  reg |= SCTLR_BRANCH_PRED;
51  WRITE_CP(reg, ID_SCTLR);
52 }
53 /* branch_pred_disable: Disable branch predictor */
54 static inline void branch_pred_disable(void)
55 {
56  unsigned reg;
57 
58  READ_CP(reg, ID_SCTLR);
59  /* Set branch predictor bit in SCTLR*/
60  reg &= ~SCTLR_BRANCH_PRED;
61  WRITE_CP(reg, ID_SCTLR);
62 }
63 /* caches_enable: Enable instruction & data caches */
64 static inline void caches_enable(void)
65 {
66  unsigned reg;
67 
68  ISB(); DSB();
69  READ_CP(reg, ID_SCTLR);
70  reg |= SCTLR_ICACHE | SCTLR_DCACHE;
71  WRITE_CP(reg, ID_SCTLR);
72  ISB(); DSB();
73 }
74 /* caches_disable: Enable instruction & data caches */
75 static inline void caches_disable(void)
76 {
77  unsigned reg;
78 
79  ISB(); DSB();
80  READ_CP(reg, ID_SCTLR);
81  reg &= ~(SCTLR_ICACHE | SCTLR_DCACHE);
82  WRITE_CP(reg, ID_SCTLR);
83  ISB(); DSB();
84 }
85 /* dcache_enable: Enable data cache */
86 static inline void dcache_enable(void)
87 {
88  unsigned reg;
89 
90  /* Use ISB & DSB to ensure memory operations ordering */
91  ISB(); DSB();
92  READ_CP(reg, ID_SCTLR);
93  reg |= SCTLR_DCACHE;
94  WRITE_CP(reg, ID_SCTLR);
95  ISB(); DSB();
96 }
97 /* dcache_disable: Disable data cache */
98 static inline void dcache_disable(void)
99 {
100  unsigned reg;
101 
102  ISB(); DSB();
103  READ_CP(reg, ID_SCTLR);
104  reg &= ~SCTLR_DCACHE;
105  WRITE_CP(reg, ID_SCTLR);
106  ISB(); DSB();
107 }
108 /* icache_enable: Enable instruction cache */
109 static inline void icache_enable(void)
110 {
111  unsigned reg;
112 
113  ISB(); DSB();
114  READ_CP(reg, ID_SCTLR);
115  reg |= SCTLR_ICACHE;
116  WRITE_CP(reg, ID_SCTLR);
117  ISB(); DSB();
118 }
119 /* icache_enable: Disable instruction cache */
120 static inline void icache_disable(void)
121 {
122  unsigned reg;
123 
124  ISB(); DSB();
125  READ_CP(reg, ID_SCTLR);
126  reg &= ~SCTLR_ICACHE;
127  WRITE_CP(reg, ID_SCTLR);
128  ISB(); DSB();
129 }
130 /* dcache_clean_range: Clean data cache of memory range */
131 void dcache_clean_range(void *addr_, unsigned size);
132 
133 /* dcache_inval_range: Invalidate data cache of memory range */
134 void dcache_inval_range(void *addr_, unsigned size);
135 
136 /* dcache_flush_range: Clean & invalidate data cache of memory range */
137 void dcache_flush_range(void *addr_, unsigned size);
138 
139 /* dcache_flush_all: Clean & invalidate all data cache */
140 void dcache_flush_all(void);
141 
142 void dcache_flush_disable(void);
143 
144 #endif
static void icache_enable(void)
Definition: cache.h:109
#define SCTLR_BRANCH_PRED
Definition: coproc.h:68
void dcache_flush_disable(void)
#define ID_SCTLR
Definition: coproc.h:116
#define READ_CP(dst, id)
Definition: coproc.h:203
void dcache_clean_range(void *addr_, unsigned size)
void dcache_flush_range(void *addr_, unsigned size)
#define SCTLR_DCACHE
Definition: coproc.h:64
#define DSB()
Definition: coproc.h:213
#define ISB()
Definition: coproc.h:221
void dcache_inval_range(void *addr_, unsigned size)
static void branch_pred_disable(void)
Definition: cache.h:54
uint32_t size
This is reserved by symbol table & ELF headers.
Definition: multiboot.h:67
void dcache_flush_all(void)
static void caches_disable(void)
Definition: cache.h:75
static void dcache_disable(void)
Definition: cache.h:98
static void icache_disable(void)
Definition: cache.h:120
static void branch_pred_enable(void)
Definition: cache.h:44
#define SCTLR_ICACHE
Definition: coproc.h:69
static void caches_enable(void)
Definition: cache.h:64
static void dcache_enable(void)
Definition: cache.h:86
#define WRITE_CP(src, id)
Definition: coproc.h:204