blob: ffe35111d589729c7cb94c8580f46254e0725883 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenkf8062712005-01-09 23:16:25 +00002/*
3 * (C) Copyright 2004 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>
wdenkf8062712005-01-09 23:16:25 +000011 */
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>
Simon Glass274e0b02020-05-10 11:39:56 -060021#include <asm/cache.h>
Jean-Christophe PLAGNIOL-VILLARD9053b5a2009-04-05 13:02:43 +020022#include <asm/system.h>
wdenkf8062712005-01-09 23:16:25 +000023
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020024static void cache_flush(void);
wdenkf8062712005-01-09 23:16:25 +000025
wdenkf8062712005-01-09 23:16:25 +000026int cleanup_before_linux (void)
27{
28 /*
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 */
34
Simon Glassf87959b2019-11-14 12:57:40 -070035 disable_interrupts();
wdenkf8062712005-01-09 23:16:25 +000036
wdenkf8062712005-01-09 23:16:25 +000037 /* turn off I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020038 icache_disable();
39 dcache_disable();
wdenkf8062712005-01-09 23:16:25 +000040 /* flush I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020041 cache_flush();
42
43 return 0;
wdenkf8062712005-01-09 23:16:25 +000044}
45
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020046static void cache_flush(void)
wdenkf8062712005-01-09 23:16:25 +000047{
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020048 unsigned long i = 0;
Stefano Babic9e397932012-04-09 13:33:04 +020049 /* clean entire data cache */
50 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i));
51 /* invalidate both caches and flush btb */
52 asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i));
53 /* mem barrier to sync things */
54 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i));
wdenkf8062712005-01-09 23:16:25 +000055}
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000056
Trevor Woerner43ec7e02019-05-03 09:41:00 -040057#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000058void invalidate_dcache_all(void)
59{
Stefano Babic9e397932012-04-09 13:33:04 +020060 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000061}
62
63void flush_dcache_all(void)
64{
Stefano Babic9e397932012-04-09 13:33:04 +020065 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
66 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000067}
68
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000069void invalidate_dcache_range(unsigned long start, unsigned long stop)
70{
Benoît Thébaudeau1053bd22012-07-19 01:35:32 +000071 if (!check_cache_range(start, stop))
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000072 return;
73
74 while (start < stop) {
Stefano Babic9e397932012-04-09 13:33:04 +020075 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000076 start += CONFIG_SYS_CACHELINE_SIZE;
77 }
78}
79
80void flush_dcache_range(unsigned long start, unsigned long stop)
81{
Benoît Thébaudeau1053bd22012-07-19 01:35:32 +000082 if (!check_cache_range(start, stop))
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000083 return;
84
85 while (start < stop) {
Stefano Babic9e397932012-04-09 13:33:04 +020086 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000087 start += CONFIG_SYS_CACHELINE_SIZE;
88 }
89
Stefano Babic9e397932012-04-09 13:33:04 +020090 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000091}
92
Trevor Woerner43ec7e02019-05-03 09:41:00 -040093#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000094void invalidate_dcache_all(void)
95{
96}
97
98void flush_dcache_all(void)
99{
100}
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400101#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000102
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400103#if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000104void enable_caches(void)
105{
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400106#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000107 icache_enable();
108#endif
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400109#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000110 dcache_enable();
111#endif
112}
113#endif