cpu_ops.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * CPU kernel entry/exit control
  4. *
  5. * Copyright (C) 2013 ARM Ltd.
  6. */
  7. #include <linux/acpi.h>
  8. #include <linux/cache.h>
  9. #include <linux/errno.h>
  10. #include <linux/of.h>
  11. #include <linux/string.h>
  12. #include <asm/acpi.h>
  13. #include <asm/cpu_ops.h>
  14. #include <asm/smp_plat.h>
  15. extern const struct cpu_operations smp_spin_table_ops;
  16. #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
  17. extern const struct cpu_operations acpi_parking_protocol_ops;
  18. #endif
  19. extern const struct cpu_operations cpu_psci_ops;
  20. static const struct cpu_operations *cpu_ops[NR_CPUS] __ro_after_init;
  21. static const struct cpu_operations *const dt_supported_cpu_ops[] __initconst = {
  22. &smp_spin_table_ops,
  23. &cpu_psci_ops,
  24. NULL,
  25. };
  26. static const struct cpu_operations *const acpi_supported_cpu_ops[] __initconst = {
  27. #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
  28. &acpi_parking_protocol_ops,
  29. #endif
  30. &cpu_psci_ops,
  31. NULL,
  32. };
  33. static const struct cpu_operations * __init cpu_get_ops(const char *name)
  34. {
  35. const struct cpu_operations *const *ops;
  36. ops = acpi_disabled ? dt_supported_cpu_ops : acpi_supported_cpu_ops;
  37. while (*ops) {
  38. if (!strcmp(name, (*ops)->name))
  39. return *ops;
  40. ops++;
  41. }
  42. return NULL;
  43. }
  44. static const char *__init cpu_read_enable_method(int cpu)
  45. {
  46. const char *enable_method;
  47. if (acpi_disabled) {
  48. struct device_node *dn = of_get_cpu_node(cpu, NULL);
  49. if (!dn) {
  50. if (!cpu)
  51. pr_err("Failed to find device node for boot cpu\n");
  52. return NULL;
  53. }
  54. enable_method = of_get_property(dn, "enable-method", NULL);
  55. if (!enable_method) {
  56. /*
  57. * The boot CPU may not have an enable method (e.g.
  58. * when spin-table is used for secondaries).
  59. * Don't warn spuriously.
  60. */
  61. if (cpu != 0)
  62. pr_err("%pOF: missing enable-method property\n",
  63. dn);
  64. }
  65. of_node_put(dn);
  66. } else {
  67. enable_method = acpi_get_enable_method(cpu);
  68. if (!enable_method) {
  69. /*
  70. * In ACPI systems the boot CPU does not require
  71. * checking the enable method since for some
  72. * boot protocol (ie parking protocol) it need not
  73. * be initialized. Don't warn spuriously.
  74. */
  75. if (cpu != 0)
  76. pr_err("Unsupported ACPI enable-method\n");
  77. }
  78. }
  79. return enable_method;
  80. }
  81. /*
  82. * Read a cpu's enable method and record it in cpu_ops.
  83. */
  84. int __init init_cpu_ops(int cpu)
  85. {
  86. const char *enable_method = cpu_read_enable_method(cpu);
  87. if (!enable_method)
  88. return -ENODEV;
  89. cpu_ops[cpu] = cpu_get_ops(enable_method);
  90. if (!cpu_ops[cpu]) {
  91. pr_warn("Unsupported enable-method: %s\n", enable_method);
  92. return -EOPNOTSUPP;
  93. }
  94. return 0;
  95. }
  96. const struct cpu_operations *get_cpu_ops(int cpu)
  97. {
  98. return cpu_ops[cpu];
  99. }