Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __ASM_VDSO_GETTIMEOFDAY_H
3#define __ASM_VDSO_GETTIMEOFDAY_H
4
5#ifndef __ASSEMBLY__
6
7#include <asm/barrier.h>
8#include <asm/unistd.h>
9#include <asm/csr.h>
10#include <uapi/linux/time.h>
11
12#define VDSO_HAS_CLOCK_GETRES 1
13
14static __always_inline
15int gettimeofday_fallback(struct __kernel_old_timeval *_tv,
16 struct timezone *_tz)
17{
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;
22
23 asm volatile ("ecall\n"
24 : "=r" (ret)
25 : "r"(tv), "r"(tz), "r"(nr)
26 : "memory");
27
28 return ret;
29}
30
31static __always_inline
32long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
33{
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;
38
39 asm volatile ("ecall\n"
40 : "=r" (ret)
41 : "r"(clkid), "r"(ts), "r"(nr)
42 : "memory");
43
44 return ret;
45}
46
47static __always_inline
48int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
49{
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;
54
55 asm volatile ("ecall\n"
56 : "=r" (ret)
57 : "r"(clkid), "r"(ts), "r"(nr)
58 : "memory");
59
60 return ret;
61}
62
63static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
64 const struct vdso_data *vd)
65{
66 /*
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()
70 */
71 return csr_read(CSR_TIME);
72}
73
74static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
75{
76 return _vdso_data;
77}
78
79#endif /* !__ASSEMBLY__ */
80
81#endif /* __ASM_VDSO_GETTIMEOFDAY_H */