wdenk | edc48b6 | 2002-09-08 17:56:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | edc48b6 | 2002-09-08 17:56:50 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* for now: just dummy functions to satisfy the linker */ |
| 9 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 10 | #include <common.h> |
Thierry Reding | c97d974 | 2014-12-09 22:25:22 -0700 | [diff] [blame] | 11 | #include <malloc.h> |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 12 | |
Jeroen Hofstee | d746077 | 2014-06-23 22:07:04 +0200 | [diff] [blame] | 13 | __weak void flush_cache(unsigned long start, unsigned long size) |
wdenk | edc48b6 | 2002-09-08 17:56:50 +0000 | [diff] [blame] | 14 | { |
Masahiro Yamada | a8b4c8c | 2014-11-06 14:59:37 +0900 | [diff] [blame] | 15 | #if defined(CONFIG_CPU_ARM1136) |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 16 | |
Albert ARIBAUD | 7a6fd04 | 2014-04-15 16:13:47 +0200 | [diff] [blame] | 17 | #if !defined(CONFIG_SYS_ICACHE_OFF) |
| 18 | asm("mcr p15, 0, r1, c7, c5, 0"); /* invalidate I cache */ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 19 | #endif |
Albert ARIBAUD | 7a6fd04 | 2014-04-15 16:13:47 +0200 | [diff] [blame] | 20 | |
| 21 | #if !defined(CONFIG_SYS_DCACHE_OFF) |
| 22 | asm("mcr p15, 0, r1, c7, c14, 0"); /* Clean+invalidate D cache */ |
| 23 | #endif |
| 24 | |
Masahiro Yamada | a8b4c8c | 2014-11-06 14:59:37 +0900 | [diff] [blame] | 25 | #endif /* CONFIG_CPU_ARM1136 */ |
Albert ARIBAUD | 7a6fd04 | 2014-04-15 16:13:47 +0200 | [diff] [blame] | 26 | |
Masahiro Yamada | 4fb5d07 | 2014-11-06 14:59:36 +0900 | [diff] [blame] | 27 | #ifdef CONFIG_CPU_ARM926EJS |
Heiko Schocher | b642d83 | 2014-11-18 09:41:56 +0100 | [diff] [blame] | 28 | #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) |
Heiko Schocher | 5443309 | 2010-09-17 13:10:30 +0200 | [diff] [blame] | 29 | /* test and clean, page 2-23 of arm926ejs manual */ |
| 30 | asm("0: mrc p15, 0, r15, c7, c10, 3\n\t" "bne 0b\n" : : : "memory"); |
| 31 | /* disable write buffer as well (page 2-22) */ |
| 32 | asm("mcr p15, 0, %0, c7, c10, 4" : : "r" (0)); |
Heiko Schocher | b642d83 | 2014-11-18 09:41:56 +0100 | [diff] [blame] | 33 | #endif |
Masahiro Yamada | 4fb5d07 | 2014-11-06 14:59:36 +0900 | [diff] [blame] | 34 | #endif /* CONFIG_CPU_ARM926EJS */ |
wdenk | edc48b6 | 2002-09-08 17:56:50 +0000 | [diff] [blame] | 35 | return; |
| 36 | } |
Aneesh V | 3bda377 | 2011-06-16 23:30:50 +0000 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * Default implementation: |
| 40 | * do a range flush for the entire range |
| 41 | */ |
Jeroen Hofstee | d746077 | 2014-06-23 22:07:04 +0200 | [diff] [blame] | 42 | __weak void flush_dcache_all(void) |
Aneesh V | 3bda377 | 2011-06-16 23:30:50 +0000 | [diff] [blame] | 43 | { |
| 44 | flush_cache(0, ~0); |
| 45 | } |
Aneesh V | fffbb97 | 2011-08-16 04:33:05 +0000 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Default implementation of enable_caches() |
| 49 | * Real implementation should be in platform code |
| 50 | */ |
Jeroen Hofstee | d746077 | 2014-06-23 22:07:04 +0200 | [diff] [blame] | 51 | __weak void enable_caches(void) |
Aneesh V | fffbb97 | 2011-08-16 04:33:05 +0000 | [diff] [blame] | 52 | { |
| 53 | puts("WARNING: Caches not enabled\n"); |
| 54 | } |
Thierry Reding | c97d974 | 2014-12-09 22:25:22 -0700 | [diff] [blame] | 55 | |
Wu, Josh | aaa3545 | 2015-07-27 11:40:16 +0800 | [diff] [blame^] | 56 | __weak void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 57 | { |
| 58 | /* An empty stub, real implementation should be in platform code */ |
| 59 | } |
| 60 | __weak void flush_dcache_range(unsigned long start, unsigned long stop) |
| 61 | { |
| 62 | /* An empty stub, real implementation should be in platform code */ |
| 63 | } |
| 64 | |
Thierry Reding | c97d974 | 2014-12-09 22:25:22 -0700 | [diff] [blame] | 65 | #ifdef CONFIG_SYS_NONCACHED_MEMORY |
| 66 | /* |
| 67 | * Reserve one MMU section worth of address space below the malloc() area that |
| 68 | * will be mapped uncached. |
| 69 | */ |
| 70 | static unsigned long noncached_start; |
| 71 | static unsigned long noncached_end; |
| 72 | static unsigned long noncached_next; |
| 73 | |
| 74 | void noncached_init(void) |
| 75 | { |
| 76 | phys_addr_t start, end; |
| 77 | size_t size; |
| 78 | |
| 79 | end = ALIGN(mem_malloc_start, MMU_SECTION_SIZE) - MMU_SECTION_SIZE; |
| 80 | size = ALIGN(CONFIG_SYS_NONCACHED_MEMORY, MMU_SECTION_SIZE); |
| 81 | start = end - size; |
| 82 | |
| 83 | debug("mapping memory %pa-%pa non-cached\n", &start, &end); |
| 84 | |
| 85 | noncached_start = start; |
| 86 | noncached_end = end; |
| 87 | noncached_next = start; |
| 88 | |
| 89 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 90 | mmu_set_region_dcache_behaviour(noncached_start, size, DCACHE_OFF); |
| 91 | #endif |
| 92 | } |
| 93 | |
| 94 | phys_addr_t noncached_alloc(size_t size, size_t align) |
| 95 | { |
| 96 | phys_addr_t next = ALIGN(noncached_next, align); |
| 97 | |
| 98 | if (next >= noncached_end || (noncached_end - next) < size) |
| 99 | return 0; |
| 100 | |
| 101 | debug("allocated %zu bytes of uncached memory @%pa\n", size, &next); |
| 102 | noncached_next = next + size; |
| 103 | |
| 104 | return next; |
| 105 | } |
| 106 | #endif /* CONFIG_SYS_NONCACHED_MEMORY */ |