x86: apic copy calibrate_APIC_clock to each other in apic_32/64.c
[deliverable/linux.git] / arch / x86 / kernel / apic_32.c
1 /*
2 * Local APIC handling, local APIC timers
3 *
4 * (c) 1999, 2000 Ingo Molnar <mingo@redhat.com>
5 *
6 * Fixes
7 * Maciej W. Rozycki : Bits for genuine 82489DX APICs;
8 * thanks to Eric Gilmore
9 * and Rolf G. Tews
10 * for testing these extensively.
11 * Maciej W. Rozycki : Various updates and fixes.
12 * Mikael Pettersson : Power Management for UP-APIC.
13 * Pavel Machek and
14 * Mikael Pettersson : PM converted to driver model.
15 */
16
17 #include <linux/init.h>
18
19 #include <linux/mm.h>
20 #include <linux/delay.h>
21 #include <linux/bootmem.h>
22 #include <linux/interrupt.h>
23 #include <linux/mc146818rtc.h>
24 #include <linux/kernel_stat.h>
25 #include <linux/sysdev.h>
26 #include <linux/ioport.h>
27 #include <linux/cpu.h>
28 #include <linux/clockchips.h>
29 #include <linux/acpi_pmtmr.h>
30 #include <linux/module.h>
31 #include <linux/dmi.h>
32 #include <linux/dmar.h>
33
34 #include <asm/atomic.h>
35 #include <asm/smp.h>
36 #include <asm/mtrr.h>
37 #include <asm/mpspec.h>
38 #include <asm/desc.h>
39 #include <asm/arch_hooks.h>
40 #include <asm/hpet.h>
41 #include <asm/pgalloc.h>
42 #include <asm/i8253.h>
43 #include <asm/nmi.h>
44 #include <asm/idle.h>
45 #include <asm/proto.h>
46 #include <asm/timex.h>
47 #include <asm/apic.h>
48 #include <asm/i8259.h>
49
50 #include <mach_apic.h>
51 #include <mach_apicdef.h>
52 #include <mach_ipi.h>
53
54 /*
55 * Sanity check
56 */
57 #if ((SPURIOUS_APIC_VECTOR & 0x0F) != 0x0F)
58 # error SPURIOUS_APIC_VECTOR definition error
59 #endif
60
61 #ifdef CONFIG_X86_32
62 /*
63 * Knob to control our willingness to enable the local APIC.
64 *
65 * +1=force-enable
66 */
67 static int force_enable_local_apic;
68 /*
69 * APIC command line parameters
70 */
71 static int __init parse_lapic(char *arg)
72 {
73 force_enable_local_apic = 1;
74 return 0;
75 }
76 early_param("lapic", parse_lapic);
77 /* Local APIC was disabled by the BIOS and enabled by the kernel */
78 static int enabled_via_apicbase;
79
80 #endif
81
82 #ifdef CONFIG_X86_64
83 static int apic_calibrate_pmtmr __initdata;
84 static __init int setup_apicpmtimer(char *s)
85 {
86 apic_calibrate_pmtmr = 1;
87 notsc_setup(NULL);
88 return 0;
89 }
90 __setup("apicpmtimer", setup_apicpmtimer);
91 #endif
92
93 unsigned long mp_lapic_addr;
94 int disable_apic;
95 /* Disable local APIC timer from the kernel commandline or via dmi quirk */
96 static int disable_apic_timer __cpuinitdata;
97 /* Local APIC timer works in C2 */
98 int local_apic_timer_c2_ok;
99 EXPORT_SYMBOL_GPL(local_apic_timer_c2_ok);
100
101 int first_system_vector = 0xfe;
102
103 char system_vectors[NR_VECTORS] = { [0 ... NR_VECTORS-1] = SYS_VECTOR_FREE};
104
105 /*
106 * Debug level, exported for io_apic.c
107 */
108 unsigned int apic_verbosity;
109
110 int pic_mode;
111
112 /* Have we found an MP table */
113 int smp_found_config;
114
115 static struct resource lapic_resource = {
116 .name = "Local APIC",
117 .flags = IORESOURCE_MEM | IORESOURCE_BUSY,
118 };
119
120 static unsigned int calibration_result;
121
122 static int lapic_next_event(unsigned long delta,
123 struct clock_event_device *evt);
124 static void lapic_timer_setup(enum clock_event_mode mode,
125 struct clock_event_device *evt);
126 static void lapic_timer_broadcast(cpumask_t mask);
127 static void apic_pm_activate(void);
128
129 /*
130 * The local apic timer can be used for any function which is CPU local.
131 */
132 static struct clock_event_device lapic_clockevent = {
133 .name = "lapic",
134 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT
135 | CLOCK_EVT_FEAT_C3STOP | CLOCK_EVT_FEAT_DUMMY,
136 .shift = 32,
137 .set_mode = lapic_timer_setup,
138 .set_next_event = lapic_next_event,
139 .broadcast = lapic_timer_broadcast,
140 .rating = 100,
141 .irq = -1,
142 };
143 static DEFINE_PER_CPU(struct clock_event_device, lapic_events);
144
145 static unsigned long apic_phys;
146
147 /*
148 * Get the LAPIC version
149 */
150 static inline int lapic_get_version(void)
151 {
152 return GET_APIC_VERSION(apic_read(APIC_LVR));
153 }
154
155 /*
156 * Check, if the APIC is integrated or a separate chip
157 */
158 static inline int lapic_is_integrated(void)
159 {
160 #ifdef CONFIG_X86_64
161 return 1;
162 #else
163 return APIC_INTEGRATED(lapic_get_version());
164 #endif
165 }
166
167 /*
168 * Check, whether this is a modern or a first generation APIC
169 */
170 static int modern_apic(void)
171 {
172 /* AMD systems use old APIC versions, so check the CPU */
173 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
174 boot_cpu_data.x86 >= 0xf)
175 return 1;
176 return lapic_get_version() >= 0x14;
177 }
178
179 /*
180 * Paravirt kernels also might be using these below ops. So we still
181 * use generic apic_read()/apic_write(), which might be pointing to different
182 * ops in PARAVIRT case.
183 */
184 void xapic_wait_icr_idle(void)
185 {
186 while (apic_read(APIC_ICR) & APIC_ICR_BUSY)
187 cpu_relax();
188 }
189
190 u32 safe_xapic_wait_icr_idle(void)
191 {
192 u32 send_status;
193 int timeout;
194
195 timeout = 0;
196 do {
197 send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
198 if (!send_status)
199 break;
200 udelay(100);
201 } while (timeout++ < 1000);
202
203 return send_status;
204 }
205
206 void xapic_icr_write(u32 low, u32 id)
207 {
208 apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(id));
209 apic_write(APIC_ICR, low);
210 }
211
212 u64 xapic_icr_read(void)
213 {
214 u32 icr1, icr2;
215
216 icr2 = apic_read(APIC_ICR2);
217 icr1 = apic_read(APIC_ICR);
218
219 return icr1 | ((u64)icr2 << 32);
220 }
221
222 static struct apic_ops xapic_ops = {
223 .read = native_apic_mem_read,
224 .write = native_apic_mem_write,
225 .icr_read = xapic_icr_read,
226 .icr_write = xapic_icr_write,
227 .wait_icr_idle = xapic_wait_icr_idle,
228 .safe_wait_icr_idle = safe_xapic_wait_icr_idle,
229 };
230
231 struct apic_ops __read_mostly *apic_ops = &xapic_ops;
232 EXPORT_SYMBOL_GPL(apic_ops);
233
234 /**
235 * enable_NMI_through_LVT0 - enable NMI through local vector table 0
236 */
237 void __cpuinit enable_NMI_through_LVT0(void)
238 {
239 unsigned int v;
240
241 /* unmask and set to NMI */
242 v = APIC_DM_NMI;
243
244 /* Level triggered for 82489DX (32bit mode) */
245 if (!lapic_is_integrated())
246 v |= APIC_LVT_LEVEL_TRIGGER;
247
248 apic_write(APIC_LVT0, v);
249 }
250
251 #ifdef CONFIG_X86_32
252 /**
253 * get_physical_broadcast - Get number of physical broadcast IDs
254 */
255 int get_physical_broadcast(void)
256 {
257 return modern_apic() ? 0xff : 0xf;
258 }
259 #endif
260
261 /**
262 * lapic_get_maxlvt - get the maximum number of local vector table entries
263 */
264 int lapic_get_maxlvt(void)
265 {
266 unsigned int v;
267
268 v = apic_read(APIC_LVR);
269 /*
270 * - we always have APIC integrated on 64bit mode
271 * - 82489DXs do not report # of LVT entries
272 */
273 return APIC_INTEGRATED(GET_APIC_VERSION(v)) ? GET_APIC_MAXLVT(v) : 2;
274 }
275
276 /*
277 * Local APIC timer
278 */
279
280 /* Clock divisor */
281 #ifdef CONFG_X86_64
282 #define APIC_DIVISOR 1
283 #else
284 #define APIC_DIVISOR 16
285 #endif
286
287 /*
288 * This function sets up the local APIC timer, with a timeout of
289 * 'clocks' APIC bus clock. During calibration we actually call
290 * this function twice on the boot CPU, once with a bogus timeout
291 * value, second time for real. The other (noncalibrating) CPUs
292 * call this function only once, with the real, calibrated value.
293 *
294 * We do reads before writes even if unnecessary, to get around the
295 * P5 APIC double write bug.
296 */
297 static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen)
298 {
299 unsigned int lvtt_value, tmp_value;
300
301 lvtt_value = LOCAL_TIMER_VECTOR;
302 if (!oneshot)
303 lvtt_value |= APIC_LVT_TIMER_PERIODIC;
304 if (!lapic_is_integrated())
305 lvtt_value |= SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV);
306
307 if (!irqen)
308 lvtt_value |= APIC_LVT_MASKED;
309
310 apic_write(APIC_LVTT, lvtt_value);
311
312 /*
313 * Divide PICLK by 16
314 */
315 tmp_value = apic_read(APIC_TDCR);
316 apic_write(APIC_TDCR,
317 (tmp_value & ~(APIC_TDR_DIV_1 | APIC_TDR_DIV_TMBASE)) |
318 APIC_TDR_DIV_16);
319
320 if (!oneshot)
321 apic_write(APIC_TMICT, clocks / APIC_DIVISOR);
322 }
323
324 /*
325 * Setup extended LVT, AMD specific (K8, family 10h)
326 *
327 * Vector mappings are hard coded. On K8 only offset 0 (APIC500) and
328 * MCE interrupts are supported. Thus MCE offset must be set to 0.
329 *
330 * If mask=1, the LVT entry does not generate interrupts while mask=0
331 * enables the vector. See also the BKDGs.
332 */
333
334 #define APIC_EILVT_LVTOFF_MCE 0
335 #define APIC_EILVT_LVTOFF_IBS 1
336
337 static void setup_APIC_eilvt(u8 lvt_off, u8 vector, u8 msg_type, u8 mask)
338 {
339 unsigned long reg = (lvt_off << 4) + APIC_EILVT0;
340 unsigned int v = (mask << 16) | (msg_type << 8) | vector;
341
342 apic_write(reg, v);
343 }
344
345 u8 setup_APIC_eilvt_mce(u8 vector, u8 msg_type, u8 mask)
346 {
347 setup_APIC_eilvt(APIC_EILVT_LVTOFF_MCE, vector, msg_type, mask);
348 return APIC_EILVT_LVTOFF_MCE;
349 }
350
351 u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask)
352 {
353 setup_APIC_eilvt(APIC_EILVT_LVTOFF_IBS, vector, msg_type, mask);
354 return APIC_EILVT_LVTOFF_IBS;
355 }
356 EXPORT_SYMBOL_GPL(setup_APIC_eilvt_ibs);
357
358 /*
359 * Program the next event, relative to now
360 */
361 static int lapic_next_event(unsigned long delta,
362 struct clock_event_device *evt)
363 {
364 apic_write(APIC_TMICT, delta);
365 return 0;
366 }
367
368 /*
369 * Setup the lapic timer in periodic or oneshot mode
370 */
371 static void lapic_timer_setup(enum clock_event_mode mode,
372 struct clock_event_device *evt)
373 {
374 unsigned long flags;
375 unsigned int v;
376
377 /* Lapic used as dummy for broadcast ? */
378 if (evt->features & CLOCK_EVT_FEAT_DUMMY)
379 return;
380
381 local_irq_save(flags);
382
383 switch (mode) {
384 case CLOCK_EVT_MODE_PERIODIC:
385 case CLOCK_EVT_MODE_ONESHOT:
386 __setup_APIC_LVTT(calibration_result,
387 mode != CLOCK_EVT_MODE_PERIODIC, 1);
388 break;
389 case CLOCK_EVT_MODE_UNUSED:
390 case CLOCK_EVT_MODE_SHUTDOWN:
391 v = apic_read(APIC_LVTT);
392 v |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR);
393 apic_write(APIC_LVTT, v);
394 break;
395 case CLOCK_EVT_MODE_RESUME:
396 /* Nothing to do here */
397 break;
398 }
399
400 local_irq_restore(flags);
401 }
402
403 /*
404 * Local APIC timer broadcast function
405 */
406 static void lapic_timer_broadcast(cpumask_t mask)
407 {
408 #ifdef CONFIG_SMP
409 send_IPI_mask(mask, LOCAL_TIMER_VECTOR);
410 #endif
411 }
412
413 /*
414 * Setup the local APIC timer for this CPU. Copy the initilized values
415 * of the boot CPU and register the clock event in the framework.
416 */
417 static void __cpuinit setup_APIC_timer(void)
418 {
419 struct clock_event_device *levt = &__get_cpu_var(lapic_events);
420
421 memcpy(levt, &lapic_clockevent, sizeof(*levt));
422 levt->cpumask = cpumask_of_cpu(smp_processor_id());
423
424 clockevents_register_device(levt);
425 }
426
427 #ifdef CONFIG_X86_64
428 /*
429 * In this function we calibrate APIC bus clocks to the external
430 * timer. Unfortunately we cannot use jiffies and the timer irq
431 * to calibrate, since some later bootup code depends on getting
432 * the first irq? Ugh.
433 *
434 * We want to do the calibration only once since we
435 * want to have local timer irqs syncron. CPUs connected
436 * by the same APIC bus have the very same bus frequency.
437 * And we want to have irqs off anyways, no accidental
438 * APIC irq that way.
439 */
440
441 #define TICK_COUNT 100000000
442
443 static int __init calibrate_APIC_clock(void)
444 {
445 unsigned apic, apic_start;
446 unsigned long tsc, tsc_start;
447 int result;
448
449 local_irq_disable();
450
451 /*
452 * Put whatever arbitrary (but long enough) timeout
453 * value into the APIC clock, we just want to get the
454 * counter running for calibration.
455 *
456 * No interrupt enable !
457 */
458 __setup_APIC_LVTT(250000000, 0, 0);
459
460 apic_start = apic_read(APIC_TMCCT);
461 #ifdef CONFIG_X86_PM_TIMER
462 if (apic_calibrate_pmtmr && pmtmr_ioport) {
463 pmtimer_wait(5000); /* 5ms wait */
464 apic = apic_read(APIC_TMCCT);
465 result = (apic_start - apic) * 1000L / 5;
466 } else
467 #endif
468 {
469 rdtscll(tsc_start);
470
471 do {
472 apic = apic_read(APIC_TMCCT);
473 rdtscll(tsc);
474 } while ((tsc - tsc_start) < TICK_COUNT &&
475 (apic_start - apic) < TICK_COUNT);
476
477 result = (apic_start - apic) * 1000L * tsc_khz /
478 (tsc - tsc_start);
479 }
480
481 local_irq_enable();
482
483 printk(KERN_DEBUG "APIC timer calibration result %d\n", result);
484
485 printk(KERN_INFO "Detected %d.%03d MHz APIC timer.\n",
486 result / 1000 / 1000, result / 1000 % 1000);
487
488 /* Calculate the scaled math multiplication factor */
489 lapic_clockevent.mult = div_sc(result, NSEC_PER_SEC,
490 lapic_clockevent.shift);
491 lapic_clockevent.max_delta_ns =
492 clockevent_delta2ns(0x7FFFFF, &lapic_clockevent);
493 lapic_clockevent.min_delta_ns =
494 clockevent_delta2ns(0xF, &lapic_clockevent);
495
496 calibration_result = (result * APIC_DIVISOR) / HZ;
497
498 /*
499 * Do a sanity check on the APIC calibration result
500 */
501 if (calibration_result < (1000000 / HZ)) {
502 printk(KERN_WARNING
503 "APIC frequency too slow, disabling apic timer\n");
504 return -1;
505 }
506
507 return 0;
508 }
509
510 #else
511 /*
512 * In this functions we calibrate APIC bus clocks to the external timer.
513 *
514 * We want to do the calibration only once since we want to have local timer
515 * irqs syncron. CPUs connected by the same APIC bus have the very same bus
516 * frequency.
517 *
518 * This was previously done by reading the PIT/HPET and waiting for a wrap
519 * around to find out, that a tick has elapsed. I have a box, where the PIT
520 * readout is broken, so it never gets out of the wait loop again. This was
521 * also reported by others.
522 *
523 * Monitoring the jiffies value is inaccurate and the clockevents
524 * infrastructure allows us to do a simple substitution of the interrupt
525 * handler.
526 *
527 * The calibration routine also uses the pm_timer when possible, as the PIT
528 * happens to run way too slow (factor 2.3 on my VAIO CoreDuo, which goes
529 * back to normal later in the boot process).
530 */
531
532 #define LAPIC_CAL_LOOPS (HZ/10)
533
534 static __initdata int lapic_cal_loops = -1;
535 static __initdata long lapic_cal_t1, lapic_cal_t2;
536 static __initdata unsigned long long lapic_cal_tsc1, lapic_cal_tsc2;
537 static __initdata unsigned long lapic_cal_pm1, lapic_cal_pm2;
538 static __initdata unsigned long lapic_cal_j1, lapic_cal_j2;
539
540 /*
541 * Temporary interrupt handler.
542 */
543 static void __init lapic_cal_handler(struct clock_event_device *dev)
544 {
545 unsigned long long tsc = 0;
546 long tapic = apic_read(APIC_TMCCT);
547 unsigned long pm = acpi_pm_read_early();
548
549 if (cpu_has_tsc)
550 rdtscll(tsc);
551
552 switch (lapic_cal_loops++) {
553 case 0:
554 lapic_cal_t1 = tapic;
555 lapic_cal_tsc1 = tsc;
556 lapic_cal_pm1 = pm;
557 lapic_cal_j1 = jiffies;
558 break;
559
560 case LAPIC_CAL_LOOPS:
561 lapic_cal_t2 = tapic;
562 lapic_cal_tsc2 = tsc;
563 if (pm < lapic_cal_pm1)
564 pm += ACPI_PM_OVRRUN;
565 lapic_cal_pm2 = pm;
566 lapic_cal_j2 = jiffies;
567 break;
568 }
569 }
570
571 static int __init calibrate_APIC_clock(void)
572 {
573 struct clock_event_device *levt = &__get_cpu_var(lapic_events);
574 const long pm_100ms = PMTMR_TICKS_PER_SEC/10;
575 const long pm_thresh = pm_100ms/100;
576 void (*real_handler)(struct clock_event_device *dev);
577 unsigned long deltaj;
578 long delta, deltapm;
579 int pm_referenced = 0;
580
581 local_irq_disable();
582
583 /* Replace the global interrupt handler */
584 real_handler = global_clock_event->event_handler;
585 global_clock_event->event_handler = lapic_cal_handler;
586
587 /*
588 * Setup the APIC counter to 1e9. There is no way the lapic
589 * can underflow in the 100ms detection time frame
590 */
591 __setup_APIC_LVTT(1000000000, 0, 0);
592
593 /* Let the interrupts run */
594 local_irq_enable();
595
596 while (lapic_cal_loops <= LAPIC_CAL_LOOPS)
597 cpu_relax();
598
599 local_irq_disable();
600
601 /* Restore the real event handler */
602 global_clock_event->event_handler = real_handler;
603
604 /* Build delta t1-t2 as apic timer counts down */
605 delta = lapic_cal_t1 - lapic_cal_t2;
606 apic_printk(APIC_VERBOSE, "... lapic delta = %ld\n", delta);
607
608 /* Check, if the PM timer is available */
609 deltapm = lapic_cal_pm2 - lapic_cal_pm1;
610 apic_printk(APIC_VERBOSE, "... PM timer delta = %ld\n", deltapm);
611
612 if (deltapm) {
613 unsigned long mult;
614 u64 res;
615
616 mult = clocksource_hz2mult(PMTMR_TICKS_PER_SEC, 22);
617
618 if (deltapm > (pm_100ms - pm_thresh) &&
619 deltapm < (pm_100ms + pm_thresh)) {
620 apic_printk(APIC_VERBOSE, "... PM timer result ok\n");
621 } else {
622 res = (((u64) deltapm) * mult) >> 22;
623 do_div(res, 1000000);
624 printk(KERN_WARNING "APIC calibration not consistent "
625 "with PM Timer: %ldms instead of 100ms\n",
626 (long)res);
627 /* Correct the lapic counter value */
628 res = (((u64) delta) * pm_100ms);
629 do_div(res, deltapm);
630 printk(KERN_INFO "APIC delta adjusted to PM-Timer: "
631 "%lu (%ld)\n", (unsigned long) res, delta);
632 delta = (long) res;
633 }
634 pm_referenced = 1;
635 }
636
637 /* Calculate the scaled math multiplication factor */
638 lapic_clockevent.mult = div_sc(delta, TICK_NSEC * LAPIC_CAL_LOOPS,
639 lapic_clockevent.shift);
640 lapic_clockevent.max_delta_ns =
641 clockevent_delta2ns(0x7FFFFF, &lapic_clockevent);
642 lapic_clockevent.min_delta_ns =
643 clockevent_delta2ns(0xF, &lapic_clockevent);
644
645 calibration_result = (delta * APIC_DIVISOR) / LAPIC_CAL_LOOPS;
646
647 apic_printk(APIC_VERBOSE, "..... delta %ld\n", delta);
648 apic_printk(APIC_VERBOSE, "..... mult: %ld\n", lapic_clockevent.mult);
649 apic_printk(APIC_VERBOSE, "..... calibration result: %u\n",
650 calibration_result);
651
652 if (cpu_has_tsc) {
653 delta = (long)(lapic_cal_tsc2 - lapic_cal_tsc1);
654 apic_printk(APIC_VERBOSE, "..... CPU clock speed is "
655 "%ld.%04ld MHz.\n",
656 (delta / LAPIC_CAL_LOOPS) / (1000000 / HZ),
657 (delta / LAPIC_CAL_LOOPS) % (1000000 / HZ));
658 }
659
660 apic_printk(APIC_VERBOSE, "..... host bus clock speed is "
661 "%u.%04u MHz.\n",
662 calibration_result / (1000000 / HZ),
663 calibration_result % (1000000 / HZ));
664
665 /*
666 * Do a sanity check on the APIC calibration result
667 */
668 if (calibration_result < (1000000 / HZ)) {
669 local_irq_enable();
670 printk(KERN_WARNING
671 "APIC frequency too slow, disabling apic timer\n");
672 return -1;
673 }
674
675 levt->features &= ~CLOCK_EVT_FEAT_DUMMY;
676
677 /* We trust the pm timer based calibration */
678 if (!pm_referenced) {
679 apic_printk(APIC_VERBOSE, "... verify APIC timer\n");
680
681 /*
682 * Setup the apic timer manually
683 */
684 levt->event_handler = lapic_cal_handler;
685 lapic_timer_setup(CLOCK_EVT_MODE_PERIODIC, levt);
686 lapic_cal_loops = -1;
687
688 /* Let the interrupts run */
689 local_irq_enable();
690
691 while (lapic_cal_loops <= LAPIC_CAL_LOOPS)
692 cpu_relax();
693
694 local_irq_disable();
695
696 /* Stop the lapic timer */
697 lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, levt);
698
699 local_irq_enable();
700
701 /* Jiffies delta */
702 deltaj = lapic_cal_j2 - lapic_cal_j1;
703 apic_printk(APIC_VERBOSE, "... jiffies delta = %lu\n", deltaj);
704
705 /* Check, if the jiffies result is consistent */
706 if (deltaj >= LAPIC_CAL_LOOPS-2 && deltaj <= LAPIC_CAL_LOOPS+2)
707 apic_printk(APIC_VERBOSE, "... jiffies result ok\n");
708 else
709 levt->features |= CLOCK_EVT_FEAT_DUMMY;
710 } else
711 local_irq_enable();
712
713 if (levt->features & CLOCK_EVT_FEAT_DUMMY) {
714 printk(KERN_WARNING
715 "APIC timer disabled due to verification failure.\n");
716 return -1;
717 }
718
719 return 0;
720 }
721
722 #endif
723
724 /*
725 * Setup the boot APIC
726 *
727 * Calibrate and verify the result.
728 */
729 void __init setup_boot_APIC_clock(void)
730 {
731 /*
732 * The local apic timer can be disabled via the kernel
733 * commandline or from the CPU detection code. Register the lapic
734 * timer as a dummy clock event source on SMP systems, so the
735 * broadcast mechanism is used. On UP systems simply ignore it.
736 */
737 if (disable_apic_timer) {
738 printk(KERN_INFO "Disabling APIC timer\n");
739 /* No broadcast on UP ! */
740 if (num_possible_cpus() > 1) {
741 lapic_clockevent.mult = 1;
742 setup_APIC_timer();
743 }
744 return;
745 }
746
747 apic_printk(APIC_VERBOSE, "Using local APIC timer interrupts.\n"
748 "calibrating APIC timer ...\n");
749
750 if (calibrate_APIC_clock()) {
751 /* No broadcast on UP ! */
752 if (num_possible_cpus() > 1)
753 setup_APIC_timer();
754 return;
755 }
756
757 /*
758 * If nmi_watchdog is set to IO_APIC, we need the
759 * PIT/HPET going. Otherwise register lapic as a dummy
760 * device.
761 */
762 if (nmi_watchdog != NMI_IO_APIC)
763 lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY;
764 else
765 printk(KERN_WARNING "APIC timer registered as dummy,"
766 " due to nmi_watchdog=%d!\n", nmi_watchdog);
767
768 /* Setup the lapic or request the broadcast */
769 setup_APIC_timer();
770 }
771
772 void __cpuinit setup_secondary_APIC_clock(void)
773 {
774 setup_APIC_timer();
775 }
776
777 /*
778 * The guts of the apic timer interrupt
779 */
780 static void local_apic_timer_interrupt(void)
781 {
782 int cpu = smp_processor_id();
783 struct clock_event_device *evt = &per_cpu(lapic_events, cpu);
784
785 /*
786 * Normally we should not be here till LAPIC has been initialized but
787 * in some cases like kdump, its possible that there is a pending LAPIC
788 * timer interrupt from previous kernel's context and is delivered in
789 * new kernel the moment interrupts are enabled.
790 *
791 * Interrupts are enabled early and LAPIC is setup much later, hence
792 * its possible that when we get here evt->event_handler is NULL.
793 * Check for event_handler being NULL and discard the interrupt as
794 * spurious.
795 */
796 if (!evt->event_handler) {
797 printk(KERN_WARNING
798 "Spurious LAPIC timer interrupt on cpu %d\n", cpu);
799 /* Switch it off */
800 lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, evt);
801 return;
802 }
803
804 /*
805 * the NMI deadlock-detector uses this.
806 */
807 #ifdef CONFIG_X86_64
808 add_pda(apic_timer_irqs, 1);
809 #else
810 per_cpu(irq_stat, cpu).apic_timer_irqs++;
811 #endif
812
813 evt->event_handler(evt);
814 }
815
816 /*
817 * Local APIC timer interrupt. This is the most natural way for doing
818 * local interrupts, but local timer interrupts can be emulated by
819 * broadcast interrupts too. [in case the hw doesn't support APIC timers]
820 *
821 * [ if a single-CPU system runs an SMP kernel then we call the local
822 * interrupt as well. Thus we cannot inline the local irq ... ]
823 */
824 void smp_apic_timer_interrupt(struct pt_regs *regs)
825 {
826 struct pt_regs *old_regs = set_irq_regs(regs);
827
828 /*
829 * NOTE! We'd better ACK the irq immediately,
830 * because timer handling can be slow.
831 */
832 ack_APIC_irq();
833 /*
834 * update_process_times() expects us to have done irq_enter().
835 * Besides, if we don't timer interrupts ignore the global
836 * interrupt lock, which is the WrongThing (tm) to do.
837 */
838 #ifdef CONFIG_X86_64
839 exit_idle();
840 #endif
841 irq_enter();
842 local_apic_timer_interrupt();
843 irq_exit();
844
845 set_irq_regs(old_regs);
846 }
847
848 int setup_profiling_timer(unsigned int multiplier)
849 {
850 return -EINVAL;
851 }
852
853 /*
854 * Local APIC start and shutdown
855 */
856
857 /**
858 * clear_local_APIC - shutdown the local APIC
859 *
860 * This is called, when a CPU is disabled and before rebooting, so the state of
861 * the local APIC has no dangling leftovers. Also used to cleanout any BIOS
862 * leftovers during boot.
863 */
864 void clear_local_APIC(void)
865 {
866 int maxlvt;
867 u32 v;
868
869 /* APIC hasn't been mapped yet */
870 if (!apic_phys)
871 return;
872
873 maxlvt = lapic_get_maxlvt();
874 /*
875 * Masking an LVT entry can trigger a local APIC error
876 * if the vector is zero. Mask LVTERR first to prevent this.
877 */
878 if (maxlvt >= 3) {
879 v = ERROR_APIC_VECTOR; /* any non-zero vector will do */
880 apic_write(APIC_LVTERR, v | APIC_LVT_MASKED);
881 }
882 /*
883 * Careful: we have to set masks only first to deassert
884 * any level-triggered sources.
885 */
886 v = apic_read(APIC_LVTT);
887 apic_write(APIC_LVTT, v | APIC_LVT_MASKED);
888 v = apic_read(APIC_LVT0);
889 apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
890 v = apic_read(APIC_LVT1);
891 apic_write(APIC_LVT1, v | APIC_LVT_MASKED);
892 if (maxlvt >= 4) {
893 v = apic_read(APIC_LVTPC);
894 apic_write(APIC_LVTPC, v | APIC_LVT_MASKED);
895 }
896
897 /* lets not touch this if we didn't frob it */
898 #if defined(CONFIG_X86_MCE_P4THERMAL) || defined(X86_MCE_INTEL)
899 if (maxlvt >= 5) {
900 v = apic_read(APIC_LVTTHMR);
901 apic_write(APIC_LVTTHMR, v | APIC_LVT_MASKED);
902 }
903 #endif
904 /*
905 * Clean APIC state for other OSs:
906 */
907 apic_write(APIC_LVTT, APIC_LVT_MASKED);
908 apic_write(APIC_LVT0, APIC_LVT_MASKED);
909 apic_write(APIC_LVT1, APIC_LVT_MASKED);
910 if (maxlvt >= 3)
911 apic_write(APIC_LVTERR, APIC_LVT_MASKED);
912 if (maxlvt >= 4)
913 apic_write(APIC_LVTPC, APIC_LVT_MASKED);
914
915 /* Integrated APIC (!82489DX) ? */
916 if (lapic_is_integrated()) {
917 if (maxlvt > 3)
918 /* Clear ESR due to Pentium errata 3AP and 11AP */
919 apic_write(APIC_ESR, 0);
920 apic_read(APIC_ESR);
921 }
922 }
923
924 /**
925 * disable_local_APIC - clear and disable the local APIC
926 */
927 void disable_local_APIC(void)
928 {
929 unsigned int value;
930
931 clear_local_APIC();
932
933 /*
934 * Disable APIC (implies clearing of registers
935 * for 82489DX!).
936 */
937 value = apic_read(APIC_SPIV);
938 value &= ~APIC_SPIV_APIC_ENABLED;
939 apic_write(APIC_SPIV, value);
940
941 #ifdef CONFIG_X86_32
942 /*
943 * When LAPIC was disabled by the BIOS and enabled by the kernel,
944 * restore the disabled state.
945 */
946 if (enabled_via_apicbase) {
947 unsigned int l, h;
948
949 rdmsr(MSR_IA32_APICBASE, l, h);
950 l &= ~MSR_IA32_APICBASE_ENABLE;
951 wrmsr(MSR_IA32_APICBASE, l, h);
952 }
953 #endif
954 }
955
956 /*
957 * If Linux enabled the LAPIC against the BIOS default disable it down before
958 * re-entering the BIOS on shutdown. Otherwise the BIOS may get confused and
959 * not power-off. Additionally clear all LVT entries before disable_local_APIC
960 * for the case where Linux didn't enable the LAPIC.
961 */
962 void lapic_shutdown(void)
963 {
964 unsigned long flags;
965
966 if (!cpu_has_apic)
967 return;
968
969 local_irq_save(flags);
970
971 #ifdef CONFIG_X86_32
972 if (!enabled_via_apicbase)
973 clear_local_APIC();
974 else
975 #endif
976 disable_local_APIC();
977
978
979 local_irq_restore(flags);
980 }
981
982 /*
983 * This is to verify that we're looking at a real local APIC.
984 * Check these against your board if the CPUs aren't getting
985 * started for no apparent reason.
986 */
987 int __init verify_local_APIC(void)
988 {
989 unsigned int reg0, reg1;
990
991 /*
992 * The version register is read-only in a real APIC.
993 */
994 reg0 = apic_read(APIC_LVR);
995 apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg0);
996 apic_write(APIC_LVR, reg0 ^ APIC_LVR_MASK);
997 reg1 = apic_read(APIC_LVR);
998 apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg1);
999
1000 /*
1001 * The two version reads above should print the same
1002 * numbers. If the second one is different, then we
1003 * poke at a non-APIC.
1004 */
1005 if (reg1 != reg0)
1006 return 0;
1007
1008 /*
1009 * Check if the version looks reasonably.
1010 */
1011 reg1 = GET_APIC_VERSION(reg0);
1012 if (reg1 == 0x00 || reg1 == 0xff)
1013 return 0;
1014 reg1 = lapic_get_maxlvt();
1015 if (reg1 < 0x02 || reg1 == 0xff)
1016 return 0;
1017
1018 /*
1019 * The ID register is read/write in a real APIC.
1020 */
1021 reg0 = apic_read(APIC_ID);
1022 apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg0);
1023 apic_write(APIC_ID, reg0 ^ APIC_ID_MASK);
1024 reg1 = apic_read(APIC_ID);
1025 apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg1);
1026 apic_write(APIC_ID, reg0);
1027 if (reg1 != (reg0 ^ APIC_ID_MASK))
1028 return 0;
1029
1030 /*
1031 * The next two are just to see if we have sane values.
1032 * They're only really relevant if we're in Virtual Wire
1033 * compatibility mode, but most boxes are anymore.
1034 */
1035 reg0 = apic_read(APIC_LVT0);
1036 apic_printk(APIC_DEBUG, "Getting LVT0: %x\n", reg0);
1037 reg1 = apic_read(APIC_LVT1);
1038 apic_printk(APIC_DEBUG, "Getting LVT1: %x\n", reg1);
1039
1040 return 1;
1041 }
1042
1043 /**
1044 * sync_Arb_IDs - synchronize APIC bus arbitration IDs
1045 */
1046 void __init sync_Arb_IDs(void)
1047 {
1048 /*
1049 * Unsupported on P4 - see Intel Dev. Manual Vol. 3, Ch. 8.6.1 And not
1050 * needed on AMD.
1051 */
1052 if (modern_apic() || boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
1053 return;
1054
1055 /*
1056 * Wait for idle.
1057 */
1058 apic_wait_icr_idle();
1059
1060 apic_printk(APIC_DEBUG, "Synchronizing Arb IDs.\n");
1061 apic_write(APIC_ICR, APIC_DEST_ALLINC |
1062 APIC_INT_LEVELTRIG | APIC_DM_INIT);
1063 }
1064
1065 /*
1066 * An initial setup of the virtual wire mode.
1067 */
1068 void __init init_bsp_APIC(void)
1069 {
1070 unsigned int value;
1071
1072 /*
1073 * Don't do the setup now if we have a SMP BIOS as the
1074 * through-I/O-APIC virtual wire mode might be active.
1075 */
1076 if (smp_found_config || !cpu_has_apic)
1077 return;
1078
1079 /*
1080 * Do not trust the local APIC being empty at bootup.
1081 */
1082 clear_local_APIC();
1083
1084 /*
1085 * Enable APIC.
1086 */
1087 value = apic_read(APIC_SPIV);
1088 value &= ~APIC_VECTOR_MASK;
1089 value |= APIC_SPIV_APIC_ENABLED;
1090
1091 #ifdef CONFIG_X86_32
1092 /* This bit is reserved on P4/Xeon and should be cleared */
1093 if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
1094 (boot_cpu_data.x86 == 15))
1095 value &= ~APIC_SPIV_FOCUS_DISABLED;
1096 else
1097 #endif
1098 value |= APIC_SPIV_FOCUS_DISABLED;
1099 value |= SPURIOUS_APIC_VECTOR;
1100 apic_write(APIC_SPIV, value);
1101
1102 /*
1103 * Set up the virtual wire mode.
1104 */
1105 apic_write(APIC_LVT0, APIC_DM_EXTINT);
1106 value = APIC_DM_NMI;
1107 if (!lapic_is_integrated()) /* 82489DX */
1108 value |= APIC_LVT_LEVEL_TRIGGER;
1109 apic_write(APIC_LVT1, value);
1110 }
1111
1112 static void __cpuinit lapic_setup_esr(void)
1113 {
1114 unsigned long oldvalue, value, maxlvt;
1115 if (lapic_is_integrated() && !esr_disable) {
1116 if (esr_disable) {
1117 /*
1118 * Something untraceable is creating bad interrupts on
1119 * secondary quads ... for the moment, just leave the
1120 * ESR disabled - we can't do anything useful with the
1121 * errors anyway - mbligh
1122 */
1123 printk(KERN_INFO "Leaving ESR disabled.\n");
1124 return;
1125 }
1126 /* !82489DX */
1127 maxlvt = lapic_get_maxlvt();
1128 if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
1129 apic_write(APIC_ESR, 0);
1130 oldvalue = apic_read(APIC_ESR);
1131
1132 /* enables sending errors */
1133 value = ERROR_APIC_VECTOR;
1134 apic_write(APIC_LVTERR, value);
1135 /*
1136 * spec says clear errors after enabling vector.
1137 */
1138 if (maxlvt > 3)
1139 apic_write(APIC_ESR, 0);
1140 value = apic_read(APIC_ESR);
1141 if (value != oldvalue)
1142 apic_printk(APIC_VERBOSE, "ESR value before enabling "
1143 "vector: 0x%08lx after: 0x%08lx\n",
1144 oldvalue, value);
1145 } else {
1146 printk(KERN_INFO "No ESR for 82489DX.\n");
1147 }
1148 }
1149
1150
1151 /**
1152 * setup_local_APIC - setup the local APIC
1153 */
1154 void __cpuinit setup_local_APIC(void)
1155 {
1156 unsigned int value;
1157 int i, j;
1158
1159 #ifdef CONFIG_X86_32
1160 /* Pound the ESR really hard over the head with a big hammer - mbligh */
1161 if (esr_disable) {
1162 apic_write(APIC_ESR, 0);
1163 apic_write(APIC_ESR, 0);
1164 apic_write(APIC_ESR, 0);
1165 apic_write(APIC_ESR, 0);
1166 }
1167 #endif
1168
1169 preempt_disable();
1170
1171 /*
1172 * Double-check whether this APIC is really registered.
1173 * This is meaningless in clustered apic mode, so we skip it.
1174 */
1175 if (!apic_id_registered())
1176 BUG();
1177
1178 /*
1179 * Intel recommends to set DFR, LDR and TPR before enabling
1180 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
1181 * document number 292116). So here it goes...
1182 */
1183 init_apic_ldr();
1184
1185 /*
1186 * Set Task Priority to 'accept all'. We never change this
1187 * later on.
1188 */
1189 value = apic_read(APIC_TASKPRI);
1190 value &= ~APIC_TPRI_MASK;
1191 apic_write(APIC_TASKPRI, value);
1192
1193 /*
1194 * After a crash, we no longer service the interrupts and a pending
1195 * interrupt from previous kernel might still have ISR bit set.
1196 *
1197 * Most probably by now CPU has serviced that pending interrupt and
1198 * it might not have done the ack_APIC_irq() because it thought,
1199 * interrupt came from i8259 as ExtInt. LAPIC did not get EOI so it
1200 * does not clear the ISR bit and cpu thinks it has already serivced
1201 * the interrupt. Hence a vector might get locked. It was noticed
1202 * for timer irq (vector 0x31). Issue an extra EOI to clear ISR.
1203 */
1204 for (i = APIC_ISR_NR - 1; i >= 0; i--) {
1205 value = apic_read(APIC_ISR + i*0x10);
1206 for (j = 31; j >= 0; j--) {
1207 if (value & (1<<j))
1208 ack_APIC_irq();
1209 }
1210 }
1211
1212 /*
1213 * Now that we are all set up, enable the APIC
1214 */
1215 value = apic_read(APIC_SPIV);
1216 value &= ~APIC_VECTOR_MASK;
1217 /*
1218 * Enable APIC
1219 */
1220 value |= APIC_SPIV_APIC_ENABLED;
1221
1222 #ifdef CONFIG_X86_32
1223 /*
1224 * Some unknown Intel IO/APIC (or APIC) errata is biting us with
1225 * certain networking cards. If high frequency interrupts are
1226 * happening on a particular IOAPIC pin, plus the IOAPIC routing
1227 * entry is masked/unmasked at a high rate as well then sooner or
1228 * later IOAPIC line gets 'stuck', no more interrupts are received
1229 * from the device. If focus CPU is disabled then the hang goes
1230 * away, oh well :-(
1231 *
1232 * [ This bug can be reproduced easily with a level-triggered
1233 * PCI Ne2000 networking cards and PII/PIII processors, dual
1234 * BX chipset. ]
1235 */
1236 /*
1237 * Actually disabling the focus CPU check just makes the hang less
1238 * frequent as it makes the interrupt distributon model be more
1239 * like LRU than MRU (the short-term load is more even across CPUs).
1240 * See also the comment in end_level_ioapic_irq(). --macro
1241 */
1242
1243 /*
1244 * - enable focus processor (bit==0)
1245 * - 64bit mode always use processor focus
1246 * so no need to set it
1247 */
1248 value &= ~APIC_SPIV_FOCUS_DISABLED;
1249 #endif
1250
1251 /*
1252 * Set spurious IRQ vector
1253 */
1254 value |= SPURIOUS_APIC_VECTOR;
1255 apic_write(APIC_SPIV, value);
1256
1257 /*
1258 * Set up LVT0, LVT1:
1259 *
1260 * set up through-local-APIC on the BP's LINT0. This is not
1261 * strictly necessary in pure symmetric-IO mode, but sometimes
1262 * we delegate interrupts to the 8259A.
1263 */
1264 /*
1265 * TODO: set up through-local-APIC from through-I/O-APIC? --macro
1266 */
1267 value = apic_read(APIC_LVT0) & APIC_LVT_MASKED;
1268 if (!smp_processor_id() && (pic_mode || !value)) {
1269 value = APIC_DM_EXTINT;
1270 apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n",
1271 smp_processor_id());
1272 } else {
1273 value = APIC_DM_EXTINT | APIC_LVT_MASKED;
1274 apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n",
1275 smp_processor_id());
1276 }
1277 apic_write(APIC_LVT0, value);
1278
1279 /*
1280 * only the BP should see the LINT1 NMI signal, obviously.
1281 */
1282 if (!smp_processor_id())
1283 value = APIC_DM_NMI;
1284 else
1285 value = APIC_DM_NMI | APIC_LVT_MASKED;
1286 if (!lapic_is_integrated()) /* 82489DX */
1287 value |= APIC_LVT_LEVEL_TRIGGER;
1288 apic_write(APIC_LVT1, value);
1289
1290 preempt_enable();
1291 }
1292
1293 void __cpuinit end_local_APIC_setup(void)
1294 {
1295 lapic_setup_esr();
1296
1297 #ifdef CONFIG_X86_32
1298 {
1299 unsigned int value;
1300 /* Disable the local apic timer */
1301 value = apic_read(APIC_LVTT);
1302 value |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR);
1303 apic_write(APIC_LVTT, value);
1304 }
1305 #endif
1306
1307 setup_apic_nmi_watchdog(NULL);
1308 apic_pm_activate();
1309 }
1310
1311 #ifdef CONFIG_X86_64
1312 /*
1313 * Detect and enable local APICs on non-SMP boards.
1314 * Original code written by Keir Fraser.
1315 * On AMD64 we trust the BIOS - if it says no APIC it is likely
1316 * not correctly set up (usually the APIC timer won't work etc.)
1317 */
1318 static int __init detect_init_APIC(void)
1319 {
1320 if (!cpu_has_apic) {
1321 printk(KERN_INFO "No local APIC present\n");
1322 return -1;
1323 }
1324
1325 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
1326 boot_cpu_physical_apicid = 0;
1327 return 0;
1328 }
1329 #else
1330 /*
1331 * Detect and initialize APIC
1332 */
1333 static int __init detect_init_APIC(void)
1334 {
1335 u32 h, l, features;
1336
1337 /* Disabled by kernel option? */
1338 if (disable_apic)
1339 return -1;
1340
1341 switch (boot_cpu_data.x86_vendor) {
1342 case X86_VENDOR_AMD:
1343 if ((boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model > 1) ||
1344 (boot_cpu_data.x86 == 15))
1345 break;
1346 goto no_apic;
1347 case X86_VENDOR_INTEL:
1348 if (boot_cpu_data.x86 == 6 || boot_cpu_data.x86 == 15 ||
1349 (boot_cpu_data.x86 == 5 && cpu_has_apic))
1350 break;
1351 goto no_apic;
1352 default:
1353 goto no_apic;
1354 }
1355
1356 if (!cpu_has_apic) {
1357 /*
1358 * Over-ride BIOS and try to enable the local APIC only if
1359 * "lapic" specified.
1360 */
1361 if (!force_enable_local_apic) {
1362 printk(KERN_INFO "Local APIC disabled by BIOS -- "
1363 "you can enable it with \"lapic\"\n");
1364 return -1;
1365 }
1366 /*
1367 * Some BIOSes disable the local APIC in the APIC_BASE
1368 * MSR. This can only be done in software for Intel P6 or later
1369 * and AMD K7 (Model > 1) or later.
1370 */
1371 rdmsr(MSR_IA32_APICBASE, l, h);
1372 if (!(l & MSR_IA32_APICBASE_ENABLE)) {
1373 printk(KERN_INFO
1374 "Local APIC disabled by BIOS -- reenabling.\n");
1375 l &= ~MSR_IA32_APICBASE_BASE;
1376 l |= MSR_IA32_APICBASE_ENABLE | APIC_DEFAULT_PHYS_BASE;
1377 wrmsr(MSR_IA32_APICBASE, l, h);
1378 enabled_via_apicbase = 1;
1379 }
1380 }
1381 /*
1382 * The APIC feature bit should now be enabled
1383 * in `cpuid'
1384 */
1385 features = cpuid_edx(1);
1386 if (!(features & (1 << X86_FEATURE_APIC))) {
1387 printk(KERN_WARNING "Could not enable APIC!\n");
1388 return -1;
1389 }
1390 set_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC);
1391 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
1392
1393 /* The BIOS may have set up the APIC at some other address */
1394 rdmsr(MSR_IA32_APICBASE, l, h);
1395 if (l & MSR_IA32_APICBASE_ENABLE)
1396 mp_lapic_addr = l & MSR_IA32_APICBASE_BASE;
1397
1398 printk(KERN_INFO "Found and enabled local APIC!\n");
1399
1400 apic_pm_activate();
1401
1402 return 0;
1403
1404 no_apic:
1405 printk(KERN_INFO "No local APIC present or hardware disabled\n");
1406 return -1;
1407 }
1408 #endif
1409
1410 #ifdef CONFIG_X86_64
1411 void __init early_init_lapic_mapping(void)
1412 {
1413 unsigned long phys_addr;
1414
1415 /*
1416 * If no local APIC can be found then go out
1417 * : it means there is no mpatable and MADT
1418 */
1419 if (!smp_found_config)
1420 return;
1421
1422 phys_addr = mp_lapic_addr;
1423
1424 set_fixmap_nocache(FIX_APIC_BASE, phys_addr);
1425 apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
1426 APIC_BASE, phys_addr);
1427
1428 /*
1429 * Fetch the APIC ID of the BSP in case we have a
1430 * default configuration (or the MP table is broken).
1431 */
1432 boot_cpu_physical_apicid = read_apic_id();
1433 }
1434 #endif
1435
1436 /**
1437 * init_apic_mappings - initialize APIC mappings
1438 */
1439 void __init init_apic_mappings(void)
1440 {
1441 /*
1442 * If no local APIC can be found then set up a fake all
1443 * zeroes page to simulate the local APIC and another
1444 * one for the IO-APIC.
1445 */
1446 if (!smp_found_config && detect_init_APIC()) {
1447 apic_phys = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
1448 apic_phys = __pa(apic_phys);
1449 } else
1450 apic_phys = mp_lapic_addr;
1451
1452 set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
1453 apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
1454 APIC_BASE, apic_phys);
1455
1456 /*
1457 * Fetch the APIC ID of the BSP in case we have a
1458 * default configuration (or the MP table is broken).
1459 */
1460 if (boot_cpu_physical_apicid == -1U)
1461 boot_cpu_physical_apicid = read_apic_id();
1462 }
1463
1464 /*
1465 * This initializes the IO-APIC and APIC hardware if this is
1466 * a UP kernel.
1467 */
1468 int apic_version[MAX_APICS];
1469
1470 int __init APIC_init_uniprocessor(void)
1471 {
1472 #ifdef CONFIG_X86_64
1473 if (disable_apic) {
1474 printk(KERN_INFO "Apic disabled\n");
1475 return -1;
1476 }
1477 if (!cpu_has_apic) {
1478 disable_apic = 1;
1479 printk(KERN_INFO "Apic disabled by BIOS\n");
1480 return -1;
1481 }
1482 #else
1483 if (!smp_found_config && !cpu_has_apic)
1484 return -1;
1485
1486 /*
1487 * Complain if the BIOS pretends there is one.
1488 */
1489 if (!cpu_has_apic &&
1490 APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) {
1491 printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
1492 boot_cpu_physical_apicid);
1493 clear_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC);
1494 return -1;
1495 }
1496 #endif
1497
1498 #ifdef HAVE_X2APIC
1499 enable_IR_x2apic();
1500 #endif
1501 #ifdef CONFIG_X86_64
1502 setup_apic_routing();
1503 #endif
1504 verify_local_APIC();
1505 connect_bsp_APIC();
1506
1507 #ifdef CONFIG_X86_64
1508 apic_write(APIC_ID, SET_APIC_ID(boot_cpu_physical_apicid));
1509 #else
1510 /*
1511 * Hack: In case of kdump, after a crash, kernel might be booting
1512 * on a cpu with non-zero lapic id. But boot_cpu_physical_apicid
1513 * might be zero if read from MP tables. Get it from LAPIC.
1514 */
1515 # ifdef CONFIG_CRASH_DUMP
1516 boot_cpu_physical_apicid = read_apic_id();
1517 # endif
1518 #endif
1519 physid_set_mask_of_physid(boot_cpu_physical_apicid, &phys_cpu_present_map);
1520 setup_local_APIC();
1521
1522 #ifdef CONFIG_X86_64
1523 /*
1524 * Now enable IO-APICs, actually call clear_IO_APIC
1525 * We need clear_IO_APIC before enabling vector on BP
1526 */
1527 if (!skip_ioapic_setup && nr_ioapics)
1528 enable_IO_APIC();
1529 #endif
1530
1531 #ifdef CONFIG_X86_IO_APIC
1532 if (!smp_found_config || skip_ioapic_setup || !nr_ioapics)
1533 #endif
1534 localise_nmi_watchdog();
1535 end_local_APIC_setup();
1536
1537 #ifdef CONFIG_X86_IO_APIC
1538 if (smp_found_config && !skip_ioapic_setup && nr_ioapics)
1539 setup_IO_APIC();
1540 # ifdef CONFIG_X86_64
1541 else
1542 nr_ioapics = 0;
1543 # endif
1544 #endif
1545
1546 #ifdef CONFIG_X86_64
1547 setup_boot_APIC_clock();
1548 check_nmi_watchdog();
1549 #else
1550 setup_boot_clock();
1551 #endif
1552
1553 return 0;
1554 }
1555
1556 /*
1557 * Local APIC interrupts
1558 */
1559
1560 /*
1561 * This interrupt should _never_ happen with our APIC/SMP architecture
1562 */
1563 #ifdef CONFIG_X86_64
1564 asmlinkage void smp_spurious_interrupt(void)
1565 #else
1566 void smp_spurious_interrupt(struct pt_regs *regs)
1567 #endif
1568 {
1569 u32 v;
1570
1571 #ifdef CONFIG_X86_64
1572 exit_idle();
1573 #endif
1574 irq_enter();
1575 /*
1576 * Check if this really is a spurious interrupt and ACK it
1577 * if it is a vectored one. Just in case...
1578 * Spurious interrupts should not be ACKed.
1579 */
1580 v = apic_read(APIC_ISR + ((SPURIOUS_APIC_VECTOR & ~0x1f) >> 1));
1581 if (v & (1 << (SPURIOUS_APIC_VECTOR & 0x1f)))
1582 ack_APIC_irq();
1583
1584 #ifdef CONFIG_X86_64
1585 add_pda(irq_spurious_count, 1);
1586 #else
1587 /* see sw-dev-man vol 3, chapter 7.4.13.5 */
1588 printk(KERN_INFO "spurious APIC interrupt on CPU#%d, "
1589 "should never happen.\n", smp_processor_id());
1590 __get_cpu_var(irq_stat).irq_spurious_count++;
1591 #endif
1592 irq_exit();
1593 }
1594
1595 /*
1596 * This interrupt should never happen with our APIC/SMP architecture
1597 */
1598 #ifdef CONFIG_X86_64
1599 asmlinkage void smp_error_interrupt(void)
1600 #else
1601 void smp_error_interrupt(struct pt_regs *regs)
1602 #endif
1603 {
1604 u32 v, v1;
1605
1606 #ifdef CONFIG_X86_64
1607 exit_idle();
1608 #endif
1609 irq_enter();
1610 /* First tickle the hardware, only then report what went on. -- REW */
1611 v = apic_read(APIC_ESR);
1612 apic_write(APIC_ESR, 0);
1613 v1 = apic_read(APIC_ESR);
1614 ack_APIC_irq();
1615 atomic_inc(&irq_err_count);
1616
1617 /* Here is what the APIC error bits mean:
1618 0: Send CS error
1619 1: Receive CS error
1620 2: Send accept error
1621 3: Receive accept error
1622 4: Reserved
1623 5: Send illegal vector
1624 6: Received illegal vector
1625 7: Illegal register address
1626 */
1627 printk(KERN_DEBUG "APIC error on CPU%d: %02x(%02x)\n",
1628 smp_processor_id(), v , v1);
1629 irq_exit();
1630 }
1631
1632 /**
1633 * connect_bsp_APIC - attach the APIC to the interrupt system
1634 */
1635 void __init connect_bsp_APIC(void)
1636 {
1637 #ifdef CONFIG_X86_32
1638 if (pic_mode) {
1639 /*
1640 * Do not trust the local APIC being empty at bootup.
1641 */
1642 clear_local_APIC();
1643 /*
1644 * PIC mode, enable APIC mode in the IMCR, i.e. connect BSP's
1645 * local APIC to INT and NMI lines.
1646 */
1647 apic_printk(APIC_VERBOSE, "leaving PIC mode, "
1648 "enabling APIC mode.\n");
1649 outb(0x70, 0x22);
1650 outb(0x01, 0x23);
1651 }
1652 #endif
1653 enable_apic_mode();
1654 }
1655
1656 /**
1657 * disconnect_bsp_APIC - detach the APIC from the interrupt system
1658 * @virt_wire_setup: indicates, whether virtual wire mode is selected
1659 *
1660 * Virtual wire mode is necessary to deliver legacy interrupts even when the
1661 * APIC is disabled.
1662 */
1663 void disconnect_bsp_APIC(int virt_wire_setup)
1664 {
1665 unsigned int value;
1666
1667 #ifdef CONFIG_X86_32
1668 if (pic_mode) {
1669 /*
1670 * Put the board back into PIC mode (has an effect only on
1671 * certain older boards). Note that APIC interrupts, including
1672 * IPIs, won't work beyond this point! The only exception are
1673 * INIT IPIs.
1674 */
1675 apic_printk(APIC_VERBOSE, "disabling APIC mode, "
1676 "entering PIC mode.\n");
1677 outb(0x70, 0x22);
1678 outb(0x00, 0x23);
1679 return;
1680 }
1681 #endif
1682
1683 /* Go back to Virtual Wire compatibility mode */
1684
1685 /* For the spurious interrupt use vector F, and enable it */
1686 value = apic_read(APIC_SPIV);
1687 value &= ~APIC_VECTOR_MASK;
1688 value |= APIC_SPIV_APIC_ENABLED;
1689 value |= 0xf;
1690 apic_write(APIC_SPIV, value);
1691
1692 if (!virt_wire_setup) {
1693 /*
1694 * For LVT0 make it edge triggered, active high,
1695 * external and enabled
1696 */
1697 value = apic_read(APIC_LVT0);
1698 value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING |
1699 APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR |
1700 APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED);
1701 value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
1702 value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_EXTINT);
1703 apic_write(APIC_LVT0, value);
1704 } else {
1705 /* Disable LVT0 */
1706 apic_write(APIC_LVT0, APIC_LVT_MASKED);
1707 }
1708
1709 /*
1710 * For LVT1 make it edge triggered, active high,
1711 * nmi and enabled
1712 */
1713 value = apic_read(APIC_LVT1);
1714 value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING |
1715 APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR |
1716 APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED);
1717 value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
1718 value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_NMI);
1719 apic_write(APIC_LVT1, value);
1720 }
1721
1722 void __cpuinit generic_processor_info(int apicid, int version)
1723 {
1724 int cpu;
1725 cpumask_t tmp_map;
1726
1727 /*
1728 * Validate version
1729 */
1730 if (version == 0x0) {
1731 printk(KERN_WARNING "BIOS bug, APIC version is 0 for CPU#%d! "
1732 "fixing up to 0x10. (tell your hw vendor)\n",
1733 version);
1734 version = 0x10;
1735 }
1736 apic_version[apicid] = version;
1737
1738 if (num_processors >= NR_CPUS) {
1739 printk(KERN_WARNING "WARNING: NR_CPUS limit of %i reached."
1740 " Processor ignored.\n", NR_CPUS);
1741 return;
1742 }
1743
1744 num_processors++;
1745 cpus_complement(tmp_map, cpu_present_map);
1746 cpu = first_cpu(tmp_map);
1747
1748 physid_set(apicid, phys_cpu_present_map);
1749 if (apicid == boot_cpu_physical_apicid) {
1750 /*
1751 * x86_bios_cpu_apicid is required to have processors listed
1752 * in same order as logical cpu numbers. Hence the first
1753 * entry is BSP, and so on.
1754 */
1755 cpu = 0;
1756 }
1757 if (apicid > max_physical_apicid)
1758 max_physical_apicid = apicid;
1759
1760 #ifdef CONFIG_X86_32
1761 /*
1762 * Would be preferable to switch to bigsmp when CONFIG_HOTPLUG_CPU=y
1763 * but we need to work other dependencies like SMP_SUSPEND etc
1764 * before this can be done without some confusion.
1765 * if (CPU_HOTPLUG_ENABLED || num_processors > 8)
1766 * - Ashok Raj <ashok.raj@intel.com>
1767 */
1768 if (max_physical_apicid >= 8) {
1769 switch (boot_cpu_data.x86_vendor) {
1770 case X86_VENDOR_INTEL:
1771 if (!APIC_XAPIC(version)) {
1772 def_to_bigsmp = 0;
1773 break;
1774 }
1775 /* If P4 and above fall through */
1776 case X86_VENDOR_AMD:
1777 def_to_bigsmp = 1;
1778 }
1779 }
1780 #endif
1781
1782 #if defined(CONFIG_X86_SMP) || defined(CONFIG_X86_64)
1783 /* are we being called early in kernel startup? */
1784 if (early_per_cpu_ptr(x86_cpu_to_apicid)) {
1785 u16 *cpu_to_apicid = early_per_cpu_ptr(x86_cpu_to_apicid);
1786 u16 *bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
1787
1788 cpu_to_apicid[cpu] = apicid;
1789 bios_cpu_apicid[cpu] = apicid;
1790 } else {
1791 per_cpu(x86_cpu_to_apicid, cpu) = apicid;
1792 per_cpu(x86_bios_cpu_apicid, cpu) = apicid;
1793 }
1794 #endif
1795
1796 cpu_set(cpu, cpu_possible_map);
1797 cpu_set(cpu, cpu_present_map);
1798 }
1799
1800 #ifdef CONFIG_X86_64
1801 int hard_smp_processor_id(void)
1802 {
1803 return read_apic_id();
1804 }
1805 #endif
1806
1807 /*
1808 * Power management
1809 */
1810 #ifdef CONFIG_PM
1811
1812 static struct {
1813 /*
1814 * 'active' is true if the local APIC was enabled by us and
1815 * not the BIOS; this signifies that we are also responsible
1816 * for disabling it before entering apm/acpi suspend
1817 */
1818 int active;
1819 /* r/w apic fields */
1820 unsigned int apic_id;
1821 unsigned int apic_taskpri;
1822 unsigned int apic_ldr;
1823 unsigned int apic_dfr;
1824 unsigned int apic_spiv;
1825 unsigned int apic_lvtt;
1826 unsigned int apic_lvtpc;
1827 unsigned int apic_lvt0;
1828 unsigned int apic_lvt1;
1829 unsigned int apic_lvterr;
1830 unsigned int apic_tmict;
1831 unsigned int apic_tdcr;
1832 unsigned int apic_thmr;
1833 } apic_pm_state;
1834
1835 static int lapic_suspend(struct sys_device *dev, pm_message_t state)
1836 {
1837 unsigned long flags;
1838 int maxlvt;
1839
1840 if (!apic_pm_state.active)
1841 return 0;
1842
1843 maxlvt = lapic_get_maxlvt();
1844
1845 apic_pm_state.apic_id = apic_read(APIC_ID);
1846 apic_pm_state.apic_taskpri = apic_read(APIC_TASKPRI);
1847 apic_pm_state.apic_ldr = apic_read(APIC_LDR);
1848 apic_pm_state.apic_dfr = apic_read(APIC_DFR);
1849 apic_pm_state.apic_spiv = apic_read(APIC_SPIV);
1850 apic_pm_state.apic_lvtt = apic_read(APIC_LVTT);
1851 if (maxlvt >= 4)
1852 apic_pm_state.apic_lvtpc = apic_read(APIC_LVTPC);
1853 apic_pm_state.apic_lvt0 = apic_read(APIC_LVT0);
1854 apic_pm_state.apic_lvt1 = apic_read(APIC_LVT1);
1855 apic_pm_state.apic_lvterr = apic_read(APIC_LVTERR);
1856 apic_pm_state.apic_tmict = apic_read(APIC_TMICT);
1857 apic_pm_state.apic_tdcr = apic_read(APIC_TDCR);
1858 #if defined(CONFIG_X86_MCE_P4THERMAL) || defined(CONFIG_X86_MCE_INTEL)
1859 if (maxlvt >= 5)
1860 apic_pm_state.apic_thmr = apic_read(APIC_LVTTHMR);
1861 #endif
1862
1863 local_irq_save(flags);
1864 disable_local_APIC();
1865 local_irq_restore(flags);
1866 return 0;
1867 }
1868
1869 static int lapic_resume(struct sys_device *dev)
1870 {
1871 unsigned int l, h;
1872 unsigned long flags;
1873 int maxlvt;
1874
1875 if (!apic_pm_state.active)
1876 return 0;
1877
1878 maxlvt = lapic_get_maxlvt();
1879
1880 local_irq_save(flags);
1881
1882 {
1883 /*
1884 * Make sure the APICBASE points to the right address
1885 *
1886 * FIXME! This will be wrong if we ever support suspend on
1887 * SMP! We'll need to do this as part of the CPU restore!
1888 */
1889 rdmsr(MSR_IA32_APICBASE, l, h);
1890 l &= ~MSR_IA32_APICBASE_BASE;
1891 l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr;
1892 wrmsr(MSR_IA32_APICBASE, l, h);
1893 }
1894
1895 apic_write(APIC_LVTERR, ERROR_APIC_VECTOR | APIC_LVT_MASKED);
1896 apic_write(APIC_ID, apic_pm_state.apic_id);
1897 apic_write(APIC_DFR, apic_pm_state.apic_dfr);
1898 apic_write(APIC_LDR, apic_pm_state.apic_ldr);
1899 apic_write(APIC_TASKPRI, apic_pm_state.apic_taskpri);
1900 apic_write(APIC_SPIV, apic_pm_state.apic_spiv);
1901 apic_write(APIC_LVT0, apic_pm_state.apic_lvt0);
1902 apic_write(APIC_LVT1, apic_pm_state.apic_lvt1);
1903 #if defined(CONFIG_X86_MCE_P4THERMAL) || defined(CONFIG_X86_MCE_INTEL)
1904 if (maxlvt >= 5)
1905 apic_write(APIC_LVTTHMR, apic_pm_state.apic_thmr);
1906 #endif
1907 if (maxlvt >= 4)
1908 apic_write(APIC_LVTPC, apic_pm_state.apic_lvtpc);
1909 apic_write(APIC_LVTT, apic_pm_state.apic_lvtt);
1910 apic_write(APIC_TDCR, apic_pm_state.apic_tdcr);
1911 apic_write(APIC_TMICT, apic_pm_state.apic_tmict);
1912 apic_write(APIC_ESR, 0);
1913 apic_read(APIC_ESR);
1914 apic_write(APIC_LVTERR, apic_pm_state.apic_lvterr);
1915 apic_write(APIC_ESR, 0);
1916 apic_read(APIC_ESR);
1917
1918 local_irq_restore(flags);
1919
1920 return 0;
1921 }
1922
1923 /*
1924 * This device has no shutdown method - fully functioning local APICs
1925 * are needed on every CPU up until machine_halt/restart/poweroff.
1926 */
1927
1928 static struct sysdev_class lapic_sysclass = {
1929 .name = "lapic",
1930 .resume = lapic_resume,
1931 .suspend = lapic_suspend,
1932 };
1933
1934 static struct sys_device device_lapic = {
1935 .id = 0,
1936 .cls = &lapic_sysclass,
1937 };
1938
1939 static void __cpuinit apic_pm_activate(void)
1940 {
1941 apic_pm_state.active = 1;
1942 }
1943
1944 static int __init init_lapic_sysfs(void)
1945 {
1946 int error;
1947
1948 if (!cpu_has_apic)
1949 return 0;
1950 /* XXX: remove suspend/resume procs if !apic_pm_state.active? */
1951
1952 error = sysdev_class_register(&lapic_sysclass);
1953 if (!error)
1954 error = sysdev_register(&device_lapic);
1955 return error;
1956 }
1957 device_initcall(init_lapic_sysfs);
1958
1959 #else /* CONFIG_PM */
1960
1961 static void apic_pm_activate(void) { }
1962
1963 #endif /* CONFIG_PM */
1964
1965 #ifdef CONFIG_X86_64
1966 /*
1967 * apic_is_clustered_box() -- Check if we can expect good TSC
1968 *
1969 * Thus far, the major user of this is IBM's Summit2 series:
1970 *
1971 * Clustered boxes may have unsynced TSC problems if they are
1972 * multi-chassis. Use available data to take a good guess.
1973 * If in doubt, go HPET.
1974 */
1975 __cpuinit int apic_is_clustered_box(void)
1976 {
1977 int i, clusters, zeros;
1978 unsigned id;
1979 u16 *bios_cpu_apicid;
1980 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
1981
1982 /*
1983 * there is not this kind of box with AMD CPU yet.
1984 * Some AMD box with quadcore cpu and 8 sockets apicid
1985 * will be [4, 0x23] or [8, 0x27] could be thought to
1986 * vsmp box still need checking...
1987 */
1988 if ((boot_cpu_data.x86_vendor == X86_VENDOR_AMD) && !is_vsmp_box())
1989 return 0;
1990
1991 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
1992 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
1993
1994 for (i = 0; i < NR_CPUS; i++) {
1995 /* are we being called early in kernel startup? */
1996 if (bios_cpu_apicid) {
1997 id = bios_cpu_apicid[i];
1998 }
1999 else if (i < nr_cpu_ids) {
2000 if (cpu_present(i))
2001 id = per_cpu(x86_bios_cpu_apicid, i);
2002 else
2003 continue;
2004 }
2005 else
2006 break;
2007
2008 if (id != BAD_APICID)
2009 __set_bit(APIC_CLUSTERID(id), clustermap);
2010 }
2011
2012 /* Problem: Partially populated chassis may not have CPUs in some of
2013 * the APIC clusters they have been allocated. Only present CPUs have
2014 * x86_bios_cpu_apicid entries, thus causing zeroes in the bitmap.
2015 * Since clusters are allocated sequentially, count zeros only if
2016 * they are bounded by ones.
2017 */
2018 clusters = 0;
2019 zeros = 0;
2020 for (i = 0; i < NUM_APIC_CLUSTERS; i++) {
2021 if (test_bit(i, clustermap)) {
2022 clusters += 1 + zeros;
2023 zeros = 0;
2024 } else
2025 ++zeros;
2026 }
2027
2028 /* ScaleMP vSMPowered boxes have one cluster per board and TSCs are
2029 * not guaranteed to be synced between boards
2030 */
2031 if (is_vsmp_box() && clusters > 1)
2032 return 1;
2033
2034 /*
2035 * If clusters > 2, then should be multi-chassis.
2036 * May have to revisit this when multi-core + hyperthreaded CPUs come
2037 * out, but AFAIK this will work even for them.
2038 */
2039 return (clusters > 2);
2040 }
2041 #endif
2042
2043 /*
2044 * APIC command line parameters
2045 */
2046 static int __init setup_disableapic(char *arg)
2047 {
2048 disable_apic = 1;
2049 setup_clear_cpu_cap(X86_FEATURE_APIC);
2050 return 0;
2051 }
2052 early_param("disableapic", setup_disableapic);
2053
2054 /* same as disableapic, for compatibility */
2055 static int __init setup_nolapic(char *arg)
2056 {
2057 return setup_disableapic(arg);
2058 }
2059 early_param("nolapic", setup_nolapic);
2060
2061 static int __init parse_lapic_timer_c2_ok(char *arg)
2062 {
2063 local_apic_timer_c2_ok = 1;
2064 return 0;
2065 }
2066 early_param("lapic_timer_c2_ok", parse_lapic_timer_c2_ok);
2067
2068 static int __init parse_disable_apic_timer(char *arg)
2069 {
2070 disable_apic_timer = 1;
2071 return 0;
2072 }
2073 early_param("noapictimer", parse_disable_apic_timer);
2074
2075 static int __init parse_nolapic_timer(char *arg)
2076 {
2077 disable_apic_timer = 1;
2078 return 0;
2079 }
2080 early_param("nolapic_timer", parse_nolapic_timer);
2081
2082 static int __init apic_set_verbosity(char *arg)
2083 {
2084 if (!arg) {
2085 #ifdef CONFIG_X86_64
2086 skip_ioapic_setup = 0;
2087 ioapic_force = 1;
2088 return 0;
2089 #endif
2090 return -EINVAL;
2091 }
2092
2093 if (strcmp("debug", arg) == 0)
2094 apic_verbosity = APIC_DEBUG;
2095 else if (strcmp("verbose", arg) == 0)
2096 apic_verbosity = APIC_VERBOSE;
2097 else {
2098 printk(KERN_WARNING "APIC Verbosity level %s not recognised"
2099 " use apic=verbose or apic=debug\n", arg);
2100 return -EINVAL;
2101 }
2102
2103 return 0;
2104 }
2105 early_param("apic", apic_set_verbosity);
2106
2107 static int __init lapic_insert_resource(void)
2108 {
2109 if (!apic_phys)
2110 return -1;
2111
2112 /* Put local APIC into the resource map. */
2113 lapic_resource.start = apic_phys;
2114 lapic_resource.end = lapic_resource.start + PAGE_SIZE - 1;
2115 insert_resource(&iomem_resource, &lapic_resource);
2116
2117 return 0;
2118 }
2119
2120 /*
2121 * need call insert after e820_reserve_resources()
2122 * that is using request_resource
2123 */
2124 late_initcall(lapic_insert_resource);
This page took 0.081128 seconds and 5 git commands to generate.