1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) 2018 ARM Limited 4 */ 5 #ifndef __ASM_VDSO_GETTIMEOFDAY_H 6 #define __ASM_VDSO_GETTIMEOFDAY_H 7 8 #ifndef __ASSEMBLY__ 9 10 #include <asm/barrier.h> 11 #include <asm/cp15.h> 12 #include <asm/unistd.h> 13 #include <uapi/linux/time.h> 14 15 #define VDSO_HAS_CLOCK_GETRES 1 16 17 extern struct vdso_data *__get_datapage(void); 18 19 static __always_inline int gettimeofday_fallback( 20 struct __kernel_old_timeval *_tv, 21 struct timezone *_tz) 22 { 23 register struct timezone *tz asm("r1") = _tz; 24 register struct __kernel_old_timeval *tv asm("r0") = _tv; 25 register long ret asm ("r0"); 26 register long nr asm("r7") = __NR_gettimeofday; 27 28 asm volatile( 29 " swi #0\n" 30 : "=r" (ret) 31 : "r" (tv), "r" (tz), "r" (nr) 32 : "memory"); 33 34 return ret; 35 } 36 37 static __always_inline long clock_gettime_fallback( 38 clockid_t _clkid, 39 struct __kernel_timespec *_ts) 40 { 41 register struct __kernel_timespec *ts asm("r1") = _ts; 42 register clockid_t clkid asm("r0") = _clkid; 43 register long ret asm ("r0"); 44 register long nr asm("r7") = __NR_clock_gettime64; 45 46 asm volatile( 47 " swi #0\n" 48 : "=r" (ret) 49 : "r" (clkid), "r" (ts), "r" (nr) 50 : "memory"); 51 52 return ret; 53 } 54 55 static __always_inline int clock_getres_fallback( 56 clockid_t _clkid, 57 struct __kernel_timespec *_ts) 58 { 59 register struct __kernel_timespec *ts asm("r1") = _ts; 60 register clockid_t clkid asm("r0") = _clkid; 61 register long ret asm ("r0"); 62 register long nr asm("r7") = __NR_clock_getres_time64; 63 64 asm volatile( 65 " swi #0\n" 66 : "=r" (ret) 67 : "r" (clkid), "r" (ts), "r" (nr) 68 : "memory"); 69 70 return ret; 71 } 72 73 static __always_inline u64 __arch_get_hw_counter(int clock_mode) 74 { 75 #ifdef CONFIG_ARM_ARCH_TIMER 76 u64 cycle_now; 77 78 if (!clock_mode) 79 return -EINVAL; 80 81 isb(); 82 cycle_now = read_sysreg(CNTVCT); 83 84 return cycle_now; 85 #else 86 return -EINVAL; /* use fallback */ 87 #endif 88 } 89 90 static __always_inline const struct vdso_data *__arch_get_vdso_data(void) 91 { 92 return __get_datapage(); 93 } 94 95 #endif /* !__ASSEMBLY__ */ 96 97 #endif /* __ASM_VDSO_GETTIMEOFDAY_H */ 98