blob: 6259ffa510866024d26aa110c8494d86b719db02 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dirk Behme7d75a102008-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 Zundelf1b3f2b2009-05-13 10:54:10 +020010 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
Dirk Behme7d75a102008-12-14 09:47:13 +010011 */
12
13/*
14 * CPU specific code
15 */
16
17#include <common.h>
18#include <command.h>
Simon Glass1d91ba72019-11-14 12:57:37 -070019#include <cpu_func.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070020#include <irq_func.h>
Jean-Christophe PLAGNIOL-VILLARD9053b5a2009-04-05 13:02:43 +020021#include <asm/system.h>
Kim, Heung Jun3b5ac952009-06-20 11:02:17 +020022#include <asm/cache.h>
Aneesh V3e3bc1e2011-06-16 23:30:49 +000023#include <asm/armv7.h>
Mathieu J. Poirier4d81b2de2012-07-31 08:59:32 +000024#include <linux/compiler.h>
Dirk Behme7d75a102008-12-14 09:47:13 +010025
Mathieu J. Poirier4d81b2de2012-07-31 08:59:32 +000026void __weak cpu_cache_initialization(void){}
27
Simon Glass442e5d72015-05-13 07:02:25 -060028int cleanup_before_linux_select(int flags)
Dirk Behme7d75a102008-12-14 09:47:13 +010029{
Dirk Behme7d75a102008-12-14 09:47:13 +010030 /*
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 */
Stefano Babic84fb0dd2012-03-15 04:01:41 +000036#ifndef CONFIG_SPL_BUILD
Dirk Behme7d75a102008-12-14 09:47:13 +010037 disable_interrupts();
Stefano Babic84fb0dd2012-03-15 04:01:41 +000038#endif
Dirk Behme7d75a102008-12-14 09:47:13 +010039
Simon Glass442e5d72015-05-13 07:02:25 -060040 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();
Dirk Behme7d75a102008-12-14 09:47:13 +010047
Simon Glass442e5d72015-05-13 07:02:25 -060048 /*
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();
Sjoerd Simons01947b82015-08-30 16:55:49 -060059
60 icache_disable();
61 invalidate_icache_all();
Simon Glass442e5d72015-05-13 07:02:25 -060062 } else {
Sjoerd Simons01947b82015-08-30 16:55:49 -060063 /*
64 * Turn off I-cache and invalidate it
65 */
66 icache_disable();
67 invalidate_icache_all();
68
Simon Glass442e5d72015-05-13 07:02:25 -060069 flush_dcache_all();
70 invalidate_icache_all();
71 icache_enable();
72 }
Dirk Behme7d75a102008-12-14 09:47:13 +010073
Mathieu J. Poirier4d81b2de2012-07-31 08:59:32 +000074 /*
75 * Some CPU need more cache attention before starting the kernel.
76 */
77 cpu_cache_initialization();
78
Dirk Behme7d75a102008-12-14 09:47:13 +010079 return 0;
80}
Simon Glass442e5d72015-05-13 07:02:25 -060081
82int cleanup_before_linux(void)
83{
84 return cleanup_before_linux_select(CBL_ALL);
85}
Marek Vasut13578042023-07-01 17:26:18 +020086
87void allow_unaligned(void)
88{
89 v7_arch_cp15_allow_unaligned();
90}