1 /* RISC-V instruction cache flushing VDSO calls
2 Copyright (C) 2017-2019 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
23 #include <sys/cachectl.h>
24 #if __has_include (<asm/syscalls.h>)
25 # include <asm/syscalls.h>
27 # include <asm/unistd.h>
30 typedef int (*func_type
) (void *, void *, unsigned long int);
33 __riscv_flush_icache_syscall (void *start
, void *end
, unsigned long int flags
)
35 return INLINE_SYSCALL (riscv_flush_icache
, 3, start
, end
, flags
);
39 __lookup_riscv_flush_icache (void)
41 PREPARE_VERSION_KNOWN (linux_version
, LINUX_4_15
);
43 func_type func
= _dl_vdso_vsym ("__vdso_flush_icache", &linux_version
);
45 /* If there is no vDSO entry then call the system call directly. All Linux
46 versions provide the vDSO entry, but QEMU's user-mode emulation doesn't
49 func
= &__riscv_flush_icache_syscall
;
57 libc_ifunc (__riscv_flush_icache
, __lookup_riscv_flush_icache ())
62 __riscv_flush_icache (void *start
, void *end
, unsigned long int flags
)
64 static volatile func_type cached_func
;
66 func_type func
= atomic_load_relaxed (&cached_func
);
70 func
= __lookup_riscv_flush_icache ();
71 atomic_store_relaxed (&cached_func
, func
);
74 return func (start
, end
, flags
);