Tom Rini | 83d290c | 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 | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 9 | #include <common.h> |
Thierry Reding | 1dfdd9b | 2014-12-09 22:25:22 -0700 | [diff] [blame] | 10 | #include <malloc.h> |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 11 | |
Wu, Josh | 633b6cc | 2015-07-27 11:40:17 +0800 | [diff] [blame] | 12 | /* |
| 13 | * Flush range from all levels of d-cache/unified-cache. |
| 14 | * Affects the range [start, start + size - 1]. |
| 15 | */ |
Jeroen Hofstee | fcfddfd | 2014-06-23 22:07:04 +0200 | [diff] [blame] | 16 | __weak void flush_cache(unsigned long start, unsigned long size) |
wdenk | edc48b6 | 2002-09-08 17:56:50 +0000 | [diff] [blame] | 17 | { |
Wu, Josh | 633b6cc | 2015-07-27 11:40:17 +0800 | [diff] [blame] | 18 | flush_dcache_range(start, start + size); |
wdenk | edc48b6 | 2002-09-08 17:56:50 +0000 | [diff] [blame] | 19 | } |
Aneesh V | e05f007 | 2011-06-16 23:30:50 +0000 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * Default implementation: |
| 23 | * do a range flush for the entire range |
| 24 | */ |
Jeroen Hofstee | fcfddfd | 2014-06-23 22:07:04 +0200 | [diff] [blame] | 25 | __weak void flush_dcache_all(void) |
Aneesh V | e05f007 | 2011-06-16 23:30:50 +0000 | [diff] [blame] | 26 | { |
| 27 | flush_cache(0, ~0); |
| 28 | } |
Aneesh V | cba4b18 | 2011-08-16 04:33:05 +0000 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | * Default implementation of enable_caches() |
| 32 | * Real implementation should be in platform code |
| 33 | */ |
Jeroen Hofstee | fcfddfd | 2014-06-23 22:07:04 +0200 | [diff] [blame] | 34 | __weak void enable_caches(void) |
Aneesh V | cba4b18 | 2011-08-16 04:33:05 +0000 | [diff] [blame] | 35 | { |
| 36 | puts("WARNING: Caches not enabled\n"); |
| 37 | } |
Thierry Reding | 1dfdd9b | 2014-12-09 22:25:22 -0700 | [diff] [blame] | 38 | |
Wu, Josh | 387871a | 2015-07-27 11:40:16 +0800 | [diff] [blame] | 39 | __weak void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 40 | { |
| 41 | /* An empty stub, real implementation should be in platform code */ |
| 42 | } |
| 43 | __weak void flush_dcache_range(unsigned long start, unsigned long stop) |
| 44 | { |
| 45 | /* An empty stub, real implementation should be in platform code */ |
| 46 | } |
| 47 | |
Simon Glass | 397b569 | 2016-06-19 19:43:01 -0600 | [diff] [blame] | 48 | int check_cache_range(unsigned long start, unsigned long stop) |
| 49 | { |
| 50 | int ok = 1; |
| 51 | |
| 52 | if (start & (CONFIG_SYS_CACHELINE_SIZE - 1)) |
| 53 | ok = 0; |
| 54 | |
| 55 | if (stop & (CONFIG_SYS_CACHELINE_SIZE - 1)) |
| 56 | ok = 0; |
| 57 | |
| 58 | if (!ok) { |
Simon Glass | bcc53bf | 2016-06-19 19:43:05 -0600 | [diff] [blame] | 59 | warn_non_spl("CACHE: Misaligned operation at range [%08lx, %08lx]\n", |
| 60 | start, stop); |
Simon Glass | 397b569 | 2016-06-19 19:43:01 -0600 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | return ok; |
| 64 | } |
| 65 | |
Thierry Reding | 1dfdd9b | 2014-12-09 22:25:22 -0700 | [diff] [blame] | 66 | #ifdef CONFIG_SYS_NONCACHED_MEMORY |
| 67 | /* |
| 68 | * Reserve one MMU section worth of address space below the malloc() area that |
| 69 | * will be mapped uncached. |
| 70 | */ |
| 71 | static unsigned long noncached_start; |
| 72 | static unsigned long noncached_end; |
| 73 | static unsigned long noncached_next; |
| 74 | |
| 75 | void noncached_init(void) |
| 76 | { |
| 77 | phys_addr_t start, end; |
| 78 | size_t size; |
| 79 | |
Stephen Warren | 5e0404f | 2019-08-27 11:54:31 -0600 | [diff] [blame] | 80 | /* If this calculation changes, update board_f.c:reserve_noncached() */ |
Thierry Reding | 1dfdd9b | 2014-12-09 22:25:22 -0700 | [diff] [blame] | 81 | end = ALIGN(mem_malloc_start, MMU_SECTION_SIZE) - MMU_SECTION_SIZE; |
| 82 | size = ALIGN(CONFIG_SYS_NONCACHED_MEMORY, MMU_SECTION_SIZE); |
| 83 | start = end - size; |
| 84 | |
| 85 | debug("mapping memory %pa-%pa non-cached\n", &start, &end); |
| 86 | |
| 87 | noncached_start = start; |
| 88 | noncached_end = end; |
| 89 | noncached_next = start; |
| 90 | |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 91 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Thierry Reding | 1dfdd9b | 2014-12-09 22:25:22 -0700 | [diff] [blame] | 92 | mmu_set_region_dcache_behaviour(noncached_start, size, DCACHE_OFF); |
| 93 | #endif |
| 94 | } |
| 95 | |
| 96 | phys_addr_t noncached_alloc(size_t size, size_t align) |
| 97 | { |
| 98 | phys_addr_t next = ALIGN(noncached_next, align); |
| 99 | |
| 100 | if (next >= noncached_end || (noncached_end - next) < size) |
| 101 | return 0; |
| 102 | |
| 103 | debug("allocated %zu bytes of uncached memory @%pa\n", size, &next); |
| 104 | noncached_next = next + size; |
| 105 | |
| 106 | return next; |
| 107 | } |
| 108 | #endif /* CONFIG_SYS_NONCACHED_MEMORY */ |
Albert ARIBAUD | 62e9207 | 2015-10-23 18:06:40 +0200 | [diff] [blame] | 109 | |
Tom Rini | 3a64940 | 2017-03-18 09:01:44 -0400 | [diff] [blame] | 110 | #if CONFIG_IS_ENABLED(SYS_THUMB_BUILD) |
Albert ARIBAUD | 62e9207 | 2015-10-23 18:06:40 +0200 | [diff] [blame] | 111 | void invalidate_l2_cache(void) |
| 112 | { |
| 113 | unsigned int val = 0; |
| 114 | |
| 115 | asm volatile("mcr p15, 1, %0, c15, c11, 0 @ invl l2 cache" |
| 116 | : : "r" (val) : "cc"); |
| 117 | isb(); |
| 118 | } |
| 119 | #endif |