1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_VDSO_GETTIMEOFDAY_H
3 #define _ASM_POWERPC_VDSO_GETTIMEOFDAY_H
8 #include <asm/vdso/timebase.h>
9 #include <asm/barrier.h>
10 #include <asm/unistd.h>
11 #include <uapi/linux/time.h>
13 #define VDSO_HAS_CLOCK_GETRES 1
15 #define VDSO_HAS_TIME 1
17 static __always_inline int do_syscall_2(const unsigned long _r0, const unsigned long _r3,
18 const unsigned long _r4)
20 register long r0 asm("r0") = _r0;
21 register unsigned long r3 asm("r3") = _r3;
22 register unsigned long r4 asm("r4") = _r4;
23 register int ret asm ("r3");
30 : "=r" (ret), "+r" (r4), "+r" (r0)
32 : "memory", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "cr0", "ctr");
37 static __always_inline
38 int gettimeofday_fallback(struct __kernel_old_timeval *_tv, struct timezone *_tz)
40 return do_syscall_2(__NR_gettimeofday, (unsigned long)_tv, (unsigned long)_tz);
45 static __always_inline
46 int clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
48 return do_syscall_2(__NR_clock_gettime, _clkid, (unsigned long)_ts);
51 static __always_inline
52 int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
54 return do_syscall_2(__NR_clock_getres, _clkid, (unsigned long)_ts);
59 #define BUILD_VDSO32 1
61 static __always_inline
62 int clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
64 return do_syscall_2(__NR_clock_gettime64, _clkid, (unsigned long)_ts);
67 static __always_inline
68 int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
70 return do_syscall_2(__NR_clock_getres_time64, _clkid, (unsigned long)_ts);
73 static __always_inline
74 int clock_gettime32_fallback(clockid_t _clkid, struct old_timespec32 *_ts)
76 return do_syscall_2(__NR_clock_gettime, _clkid, (unsigned long)_ts);
79 static __always_inline
80 int clock_getres32_fallback(clockid_t _clkid, struct old_timespec32 *_ts)
82 return do_syscall_2(__NR_clock_getres, _clkid, (unsigned long)_ts);
86 static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
87 const struct vdso_data *vd)
92 const struct vdso_data *__arch_get_vdso_data(void);
95 static __always_inline
96 const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd)
98 return (void *)vd + PAGE_SIZE;
102 static inline bool vdso_clocksource_ok(const struct vdso_data *vd)
106 #define vdso_clocksource_ok vdso_clocksource_ok
109 * powerpc specific delta calculation.
111 * This variant removes the masking of the subtraction because the
112 * clocksource mask of all VDSO capable clocksources on powerpc is U64_MAX
113 * which would result in a pointless operation. The compiler cannot
114 * optimize it away as the mask comes from the vdso data and is not compile
117 static __always_inline u64 vdso_calc_delta(u64 cycles, u64 last, u64 mask, u32 mult)
119 return (cycles - last) * mult;
121 #define vdso_calc_delta vdso_calc_delta
123 #ifndef __powerpc64__
124 static __always_inline u64 vdso_shift_ns(u64 ns, unsigned long shift)
130 lo |= hi << (32 - shift);
136 return ((u64)hi << 32) | lo;
138 #define vdso_shift_ns vdso_shift_ns
142 int __c_kernel_clock_gettime(clockid_t clock, struct __kernel_timespec *ts,
143 const struct vdso_data *vd);
144 int __c_kernel_clock_getres(clockid_t clock_id, struct __kernel_timespec *res,
145 const struct vdso_data *vd);
147 int __c_kernel_clock_gettime(clockid_t clock, struct old_timespec32 *ts,
148 const struct vdso_data *vd);
149 int __c_kernel_clock_gettime64(clockid_t clock, struct __kernel_timespec *ts,
150 const struct vdso_data *vd);
151 int __c_kernel_clock_getres(clockid_t clock_id, struct old_timespec32 *res,
152 const struct vdso_data *vd);
154 int __c_kernel_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz,
155 const struct vdso_data *vd);
156 __kernel_old_time_t __c_kernel_time(__kernel_old_time_t *time,
157 const struct vdso_data *vd);
158 #endif /* __ASSEMBLY__ */
160 #endif /* _ASM_POWERPC_VDSO_GETTIMEOFDAY_H */