2019-06-21 10:52:37 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 ARM Limited
|
|
|
|
*/
|
|
|
|
#ifndef __ASM_VDSO_GETTIMEOFDAY_H
|
|
|
|
#define __ASM_VDSO_GETTIMEOFDAY_H
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
2020-07-10 14:49:40 +01:00
|
|
|
#include <asm/barrier.h>
|
2024-05-08 23:50:07 +02:00
|
|
|
#include <asm/unistd_compat_32.h>
|
2020-03-20 14:53:46 +00:00
|
|
|
#include <asm/errno.h>
|
2019-06-21 10:52:37 +01:00
|
|
|
|
|
|
|
#include <asm/vdso/compat_barrier.h>
|
|
|
|
|
|
|
|
#define VDSO_HAS_CLOCK_GETRES 1
|
|
|
|
|
2019-08-30 14:58:55 +01:00
|
|
|
#define BUILD_VDSO32 1
|
2019-07-28 15:12:56 +02:00
|
|
|
|
2019-06-21 10:52:37 +01:00
|
|
|
static __always_inline
|
|
|
|
int gettimeofday_fallback(struct __kernel_old_timeval *_tv,
|
|
|
|
struct timezone *_tz)
|
|
|
|
{
|
|
|
|
register struct timezone *tz asm("r1") = _tz;
|
|
|
|
register struct __kernel_old_timeval *tv asm("r0") = _tv;
|
|
|
|
register long ret asm ("r0");
|
2024-05-08 23:50:07 +02:00
|
|
|
register long nr asm("r7") = __NR_compat32_gettimeofday;
|
2019-06-21 10:52:37 +01:00
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
" swi #0\n"
|
|
|
|
: "=r" (ret)
|
|
|
|
: "r" (tv), "r" (tz), "r" (nr)
|
|
|
|
: "memory");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline
|
|
|
|
long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
|
|
|
|
{
|
|
|
|
register struct __kernel_timespec *ts asm("r1") = _ts;
|
|
|
|
register clockid_t clkid asm("r0") = _clkid;
|
|
|
|
register long ret asm ("r0");
|
2024-05-08 23:50:07 +02:00
|
|
|
register long nr asm("r7") = __NR_compat32_clock_gettime64;
|
2019-06-21 10:52:37 +01:00
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
" swi #0\n"
|
|
|
|
: "=r" (ret)
|
|
|
|
: "r" (clkid), "r" (ts), "r" (nr)
|
|
|
|
: "memory");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-28 15:12:56 +02:00
|
|
|
static __always_inline
|
|
|
|
long clock_gettime32_fallback(clockid_t _clkid, struct old_timespec32 *_ts)
|
|
|
|
{
|
|
|
|
register struct old_timespec32 *ts asm("r1") = _ts;
|
|
|
|
register clockid_t clkid asm("r0") = _clkid;
|
|
|
|
register long ret asm ("r0");
|
2024-05-08 23:50:07 +02:00
|
|
|
register long nr asm("r7") = __NR_compat32_clock_gettime;
|
2019-07-28 15:12:56 +02:00
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
" swi #0\n"
|
|
|
|
: "=r" (ret)
|
|
|
|
: "r" (clkid), "r" (ts), "r" (nr)
|
|
|
|
: "memory");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-21 10:52:37 +01:00
|
|
|
static __always_inline
|
|
|
|
int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
|
|
|
|
{
|
|
|
|
register struct __kernel_timespec *ts asm("r1") = _ts;
|
|
|
|
register clockid_t clkid asm("r0") = _clkid;
|
|
|
|
register long ret asm ("r0");
|
2024-05-08 23:50:07 +02:00
|
|
|
register long nr asm("r7") = __NR_compat32_clock_getres_time64;
|
2019-06-21 10:52:37 +01:00
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
" swi #0\n"
|
|
|
|
: "=r" (ret)
|
|
|
|
: "r" (clkid), "r" (ts), "r" (nr)
|
|
|
|
: "memory");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-28 15:12:56 +02:00
|
|
|
static __always_inline
|
|
|
|
int clock_getres32_fallback(clockid_t _clkid, struct old_timespec32 *_ts)
|
|
|
|
{
|
|
|
|
register struct old_timespec32 *ts asm("r1") = _ts;
|
|
|
|
register clockid_t clkid asm("r0") = _clkid;
|
|
|
|
register long ret asm ("r0");
|
2024-05-08 23:50:07 +02:00
|
|
|
register long nr asm("r7") = __NR_compat32_clock_getres;
|
2019-07-28 15:12:56 +02:00
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
" swi #0\n"
|
|
|
|
: "=r" (ret)
|
|
|
|
: "r" (clkid), "r" (ts), "r" (nr)
|
|
|
|
: "memory");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-08-04 22:37:48 +02:00
|
|
|
static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
|
2025-02-04 13:05:40 +01:00
|
|
|
const struct vdso_time_data *vd)
|
2019-06-21 10:52:37 +01:00
|
|
|
{
|
|
|
|
u64 res;
|
|
|
|
|
2019-06-25 17:18:04 +01:00
|
|
|
/*
|
2020-02-07 13:38:58 +01:00
|
|
|
* Core checks for mode already, so this raced against a concurrent
|
|
|
|
* update. Return something. Core will do another round and then
|
|
|
|
* see the mode change and fallback to the syscall.
|
2019-06-25 17:18:04 +01:00
|
|
|
*/
|
2020-07-06 17:37:59 +01:00
|
|
|
if (clock_mode != VDSO_CLOCKMODE_ARCHTIMER)
|
2020-02-07 13:38:58 +01:00
|
|
|
return 0;
|
2019-06-25 17:18:04 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This isb() is required to prevent that the counter value
|
|
|
|
* is speculated.
|
|
|
|
*/
|
2019-06-21 10:52:37 +01:00
|
|
|
isb();
|
|
|
|
asm volatile("mrrc p15, 1, %Q0, %R0, c14" : "=r" (res));
|
2019-06-25 17:18:04 +01:00
|
|
|
/*
|
|
|
|
* This isb() is required to prevent that the seq lock is
|
|
|
|
* speculated.
|
|
|
|
*/
|
|
|
|
isb();
|
2019-06-21 10:52:37 +01:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2025-02-04 13:05:40 +01:00
|
|
|
static __always_inline const struct vdso_time_data *__arch_get_vdso_u_time_data(void)
|
2019-06-21 10:52:37 +01:00
|
|
|
{
|
2025-02-04 13:05:40 +01:00
|
|
|
const struct vdso_time_data *ret;
|
2019-06-21 10:52:37 +01:00
|
|
|
|
|
|
|
/*
|
2025-02-04 13:05:40 +01:00
|
|
|
* This simply puts &_vdso_time_data into ret. The reason why we don't use
|
|
|
|
* `ret = _vdso_time_data` is that the compiler tends to optimise this in a
|
|
|
|
* very suboptimal way: instead of keeping &_vdso_time_data in a register,
|
|
|
|
* it goes through a relocation almost every time _vdso_time_data must be
|
2019-06-21 10:52:37 +01:00
|
|
|
* accessed (even in subfunctions). This is both time and space
|
|
|
|
* consuming: each relocation uses a word in the code section, and it
|
|
|
|
* has to be loaded at runtime.
|
|
|
|
*
|
|
|
|
* This trick hides the assignment from the compiler. Since it cannot
|
|
|
|
* track where the pointer comes from, it will only use one relocation
|
2025-02-04 13:05:40 +01:00
|
|
|
* where __aarch64_get_vdso_u_time_data() is called, and then keep the
|
|
|
|
* result in a register.
|
2019-06-21 10:52:37 +01:00
|
|
|
*/
|
2025-03-03 12:11:21 +01:00
|
|
|
asm volatile("mov %0, %1" : "=r"(ret) : "r"(&vdso_u_time_data));
|
2019-06-21 10:52:37 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2025-02-04 13:05:40 +01:00
|
|
|
#define __arch_get_vdso_u_time_data __arch_get_vdso_u_time_data
|
2019-06-21 10:52:37 +01:00
|
|
|
|
2025-03-03 12:11:18 +01:00
|
|
|
static inline bool vdso_clocksource_ok(const struct vdso_clock *vc)
|
2020-07-06 17:37:59 +01:00
|
|
|
{
|
2025-03-03 12:11:18 +01:00
|
|
|
return vc->clock_mode == VDSO_CLOCKMODE_ARCHTIMER;
|
2020-07-06 17:37:59 +01:00
|
|
|
}
|
|
|
|
#define vdso_clocksource_ok vdso_clocksource_ok
|
|
|
|
|
2019-06-21 10:52:37 +01:00
|
|
|
#endif /* !__ASSEMBLY__ */
|
|
|
|
|
|
|
|
#endif /* __ASM_VDSO_GETTIMEOFDAY_H */
|