ia64/xen-unstable

view xen/arch/ia64/linux-xen/smpboot.c @ 18759:57c94bdbd6b3

[IA64] fix {un}lock_ipi_calllock().

Now _raw_spin_lock() checks whether interrupt is masked or not.
If masked, it panics.
lock_ipi_calllock() violates the assumption.
This patch make lock_ipi_calllock() use spin_lock_irqsave()
instead of spin_lock_irq().

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Tue Nov 04 14:35:24 2008 +0900 (2008-11-04)
parents bfddf170cef9
children 5599cc1e0a84
line source
1 /*
2 * SMP boot-related support
3 *
4 * Copyright (C) 1998-2003, 2005 Hewlett-Packard Co
5 * David Mosberger-Tang <davidm@hpl.hp.com>
6 * Copyright (C) 2001, 2004-2005 Intel Corp
7 * Rohit Seth <rohit.seth@intel.com>
8 * Suresh Siddha <suresh.b.siddha@intel.com>
9 * Gordon Jin <gordon.jin@intel.com>
10 * Ashok Raj <ashok.raj@intel.com>
11 *
12 * 01/05/16 Rohit Seth <rohit.seth@intel.com> Moved SMP booting functions from smp.c to here.
13 * 01/04/27 David Mosberger <davidm@hpl.hp.com> Added ITC synching code.
14 * 02/07/31 David Mosberger <davidm@hpl.hp.com> Switch over to hotplug-CPU boot-sequence.
15 * smp_boot_cpus()/smp_commence() is replaced by
16 * smp_prepare_cpus()/__cpu_up()/smp_cpus_done().
17 * 04/06/21 Ashok Raj <ashok.raj@intel.com> Added CPU Hotplug Support
18 * 04/12/26 Jin Gordon <gordon.jin@intel.com>
19 * 04/12/26 Rohit Seth <rohit.seth@intel.com>
20 * Add multi-threading and multi-core detection
21 * 05/01/30 Suresh Siddha <suresh.b.siddha@intel.com>
22 * Setup cpu_sibling_map and cpu_core_map
23 */
24 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/acpi.h>
28 #include <linux/bootmem.h>
29 #include <linux/cpu.h>
30 #include <linux/delay.h>
31 #include <linux/init.h>
32 #include <linux/interrupt.h>
33 #include <linux/irq.h>
34 #include <linux/kernel.h>
35 #include <linux/kernel_stat.h>
36 #include <linux/mm.h>
37 #include <linux/notifier.h> /* hg add me */
38 #include <linux/smp.h>
39 #include <linux/smp_lock.h>
40 #include <linux/spinlock.h>
41 #include <linux/efi.h>
42 #include <linux/percpu.h>
43 #include <linux/bitops.h>
45 #include <asm/atomic.h>
46 #include <asm/cache.h>
47 #include <asm/current.h>
48 #include <asm/delay.h>
49 #include <asm/ia32.h>
50 #include <asm/io.h>
51 #include <asm/irq.h>
52 #include <asm/machvec.h>
53 #include <asm/mca.h>
54 #include <asm/page.h>
55 #include <asm/pgalloc.h>
56 #include <asm/pgtable.h>
57 #include <asm/processor.h>
58 #include <asm/ptrace.h>
59 #include <asm/sal.h>
60 #include <asm/system.h>
61 #include <asm/tlbflush.h>
62 #include <asm/unistd.h>
64 #ifdef XEN
65 #include <xen/domain.h>
66 #include <asm/hw_irq.h>
67 #include <asm/vmx.h>
68 #ifndef CONFIG_SMP
69 cpumask_t cpu_online_map = CPU_MASK_CPU0;
70 EXPORT_SYMBOL(cpu_online_map);
71 #endif
72 #endif
74 #ifdef CONFIG_SMP /* ifdef XEN */
76 #define SMP_DEBUG 0
78 #if SMP_DEBUG
79 #define Dprintk(x...) printk(x)
80 #else
81 #define Dprintk(x...)
82 #endif
84 #ifdef CONFIG_HOTPLUG_CPU
85 /*
86 * Store all idle threads, this can be reused instead of creating
87 * a new thread. Also avoids complicated thread destroy functionality
88 * for idle threads.
89 */
90 struct task_struct *idle_thread_array[NR_CPUS];
92 /*
93 * Global array allocated for NR_CPUS at boot time
94 */
95 struct sal_to_os_boot sal_boot_rendez_state[NR_CPUS];
97 /*
98 * start_ap in head.S uses this to store current booting cpu
99 * info.
100 */
101 struct sal_to_os_boot *sal_state_for_booting_cpu = &sal_boot_rendez_state[0];
103 #define set_brendez_area(x) (sal_state_for_booting_cpu = &sal_boot_rendez_state[(x)]);
105 #define get_idle_for_cpu(x) (idle_thread_array[(x)])
106 #define set_idle_for_cpu(x,p) (idle_thread_array[(x)] = (p))
108 #else
110 #define get_idle_for_cpu(x) (NULL)
111 #define set_idle_for_cpu(x,p)
112 #define set_brendez_area(x)
113 #endif
116 /*
117 * ITC synchronization related stuff:
118 */
119 #define MASTER 0
120 #define SLAVE (SMP_CACHE_BYTES/8)
122 #define NUM_ROUNDS 64 /* magic value */
123 #define NUM_ITERS 5 /* likewise */
125 static DEFINE_SPINLOCK(itc_sync_lock);
126 static volatile unsigned long go[SLAVE + 1];
128 #define DEBUG_ITC_SYNC 0
130 extern void __devinit calibrate_delay (void);
131 extern void start_ap (void);
132 extern unsigned long ia64_iobase;
134 task_t *task_for_booting_cpu;
136 /*
137 * State for each CPU
138 */
139 DEFINE_PER_CPU(int, cpu_state);
141 /* Bitmasks of currently online, and possible CPUs */
142 cpumask_t cpu_online_map;
143 EXPORT_SYMBOL(cpu_online_map);
144 cpumask_t cpu_possible_map;
145 EXPORT_SYMBOL(cpu_possible_map);
147 cpumask_t cpu_core_map[NR_CPUS] __cacheline_aligned;
148 cpumask_t cpu_sibling_map[NR_CPUS] __cacheline_aligned;
149 int smp_num_siblings = 1;
150 int smp_num_cpucores = 1;
152 /* which logical CPU number maps to which CPU (physical APIC ID) */
153 volatile int ia64_cpu_to_sapicid[NR_CPUS];
154 EXPORT_SYMBOL(ia64_cpu_to_sapicid);
156 static volatile cpumask_t cpu_callin_map;
158 struct smp_boot_data smp_boot_data __initdata;
160 unsigned long ap_wakeup_vector = -1; /* External Int use to wakeup APs */
162 char __initdata no_int_routing;
164 unsigned char smp_int_redirect; /* are INT and IPI redirectable by the chipset? */
166 static int __init
167 nointroute (char *str)
168 {
169 no_int_routing = 1;
170 printk ("no_int_routing on\n");
171 return 1;
172 }
174 __setup("nointroute", nointroute);
176 static void fix_b0_for_bsp(void)
177 {
178 #ifdef CONFIG_HOTPLUG_CPU
179 int cpuid;
180 static int fix_bsp_b0 = 1;
182 cpuid = smp_processor_id();
184 /*
185 * Cache the b0 value on the first AP that comes up
186 */
187 if (!(fix_bsp_b0 && cpuid))
188 return;
190 sal_boot_rendez_state[0].br[0] = sal_boot_rendez_state[cpuid].br[0];
191 printk ("Fixed BSP b0 value from CPU %d\n", cpuid);
193 fix_bsp_b0 = 0;
194 #endif
195 }
197 void
198 sync_master (void *arg)
199 {
200 unsigned long flags, i;
202 go[MASTER] = 0;
204 local_irq_save(flags);
205 {
206 for (i = 0; i < NUM_ROUNDS*NUM_ITERS; ++i) {
207 while (!go[MASTER])
208 cpu_relax();
209 go[MASTER] = 0;
210 go[SLAVE] = ia64_get_itc();
211 }
212 }
213 local_irq_restore(flags);
214 }
216 /*
217 * Return the number of cycles by which our itc differs from the itc on the master
218 * (time-keeper) CPU. A positive number indicates our itc is ahead of the master,
219 * negative that it is behind.
220 */
221 static inline long
222 #ifdef XEN /* warning cleanup */
223 get_delta (unsigned long *rt, unsigned long *master)
224 #else
225 get_delta (long *rt, long *master)
226 #endif
227 {
228 unsigned long best_t0 = 0, best_t1 = ~0UL, best_tm = 0;
229 unsigned long tcenter, t0, t1, tm;
230 long i;
232 for (i = 0; i < NUM_ITERS; ++i) {
233 t0 = ia64_get_itc();
234 go[MASTER] = 1;
235 while (!(tm = go[SLAVE]))
236 cpu_relax();
237 go[SLAVE] = 0;
238 t1 = ia64_get_itc();
240 if (t1 - t0 < best_t1 - best_t0)
241 best_t0 = t0, best_t1 = t1, best_tm = tm;
242 }
244 *rt = best_t1 - best_t0;
245 *master = best_tm - best_t0;
247 /* average best_t0 and best_t1 without overflow: */
248 tcenter = (best_t0/2 + best_t1/2);
249 if (best_t0 % 2 + best_t1 % 2 == 2)
250 ++tcenter;
251 return tcenter - best_tm;
252 }
254 /*
255 * Synchronize ar.itc of the current (slave) CPU with the ar.itc of the MASTER CPU
256 * (normally the time-keeper CPU). We use a closed loop to eliminate the possibility of
257 * unaccounted-for errors (such as getting a machine check in the middle of a calibration
258 * step). The basic idea is for the slave to ask the master what itc value it has and to
259 * read its own itc before and after the master responds. Each iteration gives us three
260 * timestamps:
261 *
262 * slave master
263 *
264 * t0 ---\
265 * ---\
266 * --->
267 * tm
268 * /---
269 * /---
270 * t1 <---
271 *
272 *
273 * The goal is to adjust the slave's ar.itc such that tm falls exactly half-way between t0
274 * and t1. If we achieve this, the clocks are synchronized provided the interconnect
275 * between the slave and the master is symmetric. Even if the interconnect were
276 * asymmetric, we would still know that the synchronization error is smaller than the
277 * roundtrip latency (t0 - t1).
278 *
279 * When the interconnect is quiet and symmetric, this lets us synchronize the itc to
280 * within one or two cycles. However, we can only *guarantee* that the synchronization is
281 * accurate to within a round-trip time, which is typically in the range of several
282 * hundred cycles (e.g., ~500 cycles). In practice, this means that the itc's are usually
283 * almost perfectly synchronized, but we shouldn't assume that the accuracy is much better
284 * than half a micro second or so.
285 */
286 void
287 ia64_sync_itc (unsigned int master)
288 {
289 long i, delta, adj, adjust_latency = 0, done = 0;
290 unsigned long flags, rt, master_time_stamp, bound;
291 #if DEBUG_ITC_SYNC
292 struct {
293 long rt; /* roundtrip time */
294 long master; /* master's timestamp */
295 long diff; /* difference between midpoint and master's timestamp */
296 long lat; /* estimate of itc adjustment latency */
297 } t[NUM_ROUNDS];
298 #endif
300 /*
301 * Make sure local timer ticks are disabled while we sync. If
302 * they were enabled, we'd have to worry about nasty issues
303 * like setting the ITC ahead of (or a long time before) the
304 * next scheduled tick.
305 */
306 BUG_ON((ia64_get_itv() & (1 << 16)) == 0);
308 go[MASTER] = 1;
310 if (smp_call_function_single(master, sync_master, NULL, 1, 0) < 0) {
311 printk(KERN_ERR "sync_itc: failed to get attention of CPU %u!\n", master);
312 return;
313 }
315 while (go[MASTER])
316 cpu_relax(); /* wait for master to be ready */
318 spin_lock_irqsave(&itc_sync_lock, flags);
319 {
320 for (i = 0; i < NUM_ROUNDS; ++i) {
321 delta = get_delta(&rt, &master_time_stamp);
322 if (delta == 0) {
323 done = 1; /* let's lock on to this... */
324 bound = rt;
325 }
327 if (!done) {
328 if (i > 0) {
329 adjust_latency += -delta;
330 adj = -delta + adjust_latency/4;
331 } else
332 adj = -delta;
334 ia64_set_itc(ia64_get_itc() + adj);
335 }
336 #if DEBUG_ITC_SYNC
337 t[i].rt = rt;
338 t[i].master = master_time_stamp;
339 t[i].diff = delta;
340 t[i].lat = adjust_latency/4;
341 #endif
342 }
343 }
344 spin_unlock_irqrestore(&itc_sync_lock, flags);
346 #if DEBUG_ITC_SYNC
347 for (i = 0; i < NUM_ROUNDS; ++i)
348 printk("rt=%5ld master=%5ld diff=%5ld adjlat=%5ld\n",
349 t[i].rt, t[i].master, t[i].diff, t[i].lat);
350 #endif
352 printk(KERN_INFO "CPU %d: synchronized ITC with CPU %u (last diff %ld cycles, "
353 "maxerr %lu cycles)\n", smp_processor_id(), master, delta, rt);
354 }
356 /*
357 * Ideally sets up per-cpu profiling hooks. Doesn't do much now...
358 */
359 static inline void __devinit
360 smp_setup_percpu_timer (void)
361 {
362 }
364 static void __devinit
365 smp_callin (void)
366 {
367 #ifdef XEN
368 /* work around for spinlock irq assert. */
369 unsigned long flags;
370 #endif
371 int cpuid, phys_id;
372 extern void ia64_init_itm(void);
374 #ifdef CONFIG_PERFMON
375 extern void pfm_init_percpu(void);
376 #endif
378 cpuid = smp_processor_id();
379 phys_id = hard_smp_processor_id();
381 if (cpu_online(cpuid)) {
382 printk(KERN_ERR "huh, phys CPU#0x%x, CPU#0x%x already present??\n",
383 phys_id, cpuid);
384 BUG();
385 }
387 fix_b0_for_bsp();
389 #ifdef XEN
390 lock_ipi_calllock(&flags);
391 #else
392 lock_ipi_calllock();
393 #endif
394 cpu_set(cpuid, cpu_online_map);
395 #ifdef XEN
396 unlock_ipi_calllock(flags);
397 #else
398 unlock_ipi_calllock();
399 #endif
400 per_cpu(cpu_state, cpuid) = CPU_ONLINE;
402 smp_setup_percpu_timer();
404 ia64_mca_cmc_vector_setup(); /* Setup vector on AP */
406 #ifdef CONFIG_PERFMON
407 pfm_init_percpu();
408 #endif
410 local_irq_enable();
412 if (!(sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)) {
413 /*
414 * Synchronize the ITC with the BP. Need to do this after irqs are
415 * enabled because ia64_sync_itc() calls smp_call_function_single(), which
416 * calls spin_unlock_bh(), which calls spin_unlock_bh(), which calls
417 * local_bh_enable(), which bugs out if irqs are not enabled...
418 */
419 Dprintk("Going to syncup ITC with BP.\n");
420 ia64_sync_itc(0);
421 }
423 /*
424 * Get our bogomips.
425 */
426 ia64_init_itm();
427 #ifndef XEN
428 calibrate_delay();
429 #endif
430 local_cpu_data->loops_per_jiffy = loops_per_jiffy;
432 #ifdef CONFIG_IA32_SUPPORT
433 ia32_gdt_init();
434 #endif
436 /*
437 * Allow the master to continue.
438 */
439 cpu_set(cpuid, cpu_callin_map);
440 Dprintk("Stack on CPU %d at about %p\n",cpuid, &cpuid);
441 }
444 /*
445 * Activate a secondary processor. head.S calls this.
446 */
447 int __devinit
448 start_secondary (void *unused)
449 {
450 /* Early console may use I/O ports */
451 ia64_set_kr(IA64_KR_IO_BASE, __pa(ia64_iobase));
452 Dprintk("start_secondary: starting CPU 0x%x\n", hard_smp_processor_id());
453 #ifndef XEN
454 efi_map_pal_code();
455 #endif
456 cpu_init();
457 smp_callin();
459 #ifdef XEN
460 if (vmx_enabled)
461 vmx_init_env(0, 0);
463 startup_cpu_idle_loop();
464 #else
465 cpu_idle();
466 #endif
467 return 0;
468 }
470 struct pt_regs * __devinit idle_regs(struct pt_regs *regs)
471 {
472 return NULL;
473 }
475 #ifndef XEN
476 struct create_idle {
477 struct task_struct *idle;
478 struct completion done;
479 int cpu;
480 };
482 void
483 do_fork_idle(void *_c_idle)
484 {
485 struct create_idle *c_idle = _c_idle;
487 c_idle->idle = fork_idle(c_idle->cpu);
488 complete(&c_idle->done);
489 }
490 #endif
492 static int __devinit
493 do_boot_cpu (int sapicid, int cpu)
494 {
495 int timeout;
496 #ifndef XEN
497 struct create_idle c_idle = {
498 .cpu = cpu,
499 .done = COMPLETION_INITIALIZER(c_idle.done),
500 };
501 DECLARE_WORK(work, do_fork_idle, &c_idle);
503 c_idle.idle = get_idle_for_cpu(cpu);
504 if (c_idle.idle) {
505 init_idle(c_idle.idle, cpu);
506 goto do_rest;
507 }
509 /*
510 * We can't use kernel_thread since we must avoid to reschedule the child.
511 */
512 if (!keventd_up() || current_is_keventd())
513 work.func(work.data);
514 else {
515 schedule_work(&work);
516 wait_for_completion(&c_idle.done);
517 }
519 if (IS_ERR(c_idle.idle))
520 panic("failed fork for CPU %d", cpu);
522 set_idle_for_cpu(cpu, c_idle.idle);
524 do_rest:
525 task_for_booting_cpu = c_idle.idle;
526 #else
527 struct vcpu *v;
529 v = alloc_idle_vcpu(cpu);
530 BUG_ON(v == NULL);
532 //printf ("do_boot_cpu: cpu=%d, domain=%p, vcpu=%p\n", cpu, idle, v);
534 task_for_booting_cpu = (task_t *)v;
536 /* Set cpu number. */
537 get_thread_info(v)->cpu = cpu;
538 #endif
540 Dprintk("Sending wakeup vector %lu to AP 0x%x/0x%x.\n", ap_wakeup_vector, cpu, sapicid);
542 set_brendez_area(cpu);
543 platform_send_ipi(cpu, ap_wakeup_vector, IA64_IPI_DM_INT, 0);
545 /*
546 * Wait 10s total for the AP to start
547 */
548 Dprintk("Waiting on callin_map ...");
549 for (timeout = 0; timeout < 100000; timeout++) {
550 if (cpu_isset(cpu, cpu_callin_map))
551 break; /* It has booted */
552 udelay(100);
553 }
554 Dprintk("\n");
556 if (!cpu_isset(cpu, cpu_callin_map)) {
557 printk(KERN_ERR "Processor 0x%x/0x%x is stuck.\n", cpu, sapicid);
558 ia64_cpu_to_sapicid[cpu] = -1;
559 cpu_clear(cpu, cpu_online_map); /* was set in smp_callin() */
560 return -EINVAL;
561 }
562 return 0;
563 }
565 #ifndef XEN
566 static int __init
567 decay (char *str)
568 {
569 int ticks;
570 get_option (&str, &ticks);
571 return 1;
572 }
574 __setup("decay=", decay);
575 #endif
577 /*
578 * Initialize the logical CPU number to SAPICID mapping
579 */
580 void __init
581 smp_build_cpu_map (void)
582 {
583 int sapicid, cpu, i;
584 int boot_cpu_id = hard_smp_processor_id();
586 for (cpu = 0; cpu < NR_CPUS; cpu++) {
587 ia64_cpu_to_sapicid[cpu] = -1;
588 #ifndef XEN
589 #ifdef CONFIG_HOTPLUG_CPU
590 cpu_set(cpu, cpu_possible_map);
591 #endif
592 #endif
593 }
595 ia64_cpu_to_sapicid[0] = boot_cpu_id;
596 cpus_clear(cpu_present_map);
597 cpu_set(0, cpu_present_map);
598 cpu_set(0, cpu_possible_map);
599 for (cpu = 1, i = 0; i < smp_boot_data.cpu_count; i++) {
600 sapicid = smp_boot_data.cpu_phys_id[i];
601 if (sapicid == boot_cpu_id)
602 continue;
603 cpu_set(cpu, cpu_present_map);
604 cpu_set(cpu, cpu_possible_map);
605 ia64_cpu_to_sapicid[cpu] = sapicid;
606 cpu++;
607 }
608 }
610 /*
611 * Cycle through the APs sending Wakeup IPIs to boot each.
612 */
613 void __init
614 smp_prepare_cpus (unsigned int max_cpus)
615 {
616 int boot_cpu_id = hard_smp_processor_id();
618 /*
619 * Initialize the per-CPU profiling counter/multiplier
620 */
622 smp_setup_percpu_timer();
624 /*
625 * We have the boot CPU online for sure.
626 */
627 cpu_set(0, cpu_online_map);
628 cpu_set(0, cpu_callin_map);
630 local_cpu_data->loops_per_jiffy = loops_per_jiffy;
631 ia64_cpu_to_sapicid[0] = boot_cpu_id;
633 printk(KERN_INFO "Boot processor id 0x%x/0x%x\n", 0, boot_cpu_id);
635 current_thread_info()->cpu = 0;
637 /*
638 * If SMP should be disabled, then really disable it!
639 */
640 if (!max_cpus) {
641 printk(KERN_INFO "SMP mode deactivated.\n");
642 cpus_clear(cpu_online_map);
643 cpus_clear(cpu_present_map);
644 cpus_clear(cpu_possible_map);
645 cpu_set(0, cpu_online_map);
646 cpu_set(0, cpu_present_map);
647 cpu_set(0, cpu_possible_map);
648 return;
649 }
650 }
652 void __devinit smp_prepare_boot_cpu(void)
653 {
654 cpu_set(smp_processor_id(), cpu_online_map);
655 cpu_set(smp_processor_id(), cpu_callin_map);
656 per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
657 }
659 /*
660 * mt_info[] is a temporary store for all info returned by
661 * PAL_LOGICAL_TO_PHYSICAL, to be copied into cpuinfo_ia64 when the
662 * specific cpu comes.
663 */
664 static struct {
665 __u32 socket_id;
666 __u16 core_id;
667 __u16 thread_id;
668 __u16 proc_fixed_addr;
669 __u8 valid;
670 } mt_info[NR_CPUS] __devinitdata;
672 #if defined(XEN) && !defined(CONFIG_HOTPLUG_CPU)
673 static inline void
674 remove_from_mtinfo(int cpu)
675 {
676 int i;
678 for_each_cpu(i)
679 if (mt_info[i].valid && mt_info[i].socket_id ==
680 cpu_data(cpu)->socket_id)
681 mt_info[i].valid = 0;
682 }
684 static inline void
685 clear_cpu_sibling_map(int cpu)
686 {
687 int i;
689 for_each_cpu_mask(i, cpu_sibling_map[cpu])
690 cpu_clear(cpu, cpu_sibling_map[i]);
691 for_each_cpu_mask(i, cpu_core_map[cpu])
692 cpu_clear(cpu, cpu_core_map[i]);
694 cpus_clear(cpu_sibling_map[cpu]);
695 cpus_clear(cpu_core_map[cpu]);
696 }
698 static void
699 remove_siblinginfo(int cpu)
700 {
701 int last = 0;
703 if (cpu_data(cpu)->threads_per_core == 1 &&
704 cpu_data(cpu)->cores_per_socket == 1) {
705 cpu_clear(cpu, cpu_core_map[cpu]);
706 cpu_clear(cpu, cpu_sibling_map[cpu]);
707 return;
708 }
710 last = (cpus_weight(cpu_core_map[cpu]) == 1 ? 1 : 0);
712 /* remove it from all sibling map's */
713 clear_cpu_sibling_map(cpu);
715 /* if this cpu is the last in the core group, remove all its info
716 * from mt_info structure
717 */
718 if (last)
719 remove_from_mtinfo(cpu);
720 }
722 extern void fixup_irqs(void);
723 /* must be called with cpucontrol mutex held */
724 int __cpu_disable(void)
725 {
726 int cpu = smp_processor_id();
728 /*
729 * dont permit boot processor for now
730 */
731 if (cpu == 0)
732 return -EBUSY;
734 remove_siblinginfo(cpu);
735 cpu_clear(cpu, cpu_online_map);
736 #ifndef XEN
737 fixup_irqs();
738 #endif
739 local_flush_tlb_all();
740 cpu_clear(cpu, cpu_callin_map);
741 return 0;
742 }
743 #else /* !CONFIG_HOTPLUG_CPU */
744 int __cpu_disable(void)
745 {
746 return -ENOSYS;
747 }
748 #endif /* CONFIG_HOTPLUG_CPU */
750 #ifdef CONFIG_HOTPLUG_CPU
751 void __cpu_die(unsigned int cpu)
752 {
753 unsigned int i;
755 for (i = 0; i < 100; i++) {
756 /* They ack this in play_dead by setting CPU_DEAD */
757 if (per_cpu(cpu_state, cpu) == CPU_DEAD)
758 {
759 printk ("CPU %d is now offline\n", cpu);
760 return;
761 }
762 #ifdef XEN
763 udelay(100 * 1000);
764 #else
765 msleep(100);
766 #endif
767 }
768 printk(KERN_ERR "CPU %u didn't die...\n", cpu);
769 }
770 #else /* !CONFIG_HOTPLUG_CPU */
771 void __cpu_die(unsigned int cpu)
772 {
773 /* We said "no" in __cpu_disable */
774 BUG();
775 }
776 #endif /* CONFIG_HOTPLUG_CPU */
778 void
779 smp_cpus_done (unsigned int dummy)
780 {
781 int cpu;
782 unsigned long bogosum = 0;
784 /*
785 * Allow the user to impress friends.
786 */
788 for (cpu = 0; cpu < NR_CPUS; cpu++)
789 if (cpu_online(cpu))
790 bogosum += cpu_data(cpu)->loops_per_jiffy;
792 printk(KERN_INFO "Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
793 (int)num_online_cpus(), bogosum/(500000/HZ), (bogosum/(5000/HZ))%100);
794 }
796 static inline void __devinit
797 set_cpu_sibling_map(int cpu)
798 {
799 int i;
801 for_each_online_cpu(i) {
802 if ((cpu_data(cpu)->socket_id == cpu_data(i)->socket_id)) {
803 cpu_set(i, cpu_core_map[cpu]);
804 cpu_set(cpu, cpu_core_map[i]);
805 if (cpu_data(cpu)->core_id == cpu_data(i)->core_id) {
806 cpu_set(i, cpu_sibling_map[cpu]);
807 cpu_set(cpu, cpu_sibling_map[i]);
808 }
809 }
810 }
811 }
813 int __devinit
814 __cpu_up (unsigned int cpu)
815 {
816 int ret;
817 int sapicid;
819 sapicid = ia64_cpu_to_sapicid[cpu];
820 if (sapicid == -1)
821 return -EINVAL;
823 /*
824 * Already booted cpu? not valid anymore since we dont
825 * do idle loop tightspin anymore.
826 */
827 if (cpu_isset(cpu, cpu_callin_map))
828 return -EINVAL;
830 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
831 /* Processor goes to start_secondary(), sets online flag */
832 ret = do_boot_cpu(sapicid, cpu);
833 if (ret < 0)
834 return ret;
836 if (cpu_data(cpu)->threads_per_core == 1 &&
837 cpu_data(cpu)->cores_per_socket == 1) {
838 cpu_set(cpu, cpu_sibling_map[cpu]);
839 cpu_set(cpu, cpu_core_map[cpu]);
840 return 0;
841 }
843 set_cpu_sibling_map(cpu);
845 return 0;
846 }
848 /*
849 * Assume that CPU's have been discovered by some platform-dependent interface. For
850 * SoftSDV/Lion, that would be ACPI.
851 *
852 * Setup of the IPI irq handler is done in irq.c:init_IRQ_SMP().
853 */
854 void __init
855 init_smp_config(void)
856 {
857 struct fptr {
858 unsigned long fp;
859 unsigned long gp;
860 } *ap_startup;
861 long sal_ret;
863 /* Tell SAL where to drop the AP's. */
864 ap_startup = (struct fptr *) start_ap;
865 sal_ret = ia64_sal_set_vectors(SAL_VECTOR_OS_BOOT_RENDEZ,
866 ia64_tpa(ap_startup->fp), ia64_tpa(ap_startup->gp), 0, 0, 0, 0);
867 if (sal_ret < 0)
868 printk(KERN_ERR "SMP: Can't set SAL AP Boot Rendezvous: %s\n",
869 ia64_sal_strerror(sal_ret));
870 }
872 static inline int __devinit
873 check_for_mtinfo_index(void)
874 {
875 int i;
877 for_each_cpu(i)
878 if (!mt_info[i].valid)
879 return i;
881 return -1;
882 }
884 /*
885 * Search the mt_info to find out if this socket's cid/tid information is
886 * cached or not. If the socket exists, fill in the core_id and thread_id
887 * in cpuinfo
888 */
889 static int __devinit
890 check_for_new_socket(__u16 logical_address, struct cpuinfo_ia64 *c)
891 {
892 int i;
893 __u32 sid = c->socket_id;
895 for_each_cpu(i) {
896 if (mt_info[i].valid && mt_info[i].proc_fixed_addr == logical_address
897 && mt_info[i].socket_id == sid) {
898 c->core_id = mt_info[i].core_id;
899 c->thread_id = mt_info[i].thread_id;
900 return 1; /* not a new socket */
901 }
902 }
903 return 0;
904 }
906 /*
907 * identify_siblings(cpu) gets called from identify_cpu. This populates the
908 * information related to logical execution units in per_cpu_data structure.
909 */
910 void __devinit
911 identify_siblings(struct cpuinfo_ia64 *c)
912 {
913 s64 status;
914 u16 pltid;
915 u64 proc_fixed_addr;
916 int count, i;
917 pal_logical_to_physical_t info;
919 if (smp_num_cpucores == 1 && smp_num_siblings == 1)
920 return;
922 if ((status = ia64_pal_logical_to_phys(0, &info)) != PAL_STATUS_SUCCESS) {
923 printk(KERN_ERR "ia64_pal_logical_to_phys failed with %ld\n",
924 status);
925 return;
926 }
927 if ((status = ia64_sal_physical_id_info(&pltid)) != PAL_STATUS_SUCCESS) {
928 printk(KERN_ERR "ia64_sal_pltid failed with %ld\n", status);
929 return;
930 }
931 if ((status = ia64_pal_fixed_addr(&proc_fixed_addr)) != PAL_STATUS_SUCCESS) {
932 printk(KERN_ERR "ia64_pal_fixed_addr failed with %ld\n", status);
933 return;
934 }
936 c->socket_id = (pltid << 8) | info.overview_ppid;
937 c->cores_per_socket = info.overview_cpp;
938 c->threads_per_core = info.overview_tpc;
939 count = c->num_log = info.overview_num_log;
941 /* If the thread and core id information is already cached, then
942 * we will simply update cpu_info and return. Otherwise, we will
943 * do the PAL calls and cache core and thread id's of all the siblings.
944 */
945 if (check_for_new_socket(proc_fixed_addr, c))
946 return;
948 for (i = 0; i < count; i++) {
949 int index;
951 if (i && (status = ia64_pal_logical_to_phys(i, &info))
952 != PAL_STATUS_SUCCESS) {
953 printk(KERN_ERR "ia64_pal_logical_to_phys failed"
954 " with %ld\n", status);
955 return;
956 }
957 if (info.log2_la == proc_fixed_addr) {
958 c->core_id = info.log1_cid;
959 c->thread_id = info.log1_tid;
960 }
962 index = check_for_mtinfo_index();
963 /* We will not do the mt_info caching optimization in this case.
964 */
965 if (index < 0)
966 continue;
968 mt_info[index].valid = 1;
969 mt_info[index].socket_id = c->socket_id;
970 mt_info[index].core_id = info.log1_cid;
971 mt_info[index].thread_id = info.log1_tid;
972 mt_info[index].proc_fixed_addr = info.log2_la;
973 }
974 }
975 #endif /* CONFIG_SMP ifdef XEN */