From 408a7e27d991f2cbc3335b8d2a119ad5db7d9a6d Mon Sep 17 00:00:00 2001 From: X512 Date: Fri, 17 Mar 2023 20:14:13 +0900 Subject: [PATCH] kernel: implement clear_caches for riscv64 Change-Id: I28296725ce22b47e94481abf794b92cf4ffd98a5 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6217 Tested-by: Automation Reviewed-by: Alex von Gluck IV Reviewed-by: waddlesplash --- src/system/kernel/arch/riscv64/arch_cpu.cpp | 6 ++++++ src/system/kernel/cpu.cpp | 5 ++++- src/system/libroot/os/arch/riscv64/cachectl.cpp | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/system/kernel/arch/riscv64/arch_cpu.cpp b/src/system/kernel/arch/riscv64/arch_cpu.cpp index a745eafb36..972336a733 100644 --- a/src/system/kernel/arch/riscv64/arch_cpu.cpp +++ b/src/system/kernel/arch/riscv64/arch_cpu.cpp @@ -90,6 +90,12 @@ arch_cpu_init_post_modules(kernel_args *args) void arch_cpu_sync_icache(void *address, size_t len) { + FenceI(); + + if (smp_get_num_cpus() > 1) { + memory_full_barrier(); + sbi_remote_fence_i(0, -1); + } } diff --git a/src/system/kernel/cpu.cpp b/src/system/kernel/cpu.cpp index 99348a21d0..d9712be109 100644 --- a/src/system/kernel/cpu.cpp +++ b/src/system/kernel/cpu.cpp @@ -189,7 +189,10 @@ cpu_frequency(int32 cpu) void clear_caches(void *address, size_t length, uint32 flags) { - // ToDo: implement me! + // TODO: data cache + if ((B_INVALIDATE_ICACHE & flags) != 0) { + arch_cpu_sync_icache(address, length); + } } diff --git a/src/system/libroot/os/arch/riscv64/cachectl.cpp b/src/system/libroot/os/arch/riscv64/cachectl.cpp index 616290c169..2200ce1738 100644 --- a/src/system/libroot/os/arch/riscv64/cachectl.cpp +++ b/src/system/libroot/os/arch/riscv64/cachectl.cpp @@ -3,9 +3,11 @@ * Distributed under the terms of the MIT License. */ +#include + extern "C" void __riscv_flush_icache(void *start, void *end, unsigned long int flags) { - __asm__ volatile ("fence.i"); + clear_caches(start, (uint8*)end - (uint8*)start, B_INVALIDATE_ICACHE); }