blob: a2ec5e28c7dcef6236258f547909ced3eeb1eedf [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vasily Khoruzhick9cfc0592016-03-20 18:37:07 -07002/*
3 * (C) Copyright 2016 Vasily Khoruzhick <anarsoul@gmail.com>
Vasily Khoruzhick9cfc0592016-03-20 18:37:07 -07004 */
5
Simon Glass1eb69ae2019-11-14 12:57:39 -07006#include <cpu_func.h>
Simon Glass90526e92020-05-10 11:39:56 -06007#include <asm/cache.h>
Vasily Khoruzhick9cfc0592016-03-20 18:37:07 -07008#include <linux/types.h>
9#include <common.h>
10
Trevor Woerner10015022019-05-03 09:41:00 -040011#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Vasily Khoruzhick9cfc0592016-03-20 18:37:07 -070012void invalidate_dcache_all(void)
13{
14 /* Flush/Invalidate I cache */
15 asm volatile("mcr p15, 0, %0, c7, c5, 0\n" : : "r"(0));
16 /* Flush/Invalidate D cache */
17 asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
18}
19
20void flush_dcache_all(void)
21{
22 return invalidate_dcache_all();
23}
24
25void invalidate_dcache_range(unsigned long start, unsigned long stop)
26{
27 start &= ~(CONFIG_SYS_CACHELINE_SIZE - 1);
28 stop &= ~(CONFIG_SYS_CACHELINE_SIZE - 1);
29
30 while (start <= stop) {
31 asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
32 start += CONFIG_SYS_CACHELINE_SIZE;
33 }
34}
35
36void flush_dcache_range(unsigned long start, unsigned long stop)
37{
38 return invalidate_dcache_range(start, stop);
39}
Trevor Woerner10015022019-05-03 09:41:00 -040040#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Vasily Khoruzhick9cfc0592016-03-20 18:37:07 -070041void invalidate_dcache_all(void)
42{
43}
44
45void flush_dcache_all(void)
46{
47}
Trevor Woerner10015022019-05-03 09:41:00 -040048#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Vasily Khoruzhick9cfc0592016-03-20 18:37:07 -070049
50/*
51 * Stub implementations for l2 cache operations
52 */
53
54__weak void l2_cache_disable(void) {}
55
Tom Rini3a649402017-03-18 09:01:44 -040056#if CONFIG_IS_ENABLED(SYS_THUMB_BUILD)
Vasily Khoruzhick9cfc0592016-03-20 18:37:07 -070057__weak void invalidate_l2_cache(void) {}
58#endif