Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | edc48b6 | 2002-09-08 17:56:50 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | edc48b6 | 2002-09-08 17:56:50 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* for now: just dummy functions to satisfy the linker */ |
| 8 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 9 | #include <common.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Thierry Reding | c97d974 | 2014-12-09 22:25:22 -0700 | [diff] [blame] | 12 | #include <malloc.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 13 | #include <asm/cache.h> |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 14 | |
Ovidiu Panait | 68b371a | 2020-03-29 20:57:39 +0300 | [diff] [blame] | 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Wu, Josh | 2219026 | 2015-07-27 11:40:17 +0800 | [diff] [blame] | 17 | /* |
| 18 | * Flush range from all levels of d-cache/unified-cache. |
| 19 | * Affects the range [start, start + size - 1]. |
| 20 | */ |
Jeroen Hofstee | d746077 | 2014-06-23 22:07:04 +0200 | [diff] [blame] | 21 | __weak void flush_cache(unsigned long start, unsigned long size) |
wdenk | edc48b6 | 2002-09-08 17:56:50 +0000 | [diff] [blame] | 22 | { |
Wu, Josh | 2219026 | 2015-07-27 11:40:17 +0800 | [diff] [blame] | 23 | flush_dcache_range(start, start + size); |
wdenk | edc48b6 | 2002-09-08 17:56:50 +0000 | [diff] [blame] | 24 | } |
Aneesh V | 3bda377 | 2011-06-16 23:30:50 +0000 | [diff] [blame] | 25 | |
| 26 | /* |
| 27 | * Default implementation: |
| 28 | * do a range flush for the entire range |
| 29 | */ |
Jeroen Hofstee | d746077 | 2014-06-23 22:07:04 +0200 | [diff] [blame] | 30 | __weak void flush_dcache_all(void) |
Aneesh V | 3bda377 | 2011-06-16 23:30:50 +0000 | [diff] [blame] | 31 | { |
| 32 | flush_cache(0, ~0); |
| 33 | } |
Aneesh V | fffbb97 | 2011-08-16 04:33:05 +0000 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * Default implementation of enable_caches() |
| 37 | * Real implementation should be in platform code |
| 38 | */ |
Jeroen Hofstee | d746077 | 2014-06-23 22:07:04 +0200 | [diff] [blame] | 39 | __weak void enable_caches(void) |
Aneesh V | fffbb97 | 2011-08-16 04:33:05 +0000 | [diff] [blame] | 40 | { |
| 41 | puts("WARNING: Caches not enabled\n"); |
| 42 | } |
Thierry Reding | c97d974 | 2014-12-09 22:25:22 -0700 | [diff] [blame] | 43 | |
Wu, Josh | aaa3545 | 2015-07-27 11:40:16 +0800 | [diff] [blame] | 44 | __weak void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 45 | { |
| 46 | /* An empty stub, real implementation should be in platform code */ |
| 47 | } |
| 48 | __weak void flush_dcache_range(unsigned long start, unsigned long stop) |
| 49 | { |
| 50 | /* An empty stub, real implementation should be in platform code */ |
| 51 | } |
| 52 | |
Simon Glass | 8540658 | 2016-06-19 19:43:01 -0600 | [diff] [blame] | 53 | int check_cache_range(unsigned long start, unsigned long stop) |
| 54 | { |
| 55 | int ok = 1; |
| 56 | |
| 57 | if (start & (CONFIG_SYS_CACHELINE_SIZE - 1)) |
| 58 | ok = 0; |
| 59 | |
| 60 | if (stop & (CONFIG_SYS_CACHELINE_SIZE - 1)) |
| 61 | ok = 0; |
| 62 | |
| 63 | if (!ok) { |
Simon Glass | 143997a | 2016-06-19 19:43:05 -0600 | [diff] [blame] | 64 | warn_non_spl("CACHE: Misaligned operation at range [%08lx, %08lx]\n", |
| 65 | start, stop); |
Simon Glass | 8540658 | 2016-06-19 19:43:01 -0600 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | return ok; |
| 69 | } |
| 70 | |
Thierry Reding | c97d974 | 2014-12-09 22:25:22 -0700 | [diff] [blame] | 71 | #ifdef CONFIG_SYS_NONCACHED_MEMORY |
| 72 | /* |
| 73 | * Reserve one MMU section worth of address space below the malloc() area that |
| 74 | * will be mapped uncached. |
| 75 | */ |
| 76 | static unsigned long noncached_start; |
| 77 | static unsigned long noncached_end; |
| 78 | static unsigned long noncached_next; |
| 79 | |
Patrice Chotard | e2eb721 | 2020-04-28 11:38:03 +0200 | [diff] [blame] | 80 | void noncached_set_region(void) |
| 81 | { |
| 82 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
| 83 | mmu_set_region_dcache_behaviour(noncached_start, |
| 84 | noncached_end - noncached_start, |
| 85 | DCACHE_OFF); |
| 86 | #endif |
| 87 | } |
| 88 | |
Ovidiu Panait | 1c45ed9 | 2020-11-28 10:43:13 +0200 | [diff] [blame] | 89 | int noncached_init(void) |
Thierry Reding | c97d974 | 2014-12-09 22:25:22 -0700 | [diff] [blame] | 90 | { |
| 91 | phys_addr_t start, end; |
| 92 | size_t size; |
| 93 | |
Stephen Warren | 9b49643 | 2019-08-27 11:54:31 -0600 | [diff] [blame] | 94 | /* If this calculation changes, update board_f.c:reserve_noncached() */ |
Thierry Reding | c97d974 | 2014-12-09 22:25:22 -0700 | [diff] [blame] | 95 | end = ALIGN(mem_malloc_start, MMU_SECTION_SIZE) - MMU_SECTION_SIZE; |
| 96 | size = ALIGN(CONFIG_SYS_NONCACHED_MEMORY, MMU_SECTION_SIZE); |
| 97 | start = end - size; |
| 98 | |
| 99 | debug("mapping memory %pa-%pa non-cached\n", &start, &end); |
| 100 | |
| 101 | noncached_start = start; |
| 102 | noncached_end = end; |
| 103 | noncached_next = start; |
| 104 | |
Patrice Chotard | e2eb721 | 2020-04-28 11:38:03 +0200 | [diff] [blame] | 105 | noncached_set_region(); |
Ovidiu Panait | 1c45ed9 | 2020-11-28 10:43:13 +0200 | [diff] [blame] | 106 | |
| 107 | return 0; |
Thierry Reding | c97d974 | 2014-12-09 22:25:22 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | phys_addr_t noncached_alloc(size_t size, size_t align) |
| 111 | { |
| 112 | phys_addr_t next = ALIGN(noncached_next, align); |
| 113 | |
| 114 | if (next >= noncached_end || (noncached_end - next) < size) |
| 115 | return 0; |
| 116 | |
| 117 | debug("allocated %zu bytes of uncached memory @%pa\n", size, &next); |
| 118 | noncached_next = next + size; |
| 119 | |
| 120 | return next; |
| 121 | } |
| 122 | #endif /* CONFIG_SYS_NONCACHED_MEMORY */ |
Albert ARIBAUD | a382322 | 2015-10-23 18:06:40 +0200 | [diff] [blame] | 123 | |
Tom Rini | 1c640a6 | 2017-03-18 09:01:44 -0400 | [diff] [blame] | 124 | #if CONFIG_IS_ENABLED(SYS_THUMB_BUILD) |
Albert ARIBAUD | a382322 | 2015-10-23 18:06:40 +0200 | [diff] [blame] | 125 | void invalidate_l2_cache(void) |
| 126 | { |
| 127 | unsigned int val = 0; |
| 128 | |
| 129 | asm volatile("mcr p15, 1, %0, c15, c11, 0 @ invl l2 cache" |
| 130 | : : "r" (val) : "cc"); |
| 131 | isb(); |
| 132 | } |
| 133 | #endif |
Ovidiu Panait | 68b371a | 2020-03-29 20:57:39 +0300 | [diff] [blame] | 134 | |
Ovidiu Panait | 2a2941b | 2020-03-29 20:57:41 +0300 | [diff] [blame] | 135 | int arch_reserve_mmu(void) |
Ovidiu Panait | 68b371a | 2020-03-29 20:57:39 +0300 | [diff] [blame] | 136 | { |
Ovidiu Panait | 2b61847 | 2020-03-29 20:57:40 +0300 | [diff] [blame] | 137 | return arm_reserve_mmu(); |
| 138 | } |
| 139 | |
| 140 | __weak int arm_reserve_mmu(void) |
| 141 | { |
Ovidiu Panait | 68b371a | 2020-03-29 20:57:39 +0300 | [diff] [blame] | 142 | #if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) |
| 143 | /* reserve TLB table */ |
| 144 | gd->arch.tlb_size = PGTABLE_SIZE; |
| 145 | gd->relocaddr -= gd->arch.tlb_size; |
| 146 | |
| 147 | /* round down to next 64 kB limit */ |
| 148 | gd->relocaddr &= ~(0x10000 - 1); |
| 149 | |
| 150 | gd->arch.tlb_addr = gd->relocaddr; |
| 151 | debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr, |
| 152 | gd->arch.tlb_addr + gd->arch.tlb_size); |
| 153 | |
| 154 | #ifdef CONFIG_SYS_MEM_RESERVE_SECURE |
| 155 | /* |
| 156 | * Record allocated tlb_addr in case gd->tlb_addr to be overwritten |
| 157 | * with location within secure ram. |
| 158 | */ |
| 159 | gd->arch.tlb_allocated = gd->arch.tlb_addr; |
| 160 | #endif |
| 161 | #endif |
| 162 | |
| 163 | return 0; |
| 164 | } |