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
23 static __always_inline
long gettimeofday_fallback(
24 struct __kernel_old_timeval
*_tv
,
27 register struct timezone
*tz
asm("a1") = _tz
;
28 register struct __kernel_old_timeval
*tv
asm("a0") = _tv
;
29 register long ret
asm("v0");
30 register long nr
asm("v0") = __NR_gettimeofday
;
31 register long error
asm("a3");
35 : "=r" (ret
), "=r" (error
)
36 : "r" (tv
), "r" (tz
), "r" (nr
)
37 : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
38 "$14", "$15", "$24", "$25", "hi", "lo", "memory");
40 return error
? -ret
: ret
;
43 static __always_inline
long clock_gettime_fallback(
45 struct __kernel_timespec
*_ts
)
47 register struct __kernel_timespec
*ts
asm("a1") = _ts
;
48 register clockid_t clkid
asm("a0") = _clkid
;
49 register long ret
asm("v0");
50 #if _MIPS_SIM == _MIPS_SIM_ABI64
51 register long nr
asm("v0") = __NR_clock_gettime
;
53 register long nr
asm("v0") = __NR_clock_gettime64
;
55 register long error
asm("a3");
59 : "=r" (ret
), "=r" (error
)
60 : "r" (clkid
), "r" (ts
), "r" (nr
)
61 : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
62 "$14", "$15", "$24", "$25", "hi", "lo", "memory");
64 return error
? -ret
: ret
;
67 static __always_inline
int clock_getres_fallback(
69 struct __kernel_timespec
*_ts
)
71 register struct __kernel_timespec
*ts
asm("a1") = _ts
;
72 register clockid_t clkid
asm("a0") = _clkid
;
73 register long ret
asm("v0");
74 #if _MIPS_SIM == _MIPS_SIM_ABI64
75 register long nr
asm("v0") = __NR_clock_getres
;
77 register long nr
asm("v0") = __NR_clock_getres_time64
;
79 register long error
asm("a3");
83 : "=r" (ret
), "=r" (error
)
84 : "r" (clkid
), "r" (ts
), "r" (nr
)
85 : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
86 "$14", "$15", "$24", "$25", "hi", "lo", "memory");
88 return error
? -ret
: ret
;
91 #if _MIPS_SIM != _MIPS_SIM_ABI64
93 static __always_inline
long clock_gettime32_fallback(
95 struct old_timespec32
*_ts
)
97 register struct old_timespec32
*ts
asm("a1") = _ts
;
98 register clockid_t clkid
asm("a0") = _clkid
;
99 register long ret
asm("v0");
100 register long nr
asm("v0") = __NR_clock_gettime
;
101 register long error
asm("a3");
105 : "=r" (ret
), "=r" (error
)
106 : "r" (clkid
), "r" (ts
), "r" (nr
)
107 : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
108 "$14", "$15", "$24", "$25", "hi", "lo", "memory");
110 return error
? -ret
: ret
;
113 static __always_inline
int clock_getres32_fallback(
115 struct old_timespec32
*_ts
)
117 register struct old_timespec32
*ts
asm("a1") = _ts
;
118 register clockid_t clkid
asm("a0") = _clkid
;
119 register long ret
asm("v0");
120 register long nr
asm("v0") = __NR_clock_getres
;
121 register long error
asm("a3");
125 : "=r" (ret
), "=r" (error
)
126 : "r" (clkid
), "r" (ts
), "r" (nr
)
127 : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
128 "$14", "$15", "$24", "$25", "hi", "lo", "memory");
130 return error
? -ret
: ret
;
134 #ifdef CONFIG_CSRC_R4K
136 static __always_inline u64
read_r4k_count(void)
140 __asm__
__volatile__(
152 #ifdef CONFIG_CLKSRC_MIPS_GIC
154 static __always_inline u64
read_gic_count(const struct vdso_data
*data
)
156 void __iomem
*gic
= get_gic(data
);
160 hi
= __raw_readl(gic
+ sizeof(lo
));
161 lo
= __raw_readl(gic
);
162 hi2
= __raw_readl(gic
+ sizeof(lo
));
165 return (((u64
)hi
) << 32) + lo
;
170 static __always_inline u64
__arch_get_hw_counter(s32 clock_mode
,
171 const struct vdso_data
*vd
)
173 #ifdef CONFIG_CSRC_R4K
174 if (clock_mode
== VDSO_CLOCKMODE_R4K
)
175 return read_r4k_count();
177 #ifdef CONFIG_CLKSRC_MIPS_GIC
178 if (clock_mode
== VDSO_CLOCKMODE_GIC
)
179 return read_gic_count(vd
);
182 * Core checks mode already. So this raced against a concurrent
183 * update. Return something. Core will do another round see the
184 * change and fallback to syscall.
189 static inline bool mips_vdso_hres_capable(void)
191 return IS_ENABLED(CONFIG_CSRC_R4K
) ||
192 IS_ENABLED(CONFIG_CLKSRC_MIPS_GIC
);
194 #define __arch_vdso_hres_capable mips_vdso_hres_capable
196 static __always_inline
const struct vdso_data
*__arch_get_vdso_data(void)
198 return get_vdso_data();
201 #endif /* !__ASSEMBLY__ */
203 #endif /* __ASM_VDSO_GETTIMEOFDAY_H */