aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/apic/io_apic.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/kernel/apic/io_apic.c')
-rw-r--r--arch/x86/kernel/apic/io_apic.c268
1 files changed, 128 insertions, 140 deletions
diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
index 00e6071cefc4..42cdc78427a2 100644
--- a/arch/x86/kernel/apic/io_apic.c
+++ b/arch/x86/kernel/apic/io_apic.c
@@ -389,6 +389,8 @@ struct io_apic {
389 unsigned int index; 389 unsigned int index;
390 unsigned int unused[3]; 390 unsigned int unused[3];
391 unsigned int data; 391 unsigned int data;
392 unsigned int unused2[11];
393 unsigned int eoi;
392}; 394};
393 395
394static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx) 396static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx)
@@ -397,6 +399,12 @@ static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx)
397 + (mp_ioapics[idx].apicaddr & ~PAGE_MASK); 399 + (mp_ioapics[idx].apicaddr & ~PAGE_MASK);
398} 400}
399 401
402static inline void io_apic_eoi(unsigned int apic, unsigned int vector)
403{
404 struct io_apic __iomem *io_apic = io_apic_base(apic);
405 writel(vector, &io_apic->eoi);
406}
407
400static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg) 408static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg)
401{ 409{
402 struct io_apic __iomem *io_apic = io_apic_base(apic); 410 struct io_apic __iomem *io_apic = io_apic_base(apic);
@@ -546,16 +554,12 @@ static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, struct irq
546 554
547 apic = entry->apic; 555 apic = entry->apic;
548 pin = entry->pin; 556 pin = entry->pin;
549#ifdef CONFIG_INTR_REMAP
550 /* 557 /*
551 * With interrupt-remapping, destination information comes 558 * With interrupt-remapping, destination information comes
552 * from interrupt-remapping table entry. 559 * from interrupt-remapping table entry.
553 */ 560 */
554 if (!irq_remapped(irq)) 561 if (!irq_remapped(irq))
555 io_apic_write(apic, 0x11 + pin*2, dest); 562 io_apic_write(apic, 0x11 + pin*2, dest);
556#else
557 io_apic_write(apic, 0x11 + pin*2, dest);
558#endif
559 reg = io_apic_read(apic, 0x10 + pin*2); 563 reg = io_apic_read(apic, 0x10 + pin*2);
560 reg &= ~IO_APIC_REDIR_VECTOR_MASK; 564 reg &= ~IO_APIC_REDIR_VECTOR_MASK;
561 reg |= vector; 565 reg |= vector;
@@ -849,9 +853,9 @@ __setup("pirq=", ioapic_pirq_setup);
849static struct IO_APIC_route_entry *early_ioapic_entries[MAX_IO_APICS]; 853static struct IO_APIC_route_entry *early_ioapic_entries[MAX_IO_APICS];
850 854
851/* 855/*
852 * Saves and masks all the unmasked IO-APIC RTE's 856 * Saves all the IO-APIC RTE's
853 */ 857 */
854int save_mask_IO_APIC_setup(void) 858int save_IO_APIC_setup(void)
855{ 859{
856 union IO_APIC_reg_01 reg_01; 860 union IO_APIC_reg_01 reg_01;
857 unsigned long flags; 861 unsigned long flags;
@@ -876,16 +880,9 @@ int save_mask_IO_APIC_setup(void)
876 } 880 }
877 881
878 for (apic = 0; apic < nr_ioapics; apic++) 882 for (apic = 0; apic < nr_ioapics; apic++)
879 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) { 883 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
880 struct IO_APIC_route_entry entry; 884 early_ioapic_entries[apic][pin] =
881
882 entry = early_ioapic_entries[apic][pin] =
883 ioapic_read_entry(apic, pin); 885 ioapic_read_entry(apic, pin);
884 if (!entry.mask) {
885 entry.mask = 1;
886 ioapic_write_entry(apic, pin, entry);
887 }
888 }
889 886
890 return 0; 887 return 0;
891 888
@@ -898,6 +895,25 @@ nomem:
898 return -ENOMEM; 895 return -ENOMEM;
899} 896}
900 897
898void mask_IO_APIC_setup(void)
899{
900 int apic, pin;
901
902 for (apic = 0; apic < nr_ioapics; apic++) {
903 if (!early_ioapic_entries[apic])
904 break;
905 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
906 struct IO_APIC_route_entry entry;
907
908 entry = early_ioapic_entries[apic][pin];
909 if (!entry.mask) {
910 entry.mask = 1;
911 ioapic_write_entry(apic, pin, entry);
912 }
913 }
914 }
915}
916
901void restore_IO_APIC_setup(void) 917void restore_IO_APIC_setup(void)
902{ 918{
903 int apic, pin; 919 int apic, pin;
@@ -1411,9 +1427,8 @@ void __setup_vector_irq(int cpu)
1411} 1427}
1412 1428
1413static struct irq_chip ioapic_chip; 1429static struct irq_chip ioapic_chip;
1414#ifdef CONFIG_INTR_REMAP
1415static struct irq_chip ir_ioapic_chip; 1430static struct irq_chip ir_ioapic_chip;
1416#endif 1431static struct irq_chip msi_ir_chip;
1417 1432
1418#define IOAPIC_AUTO -1 1433#define IOAPIC_AUTO -1
1419#define IOAPIC_EDGE 0 1434#define IOAPIC_EDGE 0
@@ -1452,7 +1467,6 @@ static void ioapic_register_intr(int irq, struct irq_desc *desc, unsigned long t
1452 else 1467 else
1453 desc->status &= ~IRQ_LEVEL; 1468 desc->status &= ~IRQ_LEVEL;
1454 1469
1455#ifdef CONFIG_INTR_REMAP
1456 if (irq_remapped(irq)) { 1470 if (irq_remapped(irq)) {
1457 desc->status |= IRQ_MOVE_PCNTXT; 1471 desc->status |= IRQ_MOVE_PCNTXT;
1458 if (trigger) 1472 if (trigger)
@@ -1464,7 +1478,7 @@ static void ioapic_register_intr(int irq, struct irq_desc *desc, unsigned long t
1464 handle_edge_irq, "edge"); 1478 handle_edge_irq, "edge");
1465 return; 1479 return;
1466 } 1480 }
1467#endif 1481
1468 if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) || 1482 if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
1469 trigger == IOAPIC_LEVEL) 1483 trigger == IOAPIC_LEVEL)
1470 set_irq_chip_and_handler_name(irq, &ioapic_chip, 1484 set_irq_chip_and_handler_name(irq, &ioapic_chip,
@@ -1478,14 +1492,13 @@ static void ioapic_register_intr(int irq, struct irq_desc *desc, unsigned long t
1478int setup_ioapic_entry(int apic_id, int irq, 1492int setup_ioapic_entry(int apic_id, int irq,
1479 struct IO_APIC_route_entry *entry, 1493 struct IO_APIC_route_entry *entry,
1480 unsigned int destination, int trigger, 1494 unsigned int destination, int trigger,
1481 int polarity, int vector) 1495 int polarity, int vector, int pin)
1482{ 1496{
1483 /* 1497 /*
1484 * add it to the IO-APIC irq-routing table: 1498 * add it to the IO-APIC irq-routing table:
1485 */ 1499 */
1486 memset(entry,0,sizeof(*entry)); 1500 memset(entry,0,sizeof(*entry));
1487 1501
1488#ifdef CONFIG_INTR_REMAP
1489 if (intr_remapping_enabled) { 1502 if (intr_remapping_enabled) {
1490 struct intel_iommu *iommu = map_ioapic_to_ir(apic_id); 1503 struct intel_iommu *iommu = map_ioapic_to_ir(apic_id);
1491 struct irte irte; 1504 struct irte irte;
@@ -1504,7 +1517,14 @@ int setup_ioapic_entry(int apic_id, int irq,
1504 1517
1505 irte.present = 1; 1518 irte.present = 1;
1506 irte.dst_mode = apic->irq_dest_mode; 1519 irte.dst_mode = apic->irq_dest_mode;
1507 irte.trigger_mode = trigger; 1520 /*
1521 * Trigger mode in the IRTE will always be edge, and the
1522 * actual level or edge trigger will be setup in the IO-APIC
1523 * RTE. This will help simplify level triggered irq migration.
1524 * For more details, see the comments above explainig IO-APIC
1525 * irq migration in the presence of interrupt-remapping.
1526 */
1527 irte.trigger_mode = 0;
1508 irte.dlvry_mode = apic->irq_delivery_mode; 1528 irte.dlvry_mode = apic->irq_delivery_mode;
1509 irte.vector = vector; 1529 irte.vector = vector;
1510 irte.dest_id = IRTE_DEST(destination); 1530 irte.dest_id = IRTE_DEST(destination);
@@ -1515,18 +1535,21 @@ int setup_ioapic_entry(int apic_id, int irq,
1515 ir_entry->zero = 0; 1535 ir_entry->zero = 0;
1516 ir_entry->format = 1; 1536 ir_entry->format = 1;
1517 ir_entry->index = (index & 0x7fff); 1537 ir_entry->index = (index & 0x7fff);
1518 } else 1538 /*
1519#endif 1539 * IO-APIC RTE will be configured with virtual vector.
1520 { 1540 * irq handler will do the explicit EOI to the io-apic.
1541 */
1542 ir_entry->vector = pin;
1543 } else {
1521 entry->delivery_mode = apic->irq_delivery_mode; 1544 entry->delivery_mode = apic->irq_delivery_mode;
1522 entry->dest_mode = apic->irq_dest_mode; 1545 entry->dest_mode = apic->irq_dest_mode;
1523 entry->dest = destination; 1546 entry->dest = destination;
1547 entry->vector = vector;
1524 } 1548 }
1525 1549
1526 entry->mask = 0; /* enable IRQ */ 1550 entry->mask = 0; /* enable IRQ */
1527 entry->trigger = trigger; 1551 entry->trigger = trigger;
1528 entry->polarity = polarity; 1552 entry->polarity = polarity;
1529 entry->vector = vector;
1530 1553
1531 /* Mask level triggered irqs. 1554 /* Mask level triggered irqs.
1532 * Use IRQ_DELAYED_DISABLE for edge triggered irqs. 1555 * Use IRQ_DELAYED_DISABLE for edge triggered irqs.
@@ -1561,7 +1584,7 @@ static void setup_IO_APIC_irq(int apic_id, int pin, unsigned int irq, struct irq
1561 1584
1562 1585
1563 if (setup_ioapic_entry(mp_ioapics[apic_id].apicid, irq, &entry, 1586 if (setup_ioapic_entry(mp_ioapics[apic_id].apicid, irq, &entry,
1564 dest, trigger, polarity, cfg->vector)) { 1587 dest, trigger, polarity, cfg->vector, pin)) {
1565 printk("Failed to setup ioapic entry for ioapic %d, pin %d\n", 1588 printk("Failed to setup ioapic entry for ioapic %d, pin %d\n",
1566 mp_ioapics[apic_id].apicid, pin); 1589 mp_ioapics[apic_id].apicid, pin);
1567 __clear_irq_vector(irq, cfg); 1590 __clear_irq_vector(irq, cfg);
@@ -1642,10 +1665,8 @@ static void __init setup_timer_IRQ0_pin(unsigned int apic_id, unsigned int pin,
1642{ 1665{
1643 struct IO_APIC_route_entry entry; 1666 struct IO_APIC_route_entry entry;
1644 1667
1645#ifdef CONFIG_INTR_REMAP
1646 if (intr_remapping_enabled) 1668 if (intr_remapping_enabled)
1647 return; 1669 return;
1648#endif
1649 1670
1650 memset(&entry, 0, sizeof(entry)); 1671 memset(&entry, 0, sizeof(entry));
1651 1672
@@ -2040,8 +2061,13 @@ void disable_IO_APIC(void)
2040 * If the i8259 is routed through an IOAPIC 2061 * If the i8259 is routed through an IOAPIC
2041 * Put that IOAPIC in virtual wire mode 2062 * Put that IOAPIC in virtual wire mode
2042 * so legacy interrupts can be delivered. 2063 * so legacy interrupts can be delivered.
2064 *
2065 * With interrupt-remapping, for now we will use virtual wire A mode,
2066 * as virtual wire B is little complex (need to configure both
2067 * IOAPIC RTE aswell as interrupt-remapping table entry).
2068 * As this gets called during crash dump, keep this simple for now.
2043 */ 2069 */
2044 if (ioapic_i8259.pin != -1) { 2070 if (ioapic_i8259.pin != -1 && !intr_remapping_enabled) {
2045 struct IO_APIC_route_entry entry; 2071 struct IO_APIC_route_entry entry;
2046 2072
2047 memset(&entry, 0, sizeof(entry)); 2073 memset(&entry, 0, sizeof(entry));
@@ -2061,7 +2087,10 @@ void disable_IO_APIC(void)
2061 ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry); 2087 ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry);
2062 } 2088 }
2063 2089
2064 disconnect_bsp_APIC(ioapic_i8259.pin != -1); 2090 /*
2091 * Use virtual wire A mode when interrupt remapping is enabled.
2092 */
2093 disconnect_bsp_APIC(!intr_remapping_enabled && ioapic_i8259.pin != -1);
2065} 2094}
2066 2095
2067#ifdef CONFIG_X86_32 2096#ifdef CONFIG_X86_32
@@ -2303,37 +2332,24 @@ static int ioapic_retrigger_irq(unsigned int irq)
2303#ifdef CONFIG_SMP 2332#ifdef CONFIG_SMP
2304 2333
2305#ifdef CONFIG_INTR_REMAP 2334#ifdef CONFIG_INTR_REMAP
2306static void ir_irq_migration(struct work_struct *work);
2307
2308static DECLARE_DELAYED_WORK(ir_migration_work, ir_irq_migration);
2309 2335
2310/* 2336/*
2311 * Migrate the IO-APIC irq in the presence of intr-remapping. 2337 * Migrate the IO-APIC irq in the presence of intr-remapping.
2312 * 2338 *
2313 * For edge triggered, irq migration is a simple atomic update(of vector 2339 * For both level and edge triggered, irq migration is a simple atomic
2314 * and cpu destination) of IRTE and flush the hardware cache. 2340 * update(of vector and cpu destination) of IRTE and flush the hardware cache.
2315 *
2316 * For level triggered, we need to modify the io-apic RTE aswell with the update
2317 * vector information, along with modifying IRTE with vector and destination.
2318 * So irq migration for level triggered is little bit more complex compared to
2319 * edge triggered migration. But the good news is, we use the same algorithm
2320 * for level triggered migration as we have today, only difference being,
2321 * we now initiate the irq migration from process context instead of the
2322 * interrupt context.
2323 * 2341 *
2324 * In future, when we do a directed EOI (combined with cpu EOI broadcast 2342 * For level triggered, we eliminate the io-apic RTE modification (with the
2325 * suppression) to the IO-APIC, level triggered irq migration will also be 2343 * updated vector information), by using a virtual vector (io-apic pin number).
2326 * as simple as edge triggered migration and we can do the irq migration 2344 * Real vector that is used for interrupting cpu will be coming from
2327 * with a simple atomic update to IO-APIC RTE. 2345 * the interrupt-remapping table entry.
2328 */ 2346 */
2329static void 2347static void
2330migrate_ioapic_irq_desc(struct irq_desc *desc, const struct cpumask *mask) 2348migrate_ioapic_irq_desc(struct irq_desc *desc, const struct cpumask *mask)
2331{ 2349{
2332 struct irq_cfg *cfg; 2350 struct irq_cfg *cfg;
2333 struct irte irte; 2351 struct irte irte;
2334 int modify_ioapic_rte;
2335 unsigned int dest; 2352 unsigned int dest;
2336 unsigned long flags;
2337 unsigned int irq; 2353 unsigned int irq;
2338 2354
2339 if (!cpumask_intersects(mask, cpu_online_mask)) 2355 if (!cpumask_intersects(mask, cpu_online_mask))
@@ -2351,13 +2367,6 @@ migrate_ioapic_irq_desc(struct irq_desc *desc, const struct cpumask *mask)
2351 2367
2352 dest = apic->cpu_mask_to_apicid_and(cfg->domain, mask); 2368 dest = apic->cpu_mask_to_apicid_and(cfg->domain, mask);
2353 2369
2354 modify_ioapic_rte = desc->status & IRQ_LEVEL;
2355 if (modify_ioapic_rte) {
2356 spin_lock_irqsave(&ioapic_lock, flags);
2357 __target_IO_APIC_irq(irq, dest, cfg);
2358 spin_unlock_irqrestore(&ioapic_lock, flags);
2359 }
2360
2361 irte.vector = cfg->vector; 2370 irte.vector = cfg->vector;
2362 irte.dest_id = IRTE_DEST(dest); 2371 irte.dest_id = IRTE_DEST(dest);
2363 2372
@@ -2372,73 +2381,12 @@ migrate_ioapic_irq_desc(struct irq_desc *desc, const struct cpumask *mask)
2372 cpumask_copy(desc->affinity, mask); 2381 cpumask_copy(desc->affinity, mask);
2373} 2382}
2374 2383
2375static int migrate_irq_remapped_level_desc(struct irq_desc *desc)
2376{
2377 int ret = -1;
2378 struct irq_cfg *cfg = desc->chip_data;
2379
2380 mask_IO_APIC_irq_desc(desc);
2381
2382 if (io_apic_level_ack_pending(cfg)) {
2383 /*
2384 * Interrupt in progress. Migrating irq now will change the
2385 * vector information in the IO-APIC RTE and that will confuse
2386 * the EOI broadcast performed by cpu.
2387 * So, delay the irq migration to the next instance.
2388 */
2389 schedule_delayed_work(&ir_migration_work, 1);
2390 goto unmask;
2391 }
2392
2393 /* everthing is clear. we have right of way */
2394 migrate_ioapic_irq_desc(desc, desc->pending_mask);
2395
2396 ret = 0;
2397 desc->status &= ~IRQ_MOVE_PENDING;
2398 cpumask_clear(desc->pending_mask);
2399
2400unmask:
2401 unmask_IO_APIC_irq_desc(desc);
2402
2403 return ret;
2404}
2405
2406static void ir_irq_migration(struct work_struct *work)
2407{
2408 unsigned int irq;
2409 struct irq_desc *desc;
2410
2411 for_each_irq_desc(irq, desc) {
2412 if (desc->status & IRQ_MOVE_PENDING) {
2413 unsigned long flags;
2414
2415 spin_lock_irqsave(&desc->lock, flags);
2416 if (!desc->chip->set_affinity ||
2417 !(desc->status & IRQ_MOVE_PENDING)) {
2418 desc->status &= ~IRQ_MOVE_PENDING;
2419 spin_unlock_irqrestore(&desc->lock, flags);
2420 continue;
2421 }
2422
2423 desc->chip->set_affinity(irq, desc->pending_mask);
2424 spin_unlock_irqrestore(&desc->lock, flags);
2425 }
2426 }
2427}
2428
2429/* 2384/*
2430 * Migrates the IRQ destination in the process context. 2385 * Migrates the IRQ destination in the process context.
2431 */ 2386 */
2432static void set_ir_ioapic_affinity_irq_desc(struct irq_desc *desc, 2387static void set_ir_ioapic_affinity_irq_desc(struct irq_desc *desc,
2433 const struct cpumask *mask) 2388 const struct cpumask *mask)
2434{ 2389{
2435 if (desc->status & IRQ_LEVEL) {
2436 desc->status |= IRQ_MOVE_PENDING;
2437 cpumask_copy(desc->pending_mask, mask);
2438 migrate_irq_remapped_level_desc(desc);
2439 return;
2440 }
2441
2442 migrate_ioapic_irq_desc(desc, mask); 2390 migrate_ioapic_irq_desc(desc, mask);
2443} 2391}
2444static void set_ir_ioapic_affinity_irq(unsigned int irq, 2392static void set_ir_ioapic_affinity_irq(unsigned int irq,
@@ -2448,6 +2396,11 @@ static void set_ir_ioapic_affinity_irq(unsigned int irq,
2448 2396
2449 set_ir_ioapic_affinity_irq_desc(desc, mask); 2397 set_ir_ioapic_affinity_irq_desc(desc, mask);
2450} 2398}
2399#else
2400static inline void set_ir_ioapic_affinity_irq_desc(struct irq_desc *desc,
2401 const struct cpumask *mask)
2402{
2403}
2451#endif 2404#endif
2452 2405
2453asmlinkage void smp_irq_move_cleanup_interrupt(void) 2406asmlinkage void smp_irq_move_cleanup_interrupt(void)
@@ -2461,6 +2414,7 @@ asmlinkage void smp_irq_move_cleanup_interrupt(void)
2461 me = smp_processor_id(); 2414 me = smp_processor_id();
2462 for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) { 2415 for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
2463 unsigned int irq; 2416 unsigned int irq;
2417 unsigned int irr;
2464 struct irq_desc *desc; 2418 struct irq_desc *desc;
2465 struct irq_cfg *cfg; 2419 struct irq_cfg *cfg;
2466 irq = __get_cpu_var(vector_irq)[vector]; 2420 irq = __get_cpu_var(vector_irq)[vector];
@@ -2480,6 +2434,18 @@ asmlinkage void smp_irq_move_cleanup_interrupt(void)
2480 if (vector == cfg->vector && cpumask_test_cpu(me, cfg->domain)) 2434 if (vector == cfg->vector && cpumask_test_cpu(me, cfg->domain))
2481 goto unlock; 2435 goto unlock;
2482 2436
2437 irr = apic_read(APIC_IRR + (vector / 32 * 0x10));
2438 /*
2439 * Check if the vector that needs to be cleanedup is
2440 * registered at the cpu's IRR. If so, then this is not
2441 * the best time to clean it up. Lets clean it up in the
2442 * next attempt by sending another IRQ_MOVE_CLEANUP_VECTOR
2443 * to myself.
2444 */
2445 if (irr & (1 << (vector % 32))) {
2446 apic->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR);
2447 goto unlock;
2448 }
2483 __get_cpu_var(vector_irq)[vector] = -1; 2449 __get_cpu_var(vector_irq)[vector] = -1;
2484 cfg->move_cleanup_count--; 2450 cfg->move_cleanup_count--;
2485unlock: 2451unlock:
@@ -2529,9 +2495,44 @@ static inline void irq_complete_move(struct irq_desc **descp) {}
2529#endif 2495#endif
2530 2496
2531#ifdef CONFIG_INTR_REMAP 2497#ifdef CONFIG_INTR_REMAP
2498static void __eoi_ioapic_irq(unsigned int irq, struct irq_cfg *cfg)
2499{
2500 int apic, pin;
2501 struct irq_pin_list *entry;
2502
2503 entry = cfg->irq_2_pin;
2504 for (;;) {
2505
2506 if (!entry)
2507 break;
2508
2509 apic = entry->apic;
2510 pin = entry->pin;
2511 io_apic_eoi(apic, pin);
2512 entry = entry->next;
2513 }
2514}
2515
2516static void
2517eoi_ioapic_irq(struct irq_desc *desc)
2518{
2519 struct irq_cfg *cfg;
2520 unsigned long flags;
2521 unsigned int irq;
2522
2523 irq = desc->irq;
2524 cfg = desc->chip_data;
2525
2526 spin_lock_irqsave(&ioapic_lock, flags);
2527 __eoi_ioapic_irq(irq, cfg);
2528 spin_unlock_irqrestore(&ioapic_lock, flags);
2529}
2530
2532static void ack_x2apic_level(unsigned int irq) 2531static void ack_x2apic_level(unsigned int irq)
2533{ 2532{
2533 struct irq_desc *desc = irq_to_desc(irq);
2534 ack_x2APIC_irq(); 2534 ack_x2APIC_irq();
2535 eoi_ioapic_irq(desc);
2535} 2536}
2536 2537
2537static void ack_x2apic_edge(unsigned int irq) 2538static void ack_x2apic_edge(unsigned int irq)
@@ -2901,10 +2902,8 @@ static inline void __init check_timer(void)
2901 * 8259A. 2902 * 8259A.
2902 */ 2903 */
2903 if (pin1 == -1) { 2904 if (pin1 == -1) {
2904#ifdef CONFIG_INTR_REMAP
2905 if (intr_remapping_enabled) 2905 if (intr_remapping_enabled)
2906 panic("BIOS bug: timer not connected to IO-APIC"); 2906 panic("BIOS bug: timer not connected to IO-APIC");
2907#endif
2908 pin1 = pin2; 2907 pin1 = pin2;
2909 apic1 = apic2; 2908 apic1 = apic2;
2910 no_pin1 = 1; 2909 no_pin1 = 1;
@@ -2940,10 +2939,8 @@ static inline void __init check_timer(void)
2940 clear_IO_APIC_pin(0, pin1); 2939 clear_IO_APIC_pin(0, pin1);
2941 goto out; 2940 goto out;
2942 } 2941 }
2943#ifdef CONFIG_INTR_REMAP
2944 if (intr_remapping_enabled) 2942 if (intr_remapping_enabled)
2945 panic("timer doesn't work through Interrupt-remapped IO-APIC"); 2943 panic("timer doesn't work through Interrupt-remapped IO-APIC");
2946#endif
2947 local_irq_disable(); 2944 local_irq_disable();
2948 clear_IO_APIC_pin(apic1, pin1); 2945 clear_IO_APIC_pin(apic1, pin1);
2949 if (!no_pin1) 2946 if (!no_pin1)
@@ -3237,9 +3234,7 @@ void destroy_irq(unsigned int irq)
3237 if (desc) 3234 if (desc)
3238 desc->chip_data = cfg; 3235 desc->chip_data = cfg;
3239 3236
3240#ifdef CONFIG_INTR_REMAP
3241 free_irte(irq); 3237 free_irte(irq);
3242#endif
3243 spin_lock_irqsave(&vector_lock, flags); 3238 spin_lock_irqsave(&vector_lock, flags);
3244 __clear_irq_vector(irq, cfg); 3239 __clear_irq_vector(irq, cfg);
3245 spin_unlock_irqrestore(&vector_lock, flags); 3240 spin_unlock_irqrestore(&vector_lock, flags);
@@ -3265,7 +3260,6 @@ static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_ms
3265 3260
3266 dest = apic->cpu_mask_to_apicid_and(cfg->domain, apic->target_cpus()); 3261 dest = apic->cpu_mask_to_apicid_and(cfg->domain, apic->target_cpus());
3267 3262
3268#ifdef CONFIG_INTR_REMAP
3269 if (irq_remapped(irq)) { 3263 if (irq_remapped(irq)) {
3270 struct irte irte; 3264 struct irte irte;
3271 int ir_index; 3265 int ir_index;
@@ -3291,10 +3285,13 @@ static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_ms
3291 MSI_ADDR_IR_SHV | 3285 MSI_ADDR_IR_SHV |
3292 MSI_ADDR_IR_INDEX1(ir_index) | 3286 MSI_ADDR_IR_INDEX1(ir_index) |
3293 MSI_ADDR_IR_INDEX2(ir_index); 3287 MSI_ADDR_IR_INDEX2(ir_index);
3294 } else 3288 } else {
3295#endif 3289 if (x2apic_enabled())
3296 { 3290 msg->address_hi = MSI_ADDR_BASE_HI |
3297 msg->address_hi = MSI_ADDR_BASE_HI; 3291 MSI_ADDR_EXT_DEST_ID(dest);
3292 else
3293 msg->address_hi = MSI_ADDR_BASE_HI;
3294
3298 msg->address_lo = 3295 msg->address_lo =
3299 MSI_ADDR_BASE_LO | 3296 MSI_ADDR_BASE_LO |
3300 ((apic->irq_dest_mode == 0) ? 3297 ((apic->irq_dest_mode == 0) ?
@@ -3405,6 +3402,7 @@ static struct irq_chip msi_ir_chip = {
3405#endif 3402#endif
3406 .retrigger = ioapic_retrigger_irq, 3403 .retrigger = ioapic_retrigger_irq,
3407}; 3404};
3405#endif
3408 3406
3409/* 3407/*
3410 * Map the PCI dev to the corresponding remapping hardware unit 3408 * Map the PCI dev to the corresponding remapping hardware unit
@@ -3432,7 +3430,6 @@ static int msi_alloc_irte(struct pci_dev *dev, int irq, int nvec)
3432 } 3430 }
3433 return index; 3431 return index;
3434} 3432}
3435#endif
3436 3433
3437static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int irq) 3434static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int irq)
3438{ 3435{
@@ -3446,7 +3443,6 @@ static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int irq)
3446 set_irq_msi(irq, msidesc); 3443 set_irq_msi(irq, msidesc);
3447 write_msi_msg(irq, &msg); 3444 write_msi_msg(irq, &msg);
3448 3445
3449#ifdef CONFIG_INTR_REMAP
3450 if (irq_remapped(irq)) { 3446 if (irq_remapped(irq)) {
3451 struct irq_desc *desc = irq_to_desc(irq); 3447 struct irq_desc *desc = irq_to_desc(irq);
3452 /* 3448 /*
@@ -3455,7 +3451,6 @@ static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int irq)
3455 desc->status |= IRQ_MOVE_PCNTXT; 3451 desc->status |= IRQ_MOVE_PCNTXT;
3456 set_irq_chip_and_handler_name(irq, &msi_ir_chip, handle_edge_irq, "edge"); 3452 set_irq_chip_and_handler_name(irq, &msi_ir_chip, handle_edge_irq, "edge");
3457 } else 3453 } else
3458#endif
3459 set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, "edge"); 3454 set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, "edge");
3460 3455
3461 dev_printk(KERN_DEBUG, &dev->dev, "irq %d for MSI/MSI-X\n", irq); 3456 dev_printk(KERN_DEBUG, &dev->dev, "irq %d for MSI/MSI-X\n", irq);
@@ -3469,11 +3464,8 @@ int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
3469 int ret, sub_handle; 3464 int ret, sub_handle;
3470 struct msi_desc *msidesc; 3465 struct msi_desc *msidesc;
3471 unsigned int irq_want; 3466 unsigned int irq_want;
3472
3473#ifdef CONFIG_INTR_REMAP
3474 struct intel_iommu *iommu = 0; 3467 struct intel_iommu *iommu = 0;
3475 int index = 0; 3468 int index = 0;
3476#endif
3477 3469
3478 irq_want = nr_irqs_gsi; 3470 irq_want = nr_irqs_gsi;
3479 sub_handle = 0; 3471 sub_handle = 0;
@@ -3482,7 +3474,6 @@ int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
3482 if (irq == 0) 3474 if (irq == 0)
3483 return -1; 3475 return -1;
3484 irq_want = irq + 1; 3476 irq_want = irq + 1;
3485#ifdef CONFIG_INTR_REMAP
3486 if (!intr_remapping_enabled) 3477 if (!intr_remapping_enabled)
3487 goto no_ir; 3478 goto no_ir;
3488 3479
@@ -3510,7 +3501,6 @@ int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
3510 set_irte_irq(irq, iommu, index, sub_handle); 3501 set_irte_irq(irq, iommu, index, sub_handle);
3511 } 3502 }
3512no_ir: 3503no_ir:
3513#endif
3514 ret = setup_msi_irq(dev, msidesc, irq); 3504 ret = setup_msi_irq(dev, msidesc, irq);
3515 if (ret < 0) 3505 if (ret < 0)
3516 goto error; 3506 goto error;
@@ -3528,7 +3518,7 @@ void arch_teardown_msi_irq(unsigned int irq)
3528 destroy_irq(irq); 3518 destroy_irq(irq);
3529} 3519}
3530 3520
3531#ifdef CONFIG_DMAR 3521#if defined (CONFIG_DMAR) || defined (CONFIG_INTR_REMAP)
3532#ifdef CONFIG_SMP 3522#ifdef CONFIG_SMP
3533static void dmar_msi_set_affinity(unsigned int irq, const struct cpumask *mask) 3523static void dmar_msi_set_affinity(unsigned int irq, const struct cpumask *mask)
3534{ 3524{
@@ -4045,11 +4035,9 @@ void __init setup_ioapic_dest(void)
4045 else 4035 else
4046 mask = apic->target_cpus(); 4036 mask = apic->target_cpus();
4047 4037
4048#ifdef CONFIG_INTR_REMAP
4049 if (intr_remapping_enabled) 4038 if (intr_remapping_enabled)
4050 set_ir_ioapic_affinity_irq_desc(desc, mask); 4039 set_ir_ioapic_affinity_irq_desc(desc, mask);
4051 else 4040 else
4052#endif
4053 set_ioapic_affinity_irq_desc(desc, mask); 4041 set_ioapic_affinity_irq_desc(desc, mask);
4054 } 4042 }
4055 4043