blob: 177d1f40b93f96efc729238873c939264babfd08 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk8ed96042005-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 Zundel792a09e2009-05-13 10:54:10 +020010 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
wdenk8ed96042005-01-09 23:16:25 +000011 */
12
13/*
14 * CPU specific code
15 */
16
17#include <common.h>
18#include <command.h>
Simon Glass9edefc22019-11-14 12:57:37 -070019#include <cpu_func.h>
Simon Glass36bf4462019-11-14 12:57:42 -070020#include <irq_func.h>
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +020021#include <asm/system.h>
wdenk8ed96042005-01-09 23:16:25 +000022
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020023static void cache_flush(void);
wdenk8ed96042005-01-09 23:16:25 +000024
wdenk8ed96042005-01-09 23:16:25 +000025int cleanup_before_linux (void)
26{
27 /*
28 * this function is called just before we call linux
29 * it prepares the processor for linux
30 *
31 * we turn off caches etc ...
32 */
33
Simon Glass9d3915b2019-11-14 12:57:40 -070034 disable_interrupts();
wdenk8ed96042005-01-09 23:16:25 +000035
wdenk8ed96042005-01-09 23:16:25 +000036 /* turn off I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020037 icache_disable();
38 dcache_disable();
wdenk8ed96042005-01-09 23:16:25 +000039 /* flush I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020040 cache_flush();
41
42 return 0;
wdenk8ed96042005-01-09 23:16:25 +000043}
44
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020045static void cache_flush(void)
wdenk8ed96042005-01-09 23:16:25 +000046{
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020047 unsigned long i = 0;
Stefano Babicfbf4a072012-04-09 13:33:04 +020048 /* clean entire data cache */
49 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i));
50 /* invalidate both caches and flush btb */
51 asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i));
52 /* mem barrier to sync things */
53 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i));
wdenk8ed96042005-01-09 23:16:25 +000054}
Anatolij Gustschin219872c2012-04-02 06:18:00 +000055
Trevor Woerner10015022019-05-03 09:41:00 -040056#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Anatolij Gustschin219872c2012-04-02 06:18:00 +000057void invalidate_dcache_all(void)
58{
Stefano Babicfbf4a072012-04-09 13:33:04 +020059 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000060}
61
62void flush_dcache_all(void)
63{
Stefano Babicfbf4a072012-04-09 13:33:04 +020064 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
65 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000066}
67
Anatolij Gustschin219872c2012-04-02 06:18:00 +000068void invalidate_dcache_range(unsigned long start, unsigned long stop)
69{
Benoît Thébaudeauf8f09dd2012-07-19 01:35:32 +000070 if (!check_cache_range(start, stop))
Anatolij Gustschin219872c2012-04-02 06:18:00 +000071 return;
72
73 while (start < stop) {
Stefano Babicfbf4a072012-04-09 13:33:04 +020074 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000075 start += CONFIG_SYS_CACHELINE_SIZE;
76 }
77}
78
79void flush_dcache_range(unsigned long start, unsigned long stop)
80{
Benoît Thébaudeauf8f09dd2012-07-19 01:35:32 +000081 if (!check_cache_range(start, stop))
Anatolij Gustschin219872c2012-04-02 06:18:00 +000082 return;
83
84 while (start < stop) {
Stefano Babicfbf4a072012-04-09 13:33:04 +020085 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000086 start += CONFIG_SYS_CACHELINE_SIZE;
87 }
88
Stefano Babicfbf4a072012-04-09 13:33:04 +020089 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin219872c2012-04-02 06:18:00 +000090}
91
Trevor Woerner10015022019-05-03 09:41:00 -040092#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Anatolij Gustschin219872c2012-04-02 06:18:00 +000093void invalidate_dcache_all(void)
94{
95}
96
97void flush_dcache_all(void)
98{
99}
Trevor Woerner10015022019-05-03 09:41:00 -0400100#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Benoît Thébaudeauccfa3982012-10-04 10:04:02 +0000101
Trevor Woerner10015022019-05-03 09:41:00 -0400102#if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Benoît Thébaudeauccfa3982012-10-04 10:04:02 +0000103void enable_caches(void)
104{
Trevor Woerner10015022019-05-03 09:41:00 -0400105#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Benoît Thébaudeauccfa3982012-10-04 10:04:02 +0000106 icache_enable();
107#endif
Trevor Woerner10015022019-05-03 09:41:00 -0400108#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Benoît Thébaudeauccfa3982012-10-04 10:04:02 +0000109 dcache_enable();
110#endif
111}
112#endif