hotplug.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* linux arch/arm/mach-exynos4/hotplug.c
  2. *
  3. * Cloned from linux/arch/arm/mach-realview/hotplug.c
  4. *
  5. * Copyright (C) 2002 ARM Ltd.
  6. * All Rights Reserved
  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/kernel.h>
  13. #include <linux/errno.h>
  14. #include <linux/smp.h>
  15. #include <linux/io.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/cp15.h>
  18. #include <asm/smp_plat.h>
  19. #include <mach/regs-pmu.h>
  20. extern volatile int pen_release;
  21. static inline void cpu_enter_lowpower(void)
  22. {
  23. unsigned int v;
  24. flush_cache_all();
  25. asm volatile(
  26. " mcr p15, 0, %1, c7, c5, 0\n"
  27. " mcr p15, 0, %1, c7, c10, 4\n"
  28. /*
  29. * Turn off coherency
  30. */
  31. " mrc p15, 0, %0, c1, c0, 1\n"
  32. " bic %0, %0, %3\n"
  33. " mcr p15, 0, %0, c1, c0, 1\n"
  34. " mrc p15, 0, %0, c1, c0, 0\n"
  35. " bic %0, %0, %2\n"
  36. " mcr p15, 0, %0, c1, c0, 0\n"
  37. : "=&r" (v)
  38. : "r" (0), "Ir" (CR_C), "Ir" (0x40)
  39. : "cc");
  40. }
  41. static inline void cpu_leave_lowpower(void)
  42. {
  43. unsigned int v;
  44. asm volatile(
  45. "mrc p15, 0, %0, c1, c0, 0\n"
  46. " orr %0, %0, %1\n"
  47. " mcr p15, 0, %0, c1, c0, 0\n"
  48. " mrc p15, 0, %0, c1, c0, 1\n"
  49. " orr %0, %0, %2\n"
  50. " mcr p15, 0, %0, c1, c0, 1\n"
  51. : "=&r" (v)
  52. : "Ir" (CR_C), "Ir" (0x40)
  53. : "cc");
  54. }
  55. static inline void platform_do_lowpower(unsigned int cpu, int *spurious)
  56. {
  57. for (;;) {
  58. /* make cpu1 to be turned off at next WFI command */
  59. if (cpu == 1)
  60. __raw_writel(0, S5P_ARM_CORE1_CONFIGURATION);
  61. /*
  62. * here's the WFI
  63. */
  64. asm(".word 0xe320f003\n"
  65. :
  66. :
  67. : "memory", "cc");
  68. if (pen_release == cpu_logical_map(cpu)) {
  69. /*
  70. * OK, proper wakeup, we're done
  71. */
  72. break;
  73. }
  74. /*
  75. * Getting here, means that we have come out of WFI without
  76. * having been woken up - this shouldn't happen
  77. *
  78. * Just note it happening - when we're woken, we can report
  79. * its occurrence.
  80. */
  81. (*spurious)++;
  82. }
  83. }
  84. int platform_cpu_kill(unsigned int cpu)
  85. {
  86. return 1;
  87. }
  88. /*
  89. * platform-specific code to shutdown a CPU
  90. *
  91. * Called with IRQs disabled
  92. */
  93. void platform_cpu_die(unsigned int cpu)
  94. {
  95. int spurious = 0;
  96. /*
  97. * we're ready for shutdown now, so do it
  98. */
  99. cpu_enter_lowpower();
  100. platform_do_lowpower(cpu, &spurious);
  101. /*
  102. * bring this CPU back into the world of cache
  103. * coherency, and then restore interrupts
  104. */
  105. cpu_leave_lowpower();
  106. if (spurious)
  107. pr_warn("CPU%u: %u spurious wakeup calls\n", cpu, spurious);
  108. }
  109. int platform_cpu_disable(unsigned int cpu)
  110. {
  111. /*
  112. * we don't allow CPU 0 to be shutdown (it is still too special
  113. * e.g. clock tick interrupts)
  114. */
  115. return cpu == 0 ? -EPERM : 0;
  116. }