blob: 2119382ab2451583a0399672e0bf914389d8743c [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 +000011
12#ifndef CONFIG_SYS_CACHELINE_SIZE
13#define CONFIG_SYS_CACHELINE_SIZE 32
14#endif
15
16void invalidate_dcache_all(void)
Ilya Yanokc8500692011-11-28 06:37:32 +000017{
Marek Vasut8ed61312012-04-06 03:25:07 +000018 asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
Ilya Yanokc8500692011-11-28 06:37:32 +000019}
20
Marek Vasutfc928512012-03-15 18:33:17 +000021void flush_dcache_all(void)
Ilya Yanokc8500692011-11-28 06:37:32 +000022{
Marek Vasutfc928512012-03-15 18:33:17 +000023 asm volatile(
24 "0:"
25 "mrc p15, 0, r15, c7, c14, 3\n"
26 "bne 0b\n"
27 "mcr p15, 0, %0, c7, c10, 4\n"
Marek Vasut8ed61312012-04-06 03:25:07 +000028 : : "r"(0) : "memory"
Marek Vasutfc928512012-03-15 18:33:17 +000029 );
Ilya Yanokc8500692011-11-28 06:37:32 +000030}
31
Ilya Yanokc8500692011-11-28 06:37:32 +000032void invalidate_dcache_range(unsigned long start, unsigned long stop)
33{
Marek Vasutfc928512012-03-15 18:33:17 +000034 if (!check_cache_range(start, stop))
35 return;
36
37 while (start < stop) {
Marek Vasut8ed61312012-04-06 03:25:07 +000038 asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
Marek Vasutfc928512012-03-15 18:33:17 +000039 start += CONFIG_SYS_CACHELINE_SIZE;
40 }
Ilya Yanokc8500692011-11-28 06:37:32 +000041}
42
43void flush_dcache_range(unsigned long start, unsigned long stop)
44{
Marek Vasutfc928512012-03-15 18:33:17 +000045 if (!check_cache_range(start, stop))
46 return;
47
48 while (start < stop) {
Marek Vasut8ed61312012-04-06 03:25:07 +000049 asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start));
Marek Vasutfc928512012-03-15 18:33:17 +000050 start += CONFIG_SYS_CACHELINE_SIZE;
51 }
52
Marek Vasut8ed61312012-04-06 03:25:07 +000053 asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0));
Marek Vasutfc928512012-03-15 18:33:17 +000054}
Ilya Yanokc8500692011-11-28 06:37:32 +000055#else /* #ifndef CONFIG_SYS_DCACHE_OFF */
56void invalidate_dcache_all(void)
57{
58}
59
60void flush_dcache_all(void)
61{
62}
Ilya Yanokc8500692011-11-28 06:37:32 +000063#endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
Michael Walle5ae3eec2012-02-06 22:42:10 +053064
65/*
66 * Stub implementations for l2 cache operations
67 */
Albert ARIBAUDa3823222015-10-23 18:06:40 +020068
Jeroen Hofstee2f65bef2014-10-27 20:10:06 +010069__weak void l2_cache_disable(void) {}
Albert ARIBAUDa3823222015-10-23 18:06:40 +020070
71#if defined CONFIG_SYS_THUMB_BUILD
72__weak void invalidate_l2_cache(void) {}
73#endif