m32r: fix build due to notify_cpu_starting() change
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / m32r / kernel / smpboot.c
blob39cb6da72dcbef3358d04e2b419a150f88c299ba
1 /*
2 * linux/arch/m32r/kernel/smpboot.c
3 * orig : i386 2.4.10
5 * M32R SMP booting functions
7 * Copyright (c) 2001, 2002, 2003 Hitoshi Yamamoto
9 * Taken from i386 version.
10 * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
11 * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com>
13 * Much of the core SMP work is based on previous work by Thomas Radke, to
14 * whom a great many thanks are extended.
16 * Thanks to Intel for making available several different Pentium,
17 * Pentium Pro and Pentium-II/Xeon MP machines.
18 * Original development of Linux SMP code supported by Caldera.
20 * This code is released under the GNU General Public License version 2 or
21 * later.
23 * Fixes
24 * Felix Koop : NR_CPUS used properly
25 * Jose Renau : Handle single CPU case.
26 * Alan Cox : By repeated request
27 * 8) - Total BogoMIP report.
28 * Greg Wright : Fix for kernel stacks panic.
29 * Erich Boleyn : MP v1.4 and additional changes.
30 * Matthias Sattler : Changes for 2.1 kernel map.
31 * Michel Lespinasse : Changes for 2.1 kernel map.
32 * Michael Chastain : Change trampoline.S to gnu as.
33 * Alan Cox : Dumb bug: 'B' step PPro's are fine
34 * Ingo Molnar : Added APIC timers, based on code
35 * from Jose Renau
36 * Ingo Molnar : various cleanups and rewrites
37 * Tigran Aivazian : fixed "0.00 in /proc/uptime on SMP" bug.
38 * Maciej W. Rozycki : Bits for genuine 82489DX APICs
39 * Martin J. Bligh : Added support for multi-quad systems
42 #include <linux/module.h>
43 #include <linux/cpu.h>
44 #include <linux/init.h>
45 #include <linux/kernel.h>
46 #include <linux/mm.h>
47 #include <linux/sched.h>
48 #include <linux/err.h>
49 #include <linux/irq.h>
50 #include <linux/bootmem.h>
51 #include <linux/delay.h>
53 #include <asm/io.h>
54 #include <asm/pgalloc.h>
55 #include <asm/tlbflush.h>
57 #define DEBUG_SMP
58 #ifdef DEBUG_SMP
59 #define Dprintk(x...) printk(x)
60 #else
61 #define Dprintk(x...)
62 #endif
64 extern cpumask_t cpu_initialized;
66 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
67 /* Data structures and variables */
68 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
70 /* Processor that is doing the boot up */
71 static unsigned int bsp_phys_id = -1;
73 /* Bitmask of physically existing CPUs */
74 physid_mask_t phys_cpu_present_map;
76 /* Bitmask of currently online CPUs */
77 cpumask_t cpu_online_map;
78 EXPORT_SYMBOL(cpu_online_map);
80 cpumask_t cpu_bootout_map;
81 cpumask_t cpu_bootin_map;
82 static cpumask_t cpu_callin_map;
83 cpumask_t cpu_callout_map;
84 EXPORT_SYMBOL(cpu_callout_map);
85 cpumask_t cpu_possible_map = CPU_MASK_ALL;
86 EXPORT_SYMBOL(cpu_possible_map);
88 /* Per CPU bogomips and other parameters */
89 struct cpuinfo_m32r cpu_data[NR_CPUS] __cacheline_aligned;
91 static int cpucount;
92 static cpumask_t smp_commenced_mask;
94 extern struct {
95 void * spi;
96 unsigned short ss;
97 } stack_start;
99 /* which physical physical ID maps to which logical CPU number */
100 static volatile int physid_2_cpu[NR_CPUS];
101 #define physid_to_cpu(physid) physid_2_cpu[physid]
103 /* which logical CPU number maps to which physical ID */
104 volatile int cpu_2_physid[NR_CPUS];
106 DEFINE_PER_CPU(int, prof_multiplier) = 1;
107 DEFINE_PER_CPU(int, prof_old_multiplier) = 1;
108 DEFINE_PER_CPU(int, prof_counter) = 1;
110 spinlock_t ipi_lock[NR_IPIS];
112 static unsigned int calibration_result;
114 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
115 /* Function Prototypes */
116 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
118 void smp_prepare_boot_cpu(void);
119 void smp_prepare_cpus(unsigned int);
120 static void init_ipi_lock(void);
121 static void do_boot_cpu(int);
122 int __cpu_up(unsigned int);
123 void smp_cpus_done(unsigned int);
125 int start_secondary(void *);
126 static void smp_callin(void);
127 static void smp_online(void);
129 static void show_mp_info(int);
130 static void smp_store_cpu_info(int);
131 static void show_cpu_info(int);
132 int setup_profiling_timer(unsigned int);
133 static void init_cpu_to_physid(void);
134 static void map_cpu_to_physid(int, int);
135 static void unmap_cpu_to_physid(int, int);
137 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
138 /* Boot up APs Routines : BSP */
139 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
140 void __devinit smp_prepare_boot_cpu(void)
142 bsp_phys_id = hard_smp_processor_id();
143 physid_set(bsp_phys_id, phys_cpu_present_map);
144 cpu_set(0, cpu_online_map); /* BSP's cpu_id == 0 */
145 cpu_set(0, cpu_callout_map);
146 cpu_set(0, cpu_callin_map);
149 * Initialize the logical to physical CPU number mapping
151 init_cpu_to_physid();
152 map_cpu_to_physid(0, bsp_phys_id);
153 current_thread_info()->cpu = 0;
156 /*==========================================================================*
157 * Name: smp_prepare_cpus (old smp_boot_cpus)
159 * Description: This routine boot up APs.
161 * Born on Date: 2002.02.05
163 * Arguments: NONE
165 * Returns: void (cannot fail)
167 * Modification log:
168 * Date Who Description
169 * ---------- --- --------------------------------------------------------
170 * 2003-06-24 hy modify for linux-2.5.69
172 *==========================================================================*/
173 void __init smp_prepare_cpus(unsigned int max_cpus)
175 int phys_id;
176 unsigned long nr_cpu;
178 nr_cpu = inl(M32R_FPGA_NUM_OF_CPUS_PORTL);
179 if (nr_cpu > NR_CPUS) {
180 printk(KERN_INFO "NUM_OF_CPUS reg. value [%ld] > NR_CPU [%d]",
181 nr_cpu, NR_CPUS);
182 goto smp_done;
184 for (phys_id = 0 ; phys_id < nr_cpu ; phys_id++)
185 physid_set(phys_id, phys_cpu_present_map);
186 #ifndef CONFIG_HOTPLUG_CPU
187 cpu_present_map = cpu_possible_map;
188 #endif
190 show_mp_info(nr_cpu);
192 init_ipi_lock();
195 * Setup boot CPU information
197 smp_store_cpu_info(0); /* Final full version of the data */
200 * If SMP should be disabled, then really disable it!
202 if (!max_cpus) {
203 printk(KERN_INFO "SMP mode deactivated by commandline.\n");
204 goto smp_done;
208 * Now scan the CPU present map and fire up the other CPUs.
210 Dprintk("CPU present map : %lx\n", physids_coerce(phys_cpu_present_map));
212 for (phys_id = 0 ; phys_id < NR_CPUS ; phys_id++) {
214 * Don't even attempt to start the boot CPU!
216 if (phys_id == bsp_phys_id)
217 continue;
219 if (!physid_isset(phys_id, phys_cpu_present_map))
220 continue;
222 if ((max_cpus >= 0) && (max_cpus <= cpucount + 1))
223 continue;
225 do_boot_cpu(phys_id);
228 * Make sure we unmap all failed CPUs
230 if (physid_to_cpu(phys_id) == -1) {
231 physid_clear(phys_id, phys_cpu_present_map);
232 printk("phys CPU#%d not responding - " \
233 "cannot use it.\n", phys_id);
237 smp_done:
238 Dprintk("Boot done.\n");
242 * init_ipi_lock : Initialize IPI locks.
244 static void __init init_ipi_lock(void)
246 int ipi;
248 for (ipi = 0 ; ipi < NR_IPIS ; ipi++)
249 spin_lock_init(&ipi_lock[ipi]);
252 /*==========================================================================*
253 * Name: do_boot_cpu
255 * Description: This routine boot up one AP.
257 * Born on Date: 2002.02.05
259 * Arguments: phys_id - Target CPU physical ID
261 * Returns: void (cannot fail)
263 * Modification log:
264 * Date Who Description
265 * ---------- --- --------------------------------------------------------
266 * 2003-06-24 hy modify for linux-2.5.69
268 *==========================================================================*/
269 static void __init do_boot_cpu(int phys_id)
271 struct task_struct *idle;
272 unsigned long send_status, boot_status;
273 int timeout, cpu_id;
275 cpu_id = ++cpucount;
278 * We can't use kernel_thread since we must avoid to
279 * reschedule the child.
281 idle = fork_idle(cpu_id);
282 if (IS_ERR(idle))
283 panic("failed fork for CPU#%d.", cpu_id);
285 idle->thread.lr = (unsigned long)start_secondary;
287 map_cpu_to_physid(cpu_id, phys_id);
289 /* So we see what's up */
290 printk("Booting processor %d/%d\n", phys_id, cpu_id);
291 stack_start.spi = (void *)idle->thread.sp;
292 task_thread_info(idle)->cpu = cpu_id;
295 * Send Startup IPI
296 * 1.IPI received by CPU#(phys_id).
297 * 2.CPU#(phys_id) enter startup_AP (arch/m32r/kernel/head.S)
298 * 3.CPU#(phys_id) enter start_secondary()
300 send_status = 0;
301 boot_status = 0;
303 cpu_set(phys_id, cpu_bootout_map);
305 /* Send Startup IPI */
306 send_IPI_mask_phys(cpumask_of_cpu(phys_id), CPU_BOOT_IPI, 0);
308 Dprintk("Waiting for send to finish...\n");
309 timeout = 0;
311 /* Wait 100[ms] */
312 do {
313 Dprintk("+");
314 udelay(1000);
315 send_status = !cpu_isset(phys_id, cpu_bootin_map);
316 } while (send_status && (timeout++ < 100));
318 Dprintk("After Startup.\n");
320 if (!send_status) {
322 * allow APs to start initializing.
324 Dprintk("Before Callout %d.\n", cpu_id);
325 cpu_set(cpu_id, cpu_callout_map);
326 Dprintk("After Callout %d.\n", cpu_id);
329 * Wait 5s total for a response
331 for (timeout = 0; timeout < 5000; timeout++) {
332 if (cpu_isset(cpu_id, cpu_callin_map))
333 break; /* It has booted */
334 udelay(1000);
337 if (cpu_isset(cpu_id, cpu_callin_map)) {
338 /* number CPUs logically, starting from 1 (BSP is 0) */
339 Dprintk("OK.\n");
340 } else {
341 boot_status = 1;
342 printk("Not responding.\n");
344 } else
345 printk("IPI never delivered???\n");
347 if (send_status || boot_status) {
348 unmap_cpu_to_physid(cpu_id, phys_id);
349 cpu_clear(cpu_id, cpu_callout_map);
350 cpu_clear(cpu_id, cpu_callin_map);
351 cpu_clear(cpu_id, cpu_initialized);
352 cpucount--;
356 int __cpuinit __cpu_up(unsigned int cpu_id)
358 int timeout;
360 cpu_set(cpu_id, smp_commenced_mask);
363 * Wait 5s total for a response
365 for (timeout = 0; timeout < 5000; timeout++) {
366 if (cpu_isset(cpu_id, cpu_online_map))
367 break;
368 udelay(1000);
370 if (!cpu_isset(cpu_id, cpu_online_map))
371 BUG();
373 return 0;
376 void __init smp_cpus_done(unsigned int max_cpus)
378 int cpu_id, timeout;
379 unsigned long bogosum = 0;
381 for (timeout = 0; timeout < 5000; timeout++) {
382 if (cpus_equal(cpu_callin_map, cpu_online_map))
383 break;
384 udelay(1000);
386 if (!cpus_equal(cpu_callin_map, cpu_online_map))
387 BUG();
389 for (cpu_id = 0 ; cpu_id < num_online_cpus() ; cpu_id++)
390 show_cpu_info(cpu_id);
393 * Allow the user to impress friends.
395 Dprintk("Before bogomips.\n");
396 if (cpucount) {
397 for_each_cpu_mask(cpu_id, cpu_online_map)
398 bogosum += cpu_data[cpu_id].loops_per_jiffy;
400 printk(KERN_INFO "Total of %d processors activated " \
401 "(%lu.%02lu BogoMIPS).\n", cpucount + 1,
402 bogosum / (500000 / HZ),
403 (bogosum / (5000 / HZ)) % 100);
404 Dprintk("Before bogocount - setting activated=1.\n");
408 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
409 /* Activate a secondary processor Routines */
410 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
412 /*==========================================================================*
413 * Name: start_secondary
415 * Description: This routine activate a secondary processor.
417 * Born on Date: 2002.02.05
419 * Arguments: *unused - currently unused.
421 * Returns: void (cannot fail)
423 * Modification log:
424 * Date Who Description
425 * ---------- --- --------------------------------------------------------
426 * 2003-06-24 hy modify for linux-2.5.69
428 *==========================================================================*/
429 int __init start_secondary(void *unused)
431 cpu_init();
432 preempt_disable();
433 smp_callin();
434 while (!cpu_isset(smp_processor_id(), smp_commenced_mask))
435 cpu_relax();
437 smp_online();
440 * low-memory mappings have been cleared, flush them from
441 * the local TLBs too.
443 local_flush_tlb_all();
445 cpu_idle();
446 return 0;
449 /*==========================================================================*
450 * Name: smp_callin
452 * Description: This routine activate a secondary processor.
454 * Born on Date: 2002.02.05
456 * Arguments: NONE
458 * Returns: void (cannot fail)
460 * Modification log:
461 * Date Who Description
462 * ---------- --- --------------------------------------------------------
463 * 2003-06-24 hy modify for linux-2.5.69
465 *==========================================================================*/
466 static void __init smp_callin(void)
468 int phys_id = hard_smp_processor_id();
469 int cpu_id = smp_processor_id();
470 unsigned long timeout;
472 if (cpu_isset(cpu_id, cpu_callin_map)) {
473 printk("huh, phys CPU#%d, CPU#%d already present??\n",
474 phys_id, cpu_id);
475 BUG();
477 Dprintk("CPU#%d (phys ID: %d) waiting for CALLOUT\n", cpu_id, phys_id);
479 /* Waiting 2s total for startup (udelay is not yet working) */
480 timeout = jiffies + (2 * HZ);
481 while (time_before(jiffies, timeout)) {
482 /* Has the boot CPU finished it's STARTUP sequence ? */
483 if (cpu_isset(cpu_id, cpu_callout_map))
484 break;
485 cpu_relax();
488 if (!time_before(jiffies, timeout)) {
489 printk("BUG: CPU#%d started up but did not get a callout!\n",
490 cpu_id);
491 BUG();
494 /* Allow the master to continue. */
495 cpu_set(cpu_id, cpu_callin_map);
498 static void __init smp_online(void)
500 int cpu_id = smp_processor_id();
502 notify_cpu_starting(cpu_id);
504 local_irq_enable();
506 /* Get our bogomips. */
507 calibrate_delay();
509 /* Save our processor parameters */
510 smp_store_cpu_info(cpu_id);
512 cpu_set(cpu_id, cpu_online_map);
515 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
516 /* Boot up CPUs common Routines */
517 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
518 static void __init show_mp_info(int nr_cpu)
520 int i;
521 char cpu_model0[17], cpu_model1[17], cpu_ver[9];
523 strncpy(cpu_model0, (char *)M32R_FPGA_CPU_NAME_ADDR, 16);
524 strncpy(cpu_model1, (char *)M32R_FPGA_MODEL_ID_ADDR, 16);
525 strncpy(cpu_ver, (char *)M32R_FPGA_VERSION_ADDR, 8);
527 cpu_model0[16] = '\0';
528 for (i = 15 ; i >= 0 ; i--) {
529 if (cpu_model0[i] != ' ')
530 break;
531 cpu_model0[i] = '\0';
533 cpu_model1[16] = '\0';
534 for (i = 15 ; i >= 0 ; i--) {
535 if (cpu_model1[i] != ' ')
536 break;
537 cpu_model1[i] = '\0';
539 cpu_ver[8] = '\0';
540 for (i = 7 ; i >= 0 ; i--) {
541 if (cpu_ver[i] != ' ')
542 break;
543 cpu_ver[i] = '\0';
546 printk(KERN_INFO "M32R-mp information\n");
547 printk(KERN_INFO " On-chip CPUs : %d\n", nr_cpu);
548 printk(KERN_INFO " CPU model : %s/%s(%s)\n", cpu_model0,
549 cpu_model1, cpu_ver);
553 * The bootstrap kernel entry code has set these up. Save them for
554 * a given CPU
556 static void __init smp_store_cpu_info(int cpu_id)
558 struct cpuinfo_m32r *ci = cpu_data + cpu_id;
560 *ci = boot_cpu_data;
561 ci->loops_per_jiffy = loops_per_jiffy;
564 static void __init show_cpu_info(int cpu_id)
566 struct cpuinfo_m32r *ci = &cpu_data[cpu_id];
568 printk("CPU#%d : ", cpu_id);
570 #define PRINT_CLOCK(name, value) \
571 printk(name " clock %d.%02dMHz", \
572 ((value) / 1000000), ((value) % 1000000) / 10000)
574 PRINT_CLOCK("CPU", (int)ci->cpu_clock);
575 PRINT_CLOCK(", Bus", (int)ci->bus_clock);
576 printk(", loops_per_jiffy[%ld]\n", ci->loops_per_jiffy);
580 * the frequency of the profiling timer can be changed
581 * by writing a multiplier value into /proc/profile.
583 int setup_profiling_timer(unsigned int multiplier)
585 int i;
588 * Sanity check. [at least 500 APIC cycles should be
589 * between APIC interrupts as a rule of thumb, to avoid
590 * irqs flooding us]
592 if ( (!multiplier) || (calibration_result / multiplier < 500))
593 return -EINVAL;
596 * Set the new multiplier for each CPU. CPUs don't start using the
597 * new values until the next timer interrupt in which they do process
598 * accounting. At that time they also adjust their APIC timers
599 * accordingly.
601 for (i = 0; i < NR_CPUS; ++i)
602 per_cpu(prof_multiplier, i) = multiplier;
604 return 0;
607 /* Initialize all maps between cpu number and apicids */
608 static void __init init_cpu_to_physid(void)
610 int i;
612 for (i = 0 ; i < NR_CPUS ; i++) {
613 cpu_2_physid[i] = -1;
614 physid_2_cpu[i] = -1;
619 * set up a mapping between cpu and apicid. Uses logical apicids for multiquad,
620 * else physical apic ids
622 static void __init map_cpu_to_physid(int cpu_id, int phys_id)
624 physid_2_cpu[phys_id] = cpu_id;
625 cpu_2_physid[cpu_id] = phys_id;
629 * undo a mapping between cpu and apicid. Uses logical apicids for multiquad,
630 * else physical apic ids
632 static void __init unmap_cpu_to_physid(int cpu_id, int phys_id)
634 physid_2_cpu[phys_id] = -1;
635 cpu_2_physid[cpu_id] = -1;