blob: 6eac5ef3fe0049f5f41d11c1762f2a299527398d [file] [log] [blame]
Dirk Behme0b02b182008-12-14 09:47:13 +01001/*
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 Zundel792a09e2009-05-13 10:54:10 +02009 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
Dirk Behme0b02b182008-12-14 09:47:13 +010010 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020011 * SPDX-License-Identifier: GPL-2.0+
Dirk Behme0b02b182008-12-14 09:47:13 +010012 */
13
14/*
15 * CPU specific code
16 */
17
18#include <common.h>
19#include <command.h>
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +020020#include <asm/system.h>
Kim, Heung Jun06e758e2009-06-20 11:02:17 +020021#include <asm/cache.h>
Aneesh Vc2dd0d42011-06-16 23:30:49 +000022#include <asm/armv7.h>
Mathieu J. Poirier53e6f6a2012-07-31 08:59:32 +000023#include <linux/compiler.h>
Dirk Behme0b02b182008-12-14 09:47:13 +010024
Mathieu J. Poirier53e6f6a2012-07-31 08:59:32 +000025void __weak cpu_cache_initialization(void){}
26
Simon Glass4d24a112015-05-13 07:02:25 -060027int cleanup_before_linux_select(int flags)
Dirk Behme0b02b182008-12-14 09:47:13 +010028{
Dirk Behme0b02b182008-12-14 09:47:13 +010029 /*
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 Babicd4605872012-03-15 04:01:41 +000035#ifndef CONFIG_SPL_BUILD
Dirk Behme0b02b182008-12-14 09:47:13 +010036 disable_interrupts();
Stefano Babicd4605872012-03-15 04:01:41 +000037#endif
Dirk Behme0b02b182008-12-14 09:47:13 +010038
Simon Glass4d24a112015-05-13 07:02:25 -060039 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 Behme0b02b182008-12-14 09:47:13 +010046
Simon Glass4d24a112015-05-13 07:02:25 -060047 /*
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 Simons81b06182015-08-30 16:55:49 -060058
59 icache_disable();
60 invalidate_icache_all();
Simon Glass4d24a112015-05-13 07:02:25 -060061 } else {
Sjoerd Simons81b06182015-08-30 16:55:49 -060062 /*
63 * Turn off I-cache and invalidate it
64 */
65 icache_disable();
66 invalidate_icache_all();
67
Simon Glass4d24a112015-05-13 07:02:25 -060068 flush_dcache_all();
69 invalidate_icache_all();
70 icache_enable();
71 }
Dirk Behme0b02b182008-12-14 09:47:13 +010072
Mathieu J. Poirier53e6f6a2012-07-31 08:59:32 +000073 /*
74 * Some CPU need more cache attention before starting the kernel.
75 */
76 cpu_cache_initialization();
77
Dirk Behme0b02b182008-12-14 09:47:13 +010078 return 0;
79}
Simon Glass4d24a112015-05-13 07:02:25 -060080
81int cleanup_before_linux(void)
82{
83 return cleanup_before_linux_select(CBL_ALL);
84}