cpu_ops.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * CPU kernel entry/exit control
  3. *
  4. * Copyright (C) 2013 ARM Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/acpi.h>
  19. #include <linux/errno.h>
  20. #include <linux/of.h>
  21. #include <linux/string.h>
  22. #include <asm/acpi.h>
  23. #include <asm/cpu_ops.h>
  24. #include <asm/smp_plat.h>
  25. extern const struct cpu_operations smp_spin_table_ops;
  26. extern const struct cpu_operations acpi_parking_protocol_ops;
  27. extern const struct cpu_operations cpu_psci_ops;
  28. const struct cpu_operations *cpu_ops[NR_CPUS];
  29. static const struct cpu_operations *dt_supported_cpu_ops[] __initconst = {
  30. &smp_spin_table_ops,
  31. &cpu_psci_ops,
  32. NULL,
  33. };
  34. static const struct cpu_operations *acpi_supported_cpu_ops[] __initconst = {
  35. #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
  36. &acpi_parking_protocol_ops,
  37. #endif
  38. &cpu_psci_ops,
  39. NULL,
  40. };
  41. static const struct cpu_operations * __init cpu_get_ops(const char *name)
  42. {
  43. const struct cpu_operations **ops;
  44. ops = acpi_disabled ? dt_supported_cpu_ops : acpi_supported_cpu_ops;
  45. while (*ops) {
  46. if (!strcmp(name, (*ops)->name))
  47. return *ops;
  48. ops++;
  49. }
  50. return NULL;
  51. }
  52. static const char *__init cpu_read_enable_method(int cpu)
  53. {
  54. const char *enable_method;
  55. if (acpi_disabled) {
  56. struct device_node *dn = of_get_cpu_node(cpu, NULL);
  57. if (!dn) {
  58. if (!cpu)
  59. pr_err("Failed to find device node for boot cpu\n");
  60. return NULL;
  61. }
  62. enable_method = of_get_property(dn, "enable-method", NULL);
  63. if (!enable_method) {
  64. /*
  65. * The boot CPU may not have an enable method (e.g.
  66. * when spin-table is used for secondaries).
  67. * Don't warn spuriously.
  68. */
  69. if (cpu != 0)
  70. pr_err("%s: missing enable-method property\n",
  71. dn->full_name);
  72. }
  73. } else {
  74. enable_method = acpi_get_enable_method(cpu);
  75. if (!enable_method) {
  76. /*
  77. * In ACPI systems the boot CPU does not require
  78. * checking the enable method since for some
  79. * boot protocol (ie parking protocol) it need not
  80. * be initialized. Don't warn spuriously.
  81. */
  82. if (cpu != 0)
  83. pr_err("Unsupported ACPI enable-method\n");
  84. }
  85. }
  86. return enable_method;
  87. }
  88. /*
  89. * Read a cpu's enable method and record it in cpu_ops.
  90. */
  91. int __init cpu_read_ops(int cpu)
  92. {
  93. const char *enable_method = cpu_read_enable_method(cpu);
  94. if (!enable_method)
  95. return -ENODEV;
  96. cpu_ops[cpu] = cpu_get_ops(enable_method);
  97. if (!cpu_ops[cpu]) {
  98. pr_warn("Unsupported enable-method: %s\n", enable_method);
  99. return -EOPNOTSUPP;
  100. }
  101. return 0;
  102. }