1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2018 ARM Limited
5 #ifndef __ASM_VDSO_GETTIMEOFDAY_H
6 #define __ASM_VDSO_GETTIMEOFDAY_H
10 #include <asm/unistd.h>
11 #include <uapi/linux/time.h>
13 #include <asm/vdso/clocksource.h>
15 #define __VDSO_USE_SYSCALL ULLONG_MAX
17 #define VDSO_HAS_CLOCK_GETRES 1
19 static __always_inline
20 int gettimeofday_fallback(struct __kernel_old_timeval *_tv,
23 register struct timezone *tz asm("x1") = _tz;
24 register struct __kernel_old_timeval *tv asm("x0") = _tv;
25 register long ret asm ("x0");
26 register long nr asm("x8") = __NR_gettimeofday;
31 : "r" (tv), "r" (tz), "r" (nr)
37 static __always_inline
38 long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
40 register struct __kernel_timespec *ts asm("x1") = _ts;
41 register clockid_t clkid asm("x0") = _clkid;
42 register long ret asm ("x0");
43 register long nr asm("x8") = __NR_clock_gettime;
48 : "r" (clkid), "r" (ts), "r" (nr)
54 static __always_inline
55 int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
57 register struct __kernel_timespec *ts asm("x1") = _ts;
58 register clockid_t clkid asm("x0") = _clkid;
59 register long ret asm ("x0");
60 register long nr asm("x8") = __NR_clock_getres;
65 : "r" (clkid), "r" (ts), "r" (nr)
71 static __always_inline u64 __arch_get_hw_counter(s32 clock_mode)
76 * clock_mode != NONE implies that vDSO are enabled otherwise
77 * fallback on syscall.
79 if (clock_mode == VDSO_CLOCKMODE_NONE)
80 return __VDSO_USE_SYSCALL;
83 * This isb() is required to prevent that the counter value
87 asm volatile("mrs %0, cntvct_el0" : "=r" (res) :: "memory");
88 arch_counter_enforce_ordering(res);
93 static __always_inline
94 const struct vdso_data *__arch_get_vdso_data(void)
99 #endif /* !__ASSEMBLY__ */
101 #endif /* __ASM_VDSO_GETTIMEOFDAY_H */