blob: a7aed4b2b70a720654d0180207e6a903a3e1ed74 [file] [log] [blame]
wdenk8ed96042005-01-09 23:16:25 +00001/*
2 * (C) Copyright 2004 Texas Insturments
3 *
4 * (C) Copyright 2002
5 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
6 * Marius Groeger <mgroeger@sysgo.de>
7 *
8 * (C) Copyright 2002
Detlev Zundel792a09e2009-05-13 10:54:10 +02009 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
wdenk8ed96042005-01-09 23:16:25 +000010 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020011 * SPDX-License-Identifier: GPL-2.0+
wdenk8ed96042005-01-09 23:16:25 +000012 */
13
14/*
15 * CPU specific code
16 */
17
18#include <common.h>
19#include <command.h>
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +020020#include <asm/system.h>
wdenk8ed96042005-01-09 23:16:25 +000021
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020022static void cache_flush(void);
wdenk8ed96042005-01-09 23:16:25 +000023
wdenk8ed96042005-01-09 23:16:25 +000024int cleanup_before_linux (void)
25{
26 /*
27 * this function is called just before we call linux
28 * it prepares the processor for linux
29 *
30 * we turn off caches etc ...
31 */
32
wdenk8ed96042005-01-09 23:16:25 +000033 disable_interrupts ();
34
35#ifdef CONFIG_LCD
36 {
37 extern void lcd_disable(void);
38 extern void lcd_panel_disable(void);
39
40 lcd_disable(); /* proper disable of lcd & panel */
41 lcd_panel_disable();
42 }
43#endif
44
45 /* turn off I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020046 icache_disable();
47 dcache_disable();
wdenk8ed96042005-01-09 23:16:25 +000048 /* flush I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020049 cache_flush();
50
51 return 0;
wdenk8ed96042005-01-09 23:16:25 +000052}
53
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020054static void cache_flush(void)
wdenk8ed96042005-01-09 23:16:25 +000055{
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020056 unsigned long i = 0;
Stefano Babicfbf4a072012-04-09 13:33:04 +020057 /* clean entire data cache */
58 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i));
59 /* invalidate both caches and flush btb */
60 asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i));
61 /* mem barrier to sync things */
62 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i));
wdenk8ed96042005-01-09 23:16:25 +000063}
Anatolij Gustschin219872c2012-04-02 06:18:00 +000064
65#ifndef CONFIG_SYS_DCACHE_OFF
66
67#ifndef CONFIG_SYS_CACHELINE_SIZE
68#define CONFIG_SYS_CACHELINE_SIZE 32
69#endif
70
71void invalidate_dcache_all(void)
72{
Stefano Babicfbf4a072012-04-09 13:33:04 +020073 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000074}
75
76void flush_dcache_all(void)
77{
Stefano Babicfbf4a072012-04-09 13:33:04 +020078 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
79 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000080}
81
Benoît Thébaudeauf8f09dd2012-07-19 01:35:32 +000082static int check_cache_range(unsigned long start, unsigned long stop)
Anatolij Gustschin219872c2012-04-02 06:18:00 +000083{
84 int ok = 1;
85
86 if (start & (CONFIG_SYS_CACHELINE_SIZE - 1))
87 ok = 0;
88
89 if (stop & (CONFIG_SYS_CACHELINE_SIZE - 1))
90 ok = 0;
91
92 if (!ok)
93 debug("CACHE: Misaligned operation at range [%08lx, %08lx]\n",
94 start, stop);
95
96 return ok;
97}
98
99void invalidate_dcache_range(unsigned long start, unsigned long stop)
100{
Benoît Thébaudeauf8f09dd2012-07-19 01:35:32 +0000101 if (!check_cache_range(start, stop))
Anatolij Gustschin219872c2012-04-02 06:18:00 +0000102 return;
103
104 while (start < stop) {
Stefano Babicfbf4a072012-04-09 13:33:04 +0200105 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
Anatolij Gustschin219872c2012-04-02 06:18:00 +0000106 start += CONFIG_SYS_CACHELINE_SIZE;
107 }
108}
109
110void flush_dcache_range(unsigned long start, unsigned long stop)
111{
Benoît Thébaudeauf8f09dd2012-07-19 01:35:32 +0000112 if (!check_cache_range(start, stop))
Anatolij Gustschin219872c2012-04-02 06:18:00 +0000113 return;
114
115 while (start < stop) {
Stefano Babicfbf4a072012-04-09 13:33:04 +0200116 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
Anatolij Gustschin219872c2012-04-02 06:18:00 +0000117 start += CONFIG_SYS_CACHELINE_SIZE;
118 }
119
Stefano Babicfbf4a072012-04-09 13:33:04 +0200120 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin219872c2012-04-02 06:18:00 +0000121}
122
123void flush_cache(unsigned long start, unsigned long size)
124{
125 flush_dcache_range(start, start + size);
126}
127
Anatolij Gustschin219872c2012-04-02 06:18:00 +0000128#else /* #ifndef CONFIG_SYS_DCACHE_OFF */
129void invalidate_dcache_all(void)
130{
131}
132
133void flush_dcache_all(void)
134{
135}
136
137void invalidate_dcache_range(unsigned long start, unsigned long stop)
138{
139}
140
141void flush_dcache_range(unsigned long start, unsigned long stop)
142{
143}
144
145void flush_cache(unsigned long start, unsigned long size)
146{
147}
148#endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
Benoît Thébaudeauccfa3982012-10-04 10:04:02 +0000149
150#if !defined(CONFIG_SYS_ICACHE_OFF) || !defined(CONFIG_SYS_DCACHE_OFF)
151void enable_caches(void)
152{
153#ifndef CONFIG_SYS_ICACHE_OFF
154 icache_enable();
155#endif
156#ifndef CONFIG_SYS_DCACHE_OFF
157 dcache_enable();
158#endif
159}
160#endif