ath9k: Fix IRQ nobody cared issue with ath9k
[pandora-kernel.git] / arch / avr32 / kernel / traps.c
1 /*
2  * Copyright (C) 2004-2006 Atmel Corporation
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8
9 #include <linux/bug.h>
10 #include <linux/init.h>
11 #include <linux/kallsyms.h>
12 #include <linux/kdebug.h>
13 #include <linux/module.h>
14 #include <linux/notifier.h>
15 #include <linux/sched.h>
16 #include <linux/uaccess.h>
17
18 #include <asm/addrspace.h>
19 #include <asm/mmu_context.h>
20 #include <asm/ocd.h>
21 #include <asm/sysreg.h>
22 #include <asm/traps.h>
23
24 static DEFINE_SPINLOCK(die_lock);
25
26 void NORET_TYPE die(const char *str, struct pt_regs *regs, long err)
27 {
28         static int die_counter;
29
30         console_verbose();
31         spin_lock_irq(&die_lock);
32         bust_spinlocks(1);
33
34         printk(KERN_ALERT "Oops: %s, sig: %ld [#%d]\n" KERN_EMERG,
35                str, err, ++die_counter);
36 #ifdef CONFIG_PREEMPT
37         printk("PREEMPT ");
38 #endif
39 #ifdef CONFIG_FRAME_POINTER
40         printk("FRAME_POINTER ");
41 #endif
42         if (current_cpu_data.features & AVR32_FEATURE_OCD) {
43                 unsigned long did = ocd_read(DID);
44                 printk("chip: 0x%03lx:0x%04lx rev %lu\n",
45                        (did >> 1) & 0x7ff,
46                        (did >> 12) & 0x7fff,
47                        (did >> 28) & 0xf);
48         } else {
49                 printk("cpu: arch %u r%u / core %u r%u\n",
50                        current_cpu_data.arch_type,
51                        current_cpu_data.arch_revision,
52                        current_cpu_data.cpu_type,
53                        current_cpu_data.cpu_revision);
54         }
55
56         print_modules();
57         show_regs_log_lvl(regs, KERN_EMERG);
58         show_stack_log_lvl(current, regs->sp, regs, KERN_EMERG);
59         bust_spinlocks(0);
60         add_taint(TAINT_DIE);
61         spin_unlock_irq(&die_lock);
62
63         if (in_interrupt())
64                 panic("Fatal exception in interrupt");
65
66         if (panic_on_oops)
67                 panic("Fatal exception");
68
69         do_exit(err);
70 }
71
72 void _exception(long signr, struct pt_regs *regs, int code,
73                 unsigned long addr)
74 {
75         siginfo_t info;
76
77         if (!user_mode(regs))
78                 die("Unhandled exception in kernel mode", regs, signr);
79
80         memset(&info, 0, sizeof(info));
81         info.si_signo = signr;
82         info.si_code = code;
83         info.si_addr = (void __user *)addr;
84         force_sig_info(signr, &info, current);
85
86         /*
87          * Init gets no signals that it doesn't have a handler for.
88          * That's all very well, but if it has caused a synchronous
89          * exception and we ignore the resulting signal, it will just
90          * generate the same exception over and over again and we get
91          * nowhere.  Better to kill it and let the kernel panic.
92          */
93         if (is_global_init(current)) {
94                 __sighandler_t handler;
95
96                 spin_lock_irq(&current->sighand->siglock);
97                 handler = current->sighand->action[signr-1].sa.sa_handler;
98                 spin_unlock_irq(&current->sighand->siglock);
99                 if (handler == SIG_DFL) {
100                         /* init has generated a synchronous exception
101                            and it doesn't have a handler for the signal */
102                         printk(KERN_CRIT "init has generated signal %ld "
103                                "but has no handler for it\n", signr);
104                         do_exit(signr);
105                 }
106         }
107 }
108
109 asmlinkage void do_nmi(unsigned long ecr, struct pt_regs *regs)
110 {
111         int ret;
112
113         nmi_enter();
114
115         ret = notify_die(DIE_NMI, "NMI", regs, 0, ecr, SIGINT);
116         switch (ret) {
117         case NOTIFY_OK:
118         case NOTIFY_STOP:
119                 return;
120         case NOTIFY_BAD:
121                 die("Fatal Non-Maskable Interrupt", regs, SIGINT);
122         default:
123                 break;
124         }
125
126         printk(KERN_ALERT "Got NMI, but nobody cared. Disabling...\n");
127         nmi_disable();
128 }
129
130 asmlinkage void do_critical_exception(unsigned long ecr, struct pt_regs *regs)
131 {
132         die("Critical exception", regs, SIGKILL);
133 }
134
135 asmlinkage void do_address_exception(unsigned long ecr, struct pt_regs *regs)
136 {
137         _exception(SIGBUS, regs, BUS_ADRALN, regs->pc);
138 }
139
140 /* This way of handling undefined instructions is stolen from ARM */
141 static LIST_HEAD(undef_hook);
142 static DEFINE_SPINLOCK(undef_lock);
143
144 void register_undef_hook(struct undef_hook *hook)
145 {
146         spin_lock_irq(&undef_lock);
147         list_add(&hook->node, &undef_hook);
148         spin_unlock_irq(&undef_lock);
149 }
150
151 void unregister_undef_hook(struct undef_hook *hook)
152 {
153         spin_lock_irq(&undef_lock);
154         list_del(&hook->node);
155         spin_unlock_irq(&undef_lock);
156 }
157
158 static int do_cop_absent(u32 insn)
159 {
160         int cop_nr;
161         u32 cpucr;
162
163         if ((insn & 0xfdf00000) == 0xf1900000)
164                 /* LDC0 */
165                 cop_nr = 0;
166         else
167                 cop_nr = (insn >> 13) & 0x7;
168
169         /* Try enabling the coprocessor */
170         cpucr = sysreg_read(CPUCR);
171         cpucr |= (1 << (24 + cop_nr));
172         sysreg_write(CPUCR, cpucr);
173
174         cpucr = sysreg_read(CPUCR);
175         if (!(cpucr & (1 << (24 + cop_nr))))
176                 return -ENODEV;
177
178         return 0;
179 }
180
181 #ifdef CONFIG_BUG
182 int is_valid_bugaddr(unsigned long pc)
183 {
184         unsigned short opcode;
185
186         if (pc < PAGE_OFFSET)
187                 return 0;
188         if (probe_kernel_address((u16 *)pc, opcode))
189                 return 0;
190
191         return opcode == AVR32_BUG_OPCODE;
192 }
193 #endif
194
195 asmlinkage void do_illegal_opcode(unsigned long ecr, struct pt_regs *regs)
196 {
197         u32 insn;
198         struct undef_hook *hook;
199         void __user *pc;
200         long code;
201
202 #ifdef CONFIG_BUG
203         if (!user_mode(regs) && (ecr == ECR_ILLEGAL_OPCODE)) {
204                 enum bug_trap_type type;
205
206                 type = report_bug(regs->pc, regs);
207                 switch (type) {
208                 case BUG_TRAP_TYPE_NONE:
209                         break;
210                 case BUG_TRAP_TYPE_WARN:
211                         regs->pc += 2;
212                         return;
213                 case BUG_TRAP_TYPE_BUG:
214                         die("Kernel BUG", regs, SIGKILL);
215                 }
216         }
217 #endif
218
219         local_irq_enable();
220
221         if (user_mode(regs)) {
222                 pc = (void __user *)instruction_pointer(regs);
223                 if (get_user(insn, (u32 __user *)pc))
224                         goto invalid_area;
225
226                 if (ecr == ECR_COPROC_ABSENT && !do_cop_absent(insn))
227                         return;
228
229                 spin_lock_irq(&undef_lock);
230                 list_for_each_entry(hook, &undef_hook, node) {
231                         if ((insn & hook->insn_mask) == hook->insn_val) {
232                                 if (hook->fn(regs, insn) == 0) {
233                                         spin_unlock_irq(&undef_lock);
234                                         return;
235                                 }
236                         }
237                 }
238                 spin_unlock_irq(&undef_lock);
239         }
240
241         switch (ecr) {
242         case ECR_PRIVILEGE_VIOLATION:
243                 code = ILL_PRVOPC;
244                 break;
245         case ECR_COPROC_ABSENT:
246                 code = ILL_COPROC;
247                 break;
248         default:
249                 code = ILL_ILLOPC;
250                 break;
251         }
252
253         _exception(SIGILL, regs, code, regs->pc);
254         return;
255
256 invalid_area:
257         _exception(SIGSEGV, regs, SEGV_MAPERR, regs->pc);
258 }
259
260 asmlinkage void do_fpe(unsigned long ecr, struct pt_regs *regs)
261 {
262         /* We have no FPU yet */
263         _exception(SIGILL, regs, ILL_COPROC, regs->pc);
264 }
265
266
267 void __init trap_init(void)
268 {
269
270 }