]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/blackfin/kernel/traps.c
Merge tag 'efi-urgent' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi into...
[mirror_ubuntu-artful-kernel.git] / arch / blackfin / kernel / traps.c
1 /*
2 * Main exception handling logic.
3 *
4 * Copyright 2004-2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later
7 */
8
9 #include <linux/bug.h>
10 #include <linux/uaccess.h>
11 #include <linux/module.h>
12 #include <linux/sched/signal.h>
13 #include <linux/sched/debug.h>
14 #include <asm/traps.h>
15 #include <asm/cplb.h>
16 #include <asm/blackfin.h>
17 #include <asm/irq_handler.h>
18 #include <linux/irq.h>
19 #include <asm/trace.h>
20 #include <asm/fixed_code.h>
21 #include <asm/pseudo_instructions.h>
22 #include <asm/pda.h>
23 #include <asm/asm-offsets.h>
24
25 #ifdef CONFIG_KGDB
26 # include <linux/kgdb.h>
27
28 # define CHK_DEBUGGER_TRAP() \
29 do { \
30 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
31 } while (0)
32 # define CHK_DEBUGGER_TRAP_MAYBE() \
33 do { \
34 if (kgdb_connected) \
35 CHK_DEBUGGER_TRAP(); \
36 } while (0)
37 #else
38 # define CHK_DEBUGGER_TRAP() do { } while (0)
39 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
40 #endif
41
42
43 #ifdef CONFIG_DEBUG_VERBOSE
44 #define verbose_printk(fmt, arg...) \
45 printk(fmt, ##arg)
46 #else
47 #define verbose_printk(fmt, arg...) \
48 ({ if (0) printk(fmt, ##arg); 0; })
49 #endif
50
51 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
52 u32 last_seqstat;
53 #ifdef CONFIG_DEBUG_MMRS_MODULE
54 EXPORT_SYMBOL(last_seqstat);
55 #endif
56 #endif
57
58 /* Initiate the event table handler */
59 void __init trap_init(void)
60 {
61 CSYNC();
62 bfin_write_EVT3(trap);
63 CSYNC();
64 }
65
66 static int kernel_mode_regs(struct pt_regs *regs)
67 {
68 return regs->ipend & 0xffc0;
69 }
70
71 asmlinkage notrace void trap_c(struct pt_regs *fp)
72 {
73 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
74 int j;
75 #endif
76 #ifdef CONFIG_BFIN_PSEUDODBG_INSNS
77 int opcode;
78 #endif
79 unsigned int cpu = raw_smp_processor_id();
80 const char *strerror = NULL;
81 int sig = 0;
82 siginfo_t info;
83 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
84
85 trace_buffer_save(j);
86 #if defined(CONFIG_DEBUG_MMRS) || defined(CONFIG_DEBUG_MMRS_MODULE)
87 last_seqstat = (u32)fp->seqstat;
88 #endif
89
90 /* Important - be very careful dereferncing pointers - will lead to
91 * double faults if the stack has become corrupt
92 */
93
94 /* trap_c() will be called for exceptions. During exceptions
95 * processing, the pc value should be set with retx value.
96 * With this change we can cleanup some code in signal.c- TODO
97 */
98 fp->orig_pc = fp->retx;
99 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
100 trapnr, fp->ipend, fp->pc, fp->retx); */
101
102 /* send the appropriate signal to the user program */
103 switch (trapnr) {
104
105 /* This table works in conjunction with the one in ./mach-common/entry.S
106 * Some exceptions are handled there (in assembly, in exception space)
107 * Some are handled here, (in C, in interrupt space)
108 * Some, like CPLB, are handled in both, where the normal path is
109 * handled in assembly/exception space, and the error path is handled
110 * here
111 */
112
113 /* 0x00 - Linux Syscall, getting here is an error */
114 /* 0x01 - userspace gdb breakpoint, handled here */
115 case VEC_EXCPT01:
116 info.si_code = TRAP_ILLTRAP;
117 sig = SIGTRAP;
118 CHK_DEBUGGER_TRAP_MAYBE();
119 /* Check if this is a breakpoint in kernel space */
120 if (kernel_mode_regs(fp))
121 goto traps_done;
122 else
123 break;
124 /* 0x03 - User Defined, userspace stack overflow */
125 case VEC_EXCPT03:
126 info.si_code = SEGV_STACKFLOW;
127 sig = SIGSEGV;
128 strerror = KERN_NOTICE EXC_0x03(KERN_NOTICE);
129 CHK_DEBUGGER_TRAP_MAYBE();
130 break;
131 /* 0x02 - KGDB initial connection and break signal trap */
132 case VEC_EXCPT02:
133 #ifdef CONFIG_KGDB
134 info.si_code = TRAP_ILLTRAP;
135 sig = SIGTRAP;
136 CHK_DEBUGGER_TRAP();
137 goto traps_done;
138 #endif
139 /* 0x04 - User Defined */
140 /* 0x05 - User Defined */
141 /* 0x06 - User Defined */
142 /* 0x07 - User Defined */
143 /* 0x08 - User Defined */
144 /* 0x09 - User Defined */
145 /* 0x0A - User Defined */
146 /* 0x0B - User Defined */
147 /* 0x0C - User Defined */
148 /* 0x0D - User Defined */
149 /* 0x0E - User Defined */
150 /* 0x0F - User Defined */
151 /* If we got here, it is most likely that someone was trying to use a
152 * custom exception handler, and it is not actually installed properly
153 */
154 case VEC_EXCPT04 ... VEC_EXCPT15:
155 info.si_code = ILL_ILLPARAOP;
156 sig = SIGILL;
157 strerror = KERN_NOTICE EXC_0x04(KERN_NOTICE);
158 CHK_DEBUGGER_TRAP_MAYBE();
159 break;
160 /* 0x10 HW Single step, handled here */
161 case VEC_STEP:
162 info.si_code = TRAP_STEP;
163 sig = SIGTRAP;
164 CHK_DEBUGGER_TRAP_MAYBE();
165 /* Check if this is a single step in kernel space */
166 if (kernel_mode_regs(fp))
167 goto traps_done;
168 else
169 break;
170 /* 0x11 - Trace Buffer Full, handled here */
171 case VEC_OVFLOW:
172 info.si_code = TRAP_TRACEFLOW;
173 sig = SIGTRAP;
174 strerror = KERN_NOTICE EXC_0x11(KERN_NOTICE);
175 CHK_DEBUGGER_TRAP_MAYBE();
176 break;
177 /* 0x12 - Reserved, Caught by default */
178 /* 0x13 - Reserved, Caught by default */
179 /* 0x14 - Reserved, Caught by default */
180 /* 0x15 - Reserved, Caught by default */
181 /* 0x16 - Reserved, Caught by default */
182 /* 0x17 - Reserved, Caught by default */
183 /* 0x18 - Reserved, Caught by default */
184 /* 0x19 - Reserved, Caught by default */
185 /* 0x1A - Reserved, Caught by default */
186 /* 0x1B - Reserved, Caught by default */
187 /* 0x1C - Reserved, Caught by default */
188 /* 0x1D - Reserved, Caught by default */
189 /* 0x1E - Reserved, Caught by default */
190 /* 0x1F - Reserved, Caught by default */
191 /* 0x20 - Reserved, Caught by default */
192 /* 0x21 - Undefined Instruction, handled here */
193 case VEC_UNDEF_I:
194 #ifdef CONFIG_BUG
195 if (kernel_mode_regs(fp)) {
196 switch (report_bug(fp->pc, fp)) {
197 case BUG_TRAP_TYPE_NONE:
198 break;
199 case BUG_TRAP_TYPE_WARN:
200 dump_bfin_trace_buffer();
201 fp->pc += 2;
202 goto traps_done;
203 case BUG_TRAP_TYPE_BUG:
204 /* call to panic() will dump trace, and it is
205 * off at this point, so it won't be clobbered
206 */
207 panic("BUG()");
208 }
209 }
210 #endif
211 #ifdef CONFIG_BFIN_PSEUDODBG_INSNS
212 /*
213 * Support for the fake instructions, if the instruction fails,
214 * then just execute a illegal opcode failure (like normal).
215 * Don't support these instructions inside the kernel
216 */
217 if (!kernel_mode_regs(fp) && get_instruction(&opcode, (unsigned short *)fp->pc)) {
218 if (execute_pseudodbg_assert(fp, opcode))
219 goto traps_done;
220 if (execute_pseudodbg(fp, opcode))
221 goto traps_done;
222 }
223 #endif
224 info.si_code = ILL_ILLOPC;
225 sig = SIGILL;
226 strerror = KERN_NOTICE EXC_0x21(KERN_NOTICE);
227 CHK_DEBUGGER_TRAP_MAYBE();
228 break;
229 /* 0x22 - Illegal Instruction Combination, handled here */
230 case VEC_ILGAL_I:
231 info.si_code = ILL_ILLPARAOP;
232 sig = SIGILL;
233 strerror = KERN_NOTICE EXC_0x22(KERN_NOTICE);
234 CHK_DEBUGGER_TRAP_MAYBE();
235 break;
236 /* 0x23 - Data CPLB protection violation, handled here */
237 case VEC_CPLB_VL:
238 info.si_code = ILL_CPLB_VI;
239 sig = SIGSEGV;
240 strerror = KERN_NOTICE EXC_0x23(KERN_NOTICE);
241 CHK_DEBUGGER_TRAP_MAYBE();
242 break;
243 /* 0x24 - Data access misaligned, handled here */
244 case VEC_MISALI_D:
245 info.si_code = BUS_ADRALN;
246 sig = SIGBUS;
247 strerror = KERN_NOTICE EXC_0x24(KERN_NOTICE);
248 CHK_DEBUGGER_TRAP_MAYBE();
249 break;
250 /* 0x25 - Unrecoverable Event, handled here */
251 case VEC_UNCOV:
252 info.si_code = ILL_ILLEXCPT;
253 sig = SIGILL;
254 strerror = KERN_NOTICE EXC_0x25(KERN_NOTICE);
255 CHK_DEBUGGER_TRAP_MAYBE();
256 break;
257 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
258 error case is handled here */
259 case VEC_CPLB_M:
260 info.si_code = BUS_ADRALN;
261 sig = SIGBUS;
262 strerror = KERN_NOTICE EXC_0x26(KERN_NOTICE);
263 break;
264 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
265 case VEC_CPLB_MHIT:
266 info.si_code = ILL_CPLB_MULHIT;
267 sig = SIGSEGV;
268 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
269 if (cpu_pda[cpu].dcplb_fault_addr < FIXED_CODE_START)
270 strerror = KERN_NOTICE "NULL pointer access\n";
271 else
272 #endif
273 strerror = KERN_NOTICE EXC_0x27(KERN_NOTICE);
274 CHK_DEBUGGER_TRAP_MAYBE();
275 break;
276 /* 0x28 - Emulation Watchpoint, handled here */
277 case VEC_WATCH:
278 info.si_code = TRAP_WATCHPT;
279 sig = SIGTRAP;
280 pr_debug(EXC_0x28(KERN_DEBUG));
281 CHK_DEBUGGER_TRAP_MAYBE();
282 /* Check if this is a watchpoint in kernel space */
283 if (kernel_mode_regs(fp))
284 goto traps_done;
285 else
286 break;
287 #ifdef CONFIG_BF535
288 /* 0x29 - Instruction fetch access error (535 only) */
289 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
290 info.si_code = BUS_OPFETCH;
291 sig = SIGBUS;
292 strerror = KERN_NOTICE "BF535: VEC_ISTRU_VL\n";
293 CHK_DEBUGGER_TRAP_MAYBE();
294 break;
295 #else
296 /* 0x29 - Reserved, Caught by default */
297 #endif
298 /* 0x2A - Instruction fetch misaligned, handled here */
299 case VEC_MISALI_I:
300 info.si_code = BUS_ADRALN;
301 sig = SIGBUS;
302 strerror = KERN_NOTICE EXC_0x2A(KERN_NOTICE);
303 CHK_DEBUGGER_TRAP_MAYBE();
304 break;
305 /* 0x2B - Instruction CPLB protection violation, handled here */
306 case VEC_CPLB_I_VL:
307 info.si_code = ILL_CPLB_VI;
308 sig = SIGBUS;
309 strerror = KERN_NOTICE EXC_0x2B(KERN_NOTICE);
310 CHK_DEBUGGER_TRAP_MAYBE();
311 break;
312 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
313 case VEC_CPLB_I_M:
314 info.si_code = ILL_CPLB_MISS;
315 sig = SIGBUS;
316 strerror = KERN_NOTICE EXC_0x2C(KERN_NOTICE);
317 break;
318 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
319 case VEC_CPLB_I_MHIT:
320 info.si_code = ILL_CPLB_MULHIT;
321 sig = SIGSEGV;
322 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
323 if (cpu_pda[cpu].icplb_fault_addr < FIXED_CODE_START)
324 strerror = KERN_NOTICE "Jump to NULL address\n";
325 else
326 #endif
327 strerror = KERN_NOTICE EXC_0x2D(KERN_NOTICE);
328 CHK_DEBUGGER_TRAP_MAYBE();
329 break;
330 /* 0x2E - Illegal use of Supervisor Resource, handled here */
331 case VEC_ILL_RES:
332 info.si_code = ILL_PRVOPC;
333 sig = SIGILL;
334 strerror = KERN_NOTICE EXC_0x2E(KERN_NOTICE);
335 CHK_DEBUGGER_TRAP_MAYBE();
336 break;
337 /* 0x2F - Reserved, Caught by default */
338 /* 0x30 - Reserved, Caught by default */
339 /* 0x31 - Reserved, Caught by default */
340 /* 0x32 - Reserved, Caught by default */
341 /* 0x33 - Reserved, Caught by default */
342 /* 0x34 - Reserved, Caught by default */
343 /* 0x35 - Reserved, Caught by default */
344 /* 0x36 - Reserved, Caught by default */
345 /* 0x37 - Reserved, Caught by default */
346 /* 0x38 - Reserved, Caught by default */
347 /* 0x39 - Reserved, Caught by default */
348 /* 0x3A - Reserved, Caught by default */
349 /* 0x3B - Reserved, Caught by default */
350 /* 0x3C - Reserved, Caught by default */
351 /* 0x3D - Reserved, Caught by default */
352 /* 0x3E - Reserved, Caught by default */
353 /* 0x3F - Reserved, Caught by default */
354 case VEC_HWERR:
355 info.si_code = BUS_ADRALN;
356 sig = SIGBUS;
357 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
358 /* System MMR Error */
359 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
360 info.si_code = BUS_ADRALN;
361 sig = SIGBUS;
362 strerror = KERN_NOTICE HWC_x2(KERN_NOTICE);
363 break;
364 /* External Memory Addressing Error */
365 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
366 if (ANOMALY_05000310) {
367 static unsigned long anomaly_rets;
368
369 if ((fp->pc >= (L1_CODE_START + L1_CODE_LENGTH - 512)) &&
370 (fp->pc < (L1_CODE_START + L1_CODE_LENGTH))) {
371 /*
372 * A false hardware error will happen while fetching at
373 * the L1 instruction SRAM boundary. Ignore it.
374 */
375 anomaly_rets = fp->rets;
376 goto traps_done;
377 } else if (fp->rets == anomaly_rets) {
378 /*
379 * While boundary code returns to a function, at the ret
380 * point, a new false hardware error might occur too based
381 * on tests. Ignore it too.
382 */
383 goto traps_done;
384 } else if ((fp->rets >= (L1_CODE_START + L1_CODE_LENGTH - 512)) &&
385 (fp->rets < (L1_CODE_START + L1_CODE_LENGTH))) {
386 /*
387 * If boundary code calls a function, at the entry point,
388 * a new false hardware error maybe happen based on tests.
389 * Ignore it too.
390 */
391 goto traps_done;
392 } else
393 anomaly_rets = 0;
394 }
395
396 info.si_code = BUS_ADRERR;
397 sig = SIGBUS;
398 strerror = KERN_NOTICE HWC_x3(KERN_NOTICE);
399 break;
400 /* Performance Monitor Overflow */
401 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
402 strerror = KERN_NOTICE HWC_x12(KERN_NOTICE);
403 break;
404 /* RAISE 5 instruction */
405 case (SEQSTAT_HWERRCAUSE_RAISE_5):
406 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
407 break;
408 default: /* Reserved */
409 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
410 break;
411 }
412 CHK_DEBUGGER_TRAP_MAYBE();
413 break;
414 /*
415 * We should be handling all known exception types above,
416 * if we get here we hit a reserved one, so panic
417 */
418 default:
419 info.si_code = ILL_ILLPARAOP;
420 sig = SIGILL;
421 verbose_printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
422 (fp->seqstat & SEQSTAT_EXCAUSE));
423 CHK_DEBUGGER_TRAP_MAYBE();
424 break;
425 }
426
427 BUG_ON(sig == 0);
428
429 /* If the fault was caused by a kernel thread, or interrupt handler
430 * we will kernel panic, so the system reboots.
431 */
432 if (kernel_mode_regs(fp) || (current && !current->mm)) {
433 console_verbose();
434 oops_in_progress = 1;
435 }
436
437 if (sig != SIGTRAP) {
438 if (strerror)
439 verbose_printk(strerror);
440
441 dump_bfin_process(fp);
442 dump_bfin_mem(fp);
443 show_regs(fp);
444
445 /* Print out the trace buffer if it makes sense */
446 #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
447 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
448 verbose_printk(KERN_NOTICE "No trace since you do not have "
449 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n\n");
450 else
451 #endif
452 dump_bfin_trace_buffer();
453
454 if (oops_in_progress) {
455 /* Dump the current kernel stack */
456 verbose_printk(KERN_NOTICE "Kernel Stack\n");
457 show_stack(current, NULL);
458 print_modules();
459 #ifndef CONFIG_ACCESS_CHECK
460 verbose_printk(KERN_EMERG "Please turn on "
461 "CONFIG_ACCESS_CHECK\n");
462 #endif
463 panic("Kernel exception");
464 } else {
465 #ifdef CONFIG_DEBUG_VERBOSE
466 unsigned long *stack;
467 /* Dump the user space stack */
468 stack = (unsigned long *)rdusp();
469 verbose_printk(KERN_NOTICE "Userspace Stack\n");
470 show_stack(NULL, stack);
471 #endif
472 }
473 }
474
475 #ifdef CONFIG_IPIPE
476 if (!ipipe_trap_notify(fp->seqstat & 0x3f, fp))
477 #endif
478 {
479 info.si_signo = sig;
480 info.si_errno = 0;
481 switch (trapnr) {
482 case VEC_CPLB_VL:
483 case VEC_MISALI_D:
484 case VEC_CPLB_M:
485 case VEC_CPLB_MHIT:
486 info.si_addr = (void __user *)cpu_pda[cpu].dcplb_fault_addr;
487 break;
488 default:
489 info.si_addr = (void __user *)fp->pc;
490 break;
491 }
492 force_sig_info(sig, &info, current);
493 }
494
495 if ((ANOMALY_05000461 && trapnr == VEC_HWERR && !access_ok(VERIFY_READ, fp->pc, 8)) ||
496 (ANOMALY_05000281 && trapnr == VEC_HWERR) ||
497 (ANOMALY_05000189 && (trapnr == VEC_CPLB_I_VL || trapnr == VEC_CPLB_VL)))
498 fp->pc = SAFE_USER_INSTRUCTION;
499
500 traps_done:
501 trace_buffer_restore(j);
502 }
503
504 asmlinkage void double_fault_c(struct pt_regs *fp)
505 {
506 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
507 int j;
508 trace_buffer_save(j);
509 #endif
510
511 console_verbose();
512 oops_in_progress = 1;
513 #ifdef CONFIG_DEBUG_VERBOSE
514 printk(KERN_EMERG "Double Fault\n");
515 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
516 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
517 unsigned int cpu = raw_smp_processor_id();
518 char buf[150];
519 decode_address(buf, cpu_pda[cpu].retx_doublefault);
520 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
521 (unsigned int)cpu_pda[cpu].seqstat_doublefault & SEQSTAT_EXCAUSE, buf);
522 decode_address(buf, cpu_pda[cpu].dcplb_doublefault_addr);
523 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
524 decode_address(buf, cpu_pda[cpu].icplb_doublefault_addr);
525 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
526
527 decode_address(buf, fp->retx);
528 printk(KERN_NOTICE "The instruction at %s caused a double exception\n", buf);
529 } else
530 #endif
531 {
532 dump_bfin_process(fp);
533 dump_bfin_mem(fp);
534 show_regs(fp);
535 dump_bfin_trace_buffer();
536 }
537 #endif
538 panic("Double Fault - unrecoverable event");
539
540 }
541
542
543 void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
544 {
545 switch (cplb_panic) {
546 case CPLB_NO_UNLOCKED:
547 printk(KERN_EMERG "All CPLBs are locked\n");
548 break;
549 case CPLB_PROT_VIOL:
550 return;
551 case CPLB_NO_ADDR_MATCH:
552 return;
553 case CPLB_UNKNOWN_ERR:
554 printk(KERN_EMERG "Unknown CPLB Exception\n");
555 break;
556 }
557
558 oops_in_progress = 1;
559
560 dump_bfin_process(fp);
561 dump_bfin_mem(fp);
562 show_regs(fp);
563 dump_stack();
564 panic("Unrecoverable event");
565 }
566
567 #ifdef CONFIG_BUG
568 int is_valid_bugaddr(unsigned long addr)
569 {
570 unsigned int opcode;
571
572 if (!get_instruction(&opcode, (unsigned short *)addr))
573 return 0;
574
575 return opcode == BFIN_BUG_OPCODE;
576 }
577 #endif
578
579 /* stub this out */
580 #ifndef CONFIG_DEBUG_VERBOSE
581 void show_regs(struct pt_regs *fp)
582 {
583
584 }
585 #endif