blob: 1e16b89d0066349a5e257e0c364cb477b909324a [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>
Marek Vasut84a74922023-07-01 17:26:19 +020023#include <asm/arm11.h>
wdenkf8062712005-01-09 23:16:25 +000024
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020025static void cache_flush(void);
wdenkf8062712005-01-09 23:16:25 +000026
wdenkf8062712005-01-09 23:16:25 +000027int cleanup_before_linux (void)
28{
29 /*
30 * this function is called just before we call linux
31 * it prepares the processor for linux
32 *
33 * we turn off caches etc ...
34 */
35
Simon Glassf87959b2019-11-14 12:57:40 -070036 disable_interrupts();
wdenkf8062712005-01-09 23:16:25 +000037
wdenkf8062712005-01-09 23:16:25 +000038 /* turn off I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020039 icache_disable();
40 dcache_disable();
wdenkf8062712005-01-09 23:16:25 +000041 /* flush I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020042 cache_flush();
43
44 return 0;
wdenkf8062712005-01-09 23:16:25 +000045}
46
Marek Vasut84a74922023-07-01 17:26:19 +020047void allow_unaligned(void)
48{
49 arm11_arch_cp15_allow_unaligned();
50}
51
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020052static void cache_flush(void)
wdenkf8062712005-01-09 23:16:25 +000053{
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020054 unsigned long i = 0;
Stefano Babic9e397932012-04-09 13:33:04 +020055 /* clean entire data cache */
56 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i));
57 /* invalidate both caches and flush btb */
58 asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i));
59 /* mem barrier to sync things */
60 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i));
wdenkf8062712005-01-09 23:16:25 +000061}
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000062
Trevor Woerner43ec7e02019-05-03 09:41:00 -040063#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000064void invalidate_dcache_all(void)
65{
Stefano Babic9e397932012-04-09 13:33:04 +020066 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000067}
68
69void flush_dcache_all(void)
70{
Stefano Babic9e397932012-04-09 13:33:04 +020071 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
72 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000073}
74
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000075void invalidate_dcache_range(unsigned long start, unsigned long stop)
76{
Benoît Thébaudeau1053bd22012-07-19 01:35:32 +000077 if (!check_cache_range(start, stop))
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000078 return;
79
80 while (start < stop) {
Stefano Babic9e397932012-04-09 13:33:04 +020081 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000082 start += CONFIG_SYS_CACHELINE_SIZE;
83 }
84}
85
86void flush_dcache_range(unsigned long start, unsigned long stop)
87{
Benoît Thébaudeau1053bd22012-07-19 01:35:32 +000088 if (!check_cache_range(start, stop))
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000089 return;
90
91 while (start < stop) {
Stefano Babic9e397932012-04-09 13:33:04 +020092 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000093 start += CONFIG_SYS_CACHELINE_SIZE;
94 }
95
Stefano Babic9e397932012-04-09 13:33:04 +020096 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000097}
98
Trevor Woerner43ec7e02019-05-03 09:41:00 -040099#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Anatolij Gustschin02966ca2012-04-02 06:18:00 +0000100void invalidate_dcache_all(void)
101{
102}
103
104void flush_dcache_all(void)
105{
106}
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400107#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000108
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400109#if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000110void enable_caches(void)
111{
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400112#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000113 icache_enable();
114#endif
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400115#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000116 dcache_enable();
117#endif
118}
119#endif