cpu_ops.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. extern const struct cpu_operations smp_spin_table_ops;
  24. extern const struct cpu_operations cpu_psci_ops;
  25. const struct cpu_operations *cpu_ops[NR_CPUS];
  26. static const struct cpu_operations *supported_cpu_ops[] __initconst = {
  27. #ifdef CONFIG_SMP
  28. &smp_spin_table_ops,
  29. &cpu_psci_ops,
  30. #endif
  31. NULL,
  32. };
  33. static const struct cpu_operations * __init cpu_get_ops(const char *name)
  34. {
  35. const struct cpu_operations **ops = supported_cpu_ops;
  36. while (*ops) {
  37. if (!strcmp(name, (*ops)->name))
  38. return *ops;
  39. ops++;
  40. }
  41. return NULL;
  42. }
  43. /*
  44. * Read a cpu's enable method from the device tree and record it in cpu_ops.
  45. */
  46. int __init cpu_read_ops(struct device_node *dn, int cpu)
  47. {
  48. const char *enable_method = of_get_property(dn, "enable-method", NULL);
  49. if (!enable_method) {
  50. /*
  51. * The boot CPU may not have an enable method (e.g. when
  52. * spin-table is used for secondaries). Don't warn spuriously.
  53. */
  54. if (cpu != 0)
  55. pr_err("%s: missing enable-method property\n",
  56. dn->full_name);
  57. return -ENOENT;
  58. }
  59. cpu_ops[cpu] = cpu_get_ops(enable_method);
  60. if (!cpu_ops[cpu]) {
  61. pr_warn("%s: unsupported enable-method property: %s\n",
  62. dn->full_name, enable_method);
  63. return -EOPNOTSUPP;
  64. }
  65. return 0;
  66. }
  67. void __init cpu_read_bootcpu_ops(void)
  68. {
  69. struct device_node *dn = of_get_cpu_node(0, NULL);
  70. if (!dn) {
  71. pr_err("Failed to find device node for boot cpu\n");
  72. return;
  73. }
  74. cpu_read_ops(dn, 0);
  75. }