blob: 5437a122a100480881b3c66f8e1c24cf12eb3a58 [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>
8
Rick Chen842d5802018-11-07 09:34:06 +08009void invalidate_icache_all(void)
10{
11 asm volatile ("fence.i" ::: "memory");
12}
13
Lukas Auer6280e322019-01-04 01:37:29 +010014__weak void flush_dcache_all(void)
Rick Chen842d5802018-11-07 09:34:06 +080015{
Rick Chen842d5802018-11-07 09:34:06 +080016}
Lukas Auer6280e322019-01-04 01:37:29 +010017
18__weak void flush_dcache_range(unsigned long start, unsigned long end)
Rick Chen6eedd922017-12-26 13:55:49 +080019{
20}
21
22void invalidate_icache_range(unsigned long start, unsigned long end)
23{
Lukas Auer76562282018-11-22 11:26:23 +010024 /*
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 Auer6280e322019-01-04 01:37:29 +010031__weak void invalidate_dcache_range(unsigned long start, unsigned long end)
Lukas Auer76562282018-11-22 11:26:23 +010032{
Rick Chen6eedd922017-12-26 13:55:49 +080033}
34
Rick Chen842d5802018-11-07 09:34:06 +080035void cache_flush(void)
Rick Chen6eedd922017-12-26 13:55:49 +080036{
Rick Chen842d5802018-11-07 09:34:06 +080037 invalidate_icache_all();
38 flush_dcache_all();
Rick Chen6eedd922017-12-26 13:55:49 +080039}
40
41void flush_cache(unsigned long addr, unsigned long size)
42{
Lukas Auer09dfc3c2019-01-04 01:37:30 +010043 invalidate_icache_range(addr, addr + size);
44 flush_dcache_range(addr, addr + size);
Rick Chen6eedd922017-12-26 13:55:49 +080045}
46
Rick Chen842d5802018-11-07 09:34:06 +080047__weak void icache_enable(void)
Rick Chen6eedd922017-12-26 13:55:49 +080048{
49}
50
Rick Chen842d5802018-11-07 09:34:06 +080051__weak void icache_disable(void)
Rick Chen6eedd922017-12-26 13:55:49 +080052{
53}
54
Rick Chen842d5802018-11-07 09:34:06 +080055__weak int icache_status(void)
Rick Chen6eedd922017-12-26 13:55:49 +080056{
57 return 0;
58}
59
Rick Chen842d5802018-11-07 09:34:06 +080060__weak void dcache_enable(void)
Rick Chen6eedd922017-12-26 13:55:49 +080061{
62}
63
Rick Chen842d5802018-11-07 09:34:06 +080064__weak void dcache_disable(void)
Rick Chen6eedd922017-12-26 13:55:49 +080065{
66}
67
Rick Chen842d5802018-11-07 09:34:06 +080068__weak int dcache_status(void)
Rick Chen6eedd922017-12-26 13:55:49 +080069{
70 return 0;
71}