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/unistd.h>
8 #include <asm/csr.h>
9 #include <uapi/linux/time.h>
10 
11 #define VDSO_HAS_CLOCK_GETRES	1
12 
13 static __always_inline
14 int gettimeofday_fallback(struct __kernel_old_timeval *_tv,
15 			  struct timezone *_tz)
16 {
17 	register struct __kernel_old_timeval *tv asm("a0") = _tv;
18 	register struct timezone *tz asm("a1") = _tz;
19 	register long ret asm("a0");
20 	register long nr asm("a7") = __NR_gettimeofday;
21 
22 	asm volatile ("ecall\n"
23 		      : "=r" (ret)
24 		      : "r"(tv), "r"(tz), "r"(nr)
25 		      : "memory");
26 
27 	return ret;
28 }
29 
30 static __always_inline
31 long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
32 {
33 	register clockid_t clkid asm("a0") = _clkid;
34 	register struct __kernel_timespec *ts asm("a1") = _ts;
35 	register long ret asm("a0");
36 	register long nr asm("a7") = __NR_clock_gettime;
37 
38 	asm volatile ("ecall\n"
39 		      : "=r" (ret)
40 		      : "r"(clkid), "r"(ts), "r"(nr)
41 		      : "memory");
42 
43 	return ret;
44 }
45 
46 static __always_inline
47 int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
48 {
49 	register clockid_t clkid asm("a0") = _clkid;
50 	register struct __kernel_timespec *ts asm("a1") = _ts;
51 	register long ret asm("a0");
52 	register long nr asm("a7") = __NR_clock_getres;
53 
54 	asm volatile ("ecall\n"
55 		      : "=r" (ret)
56 		      : "r"(clkid), "r"(ts), "r"(nr)
57 		      : "memory");
58 
59 	return ret;
60 }
61 
62 static __always_inline u64 __arch_get_hw_counter(s32 clock_mode)
63 {
64 	/*
65 	 * The purpose of csr_read(CSR_TIME) is to trap the system into
66 	 * M-mode to obtain the value of CSR_TIME. Hence, unlike other
67 	 * architecture, no fence instructions surround the csr_read()
68 	 */
69 	return csr_read(CSR_TIME);
70 }
71 
72 static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
73 {
74 	return _vdso_data;
75 }
76 
77 #endif /* !__ASSEMBLY__ */
78 
79 #endif /* __ASM_VDSO_GETTIMEOFDAY_H */
80