blob: b1d42bcc2bb86d64cf04b087f80c73c268f62414 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rick Chen6eedd922017-12-26 13:55:49 +08002/*
3 * Copyright (C) 2017 Andes Technology Corporation
4 * Rick Chen, Andes Technology Corporation <rick@andestech.com>
Rick Chen6eedd922017-12-26 13:55:49 +08005 */
6
7#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07008#include <cpu_func.h>
Rick Chen6eedd922017-12-26 13:55:49 +08009
Rick Chen842d5802018-11-07 09:34:06 +080010void invalidate_icache_all(void)
11{
12 asm volatile ("fence.i" ::: "memory");
13}
14
Lukas Auer6280e322019-01-04 01:37:29 +010015__weak void flush_dcache_all(void)
Rick Chen842d5802018-11-07 09:34:06 +080016{
Rick Chen842d5802018-11-07 09:34:06 +080017}
Lukas Auer6280e322019-01-04 01:37:29 +010018
19__weak void flush_dcache_range(unsigned long start, unsigned long end)
Rick Chen6eedd922017-12-26 13:55:49 +080020{
21}
22
23void invalidate_icache_range(unsigned long start, unsigned long end)
24{
Lukas Auer76562282018-11-22 11:26:23 +010025 /*
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 Auer6280e322019-01-04 01:37:29 +010032__weak void invalidate_dcache_range(unsigned long start, unsigned long end)
Lukas Auer76562282018-11-22 11:26:23 +010033{
Rick Chen6eedd922017-12-26 13:55:49 +080034}
35
Rick Chen842d5802018-11-07 09:34:06 +080036void cache_flush(void)
Rick Chen6eedd922017-12-26 13:55:49 +080037{
Rick Chen842d5802018-11-07 09:34:06 +080038 invalidate_icache_all();
39 flush_dcache_all();
Rick Chen6eedd922017-12-26 13:55:49 +080040}
41
42void flush_cache(unsigned long addr, unsigned long size)
43{
Lukas Auer09dfc3c2019-01-04 01:37:30 +010044 invalidate_icache_range(addr, addr + size);
45 flush_dcache_range(addr, addr + size);
Rick Chen6eedd922017-12-26 13:55:49 +080046}
47
Rick Chen842d5802018-11-07 09:34:06 +080048__weak void icache_enable(void)
Rick Chen6eedd922017-12-26 13:55:49 +080049{
50}
51
Rick Chen842d5802018-11-07 09:34:06 +080052__weak void icache_disable(void)
Rick Chen6eedd922017-12-26 13:55:49 +080053{
54}
55
Rick Chen842d5802018-11-07 09:34:06 +080056__weak int icache_status(void)
Rick Chen6eedd922017-12-26 13:55:49 +080057{
58 return 0;
59}
60
Rick Chen842d5802018-11-07 09:34:06 +080061__weak void dcache_enable(void)
Rick Chen6eedd922017-12-26 13:55:49 +080062{
63}
64
Rick Chen842d5802018-11-07 09:34:06 +080065__weak void dcache_disable(void)
Rick Chen6eedd922017-12-26 13:55:49 +080066{
67}
68
Rick Chen842d5802018-11-07 09:34:06 +080069__weak int dcache_status(void)
Rick Chen6eedd922017-12-26 13:55:49 +080070{
71 return 0;
72}