blob: cd3f6c10ae1286c93dc93881c40064ab2ae8bcae [file] [log] [blame]
David Feng85fd5f12013-12-14 11:47:35 +08001/*
2 * (C) Copyright 2013
3 * David Feng <fenghua@phytium.com.cn>
4 *
Alexander Grafe317fe82016-03-04 01:09:47 +01005 * (C) Copyright 2016
6 * Alexander Graf <agraf@suse.de>
7 *
David Feng85fd5f12013-12-14 11:47:35 +08008 * SPDX-License-Identifier: GPL-2.0+
9 */
10
11#include <common.h>
12#include <asm/system.h>
13#include <asm/armv8/mmu.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17#ifndef CONFIG_SYS_DCACHE_OFF
Sergey Temerkhanov78eaa492015-10-14 09:55:45 -070018
Alexander Grafe317fe82016-03-04 01:09:47 +010019/*
20 * With 4k page granule, a virtual address is split into 4 lookup parts
21 * spanning 9 bits each:
22 *
23 * _______________________________________________
24 * | | | | | | |
25 * | 0 | Lv0 | Lv1 | Lv2 | Lv3 | off |
26 * |_______|_______|_______|_______|_______|_______|
27 * 63-48 47-39 38-30 29-21 20-12 11-00
28 *
29 * mask page size
30 *
31 * Lv0: FF8000000000 --
32 * Lv1: 7FC0000000 1G
33 * Lv2: 3FE00000 2M
34 * Lv3: 1FF000 4K
35 * off: FFF
36 */
Sergey Temerkhanov78eaa492015-10-14 09:55:45 -070037
York Suna81fcd12016-06-24 16:46:20 -070038u64 get_tcr(int el, u64 *pips, u64 *pva_bits)
Alexander Graffb74cc12016-03-04 01:09:45 +010039{
40 u64 max_addr = 0;
41 u64 ips, va_bits;
42 u64 tcr;
43 int i;
44
45 /* Find the largest address we need to support */
Alexander Graf6b3e7ca2016-03-04 01:09:48 +010046 for (i = 0; mem_map[i].size || mem_map[i].attrs; i++)
York Sunc7104e52016-06-24 16:46:22 -070047 max_addr = max(max_addr, mem_map[i].virt + mem_map[i].size);
Alexander Graffb74cc12016-03-04 01:09:45 +010048
49 /* Calculate the maximum physical (and thus virtual) address */
50 if (max_addr > (1ULL << 44)) {
51 ips = 5;
52 va_bits = 48;
53 } else if (max_addr > (1ULL << 42)) {
54 ips = 4;
55 va_bits = 44;
56 } else if (max_addr > (1ULL << 40)) {
57 ips = 3;
58 va_bits = 42;
59 } else if (max_addr > (1ULL << 36)) {
60 ips = 2;
61 va_bits = 40;
62 } else if (max_addr > (1ULL << 32)) {
63 ips = 1;
64 va_bits = 36;
65 } else {
66 ips = 0;
67 va_bits = 32;
68 }
69
70 if (el == 1) {
Alexander Graff03c0e42016-03-04 01:09:46 +010071 tcr = TCR_EL1_RSVD | (ips << 32) | TCR_EPD1_DISABLE;
Alexander Graffb74cc12016-03-04 01:09:45 +010072 } else if (el == 2) {
73 tcr = TCR_EL2_RSVD | (ips << 16);
74 } else {
75 tcr = TCR_EL3_RSVD | (ips << 16);
76 }
77
78 /* PTWs cacheable, inner/outer WBWA and inner shareable */
Alexander Grafe317fe82016-03-04 01:09:47 +010079 tcr |= TCR_TG0_4K | TCR_SHARED_INNER | TCR_ORGN_WBWA | TCR_IRGN_WBWA;
80 tcr |= TCR_T0SZ(va_bits);
Alexander Graffb74cc12016-03-04 01:09:45 +010081
82 if (pips)
83 *pips = ips;
84 if (pva_bits)
85 *pva_bits = va_bits;
86
87 return tcr;
88}
89
Alexander Grafe317fe82016-03-04 01:09:47 +010090#define MAX_PTE_ENTRIES 512
91
92static int pte_type(u64 *pte)
93{
94 return *pte & PTE_TYPE_MASK;
95}
96
97/* Returns the LSB number for a PTE on level <level> */
98static int level2shift(int level)
99{
100 /* Page is 12 bits wide, every level translates 9 bits */
101 return (12 + 9 * (3 - level));
102}
103
104static u64 *find_pte(u64 addr, int level)
105{
106 int start_level = 0;
107 u64 *pte;
108 u64 idx;
109 u64 va_bits;
110 int i;
111
112 debug("addr=%llx level=%d\n", addr, level);
113
114 get_tcr(0, NULL, &va_bits);
115 if (va_bits < 39)
116 start_level = 1;
117
118 if (level < start_level)
119 return NULL;
120
121 /* Walk through all page table levels to find our PTE */
122 pte = (u64*)gd->arch.tlb_addr;
123 for (i = start_level; i < 4; i++) {
124 idx = (addr >> level2shift(i)) & 0x1FF;
125 pte += idx;
126 debug("idx=%llx PTE %p at level %d: %llx\n", idx, pte, i, *pte);
127
128 /* Found it */
129 if (i == level)
130 return pte;
131 /* PTE is no table (either invalid or block), can't traverse */
132 if (pte_type(pte) != PTE_TYPE_TABLE)
133 return NULL;
134 /* Off to the next level */
135 pte = (u64*)(*pte & 0x0000fffffffff000ULL);
136 }
137
138 /* Should never reach here */
139 return NULL;
140}
141
142/* Returns and creates a new full table (512 entries) */
143static u64 *create_table(void)
144{
145 u64 *new_table = (u64*)gd->arch.tlb_fillptr;
146 u64 pt_len = MAX_PTE_ENTRIES * sizeof(u64);
147
148 /* Allocate MAX_PTE_ENTRIES pte entries */
149 gd->arch.tlb_fillptr += pt_len;
150
151 if (gd->arch.tlb_fillptr - gd->arch.tlb_addr > gd->arch.tlb_size)
152 panic("Insufficient RAM for page table: 0x%lx > 0x%lx. "
153 "Please increase the size in get_page_table_size()",
154 gd->arch.tlb_fillptr - gd->arch.tlb_addr,
155 gd->arch.tlb_size);
156
157 /* Mark all entries as invalid */
158 memset(new_table, 0, pt_len);
159
160 return new_table;
161}
162
163static void set_pte_table(u64 *pte, u64 *table)
164{
165 /* Point *pte to the new table */
166 debug("Setting %p to addr=%p\n", pte, table);
167 *pte = PTE_TYPE_TABLE | (ulong)table;
168}
169
York Sunf44afe72016-06-24 16:46:21 -0700170/* Splits a block PTE into table with subpages spanning the old block */
171static void split_block(u64 *pte, int level)
172{
173 u64 old_pte = *pte;
174 u64 *new_table;
175 u64 i = 0;
176 /* level describes the parent level, we need the child ones */
177 int levelshift = level2shift(level + 1);
178
179 if (pte_type(pte) != PTE_TYPE_BLOCK)
180 panic("PTE %p (%llx) is not a block. Some driver code wants to "
181 "modify dcache settings for an range not covered in "
182 "mem_map.", pte, old_pte);
183
184 new_table = create_table();
185 debug("Splitting pte %p (%llx) into %p\n", pte, old_pte, new_table);
186
187 for (i = 0; i < MAX_PTE_ENTRIES; i++) {
188 new_table[i] = old_pte | (i << levelshift);
189
190 /* Level 3 block PTEs have the table type */
191 if ((level + 1) == 3)
192 new_table[i] |= PTE_TYPE_TABLE;
193
194 debug("Setting new_table[%lld] = %llx\n", i, new_table[i]);
195 }
196
197 /* Set the new table into effect */
198 set_pte_table(pte, new_table);
199}
200
Alexander Grafe317fe82016-03-04 01:09:47 +0100201/* Add one mm_region map entry to the page tables */
202static void add_map(struct mm_region *map)
203{
204 u64 *pte;
York Sunc7104e52016-06-24 16:46:22 -0700205 u64 virt = map->virt;
206 u64 phys = map->phys;
Alexander Grafe317fe82016-03-04 01:09:47 +0100207 u64 size = map->size;
208 u64 attrs = map->attrs | PTE_TYPE_BLOCK | PTE_BLOCK_AF;
209 u64 blocksize;
210 int level;
211 u64 *new_table;
212
213 while (size) {
York Sunc7104e52016-06-24 16:46:22 -0700214 pte = find_pte(virt, 0);
Alexander Grafe317fe82016-03-04 01:09:47 +0100215 if (pte && (pte_type(pte) == PTE_TYPE_FAULT)) {
York Sunc7104e52016-06-24 16:46:22 -0700216 debug("Creating table for virt 0x%llx\n", virt);
Alexander Grafe317fe82016-03-04 01:09:47 +0100217 new_table = create_table();
218 set_pte_table(pte, new_table);
219 }
220
221 for (level = 1; level < 4; level++) {
York Sunc7104e52016-06-24 16:46:22 -0700222 pte = find_pte(virt, level);
York Sunf44afe72016-06-24 16:46:21 -0700223 if (!pte)
224 panic("pte not found\n");
York Sunc7104e52016-06-24 16:46:22 -0700225
Alexander Grafe317fe82016-03-04 01:09:47 +0100226 blocksize = 1ULL << level2shift(level);
York Sunc7104e52016-06-24 16:46:22 -0700227 debug("Checking if pte fits for virt=%llx size=%llx blocksize=%llx\n",
228 virt, size, blocksize);
229 if (size >= blocksize && !(virt & (blocksize - 1))) {
Alexander Grafe317fe82016-03-04 01:09:47 +0100230 /* Page fits, create block PTE */
York Sunc7104e52016-06-24 16:46:22 -0700231 debug("Setting PTE %p to block virt=%llx\n",
232 pte, virt);
233 *pte = phys | attrs;
234 virt += blocksize;
235 phys += blocksize;
Alexander Grafe317fe82016-03-04 01:09:47 +0100236 size -= blocksize;
237 break;
York Sunf44afe72016-06-24 16:46:21 -0700238 } else if (pte_type(pte) == PTE_TYPE_FAULT) {
Alexander Grafe317fe82016-03-04 01:09:47 +0100239 /* Page doesn't fit, create subpages */
York Sunc7104e52016-06-24 16:46:22 -0700240 debug("Creating subtable for virt 0x%llx blksize=%llx\n",
241 virt, blocksize);
Alexander Grafe317fe82016-03-04 01:09:47 +0100242 new_table = create_table();
243 set_pte_table(pte, new_table);
York Sunf44afe72016-06-24 16:46:21 -0700244 } else if (pte_type(pte) == PTE_TYPE_BLOCK) {
York Sunc7104e52016-06-24 16:46:22 -0700245 debug("Split block into subtable for virt 0x%llx blksize=0x%llx\n",
246 virt, blocksize);
York Sunf44afe72016-06-24 16:46:21 -0700247 split_block(pte, level);
Alexander Grafe317fe82016-03-04 01:09:47 +0100248 }
249 }
250 }
251}
252
Alexander Grafe317fe82016-03-04 01:09:47 +0100253enum pte_type {
254 PTE_INVAL,
255 PTE_BLOCK,
256 PTE_LEVEL,
257};
258
259/*
260 * This is a recursively called function to count the number of
261 * page tables we need to cover a particular PTE range. If you
262 * call this with level = -1 you basically get the full 48 bit
263 * coverage.
264 */
265static int count_required_pts(u64 addr, int level, u64 maxaddr)
266{
267 int levelshift = level2shift(level);
268 u64 levelsize = 1ULL << levelshift;
269 u64 levelmask = levelsize - 1;
270 u64 levelend = addr + levelsize;
271 int r = 0;
272 int i;
273 enum pte_type pte_type = PTE_INVAL;
274
Alexander Graf6b3e7ca2016-03-04 01:09:48 +0100275 for (i = 0; mem_map[i].size || mem_map[i].attrs; i++) {
Alexander Grafe317fe82016-03-04 01:09:47 +0100276 struct mm_region *map = &mem_map[i];
York Sunc7104e52016-06-24 16:46:22 -0700277 u64 start = map->virt;
Alexander Grafe317fe82016-03-04 01:09:47 +0100278 u64 end = start + map->size;
279
280 /* Check if the PTE would overlap with the map */
281 if (max(addr, start) <= min(levelend, end)) {
282 start = max(addr, start);
283 end = min(levelend, end);
284
285 /* We need a sub-pt for this level */
286 if ((start & levelmask) || (end & levelmask)) {
287 pte_type = PTE_LEVEL;
288 break;
289 }
Sergey Temerkhanov78eaa492015-10-14 09:55:45 -0700290
Alexander Grafe317fe82016-03-04 01:09:47 +0100291 /* Lv0 can not do block PTEs, so do levels here too */
292 if (level <= 0) {
293 pte_type = PTE_LEVEL;
294 break;
Sergey Temerkhanov78eaa492015-10-14 09:55:45 -0700295 }
296
Alexander Grafe317fe82016-03-04 01:09:47 +0100297 /* PTE is active, but fits into a block */
298 pte_type = PTE_BLOCK;
299 }
300 }
301
302 /*
303 * Block PTEs at this level are already covered by the parent page
304 * table, so we only need to count sub page tables.
305 */
306 if (pte_type == PTE_LEVEL) {
307 int sublevel = level + 1;
308 u64 sublevelsize = 1ULL << level2shift(sublevel);
309
310 /* Account for the new sub page table ... */
311 r = 1;
312
313 /* ... and for all child page tables that one might have */
314 for (i = 0; i < MAX_PTE_ENTRIES; i++) {
315 r += count_required_pts(addr, sublevel, maxaddr);
316 addr += sublevelsize;
317
318 if (addr >= maxaddr) {
319 /*
320 * We reached the end of address space, no need
321 * to look any further.
322 */
323 break;
324 }
Sergey Temerkhanov78eaa492015-10-14 09:55:45 -0700325 }
326 }
Alexander Grafe317fe82016-03-04 01:09:47 +0100327
328 return r;
329}
330
331/* Returns the estimated required size of all page tables */
Alexander Grafbc78b922016-03-21 20:26:12 +0100332__weak u64 get_page_table_size(void)
Alexander Grafe317fe82016-03-04 01:09:47 +0100333{
334 u64 one_pt = MAX_PTE_ENTRIES * sizeof(u64);
335 u64 size = 0;
336 u64 va_bits;
337 int start_level = 0;
338
339 get_tcr(0, NULL, &va_bits);
340 if (va_bits < 39)
341 start_level = 1;
342
343 /* Account for all page tables we would need to cover our memory map */
344 size = one_pt * count_required_pts(0, start_level - 1, 1ULL << va_bits);
345
346 /*
347 * We need to duplicate our page table once to have an emergency pt to
348 * resort to when splitting page tables later on
349 */
350 size *= 2;
351
352 /*
353 * We may need to split page tables later on if dcache settings change,
354 * so reserve up to 4 (random pick) page tables for that.
355 */
356 size += one_pt * 4;
357
358 return size;
359}
360
York Suna81fcd12016-06-24 16:46:20 -0700361void setup_pgtables(void)
Alexander Grafe317fe82016-03-04 01:09:47 +0100362{
363 int i;
364
York Suna81fcd12016-06-24 16:46:20 -0700365 if (!gd->arch.tlb_fillptr || !gd->arch.tlb_addr)
366 panic("Page table pointer not setup.");
367
Alexander Grafe317fe82016-03-04 01:09:47 +0100368 /*
369 * Allocate the first level we're on with invalidate entries.
370 * If the starting level is 0 (va_bits >= 39), then this is our
371 * Lv0 page table, otherwise it's the entry Lv1 page table.
372 */
373 create_table();
374
375 /* Now add all MMU table entries one after another to the table */
Alexander Graf6b3e7ca2016-03-04 01:09:48 +0100376 for (i = 0; mem_map[i].size || mem_map[i].attrs; i++)
Alexander Grafe317fe82016-03-04 01:09:47 +0100377 add_map(&mem_map[i]);
Alexander Grafe317fe82016-03-04 01:09:47 +0100378}
379
380static void setup_all_pgtables(void)
381{
382 u64 tlb_addr = gd->arch.tlb_addr;
Alexander Graffa3754e2016-07-30 23:13:03 +0200383 u64 tlb_size = gd->arch.tlb_size;
Alexander Grafe317fe82016-03-04 01:09:47 +0100384
385 /* Reset the fill ptr */
386 gd->arch.tlb_fillptr = tlb_addr;
387
388 /* Create normal system page tables */
389 setup_pgtables();
390
391 /* Create emergency page tables */
Alexander Graffa3754e2016-07-30 23:13:03 +0200392 gd->arch.tlb_size -= (uintptr_t)gd->arch.tlb_fillptr -
393 (uintptr_t)gd->arch.tlb_addr;
Alexander Grafe317fe82016-03-04 01:09:47 +0100394 gd->arch.tlb_addr = gd->arch.tlb_fillptr;
395 setup_pgtables();
396 gd->arch.tlb_emerg = gd->arch.tlb_addr;
397 gd->arch.tlb_addr = tlb_addr;
Alexander Graffa3754e2016-07-30 23:13:03 +0200398 gd->arch.tlb_size = tlb_size;
Sergey Temerkhanov78eaa492015-10-14 09:55:45 -0700399}
400
David Feng85fd5f12013-12-14 11:47:35 +0800401/* to activate the MMU we need to set up virtual memory */
Stephen Warren7333c6a2015-10-05 12:09:00 -0600402__weak void mmu_setup(void)
David Feng85fd5f12013-12-14 11:47:35 +0800403{
Thierry Reding59c364d2015-07-22 17:10:11 -0600404 int el;
David Feng85fd5f12013-12-14 11:47:35 +0800405
Alexander Grafe317fe82016-03-04 01:09:47 +0100406 /* Set up page tables only once */
407 if (!gd->arch.tlb_fillptr)
408 setup_all_pgtables();
Alexander Graffb74cc12016-03-04 01:09:45 +0100409
410 el = current_el();
411 set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(el, NULL, NULL),
412 MEMORY_ATTRIBUTES);
Alexander Graffb74cc12016-03-04 01:09:45 +0100413
David Feng85fd5f12013-12-14 11:47:35 +0800414 /* enable the mmu */
415 set_sctlr(get_sctlr() | CR_M);
416}
417
418/*
419 * Performs a invalidation of the entire data cache at all levels
420 */
421void invalidate_dcache_all(void)
422{
York Sunef042012014-02-26 13:26:04 -0800423 __asm_invalidate_dcache_all();
David Feng85fd5f12013-12-14 11:47:35 +0800424}
425
426/*
York Sun1ce575f2015-01-06 13:18:42 -0800427 * Performs a clean & invalidation of the entire data cache at all levels.
428 * This function needs to be inline to avoid using stack.
429 * __asm_flush_l3_cache return status of timeout
David Feng85fd5f12013-12-14 11:47:35 +0800430 */
York Sun1ce575f2015-01-06 13:18:42 -0800431inline void flush_dcache_all(void)
David Feng85fd5f12013-12-14 11:47:35 +0800432{
York Sun1ce575f2015-01-06 13:18:42 -0800433 int ret;
434
David Feng85fd5f12013-12-14 11:47:35 +0800435 __asm_flush_dcache_all();
York Sun1ce575f2015-01-06 13:18:42 -0800436 ret = __asm_flush_l3_cache();
437 if (ret)
438 debug("flushing dcache returns 0x%x\n", ret);
439 else
440 debug("flushing dcache successfully.\n");
David Feng85fd5f12013-12-14 11:47:35 +0800441}
442
443/*
444 * Invalidates range in all levels of D-cache/unified cache
445 */
446void invalidate_dcache_range(unsigned long start, unsigned long stop)
447{
448 __asm_flush_dcache_range(start, stop);
449}
450
451/*
452 * Flush range(clean & invalidate) from all levels of D-cache/unified cache
453 */
454void flush_dcache_range(unsigned long start, unsigned long stop)
455{
456 __asm_flush_dcache_range(start, stop);
457}
458
459void dcache_enable(void)
460{
461 /* The data cache is not active unless the mmu is enabled */
462 if (!(get_sctlr() & CR_M)) {
463 invalidate_dcache_all();
464 __asm_invalidate_tlb_all();
465 mmu_setup();
466 }
467
468 set_sctlr(get_sctlr() | CR_C);
469}
470
471void dcache_disable(void)
472{
473 uint32_t sctlr;
474
475 sctlr = get_sctlr();
476
477 /* if cache isn't enabled no need to disable */
478 if (!(sctlr & CR_C))
479 return;
480
481 set_sctlr(sctlr & ~(CR_C|CR_M));
482
483 flush_dcache_all();
484 __asm_invalidate_tlb_all();
485}
486
487int dcache_status(void)
488{
489 return (get_sctlr() & CR_C) != 0;
490}
491
Siva Durga Prasad Paladuguba2432a2015-06-26 18:05:07 +0530492u64 *__weak arch_get_page_table(void) {
493 puts("No page table offset defined\n");
494
495 return NULL;
496}
497
Alexander Grafe317fe82016-03-04 01:09:47 +0100498static bool is_aligned(u64 addr, u64 size, u64 align)
499{
500 return !(addr & (align - 1)) && !(size & (align - 1));
501}
502
503static u64 set_one_region(u64 start, u64 size, u64 attrs, int level)
504{
505 int levelshift = level2shift(level);
506 u64 levelsize = 1ULL << levelshift;
507 u64 *pte = find_pte(start, level);
508
509 /* Can we can just modify the current level block PTE? */
510 if (is_aligned(start, size, levelsize)) {
511 *pte &= ~PMD_ATTRINDX_MASK;
512 *pte |= attrs;
513 debug("Set attrs=%llx pte=%p level=%d\n", attrs, pte, level);
514
515 return levelsize;
516 }
517
518 /* Unaligned or doesn't fit, maybe split block into table */
519 debug("addr=%llx level=%d pte=%p (%llx)\n", start, level, pte, *pte);
520
521 /* Maybe we need to split the block into a table */
522 if (pte_type(pte) == PTE_TYPE_BLOCK)
523 split_block(pte, level);
524
525 /* And then double-check it became a table or already is one */
526 if (pte_type(pte) != PTE_TYPE_TABLE)
527 panic("PTE %p (%llx) for addr=%llx should be a table",
528 pte, *pte, start);
529
530 /* Roll on to the next page table level */
531 return 0;
532}
533
534void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
535 enum dcache_option option)
536{
537 u64 attrs = PMD_ATTRINDX(option);
538 u64 real_start = start;
539 u64 real_size = size;
540
541 debug("start=%lx size=%lx\n", (ulong)start, (ulong)size);
542
York Suna81fcd12016-06-24 16:46:20 -0700543 if (!gd->arch.tlb_emerg)
544 panic("Emergency page table not setup.");
545
Alexander Grafe317fe82016-03-04 01:09:47 +0100546 /*
547 * We can not modify page tables that we're currently running on,
548 * so we first need to switch to the "emergency" page tables where
549 * we can safely modify our primary page tables and then switch back
550 */
551 __asm_switch_ttbr(gd->arch.tlb_emerg);
552
553 /*
554 * Loop through the address range until we find a page granule that fits
555 * our alignment constraints, then set it to the new cache attributes
556 */
557 while (size > 0) {
558 int level;
559 u64 r;
560
561 for (level = 1; level < 4; level++) {
562 r = set_one_region(start, size, attrs, level);
563 if (r) {
564 /* PTE successfully replaced */
565 size -= r;
566 start += r;
567 break;
568 }
569 }
570
571 }
572
573 /* We're done modifying page tables, switch back to our primary ones */
574 __asm_switch_ttbr(gd->arch.tlb_addr);
575
576 /*
577 * Make sure there's nothing stale in dcache for a region that might
578 * have caches off now
579 */
580 flush_dcache_range(real_start, real_start + real_size);
581}
Sergey Temerkhanov78eaa492015-10-14 09:55:45 -0700582
David Feng85fd5f12013-12-14 11:47:35 +0800583#else /* CONFIG_SYS_DCACHE_OFF */
584
Alexander Grafbc40da92016-03-04 01:09:55 +0100585/*
586 * For SPL builds, we may want to not have dcache enabled. Any real U-Boot
587 * running however really wants to have dcache and the MMU active. Check that
588 * everything is sane and give the developer a hint if it isn't.
589 */
590#ifndef CONFIG_SPL_BUILD
591#error Please describe your MMU layout in CONFIG_SYS_MEM_MAP and enable dcache.
592#endif
593
David Feng85fd5f12013-12-14 11:47:35 +0800594void invalidate_dcache_all(void)
595{
596}
597
598void flush_dcache_all(void)
599{
600}
601
David Feng85fd5f12013-12-14 11:47:35 +0800602void dcache_enable(void)
603{
604}
605
606void dcache_disable(void)
607{
608}
609
610int dcache_status(void)
611{
612 return 0;
613}
614
Siva Durga Prasad Paladuguba2432a2015-06-26 18:05:07 +0530615void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
616 enum dcache_option option)
617{
618}
619
David Feng85fd5f12013-12-14 11:47:35 +0800620#endif /* CONFIG_SYS_DCACHE_OFF */
621
622#ifndef CONFIG_SYS_ICACHE_OFF
623
624void icache_enable(void)
625{
York Sunef042012014-02-26 13:26:04 -0800626 __asm_invalidate_icache_all();
David Feng85fd5f12013-12-14 11:47:35 +0800627 set_sctlr(get_sctlr() | CR_I);
628}
629
630void icache_disable(void)
631{
632 set_sctlr(get_sctlr() & ~CR_I);
633}
634
635int icache_status(void)
636{
637 return (get_sctlr() & CR_I) != 0;
638}
639
640void invalidate_icache_all(void)
641{
642 __asm_invalidate_icache_all();
643}
644
645#else /* CONFIG_SYS_ICACHE_OFF */
646
647void icache_enable(void)
648{
649}
650
651void icache_disable(void)
652{
653}
654
655int icache_status(void)
656{
657 return 0;
658}
659
660void invalidate_icache_all(void)
661{
662}
663
664#endif /* CONFIG_SYS_ICACHE_OFF */
665
666/*
667 * Enable dCache & iCache, whether cache is actually enabled
668 * depend on CONFIG_SYS_DCACHE_OFF and CONFIG_SYS_ICACHE_OFF
669 */
York Suna84cd722014-06-23 15:15:54 -0700670void __weak enable_caches(void)
David Feng85fd5f12013-12-14 11:47:35 +0800671{
672 icache_enable();
673 dcache_enable();
674}