2 * FP/SIMD context switching and fault handling
4 * Copyright (C) 2012 ARM Ltd.
5 * Author: Catalin Marinas <catalin.marinas@arm.com>
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.
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.
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/>.
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/sched.h>
23 #include <linux/signal.h>
25 #include <asm/fpsimd.h>
26 #include <asm/cputype.h>
28 #define FPEXC_IOF (1 << 0)
29 #define FPEXC_DZF (1 << 1)
30 #define FPEXC_OFF (1 << 2)
31 #define FPEXC_UFF (1 << 3)
32 #define FPEXC_IXF (1 << 4)
33 #define FPEXC_IDF (1 << 7)
36 * Trapped FP/ASIMD access.
38 void do_fpsimd_acc(unsigned int esr, struct pt_regs *regs)
40 /* TODO: implement lazy context saving/restoring */
45 * Raise a SIGFPE for the current process.
47 void do_fpsimd_exc(unsigned int esr, struct pt_regs *regs)
50 unsigned int si_code = 0;
54 else if (esr & FPEXC_DZF)
56 else if (esr & FPEXC_OFF)
58 else if (esr & FPEXC_UFF)
60 else if (esr & FPEXC_IXF)
63 memset(&info, 0, sizeof(info));
64 info.si_signo = SIGFPE;
65 info.si_code = si_code;
66 info.si_addr = (void __user *)instruction_pointer(regs);
68 send_sig_info(SIGFPE, &info, current);
71 void fpsimd_thread_switch(struct task_struct *next)
73 /* check if not kernel threads */
75 fpsimd_save_state(¤t->thread.fpsimd_state);
77 fpsimd_load_state(&next->thread.fpsimd_state);
80 void fpsimd_flush_thread(void)
83 memset(¤t->thread.fpsimd_state, 0, sizeof(struct fpsimd_state));
84 fpsimd_load_state(¤t->thread.fpsimd_state);
89 * FP/SIMD support code initialisation.
91 static int __init fpsimd_init(void)
93 u64 pfr = read_cpuid(ID_AA64PFR0_EL1);
95 if (pfr & (0xf << 16)) {
96 pr_notice("Floating-point is not implemented\n");
99 elf_hwcap |= HWCAP_FP;
101 if (pfr & (0xf << 20))
102 pr_notice("Advanced SIMD is not implemented\n");
104 elf_hwcap |= HWCAP_ASIMD;
108 late_initcall(fpsimd_init);