Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2004 Texas Insturments |
| 4 | * |
| 5 | * (C) Copyright 2002 |
| 6 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 7 | * Marius Groeger <mgroeger@sysgo.de> |
| 8 | * |
| 9 | * (C) Copyright 2002 |
Detlev Zundel | f1b3f2b | 2009-05-13 10:54:10 +0200 | [diff] [blame] | 10 | * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de> |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * CPU specific code |
| 15 | */ |
| 16 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 17 | #include <command.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 18 | #include <cpu_func.h> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 19 | #include <irq_func.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 20 | #include <asm/cache.h> |
Jean-Christophe PLAGNIOL-VILLARD | 9053b5a | 2009-04-05 13:02:43 +0200 | [diff] [blame] | 21 | #include <asm/system.h> |
Marek Vasut | 84a7492 | 2023-07-01 17:26:19 +0200 | [diff] [blame] | 22 | #include <asm/arm11.h> |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 23 | |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 24 | static void cache_flush(void); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 25 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 26 | int cleanup_before_linux (void) |
| 27 | { |
| 28 | /* |
| 29 | * this function is called just before we call linux |
| 30 | * it prepares the processor for linux |
| 31 | * |
| 32 | * we turn off caches etc ... |
| 33 | */ |
| 34 | |
Simon Glass | f87959b | 2019-11-14 12:57:40 -0700 | [diff] [blame] | 35 | disable_interrupts(); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 36 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 37 | /* turn off I/D-cache */ |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 38 | icache_disable(); |
| 39 | dcache_disable(); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 40 | /* flush I/D-cache */ |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 41 | cache_flush(); |
| 42 | |
| 43 | return 0; |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Marek Vasut | 84a7492 | 2023-07-01 17:26:19 +0200 | [diff] [blame] | 46 | void allow_unaligned(void) |
| 47 | { |
| 48 | arm11_arch_cp15_allow_unaligned(); |
| 49 | } |
| 50 | |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 51 | static void cache_flush(void) |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 52 | { |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 53 | unsigned long i = 0; |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 54 | /* clean entire data cache */ |
| 55 | asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i)); |
| 56 | /* invalidate both caches and flush btb */ |
| 57 | asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i)); |
| 58 | /* mem barrier to sync things */ |
| 59 | asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i)); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 60 | } |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 61 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 62 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 63 | void invalidate_dcache_all(void) |
| 64 | { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 65 | asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void flush_dcache_all(void) |
| 69 | { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 70 | asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0)); |
| 71 | asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 74 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 75 | { |
Benoît Thébaudeau | 1053bd2 | 2012-07-19 01:35:32 +0000 | [diff] [blame] | 76 | if (!check_cache_range(start, stop)) |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 77 | return; |
| 78 | |
| 79 | while (start < stop) { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 80 | asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 81 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void flush_dcache_range(unsigned long start, unsigned long stop) |
| 86 | { |
Benoît Thébaudeau | 1053bd2 | 2012-07-19 01:35:32 +0000 | [diff] [blame] | 87 | if (!check_cache_range(start, stop)) |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 88 | return; |
| 89 | |
| 90 | while (start < stop) { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 91 | asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 92 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 93 | } |
| 94 | |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 95 | asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 98 | #else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 99 | void invalidate_dcache_all(void) |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | void flush_dcache_all(void) |
| 104 | { |
| 105 | } |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 106 | #endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ |
Benoît Thébaudeau | dbbd845 | 2012-10-04 10:04:02 +0000 | [diff] [blame] | 107 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 108 | #if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) |
Benoît Thébaudeau | dbbd845 | 2012-10-04 10:04:02 +0000 | [diff] [blame] | 109 | void enable_caches(void) |
| 110 | { |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 111 | #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF) |
Benoît Thébaudeau | dbbd845 | 2012-10-04 10:04:02 +0000 | [diff] [blame] | 112 | icache_enable(); |
| 113 | #endif |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 114 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Benoît Thébaudeau | dbbd845 | 2012-10-04 10:04:02 +0000 | [diff] [blame] | 115 | dcache_enable(); |
| 116 | #endif |
| 117 | } |
| 118 | #endif |
Heinrich Schuchardt | 6d8c8db | 2024-06-16 19:31:04 +0200 | [diff] [blame] | 119 | |
| 120 | #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF) |
| 121 | /* Invalidate entire I-cache */ |
| 122 | void invalidate_icache_all(void) |
| 123 | { |
| 124 | unsigned long i = 0; |
| 125 | |
| 126 | asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i)); |
| 127 | } |
| 128 | #else |
| 129 | void invalidate_icache_all(void) {} |
| 130 | #endif |