RV32 SoC DS UG
High-Perf RV32 SoC DS UG
RV64 SoC DS UG API and Examples
Embedded IDE UG
Loading...
Searching...
No Matches
vexriscv.h
Go to the documentation of this file.
1
2// Copyright (C) 2013-2026 Efinix Inc. All rights reserved.
3// Full license header bsp/efinix/EfxSapphireSocRV64/include/LICENSE.MD
5
6#ifndef VEX_RISCV_H_
7#define VEX_RISCV_H_
8
9#include "riscv.h"
10#include "type.h"
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16//Invalidate the whole instruction cache
17#define instruction_cache_invalidate() asm("fence.i");
18
19#if __riscv_xlen == 32
20 //Invalidate the whole data cache
21 #define data_cache_invalidate_all() asm(".word(0x500F)");
22
23 //Invalidate all the data cache ways lines which could store the given address
24 #define data_cache_invalidate_address(address) \
25 ({ \
26 asm volatile( \
27 ".word ((0x500F) | (regnum_%0 << 15));" \
28 : \
29 : "r" (address) \
30 ); \
31 })
32#endif //RV32
33
34#if __riscv_xlen == 64
35 #ifdef __riscv_zicbom
36 // Flush the caches using the Rvcbm flush instruction. This will also flush the L2 cache, work with virtual address
37 // Note, to ensure all the flush are done, call the rvcbm_fence()
38 #define rvcbm_flush_address(address) \
39 ({ \
40 register uintptr_t _tmp = (uintptr_t)(address); \
41 __asm__ volatile (".word 0x20200F | (regnum_%0 << 15)" :: "r"(_tmp)); \
42 })
43
44 // Flush the caches using the Rvcbm flush instruction. This will also flush the L2 cache, work with virtual address
45 // Note, to ensure all the flush are done, call the rvcbm_fence()
46 static void rvcbm_flush(void* address, u64 size){
47 u64 ptr = (((u64)address) >> 6) << 6;
48 u64 end = (u64)address + size;
49 while(ptr < end){
50 rvcbm_flush_address(ptr);
51 ptr += 64;
52 }
53 }
54
55 // Ensure all the previously executed rvcbm flush are done
56 #define rvcbm_fence() asm("fence")
57
58 #endif // __riscv_zicbom
59
60 // Software Prefetcher
61 // Ask the L1 data cache to prefetch the memory at the given address, for future CPU read
62 #define prefetch_r(address) \
63 ({ \
64 register uintptr_t _tmp = (uintptr_t)(address); \
65 __asm__ volatile ("ori x0, %0, 1" :: "r"(_tmp)); \
66 })
67
68 // Ask the L1 data cache to prefetch the memory at given address, for future CPU read/write
69 #define prefetch_rw(address) \
70 ({ \
71 register uintptr_t _tmp = (uintptr_t)(address); \
72 __asm__ volatile ("ori x0, %0, 3" :: "r"(_tmp)); \
73 })
74
75
76 // Ask the L1 data cache to prefetch the memory at the given (address + offset * 64), for future CPU read
77 #define prefetch_r_line(address, offset) \
78 ({ \
79 register uintptr_t _tmp = (uintptr_t)(address); \
80 __asm__ volatile ("ori x0, %0, %c1" :: "r"(_tmp), "i"(1 + ((offset) * 64))); \
81 })
82
83 // Ask the L1 data cache to prefetch the memory at the given (address + offset * 64), for future CPU read/write
84 #define prefetch_rw_line(address, offset) \
85 ({ \
86 register uintptr_t _tmp = (uintptr_t)(address); \
87 __asm__ volatile ("ori x0, %0, %c1" :: "r"(_tmp), "i"(3 + ((offset) * 64))); \
88 })
89#endif //RV64
90
91#ifdef __cplusplus
92}
93#endif // C_plusplus
94
95#endif // VEX_RISCV_H_
96
97
RISC-V related functions and definitions.
uint64_t u64
Definition type.h:24