cache.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <errno.h>
  2. #include "syscall.h"
  3. #include "atomic.h"
  4. #ifdef SYS_cacheflush
  5. int _flush_cache(void *addr, int len, int op)
  6. {
  7. return syscall(SYS_cacheflush, addr, len, op);
  8. }
  9. weak_alias(_flush_cache, cacheflush);
  10. #endif
  11. #ifdef SYS_cachectl
  12. int __cachectl(void *addr, int len, int op)
  13. {
  14. return syscall(SYS_cachectl, addr, len, op);
  15. }
  16. weak_alias(__cachectl, cachectl);
  17. #endif
  18. #ifdef SYS_riscv_flush_icache
  19. #define VDSO_FLUSH_ICACHE_SYM "__vdso_flush_icache"
  20. #define VDSO_FLUSH_ICACHE_VER "LINUX_4.15"
  21. static void *volatile vdso_func;
  22. static int flush_icache_init(void *start, void *end, unsigned long int flags)
  23. {
  24. void *p = __vdsosym(VDSO_FLUSH_ICACHE_VER, VDSO_FLUSH_ICACHE_SYM);
  25. int (*f)(void *, void *, unsigned long int) =
  26. (int (*)(void *, void *, unsigned long int))p;
  27. a_cas_p(&vdso_func, (void *)flush_icache_init, p);
  28. return f ? f(start, end, flags) : -ENOSYS;
  29. }
  30. static void *volatile vdso_func = (void *)flush_icache_init;
  31. int __riscv_flush_icache(void *start, void *end, unsigned long int flags)
  32. {
  33. int (*f)(void *, void *, unsigned long int) =
  34. (int (*)(void *, void *, unsigned long int))vdso_func;
  35. if (f) {
  36. int r = f(start, end, flags);
  37. if (!r) return r;
  38. if (r != -ENOSYS) return __syscall_ret(r);
  39. }
  40. }
  41. weak_alias(__riscv_flush_icache, riscv_flush_icache);
  42. #endif