Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2017 Andes Technology Corporation |
| 4 | * Rick Chen, Andes Technology Corporation <rick@andestech.com> |
| 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 | 05a684e | 2019-08-28 18:46:09 +0800 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 10 | #include <asm/cache.h> |
Rick Chen | 05a684e | 2019-08-28 18:46:09 +0800 | [diff] [blame] | 11 | #include <dm/uclass-internal.h> |
| 12 | #include <cache.h> |
Rick Chen | 49cb706 | 2019-08-28 18:46:11 +0800 | [diff] [blame] | 13 | #include <asm/csr.h> |
| 14 | |
| 15 | #ifdef CONFIG_RISCV_NDS_CACHE |
Pragnesh Patel | d12b55b | 2020-03-14 19:12:28 +0530 | [diff] [blame] | 16 | #if CONFIG_IS_ENABLED(RISCV_MMODE) |
Rick Chen | 49cb706 | 2019-08-28 18:46:11 +0800 | [diff] [blame] | 17 | /* mcctlcommand */ |
| 18 | #define CCTL_REG_MCCTLCOMMAND_NUM 0x7cc |
| 19 | |
| 20 | /* D-cache operation */ |
| 21 | #define CCTL_L1D_WBINVAL_ALL 6 |
| 22 | #endif |
Rick Chen | 883275d | 2019-11-14 13:52:25 +0800 | [diff] [blame] | 23 | #endif |
| 24 | |
| 25 | #ifdef CONFIG_V5L2_CACHE |
| 26 | static void _cache_enable(void) |
| 27 | { |
| 28 | struct udevice *dev = NULL; |
| 29 | |
| 30 | uclass_find_first_device(UCLASS_CACHE, &dev); |
| 31 | |
| 32 | if (dev) |
| 33 | cache_enable(dev); |
| 34 | } |
| 35 | |
| 36 | static void _cache_disable(void) |
| 37 | { |
| 38 | struct udevice *dev = NULL; |
| 39 | |
| 40 | uclass_find_first_device(UCLASS_CACHE, &dev); |
| 41 | |
| 42 | if (dev) |
| 43 | cache_disable(dev); |
| 44 | } |
| 45 | #endif |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 46 | |
Lukas Auer | 6280e32 | 2019-01-04 01:37:29 +0100 | [diff] [blame] | 47 | void flush_dcache_all(void) |
| 48 | { |
Rick Chen | 883275d | 2019-11-14 13:52:25 +0800 | [diff] [blame] | 49 | #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF) |
Rick Chen | 49cb706 | 2019-08-28 18:46:11 +0800 | [diff] [blame] | 50 | #ifdef CONFIG_RISCV_NDS_CACHE |
Pragnesh Patel | d12b55b | 2020-03-14 19:12:28 +0530 | [diff] [blame] | 51 | #if CONFIG_IS_ENABLED(RISCV_MMODE) |
Rick Chen | 49cb706 | 2019-08-28 18:46:11 +0800 | [diff] [blame] | 52 | csr_write(CCTL_REG_MCCTLCOMMAND_NUM, CCTL_L1D_WBINVAL_ALL); |
| 53 | #endif |
Rick Chen | 883275d | 2019-11-14 13:52:25 +0800 | [diff] [blame] | 54 | #endif |
| 55 | #endif |
Lukas Auer | 6280e32 | 2019-01-04 01:37:29 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void flush_dcache_range(unsigned long start, unsigned long end) |
| 59 | { |
| 60 | flush_dcache_all(); |
| 61 | } |
| 62 | |
| 63 | void invalidate_dcache_range(unsigned long start, unsigned long end) |
| 64 | { |
| 65 | flush_dcache_all(); |
| 66 | } |
| 67 | |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 68 | void icache_enable(void) |
| 69 | { |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void icache_disable(void) |
| 73 | { |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void dcache_enable(void) |
| 77 | { |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void dcache_disable(void) |
| 81 | { |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | int icache_status(void) |
| 85 | { |
Leo Yu-Chi Liang | 816979a | 2023-02-06 16:10:44 +0800 | [diff] [blame^] | 86 | return 0; |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | int dcache_status(void) |
| 90 | { |
Leo Yu-Chi Liang | 816979a | 2023-02-06 16:10:44 +0800 | [diff] [blame^] | 91 | return 0; |
Rick Chen | 842d580 | 2018-11-07 09:34:06 +0800 | [diff] [blame] | 92 | } |