pj4-cp0.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * linux/arch/arm/kernel/pj4-cp0.c
  3. *
  4. * PJ4 iWMMXt coprocessor context switching and handling
  5. *
  6. * Copyright (c) 2010 Marvell International Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/types.h>
  13. #include <linux/kernel.h>
  14. #include <linux/signal.h>
  15. #include <linux/sched.h>
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <asm/thread_notify.h>
  19. static int iwmmxt_do(struct notifier_block *self, unsigned long cmd, void *t)
  20. {
  21. struct thread_info *thread = t;
  22. switch (cmd) {
  23. case THREAD_NOTIFY_FLUSH:
  24. /*
  25. * flush_thread() zeroes thread->fpstate, so no need
  26. * to do anything here.
  27. *
  28. * FALLTHROUGH: Ensure we don't try to overwrite our newly
  29. * initialised state information on the first fault.
  30. */
  31. case THREAD_NOTIFY_EXIT:
  32. iwmmxt_task_release(thread);
  33. break;
  34. case THREAD_NOTIFY_SWITCH:
  35. iwmmxt_task_switch(thread);
  36. break;
  37. }
  38. return NOTIFY_DONE;
  39. }
  40. static struct notifier_block iwmmxt_notifier_block = {
  41. .notifier_call = iwmmxt_do,
  42. };
  43. static u32 __init pj4_cp_access_read(void)
  44. {
  45. u32 value;
  46. __asm__ __volatile__ (
  47. "mrc p15, 0, %0, c1, c0, 2\n\t"
  48. : "=r" (value));
  49. return value;
  50. }
  51. static void __init pj4_cp_access_write(u32 value)
  52. {
  53. u32 temp;
  54. __asm__ __volatile__ (
  55. "mcr p15, 0, %1, c1, c0, 2\n\t"
  56. "mrc p15, 0, %0, c1, c0, 2\n\t"
  57. "mov %0, %0\n\t"
  58. "sub pc, pc, #4\n\t"
  59. : "=r" (temp) : "r" (value));
  60. }
  61. /*
  62. * Disable CP0/CP1 on boot, and let call_fpe() and the iWMMXt lazy
  63. * switch code handle iWMMXt context switching.
  64. */
  65. static int __init pj4_cp0_init(void)
  66. {
  67. u32 cp_access;
  68. cp_access = pj4_cp_access_read() & ~0xf;
  69. pj4_cp_access_write(cp_access);
  70. printk(KERN_INFO "PJ4 iWMMXt coprocessor enabled.\n");
  71. elf_hwcap |= HWCAP_IWMMXT;
  72. thread_register_notifier(&iwmmxt_notifier_block);
  73. return 0;
  74. }
  75. late_initcall(pj4_cp0_init);