fpsimd.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #include <linux/kernel.h>
  20. #include <linux/init.h>
  21. #include <linux/sched.h>
  22. #include <linux/signal.h>
  23. #include <asm/fpsimd.h>
  24. #include <asm/cputype.h>
  25. #define FPEXC_IOF (1 << 0)
  26. #define FPEXC_DZF (1 << 1)
  27. #define FPEXC_OFF (1 << 2)
  28. #define FPEXC_UFF (1 << 3)
  29. #define FPEXC_IXF (1 << 4)
  30. #define FPEXC_IDF (1 << 7)
  31. /*
  32. * Trapped FP/ASIMD access.
  33. */
  34. void do_fpsimd_acc(unsigned int esr, struct pt_regs *regs)
  35. {
  36. /* TODO: implement lazy context saving/restoring */
  37. WARN_ON(1);
  38. }
  39. /*
  40. * Raise a SIGFPE for the current process.
  41. */
  42. void do_fpsimd_exc(unsigned int esr, struct pt_regs *regs)
  43. {
  44. siginfo_t info;
  45. unsigned int si_code = 0;
  46. if (esr & FPEXC_IOF)
  47. si_code = FPE_FLTINV;
  48. else if (esr & FPEXC_DZF)
  49. si_code = FPE_FLTDIV;
  50. else if (esr & FPEXC_OFF)
  51. si_code = FPE_FLTOVF;
  52. else if (esr & FPEXC_UFF)
  53. si_code = FPE_FLTUND;
  54. else if (esr & FPEXC_IXF)
  55. si_code = FPE_FLTRES;
  56. memset(&info, 0, sizeof(info));
  57. info.si_signo = SIGFPE;
  58. info.si_code = si_code;
  59. info.si_addr = (void __user *)instruction_pointer(regs);
  60. send_sig_info(SIGFPE, &info, current);
  61. }
  62. void fpsimd_thread_switch(struct task_struct *next)
  63. {
  64. /* check if not kernel threads */
  65. if (current->mm)
  66. fpsimd_save_state(&current->thread.fpsimd_state);
  67. if (next->mm)
  68. fpsimd_load_state(&next->thread.fpsimd_state);
  69. }
  70. void fpsimd_flush_thread(void)
  71. {
  72. memset(&current->thread.fpsimd_state, 0, sizeof(struct fpsimd_state));
  73. fpsimd_load_state(&current->thread.fpsimd_state);
  74. }
  75. /*
  76. * FP/SIMD support code initialisation.
  77. */
  78. static int __init fpsimd_init(void)
  79. {
  80. u64 pfr = read_cpuid(ID_AA64PFR0_EL1);
  81. if (pfr & (0xf << 16)) {
  82. pr_notice("Floating-point is not implemented\n");
  83. return 0;
  84. }
  85. elf_hwcap |= HWCAP_FP;
  86. if (pfr & (0xf << 20))
  87. pr_notice("Advanced SIMD is not implemented\n");
  88. else
  89. elf_hwcap |= HWCAP_ASIMD;
  90. return 0;
  91. }
  92. late_initcall(fpsimd_init);