blob: d56e594af2952f18e62d7b10d89ef4e00c92c2a1 [file] [log] [blame]
Ilya Yanokc8500692011-11-28 06:37:32 +00001/*
2 * (C) Copyright 2011
3 * Ilya Yanok, EmCraft Systems
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Ilya Yanokc8500692011-11-28 06:37:32 +00006 */
7#include <linux/types.h>
8#include <common.h>
9
10#ifndef CONFIG_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}
Ilya Yanokc8500692011-11-28 06:37:32 +000050#else /* #ifndef CONFIG_SYS_DCACHE_OFF */
51void invalidate_dcache_all(void)
52{
53}
54
55void flush_dcache_all(void)
56{
57}
Ilya Yanokc8500692011-11-28 06:37:32 +000058#endif /* #ifndef CONFIG_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