blob: ffe35111d589729c7cb94c8580f46254e0725883 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk8ed96042005-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 Zundel792a09e2009-05-13 10:54:10 +020010 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
wdenk8ed96042005-01-09 23:16:25 +000011 */
12
13/*
14 * CPU specific code
15 */
16
17#include <common.h>
18#include <command.h>
Simon Glass9edefc22019-11-14 12:57:37 -070019#include <cpu_func.h>
Simon Glass36bf4462019-11-14 12:57:42 -070020#include <irq_func.h>
Simon Glass90526e92020-05-10 11:39:56 -060021#include <asm/cache.h>
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +020022#include <asm/system.h>
wdenk8ed96042005-01-09 23:16:25 +000023
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020024static void cache_flush(void);
wdenk8ed96042005-01-09 23:16:25 +000025
wdenk8ed96042005-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 Glass9d3915b2019-11-14 12:57:40 -070035 disable_interrupts();
wdenk8ed96042005-01-09 23:16:25 +000036
wdenk8ed96042005-01-09 23:16:25 +000037 /* turn off I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020038 icache_disable();
39 dcache_disable();
wdenk8ed96042005-01-09 23:16:25 +000040 /* flush I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020041 cache_flush();
42
43 return 0;
wdenk8ed96042005-01-09 23:16:25 +000044}
45
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020046static void cache_flush(void)
wdenk8ed96042005-01-09 23:16:25 +000047{
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020048 unsigned long i = 0;
Stefano Babicfbf4a072012-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));
wdenk8ed96042005-01-09 23:16:25 +000055}
Anatolij Gustschin219872c2012-04-02 06:18:00 +000056
Trevor Woerner10015022019-05-03 09:41:00 -040057#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Anatolij Gustschin219872c2012-04-02 06:18:00 +000058void invalidate_dcache_all(void)
59{
Stefano Babicfbf4a072012-04-09 13:33:04 +020060 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000061}
62
63void flush_dcache_all(void)
64{
Stefano Babicfbf4a072012-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 Gustschin219872c2012-04-02 06:18:00 +000067}
68
Anatolij Gustschin219872c2012-04-02 06:18:00 +000069void invalidate_dcache_range(unsigned long start, unsigned long stop)
70{
Benoît Thébaudeauf8f09dd2012-07-19 01:35:32 +000071 if (!check_cache_range(start, stop))
Anatolij Gustschin219872c2012-04-02 06:18:00 +000072 return;
73
74 while (start < stop) {
Stefano Babicfbf4a072012-04-09 13:33:04 +020075 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
Anatolij Gustschin219872c2012-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ébaudeauf8f09dd2012-07-19 01:35:32 +000082 if (!check_cache_range(start, stop))
Anatolij Gustschin219872c2012-04-02 06:18:00 +000083 return;
84
85 while (start < stop) {
Stefano Babicfbf4a072012-04-09 13:33:04 +020086 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000087 start += CONFIG_SYS_CACHELINE_SIZE;
88 }
89
Stefano Babicfbf4a072012-04-09 13:33:04 +020090 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000091}
92
Trevor Woerner10015022019-05-03 09:41:00 -040093#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Anatolij Gustschin219872c2012-04-02 06:18:00 +000094void invalidate_dcache_all(void)
95{
96}
97
98void flush_dcache_all(void)
99{
100}
Trevor Woerner10015022019-05-03 09:41:00 -0400101#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Benoît Thébaudeauccfa3982012-10-04 10:04:02 +0000102
Trevor Woerner10015022019-05-03 09:41:00 -0400103#if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Benoît Thébaudeauccfa3982012-10-04 10:04:02 +0000104void enable_caches(void)
105{
Trevor Woerner10015022019-05-03 09:41:00 -0400106#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Benoît Thébaudeauccfa3982012-10-04 10:04:02 +0000107 icache_enable();
108#endif
Trevor Woerner10015022019-05-03 09:41:00 -0400109#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Benoît Thébaudeauccfa3982012-10-04 10:04:02 +0000110 dcache_enable();
111#endif
112}
113#endif