Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar |
| 3 | * |
| 4 | * This file contains the lowest level x86_64-specific interrupt |
| 5 | * entry and irq statistics code. All the remaining irq logic is |
| 6 | * done by the generic kernel/irq/ code and in the |
| 7 | * x86_64-specific irq controller code. (e.g. i8259.c and |
| 8 | * io_apic.c.) |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kernel_stat.h> |
| 12 | #include <linux/interrupt.h> |
| 13 | #include <linux/seq_file.h> |
| 14 | #include <linux/module.h> |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 15 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/uaccess.h> |
| 17 | #include <asm/io_apic.h> |
Andi Kleen | 95833c8 | 2006-01-11 22:44:36 +0100 | [diff] [blame] | 18 | #include <asm/idle.h> |
Eric W. Biederman | 2fb12a9 | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 19 | #include <asm/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Eric Sandeen | 4961f10 | 2006-06-26 14:00:05 +0200 | [diff] [blame] | 21 | /* |
| 22 | * Probabilistic stack overflow check: |
| 23 | * |
| 24 | * Only check the stack in process context, because everything else |
| 25 | * runs on the big interrupt stacks. Checking reliably is too expensive, |
| 26 | * so we just check from interrupts. |
| 27 | */ |
| 28 | static inline void stack_overflow_check(struct pt_regs *regs) |
| 29 | { |
Ingo Molnar | f377fa1 | 2008-11-23 09:02:26 +0100 | [diff] [blame^] | 30 | #ifdef CONFIG_DEBUG_STACKOVERFLOW |
Roman Zippel | c9f4f06 | 2007-05-09 02:35:16 -0700 | [diff] [blame] | 31 | u64 curbase = (u64)task_stack_page(current); |
Eric Sandeen | 4961f10 | 2006-06-26 14:00:05 +0200 | [diff] [blame] | 32 | |
Ingo Molnar | f377fa1 | 2008-11-23 09:02:26 +0100 | [diff] [blame^] | 33 | WARN_ONCE(regs->sp >= curbase && |
| 34 | regs->sp <= curbase + THREAD_SIZE && |
| 35 | regs->sp < curbase + sizeof(struct thread_info) + |
| 36 | sizeof(struct pt_regs) + 128, |
| 37 | |
| 38 | "do_IRQ: %s near stack overflow (cur:%Lx,sp:%lx)\n", |
| 39 | current->comm, curbase, regs->sp); |
Eric Sandeen | 4961f10 | 2006-06-26 14:00:05 +0200 | [diff] [blame] | 40 | #endif |
Ingo Molnar | f377fa1 | 2008-11-23 09:02:26 +0100 | [diff] [blame^] | 41 | } |
Eric Sandeen | 4961f10 | 2006-06-26 14:00:05 +0200 | [diff] [blame] | 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | * do_IRQ handles all normal device IRQ's (the special |
| 45 | * SMP cross-CPU interrupts have their own specific |
| 46 | * handlers). |
| 47 | */ |
| 48 | asmlinkage unsigned int do_IRQ(struct pt_regs *regs) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 49 | { |
| 50 | struct pt_regs *old_regs = set_irq_regs(regs); |
Yinghai Lu | 46926b6 | 2008-08-19 20:50:15 -0700 | [diff] [blame] | 51 | struct irq_desc *desc; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 52 | |
Rusty Russell | 19eadf9 | 2006-06-27 02:53:44 -0700 | [diff] [blame] | 53 | /* high bit used in ret_from_ code */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 54 | unsigned vector = ~regs->orig_ax; |
Eric W. Biederman | e500f57 | 2006-10-04 02:16:50 -0700 | [diff] [blame] | 55 | unsigned irq; |
| 56 | |
| 57 | exit_idle(); |
| 58 | irq_enter(); |
Eric W. Biederman | 550f229 | 2006-10-04 02:16:51 -0700 | [diff] [blame] | 59 | irq = __get_cpu_var(vector_irq)[vector]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Eric Sandeen | 4961f10 | 2006-06-26 14:00:05 +0200 | [diff] [blame] | 61 | stack_overflow_check(regs); |
Eric W. Biederman | d3696cf | 2006-10-08 23:41:59 -0600 | [diff] [blame] | 62 | |
Yinghai Lu | cb5bc83 | 2008-08-19 20:50:17 -0700 | [diff] [blame] | 63 | desc = irq_to_desc(irq); |
Yinghai Lu | 46926b6 | 2008-08-19 20:50:15 -0700 | [diff] [blame] | 64 | if (likely(desc)) |
| 65 | generic_handle_irq_desc(irq, desc); |
Eric W. Biederman | 2fb12a9 | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 66 | else { |
| 67 | if (!disable_apic) |
| 68 | ack_APIC_irq(); |
| 69 | |
| 70 | if (printk_ratelimit()) |
| 71 | printk(KERN_EMERG "%s: %d.%d No irq handler for vector\n", |
| 72 | __func__, smp_processor_id(), vector); |
| 73 | } |
Eric W. Biederman | d3696cf | 2006-10-08 23:41:59 -0600 | [diff] [blame] | 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | irq_exit(); |
| 76 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 77 | set_irq_regs(old_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | return 1; |
| 79 | } |
| 80 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 81 | #ifdef CONFIG_HOTPLUG_CPU |
| 82 | void fixup_irqs(cpumask_t map) |
| 83 | { |
| 84 | unsigned int irq; |
| 85 | static int warned; |
Yinghai Lu | 2c6927a | 2008-08-19 20:50:11 -0700 | [diff] [blame] | 86 | struct irq_desc *desc; |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 87 | |
Yinghai Lu | 2c6927a | 2008-08-19 20:50:11 -0700 | [diff] [blame] | 88 | for_each_irq_desc(irq, desc) { |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 89 | cpumask_t mask; |
Siddha, Suresh B | 48d8d7e | 2007-06-25 15:52:35 -0700 | [diff] [blame] | 90 | int break_affinity = 0; |
| 91 | int set_affinity = 1; |
| 92 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 93 | if (irq == 2) |
| 94 | continue; |
| 95 | |
Siddha, Suresh B | 48d8d7e | 2007-06-25 15:52:35 -0700 | [diff] [blame] | 96 | /* interrupt's are disabled at this point */ |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 97 | spin_lock(&desc->lock); |
Siddha, Suresh B | 48d8d7e | 2007-06-25 15:52:35 -0700 | [diff] [blame] | 98 | |
| 99 | if (!irq_has_action(irq) || |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 100 | cpus_equal(desc->affinity, map)) { |
| 101 | spin_unlock(&desc->lock); |
Siddha, Suresh B | 48d8d7e | 2007-06-25 15:52:35 -0700 | [diff] [blame] | 102 | continue; |
| 103 | } |
| 104 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 105 | cpus_and(mask, desc->affinity, map); |
Siddha, Suresh B | 48d8d7e | 2007-06-25 15:52:35 -0700 | [diff] [blame] | 106 | if (cpus_empty(mask)) { |
| 107 | break_affinity = 1; |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 108 | mask = map; |
| 109 | } |
Siddha, Suresh B | 48d8d7e | 2007-06-25 15:52:35 -0700 | [diff] [blame] | 110 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 111 | if (desc->chip->mask) |
| 112 | desc->chip->mask(irq); |
Siddha, Suresh B | 48d8d7e | 2007-06-25 15:52:35 -0700 | [diff] [blame] | 113 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 114 | if (desc->chip->set_affinity) |
| 115 | desc->chip->set_affinity(irq, mask); |
Siddha, Suresh B | 48d8d7e | 2007-06-25 15:52:35 -0700 | [diff] [blame] | 116 | else if (!(warned++)) |
| 117 | set_affinity = 0; |
| 118 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 119 | if (desc->chip->unmask) |
| 120 | desc->chip->unmask(irq); |
Siddha, Suresh B | 48d8d7e | 2007-06-25 15:52:35 -0700 | [diff] [blame] | 121 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 122 | spin_unlock(&desc->lock); |
Siddha, Suresh B | 48d8d7e | 2007-06-25 15:52:35 -0700 | [diff] [blame] | 123 | |
| 124 | if (break_affinity && set_affinity) |
| 125 | printk("Broke affinity for irq %i\n", irq); |
| 126 | else if (!set_affinity) |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 127 | printk("Cannot set affinity for irq %i\n", irq); |
| 128 | } |
| 129 | |
| 130 | /* That doesn't seem sufficient. Give it 1ms. */ |
| 131 | local_irq_enable(); |
| 132 | mdelay(1); |
| 133 | local_irq_disable(); |
| 134 | } |
| 135 | #endif |
Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 136 | |
| 137 | extern void call_softirq(void); |
| 138 | |
| 139 | asmlinkage void do_softirq(void) |
| 140 | { |
| 141 | __u32 pending; |
| 142 | unsigned long flags; |
| 143 | |
| 144 | if (in_interrupt()) |
| 145 | return; |
| 146 | |
| 147 | local_irq_save(flags); |
| 148 | pending = local_softirq_pending(); |
| 149 | /* Switch to interrupt stack */ |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 150 | if (pending) { |
Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 151 | call_softirq(); |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 152 | WARN_ON_ONCE(softirq_count()); |
| 153 | } |
Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 154 | local_irq_restore(flags); |
| 155 | } |