blob: 16eea693d12e8cc41b69ec52036b0dc0d981ad1d [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 */
6#include <linux/types.h>
7#include <common.h>
8
Trevor Woerner43ec7e02019-05-03 09:41:00 -04009#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Marek Vasutfc928512012-03-15 18:33:17 +000010void invalidate_dcache_all(void)
Ilya Yanokc8500692011-11-28 06:37:32 +000011{
Marek Vasut8ed61312012-04-06 03:25:07 +000012 asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
Ilya Yanokc8500692011-11-28 06:37:32 +000013}
14
Marek Vasutfc928512012-03-15 18:33:17 +000015void flush_dcache_all(void)
Ilya Yanokc8500692011-11-28 06:37:32 +000016{
Marek Vasutfc928512012-03-15 18:33:17 +000017 asm volatile(
18 "0:"
19 "mrc p15, 0, r15, c7, c14, 3\n"
20 "bne 0b\n"
21 "mcr p15, 0, %0, c7, c10, 4\n"
Marek Vasut8ed61312012-04-06 03:25:07 +000022 : : "r"(0) : "memory"
Marek Vasutfc928512012-03-15 18:33:17 +000023 );
Ilya Yanokc8500692011-11-28 06:37:32 +000024}
25
Ilya Yanokc8500692011-11-28 06:37:32 +000026void invalidate_dcache_range(unsigned long start, unsigned long stop)
27{
Marek Vasutfc928512012-03-15 18:33:17 +000028 if (!check_cache_range(start, stop))
29 return;
30
31 while (start < stop) {
Marek Vasut8ed61312012-04-06 03:25:07 +000032 asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
Marek Vasutfc928512012-03-15 18:33:17 +000033 start += CONFIG_SYS_CACHELINE_SIZE;
34 }
Ilya Yanokc8500692011-11-28 06:37:32 +000035}
36
37void flush_dcache_range(unsigned long start, unsigned long stop)
38{
Marek Vasutfc928512012-03-15 18:33:17 +000039 if (!check_cache_range(start, stop))
40 return;
41
42 while (start < stop) {
Marek Vasut8ed61312012-04-06 03:25:07 +000043 asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start));
Marek Vasutfc928512012-03-15 18:33:17 +000044 start += CONFIG_SYS_CACHELINE_SIZE;
45 }
46
Marek Vasut8ed61312012-04-06 03:25:07 +000047 asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0));
Marek Vasutfc928512012-03-15 18:33:17 +000048}
Trevor Woerner43ec7e02019-05-03 09:41:00 -040049#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Ilya Yanokc8500692011-11-28 06:37:32 +000050void invalidate_dcache_all(void)
51{
52}
53
54void flush_dcache_all(void)
55{
56}
Trevor Woerner43ec7e02019-05-03 09:41:00 -040057#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Michael Walle5ae3eec2012-02-06 22:42:10 +053058
59/*
60 * Stub implementations for l2 cache operations
61 */
Albert ARIBAUDa3823222015-10-23 18:06:40 +020062
Jeroen Hofstee2f65bef2014-10-27 20:10:06 +010063__weak void l2_cache_disable(void) {}
Albert ARIBAUDa3823222015-10-23 18:06:40 +020064
Tom Rini1c640a62017-03-18 09:01:44 -040065#if CONFIG_IS_ENABLED(SYS_THUMB_BUILD)
Albert ARIBAUDa3823222015-10-23 18:06:40 +020066__weak void invalidate_l2_cache(void) {}
67#endif
Adam Ford554d8792018-08-16 13:23:11 -050068
Trevor Woerner43ec7e02019-05-03 09:41:00 -040069#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Adam Ford554d8792018-08-16 13:23:11 -050070/* Invalidate entire I-cache and branch predictor array */
71void invalidate_icache_all(void)
72{
73 unsigned long i = 0;
74
75 asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
76}
77#else
78void invalidate_icache_all(void) {}
79#endif
80
81void enable_caches(void)
82{
Trevor Woerner43ec7e02019-05-03 09:41:00 -040083#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Adam Ford554d8792018-08-16 13:23:11 -050084 icache_enable();
85#endif
Trevor Woerner43ec7e02019-05-03 09:41:00 -040086#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Adam Ford554d8792018-08-16 13:23:11 -050087 dcache_enable();
88#endif
89}
90