psci_smp.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. #if defined(CONFIG_ARCH_MT6735) || defined(CONFIG_ARCH_MT6735M) || \
  23. defined(CONFIG_ARCH_MT6753)
  24. #include <mt-smp.h>
  25. #endif
  26. /*
  27. * psci_smp assumes that the following is true about PSCI:
  28. *
  29. * cpu_suspend Suspend the execution on a CPU
  30. * @state we don't currently describe affinity levels, so just pass 0.
  31. * @entry_point the first instruction to be executed on return
  32. * returns 0 success, < 0 on failure
  33. *
  34. * cpu_off Power down a CPU
  35. * @state we don't currently describe affinity levels, so just pass 0.
  36. * no return on successful call
  37. *
  38. * cpu_on Power up a CPU
  39. * @cpuid cpuid of target CPU, as from MPIDR
  40. * @entry_point the first instruction to be executed on return
  41. * returns 0 success, < 0 on failure
  42. *
  43. * migrate Migrate the context to a different CPU
  44. * @cpuid cpuid of target CPU, as from MPIDR
  45. * returns 0 success, < 0 on failure
  46. *
  47. */
  48. extern void secondary_startup(void);
  49. static int psci_boot_secondary(unsigned int cpu, struct task_struct *idle)
  50. {
  51. #if defined(CONFIG_ARCH_MT6735) || defined(CONFIG_ARCH_MT6735M) || \
  52. defined(CONFIG_ARCH_MT6753)
  53. int ret = -1;
  54. if (psci_ops.cpu_on)
  55. ret = psci_ops.cpu_on(cpu_logical_map(cpu),
  56. __pa(secondary_startup));
  57. if (ret < 0) {
  58. pr_err("psci cpu_on failed\n");
  59. return -ENODEV;
  60. }
  61. ret = mt_smp_boot_secondary(cpu, idle);
  62. if (ret < 0) {
  63. pr_err("mt_smp_boot_secondary failed\n");
  64. return -ENODEV;
  65. }
  66. return 0;
  67. #else
  68. if (psci_ops.cpu_on)
  69. return psci_ops.cpu_on(cpu_logical_map(cpu),
  70. __pa(secondary_startup));
  71. return -ENODEV;
  72. #endif
  73. }
  74. #ifdef CONFIG_HOTPLUG_CPU
  75. void __ref psci_cpu_die(unsigned int cpu)
  76. {
  77. const struct psci_power_state ps = {
  78. .type = PSCI_POWER_STATE_TYPE_POWER_DOWN,
  79. };
  80. if (psci_ops.cpu_off)
  81. psci_ops.cpu_off(ps);
  82. /* We should never return */
  83. panic("psci: cpu %d failed to shutdown\n", cpu);
  84. }
  85. #if defined(CONFIG_ARCH_MT6735) || defined(CONFIG_ARCH_MT6735M) || \
  86. defined(CONFIG_ARCH_MT6753)
  87. int __ref psci_cpu_kill(unsigned int cpu)
  88. {
  89. return mt_cpu_kill(cpu);
  90. }
  91. #else
  92. int __ref psci_cpu_kill(unsigned int cpu)
  93. {
  94. int err, i;
  95. if (!psci_ops.affinity_info)
  96. return 1;
  97. /*
  98. * cpu_kill could race with cpu_die and we can
  99. * potentially end up declaring this cpu undead
  100. * while it is dying. So, try again a few times.
  101. */
  102. for (i = 0; i < 10; i++) {
  103. err = psci_ops.affinity_info(cpu_logical_map(cpu), 0);
  104. if (err == PSCI_0_2_AFFINITY_LEVEL_OFF) {
  105. pr_info("CPU%d killed.\n", cpu);
  106. return 1;
  107. }
  108. msleep(10);
  109. pr_info("Retrying again to check for CPU kill\n");
  110. }
  111. pr_warn("CPU%d may not have shut down cleanly (AFFINITY_INFO reports %d)\n",
  112. cpu, err);
  113. /* Make platform_cpu_kill() fail. */
  114. return 0;
  115. }
  116. #endif
  117. #endif
  118. bool __init psci_smp_available(void)
  119. {
  120. /* is cpu_on available at least? */
  121. return (psci_ops.cpu_on != NULL);
  122. }
  123. struct smp_operations __initdata psci_smp_ops = {
  124. #if defined(CONFIG_ARCH_MT6735) || defined(CONFIG_ARCH_MT6735M) || \
  125. defined(CONFIG_ARCH_MT6753)
  126. .smp_prepare_cpus = mt_smp_prepare_cpus,
  127. #endif
  128. .smp_boot_secondary = psci_boot_secondary,
  129. #if defined(CONFIG_ARCH_MT6735) || defined(CONFIG_ARCH_MT6735M) || \
  130. defined(CONFIG_ARCH_MT6753)
  131. .smp_secondary_init = mt_smp_secondary_init,
  132. #endif
  133. #ifdef CONFIG_HOTPLUG_CPU
  134. .cpu_die = psci_cpu_die,
  135. .cpu_kill = psci_cpu_kill,
  136. #endif
  137. };