blob: 4bf0446b543858eebca5d7d92730161fceab0b27 [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
wdenkf8062712005-01-09 23:16:25 +000017#include <command.h>
Simon Glass1d91ba72019-11-14 12:57:37 -070018#include <cpu_func.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070019#include <irq_func.h>
Simon Glass274e0b02020-05-10 11:39:56 -060020#include <asm/cache.h>
Jean-Christophe PLAGNIOL-VILLARD9053b5a2009-04-05 13:02:43 +020021#include <asm/system.h>
Marek Vasut84a74922023-07-01 17:26:19 +020022#include <asm/arm11.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
Marek Vasut84a74922023-07-01 17:26:19 +020046void allow_unaligned(void)
47{
48 arm11_arch_cp15_allow_unaligned();
49}
50
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020051static void cache_flush(void)
wdenkf8062712005-01-09 23:16:25 +000052{
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020053 unsigned long i = 0;
Stefano Babic9e397932012-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));
wdenkf8062712005-01-09 23:16:25 +000060}
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000061
Trevor Woerner43ec7e02019-05-03 09:41:00 -040062#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000063void invalidate_dcache_all(void)
64{
Stefano Babic9e397932012-04-09 13:33:04 +020065 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000066}
67
68void flush_dcache_all(void)
69{
Stefano Babic9e397932012-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 Gustschin02966ca2012-04-02 06:18:00 +000072}
73
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000074void invalidate_dcache_range(unsigned long start, unsigned long stop)
75{
Benoît Thébaudeau1053bd22012-07-19 01:35:32 +000076 if (!check_cache_range(start, stop))
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000077 return;
78
79 while (start < stop) {
Stefano Babic9e397932012-04-09 13:33:04 +020080 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
Anatolij Gustschin02966ca2012-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ébaudeau1053bd22012-07-19 01:35:32 +000087 if (!check_cache_range(start, stop))
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000088 return;
89
90 while (start < stop) {
Stefano Babic9e397932012-04-09 13:33:04 +020091 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000092 start += CONFIG_SYS_CACHELINE_SIZE;
93 }
94
Stefano Babic9e397932012-04-09 13:33:04 +020095 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000096}
97
Trevor Woerner43ec7e02019-05-03 09:41:00 -040098#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000099void invalidate_dcache_all(void)
100{
101}
102
103void flush_dcache_all(void)
104{
105}
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400106#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000107
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400108#if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000109void enable_caches(void)
110{
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400111#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000112 icache_enable();
113#endif
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400114#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000115 dcache_enable();
116#endif
117}
118#endif
Heinrich Schuchardt6d8c8db2024-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