thumbee.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/system_info.h>
  22. #include <asm/thread_notify.h>
  23. /*
  24. * Access to the ThumbEE Handler Base register
  25. */
  26. static inline unsigned long teehbr_read(void)
  27. {
  28. unsigned long v;
  29. asm("mrc p14, 6, %0, c1, c0, 0\n" : "=r" (v));
  30. return v;
  31. }
  32. static inline void teehbr_write(unsigned long v)
  33. {
  34. asm("mcr p14, 6, %0, c1, c0, 0\n" : : "r" (v));
  35. }
  36. static int thumbee_notifier(struct notifier_block *self, unsigned long cmd, void *t)
  37. {
  38. struct thread_info *thread = t;
  39. switch (cmd) {
  40. case THREAD_NOTIFY_FLUSH:
  41. thread->thumbee_state = 0;
  42. break;
  43. case THREAD_NOTIFY_SWITCH:
  44. current_thread_info()->thumbee_state = teehbr_read();
  45. teehbr_write(thread->thumbee_state);
  46. break;
  47. }
  48. return NOTIFY_DONE;
  49. }
  50. static struct notifier_block thumbee_notifier_block = {
  51. .notifier_call = thumbee_notifier,
  52. };
  53. static int __init thumbee_init(void)
  54. {
  55. unsigned long pfr0;
  56. unsigned int cpu_arch = cpu_architecture();
  57. if (cpu_arch < CPU_ARCH_ARMv7)
  58. return 0;
  59. /* processor feature register 0 */
  60. asm("mrc p15, 0, %0, c0, c1, 0\n" : "=r" (pfr0));
  61. if ((pfr0 & 0x0000f000) != 0x00001000)
  62. return 0;
  63. printk(KERN_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);