1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/export.h>
22#include <linux/jiffies.h>
23#include <linux/init.h>
24#include <linux/io.h>
25#include <asm/cacheflush.h>
26#include <asm/smp_scu.h>
27#include <linux/irqchip/arm-gic.h>
28#include "common.h"
29
30
31
32
33
34
35static int ncores;
36
37int zynq_cpun_start(u32 address, int cpu)
38{
39 u32 trampoline_code_size = &zynq_secondary_trampoline_end -
40 &zynq_secondary_trampoline;
41
42
43
44 if (!(address & 3) && (!address || (address >= trampoline_code_size))) {
45
46 static u8 __iomem *zero;
47 u32 trampoline_size = &zynq_secondary_trampoline_jump -
48 &zynq_secondary_trampoline;
49
50 zynq_slcr_cpu_stop(cpu);
51 if (address) {
52 if (__pa(PAGE_OFFSET)) {
53 zero = ioremap(0, trampoline_code_size);
54 if (!zero) {
55 pr_warn("BOOTUP jump vectors not accessible\n");
56 return -1;
57 }
58 } else {
59 zero = (__force u8 __iomem *)PAGE_OFFSET;
60 }
61
62
63
64
65
66
67
68 memcpy((__force void *)zero, &zynq_secondary_trampoline,
69 trampoline_size);
70 writel(address, zero + trampoline_size);
71
72 flush_cache_all();
73 outer_flush_range(0, trampoline_code_size);
74 smp_wmb();
75
76 if (__pa(PAGE_OFFSET))
77 iounmap(zero);
78 }
79 zynq_slcr_cpu_start(cpu);
80
81 return 0;
82 }
83
84 pr_warn("Can't start CPU%d: Wrong starting address %x\n", cpu, address);
85
86 return -1;
87}
88EXPORT_SYMBOL(zynq_cpun_start);
89
90static int zynq_boot_secondary(unsigned int cpu, struct task_struct *idle)
91{
92 if (!zynq_efuse_cpu_state(cpu))
93 return -1;
94
95 return zynq_cpun_start(virt_to_phys(secondary_startup), cpu);
96}
97
98
99
100
101
102static void __init zynq_smp_init_cpus(void)
103{
104 int i;
105
106 ncores = scu_get_core_count(zynq_scu_base);
107
108 for (i = 0; i < ncores && i < CONFIG_NR_CPUS; i++)
109 set_cpu_possible(i, true);
110}
111
112static void __init zynq_smp_prepare_cpus(unsigned int max_cpus)
113{
114 scu_enable(zynq_scu_base);
115}
116
117
118
119
120
121
122
123
124static void zynq_secondary_init(unsigned int cpu)
125{
126 zynq_core_pm_init();
127 zynq_prefetch_init();
128}
129
130#ifdef CONFIG_HOTPLUG_CPU
131static int zynq_cpu_kill(unsigned cpu)
132{
133 unsigned long timeout = jiffies + msecs_to_jiffies(50);
134
135 while (zynq_slcr_cpu_state_read(cpu))
136 if (time_after(jiffies, timeout))
137 return 0;
138
139 zynq_slcr_cpu_stop(cpu);
140 return 1;
141}
142
143
144
145
146
147
148
149
150static void zynq_cpu_die(unsigned int cpu)
151{
152 zynq_slcr_cpu_state_write(cpu, true);
153
154
155
156
157
158
159 for (;;)
160 cpu_do_idle();
161}
162#endif
163
164const struct smp_operations zynq_smp_ops __initconst = {
165 .smp_init_cpus = zynq_smp_init_cpus,
166 .smp_prepare_cpus = zynq_smp_prepare_cpus,
167 .smp_boot_secondary = zynq_boot_secondary,
168 .smp_secondary_init = zynq_secondary_init,
169#ifdef CONFIG_HOTPLUG_CPU
170 .cpu_die = zynq_cpu_die,
171 .cpu_kill = zynq_cpu_kill,
172#endif
173};
174