wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2004 Texas Insturments |
| 3 | * |
| 4 | * (C) Copyright 2002 |
| 5 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 6 | * Marius Groeger <mgroeger@sysgo.de> |
| 7 | * |
| 8 | * (C) Copyright 2002 |
Detlev Zundel | f1b3f2b | 2009-05-13 10:54:10 +0200 | [diff] [blame] | 9 | * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de> |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 10 | * |
| 11 | * See file CREDITS for list of people who contributed to this |
| 12 | * project. |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License as |
| 16 | * published by the Free Software Foundation; either version 2 of |
| 17 | * the License, or (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 27 | * MA 02111-1307 USA |
| 28 | */ |
| 29 | |
| 30 | /* |
| 31 | * CPU specific code |
| 32 | */ |
| 33 | |
| 34 | #include <common.h> |
| 35 | #include <command.h> |
Jean-Christophe PLAGNIOL-VILLARD | 9053b5a | 2009-04-05 13:02:43 +0200 | [diff] [blame] | 36 | #include <asm/system.h> |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 37 | |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 38 | static void cache_flush(void); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 39 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 40 | int cleanup_before_linux (void) |
| 41 | { |
| 42 | /* |
| 43 | * this function is called just before we call linux |
| 44 | * it prepares the processor for linux |
| 45 | * |
| 46 | * we turn off caches etc ... |
| 47 | */ |
| 48 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 49 | disable_interrupts (); |
| 50 | |
| 51 | #ifdef CONFIG_LCD |
| 52 | { |
| 53 | extern void lcd_disable(void); |
| 54 | extern void lcd_panel_disable(void); |
| 55 | |
| 56 | lcd_disable(); /* proper disable of lcd & panel */ |
| 57 | lcd_panel_disable(); |
| 58 | } |
| 59 | #endif |
| 60 | |
| 61 | /* turn off I/D-cache */ |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 62 | icache_disable(); |
| 63 | dcache_disable(); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 64 | /* flush I/D-cache */ |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 65 | cache_flush(); |
| 66 | |
| 67 | return 0; |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 70 | static void cache_flush(void) |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 71 | { |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 72 | unsigned long i = 0; |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 73 | /* clean entire data cache */ |
| 74 | asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i)); |
| 75 | /* invalidate both caches and flush btb */ |
| 76 | asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i)); |
| 77 | /* mem barrier to sync things */ |
| 78 | asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i)); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 79 | } |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 80 | |
| 81 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 82 | |
| 83 | #ifndef CONFIG_SYS_CACHELINE_SIZE |
| 84 | #define CONFIG_SYS_CACHELINE_SIZE 32 |
| 85 | #endif |
| 86 | |
| 87 | void invalidate_dcache_all(void) |
| 88 | { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 89 | asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void flush_dcache_all(void) |
| 93 | { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 94 | asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0)); |
| 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 | |
Benoît Thébaudeau | 1053bd2 | 2012-07-19 01:35:32 +0000 | [diff] [blame] | 98 | static int check_cache_range(unsigned long start, unsigned long stop) |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 99 | { |
| 100 | int ok = 1; |
| 101 | |
| 102 | if (start & (CONFIG_SYS_CACHELINE_SIZE - 1)) |
| 103 | ok = 0; |
| 104 | |
| 105 | if (stop & (CONFIG_SYS_CACHELINE_SIZE - 1)) |
| 106 | ok = 0; |
| 107 | |
| 108 | if (!ok) |
| 109 | debug("CACHE: Misaligned operation at range [%08lx, %08lx]\n", |
| 110 | start, stop); |
| 111 | |
| 112 | return ok; |
| 113 | } |
| 114 | |
| 115 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 116 | { |
Benoît Thébaudeau | 1053bd2 | 2012-07-19 01:35:32 +0000 | [diff] [blame] | 117 | if (!check_cache_range(start, stop)) |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 118 | return; |
| 119 | |
| 120 | while (start < stop) { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 121 | asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 122 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | void flush_dcache_range(unsigned long start, unsigned long stop) |
| 127 | { |
Benoît Thébaudeau | 1053bd2 | 2012-07-19 01:35:32 +0000 | [diff] [blame] | 128 | if (!check_cache_range(start, stop)) |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 129 | return; |
| 130 | |
| 131 | while (start < stop) { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 132 | asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 133 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 134 | } |
| 135 | |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 136 | asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | void flush_cache(unsigned long start, unsigned long size) |
| 140 | { |
| 141 | flush_dcache_range(start, start + size); |
| 142 | } |
| 143 | |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 144 | #else /* #ifndef CONFIG_SYS_DCACHE_OFF */ |
| 145 | void invalidate_dcache_all(void) |
| 146 | { |
| 147 | } |
| 148 | |
| 149 | void flush_dcache_all(void) |
| 150 | { |
| 151 | } |
| 152 | |
| 153 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 154 | { |
| 155 | } |
| 156 | |
| 157 | void flush_dcache_range(unsigned long start, unsigned long stop) |
| 158 | { |
| 159 | } |
| 160 | |
| 161 | void flush_cache(unsigned long start, unsigned long size) |
| 162 | { |
| 163 | } |
| 164 | #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */ |
Benoît Thébaudeau | dbbd845 | 2012-10-04 10:04:02 +0000 | [diff] [blame] | 165 | |
| 166 | #if !defined(CONFIG_SYS_ICACHE_OFF) || !defined(CONFIG_SYS_DCACHE_OFF) |
| 167 | void enable_caches(void) |
| 168 | { |
| 169 | #ifndef CONFIG_SYS_ICACHE_OFF |
| 170 | icache_enable(); |
| 171 | #endif |
| 172 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 173 | dcache_enable(); |
| 174 | #endif |
| 175 | } |
| 176 | #endif |