import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / arm / kernel / psci_smp.c
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * Copyright (C) 2012 ARM Limited
12 *
13 * Author: Will Deacon <will.deacon@arm.com>
14 */
15
16 #include <linux/init.h>
17 #include <linux/smp.h>
18 #include <linux/of.h>
19 #include <linux/delay.h>
20 #include <uapi/linux/psci.h>
21
22 #include <asm/psci.h>
23 #include <asm/smp_plat.h>
24
25 /*
26 * psci_smp assumes that the following is true about PSCI:
27 *
28 * cpu_suspend Suspend the execution on a CPU
29 * @state we don't currently describe affinity levels, so just pass 0.
30 * @entry_point the first instruction to be executed on return
31 * returns 0 success, < 0 on failure
32 *
33 * cpu_off Power down a CPU
34 * @state we don't currently describe affinity levels, so just pass 0.
35 * no return on successful call
36 *
37 * cpu_on Power up a CPU
38 * @cpuid cpuid of target CPU, as from MPIDR
39 * @entry_point the first instruction to be executed on return
40 * returns 0 success, < 0 on failure
41 *
42 * migrate Migrate the context to a different CPU
43 * @cpuid cpuid of target CPU, as from MPIDR
44 * returns 0 success, < 0 on failure
45 *
46 */
47
48 extern void secondary_startup(void);
49
50 extern void __init mt_smp_prepare_cpus(unsigned int max_cpus);
51 extern void mt_smp_secondary_init(unsigned int cpu);
52 extern int mt_smp_boot_secondary(unsigned int cpu, struct task_struct *idle);
53 extern int mt_cpu_kill(unsigned int cpu);
54
55 static int psci_boot_secondary(unsigned int cpu, struct task_struct *idle)
56 {
57 int ret = -1;
58
59 if (psci_ops.cpu_on)
60 ret = psci_ops.cpu_on(cpu_logical_map(cpu),
61 __pa(secondary_startup));
62
63 if (ret < 0) {
64 pr_err("psci cpu_on failed\n");
65 return -ENODEV;
66 }
67
68 ret = mt_smp_boot_secondary(cpu, idle);
69 if (ret < 0) {
70 pr_err("mt_smp_boot_secondary failed\n");
71 return -ENODEV;
72 }
73 return 0;
74 }
75
76 #ifdef CONFIG_HOTPLUG_CPU
77 void __ref psci_cpu_die(unsigned int cpu)
78 {
79 const struct psci_power_state ps = {
80 .type = PSCI_POWER_STATE_TYPE_POWER_DOWN,
81 };
82
83 if (psci_ops.cpu_off)
84 psci_ops.cpu_off(ps);
85
86 /* We should never return */
87 panic("psci: cpu %d failed to shutdown\n", cpu);
88 }
89
90 int __ref psci_cpu_kill(unsigned int cpu)
91 {
92 //TODO: do more accurate synchornization between src CPU and dst CPU when applying psci
93 //int err, i;
94 //
95 //if (!psci_ops.affinity_info)
96 // return 1;
97 ///*
98 // * cpu_kill could race with cpu_die and we can
99 // * potentially end up declaring this cpu undead
100 // * while it is dying. So, try again a few times.
101 // */
102 //
103 //for (i = 0; i < 10; i++) {
104 // err = psci_ops.affinity_info(cpu_logical_map(cpu), 0);
105 // if (err == PSCI_0_2_AFFINITY_LEVEL_OFF) {
106 // pr_info("CPU%d killed.\n", cpu);
107 // return 1;
108 // }
109 //
110 // msleep(10);
111 // pr_info("Retrying again to check for CPU kill\n");
112 //}
113 //
114 //pr_warn("CPU%d may not have shut down cleanly (AFFINITY_INFO reports %d)\n",
115 // cpu, err);
116 ///* Make platform_cpu_kill() fail. */
117 //return 0;
118 return mt_cpu_kill(cpu);
119 }
120
121 #endif
122
123 bool __init psci_smp_available(void)
124 {
125 /* is cpu_on available at least? */
126 return (psci_ops.cpu_on != NULL);
127 }
128
129 struct smp_operations __initdata psci_smp_ops = {
130 .smp_prepare_cpus = mt_smp_prepare_cpus,
131 .smp_boot_secondary = psci_boot_secondary,
132 // FIXME: better way?
133 .smp_secondary_init = mt_smp_secondary_init,
134 #ifdef CONFIG_HOTPLUG_CPU
135 .cpu_die = psci_cpu_die,
136 .cpu_kill = psci_cpu_kill,
137 #endif
138 };