cache_v8.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. /*
  2. * (C) Copyright 2013
  3. * David Feng <fenghua@phytium.com.cn>
  4. *
  5. * (C) Copyright 2016
  6. * Alexander Graf <agraf@suse.de>
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <asm/system.h>
  12. #include <asm/armv8/mmu.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. #ifndef CONFIG_SYS_DCACHE_OFF
  15. /*
  16. * With 4k page granule, a virtual address is split into 4 lookup parts
  17. * spanning 9 bits each:
  18. *
  19. * _______________________________________________
  20. * | | | | | | |
  21. * | 0 | Lv0 | Lv1 | Lv2 | Lv3 | off |
  22. * |_______|_______|_______|_______|_______|_______|
  23. * 63-48 47-39 38-30 29-21 20-12 11-00
  24. *
  25. * mask page size
  26. *
  27. * Lv0: FF8000000000 --
  28. * Lv1: 7FC0000000 1G
  29. * Lv2: 3FE00000 2M
  30. * Lv3: 1FF000 4K
  31. * off: FFF
  32. */
  33. #ifdef CONFIG_SYS_FULL_VA
  34. static struct mm_region mem_map[] = CONFIG_SYS_MEM_MAP;
  35. static u64 get_tcr(int el, u64 *pips, u64 *pva_bits)
  36. {
  37. u64 max_addr = 0;
  38. u64 ips, va_bits;
  39. u64 tcr;
  40. int i;
  41. /* Find the largest address we need to support */
  42. for (i = 0; i < ARRAY_SIZE(mem_map); i++)
  43. max_addr = max(max_addr, mem_map[i].base + mem_map[i].size);
  44. /* Calculate the maximum physical (and thus virtual) address */
  45. if (max_addr > (1ULL << 44)) {
  46. ips = 5;
  47. va_bits = 48;
  48. } else if (max_addr > (1ULL << 42)) {
  49. ips = 4;
  50. va_bits = 44;
  51. } else if (max_addr > (1ULL << 40)) {
  52. ips = 3;
  53. va_bits = 42;
  54. } else if (max_addr > (1ULL << 36)) {
  55. ips = 2;
  56. va_bits = 40;
  57. } else if (max_addr > (1ULL << 32)) {
  58. ips = 1;
  59. va_bits = 36;
  60. } else {
  61. ips = 0;
  62. va_bits = 32;
  63. }
  64. if (el == 1) {
  65. tcr = TCR_EL1_RSVD | (ips << 32) | TCR_EPD1_DISABLE;
  66. } else if (el == 2) {
  67. tcr = TCR_EL2_RSVD | (ips << 16);
  68. } else {
  69. tcr = TCR_EL3_RSVD | (ips << 16);
  70. }
  71. /* PTWs cacheable, inner/outer WBWA and inner shareable */
  72. tcr |= TCR_TG0_4K | TCR_SHARED_INNER | TCR_ORGN_WBWA | TCR_IRGN_WBWA;
  73. tcr |= TCR_T0SZ(va_bits);
  74. if (pips)
  75. *pips = ips;
  76. if (pva_bits)
  77. *pva_bits = va_bits;
  78. return tcr;
  79. }
  80. #define MAX_PTE_ENTRIES 512
  81. static int pte_type(u64 *pte)
  82. {
  83. return *pte & PTE_TYPE_MASK;
  84. }
  85. /* Returns the LSB number for a PTE on level <level> */
  86. static int level2shift(int level)
  87. {
  88. /* Page is 12 bits wide, every level translates 9 bits */
  89. return (12 + 9 * (3 - level));
  90. }
  91. static u64 *find_pte(u64 addr, int level)
  92. {
  93. int start_level = 0;
  94. u64 *pte;
  95. u64 idx;
  96. u64 va_bits;
  97. int i;
  98. debug("addr=%llx level=%d\n", addr, level);
  99. get_tcr(0, NULL, &va_bits);
  100. if (va_bits < 39)
  101. start_level = 1;
  102. if (level < start_level)
  103. return NULL;
  104. /* Walk through all page table levels to find our PTE */
  105. pte = (u64*)gd->arch.tlb_addr;
  106. for (i = start_level; i < 4; i++) {
  107. idx = (addr >> level2shift(i)) & 0x1FF;
  108. pte += idx;
  109. debug("idx=%llx PTE %p at level %d: %llx\n", idx, pte, i, *pte);
  110. /* Found it */
  111. if (i == level)
  112. return pte;
  113. /* PTE is no table (either invalid or block), can't traverse */
  114. if (pte_type(pte) != PTE_TYPE_TABLE)
  115. return NULL;
  116. /* Off to the next level */
  117. pte = (u64*)(*pte & 0x0000fffffffff000ULL);
  118. }
  119. /* Should never reach here */
  120. return NULL;
  121. }
  122. /* Returns and creates a new full table (512 entries) */
  123. static u64 *create_table(void)
  124. {
  125. u64 *new_table = (u64*)gd->arch.tlb_fillptr;
  126. u64 pt_len = MAX_PTE_ENTRIES * sizeof(u64);
  127. /* Allocate MAX_PTE_ENTRIES pte entries */
  128. gd->arch.tlb_fillptr += pt_len;
  129. if (gd->arch.tlb_fillptr - gd->arch.tlb_addr > gd->arch.tlb_size)
  130. panic("Insufficient RAM for page table: 0x%lx > 0x%lx. "
  131. "Please increase the size in get_page_table_size()",
  132. gd->arch.tlb_fillptr - gd->arch.tlb_addr,
  133. gd->arch.tlb_size);
  134. /* Mark all entries as invalid */
  135. memset(new_table, 0, pt_len);
  136. return new_table;
  137. }
  138. static void set_pte_table(u64 *pte, u64 *table)
  139. {
  140. /* Point *pte to the new table */
  141. debug("Setting %p to addr=%p\n", pte, table);
  142. *pte = PTE_TYPE_TABLE | (ulong)table;
  143. }
  144. /* Add one mm_region map entry to the page tables */
  145. static void add_map(struct mm_region *map)
  146. {
  147. u64 *pte;
  148. u64 addr = map->base;
  149. u64 size = map->size;
  150. u64 attrs = map->attrs | PTE_TYPE_BLOCK | PTE_BLOCK_AF;
  151. u64 blocksize;
  152. int level;
  153. u64 *new_table;
  154. while (size) {
  155. pte = find_pte(addr, 0);
  156. if (pte && (pte_type(pte) == PTE_TYPE_FAULT)) {
  157. debug("Creating table for addr 0x%llx\n", addr);
  158. new_table = create_table();
  159. set_pte_table(pte, new_table);
  160. }
  161. for (level = 1; level < 4; level++) {
  162. pte = find_pte(addr, level);
  163. blocksize = 1ULL << level2shift(level);
  164. debug("Checking if pte fits for addr=%llx size=%llx "
  165. "blocksize=%llx\n", addr, size, blocksize);
  166. if (size >= blocksize && !(addr & (blocksize - 1))) {
  167. /* Page fits, create block PTE */
  168. debug("Setting PTE %p to block addr=%llx\n",
  169. pte, addr);
  170. *pte = addr | attrs;
  171. addr += blocksize;
  172. size -= blocksize;
  173. break;
  174. } else if ((pte_type(pte) == PTE_TYPE_FAULT)) {
  175. /* Page doesn't fit, create subpages */
  176. debug("Creating subtable for addr 0x%llx "
  177. "blksize=%llx\n", addr, blocksize);
  178. new_table = create_table();
  179. set_pte_table(pte, new_table);
  180. }
  181. }
  182. }
  183. }
  184. /* Splits a block PTE into table with subpages spanning the old block */
  185. static void split_block(u64 *pte, int level)
  186. {
  187. u64 old_pte = *pte;
  188. u64 *new_table;
  189. u64 i = 0;
  190. /* level describes the parent level, we need the child ones */
  191. int levelshift = level2shift(level + 1);
  192. if (pte_type(pte) != PTE_TYPE_BLOCK)
  193. panic("PTE %p (%llx) is not a block. Some driver code wants to "
  194. "modify dcache settings for an range not covered in "
  195. "mem_map.", pte, old_pte);
  196. new_table = create_table();
  197. debug("Splitting pte %p (%llx) into %p\n", pte, old_pte, new_table);
  198. for (i = 0; i < MAX_PTE_ENTRIES; i++) {
  199. new_table[i] = old_pte | (i << levelshift);
  200. /* Level 3 block PTEs have the table type */
  201. if ((level + 1) == 3)
  202. new_table[i] |= PTE_TYPE_TABLE;
  203. debug("Setting new_table[%lld] = %llx\n", i, new_table[i]);
  204. }
  205. /* Set the new table into effect */
  206. set_pte_table(pte, new_table);
  207. }
  208. enum pte_type {
  209. PTE_INVAL,
  210. PTE_BLOCK,
  211. PTE_LEVEL,
  212. };
  213. /*
  214. * This is a recursively called function to count the number of
  215. * page tables we need to cover a particular PTE range. If you
  216. * call this with level = -1 you basically get the full 48 bit
  217. * coverage.
  218. */
  219. static int count_required_pts(u64 addr, int level, u64 maxaddr)
  220. {
  221. int levelshift = level2shift(level);
  222. u64 levelsize = 1ULL << levelshift;
  223. u64 levelmask = levelsize - 1;
  224. u64 levelend = addr + levelsize;
  225. int r = 0;
  226. int i;
  227. enum pte_type pte_type = PTE_INVAL;
  228. for (i = 0; i < ARRAY_SIZE(mem_map); i++) {
  229. struct mm_region *map = &mem_map[i];
  230. u64 start = map->base;
  231. u64 end = start + map->size;
  232. /* Check if the PTE would overlap with the map */
  233. if (max(addr, start) <= min(levelend, end)) {
  234. start = max(addr, start);
  235. end = min(levelend, end);
  236. /* We need a sub-pt for this level */
  237. if ((start & levelmask) || (end & levelmask)) {
  238. pte_type = PTE_LEVEL;
  239. break;
  240. }
  241. /* Lv0 can not do block PTEs, so do levels here too */
  242. if (level <= 0) {
  243. pte_type = PTE_LEVEL;
  244. break;
  245. }
  246. /* PTE is active, but fits into a block */
  247. pte_type = PTE_BLOCK;
  248. }
  249. }
  250. /*
  251. * Block PTEs at this level are already covered by the parent page
  252. * table, so we only need to count sub page tables.
  253. */
  254. if (pte_type == PTE_LEVEL) {
  255. int sublevel = level + 1;
  256. u64 sublevelsize = 1ULL << level2shift(sublevel);
  257. /* Account for the new sub page table ... */
  258. r = 1;
  259. /* ... and for all child page tables that one might have */
  260. for (i = 0; i < MAX_PTE_ENTRIES; i++) {
  261. r += count_required_pts(addr, sublevel, maxaddr);
  262. addr += sublevelsize;
  263. if (addr >= maxaddr) {
  264. /*
  265. * We reached the end of address space, no need
  266. * to look any further.
  267. */
  268. break;
  269. }
  270. }
  271. }
  272. return r;
  273. }
  274. /* Returns the estimated required size of all page tables */
  275. u64 get_page_table_size(void)
  276. {
  277. u64 one_pt = MAX_PTE_ENTRIES * sizeof(u64);
  278. u64 size = 0;
  279. u64 va_bits;
  280. int start_level = 0;
  281. get_tcr(0, NULL, &va_bits);
  282. if (va_bits < 39)
  283. start_level = 1;
  284. /* Account for all page tables we would need to cover our memory map */
  285. size = one_pt * count_required_pts(0, start_level - 1, 1ULL << va_bits);
  286. /*
  287. * We need to duplicate our page table once to have an emergency pt to
  288. * resort to when splitting page tables later on
  289. */
  290. size *= 2;
  291. /*
  292. * We may need to split page tables later on if dcache settings change,
  293. * so reserve up to 4 (random pick) page tables for that.
  294. */
  295. size += one_pt * 4;
  296. return size;
  297. }
  298. static void setup_pgtables(void)
  299. {
  300. int i;
  301. /*
  302. * Allocate the first level we're on with invalidate entries.
  303. * If the starting level is 0 (va_bits >= 39), then this is our
  304. * Lv0 page table, otherwise it's the entry Lv1 page table.
  305. */
  306. create_table();
  307. /* Now add all MMU table entries one after another to the table */
  308. for (i = 0; i < ARRAY_SIZE(mem_map); i++)
  309. add_map(&mem_map[i]);
  310. /* Create the same thing once more for our emergency page table */
  311. create_table();
  312. }
  313. static void setup_all_pgtables(void)
  314. {
  315. u64 tlb_addr = gd->arch.tlb_addr;
  316. /* Reset the fill ptr */
  317. gd->arch.tlb_fillptr = tlb_addr;
  318. /* Create normal system page tables */
  319. setup_pgtables();
  320. /* Create emergency page tables */
  321. gd->arch.tlb_addr = gd->arch.tlb_fillptr;
  322. setup_pgtables();
  323. gd->arch.tlb_emerg = gd->arch.tlb_addr;
  324. gd->arch.tlb_addr = tlb_addr;
  325. }
  326. #else
  327. inline void set_pgtable_section(u64 *page_table, u64 index, u64 section,
  328. u64 memory_type, u64 attribute)
  329. {
  330. u64 value;
  331. value = section | PMD_TYPE_SECT | PMD_SECT_AF;
  332. value |= PMD_ATTRINDX(memory_type);
  333. value |= attribute;
  334. page_table[index] = value;
  335. }
  336. inline void set_pgtable_table(u64 *page_table, u64 index, u64 *table_addr)
  337. {
  338. u64 value;
  339. value = (u64)table_addr | PMD_TYPE_TABLE;
  340. page_table[index] = value;
  341. }
  342. #endif
  343. /* to activate the MMU we need to set up virtual memory */
  344. __weak void mmu_setup(void)
  345. {
  346. #ifndef CONFIG_SYS_FULL_VA
  347. bd_t *bd = gd->bd;
  348. u64 *page_table = (u64 *)gd->arch.tlb_addr, i, j;
  349. #endif
  350. int el;
  351. #ifdef CONFIG_SYS_FULL_VA
  352. /* Set up page tables only once */
  353. if (!gd->arch.tlb_fillptr)
  354. setup_all_pgtables();
  355. el = current_el();
  356. set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(el, NULL, NULL),
  357. MEMORY_ATTRIBUTES);
  358. #else
  359. /* Setup an identity-mapping for all spaces */
  360. for (i = 0; i < (PGTABLE_SIZE >> 3); i++) {
  361. set_pgtable_section(page_table, i, i << SECTION_SHIFT,
  362. MT_DEVICE_NGNRNE, PMD_SECT_NON_SHARE);
  363. }
  364. /* Setup an identity-mapping for all RAM space */
  365. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  366. ulong start = bd->bi_dram[i].start;
  367. ulong end = bd->bi_dram[i].start + bd->bi_dram[i].size;
  368. for (j = start >> SECTION_SHIFT;
  369. j < end >> SECTION_SHIFT; j++) {
  370. set_pgtable_section(page_table, j, j << SECTION_SHIFT,
  371. MT_NORMAL, PMD_SECT_NON_SHARE);
  372. }
  373. }
  374. /* load TTBR0 */
  375. el = current_el();
  376. if (el == 1) {
  377. set_ttbr_tcr_mair(el, gd->arch.tlb_addr,
  378. TCR_EL1_RSVD | TCR_FLAGS | TCR_EL1_IPS_BITS,
  379. MEMORY_ATTRIBUTES);
  380. } else if (el == 2) {
  381. set_ttbr_tcr_mair(el, gd->arch.tlb_addr,
  382. TCR_EL2_RSVD | TCR_FLAGS | TCR_EL2_IPS_BITS,
  383. MEMORY_ATTRIBUTES);
  384. } else {
  385. set_ttbr_tcr_mair(el, gd->arch.tlb_addr,
  386. TCR_EL3_RSVD | TCR_FLAGS | TCR_EL3_IPS_BITS,
  387. MEMORY_ATTRIBUTES);
  388. }
  389. #endif
  390. /* enable the mmu */
  391. set_sctlr(get_sctlr() | CR_M);
  392. }
  393. /*
  394. * Performs a invalidation of the entire data cache at all levels
  395. */
  396. void invalidate_dcache_all(void)
  397. {
  398. __asm_invalidate_dcache_all();
  399. }
  400. /*
  401. * Performs a clean & invalidation of the entire data cache at all levels.
  402. * This function needs to be inline to avoid using stack.
  403. * __asm_flush_l3_cache return status of timeout
  404. */
  405. inline void flush_dcache_all(void)
  406. {
  407. int ret;
  408. __asm_flush_dcache_all();
  409. ret = __asm_flush_l3_cache();
  410. if (ret)
  411. debug("flushing dcache returns 0x%x\n", ret);
  412. else
  413. debug("flushing dcache successfully.\n");
  414. }
  415. /*
  416. * Invalidates range in all levels of D-cache/unified cache
  417. */
  418. void invalidate_dcache_range(unsigned long start, unsigned long stop)
  419. {
  420. __asm_flush_dcache_range(start, stop);
  421. }
  422. /*
  423. * Flush range(clean & invalidate) from all levels of D-cache/unified cache
  424. */
  425. void flush_dcache_range(unsigned long start, unsigned long stop)
  426. {
  427. __asm_flush_dcache_range(start, stop);
  428. }
  429. void dcache_enable(void)
  430. {
  431. /* The data cache is not active unless the mmu is enabled */
  432. if (!(get_sctlr() & CR_M)) {
  433. invalidate_dcache_all();
  434. __asm_invalidate_tlb_all();
  435. mmu_setup();
  436. }
  437. set_sctlr(get_sctlr() | CR_C);
  438. }
  439. void dcache_disable(void)
  440. {
  441. uint32_t sctlr;
  442. sctlr = get_sctlr();
  443. /* if cache isn't enabled no need to disable */
  444. if (!(sctlr & CR_C))
  445. return;
  446. set_sctlr(sctlr & ~(CR_C|CR_M));
  447. flush_dcache_all();
  448. __asm_invalidate_tlb_all();
  449. }
  450. int dcache_status(void)
  451. {
  452. return (get_sctlr() & CR_C) != 0;
  453. }
  454. u64 *__weak arch_get_page_table(void) {
  455. puts("No page table offset defined\n");
  456. return NULL;
  457. }
  458. #ifndef CONFIG_SYS_FULL_VA
  459. void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
  460. enum dcache_option option)
  461. {
  462. u64 *page_table = arch_get_page_table();
  463. u64 upto, end;
  464. if (page_table == NULL)
  465. return;
  466. end = ALIGN(start + size, (1 << MMU_SECTION_SHIFT)) >>
  467. MMU_SECTION_SHIFT;
  468. start = start >> MMU_SECTION_SHIFT;
  469. for (upto = start; upto < end; upto++) {
  470. page_table[upto] &= ~PMD_ATTRINDX_MASK;
  471. page_table[upto] |= PMD_ATTRINDX(option);
  472. }
  473. asm volatile("dsb sy");
  474. __asm_invalidate_tlb_all();
  475. asm volatile("dsb sy");
  476. asm volatile("isb");
  477. start = start << MMU_SECTION_SHIFT;
  478. end = end << MMU_SECTION_SHIFT;
  479. flush_dcache_range(start, end);
  480. asm volatile("dsb sy");
  481. }
  482. #else
  483. static bool is_aligned(u64 addr, u64 size, u64 align)
  484. {
  485. return !(addr & (align - 1)) && !(size & (align - 1));
  486. }
  487. static u64 set_one_region(u64 start, u64 size, u64 attrs, int level)
  488. {
  489. int levelshift = level2shift(level);
  490. u64 levelsize = 1ULL << levelshift;
  491. u64 *pte = find_pte(start, level);
  492. /* Can we can just modify the current level block PTE? */
  493. if (is_aligned(start, size, levelsize)) {
  494. *pte &= ~PMD_ATTRINDX_MASK;
  495. *pte |= attrs;
  496. debug("Set attrs=%llx pte=%p level=%d\n", attrs, pte, level);
  497. return levelsize;
  498. }
  499. /* Unaligned or doesn't fit, maybe split block into table */
  500. debug("addr=%llx level=%d pte=%p (%llx)\n", start, level, pte, *pte);
  501. /* Maybe we need to split the block into a table */
  502. if (pte_type(pte) == PTE_TYPE_BLOCK)
  503. split_block(pte, level);
  504. /* And then double-check it became a table or already is one */
  505. if (pte_type(pte) != PTE_TYPE_TABLE)
  506. panic("PTE %p (%llx) for addr=%llx should be a table",
  507. pte, *pte, start);
  508. /* Roll on to the next page table level */
  509. return 0;
  510. }
  511. void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
  512. enum dcache_option option)
  513. {
  514. u64 attrs = PMD_ATTRINDX(option);
  515. u64 real_start = start;
  516. u64 real_size = size;
  517. debug("start=%lx size=%lx\n", (ulong)start, (ulong)size);
  518. /*
  519. * We can not modify page tables that we're currently running on,
  520. * so we first need to switch to the "emergency" page tables where
  521. * we can safely modify our primary page tables and then switch back
  522. */
  523. __asm_switch_ttbr(gd->arch.tlb_emerg);
  524. /*
  525. * Loop through the address range until we find a page granule that fits
  526. * our alignment constraints, then set it to the new cache attributes
  527. */
  528. while (size > 0) {
  529. int level;
  530. u64 r;
  531. for (level = 1; level < 4; level++) {
  532. r = set_one_region(start, size, attrs, level);
  533. if (r) {
  534. /* PTE successfully replaced */
  535. size -= r;
  536. start += r;
  537. break;
  538. }
  539. }
  540. }
  541. /* We're done modifying page tables, switch back to our primary ones */
  542. __asm_switch_ttbr(gd->arch.tlb_addr);
  543. /*
  544. * Make sure there's nothing stale in dcache for a region that might
  545. * have caches off now
  546. */
  547. flush_dcache_range(real_start, real_start + real_size);
  548. }
  549. #endif
  550. #else /* CONFIG_SYS_DCACHE_OFF */
  551. void invalidate_dcache_all(void)
  552. {
  553. }
  554. void flush_dcache_all(void)
  555. {
  556. }
  557. void dcache_enable(void)
  558. {
  559. }
  560. void dcache_disable(void)
  561. {
  562. }
  563. int dcache_status(void)
  564. {
  565. return 0;
  566. }
  567. void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
  568. enum dcache_option option)
  569. {
  570. }
  571. #endif /* CONFIG_SYS_DCACHE_OFF */
  572. #ifndef CONFIG_SYS_ICACHE_OFF
  573. void icache_enable(void)
  574. {
  575. __asm_invalidate_icache_all();
  576. set_sctlr(get_sctlr() | CR_I);
  577. }
  578. void icache_disable(void)
  579. {
  580. set_sctlr(get_sctlr() & ~CR_I);
  581. }
  582. int icache_status(void)
  583. {
  584. return (get_sctlr() & CR_I) != 0;
  585. }
  586. void invalidate_icache_all(void)
  587. {
  588. __asm_invalidate_icache_all();
  589. }
  590. #else /* CONFIG_SYS_ICACHE_OFF */
  591. void icache_enable(void)
  592. {
  593. }
  594. void icache_disable(void)
  595. {
  596. }
  597. int icache_status(void)
  598. {
  599. return 0;
  600. }
  601. void invalidate_icache_all(void)
  602. {
  603. }
  604. #endif /* CONFIG_SYS_ICACHE_OFF */
  605. /*
  606. * Enable dCache & iCache, whether cache is actually enabled
  607. * depend on CONFIG_SYS_DCACHE_OFF and CONFIG_SYS_ICACHE_OFF
  608. */
  609. void __weak enable_caches(void)
  610. {
  611. icache_enable();
  612. dcache_enable();
  613. }