thumbee.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * arch/arm/kernel/thumbee.c
  4. *
  5. * Copyright (C) 2008 ARM Limited
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/init.h>
  9. #include <asm/cputype.h>
  10. #include <asm/system_info.h>
  11. #include <asm/thread_notify.h>
  12. /*
  13. * Access to the ThumbEE Handler Base register
  14. */
  15. static inline unsigned long teehbr_read(void)
  16. {
  17. unsigned long v;
  18. asm("mrc p14, 6, %0, c1, c0, 0\n" : "=r" (v));
  19. return v;
  20. }
  21. static inline void teehbr_write(unsigned long v)
  22. {
  23. asm("mcr p14, 6, %0, c1, c0, 0\n" : : "r" (v));
  24. }
  25. static int thumbee_notifier(struct notifier_block *self, unsigned long cmd, void *t)
  26. {
  27. struct thread_info *thread = t;
  28. switch (cmd) {
  29. case THREAD_NOTIFY_FLUSH:
  30. teehbr_write(0);
  31. break;
  32. case THREAD_NOTIFY_SWITCH:
  33. current_thread_info()->thumbee_state = teehbr_read();
  34. teehbr_write(thread->thumbee_state);
  35. break;
  36. }
  37. return NOTIFY_DONE;
  38. }
  39. static struct notifier_block thumbee_notifier_block = {
  40. .notifier_call = thumbee_notifier,
  41. };
  42. static int __init thumbee_init(void)
  43. {
  44. unsigned long pfr0;
  45. unsigned int cpu_arch = cpu_architecture();
  46. if (cpu_arch < CPU_ARCH_ARMv7)
  47. return 0;
  48. pfr0 = read_cpuid_ext(CPUID_EXT_PFR0);
  49. if ((pfr0 & 0x0000f000) != 0x00001000)
  50. return 0;
  51. pr_info("ThumbEE CPU extension supported.\n");
  52. elf_hwcap |= HWCAP_THUMBEE;
  53. thread_register_notifier(&thumbee_notifier_block);
  54. return 0;
  55. }
  56. late_initcall(thumbee_init);