blob: 41feeefec1606d0358856f84bc4c0edad10e9122 [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
54#ifndef CONFIG_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
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000090#else /* #ifndef CONFIG_SYS_DCACHE_OFF */
91void invalidate_dcache_all(void)
92{
93}
94
95void flush_dcache_all(void)
96{
97}
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000098#endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +000099
100#if !defined(CONFIG_SYS_ICACHE_OFF) || !defined(CONFIG_SYS_DCACHE_OFF)
101void enable_caches(void)
102{
103#ifndef CONFIG_SYS_ICACHE_OFF
104 icache_enable();
105#endif
106#ifndef CONFIG_SYS_DCACHE_OFF
107 dcache_enable();
108#endif
109}
110#endif