14bff8cb5SSven Schnelle /* SPDX-License-Identifier: GPL-2.0 */
24bff8cb5SSven Schnelle #ifndef ASM_VDSO_GETTIMEOFDAY_H
34bff8cb5SSven Schnelle #define ASM_VDSO_GETTIMEOFDAY_H
44bff8cb5SSven Schnelle 
54bff8cb5SSven Schnelle #define VDSO_HAS_TIME 1
64bff8cb5SSven Schnelle 
74bff8cb5SSven Schnelle #define VDSO_HAS_CLOCK_GETRES 1
84bff8cb5SSven Schnelle 
9*36af1c5cSHeiko Carstens #include <asm/syscall.h>
104bff8cb5SSven Schnelle #include <asm/timex.h>
114bff8cb5SSven Schnelle #include <asm/unistd.h>
124bff8cb5SSven Schnelle #include <linux/compiler.h>
134bff8cb5SSven Schnelle 
144bff8cb5SSven Schnelle #define vdso_calc_delta __arch_vdso_calc_delta
__arch_vdso_calc_delta(u64 cycles,u64 last,u64 mask,u32 mult)154bff8cb5SSven Schnelle static __always_inline u64 __arch_vdso_calc_delta(u64 cycles, u64 last, u64 mask, u32 mult)
164bff8cb5SSven Schnelle {
174bff8cb5SSven Schnelle 	return (cycles - last) * mult;
184bff8cb5SSven Schnelle }
194bff8cb5SSven Schnelle 
__arch_get_vdso_data(void)204bff8cb5SSven Schnelle static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
214bff8cb5SSven Schnelle {
224bff8cb5SSven Schnelle 	return _vdso_data;
234bff8cb5SSven Schnelle }
244bff8cb5SSven Schnelle 
__arch_get_hw_counter(s32 clock_mode,const struct vdso_data * vd)254bff8cb5SSven Schnelle static inline u64 __arch_get_hw_counter(s32 clock_mode, const struct vdso_data *vd)
264bff8cb5SSven Schnelle {
274bff8cb5SSven Schnelle 	u64 adj, now;
284bff8cb5SSven Schnelle 
294bff8cb5SSven Schnelle 	now = get_tod_clock();
301ba2d6c0SHeiko Carstens 	adj = vd->arch_data.tod_steering_end - now;
314bff8cb5SSven Schnelle 	if (unlikely((s64) adj > 0))
321ba2d6c0SHeiko Carstens 		now += (vd->arch_data.tod_steering_delta < 0) ? (adj >> 15) : -(adj >> 15);
334bff8cb5SSven Schnelle 	return now;
344bff8cb5SSven Schnelle }
354bff8cb5SSven Schnelle 
364bff8cb5SSven Schnelle static __always_inline
clock_gettime_fallback(clockid_t clkid,struct __kernel_timespec * ts)374bff8cb5SSven Schnelle long clock_gettime_fallback(clockid_t clkid, struct __kernel_timespec *ts)
384bff8cb5SSven Schnelle {
39*36af1c5cSHeiko Carstens 	return syscall2(__NR_clock_gettime, (long)clkid, (long)ts);
404bff8cb5SSven Schnelle }
414bff8cb5SSven Schnelle 
424bff8cb5SSven Schnelle static __always_inline
gettimeofday_fallback(register struct __kernel_old_timeval * tv,register struct timezone * tz)434bff8cb5SSven Schnelle long gettimeofday_fallback(register struct __kernel_old_timeval *tv,
444bff8cb5SSven Schnelle 			   register struct timezone *tz)
454bff8cb5SSven Schnelle {
46*36af1c5cSHeiko Carstens 	return syscall2(__NR_gettimeofday, (long)tv, (long)tz);
474bff8cb5SSven Schnelle }
484bff8cb5SSven Schnelle 
494bff8cb5SSven Schnelle static __always_inline
clock_getres_fallback(clockid_t clkid,struct __kernel_timespec * ts)504bff8cb5SSven Schnelle long clock_getres_fallback(clockid_t clkid, struct __kernel_timespec *ts)
514bff8cb5SSven Schnelle {
52*36af1c5cSHeiko Carstens 	return syscall2(__NR_clock_getres, (long)clkid, (long)ts);
534bff8cb5SSven Schnelle }
544bff8cb5SSven Schnelle 
55eeab78b0SHeiko Carstens #ifdef CONFIG_TIME_NS
56808094fcSChristophe Leroy static __always_inline
__arch_get_timens_vdso_data(const struct vdso_data * vd)57808094fcSChristophe Leroy const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd)
58eeab78b0SHeiko Carstens {
59eeab78b0SHeiko Carstens 	return _timens_data;
60eeab78b0SHeiko Carstens }
61eeab78b0SHeiko Carstens #endif
62eeab78b0SHeiko Carstens 
634bff8cb5SSven Schnelle #endif
64