blob: 7b7eaaf31df8e231059cdabd6ac58ec427c676d6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ilya Yanokc8500692011-11-28 06:37:32 +00002/*
3 * (C) Copyright 2011
4 * Ilya Yanok, EmCraft Systems
Ilya Yanokc8500692011-11-28 06:37:32 +00005 */
Simon Glass1d91ba72019-11-14 12:57:37 -07006#include <cpu_func.h>
Ilya Yanokc8500692011-11-28 06:37:32 +00007#include <linux/types.h>
8#include <common.h>
9
Trevor Woerner43ec7e02019-05-03 09:41:00 -040010#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Marek Vasutfc928512012-03-15 18:33:17 +000011void invalidate_dcache_all(void)
Ilya Yanokc8500692011-11-28 06:37:32 +000012{
Marek Vasut8ed61312012-04-06 03:25:07 +000013 asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
Ilya Yanokc8500692011-11-28 06:37:32 +000014}
15
Marek Vasutfc928512012-03-15 18:33:17 +000016void flush_dcache_all(void)
Ilya Yanokc8500692011-11-28 06:37:32 +000017{
Marek Vasutfc928512012-03-15 18:33:17 +000018 asm volatile(
19 "0:"
20 "mrc p15, 0, r15, c7, c14, 3\n"
21 "bne 0b\n"
22 "mcr p15, 0, %0, c7, c10, 4\n"
Marek Vasut8ed61312012-04-06 03:25:07 +000023 : : "r"(0) : "memory"
Marek Vasutfc928512012-03-15 18:33:17 +000024 );
Ilya Yanokc8500692011-11-28 06:37:32 +000025}
26
Ilya Yanokc8500692011-11-28 06:37:32 +000027void invalidate_dcache_range(unsigned long start, unsigned long stop)
28{
Marek Vasutfc928512012-03-15 18:33:17 +000029 if (!check_cache_range(start, stop))
30 return;
31
32 while (start < stop) {
Marek Vasut8ed61312012-04-06 03:25:07 +000033 asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
Marek Vasutfc928512012-03-15 18:33:17 +000034 start += CONFIG_SYS_CACHELINE_SIZE;
35 }
Ilya Yanokc8500692011-11-28 06:37:32 +000036}
37
38void flush_dcache_range(unsigned long start, unsigned long stop)
39{
Marek Vasutfc928512012-03-15 18:33:17 +000040 if (!check_cache_range(start, stop))
41 return;
42
43 while (start < stop) {
Marek Vasut8ed61312012-04-06 03:25:07 +000044 asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start));
Marek Vasutfc928512012-03-15 18:33:17 +000045 start += CONFIG_SYS_CACHELINE_SIZE;
46 }
47
Marek Vasut8ed61312012-04-06 03:25:07 +000048 asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0));
Marek Vasutfc928512012-03-15 18:33:17 +000049}
Trevor Woerner43ec7e02019-05-03 09:41:00 -040050#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Ilya Yanokc8500692011-11-28 06:37:32 +000051void invalidate_dcache_all(void)
52{
53}
54
55void flush_dcache_all(void)
56{
57}
Trevor Woerner43ec7e02019-05-03 09:41:00 -040058#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Michael Walle5ae3eec2012-02-06 22:42:10 +053059
60/*
61 * Stub implementations for l2 cache operations
62 */
Albert ARIBAUDa3823222015-10-23 18:06:40 +020063
Jeroen Hofstee2f65bef2014-10-27 20:10:06 +010064__weak void l2_cache_disable(void) {}
Albert ARIBAUDa3823222015-10-23 18:06:40 +020065
Tom Rini1c640a62017-03-18 09:01:44 -040066#if CONFIG_IS_ENABLED(SYS_THUMB_BUILD)
Albert ARIBAUDa3823222015-10-23 18:06:40 +020067__weak void invalidate_l2_cache(void) {}
68#endif
Adam Ford554d8792018-08-16 13:23:11 -050069
Trevor Woerner43ec7e02019-05-03 09:41:00 -040070#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Adam Ford554d8792018-08-16 13:23:11 -050071/* Invalidate entire I-cache and branch predictor array */
72void invalidate_icache_all(void)
73{
74 unsigned long i = 0;
75
76 asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
77}
78#else
79void invalidate_icache_all(void) {}
80#endif
81
82void enable_caches(void)
83{
Trevor Woerner43ec7e02019-05-03 09:41:00 -040084#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Adam Ford554d8792018-08-16 13:23:11 -050085 icache_enable();
86#endif
Trevor Woerner43ec7e02019-05-03 09:41:00 -040087#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Adam Ford554d8792018-08-16 13:23:11 -050088 dcache_enable();
89#endif
90}
91