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> | ||||
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 9 | |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 10 | void invalidate_icache_all(void) |
11 | { | ||||
12 | asm volatile ("fence.i" ::: "memory"); | ||||
13 | } | ||||
14 | |||||
Lukas Auer | 6280e32 | 2019-01-04 01:37:29 +0100 | [diff] [blame] | 15 | __weak void flush_dcache_all(void) |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 16 | { |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 17 | } |
Lukas Auer | 6280e32 | 2019-01-04 01:37:29 +0100 | [diff] [blame] | 18 | |
19 | __weak void flush_dcache_range(unsigned long start, unsigned long end) | ||||
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 20 | { |
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 | |||||
Lukas Auer | 6280e32 | 2019-01-04 01:37:29 +0100 | [diff] [blame] | 32 | __weak 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 | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 34 | } |
35 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 36 | void cache_flush(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 37 | { |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 38 | invalidate_icache_all(); |
39 | flush_dcache_all(); | ||||
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 40 | } |
41 | |||||
42 | void flush_cache(unsigned long addr, unsigned long size) | ||||
43 | { | ||||
Lukas Auer | 09dfc3c | 2019-01-04 01:37:30 +0100 | [diff] [blame] | 44 | invalidate_icache_range(addr, addr + size); |
45 | flush_dcache_range(addr, addr + size); | ||||
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 46 | } |
47 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 48 | __weak void icache_enable(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 49 | { |
50 | } | ||||
51 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 52 | __weak void icache_disable(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 53 | { |
54 | } | ||||
55 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 56 | __weak int icache_status(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 57 | { |
58 | return 0; | ||||
59 | } | ||||
60 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 61 | __weak void dcache_enable(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 62 | { |
63 | } | ||||
64 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 65 | __weak void dcache_disable(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 66 | { |
67 | } | ||||
68 | |||||
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 69 | __weak int dcache_status(void) |
Rick Chen | 6eedd92 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 70 | { |
71 | return 0; | ||||
72 | } | ||||
Zong Li | a33070c | 2021-09-01 15:01:40 +0800 | [diff] [blame] | 73 | |
74 | __weak void enable_caches(void) | ||||
75 | { | ||||
76 | } |