blob: ef32c3f0abd4e92b0950f65ca986dd9cf5f06c39 [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
wdenk8ed96042005-01-09 23:16:25 +000035 /* turn off I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020036 icache_disable();
37 dcache_disable();
wdenk8ed96042005-01-09 23:16:25 +000038 /* flush I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020039 cache_flush();
40
41 return 0;
wdenk8ed96042005-01-09 23:16:25 +000042}
43
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020044static void cache_flush(void)
wdenk8ed96042005-01-09 23:16:25 +000045{
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020046 unsigned long i = 0;
Stefano Babicfbf4a072012-04-09 13:33:04 +020047 /* clean entire data cache */
48 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i));
49 /* invalidate both caches and flush btb */
50 asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i));
51 /* mem barrier to sync things */
52 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i));
wdenk8ed96042005-01-09 23:16:25 +000053}
Anatolij Gustschin219872c2012-04-02 06:18:00 +000054
55#ifndef CONFIG_SYS_DCACHE_OFF
Anatolij Gustschin219872c2012-04-02 06:18:00 +000056void invalidate_dcache_all(void)
57{
Stefano Babicfbf4a072012-04-09 13:33:04 +020058 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000059}
60
61void flush_dcache_all(void)
62{
Stefano Babicfbf4a072012-04-09 13:33:04 +020063 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
64 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000065}
66
Anatolij Gustschin219872c2012-04-02 06:18:00 +000067void invalidate_dcache_range(unsigned long start, unsigned long stop)
68{
Benoît Thébaudeauf8f09dd2012-07-19 01:35:32 +000069 if (!check_cache_range(start, stop))
Anatolij Gustschin219872c2012-04-02 06:18:00 +000070 return;
71
72 while (start < stop) {
Stefano Babicfbf4a072012-04-09 13:33:04 +020073 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000074 start += CONFIG_SYS_CACHELINE_SIZE;
75 }
76}
77
78void flush_dcache_range(unsigned long start, unsigned long stop)
79{
Benoît Thébaudeauf8f09dd2012-07-19 01:35:32 +000080 if (!check_cache_range(start, stop))
Anatolij Gustschin219872c2012-04-02 06:18:00 +000081 return;
82
83 while (start < stop) {
Stefano Babicfbf4a072012-04-09 13:33:04 +020084 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000085 start += CONFIG_SYS_CACHELINE_SIZE;
86 }
87
Stefano Babicfbf4a072012-04-09 13:33:04 +020088 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000089}
90
Anatolij Gustschin219872c2012-04-02 06:18:00 +000091#else /* #ifndef CONFIG_SYS_DCACHE_OFF */
92void invalidate_dcache_all(void)
93{
94}
95
96void flush_dcache_all(void)
97{
98}
Anatolij Gustschin219872c2012-04-02 06:18:00 +000099#endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
Benoît Thébaudeauccfa3982012-10-04 10:04:02 +0000100
101#if !defined(CONFIG_SYS_ICACHE_OFF) || !defined(CONFIG_SYS_DCACHE_OFF)
102void enable_caches(void)
103{
104#ifndef CONFIG_SYS_ICACHE_OFF
105 icache_enable();
106#endif
107#ifndef CONFIG_SYS_DCACHE_OFF
108 dcache_enable();
109#endif
110}
111#endif