diff options
Diffstat (limited to 'arch/x86/kernel/io_apic_64.c')
-rw-r--r-- | arch/x86/kernel/io_apic_64.c | 971 |
1 files changed, 782 insertions, 189 deletions
diff --git a/arch/x86/kernel/io_apic_64.c b/arch/x86/kernel/io_apic_64.c index ef1a8dfcc529..02063ae042f7 100644 --- a/arch/x86/kernel/io_apic_64.c +++ b/arch/x86/kernel/io_apic_64.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <acpi/acpi_bus.h> | 37 | #include <acpi/acpi_bus.h> |
38 | #endif | 38 | #endif |
39 | #include <linux/bootmem.h> | 39 | #include <linux/bootmem.h> |
40 | #include <linux/dmar.h> | ||
40 | 41 | ||
41 | #include <asm/idle.h> | 42 | #include <asm/idle.h> |
42 | #include <asm/io.h> | 43 | #include <asm/io.h> |
@@ -45,13 +46,17 @@ | |||
45 | #include <asm/proto.h> | 46 | #include <asm/proto.h> |
46 | #include <asm/acpi.h> | 47 | #include <asm/acpi.h> |
47 | #include <asm/dma.h> | 48 | #include <asm/dma.h> |
49 | #include <asm/i8259.h> | ||
48 | #include <asm/nmi.h> | 50 | #include <asm/nmi.h> |
49 | #include <asm/msidef.h> | 51 | #include <asm/msidef.h> |
50 | #include <asm/hypertransport.h> | 52 | #include <asm/hypertransport.h> |
53 | #include <asm/irq_remapping.h> | ||
51 | 54 | ||
52 | #include <mach_ipi.h> | 55 | #include <mach_ipi.h> |
53 | #include <mach_apic.h> | 56 | #include <mach_apic.h> |
54 | 57 | ||
58 | #define __apicdebuginit(type) static type __init | ||
59 | |||
55 | struct irq_cfg { | 60 | struct irq_cfg { |
56 | cpumask_t domain; | 61 | cpumask_t domain; |
57 | cpumask_t old_domain; | 62 | cpumask_t old_domain; |
@@ -61,7 +66,7 @@ struct irq_cfg { | |||
61 | }; | 66 | }; |
62 | 67 | ||
63 | /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */ | 68 | /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */ |
64 | struct irq_cfg irq_cfg[NR_IRQS] __read_mostly = { | 69 | static struct irq_cfg irq_cfg[NR_IRQS] __read_mostly = { |
65 | [0] = { .domain = CPU_MASK_ALL, .vector = IRQ0_VECTOR, }, | 70 | [0] = { .domain = CPU_MASK_ALL, .vector = IRQ0_VECTOR, }, |
66 | [1] = { .domain = CPU_MASK_ALL, .vector = IRQ1_VECTOR, }, | 71 | [1] = { .domain = CPU_MASK_ALL, .vector = IRQ1_VECTOR, }, |
67 | [2] = { .domain = CPU_MASK_ALL, .vector = IRQ2_VECTOR, }, | 72 | [2] = { .domain = CPU_MASK_ALL, .vector = IRQ2_VECTOR, }, |
@@ -82,7 +87,9 @@ struct irq_cfg irq_cfg[NR_IRQS] __read_mostly = { | |||
82 | 87 | ||
83 | static int assign_irq_vector(int irq, cpumask_t mask); | 88 | static int assign_irq_vector(int irq, cpumask_t mask); |
84 | 89 | ||
85 | #define __apicdebuginit __init | 90 | int first_system_vector = 0xfe; |
91 | |||
92 | char system_vectors[NR_VECTORS] = { [0 ... NR_VECTORS-1] = SYS_VECTOR_FREE}; | ||
86 | 93 | ||
87 | int sis_apic_bug; /* not actually supported, dummy for compile */ | 94 | int sis_apic_bug; /* not actually supported, dummy for compile */ |
88 | 95 | ||
@@ -90,29 +97,34 @@ static int no_timer_check; | |||
90 | 97 | ||
91 | static int disable_timer_pin_1 __initdata; | 98 | static int disable_timer_pin_1 __initdata; |
92 | 99 | ||
93 | int timer_over_8254 __initdata = 1; | 100 | int timer_through_8259 __initdata; |
94 | 101 | ||
95 | /* Where if anywhere is the i8259 connect in external int mode */ | 102 | /* Where if anywhere is the i8259 connect in external int mode */ |
96 | static struct { int pin, apic; } ioapic_i8259 = { -1, -1 }; | 103 | static struct { int pin, apic; } ioapic_i8259 = { -1, -1 }; |
97 | 104 | ||
98 | static DEFINE_SPINLOCK(ioapic_lock); | 105 | static DEFINE_SPINLOCK(ioapic_lock); |
99 | DEFINE_SPINLOCK(vector_lock); | 106 | static DEFINE_SPINLOCK(vector_lock); |
100 | 107 | ||
101 | /* | 108 | /* |
102 | * # of IRQ routing registers | 109 | * # of IRQ routing registers |
103 | */ | 110 | */ |
104 | int nr_ioapic_registers[MAX_IO_APICS]; | 111 | int nr_ioapic_registers[MAX_IO_APICS]; |
105 | 112 | ||
113 | /* I/O APIC RTE contents at the OS boot up */ | ||
114 | struct IO_APIC_route_entry *early_ioapic_entries[MAX_IO_APICS]; | ||
115 | |||
106 | /* I/O APIC entries */ | 116 | /* I/O APIC entries */ |
107 | struct mpc_config_ioapic mp_ioapics[MAX_IO_APICS]; | 117 | struct mp_config_ioapic mp_ioapics[MAX_IO_APICS]; |
108 | int nr_ioapics; | 118 | int nr_ioapics; |
109 | 119 | ||
110 | /* MP IRQ source entries */ | 120 | /* MP IRQ source entries */ |
111 | struct mpc_config_intsrc mp_irqs[MAX_IRQ_SOURCES]; | 121 | struct mp_config_intsrc mp_irqs[MAX_IRQ_SOURCES]; |
112 | 122 | ||
113 | /* # of MP IRQ source entries */ | 123 | /* # of MP IRQ source entries */ |
114 | int mp_irq_entries; | 124 | int mp_irq_entries; |
115 | 125 | ||
126 | DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES); | ||
127 | |||
116 | /* | 128 | /* |
117 | * Rough estimation of how many shared IRQs there are, can | 129 | * Rough estimation of how many shared IRQs there are, can |
118 | * be changed anytime. | 130 | * be changed anytime. |
@@ -140,7 +152,7 @@ struct io_apic { | |||
140 | static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx) | 152 | static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx) |
141 | { | 153 | { |
142 | return (void __iomem *) __fix_to_virt(FIX_IO_APIC_BASE_0 + idx) | 154 | return (void __iomem *) __fix_to_virt(FIX_IO_APIC_BASE_0 + idx) |
143 | + (mp_ioapics[idx].mpc_apicaddr & ~PAGE_MASK); | 155 | + (mp_ioapics[idx].mp_apicaddr & ~PAGE_MASK); |
144 | } | 156 | } |
145 | 157 | ||
146 | static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg) | 158 | static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg) |
@@ -183,7 +195,7 @@ static bool io_apic_level_ack_pending(unsigned int irq) | |||
183 | break; | 195 | break; |
184 | reg = io_apic_read(entry->apic, 0x10 + pin*2); | 196 | reg = io_apic_read(entry->apic, 0x10 + pin*2); |
185 | /* Is the remote IRR bit set? */ | 197 | /* Is the remote IRR bit set? */ |
186 | if ((reg >> 14) & 1) { | 198 | if (reg & IO_APIC_REDIR_REMOTE_IRR) { |
187 | spin_unlock_irqrestore(&ioapic_lock, flags); | 199 | spin_unlock_irqrestore(&ioapic_lock, flags); |
188 | return true; | 200 | return true; |
189 | } | 201 | } |
@@ -296,9 +308,14 @@ static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, u8 vector) | |||
296 | pin = entry->pin; | 308 | pin = entry->pin; |
297 | if (pin == -1) | 309 | if (pin == -1) |
298 | break; | 310 | break; |
299 | io_apic_write(apic, 0x11 + pin*2, dest); | 311 | /* |
312 | * With interrupt-remapping, destination information comes | ||
313 | * from interrupt-remapping table entry. | ||
314 | */ | ||
315 | if (!irq_remapped(irq)) | ||
316 | io_apic_write(apic, 0x11 + pin*2, dest); | ||
300 | reg = io_apic_read(apic, 0x10 + pin*2); | 317 | reg = io_apic_read(apic, 0x10 + pin*2); |
301 | reg &= ~0x000000ff; | 318 | reg &= ~IO_APIC_REDIR_VECTOR_MASK; |
302 | reg |= vector; | 319 | reg |= vector; |
303 | io_apic_modify(apic, reg); | 320 | io_apic_modify(apic, reg); |
304 | if (!entry->next) | 321 | if (!entry->next) |
@@ -360,16 +377,37 @@ static void add_pin_to_irq(unsigned int irq, int apic, int pin) | |||
360 | entry->pin = pin; | 377 | entry->pin = pin; |
361 | } | 378 | } |
362 | 379 | ||
380 | /* | ||
381 | * Reroute an IRQ to a different pin. | ||
382 | */ | ||
383 | static void __init replace_pin_at_irq(unsigned int irq, | ||
384 | int oldapic, int oldpin, | ||
385 | int newapic, int newpin) | ||
386 | { | ||
387 | struct irq_pin_list *entry = irq_2_pin + irq; | ||
388 | |||
389 | while (1) { | ||
390 | if (entry->apic == oldapic && entry->pin == oldpin) { | ||
391 | entry->apic = newapic; | ||
392 | entry->pin = newpin; | ||
393 | } | ||
394 | if (!entry->next) | ||
395 | break; | ||
396 | entry = irq_2_pin + entry->next; | ||
397 | } | ||
398 | } | ||
399 | |||
363 | 400 | ||
364 | #define DO_ACTION(name,R,ACTION, FINAL) \ | 401 | #define DO_ACTION(name,R,ACTION, FINAL) \ |
365 | \ | 402 | \ |
366 | static void name##_IO_APIC_irq (unsigned int irq) \ | 403 | static void name##_IO_APIC_irq (unsigned int irq) \ |
367 | __DO_ACTION(R, ACTION, FINAL) | 404 | __DO_ACTION(R, ACTION, FINAL) |
368 | 405 | ||
369 | DO_ACTION( __mask, 0, |= 0x00010000, io_apic_sync(entry->apic) ) | 406 | /* mask = 1 */ |
370 | /* mask = 1 */ | 407 | DO_ACTION(__mask, 0, |= IO_APIC_REDIR_MASKED, io_apic_sync(entry->apic)) |
371 | DO_ACTION( __unmask, 0, &= 0xfffeffff, ) | 408 | |
372 | /* mask = 0 */ | 409 | /* mask = 0 */ |
410 | DO_ACTION(__unmask, 0, &= ~IO_APIC_REDIR_MASKED, ) | ||
373 | 411 | ||
374 | static void mask_IO_APIC_irq (unsigned int irq) | 412 | static void mask_IO_APIC_irq (unsigned int irq) |
375 | { | 413 | { |
@@ -412,6 +450,69 @@ static void clear_IO_APIC (void) | |||
412 | clear_IO_APIC_pin(apic, pin); | 450 | clear_IO_APIC_pin(apic, pin); |
413 | } | 451 | } |
414 | 452 | ||
453 | /* | ||
454 | * Saves and masks all the unmasked IO-APIC RTE's | ||
455 | */ | ||
456 | int save_mask_IO_APIC_setup(void) | ||
457 | { | ||
458 | union IO_APIC_reg_01 reg_01; | ||
459 | unsigned long flags; | ||
460 | int apic, pin; | ||
461 | |||
462 | /* | ||
463 | * The number of IO-APIC IRQ registers (== #pins): | ||
464 | */ | ||
465 | for (apic = 0; apic < nr_ioapics; apic++) { | ||
466 | spin_lock_irqsave(&ioapic_lock, flags); | ||
467 | reg_01.raw = io_apic_read(apic, 1); | ||
468 | spin_unlock_irqrestore(&ioapic_lock, flags); | ||
469 | nr_ioapic_registers[apic] = reg_01.bits.entries+1; | ||
470 | } | ||
471 | |||
472 | for (apic = 0; apic < nr_ioapics; apic++) { | ||
473 | early_ioapic_entries[apic] = | ||
474 | kzalloc(sizeof(struct IO_APIC_route_entry) * | ||
475 | nr_ioapic_registers[apic], GFP_KERNEL); | ||
476 | if (!early_ioapic_entries[apic]) | ||
477 | return -ENOMEM; | ||
478 | } | ||
479 | |||
480 | for (apic = 0; apic < nr_ioapics; apic++) | ||
481 | for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) { | ||
482 | struct IO_APIC_route_entry entry; | ||
483 | |||
484 | entry = early_ioapic_entries[apic][pin] = | ||
485 | ioapic_read_entry(apic, pin); | ||
486 | if (!entry.mask) { | ||
487 | entry.mask = 1; | ||
488 | ioapic_write_entry(apic, pin, entry); | ||
489 | } | ||
490 | } | ||
491 | return 0; | ||
492 | } | ||
493 | |||
494 | void restore_IO_APIC_setup(void) | ||
495 | { | ||
496 | int apic, pin; | ||
497 | |||
498 | for (apic = 0; apic < nr_ioapics; apic++) | ||
499 | for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) | ||
500 | ioapic_write_entry(apic, pin, | ||
501 | early_ioapic_entries[apic][pin]); | ||
502 | } | ||
503 | |||
504 | void reinit_intr_remapped_IO_APIC(int intr_remapping) | ||
505 | { | ||
506 | /* | ||
507 | * for now plain restore of previous settings. | ||
508 | * TBD: In the case of OS enabling interrupt-remapping, | ||
509 | * IO-APIC RTE's need to be setup to point to interrupt-remapping | ||
510 | * table entries. for now, do a plain restore, and wait for | ||
511 | * the setup_IO_APIC_irqs() to do proper initialization. | ||
512 | */ | ||
513 | restore_IO_APIC_setup(); | ||
514 | } | ||
515 | |||
415 | int skip_ioapic_setup; | 516 | int skip_ioapic_setup; |
416 | int ioapic_force; | 517 | int ioapic_force; |
417 | 518 | ||
@@ -430,20 +531,6 @@ static int __init disable_timer_pin_setup(char *arg) | |||
430 | } | 531 | } |
431 | __setup("disable_timer_pin_1", disable_timer_pin_setup); | 532 | __setup("disable_timer_pin_1", disable_timer_pin_setup); |
432 | 533 | ||
433 | static int __init setup_disable_8254_timer(char *s) | ||
434 | { | ||
435 | timer_over_8254 = -1; | ||
436 | return 1; | ||
437 | } | ||
438 | static int __init setup_enable_8254_timer(char *s) | ||
439 | { | ||
440 | timer_over_8254 = 2; | ||
441 | return 1; | ||
442 | } | ||
443 | |||
444 | __setup("disable_8254_timer", setup_disable_8254_timer); | ||
445 | __setup("enable_8254_timer", setup_enable_8254_timer); | ||
446 | |||
447 | 534 | ||
448 | /* | 535 | /* |
449 | * Find the IRQ entry number of a certain pin. | 536 | * Find the IRQ entry number of a certain pin. |
@@ -453,10 +540,10 @@ static int find_irq_entry(int apic, int pin, int type) | |||
453 | int i; | 540 | int i; |
454 | 541 | ||
455 | for (i = 0; i < mp_irq_entries; i++) | 542 | for (i = 0; i < mp_irq_entries; i++) |
456 | if (mp_irqs[i].mpc_irqtype == type && | 543 | if (mp_irqs[i].mp_irqtype == type && |
457 | (mp_irqs[i].mpc_dstapic == mp_ioapics[apic].mpc_apicid || | 544 | (mp_irqs[i].mp_dstapic == mp_ioapics[apic].mp_apicid || |
458 | mp_irqs[i].mpc_dstapic == MP_APIC_ALL) && | 545 | mp_irqs[i].mp_dstapic == MP_APIC_ALL) && |
459 | mp_irqs[i].mpc_dstirq == pin) | 546 | mp_irqs[i].mp_dstirq == pin) |
460 | return i; | 547 | return i; |
461 | 548 | ||
462 | return -1; | 549 | return -1; |
@@ -470,13 +557,13 @@ static int __init find_isa_irq_pin(int irq, int type) | |||
470 | int i; | 557 | int i; |
471 | 558 | ||
472 | for (i = 0; i < mp_irq_entries; i++) { | 559 | for (i = 0; i < mp_irq_entries; i++) { |
473 | int lbus = mp_irqs[i].mpc_srcbus; | 560 | int lbus = mp_irqs[i].mp_srcbus; |
474 | 561 | ||
475 | if (test_bit(lbus, mp_bus_not_pci) && | 562 | if (test_bit(lbus, mp_bus_not_pci) && |
476 | (mp_irqs[i].mpc_irqtype == type) && | 563 | (mp_irqs[i].mp_irqtype == type) && |
477 | (mp_irqs[i].mpc_srcbusirq == irq)) | 564 | (mp_irqs[i].mp_srcbusirq == irq)) |
478 | 565 | ||
479 | return mp_irqs[i].mpc_dstirq; | 566 | return mp_irqs[i].mp_dstirq; |
480 | } | 567 | } |
481 | return -1; | 568 | return -1; |
482 | } | 569 | } |
@@ -486,17 +573,17 @@ static int __init find_isa_irq_apic(int irq, int type) | |||
486 | int i; | 573 | int i; |
487 | 574 | ||
488 | for (i = 0; i < mp_irq_entries; i++) { | 575 | for (i = 0; i < mp_irq_entries; i++) { |
489 | int lbus = mp_irqs[i].mpc_srcbus; | 576 | int lbus = mp_irqs[i].mp_srcbus; |
490 | 577 | ||
491 | if (test_bit(lbus, mp_bus_not_pci) && | 578 | if (test_bit(lbus, mp_bus_not_pci) && |
492 | (mp_irqs[i].mpc_irqtype == type) && | 579 | (mp_irqs[i].mp_irqtype == type) && |
493 | (mp_irqs[i].mpc_srcbusirq == irq)) | 580 | (mp_irqs[i].mp_srcbusirq == irq)) |
494 | break; | 581 | break; |
495 | } | 582 | } |
496 | if (i < mp_irq_entries) { | 583 | if (i < mp_irq_entries) { |
497 | int apic; | 584 | int apic; |
498 | for(apic = 0; apic < nr_ioapics; apic++) { | 585 | for(apic = 0; apic < nr_ioapics; apic++) { |
499 | if (mp_ioapics[apic].mpc_apicid == mp_irqs[i].mpc_dstapic) | 586 | if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic) |
500 | return apic; | 587 | return apic; |
501 | } | 588 | } |
502 | } | 589 | } |
@@ -516,28 +603,28 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin) | |||
516 | 603 | ||
517 | apic_printk(APIC_DEBUG, "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n", | 604 | apic_printk(APIC_DEBUG, "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n", |
518 | bus, slot, pin); | 605 | bus, slot, pin); |
519 | if (mp_bus_id_to_pci_bus[bus] == -1) { | 606 | if (test_bit(bus, mp_bus_not_pci)) { |
520 | apic_printk(APIC_VERBOSE, "PCI BIOS passed nonexistent PCI bus %d!\n", bus); | 607 | apic_printk(APIC_VERBOSE, "PCI BIOS passed nonexistent PCI bus %d!\n", bus); |
521 | return -1; | 608 | return -1; |
522 | } | 609 | } |
523 | for (i = 0; i < mp_irq_entries; i++) { | 610 | for (i = 0; i < mp_irq_entries; i++) { |
524 | int lbus = mp_irqs[i].mpc_srcbus; | 611 | int lbus = mp_irqs[i].mp_srcbus; |
525 | 612 | ||
526 | for (apic = 0; apic < nr_ioapics; apic++) | 613 | for (apic = 0; apic < nr_ioapics; apic++) |
527 | if (mp_ioapics[apic].mpc_apicid == mp_irqs[i].mpc_dstapic || | 614 | if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic || |
528 | mp_irqs[i].mpc_dstapic == MP_APIC_ALL) | 615 | mp_irqs[i].mp_dstapic == MP_APIC_ALL) |
529 | break; | 616 | break; |
530 | 617 | ||
531 | if (!test_bit(lbus, mp_bus_not_pci) && | 618 | if (!test_bit(lbus, mp_bus_not_pci) && |
532 | !mp_irqs[i].mpc_irqtype && | 619 | !mp_irqs[i].mp_irqtype && |
533 | (bus == lbus) && | 620 | (bus == lbus) && |
534 | (slot == ((mp_irqs[i].mpc_srcbusirq >> 2) & 0x1f))) { | 621 | (slot == ((mp_irqs[i].mp_srcbusirq >> 2) & 0x1f))) { |
535 | int irq = pin_2_irq(i,apic,mp_irqs[i].mpc_dstirq); | 622 | int irq = pin_2_irq(i,apic,mp_irqs[i].mp_dstirq); |
536 | 623 | ||
537 | if (!(apic || IO_APIC_IRQ(irq))) | 624 | if (!(apic || IO_APIC_IRQ(irq))) |
538 | continue; | 625 | continue; |
539 | 626 | ||
540 | if (pin == (mp_irqs[i].mpc_srcbusirq & 3)) | 627 | if (pin == (mp_irqs[i].mp_srcbusirq & 3)) |
541 | return irq; | 628 | return irq; |
542 | /* | 629 | /* |
543 | * Use the first all-but-pin matching entry as a | 630 | * Use the first all-but-pin matching entry as a |
@@ -565,13 +652,13 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin) | |||
565 | 652 | ||
566 | static int MPBIOS_polarity(int idx) | 653 | static int MPBIOS_polarity(int idx) |
567 | { | 654 | { |
568 | int bus = mp_irqs[idx].mpc_srcbus; | 655 | int bus = mp_irqs[idx].mp_srcbus; |
569 | int polarity; | 656 | int polarity; |
570 | 657 | ||
571 | /* | 658 | /* |
572 | * Determine IRQ line polarity (high active or low active): | 659 | * Determine IRQ line polarity (high active or low active): |
573 | */ | 660 | */ |
574 | switch (mp_irqs[idx].mpc_irqflag & 3) | 661 | switch (mp_irqs[idx].mp_irqflag & 3) |
575 | { | 662 | { |
576 | case 0: /* conforms, ie. bus-type dependent polarity */ | 663 | case 0: /* conforms, ie. bus-type dependent polarity */ |
577 | if (test_bit(bus, mp_bus_not_pci)) | 664 | if (test_bit(bus, mp_bus_not_pci)) |
@@ -607,13 +694,13 @@ static int MPBIOS_polarity(int idx) | |||
607 | 694 | ||
608 | static int MPBIOS_trigger(int idx) | 695 | static int MPBIOS_trigger(int idx) |
609 | { | 696 | { |
610 | int bus = mp_irqs[idx].mpc_srcbus; | 697 | int bus = mp_irqs[idx].mp_srcbus; |
611 | int trigger; | 698 | int trigger; |
612 | 699 | ||
613 | /* | 700 | /* |
614 | * Determine IRQ trigger mode (edge or level sensitive): | 701 | * Determine IRQ trigger mode (edge or level sensitive): |
615 | */ | 702 | */ |
616 | switch ((mp_irqs[idx].mpc_irqflag>>2) & 3) | 703 | switch ((mp_irqs[idx].mp_irqflag>>2) & 3) |
617 | { | 704 | { |
618 | case 0: /* conforms, ie. bus-type dependent */ | 705 | case 0: /* conforms, ie. bus-type dependent */ |
619 | if (test_bit(bus, mp_bus_not_pci)) | 706 | if (test_bit(bus, mp_bus_not_pci)) |
@@ -660,16 +747,16 @@ static inline int irq_trigger(int idx) | |||
660 | static int pin_2_irq(int idx, int apic, int pin) | 747 | static int pin_2_irq(int idx, int apic, int pin) |
661 | { | 748 | { |
662 | int irq, i; | 749 | int irq, i; |
663 | int bus = mp_irqs[idx].mpc_srcbus; | 750 | int bus = mp_irqs[idx].mp_srcbus; |
664 | 751 | ||
665 | /* | 752 | /* |
666 | * Debugging check, we are in big trouble if this message pops up! | 753 | * Debugging check, we are in big trouble if this message pops up! |
667 | */ | 754 | */ |
668 | if (mp_irqs[idx].mpc_dstirq != pin) | 755 | if (mp_irqs[idx].mp_dstirq != pin) |
669 | printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n"); | 756 | printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n"); |
670 | 757 | ||
671 | if (test_bit(bus, mp_bus_not_pci)) { | 758 | if (test_bit(bus, mp_bus_not_pci)) { |
672 | irq = mp_irqs[idx].mpc_srcbusirq; | 759 | irq = mp_irqs[idx].mp_srcbusirq; |
673 | } else { | 760 | } else { |
674 | /* | 761 | /* |
675 | * PCI IRQs are mapped in order | 762 | * PCI IRQs are mapped in order |
@@ -683,6 +770,19 @@ static int pin_2_irq(int idx, int apic, int pin) | |||
683 | return irq; | 770 | return irq; |
684 | } | 771 | } |
685 | 772 | ||
773 | void lock_vector_lock(void) | ||
774 | { | ||
775 | /* Used to the online set of cpus does not change | ||
776 | * during assign_irq_vector. | ||
777 | */ | ||
778 | spin_lock(&vector_lock); | ||
779 | } | ||
780 | |||
781 | void unlock_vector_lock(void) | ||
782 | { | ||
783 | spin_unlock(&vector_lock); | ||
784 | } | ||
785 | |||
686 | static int __assign_irq_vector(int irq, cpumask_t mask) | 786 | static int __assign_irq_vector(int irq, cpumask_t mask) |
687 | { | 787 | { |
688 | /* | 788 | /* |
@@ -718,7 +818,7 @@ static int __assign_irq_vector(int irq, cpumask_t mask) | |||
718 | return 0; | 818 | return 0; |
719 | } | 819 | } |
720 | 820 | ||
721 | for_each_cpu_mask(cpu, mask) { | 821 | for_each_cpu_mask_nr(cpu, mask) { |
722 | cpumask_t domain, new_mask; | 822 | cpumask_t domain, new_mask; |
723 | int new_cpu; | 823 | int new_cpu; |
724 | int vector, offset; | 824 | int vector, offset; |
@@ -730,7 +830,7 @@ static int __assign_irq_vector(int irq, cpumask_t mask) | |||
730 | offset = current_offset; | 830 | offset = current_offset; |
731 | next: | 831 | next: |
732 | vector += 8; | 832 | vector += 8; |
733 | if (vector >= FIRST_SYSTEM_VECTOR) { | 833 | if (vector >= first_system_vector) { |
734 | /* If we run out of vectors on large boxen, must share them. */ | 834 | /* If we run out of vectors on large boxen, must share them. */ |
735 | offset = (offset + 1) % 8; | 835 | offset = (offset + 1) % 8; |
736 | vector = FIRST_DEVICE_VECTOR + offset; | 836 | vector = FIRST_DEVICE_VECTOR + offset; |
@@ -739,7 +839,7 @@ next: | |||
739 | continue; | 839 | continue; |
740 | if (vector == IA32_SYSCALL_VECTOR) | 840 | if (vector == IA32_SYSCALL_VECTOR) |
741 | goto next; | 841 | goto next; |
742 | for_each_cpu_mask(new_cpu, new_mask) | 842 | for_each_cpu_mask_nr(new_cpu, new_mask) |
743 | if (per_cpu(vector_irq, new_cpu)[vector] != -1) | 843 | if (per_cpu(vector_irq, new_cpu)[vector] != -1) |
744 | goto next; | 844 | goto next; |
745 | /* Found one! */ | 845 | /* Found one! */ |
@@ -749,7 +849,7 @@ next: | |||
749 | cfg->move_in_progress = 1; | 849 | cfg->move_in_progress = 1; |
750 | cfg->old_domain = cfg->domain; | 850 | cfg->old_domain = cfg->domain; |
751 | } | 851 | } |
752 | for_each_cpu_mask(new_cpu, new_mask) | 852 | for_each_cpu_mask_nr(new_cpu, new_mask) |
753 | per_cpu(vector_irq, new_cpu)[vector] = irq; | 853 | per_cpu(vector_irq, new_cpu)[vector] = irq; |
754 | cfg->vector = vector; | 854 | cfg->vector = vector; |
755 | cfg->domain = domain; | 855 | cfg->domain = domain; |
@@ -781,7 +881,7 @@ static void __clear_irq_vector(int irq) | |||
781 | 881 | ||
782 | vector = cfg->vector; | 882 | vector = cfg->vector; |
783 | cpus_and(mask, cfg->domain, cpu_online_map); | 883 | cpus_and(mask, cfg->domain, cpu_online_map); |
784 | for_each_cpu_mask(cpu, mask) | 884 | for_each_cpu_mask_nr(cpu, mask) |
785 | per_cpu(vector_irq, cpu)[vector] = -1; | 885 | per_cpu(vector_irq, cpu)[vector] = -1; |
786 | 886 | ||
787 | cfg->vector = 0; | 887 | cfg->vector = 0; |
@@ -811,20 +911,99 @@ void __setup_vector_irq(int cpu) | |||
811 | } | 911 | } |
812 | } | 912 | } |
813 | 913 | ||
814 | |||
815 | static struct irq_chip ioapic_chip; | 914 | static struct irq_chip ioapic_chip; |
915 | #ifdef CONFIG_INTR_REMAP | ||
916 | static struct irq_chip ir_ioapic_chip; | ||
917 | #endif | ||
816 | 918 | ||
817 | static void ioapic_register_intr(int irq, unsigned long trigger) | 919 | static void ioapic_register_intr(int irq, unsigned long trigger) |
818 | { | 920 | { |
819 | if (trigger) { | 921 | if (trigger) |
820 | irq_desc[irq].status |= IRQ_LEVEL; | 922 | irq_desc[irq].status |= IRQ_LEVEL; |
821 | set_irq_chip_and_handler_name(irq, &ioapic_chip, | 923 | else |
822 | handle_fasteoi_irq, "fasteoi"); | ||
823 | } else { | ||
824 | irq_desc[irq].status &= ~IRQ_LEVEL; | 924 | irq_desc[irq].status &= ~IRQ_LEVEL; |
925 | |||
926 | #ifdef CONFIG_INTR_REMAP | ||
927 | if (irq_remapped(irq)) { | ||
928 | irq_desc[irq].status |= IRQ_MOVE_PCNTXT; | ||
929 | if (trigger) | ||
930 | set_irq_chip_and_handler_name(irq, &ir_ioapic_chip, | ||
931 | handle_fasteoi_irq, | ||
932 | "fasteoi"); | ||
933 | else | ||
934 | set_irq_chip_and_handler_name(irq, &ir_ioapic_chip, | ||
935 | handle_edge_irq, "edge"); | ||
936 | return; | ||
937 | } | ||
938 | #endif | ||
939 | if (trigger) | ||
940 | set_irq_chip_and_handler_name(irq, &ioapic_chip, | ||
941 | handle_fasteoi_irq, | ||
942 | "fasteoi"); | ||
943 | else | ||
825 | set_irq_chip_and_handler_name(irq, &ioapic_chip, | 944 | set_irq_chip_and_handler_name(irq, &ioapic_chip, |
826 | handle_edge_irq, "edge"); | 945 | handle_edge_irq, "edge"); |
946 | } | ||
947 | |||
948 | static int setup_ioapic_entry(int apic, int irq, | ||
949 | struct IO_APIC_route_entry *entry, | ||
950 | unsigned int destination, int trigger, | ||
951 | int polarity, int vector) | ||
952 | { | ||
953 | /* | ||
954 | * add it to the IO-APIC irq-routing table: | ||
955 | */ | ||
956 | memset(entry,0,sizeof(*entry)); | ||
957 | |||
958 | #ifdef CONFIG_INTR_REMAP | ||
959 | if (intr_remapping_enabled) { | ||
960 | struct intel_iommu *iommu = map_ioapic_to_ir(apic); | ||
961 | struct irte irte; | ||
962 | struct IR_IO_APIC_route_entry *ir_entry = | ||
963 | (struct IR_IO_APIC_route_entry *) entry; | ||
964 | int index; | ||
965 | |||
966 | if (!iommu) | ||
967 | panic("No mapping iommu for ioapic %d\n", apic); | ||
968 | |||
969 | index = alloc_irte(iommu, irq, 1); | ||
970 | if (index < 0) | ||
971 | panic("Failed to allocate IRTE for ioapic %d\n", apic); | ||
972 | |||
973 | memset(&irte, 0, sizeof(irte)); | ||
974 | |||
975 | irte.present = 1; | ||
976 | irte.dst_mode = INT_DEST_MODE; | ||
977 | irte.trigger_mode = trigger; | ||
978 | irte.dlvry_mode = INT_DELIVERY_MODE; | ||
979 | irte.vector = vector; | ||
980 | irte.dest_id = IRTE_DEST(destination); | ||
981 | |||
982 | modify_irte(irq, &irte); | ||
983 | |||
984 | ir_entry->index2 = (index >> 15) & 0x1; | ||
985 | ir_entry->zero = 0; | ||
986 | ir_entry->format = 1; | ||
987 | ir_entry->index = (index & 0x7fff); | ||
988 | } else | ||
989 | #endif | ||
990 | { | ||
991 | entry->delivery_mode = INT_DELIVERY_MODE; | ||
992 | entry->dest_mode = INT_DEST_MODE; | ||
993 | entry->dest = destination; | ||
827 | } | 994 | } |
995 | |||
996 | entry->mask = 0; /* enable IRQ */ | ||
997 | entry->trigger = trigger; | ||
998 | entry->polarity = polarity; | ||
999 | entry->vector = vector; | ||
1000 | |||
1001 | /* Mask level triggered irqs. | ||
1002 | * Use IRQ_DELAYED_DISABLE for edge triggered irqs. | ||
1003 | */ | ||
1004 | if (trigger) | ||
1005 | entry->mask = 1; | ||
1006 | return 0; | ||
828 | } | 1007 | } |
829 | 1008 | ||
830 | static void setup_IO_APIC_irq(int apic, int pin, unsigned int irq, | 1009 | static void setup_IO_APIC_irq(int apic, int pin, unsigned int irq, |
@@ -846,27 +1025,18 @@ static void setup_IO_APIC_irq(int apic, int pin, unsigned int irq, | |||
846 | apic_printk(APIC_VERBOSE,KERN_DEBUG | 1025 | apic_printk(APIC_VERBOSE,KERN_DEBUG |
847 | "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> " | 1026 | "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> " |
848 | "IRQ %d Mode:%i Active:%i)\n", | 1027 | "IRQ %d Mode:%i Active:%i)\n", |
849 | apic, mp_ioapics[apic].mpc_apicid, pin, cfg->vector, | 1028 | apic, mp_ioapics[apic].mp_apicid, pin, cfg->vector, |
850 | irq, trigger, polarity); | 1029 | irq, trigger, polarity); |
851 | 1030 | ||
852 | /* | ||
853 | * add it to the IO-APIC irq-routing table: | ||
854 | */ | ||
855 | memset(&entry,0,sizeof(entry)); | ||
856 | 1031 | ||
857 | entry.delivery_mode = INT_DELIVERY_MODE; | 1032 | if (setup_ioapic_entry(mp_ioapics[apic].mp_apicid, irq, &entry, |
858 | entry.dest_mode = INT_DEST_MODE; | 1033 | cpu_mask_to_apicid(mask), trigger, polarity, |
859 | entry.dest = cpu_mask_to_apicid(mask); | 1034 | cfg->vector)) { |
860 | entry.mask = 0; /* enable IRQ */ | 1035 | printk("Failed to setup ioapic entry for ioapic %d, pin %d\n", |
861 | entry.trigger = trigger; | 1036 | mp_ioapics[apic].mp_apicid, pin); |
862 | entry.polarity = polarity; | 1037 | __clear_irq_vector(irq); |
863 | entry.vector = cfg->vector; | 1038 | return; |
864 | 1039 | } | |
865 | /* Mask level triggered irqs. | ||
866 | * Use IRQ_DELAYED_DISABLE for edge triggered irqs. | ||
867 | */ | ||
868 | if (trigger) | ||
869 | entry.mask = 1; | ||
870 | 1040 | ||
871 | ioapic_register_intr(irq, trigger); | 1041 | ioapic_register_intr(irq, trigger); |
872 | if (irq < 16) | 1042 | if (irq < 16) |
@@ -887,10 +1057,10 @@ static void __init setup_IO_APIC_irqs(void) | |||
887 | idx = find_irq_entry(apic,pin,mp_INT); | 1057 | idx = find_irq_entry(apic,pin,mp_INT); |
888 | if (idx == -1) { | 1058 | if (idx == -1) { |
889 | if (first_notcon) { | 1059 | if (first_notcon) { |
890 | apic_printk(APIC_VERBOSE, KERN_DEBUG " IO-APIC (apicid-pin) %d-%d", mp_ioapics[apic].mpc_apicid, pin); | 1060 | apic_printk(APIC_VERBOSE, KERN_DEBUG " IO-APIC (apicid-pin) %d-%d", mp_ioapics[apic].mp_apicid, pin); |
891 | first_notcon = 0; | 1061 | first_notcon = 0; |
892 | } else | 1062 | } else |
893 | apic_printk(APIC_VERBOSE, ", %d-%d", mp_ioapics[apic].mpc_apicid, pin); | 1063 | apic_printk(APIC_VERBOSE, ", %d-%d", mp_ioapics[apic].mp_apicid, pin); |
894 | continue; | 1064 | continue; |
895 | } | 1065 | } |
896 | if (!first_notcon) { | 1066 | if (!first_notcon) { |
@@ -911,26 +1081,24 @@ static void __init setup_IO_APIC_irqs(void) | |||
911 | } | 1081 | } |
912 | 1082 | ||
913 | /* | 1083 | /* |
914 | * Set up the 8259A-master output pin as broadcast to all | 1084 | * Set up the timer pin, possibly with the 8259A-master behind. |
915 | * CPUs. | ||
916 | */ | 1085 | */ |
917 | static void __init setup_ExtINT_IRQ0_pin(unsigned int apic, unsigned int pin, int vector) | 1086 | static void __init setup_timer_IRQ0_pin(unsigned int apic, unsigned int pin, |
1087 | int vector) | ||
918 | { | 1088 | { |
919 | struct IO_APIC_route_entry entry; | 1089 | struct IO_APIC_route_entry entry; |
920 | 1090 | ||
921 | memset(&entry, 0, sizeof(entry)); | 1091 | if (intr_remapping_enabled) |
922 | 1092 | return; | |
923 | disable_8259A_irq(0); | ||
924 | 1093 | ||
925 | /* mask LVT0 */ | 1094 | memset(&entry, 0, sizeof(entry)); |
926 | apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT); | ||
927 | 1095 | ||
928 | /* | 1096 | /* |
929 | * We use logical delivery to get the timer IRQ | 1097 | * We use logical delivery to get the timer IRQ |
930 | * to the first CPU. | 1098 | * to the first CPU. |
931 | */ | 1099 | */ |
932 | entry.dest_mode = INT_DEST_MODE; | 1100 | entry.dest_mode = INT_DEST_MODE; |
933 | entry.mask = 0; /* unmask IRQ now */ | 1101 | entry.mask = 1; /* mask IRQ now */ |
934 | entry.dest = cpu_mask_to_apicid(TARGET_CPUS); | 1102 | entry.dest = cpu_mask_to_apicid(TARGET_CPUS); |
935 | entry.delivery_mode = INT_DELIVERY_MODE; | 1103 | entry.delivery_mode = INT_DELIVERY_MODE; |
936 | entry.polarity = 0; | 1104 | entry.polarity = 0; |
@@ -939,7 +1107,7 @@ static void __init setup_ExtINT_IRQ0_pin(unsigned int apic, unsigned int pin, in | |||
939 | 1107 | ||
940 | /* | 1108 | /* |
941 | * The timer IRQ doesn't have to know that behind the | 1109 | * The timer IRQ doesn't have to know that behind the |
942 | * scene we have a 8259A-master in AEOI mode ... | 1110 | * scene we may have a 8259A-master in AEOI mode ... |
943 | */ | 1111 | */ |
944 | set_irq_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq, "edge"); | 1112 | set_irq_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq, "edge"); |
945 | 1113 | ||
@@ -947,11 +1115,10 @@ static void __init setup_ExtINT_IRQ0_pin(unsigned int apic, unsigned int pin, in | |||
947 | * Add it to the IO-APIC irq-routing table: | 1115 | * Add it to the IO-APIC irq-routing table: |
948 | */ | 1116 | */ |
949 | ioapic_write_entry(apic, pin, entry); | 1117 | ioapic_write_entry(apic, pin, entry); |
950 | |||
951 | enable_8259A_irq(0); | ||
952 | } | 1118 | } |
953 | 1119 | ||
954 | void __apicdebuginit print_IO_APIC(void) | 1120 | |
1121 | __apicdebuginit(void) print_IO_APIC(void) | ||
955 | { | 1122 | { |
956 | int apic, i; | 1123 | int apic, i; |
957 | union IO_APIC_reg_00 reg_00; | 1124 | union IO_APIC_reg_00 reg_00; |
@@ -965,7 +1132,7 @@ void __apicdebuginit print_IO_APIC(void) | |||
965 | printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries); | 1132 | printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries); |
966 | for (i = 0; i < nr_ioapics; i++) | 1133 | for (i = 0; i < nr_ioapics; i++) |
967 | printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n", | 1134 | printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n", |
968 | mp_ioapics[i].mpc_apicid, nr_ioapic_registers[i]); | 1135 | mp_ioapics[i].mp_apicid, nr_ioapic_registers[i]); |
969 | 1136 | ||
970 | /* | 1137 | /* |
971 | * We are a bit conservative about what we expect. We have to | 1138 | * We are a bit conservative about what we expect. We have to |
@@ -983,7 +1150,7 @@ void __apicdebuginit print_IO_APIC(void) | |||
983 | spin_unlock_irqrestore(&ioapic_lock, flags); | 1150 | spin_unlock_irqrestore(&ioapic_lock, flags); |
984 | 1151 | ||
985 | printk("\n"); | 1152 | printk("\n"); |
986 | printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].mpc_apicid); | 1153 | printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].mp_apicid); |
987 | printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw); | 1154 | printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw); |
988 | printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID); | 1155 | printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID); |
989 | 1156 | ||
@@ -1045,9 +1212,7 @@ void __apicdebuginit print_IO_APIC(void) | |||
1045 | return; | 1212 | return; |
1046 | } | 1213 | } |
1047 | 1214 | ||
1048 | #if 0 | 1215 | __apicdebuginit(void) print_APIC_bitfield(int base) |
1049 | |||
1050 | static __apicdebuginit void print_APIC_bitfield (int base) | ||
1051 | { | 1216 | { |
1052 | unsigned int v; | 1217 | unsigned int v; |
1053 | int i, j; | 1218 | int i, j; |
@@ -1068,16 +1233,18 @@ static __apicdebuginit void print_APIC_bitfield (int base) | |||
1068 | } | 1233 | } |
1069 | } | 1234 | } |
1070 | 1235 | ||
1071 | void __apicdebuginit print_local_APIC(void * dummy) | 1236 | __apicdebuginit(void) print_local_APIC(void *dummy) |
1072 | { | 1237 | { |
1073 | unsigned int v, ver, maxlvt; | 1238 | unsigned int v, ver, maxlvt; |
1239 | unsigned long icr; | ||
1074 | 1240 | ||
1075 | if (apic_verbosity == APIC_QUIET) | 1241 | if (apic_verbosity == APIC_QUIET) |
1076 | return; | 1242 | return; |
1077 | 1243 | ||
1078 | printk("\n" KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n", | 1244 | printk("\n" KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n", |
1079 | smp_processor_id(), hard_smp_processor_id()); | 1245 | smp_processor_id(), hard_smp_processor_id()); |
1080 | printk(KERN_INFO "... APIC ID: %08x (%01x)\n", v, GET_APIC_ID(read_apic_id())); | 1246 | v = apic_read(APIC_ID); |
1247 | printk(KERN_INFO "... APIC ID: %08x (%01x)\n", v, read_apic_id()); | ||
1081 | v = apic_read(APIC_LVR); | 1248 | v = apic_read(APIC_LVR); |
1082 | printk(KERN_INFO "... APIC VERSION: %08x\n", v); | 1249 | printk(KERN_INFO "... APIC VERSION: %08x\n", v); |
1083 | ver = GET_APIC_VERSION(v); | 1250 | ver = GET_APIC_VERSION(v); |
@@ -1113,10 +1280,9 @@ void __apicdebuginit print_local_APIC(void * dummy) | |||
1113 | v = apic_read(APIC_ESR); | 1280 | v = apic_read(APIC_ESR); |
1114 | printk(KERN_DEBUG "... APIC ESR: %08x\n", v); | 1281 | printk(KERN_DEBUG "... APIC ESR: %08x\n", v); |
1115 | 1282 | ||
1116 | v = apic_read(APIC_ICR); | 1283 | icr = apic_icr_read(); |
1117 | printk(KERN_DEBUG "... APIC ICR: %08x\n", v); | 1284 | printk(KERN_DEBUG "... APIC ICR: %08x\n", (u32)icr); |
1118 | v = apic_read(APIC_ICR2); | 1285 | printk(KERN_DEBUG "... APIC ICR2: %08x\n", (u32)(icr >> 32)); |
1119 | printk(KERN_DEBUG "... APIC ICR2: %08x\n", v); | ||
1120 | 1286 | ||
1121 | v = apic_read(APIC_LVTT); | 1287 | v = apic_read(APIC_LVTT); |
1122 | printk(KERN_DEBUG "... APIC LVTT: %08x\n", v); | 1288 | printk(KERN_DEBUG "... APIC LVTT: %08x\n", v); |
@@ -1144,12 +1310,12 @@ void __apicdebuginit print_local_APIC(void * dummy) | |||
1144 | printk("\n"); | 1310 | printk("\n"); |
1145 | } | 1311 | } |
1146 | 1312 | ||
1147 | void print_all_local_APICs (void) | 1313 | __apicdebuginit(void) print_all_local_APICs(void) |
1148 | { | 1314 | { |
1149 | on_each_cpu(print_local_APIC, NULL, 1, 1); | 1315 | on_each_cpu(print_local_APIC, NULL, 1); |
1150 | } | 1316 | } |
1151 | 1317 | ||
1152 | void __apicdebuginit print_PIC(void) | 1318 | __apicdebuginit(void) print_PIC(void) |
1153 | { | 1319 | { |
1154 | unsigned int v; | 1320 | unsigned int v; |
1155 | unsigned long flags; | 1321 | unsigned long flags; |
@@ -1181,7 +1347,17 @@ void __apicdebuginit print_PIC(void) | |||
1181 | printk(KERN_DEBUG "... PIC ELCR: %04x\n", v); | 1347 | printk(KERN_DEBUG "... PIC ELCR: %04x\n", v); |
1182 | } | 1348 | } |
1183 | 1349 | ||
1184 | #endif /* 0 */ | 1350 | __apicdebuginit(int) print_all_ICs(void) |
1351 | { | ||
1352 | print_PIC(); | ||
1353 | print_all_local_APICs(); | ||
1354 | print_IO_APIC(); | ||
1355 | |||
1356 | return 0; | ||
1357 | } | ||
1358 | |||
1359 | fs_initcall(print_all_ICs); | ||
1360 | |||
1185 | 1361 | ||
1186 | void __init enable_IO_APIC(void) | 1362 | void __init enable_IO_APIC(void) |
1187 | { | 1363 | { |
@@ -1271,7 +1447,7 @@ void disable_IO_APIC(void) | |||
1271 | entry.dest_mode = 0; /* Physical */ | 1447 | entry.dest_mode = 0; /* Physical */ |
1272 | entry.delivery_mode = dest_ExtINT; /* ExtInt */ | 1448 | entry.delivery_mode = dest_ExtINT; /* ExtInt */ |
1273 | entry.vector = 0; | 1449 | entry.vector = 0; |
1274 | entry.dest = GET_APIC_ID(read_apic_id()); | 1450 | entry.dest = read_apic_id(); |
1275 | 1451 | ||
1276 | /* | 1452 | /* |
1277 | * Add it to the IO-APIC irq-routing table: | 1453 | * Add it to the IO-APIC irq-routing table: |
@@ -1358,12 +1534,10 @@ static unsigned int startup_ioapic_irq(unsigned int irq) | |||
1358 | static int ioapic_retrigger_irq(unsigned int irq) | 1534 | static int ioapic_retrigger_irq(unsigned int irq) |
1359 | { | 1535 | { |
1360 | struct irq_cfg *cfg = &irq_cfg[irq]; | 1536 | struct irq_cfg *cfg = &irq_cfg[irq]; |
1361 | cpumask_t mask; | ||
1362 | unsigned long flags; | 1537 | unsigned long flags; |
1363 | 1538 | ||
1364 | spin_lock_irqsave(&vector_lock, flags); | 1539 | spin_lock_irqsave(&vector_lock, flags); |
1365 | mask = cpumask_of_cpu(first_cpu(cfg->domain)); | 1540 | send_IPI_mask(cpumask_of_cpu(first_cpu(cfg->domain)), cfg->vector); |
1366 | send_IPI_mask(mask, cfg->vector); | ||
1367 | spin_unlock_irqrestore(&vector_lock, flags); | 1541 | spin_unlock_irqrestore(&vector_lock, flags); |
1368 | 1542 | ||
1369 | return 1; | 1543 | return 1; |
@@ -1379,6 +1553,147 @@ static int ioapic_retrigger_irq(unsigned int irq) | |||
1379 | */ | 1553 | */ |
1380 | 1554 | ||
1381 | #ifdef CONFIG_SMP | 1555 | #ifdef CONFIG_SMP |
1556 | |||
1557 | #ifdef CONFIG_INTR_REMAP | ||
1558 | static void ir_irq_migration(struct work_struct *work); | ||
1559 | |||
1560 | static DECLARE_DELAYED_WORK(ir_migration_work, ir_irq_migration); | ||
1561 | |||
1562 | /* | ||
1563 | * Migrate the IO-APIC irq in the presence of intr-remapping. | ||
1564 | * | ||
1565 | * For edge triggered, irq migration is a simple atomic update(of vector | ||
1566 | * and cpu destination) of IRTE and flush the hardware cache. | ||
1567 | * | ||
1568 | * For level triggered, we need to modify the io-apic RTE aswell with the update | ||
1569 | * vector information, along with modifying IRTE with vector and destination. | ||
1570 | * So irq migration for level triggered is little bit more complex compared to | ||
1571 | * edge triggered migration. But the good news is, we use the same algorithm | ||
1572 | * for level triggered migration as we have today, only difference being, | ||
1573 | * we now initiate the irq migration from process context instead of the | ||
1574 | * interrupt context. | ||
1575 | * | ||
1576 | * In future, when we do a directed EOI (combined with cpu EOI broadcast | ||
1577 | * suppression) to the IO-APIC, level triggered irq migration will also be | ||
1578 | * as simple as edge triggered migration and we can do the irq migration | ||
1579 | * with a simple atomic update to IO-APIC RTE. | ||
1580 | */ | ||
1581 | static void migrate_ioapic_irq(int irq, cpumask_t mask) | ||
1582 | { | ||
1583 | struct irq_cfg *cfg = irq_cfg + irq; | ||
1584 | struct irq_desc *desc = irq_desc + irq; | ||
1585 | cpumask_t tmp, cleanup_mask; | ||
1586 | struct irte irte; | ||
1587 | int modify_ioapic_rte = desc->status & IRQ_LEVEL; | ||
1588 | unsigned int dest; | ||
1589 | unsigned long flags; | ||
1590 | |||
1591 | cpus_and(tmp, mask, cpu_online_map); | ||
1592 | if (cpus_empty(tmp)) | ||
1593 | return; | ||
1594 | |||
1595 | if (get_irte(irq, &irte)) | ||
1596 | return; | ||
1597 | |||
1598 | if (assign_irq_vector(irq, mask)) | ||
1599 | return; | ||
1600 | |||
1601 | cpus_and(tmp, cfg->domain, mask); | ||
1602 | dest = cpu_mask_to_apicid(tmp); | ||
1603 | |||
1604 | if (modify_ioapic_rte) { | ||
1605 | spin_lock_irqsave(&ioapic_lock, flags); | ||
1606 | __target_IO_APIC_irq(irq, dest, cfg->vector); | ||
1607 | spin_unlock_irqrestore(&ioapic_lock, flags); | ||
1608 | } | ||
1609 | |||
1610 | irte.vector = cfg->vector; | ||
1611 | irte.dest_id = IRTE_DEST(dest); | ||
1612 | |||
1613 | /* | ||
1614 | * Modified the IRTE and flushes the Interrupt entry cache. | ||
1615 | */ | ||
1616 | modify_irte(irq, &irte); | ||
1617 | |||
1618 | if (cfg->move_in_progress) { | ||
1619 | cpus_and(cleanup_mask, cfg->old_domain, cpu_online_map); | ||
1620 | cfg->move_cleanup_count = cpus_weight(cleanup_mask); | ||
1621 | send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR); | ||
1622 | cfg->move_in_progress = 0; | ||
1623 | } | ||
1624 | |||
1625 | irq_desc[irq].affinity = mask; | ||
1626 | } | ||
1627 | |||
1628 | static int migrate_irq_remapped_level(int irq) | ||
1629 | { | ||
1630 | int ret = -1; | ||
1631 | |||
1632 | mask_IO_APIC_irq(irq); | ||
1633 | |||
1634 | if (io_apic_level_ack_pending(irq)) { | ||
1635 | /* | ||
1636 | * Interrupt in progress. Migrating irq now will change the | ||
1637 | * vector information in the IO-APIC RTE and that will confuse | ||
1638 | * the EOI broadcast performed by cpu. | ||
1639 | * So, delay the irq migration to the next instance. | ||
1640 | */ | ||
1641 | schedule_delayed_work(&ir_migration_work, 1); | ||
1642 | goto unmask; | ||
1643 | } | ||
1644 | |||
1645 | /* everthing is clear. we have right of way */ | ||
1646 | migrate_ioapic_irq(irq, irq_desc[irq].pending_mask); | ||
1647 | |||
1648 | ret = 0; | ||
1649 | irq_desc[irq].status &= ~IRQ_MOVE_PENDING; | ||
1650 | cpus_clear(irq_desc[irq].pending_mask); | ||
1651 | |||
1652 | unmask: | ||
1653 | unmask_IO_APIC_irq(irq); | ||
1654 | return ret; | ||
1655 | } | ||
1656 | |||
1657 | static void ir_irq_migration(struct work_struct *work) | ||
1658 | { | ||
1659 | int irq; | ||
1660 | |||
1661 | for (irq = 0; irq < NR_IRQS; irq++) { | ||
1662 | struct irq_desc *desc = irq_desc + irq; | ||
1663 | if (desc->status & IRQ_MOVE_PENDING) { | ||
1664 | unsigned long flags; | ||
1665 | |||
1666 | spin_lock_irqsave(&desc->lock, flags); | ||
1667 | if (!desc->chip->set_affinity || | ||
1668 | !(desc->status & IRQ_MOVE_PENDING)) { | ||
1669 | desc->status &= ~IRQ_MOVE_PENDING; | ||
1670 | spin_unlock_irqrestore(&desc->lock, flags); | ||
1671 | continue; | ||
1672 | } | ||
1673 | |||
1674 | desc->chip->set_affinity(irq, | ||
1675 | irq_desc[irq].pending_mask); | ||
1676 | spin_unlock_irqrestore(&desc->lock, flags); | ||
1677 | } | ||
1678 | } | ||
1679 | } | ||
1680 | |||
1681 | /* | ||
1682 | * Migrates the IRQ destination in the process context. | ||
1683 | */ | ||
1684 | static void set_ir_ioapic_affinity_irq(unsigned int irq, cpumask_t mask) | ||
1685 | { | ||
1686 | if (irq_desc[irq].status & IRQ_LEVEL) { | ||
1687 | irq_desc[irq].status |= IRQ_MOVE_PENDING; | ||
1688 | irq_desc[irq].pending_mask = mask; | ||
1689 | migrate_irq_remapped_level(irq); | ||
1690 | return; | ||
1691 | } | ||
1692 | |||
1693 | migrate_ioapic_irq(irq, mask); | ||
1694 | } | ||
1695 | #endif | ||
1696 | |||
1382 | asmlinkage void smp_irq_move_cleanup_interrupt(void) | 1697 | asmlinkage void smp_irq_move_cleanup_interrupt(void) |
1383 | { | 1698 | { |
1384 | unsigned vector, me; | 1699 | unsigned vector, me; |
@@ -1435,6 +1750,17 @@ static void irq_complete_move(unsigned int irq) | |||
1435 | #else | 1750 | #else |
1436 | static inline void irq_complete_move(unsigned int irq) {} | 1751 | static inline void irq_complete_move(unsigned int irq) {} |
1437 | #endif | 1752 | #endif |
1753 | #ifdef CONFIG_INTR_REMAP | ||
1754 | static void ack_x2apic_level(unsigned int irq) | ||
1755 | { | ||
1756 | ack_x2APIC_irq(); | ||
1757 | } | ||
1758 | |||
1759 | static void ack_x2apic_edge(unsigned int irq) | ||
1760 | { | ||
1761 | ack_x2APIC_irq(); | ||
1762 | } | ||
1763 | #endif | ||
1438 | 1764 | ||
1439 | static void ack_apic_edge(unsigned int irq) | 1765 | static void ack_apic_edge(unsigned int irq) |
1440 | { | 1766 | { |
@@ -1509,6 +1835,21 @@ static struct irq_chip ioapic_chip __read_mostly = { | |||
1509 | .retrigger = ioapic_retrigger_irq, | 1835 | .retrigger = ioapic_retrigger_irq, |
1510 | }; | 1836 | }; |
1511 | 1837 | ||
1838 | #ifdef CONFIG_INTR_REMAP | ||
1839 | static struct irq_chip ir_ioapic_chip __read_mostly = { | ||
1840 | .name = "IR-IO-APIC", | ||
1841 | .startup = startup_ioapic_irq, | ||
1842 | .mask = mask_IO_APIC_irq, | ||
1843 | .unmask = unmask_IO_APIC_irq, | ||
1844 | .ack = ack_x2apic_edge, | ||
1845 | .eoi = ack_x2apic_level, | ||
1846 | #ifdef CONFIG_SMP | ||
1847 | .set_affinity = set_ir_ioapic_affinity_irq, | ||
1848 | #endif | ||
1849 | .retrigger = ioapic_retrigger_irq, | ||
1850 | }; | ||
1851 | #endif | ||
1852 | |||
1512 | static inline void init_IO_APIC_traps(void) | 1853 | static inline void init_IO_APIC_traps(void) |
1513 | { | 1854 | { |
1514 | int irq; | 1855 | int irq; |
@@ -1540,7 +1881,7 @@ static inline void init_IO_APIC_traps(void) | |||
1540 | } | 1881 | } |
1541 | } | 1882 | } |
1542 | 1883 | ||
1543 | static void enable_lapic_irq (unsigned int irq) | 1884 | static void unmask_lapic_irq(unsigned int irq) |
1544 | { | 1885 | { |
1545 | unsigned long v; | 1886 | unsigned long v; |
1546 | 1887 | ||
@@ -1548,7 +1889,7 @@ static void enable_lapic_irq (unsigned int irq) | |||
1548 | apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED); | 1889 | apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED); |
1549 | } | 1890 | } |
1550 | 1891 | ||
1551 | static void disable_lapic_irq (unsigned int irq) | 1892 | static void mask_lapic_irq(unsigned int irq) |
1552 | { | 1893 | { |
1553 | unsigned long v; | 1894 | unsigned long v; |
1554 | 1895 | ||
@@ -1561,19 +1902,20 @@ static void ack_lapic_irq (unsigned int irq) | |||
1561 | ack_APIC_irq(); | 1902 | ack_APIC_irq(); |
1562 | } | 1903 | } |
1563 | 1904 | ||
1564 | static void end_lapic_irq (unsigned int i) { /* nothing */ } | 1905 | static struct irq_chip lapic_chip __read_mostly = { |
1565 | 1906 | .name = "local-APIC", | |
1566 | static struct hw_interrupt_type lapic_irq_type __read_mostly = { | 1907 | .mask = mask_lapic_irq, |
1567 | .name = "local-APIC", | 1908 | .unmask = unmask_lapic_irq, |
1568 | .typename = "local-APIC-edge", | 1909 | .ack = ack_lapic_irq, |
1569 | .startup = NULL, /* startup_irq() not used for IRQ0 */ | ||
1570 | .shutdown = NULL, /* shutdown_irq() not used for IRQ0 */ | ||
1571 | .enable = enable_lapic_irq, | ||
1572 | .disable = disable_lapic_irq, | ||
1573 | .ack = ack_lapic_irq, | ||
1574 | .end = end_lapic_irq, | ||
1575 | }; | 1910 | }; |
1576 | 1911 | ||
1912 | static void lapic_register_intr(int irq) | ||
1913 | { | ||
1914 | irq_desc[irq].status &= ~IRQ_LEVEL; | ||
1915 | set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq, | ||
1916 | "edge"); | ||
1917 | } | ||
1918 | |||
1577 | static void __init setup_nmi(void) | 1919 | static void __init setup_nmi(void) |
1578 | { | 1920 | { |
1579 | /* | 1921 | /* |
@@ -1659,6 +2001,7 @@ static inline void __init check_timer(void) | |||
1659 | struct irq_cfg *cfg = irq_cfg + 0; | 2001 | struct irq_cfg *cfg = irq_cfg + 0; |
1660 | int apic1, pin1, apic2, pin2; | 2002 | int apic1, pin1, apic2, pin2; |
1661 | unsigned long flags; | 2003 | unsigned long flags; |
2004 | int no_pin1 = 0; | ||
1662 | 2005 | ||
1663 | local_irq_save(flags); | 2006 | local_irq_save(flags); |
1664 | 2007 | ||
@@ -1669,34 +2012,50 @@ static inline void __init check_timer(void) | |||
1669 | assign_irq_vector(0, TARGET_CPUS); | 2012 | assign_irq_vector(0, TARGET_CPUS); |
1670 | 2013 | ||
1671 | /* | 2014 | /* |
1672 | * Subtle, code in do_timer_interrupt() expects an AEOI | 2015 | * As IRQ0 is to be enabled in the 8259A, the virtual |
1673 | * mode for the 8259A whenever interrupts are routed | 2016 | * wire has to be disabled in the local APIC. |
1674 | * through I/O APICs. Also IRQ0 has to be enabled in | ||
1675 | * the 8259A which implies the virtual wire has to be | ||
1676 | * disabled in the local APIC. | ||
1677 | */ | 2017 | */ |
1678 | apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT); | 2018 | apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT); |
1679 | init_8259A(1); | 2019 | init_8259A(1); |
1680 | if (timer_over_8254 > 0) | ||
1681 | enable_8259A_irq(0); | ||
1682 | 2020 | ||
1683 | pin1 = find_isa_irq_pin(0, mp_INT); | 2021 | pin1 = find_isa_irq_pin(0, mp_INT); |
1684 | apic1 = find_isa_irq_apic(0, mp_INT); | 2022 | apic1 = find_isa_irq_apic(0, mp_INT); |
1685 | pin2 = ioapic_i8259.pin; | 2023 | pin2 = ioapic_i8259.pin; |
1686 | apic2 = ioapic_i8259.apic; | 2024 | apic2 = ioapic_i8259.apic; |
1687 | 2025 | ||
1688 | apic_printk(APIC_VERBOSE,KERN_INFO "..TIMER: vector=0x%02X apic1=%d pin1=%d apic2=%d pin2=%d\n", | 2026 | apic_printk(APIC_QUIET, KERN_INFO "..TIMER: vector=0x%02X " |
1689 | cfg->vector, apic1, pin1, apic2, pin2); | 2027 | "apic1=%d pin1=%d apic2=%d pin2=%d\n", |
2028 | cfg->vector, apic1, pin1, apic2, pin2); | ||
2029 | |||
2030 | /* | ||
2031 | * Some BIOS writers are clueless and report the ExtINTA | ||
2032 | * I/O APIC input from the cascaded 8259A as the timer | ||
2033 | * interrupt input. So just in case, if only one pin | ||
2034 | * was found above, try it both directly and through the | ||
2035 | * 8259A. | ||
2036 | */ | ||
2037 | if (pin1 == -1) { | ||
2038 | if (intr_remapping_enabled) | ||
2039 | panic("BIOS bug: timer not connected to IO-APIC"); | ||
2040 | pin1 = pin2; | ||
2041 | apic1 = apic2; | ||
2042 | no_pin1 = 1; | ||
2043 | } else if (pin2 == -1) { | ||
2044 | pin2 = pin1; | ||
2045 | apic2 = apic1; | ||
2046 | } | ||
1690 | 2047 | ||
1691 | if (pin1 != -1) { | 2048 | if (pin1 != -1) { |
1692 | /* | 2049 | /* |
1693 | * Ok, does IRQ0 through the IOAPIC work? | 2050 | * Ok, does IRQ0 through the IOAPIC work? |
1694 | */ | 2051 | */ |
2052 | if (no_pin1) { | ||
2053 | add_pin_to_irq(0, apic1, pin1); | ||
2054 | setup_timer_IRQ0_pin(apic1, pin1, cfg->vector); | ||
2055 | } | ||
1695 | unmask_IO_APIC_irq(0); | 2056 | unmask_IO_APIC_irq(0); |
1696 | if (!no_timer_check && timer_irq_works()) { | 2057 | if (!no_timer_check && timer_irq_works()) { |
1697 | nmi_watchdog_default(); | ||
1698 | if (nmi_watchdog == NMI_IO_APIC) { | 2058 | if (nmi_watchdog == NMI_IO_APIC) { |
1699 | disable_8259A_irq(0); | ||
1700 | setup_nmi(); | 2059 | setup_nmi(); |
1701 | enable_8259A_irq(0); | 2060 | enable_8259A_irq(0); |
1702 | } | 2061 | } |
@@ -1704,55 +2063,65 @@ static inline void __init check_timer(void) | |||
1704 | clear_IO_APIC_pin(0, pin1); | 2063 | clear_IO_APIC_pin(0, pin1); |
1705 | goto out; | 2064 | goto out; |
1706 | } | 2065 | } |
2066 | if (intr_remapping_enabled) | ||
2067 | panic("timer doesn't work through Interrupt-remapped IO-APIC"); | ||
1707 | clear_IO_APIC_pin(apic1, pin1); | 2068 | clear_IO_APIC_pin(apic1, pin1); |
1708 | apic_printk(APIC_QUIET,KERN_ERR "..MP-BIOS bug: 8254 timer not " | 2069 | if (!no_pin1) |
1709 | "connected to IO-APIC\n"); | 2070 | apic_printk(APIC_QUIET, KERN_ERR "..MP-BIOS bug: " |
1710 | } | 2071 | "8254 timer not connected to IO-APIC\n"); |
1711 | 2072 | ||
1712 | apic_printk(APIC_VERBOSE,KERN_INFO "...trying to set up timer (IRQ0) " | 2073 | apic_printk(APIC_QUIET, KERN_INFO "...trying to set up timer " |
1713 | "through the 8259A ... "); | 2074 | "(IRQ0) through the 8259A ...\n"); |
1714 | if (pin2 != -1) { | 2075 | apic_printk(APIC_QUIET, KERN_INFO |
1715 | apic_printk(APIC_VERBOSE,"\n..... (found apic %d pin %d) ...", | 2076 | "..... (found apic %d pin %d) ...\n", apic2, pin2); |
1716 | apic2, pin2); | ||
1717 | /* | 2077 | /* |
1718 | * legacy devices should be connected to IO APIC #0 | 2078 | * legacy devices should be connected to IO APIC #0 |
1719 | */ | 2079 | */ |
1720 | setup_ExtINT_IRQ0_pin(apic2, pin2, cfg->vector); | 2080 | replace_pin_at_irq(0, apic1, pin1, apic2, pin2); |
2081 | setup_timer_IRQ0_pin(apic2, pin2, cfg->vector); | ||
2082 | unmask_IO_APIC_irq(0); | ||
2083 | enable_8259A_irq(0); | ||
1721 | if (timer_irq_works()) { | 2084 | if (timer_irq_works()) { |
1722 | apic_printk(APIC_VERBOSE," works.\n"); | 2085 | apic_printk(APIC_QUIET, KERN_INFO "....... works.\n"); |
1723 | nmi_watchdog_default(); | 2086 | timer_through_8259 = 1; |
1724 | if (nmi_watchdog == NMI_IO_APIC) { | 2087 | if (nmi_watchdog == NMI_IO_APIC) { |
2088 | disable_8259A_irq(0); | ||
1725 | setup_nmi(); | 2089 | setup_nmi(); |
2090 | enable_8259A_irq(0); | ||
1726 | } | 2091 | } |
1727 | goto out; | 2092 | goto out; |
1728 | } | 2093 | } |
1729 | /* | 2094 | /* |
1730 | * Cleanup, just in case ... | 2095 | * Cleanup, just in case ... |
1731 | */ | 2096 | */ |
2097 | disable_8259A_irq(0); | ||
1732 | clear_IO_APIC_pin(apic2, pin2); | 2098 | clear_IO_APIC_pin(apic2, pin2); |
2099 | apic_printk(APIC_QUIET, KERN_INFO "....... failed.\n"); | ||
1733 | } | 2100 | } |
1734 | apic_printk(APIC_VERBOSE," failed.\n"); | ||
1735 | 2101 | ||
1736 | if (nmi_watchdog == NMI_IO_APIC) { | 2102 | if (nmi_watchdog == NMI_IO_APIC) { |
1737 | printk(KERN_WARNING "timer doesn't work through the IO-APIC - disabling NMI Watchdog!\n"); | 2103 | apic_printk(APIC_QUIET, KERN_WARNING "timer doesn't work " |
1738 | nmi_watchdog = 0; | 2104 | "through the IO-APIC - disabling NMI Watchdog!\n"); |
2105 | nmi_watchdog = NMI_NONE; | ||
1739 | } | 2106 | } |
1740 | 2107 | ||
1741 | apic_printk(APIC_VERBOSE, KERN_INFO "...trying to set up timer as Virtual Wire IRQ..."); | 2108 | apic_printk(APIC_QUIET, KERN_INFO |
2109 | "...trying to set up timer as Virtual Wire IRQ...\n"); | ||
1742 | 2110 | ||
1743 | disable_8259A_irq(0); | 2111 | lapic_register_intr(0); |
1744 | irq_desc[0].chip = &lapic_irq_type; | ||
1745 | apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector); /* Fixed mode */ | 2112 | apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector); /* Fixed mode */ |
1746 | enable_8259A_irq(0); | 2113 | enable_8259A_irq(0); |
1747 | 2114 | ||
1748 | if (timer_irq_works()) { | 2115 | if (timer_irq_works()) { |
1749 | apic_printk(APIC_VERBOSE," works.\n"); | 2116 | apic_printk(APIC_QUIET, KERN_INFO "..... works.\n"); |
1750 | goto out; | 2117 | goto out; |
1751 | } | 2118 | } |
2119 | disable_8259A_irq(0); | ||
1752 | apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | cfg->vector); | 2120 | apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | cfg->vector); |
1753 | apic_printk(APIC_VERBOSE," failed.\n"); | 2121 | apic_printk(APIC_QUIET, KERN_INFO "..... failed.\n"); |
1754 | 2122 | ||
1755 | apic_printk(APIC_VERBOSE, KERN_INFO "...trying to set up timer as ExtINT IRQ..."); | 2123 | apic_printk(APIC_QUIET, KERN_INFO |
2124 | "...trying to set up timer as ExtINT IRQ...\n"); | ||
1756 | 2125 | ||
1757 | init_8259A(0); | 2126 | init_8259A(0); |
1758 | make_8259A_irq(0); | 2127 | make_8259A_irq(0); |
@@ -1761,11 +2130,12 @@ static inline void __init check_timer(void) | |||
1761 | unlock_ExtINT_logic(); | 2130 | unlock_ExtINT_logic(); |
1762 | 2131 | ||
1763 | if (timer_irq_works()) { | 2132 | if (timer_irq_works()) { |
1764 | apic_printk(APIC_VERBOSE," works.\n"); | 2133 | apic_printk(APIC_QUIET, KERN_INFO "..... works.\n"); |
1765 | goto out; | 2134 | goto out; |
1766 | } | 2135 | } |
1767 | apic_printk(APIC_VERBOSE," failed :(.\n"); | 2136 | apic_printk(APIC_QUIET, KERN_INFO "..... failed :(.\n"); |
1768 | panic("IO-APIC + timer doesn't work! Try using the 'noapic' kernel parameter\n"); | 2137 | panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a " |
2138 | "report. Then try booting with the 'noapic' option.\n"); | ||
1769 | out: | 2139 | out: |
1770 | local_irq_restore(flags); | 2140 | local_irq_restore(flags); |
1771 | } | 2141 | } |
@@ -1778,11 +2148,21 @@ static int __init notimercheck(char *s) | |||
1778 | __setup("no_timer_check", notimercheck); | 2148 | __setup("no_timer_check", notimercheck); |
1779 | 2149 | ||
1780 | /* | 2150 | /* |
1781 | * | 2151 | * Traditionally ISA IRQ2 is the cascade IRQ, and is not available |
1782 | * IRQs that are handled by the PIC in the MPS IOAPIC case. | 2152 | * to devices. However there may be an I/O APIC pin available for |
1783 | * - IRQ2 is the cascade IRQ, and cannot be a io-apic IRQ. | 2153 | * this interrupt regardless. The pin may be left unconnected, but |
1784 | * Linux doesn't really care, as it's not actually used | 2154 | * typically it will be reused as an ExtINT cascade interrupt for |
1785 | * for any interrupt handling anyway. | 2155 | * the master 8259A. In the MPS case such a pin will normally be |
2156 | * reported as an ExtINT interrupt in the MP table. With ACPI | ||
2157 | * there is no provision for ExtINT interrupts, and in the absence | ||
2158 | * of an override it would be treated as an ordinary ISA I/O APIC | ||
2159 | * interrupt, that is edge-triggered and unmasked by default. We | ||
2160 | * used to do this, but it caused problems on some systems because | ||
2161 | * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using | ||
2162 | * the same ExtINT cascade interrupt to drive the local APIC of the | ||
2163 | * bootstrap processor. Therefore we refrain from routing IRQ2 to | ||
2164 | * the I/O APIC in all cases now. No actual device should request | ||
2165 | * it anyway. --macro | ||
1786 | */ | 2166 | */ |
1787 | #define PIC_IRQS (1<<2) | 2167 | #define PIC_IRQS (1<<2) |
1788 | 2168 | ||
@@ -1793,10 +2173,7 @@ void __init setup_IO_APIC(void) | |||
1793 | * calling enable_IO_APIC() is moved to setup_local_APIC for BP | 2173 | * calling enable_IO_APIC() is moved to setup_local_APIC for BP |
1794 | */ | 2174 | */ |
1795 | 2175 | ||
1796 | if (acpi_ioapic) | 2176 | io_apic_irqs = ~PIC_IRQS; |
1797 | io_apic_irqs = ~0; /* all IRQs go through IOAPIC */ | ||
1798 | else | ||
1799 | io_apic_irqs = ~PIC_IRQS; | ||
1800 | 2177 | ||
1801 | apic_printk(APIC_VERBOSE, "ENABLING IO-APIC IRQs\n"); | 2178 | apic_printk(APIC_VERBOSE, "ENABLING IO-APIC IRQs\n"); |
1802 | 2179 | ||
@@ -1804,8 +2181,6 @@ void __init setup_IO_APIC(void) | |||
1804 | setup_IO_APIC_irqs(); | 2181 | setup_IO_APIC_irqs(); |
1805 | init_IO_APIC_traps(); | 2182 | init_IO_APIC_traps(); |
1806 | check_timer(); | 2183 | check_timer(); |
1807 | if (!acpi_ioapic) | ||
1808 | print_IO_APIC(); | ||
1809 | } | 2184 | } |
1810 | 2185 | ||
1811 | struct sysfs_ioapic_data { | 2186 | struct sysfs_ioapic_data { |
@@ -1841,8 +2216,8 @@ static int ioapic_resume(struct sys_device *dev) | |||
1841 | 2216 | ||
1842 | spin_lock_irqsave(&ioapic_lock, flags); | 2217 | spin_lock_irqsave(&ioapic_lock, flags); |
1843 | reg_00.raw = io_apic_read(dev->id, 0); | 2218 | reg_00.raw = io_apic_read(dev->id, 0); |
1844 | if (reg_00.bits.ID != mp_ioapics[dev->id].mpc_apicid) { | 2219 | if (reg_00.bits.ID != mp_ioapics[dev->id].mp_apicid) { |
1845 | reg_00.bits.ID = mp_ioapics[dev->id].mpc_apicid; | 2220 | reg_00.bits.ID = mp_ioapics[dev->id].mp_apicid; |
1846 | io_apic_write(dev->id, 0, reg_00.raw); | 2221 | io_apic_write(dev->id, 0, reg_00.raw); |
1847 | } | 2222 | } |
1848 | spin_unlock_irqrestore(&ioapic_lock, flags); | 2223 | spin_unlock_irqrestore(&ioapic_lock, flags); |
@@ -1927,6 +2302,9 @@ void destroy_irq(unsigned int irq) | |||
1927 | 2302 | ||
1928 | dynamic_irq_cleanup(irq); | 2303 | dynamic_irq_cleanup(irq); |
1929 | 2304 | ||
2305 | #ifdef CONFIG_INTR_REMAP | ||
2306 | free_irte(irq); | ||
2307 | #endif | ||
1930 | spin_lock_irqsave(&vector_lock, flags); | 2308 | spin_lock_irqsave(&vector_lock, flags); |
1931 | __clear_irq_vector(irq); | 2309 | __clear_irq_vector(irq); |
1932 | spin_unlock_irqrestore(&vector_lock, flags); | 2310 | spin_unlock_irqrestore(&vector_lock, flags); |
@@ -1945,10 +2323,41 @@ static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_ms | |||
1945 | 2323 | ||
1946 | tmp = TARGET_CPUS; | 2324 | tmp = TARGET_CPUS; |
1947 | err = assign_irq_vector(irq, tmp); | 2325 | err = assign_irq_vector(irq, tmp); |
1948 | if (!err) { | 2326 | if (err) |
1949 | cpus_and(tmp, cfg->domain, tmp); | 2327 | return err; |
1950 | dest = cpu_mask_to_apicid(tmp); | 2328 | |
2329 | cpus_and(tmp, cfg->domain, tmp); | ||
2330 | dest = cpu_mask_to_apicid(tmp); | ||
2331 | |||
2332 | #ifdef CONFIG_INTR_REMAP | ||
2333 | if (irq_remapped(irq)) { | ||
2334 | struct irte irte; | ||
2335 | int ir_index; | ||
2336 | u16 sub_handle; | ||
2337 | |||
2338 | ir_index = map_irq_to_irte_handle(irq, &sub_handle); | ||
2339 | BUG_ON(ir_index == -1); | ||
2340 | |||
2341 | memset (&irte, 0, sizeof(irte)); | ||
1951 | 2342 | ||
2343 | irte.present = 1; | ||
2344 | irte.dst_mode = INT_DEST_MODE; | ||
2345 | irte.trigger_mode = 0; /* edge */ | ||
2346 | irte.dlvry_mode = INT_DELIVERY_MODE; | ||
2347 | irte.vector = cfg->vector; | ||
2348 | irte.dest_id = IRTE_DEST(dest); | ||
2349 | |||
2350 | modify_irte(irq, &irte); | ||
2351 | |||
2352 | msg->address_hi = MSI_ADDR_BASE_HI; | ||
2353 | msg->data = sub_handle; | ||
2354 | msg->address_lo = MSI_ADDR_BASE_LO | MSI_ADDR_IR_EXT_INT | | ||
2355 | MSI_ADDR_IR_SHV | | ||
2356 | MSI_ADDR_IR_INDEX1(ir_index) | | ||
2357 | MSI_ADDR_IR_INDEX2(ir_index); | ||
2358 | } else | ||
2359 | #endif | ||
2360 | { | ||
1952 | msg->address_hi = MSI_ADDR_BASE_HI; | 2361 | msg->address_hi = MSI_ADDR_BASE_HI; |
1953 | msg->address_lo = | 2362 | msg->address_lo = |
1954 | MSI_ADDR_BASE_LO | | 2363 | MSI_ADDR_BASE_LO | |
@@ -1999,6 +2408,55 @@ static void set_msi_irq_affinity(unsigned int irq, cpumask_t mask) | |||
1999 | write_msi_msg(irq, &msg); | 2408 | write_msi_msg(irq, &msg); |
2000 | irq_desc[irq].affinity = mask; | 2409 | irq_desc[irq].affinity = mask; |
2001 | } | 2410 | } |
2411 | |||
2412 | #ifdef CONFIG_INTR_REMAP | ||
2413 | /* | ||
2414 | * Migrate the MSI irq to another cpumask. This migration is | ||
2415 | * done in the process context using interrupt-remapping hardware. | ||
2416 | */ | ||
2417 | static void ir_set_msi_irq_affinity(unsigned int irq, cpumask_t mask) | ||
2418 | { | ||
2419 | struct irq_cfg *cfg = irq_cfg + irq; | ||
2420 | unsigned int dest; | ||
2421 | cpumask_t tmp, cleanup_mask; | ||
2422 | struct irte irte; | ||
2423 | |||
2424 | cpus_and(tmp, mask, cpu_online_map); | ||
2425 | if (cpus_empty(tmp)) | ||
2426 | return; | ||
2427 | |||
2428 | if (get_irte(irq, &irte)) | ||
2429 | return; | ||
2430 | |||
2431 | if (assign_irq_vector(irq, mask)) | ||
2432 | return; | ||
2433 | |||
2434 | cpus_and(tmp, cfg->domain, mask); | ||
2435 | dest = cpu_mask_to_apicid(tmp); | ||
2436 | |||
2437 | irte.vector = cfg->vector; | ||
2438 | irte.dest_id = IRTE_DEST(dest); | ||
2439 | |||
2440 | /* | ||
2441 | * atomically update the IRTE with the new destination and vector. | ||
2442 | */ | ||
2443 | modify_irte(irq, &irte); | ||
2444 | |||
2445 | /* | ||
2446 | * After this point, all the interrupts will start arriving | ||
2447 | * at the new destination. So, time to cleanup the previous | ||
2448 | * vector allocation. | ||
2449 | */ | ||
2450 | if (cfg->move_in_progress) { | ||
2451 | cpus_and(cleanup_mask, cfg->old_domain, cpu_online_map); | ||
2452 | cfg->move_cleanup_count = cpus_weight(cleanup_mask); | ||
2453 | send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR); | ||
2454 | cfg->move_in_progress = 0; | ||
2455 | } | ||
2456 | |||
2457 | irq_desc[irq].affinity = mask; | ||
2458 | } | ||
2459 | #endif | ||
2002 | #endif /* CONFIG_SMP */ | 2460 | #endif /* CONFIG_SMP */ |
2003 | 2461 | ||
2004 | /* | 2462 | /* |
@@ -2016,26 +2474,157 @@ static struct irq_chip msi_chip = { | |||
2016 | .retrigger = ioapic_retrigger_irq, | 2474 | .retrigger = ioapic_retrigger_irq, |
2017 | }; | 2475 | }; |
2018 | 2476 | ||
2019 | int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc) | 2477 | #ifdef CONFIG_INTR_REMAP |
2478 | static struct irq_chip msi_ir_chip = { | ||
2479 | .name = "IR-PCI-MSI", | ||
2480 | .unmask = unmask_msi_irq, | ||
2481 | .mask = mask_msi_irq, | ||
2482 | .ack = ack_x2apic_edge, | ||
2483 | #ifdef CONFIG_SMP | ||
2484 | .set_affinity = ir_set_msi_irq_affinity, | ||
2485 | #endif | ||
2486 | .retrigger = ioapic_retrigger_irq, | ||
2487 | }; | ||
2488 | |||
2489 | /* | ||
2490 | * Map the PCI dev to the corresponding remapping hardware unit | ||
2491 | * and allocate 'nvec' consecutive interrupt-remapping table entries | ||
2492 | * in it. | ||
2493 | */ | ||
2494 | static int msi_alloc_irte(struct pci_dev *dev, int irq, int nvec) | ||
2495 | { | ||
2496 | struct intel_iommu *iommu; | ||
2497 | int index; | ||
2498 | |||
2499 | iommu = map_dev_to_ir(dev); | ||
2500 | if (!iommu) { | ||
2501 | printk(KERN_ERR | ||
2502 | "Unable to map PCI %s to iommu\n", pci_name(dev)); | ||
2503 | return -ENOENT; | ||
2504 | } | ||
2505 | |||
2506 | index = alloc_irte(iommu, irq, nvec); | ||
2507 | if (index < 0) { | ||
2508 | printk(KERN_ERR | ||
2509 | "Unable to allocate %d IRTE for PCI %s\n", nvec, | ||
2510 | pci_name(dev)); | ||
2511 | return -ENOSPC; | ||
2512 | } | ||
2513 | return index; | ||
2514 | } | ||
2515 | #endif | ||
2516 | |||
2517 | static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc, int irq) | ||
2020 | { | 2518 | { |
2519 | int ret; | ||
2021 | struct msi_msg msg; | 2520 | struct msi_msg msg; |
2521 | |||
2522 | ret = msi_compose_msg(dev, irq, &msg); | ||
2523 | if (ret < 0) | ||
2524 | return ret; | ||
2525 | |||
2526 | set_irq_msi(irq, desc); | ||
2527 | write_msi_msg(irq, &msg); | ||
2528 | |||
2529 | #ifdef CONFIG_INTR_REMAP | ||
2530 | if (irq_remapped(irq)) { | ||
2531 | struct irq_desc *desc = irq_desc + irq; | ||
2532 | /* | ||
2533 | * irq migration in process context | ||
2534 | */ | ||
2535 | desc->status |= IRQ_MOVE_PCNTXT; | ||
2536 | set_irq_chip_and_handler_name(irq, &msi_ir_chip, handle_edge_irq, "edge"); | ||
2537 | } else | ||
2538 | #endif | ||
2539 | set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, "edge"); | ||
2540 | |||
2541 | return 0; | ||
2542 | } | ||
2543 | |||
2544 | int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc) | ||
2545 | { | ||
2022 | int irq, ret; | 2546 | int irq, ret; |
2547 | |||
2023 | irq = create_irq(); | 2548 | irq = create_irq(); |
2024 | if (irq < 0) | 2549 | if (irq < 0) |
2025 | return irq; | 2550 | return irq; |
2026 | 2551 | ||
2027 | ret = msi_compose_msg(dev, irq, &msg); | 2552 | #ifdef CONFIG_INTR_REMAP |
2553 | if (!intr_remapping_enabled) | ||
2554 | goto no_ir; | ||
2555 | |||
2556 | ret = msi_alloc_irte(dev, irq, 1); | ||
2557 | if (ret < 0) | ||
2558 | goto error; | ||
2559 | no_ir: | ||
2560 | #endif | ||
2561 | ret = setup_msi_irq(dev, desc, irq); | ||
2028 | if (ret < 0) { | 2562 | if (ret < 0) { |
2029 | destroy_irq(irq); | 2563 | destroy_irq(irq); |
2030 | return ret; | 2564 | return ret; |
2031 | } | 2565 | } |
2566 | return 0; | ||
2032 | 2567 | ||
2033 | set_irq_msi(irq, desc); | 2568 | #ifdef CONFIG_INTR_REMAP |
2034 | write_msi_msg(irq, &msg); | 2569 | error: |
2570 | destroy_irq(irq); | ||
2571 | return ret; | ||
2572 | #endif | ||
2573 | } | ||
2035 | 2574 | ||
2036 | set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, "edge"); | 2575 | int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) |
2576 | { | ||
2577 | int irq, ret, sub_handle; | ||
2578 | struct msi_desc *desc; | ||
2579 | #ifdef CONFIG_INTR_REMAP | ||
2580 | struct intel_iommu *iommu = 0; | ||
2581 | int index = 0; | ||
2582 | #endif | ||
2583 | |||
2584 | sub_handle = 0; | ||
2585 | list_for_each_entry(desc, &dev->msi_list, list) { | ||
2586 | irq = create_irq(); | ||
2587 | if (irq < 0) | ||
2588 | return irq; | ||
2589 | #ifdef CONFIG_INTR_REMAP | ||
2590 | if (!intr_remapping_enabled) | ||
2591 | goto no_ir; | ||
2037 | 2592 | ||
2593 | if (!sub_handle) { | ||
2594 | /* | ||
2595 | * allocate the consecutive block of IRTE's | ||
2596 | * for 'nvec' | ||
2597 | */ | ||
2598 | index = msi_alloc_irte(dev, irq, nvec); | ||
2599 | if (index < 0) { | ||
2600 | ret = index; | ||
2601 | goto error; | ||
2602 | } | ||
2603 | } else { | ||
2604 | iommu = map_dev_to_ir(dev); | ||
2605 | if (!iommu) { | ||
2606 | ret = -ENOENT; | ||
2607 | goto error; | ||
2608 | } | ||
2609 | /* | ||
2610 | * setup the mapping between the irq and the IRTE | ||
2611 | * base index, the sub_handle pointing to the | ||
2612 | * appropriate interrupt remap table entry. | ||
2613 | */ | ||
2614 | set_irte_irq(irq, iommu, index, sub_handle); | ||
2615 | } | ||
2616 | no_ir: | ||
2617 | #endif | ||
2618 | ret = setup_msi_irq(dev, desc, irq); | ||
2619 | if (ret < 0) | ||
2620 | goto error; | ||
2621 | sub_handle++; | ||
2622 | } | ||
2038 | return 0; | 2623 | return 0; |
2624 | |||
2625 | error: | ||
2626 | destroy_irq(irq); | ||
2627 | return ret; | ||
2039 | } | 2628 | } |
2040 | 2629 | ||
2041 | void arch_teardown_msi_irq(unsigned int irq) | 2630 | void arch_teardown_msi_irq(unsigned int irq) |
@@ -2242,8 +2831,8 @@ int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity) | |||
2242 | return -1; | 2831 | return -1; |
2243 | 2832 | ||
2244 | for (i = 0; i < mp_irq_entries; i++) | 2833 | for (i = 0; i < mp_irq_entries; i++) |
2245 | if (mp_irqs[i].mpc_irqtype == mp_INT && | 2834 | if (mp_irqs[i].mp_irqtype == mp_INT && |
2246 | mp_irqs[i].mpc_srcbusirq == bus_irq) | 2835 | mp_irqs[i].mp_srcbusirq == bus_irq) |
2247 | break; | 2836 | break; |
2248 | if (i >= mp_irq_entries) | 2837 | if (i >= mp_irq_entries) |
2249 | return -1; | 2838 | return -1; |
@@ -2283,6 +2872,10 @@ void __init setup_ioapic_dest(void) | |||
2283 | setup_IO_APIC_irq(ioapic, pin, irq, | 2872 | setup_IO_APIC_irq(ioapic, pin, irq, |
2284 | irq_trigger(irq_entry), | 2873 | irq_trigger(irq_entry), |
2285 | irq_polarity(irq_entry)); | 2874 | irq_polarity(irq_entry)); |
2875 | #ifdef CONFIG_INTR_REMAP | ||
2876 | else if (intr_remapping_enabled) | ||
2877 | set_ir_ioapic_affinity_irq(irq, TARGET_CPUS); | ||
2878 | #endif | ||
2286 | else | 2879 | else |
2287 | set_ioapic_affinity_irq(irq, TARGET_CPUS); | 2880 | set_ioapic_affinity_irq(irq, TARGET_CPUS); |
2288 | } | 2881 | } |
@@ -2336,7 +2929,7 @@ void __init ioapic_init_mappings(void) | |||
2336 | ioapic_res = ioapic_setup_resources(); | 2929 | ioapic_res = ioapic_setup_resources(); |
2337 | for (i = 0; i < nr_ioapics; i++) { | 2930 | for (i = 0; i < nr_ioapics; i++) { |
2338 | if (smp_found_config) { | 2931 | if (smp_found_config) { |
2339 | ioapic_phys = mp_ioapics[i].mpc_apicaddr; | 2932 | ioapic_phys = mp_ioapics[i].mp_apicaddr; |
2340 | } else { | 2933 | } else { |
2341 | ioapic_phys = (unsigned long) | 2934 | ioapic_phys = (unsigned long) |
2342 | alloc_bootmem_pages(PAGE_SIZE); | 2935 | alloc_bootmem_pages(PAGE_SIZE); |