Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (C) 2018 ARM Limited
0003  * Copyright (C) 2015 Imagination Technologies
0004  * Author: Alex Smith <alex.smith@imgtec.com>
0005  *
0006  * This program is free software; you can redistribute it and/or modify it
0007  * under the terms of the GNU General Public License as published by the
0008  * Free Software Foundation;  either version 2 of the  License, or (at your
0009  * option) any later version.
0010  */
0011 #ifndef __ASM_VDSO_GETTIMEOFDAY_H
0012 #define __ASM_VDSO_GETTIMEOFDAY_H
0013 
0014 #ifndef __ASSEMBLY__
0015 
0016 #include <asm/vdso/vdso.h>
0017 #include <asm/clocksource.h>
0018 #include <asm/unistd.h>
0019 #include <asm/vdso.h>
0020 
0021 #define VDSO_HAS_CLOCK_GETRES       1
0022 
0023 #if MIPS_ISA_REV < 6
0024 #define VDSO_SYSCALL_CLOBBERS "hi", "lo",
0025 #else
0026 #define VDSO_SYSCALL_CLOBBERS
0027 #endif
0028 
0029 static __always_inline long gettimeofday_fallback(
0030                 struct __kernel_old_timeval *_tv,
0031                 struct timezone *_tz)
0032 {
0033     register struct timezone *tz asm("a1") = _tz;
0034     register struct __kernel_old_timeval *tv asm("a0") = _tv;
0035     register long ret asm("v0");
0036     register long nr asm("v0") = __NR_gettimeofday;
0037     register long error asm("a3");
0038 
0039     asm volatile(
0040     "       syscall\n"
0041     : "=r" (ret), "=r" (error)
0042     : "r" (tv), "r" (tz), "r" (nr)
0043     : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
0044       "$14", "$15", "$24", "$25",
0045       VDSO_SYSCALL_CLOBBERS
0046       "memory");
0047 
0048     return error ? -ret : ret;
0049 }
0050 
0051 static __always_inline long clock_gettime_fallback(
0052                     clockid_t _clkid,
0053                     struct __kernel_timespec *_ts)
0054 {
0055     register struct __kernel_timespec *ts asm("a1") = _ts;
0056     register clockid_t clkid asm("a0") = _clkid;
0057     register long ret asm("v0");
0058 #if _MIPS_SIM == _MIPS_SIM_ABI64
0059     register long nr asm("v0") = __NR_clock_gettime;
0060 #else
0061     register long nr asm("v0") = __NR_clock_gettime64;
0062 #endif
0063     register long error asm("a3");
0064 
0065     asm volatile(
0066     "       syscall\n"
0067     : "=r" (ret), "=r" (error)
0068     : "r" (clkid), "r" (ts), "r" (nr)
0069     : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
0070       "$14", "$15", "$24", "$25",
0071       VDSO_SYSCALL_CLOBBERS
0072       "memory");
0073 
0074     return error ? -ret : ret;
0075 }
0076 
0077 static __always_inline int clock_getres_fallback(
0078                     clockid_t _clkid,
0079                     struct __kernel_timespec *_ts)
0080 {
0081     register struct __kernel_timespec *ts asm("a1") = _ts;
0082     register clockid_t clkid asm("a0") = _clkid;
0083     register long ret asm("v0");
0084 #if _MIPS_SIM == _MIPS_SIM_ABI64
0085     register long nr asm("v0") = __NR_clock_getres;
0086 #else
0087     register long nr asm("v0") = __NR_clock_getres_time64;
0088 #endif
0089     register long error asm("a3");
0090 
0091     asm volatile(
0092     "       syscall\n"
0093     : "=r" (ret), "=r" (error)
0094     : "r" (clkid), "r" (ts), "r" (nr)
0095     : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
0096       "$14", "$15", "$24", "$25",
0097       VDSO_SYSCALL_CLOBBERS
0098       "memory");
0099 
0100     return error ? -ret : ret;
0101 }
0102 
0103 #if _MIPS_SIM != _MIPS_SIM_ABI64
0104 
0105 static __always_inline long clock_gettime32_fallback(
0106                     clockid_t _clkid,
0107                     struct old_timespec32 *_ts)
0108 {
0109     register struct old_timespec32 *ts asm("a1") = _ts;
0110     register clockid_t clkid asm("a0") = _clkid;
0111     register long ret asm("v0");
0112     register long nr asm("v0") = __NR_clock_gettime;
0113     register long error asm("a3");
0114 
0115     asm volatile(
0116     "       syscall\n"
0117     : "=r" (ret), "=r" (error)
0118     : "r" (clkid), "r" (ts), "r" (nr)
0119     : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
0120       "$14", "$15", "$24", "$25",
0121       VDSO_SYSCALL_CLOBBERS
0122       "memory");
0123 
0124     return error ? -ret : ret;
0125 }
0126 
0127 static __always_inline int clock_getres32_fallback(
0128                     clockid_t _clkid,
0129                     struct old_timespec32 *_ts)
0130 {
0131     register struct old_timespec32 *ts asm("a1") = _ts;
0132     register clockid_t clkid asm("a0") = _clkid;
0133     register long ret asm("v0");
0134     register long nr asm("v0") = __NR_clock_getres;
0135     register long error asm("a3");
0136 
0137     asm volatile(
0138     "       syscall\n"
0139     : "=r" (ret), "=r" (error)
0140     : "r" (clkid), "r" (ts), "r" (nr)
0141     : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
0142       "$14", "$15", "$24", "$25",
0143       VDSO_SYSCALL_CLOBBERS
0144       "memory");
0145 
0146     return error ? -ret : ret;
0147 }
0148 #endif
0149 
0150 #ifdef CONFIG_CSRC_R4K
0151 
0152 static __always_inline u64 read_r4k_count(void)
0153 {
0154     unsigned int count;
0155 
0156     __asm__ __volatile__(
0157     "   .set push\n"
0158     "   .set mips32r2\n"
0159     "   rdhwr   %0, $2\n"
0160     "   .set pop\n"
0161     : "=r" (count));
0162 
0163     return count;
0164 }
0165 
0166 #endif
0167 
0168 #ifdef CONFIG_CLKSRC_MIPS_GIC
0169 
0170 static __always_inline u64 read_gic_count(const struct vdso_data *data)
0171 {
0172     void __iomem *gic = get_gic(data);
0173     u32 hi, hi2, lo;
0174 
0175     do {
0176         hi = __raw_readl(gic + sizeof(lo));
0177         lo = __raw_readl(gic);
0178         hi2 = __raw_readl(gic + sizeof(lo));
0179     } while (hi2 != hi);
0180 
0181     return (((u64)hi) << 32) + lo;
0182 }
0183 
0184 #endif
0185 
0186 static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
0187                          const struct vdso_data *vd)
0188 {
0189 #ifdef CONFIG_CSRC_R4K
0190     if (clock_mode == VDSO_CLOCKMODE_R4K)
0191         return read_r4k_count();
0192 #endif
0193 #ifdef CONFIG_CLKSRC_MIPS_GIC
0194     if (clock_mode == VDSO_CLOCKMODE_GIC)
0195         return read_gic_count(vd);
0196 #endif
0197     /*
0198      * Core checks mode already. So this raced against a concurrent
0199      * update. Return something. Core will do another round see the
0200      * change and fallback to syscall.
0201      */
0202     return 0;
0203 }
0204 
0205 static inline bool mips_vdso_hres_capable(void)
0206 {
0207     return IS_ENABLED(CONFIG_CSRC_R4K) ||
0208            IS_ENABLED(CONFIG_CLKSRC_MIPS_GIC);
0209 }
0210 #define __arch_vdso_hres_capable mips_vdso_hres_capable
0211 
0212 static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
0213 {
0214     return get_vdso_data();
0215 }
0216 
0217 #endif /* !__ASSEMBLY__ */
0218 
0219 #endif /* __ASM_VDSO_GETTIMEOFDAY_H */