1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_VDSO_GETTIMEOFDAY_H
3 #define __ASM_VDSO_GETTIMEOFDAY_H
7 #include <asm/barrier.h>
8 #include <asm/unistd.h>
10 #include <uapi/linux/time.h>
13 * 32-bit land is lacking generic time vsyscalls as well as the legacy 32-bit
14 * time syscalls like gettimeofday. Skip these definitions since on 32-bit.
16 #ifdef CONFIG_GENERIC_TIME_VSYSCALL
18 #define VDSO_HAS_CLOCK_GETRES 1
20 static __always_inline
21 int gettimeofday_fallback(struct __kernel_old_timeval
*_tv
,
24 register struct __kernel_old_timeval
*tv
asm("a0") = _tv
;
25 register struct timezone
*tz
asm("a1") = _tz
;
26 register long ret
asm("a0");
27 register long nr
asm("a7") = __NR_gettimeofday
;
29 asm volatile ("ecall\n"
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 clockid_t clkid
asm("a0") = _clkid
;
41 register struct __kernel_timespec
*ts
asm("a1") = _ts
;
42 register long ret
asm("a0");
43 register long nr
asm("a7") = __NR_clock_gettime
;
45 asm volatile ("ecall\n"
47 : "r"(clkid
), "r"(ts
), "r"(nr
)
53 static __always_inline
54 int clock_getres_fallback(clockid_t _clkid
, struct __kernel_timespec
*_ts
)
56 register clockid_t clkid
asm("a0") = _clkid
;
57 register struct __kernel_timespec
*ts
asm("a1") = _ts
;
58 register long ret
asm("a0");
59 register long nr
asm("a7") = __NR_clock_getres
;
61 asm volatile ("ecall\n"
63 : "r"(clkid
), "r"(ts
), "r"(nr
)
69 #endif /* CONFIG_GENERIC_TIME_VSYSCALL */
71 static __always_inline u64
__arch_get_hw_counter(s32 clock_mode
,
72 const struct vdso_data
*vd
)
75 * The purpose of csr_read(CSR_TIME) is to trap the system into
76 * M-mode to obtain the value of CSR_TIME. Hence, unlike other
77 * architecture, no fence instructions surround the csr_read()
79 return csr_read(CSR_TIME
);
82 static __always_inline
const struct vdso_data
*__arch_get_vdso_data(void)
88 static __always_inline
89 const struct vdso_data
*__arch_get_timens_vdso_data(const struct vdso_data
*vd
)
94 #endif /* !__ASSEMBLY__ */
96 #endif /* __ASM_VDSO_GETTIMEOFDAY_H */