Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 9edefc2 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 11 | #include <asm/system.h> |
R Sricharan | 96fdbec | 2013-03-04 20:04:44 +0000 | [diff] [blame] | 12 | #include <asm/cache.h> |
| 13 | #include <linux/compiler.h> |
Lokesh Vutla | a43d46a | 2018-04-26 18:21:31 +0530 | [diff] [blame] | 14 | #include <asm/armv7_mpu.h> |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 15 | |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 16 | #if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) |
Heiko Schocher | 880eff5 | 2010-09-17 13:10:29 +0200 | [diff] [blame] | 17 | |
Heiko Schocher | 880eff5 | 2010-09-17 13:10:29 +0200 | [diff] [blame] | 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Lokesh Vutla | a43d46a | 2018-04-26 18:21:31 +0530 | [diff] [blame] | 20 | #ifdef CONFIG_SYS_ARM_MMU |
Jeroen Hofstee | fcfddfd | 2014-06-23 22:07:04 +0200 | [diff] [blame] | 21 | __weak void arm_init_before_mmu(void) |
Aneesh V | c2dd0d4 | 2011-06-16 23:30:49 +0000 | [diff] [blame] | 22 | { |
| 23 | } |
Aneesh V | c2dd0d4 | 2011-06-16 23:30:49 +0000 | [diff] [blame] | 24 | |
R Sricharan | de63ac2 | 2013-03-04 20:04:45 +0000 | [diff] [blame] | 25 | __weak void arm_init_domains(void) |
| 26 | { |
| 27 | } |
| 28 | |
Marek Szyprowski | d877f8f | 2020-06-03 14:43:42 +0200 | [diff] [blame] | 29 | static void set_section_phys(int section, phys_addr_t phys, |
| 30 | enum dcache_option option) |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 31 | { |
Alexander Graf | d990f5c | 2016-03-16 15:41:21 +0100 | [diff] [blame] | 32 | #ifdef CONFIG_ARMV7_LPAE |
| 33 | u64 *page_table = (u64 *)gd->arch.tlb_addr; |
| 34 | /* Need to set the access flag to not fault */ |
| 35 | u64 value = TTB_SECT_AP | TTB_SECT_AF; |
| 36 | #else |
Simon Glass | 34fd5d2 | 2012-12-13 20:48:39 +0000 | [diff] [blame] | 37 | u32 *page_table = (u32 *)gd->arch.tlb_addr; |
Alexander Graf | d990f5c | 2016-03-16 15:41:21 +0100 | [diff] [blame] | 38 | u32 value = TTB_SECT_AP; |
| 39 | #endif |
Simon Glass | 0dde7f5 | 2012-10-17 13:24:53 +0000 | [diff] [blame] | 40 | |
Alexander Graf | d990f5c | 2016-03-16 15:41:21 +0100 | [diff] [blame] | 41 | /* Add the page offset */ |
Marek Szyprowski | d877f8f | 2020-06-03 14:43:42 +0200 | [diff] [blame] | 42 | value |= phys; |
Alexander Graf | d990f5c | 2016-03-16 15:41:21 +0100 | [diff] [blame] | 43 | |
| 44 | /* Add caching bits */ |
Simon Glass | 0dde7f5 | 2012-10-17 13:24:53 +0000 | [diff] [blame] | 45 | value |= option; |
Alexander Graf | d990f5c | 2016-03-16 15:41:21 +0100 | [diff] [blame] | 46 | |
| 47 | /* Set PTE */ |
Simon Glass | 0dde7f5 | 2012-10-17 13:24:53 +0000 | [diff] [blame] | 48 | page_table[section] = value; |
| 49 | } |
| 50 | |
Marek Szyprowski | d877f8f | 2020-06-03 14:43:42 +0200 | [diff] [blame] | 51 | void set_section_dcache(int section, enum dcache_option option) |
| 52 | { |
| 53 | set_section_phys(section, (u32)section << MMU_SECTION_SHIFT, option); |
| 54 | } |
| 55 | |
Jeroen Hofstee | fcfddfd | 2014-06-23 22:07:04 +0200 | [diff] [blame] | 56 | __weak void mmu_page_table_flush(unsigned long start, unsigned long stop) |
Simon Glass | 0dde7f5 | 2012-10-17 13:24:53 +0000 | [diff] [blame] | 57 | { |
| 58 | debug("%s: Warning: not implemented\n", __func__); |
| 59 | } |
| 60 | |
Marek Szyprowski | d877f8f | 2020-06-03 14:43:42 +0200 | [diff] [blame] | 61 | void mmu_set_region_dcache_behaviour_phys(phys_addr_t start, phys_addr_t phys, |
| 62 | size_t size, enum dcache_option option) |
Simon Glass | 0dde7f5 | 2012-10-17 13:24:53 +0000 | [diff] [blame] | 63 | { |
Stefan Agner | c5b3cab | 2016-08-14 21:33:00 -0700 | [diff] [blame] | 64 | #ifdef CONFIG_ARMV7_LPAE |
| 65 | u64 *page_table = (u64 *)gd->arch.tlb_addr; |
| 66 | #else |
Simon Glass | 34fd5d2 | 2012-12-13 20:48:39 +0000 | [diff] [blame] | 67 | u32 *page_table = (u32 *)gd->arch.tlb_addr; |
Stefan Agner | c5b3cab | 2016-08-14 21:33:00 -0700 | [diff] [blame] | 68 | #endif |
Stefan Agner | 8f894a4 | 2016-08-14 21:33:01 -0700 | [diff] [blame] | 69 | unsigned long startpt, stoppt; |
Thierry Reding | 25026fa | 2014-08-26 17:34:21 +0200 | [diff] [blame] | 70 | unsigned long upto, end; |
Simon Glass | 0dde7f5 | 2012-10-17 13:24:53 +0000 | [diff] [blame] | 71 | |
Patrick Delaunay | 54be09c | 2020-04-24 20:20:17 +0200 | [diff] [blame] | 72 | /* div by 2 before start + size to avoid phys_addr_t overflow */ |
| 73 | end = ALIGN((start / 2) + (size / 2), MMU_SECTION_SIZE / 2) |
| 74 | >> (MMU_SECTION_SHIFT - 1); |
Simon Glass | 0dde7f5 | 2012-10-17 13:24:53 +0000 | [diff] [blame] | 75 | start = start >> MMU_SECTION_SHIFT; |
Patrick Delaunay | 54be09c | 2020-04-24 20:20:17 +0200 | [diff] [blame] | 76 | |
Keerthy | 06d43c8 | 2016-10-29 15:19:10 +0530 | [diff] [blame] | 77 | #ifdef CONFIG_ARMV7_LPAE |
| 78 | debug("%s: start=%pa, size=%zu, option=%llx\n", __func__, &start, size, |
| 79 | option); |
| 80 | #else |
Keerthy | 2b373cb | 2016-10-29 15:19:09 +0530 | [diff] [blame] | 81 | debug("%s: start=%pa, size=%zu, option=0x%x\n", __func__, &start, size, |
Simon Glass | 0dde7f5 | 2012-10-17 13:24:53 +0000 | [diff] [blame] | 82 | option); |
Keerthy | 06d43c8 | 2016-10-29 15:19:10 +0530 | [diff] [blame] | 83 | #endif |
Marek Szyprowski | d877f8f | 2020-06-03 14:43:42 +0200 | [diff] [blame] | 84 | for (upto = start; upto < end; upto++, phys += MMU_SECTION_SIZE) |
| 85 | set_section_phys(upto, phys, option); |
Stefan Agner | 8f894a4 | 2016-08-14 21:33:01 -0700 | [diff] [blame] | 86 | |
| 87 | /* |
| 88 | * Make sure range is cache line aligned |
| 89 | * Only CPU maintains page tables, hence it is safe to always |
| 90 | * flush complete cache lines... |
| 91 | */ |
| 92 | |
| 93 | startpt = (unsigned long)&page_table[start]; |
| 94 | startpt &= ~(CONFIG_SYS_CACHELINE_SIZE - 1); |
| 95 | stoppt = (unsigned long)&page_table[end]; |
| 96 | stoppt = ALIGN(stoppt, CONFIG_SYS_CACHELINE_SIZE); |
| 97 | mmu_page_table_flush(startpt, stoppt); |
Simon Glass | 0dde7f5 | 2012-10-17 13:24:53 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Marek Szyprowski | d877f8f | 2020-06-03 14:43:42 +0200 | [diff] [blame] | 100 | void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size, |
| 101 | enum dcache_option option) |
| 102 | { |
| 103 | mmu_set_region_dcache_behaviour_phys(start, start, size, option); |
| 104 | } |
| 105 | |
R Sricharan | 96fdbec | 2013-03-04 20:04:44 +0000 | [diff] [blame] | 106 | __weak void dram_bank_mmu_setup(int bank) |
Simon Glass | 0dde7f5 | 2012-10-17 13:24:53 +0000 | [diff] [blame] | 107 | { |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 108 | struct bd_info *bd = gd->bd; |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 109 | int i; |
| 110 | |
Patrick Delaunay | c8ec1e3 | 2020-04-24 20:20:15 +0200 | [diff] [blame] | 111 | /* bd->bi_dram is available only after relocation */ |
| 112 | if ((gd->flags & GD_FLG_RELOC) == 0) |
| 113 | return; |
| 114 | |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 115 | debug("%s: bank: %d\n", __func__, bank); |
Alexander Graf | d990f5c | 2016-03-16 15:41:21 +0100 | [diff] [blame] | 116 | for (i = bd->bi_dram[bank].start >> MMU_SECTION_SHIFT; |
| 117 | i < (bd->bi_dram[bank].start >> MMU_SECTION_SHIFT) + |
| 118 | (bd->bi_dram[bank].size >> MMU_SECTION_SHIFT); |
Patrick Delaunay | 2e8d68e | 2020-04-24 20:20:16 +0200 | [diff] [blame] | 119 | i++) |
| 120 | set_section_dcache(i, DCACHE_DEFAULT_OPTION); |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 121 | } |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 122 | |
| 123 | /* to activate the MMU we need to set up virtual memory: use 1M areas */ |
Heiko Schocher | 880eff5 | 2010-09-17 13:10:29 +0200 | [diff] [blame] | 124 | static inline void mmu_setup(void) |
| 125 | { |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 126 | int i; |
Heiko Schocher | 880eff5 | 2010-09-17 13:10:29 +0200 | [diff] [blame] | 127 | u32 reg; |
| 128 | |
Aneesh V | c2dd0d4 | 2011-06-16 23:30:49 +0000 | [diff] [blame] | 129 | arm_init_before_mmu(); |
Heiko Schocher | 880eff5 | 2010-09-17 13:10:29 +0200 | [diff] [blame] | 130 | /* Set up an identity-mapping for all 4GB, rw for everyone */ |
Alexander Graf | d990f5c | 2016-03-16 15:41:21 +0100 | [diff] [blame] | 131 | for (i = 0; i < ((4096ULL * 1024 * 1024) >> MMU_SECTION_SHIFT); i++) |
Simon Glass | 0dde7f5 | 2012-10-17 13:24:53 +0000 | [diff] [blame] | 132 | set_section_dcache(i, DCACHE_OFF); |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 133 | |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 134 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 135 | dram_bank_mmu_setup(i); |
| 136 | } |
Heiko Schocher | 880eff5 | 2010-09-17 13:10:29 +0200 | [diff] [blame] | 137 | |
Simon Glass | 10d602a | 2017-05-31 17:57:13 -0600 | [diff] [blame] | 138 | #if defined(CONFIG_ARMV7_LPAE) && __LINUX_ARM_ARCH__ != 4 |
Alexander Graf | d990f5c | 2016-03-16 15:41:21 +0100 | [diff] [blame] | 139 | /* Set up 4 PTE entries pointing to our 4 1GB page tables */ |
| 140 | for (i = 0; i < 4; i++) { |
| 141 | u64 *page_table = (u64 *)(gd->arch.tlb_addr + (4096 * 4)); |
| 142 | u64 tpt = gd->arch.tlb_addr + (4096 * i); |
| 143 | page_table[i] = tpt | TTB_PAGETABLE; |
| 144 | } |
| 145 | |
| 146 | reg = TTBCR_EAE; |
| 147 | #if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH) |
| 148 | reg |= TTBCR_ORGN0_WT | TTBCR_IRGN0_WT; |
| 149 | #elif defined(CONFIG_SYS_ARM_CACHE_WRITEALLOC) |
| 150 | reg |= TTBCR_ORGN0_WBWA | TTBCR_IRGN0_WBWA; |
| 151 | #else |
| 152 | reg |= TTBCR_ORGN0_WBNWA | TTBCR_IRGN0_WBNWA; |
| 153 | #endif |
| 154 | |
| 155 | if (is_hyp()) { |
Simon Glass | 579dfca | 2017-05-31 17:57:12 -0600 | [diff] [blame] | 156 | /* Set HTCR to enable LPAE */ |
Alexander Graf | d990f5c | 2016-03-16 15:41:21 +0100 | [diff] [blame] | 157 | asm volatile("mcr p15, 4, %0, c2, c0, 2" |
| 158 | : : "r" (reg) : "memory"); |
| 159 | /* Set HTTBR0 */ |
| 160 | asm volatile("mcrr p15, 4, %0, %1, c2" |
| 161 | : |
| 162 | : "r"(gd->arch.tlb_addr + (4096 * 4)), "r"(0) |
| 163 | : "memory"); |
| 164 | /* Set HMAIR */ |
| 165 | asm volatile("mcr p15, 4, %0, c10, c2, 0" |
| 166 | : : "r" (MEMORY_ATTRIBUTES) : "memory"); |
| 167 | } else { |
| 168 | /* Set TTBCR to enable LPAE */ |
| 169 | asm volatile("mcr p15, 0, %0, c2, c0, 2" |
| 170 | : : "r" (reg) : "memory"); |
| 171 | /* Set 64-bit TTBR0 */ |
| 172 | asm volatile("mcrr p15, 0, %0, %1, c2" |
| 173 | : |
| 174 | : "r"(gd->arch.tlb_addr + (4096 * 4)), "r"(0) |
| 175 | : "memory"); |
| 176 | /* Set MAIR */ |
| 177 | asm volatile("mcr p15, 0, %0, c10, c2, 0" |
| 178 | : : "r" (MEMORY_ATTRIBUTES) : "memory"); |
| 179 | } |
Lokesh Vutla | acf1500 | 2018-04-26 18:21:26 +0530 | [diff] [blame] | 180 | #elif defined(CONFIG_CPU_V7A) |
Simon Glass | 50a4886 | 2017-05-31 17:57:14 -0600 | [diff] [blame] | 181 | if (is_hyp()) { |
| 182 | /* Set HTCR to disable LPAE */ |
| 183 | asm volatile("mcr p15, 4, %0, c2, c0, 2" |
| 184 | : : "r" (0) : "memory"); |
| 185 | } else { |
| 186 | /* Set TTBCR to disable LPAE */ |
| 187 | asm volatile("mcr p15, 0, %0, c2, c0, 2" |
| 188 | : : "r" (0) : "memory"); |
| 189 | } |
Bryan Brinsko | 97840b5 | 2015-03-24 11:25:12 -0500 | [diff] [blame] | 190 | /* Set TTBR0 */ |
| 191 | reg = gd->arch.tlb_addr & TTBR0_BASE_ADDR_MASK; |
| 192 | #if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH) |
| 193 | reg |= TTBR0_RGN_WT | TTBR0_IRGN_WT; |
| 194 | #elif defined(CONFIG_SYS_ARM_CACHE_WRITEALLOC) |
| 195 | reg |= TTBR0_RGN_WBWA | TTBR0_IRGN_WBWA; |
| 196 | #else |
| 197 | reg |= TTBR0_RGN_WB | TTBR0_IRGN_WB; |
| 198 | #endif |
| 199 | asm volatile("mcr p15, 0, %0, c2, c0, 0" |
| 200 | : : "r" (reg) : "memory"); |
| 201 | #else |
Heiko Schocher | 880eff5 | 2010-09-17 13:10:29 +0200 | [diff] [blame] | 202 | /* Copy the page table address to cp15 */ |
| 203 | asm volatile("mcr p15, 0, %0, c2, c0, 0" |
Simon Glass | 34fd5d2 | 2012-12-13 20:48:39 +0000 | [diff] [blame] | 204 | : : "r" (gd->arch.tlb_addr) : "memory"); |
Bryan Brinsko | 97840b5 | 2015-03-24 11:25:12 -0500 | [diff] [blame] | 205 | #endif |
Patrick Delaunay | 503eea4 | 2021-02-05 13:53:36 +0100 | [diff] [blame^] | 206 | /* |
| 207 | * initial value of Domain Access Control Register (DACR) |
| 208 | * Set the access control to client (1U) for each of the 16 domains |
| 209 | */ |
Heiko Schocher | 880eff5 | 2010-09-17 13:10:29 +0200 | [diff] [blame] | 210 | asm volatile("mcr p15, 0, %0, c3, c0, 0" |
Patrick Delaunay | 503eea4 | 2021-02-05 13:53:36 +0100 | [diff] [blame^] | 211 | : : "r" (0x55555555)); |
R Sricharan | de63ac2 | 2013-03-04 20:04:45 +0000 | [diff] [blame] | 212 | |
| 213 | arm_init_domains(); |
| 214 | |
Heiko Schocher | 880eff5 | 2010-09-17 13:10:29 +0200 | [diff] [blame] | 215 | /* and enable the mmu */ |
| 216 | reg = get_cr(); /* get control reg. */ |
Heiko Schocher | 880eff5 | 2010-09-17 13:10:29 +0200 | [diff] [blame] | 217 | set_cr(reg | CR_M); |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 218 | } |
| 219 | |
Aneesh V | e05f007 | 2011-06-16 23:30:50 +0000 | [diff] [blame] | 220 | static int mmu_enabled(void) |
| 221 | { |
| 222 | return get_cr() & CR_M; |
| 223 | } |
Lokesh Vutla | a43d46a | 2018-04-26 18:21:31 +0530 | [diff] [blame] | 224 | #endif /* CONFIG_SYS_ARM_MMU */ |
Aneesh V | e05f007 | 2011-06-16 23:30:50 +0000 | [diff] [blame] | 225 | |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 226 | /* cache_bit must be either CR_I or CR_C */ |
| 227 | static void cache_enable(uint32_t cache_bit) |
| 228 | { |
| 229 | uint32_t reg; |
| 230 | |
Lokesh Vutla | a43d46a | 2018-04-26 18:21:31 +0530 | [diff] [blame] | 231 | /* The data cache is not active unless the mmu/mpu is enabled too */ |
| 232 | #ifdef CONFIG_SYS_ARM_MMU |
Aneesh V | e05f007 | 2011-06-16 23:30:50 +0000 | [diff] [blame] | 233 | if ((cache_bit == CR_C) && !mmu_enabled()) |
Heiko Schocher | 880eff5 | 2010-09-17 13:10:29 +0200 | [diff] [blame] | 234 | mmu_setup(); |
Lokesh Vutla | a43d46a | 2018-04-26 18:21:31 +0530 | [diff] [blame] | 235 | #elif defined(CONFIG_SYS_ARM_MPU) |
| 236 | if ((cache_bit == CR_C) && !mpu_enabled()) { |
| 237 | printf("Consider enabling MPU before enabling caches\n"); |
| 238 | return; |
| 239 | } |
| 240 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 241 | reg = get_cr(); /* get control reg. */ |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 242 | set_cr(reg | cache_bit); |
| 243 | } |
| 244 | |
| 245 | /* cache_bit must be either CR_I or CR_C */ |
| 246 | static void cache_disable(uint32_t cache_bit) |
| 247 | { |
| 248 | uint32_t reg; |
| 249 | |
SRICHARAN R | d702b08 | 2012-05-16 23:52:54 +0000 | [diff] [blame] | 250 | reg = get_cr(); |
SRICHARAN R | d702b08 | 2012-05-16 23:52:54 +0000 | [diff] [blame] | 251 | |
Heiko Schocher | 880eff5 | 2010-09-17 13:10:29 +0200 | [diff] [blame] | 252 | if (cache_bit == CR_C) { |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 253 | /* if cache isn;t enabled no need to disable */ |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 254 | if ((reg & CR_C) != CR_C) |
| 255 | return; |
Lokesh Vutla | 7a540ee | 2019-10-30 15:55:41 +0530 | [diff] [blame] | 256 | #ifdef CONFIG_SYS_ARM_MMU |
Heiko Schocher | 880eff5 | 2010-09-17 13:10:29 +0200 | [diff] [blame] | 257 | /* if disabling data cache, disable mmu too */ |
| 258 | cache_bit |= CR_M; |
Lokesh Vutla | 7a540ee | 2019-10-30 15:55:41 +0530 | [diff] [blame] | 259 | #endif |
Heiko Schocher | 880eff5 | 2010-09-17 13:10:29 +0200 | [diff] [blame] | 260 | } |
Arun Mankuzhi | 44df5e8 | 2012-11-30 13:01:14 +0000 | [diff] [blame] | 261 | reg = get_cr(); |
Lothar Waßmann | 53d4ed7 | 2017-06-08 09:48:41 +0200 | [diff] [blame] | 262 | |
Lokesh Vutla | 7a540ee | 2019-10-30 15:55:41 +0530 | [diff] [blame] | 263 | #ifdef CONFIG_SYS_ARM_MMU |
Arun Mankuzhi | 44df5e8 | 2012-11-30 13:01:14 +0000 | [diff] [blame] | 264 | if (cache_bit == (CR_C | CR_M)) |
Lokesh Vutla | 7a540ee | 2019-10-30 15:55:41 +0530 | [diff] [blame] | 265 | #elif defined(CONFIG_SYS_ARM_MPU) |
| 266 | if (cache_bit == CR_C) |
| 267 | #endif |
Arun Mankuzhi | 44df5e8 | 2012-11-30 13:01:14 +0000 | [diff] [blame] | 268 | flush_dcache_all(); |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 269 | set_cr(reg & ~cache_bit); |
| 270 | } |
| 271 | #endif |
| 272 | |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 273 | #if CONFIG_IS_ENABLED(SYS_ICACHE_OFF) |
Simon Glass | 6cc915b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 274 | void icache_enable(void) |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 275 | { |
| 276 | return; |
| 277 | } |
| 278 | |
Simon Glass | 6cc915b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 279 | void icache_disable(void) |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 280 | { |
| 281 | return; |
| 282 | } |
| 283 | |
Simon Glass | 6cc915b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 284 | int icache_status(void) |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 285 | { |
| 286 | return 0; /* always off */ |
| 287 | } |
| 288 | #else |
| 289 | void icache_enable(void) |
| 290 | { |
| 291 | cache_enable(CR_I); |
| 292 | } |
| 293 | |
| 294 | void icache_disable(void) |
| 295 | { |
| 296 | cache_disable(CR_I); |
| 297 | } |
| 298 | |
| 299 | int icache_status(void) |
| 300 | { |
| 301 | return (get_cr() & CR_I) != 0; |
| 302 | } |
| 303 | #endif |
| 304 | |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 305 | #if CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Simon Glass | 6cc915b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 306 | void dcache_enable(void) |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 307 | { |
| 308 | return; |
| 309 | } |
| 310 | |
Simon Glass | 6cc915b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 311 | void dcache_disable(void) |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 312 | { |
| 313 | return; |
| 314 | } |
| 315 | |
Simon Glass | 6cc915b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 316 | int dcache_status(void) |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 317 | { |
| 318 | return 0; /* always off */ |
| 319 | } |
| 320 | #else |
| 321 | void dcache_enable(void) |
| 322 | { |
| 323 | cache_enable(CR_C); |
| 324 | } |
| 325 | |
| 326 | void dcache_disable(void) |
| 327 | { |
| 328 | cache_disable(CR_C); |
| 329 | } |
| 330 | |
| 331 | int dcache_status(void) |
| 332 | { |
| 333 | return (get_cr() & CR_C) != 0; |
| 334 | } |
| 335 | #endif |