hotplug.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * SMP support for R-Mobile / SH-Mobile
  3. *
  4. * Copyright (C) 2010 Magnus Damm
  5. *
  6. * Based on realview, Copyright (C) 2002 ARM Ltd, 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/cpumask.h>
  16. #include <linux/delay.h>
  17. #include <mach/common.h>
  18. #include <asm/cacheflush.h>
  19. static cpumask_t dead_cpus;
  20. int platform_cpu_kill(unsigned int cpu)
  21. {
  22. int k;
  23. /* this function is running on another CPU than the offline target,
  24. * here we need wait for shutdown code in platform_cpu_die() to
  25. * finish before asking SoC-specific code to power off the CPU core.
  26. */
  27. for (k = 0; k < 1000; k++) {
  28. if (cpumask_test_cpu(cpu, &dead_cpus))
  29. return shmobile_platform_cpu_kill(cpu);
  30. mdelay(1);
  31. }
  32. return 0;
  33. }
  34. void platform_cpu_die(unsigned int cpu)
  35. {
  36. /* hardware shutdown code running on the CPU that is being offlined */
  37. flush_cache_all();
  38. dsb();
  39. /* notify platform_cpu_kill() that hardware shutdown is finished */
  40. cpumask_set_cpu(cpu, &dead_cpus);
  41. /* wait for SoC code in platform_cpu_kill() to shut off CPU core
  42. * power. CPU bring up starts from the reset vector.
  43. */
  44. while (1) {
  45. /*
  46. * here's the WFI
  47. */
  48. asm(".word 0xe320f003\n"
  49. :
  50. :
  51. : "memory", "cc");
  52. }
  53. }
  54. int platform_cpu_disable(unsigned int cpu)
  55. {
  56. cpumask_clear_cpu(cpu, &dead_cpus);
  57. /*
  58. * we don't allow CPU 0 to be shutdown (it is still too special
  59. * e.g. clock tick interrupts)
  60. */
  61. return cpu == 0 ? -EPERM : 0;
  62. }