1
2
3
4
5
6
7
8
9
10
11
12
13
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48extern void secondary_startup(void);
49
50static int psci_boot_secondary(unsigned int cpu, struct task_struct *idle)
51{
52 if (psci_ops.cpu_on)
53 return psci_ops.cpu_on(cpu_logical_map(cpu),
54 __pa(secondary_startup));
55 return -ENODEV;
56}
57
58#ifdef CONFIG_HOTPLUG_CPU
59void __ref psci_cpu_die(unsigned int cpu)
60{
61 const struct psci_power_state ps = {
62 .type = PSCI_POWER_STATE_TYPE_POWER_DOWN,
63 };
64
65 if (psci_ops.cpu_off)
66 psci_ops.cpu_off(ps);
67
68
69 panic("psci: cpu %d failed to shutdown\n", cpu);
70}
71
72int __ref psci_cpu_kill(unsigned int cpu)
73{
74 int err, i;
75
76 if (!psci_ops.affinity_info)
77 return 1;
78
79
80
81
82
83
84 for (i = 0; i < 10; i++) {
85 err = psci_ops.affinity_info(cpu_logical_map(cpu), 0);
86 if (err == PSCI_0_2_AFFINITY_LEVEL_OFF) {
87 pr_info("CPU%d killed.\n", cpu);
88 return 1;
89 }
90
91 msleep(10);
92 pr_info("Retrying again to check for CPU kill\n");
93 }
94
95 pr_warn("CPU%d may not have shut down cleanly (AFFINITY_INFO reports %d)\n",
96 cpu, err);
97
98 return 0;
99}
100
101#endif
102
103bool __init psci_smp_available(void)
104{
105
106 return (psci_ops.cpu_on != NULL);
107}
108
109struct smp_operations __initdata psci_smp_ops = {
110 .smp_boot_secondary = psci_boot_secondary,
111#ifdef CONFIG_HOTPLUG_CPU
112 .cpu_die = psci_cpu_die,
113 .cpu_kill = psci_cpu_kill,
114#endif
115};
116