Commit | Line | Data |
---|---|---|
368dd5ac AT |
1 | /* SMP support routines. |
2 | * | |
3 | * Copyright (C) 2006-2008 Panasonic Corporation | |
4 | * All Rights Reserved. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * version 2 as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | */ | |
15 | ||
16 | #include <linux/interrupt.h> | |
17 | #include <linux/spinlock.h> | |
18 | #include <linux/init.h> | |
19 | #include <linux/jiffies.h> | |
20 | #include <linux/cpumask.h> | |
21 | #include <linux/err.h> | |
22 | #include <linux/kernel.h> | |
23 | #include <linux/delay.h> | |
24 | #include <linux/sched.h> | |
25 | #include <linux/profile.h> | |
26 | #include <linux/smp.h> | |
27 | #include <asm/tlbflush.h> | |
28 | #include <asm/system.h> | |
29 | #include <asm/bitops.h> | |
30 | #include <asm/processor.h> | |
31 | #include <asm/bug.h> | |
32 | #include <asm/exceptions.h> | |
33 | #include <asm/hardirq.h> | |
34 | #include <asm/fpu.h> | |
35 | #include <asm/mmu_context.h> | |
36 | #include <asm/thread_info.h> | |
37 | #include <asm/cpu-regs.h> | |
38 | #include <asm/intctl-regs.h> | |
39 | #include "internal.h" | |
40 | ||
41 | #ifdef CONFIG_HOTPLUG_CPU | |
42 | #include <linux/cpu.h> | |
43 | #include <asm/cacheflush.h> | |
44 | ||
45 | static unsigned long sleep_mode[NR_CPUS]; | |
46 | ||
47 | static void run_sleep_cpu(unsigned int cpu); | |
48 | static void run_wakeup_cpu(unsigned int cpu); | |
49 | #endif /* CONFIG_HOTPLUG_CPU */ | |
50 | ||
51 | /* | |
52 | * Debug Message function | |
53 | */ | |
54 | ||
55 | #undef DEBUG_SMP | |
56 | #ifdef DEBUG_SMP | |
57 | #define Dprintk(fmt, ...) printk(KERN_DEBUG fmt, ##__VA_ARGS__) | |
58 | #else | |
59 | #define Dprintk(fmt, ...) no_printk(KERN_DEBUG fmt, ##__VA_ARGS__) | |
60 | #endif | |
61 | ||
62 | /* timeout value in msec for smp_nmi_call_function. zero is no timeout. */ | |
63 | #define CALL_FUNCTION_NMI_IPI_TIMEOUT 0 | |
64 | ||
65 | /* | |
66 | * Structure and data for smp_nmi_call_function(). | |
67 | */ | |
68 | struct nmi_call_data_struct { | |
69 | smp_call_func_t func; | |
70 | void *info; | |
71 | cpumask_t started; | |
72 | cpumask_t finished; | |
73 | int wait; | |
74 | char size_alignment[0] | |
75 | __attribute__ ((__aligned__(SMP_CACHE_BYTES))); | |
76 | } __attribute__ ((__aligned__(SMP_CACHE_BYTES))); | |
77 | ||
78 | static DEFINE_SPINLOCK(smp_nmi_call_lock); | |
79 | static struct nmi_call_data_struct *nmi_call_data; | |
80 | ||
81 | /* | |
82 | * Data structures and variables | |
83 | */ | |
84 | static cpumask_t cpu_callin_map; /* Bitmask of callin CPUs */ | |
85 | static cpumask_t cpu_callout_map; /* Bitmask of callout CPUs */ | |
86 | cpumask_t cpu_boot_map; /* Bitmask of boot APs */ | |
87 | unsigned long start_stack[NR_CPUS - 1]; | |
88 | ||
89 | /* | |
90 | * Per CPU parameters | |
91 | */ | |
92 | struct mn10300_cpuinfo cpu_data[NR_CPUS] __cacheline_aligned; | |
93 | ||
94 | static int cpucount; /* The count of boot CPUs */ | |
95 | static cpumask_t smp_commenced_mask; | |
96 | cpumask_t cpu_initialized __initdata = CPU_MASK_NONE; | |
97 | ||
98 | /* | |
99 | * Function Prototypes | |
100 | */ | |
101 | static int do_boot_cpu(int); | |
102 | static void smp_show_cpu_info(int cpu_id); | |
103 | static void smp_callin(void); | |
104 | static void smp_online(void); | |
105 | static void smp_store_cpu_info(int); | |
106 | static void smp_cpu_init(void); | |
107 | static void smp_tune_scheduling(void); | |
108 | static void send_IPI_mask(const cpumask_t *cpumask, int irq); | |
109 | static void init_ipi(void); | |
110 | ||
111 | /* | |
112 | * IPI Initialization interrupt definitions | |
113 | */ | |
114 | static void mn10300_ipi_disable(unsigned int irq); | |
115 | static void mn10300_ipi_enable(unsigned int irq); | |
3ba65467 TG |
116 | static void mn10300_ipi_chip_disable(struct irq_data *d); |
117 | static void mn10300_ipi_chip_enable(struct irq_data *d); | |
118 | static void mn10300_ipi_ack(struct irq_data *d); | |
119 | static void mn10300_ipi_nop(struct irq_data *d); | |
368dd5ac AT |
120 | |
121 | static struct irq_chip mn10300_ipi_type = { | |
122 | .name = "cpu_ipi", | |
3ba65467 TG |
123 | .irq_disable = mn10300_ipi_chip_disable, |
124 | .irq_enable = mn10300_ipi_chip_enable, | |
125 | .irq_ack = mn10300_ipi_ack, | |
126 | .irq_eoi = mn10300_ipi_nop | |
368dd5ac AT |
127 | }; |
128 | ||
129 | static irqreturn_t smp_reschedule_interrupt(int irq, void *dev_id); | |
130 | static irqreturn_t smp_call_function_interrupt(int irq, void *dev_id); | |
368dd5ac AT |
131 | |
132 | static struct irqaction reschedule_ipi = { | |
133 | .handler = smp_reschedule_interrupt, | |
134 | .name = "smp reschedule IPI" | |
135 | }; | |
136 | static struct irqaction call_function_ipi = { | |
137 | .handler = smp_call_function_interrupt, | |
138 | .name = "smp call function IPI" | |
139 | }; | |
730c1fad MS |
140 | |
141 | #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) | |
142 | static irqreturn_t smp_ipi_timer_interrupt(int irq, void *dev_id); | |
368dd5ac AT |
143 | static struct irqaction local_timer_ipi = { |
144 | .handler = smp_ipi_timer_interrupt, | |
145 | .flags = IRQF_DISABLED, | |
146 | .name = "smp local timer IPI" | |
147 | }; | |
730c1fad | 148 | #endif |
368dd5ac AT |
149 | |
150 | /** | |
151 | * init_ipi - Initialise the IPI mechanism | |
152 | */ | |
153 | static void init_ipi(void) | |
154 | { | |
155 | unsigned long flags; | |
156 | u16 tmp16; | |
157 | ||
158 | /* set up the reschedule IPI */ | |
f4c547eb TG |
159 | irq_set_chip_and_handler(RESCHEDULE_IPI, &mn10300_ipi_type, |
160 | handle_percpu_irq); | |
368dd5ac AT |
161 | setup_irq(RESCHEDULE_IPI, &reschedule_ipi); |
162 | set_intr_level(RESCHEDULE_IPI, RESCHEDULE_GxICR_LV); | |
163 | mn10300_ipi_enable(RESCHEDULE_IPI); | |
164 | ||
165 | /* set up the call function IPI */ | |
f4c547eb TG |
166 | irq_set_chip_and_handler(CALL_FUNC_SINGLE_IPI, &mn10300_ipi_type, |
167 | handle_percpu_irq); | |
368dd5ac AT |
168 | setup_irq(CALL_FUNC_SINGLE_IPI, &call_function_ipi); |
169 | set_intr_level(CALL_FUNC_SINGLE_IPI, CALL_FUNCTION_GxICR_LV); | |
170 | mn10300_ipi_enable(CALL_FUNC_SINGLE_IPI); | |
171 | ||
172 | /* set up the local timer IPI */ | |
730c1fad MS |
173 | #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || \ |
174 | defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) | |
f4c547eb TG |
175 | irq_set_chip_and_handler(LOCAL_TIMER_IPI, &mn10300_ipi_type, |
176 | handle_percpu_irq); | |
368dd5ac AT |
177 | setup_irq(LOCAL_TIMER_IPI, &local_timer_ipi); |
178 | set_intr_level(LOCAL_TIMER_IPI, LOCAL_TIMER_GxICR_LV); | |
179 | mn10300_ipi_enable(LOCAL_TIMER_IPI); | |
730c1fad | 180 | #endif |
368dd5ac AT |
181 | |
182 | #ifdef CONFIG_MN10300_CACHE_ENABLED | |
183 | /* set up the cache flush IPI */ | |
184 | flags = arch_local_cli_save(); | |
185 | __set_intr_stub(NUM2EXCEP_IRQ_LEVEL(FLUSH_CACHE_GxICR_LV), | |
186 | mn10300_low_ipi_handler); | |
187 | GxICR(FLUSH_CACHE_IPI) = FLUSH_CACHE_GxICR_LV | GxICR_DETECT; | |
188 | mn10300_ipi_enable(FLUSH_CACHE_IPI); | |
189 | arch_local_irq_restore(flags); | |
190 | #endif | |
191 | ||
192 | /* set up the NMI call function IPI */ | |
193 | flags = arch_local_cli_save(); | |
194 | GxICR(CALL_FUNCTION_NMI_IPI) = GxICR_NMI | GxICR_ENABLE | GxICR_DETECT; | |
195 | tmp16 = GxICR(CALL_FUNCTION_NMI_IPI); | |
196 | arch_local_irq_restore(flags); | |
197 | ||
198 | /* set up the SMP boot IPI */ | |
199 | flags = arch_local_cli_save(); | |
200 | __set_intr_stub(NUM2EXCEP_IRQ_LEVEL(SMP_BOOT_GxICR_LV), | |
201 | mn10300_low_ipi_handler); | |
202 | arch_local_irq_restore(flags); | |
203 | } | |
204 | ||
205 | /** | |
206 | * mn10300_ipi_shutdown - Shut down handling of an IPI | |
207 | * @irq: The IPI to be shut down. | |
208 | */ | |
209 | static void mn10300_ipi_shutdown(unsigned int irq) | |
210 | { | |
211 | unsigned long flags; | |
212 | u16 tmp; | |
213 | ||
214 | flags = arch_local_cli_save(); | |
215 | ||
216 | tmp = GxICR(irq); | |
217 | GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_DETECT; | |
218 | tmp = GxICR(irq); | |
219 | ||
220 | arch_local_irq_restore(flags); | |
221 | } | |
222 | ||
223 | /** | |
224 | * mn10300_ipi_enable - Enable an IPI | |
225 | * @irq: The IPI to be enabled. | |
226 | */ | |
227 | static void mn10300_ipi_enable(unsigned int irq) | |
228 | { | |
229 | unsigned long flags; | |
230 | u16 tmp; | |
231 | ||
232 | flags = arch_local_cli_save(); | |
233 | ||
234 | tmp = GxICR(irq); | |
235 | GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE; | |
236 | tmp = GxICR(irq); | |
237 | ||
238 | arch_local_irq_restore(flags); | |
239 | } | |
240 | ||
3ba65467 TG |
241 | static void mn10300_ipi_chip_enable(struct irq_data *d) |
242 | { | |
243 | mn10300_ipi_enable(d->irq); | |
244 | } | |
245 | ||
368dd5ac AT |
246 | /** |
247 | * mn10300_ipi_disable - Disable an IPI | |
248 | * @irq: The IPI to be disabled. | |
249 | */ | |
250 | static void mn10300_ipi_disable(unsigned int irq) | |
251 | { | |
252 | unsigned long flags; | |
253 | u16 tmp; | |
254 | ||
255 | flags = arch_local_cli_save(); | |
256 | ||
257 | tmp = GxICR(irq); | |
258 | GxICR(irq) = tmp & GxICR_LEVEL; | |
259 | tmp = GxICR(irq); | |
260 | ||
261 | arch_local_irq_restore(flags); | |
262 | } | |
263 | ||
3ba65467 TG |
264 | static void mn10300_ipi_chip_disable(struct irq_data *d) |
265 | { | |
266 | mn10300_ipi_disable(d->irq); | |
267 | } | |
268 | ||
269 | ||
368dd5ac AT |
270 | /** |
271 | * mn10300_ipi_ack - Acknowledge an IPI interrupt in the PIC | |
272 | * @irq: The IPI to be acknowledged. | |
273 | * | |
274 | * Clear the interrupt detection flag for the IPI on the appropriate interrupt | |
275 | * channel in the PIC. | |
276 | */ | |
3ba65467 | 277 | static void mn10300_ipi_ack(struct irq_data *d) |
368dd5ac | 278 | { |
3ba65467 | 279 | unsigned int irq = d->irq; |
368dd5ac AT |
280 | unsigned long flags; |
281 | u16 tmp; | |
282 | ||
283 | flags = arch_local_cli_save(); | |
284 | GxICR_u8(irq) = GxICR_DETECT; | |
285 | tmp = GxICR(irq); | |
286 | arch_local_irq_restore(flags); | |
287 | } | |
288 | ||
289 | /** | |
290 | * mn10300_ipi_nop - Dummy IPI action | |
291 | * @irq: The IPI to be acted upon. | |
292 | */ | |
3ba65467 | 293 | static void mn10300_ipi_nop(struct irq_data *d) |
368dd5ac AT |
294 | { |
295 | } | |
296 | ||
297 | /** | |
298 | * send_IPI_mask - Send IPIs to all CPUs in list | |
299 | * @cpumask: The list of CPUs to target. | |
300 | * @irq: The IPI request to be sent. | |
301 | * | |
302 | * Send the specified IPI to all the CPUs in the list, not waiting for them to | |
303 | * finish before returning. The caller is responsible for synchronisation if | |
304 | * that is needed. | |
305 | */ | |
306 | static void send_IPI_mask(const cpumask_t *cpumask, int irq) | |
307 | { | |
308 | int i; | |
309 | u16 tmp; | |
310 | ||
311 | for (i = 0; i < NR_CPUS; i++) { | |
312 | if (cpu_isset(i, *cpumask)) { | |
313 | /* send IPI */ | |
314 | tmp = CROSS_GxICR(irq, i); | |
315 | CROSS_GxICR(irq, i) = | |
316 | tmp | GxICR_REQUEST | GxICR_DETECT; | |
317 | tmp = CROSS_GxICR(irq, i); /* flush write buffer */ | |
318 | } | |
319 | } | |
320 | } | |
321 | ||
322 | /** | |
323 | * send_IPI_self - Send an IPI to this CPU. | |
324 | * @irq: The IPI request to be sent. | |
325 | * | |
326 | * Send the specified IPI to the current CPU. | |
327 | */ | |
328 | void send_IPI_self(int irq) | |
329 | { | |
330 | send_IPI_mask(cpumask_of(smp_processor_id()), irq); | |
331 | } | |
332 | ||
333 | /** | |
334 | * send_IPI_allbutself - Send IPIs to all the other CPUs. | |
335 | * @irq: The IPI request to be sent. | |
336 | * | |
337 | * Send the specified IPI to all CPUs in the system barring the current one, | |
338 | * not waiting for them to finish before returning. The caller is responsible | |
339 | * for synchronisation if that is needed. | |
340 | */ | |
341 | void send_IPI_allbutself(int irq) | |
342 | { | |
343 | cpumask_t cpumask; | |
344 | ||
345 | cpumask = cpu_online_map; | |
346 | cpu_clear(smp_processor_id(), cpumask); | |
347 | send_IPI_mask(&cpumask, irq); | |
348 | } | |
349 | ||
350 | void arch_send_call_function_ipi_mask(const struct cpumask *mask) | |
351 | { | |
352 | BUG(); | |
353 | /*send_IPI_mask(mask, CALL_FUNCTION_IPI);*/ | |
354 | } | |
355 | ||
356 | void arch_send_call_function_single_ipi(int cpu) | |
357 | { | |
358 | send_IPI_mask(cpumask_of(cpu), CALL_FUNC_SINGLE_IPI); | |
359 | } | |
360 | ||
361 | /** | |
362 | * smp_send_reschedule - Send reschedule IPI to a CPU | |
363 | * @cpu: The CPU to target. | |
364 | */ | |
365 | void smp_send_reschedule(int cpu) | |
366 | { | |
367 | send_IPI_mask(cpumask_of(cpu), RESCHEDULE_IPI); | |
368 | } | |
369 | ||
370 | /** | |
371 | * smp_nmi_call_function - Send a call function NMI IPI to all CPUs | |
372 | * @func: The function to ask to be run. | |
373 | * @info: The context data to pass to that function. | |
374 | * @wait: If true, wait (atomically) until function is run on all CPUs. | |
375 | * | |
376 | * Send a non-maskable request to all CPUs in the system, requesting them to | |
377 | * run the specified function with the given context data, and, potentially, to | |
378 | * wait for completion of that function on all CPUs. | |
379 | * | |
380 | * Returns 0 if successful, -ETIMEDOUT if we were asked to wait, but hit the | |
381 | * timeout. | |
382 | */ | |
383 | int smp_nmi_call_function(smp_call_func_t func, void *info, int wait) | |
384 | { | |
385 | struct nmi_call_data_struct data; | |
386 | unsigned long flags; | |
387 | unsigned int cnt; | |
388 | int cpus, ret = 0; | |
389 | ||
390 | cpus = num_online_cpus() - 1; | |
391 | if (cpus < 1) | |
392 | return 0; | |
393 | ||
394 | data.func = func; | |
395 | data.info = info; | |
396 | data.started = cpu_online_map; | |
397 | cpu_clear(smp_processor_id(), data.started); | |
398 | data.wait = wait; | |
399 | if (wait) | |
400 | data.finished = data.started; | |
401 | ||
402 | spin_lock_irqsave(&smp_nmi_call_lock, flags); | |
403 | nmi_call_data = &data; | |
404 | smp_mb(); | |
405 | ||
406 | /* Send a message to all other CPUs and wait for them to respond */ | |
407 | send_IPI_allbutself(CALL_FUNCTION_NMI_IPI); | |
408 | ||
409 | /* Wait for response */ | |
410 | if (CALL_FUNCTION_NMI_IPI_TIMEOUT > 0) { | |
411 | for (cnt = 0; | |
412 | cnt < CALL_FUNCTION_NMI_IPI_TIMEOUT && | |
413 | !cpus_empty(data.started); | |
414 | cnt++) | |
415 | mdelay(1); | |
416 | ||
417 | if (wait && cnt < CALL_FUNCTION_NMI_IPI_TIMEOUT) { | |
418 | for (cnt = 0; | |
419 | cnt < CALL_FUNCTION_NMI_IPI_TIMEOUT && | |
420 | !cpus_empty(data.finished); | |
421 | cnt++) | |
422 | mdelay(1); | |
423 | } | |
424 | ||
425 | if (cnt >= CALL_FUNCTION_NMI_IPI_TIMEOUT) | |
426 | ret = -ETIMEDOUT; | |
427 | ||
428 | } else { | |
429 | /* If timeout value is zero, wait until cpumask has been | |
430 | * cleared */ | |
431 | while (!cpus_empty(data.started)) | |
432 | barrier(); | |
433 | if (wait) | |
434 | while (!cpus_empty(data.finished)) | |
435 | barrier(); | |
436 | } | |
437 | ||
438 | spin_unlock_irqrestore(&smp_nmi_call_lock, flags); | |
439 | return ret; | |
440 | } | |
441 | ||
67ddb405 DH |
442 | /** |
443 | * smp_jump_to_debugger - Make other CPUs enter the debugger by sending an IPI | |
444 | * | |
445 | * Send a non-maskable request to all other CPUs in the system, instructing | |
446 | * them to jump into the debugger. The caller is responsible for checking that | |
447 | * the other CPUs responded to the instruction. | |
448 | * | |
449 | * The caller should make sure that this CPU's debugger IPI is disabled. | |
450 | */ | |
451 | void smp_jump_to_debugger(void) | |
452 | { | |
453 | if (num_online_cpus() > 1) | |
454 | /* Send a message to all other CPUs */ | |
455 | send_IPI_allbutself(DEBUGGER_NMI_IPI); | |
456 | } | |
457 | ||
368dd5ac AT |
458 | /** |
459 | * stop_this_cpu - Callback to stop a CPU. | |
460 | * @unused: Callback context (ignored). | |
461 | */ | |
462 | void stop_this_cpu(void *unused) | |
463 | { | |
464 | static volatile int stopflag; | |
465 | unsigned long flags; | |
466 | ||
467 | #ifdef CONFIG_GDBSTUB | |
468 | /* In case of single stepping smp_send_stop by other CPU, | |
469 | * clear procindebug to avoid deadlock. | |
470 | */ | |
471 | atomic_set(&procindebug[smp_processor_id()], 0); | |
472 | #endif /* CONFIG_GDBSTUB */ | |
473 | ||
474 | flags = arch_local_cli_save(); | |
475 | cpu_clear(smp_processor_id(), cpu_online_map); | |
476 | ||
477 | while (!stopflag) | |
478 | cpu_relax(); | |
479 | ||
480 | cpu_set(smp_processor_id(), cpu_online_map); | |
481 | arch_local_irq_restore(flags); | |
482 | } | |
483 | ||
484 | /** | |
485 | * smp_send_stop - Send a stop request to all CPUs. | |
486 | */ | |
487 | void smp_send_stop(void) | |
488 | { | |
489 | smp_nmi_call_function(stop_this_cpu, NULL, 0); | |
490 | } | |
491 | ||
492 | /** | |
493 | * smp_reschedule_interrupt - Reschedule IPI handler | |
494 | * @irq: The interrupt number. | |
495 | * @dev_id: The device ID. | |
496 | * | |
368dd5ac AT |
497 | * Returns IRQ_HANDLED to indicate we handled the interrupt successfully. |
498 | */ | |
499 | static irqreturn_t smp_reschedule_interrupt(int irq, void *dev_id) | |
500 | { | |
184748cc | 501 | scheduler_ipi(); |
368dd5ac AT |
502 | return IRQ_HANDLED; |
503 | } | |
504 | ||
505 | /** | |
506 | * smp_call_function_interrupt - Call function IPI handler | |
507 | * @irq: The interrupt number. | |
508 | * @dev_id: The device ID. | |
509 | * | |
510 | * Returns IRQ_HANDLED to indicate we handled the interrupt successfully. | |
511 | */ | |
512 | static irqreturn_t smp_call_function_interrupt(int irq, void *dev_id) | |
513 | { | |
514 | /* generic_smp_call_function_interrupt(); */ | |
515 | generic_smp_call_function_single_interrupt(); | |
516 | return IRQ_HANDLED; | |
517 | } | |
518 | ||
519 | /** | |
520 | * smp_nmi_call_function_interrupt - Non-maskable call function IPI handler | |
521 | */ | |
522 | void smp_nmi_call_function_interrupt(void) | |
523 | { | |
524 | smp_call_func_t func = nmi_call_data->func; | |
525 | void *info = nmi_call_data->info; | |
526 | int wait = nmi_call_data->wait; | |
527 | ||
528 | /* Notify the initiating CPU that I've grabbed the data and am about to | |
529 | * execute the function | |
530 | */ | |
531 | smp_mb(); | |
532 | cpu_clear(smp_processor_id(), nmi_call_data->started); | |
533 | (*func)(info); | |
534 | ||
535 | if (wait) { | |
536 | smp_mb(); | |
537 | cpu_clear(smp_processor_id(), nmi_call_data->finished); | |
538 | } | |
539 | } | |
540 | ||
730c1fad MS |
541 | #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || \ |
542 | defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) | |
368dd5ac AT |
543 | /** |
544 | * smp_ipi_timer_interrupt - Local timer IPI handler | |
545 | * @irq: The interrupt number. | |
546 | * @dev_id: The device ID. | |
547 | * | |
548 | * Returns IRQ_HANDLED to indicate we handled the interrupt successfully. | |
549 | */ | |
550 | static irqreturn_t smp_ipi_timer_interrupt(int irq, void *dev_id) | |
551 | { | |
552 | return local_timer_interrupt(); | |
553 | } | |
730c1fad | 554 | #endif |
368dd5ac AT |
555 | |
556 | void __init smp_init_cpus(void) | |
557 | { | |
558 | int i; | |
559 | for (i = 0; i < NR_CPUS; i++) { | |
560 | set_cpu_possible(i, true); | |
561 | set_cpu_present(i, true); | |
562 | } | |
563 | } | |
564 | ||
565 | /** | |
566 | * smp_cpu_init - Initialise AP in start_secondary. | |
567 | * | |
568 | * For this Application Processor, set up init_mm, initialise FPU and set | |
569 | * interrupt level 0-6 setting. | |
570 | */ | |
571 | static void __init smp_cpu_init(void) | |
572 | { | |
573 | unsigned long flags; | |
574 | int cpu_id = smp_processor_id(); | |
575 | u16 tmp16; | |
576 | ||
577 | if (test_and_set_bit(cpu_id, &cpu_initialized)) { | |
578 | printk(KERN_WARNING "CPU#%d already initialized!\n", cpu_id); | |
579 | for (;;) | |
580 | local_irq_enable(); | |
581 | } | |
582 | printk(KERN_INFO "Initializing CPU#%d\n", cpu_id); | |
583 | ||
584 | atomic_inc(&init_mm.mm_count); | |
585 | current->active_mm = &init_mm; | |
586 | BUG_ON(current->mm); | |
587 | ||
588 | enter_lazy_tlb(&init_mm, current); | |
589 | ||
590 | /* Force FPU initialization */ | |
591 | clear_using_fpu(current); | |
592 | ||
593 | GxICR(CALL_FUNC_SINGLE_IPI) = CALL_FUNCTION_GxICR_LV | GxICR_DETECT; | |
594 | mn10300_ipi_enable(CALL_FUNC_SINGLE_IPI); | |
595 | ||
596 | GxICR(LOCAL_TIMER_IPI) = LOCAL_TIMER_GxICR_LV | GxICR_DETECT; | |
597 | mn10300_ipi_enable(LOCAL_TIMER_IPI); | |
598 | ||
599 | GxICR(RESCHEDULE_IPI) = RESCHEDULE_GxICR_LV | GxICR_DETECT; | |
600 | mn10300_ipi_enable(RESCHEDULE_IPI); | |
601 | ||
602 | #ifdef CONFIG_MN10300_CACHE_ENABLED | |
603 | GxICR(FLUSH_CACHE_IPI) = FLUSH_CACHE_GxICR_LV | GxICR_DETECT; | |
604 | mn10300_ipi_enable(FLUSH_CACHE_IPI); | |
605 | #endif | |
606 | ||
607 | mn10300_ipi_shutdown(SMP_BOOT_IRQ); | |
608 | ||
609 | /* Set up the non-maskable call function IPI */ | |
610 | flags = arch_local_cli_save(); | |
611 | GxICR(CALL_FUNCTION_NMI_IPI) = GxICR_NMI | GxICR_ENABLE | GxICR_DETECT; | |
612 | tmp16 = GxICR(CALL_FUNCTION_NMI_IPI); | |
613 | arch_local_irq_restore(flags); | |
614 | } | |
615 | ||
616 | /** | |
617 | * smp_prepare_cpu_init - Initialise CPU in startup_secondary | |
618 | * | |
67ddb405 | 619 | * Set interrupt level 0-6 setting and init ICR of the kernel debugger. |
368dd5ac AT |
620 | */ |
621 | void smp_prepare_cpu_init(void) | |
622 | { | |
623 | int loop; | |
624 | ||
625 | /* Set the interrupt vector registers */ | |
626 | IVAR0 = EXCEP_IRQ_LEVEL0; | |
627 | IVAR1 = EXCEP_IRQ_LEVEL1; | |
628 | IVAR2 = EXCEP_IRQ_LEVEL2; | |
629 | IVAR3 = EXCEP_IRQ_LEVEL3; | |
630 | IVAR4 = EXCEP_IRQ_LEVEL4; | |
631 | IVAR5 = EXCEP_IRQ_LEVEL5; | |
632 | IVAR6 = EXCEP_IRQ_LEVEL6; | |
633 | ||
634 | /* Disable all interrupts and set to priority 6 (lowest) */ | |
635 | for (loop = 0; loop < GxICR_NUM_IRQS; loop++) | |
636 | GxICR(loop) = GxICR_LEVEL_6 | GxICR_DETECT; | |
637 | ||
67ddb405 DH |
638 | #ifdef CONFIG_KERNEL_DEBUGGER |
639 | /* initialise the kernel debugger interrupt */ | |
368dd5ac AT |
640 | do { |
641 | unsigned long flags; | |
642 | u16 tmp16; | |
643 | ||
644 | flags = arch_local_cli_save(); | |
67ddb405 DH |
645 | GxICR(DEBUGGER_NMI_IPI) = GxICR_NMI | GxICR_ENABLE | GxICR_DETECT; |
646 | tmp16 = GxICR(DEBUGGER_NMI_IPI); | |
368dd5ac AT |
647 | arch_local_irq_restore(flags); |
648 | } while (0); | |
649 | #endif | |
650 | } | |
651 | ||
652 | /** | |
653 | * start_secondary - Activate a secondary CPU (AP) | |
654 | * @unused: Thread parameter (ignored). | |
655 | */ | |
656 | int __init start_secondary(void *unused) | |
657 | { | |
658 | smp_cpu_init(); | |
368dd5ac AT |
659 | smp_callin(); |
660 | while (!cpu_isset(smp_processor_id(), smp_commenced_mask)) | |
661 | cpu_relax(); | |
662 | ||
663 | local_flush_tlb(); | |
664 | preempt_disable(); | |
665 | smp_online(); | |
666 | ||
730c1fad MS |
667 | #ifdef CONFIG_GENERIC_CLOCKEVENTS |
668 | init_clockevents(); | |
669 | #endif | |
368dd5ac AT |
670 | cpu_idle(); |
671 | return 0; | |
672 | } | |
673 | ||
674 | /** | |
675 | * smp_prepare_cpus - Boot up secondary CPUs (APs) | |
676 | * @max_cpus: Maximum number of CPUs to boot. | |
677 | * | |
678 | * Call do_boot_cpu, and boot up APs. | |
679 | */ | |
680 | void __init smp_prepare_cpus(unsigned int max_cpus) | |
681 | { | |
682 | int phy_id; | |
683 | ||
684 | /* Setup boot CPU information */ | |
685 | smp_store_cpu_info(0); | |
686 | smp_tune_scheduling(); | |
687 | ||
688 | init_ipi(); | |
689 | ||
690 | /* If SMP should be disabled, then finish */ | |
691 | if (max_cpus == 0) { | |
692 | printk(KERN_INFO "SMP mode deactivated.\n"); | |
693 | goto smp_done; | |
694 | } | |
695 | ||
696 | /* Boot secondary CPUs (for which phy_id > 0) */ | |
697 | for (phy_id = 0; phy_id < NR_CPUS; phy_id++) { | |
698 | /* Don't boot primary CPU */ | |
699 | if (max_cpus <= cpucount + 1) | |
700 | continue; | |
701 | if (phy_id != 0) | |
702 | do_boot_cpu(phy_id); | |
703 | set_cpu_possible(phy_id, true); | |
704 | smp_show_cpu_info(phy_id); | |
705 | } | |
706 | ||
707 | smp_done: | |
708 | Dprintk("Boot done.\n"); | |
709 | } | |
710 | ||
711 | /** | |
712 | * smp_store_cpu_info - Save a CPU's information | |
713 | * @cpu: The CPU to save for. | |
714 | * | |
715 | * Save boot_cpu_data and jiffy for the specified CPU. | |
716 | */ | |
717 | static void __init smp_store_cpu_info(int cpu) | |
718 | { | |
719 | struct mn10300_cpuinfo *ci = &cpu_data[cpu]; | |
720 | ||
721 | *ci = boot_cpu_data; | |
722 | ci->loops_per_jiffy = loops_per_jiffy; | |
723 | ci->type = CPUREV; | |
724 | } | |
725 | ||
726 | /** | |
727 | * smp_tune_scheduling - Set time slice value | |
728 | * | |
729 | * Nothing to do here. | |
730 | */ | |
731 | static void __init smp_tune_scheduling(void) | |
732 | { | |
733 | } | |
734 | ||
735 | /** | |
736 | * do_boot_cpu: Boot up one CPU | |
737 | * @phy_id: Physical ID of CPU to boot. | |
738 | * | |
739 | * Send an IPI to a secondary CPU to boot it. Returns 0 on success, 1 | |
740 | * otherwise. | |
741 | */ | |
742 | static int __init do_boot_cpu(int phy_id) | |
743 | { | |
744 | struct task_struct *idle; | |
745 | unsigned long send_status, callin_status; | |
746 | int timeout, cpu_id; | |
747 | ||
748 | send_status = GxICR_REQUEST; | |
749 | callin_status = 0; | |
750 | timeout = 0; | |
751 | cpu_id = phy_id; | |
752 | ||
753 | cpucount++; | |
754 | ||
755 | /* Create idle thread for this CPU */ | |
756 | idle = fork_idle(cpu_id); | |
757 | if (IS_ERR(idle)) | |
758 | panic("Failed fork for CPU#%d.", cpu_id); | |
759 | ||
760 | idle->thread.pc = (unsigned long)start_secondary; | |
761 | ||
762 | printk(KERN_NOTICE "Booting CPU#%d\n", cpu_id); | |
763 | start_stack[cpu_id - 1] = idle->thread.sp; | |
764 | ||
765 | task_thread_info(idle)->cpu = cpu_id; | |
766 | ||
767 | /* Send boot IPI to AP */ | |
768 | send_IPI_mask(cpumask_of(phy_id), SMP_BOOT_IRQ); | |
769 | ||
770 | Dprintk("Waiting for send to finish...\n"); | |
771 | ||
772 | /* Wait for AP's IPI receive in 100[ms] */ | |
773 | do { | |
774 | udelay(1000); | |
775 | send_status = | |
776 | CROSS_GxICR(SMP_BOOT_IRQ, phy_id) & GxICR_REQUEST; | |
777 | } while (send_status == GxICR_REQUEST && timeout++ < 100); | |
778 | ||
779 | Dprintk("Waiting for cpu_callin_map.\n"); | |
780 | ||
781 | if (send_status == 0) { | |
782 | /* Allow AP to start initializing */ | |
783 | cpu_set(cpu_id, cpu_callout_map); | |
784 | ||
785 | /* Wait for setting cpu_callin_map */ | |
786 | timeout = 0; | |
787 | do { | |
788 | udelay(1000); | |
789 | callin_status = cpu_isset(cpu_id, cpu_callin_map); | |
790 | } while (callin_status == 0 && timeout++ < 5000); | |
791 | ||
792 | if (callin_status == 0) | |
793 | Dprintk("Not responding.\n"); | |
794 | } else { | |
795 | printk(KERN_WARNING "IPI not delivered.\n"); | |
796 | } | |
797 | ||
798 | if (send_status == GxICR_REQUEST || callin_status == 0) { | |
799 | cpu_clear(cpu_id, cpu_callout_map); | |
800 | cpu_clear(cpu_id, cpu_callin_map); | |
801 | cpu_clear(cpu_id, cpu_initialized); | |
802 | cpucount--; | |
803 | return 1; | |
804 | } | |
805 | return 0; | |
806 | } | |
807 | ||
808 | /** | |
809 | * smp_show_cpu_info - Show SMP CPU information | |
810 | * @cpu: The CPU of interest. | |
811 | */ | |
812 | static void __init smp_show_cpu_info(int cpu) | |
813 | { | |
814 | struct mn10300_cpuinfo *ci = &cpu_data[cpu]; | |
815 | ||
816 | printk(KERN_INFO | |
817 | "CPU#%d : ioclk speed: %lu.%02luMHz : bogomips : %lu.%02lu\n", | |
818 | cpu, | |
819 | MN10300_IOCLK / 1000000, | |
820 | (MN10300_IOCLK / 10000) % 100, | |
821 | ci->loops_per_jiffy / (500000 / HZ), | |
822 | (ci->loops_per_jiffy / (5000 / HZ)) % 100); | |
823 | } | |
824 | ||
825 | /** | |
826 | * smp_callin - Set cpu_callin_map of the current CPU ID | |
827 | */ | |
828 | static void __init smp_callin(void) | |
829 | { | |
830 | unsigned long timeout; | |
831 | int cpu; | |
832 | ||
833 | cpu = smp_processor_id(); | |
834 | timeout = jiffies + (2 * HZ); | |
835 | ||
836 | if (cpu_isset(cpu, cpu_callin_map)) { | |
837 | printk(KERN_ERR "CPU#%d already present.\n", cpu); | |
838 | BUG(); | |
839 | } | |
840 | Dprintk("CPU#%d waiting for CALLOUT\n", cpu); | |
841 | ||
842 | /* Wait for AP startup 2s total */ | |
843 | while (time_before(jiffies, timeout)) { | |
844 | if (cpu_isset(cpu, cpu_callout_map)) | |
845 | break; | |
846 | cpu_relax(); | |
847 | } | |
848 | ||
849 | if (!time_before(jiffies, timeout)) { | |
850 | printk(KERN_ERR | |
851 | "BUG: CPU#%d started up but did not get a callout!\n", | |
852 | cpu); | |
853 | BUG(); | |
854 | } | |
855 | ||
856 | #ifdef CONFIG_CALIBRATE_DELAY | |
857 | calibrate_delay(); /* Get our bogomips */ | |
858 | #endif | |
859 | ||
860 | /* Save our processor parameters */ | |
861 | smp_store_cpu_info(cpu); | |
862 | ||
863 | /* Allow the boot processor to continue */ | |
864 | cpu_set(cpu, cpu_callin_map); | |
865 | } | |
866 | ||
867 | /** | |
868 | * smp_online - Set cpu_online_map | |
869 | */ | |
870 | static void __init smp_online(void) | |
871 | { | |
872 | int cpu; | |
873 | ||
874 | cpu = smp_processor_id(); | |
875 | ||
876 | local_irq_enable(); | |
877 | ||
878 | cpu_set(cpu, cpu_online_map); | |
879 | smp_wmb(); | |
880 | } | |
881 | ||
882 | /** | |
883 | * smp_cpus_done - | |
884 | * @max_cpus: Maximum CPU count. | |
885 | * | |
886 | * Do nothing. | |
887 | */ | |
888 | void __init smp_cpus_done(unsigned int max_cpus) | |
889 | { | |
890 | } | |
891 | ||
892 | /* | |
893 | * smp_prepare_boot_cpu - Set up stuff for the boot processor. | |
894 | * | |
895 | * Set up the cpu_online_map, cpu_callout_map and cpu_callin_map of the boot | |
896 | * processor (CPU 0). | |
897 | */ | |
898 | void __devinit smp_prepare_boot_cpu(void) | |
899 | { | |
900 | cpu_set(0, cpu_callout_map); | |
901 | cpu_set(0, cpu_callin_map); | |
902 | current_thread_info()->cpu = 0; | |
903 | } | |
904 | ||
905 | /* | |
906 | * initialize_secondary - Initialise a secondary CPU (Application Processor). | |
907 | * | |
908 | * Set SP register and jump to thread's PC address. | |
909 | */ | |
910 | void initialize_secondary(void) | |
911 | { | |
912 | asm volatile ( | |
913 | "mov %0,sp \n" | |
914 | "jmp (%1) \n" | |
915 | : | |
916 | : "a"(current->thread.sp), "a"(current->thread.pc)); | |
917 | } | |
918 | ||
919 | /** | |
920 | * __cpu_up - Set smp_commenced_mask for the nominated CPU | |
921 | * @cpu: The target CPU. | |
922 | */ | |
923 | int __devinit __cpu_up(unsigned int cpu) | |
924 | { | |
925 | int timeout; | |
926 | ||
927 | #ifdef CONFIG_HOTPLUG_CPU | |
928 | if (num_online_cpus() == 1) | |
929 | disable_hlt(); | |
930 | if (sleep_mode[cpu]) | |
931 | run_wakeup_cpu(cpu); | |
932 | #endif /* CONFIG_HOTPLUG_CPU */ | |
933 | ||
934 | cpu_set(cpu, smp_commenced_mask); | |
935 | ||
936 | /* Wait 5s total for a response */ | |
937 | for (timeout = 0 ; timeout < 5000 ; timeout++) { | |
938 | if (cpu_isset(cpu, cpu_online_map)) | |
939 | break; | |
940 | udelay(1000); | |
941 | } | |
942 | ||
943 | BUG_ON(!cpu_isset(cpu, cpu_online_map)); | |
944 | return 0; | |
945 | } | |
946 | ||
947 | /** | |
948 | * setup_profiling_timer - Set up the profiling timer | |
949 | * @multiplier - The frequency multiplier to use | |
950 | * | |
951 | * The frequency of the profiling timer can be changed by writing a multiplier | |
952 | * value into /proc/profile. | |
953 | */ | |
954 | int setup_profiling_timer(unsigned int multiplier) | |
955 | { | |
956 | return -EINVAL; | |
957 | } | |
958 | ||
959 | /* | |
960 | * CPU hotplug routines | |
961 | */ | |
962 | #ifdef CONFIG_HOTPLUG_CPU | |
963 | ||
964 | static DEFINE_PER_CPU(struct cpu, cpu_devices); | |
965 | ||
966 | static int __init topology_init(void) | |
967 | { | |
968 | int cpu, ret; | |
969 | ||
970 | for_each_cpu(cpu) { | |
971 | ret = register_cpu(&per_cpu(cpu_devices, cpu), cpu, NULL); | |
972 | if (ret) | |
973 | printk(KERN_WARNING | |
974 | "topology_init: register_cpu %d failed (%d)\n", | |
975 | cpu, ret); | |
976 | } | |
977 | return 0; | |
978 | } | |
979 | ||
980 | subsys_initcall(topology_init); | |
981 | ||
982 | int __cpu_disable(void) | |
983 | { | |
984 | int cpu = smp_processor_id(); | |
985 | if (cpu == 0) | |
986 | return -EBUSY; | |
987 | ||
988 | migrate_irqs(); | |
989 | cpu_clear(cpu, current->active_mm->cpu_vm_mask); | |
990 | return 0; | |
991 | } | |
992 | ||
993 | void __cpu_die(unsigned int cpu) | |
994 | { | |
995 | run_sleep_cpu(cpu); | |
996 | ||
997 | if (num_online_cpus() == 1) | |
998 | enable_hlt(); | |
999 | } | |
1000 | ||
1001 | #ifdef CONFIG_MN10300_CACHE_ENABLED | |
1002 | static inline void hotplug_cpu_disable_cache(void) | |
1003 | { | |
1004 | int tmp; | |
1005 | asm volatile( | |
1006 | " movhu (%1),%0 \n" | |
1007 | " and %2,%0 \n" | |
1008 | " movhu %0,(%1) \n" | |
1009 | "1: movhu (%1),%0 \n" | |
1010 | " btst %3,%0 \n" | |
1011 | " bne 1b \n" | |
1012 | : "=&r"(tmp) | |
1013 | : "a"(&CHCTR), | |
1014 | "i"(~(CHCTR_ICEN | CHCTR_DCEN)), | |
1015 | "i"(CHCTR_ICBUSY | CHCTR_DCBUSY) | |
1016 | : "memory", "cc"); | |
1017 | } | |
1018 | ||
1019 | static inline void hotplug_cpu_enable_cache(void) | |
1020 | { | |
1021 | int tmp; | |
1022 | asm volatile( | |
1023 | "movhu (%1),%0 \n" | |
1024 | "or %2,%0 \n" | |
1025 | "movhu %0,(%1) \n" | |
1026 | : "=&r"(tmp) | |
1027 | : "a"(&CHCTR), | |
1028 | "i"(CHCTR_ICEN | CHCTR_DCEN) | |
1029 | : "memory", "cc"); | |
1030 | } | |
1031 | ||
1032 | static inline void hotplug_cpu_invalidate_cache(void) | |
1033 | { | |
1034 | int tmp; | |
1035 | asm volatile ( | |
1036 | "movhu (%1),%0 \n" | |
1037 | "or %2,%0 \n" | |
1038 | "movhu %0,(%1) \n" | |
1039 | : "=&r"(tmp) | |
1040 | : "a"(&CHCTR), | |
1041 | "i"(CHCTR_ICINV | CHCTR_DCINV) | |
1042 | : "cc"); | |
1043 | } | |
1044 | ||
1045 | #else /* CONFIG_MN10300_CACHE_ENABLED */ | |
1046 | #define hotplug_cpu_disable_cache() do {} while (0) | |
1047 | #define hotplug_cpu_enable_cache() do {} while (0) | |
1048 | #define hotplug_cpu_invalidate_cache() do {} while (0) | |
1049 | #endif /* CONFIG_MN10300_CACHE_ENABLED */ | |
1050 | ||
1051 | /** | |
1052 | * hotplug_cpu_nmi_call_function - Call a function on other CPUs for hotplug | |
1053 | * @cpumask: List of target CPUs. | |
1054 | * @func: The function to call on those CPUs. | |
1055 | * @info: The context data for the function to be called. | |
1056 | * @wait: Whether to wait for the calls to complete. | |
1057 | * | |
1058 | * Non-maskably call a function on another CPU for hotplug purposes. | |
1059 | * | |
1060 | * This function must be called with maskable interrupts disabled. | |
1061 | */ | |
1062 | static int hotplug_cpu_nmi_call_function(cpumask_t cpumask, | |
1063 | smp_call_func_t func, void *info, | |
1064 | int wait) | |
1065 | { | |
1066 | /* | |
1067 | * The address and the size of nmi_call_func_mask_data | |
1068 | * need to be aligned on L1_CACHE_BYTES. | |
1069 | */ | |
1070 | static struct nmi_call_data_struct nmi_call_func_mask_data | |
1071 | __cacheline_aligned; | |
1072 | unsigned long start, end; | |
1073 | ||
1074 | start = (unsigned long)&nmi_call_func_mask_data; | |
1075 | end = start + sizeof(struct nmi_call_data_struct); | |
1076 | ||
1077 | nmi_call_func_mask_data.func = func; | |
1078 | nmi_call_func_mask_data.info = info; | |
1079 | nmi_call_func_mask_data.started = cpumask; | |
1080 | nmi_call_func_mask_data.wait = wait; | |
1081 | if (wait) | |
1082 | nmi_call_func_mask_data.finished = cpumask; | |
1083 | ||
1084 | spin_lock(&smp_nmi_call_lock); | |
1085 | nmi_call_data = &nmi_call_func_mask_data; | |
1086 | mn10300_local_dcache_flush_range(start, end); | |
1087 | smp_wmb(); | |
1088 | ||
1089 | send_IPI_mask(cpumask, CALL_FUNCTION_NMI_IPI); | |
1090 | ||
1091 | do { | |
1092 | mn10300_local_dcache_inv_range(start, end); | |
1093 | barrier(); | |
1094 | } while (!cpus_empty(nmi_call_func_mask_data.started)); | |
1095 | ||
1096 | if (wait) { | |
1097 | do { | |
1098 | mn10300_local_dcache_inv_range(start, end); | |
1099 | barrier(); | |
1100 | } while (!cpus_empty(nmi_call_func_mask_data.finished)); | |
1101 | } | |
1102 | ||
1103 | spin_unlock(&smp_nmi_call_lock); | |
1104 | return 0; | |
1105 | } | |
1106 | ||
1107 | static void restart_wakeup_cpu(void) | |
1108 | { | |
1109 | unsigned int cpu = smp_processor_id(); | |
1110 | ||
1111 | cpu_set(cpu, cpu_callin_map); | |
1112 | local_flush_tlb(); | |
1113 | cpu_set(cpu, cpu_online_map); | |
1114 | smp_wmb(); | |
1115 | } | |
1116 | ||
1117 | static void prepare_sleep_cpu(void *unused) | |
1118 | { | |
1119 | sleep_mode[smp_processor_id()] = 1; | |
1120 | smp_mb(); | |
1121 | mn10300_local_dcache_flush_inv(); | |
1122 | hotplug_cpu_disable_cache(); | |
1123 | hotplug_cpu_invalidate_cache(); | |
1124 | } | |
1125 | ||
1126 | /* when this function called, IE=0, NMID=0. */ | |
1127 | static void sleep_cpu(void *unused) | |
1128 | { | |
1129 | unsigned int cpu_id = smp_processor_id(); | |
1130 | /* | |
1131 | * CALL_FUNCTION_NMI_IPI for wakeup_cpu() shall not be requested, | |
1132 | * before this cpu goes in SLEEP mode. | |
1133 | */ | |
1134 | do { | |
1135 | smp_mb(); | |
1136 | __sleep_cpu(); | |
1137 | } while (sleep_mode[cpu_id]); | |
1138 | restart_wakeup_cpu(); | |
1139 | } | |
1140 | ||
1141 | static void run_sleep_cpu(unsigned int cpu) | |
1142 | { | |
1143 | unsigned long flags; | |
1144 | cpumask_t cpumask = cpumask_of(cpu); | |
1145 | ||
1146 | flags = arch_local_cli_save(); | |
1147 | hotplug_cpu_nmi_call_function(cpumask, prepare_sleep_cpu, NULL, 1); | |
1148 | hotplug_cpu_nmi_call_function(cpumask, sleep_cpu, NULL, 0); | |
1149 | udelay(1); /* delay for the cpu to sleep. */ | |
1150 | arch_local_irq_restore(flags); | |
1151 | } | |
1152 | ||
1153 | static void wakeup_cpu(void) | |
1154 | { | |
1155 | hotplug_cpu_invalidate_cache(); | |
1156 | hotplug_cpu_enable_cache(); | |
1157 | smp_mb(); | |
1158 | sleep_mode[smp_processor_id()] = 0; | |
1159 | } | |
1160 | ||
1161 | static void run_wakeup_cpu(unsigned int cpu) | |
1162 | { | |
1163 | unsigned long flags; | |
1164 | ||
1165 | flags = arch_local_cli_save(); | |
1166 | #if NR_CPUS == 2 | |
1167 | mn10300_local_dcache_flush_inv(); | |
1168 | #else | |
1169 | /* | |
1170 | * Before waking up the cpu, | |
1171 | * all online cpus should stop and flush D-Cache for global data. | |
1172 | */ | |
1173 | #error not support NR_CPUS > 2, when CONFIG_HOTPLUG_CPU=y. | |
1174 | #endif | |
1175 | hotplug_cpu_nmi_call_function(cpumask_of(cpu), wakeup_cpu, NULL, 1); | |
1176 | arch_local_irq_restore(flags); | |
1177 | } | |
1178 | ||
1179 | #endif /* CONFIG_HOTPLUG_CPU */ |