thumbee.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * arch/arm/kernel/thumbee.c
  3. *
  4. * Copyright (C) 2008 ARM Limited
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/init.h>
  21. #include <asm/cputype.h>
  22. #include <asm/system_info.h>
  23. #include <asm/thread_notify.h>
  24. /*
  25. * Access to the ThumbEE Handler Base register
  26. */
  27. static inline unsigned long teehbr_read(void)
  28. {
  29. unsigned long v;
  30. asm("mrc p14, 6, %0, c1, c0, 0\n" : "=r" (v));
  31. return v;
  32. }
  33. static inline void teehbr_write(unsigned long v)
  34. {
  35. asm("mcr p14, 6, %0, c1, c0, 0\n" : : "r" (v));
  36. }
  37. static int thumbee_notifier(struct notifier_block *self, unsigned long cmd, void *t)
  38. {
  39. struct thread_info *thread = t;
  40. switch (cmd) {
  41. case THREAD_NOTIFY_FLUSH:
  42. teehbr_write(0);
  43. break;
  44. case THREAD_NOTIFY_SWITCH:
  45. current_thread_info()->thumbee_state = teehbr_read();
  46. teehbr_write(thread->thumbee_state);
  47. break;
  48. }
  49. return NOTIFY_DONE;
  50. }
  51. static struct notifier_block thumbee_notifier_block = {
  52. .notifier_call = thumbee_notifier,
  53. };
  54. static int __init thumbee_init(void)
  55. {
  56. unsigned long pfr0;
  57. unsigned int cpu_arch = cpu_architecture();
  58. if (cpu_arch < CPU_ARCH_ARMv7)
  59. return 0;
  60. pfr0 = read_cpuid_ext(CPUID_EXT_PFR0);
  61. if ((pfr0 & 0x0000f000) != 0x00001000)
  62. return 0;
  63. pr_info("ThumbEE CPU extension supported.\n");
  64. elf_hwcap |= HWCAP_THUMBEE;
  65. thread_register_notifier(&thumbee_notifier_block);
  66. return 0;
  67. }
  68. late_initcall(thumbee_init);