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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 11 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * CPU specific code |
| 16 | */ |
| 17 | |
| 18 | #include <common.h> |
| 19 | #include <command.h> |
Jean-Christophe PLAGNIOL-VILLARD | 9053b5a | 2009-04-05 13:02:43 +0200 | [diff] [blame] | 20 | #include <asm/system.h> |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 21 | |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 22 | static void cache_flush(void); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 23 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 24 | int cleanup_before_linux (void) |
| 25 | { |
| 26 | /* |
| 27 | * this function is called just before we call linux |
| 28 | * it prepares the processor for linux |
| 29 | * |
| 30 | * we turn off caches etc ... |
| 31 | */ |
| 32 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 33 | disable_interrupts (); |
| 34 | |
| 35 | #ifdef CONFIG_LCD |
| 36 | { |
| 37 | extern void lcd_disable(void); |
| 38 | extern void lcd_panel_disable(void); |
| 39 | |
| 40 | lcd_disable(); /* proper disable of lcd & panel */ |
| 41 | lcd_panel_disable(); |
| 42 | } |
| 43 | #endif |
| 44 | |
| 45 | /* turn off I/D-cache */ |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 46 | icache_disable(); |
| 47 | dcache_disable(); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 48 | /* flush I/D-cache */ |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 49 | cache_flush(); |
| 50 | |
| 51 | return 0; |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 54 | static void cache_flush(void) |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 55 | { |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 56 | unsigned long i = 0; |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 57 | /* clean entire data cache */ |
| 58 | asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i)); |
| 59 | /* invalidate both caches and flush btb */ |
| 60 | asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i)); |
| 61 | /* mem barrier to sync things */ |
| 62 | asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i)); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 63 | } |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 64 | |
| 65 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 66 | |
| 67 | #ifndef CONFIG_SYS_CACHELINE_SIZE |
| 68 | #define CONFIG_SYS_CACHELINE_SIZE 32 |
| 69 | #endif |
| 70 | |
| 71 | void invalidate_dcache_all(void) |
| 72 | { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 73 | asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void flush_dcache_all(void) |
| 77 | { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 78 | asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0)); |
| 79 | asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Benoît Thébaudeau | 1053bd2 | 2012-07-19 01:35:32 +0000 | [diff] [blame] | 82 | static int check_cache_range(unsigned long start, unsigned long stop) |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 83 | { |
| 84 | int ok = 1; |
| 85 | |
| 86 | if (start & (CONFIG_SYS_CACHELINE_SIZE - 1)) |
| 87 | ok = 0; |
| 88 | |
| 89 | if (stop & (CONFIG_SYS_CACHELINE_SIZE - 1)) |
| 90 | ok = 0; |
| 91 | |
| 92 | if (!ok) |
| 93 | debug("CACHE: Misaligned operation at range [%08lx, %08lx]\n", |
| 94 | start, stop); |
| 95 | |
| 96 | return ok; |
| 97 | } |
| 98 | |
| 99 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 100 | { |
Benoît Thébaudeau | 1053bd2 | 2012-07-19 01:35:32 +0000 | [diff] [blame] | 101 | if (!check_cache_range(start, stop)) |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 102 | return; |
| 103 | |
| 104 | while (start < stop) { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 105 | asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 106 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | void flush_dcache_range(unsigned long start, unsigned long stop) |
| 111 | { |
Benoît Thébaudeau | 1053bd2 | 2012-07-19 01:35:32 +0000 | [diff] [blame] | 112 | if (!check_cache_range(start, stop)) |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 113 | return; |
| 114 | |
| 115 | while (start < stop) { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 116 | asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 117 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 118 | } |
| 119 | |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 120 | asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void flush_cache(unsigned long start, unsigned long size) |
| 124 | { |
| 125 | flush_dcache_range(start, start + size); |
| 126 | } |
| 127 | |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 128 | #else /* #ifndef CONFIG_SYS_DCACHE_OFF */ |
| 129 | void invalidate_dcache_all(void) |
| 130 | { |
| 131 | } |
| 132 | |
| 133 | void flush_dcache_all(void) |
| 134 | { |
| 135 | } |
| 136 | |
| 137 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 138 | { |
| 139 | } |
| 140 | |
| 141 | void flush_dcache_range(unsigned long start, unsigned long stop) |
| 142 | { |
| 143 | } |
| 144 | |
| 145 | void flush_cache(unsigned long start, unsigned long size) |
| 146 | { |
| 147 | } |
| 148 | #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */ |
Benoît Thébaudeau | dbbd845 | 2012-10-04 10:04:02 +0000 | [diff] [blame] | 149 | |
| 150 | #if !defined(CONFIG_SYS_ICACHE_OFF) || !defined(CONFIG_SYS_DCACHE_OFF) |
| 151 | void enable_caches(void) |
| 152 | { |
| 153 | #ifndef CONFIG_SYS_ICACHE_OFF |
| 154 | icache_enable(); |
| 155 | #endif |
| 156 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 157 | dcache_enable(); |
| 158 | #endif |
| 159 | } |
| 160 | #endif |