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> |
Vasily Khoruzhick | 9cfc059 | 2016-03-20 18:37:07 -0700 | [diff] [blame] | 7 | #include <linux/types.h> |
| 8 | #include <common.h> |
| 9 | |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 10 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Vasily Khoruzhick | 9cfc059 | 2016-03-20 18:37:07 -0700 | [diff] [blame] | 11 | void invalidate_dcache_all(void) |
| 12 | { |
| 13 | /* Flush/Invalidate I cache */ |
| 14 | asm volatile("mcr p15, 0, %0, c7, c5, 0\n" : : "r"(0)); |
| 15 | /* Flush/Invalidate D cache */ |
| 16 | asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0)); |
| 17 | } |
| 18 | |
| 19 | void flush_dcache_all(void) |
| 20 | { |
| 21 | return invalidate_dcache_all(); |
| 22 | } |
| 23 | |
| 24 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 25 | { |
| 26 | start &= ~(CONFIG_SYS_CACHELINE_SIZE - 1); |
| 27 | stop &= ~(CONFIG_SYS_CACHELINE_SIZE - 1); |
| 28 | |
| 29 | while (start <= stop) { |
| 30 | asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start)); |
| 31 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | void flush_dcache_range(unsigned long start, unsigned long stop) |
| 36 | { |
| 37 | return invalidate_dcache_range(start, stop); |
| 38 | } |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 39 | #else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ |
Vasily Khoruzhick | 9cfc059 | 2016-03-20 18:37:07 -0700 | [diff] [blame] | 40 | void invalidate_dcache_all(void) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | void flush_dcache_all(void) |
| 45 | { |
| 46 | } |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 47 | #endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ |
Vasily Khoruzhick | 9cfc059 | 2016-03-20 18:37:07 -0700 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * Stub implementations for l2 cache operations |
| 51 | */ |
| 52 | |
| 53 | __weak void l2_cache_disable(void) {} |
| 54 | |
Tom Rini | 3a64940 | 2017-03-18 09:01:44 -0400 | [diff] [blame] | 55 | #if CONFIG_IS_ENABLED(SYS_THUMB_BUILD) |
Vasily Khoruzhick | 9cfc059 | 2016-03-20 18:37:07 -0700 | [diff] [blame] | 56 | __weak void invalidate_l2_cache(void) {} |
| 57 | #endif |