blob: 8aee1539a9db8b7d2a6b6b76af02e603e096f84f [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>
Jean-Christophe PLAGNIOL-VILLARD9053b5a2009-04-05 13:02:43 +020019#include <asm/system.h>
wdenkf8062712005-01-09 23:16:25 +000020
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020021static void cache_flush(void);
wdenkf8062712005-01-09 23:16:25 +000022
wdenkf8062712005-01-09 23:16:25 +000023int cleanup_before_linux (void)
24{
25 /*
26 * this function is called just before we call linux
27 * it prepares the processor for linux
28 *
29 * we turn off caches etc ...
30 */
31
wdenkf8062712005-01-09 23:16:25 +000032 disable_interrupts ();
33
wdenkf8062712005-01-09 23:16:25 +000034 /* turn off I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020035 icache_disable();
36 dcache_disable();
wdenkf8062712005-01-09 23:16:25 +000037 /* flush I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020038 cache_flush();
39
40 return 0;
wdenkf8062712005-01-09 23:16:25 +000041}
42
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020043static void cache_flush(void)
wdenkf8062712005-01-09 23:16:25 +000044{
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020045 unsigned long i = 0;
Stefano Babic9e397932012-04-09 13:33:04 +020046 /* clean entire data cache */
47 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i));
48 /* invalidate both caches and flush btb */
49 asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i));
50 /* mem barrier to sync things */
51 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i));
wdenkf8062712005-01-09 23:16:25 +000052}
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000053
Trevor Woerner43ec7e02019-05-03 09:41:00 -040054#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000055void invalidate_dcache_all(void)
56{
Stefano Babic9e397932012-04-09 13:33:04 +020057 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000058}
59
60void flush_dcache_all(void)
61{
Stefano Babic9e397932012-04-09 13:33:04 +020062 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
63 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000064}
65
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000066void invalidate_dcache_range(unsigned long start, unsigned long stop)
67{
Benoît Thébaudeau1053bd22012-07-19 01:35:32 +000068 if (!check_cache_range(start, stop))
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000069 return;
70
71 while (start < stop) {
Stefano Babic9e397932012-04-09 13:33:04 +020072 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000073 start += CONFIG_SYS_CACHELINE_SIZE;
74 }
75}
76
77void flush_dcache_range(unsigned long start, unsigned long stop)
78{
Benoît Thébaudeau1053bd22012-07-19 01:35:32 +000079 if (!check_cache_range(start, stop))
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000080 return;
81
82 while (start < stop) {
Stefano Babic9e397932012-04-09 13:33:04 +020083 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000084 start += CONFIG_SYS_CACHELINE_SIZE;
85 }
86
Stefano Babic9e397932012-04-09 13:33:04 +020087 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000088}
89
Trevor Woerner43ec7e02019-05-03 09:41:00 -040090#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000091void invalidate_dcache_all(void)
92{
93}
94
95void flush_dcache_all(void)
96{
97}
Trevor Woerner43ec7e02019-05-03 09:41:00 -040098#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +000099
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400100#if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000101void enable_caches(void)
102{
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400103#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000104 icache_enable();
105#endif
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400106#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000107 dcache_enable();
108#endif
109}
110#endif