1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright 2006 Andi Kleen, SUSE Labs. 4 */ 5 6 #ifndef _ASM_SPARC_VDSO_GETTIMEOFDAY_H 7 #define _ASM_SPARC_VDSO_GETTIMEOFDAY_H 8 9 #include <uapi/linux/time.h> 10 #include <uapi/linux/unistd.h> 11 12 #include <vdso/align.h> 13 #include <vdso/clocksource.h> 14 #include <vdso/datapage.h> 15 #include <vdso/page.h> 16 17 #include <linux/types.h> 18 19 #ifdef CONFIG_SPARC64 20 static __always_inline u64 vread_tick(void) 21 { 22 u64 ret; 23 24 __asm__ __volatile__("rd %%tick, %0" : "=r" (ret)); 25 return ret; 26 } 27 28 static __always_inline u64 vread_tick_stick(void) 29 { 30 u64 ret; 31 32 __asm__ __volatile__("rd %%asr24, %0" : "=r" (ret)); 33 return ret; 34 } 35 #else 36 static __always_inline u64 vdso_shift_ns(u64 val, u32 amt) 37 { 38 u64 ret; 39 40 __asm__ __volatile__("sllx %H1, 32, %%g1\n\t" 41 "srl %L1, 0, %L1\n\t" 42 "or %%g1, %L1, %%g1\n\t" 43 "srlx %%g1, %2, %L0\n\t" 44 "srlx %L0, 32, %H0" 45 : "=r" (ret) 46 : "r" (val), "r" (amt) 47 : "g1"); 48 return ret; 49 } 50 #define vdso_shift_ns vdso_shift_ns 51 52 static __always_inline u64 vread_tick(void) 53 { 54 register unsigned long long ret asm("o4"); 55 56 __asm__ __volatile__("rd %%tick, %L0\n\t" 57 "srlx %L0, 32, %H0" 58 : "=r" (ret)); 59 return ret; 60 } 61 62 static __always_inline u64 vread_tick_stick(void) 63 { 64 register unsigned long long ret asm("o4"); 65 66 __asm__ __volatile__("rd %%asr24, %L0\n\t" 67 "srlx %L0, 32, %H0" 68 : "=r" (ret)); 69 return ret; 70 } 71 #endif 72 73 static __always_inline u64 __arch_get_hw_counter(s32 clock_mode, const struct vdso_time_data *vd) 74 { 75 if (likely(clock_mode == VDSO_CLOCKMODE_STICK)) 76 return vread_tick_stick(); 77 else 78 return vread_tick(); 79 } 80 81 #ifdef CONFIG_SPARC64 82 #define SYSCALL_STRING \ 83 "ta 0x6d;" \ 84 "bcs,a 1f;" \ 85 " sub %%g0, %%o0, %%o0;" \ 86 "1:" 87 #else 88 #define SYSCALL_STRING \ 89 "ta 0x10;" \ 90 "bcs,a 1f;" \ 91 " sub %%g0, %%o0, %%o0;" \ 92 "1:" 93 #endif 94 95 #define SYSCALL_CLOBBERS \ 96 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \ 97 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \ 98 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \ 99 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \ 100 "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", \ 101 "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62", \ 102 "cc", "memory" 103 104 #ifdef CONFIG_SPARC64 105 106 static __always_inline 107 long clock_gettime_fallback(clockid_t clock, struct __kernel_timespec *ts) 108 { 109 register long num __asm__("g1") = __NR_clock_gettime; 110 register long o0 __asm__("o0") = clock; 111 register long o1 __asm__("o1") = (long) ts; 112 113 __asm__ __volatile__(SYSCALL_STRING : "=r" (o0) : "r" (num), 114 "0" (o0), "r" (o1) : SYSCALL_CLOBBERS); 115 return o0; 116 } 117 118 #else /* !CONFIG_SPARC64 */ 119 120 static __always_inline 121 long clock_gettime_fallback(clockid_t clock, struct __kernel_timespec *ts) 122 { 123 register long num __asm__("g1") = __NR_clock_gettime64; 124 register long o0 __asm__("o0") = clock; 125 register long o1 __asm__("o1") = (long) ts; 126 127 __asm__ __volatile__(SYSCALL_STRING : "=r" (o0) : "r" (num), 128 "0" (o0), "r" (o1) : SYSCALL_CLOBBERS); 129 return o0; 130 } 131 132 static __always_inline 133 long clock_gettime32_fallback(clockid_t clock, struct old_timespec32 *ts) 134 { 135 register long num __asm__("g1") = __NR_clock_gettime; 136 register long o0 __asm__("o0") = clock; 137 register long o1 __asm__("o1") = (long) ts; 138 139 __asm__ __volatile__(SYSCALL_STRING : "=r" (o0) : "r" (num), 140 "0" (o0), "r" (o1) : SYSCALL_CLOBBERS); 141 return o0; 142 } 143 144 #endif /* CONFIG_SPARC64 */ 145 146 static __always_inline 147 long gettimeofday_fallback(struct __kernel_old_timeval *tv, struct timezone *tz) 148 { 149 register long num __asm__("g1") = __NR_gettimeofday; 150 register long o0 __asm__("o0") = (long) tv; 151 register long o1 __asm__("o1") = (long) tz; 152 153 __asm__ __volatile__(SYSCALL_STRING : "=r" (o0) : "r" (num), 154 "0" (o0), "r" (o1) : SYSCALL_CLOBBERS); 155 return o0; 156 } 157 158 static __always_inline const struct vdso_time_data *__arch_get_vdso_u_time_data(void) 159 { 160 unsigned long ret; 161 162 /* 163 * SPARC does not support native PC-relative code relocations. 164 * Calculate the address manually, works for 32 and 64 bit code. 165 */ 166 __asm__ __volatile__( 167 "1:\n" 168 "call 3f\n" // Jump over the embedded data and set up %o7 169 "nop\n" // Delay slot 170 "2:\n" 171 ".word vdso_u_time_data - .\n" // Embedded offset to external symbol 172 "3:\n" 173 "add %%o7, 2b - 1b, %%o7\n" // Point %o7 to the embedded offset 174 "ldsw [%%o7], %0\n" // Load the offset 175 "add %0, %%o7, %0\n" // Calculate the absolute address 176 : "=r" (ret) 177 : 178 : "o7"); 179 180 return (const struct vdso_time_data *)ret; 181 } 182 #define __arch_get_vdso_u_time_data __arch_get_vdso_u_time_data 183 184 #endif /* _ASM_SPARC_VDSO_GETTIMEOFDAY_H */ 185