1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/err.h>
22#include <linux/errno.h>
23#include <linux/kernel.h>
24#include <linux/init.h>
25#include <linux/interrupt.h>
26#include <linux/module.h>
27#include <linux/percpu.h>
28#include <linux/sched.h>
29#include <linux/smp.h>
30#include <linux/spinlock.h>
31#include <linux/cpu.h>
32
33#include <asm/time.h>
34#include <asm/hexagon_vm.h>
35
36#define BASE_IPI_IRQ 26
37
38
39
40
41
42
43
44struct ipi_data {
45 unsigned long bits;
46};
47
48static DEFINE_PER_CPU(struct ipi_data, ipi_data);
49
50static inline void __handle_ipi(unsigned long *ops, struct ipi_data *ipi,
51 int cpu)
52{
53 unsigned long msg = 0;
54 do {
55 msg = find_next_bit(ops, BITS_PER_LONG, msg+1);
56
57 switch (msg) {
58
59 case IPI_TIMER:
60 ipi_timer();
61 break;
62
63 case IPI_CALL_FUNC:
64 generic_smp_call_function_interrupt();
65 break;
66
67 case IPI_CPU_STOP:
68
69
70
71 __vmstop();
72 break;
73
74 case IPI_RESCHEDULE:
75 scheduler_ipi();
76 break;
77 }
78 } while (msg < BITS_PER_LONG);
79}
80
81
82void smp_vm_unmask_irq(void *info)
83{
84 __vmintop_locen((long) info);
85}
86
87
88
89
90
91
92
93
94irqreturn_t handle_ipi(int irq, void *desc)
95{
96 int cpu = smp_processor_id();
97 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
98 unsigned long ops;
99
100 while ((ops = xchg(&ipi->bits, 0)) != 0)
101 __handle_ipi(&ops, ipi, cpu);
102 return IRQ_HANDLED;
103}
104
105void send_ipi(const struct cpumask *cpumask, enum ipi_message_type msg)
106{
107 unsigned long flags;
108 unsigned long cpu;
109 unsigned long retval;
110
111 local_irq_save(flags);
112
113 for_each_cpu(cpu, cpumask) {
114 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
115
116 set_bit(msg, &ipi->bits);
117
118 retval = __vmintop_post(BASE_IPI_IRQ+cpu);
119
120 if (retval != 0) {
121 printk(KERN_ERR "interrupt %ld not configured?\n",
122 BASE_IPI_IRQ+cpu);
123 }
124 }
125
126 local_irq_restore(flags);
127}
128
129static struct irqaction ipi_intdesc = {
130 .handler = handle_ipi,
131 .flags = IRQF_TRIGGER_RISING,
132 .name = "ipi_handler"
133};
134
135void __init smp_prepare_boot_cpu(void)
136{
137}
138
139
140
141
142
143
144
145void start_secondary(void)
146{
147 unsigned int cpu;
148 unsigned long thread_ptr;
149
150
151 __asm__ __volatile__(
152 "%0 = SP;\n"
153 : "=r" (thread_ptr)
154 );
155
156 thread_ptr = thread_ptr & ~(THREAD_SIZE-1);
157
158 __asm__ __volatile__(
159 QUOTED_THREADINFO_REG " = %0;\n"
160 :
161 : "r" (thread_ptr)
162 );
163
164
165 atomic_inc(&init_mm.mm_count);
166 current->active_mm = &init_mm;
167
168 cpu = smp_processor_id();
169
170 setup_irq(BASE_IPI_IRQ + cpu, &ipi_intdesc);
171
172
173 setup_percpu_clockdev();
174
175 printk(KERN_INFO "%s cpu %d\n", __func__, current_thread_info()->cpu);
176
177 notify_cpu_starting(cpu);
178
179 set_cpu_online(cpu, true);
180
181 local_irq_enable();
182
183 cpu_startup_entry(CPUHP_ONLINE);
184}
185
186
187
188
189
190
191
192
193int __cpu_up(unsigned int cpu, struct task_struct *idle)
194{
195 struct thread_info *thread = (struct thread_info *)idle->stack;
196 void *stack_start;
197
198 thread->cpu = cpu;
199
200
201 stack_start = ((void *) thread) + THREAD_SIZE;
202 __vmstart(start_secondary, stack_start);
203
204 while (!cpu_online(cpu))
205 barrier();
206
207 return 0;
208}
209
210void __init smp_cpus_done(unsigned int max_cpus)
211{
212}
213
214void __init smp_prepare_cpus(unsigned int max_cpus)
215{
216 int i;
217
218
219
220
221
222
223
224 for (i = 0; i < max_cpus; i++)
225 set_cpu_present(i, true);
226
227
228 if (max_cpus > 1)
229 setup_irq(BASE_IPI_IRQ, &ipi_intdesc);
230}
231
232void smp_send_reschedule(int cpu)
233{
234 send_ipi(cpumask_of(cpu), IPI_RESCHEDULE);
235}
236
237void smp_send_stop(void)
238{
239 struct cpumask targets;
240 cpumask_copy(&targets, cpu_online_mask);
241 cpumask_clear_cpu(smp_processor_id(), &targets);
242 send_ipi(&targets, IPI_CPU_STOP);
243}
244
245void arch_send_call_function_single_ipi(int cpu)
246{
247 send_ipi(cpumask_of(cpu), IPI_CALL_FUNC);
248}
249
250void arch_send_call_function_ipi_mask(const struct cpumask *mask)
251{
252 send_ipi(mask, IPI_CALL_FUNC);
253}
254
255int setup_profiling_timer(unsigned int multiplier)
256{
257 return -EINVAL;
258}
259
260void smp_start_cpus(void)
261{
262 int i;
263
264 for (i = 0; i < NR_CPUS; i++)
265 set_cpu_possible(i, true);
266}
267