Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * FP/SIMD context switching and fault handling |
| 3 | * |
| 4 | * Copyright (C) 2012 ARM Ltd. |
| 5 | * Author: Catalin Marinas <catalin.marinas@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 | */ |
| 19 | |
Janet Liu | 32365e6 | 2015-06-11 12:02:45 +0800 | [diff] [blame] | 20 | #include <linux/cpu.h> |
Lorenzo Pieralisi | fb1ab1a | 2013-07-19 17:48:08 +0100 | [diff] [blame] | 21 | #include <linux/cpu_pm.h> |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 22 | #include <linux/kernel.h> |
| 23 | #include <linux/init.h> |
Dave Martin | 4328825d | 2017-08-03 17:23:22 +0100 | [diff] [blame^] | 24 | #include <linux/preempt.h> |
Ingo Molnar | 3f07c01 | 2017-02-08 18:51:30 +0100 | [diff] [blame] | 25 | #include <linux/sched/signal.h> |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 26 | #include <linux/signal.h> |
Ard Biesheuvel | 4cfb361 | 2013-07-09 14:18:12 +0100 | [diff] [blame] | 27 | #include <linux/hardirq.h> |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 28 | |
| 29 | #include <asm/fpsimd.h> |
| 30 | #include <asm/cputype.h> |
Dave Martin | 4328825d | 2017-08-03 17:23:22 +0100 | [diff] [blame^] | 31 | #include <asm/neon.h> |
| 32 | #include <asm/simd.h> |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 33 | |
| 34 | #define FPEXC_IOF (1 << 0) |
| 35 | #define FPEXC_DZF (1 << 1) |
| 36 | #define FPEXC_OFF (1 << 2) |
| 37 | #define FPEXC_UFF (1 << 3) |
| 38 | #define FPEXC_IXF (1 << 4) |
| 39 | #define FPEXC_IDF (1 << 7) |
| 40 | |
| 41 | /* |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 42 | * In order to reduce the number of times the FPSIMD state is needlessly saved |
| 43 | * and restored, we need to keep track of two things: |
| 44 | * (a) for each task, we need to remember which CPU was the last one to have |
| 45 | * the task's FPSIMD state loaded into its FPSIMD registers; |
| 46 | * (b) for each CPU, we need to remember which task's userland FPSIMD state has |
| 47 | * been loaded into its FPSIMD registers most recently, or whether it has |
| 48 | * been used to perform kernel mode NEON in the meantime. |
| 49 | * |
| 50 | * For (a), we add a 'cpu' field to struct fpsimd_state, which gets updated to |
Adam Buchbinder | ef769e3 | 2016-02-24 09:52:41 -0800 | [diff] [blame] | 51 | * the id of the current CPU every time the state is loaded onto a CPU. For (b), |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 52 | * we add the per-cpu variable 'fpsimd_last_state' (below), which contains the |
| 53 | * address of the userland FPSIMD state of the task that was loaded onto the CPU |
| 54 | * the most recently, or NULL if kernel mode NEON has been performed after that. |
| 55 | * |
| 56 | * With this in place, we no longer have to restore the next FPSIMD state right |
| 57 | * when switching between tasks. Instead, we can defer this check to userland |
| 58 | * resume, at which time we verify whether the CPU's fpsimd_last_state and the |
| 59 | * task's fpsimd_state.cpu are still mutually in sync. If this is the case, we |
| 60 | * can omit the FPSIMD restore. |
| 61 | * |
| 62 | * As an optimization, we use the thread_info flag TIF_FOREIGN_FPSTATE to |
| 63 | * indicate whether or not the userland FPSIMD state of the current task is |
| 64 | * present in the registers. The flag is set unless the FPSIMD registers of this |
| 65 | * CPU currently contain the most recent userland FPSIMD state of the current |
| 66 | * task. |
| 67 | * |
| 68 | * For a certain task, the sequence may look something like this: |
| 69 | * - the task gets scheduled in; if both the task's fpsimd_state.cpu field |
| 70 | * contains the id of the current CPU, and the CPU's fpsimd_last_state per-cpu |
| 71 | * variable points to the task's fpsimd_state, the TIF_FOREIGN_FPSTATE flag is |
| 72 | * cleared, otherwise it is set; |
| 73 | * |
| 74 | * - the task returns to userland; if TIF_FOREIGN_FPSTATE is set, the task's |
| 75 | * userland FPSIMD state is copied from memory to the registers, the task's |
| 76 | * fpsimd_state.cpu field is set to the id of the current CPU, the current |
| 77 | * CPU's fpsimd_last_state pointer is set to this task's fpsimd_state and the |
| 78 | * TIF_FOREIGN_FPSTATE flag is cleared; |
| 79 | * |
| 80 | * - the task executes an ordinary syscall; upon return to userland, the |
| 81 | * TIF_FOREIGN_FPSTATE flag will still be cleared, so no FPSIMD state is |
| 82 | * restored; |
| 83 | * |
| 84 | * - the task executes a syscall which executes some NEON instructions; this is |
| 85 | * preceded by a call to kernel_neon_begin(), which copies the task's FPSIMD |
| 86 | * register contents to memory, clears the fpsimd_last_state per-cpu variable |
| 87 | * and sets the TIF_FOREIGN_FPSTATE flag; |
| 88 | * |
| 89 | * - the task gets preempted after kernel_neon_end() is called; as we have not |
| 90 | * returned from the 2nd syscall yet, TIF_FOREIGN_FPSTATE is still set so |
| 91 | * whatever is in the FPSIMD registers is not saved to memory, but discarded. |
| 92 | */ |
| 93 | static DEFINE_PER_CPU(struct fpsimd_state *, fpsimd_last_state); |
| 94 | |
| 95 | /* |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 96 | * Trapped FP/ASIMD access. |
| 97 | */ |
| 98 | void do_fpsimd_acc(unsigned int esr, struct pt_regs *regs) |
| 99 | { |
| 100 | /* TODO: implement lazy context saving/restoring */ |
| 101 | WARN_ON(1); |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * Raise a SIGFPE for the current process. |
| 106 | */ |
| 107 | void do_fpsimd_exc(unsigned int esr, struct pt_regs *regs) |
| 108 | { |
| 109 | siginfo_t info; |
| 110 | unsigned int si_code = 0; |
| 111 | |
| 112 | if (esr & FPEXC_IOF) |
| 113 | si_code = FPE_FLTINV; |
| 114 | else if (esr & FPEXC_DZF) |
| 115 | si_code = FPE_FLTDIV; |
| 116 | else if (esr & FPEXC_OFF) |
| 117 | si_code = FPE_FLTOVF; |
| 118 | else if (esr & FPEXC_UFF) |
| 119 | si_code = FPE_FLTUND; |
| 120 | else if (esr & FPEXC_IXF) |
| 121 | si_code = FPE_FLTRES; |
| 122 | |
| 123 | memset(&info, 0, sizeof(info)); |
| 124 | info.si_signo = SIGFPE; |
| 125 | info.si_code = si_code; |
| 126 | info.si_addr = (void __user *)instruction_pointer(regs); |
| 127 | |
| 128 | send_sig_info(SIGFPE, &info, current); |
| 129 | } |
| 130 | |
| 131 | void fpsimd_thread_switch(struct task_struct *next) |
| 132 | { |
Suzuki K Poulose | 82e0191 | 2016-11-08 13:56:21 +0000 | [diff] [blame] | 133 | if (!system_supports_fpsimd()) |
| 134 | return; |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 135 | /* |
| 136 | * Save the current FPSIMD state to memory, but only if whatever is in |
| 137 | * the registers is in fact the most recent userland FPSIMD state of |
| 138 | * 'current'. |
| 139 | */ |
| 140 | if (current->mm && !test_thread_flag(TIF_FOREIGN_FPSTATE)) |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 141 | fpsimd_save_state(¤t->thread.fpsimd_state); |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 142 | |
| 143 | if (next->mm) { |
| 144 | /* |
| 145 | * If we are switching to a task whose most recent userland |
| 146 | * FPSIMD state is already in the registers of *this* cpu, |
| 147 | * we can skip loading the state from memory. Otherwise, set |
| 148 | * the TIF_FOREIGN_FPSTATE flag so the state will be loaded |
| 149 | * upon the next return to userland. |
| 150 | */ |
| 151 | struct fpsimd_state *st = &next->thread.fpsimd_state; |
| 152 | |
| 153 | if (__this_cpu_read(fpsimd_last_state) == st |
| 154 | && st->cpu == smp_processor_id()) |
| 155 | clear_ti_thread_flag(task_thread_info(next), |
| 156 | TIF_FOREIGN_FPSTATE); |
| 157 | else |
| 158 | set_ti_thread_flag(task_thread_info(next), |
| 159 | TIF_FOREIGN_FPSTATE); |
| 160 | } |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | void fpsimd_flush_thread(void) |
| 164 | { |
Suzuki K Poulose | 82e0191 | 2016-11-08 13:56:21 +0000 | [diff] [blame] | 165 | if (!system_supports_fpsimd()) |
| 166 | return; |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 167 | memset(¤t->thread.fpsimd_state, 0, sizeof(struct fpsimd_state)); |
Ard Biesheuvel | 674c242c | 2015-08-27 07:12:33 +0100 | [diff] [blame] | 168 | fpsimd_flush_task_state(current); |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 169 | set_thread_flag(TIF_FOREIGN_FPSTATE); |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Ard Biesheuvel | c51f926 | 2014-02-24 15:26:27 +0100 | [diff] [blame] | 172 | /* |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 173 | * Save the userland FPSIMD state of 'current' to memory, but only if the state |
| 174 | * currently held in the registers does in fact belong to 'current' |
Ard Biesheuvel | c51f926 | 2014-02-24 15:26:27 +0100 | [diff] [blame] | 175 | */ |
| 176 | void fpsimd_preserve_current_state(void) |
| 177 | { |
Suzuki K Poulose | 82e0191 | 2016-11-08 13:56:21 +0000 | [diff] [blame] | 178 | if (!system_supports_fpsimd()) |
| 179 | return; |
Ard Biesheuvel | c51f926 | 2014-02-24 15:26:27 +0100 | [diff] [blame] | 180 | preempt_disable(); |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 181 | if (!test_thread_flag(TIF_FOREIGN_FPSTATE)) |
| 182 | fpsimd_save_state(¤t->thread.fpsimd_state); |
Ard Biesheuvel | c51f926 | 2014-02-24 15:26:27 +0100 | [diff] [blame] | 183 | preempt_enable(); |
| 184 | } |
| 185 | |
| 186 | /* |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 187 | * Load the userland FPSIMD state of 'current' from memory, but only if the |
| 188 | * FPSIMD state already held in the registers is /not/ the most recent FPSIMD |
| 189 | * state of 'current' |
| 190 | */ |
| 191 | void fpsimd_restore_current_state(void) |
| 192 | { |
Suzuki K Poulose | 82e0191 | 2016-11-08 13:56:21 +0000 | [diff] [blame] | 193 | if (!system_supports_fpsimd()) |
| 194 | return; |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 195 | preempt_disable(); |
| 196 | if (test_and_clear_thread_flag(TIF_FOREIGN_FPSTATE)) { |
| 197 | struct fpsimd_state *st = ¤t->thread.fpsimd_state; |
| 198 | |
| 199 | fpsimd_load_state(st); |
Dave Martin | 5046418 | 2017-08-03 17:23:21 +0100 | [diff] [blame] | 200 | __this_cpu_write(fpsimd_last_state, st); |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 201 | st->cpu = smp_processor_id(); |
| 202 | } |
| 203 | preempt_enable(); |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * Load an updated userland FPSIMD state for 'current' from memory and set the |
| 208 | * flag that indicates that the FPSIMD register contents are the most recent |
| 209 | * FPSIMD state of 'current' |
Ard Biesheuvel | c51f926 | 2014-02-24 15:26:27 +0100 | [diff] [blame] | 210 | */ |
| 211 | void fpsimd_update_current_state(struct fpsimd_state *state) |
| 212 | { |
Suzuki K Poulose | 82e0191 | 2016-11-08 13:56:21 +0000 | [diff] [blame] | 213 | if (!system_supports_fpsimd()) |
| 214 | return; |
Ard Biesheuvel | c51f926 | 2014-02-24 15:26:27 +0100 | [diff] [blame] | 215 | preempt_disable(); |
| 216 | fpsimd_load_state(state); |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 217 | if (test_and_clear_thread_flag(TIF_FOREIGN_FPSTATE)) { |
| 218 | struct fpsimd_state *st = ¤t->thread.fpsimd_state; |
| 219 | |
Dave Martin | 5046418 | 2017-08-03 17:23:21 +0100 | [diff] [blame] | 220 | __this_cpu_write(fpsimd_last_state, st); |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 221 | st->cpu = smp_processor_id(); |
| 222 | } |
Ard Biesheuvel | c51f926 | 2014-02-24 15:26:27 +0100 | [diff] [blame] | 223 | preempt_enable(); |
| 224 | } |
| 225 | |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 226 | /* |
| 227 | * Invalidate live CPU copies of task t's FPSIMD state |
| 228 | */ |
| 229 | void fpsimd_flush_task_state(struct task_struct *t) |
| 230 | { |
| 231 | t->thread.fpsimd_state.cpu = NR_CPUS; |
| 232 | } |
| 233 | |
Ard Biesheuvel | 4cfb361 | 2013-07-09 14:18:12 +0100 | [diff] [blame] | 234 | #ifdef CONFIG_KERNEL_MODE_NEON |
| 235 | |
Ard Biesheuvel | 190f1ca | 2014-02-24 15:26:29 +0100 | [diff] [blame] | 236 | static DEFINE_PER_CPU(struct fpsimd_partial_state, hardirq_fpsimdstate); |
| 237 | static DEFINE_PER_CPU(struct fpsimd_partial_state, softirq_fpsimdstate); |
| 238 | |
Ard Biesheuvel | 4cfb361 | 2013-07-09 14:18:12 +0100 | [diff] [blame] | 239 | /* |
| 240 | * Kernel-side NEON support functions |
| 241 | */ |
Ard Biesheuvel | 190f1ca | 2014-02-24 15:26:29 +0100 | [diff] [blame] | 242 | void kernel_neon_begin_partial(u32 num_regs) |
Ard Biesheuvel | 4cfb361 | 2013-07-09 14:18:12 +0100 | [diff] [blame] | 243 | { |
Suzuki K Poulose | 82e0191 | 2016-11-08 13:56:21 +0000 | [diff] [blame] | 244 | if (WARN_ON(!system_supports_fpsimd())) |
| 245 | return; |
Ard Biesheuvel | 190f1ca | 2014-02-24 15:26:29 +0100 | [diff] [blame] | 246 | if (in_interrupt()) { |
| 247 | struct fpsimd_partial_state *s = this_cpu_ptr( |
| 248 | in_irq() ? &hardirq_fpsimdstate : &softirq_fpsimdstate); |
Ard Biesheuvel | 4cfb361 | 2013-07-09 14:18:12 +0100 | [diff] [blame] | 249 | |
Ard Biesheuvel | 190f1ca | 2014-02-24 15:26:29 +0100 | [diff] [blame] | 250 | BUG_ON(num_regs > 32); |
| 251 | fpsimd_save_partial_state(s, roundup(num_regs, 2)); |
| 252 | } else { |
| 253 | /* |
| 254 | * Save the userland FPSIMD state if we have one and if we |
| 255 | * haven't done so already. Clear fpsimd_last_state to indicate |
| 256 | * that there is no longer userland FPSIMD state in the |
| 257 | * registers. |
| 258 | */ |
| 259 | preempt_disable(); |
| 260 | if (current->mm && |
| 261 | !test_and_set_thread_flag(TIF_FOREIGN_FPSTATE)) |
| 262 | fpsimd_save_state(¤t->thread.fpsimd_state); |
| 263 | this_cpu_write(fpsimd_last_state, NULL); |
| 264 | } |
Ard Biesheuvel | 4cfb361 | 2013-07-09 14:18:12 +0100 | [diff] [blame] | 265 | } |
Ard Biesheuvel | 190f1ca | 2014-02-24 15:26:29 +0100 | [diff] [blame] | 266 | EXPORT_SYMBOL(kernel_neon_begin_partial); |
Ard Biesheuvel | 4cfb361 | 2013-07-09 14:18:12 +0100 | [diff] [blame] | 267 | |
| 268 | void kernel_neon_end(void) |
| 269 | { |
Suzuki K Poulose | 82e0191 | 2016-11-08 13:56:21 +0000 | [diff] [blame] | 270 | if (!system_supports_fpsimd()) |
| 271 | return; |
Ard Biesheuvel | 190f1ca | 2014-02-24 15:26:29 +0100 | [diff] [blame] | 272 | if (in_interrupt()) { |
| 273 | struct fpsimd_partial_state *s = this_cpu_ptr( |
| 274 | in_irq() ? &hardirq_fpsimdstate : &softirq_fpsimdstate); |
| 275 | fpsimd_load_partial_state(s); |
| 276 | } else { |
| 277 | preempt_enable(); |
| 278 | } |
Ard Biesheuvel | 4cfb361 | 2013-07-09 14:18:12 +0100 | [diff] [blame] | 279 | } |
| 280 | EXPORT_SYMBOL(kernel_neon_end); |
| 281 | |
Dave Martin | 4328825d | 2017-08-03 17:23:22 +0100 | [diff] [blame^] | 282 | DEFINE_PER_CPU(struct fpsimd_state, efi_fpsimd_state); |
| 283 | DEFINE_PER_CPU(bool, efi_fpsimd_state_used); |
| 284 | |
| 285 | /* |
| 286 | * EFI runtime services support functions |
| 287 | * |
| 288 | * The ABI for EFI runtime services allows EFI to use FPSIMD during the call. |
| 289 | * This means that for EFI (and only for EFI), we have to assume that FPSIMD |
| 290 | * is always used rather than being an optional accelerator. |
| 291 | * |
| 292 | * These functions provide the necessary support for ensuring FPSIMD |
| 293 | * save/restore in the contexts from which EFI is used. |
| 294 | * |
| 295 | * Do not use them for any other purpose -- if tempted to do so, you are |
| 296 | * either doing something wrong or you need to propose some refactoring. |
| 297 | */ |
| 298 | |
| 299 | /* |
| 300 | * __efi_fpsimd_begin(): prepare FPSIMD for making an EFI runtime services call |
| 301 | */ |
| 302 | void __efi_fpsimd_begin(void) |
| 303 | { |
| 304 | if (!system_supports_fpsimd()) |
| 305 | return; |
| 306 | |
| 307 | WARN_ON(preemptible()); |
| 308 | |
| 309 | if (may_use_simd()) |
| 310 | kernel_neon_begin(); |
| 311 | else { |
| 312 | fpsimd_save_state(this_cpu_ptr(&efi_fpsimd_state)); |
| 313 | __this_cpu_write(efi_fpsimd_state_used, true); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | /* |
| 318 | * __efi_fpsimd_end(): clean up FPSIMD after an EFI runtime services call |
| 319 | */ |
| 320 | void __efi_fpsimd_end(void) |
| 321 | { |
| 322 | if (!system_supports_fpsimd()) |
| 323 | return; |
| 324 | |
| 325 | if (__this_cpu_xchg(efi_fpsimd_state_used, false)) |
| 326 | fpsimd_load_state(this_cpu_ptr(&efi_fpsimd_state)); |
| 327 | else |
| 328 | kernel_neon_end(); |
| 329 | } |
| 330 | |
Ard Biesheuvel | 4cfb361 | 2013-07-09 14:18:12 +0100 | [diff] [blame] | 331 | #endif /* CONFIG_KERNEL_MODE_NEON */ |
| 332 | |
Lorenzo Pieralisi | fb1ab1a | 2013-07-19 17:48:08 +0100 | [diff] [blame] | 333 | #ifdef CONFIG_CPU_PM |
| 334 | static int fpsimd_cpu_pm_notifier(struct notifier_block *self, |
| 335 | unsigned long cmd, void *v) |
| 336 | { |
| 337 | switch (cmd) { |
| 338 | case CPU_PM_ENTER: |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 339 | if (current->mm && !test_thread_flag(TIF_FOREIGN_FPSTATE)) |
Lorenzo Pieralisi | fb1ab1a | 2013-07-19 17:48:08 +0100 | [diff] [blame] | 340 | fpsimd_save_state(¤t->thread.fpsimd_state); |
Leo Yan | 7c68a9c | 2014-09-01 11:09:51 +0800 | [diff] [blame] | 341 | this_cpu_write(fpsimd_last_state, NULL); |
Lorenzo Pieralisi | fb1ab1a | 2013-07-19 17:48:08 +0100 | [diff] [blame] | 342 | break; |
| 343 | case CPU_PM_EXIT: |
| 344 | if (current->mm) |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 345 | set_thread_flag(TIF_FOREIGN_FPSTATE); |
Lorenzo Pieralisi | fb1ab1a | 2013-07-19 17:48:08 +0100 | [diff] [blame] | 346 | break; |
| 347 | case CPU_PM_ENTER_FAILED: |
| 348 | default: |
| 349 | return NOTIFY_DONE; |
| 350 | } |
| 351 | return NOTIFY_OK; |
| 352 | } |
| 353 | |
| 354 | static struct notifier_block fpsimd_cpu_pm_notifier_block = { |
| 355 | .notifier_call = fpsimd_cpu_pm_notifier, |
| 356 | }; |
| 357 | |
Jisheng Zhang | a7c61a3 | 2015-11-20 17:59:10 +0800 | [diff] [blame] | 358 | static void __init fpsimd_pm_init(void) |
Lorenzo Pieralisi | fb1ab1a | 2013-07-19 17:48:08 +0100 | [diff] [blame] | 359 | { |
| 360 | cpu_pm_register_notifier(&fpsimd_cpu_pm_notifier_block); |
| 361 | } |
| 362 | |
| 363 | #else |
| 364 | static inline void fpsimd_pm_init(void) { } |
| 365 | #endif /* CONFIG_CPU_PM */ |
| 366 | |
Janet Liu | 32365e6 | 2015-06-11 12:02:45 +0800 | [diff] [blame] | 367 | #ifdef CONFIG_HOTPLUG_CPU |
Sebastian Andrzej Siewior | c23a726 | 2016-09-06 19:04:37 +0200 | [diff] [blame] | 368 | static int fpsimd_cpu_dead(unsigned int cpu) |
Janet Liu | 32365e6 | 2015-06-11 12:02:45 +0800 | [diff] [blame] | 369 | { |
Sebastian Andrzej Siewior | c23a726 | 2016-09-06 19:04:37 +0200 | [diff] [blame] | 370 | per_cpu(fpsimd_last_state, cpu) = NULL; |
| 371 | return 0; |
Janet Liu | 32365e6 | 2015-06-11 12:02:45 +0800 | [diff] [blame] | 372 | } |
| 373 | |
Janet Liu | 32365e6 | 2015-06-11 12:02:45 +0800 | [diff] [blame] | 374 | static inline void fpsimd_hotplug_init(void) |
| 375 | { |
Sebastian Andrzej Siewior | c23a726 | 2016-09-06 19:04:37 +0200 | [diff] [blame] | 376 | cpuhp_setup_state_nocalls(CPUHP_ARM64_FPSIMD_DEAD, "arm64/fpsimd:dead", |
| 377 | NULL, fpsimd_cpu_dead); |
Janet Liu | 32365e6 | 2015-06-11 12:02:45 +0800 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | #else |
| 381 | static inline void fpsimd_hotplug_init(void) { } |
| 382 | #endif |
| 383 | |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 384 | /* |
| 385 | * FP/SIMD support code initialisation. |
| 386 | */ |
| 387 | static int __init fpsimd_init(void) |
| 388 | { |
Suzuki K. Poulose | fe80f9f | 2015-10-19 14:24:53 +0100 | [diff] [blame] | 389 | if (elf_hwcap & HWCAP_FP) { |
| 390 | fpsimd_pm_init(); |
| 391 | fpsimd_hotplug_init(); |
| 392 | } else { |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 393 | pr_notice("Floating-point is not implemented\n"); |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 394 | } |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 395 | |
Suzuki K. Poulose | fe80f9f | 2015-10-19 14:24:53 +0100 | [diff] [blame] | 396 | if (!(elf_hwcap & HWCAP_ASIMD)) |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 397 | pr_notice("Advanced SIMD is not implemented\n"); |
Lorenzo Pieralisi | fb1ab1a | 2013-07-19 17:48:08 +0100 | [diff] [blame] | 398 | |
Catalin Marinas | 53631b5 | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 399 | return 0; |
| 400 | } |
| 401 | late_initcall(fpsimd_init); |