1 /* SMP support routines.
3 * Copyright (C) 2006-2008 Panasonic Corporation
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.
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.
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 <linux/cpu.h>
28 #include <asm/tlbflush.h>
29 #include <asm/bitops.h>
30 #include <asm/processor.h>
32 #include <asm/exceptions.h>
33 #include <asm/hardirq.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>
41 #ifdef CONFIG_HOTPLUG_CPU
42 #include <asm/cacheflush.h>
44 static unsigned long sleep_mode
[NR_CPUS
];
46 static void run_sleep_cpu(unsigned int cpu
);
47 static void run_wakeup_cpu(unsigned int cpu
);
48 #endif /* CONFIG_HOTPLUG_CPU */
51 * Debug Message function
56 #define Dprintk(fmt, ...) printk(KERN_DEBUG fmt, ##__VA_ARGS__)
58 #define Dprintk(fmt, ...) no_printk(KERN_DEBUG fmt, ##__VA_ARGS__)
61 /* timeout value in msec for smp_nmi_call_function. zero is no timeout. */
62 #define CALL_FUNCTION_NMI_IPI_TIMEOUT 0
65 * Structure and data for smp_nmi_call_function().
67 struct nmi_call_data_struct
{
73 char size_alignment
[0]
74 __attribute__ ((__aligned__(SMP_CACHE_BYTES
)));
75 } __attribute__ ((__aligned__(SMP_CACHE_BYTES
)));
77 static DEFINE_SPINLOCK(smp_nmi_call_lock
);
78 static struct nmi_call_data_struct
*nmi_call_data
;
81 * Data structures and variables
83 static cpumask_t cpu_callin_map
; /* Bitmask of callin CPUs */
84 static cpumask_t cpu_callout_map
; /* Bitmask of callout CPUs */
85 cpumask_t cpu_boot_map
; /* Bitmask of boot APs */
86 unsigned long start_stack
[NR_CPUS
- 1];
91 struct mn10300_cpuinfo cpu_data
[NR_CPUS
] __cacheline_aligned
;
93 static int cpucount
; /* The count of boot CPUs */
94 static cpumask_t smp_commenced_mask
;
95 cpumask_t cpu_initialized __initdata
= CPU_MASK_NONE
;
100 static int do_boot_cpu(int);
101 static void smp_show_cpu_info(int cpu_id
);
102 static void smp_callin(void);
103 static void smp_online(void);
104 static void smp_store_cpu_info(int);
105 static void smp_cpu_init(void);
106 static void smp_tune_scheduling(void);
107 static void send_IPI_mask(const cpumask_t
*cpumask
, int irq
);
108 static void init_ipi(void);
111 * IPI Initialization interrupt definitions
113 static void mn10300_ipi_disable(unsigned int irq
);
114 static void mn10300_ipi_enable(unsigned int irq
);
115 static void mn10300_ipi_chip_disable(struct irq_data
*d
);
116 static void mn10300_ipi_chip_enable(struct irq_data
*d
);
117 static void mn10300_ipi_ack(struct irq_data
*d
);
118 static void mn10300_ipi_nop(struct irq_data
*d
);
120 static struct irq_chip mn10300_ipi_type
= {
122 .irq_disable
= mn10300_ipi_chip_disable
,
123 .irq_enable
= mn10300_ipi_chip_enable
,
124 .irq_ack
= mn10300_ipi_ack
,
125 .irq_eoi
= mn10300_ipi_nop
128 static irqreturn_t
smp_reschedule_interrupt(int irq
, void *dev_id
);
129 static irqreturn_t
smp_call_function_interrupt(int irq
, void *dev_id
);
131 static struct irqaction reschedule_ipi
= {
132 .handler
= smp_reschedule_interrupt
,
133 .flags
= IRQF_NOBALANCING
,
134 .name
= "smp reschedule IPI"
136 static struct irqaction call_function_ipi
= {
137 .handler
= smp_call_function_interrupt
,
138 .flags
= IRQF_NOBALANCING
,
139 .name
= "smp call function IPI"
142 #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
143 static irqreturn_t
smp_ipi_timer_interrupt(int irq
, void *dev_id
);
144 static struct irqaction local_timer_ipi
= {
145 .handler
= smp_ipi_timer_interrupt
,
146 .flags
= IRQF_DISABLED
| IRQF_NOBALANCING
,
147 .name
= "smp local timer IPI"
152 * init_ipi - Initialise the IPI mechanism
154 static void init_ipi(void)
159 /* set up the reschedule IPI */
160 irq_set_chip_and_handler(RESCHEDULE_IPI
, &mn10300_ipi_type
,
162 setup_irq(RESCHEDULE_IPI
, &reschedule_ipi
);
163 set_intr_level(RESCHEDULE_IPI
, RESCHEDULE_GxICR_LV
);
164 mn10300_ipi_enable(RESCHEDULE_IPI
);
166 /* set up the call function IPI */
167 irq_set_chip_and_handler(CALL_FUNC_SINGLE_IPI
, &mn10300_ipi_type
,
169 setup_irq(CALL_FUNC_SINGLE_IPI
, &call_function_ipi
);
170 set_intr_level(CALL_FUNC_SINGLE_IPI
, CALL_FUNCTION_GxICR_LV
);
171 mn10300_ipi_enable(CALL_FUNC_SINGLE_IPI
);
173 /* set up the local timer IPI */
174 #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || \
175 defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
176 irq_set_chip_and_handler(LOCAL_TIMER_IPI
, &mn10300_ipi_type
,
178 setup_irq(LOCAL_TIMER_IPI
, &local_timer_ipi
);
179 set_intr_level(LOCAL_TIMER_IPI
, LOCAL_TIMER_GxICR_LV
);
180 mn10300_ipi_enable(LOCAL_TIMER_IPI
);
183 #ifdef CONFIG_MN10300_CACHE_ENABLED
184 /* set up the cache flush IPI */
185 irq_set_chip(FLUSH_CACHE_IPI
, &mn10300_ipi_type
);
186 flags
= arch_local_cli_save();
187 __set_intr_stub(NUM2EXCEP_IRQ_LEVEL(FLUSH_CACHE_GxICR_LV
),
188 mn10300_low_ipi_handler
);
189 GxICR(FLUSH_CACHE_IPI
) = FLUSH_CACHE_GxICR_LV
| GxICR_DETECT
;
190 mn10300_ipi_enable(FLUSH_CACHE_IPI
);
191 arch_local_irq_restore(flags
);
194 /* set up the NMI call function IPI */
195 irq_set_chip(CALL_FUNCTION_NMI_IPI
, &mn10300_ipi_type
);
196 flags
= arch_local_cli_save();
197 GxICR(CALL_FUNCTION_NMI_IPI
) = GxICR_NMI
| GxICR_ENABLE
| GxICR_DETECT
;
198 tmp16
= GxICR(CALL_FUNCTION_NMI_IPI
);
199 arch_local_irq_restore(flags
);
201 /* set up the SMP boot IPI */
202 flags
= arch_local_cli_save();
203 __set_intr_stub(NUM2EXCEP_IRQ_LEVEL(SMP_BOOT_GxICR_LV
),
204 mn10300_low_ipi_handler
);
205 arch_local_irq_restore(flags
);
207 #ifdef CONFIG_KERNEL_DEBUGGER
208 irq_set_chip(DEBUGGER_NMI_IPI
, &mn10300_ipi_type
);
213 * mn10300_ipi_shutdown - Shut down handling of an IPI
214 * @irq: The IPI to be shut down.
216 static void mn10300_ipi_shutdown(unsigned int irq
)
221 flags
= arch_local_cli_save();
224 GxICR(irq
) = (tmp
& GxICR_LEVEL
) | GxICR_DETECT
;
227 arch_local_irq_restore(flags
);
231 * mn10300_ipi_enable - Enable an IPI
232 * @irq: The IPI to be enabled.
234 static void mn10300_ipi_enable(unsigned int irq
)
239 flags
= arch_local_cli_save();
242 GxICR(irq
) = (tmp
& GxICR_LEVEL
) | GxICR_ENABLE
;
245 arch_local_irq_restore(flags
);
248 static void mn10300_ipi_chip_enable(struct irq_data
*d
)
250 mn10300_ipi_enable(d
->irq
);
254 * mn10300_ipi_disable - Disable an IPI
255 * @irq: The IPI to be disabled.
257 static void mn10300_ipi_disable(unsigned int irq
)
262 flags
= arch_local_cli_save();
265 GxICR(irq
) = tmp
& GxICR_LEVEL
;
268 arch_local_irq_restore(flags
);
271 static void mn10300_ipi_chip_disable(struct irq_data
*d
)
273 mn10300_ipi_disable(d
->irq
);
278 * mn10300_ipi_ack - Acknowledge an IPI interrupt in the PIC
279 * @irq: The IPI to be acknowledged.
281 * Clear the interrupt detection flag for the IPI on the appropriate interrupt
282 * channel in the PIC.
284 static void mn10300_ipi_ack(struct irq_data
*d
)
286 unsigned int irq
= d
->irq
;
290 flags
= arch_local_cli_save();
291 GxICR_u8(irq
) = GxICR_DETECT
;
293 arch_local_irq_restore(flags
);
297 * mn10300_ipi_nop - Dummy IPI action
298 * @irq: The IPI to be acted upon.
300 static void mn10300_ipi_nop(struct irq_data
*d
)
305 * send_IPI_mask - Send IPIs to all CPUs in list
306 * @cpumask: The list of CPUs to target.
307 * @irq: The IPI request to be sent.
309 * Send the specified IPI to all the CPUs in the list, not waiting for them to
310 * finish before returning. The caller is responsible for synchronisation if
313 static void send_IPI_mask(const cpumask_t
*cpumask
, int irq
)
318 for (i
= 0; i
< NR_CPUS
; i
++) {
319 if (cpumask_test_cpu(i
, cpumask
)) {
321 tmp
= CROSS_GxICR(irq
, i
);
322 CROSS_GxICR(irq
, i
) =
323 tmp
| GxICR_REQUEST
| GxICR_DETECT
;
324 tmp
= CROSS_GxICR(irq
, i
); /* flush write buffer */
330 * send_IPI_self - Send an IPI to this CPU.
331 * @irq: The IPI request to be sent.
333 * Send the specified IPI to the current CPU.
335 void send_IPI_self(int irq
)
337 send_IPI_mask(cpumask_of(smp_processor_id()), irq
);
341 * send_IPI_allbutself - Send IPIs to all the other CPUs.
342 * @irq: The IPI request to be sent.
344 * Send the specified IPI to all CPUs in the system barring the current one,
345 * not waiting for them to finish before returning. The caller is responsible
346 * for synchronisation if that is needed.
348 void send_IPI_allbutself(int irq
)
352 cpumask_copy(&cpumask
, cpu_online_mask
);
353 cpumask_clear_cpu(smp_processor_id(), &cpumask
);
354 send_IPI_mask(&cpumask
, irq
);
357 void arch_send_call_function_ipi_mask(const struct cpumask
*mask
)
360 /*send_IPI_mask(mask, CALL_FUNCTION_IPI);*/
363 void arch_send_call_function_single_ipi(int cpu
)
365 send_IPI_mask(cpumask_of(cpu
), CALL_FUNC_SINGLE_IPI
);
369 * smp_send_reschedule - Send reschedule IPI to a CPU
370 * @cpu: The CPU to target.
372 void smp_send_reschedule(int cpu
)
374 send_IPI_mask(cpumask_of(cpu
), RESCHEDULE_IPI
);
378 * smp_nmi_call_function - Send a call function NMI IPI to all CPUs
379 * @func: The function to ask to be run.
380 * @info: The context data to pass to that function.
381 * @wait: If true, wait (atomically) until function is run on all CPUs.
383 * Send a non-maskable request to all CPUs in the system, requesting them to
384 * run the specified function with the given context data, and, potentially, to
385 * wait for completion of that function on all CPUs.
387 * Returns 0 if successful, -ETIMEDOUT if we were asked to wait, but hit the
390 int smp_nmi_call_function(smp_call_func_t func
, void *info
, int wait
)
392 struct nmi_call_data_struct data
;
397 cpus
= num_online_cpus() - 1;
403 cpumask_copy(&data
.started
, cpu_online_mask
);
404 cpumask_clear_cpu(smp_processor_id(), &data
.started
);
407 data
.finished
= data
.started
;
409 spin_lock_irqsave(&smp_nmi_call_lock
, flags
);
410 nmi_call_data
= &data
;
413 /* Send a message to all other CPUs and wait for them to respond */
414 send_IPI_allbutself(CALL_FUNCTION_NMI_IPI
);
416 /* Wait for response */
417 if (CALL_FUNCTION_NMI_IPI_TIMEOUT
> 0) {
419 cnt
< CALL_FUNCTION_NMI_IPI_TIMEOUT
&&
420 !cpumask_empty(&data
.started
);
424 if (wait
&& cnt
< CALL_FUNCTION_NMI_IPI_TIMEOUT
) {
426 cnt
< CALL_FUNCTION_NMI_IPI_TIMEOUT
&&
427 !cpumask_empty(&data
.finished
);
432 if (cnt
>= CALL_FUNCTION_NMI_IPI_TIMEOUT
)
436 /* If timeout value is zero, wait until cpumask has been
438 while (!cpumask_empty(&data
.started
))
441 while (!cpumask_empty(&data
.finished
))
445 spin_unlock_irqrestore(&smp_nmi_call_lock
, flags
);
450 * smp_jump_to_debugger - Make other CPUs enter the debugger by sending an IPI
452 * Send a non-maskable request to all other CPUs in the system, instructing
453 * them to jump into the debugger. The caller is responsible for checking that
454 * the other CPUs responded to the instruction.
456 * The caller should make sure that this CPU's debugger IPI is disabled.
458 void smp_jump_to_debugger(void)
460 if (num_online_cpus() > 1)
461 /* Send a message to all other CPUs */
462 send_IPI_allbutself(DEBUGGER_NMI_IPI
);
466 * stop_this_cpu - Callback to stop a CPU.
467 * @unused: Callback context (ignored).
469 void stop_this_cpu(void *unused
)
471 static volatile int stopflag
;
474 #ifdef CONFIG_GDBSTUB
475 /* In case of single stepping smp_send_stop by other CPU,
476 * clear procindebug to avoid deadlock.
478 atomic_set(&procindebug
[smp_processor_id()], 0);
479 #endif /* CONFIG_GDBSTUB */
481 flags
= arch_local_cli_save();
482 set_cpu_online(smp_processor_id(), false);
487 set_cpu_online(smp_processor_id(), true);
488 arch_local_irq_restore(flags
);
492 * smp_send_stop - Send a stop request to all CPUs.
494 void smp_send_stop(void)
496 smp_nmi_call_function(stop_this_cpu
, NULL
, 0);
500 * smp_reschedule_interrupt - Reschedule IPI handler
501 * @irq: The interrupt number.
502 * @dev_id: The device ID.
504 * Returns IRQ_HANDLED to indicate we handled the interrupt successfully.
506 static irqreturn_t
smp_reschedule_interrupt(int irq
, void *dev_id
)
513 * smp_call_function_interrupt - Call function IPI handler
514 * @irq: The interrupt number.
515 * @dev_id: The device ID.
517 * Returns IRQ_HANDLED to indicate we handled the interrupt successfully.
519 static irqreturn_t
smp_call_function_interrupt(int irq
, void *dev_id
)
521 /* generic_smp_call_function_interrupt(); */
522 generic_smp_call_function_single_interrupt();
527 * smp_nmi_call_function_interrupt - Non-maskable call function IPI handler
529 void smp_nmi_call_function_interrupt(void)
531 smp_call_func_t func
= nmi_call_data
->func
;
532 void *info
= nmi_call_data
->info
;
533 int wait
= nmi_call_data
->wait
;
535 /* Notify the initiating CPU that I've grabbed the data and am about to
536 * execute the function
539 cpumask_clear_cpu(smp_processor_id(), &nmi_call_data
->started
);
544 cpumask_clear_cpu(smp_processor_id(),
545 &nmi_call_data
->finished
);
549 #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || \
550 defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
552 * smp_ipi_timer_interrupt - Local timer IPI handler
553 * @irq: The interrupt number.
554 * @dev_id: The device ID.
556 * Returns IRQ_HANDLED to indicate we handled the interrupt successfully.
558 static irqreturn_t
smp_ipi_timer_interrupt(int irq
, void *dev_id
)
560 return local_timer_interrupt();
564 void __init
smp_init_cpus(void)
567 for (i
= 0; i
< NR_CPUS
; i
++) {
568 set_cpu_possible(i
, true);
569 set_cpu_present(i
, true);
574 * smp_cpu_init - Initialise AP in start_secondary.
576 * For this Application Processor, set up init_mm, initialise FPU and set
577 * interrupt level 0-6 setting.
579 static void __init
smp_cpu_init(void)
582 int cpu_id
= smp_processor_id();
585 if (test_and_set_bit(cpu_id
, &cpu_initialized
)) {
586 printk(KERN_WARNING
"CPU#%d already initialized!\n", cpu_id
);
590 printk(KERN_INFO
"Initializing CPU#%d\n", cpu_id
);
592 atomic_inc(&init_mm
.mm_count
);
593 current
->active_mm
= &init_mm
;
596 enter_lazy_tlb(&init_mm
, current
);
598 /* Force FPU initialization */
599 clear_using_fpu(current
);
601 GxICR(CALL_FUNC_SINGLE_IPI
) = CALL_FUNCTION_GxICR_LV
| GxICR_DETECT
;
602 mn10300_ipi_enable(CALL_FUNC_SINGLE_IPI
);
604 GxICR(LOCAL_TIMER_IPI
) = LOCAL_TIMER_GxICR_LV
| GxICR_DETECT
;
605 mn10300_ipi_enable(LOCAL_TIMER_IPI
);
607 GxICR(RESCHEDULE_IPI
) = RESCHEDULE_GxICR_LV
| GxICR_DETECT
;
608 mn10300_ipi_enable(RESCHEDULE_IPI
);
610 #ifdef CONFIG_MN10300_CACHE_ENABLED
611 GxICR(FLUSH_CACHE_IPI
) = FLUSH_CACHE_GxICR_LV
| GxICR_DETECT
;
612 mn10300_ipi_enable(FLUSH_CACHE_IPI
);
615 mn10300_ipi_shutdown(SMP_BOOT_IRQ
);
617 /* Set up the non-maskable call function IPI */
618 flags
= arch_local_cli_save();
619 GxICR(CALL_FUNCTION_NMI_IPI
) = GxICR_NMI
| GxICR_ENABLE
| GxICR_DETECT
;
620 tmp16
= GxICR(CALL_FUNCTION_NMI_IPI
);
621 arch_local_irq_restore(flags
);
625 * smp_prepare_cpu_init - Initialise CPU in startup_secondary
627 * Set interrupt level 0-6 setting and init ICR of the kernel debugger.
629 void smp_prepare_cpu_init(void)
633 /* Set the interrupt vector registers */
634 IVAR0
= EXCEP_IRQ_LEVEL0
;
635 IVAR1
= EXCEP_IRQ_LEVEL1
;
636 IVAR2
= EXCEP_IRQ_LEVEL2
;
637 IVAR3
= EXCEP_IRQ_LEVEL3
;
638 IVAR4
= EXCEP_IRQ_LEVEL4
;
639 IVAR5
= EXCEP_IRQ_LEVEL5
;
640 IVAR6
= EXCEP_IRQ_LEVEL6
;
642 /* Disable all interrupts and set to priority 6 (lowest) */
643 for (loop
= 0; loop
< GxICR_NUM_IRQS
; loop
++)
644 GxICR(loop
) = GxICR_LEVEL_6
| GxICR_DETECT
;
646 #ifdef CONFIG_KERNEL_DEBUGGER
647 /* initialise the kernel debugger interrupt */
652 flags
= arch_local_cli_save();
653 GxICR(DEBUGGER_NMI_IPI
) = GxICR_NMI
| GxICR_ENABLE
| GxICR_DETECT
;
654 tmp16
= GxICR(DEBUGGER_NMI_IPI
);
655 arch_local_irq_restore(flags
);
661 * start_secondary - Activate a secondary CPU (AP)
662 * @unused: Thread parameter (ignored).
664 int __init
start_secondary(void *unused
)
668 while (!cpumask_test_cpu(smp_processor_id(), &smp_commenced_mask
))
675 #ifdef CONFIG_GENERIC_CLOCKEVENTS
678 cpu_startup_entry(CPUHP_ONLINE
);
683 * smp_prepare_cpus - Boot up secondary CPUs (APs)
684 * @max_cpus: Maximum number of CPUs to boot.
686 * Call do_boot_cpu, and boot up APs.
688 void __init
smp_prepare_cpus(unsigned int max_cpus
)
692 /* Setup boot CPU information */
693 smp_store_cpu_info(0);
694 smp_tune_scheduling();
698 /* If SMP should be disabled, then finish */
700 printk(KERN_INFO
"SMP mode deactivated.\n");
704 /* Boot secondary CPUs (for which phy_id > 0) */
705 for (phy_id
= 0; phy_id
< NR_CPUS
; phy_id
++) {
706 /* Don't boot primary CPU */
707 if (max_cpus
<= cpucount
+ 1)
711 set_cpu_possible(phy_id
, true);
712 smp_show_cpu_info(phy_id
);
716 Dprintk("Boot done.\n");
720 * smp_store_cpu_info - Save a CPU's information
721 * @cpu: The CPU to save for.
723 * Save boot_cpu_data and jiffy for the specified CPU.
725 static void __init
smp_store_cpu_info(int cpu
)
727 struct mn10300_cpuinfo
*ci
= &cpu_data
[cpu
];
730 ci
->loops_per_jiffy
= loops_per_jiffy
;
735 * smp_tune_scheduling - Set time slice value
737 * Nothing to do here.
739 static void __init
smp_tune_scheduling(void)
744 * do_boot_cpu: Boot up one CPU
745 * @phy_id: Physical ID of CPU to boot.
747 * Send an IPI to a secondary CPU to boot it. Returns 0 on success, 1
750 static int __init
do_boot_cpu(int phy_id
)
752 struct task_struct
*idle
;
753 unsigned long send_status
, callin_status
;
756 send_status
= GxICR_REQUEST
;
763 /* Create idle thread for this CPU */
764 idle
= fork_idle(cpu_id
);
766 panic("Failed fork for CPU#%d.", cpu_id
);
768 idle
->thread
.pc
= (unsigned long)start_secondary
;
770 printk(KERN_NOTICE
"Booting CPU#%d\n", cpu_id
);
771 start_stack
[cpu_id
- 1] = idle
->thread
.sp
;
773 task_thread_info(idle
)->cpu
= cpu_id
;
775 /* Send boot IPI to AP */
776 send_IPI_mask(cpumask_of(phy_id
), SMP_BOOT_IRQ
);
778 Dprintk("Waiting for send to finish...\n");
780 /* Wait for AP's IPI receive in 100[ms] */
784 CROSS_GxICR(SMP_BOOT_IRQ
, phy_id
) & GxICR_REQUEST
;
785 } while (send_status
== GxICR_REQUEST
&& timeout
++ < 100);
787 Dprintk("Waiting for cpu_callin_map.\n");
789 if (send_status
== 0) {
790 /* Allow AP to start initializing */
791 cpumask_set_cpu(cpu_id
, &cpu_callout_map
);
793 /* Wait for setting cpu_callin_map */
797 callin_status
= cpumask_test_cpu(cpu_id
,
799 } while (callin_status
== 0 && timeout
++ < 5000);
801 if (callin_status
== 0)
802 Dprintk("Not responding.\n");
804 printk(KERN_WARNING
"IPI not delivered.\n");
807 if (send_status
== GxICR_REQUEST
|| callin_status
== 0) {
808 cpumask_clear_cpu(cpu_id
, &cpu_callout_map
);
809 cpumask_clear_cpu(cpu_id
, &cpu_callin_map
);
810 cpumask_clear_cpu(cpu_id
, &cpu_initialized
);
818 * smp_show_cpu_info - Show SMP CPU information
819 * @cpu: The CPU of interest.
821 static void __init
smp_show_cpu_info(int cpu
)
823 struct mn10300_cpuinfo
*ci
= &cpu_data
[cpu
];
826 "CPU#%d : ioclk speed: %lu.%02luMHz : bogomips : %lu.%02lu\n",
828 MN10300_IOCLK
/ 1000000,
829 (MN10300_IOCLK
/ 10000) % 100,
830 ci
->loops_per_jiffy
/ (500000 / HZ
),
831 (ci
->loops_per_jiffy
/ (5000 / HZ
)) % 100);
835 * smp_callin - Set cpu_callin_map of the current CPU ID
837 static void __init
smp_callin(void)
839 unsigned long timeout
;
842 cpu
= smp_processor_id();
843 timeout
= jiffies
+ (2 * HZ
);
845 if (cpumask_test_cpu(cpu
, &cpu_callin_map
)) {
846 printk(KERN_ERR
"CPU#%d already present.\n", cpu
);
849 Dprintk("CPU#%d waiting for CALLOUT\n", cpu
);
851 /* Wait for AP startup 2s total */
852 while (time_before(jiffies
, timeout
)) {
853 if (cpumask_test_cpu(cpu
, &cpu_callout_map
))
858 if (!time_before(jiffies
, timeout
)) {
860 "BUG: CPU#%d started up but did not get a callout!\n",
865 #ifdef CONFIG_CALIBRATE_DELAY
866 calibrate_delay(); /* Get our bogomips */
869 /* Save our processor parameters */
870 smp_store_cpu_info(cpu
);
872 /* Allow the boot processor to continue */
873 cpumask_set_cpu(cpu
, &cpu_callin_map
);
877 * smp_online - Set cpu_online_mask
879 static void __init
smp_online(void)
883 cpu
= smp_processor_id();
885 notify_cpu_starting(cpu
);
887 set_cpu_online(cpu
, true);
894 * @max_cpus: Maximum CPU count.
898 void __init
smp_cpus_done(unsigned int max_cpus
)
903 * smp_prepare_boot_cpu - Set up stuff for the boot processor.
905 * Set up the cpu_online_mask, cpu_callout_map and cpu_callin_map of the boot
908 void smp_prepare_boot_cpu(void)
910 cpumask_set_cpu(0, &cpu_callout_map
);
911 cpumask_set_cpu(0, &cpu_callin_map
);
912 current_thread_info()->cpu
= 0;
916 * initialize_secondary - Initialise a secondary CPU (Application Processor).
918 * Set SP register and jump to thread's PC address.
920 void initialize_secondary(void)
926 : "a"(current
->thread
.sp
), "a"(current
->thread
.pc
));
930 * __cpu_up - Set smp_commenced_mask for the nominated CPU
931 * @cpu: The target CPU.
933 int __cpu_up(unsigned int cpu
, struct task_struct
*tidle
)
937 #ifdef CONFIG_HOTPLUG_CPU
940 #endif /* CONFIG_HOTPLUG_CPU */
942 cpumask_set_cpu(cpu
, &smp_commenced_mask
);
944 /* Wait 5s total for a response */
945 for (timeout
= 0 ; timeout
< 5000 ; timeout
++) {
951 BUG_ON(!cpu_online(cpu
));
956 * setup_profiling_timer - Set up the profiling timer
957 * @multiplier - The frequency multiplier to use
959 * The frequency of the profiling timer can be changed by writing a multiplier
960 * value into /proc/profile.
962 int setup_profiling_timer(unsigned int multiplier
)
968 * CPU hotplug routines
970 #ifdef CONFIG_HOTPLUG_CPU
972 static DEFINE_PER_CPU(struct cpu
, cpu_devices
);
974 static int __init
topology_init(void)
979 ret
= register_cpu(&per_cpu(cpu_devices
, cpu
), cpu
, NULL
);
982 "topology_init: register_cpu %d failed (%d)\n",
988 subsys_initcall(topology_init
);
990 int __cpu_disable(void)
992 int cpu
= smp_processor_id();
997 cpumask_clear_cpu(cpu
, &mm_cpumask(current
->active_mm
));
1001 void __cpu_die(unsigned int cpu
)
1006 #ifdef CONFIG_MN10300_CACHE_ENABLED
1007 static inline void hotplug_cpu_disable_cache(void)
1014 "1: movhu (%1),%0 \n"
1019 "i"(~(CHCTR_ICEN
| CHCTR_DCEN
)),
1020 "i"(CHCTR_ICBUSY
| CHCTR_DCBUSY
)
1024 static inline void hotplug_cpu_enable_cache(void)
1033 "i"(CHCTR_ICEN
| CHCTR_DCEN
)
1037 static inline void hotplug_cpu_invalidate_cache(void)
1046 "i"(CHCTR_ICINV
| CHCTR_DCINV
)
1050 #else /* CONFIG_MN10300_CACHE_ENABLED */
1051 #define hotplug_cpu_disable_cache() do {} while (0)
1052 #define hotplug_cpu_enable_cache() do {} while (0)
1053 #define hotplug_cpu_invalidate_cache() do {} while (0)
1054 #endif /* CONFIG_MN10300_CACHE_ENABLED */
1057 * hotplug_cpu_nmi_call_function - Call a function on other CPUs for hotplug
1058 * @cpumask: List of target CPUs.
1059 * @func: The function to call on those CPUs.
1060 * @info: The context data for the function to be called.
1061 * @wait: Whether to wait for the calls to complete.
1063 * Non-maskably call a function on another CPU for hotplug purposes.
1065 * This function must be called with maskable interrupts disabled.
1067 static int hotplug_cpu_nmi_call_function(cpumask_t cpumask
,
1068 smp_call_func_t func
, void *info
,
1072 * The address and the size of nmi_call_func_mask_data
1073 * need to be aligned on L1_CACHE_BYTES.
1075 static struct nmi_call_data_struct nmi_call_func_mask_data
1076 __cacheline_aligned
;
1077 unsigned long start
, end
;
1079 start
= (unsigned long)&nmi_call_func_mask_data
;
1080 end
= start
+ sizeof(struct nmi_call_data_struct
);
1082 nmi_call_func_mask_data
.func
= func
;
1083 nmi_call_func_mask_data
.info
= info
;
1084 nmi_call_func_mask_data
.started
= cpumask
;
1085 nmi_call_func_mask_data
.wait
= wait
;
1087 nmi_call_func_mask_data
.finished
= cpumask
;
1089 spin_lock(&smp_nmi_call_lock
);
1090 nmi_call_data
= &nmi_call_func_mask_data
;
1091 mn10300_local_dcache_flush_range(start
, end
);
1094 send_IPI_mask(cpumask
, CALL_FUNCTION_NMI_IPI
);
1097 mn10300_local_dcache_inv_range(start
, end
);
1099 } while (!cpumask_empty(&nmi_call_func_mask_data
.started
));
1103 mn10300_local_dcache_inv_range(start
, end
);
1105 } while (!cpumask_empty(&nmi_call_func_mask_data
.finished
));
1108 spin_unlock(&smp_nmi_call_lock
);
1112 static void restart_wakeup_cpu(void)
1114 unsigned int cpu
= smp_processor_id();
1116 cpumask_set_cpu(cpu
, &cpu_callin_map
);
1118 set_cpu_online(cpu
, true);
1122 static void prepare_sleep_cpu(void *unused
)
1124 sleep_mode
[smp_processor_id()] = 1;
1126 mn10300_local_dcache_flush_inv();
1127 hotplug_cpu_disable_cache();
1128 hotplug_cpu_invalidate_cache();
1131 /* when this function called, IE=0, NMID=0. */
1132 static void sleep_cpu(void *unused
)
1134 unsigned int cpu_id
= smp_processor_id();
1136 * CALL_FUNCTION_NMI_IPI for wakeup_cpu() shall not be requested,
1137 * before this cpu goes in SLEEP mode.
1142 } while (sleep_mode
[cpu_id
]);
1143 restart_wakeup_cpu();
1146 static void run_sleep_cpu(unsigned int cpu
)
1148 unsigned long flags
;
1151 cpumask_copy(&cpumask
, &cpumask_of(cpu
));
1152 flags
= arch_local_cli_save();
1153 hotplug_cpu_nmi_call_function(cpumask
, prepare_sleep_cpu
, NULL
, 1);
1154 hotplug_cpu_nmi_call_function(cpumask
, sleep_cpu
, NULL
, 0);
1155 udelay(1); /* delay for the cpu to sleep. */
1156 arch_local_irq_restore(flags
);
1159 static void wakeup_cpu(void)
1161 hotplug_cpu_invalidate_cache();
1162 hotplug_cpu_enable_cache();
1164 sleep_mode
[smp_processor_id()] = 0;
1167 static void run_wakeup_cpu(unsigned int cpu
)
1169 unsigned long flags
;
1171 flags
= arch_local_cli_save();
1173 mn10300_local_dcache_flush_inv();
1176 * Before waking up the cpu,
1177 * all online cpus should stop and flush D-Cache for global data.
1179 #error not support NR_CPUS > 2, when CONFIG_HOTPLUG_CPU=y.
1181 hotplug_cpu_nmi_call_function(cpumask_of(cpu
), wakeup_cpu
, NULL
, 1);
1182 arch_local_irq_restore(flags
);
1185 #endif /* CONFIG_HOTPLUG_CPU */