hotplug.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) STMicroelectronics 2009
  3. * Copyright (C) ST-Ericsson SA 2010
  4. *
  5. * License Terms: GNU General Public License v2
  6. * Based on ARM realview platform
  7. *
  8. * Author: Sundar Iyer <sundar.iyer@stericsson.com>
  9. *
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/errno.h>
  13. #include <linux/smp.h>
  14. #include <linux/completion.h>
  15. #include <asm/cacheflush.h>
  16. extern volatile int pen_release;
  17. static DECLARE_COMPLETION(cpu_killed);
  18. static inline void platform_do_lowpower(unsigned int cpu)
  19. {
  20. flush_cache_all();
  21. /* we put the platform to just WFI */
  22. for (;;) {
  23. __asm__ __volatile__("dsb\n\t" "wfi\n\t"
  24. : : : "memory");
  25. if (pen_release == cpu) {
  26. /*
  27. * OK, proper wakeup, we're done
  28. */
  29. break;
  30. }
  31. }
  32. }
  33. int platform_cpu_kill(unsigned int cpu)
  34. {
  35. return wait_for_completion_timeout(&cpu_killed, 5000);
  36. }
  37. /*
  38. * platform-specific code to shutdown a CPU
  39. *
  40. * Called with IRQs disabled
  41. */
  42. void platform_cpu_die(unsigned int cpu)
  43. {
  44. #ifdef DEBUG
  45. unsigned int this_cpu = hard_smp_processor_id();
  46. if (cpu != this_cpu) {
  47. printk(KERN_CRIT "Eek! platform_cpu_die running on %u, should be %u\n",
  48. this_cpu, cpu);
  49. BUG();
  50. }
  51. #endif
  52. printk(KERN_NOTICE "CPU%u: shutdown\n", cpu);
  53. complete(&cpu_killed);
  54. /* directly enter low power state, skipping secure registers */
  55. platform_do_lowpower(cpu);
  56. }
  57. int platform_cpu_disable(unsigned int cpu)
  58. {
  59. /*
  60. * we don't allow CPU 0 to be shutdown (it is still too special
  61. * e.g. clock tick interrupts)
  62. */
  63. return cpu == 0 ? -EPERM : 0;
  64. }