1*0d3b051aSGuo Ren /* SPDX-License-Identifier: GPL-2.0 */
2*0d3b051aSGuo Ren 
3*0d3b051aSGuo Ren #ifndef __ASM_VDSO_CSKY_GETTIMEOFDAY_H
4*0d3b051aSGuo Ren #define __ASM_VDSO_CSKY_GETTIMEOFDAY_H
5*0d3b051aSGuo Ren 
6*0d3b051aSGuo Ren #ifndef __ASSEMBLY__
7*0d3b051aSGuo Ren 
8*0d3b051aSGuo Ren #include <asm/barrier.h>
9*0d3b051aSGuo Ren #include <asm/unistd.h>
10*0d3b051aSGuo Ren #include <abi/regdef.h>
11*0d3b051aSGuo Ren #include <uapi/linux/time.h>
12*0d3b051aSGuo Ren 
13*0d3b051aSGuo Ren #define VDSO_HAS_CLOCK_GETRES	1
14*0d3b051aSGuo Ren 
15*0d3b051aSGuo Ren static __always_inline
gettimeofday_fallback(struct __kernel_old_timeval * _tv,struct timezone * _tz)16*0d3b051aSGuo Ren int gettimeofday_fallback(struct __kernel_old_timeval *_tv,
17*0d3b051aSGuo Ren 			  struct timezone *_tz)
18*0d3b051aSGuo Ren {
19*0d3b051aSGuo Ren 	register struct __kernel_old_timeval *tv asm("a0") = _tv;
20*0d3b051aSGuo Ren 	register struct timezone *tz asm("a1") = _tz;
21*0d3b051aSGuo Ren 	register long ret asm("a0");
22*0d3b051aSGuo Ren 	register long nr asm(syscallid) = __NR_gettimeofday;
23*0d3b051aSGuo Ren 
24*0d3b051aSGuo Ren 	asm volatile ("trap 0\n"
25*0d3b051aSGuo Ren 		      : "=r" (ret)
26*0d3b051aSGuo Ren 		      : "r"(tv), "r"(tz), "r"(nr)
27*0d3b051aSGuo Ren 		      : "memory");
28*0d3b051aSGuo Ren 
29*0d3b051aSGuo Ren 	return ret;
30*0d3b051aSGuo Ren }
31*0d3b051aSGuo Ren 
32*0d3b051aSGuo Ren static __always_inline
clock_gettime_fallback(clockid_t _clkid,struct __kernel_timespec * _ts)33*0d3b051aSGuo Ren long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
34*0d3b051aSGuo Ren {
35*0d3b051aSGuo Ren 	register clockid_t clkid asm("a0") = _clkid;
36*0d3b051aSGuo Ren 	register struct __kernel_timespec *ts asm("a1") = _ts;
37*0d3b051aSGuo Ren 	register long ret asm("a0");
38*0d3b051aSGuo Ren 	register long nr asm(syscallid) = __NR_clock_gettime64;
39*0d3b051aSGuo Ren 
40*0d3b051aSGuo Ren 	asm volatile ("trap 0\n"
41*0d3b051aSGuo Ren 		      : "=r" (ret)
42*0d3b051aSGuo Ren 		      : "r"(clkid), "r"(ts), "r"(nr)
43*0d3b051aSGuo Ren 		      : "memory");
44*0d3b051aSGuo Ren 
45*0d3b051aSGuo Ren 	return ret;
46*0d3b051aSGuo Ren }
47*0d3b051aSGuo Ren 
48*0d3b051aSGuo Ren static __always_inline
clock_gettime32_fallback(clockid_t _clkid,struct old_timespec32 * _ts)49*0d3b051aSGuo Ren long clock_gettime32_fallback(clockid_t _clkid, struct old_timespec32 *_ts)
50*0d3b051aSGuo Ren {
51*0d3b051aSGuo Ren 	register clockid_t clkid asm("a0") = _clkid;
52*0d3b051aSGuo Ren 	register struct old_timespec32 *ts asm("a1") = _ts;
53*0d3b051aSGuo Ren 	register long ret asm("a0");
54*0d3b051aSGuo Ren 	register long nr asm(syscallid) = __NR_clock_gettime;
55*0d3b051aSGuo Ren 
56*0d3b051aSGuo Ren 	asm volatile ("trap 0\n"
57*0d3b051aSGuo Ren 		      : "=r" (ret)
58*0d3b051aSGuo Ren 		      : "r"(clkid), "r"(ts), "r"(nr)
59*0d3b051aSGuo Ren 		      : "memory");
60*0d3b051aSGuo Ren 
61*0d3b051aSGuo Ren 	return ret;
62*0d3b051aSGuo Ren }
63*0d3b051aSGuo Ren 
64*0d3b051aSGuo Ren static __always_inline
clock_getres_fallback(clockid_t _clkid,struct __kernel_timespec * _ts)65*0d3b051aSGuo Ren int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
66*0d3b051aSGuo Ren {
67*0d3b051aSGuo Ren 	register clockid_t clkid asm("a0") = _clkid;
68*0d3b051aSGuo Ren 	register struct __kernel_timespec *ts asm("a1") = _ts;
69*0d3b051aSGuo Ren 	register long ret asm("a0");
70*0d3b051aSGuo Ren 	register long nr asm(syscallid) = __NR_clock_getres_time64;
71*0d3b051aSGuo Ren 
72*0d3b051aSGuo Ren 	asm volatile ("trap 0\n"
73*0d3b051aSGuo Ren 		      : "=r" (ret)
74*0d3b051aSGuo Ren 		      : "r"(clkid), "r"(ts), "r"(nr)
75*0d3b051aSGuo Ren 		      : "memory");
76*0d3b051aSGuo Ren 
77*0d3b051aSGuo Ren 	return ret;
78*0d3b051aSGuo Ren }
79*0d3b051aSGuo Ren 
80*0d3b051aSGuo Ren static __always_inline
clock_getres32_fallback(clockid_t _clkid,struct old_timespec32 * _ts)81*0d3b051aSGuo Ren int clock_getres32_fallback(clockid_t _clkid, struct old_timespec32 *_ts)
82*0d3b051aSGuo Ren {
83*0d3b051aSGuo Ren 	register clockid_t clkid asm("a0") = _clkid;
84*0d3b051aSGuo Ren 	register struct old_timespec32 *ts asm("a1") = _ts;
85*0d3b051aSGuo Ren 	register long ret asm("a0");
86*0d3b051aSGuo Ren 	register long nr asm(syscallid) = __NR_clock_getres;
87*0d3b051aSGuo Ren 
88*0d3b051aSGuo Ren 	asm volatile ("trap 0\n"
89*0d3b051aSGuo Ren 		      : "=r" (ret)
90*0d3b051aSGuo Ren 		      : "r"(clkid), "r"(ts), "r"(nr)
91*0d3b051aSGuo Ren 		      : "memory");
92*0d3b051aSGuo Ren 
93*0d3b051aSGuo Ren 	return ret;
94*0d3b051aSGuo Ren }
95*0d3b051aSGuo Ren 
96*0d3b051aSGuo Ren uint64_t csky_pmu_read_cc(void);
__arch_get_hw_counter(s32 clock_mode,const struct vdso_data * vd)97*0d3b051aSGuo Ren static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
98*0d3b051aSGuo Ren 						 const struct vdso_data *vd)
99*0d3b051aSGuo Ren {
100*0d3b051aSGuo Ren #ifdef CONFIG_CSKY_PMU_V1
101*0d3b051aSGuo Ren 	return csky_pmu_read_cc();
102*0d3b051aSGuo Ren #else
103*0d3b051aSGuo Ren 	return 0;
104*0d3b051aSGuo Ren #endif
105*0d3b051aSGuo Ren }
106*0d3b051aSGuo Ren 
__arch_get_vdso_data(void)107*0d3b051aSGuo Ren static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
108*0d3b051aSGuo Ren {
109*0d3b051aSGuo Ren 	return _vdso_data;
110*0d3b051aSGuo Ren }
111*0d3b051aSGuo Ren 
112*0d3b051aSGuo Ren #endif /* !__ASSEMBLY__ */
113*0d3b051aSGuo Ren 
114*0d3b051aSGuo Ren #endif /* __ASM_VDSO_CSKY_GETTIMEOFDAY_H */
115