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 | |||||
Lukas Auer | 6280e32 | 2019-01-04 01:37:29 +0100 | [diff] [blame] | 14 | __weak void flush_dcache_all(void) |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 15 | { |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 16 | } |
Lukas Auer | 6280e32 | 2019-01-04 01:37:29 +0100 | [diff] [blame] | 17 | |
18 | __weak void flush_dcache_range(unsigned long start, unsigned long end) | ||||
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 19 | { |
20 | } | ||||
21 | |||||
22 | void invalidate_icache_range(unsigned long start, unsigned long end) | ||||
23 | { | ||||
Lukas Auer | 7656228 | 2018-11-22 11:26:23 +0100 | [diff] [blame] | 24 | /* |
25 | * RISC-V does not have an instruction for invalidating parts of the | ||||
26 | * instruction cache. Invalidate all of it instead. | ||||
27 | */ | ||||
28 | invalidate_icache_all(); | ||||
29 | } | ||||
30 | |||||
Lukas Auer | 6280e32 | 2019-01-04 01:37:29 +0100 | [diff] [blame] | 31 | __weak void invalidate_dcache_range(unsigned long start, unsigned long end) |
Lukas Auer | 7656228 | 2018-11-22 11:26:23 +0100 | [diff] [blame] | 32 | { |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 33 | } |
34 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 35 | void cache_flush(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 36 | { |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 37 | invalidate_icache_all(); |
38 | flush_dcache_all(); | ||||
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 39 | } |
40 | |||||
41 | void flush_cache(unsigned long addr, unsigned long size) | ||||
42 | { | ||||
Lukas Auer | 09dfc3c | 2019-01-04 01:37:30 +0100 | [diff] [blame] | 43 | invalidate_icache_range(addr, addr + size); |
44 | flush_dcache_range(addr, addr + size); | ||||
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 45 | } |
46 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 47 | __weak void icache_enable(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 48 | { |
49 | } | ||||
50 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 51 | __weak void icache_disable(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 52 | { |
53 | } | ||||
54 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 55 | __weak int icache_status(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 56 | { |
57 | return 0; | ||||
58 | } | ||||
59 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 60 | __weak void dcache_enable(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 61 | { |
62 | } | ||||
63 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 64 | __weak void dcache_disable(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 65 | { |
66 | } | ||||
67 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 68 | __weak int dcache_status(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 69 | { |
70 | return 0; | ||||
71 | } |