blob: ae5c60716ffdd82742dc783095eebd54a0dde7eb [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
14void flush_dcache_all(void)
15{
16 asm volatile ("fence" :::"memory");
17}
Rick Chen6eedd922017-12-26 13:55:49 +080018void flush_dcache_range(unsigned long start, unsigned long end)
19{
Rick Chen842d5802018-11-07 09:34:06 +080020 flush_dcache_all();
Rick Chen6eedd922017-12-26 13:55:49 +080021}
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
Rick Chen842d5802018-11-07 09:34:06 +080032void invalidate_dcache_range(unsigned long start, unsigned long end)
Lukas Auer76562282018-11-22 11:26:23 +010033{
Rick Chen842d5802018-11-07 09:34:06 +080034 flush_dcache_all();
Rick Chen6eedd922017-12-26 13:55:49 +080035}
36
Rick Chen842d5802018-11-07 09:34:06 +080037void cache_flush(void)
Rick Chen6eedd922017-12-26 13:55:49 +080038{
Rick Chen842d5802018-11-07 09:34:06 +080039 invalidate_icache_all();
40 flush_dcache_all();
Rick Chen6eedd922017-12-26 13:55:49 +080041}
42
43void flush_cache(unsigned long addr, unsigned long size)
44{
Rick Chen842d5802018-11-07 09:34:06 +080045 invalidate_icache_all();
46 flush_dcache_all();
Rick Chen6eedd922017-12-26 13:55:49 +080047}
48
Rick Chen842d5802018-11-07 09:34:06 +080049__weak void icache_enable(void)
Rick Chen6eedd922017-12-26 13:55:49 +080050{
51}
52
Rick Chen842d5802018-11-07 09:34:06 +080053__weak void icache_disable(void)
Rick Chen6eedd922017-12-26 13:55:49 +080054{
55}
56
Rick Chen842d5802018-11-07 09:34:06 +080057__weak int icache_status(void)
Rick Chen6eedd922017-12-26 13:55:49 +080058{
59 return 0;
60}
61
Rick Chen842d5802018-11-07 09:34:06 +080062__weak void dcache_enable(void)
Rick Chen6eedd922017-12-26 13:55:49 +080063{
64}
65
Rick Chen842d5802018-11-07 09:34:06 +080066__weak void dcache_disable(void)
Rick Chen6eedd922017-12-26 13:55:49 +080067{
68}
69
Rick Chen842d5802018-11-07 09:34:06 +080070__weak int dcache_status(void)
Rick Chen6eedd922017-12-26 13:55:49 +080071{
72 return 0;
73}