.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
---|
1 | 2 | /* |
---|
2 | 3 | * arch/arm64/include/asm/arch_timer.h |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2012 ARM Ltd. |
---|
5 | 6 | * Author: Marc Zyngier <marc.zyngier@arm.com> |
---|
6 | | - * |
---|
7 | | - * This program is free software: you can redistribute it and/or modify |
---|
8 | | - * it under the terms of the GNU General Public License version 2 as |
---|
9 | | - * published by the Free Software Foundation. |
---|
10 | | - * |
---|
11 | | - * This program is distributed in the hope that it will be useful, |
---|
12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | | - * GNU General Public License for more details. |
---|
15 | | - * |
---|
16 | | - * You should have received a copy of the GNU General Public License |
---|
17 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | 7 | */ |
---|
19 | 8 | #ifndef __ASM_ARCH_TIMER_H |
---|
20 | 9 | #define __ASM_ARCH_TIMER_H |
---|
21 | 10 | |
---|
22 | 11 | #include <asm/barrier.h> |
---|
| 12 | +#include <asm/hwcap.h> |
---|
23 | 13 | #include <asm/sysreg.h> |
---|
24 | 14 | |
---|
25 | 15 | #include <linux/bug.h> |
---|
.. | .. |
---|
31 | 21 | #include <clocksource/arm_arch_timer.h> |
---|
32 | 22 | |
---|
33 | 23 | #if IS_ENABLED(CONFIG_ARM_ARCH_TIMER_OOL_WORKAROUND) |
---|
34 | | -extern struct static_key_false arch_timer_read_ool_enabled; |
---|
35 | | -#define needs_unstable_timer_counter_workaround() \ |
---|
36 | | - static_branch_unlikely(&arch_timer_read_ool_enabled) |
---|
| 24 | +#define has_erratum_handler(h) \ |
---|
| 25 | + ({ \ |
---|
| 26 | + const struct arch_timer_erratum_workaround *__wa; \ |
---|
| 27 | + __wa = __this_cpu_read(timer_unstable_counter_workaround); \ |
---|
| 28 | + (__wa && __wa->h); \ |
---|
| 29 | + }) |
---|
| 30 | + |
---|
| 31 | +#define erratum_handler(h) \ |
---|
| 32 | + ({ \ |
---|
| 33 | + const struct arch_timer_erratum_workaround *__wa; \ |
---|
| 34 | + __wa = __this_cpu_read(timer_unstable_counter_workaround); \ |
---|
| 35 | + (__wa && __wa->h) ? __wa->h : arch_timer_##h; \ |
---|
| 36 | + }) |
---|
| 37 | + |
---|
37 | 38 | #else |
---|
38 | | -#define needs_unstable_timer_counter_workaround() false |
---|
| 39 | +#define has_erratum_handler(h) false |
---|
| 40 | +#define erratum_handler(h) (arch_timer_##h) |
---|
39 | 41 | #endif |
---|
40 | 42 | |
---|
41 | 43 | enum arch_timer_erratum_match_type { |
---|
.. | .. |
---|
56 | 58 | u64 (*read_cntvct_el0)(void); |
---|
57 | 59 | int (*set_next_event_phys)(unsigned long, struct clock_event_device *); |
---|
58 | 60 | int (*set_next_event_virt)(unsigned long, struct clock_event_device *); |
---|
| 61 | + bool disable_compat_vdso; |
---|
59 | 62 | }; |
---|
60 | 63 | |
---|
61 | 64 | DECLARE_PER_CPU(const struct arch_timer_erratum_workaround *, |
---|
62 | 65 | timer_unstable_counter_workaround); |
---|
63 | 66 | |
---|
| 67 | +/* inline sysreg accessors that make erratum_handler() work */ |
---|
| 68 | +static inline notrace u32 arch_timer_read_cntp_tval_el0(void) |
---|
| 69 | +{ |
---|
| 70 | + return read_sysreg(cntp_tval_el0); |
---|
| 71 | +} |
---|
| 72 | + |
---|
| 73 | +static inline notrace u32 arch_timer_read_cntv_tval_el0(void) |
---|
| 74 | +{ |
---|
| 75 | + return read_sysreg(cntv_tval_el0); |
---|
| 76 | +} |
---|
| 77 | + |
---|
| 78 | +static inline notrace u64 arch_timer_read_cntpct_el0(void) |
---|
| 79 | +{ |
---|
| 80 | + return read_sysreg(cntpct_el0); |
---|
| 81 | +} |
---|
| 82 | + |
---|
| 83 | +static inline notrace u64 arch_timer_read_cntvct_el0(void) |
---|
| 84 | +{ |
---|
| 85 | + return read_sysreg(cntvct_el0); |
---|
| 86 | +} |
---|
| 87 | + |
---|
64 | 88 | #define arch_timer_reg_read_stable(reg) \ |
---|
65 | | -({ \ |
---|
66 | | - u64 _val; \ |
---|
67 | | - if (needs_unstable_timer_counter_workaround()) { \ |
---|
68 | | - const struct arch_timer_erratum_workaround *wa; \ |
---|
| 89 | + ({ \ |
---|
| 90 | + u64 _val; \ |
---|
| 91 | + \ |
---|
69 | 92 | preempt_disable_notrace(); \ |
---|
70 | | - wa = __this_cpu_read(timer_unstable_counter_workaround); \ |
---|
71 | | - if (wa && wa->read_##reg) \ |
---|
72 | | - _val = wa->read_##reg(); \ |
---|
73 | | - else \ |
---|
74 | | - _val = read_sysreg(reg); \ |
---|
| 93 | + _val = erratum_handler(read_ ## reg)(); \ |
---|
75 | 94 | preempt_enable_notrace(); \ |
---|
76 | | - } else { \ |
---|
77 | | - _val = read_sysreg(reg); \ |
---|
78 | | - } \ |
---|
79 | | - _val; \ |
---|
80 | | -}) |
---|
| 95 | + \ |
---|
| 96 | + _val; \ |
---|
| 97 | + }) |
---|
81 | 98 | |
---|
82 | 99 | /* |
---|
83 | 100 | * These register accessors are marked inline so the compiler can |
---|
.. | .. |
---|
148 | 165 | isb(); |
---|
149 | 166 | } |
---|
150 | 167 | |
---|
151 | | -/* |
---|
152 | | - * Ensure that reads of the counter are treated the same as memory reads |
---|
153 | | - * for the purposes of ordering by subsequent memory barriers. |
---|
154 | | - * |
---|
155 | | - * This insanity brought to you by speculative system register reads, |
---|
156 | | - * out-of-order memory accesses, sequence locks and Thomas Gleixner. |
---|
157 | | - * |
---|
158 | | - * http://lists.infradead.org/pipermail/linux-arm-kernel/2019-February/631195.html |
---|
159 | | - */ |
---|
160 | | -#define arch_counter_enforce_ordering(val) do { \ |
---|
161 | | - u64 tmp, _val = (val); \ |
---|
162 | | - \ |
---|
163 | | - asm volatile( \ |
---|
164 | | - " eor %0, %1, %1\n" \ |
---|
165 | | - " add %0, sp, %0\n" \ |
---|
166 | | - " ldr xzr, [%0]" \ |
---|
167 | | - : "=r" (tmp) : "r" (_val)); \ |
---|
168 | | -} while (0) |
---|
169 | | - |
---|
170 | | -static inline u64 arch_counter_get_cntpct(void) |
---|
| 168 | +static __always_inline u64 __arch_counter_get_cntpct_stable(void) |
---|
171 | 169 | { |
---|
172 | 170 | u64 cnt; |
---|
173 | 171 | |
---|
.. | .. |
---|
177 | 175 | return cnt; |
---|
178 | 176 | } |
---|
179 | 177 | |
---|
180 | | -static inline u64 arch_counter_get_cntvct(void) |
---|
| 178 | +static __always_inline u64 __arch_counter_get_cntpct(void) |
---|
| 179 | +{ |
---|
| 180 | + u64 cnt; |
---|
| 181 | + |
---|
| 182 | + isb(); |
---|
| 183 | + cnt = read_sysreg(cntpct_el0); |
---|
| 184 | + arch_counter_enforce_ordering(cnt); |
---|
| 185 | + return cnt; |
---|
| 186 | +} |
---|
| 187 | + |
---|
| 188 | +static __always_inline u64 __arch_counter_get_cntvct_stable(void) |
---|
181 | 189 | { |
---|
182 | 190 | u64 cnt; |
---|
183 | 191 | |
---|
.. | .. |
---|
187 | 195 | return cnt; |
---|
188 | 196 | } |
---|
189 | 197 | |
---|
190 | | -#undef arch_counter_enforce_ordering |
---|
| 198 | +static __always_inline u64 __arch_counter_get_cntvct(void) |
---|
| 199 | +{ |
---|
| 200 | + u64 cnt; |
---|
| 201 | + |
---|
| 202 | + isb(); |
---|
| 203 | + cnt = read_sysreg(cntvct_el0); |
---|
| 204 | + arch_counter_enforce_ordering(cnt); |
---|
| 205 | + return cnt; |
---|
| 206 | +} |
---|
191 | 207 | |
---|
192 | 208 | static inline int arch_timer_arch_init(void) |
---|
193 | 209 | { |
---|
194 | 210 | return 0; |
---|
195 | 211 | } |
---|
196 | 212 | |
---|
| 213 | +static inline void arch_timer_set_evtstrm_feature(void) |
---|
| 214 | +{ |
---|
| 215 | + cpu_set_named_feature(EVTSTRM); |
---|
| 216 | +#ifdef CONFIG_COMPAT |
---|
| 217 | + compat_elf_hwcap |= COMPAT_HWCAP_EVTSTRM; |
---|
| 218 | +#endif |
---|
| 219 | +} |
---|
| 220 | + |
---|
| 221 | +static inline bool arch_timer_have_evtstrm_feature(void) |
---|
| 222 | +{ |
---|
| 223 | + return cpu_have_named_feature(EVTSTRM); |
---|
| 224 | +} |
---|
197 | 225 | #endif |
---|