Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2008 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 | 792a09e | 2009-05-13 10:54:10 +0200 | [diff] [blame] | 9 | * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de> |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 10 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 11 | * SPDX-License-Identifier: GPL-2.0+ |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * CPU specific code |
| 16 | */ |
| 17 | |
| 18 | #include <common.h> |
| 19 | #include <command.h> |
Jean-Christophe PLAGNIOL-VILLARD | 677e62f | 2009-04-05 13:02:43 +0200 | [diff] [blame] | 20 | #include <asm/system.h> |
Kim, Heung Jun | 06e758e | 2009-06-20 11:02:17 +0200 | [diff] [blame] | 21 | #include <asm/cache.h> |
Aneesh V | c2dd0d4 | 2011-06-16 23:30:49 +0000 | [diff] [blame] | 22 | #include <asm/armv7.h> |
Mathieu J. Poirier | 53e6f6a | 2012-07-31 08:59:32 +0000 | [diff] [blame] | 23 | #include <linux/compiler.h> |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 24 | |
Mathieu J. Poirier | 53e6f6a | 2012-07-31 08:59:32 +0000 | [diff] [blame] | 25 | void __weak cpu_cache_initialization(void){} |
| 26 | |
Simon Glass | 4d24a11 | 2015-05-13 07:02:25 -0600 | [diff] [blame] | 27 | int cleanup_before_linux_select(int flags) |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 28 | { |
Dirk Behme | 0b02b18 | 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 | d460587 | 2012-03-15 04:01:41 +0000 | [diff] [blame] | 35 | #ifndef CONFIG_SPL_BUILD |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 36 | disable_interrupts(); |
Stefano Babic | d460587 | 2012-03-15 04:01:41 +0000 | [diff] [blame] | 37 | #endif |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 38 | |
Aneesh V | c2dd0d4 | 2011-06-16 23:30:49 +0000 | [diff] [blame] | 39 | /* |
| 40 | * Turn off I-cache and invalidate it |
| 41 | */ |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 42 | icache_disable(); |
Aneesh V | c2dd0d4 | 2011-06-16 23:30:49 +0000 | [diff] [blame] | 43 | invalidate_icache_all(); |
| 44 | |
Simon Glass | 4d24a11 | 2015-05-13 07:02:25 -0600 | [diff] [blame] | 45 | if (flags & CBL_DISABLE_CACHES) { |
| 46 | /* |
| 47 | * turn off D-cache |
| 48 | * dcache_disable() in turn flushes the d-cache and disables MMU |
| 49 | */ |
| 50 | dcache_disable(); |
| 51 | v7_outer_cache_disable(); |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 52 | |
Simon Glass | 4d24a11 | 2015-05-13 07:02:25 -0600 | [diff] [blame] | 53 | /* |
| 54 | * After D-cache is flushed and before it is disabled there may |
| 55 | * be some new valid entries brought into the cache. We are |
| 56 | * sure that these lines are not dirty and will not affect our |
| 57 | * execution. (because unwinding the call-stack and setting a |
| 58 | * bit in CP15 SCTRL is all we did during this. We have not |
| 59 | * pushed anything on to the stack. Neither have we affected |
| 60 | * any static data) So just invalidate the entire d-cache again |
| 61 | * to avoid coherency problems for kernel |
| 62 | */ |
| 63 | invalidate_dcache_all(); |
| 64 | } else { |
| 65 | flush_dcache_all(); |
| 66 | invalidate_icache_all(); |
| 67 | icache_enable(); |
| 68 | } |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 69 | |
Mathieu J. Poirier | 53e6f6a | 2012-07-31 08:59:32 +0000 | [diff] [blame] | 70 | /* |
| 71 | * Some CPU need more cache attention before starting the kernel. |
| 72 | */ |
| 73 | cpu_cache_initialization(); |
| 74 | |
Dirk Behme | 0b02b18 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 75 | return 0; |
| 76 | } |
Simon Glass | 4d24a11 | 2015-05-13 07:02:25 -0600 | [diff] [blame] | 77 | |
| 78 | int cleanup_before_linux(void) |
| 79 | { |
| 80 | return cleanup_before_linux_select(CBL_ALL); |
| 81 | } |