Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2008 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> |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * CPU specific code |
| 15 | */ |
| 16 | |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [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> |
Jean-Christophe PLAGNIOL-VILLARD | 9053b5a | 2009-04-05 13:02:43 +0200 | [diff] [blame] | 20 | #include <asm/system.h> |
Kim, Heung Jun | 3b5ac95 | 2009-06-20 11:02:17 +0200 | [diff] [blame] | 21 | #include <asm/cache.h> |
Aneesh V | 3e3bc1e | 2011-06-16 23:30:49 +0000 | [diff] [blame] | 22 | #include <asm/armv7.h> |
Mathieu J. Poirier | 4d81b2de | 2012-07-31 08:59:32 +0000 | [diff] [blame] | 23 | #include <linux/compiler.h> |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 24 | |
Mathieu J. Poirier | 4d81b2de | 2012-07-31 08:59:32 +0000 | [diff] [blame] | 25 | void __weak cpu_cache_initialization(void){} |
| 26 | |
Simon Glass | 442e5d7 | 2015-05-13 07:02:25 -0600 | [diff] [blame] | 27 | int cleanup_before_linux_select(int flags) |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 28 | { |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 29 | /* |
| 30 | * this function is called just before we call linux |
| 31 | * it prepares the processor for linux |
| 32 | * |
| 33 | * we turn off caches etc ... |
| 34 | */ |
Stefano Babic | 84fb0dd | 2012-03-15 04:01:41 +0000 | [diff] [blame] | 35 | #ifndef CONFIG_SPL_BUILD |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 36 | disable_interrupts(); |
Stefano Babic | 84fb0dd | 2012-03-15 04:01:41 +0000 | [diff] [blame] | 37 | #endif |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 38 | |
Simon Glass | 442e5d7 | 2015-05-13 07:02:25 -0600 | [diff] [blame] | 39 | if (flags & CBL_DISABLE_CACHES) { |
| 40 | /* |
| 41 | * turn off D-cache |
| 42 | * dcache_disable() in turn flushes the d-cache and disables MMU |
| 43 | */ |
| 44 | dcache_disable(); |
| 45 | v7_outer_cache_disable(); |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 46 | |
Simon Glass | 442e5d7 | 2015-05-13 07:02:25 -0600 | [diff] [blame] | 47 | /* |
| 48 | * After D-cache is flushed and before it is disabled there may |
| 49 | * be some new valid entries brought into the cache. We are |
| 50 | * sure that these lines are not dirty and will not affect our |
| 51 | * execution. (because unwinding the call-stack and setting a |
| 52 | * bit in CP15 SCTRL is all we did during this. We have not |
| 53 | * pushed anything on to the stack. Neither have we affected |
| 54 | * any static data) So just invalidate the entire d-cache again |
| 55 | * to avoid coherency problems for kernel |
| 56 | */ |
| 57 | invalidate_dcache_all(); |
Sjoerd Simons | 01947b8 | 2015-08-30 16:55:49 -0600 | [diff] [blame] | 58 | |
| 59 | icache_disable(); |
| 60 | invalidate_icache_all(); |
Simon Glass | 442e5d7 | 2015-05-13 07:02:25 -0600 | [diff] [blame] | 61 | } else { |
Sjoerd Simons | 01947b8 | 2015-08-30 16:55:49 -0600 | [diff] [blame] | 62 | /* |
| 63 | * Turn off I-cache and invalidate it |
| 64 | */ |
| 65 | icache_disable(); |
| 66 | invalidate_icache_all(); |
| 67 | |
Simon Glass | 442e5d7 | 2015-05-13 07:02:25 -0600 | [diff] [blame] | 68 | flush_dcache_all(); |
| 69 | invalidate_icache_all(); |
| 70 | icache_enable(); |
| 71 | } |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 72 | |
Mathieu J. Poirier | 4d81b2de | 2012-07-31 08:59:32 +0000 | [diff] [blame] | 73 | /* |
| 74 | * Some CPU need more cache attention before starting the kernel. |
| 75 | */ |
| 76 | cpu_cache_initialization(); |
| 77 | |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 78 | return 0; |
| 79 | } |
Simon Glass | 442e5d7 | 2015-05-13 07:02:25 -0600 | [diff] [blame] | 80 | |
| 81 | int cleanup_before_linux(void) |
| 82 | { |
| 83 | return cleanup_before_linux_select(CBL_ALL); |
| 84 | } |
Marek Vasut | 1357804 | 2023-07-01 17:26:18 +0200 | [diff] [blame] | 85 | |
| 86 | void allow_unaligned(void) |
| 87 | { |
| 88 | v7_arch_cp15_allow_unaligned(); |
| 89 | } |