xref: /OK3568_Linux_fs/u-boot/arch/arm/cpu/armv7/cpu.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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
9  * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
10  *
11  * SPDX-License-Identifier:	GPL-2.0+
12  */
13 
14 /*
15  * CPU specific code
16  */
17 
18 #include <common.h>
19 #include <command.h>
20 #include <asm/system.h>
21 #include <asm/cache.h>
22 #include <asm/armv7.h>
23 #include <linux/compiler.h>
24 
cpu_cache_initialization(void)25 void __weak cpu_cache_initialization(void){}
26 
cleanup_before_linux_select(int flags)27 int cleanup_before_linux_select(int flags)
28 {
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 	 */
35 #ifndef CONFIG_SPL_BUILD
36 	disable_interrupts();
37 #endif
38 	disable_async_abort();
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 		invalidate_dcache_all();
59 
60 		icache_disable();
61 		invalidate_icache_all();
62 	} else {
63 		/*
64 		 * Turn off I-cache and invalidate it
65 		 */
66 		icache_disable();
67 		invalidate_icache_all();
68 
69 		flush_dcache_all();
70 		invalidate_icache_all();
71 		icache_enable();
72 	}
73 
74 	/*
75 	 * Some CPU need more cache attention before starting the kernel.
76 	 */
77 	cpu_cache_initialization();
78 
79 	return 0;
80 }
81 
cleanup_before_linux(void)82 int cleanup_before_linux(void)
83 {
84 	return cleanup_before_linux_select(CBL_ALL);
85 }
86