1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Author: Huacai Chen <chenhuacai@loongson.cn> 4 * Copyright (C) 2020 Loongson Technology Corporation Limited 5 * 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. 10 */ 11#ifndef __ASM_VDSO_GETTIMEOFDAY_H 12#define __ASM_VDSO_GETTIMEOFDAY_H 13 14#ifndef __ASSEMBLY__ 15 16#include <asm/barrier.h> 17#include <asm/unistd.h> 18#include <asm/vdso/vdso.h> 19 20#define VDSO_HAS_CLOCK_GETRES 1 21 22static __always_inline long gettimeofday_fallback( 23 struct __kernel_old_timeval *_tv, 24 struct timezone *_tz) 25{ 26 register struct __kernel_old_timeval *tv asm("a0") = _tv; 27 register struct timezone *tz asm("a1") = _tz; 28 register long nr asm("a7") = __NR_gettimeofday; 29 register long ret asm("a0"); 30 31 asm volatile( 32 " syscall 0\n" 33 : "+r" (ret) 34 : "r" (nr), "r" (tv), "r" (tz) 35 : "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", 36 "$t8", "memory"); 37 38 return ret; 39} 40 41static __always_inline long clock_gettime_fallback( 42 clockid_t _clkid, 43 struct __kernel_timespec *_ts) 44{ 45 register clockid_t clkid asm("a0") = _clkid; 46 register struct __kernel_timespec *ts asm("a1") = _ts; 47 register long nr asm("a7") = __NR_clock_gettime; 48 register long ret asm("a0"); 49 50 asm volatile( 51 " syscall 0\n" 52 : "+r" (ret) 53 : "r" (nr), "r" (clkid), "r" (ts) 54 : "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", 55 "$t8", "memory"); 56 57 return ret; 58} 59 60static __always_inline int clock_getres_fallback( 61 clockid_t _clkid, 62 struct __kernel_timespec *_ts) 63{ 64 register clockid_t clkid asm("a0") = _clkid; 65 register struct __kernel_timespec *ts asm("a1") = _ts; 66 register long nr asm("a7") = __NR_clock_getres; 67 register long ret asm("a0"); 68 69 asm volatile( 70 " syscall 0\n" 71 : "+r" (ret) 72 : "r" (nr), "r" (clkid), "r" (ts) 73 : "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", 74 "$t8", "memory"); 75 76 return ret; 77} 78 79static __always_inline u64 __arch_get_hw_counter(s32 clock_mode, 80 const struct vdso_data *vd) 81{ 82 uint64_t count; 83 84 __asm__ __volatile__( 85 " rdtime.d %0, $zero\n" 86 : "=r" (count)); 87 88 return count; 89} 90 91static inline bool loongarch_vdso_hres_capable(void) 92{ 93 return true; 94} 95#define __arch_vdso_hres_capable loongarch_vdso_hres_capable 96 97static __always_inline const struct vdso_data *__arch_get_vdso_data(void) 98{ 99 return (const struct vdso_data *)get_vdso_data(); 100} 101 102#ifdef CONFIG_TIME_NS 103static __always_inline const struct vdso_data *__arch_get_timens_vdso_data(void) 104{ 105 return (const struct vdso_data *)(get_vdso_data() + VVAR_TIMENS_PAGE_OFFSET * PAGE_SIZE); 106} 107#endif 108#endif /* !__ASSEMBLY__ */ 109 110#endif /* __ASM_VDSO_GETTIMEOFDAY_H */ 111