riscv32: decouple from riscv64
[uclibc-ng.git] / libc / sysdeps / linux / riscv32 / cache.c
blobaa99a2a0d80cf24708dc6b0c8744003ba5bacbfa
1 /* RISC-V instruction cache flushing VDSO calls
2 Copyright (C) 2017-2020 Free Software Foundation, Inc.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <stdlib.h>
19 #include <atomic.h>
20 #include <sys/syscall.h>
22 #ifndef __NR_riscv_flush_icache
23 #define __NR_riscv_flush_icache 259
24 #endif
26 typedef int (*func_type) (void *, void *, unsigned long int);
28 static int
29 __riscv_flush_icache_syscall (void *start, void *end, unsigned long int flags)
31 return INLINE_SYSCALL (riscv_flush_icache, 3, start, end, flags);
34 static func_type
35 __lookup_riscv_flush_icache (void)
37 /* always call the system call directly.*/
38 return &__riscv_flush_icache_syscall;
41 int
42 __riscv_flush_icache (void *start, void *end, unsigned long int flags)
44 static volatile func_type cached_func;
46 func_type func = atomic_load_relaxed (&cached_func);
48 if (!func)
50 func = __lookup_riscv_flush_icache ();
51 atomic_store_relaxed (&cached_func, func);
54 return func (start, end, flags);