2 * Copyright (C) 2018 ARM Limited
3 * Copyright (C) 2015 Imagination Technologies
4 * Author: Alex Smith <alex.smith@imgtec.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
11 #ifndef __ASM_VDSO_GETTIMEOFDAY_H
12 #define __ASM_VDSO_GETTIMEOFDAY_H
16 #include <asm/vdso/vdso.h>
17 #include <asm/clocksource.h>
18 #include <asm/unistd.h>
21 #define VDSO_HAS_CLOCK_GETRES 1
24 #define VDSO_SYSCALL_CLOBBERS "hi", "lo",
26 #define VDSO_SYSCALL_CLOBBERS
29 static __always_inline
long gettimeofday_fallback(
30 struct __kernel_old_timeval
*_tv
,
33 register struct timezone
*tz
asm("a1") = _tz
;
34 register struct __kernel_old_timeval
*tv
asm("a0") = _tv
;
35 register long ret
asm("v0");
36 register long nr
asm("v0") = __NR_gettimeofday
;
37 register long error
asm("a3");
41 : "=r" (ret
), "=r" (error
)
42 : "r" (tv
), "r" (tz
), "r" (nr
)
43 : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
44 "$14", "$15", "$24", "$25",
48 return error
? -ret
: ret
;
51 static __always_inline
long clock_gettime_fallback(
53 struct __kernel_timespec
*_ts
)
55 register struct __kernel_timespec
*ts
asm("a1") = _ts
;
56 register clockid_t clkid
asm("a0") = _clkid
;
57 register long ret
asm("v0");
58 #if _MIPS_SIM == _MIPS_SIM_ABI64
59 register long nr
asm("v0") = __NR_clock_gettime
;
61 register long nr
asm("v0") = __NR_clock_gettime64
;
63 register long error
asm("a3");
67 : "=r" (ret
), "=r" (error
)
68 : "r" (clkid
), "r" (ts
), "r" (nr
)
69 : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
70 "$14", "$15", "$24", "$25",
74 return error
? -ret
: ret
;
77 static __always_inline
int clock_getres_fallback(
79 struct __kernel_timespec
*_ts
)
81 register struct __kernel_timespec
*ts
asm("a1") = _ts
;
82 register clockid_t clkid
asm("a0") = _clkid
;
83 register long ret
asm("v0");
84 #if _MIPS_SIM == _MIPS_SIM_ABI64
85 register long nr
asm("v0") = __NR_clock_getres
;
87 register long nr
asm("v0") = __NR_clock_getres_time64
;
89 register long error
asm("a3");
93 : "=r" (ret
), "=r" (error
)
94 : "r" (clkid
), "r" (ts
), "r" (nr
)
95 : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
96 "$14", "$15", "$24", "$25",
100 return error
? -ret
: ret
;
103 #if _MIPS_SIM != _MIPS_SIM_ABI64
105 static __always_inline
long clock_gettime32_fallback(
107 struct old_timespec32
*_ts
)
109 register struct old_timespec32
*ts
asm("a1") = _ts
;
110 register clockid_t clkid
asm("a0") = _clkid
;
111 register long ret
asm("v0");
112 register long nr
asm("v0") = __NR_clock_gettime
;
113 register long error
asm("a3");
117 : "=r" (ret
), "=r" (error
)
118 : "r" (clkid
), "r" (ts
), "r" (nr
)
119 : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
120 "$14", "$15", "$24", "$25",
121 VDSO_SYSCALL_CLOBBERS
124 return error
? -ret
: ret
;
127 static __always_inline
int clock_getres32_fallback(
129 struct old_timespec32
*_ts
)
131 register struct old_timespec32
*ts
asm("a1") = _ts
;
132 register clockid_t clkid
asm("a0") = _clkid
;
133 register long ret
asm("v0");
134 register long nr
asm("v0") = __NR_clock_getres
;
135 register long error
asm("a3");
139 : "=r" (ret
), "=r" (error
)
140 : "r" (clkid
), "r" (ts
), "r" (nr
)
141 : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
142 "$14", "$15", "$24", "$25",
143 VDSO_SYSCALL_CLOBBERS
146 return error
? -ret
: ret
;
150 #ifdef CONFIG_CSRC_R4K
152 static __always_inline u64
read_r4k_count(void)
156 __asm__
__volatile__(
168 #ifdef CONFIG_CLKSRC_MIPS_GIC
170 static __always_inline u64
read_gic_count(const struct vdso_data
*data
)
172 void __iomem
*gic
= get_gic(data
);
176 hi
= __raw_readl(gic
+ sizeof(lo
));
177 lo
= __raw_readl(gic
);
178 hi2
= __raw_readl(gic
+ sizeof(lo
));
181 return (((u64
)hi
) << 32) + lo
;
186 static __always_inline u64
__arch_get_hw_counter(s32 clock_mode
,
187 const struct vdso_data
*vd
)
189 #ifdef CONFIG_CSRC_R4K
190 if (clock_mode
== VDSO_CLOCKMODE_R4K
)
191 return read_r4k_count();
193 #ifdef CONFIG_CLKSRC_MIPS_GIC
194 if (clock_mode
== VDSO_CLOCKMODE_GIC
)
195 return read_gic_count(vd
);
198 * Core checks mode already. So this raced against a concurrent
199 * update. Return something. Core will do another round see the
200 * change and fallback to syscall.
205 static inline bool mips_vdso_hres_capable(void)
207 return IS_ENABLED(CONFIG_CSRC_R4K
) ||
208 IS_ENABLED(CONFIG_CLKSRC_MIPS_GIC
);
210 #define __arch_vdso_hres_capable mips_vdso_hres_capable
212 static __always_inline
const struct vdso_data
*__arch_get_vdso_data(void)
214 return get_vdso_data();
217 #endif /* !__ASSEMBLY__ */
219 #endif /* __ASM_VDSO_GETTIMEOFDAY_H */