psci_smp.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License version 2 as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * Copyright (C) 2012 ARM Limited
  12. *
  13. * Author: Will Deacon <will.deacon@arm.com>
  14. */
  15. #include <linux/init.h>
  16. #include <linux/smp.h>
  17. #include <linux/of.h>
  18. #include <linux/delay.h>
  19. #include <uapi/linux/psci.h>
  20. #include <asm/psci.h>
  21. #include <asm/smp_plat.h>
  22. /*
  23. * psci_smp assumes that the following is true about PSCI:
  24. *
  25. * cpu_suspend Suspend the execution on a CPU
  26. * @state we don't currently describe affinity levels, so just pass 0.
  27. * @entry_point the first instruction to be executed on return
  28. * returns 0 success, < 0 on failure
  29. *
  30. * cpu_off Power down a CPU
  31. * @state we don't currently describe affinity levels, so just pass 0.
  32. * no return on successful call
  33. *
  34. * cpu_on Power up a CPU
  35. * @cpuid cpuid of target CPU, as from MPIDR
  36. * @entry_point the first instruction to be executed on return
  37. * returns 0 success, < 0 on failure
  38. *
  39. * migrate Migrate the context to a different CPU
  40. * @cpuid cpuid of target CPU, as from MPIDR
  41. * returns 0 success, < 0 on failure
  42. *
  43. */
  44. extern void secondary_startup(void);
  45. static int psci_boot_secondary(unsigned int cpu, struct task_struct *idle)
  46. {
  47. if (psci_ops.cpu_on)
  48. return psci_ops.cpu_on(cpu_logical_map(cpu),
  49. __pa(secondary_startup));
  50. return -ENODEV;
  51. }
  52. #ifdef CONFIG_HOTPLUG_CPU
  53. void __ref psci_cpu_die(unsigned int cpu)
  54. {
  55. const struct psci_power_state ps = {
  56. .type = PSCI_POWER_STATE_TYPE_POWER_DOWN,
  57. };
  58. if (psci_ops.cpu_off)
  59. psci_ops.cpu_off(ps);
  60. /* We should never return */
  61. panic("psci: cpu %d failed to shutdown\n", cpu);
  62. }
  63. int __ref psci_cpu_kill(unsigned int cpu)
  64. {
  65. int err, i;
  66. if (!psci_ops.affinity_info)
  67. return 1;
  68. /*
  69. * cpu_kill could race with cpu_die and we can
  70. * potentially end up declaring this cpu undead
  71. * while it is dying. So, try again a few times.
  72. */
  73. for (i = 0; i < 10; i++) {
  74. err = psci_ops.affinity_info(cpu_logical_map(cpu), 0);
  75. if (err == PSCI_0_2_AFFINITY_LEVEL_OFF) {
  76. pr_info("CPU%d killed.\n", cpu);
  77. return 1;
  78. }
  79. msleep(10);
  80. pr_info("Retrying again to check for CPU kill\n");
  81. }
  82. pr_warn("CPU%d may not have shut down cleanly (AFFINITY_INFO reports %d)\n",
  83. cpu, err);
  84. /* Make platform_cpu_kill() fail. */
  85. return 0;
  86. }
  87. #endif
  88. bool __init psci_smp_available(void)
  89. {
  90. /* is cpu_on available at least? */
  91. return (psci_ops.cpu_on != NULL);
  92. }
  93. struct smp_operations __initdata psci_smp_ops = {
  94. .smp_boot_secondary = psci_boot_secondary,
  95. #ifdef CONFIG_HOTPLUG_CPU
  96. .cpu_die = psci_cpu_die,
  97. .cpu_kill = psci_cpu_kill,
  98. #endif
  99. };