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