- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / arch / i386 / kernel / smpboot.c
blob540ef9a988eab222664a89fdf4b866e8d3574665
1 /*
2 * x86 SMP booting functions
4 * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
5 * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com>
7 * Much of the core SMP work is based on previous work by Thomas Radke, to
8 * whom a great many thanks are extended.
10 * Thanks to Intel for making available several different Pentium,
11 * Pentium Pro and Pentium-II/Xeon MP machines.
12 * Original development of Linux SMP code supported by Caldera.
14 * This code is released under the GNU public license version 2 or
15 * later.
17 * Fixes
18 * Felix Koop : NR_CPUS used properly
19 * Jose Renau : Handle single CPU case.
20 * Alan Cox : By repeated request 8) - Total BogoMIP report.
21 * Greg Wright : Fix for kernel stacks panic.
22 * Erich Boleyn : MP v1.4 and additional changes.
23 * Matthias Sattler : Changes for 2.1 kernel map.
24 * Michel Lespinasse : Changes for 2.1 kernel map.
25 * Michael Chastain : Change trampoline.S to gnu as.
26 * Alan Cox : Dumb bug: 'B' step PPro's are fine
27 * Ingo Molnar : Added APIC timers, based on code
28 * from Jose Renau
29 * Ingo Molnar : various cleanups and rewrites
30 * Tigran Aivazian : fixed "0.00 in /proc/uptime on SMP" bug.
31 * Maciej W. Rozycki : Bits for genuine 82489DX APICs
34 #include <linux/config.h>
35 #include <linux/init.h>
37 #include <linux/mm.h>
38 #include <linux/kernel_stat.h>
39 #include <linux/smp_lock.h>
40 #include <linux/irq.h>
41 #include <linux/bootmem.h>
43 #include <linux/delay.h>
44 #include <linux/mc146818rtc.h>
45 #include <asm/mtrr.h>
46 #include <asm/pgalloc.h>
48 /* Set if we find a B stepping CPU */
49 static int smp_b_stepping;
51 /* Setup configured maximum number of CPUs to activate */
52 static int max_cpus = -1;
54 /* Total count of live CPUs */
55 int smp_num_cpus = 1;
57 /* Bitmask of currently online CPUs */
58 unsigned long cpu_online_map;
60 /* which CPU (physical APIC ID) maps to which logical CPU number */
61 volatile int x86_apicid_to_cpu[NR_CPUS];
62 /* which logical CPU number maps to which CPU (physical APIC ID) */
63 volatile int x86_cpu_to_apicid[NR_CPUS];
65 static volatile unsigned long cpu_callin_map;
66 static volatile unsigned long cpu_callout_map;
68 /* Per CPU bogomips and other parameters */
69 struct cpuinfo_x86 cpu_data[NR_CPUS];
71 /* Set when the idlers are all forked */
72 int smp_threads_ready;
75 * Setup routine for controlling SMP activation
77 * Command-line option of "nosmp" or "maxcpus=0" will disable SMP
78 * activation entirely (the MPS table probe still happens, though).
80 * Command-line option of "maxcpus=<NUM>", where <NUM> is an integer
81 * greater than 0, limits the maximum number of CPUs activated in
82 * SMP mode to <NUM>.
85 static int __init nosmp(char *str)
87 max_cpus = 0;
88 return 1;
91 __setup("nosmp", nosmp);
93 static int __init maxcpus(char *str)
95 get_option(&str, &max_cpus);
96 return 1;
99 __setup("maxcpus=", maxcpus);
102 * Trampoline 80x86 program as an array.
105 extern unsigned char trampoline_data [];
106 extern unsigned char trampoline_end [];
107 static unsigned char *trampoline_base;
110 * Currently trivial. Write the real->protected mode
111 * bootstrap into the page concerned. The caller
112 * has made sure it's suitably aligned.
115 static unsigned long __init setup_trampoline(void)
117 memcpy(trampoline_base, trampoline_data, trampoline_end - trampoline_data);
118 return virt_to_phys(trampoline_base);
122 * We are called very early to get the low memory for the
123 * SMP bootup trampoline page.
125 void __init smp_alloc_memory(void)
127 trampoline_base = (void *) alloc_bootmem_low_pages(PAGE_SIZE);
129 * Has to be in very low memory so we can execute
130 * real-mode AP code.
132 if (__pa(trampoline_base) >= 0x9F000)
133 BUG();
137 * The bootstrap kernel entry code has set these up. Save them for
138 * a given CPU
141 void __init smp_store_cpu_info(int id)
143 struct cpuinfo_x86 *c = cpu_data + id;
145 *c = boot_cpu_data;
146 c->pte_quick = 0;
147 c->pmd_quick = 0;
148 c->pgd_quick = 0;
149 c->pgtable_cache_sz = 0;
150 identify_cpu(c);
152 * Mask B, Pentium, but not Pentium MMX
154 if (c->x86_vendor == X86_VENDOR_INTEL &&
155 c->x86 == 5 &&
156 c->x86_mask >= 1 && c->x86_mask <= 4 &&
157 c->x86_model <= 3)
159 * Remember we have B step Pentia with bugs
161 smp_b_stepping = 1;
165 * Architecture specific routine called by the kernel just before init is
166 * fired off. This allows the BP to have everything in order [we hope].
167 * At the end of this all the APs will hit the system scheduling and off
168 * we go. Each AP will load the system gdt's and jump through the kernel
169 * init into idle(). At this point the scheduler will one day take over
170 * and give them jobs to do. smp_callin is a standard routine
171 * we use to track CPUs as they power up.
174 static atomic_t smp_commenced = ATOMIC_INIT(0);
176 void __init smp_commence(void)
179 * Lets the callins below out of their loop.
181 Dprintk("Setting commenced=1, go go go\n");
183 wmb();
184 atomic_set(&smp_commenced,1);
188 * TSC synchronization.
190 * We first check wether all CPUs have their TSC's synchronized,
191 * then we print a warning if not, and always resync.
194 static atomic_t tsc_start_flag = ATOMIC_INIT(0);
195 static atomic_t tsc_count_start = ATOMIC_INIT(0);
196 static atomic_t tsc_count_stop = ATOMIC_INIT(0);
197 static unsigned long long tsc_values[NR_CPUS];
199 #define NR_LOOPS 5
201 extern unsigned long fast_gettimeoffset_quotient;
204 * accurate 64-bit/32-bit division, expanded to 32-bit divisions and 64-bit
205 * multiplication. Not terribly optimized but we need it at boot time only
206 * anyway.
208 * result == a / b
209 * == (a1 + a2*(2^32)) / b
210 * == a1/b + a2*(2^32/b)
211 * == a1/b + a2*((2^32-1)/b) + a2/b + (a2*((2^32-1) % b))/b
212 * ^---- (this multiplication can overflow)
215 static unsigned long long div64 (unsigned long long a, unsigned long b0)
217 unsigned int a1, a2;
218 unsigned long long res;
220 a1 = ((unsigned int*)&a)[0];
221 a2 = ((unsigned int*)&a)[1];
223 res = a1/b0 +
224 (unsigned long long)a2 * (unsigned long long)(0xffffffff/b0) +
225 a2 / b0 +
226 (a2 * (0xffffffff % b0)) / b0;
228 return res;
231 static void __init synchronize_tsc_bp (void)
233 int i;
234 unsigned long long t0;
235 unsigned long long sum, avg;
236 long long delta;
237 unsigned long one_usec;
238 int buggy = 0;
240 printk("checking TSC synchronization across CPUs: ");
242 one_usec = ((1<<30)/fast_gettimeoffset_quotient)*(1<<2);
244 atomic_set(&tsc_start_flag, 1);
245 wmb();
248 * We loop a few times to get a primed instruction cache,
249 * then the last pass is more or less synchronized and
250 * the BP and APs set their cycle counters to zero all at
251 * once. This reduces the chance of having random offsets
252 * between the processors, and guarantees that the maximum
253 * delay between the cycle counters is never bigger than
254 * the latency of information-passing (cachelines) between
255 * two CPUs.
257 for (i = 0; i < NR_LOOPS; i++) {
259 * all APs synchronize but they loop on '== num_cpus'
261 while (atomic_read(&tsc_count_start) != smp_num_cpus-1) mb();
262 atomic_set(&tsc_count_stop, 0);
263 wmb();
265 * this lets the APs save their current TSC:
267 atomic_inc(&tsc_count_start);
269 rdtscll(tsc_values[smp_processor_id()]);
271 * We clear the TSC in the last loop:
273 if (i == NR_LOOPS-1)
274 write_tsc(0, 0);
277 * Wait for all APs to leave the synchronization point:
279 while (atomic_read(&tsc_count_stop) != smp_num_cpus-1) mb();
280 atomic_set(&tsc_count_start, 0);
281 wmb();
282 atomic_inc(&tsc_count_stop);
285 sum = 0;
286 for (i = 0; i < smp_num_cpus; i++) {
287 t0 = tsc_values[i];
288 sum += t0;
290 avg = div64(sum, smp_num_cpus);
292 sum = 0;
293 for (i = 0; i < smp_num_cpus; i++) {
294 delta = tsc_values[i] - avg;
295 if (delta < 0)
296 delta = -delta;
298 * We report bigger than 2 microseconds clock differences.
300 if (delta > 2*one_usec) {
301 long realdelta;
302 if (!buggy) {
303 buggy = 1;
304 printk("\n");
306 realdelta = div64(delta, one_usec);
307 if (tsc_values[i] < avg)
308 realdelta = -realdelta;
310 printk("BIOS BUG: CPU#%d improperly initialized, has %ld usecs TSC skew! FIXED.\n",
311 i, realdelta);
314 sum += delta;
316 if (!buggy)
317 printk("passed.\n");
320 static void __init synchronize_tsc_ap (void)
322 int i;
325 * smp_num_cpus is not necessarily known at the time
326 * this gets called, so we first wait for the BP to
327 * finish SMP initialization:
329 while (!atomic_read(&tsc_start_flag)) mb();
331 for (i = 0; i < NR_LOOPS; i++) {
332 atomic_inc(&tsc_count_start);
333 while (atomic_read(&tsc_count_start) != smp_num_cpus) mb();
335 rdtscll(tsc_values[smp_processor_id()]);
336 if (i == NR_LOOPS-1)
337 write_tsc(0, 0);
339 atomic_inc(&tsc_count_stop);
340 while (atomic_read(&tsc_count_stop) != smp_num_cpus) mb();
343 #undef NR_LOOPS
345 extern void calibrate_delay(void);
347 static atomic_t init_deasserted;
349 void __init smp_callin(void)
351 int cpuid, phys_id;
352 unsigned long timeout;
355 * If waken up by an INIT in an 82489DX configuration
356 * we may get here before an INIT-deassert IPI reaches
357 * our local APIC. We have to wait for the IPI or we'll
358 * lock up on an APIC access.
360 while (!atomic_read(&init_deasserted));
363 * (This works even if the APIC is not enabled.)
365 phys_id = GET_APIC_ID(apic_read(APIC_ID));
366 cpuid = current->processor;
367 if (test_and_set_bit(cpuid, &cpu_online_map)) {
368 printk("huh, phys CPU#%d, CPU#%d already present??\n",
369 phys_id, cpuid);
370 BUG();
372 Dprintk("CPU#%d (phys ID: %d) waiting for CALLOUT\n", cpuid, phys_id);
375 * STARTUP IPIs are fragile beasts as they might sometimes
376 * trigger some glue motherboard logic. Complete APIC bus
377 * silence for 1 second, this overestimates the time the
378 * boot CPU is spending to send the up to 2 STARTUP IPIs
379 * by a factor of two. This should be enough.
383 * Waiting 2s total for startup (udelay is not yet working)
385 timeout = jiffies + 2*HZ;
386 while (time_before(jiffies, timeout)) {
388 * Has the boot CPU finished it's STARTUP sequence?
390 if (test_bit(cpuid, &cpu_callout_map))
391 break;
394 if (!time_before(jiffies, timeout)) {
395 printk("BUG: CPU%d started up but did not get a callout!\n",
396 cpuid);
397 BUG();
401 * the boot CPU has finished the init stage and is spinning
402 * on callin_map until we finish. We are free to set up this
403 * CPU, first the APIC. (this is probably redundant on most
404 * boards)
407 Dprintk("CALLIN, before setup_local_APIC().\n");
408 setup_local_APIC();
410 sti();
412 #ifdef CONFIG_MTRR
414 * Must be done before calibration delay is computed
416 mtrr_init_secondary_cpu ();
417 #endif
419 * Get our bogomips.
421 calibrate_delay();
422 Dprintk("Stack at about %p\n",&cpuid);
425 * Save our processor parameters
427 smp_store_cpu_info(cpuid);
430 * Allow the master to continue.
432 set_bit(cpuid, &cpu_callin_map);
435 * Synchronize the TSC with the BP
437 if (cpu_has_tsc)
438 synchronize_tsc_ap();
441 int cpucount;
443 extern int cpu_idle(void);
446 * Activate a secondary processor.
448 int __init start_secondary(void *unused)
451 * Dont put anything before smp_callin(), SMP
452 * booting is too fragile that we want to limit the
453 * things done here to the most necessary things.
455 cpu_init();
456 smp_callin();
457 while (!atomic_read(&smp_commenced))
458 rep_nop();
460 * low-memory mappings have been cleared, flush them from
461 * the local TLBs too.
463 local_flush_tlb();
465 return cpu_idle();
469 * Everything has been set up for the secondary
470 * CPUs - they just need to reload everything
471 * from the task structure
472 * This function must not return.
474 void __init initialize_secondary(void)
477 * We don't actually need to load the full TSS,
478 * basically just the stack pointer and the eip.
481 asm volatile(
482 "movl %0,%%esp\n\t"
483 "jmp *%1"
485 :"r" (current->thread.esp),"r" (current->thread.eip));
488 extern struct {
489 void * esp;
490 unsigned short ss;
491 } stack_start;
493 static int __init fork_by_hand(void)
495 struct pt_regs regs;
497 * don't care about the eip and regs settings since
498 * we'll never reschedule the forked task.
500 return do_fork(CLONE_VM|CLONE_PID, 0, &regs, 0);
503 #if APIC_DEBUG
504 static inline void inquire_remote_apic(int apicid)
506 int i, regs[] = { APIC_ID >> 4, APIC_LVR >> 4, APIC_SPIV >> 4 };
507 char *names[] = { "ID", "VERSION", "SPIV" };
508 int timeout, status;
510 printk("Inquiring remote APIC #%d...\n", apicid);
512 for (i = 0; i < sizeof(regs) / sizeof(*regs); i++) {
513 printk("... APIC #%d %s: ", apicid, names[i]);
516 * Wait for idle.
518 apic_wait_icr_idle();
520 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(apicid));
521 apic_write_around(APIC_ICR, APIC_DM_REMRD | regs[i]);
523 timeout = 0;
524 do {
525 udelay(100);
526 status = apic_read(APIC_ICR) & APIC_ICR_RR_MASK;
527 } while (status == APIC_ICR_RR_INPROG && timeout++ < 1000);
529 switch (status) {
530 case APIC_ICR_RR_VALID:
531 status = apic_read(APIC_RRR);
532 printk("%08x\n", status);
533 break;
534 default:
535 printk("failed\n");
539 #endif
541 static void __init do_boot_cpu (int apicid)
543 struct task_struct *idle;
544 unsigned long send_status, accept_status, boot_status, maxlvt;
545 int timeout, num_starts, j, cpu;
546 unsigned long start_eip;
548 cpu = ++cpucount;
550 * We can't use kernel_thread since we must avoid to
551 * reschedule the child.
553 if (fork_by_hand() < 0)
554 panic("failed fork for CPU %d", cpu);
557 * We remove it from the pidhash and the runqueue
558 * once we got the process:
560 idle = init_task.prev_task;
561 if (!idle)
562 panic("No idle process for CPU %d", cpu);
564 idle->processor = cpu;
565 x86_cpu_to_apicid[cpu] = apicid;
566 x86_apicid_to_cpu[apicid] = cpu;
567 idle->has_cpu = 1; /* we schedule the first task manually */
568 idle->thread.eip = (unsigned long) start_secondary;
570 del_from_runqueue(idle);
571 unhash_process(idle);
572 init_tasks[cpu] = idle;
574 /* start_eip had better be page-aligned! */
575 start_eip = setup_trampoline();
577 /* So we see what's up */
578 printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip);
579 stack_start.esp = (void *) (1024 + PAGE_SIZE + (char *)idle);
582 * This grunge runs the startup process for
583 * the targeted processor.
586 atomic_set(&init_deasserted, 0);
588 Dprintk("Setting warm reset code and vector.\n");
590 CMOS_WRITE(0xa, 0xf);
591 local_flush_tlb();
592 Dprintk("1.\n");
593 *((volatile unsigned short *) phys_to_virt(0x469)) = start_eip >> 4;
594 Dprintk("2.\n");
595 *((volatile unsigned short *) phys_to_virt(0x467)) = start_eip & 0xf;
596 Dprintk("3.\n");
599 * Be paranoid about clearing APIC errors.
601 if (APIC_INTEGRATED(apic_version[apicid])) {
602 apic_read_around(APIC_SPIV);
603 apic_write(APIC_ESR, 0);
604 apic_read(APIC_ESR);
608 * Status is now clean
610 send_status = 0;
611 accept_status = 0;
612 boot_status = 0;
615 * Starting actual IPI sequence...
618 Dprintk("Asserting INIT.\n");
621 * Turn INIT on target chip
623 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(apicid));
626 * Send IPI
628 apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_INT_ASSERT
629 | APIC_DM_INIT);
631 Dprintk("Waiting for send to finish...\n");
632 timeout = 0;
633 do {
634 Dprintk("+");
635 udelay(100);
636 send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
637 } while (send_status && (timeout++ < 1000));
639 mdelay(10);
641 Dprintk("Deasserting INIT.\n");
643 /* Target chip */
644 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(apicid));
646 /* Send IPI */
647 apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_DM_INIT);
649 Dprintk("Waiting for send to finish...\n");
650 timeout = 0;
651 do {
652 Dprintk("+");
653 udelay(100);
654 send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
655 } while (send_status && (timeout++ < 1000));
657 atomic_set(&init_deasserted, 1);
660 * Should we send STARTUP IPIs ?
662 * Determine this based on the APIC version.
663 * If we don't have an integrated APIC, don't
664 * send the STARTUP IPIs.
666 if (APIC_INTEGRATED(apic_version[apicid]))
667 num_starts = 2;
668 else
669 num_starts = 0;
672 * Run STARTUP IPI loop.
674 Dprintk("#startup loops: %d.\n", num_starts);
676 maxlvt = get_maxlvt();
678 for (j = 1; j <= num_starts; j++) {
679 Dprintk("Sending STARTUP #%d.\n",j);
680 apic_read_around(APIC_SPIV);
681 apic_write(APIC_ESR, 0);
682 apic_read(APIC_ESR);
683 Dprintk("After apic_write.\n");
686 * STARTUP IPI
689 /* Target chip */
690 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(apicid));
692 /* Boot on the stack */
693 /* Kick the second */
694 apic_write_around(APIC_ICR, APIC_DM_STARTUP
695 | (start_eip >> 12));
698 * Give the other CPU some time to accept the IPI.
700 udelay(300);
702 Dprintk("Startup point 1.\n");
704 Dprintk("Waiting for send to finish...\n");
705 timeout = 0;
706 do {
707 Dprintk("+");
708 udelay(100);
709 send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
710 } while (send_status && (timeout++ < 1000));
713 * Give the other CPU some time to accept the IPI.
715 udelay(200);
717 * Due to the Pentium erratum 3AP.
719 if (maxlvt > 3) {
720 apic_read_around(APIC_SPIV);
721 apic_write(APIC_ESR, 0);
723 accept_status = (apic_read(APIC_ESR) & 0xEF);
724 if (send_status || accept_status)
725 break;
727 Dprintk("After Startup.\n");
729 if (send_status)
730 printk("APIC never delivered???\n");
731 if (accept_status)
732 printk("APIC delivery error (%lx).\n", accept_status);
734 if (!send_status && !accept_status) {
736 * allow APs to start initializing.
738 Dprintk("Before Callout %d.\n", cpu);
739 set_bit(cpu, &cpu_callout_map);
740 Dprintk("After Callout %d.\n", cpu);
743 * Wait 5s total for a response
745 for (timeout = 0; timeout < 50000; timeout++) {
746 if (test_bit(cpu, &cpu_callin_map))
747 break; /* It has booted */
748 udelay(100);
751 if (test_bit(cpu, &cpu_callin_map)) {
752 /* number CPUs logically, starting from 1 (BSP is 0) */
753 Dprintk("OK.\n");
754 printk("CPU%d: ", cpu);
755 print_cpu_info(&cpu_data[cpu]);
756 Dprintk("CPU has booted.\n");
757 } else {
758 boot_status = 1;
759 if (*((volatile unsigned char *)phys_to_virt(8192))
760 == 0xA5)
761 /* trampoline started but...? */
762 printk("Stuck ??\n");
763 else
764 /* trampoline code not run */
765 printk("Not responding.\n");
766 #if APIC_DEBUG
767 inquire_remote_apic(apicid);
768 #endif
771 if (send_status || accept_status || boot_status) {
772 x86_cpu_to_apicid[cpu] = -1;
773 x86_apicid_to_cpu[apicid] = -1;
774 cpucount--;
777 /* mark "stuck" area as not stuck */
778 *((volatile unsigned long *)phys_to_virt(8192)) = 0;
781 cycles_t cacheflush_time;
782 extern unsigned long cpu_khz;
784 static void smp_tune_scheduling (void)
786 unsigned long cachesize; /* kB */
787 unsigned long bandwidth = 350; /* MB/s */
789 * Rough estimation for SMP scheduling, this is the number of
790 * cycles it takes for a fully memory-limited process to flush
791 * the SMP-local cache.
793 * (For a P5 this pretty much means we will choose another idle
794 * CPU almost always at wakeup time (this is due to the small
795 * L1 cache), on PIIs it's around 50-100 usecs, depending on
796 * the cache size)
799 if (!cpu_khz) {
801 * this basically disables processor-affinity
802 * scheduling on SMP without a TSC.
804 cacheflush_time = 0;
805 return;
806 } else {
807 cachesize = boot_cpu_data.x86_cache_size;
808 if (cachesize == -1) {
809 cachesize = 16; /* Pentiums, 2x8kB cache */
810 bandwidth = 100;
813 cacheflush_time = (cpu_khz>>10) * (cachesize<<10) / bandwidth;
816 printk("per-CPU timeslice cutoff: %ld.%02ld usecs.\n",
817 (long)cacheflush_time/(cpu_khz/1000),
818 ((long)cacheflush_time*100/(cpu_khz/1000)) % 100);
822 * Cycle through the processors sending APIC IPIs to boot each.
825 extern int prof_multiplier[NR_CPUS];
826 extern int prof_old_multiplier[NR_CPUS];
827 extern int prof_counter[NR_CPUS];
829 void __init smp_boot_cpus(void)
831 int apicid, cpu;
833 #ifdef CONFIG_MTRR
834 /* Must be done before other processors booted */
835 mtrr_init_boot_cpu ();
836 #endif
838 * Initialize the logical to physical CPU number mapping
839 * and the per-CPU profiling counter/multiplier
842 for (apicid = 0; apicid < NR_CPUS; apicid++) {
843 x86_apicid_to_cpu[apicid] = -1;
844 prof_counter[apicid] = 1;
845 prof_old_multiplier[apicid] = 1;
846 prof_multiplier[apicid] = 1;
850 * Setup boot CPU information
852 smp_store_cpu_info(0); /* Final full version of the data */
853 printk("CPU%d: ", 0);
854 print_cpu_info(&cpu_data[0]);
857 * We have the boot CPU online for sure.
859 set_bit(0, &cpu_online_map);
860 x86_apicid_to_cpu[boot_cpu_id] = 0;
861 x86_cpu_to_apicid[0] = boot_cpu_id;
862 global_irq_holder = 0;
863 current->processor = 0;
864 init_idle();
865 smp_tune_scheduling();
868 * If we couldnt find an SMP configuration at boot time,
869 * get out of here now!
871 if (!smp_found_config) {
872 printk(KERN_NOTICE "SMP motherboard not detected. Using dummy APIC emulation.\n");
873 #ifndef CONFIG_VISWS
874 io_apic_irqs = 0;
875 #endif
876 cpu_online_map = phys_cpu_present_map = 1;
877 smp_num_cpus = 1;
878 goto smp_done;
882 * Should not be necessary because the MP table should list the boot
883 * CPU too, but we do it for the sake of robustness anyway.
885 if (!test_bit(boot_cpu_id, &phys_cpu_present_map)) {
886 printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
887 boot_cpu_id);
888 phys_cpu_present_map |= (1 << hard_smp_processor_id());
892 * If we couldn't find a local APIC, then get out of here now!
894 if (APIC_INTEGRATED(apic_version[boot_cpu_id]) &&
895 !test_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability)) {
896 printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
897 boot_cpu_id);
898 printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
899 #ifndef CONFIG_VISWS
900 io_apic_irqs = 0;
901 #endif
902 cpu_online_map = phys_cpu_present_map = 1;
903 smp_num_cpus = 1;
904 goto smp_done;
907 verify_local_APIC();
910 * If SMP should be disabled, then really disable it!
912 if (!max_cpus) {
913 smp_found_config = 0;
914 printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n");
915 #ifndef CONFIG_VISWS
916 io_apic_irqs = 0;
917 #endif
918 cpu_online_map = phys_cpu_present_map = 1;
919 smp_num_cpus = 1;
920 goto smp_done;
923 connect_bsp_APIC();
924 setup_local_APIC();
926 if (GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_id)
927 BUG();
930 * Now scan the CPU present map and fire up the other CPUs.
932 Dprintk("CPU present map: %lx\n", phys_cpu_present_map);
934 for (apicid = 0; apicid < NR_CPUS; apicid++) {
936 * Don't even attempt to start the boot CPU!
938 if (apicid == boot_cpu_id)
939 continue;
941 if (!(phys_cpu_present_map & (1 << apicid)))
942 continue;
943 if ((max_cpus >= 0) && (max_cpus <= cpucount+1))
944 continue;
946 do_boot_cpu(apicid);
949 * Make sure we unmap all failed CPUs
951 if ((x86_apicid_to_cpu[apicid] == -1) &&
952 (phys_cpu_present_map & (1 << apicid)))
953 printk("phys CPU #%d not responding - cannot use it.\n",apicid);
957 * Cleanup possible dangling ends...
959 #ifndef CONFIG_VISWS
962 * Install writable page 0 entry to set BIOS data area.
964 local_flush_tlb();
967 * Paranoid: Set warm reset code and vector here back
968 * to default values.
970 CMOS_WRITE(0, 0xf);
972 *((volatile long *) phys_to_virt(0x467)) = 0;
974 #endif
977 * Allow the user to impress friends.
980 Dprintk("Before bogomips.\n");
981 if (!cpucount) {
982 printk(KERN_ERR "Error: only one processor found.\n");
983 } else {
984 unsigned long bogosum = 0;
985 for (cpu = 0; cpu < NR_CPUS; cpu++)
986 if (cpu_online_map & (1<<cpu))
987 bogosum += cpu_data[cpu].loops_per_sec;
988 printk(KERN_INFO "Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
989 cpucount+1,
990 (bogosum+2500)/500000,
991 ((bogosum+2500)/5000)%100);
992 Dprintk("Before bogocount - setting activated=1.\n");
994 smp_num_cpus = cpucount + 1;
996 if (smp_b_stepping)
997 printk(KERN_WARNING "WARNING: SMP operation may be unreliable with B stepping processors.\n");
998 Dprintk("Boot done.\n");
1000 #ifndef CONFIG_VISWS
1002 * Here we can be sure that there is an IO-APIC in the system. Let's
1003 * go and set it up:
1005 if (!skip_ioapic_setup)
1006 setup_IO_APIC();
1007 #endif
1010 * Set up all local APIC timers in the system:
1012 setup_APIC_clocks();
1015 * Synchronize the TSC with the AP
1017 if (cpu_has_tsc && cpucount)
1018 synchronize_tsc_bp();
1020 smp_done:
1021 zap_low_mappings();