cop2-ex.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2014 Lemote Corporation.
  7. * written by Huacai Chen <chenhc@lemote.com>
  8. *
  9. * based on arch/mips/cavium-octeon/cpu.c
  10. * Copyright (C) 2009 Wind River Systems,
  11. * written by Ralf Baechle <ralf@linux-mips.org>
  12. */
  13. #include <linux/init.h>
  14. #include <linux/sched.h>
  15. #include <linux/notifier.h>
  16. #include <asm/fpu.h>
  17. #include <asm/cop2.h>
  18. #include <asm/current.h>
  19. #include <asm/mipsregs.h>
  20. static int loongson_cu2_call(struct notifier_block *nfb, unsigned long action,
  21. void *data)
  22. {
  23. int fpu_owned;
  24. int fr = !test_thread_flag(TIF_32BIT_FPREGS);
  25. switch (action) {
  26. case CU2_EXCEPTION:
  27. preempt_disable();
  28. fpu_owned = __is_fpu_owner();
  29. if (!fr)
  30. set_c0_status(ST0_CU1 | ST0_CU2);
  31. else
  32. set_c0_status(ST0_CU1 | ST0_CU2 | ST0_FR);
  33. enable_fpu_hazard();
  34. KSTK_STATUS(current) |= (ST0_CU1 | ST0_CU2);
  35. if (fr)
  36. KSTK_STATUS(current) |= ST0_FR;
  37. else
  38. KSTK_STATUS(current) &= ~ST0_FR;
  39. /* If FPU is owned, we needn't init or restore fp */
  40. if (!fpu_owned) {
  41. set_thread_flag(TIF_USEDFPU);
  42. if (!used_math()) {
  43. _init_fpu(current->thread.fpu.fcr31);
  44. set_used_math();
  45. } else
  46. _restore_fp(current);
  47. }
  48. preempt_enable();
  49. return NOTIFY_STOP; /* Don't call default notifier */
  50. }
  51. return NOTIFY_OK; /* Let default notifier send signals */
  52. }
  53. static int __init loongson_cu2_setup(void)
  54. {
  55. return cu2_notifier(loongson_cu2_call, 0);
  56. }
  57. early_initcall(loongson_cu2_setup);