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 | |
| 17 | #include <common.h> |
| 18 | #include <command.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 19 | #include <cpu_func.h> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 20 | #include <irq_func.h> |
Jean-Christophe PLAGNIOL-VILLARD | 9053b5a | 2009-04-05 13:02:43 +0200 | [diff] [blame] | 21 | #include <asm/system.h> |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 22 | |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 23 | static void cache_flush(void); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 24 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 25 | int cleanup_before_linux (void) |
| 26 | { |
| 27 | /* |
| 28 | * this function is called just before we call linux |
| 29 | * it prepares the processor for linux |
| 30 | * |
| 31 | * we turn off caches etc ... |
| 32 | */ |
| 33 | |
Simon Glass | f87959b | 2019-11-14 12:57:40 -0700 | [diff] [blame] | 34 | disable_interrupts(); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 35 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 36 | /* turn off I/D-cache */ |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 37 | icache_disable(); |
| 38 | dcache_disable(); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 39 | /* flush I/D-cache */ |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 40 | cache_flush(); |
| 41 | |
| 42 | return 0; |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 45 | static void cache_flush(void) |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 46 | { |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 47 | unsigned long i = 0; |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 48 | /* clean entire data cache */ |
| 49 | asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i)); |
| 50 | /* invalidate both caches and flush btb */ |
| 51 | asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i)); |
| 52 | /* mem barrier to sync things */ |
| 53 | asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i)); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 54 | } |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 55 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 56 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 57 | void invalidate_dcache_all(void) |
| 58 | { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 59 | asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void flush_dcache_all(void) |
| 63 | { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 64 | asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0)); |
| 65 | asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 68 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 69 | { |
Benoît Thébaudeau | 1053bd2 | 2012-07-19 01:35:32 +0000 | [diff] [blame] | 70 | if (!check_cache_range(start, stop)) |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 71 | return; |
| 72 | |
| 73 | while (start < stop) { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 74 | asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 75 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | void flush_dcache_range(unsigned long start, unsigned long stop) |
| 80 | { |
Benoît Thébaudeau | 1053bd2 | 2012-07-19 01:35:32 +0000 | [diff] [blame] | 81 | if (!check_cache_range(start, stop)) |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 82 | return; |
| 83 | |
| 84 | while (start < stop) { |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 85 | asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 86 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 87 | } |
| 88 | |
Stefano Babic | 9e39793 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 89 | asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0)); |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 92 | #else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ |
Anatolij Gustschin | 02966ca | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 93 | void invalidate_dcache_all(void) |
| 94 | { |
| 95 | } |
| 96 | |
| 97 | void flush_dcache_all(void) |
| 98 | { |
| 99 | } |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 100 | #endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ |
Benoît Thébaudeau | dbbd845 | 2012-10-04 10:04:02 +0000 | [diff] [blame] | 101 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 102 | #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] | 103 | void enable_caches(void) |
| 104 | { |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 105 | #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF) |
Benoît Thébaudeau | dbbd845 | 2012-10-04 10:04:02 +0000 | [diff] [blame] | 106 | icache_enable(); |
| 107 | #endif |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 108 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Benoît Thébaudeau | dbbd845 | 2012-10-04 10:04:02 +0000 | [diff] [blame] | 109 | dcache_enable(); |
| 110 | #endif |
| 111 | } |
| 112 | #endif |