| 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 |
#ifndef ARM_CACHE_H |
| 32 |
#define ARM_CACHE_H |
| 33 |
|
| 34 |
#include <stddef.h> |
| 35 |
#include <stdint.h> |
| 36 |
|
| 37 |
|
| 38 |
#define SCTLR_M (1 << 0) |
| 39 |
#define SCTLR_A (1 << 1) |
| 40 |
#define SCTLR_C (1 << 2) |
| 41 |
|
| 42 |
#define SCTLR_CP15BEN (1 << 5) |
| 43 |
|
| 44 |
#define SCTLR_B (1 << 7) |
| 45 |
|
| 46 |
#define SCTLR_SW (1 << 10) |
| 47 |
#define SCTLR_Z (1 << 11) |
| 48 |
#define SCTLR_I (1 << 12) |
| 49 |
#define SCTLR_V (1 << 13) |
| 50 |
#define SCTLR_RR (1 << 14) |
| 51 |
|
| 52 |
#define SCTLR_HA (1 << 17) |
| 53 |
|
| 54 |
|
| 55 |
#define SCTLR_WXN (1 << 19) |
| 56 |
#define SCTLR_UWXN (1 << 20) |
| 57 |
|
| 58 |
#define SCTLR_FI (1 << 21) |
| 59 |
#define SCTLR_U (1 << 22) |
| 60 |
#define SCTLR_VE (1 << 24) |
| 61 |
#define SCTLR_EE (1 << 25) |
| 62 |
|
| 63 |
#define SCTLR_NMFI (1 << 27) |
| 64 |
#define SCTLR_TRE (1 << 28) |
| 65 |
#define SCTLR_AFE (1 << 29) |
| 66 |
#define SCTLR_TE (1 << 30) |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
#define dmb() asm volatile ("dmb" : : : "memory") |
| 74 |
|
| 75 |
#define dsb() asm volatile ("dsb" : : : "memory") |
| 76 |
|
| 77 |
#define isb() asm volatile ("isb" : : : "memory") |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
static inline void tlbiall(void) |
| 85 |
{ |
| 86 |
asm volatile ("mcr p15, 0, %0, c8, c7, 0" : : "r" (0) : "memory"); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
static inline void tlbimvaa(unsigned long mva) |
| 91 |
{ |
| 92 |
asm volatile ("mcr p15, 0, %0, c8, c7, 3" : : "r" (mva) : "memory"); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
static inline void write_dacr(uint32_t val) |
| 97 |
{ |
| 98 |
asm volatile ("mcr p15, 0, %0, c3, c0, 0" : : "r" (val)); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
static inline void write_ttbr0(uint32_t val) |
| 103 |
{ |
| 104 |
asm volatile ("mcr p15, 0, %0, c2, c0, 0" : : "r" (val) : "memory"); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
static inline uint64_t read_ttbr0(void) |
| 109 |
{ |
| 110 |
uint32_t low, high; |
| 111 |
asm volatile ("mrrc p15, 0, %[low], %[high], c2" : |
| 112 |
[low] "=r" (low), [high] "=r" (high)); |
| 113 |
return ((uint64_t)high << 32) | low; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
static inline uint32_t read_ttbcr(void) |
| 118 |
{ |
| 119 |
uint32_t val = 0; |
| 120 |
asm volatile ("mrc p15, 0, %0, c2, c0, 2" : "=r" (val)); |
| 121 |
return val; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
static inline void write_ttbcr(uint32_t val) |
| 126 |
{ |
| 127 |
asm volatile ("mcr p15, 0, %0, c2, c0, 2" : : "r" (val) : "memory"); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
static inline void bpiall(void) |
| 136 |
{ |
| 137 |
asm volatile ("mcr p15, 0, %0, c7, c5, 6" : : "r" (0)); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
static inline void dccimvac(unsigned long mva) |
| 142 |
{ |
| 143 |
asm volatile ("mcr p15, 0, %0, c7, c14, 1" : : "r" (mva) : "memory"); |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
static inline void dccisw(uint32_t val) |
| 148 |
{ |
| 149 |
asm volatile ("mcr p15, 0, %0, c7, c14, 2" : : "r" (val) : "memory"); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
static inline void dccmvac(unsigned long mva) |
| 154 |
{ |
| 155 |
asm volatile ("mcr p15, 0, %0, c7, c10, 1" : : "r" (mva) : "memory"); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
static inline void dccsw(uint32_t val) |
| 160 |
{ |
| 161 |
asm volatile ("mcr p15, 0, %0, c7, c10, 2" : : "r" (val) : "memory"); |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
static inline void dcimvac(unsigned long mva) |
| 166 |
{ |
| 167 |
asm volatile ("mcr p15, 0, %0, c7, c6, 1" : : "r" (mva) : "memory"); |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
static inline void dcisw(uint32_t val) |
| 172 |
{ |
| 173 |
asm volatile ("mcr p15, 0, %0, c7, c6, 2" : : "r" (val) : "memory"); |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
static inline void iciallu(void) |
| 178 |
{ |
| 179 |
asm volatile ("mcr p15, 0, %0, c7, c5, 0" : : "r" (0)); |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
static inline uint32_t read_clidr(void) |
| 188 |
{ |
| 189 |
uint32_t val = 0; |
| 190 |
asm volatile ("mrc p15, 1, %0, c0, c0, 1" : "=r" (val)); |
| 191 |
return val; |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
static inline uint32_t read_ccsidr(void) |
| 196 |
{ |
| 197 |
uint32_t val = 0; |
| 198 |
asm volatile ("mrc p15, 1, %0, c0, c0, 0" : "=r" (val)); |
| 199 |
return val; |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
static inline uint32_t read_csselr(void) |
| 204 |
{ |
| 205 |
uint32_t val = 0; |
| 206 |
asm volatile ("mrc p15, 2, %0, c0, c0, 0" : "=r" (val)); |
| 207 |
return val; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
static inline void write_csselr(uint32_t val) |
| 212 |
{ |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
asm volatile ("mcr p15, 2, %0, c0, c0, 0" : : "r" (val)); |
| 218 |
isb(); |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
static inline uint32_t read_l2ctlr(void) |
| 223 |
{ |
| 224 |
uint32_t val = 0; |
| 225 |
asm volatile ("mrc p15, 1, %0, c9, c0, 2" : "=r" (val)); |
| 226 |
return val; |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
static inline void write_l2ctlr(uint32_t val) |
| 231 |
{ |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
asm volatile("mcr p15, 1, %0, c9, c0, 2" : : "r" (val) : "memory" ); |
| 237 |
isb(); |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
static inline uint32_t read_l2actlr(void) |
| 242 |
{ |
| 243 |
uint32_t val = 0; |
| 244 |
asm volatile ("mrc p15, 1, %0, c15, c0, 0" : "=r" (val)); |
| 245 |
return val; |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
static inline void write_l2actlr(uint32_t val) |
| 250 |
{ |
| 251 |
asm volatile ("mcr p15, 1, %0, c15, c0, 0" : : "r" (val) : "memory" ); |
| 252 |
isb(); |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
static inline uint32_t read_sctlr(void) |
| 257 |
{ |
| 258 |
uint32_t val; |
| 259 |
asm volatile ("mrc p15, 0, %0, c1, c0, 0" : "=r" (val)); |
| 260 |
return val; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
static inline void write_sctlr(uint32_t val) |
| 265 |
{ |
| 266 |
asm volatile ("mcr p15, 0, %0, c1, c0, 0" : : "r" (val) : "cc"); |
| 267 |
isb(); |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
static inline uint32_t read_dfar(void) |
| 272 |
{ |
| 273 |
uint32_t val; |
| 274 |
asm volatile ("mrc p15, 0, %0, c6, c0, 0" : "=r" (val)); |
| 275 |
return val; |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
static inline uint32_t read_dfsr(void) |
| 280 |
{ |
| 281 |
uint32_t val; |
| 282 |
asm volatile ("mrc p15, 0, %0, c5, c0, 0" : "=r" (val)); |
| 283 |
return val; |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
static inline uint32_t read_ifar(void) |
| 288 |
{ |
| 289 |
uint32_t val; |
| 290 |
asm volatile ("mrc p15, 0, %0, c6, c0, 2" : "=r" (val)); |
| 291 |
return val; |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
static inline uint32_t read_ifsr(void) |
| 296 |
{ |
| 297 |
uint32_t val; |
| 298 |
asm volatile ("mrc p15, 0, %0, c5, c0, 1" : "=r" (val)); |
| 299 |
return val; |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
static inline uint32_t read_adfsr(void) |
| 304 |
{ |
| 305 |
uint32_t val; |
| 306 |
asm volatile ("mrc p15, 0, %0, c5, c1, 0" : "=r" (val)); |
| 307 |
return val; |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
static inline uint32_t read_aifsr(void) |
| 312 |
{ |
| 313 |
uint32_t val; |
| 314 |
asm volatile ("mrc p15, 0, %0, c5, c1, 1" : "=r" (val)); |
| 315 |
return val; |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
void dcache_clean_invalidate_all(void); |
| 324 |
|
| 325 |
|
| 326 |
void dcache_clean_by_mva(void const *addr, size_t len); |
| 327 |
|
| 328 |
|
| 329 |
void dcache_clean_invalidate_by_mva(void const *addr, size_t len); |
| 330 |
|
| 331 |
|
| 332 |
void dcache_invalidate_by_mva(void const *addr, size_t len); |
| 333 |
|
| 334 |
void dcache_clean_all(void); |
| 335 |
|
| 336 |
|
| 337 |
void dcache_invalidate_all(void); |
| 338 |
|
| 339 |
|
| 340 |
unsigned int dcache_line_bytes(void); |
| 341 |
|
| 342 |
|
| 343 |
void dcache_mmu_disable(void); |
| 344 |
|
| 345 |
|
| 346 |
void dcache_mmu_enable(void); |
| 347 |
|
| 348 |
|
| 349 |
void cache_sync_instructions(void); |
| 350 |
|
| 351 |
|
| 352 |
void tlb_invalidate_all(void); |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
void mmu_init(void); |
| 360 |
|
| 361 |
enum dcache_policy { |
| 362 |
DCACHE_OFF, |
| 363 |
DCACHE_WRITEBACK, |
| 364 |
DCACHE_WRITETHROUGH, |
| 365 |
}; |
| 366 |
|
| 367 |
|
| 368 |
void mmu_disable_range(unsigned long start_mb, unsigned long size_mb); |
| 369 |
|
| 370 |
void mmu_config_range(unsigned long start_mb, unsigned long size_mb, |
| 371 |
enum dcache_policy policy); |
| 372 |
|
| 373 |
#endif |