import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / arm64 / kernel / cpu_ops.c
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
19 #include <asm/cpu_ops.h>
20 #include <asm/smp_plat.h>
21 #include <linux/errno.h>
22 #include <linux/of.h>
23 #include <linux/string.h>
24
25 extern const struct cpu_operations smp_spin_table_ops;
26 extern const struct cpu_operations cpu_psci_ops;
27 #ifdef CONFIG_MTK_PSCI
28 extern const struct cpu_operations mt_cpu_psci_ops;
29 #endif
30
31 const struct cpu_operations *cpu_ops[NR_CPUS];
32
33 static const struct cpu_operations *supported_cpu_ops[] __initconst = {
34 #ifdef CONFIG_SMP
35 &smp_spin_table_ops,
36 &cpu_psci_ops,
37 #ifdef CONFIG_MTK_PSCI
38 &mt_cpu_psci_ops,
39 #endif
40 #endif
41 NULL,
42 };
43
44 static const struct cpu_operations * __init cpu_get_ops(const char *name)
45 {
46 const struct cpu_operations **ops = supported_cpu_ops;
47
48 while (*ops) {
49 if (!strcmp(name, (*ops)->name))
50 return *ops;
51
52 ops++;
53 }
54
55 return NULL;
56 }
57
58 /*
59 * Read a cpu's enable method from the device tree and record it in cpu_ops.
60 */
61 int __init cpu_read_ops(struct device_node *dn, int cpu)
62 {
63 const char *enable_method = of_get_property(dn, "enable-method", NULL);
64 if (!enable_method) {
65 /*
66 * The boot CPU may not have an enable method (e.g. when
67 * spin-table is used for secondaries). Don't warn spuriously.
68 */
69 if (cpu != 0)
70 pr_err("%s: missing enable-method property\n",
71 dn->full_name);
72 return -ENOENT;
73 }
74
75 cpu_ops[cpu] = cpu_get_ops(enable_method);
76 if (!cpu_ops[cpu]) {
77 pr_err("%s: invalid enable-method property: %s\n",
78 dn->full_name, enable_method);
79 return -EOPNOTSUPP;
80 }
81
82 return 0;
83 }
84
85 void __init cpu_read_bootcpu_ops(void)
86 {
87 struct device_node *dn = NULL;
88 u64 mpidr = cpu_logical_map(0);
89
90 while ((dn = of_find_node_by_type(dn, "cpu"))) {
91 u64 hwid;
92 const __be32 *prop;
93
94 prop = of_get_property(dn, "reg", NULL);
95 if (!prop)
96 continue;
97
98 hwid = of_read_number(prop, of_n_addr_cells(dn));
99 if (hwid == mpidr) {
100 cpu_read_ops(dn, 0);
101 of_node_put(dn);
102 return;
103 }
104 }
105 }