Merge tag 'linux-kselftest-kunit-fixes-5.11-rc3' of git://git.kernel.org/pub/scm...
[linux/fpc-iii.git] / arch / riscv / include / asm / vdso / gettimeofday.h
blobf839f16e0d2a94d88dc657c0db6d8514c1a1844c
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_VDSO_GETTIMEOFDAY_H
3 #define __ASM_VDSO_GETTIMEOFDAY_H
5 #ifndef __ASSEMBLY__
7 #include <asm/barrier.h>
8 #include <asm/unistd.h>
9 #include <asm/csr.h>
10 #include <uapi/linux/time.h>
12 #define VDSO_HAS_CLOCK_GETRES 1
14 static __always_inline
15 int gettimeofday_fallback(struct __kernel_old_timeval *_tv,
16 struct timezone *_tz)
18 register struct __kernel_old_timeval *tv asm("a0") = _tv;
19 register struct timezone *tz asm("a1") = _tz;
20 register long ret asm("a0");
21 register long nr asm("a7") = __NR_gettimeofday;
23 asm volatile ("ecall\n"
24 : "=r" (ret)
25 : "r"(tv), "r"(tz), "r"(nr)
26 : "memory");
28 return ret;
31 static __always_inline
32 long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
34 register clockid_t clkid asm("a0") = _clkid;
35 register struct __kernel_timespec *ts asm("a1") = _ts;
36 register long ret asm("a0");
37 register long nr asm("a7") = __NR_clock_gettime;
39 asm volatile ("ecall\n"
40 : "=r" (ret)
41 : "r"(clkid), "r"(ts), "r"(nr)
42 : "memory");
44 return ret;
47 static __always_inline
48 int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
50 register clockid_t clkid asm("a0") = _clkid;
51 register struct __kernel_timespec *ts asm("a1") = _ts;
52 register long ret asm("a0");
53 register long nr asm("a7") = __NR_clock_getres;
55 asm volatile ("ecall\n"
56 : "=r" (ret)
57 : "r"(clkid), "r"(ts), "r"(nr)
58 : "memory");
60 return ret;
63 static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
64 const struct vdso_data *vd)
67 * The purpose of csr_read(CSR_TIME) is to trap the system into
68 * M-mode to obtain the value of CSR_TIME. Hence, unlike other
69 * architecture, no fence instructions surround the csr_read()
71 return csr_read(CSR_TIME);
74 static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
76 return _vdso_data;
79 #endif /* !__ASSEMBLY__ */
81 #endif /* __ASM_VDSO_GETTIMEOFDAY_H */