| 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> | 
| Frederic Weisbecker | bcbc4f2 | 2008-12-09 23:54:20 +0100 | [diff] [blame] | 16 | #include <linux/ftrace.h> | 
| Jaswinder Singh Rajput | 5f66b2a | 2009-01-04 16:25:19 +0530 | [diff] [blame] | 17 | #include <linux/uaccess.h> | 
|  | 18 | #include <linux/smp.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/io_apic.h> | 
| Andi Kleen | 95833c8 | 2006-01-11 22:44:36 +0100 | [diff] [blame] | 20 | #include <asm/idle.h> | 
| Brian Gerst | 3819cd4 | 2009-01-23 11:03:29 +0900 | [diff] [blame] | 21 | #include <asm/apic.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 |  | 
| Brian Gerst | 1b437c8 | 2009-01-19 00:38:57 +0900 | [diff] [blame] | 23 | DEFINE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat); | 
|  | 24 | EXPORT_PER_CPU_SYMBOL(irq_stat); | 
|  | 25 |  | 
| Brian Gerst | d650a51 | 2009-01-21 17:26:06 +0900 | [diff] [blame] | 26 | DEFINE_PER_CPU(struct pt_regs *, irq_regs); | 
|  | 27 | EXPORT_PER_CPU_SYMBOL(irq_regs); | 
|  | 28 |  | 
| Eric Sandeen | 4961f10 | 2006-06-26 14:00:05 +0200 | [diff] [blame] | 29 | /* | 
|  | 30 | * Probabilistic stack overflow check: | 
|  | 31 | * | 
|  | 32 | * Only check the stack in process context, because everything else | 
|  | 33 | * runs on the big interrupt stacks. Checking reliably is too expensive, | 
|  | 34 | * so we just check from interrupts. | 
|  | 35 | */ | 
|  | 36 | static inline void stack_overflow_check(struct pt_regs *regs) | 
|  | 37 | { | 
| Ingo Molnar | f377fa1 | 2008-11-23 09:02:26 +0100 | [diff] [blame] | 38 | #ifdef CONFIG_DEBUG_STACKOVERFLOW | 
| Roman Zippel | c9f4f06 | 2007-05-09 02:35:16 -0700 | [diff] [blame] | 39 | u64 curbase = (u64)task_stack_page(current); | 
| Eric Sandeen | 4961f10 | 2006-06-26 14:00:05 +0200 | [diff] [blame] | 40 |  | 
| Ingo Molnar | f377fa1 | 2008-11-23 09:02:26 +0100 | [diff] [blame] | 41 | WARN_ONCE(regs->sp >= curbase && | 
|  | 42 | regs->sp <= curbase + THREAD_SIZE && | 
|  | 43 | regs->sp <  curbase + sizeof(struct thread_info) + | 
|  | 44 | sizeof(struct pt_regs) + 128, | 
|  | 45 |  | 
|  | 46 | "do_IRQ: %s near stack overflow (cur:%Lx,sp:%lx)\n", | 
|  | 47 | current->comm, curbase, regs->sp); | 
| Eric Sandeen | 4961f10 | 2006-06-26 14:00:05 +0200 | [diff] [blame] | 48 | #endif | 
| Ingo Molnar | f377fa1 | 2008-11-23 09:02:26 +0100 | [diff] [blame] | 49 | } | 
| Eric Sandeen | 4961f10 | 2006-06-26 14:00:05 +0200 | [diff] [blame] | 50 |  | 
| Jeremy Fitzhardinge | 9b2b76a | 2009-02-06 14:09:40 -0800 | [diff] [blame] | 51 | bool handle_irq(unsigned irq, struct pt_regs *regs) | 
|  | 52 | { | 
|  | 53 | struct irq_desc *desc; | 
|  | 54 |  | 
|  | 55 | stack_overflow_check(regs); | 
|  | 56 |  | 
|  | 57 | desc = irq_to_desc(irq); | 
|  | 58 | if (unlikely(!desc)) | 
|  | 59 | return false; | 
|  | 60 |  | 
|  | 61 | generic_handle_irq_desc(irq, desc); | 
|  | 62 | return true; | 
|  | 63 | } | 
|  | 64 |  | 
| Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 65 |  | 
|  | 66 | extern void call_softirq(void); | 
|  | 67 |  | 
|  | 68 | asmlinkage void do_softirq(void) | 
|  | 69 | { | 
| Jaswinder Singh Rajput | 5f66b2a | 2009-01-04 16:25:19 +0530 | [diff] [blame] | 70 | __u32 pending; | 
|  | 71 | unsigned long flags; | 
| Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 72 |  | 
| Jaswinder Singh Rajput | 5f66b2a | 2009-01-04 16:25:19 +0530 | [diff] [blame] | 73 | if (in_interrupt()) | 
|  | 74 | return; | 
| Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 75 |  | 
| Jaswinder Singh Rajput | 5f66b2a | 2009-01-04 16:25:19 +0530 | [diff] [blame] | 76 | local_irq_save(flags); | 
|  | 77 | pending = local_softirq_pending(); | 
|  | 78 | /* Switch to interrupt stack */ | 
|  | 79 | if (pending) { | 
| Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 80 | call_softirq(); | 
| Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 81 | WARN_ON_ONCE(softirq_count()); | 
|  | 82 | } | 
| Jaswinder Singh Rajput | 5f66b2a | 2009-01-04 16:25:19 +0530 | [diff] [blame] | 83 | local_irq_restore(flags); | 
| Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 84 | } |