blob: acab9bccc01ad44e8e5150790ff3a7f38af54054 [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>
Simon Glass274e0b02020-05-10 11:39:56 -06007#include <asm/cache.h>
Ilya Yanokc8500692011-11-28 06:37:32 +00008#include <linux/types.h>
9#include <common.h>
10
Trevor Woerner43ec7e02019-05-03 09:41:00 -040011#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Marek Vasutfc928512012-03-15 18:33:17 +000012void invalidate_dcache_all(void)
Ilya Yanokc8500692011-11-28 06:37:32 +000013{
Marek Vasut8ed61312012-04-06 03:25:07 +000014 asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
Ilya Yanokc8500692011-11-28 06:37:32 +000015}
16
Marek Vasutfc928512012-03-15 18:33:17 +000017void flush_dcache_all(void)
Ilya Yanokc8500692011-11-28 06:37:32 +000018{
Marek Vasutfc928512012-03-15 18:33:17 +000019 asm volatile(
20 "0:"
21 "mrc p15, 0, r15, c7, c14, 3\n"
22 "bne 0b\n"
23 "mcr p15, 0, %0, c7, c10, 4\n"
Marek Vasut8ed61312012-04-06 03:25:07 +000024 : : "r"(0) : "memory"
Marek Vasutfc928512012-03-15 18:33:17 +000025 );
Ilya Yanokc8500692011-11-28 06:37:32 +000026}
27
Ilya Yanokc8500692011-11-28 06:37:32 +000028void invalidate_dcache_range(unsigned long start, unsigned long stop)
29{
Marek Vasutfc928512012-03-15 18:33:17 +000030 if (!check_cache_range(start, stop))
31 return;
32
33 while (start < stop) {
Marek Vasut8ed61312012-04-06 03:25:07 +000034 asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
Marek Vasutfc928512012-03-15 18:33:17 +000035 start += CONFIG_SYS_CACHELINE_SIZE;
36 }
Ilya Yanokc8500692011-11-28 06:37:32 +000037}
38
39void flush_dcache_range(unsigned long start, unsigned long stop)
40{
Marek Vasutfc928512012-03-15 18:33:17 +000041 if (!check_cache_range(start, stop))
42 return;
43
44 while (start < stop) {
Marek Vasut8ed61312012-04-06 03:25:07 +000045 asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start));
Marek Vasutfc928512012-03-15 18:33:17 +000046 start += CONFIG_SYS_CACHELINE_SIZE;
47 }
48
Marek Vasut8ed61312012-04-06 03:25:07 +000049 asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0));
Marek Vasutfc928512012-03-15 18:33:17 +000050}
Trevor Woerner43ec7e02019-05-03 09:41:00 -040051#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Ilya Yanokc8500692011-11-28 06:37:32 +000052void invalidate_dcache_all(void)
53{
54}
55
56void flush_dcache_all(void)
57{
58}
Trevor Woerner43ec7e02019-05-03 09:41:00 -040059#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Michael Walle5ae3eec2012-02-06 22:42:10 +053060
61/*
62 * Stub implementations for l2 cache operations
63 */
Albert ARIBAUDa3823222015-10-23 18:06:40 +020064
Jeroen Hofstee2f65bef2014-10-27 20:10:06 +010065__weak void l2_cache_disable(void) {}
Albert ARIBAUDa3823222015-10-23 18:06:40 +020066
Tom Rini1c640a62017-03-18 09:01:44 -040067#if CONFIG_IS_ENABLED(SYS_THUMB_BUILD)
Albert ARIBAUDa3823222015-10-23 18:06:40 +020068__weak void invalidate_l2_cache(void) {}
69#endif
Adam Ford554d8792018-08-16 13:23:11 -050070
Trevor Woerner43ec7e02019-05-03 09:41:00 -040071#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Adam Ford554d8792018-08-16 13:23:11 -050072/* Invalidate entire I-cache and branch predictor array */
73void invalidate_icache_all(void)
74{
75 unsigned long i = 0;
76
77 asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
78}
79#else
80void invalidate_icache_all(void) {}
81#endif
82
83void enable_caches(void)
84{
Trevor Woerner43ec7e02019-05-03 09:41:00 -040085#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Adam Ford554d8792018-08-16 13:23:11 -050086 icache_enable();
87#endif
Trevor Woerner43ec7e02019-05-03 09:41:00 -040088#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Adam Ford554d8792018-08-16 13:23:11 -050089 dcache_enable();
90#endif
91}
92