blob: 4bf0446b543858eebca5d7d92730161fceab0b27 [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
wdenk8ed96042005-01-09 23:16:25 +000017#include <command.h>
Simon Glass9edefc22019-11-14 12:57:37 -070018#include <cpu_func.h>
Simon Glass36bf4462019-11-14 12:57:42 -070019#include <irq_func.h>
Simon Glass90526e92020-05-10 11:39:56 -060020#include <asm/cache.h>
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +020021#include <asm/system.h>
Marek Vasut2b17dd12023-07-01 17:26:19 +020022#include <asm/arm11.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
Marek Vasut2b17dd12023-07-01 17:26:19 +020046void allow_unaligned(void)
47{
48 arm11_arch_cp15_allow_unaligned();
49}
50
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020051static void cache_flush(void)
wdenk8ed96042005-01-09 23:16:25 +000052{
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020053 unsigned long i = 0;
Stefano Babicfbf4a072012-04-09 13:33:04 +020054 /* clean entire data cache */
55 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i));
56 /* invalidate both caches and flush btb */
57 asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i));
58 /* mem barrier to sync things */
59 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i));
wdenk8ed96042005-01-09 23:16:25 +000060}
Anatolij Gustschin219872c2012-04-02 06:18:00 +000061
Trevor Woerner10015022019-05-03 09:41:00 -040062#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Anatolij Gustschin219872c2012-04-02 06:18:00 +000063void invalidate_dcache_all(void)
64{
Stefano Babicfbf4a072012-04-09 13:33:04 +020065 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000066}
67
68void flush_dcache_all(void)
69{
Stefano Babicfbf4a072012-04-09 13:33:04 +020070 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
71 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000072}
73
Anatolij Gustschin219872c2012-04-02 06:18:00 +000074void invalidate_dcache_range(unsigned long start, unsigned long stop)
75{
Benoît Thébaudeauf8f09dd2012-07-19 01:35:32 +000076 if (!check_cache_range(start, stop))
Anatolij Gustschin219872c2012-04-02 06:18:00 +000077 return;
78
79 while (start < stop) {
Stefano Babicfbf4a072012-04-09 13:33:04 +020080 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000081 start += CONFIG_SYS_CACHELINE_SIZE;
82 }
83}
84
85void flush_dcache_range(unsigned long start, unsigned long stop)
86{
Benoît Thébaudeauf8f09dd2012-07-19 01:35:32 +000087 if (!check_cache_range(start, stop))
Anatolij Gustschin219872c2012-04-02 06:18:00 +000088 return;
89
90 while (start < stop) {
Stefano Babicfbf4a072012-04-09 13:33:04 +020091 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000092 start += CONFIG_SYS_CACHELINE_SIZE;
93 }
94
Stefano Babicfbf4a072012-04-09 13:33:04 +020095 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000096}
97
Trevor Woerner10015022019-05-03 09:41:00 -040098#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Anatolij Gustschin219872c2012-04-02 06:18:00 +000099void invalidate_dcache_all(void)
100{
101}
102
103void flush_dcache_all(void)
104{
105}
Trevor Woerner10015022019-05-03 09:41:00 -0400106#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Benoît Thébaudeauccfa3982012-10-04 10:04:02 +0000107
Trevor Woerner10015022019-05-03 09:41:00 -0400108#if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Benoît Thébaudeauccfa3982012-10-04 10:04:02 +0000109void enable_caches(void)
110{
Trevor Woerner10015022019-05-03 09:41:00 -0400111#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Benoît Thébaudeauccfa3982012-10-04 10:04:02 +0000112 icache_enable();
113#endif
Trevor Woerner10015022019-05-03 09:41:00 -0400114#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Benoît Thébaudeauccfa3982012-10-04 10:04:02 +0000115 dcache_enable();
116#endif
117}
118#endif
Heinrich Schuchardt15a15e32024-06-16 19:31:04 +0200119
120#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
121/* Invalidate entire I-cache */
122void invalidate_icache_all(void)
123{
124 unsigned long i = 0;
125
126 asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
127}
128#else
129void invalidate_icache_all(void) {}
130#endif