cache.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* RISC-V instruction cache flushing VDSO calls
  2. Copyright (C) 2017-2020 Free Software Foundation, Inc.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include <stdlib.h>
  15. #include <atomic.h>
  16. #include <sys/syscall.h>
  17. typedef int (*func_type) (void *, void *, unsigned long int);
  18. static int
  19. __riscv_flush_icache_syscall (void *start, void *end, unsigned long int flags)
  20. {
  21. return INLINE_SYSCALL (riscv_flush_icache, 3, start, end, flags);
  22. }
  23. static func_type
  24. __lookup_riscv_flush_icache (void)
  25. {
  26. /* always call the system call directly.*/
  27. return &__riscv_flush_icache_syscall;
  28. }
  29. int
  30. __riscv_flush_icache (void *start, void *end, unsigned long int flags)
  31. {
  32. static volatile func_type cached_func;
  33. func_type func = atomic_load_relaxed (&cached_func);
  34. if (!func)
  35. {
  36. func = __lookup_riscv_flush_icache ();
  37. atomic_store_relaxed (&cached_func, func);
  38. }
  39. return func (start, end, flags);
  40. }