1570af302Sopenharmony_ci#include <errno.h> 2570af302Sopenharmony_ci#include "syscall.h" 3570af302Sopenharmony_ci#include "atomic.h" 4570af302Sopenharmony_ci 5570af302Sopenharmony_ci#ifdef SYS_cacheflush 6570af302Sopenharmony_ciint _flush_cache(void *addr, int len, int op) 7570af302Sopenharmony_ci{ 8570af302Sopenharmony_ci return syscall(SYS_cacheflush, addr, len, op); 9570af302Sopenharmony_ci} 10570af302Sopenharmony_ciweak_alias(_flush_cache, cacheflush); 11570af302Sopenharmony_ci#endif 12570af302Sopenharmony_ci 13570af302Sopenharmony_ci#ifdef SYS_cachectl 14570af302Sopenharmony_ciint __cachectl(void *addr, int len, int op) 15570af302Sopenharmony_ci{ 16570af302Sopenharmony_ci return syscall(SYS_cachectl, addr, len, op); 17570af302Sopenharmony_ci} 18570af302Sopenharmony_ciweak_alias(__cachectl, cachectl); 19570af302Sopenharmony_ci#endif 20570af302Sopenharmony_ci 21570af302Sopenharmony_ci#ifdef SYS_riscv_flush_icache 22570af302Sopenharmony_ci 23570af302Sopenharmony_ci#define VDSO_FLUSH_ICACHE_SYM "__vdso_flush_icache" 24570af302Sopenharmony_ci#define VDSO_FLUSH_ICACHE_VER "LINUX_4.15" 25570af302Sopenharmony_ci 26570af302Sopenharmony_cistatic void *volatile vdso_func; 27570af302Sopenharmony_ci 28570af302Sopenharmony_cistatic int flush_icache_init(void *start, void *end, unsigned long int flags) 29570af302Sopenharmony_ci{ 30570af302Sopenharmony_ci#ifndef __LITEOS__ 31570af302Sopenharmony_ci __get_vdso_info(); 32570af302Sopenharmony_ci void *p = __get_vdso_addr(VDSO_FLUSH_ICACHE_VER, VDSO_FLUSH_ICACHE_SYM); 33570af302Sopenharmony_ci#else 34570af302Sopenharmony_ci void *p = __vdsosym(VDSO_FLUSH_ICACHE_VER, VDSO_FLUSH_ICACHE_SYM); 35570af302Sopenharmony_ci#endif 36570af302Sopenharmony_ci int (*f)(void *, void *, unsigned long int) = 37570af302Sopenharmony_ci (int (*)(void *, void *, unsigned long int))p; 38570af302Sopenharmony_ci a_cas_p(&vdso_func, (void *)flush_icache_init, p); 39570af302Sopenharmony_ci return f ? f(start, end, flags) : -ENOSYS; 40570af302Sopenharmony_ci} 41570af302Sopenharmony_ci 42570af302Sopenharmony_cistatic void *volatile vdso_func = (void *)flush_icache_init; 43570af302Sopenharmony_ci 44570af302Sopenharmony_ciint __riscv_flush_icache(void *start, void *end, unsigned long int flags) 45570af302Sopenharmony_ci{ 46570af302Sopenharmony_ci int (*f)(void *, void *, unsigned long int) = 47570af302Sopenharmony_ci (int (*)(void *, void *, unsigned long int))vdso_func; 48570af302Sopenharmony_ci if (f) { 49570af302Sopenharmony_ci int r = f(start, end, flags); 50570af302Sopenharmony_ci if (!r) return r; 51570af302Sopenharmony_ci if (r != -ENOSYS) return __syscall_ret(r); 52570af302Sopenharmony_ci } 53570af302Sopenharmony_ci return syscall(SYS_riscv_flush_icache, start, end, flags); 54570af302Sopenharmony_ci} 55570af302Sopenharmony_ciweak_alias(__riscv_flush_icache, riscv_flush_icache); 56570af302Sopenharmony_ci#endif 57