Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vasily Khoruzhick | 9cfc059 | 2016-03-20 18:37:07 -0700 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 Vasily Khoruzhick <anarsoul@gmail.com> |
Vasily Khoruzhick | 9cfc059 | 2016-03-20 18:37:07 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 1eb69ae | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 6 | #include <cpu_func.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame^] | 7 | #include <asm/cache.h> |
Vasily Khoruzhick | 9cfc059 | 2016-03-20 18:37:07 -0700 | [diff] [blame] | 8 | #include <linux/types.h> |
| 9 | #include <common.h> |
| 10 | |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 11 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Vasily Khoruzhick | 9cfc059 | 2016-03-20 18:37:07 -0700 | [diff] [blame] | 12 | void 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 | |
| 20 | void flush_dcache_all(void) |
| 21 | { |
| 22 | return invalidate_dcache_all(); |
| 23 | } |
| 24 | |
| 25 | void 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 | |
| 36 | void flush_dcache_range(unsigned long start, unsigned long stop) |
| 37 | { |
| 38 | return invalidate_dcache_range(start, stop); |
| 39 | } |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 40 | #else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ |
Vasily Khoruzhick | 9cfc059 | 2016-03-20 18:37:07 -0700 | [diff] [blame] | 41 | void invalidate_dcache_all(void) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | void flush_dcache_all(void) |
| 46 | { |
| 47 | } |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 48 | #endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ |
Vasily Khoruzhick | 9cfc059 | 2016-03-20 18:37:07 -0700 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | * Stub implementations for l2 cache operations |
| 52 | */ |
| 53 | |
| 54 | __weak void l2_cache_disable(void) {} |
| 55 | |
Tom Rini | 3a64940 | 2017-03-18 09:01:44 -0400 | [diff] [blame] | 56 | #if CONFIG_IS_ENABLED(SYS_THUMB_BUILD) |
Vasily Khoruzhick | 9cfc059 | 2016-03-20 18:37:07 -0700 | [diff] [blame] | 57 | __weak void invalidate_l2_cache(void) {} |
| 58 | #endif |