hotplug.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * linux/arch/arm/mach-spear13xx/hotplug.c
  3. *
  4. * Copyright (C) 2012 ST Microelectronics Ltd.
  5. * Deepak Sikri <deepak.sikri@st.com>
  6. *
  7. * based upon linux/arch/arm/mach-realview/hotplug.c
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/smp.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/cp15.h>
  18. #include <asm/smp_plat.h>
  19. extern volatile int pen_release;
  20. static inline void cpu_enter_lowpower(void)
  21. {
  22. unsigned int v;
  23. flush_cache_all();
  24. asm volatile(
  25. " mcr p15, 0, %1, c7, c5, 0\n"
  26. " dsb\n"
  27. /*
  28. * Turn off coherency
  29. */
  30. " mrc p15, 0, %0, c1, c0, 1\n"
  31. " bic %0, %0, #0x20\n"
  32. " mcr p15, 0, %0, c1, c0, 1\n"
  33. " mrc p15, 0, %0, c1, c0, 0\n"
  34. " bic %0, %0, %2\n"
  35. " mcr p15, 0, %0, c1, c0, 0\n"
  36. : "=&r" (v)
  37. : "r" (0), "Ir" (CR_C)
  38. : "cc", "memory");
  39. }
  40. static inline void cpu_leave_lowpower(void)
  41. {
  42. unsigned int v;
  43. asm volatile("mrc p15, 0, %0, c1, c0, 0\n"
  44. " orr %0, %0, %1\n"
  45. " mcr p15, 0, %0, c1, c0, 0\n"
  46. " mrc p15, 0, %0, c1, c0, 1\n"
  47. " orr %0, %0, #0x20\n"
  48. " mcr p15, 0, %0, c1, c0, 1\n"
  49. : "=&r" (v)
  50. : "Ir" (CR_C)
  51. : "cc");
  52. }
  53. static inline void platform_do_lowpower(unsigned int cpu, int *spurious)
  54. {
  55. for (;;) {
  56. wfi();
  57. if (pen_release == cpu) {
  58. /*
  59. * OK, proper wakeup, we're done
  60. */
  61. break;
  62. }
  63. /*
  64. * Getting here, means that we have come out of WFI without
  65. * having been woken up - this shouldn't happen
  66. *
  67. * Just note it happening - when we're woken, we can report
  68. * its occurrence.
  69. */
  70. (*spurious)++;
  71. }
  72. }
  73. int platform_cpu_kill(unsigned int cpu)
  74. {
  75. return 1;
  76. }
  77. /*
  78. * platform-specific code to shutdown a CPU
  79. *
  80. * Called with IRQs disabled
  81. */
  82. void __cpuinit platform_cpu_die(unsigned int cpu)
  83. {
  84. int spurious = 0;
  85. /*
  86. * we're ready for shutdown now, so do it
  87. */
  88. cpu_enter_lowpower();
  89. platform_do_lowpower(cpu, &spurious);
  90. /*
  91. * bring this CPU back into the world of cache
  92. * coherency, and then restore interrupts
  93. */
  94. cpu_leave_lowpower();
  95. if (spurious)
  96. pr_warn("CPU%u: %u spurious wakeup calls\n", cpu, spurious);
  97. }
  98. int platform_cpu_disable(unsigned int cpu)
  99. {
  100. /*
  101. * we don't allow CPU 0 to be shutdown (it is still too special
  102. * e.g. clock tick interrupts)
  103. */
  104. return cpu == 0 ? -EPERM : 0;
  105. }