1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef ASM_VDSO_GETTIMEOFDAY_H
3 #define ASM_VDSO_GETTIMEOFDAY_H
4 
5 #define VDSO_HAS_TIME 1
6 
7 #define VDSO_HAS_CLOCK_GETRES 1
8 
9 #include <asm/syscall.h>
10 #include <asm/timex.h>
11 #include <asm/unistd.h>
12 #include <linux/compiler.h>
13 
14 #define vdso_calc_delta __arch_vdso_calc_delta
__arch_vdso_calc_delta(u64 cycles,u64 last,u64 mask,u32 mult)15 static __always_inline u64 __arch_vdso_calc_delta(u64 cycles, u64 last, u64 mask, u32 mult)
16 {
17 	return (cycles - last) * mult;
18 }
19 
__arch_get_vdso_data(void)20 static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
21 {
22 	return _vdso_data;
23 }
24 
__arch_get_hw_counter(s32 clock_mode,const struct vdso_data * vd)25 static inline u64 __arch_get_hw_counter(s32 clock_mode, const struct vdso_data *vd)
26 {
27 	u64 adj, now;
28 
29 	now = get_tod_clock();
30 	adj = vd->arch_data.tod_steering_end - now;
31 	if (unlikely((s64) adj > 0))
32 		now += (vd->arch_data.tod_steering_delta < 0) ? (adj >> 15) : -(adj >> 15);
33 	return now;
34 }
35 
36 static __always_inline
clock_gettime_fallback(clockid_t clkid,struct __kernel_timespec * ts)37 long clock_gettime_fallback(clockid_t clkid, struct __kernel_timespec *ts)
38 {
39 	return syscall2(__NR_clock_gettime, (long)clkid, (long)ts);
40 }
41 
42 static __always_inline
gettimeofday_fallback(register struct __kernel_old_timeval * tv,register struct timezone * tz)43 long gettimeofday_fallback(register struct __kernel_old_timeval *tv,
44 			   register struct timezone *tz)
45 {
46 	return syscall2(__NR_gettimeofday, (long)tv, (long)tz);
47 }
48 
49 static __always_inline
clock_getres_fallback(clockid_t clkid,struct __kernel_timespec * ts)50 long clock_getres_fallback(clockid_t clkid, struct __kernel_timespec *ts)
51 {
52 	return syscall2(__NR_clock_getres, (long)clkid, (long)ts);
53 }
54 
55 #ifdef CONFIG_TIME_NS
56 static __always_inline
__arch_get_timens_vdso_data(const struct vdso_data * vd)57 const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd)
58 {
59 	return _timens_data;
60 }
61 #endif
62 
63 #endif
64