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.
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.
11 * Copyright (C) 2012 ARM Limited
13 * Author: Will Deacon <will.deacon@arm.com>
16 #include <linux/init.h>
17 #include <linux/smp.h>
19 #include <linux/delay.h>
20 #include <uapi/linux/psci.h>
23 #include <asm/smp_plat.h>
26 * psci_smp assumes that the following is true about PSCI:
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
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
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
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
48 extern void secondary_startup(void);
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
);
55 static int psci_boot_secondary(unsigned int cpu
, struct task_struct
*idle
)
60 ret
= psci_ops
.cpu_on(cpu_logical_map(cpu
),
61 __pa(secondary_startup
));
64 pr_err("psci cpu_on failed\n");
68 ret
= mt_smp_boot_secondary(cpu
, idle
);
70 pr_err("mt_smp_boot_secondary failed\n");
76 #ifdef CONFIG_HOTPLUG_CPU
77 void __ref
psci_cpu_die(unsigned int cpu
)
79 const struct psci_power_state ps
= {
80 .type
= PSCI_POWER_STATE_TYPE_POWER_DOWN
,
86 /* We should never return */
87 panic("psci: cpu %d failed to shutdown\n", cpu
);
90 int __ref
psci_cpu_kill(unsigned int cpu
)
92 //TODO: do more accurate synchornization between src CPU and dst CPU when applying psci
95 //if (!psci_ops.affinity_info)
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.
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);
111 // pr_info("Retrying again to check for CPU kill\n");
114 //pr_warn("CPU%d may not have shut down cleanly (AFFINITY_INFO reports %d)\n",
116 ///* Make platform_cpu_kill() fail. */
118 return mt_cpu_kill(cpu
);
123 bool __init
psci_smp_available(void)
125 /* is cpu_on available at least? */
126 return (psci_ops
.cpu_on
!= NULL
);
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
,