blob: 44f27572674f61f2208be233972a1b2383a456b1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dirk Behme0b02b182008-12-14 09:47:13 +01002/*
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 Zundel792a09e2009-05-13 10:54:10 +020010 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
Dirk Behme0b02b182008-12-14 09:47:13 +010011 */
12
13/*
14 * CPU specific code
15 */
16
17#include <common.h>
18#include <command.h>
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +020019#include <asm/system.h>
Kim, Heung Jun06e758e2009-06-20 11:02:17 +020020#include <asm/cache.h>
Aneesh Vc2dd0d42011-06-16 23:30:49 +000021#include <asm/armv7.h>
Mathieu J. Poirier53e6f6a2012-07-31 08:59:32 +000022#include <linux/compiler.h>
Dirk Behme0b02b182008-12-14 09:47:13 +010023
Mathieu J. Poirier53e6f6a2012-07-31 08:59:32 +000024void __weak cpu_cache_initialization(void){}
25
Simon Glass4d24a112015-05-13 07:02:25 -060026int cleanup_before_linux_select(int flags)
Dirk Behme0b02b182008-12-14 09:47:13 +010027{
Dirk Behme0b02b182008-12-14 09:47:13 +010028 /*
29 * this function is called just before we call linux
30 * it prepares the processor for linux
31 *
32 * we turn off caches etc ...
33 */
Stefano Babicd4605872012-03-15 04:01:41 +000034#ifndef CONFIG_SPL_BUILD
Dirk Behme0b02b182008-12-14 09:47:13 +010035 disable_interrupts();
Stefano Babicd4605872012-03-15 04:01:41 +000036#endif
Dirk Behme0b02b182008-12-14 09:47:13 +010037
Simon Glass4d24a112015-05-13 07:02:25 -060038 if (flags & CBL_DISABLE_CACHES) {
39 /*
40 * turn off D-cache
41 * dcache_disable() in turn flushes the d-cache and disables MMU
42 */
43 dcache_disable();
44 v7_outer_cache_disable();
Dirk Behme0b02b182008-12-14 09:47:13 +010045
Simon Glass4d24a112015-05-13 07:02:25 -060046 /*
47 * After D-cache is flushed and before it is disabled there may
48 * be some new valid entries brought into the cache. We are
49 * sure that these lines are not dirty and will not affect our
50 * execution. (because unwinding the call-stack and setting a
51 * bit in CP15 SCTRL is all we did during this. We have not
52 * pushed anything on to the stack. Neither have we affected
53 * any static data) So just invalidate the entire d-cache again
54 * to avoid coherency problems for kernel
55 */
56 invalidate_dcache_all();
Sjoerd Simons81b06182015-08-30 16:55:49 -060057
58 icache_disable();
59 invalidate_icache_all();
Simon Glass4d24a112015-05-13 07:02:25 -060060 } else {
Sjoerd Simons81b06182015-08-30 16:55:49 -060061 /*
62 * Turn off I-cache and invalidate it
63 */
64 icache_disable();
65 invalidate_icache_all();
66
Simon Glass4d24a112015-05-13 07:02:25 -060067 flush_dcache_all();
68 invalidate_icache_all();
69 icache_enable();
70 }
Dirk Behme0b02b182008-12-14 09:47:13 +010071
Mathieu J. Poirier53e6f6a2012-07-31 08:59:32 +000072 /*
73 * Some CPU need more cache attention before starting the kernel.
74 */
75 cpu_cache_initialization();
76
Dirk Behme0b02b182008-12-14 09:47:13 +010077 return 0;
78}
Simon Glass4d24a112015-05-13 07:02:25 -060079
80int cleanup_before_linux(void)
81{
82 return cleanup_before_linux_select(CBL_ALL);
83}