1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/delay.h>
20#include <linux/init.h>
21#include <linux/of.h>
22#include <linux/smp.h>
23#include <linux/types.h>
24#include <linux/mm.h>
25
26#include <asm/cacheflush.h>
27#include <asm/cpu_ops.h>
28#include <asm/cputype.h>
29#include <asm/io.h>
30#include <asm/smp_plat.h>
31
32extern void secondary_holding_pen(void);
33volatile unsigned long __section(".mmuoff.data.read")
34secondary_holding_pen_release = INVALID_HWID;
35
36static phys_addr_t cpu_release_addr[NR_CPUS];
37
38
39
40
41
42
43
44static void write_pen_release(u64 val)
45{
46 void *start = (void *)&secondary_holding_pen_release;
47 unsigned long size = sizeof(secondary_holding_pen_release);
48
49 secondary_holding_pen_release = val;
50 __flush_dcache_area(start, size);
51}
52
53
54static int smp_spin_table_cpu_init(unsigned int cpu)
55{
56 struct device_node *dn;
57 int ret;
58
59 dn = of_get_cpu_node(cpu, NULL);
60 if (!dn)
61 return -ENODEV;
62
63
64
65
66 ret = of_property_read_u64(dn, "cpu-release-addr",
67 &cpu_release_addr[cpu]);
68 if (ret)
69 pr_err("CPU %d: missing or invalid cpu-release-addr property\n",
70 cpu);
71
72 of_node_put(dn);
73
74 return ret;
75}
76
77static int smp_spin_table_cpu_prepare(unsigned int cpu)
78{
79 __le64 __iomem *release_addr;
80
81 if (!cpu_release_addr[cpu])
82 return -ENODEV;
83
84
85
86
87
88
89
90 release_addr = ioremap_cache(cpu_release_addr[cpu],
91 sizeof(*release_addr));
92 if (!release_addr)
93 return -ENOMEM;
94
95
96
97
98
99
100
101
102 writeq_relaxed(__pa_symbol(secondary_holding_pen), release_addr);
103 __flush_dcache_area((__force void *)release_addr,
104 sizeof(*release_addr));
105
106
107
108
109 sev();
110
111 iounmap(release_addr);
112
113 return 0;
114}
115
116static int smp_spin_table_cpu_boot(unsigned int cpu)
117{
118
119
120
121 write_pen_release(cpu_logical_map(cpu));
122
123
124
125
126 sev();
127
128 return 0;
129}
130
131const struct cpu_operations smp_spin_table_ops = {
132 .name = "spin-table",
133 .cpu_init = smp_spin_table_cpu_init,
134 .cpu_prepare = smp_spin_table_cpu_prepare,
135 .cpu_boot = smp_spin_table_cpu_boot,
136};
137