1
2
3
4
5
6
7
8
9#include <linux/init.h>
10#include <linux/smp.h>
11#include <linux/of.h>
12#include <linux/delay.h>
13#include <linux/psci.h>
14
15#include <uapi/linux/psci.h>
16
17#include <asm/psci.h>
18#include <asm/smp_plat.h>
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43extern void secondary_startup(void);
44
45static int psci_boot_secondary(unsigned int cpu, struct task_struct *idle)
46{
47 if (psci_ops.cpu_on)
48 return psci_ops.cpu_on(cpu_logical_map(cpu),
49 virt_to_idmap(&secondary_startup));
50 return -ENODEV;
51}
52
53#ifdef CONFIG_HOTPLUG_CPU
54static int psci_cpu_disable(unsigned int cpu)
55{
56
57 if (!psci_ops.cpu_off)
58 return -EOPNOTSUPP;
59
60
61 if (psci_tos_resident_on(cpu))
62 return -EPERM;
63
64 return 0;
65}
66
67static void psci_cpu_die(unsigned int cpu)
68{
69 u32 state = PSCI_POWER_STATE_TYPE_POWER_DOWN <<
70 PSCI_0_2_POWER_STATE_TYPE_SHIFT;
71
72 if (psci_ops.cpu_off)
73 psci_ops.cpu_off(state);
74
75
76 panic("psci: cpu %d failed to shutdown\n", cpu);
77}
78
79static int psci_cpu_kill(unsigned int cpu)
80{
81 int err, i;
82
83 if (!psci_ops.affinity_info)
84 return 1;
85
86
87
88
89
90
91 for (i = 0; i < 10; i++) {
92 err = psci_ops.affinity_info(cpu_logical_map(cpu), 0);
93 if (err == PSCI_0_2_AFFINITY_LEVEL_OFF) {
94 pr_info("CPU%d killed.\n", cpu);
95 return 1;
96 }
97
98 msleep(10);
99 pr_info("Retrying again to check for CPU kill\n");
100 }
101
102 pr_warn("CPU%d may not have shut down cleanly (AFFINITY_INFO reports %d)\n",
103 cpu, err);
104
105 return 0;
106}
107
108#endif
109
110bool __init psci_smp_available(void)
111{
112
113 return (psci_ops.cpu_on != NULL);
114}
115
116const struct smp_operations psci_smp_ops __initconst = {
117 .smp_boot_secondary = psci_boot_secondary,
118#ifdef CONFIG_HOTPLUG_CPU
119 .cpu_disable = psci_cpu_disable,
120 .cpu_die = psci_cpu_die,
121 .cpu_kill = psci_cpu_kill,
122#endif
123};
124