1 // SPDX-License-Identifier: GPL-2.0+ 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 10 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de> 11 */ 12 13 /* 14 * CPU specific code 15 */ 16 17 #include <common.h> 18 #include <command.h> 19 #include <cpu_func.h> 20 #include <irq_func.h> 21 #include <asm/system.h> 22 #include <asm/cache.h> 23 #include <asm/armv7.h> 24 #include <linux/compiler.h> 25 cpu_cache_initialization(void)26void __weak cpu_cache_initialization(void){} 27 cleanup_before_linux_select(int flags)28int cleanup_before_linux_select(int flags) 29 { 30 /* 31 * this function is called just before we call linux 32 * it prepares the processor for linux 33 * 34 * we turn off caches etc ... 35 */ 36 #ifndef CONFIG_SPL_BUILD 37 disable_interrupts(); 38 #endif 39 40 if (flags & CBL_DISABLE_CACHES) { 41 /* 42 * turn off D-cache 43 * dcache_disable() in turn flushes the d-cache and disables MMU 44 */ 45 dcache_disable(); 46 v7_outer_cache_disable(); 47 48 /* 49 * After D-cache is flushed and before it is disabled there may 50 * be some new valid entries brought into the cache. We are 51 * sure that these lines are not dirty and will not affect our 52 * execution. (because unwinding the call-stack and setting a 53 * bit in CP15 SCTRL is all we did during this. We have not 54 * pushed anything on to the stack. Neither have we affected 55 * any static data) So just invalidate the entire d-cache again 56 * to avoid coherency problems for kernel 57 */ 58 #ifndef CONFIG_SYS_LEVEL2_CACHE_SHARE 59 invalidate_dcache_all(); 60 #endif 61 icache_disable(); 62 invalidate_icache_all(); 63 } else { 64 /* 65 * Turn off I-cache and invalidate it 66 */ 67 icache_disable(); 68 invalidate_icache_all(); 69 70 flush_dcache_all(); 71 invalidate_icache_all(); 72 icache_enable(); 73 } 74 75 /* 76 * Some CPU need more cache attention before starting the kernel. 77 */ 78 cpu_cache_initialization(); 79 80 return 0; 81 } 82 cleanup_before_linux(void)83int cleanup_before_linux(void) 84 { 85 return cleanup_before_linux_select(CBL_ALL); 86 } 87