Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 2 | /* |
3 | * Copyright (C) 2017 Andes Technology Corporation | ||||
4 | * Rick Chen, Andes Technology Corporation <rick@andestech.com> | ||||
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 5 | */ |
6 | |||||
7 | #include <common.h> | ||||
8 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 9 | void invalidate_icache_all(void) |
10 | { | ||||
11 | asm volatile ("fence.i" ::: "memory"); | ||||
12 | } | ||||
13 | |||||
14 | void flush_dcache_all(void) | ||||
15 | { | ||||
16 | asm volatile ("fence" :::"memory"); | ||||
17 | } | ||||
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 18 | void flush_dcache_range(unsigned long start, unsigned long end) |
19 | { | ||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 20 | flush_dcache_all(); |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 21 | } |
22 | |||||
23 | void invalidate_icache_range(unsigned long start, unsigned long end) | ||||
24 | { | ||||
Lukas Auer | 7656228 | 2018-11-22 11:26:23 +0100 | [diff] [blame] | 25 | /* |
26 | * RISC-V does not have an instruction for invalidating parts of the | ||||
27 | * instruction cache. Invalidate all of it instead. | ||||
28 | */ | ||||
29 | invalidate_icache_all(); | ||||
30 | } | ||||
31 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 32 | void invalidate_dcache_range(unsigned long start, unsigned long end) |
Lukas Auer | 7656228 | 2018-11-22 11:26:23 +0100 | [diff] [blame] | 33 | { |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 34 | flush_dcache_all(); |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 35 | } |
36 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 37 | void cache_flush(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 38 | { |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 39 | invalidate_icache_all(); |
40 | flush_dcache_all(); | ||||
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 41 | } |
42 | |||||
43 | void flush_cache(unsigned long addr, unsigned long size) | ||||
44 | { | ||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 45 | invalidate_icache_all(); |
46 | flush_dcache_all(); | ||||
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 47 | } |
48 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 49 | __weak void icache_enable(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 50 | { |
51 | } | ||||
52 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 53 | __weak void icache_disable(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 54 | { |
55 | } | ||||
56 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 57 | __weak int icache_status(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 58 | { |
59 | return 0; | ||||
60 | } | ||||
61 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 62 | __weak void dcache_enable(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 63 | { |
64 | } | ||||
65 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 66 | __weak void dcache_disable(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 67 | { |
68 | } | ||||
69 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 70 | __weak int dcache_status(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 71 | { |
72 | return 0; | ||||
73 | } |