blob: e133011f64b5bf661bd9aaa37013652d0a481e6d [file] [log] [blame]
Thomas Gleixnercaab2772019-06-03 07:44:50 +02001// SPDX-License-Identifier: GPL-2.0-only
Mark Rutlandcd1aebf2013-10-24 20:30:15 +01002/*
3 * CPU kernel entry/exit control
4 *
5 * Copyright (C) 2013 ARM Ltd.
Mark Rutlandcd1aebf2013-10-24 20:30:15 +01006 */
7
Lorenzo Pieralisi0f078332015-05-13 14:12:47 +01008#include <linux/acpi.h>
Jisheng Zhang5a9e3e12016-08-15 14:45:46 +08009#include <linux/cache.h>
Mark Rutlande8765b22013-10-24 20:30:17 +010010#include <linux/errno.h>
11#include <linux/of.h>
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010012#include <linux/string.h>
Lorenzo Pieralisi0f078332015-05-13 14:12:47 +010013#include <asm/acpi.h>
14#include <asm/cpu_ops.h>
15#include <asm/smp_plat.h>
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010016
17extern const struct cpu_operations smp_spin_table_ops;
Gavin Shan7fec52b2020-03-19 10:01:42 +110018#ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
Lorenzo Pieralisi5e89c552016-01-26 11:10:38 +000019extern const struct cpu_operations acpi_parking_protocol_ops;
Gavin Shan7fec52b2020-03-19 10:01:42 +110020#endif
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010021extern const struct cpu_operations cpu_psci_ops;
22
Gavin Shande58ed5e2020-03-19 10:01:44 +110023static const struct cpu_operations *cpu_ops[NR_CPUS] __ro_after_init;
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010024
Yury Norov770ba062017-11-29 17:03:03 +030025static const struct cpu_operations *const dt_supported_cpu_ops[] __initconst = {
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010026 &smp_spin_table_ops,
Lorenzo Pieralisi756854d2014-07-17 18:19:18 +010027 &cpu_psci_ops,
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010028 NULL,
29};
30
Yury Norov770ba062017-11-29 17:03:03 +030031static const struct cpu_operations *const acpi_supported_cpu_ops[] __initconst = {
Lorenzo Pieralisi5e89c552016-01-26 11:10:38 +000032#ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
33 &acpi_parking_protocol_ops,
34#endif
35 &cpu_psci_ops,
36 NULL,
37};
38
Lorenzo Pieralisi0f078332015-05-13 14:12:47 +010039static const struct cpu_operations * __init cpu_get_ops(const char *name)
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010040{
Yury Norov770ba062017-11-29 17:03:03 +030041 const struct cpu_operations *const *ops;
Lorenzo Pieralisi5e89c552016-01-26 11:10:38 +000042
43 ops = acpi_disabled ? dt_supported_cpu_ops : acpi_supported_cpu_ops;
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010044
45 while (*ops) {
46 if (!strcmp(name, (*ops)->name))
47 return *ops;
48
49 ops++;
50 }
51
52 return NULL;
53}
Mark Rutlande8765b22013-10-24 20:30:17 +010054
Lorenzo Pieralisi0f078332015-05-13 14:12:47 +010055static const char *__init cpu_read_enable_method(int cpu)
56{
57 const char *enable_method;
58
59 if (acpi_disabled) {
60 struct device_node *dn = of_get_cpu_node(cpu, NULL);
61
62 if (!dn) {
63 if (!cpu)
64 pr_err("Failed to find device node for boot cpu\n");
65 return NULL;
66 }
67
68 enable_method = of_get_property(dn, "enable-method", NULL);
69 if (!enable_method) {
70 /*
71 * The boot CPU may not have an enable method (e.g.
72 * when spin-table is used for secondaries).
73 * Don't warn spuriously.
74 */
75 if (cpu != 0)
Rob Herringa270f322017-07-18 16:42:42 -050076 pr_err("%pOF: missing enable-method property\n",
77 dn);
Lorenzo Pieralisi0f078332015-05-13 14:12:47 +010078 }
Wen Yang92606ec2019-03-05 19:34:05 +080079 of_node_put(dn);
Lorenzo Pieralisi0f078332015-05-13 14:12:47 +010080 } else {
81 enable_method = acpi_get_enable_method(cpu);
Lorenzo Pieralisi5e89c552016-01-26 11:10:38 +000082 if (!enable_method) {
83 /*
84 * In ACPI systems the boot CPU does not require
85 * checking the enable method since for some
86 * boot protocol (ie parking protocol) it need not
87 * be initialized. Don't warn spuriously.
88 */
89 if (cpu != 0)
90 pr_err("Unsupported ACPI enable-method\n");
91 }
Lorenzo Pieralisi0f078332015-05-13 14:12:47 +010092 }
93
94 return enable_method;
95}
Mark Rutlande8765b22013-10-24 20:30:17 +010096/*
Lorenzo Pieralisi0f078332015-05-13 14:12:47 +010097 * Read a cpu's enable method and record it in cpu_ops.
Mark Rutlande8765b22013-10-24 20:30:17 +010098 */
Gavin Shan6885fb12020-03-19 10:01:43 +110099int __init init_cpu_ops(int cpu)
Mark Rutlande8765b22013-10-24 20:30:17 +0100100{
Lorenzo Pieralisi0f078332015-05-13 14:12:47 +0100101 const char *enable_method = cpu_read_enable_method(cpu);
Lorenzo Pieralisi819a8822015-05-13 14:12:46 +0100102
Lorenzo Pieralisi0f078332015-05-13 14:12:47 +0100103 if (!enable_method)
Lorenzo Pieralisi819a8822015-05-13 14:12:46 +0100104 return -ENODEV;
Mark Rutlande8765b22013-10-24 20:30:17 +0100105
106 cpu_ops[cpu] = cpu_get_ops(enable_method);
107 if (!cpu_ops[cpu]) {
Lorenzo Pieralisi0f078332015-05-13 14:12:47 +0100108 pr_warn("Unsupported enable-method: %s\n", enable_method);
Mark Rutlande8765b22013-10-24 20:30:17 +0100109 return -EOPNOTSUPP;
110 }
111
112 return 0;
113}
Gavin Shande58ed5e2020-03-19 10:01:44 +1100114
115const struct cpu_operations *get_cpu_ops(int cpu)
116{
117 return cpu_ops[cpu];
118}