cpu_ops.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <asm/cpu_ops.h>
  19. #include <asm/smp_plat.h>
  20. #include <linux/errno.h>
  21. #include <linux/of.h>
  22. #include <linux/string.h>
  23. #if defined(CONFIG_MTK_PSCI)
  24. #include <mt_cpu_psci_ops.h>
  25. #endif
  26. extern const struct cpu_operations smp_spin_table_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 *supported_cpu_ops[] __initconst = {
  30. #ifdef CONFIG_SMP
  31. &smp_spin_table_ops,
  32. #ifdef CONFIG_MTK_PSCI
  33. &mt_cpu_psci_ops,
  34. #endif
  35. #endif
  36. &cpu_psci_ops,
  37. NULL,
  38. };
  39. static const struct cpu_operations * __init cpu_get_ops(const char *name)
  40. {
  41. const struct cpu_operations **ops = supported_cpu_ops;
  42. while (*ops) {
  43. if (!strcmp(name, (*ops)->name))
  44. return *ops;
  45. ops++;
  46. }
  47. return NULL;
  48. }
  49. /*
  50. * Read a cpu's enable method from the device tree and record it in cpu_ops.
  51. */
  52. int __init cpu_read_ops(struct device_node *dn, int cpu)
  53. {
  54. const char *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. when
  58. * spin-table is used for secondaries). Don't warn spuriously.
  59. */
  60. if (cpu != 0)
  61. pr_err("%s: missing enable-method property\n",
  62. dn->full_name);
  63. return -ENOENT;
  64. }
  65. cpu_ops[cpu] = cpu_get_ops(enable_method);
  66. if (!cpu_ops[cpu]) {
  67. pr_warn("%s: unsupported enable-method property: %s\n",
  68. dn->full_name, enable_method);
  69. return -EOPNOTSUPP;
  70. }
  71. return 0;
  72. }
  73. void __init cpu_read_bootcpu_ops(void)
  74. {
  75. struct device_node *dn = of_get_cpu_node(0, NULL);
  76. if (!dn) {
  77. pr_err("Failed to find device node for boot cpu\n");
  78. return;
  79. }
  80. cpu_read_ops(dn, 0);
  81. }