WIP FPC-III support
[linux/fpc-iii.git] / arch / arm64 / include / asm / vdso / gettimeofday.h
blob631ab12816335ff0bed9eda6b9eb4ad56c657b72
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (C) 2018 ARM Limited
4 */
5 #ifndef __ASM_VDSO_GETTIMEOFDAY_H
6 #define __ASM_VDSO_GETTIMEOFDAY_H
8 #ifndef __ASSEMBLY__
10 #include <asm/barrier.h>
11 #include <asm/unistd.h>
13 #define VDSO_HAS_CLOCK_GETRES 1
15 static __always_inline
16 int gettimeofday_fallback(struct __kernel_old_timeval *_tv,
17 struct timezone *_tz)
19 register struct timezone *tz asm("x1") = _tz;
20 register struct __kernel_old_timeval *tv asm("x0") = _tv;
21 register long ret asm ("x0");
22 register long nr asm("x8") = __NR_gettimeofday;
24 asm volatile(
25 " svc #0\n"
26 : "=r" (ret)
27 : "r" (tv), "r" (tz), "r" (nr)
28 : "memory");
30 return ret;
33 static __always_inline
34 long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
36 register struct __kernel_timespec *ts asm("x1") = _ts;
37 register clockid_t clkid asm("x0") = _clkid;
38 register long ret asm ("x0");
39 register long nr asm("x8") = __NR_clock_gettime;
41 asm volatile(
42 " svc #0\n"
43 : "=r" (ret)
44 : "r" (clkid), "r" (ts), "r" (nr)
45 : "memory");
47 return ret;
50 static __always_inline
51 int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
53 register struct __kernel_timespec *ts asm("x1") = _ts;
54 register clockid_t clkid asm("x0") = _clkid;
55 register long ret asm ("x0");
56 register long nr asm("x8") = __NR_clock_getres;
58 asm volatile(
59 " svc #0\n"
60 : "=r" (ret)
61 : "r" (clkid), "r" (ts), "r" (nr)
62 : "memory");
64 return ret;
67 static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
68 const struct vdso_data *vd)
70 u64 res;
73 * Core checks for mode already, so this raced against a concurrent
74 * update. Return something. Core will do another round and then
75 * see the mode change and fallback to the syscall.
77 if (clock_mode == VDSO_CLOCKMODE_NONE)
78 return 0;
81 * This isb() is required to prevent that the counter value
82 * is speculated.
84 isb();
85 asm volatile("mrs %0, cntvct_el0" : "=r" (res) :: "memory");
87 * This isb() is required to prevent that the seq lock is
88 * speculated.#
90 isb();
92 return res;
95 static __always_inline
96 const struct vdso_data *__arch_get_vdso_data(void)
98 return _vdso_data;
101 #ifdef CONFIG_TIME_NS
102 static __always_inline
103 const struct vdso_data *__arch_get_timens_vdso_data(void)
105 return _timens_data;
107 #endif
109 #endif /* !__ASSEMBLY__ */
111 #endif /* __ASM_VDSO_GETTIMEOFDAY_H */