1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#include <linux/config.h>
36#include <linux/init.h>
37
38#include <linux/mm.h>
39#include <linux/kernel_stat.h>
40#include <linux/smp_lock.h>
41#include <linux/irq.h>
42#include <linux/bootmem.h>
43
44#include <linux/delay.h>
45#include <linux/mc146818rtc.h>
46#include <asm/mtrr.h>
47#include <asm/pgalloc.h>
48#include <asm/smpboot.h>
49
50
51static int smp_b_stepping;
52
53
54static int max_cpus = -1;
55
56
57int smp_num_cpus = 1;
58
59
60int smp_num_siblings = 1;
61int __initdata phys_proc_id[NR_CPUS];
62
63
64unsigned long cpu_online_map;
65
66static volatile unsigned long cpu_callin_map;
67static volatile unsigned long cpu_callout_map;
68
69
70struct cpuinfo_x86 cpu_data[NR_CPUS] __cacheline_aligned;
71
72
73int smp_threads_ready;
74
75
76
77
78
79
80
81
82
83
84
85
86static int __init nosmp(char *str)
87{
88 max_cpus = 0;
89 return 1;
90}
91
92__setup("nosmp", nosmp);
93
94static int __init maxcpus(char *str)
95{
96 get_option(&str, &max_cpus);
97 return 1;
98}
99
100__setup("maxcpus=", maxcpus);
101
102
103
104
105
106extern unsigned char trampoline_data [];
107extern unsigned char trampoline_end [];
108static unsigned char *trampoline_base;
109
110
111
112
113
114
115
116static unsigned long __init setup_trampoline(void)
117{
118 memcpy(trampoline_base, trampoline_data, trampoline_end - trampoline_data);
119 return virt_to_phys(trampoline_base);
120}
121
122
123
124
125
126void __init smp_alloc_memory(void)
127{
128 trampoline_base = (void *) alloc_bootmem_low_pages(PAGE_SIZE);
129
130
131
132
133 if (__pa(trampoline_base) >= 0x9F000)
134 BUG();
135}
136
137
138
139
140
141
142void __init smp_store_cpu_info(int id)
143{
144 struct cpuinfo_x86 *c = cpu_data + id;
145
146 *c = boot_cpu_data;
147 c->pte_quick = 0;
148 c->pmd_quick = 0;
149 c->pgd_quick = 0;
150 c->pgtable_cache_sz = 0;
151 identify_cpu(c);
152
153
154
155 if (c->x86_vendor == X86_VENDOR_INTEL &&
156 c->x86 == 5 &&
157 c->x86_mask >= 1 && c->x86_mask <= 4 &&
158 c->x86_model <= 3)
159
160
161
162 smp_b_stepping = 1;
163}
164
165
166
167
168
169
170
171
172
173
174
175static atomic_t smp_commenced = ATOMIC_INIT(0);
176
177void __init smp_commence(void)
178{
179
180
181
182 Dprintk("Setting commenced=1, go go go\n");
183
184 wmb();
185 atomic_set(&smp_commenced,1);
186}
187
188
189
190
191
192
193
194
195static atomic_t tsc_start_flag = ATOMIC_INIT(0);
196static atomic_t tsc_count_start = ATOMIC_INIT(0);
197static atomic_t tsc_count_stop = ATOMIC_INIT(0);
198static unsigned long long tsc_values[NR_CPUS];
199
200#define NR_LOOPS 5
201
202extern unsigned long fast_gettimeoffset_quotient;
203
204
205
206
207
208
209
210
211
212
213
214
215
216static unsigned long long __init div64 (unsigned long long a, unsigned long b0)
217{
218 unsigned int a1, a2;
219 unsigned long long res;
220
221 a1 = ((unsigned int*)&a)[0];
222 a2 = ((unsigned int*)&a)[1];
223
224 res = a1/b0 +
225 (unsigned long long)a2 * (unsigned long long)(0xffffffff/b0) +
226 a2 / b0 +
227 (a2 * (0xffffffff % b0)) / b0;
228
229 return res;
230}
231
232static void __init synchronize_tsc_bp (void)
233{
234 int i;
235 unsigned long long t0;
236 unsigned long long sum, avg;
237 long long delta;
238 unsigned long one_usec;
239 int buggy = 0;
240
241 printk("checking TSC synchronization across CPUs: ");
242
243 one_usec = ((1<<30)/fast_gettimeoffset_quotient)*(1<<2);
244
245 atomic_set(&tsc_start_flag, 1);
246 wmb();
247
248
249
250
251
252
253
254
255
256
257
258 for (i = 0; i < NR_LOOPS; i++) {
259
260
261
262 while (atomic_read(&tsc_count_start) != smp_num_cpus-1) mb();
263 atomic_set(&tsc_count_stop, 0);
264 wmb();
265
266
267
268 atomic_inc(&tsc_count_start);
269
270 rdtscll(tsc_values[smp_processor_id()]);
271
272
273
274 if (i == NR_LOOPS-1)
275 write_tsc(0, 0);
276
277
278
279
280 while (atomic_read(&tsc_count_stop) != smp_num_cpus-1) mb();
281 atomic_set(&tsc_count_start, 0);
282 wmb();
283 atomic_inc(&tsc_count_stop);
284 }
285
286 sum = 0;
287 for (i = 0; i < smp_num_cpus; i++) {
288 t0 = tsc_values[i];
289 sum += t0;
290 }
291 avg = div64(sum, smp_num_cpus);
292
293 sum = 0;
294 for (i = 0; i < smp_num_cpus; i++) {
295 delta = tsc_values[i] - avg;
296 if (delta < 0)
297 delta = -delta;
298
299
300
301 if (delta > 2*one_usec) {
302 long realdelta;
303 if (!buggy) {
304 buggy = 1;
305 printk("\n");
306 }
307 realdelta = div64(delta, one_usec);
308 if (tsc_values[i] < avg)
309 realdelta = -realdelta;
310
311 printk("BIOS BUG: CPU#%d improperly initialized, has %ld usecs TSC skew! FIXED.\n",
312 i, realdelta);
313 }
314
315 sum += delta;
316 }
317 if (!buggy)
318 printk("passed.\n");
319}
320
321static void __init synchronize_tsc_ap (void)
322{
323 int i;
324
325
326
327
328
329
330 while (!atomic_read(&tsc_start_flag)) mb();
331
332 for (i = 0; i < NR_LOOPS; i++) {
333 atomic_inc(&tsc_count_start);
334 while (atomic_read(&tsc_count_start) != smp_num_cpus) mb();
335
336 rdtscll(tsc_values[smp_processor_id()]);
337 if (i == NR_LOOPS-1)
338 write_tsc(0, 0);
339
340 atomic_inc(&tsc_count_stop);
341 while (atomic_read(&tsc_count_stop) != smp_num_cpus) mb();
342 }
343}
344#undef NR_LOOPS
345
346extern void calibrate_delay(void);
347
348static atomic_t init_deasserted;
349
350void __init smp_callin(void)
351{
352 int cpuid, phys_id;
353 unsigned long timeout;
354
355
356
357
358
359
360
361 if (!clustered_apic_mode)
362 while (!atomic_read(&init_deasserted));
363
364
365
366
367 phys_id = GET_APIC_ID(apic_read(APIC_ID));
368 cpuid = current->processor;
369 if (test_and_set_bit(cpuid, &cpu_online_map)) {
370 printk("huh, phys CPU#%d, CPU#%d already present??\n",
371 phys_id, cpuid);
372 BUG();
373 }
374 Dprintk("CPU#%d (phys ID: %d) waiting for CALLOUT\n", cpuid, phys_id);
375
376
377
378
379
380
381
382
383
384
385
386
387 timeout = jiffies + 2*HZ;
388 while (time_before(jiffies, timeout)) {
389
390
391
392 if (test_bit(cpuid, &cpu_callout_map))
393 break;
394 rep_nop();
395 }
396
397 if (!time_before(jiffies, timeout)) {
398 printk("BUG: CPU%d started up but did not get a callout!\n",
399 cpuid);
400 BUG();
401 }
402
403
404
405
406
407
408
409
410 Dprintk("CALLIN, before setup_local_APIC().\n");
411
412
413
414
415 if (clustered_apic_mode)
416 clear_local_APIC();
417 setup_local_APIC();
418
419 __sti();
420
421#ifdef CONFIG_MTRR
422
423
424
425 mtrr_init_secondary_cpu ();
426#endif
427
428
429
430 calibrate_delay();
431 Dprintk("Stack at about %p\n",&cpuid);
432
433
434
435
436 smp_store_cpu_info(cpuid);
437
438
439
440
441 set_bit(cpuid, &cpu_callin_map);
442
443
444
445
446 if (cpu_has_tsc)
447 synchronize_tsc_ap();
448}
449
450int cpucount;
451
452extern int cpu_idle(void);
453
454
455
456
457int __init start_secondary(void *unused)
458{
459
460
461
462
463
464 cpu_init();
465 smp_callin();
466 while (!atomic_read(&smp_commenced))
467 rep_nop();
468
469
470
471
472 local_flush_tlb();
473
474 return cpu_idle();
475}
476
477
478
479
480
481
482
483void __init initialize_secondary(void)
484{
485
486
487
488
489
490 asm volatile(
491 "movl %0,%%esp\n\t"
492 "jmp *%1"
493 :
494 :"r" (current->thread.esp),"r" (current->thread.eip));
495}
496
497extern struct {
498 void * esp;
499 unsigned short ss;
500} stack_start;
501
502static int __init fork_by_hand(void)
503{
504 struct pt_regs regs;
505
506
507
508
509 return do_fork(CLONE_VM|CLONE_PID, 0, ®s, 0);
510}
511
512
513volatile int physical_apicid_2_cpu[MAX_APICID];
514
515volatile int cpu_2_physical_apicid[NR_CPUS];
516
517
518volatile int logical_apicid_2_cpu[MAX_APICID];
519
520volatile int cpu_2_logical_apicid[NR_CPUS];
521
522static inline void init_cpu_to_apicid(void)
523
524{
525 int apicid, cpu;
526
527 for (apicid = 0; apicid < MAX_APICID; apicid++) {
528 physical_apicid_2_cpu[apicid] = BAD_APICID;
529 logical_apicid_2_cpu[apicid] = BAD_APICID;
530 }
531 for (cpu = 0; cpu < NR_CPUS; cpu++) {
532 cpu_2_physical_apicid[cpu] = BAD_APICID;
533 cpu_2_logical_apicid[cpu] = BAD_APICID;
534 }
535}
536
537static inline void map_cpu_to_boot_apicid(int cpu, int apicid)
538
539
540
541
542{
543 if (clustered_apic_mode == CLUSTERED_APIC_NUMAQ) {
544 logical_apicid_2_cpu[apicid] = cpu;
545 cpu_2_logical_apicid[cpu] = apicid;
546 } else {
547 physical_apicid_2_cpu[apicid] = cpu;
548 cpu_2_physical_apicid[cpu] = apicid;
549 }
550}
551
552static inline void unmap_cpu_to_boot_apicid(int cpu, int apicid)
553
554
555
556
557{
558 if (clustered_apic_mode == CLUSTERED_APIC_NUMAQ) {
559 logical_apicid_2_cpu[apicid] = BAD_APICID;
560 cpu_2_logical_apicid[cpu] = BAD_APICID;
561 } else {
562 physical_apicid_2_cpu[apicid] = BAD_APICID;
563 cpu_2_physical_apicid[cpu] = BAD_APICID;
564 }
565}
566
567#if APIC_DEBUG
568static inline void inquire_remote_apic(int apicid)
569{
570 int i, regs[] = { APIC_ID >> 4, APIC_LVR >> 4, APIC_SPIV >> 4 };
571 char *names[] = { "ID", "VERSION", "SPIV" };
572 int timeout, status;
573
574 printk("Inquiring remote APIC #%d...\n", apicid);
575
576 for (i = 0; i < sizeof(regs) / sizeof(*regs); i++) {
577 printk("... APIC #%d %s: ", apicid, names[i]);
578
579
580
581
582 apic_wait_icr_idle();
583
584 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(apicid));
585 apic_write_around(APIC_ICR, APIC_DM_REMRD | regs[i]);
586
587 timeout = 0;
588 do {
589 udelay(100);
590 status = apic_read(APIC_ICR) & APIC_ICR_RR_MASK;
591 } while (status == APIC_ICR_RR_INPROG && timeout++ < 1000);
592
593 switch (status) {
594 case APIC_ICR_RR_VALID:
595 status = apic_read(APIC_RRR);
596 printk("%08x\n", status);
597 break;
598 default:
599 printk("failed\n");
600 }
601 }
602}
603#endif
604
605static int wakeup_secondary_via_NMI(int logical_apicid)
606
607
608
609
610
611{
612 unsigned long send_status = 0, accept_status = 0;
613 int timeout, maxlvt;
614
615
616 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(logical_apicid));
617
618
619
620 apic_write_around(APIC_ICR, APIC_DM_NMI | APIC_DEST_LOGICAL);
621
622 Dprintk("Waiting for send to finish...\n");
623 timeout = 0;
624 do {
625 Dprintk("+");
626 udelay(100);
627 send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
628 } while (send_status && (timeout++ < 1000));
629
630
631
632
633 udelay(200);
634
635
636
637 maxlvt = get_maxlvt();
638 if (maxlvt > 3) {
639 apic_read_around(APIC_SPIV);
640 apic_write(APIC_ESR, 0);
641 }
642 accept_status = (apic_read(APIC_ESR) & 0xEF);
643 Dprintk("NMI sent.\n");
644
645 if (send_status)
646 printk("APIC never delivered???\n");
647 if (accept_status)
648 printk("APIC delivery error (%lx).\n", accept_status);
649
650 return (send_status | accept_status);
651}
652
653static int wakeup_secondary_via_INIT(int phys_apicid, unsigned long start_eip)
654{
655 unsigned long send_status = 0, accept_status = 0;
656 int maxlvt, timeout, num_starts, j;
657
658 Dprintk("Asserting INIT.\n");
659
660
661
662
663 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
664
665
666
667
668 apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_INT_ASSERT
669 | APIC_DM_INIT);
670
671 Dprintk("Waiting for send to finish...\n");
672 timeout = 0;
673 do {
674 Dprintk("+");
675 udelay(100);
676 send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
677 } while (send_status && (timeout++ < 1000));
678
679 mdelay(10);
680
681 Dprintk("Deasserting INIT.\n");
682
683
684 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
685
686
687 apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_DM_INIT);
688
689 Dprintk("Waiting for send to finish...\n");
690 timeout = 0;
691 do {
692 Dprintk("+");
693 udelay(100);
694 send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
695 } while (send_status && (timeout++ < 1000));
696
697 atomic_set(&init_deasserted, 1);
698
699
700
701
702
703
704
705 if (APIC_INTEGRATED(apic_version[phys_apicid]))
706 num_starts = 2;
707 else
708 num_starts = 0;
709
710
711
712
713 Dprintk("#startup loops: %d.\n", num_starts);
714
715 maxlvt = get_maxlvt();
716
717 for (j = 1; j <= num_starts; j++) {
718 Dprintk("Sending STARTUP #%d.\n",j);
719 apic_read_around(APIC_SPIV);
720 apic_write(APIC_ESR, 0);
721 apic_read(APIC_ESR);
722 Dprintk("After apic_write.\n");
723
724
725
726
727
728
729 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
730
731
732
733 apic_write_around(APIC_ICR, APIC_DM_STARTUP
734 | (start_eip >> 12));
735
736
737
738
739 udelay(300);
740
741 Dprintk("Startup point 1.\n");
742
743 Dprintk("Waiting for send to finish...\n");
744 timeout = 0;
745 do {
746 Dprintk("+");
747 udelay(100);
748 send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
749 } while (send_status && (timeout++ < 1000));
750
751
752
753
754 udelay(200);
755
756
757
758 if (maxlvt > 3) {
759 apic_read_around(APIC_SPIV);
760 apic_write(APIC_ESR, 0);
761 }
762 accept_status = (apic_read(APIC_ESR) & 0xEF);
763 if (send_status || accept_status)
764 break;
765 }
766 Dprintk("After Startup.\n");
767
768 if (send_status)
769 printk("APIC never delivered???\n");
770 if (accept_status)
771 printk("APIC delivery error (%lx).\n", accept_status);
772
773 return (send_status | accept_status);
774}
775
776extern unsigned long cpu_initialized;
777
778static void __init do_boot_cpu (int apicid)
779
780
781
782
783{
784 struct task_struct *idle;
785 unsigned long boot_error = 0;
786 int timeout, cpu;
787 unsigned long start_eip;
788 unsigned short nmi_high = 0, nmi_low = 0;
789
790 cpu = ++cpucount;
791
792
793
794
795 if (fork_by_hand() < 0)
796 panic("failed fork for CPU %d", cpu);
797
798
799
800
801
802 idle = init_task.prev_task;
803 if (!idle)
804 panic("No idle process for CPU %d", cpu);
805
806 idle->processor = cpu;
807 idle->cpus_runnable = 1 << cpu;
808
809 map_cpu_to_boot_apicid(cpu, apicid);
810
811 idle->thread.eip = (unsigned long) start_secondary;
812
813 del_from_runqueue(idle);
814 unhash_process(idle);
815 init_tasks[cpu] = idle;
816
817
818 start_eip = setup_trampoline();
819
820
821 printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip);
822 stack_start.esp = (void *) (1024 + PAGE_SIZE + (char *)idle);
823
824
825
826
827
828
829 atomic_set(&init_deasserted, 0);
830
831 Dprintk("Setting warm reset code and vector.\n");
832
833 if (clustered_apic_mode == CLUSTERED_APIC_NUMAQ) {
834
835 nmi_high = *((volatile unsigned short *) TRAMPOLINE_HIGH);
836 nmi_low = *((volatile unsigned short *) TRAMPOLINE_LOW);
837 }
838
839 CMOS_WRITE(0xa, 0xf);
840 local_flush_tlb();
841 Dprintk("1.\n");
842 *((volatile unsigned short *) TRAMPOLINE_HIGH) = start_eip >> 4;
843 Dprintk("2.\n");
844 *((volatile unsigned short *) TRAMPOLINE_LOW) = start_eip & 0xf;
845 Dprintk("3.\n");
846
847
848
849
850 if (!clustered_apic_mode && APIC_INTEGRATED(apic_version[apicid])) {
851 apic_read_around(APIC_SPIV);
852 apic_write(APIC_ESR, 0);
853 apic_read(APIC_ESR);
854 }
855
856
857
858
859 boot_error = 0;
860
861
862
863
864
865 if (clustered_apic_mode == CLUSTERED_APIC_NUMAQ)
866 boot_error = wakeup_secondary_via_NMI(apicid);
867 else
868 boot_error = wakeup_secondary_via_INIT(apicid, start_eip);
869
870 if (!boot_error) {
871
872
873
874 Dprintk("Before Callout %d.\n", cpu);
875 set_bit(cpu, &cpu_callout_map);
876 Dprintk("After Callout %d.\n", cpu);
877
878
879
880
881 for (timeout = 0; timeout < 50000; timeout++) {
882 if (test_bit(cpu, &cpu_callin_map))
883 break;
884 udelay(100);
885 }
886
887 if (test_bit(cpu, &cpu_callin_map)) {
888
889 Dprintk("OK.\n");
890 printk("CPU%d: ", cpu);
891 print_cpu_info(&cpu_data[cpu]);
892 Dprintk("CPU has booted.\n");
893 } else {
894 boot_error= 1;
895 if (*((volatile unsigned char *)phys_to_virt(8192))
896 == 0xA5)
897
898 printk("Stuck ??\n");
899 else
900
901 printk("Not responding.\n");
902#if APIC_DEBUG
903 if (!clustered_apic_mode)
904 inquire_remote_apic(apicid);
905#endif
906 }
907 }
908 if (boot_error) {
909
910 unmap_cpu_to_boot_apicid(cpu, apicid);
911 clear_bit(cpu, &cpu_callout_map);
912 clear_bit(cpu, &cpu_initialized);
913 clear_bit(cpu, &cpu_online_map);
914 cpucount--;
915 }
916
917
918 *((volatile unsigned long *)phys_to_virt(8192)) = 0;
919
920 if(clustered_apic_mode == CLUSTERED_APIC_NUMAQ) {
921 printk("Restoring NMI vector\n");
922 *((volatile unsigned short *) TRAMPOLINE_HIGH) = nmi_high;
923 *((volatile unsigned short *) TRAMPOLINE_LOW) = nmi_low;
924 }
925}
926
927cycles_t cacheflush_time;
928
929static void smp_tune_scheduling (void)
930{
931 unsigned long cachesize;
932 unsigned long bandwidth = 350;
933
934
935
936
937
938
939
940
941
942
943
944 if (!cpu_khz) {
945
946
947
948
949 cacheflush_time = 0;
950 return;
951 } else {
952 cachesize = boot_cpu_data.x86_cache_size;
953 if (cachesize == -1) {
954 cachesize = 16;
955 bandwidth = 100;
956 }
957
958 cacheflush_time = (cpu_khz>>10) * (cachesize<<10) / bandwidth;
959 }
960
961 printk("per-CPU timeslice cutoff: %ld.%02ld usecs.\n",
962 (long)cacheflush_time/(cpu_khz/1000),
963 ((long)cacheflush_time*100/(cpu_khz/1000)) % 100);
964}
965
966
967
968
969
970extern int prof_multiplier[NR_CPUS];
971extern int prof_old_multiplier[NR_CPUS];
972extern int prof_counter[NR_CPUS];
973
974static int boot_cpu_logical_apicid;
975
976void *xquad_portio;
977
978int cpu_sibling_map[NR_CPUS] __cacheline_aligned;
979
980void __init smp_boot_cpus(void)
981{
982 int apicid, cpu, bit;
983
984 if ((clustered_apic_mode == CLUSTERED_APIC_NUMAQ) && (numnodes > 1)) {
985 printk("Remapping cross-quad port I/O for %d quads\n",
986 numnodes);
987 printk("xquad_portio vaddr 0x%08lx, len %08lx\n",
988 (u_long) xquad_portio,
989 (u_long) numnodes * XQUAD_PORTIO_LEN);
990 xquad_portio = ioremap (XQUAD_PORTIO_BASE,
991 numnodes * XQUAD_PORTIO_LEN);
992 }
993
994#ifdef CONFIG_MTRR
995
996 mtrr_init_boot_cpu ();
997#endif
998
999
1000
1001
1002
1003 for (cpu = 0; cpu < NR_CPUS; cpu++) {
1004 prof_counter[cpu] = 1;
1005 prof_old_multiplier[cpu] = 1;
1006 prof_multiplier[cpu] = 1;
1007 }
1008
1009 init_cpu_to_apicid();
1010
1011
1012
1013
1014 smp_store_cpu_info(0);
1015 printk("CPU%d: ", 0);
1016 print_cpu_info(&cpu_data[0]);
1017
1018
1019
1020
1021 set_bit(0, &cpu_online_map);
1022 if (clustered_apic_mode == CLUSTERED_APIC_XAPIC)
1023 boot_cpu_logical_apicid = physical_to_logical_apicid(boot_cpu_physical_apicid);
1024 else
1025 boot_cpu_logical_apicid = logical_smp_processor_id();
1026 map_cpu_to_boot_apicid(0, boot_cpu_apicid);
1027
1028 global_irq_holder = 0;
1029 current->processor = 0;
1030 init_idle();
1031 smp_tune_scheduling();
1032
1033
1034
1035
1036
1037 if (!smp_found_config) {
1038 printk(KERN_NOTICE "SMP motherboard not detected.\n");
1039#ifndef CONFIG_VISWS
1040 io_apic_irqs = 0;
1041#endif
1042 cpu_online_map = phys_cpu_present_map = 1;
1043 smp_num_cpus = 1;
1044 if (APIC_init_uniprocessor())
1045 printk(KERN_NOTICE "Local APIC not detected."
1046 " Using dummy APIC emulation.\n");
1047 goto smp_done;
1048 }
1049
1050
1051
1052
1053
1054
1055 if (!clustered_apic_mode &&
1056 !test_bit(boot_cpu_physical_apicid, &phys_cpu_present_map)) {
1057 printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
1058 boot_cpu_physical_apicid);
1059 phys_cpu_present_map |= (1 << hard_smp_processor_id());
1060 }
1061
1062
1063
1064
1065 if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid]) &&
1066 !test_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability)) {
1067 printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
1068 boot_cpu_physical_apicid);
1069 printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
1070#ifndef CONFIG_VISWS
1071 io_apic_irqs = 0;
1072#endif
1073 cpu_online_map = phys_cpu_present_map = 1;
1074 smp_num_cpus = 1;
1075 goto smp_done;
1076 }
1077
1078 verify_local_APIC();
1079
1080
1081
1082
1083 if (!max_cpus) {
1084 smp_found_config = 0;
1085 printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n");
1086#ifndef CONFIG_VISWS
1087 io_apic_irqs = 0;
1088#endif
1089 cpu_online_map = phys_cpu_present_map = 1;
1090 smp_num_cpus = 1;
1091 goto smp_done;
1092 }
1093
1094 connect_bsp_APIC();
1095 setup_local_APIC();
1096
1097 if (GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_physical_apicid)
1098 BUG();
1099
1100
1101
1102
1103
1104
1105
1106
1107 Dprintk("CPU present map: %lx\n", phys_cpu_present_map);
1108
1109 for (bit = 0; bit < NR_CPUS; bit++) {
1110 apicid = cpu_present_to_apicid(bit);
1111
1112
1113
1114 if (apicid == boot_cpu_apicid)
1115 continue;
1116
1117 if (!(phys_cpu_present_map & (1ul << bit)))
1118 continue;
1119 if ((max_cpus >= 0) && (max_cpus <= cpucount+1))
1120 continue;
1121
1122 do_boot_cpu(apicid);
1123
1124
1125
1126
1127 if ((boot_apicid_to_cpu(apicid) == -1) &&
1128 (phys_cpu_present_map & (1ul << bit)))
1129 printk("CPU #%d/0x%02x not responding - cannot use it.\n",
1130 bit, apicid);
1131 }
1132
1133
1134
1135
1136#ifndef CONFIG_VISWS
1137 {
1138
1139
1140
1141 local_flush_tlb();
1142
1143
1144
1145
1146
1147 CMOS_WRITE(0, 0xf);
1148
1149 *((volatile long *) phys_to_virt(0x467)) = 0;
1150 }
1151#endif
1152
1153
1154
1155
1156
1157 Dprintk("Before bogomips.\n");
1158 if (!cpucount) {
1159 printk(KERN_ERR "Error: only one processor found.\n");
1160 } else {
1161 unsigned long bogosum = 0;
1162 for (cpu = 0; cpu < NR_CPUS; cpu++)
1163 if (cpu_online_map & (1<<cpu))
1164 bogosum += cpu_data[cpu].loops_per_jiffy;
1165 printk(KERN_INFO "Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
1166 cpucount+1,
1167 bogosum/(500000/HZ),
1168 (bogosum/(5000/HZ))%100);
1169 Dprintk("Before bogocount - setting activated=1.\n");
1170 }
1171 smp_num_cpus = cpucount + 1;
1172
1173 if (smp_b_stepping)
1174 printk(KERN_WARNING "WARNING: SMP operation may be unreliable with B stepping processors.\n");
1175 Dprintk("Boot done.\n");
1176
1177
1178
1179
1180
1181 if (test_bit(X86_FEATURE_HT, boot_cpu_data.x86_capability)
1182 && smp_num_siblings > 1) {
1183 for (cpu = 0; cpu < NR_CPUS; cpu++)
1184 cpu_sibling_map[cpu] = NO_PROC_ID;
1185
1186 for (cpu = 0; cpu < smp_num_cpus; cpu++) {
1187 int i;
1188
1189 for (i = 0; i < smp_num_cpus; i++) {
1190 if (i == cpu)
1191 continue;
1192 if (phys_proc_id[cpu] == phys_proc_id[i]) {
1193 cpu_sibling_map[cpu] = i;
1194 printk("cpu_sibling_map[%d] = %d\n", cpu, cpu_sibling_map[cpu]);
1195 break;
1196 }
1197 }
1198 if (cpu_sibling_map[cpu] == NO_PROC_ID) {
1199 smp_num_siblings = 1;
1200 printk(KERN_WARNING "WARNING: No sibling found for CPU %d.\n", cpu);
1201 }
1202 }
1203 }
1204
1205#ifndef CONFIG_VISWS
1206
1207
1208
1209
1210 if (!skip_ioapic_setup && nr_ioapics)
1211 setup_IO_APIC();
1212#endif
1213
1214
1215
1216
1217 setup_APIC_clocks();
1218
1219
1220
1221
1222 if (cpu_has_tsc && cpucount)
1223 synchronize_tsc_bp();
1224
1225smp_done:
1226 zap_low_mappings();
1227}
1228