blob: 674ad0715b51159fe2cc3df684f36c49d65898ec [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>
Simon Glass1d91ba72019-11-14 12:57:37 -070019#include <cpu_func.h>
Jean-Christophe PLAGNIOL-VILLARD9053b5a2009-04-05 13:02:43 +020020#include <asm/system.h>
wdenkf8062712005-01-09 23:16:25 +000021
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020022static void cache_flush(void);
wdenkf8062712005-01-09 23:16:25 +000023
wdenkf8062712005-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
Simon Glassf87959b2019-11-14 12:57:40 -070033 disable_interrupts();
wdenkf8062712005-01-09 23:16:25 +000034
wdenkf8062712005-01-09 23:16:25 +000035 /* turn off I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020036 icache_disable();
37 dcache_disable();
wdenkf8062712005-01-09 23:16:25 +000038 /* flush I/D-cache */
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020039 cache_flush();
40
41 return 0;
wdenkf8062712005-01-09 23:16:25 +000042}
43
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020044static void cache_flush(void)
wdenkf8062712005-01-09 23:16:25 +000045{
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020046 unsigned long i = 0;
Stefano Babic9e397932012-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));
wdenkf8062712005-01-09 23:16:25 +000053}
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000054
Trevor Woerner43ec7e02019-05-03 09:41:00 -040055#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000056void invalidate_dcache_all(void)
57{
Stefano Babic9e397932012-04-09 13:33:04 +020058 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000059}
60
61void flush_dcache_all(void)
62{
Stefano Babic9e397932012-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 Gustschin02966ca2012-04-02 06:18:00 +000065}
66
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000067void invalidate_dcache_range(unsigned long start, unsigned long stop)
68{
Benoît Thébaudeau1053bd22012-07-19 01:35:32 +000069 if (!check_cache_range(start, stop))
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000070 return;
71
72 while (start < stop) {
Stefano Babic9e397932012-04-09 13:33:04 +020073 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
Anatolij Gustschin02966ca2012-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ébaudeau1053bd22012-07-19 01:35:32 +000080 if (!check_cache_range(start, stop))
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000081 return;
82
83 while (start < stop) {
Stefano Babic9e397932012-04-09 13:33:04 +020084 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000085 start += CONFIG_SYS_CACHELINE_SIZE;
86 }
87
Stefano Babic9e397932012-04-09 13:33:04 +020088 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000089}
90
Trevor Woerner43ec7e02019-05-03 09:41:00 -040091#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Anatolij Gustschin02966ca2012-04-02 06:18:00 +000092void invalidate_dcache_all(void)
93{
94}
95
96void flush_dcache_all(void)
97{
98}
Trevor Woerner43ec7e02019-05-03 09:41:00 -040099#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000100
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400101#if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000102void enable_caches(void)
103{
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400104#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000105 icache_enable();
106#endif
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400107#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Benoît Thébaudeaudbbd8452012-10-04 10:04:02 +0000108 dcache_enable();
109#endif
110}
111#endif