]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/blackfin/kernel/traps.c
Blackfin arch: add supporting for kgdb
[mirror_ubuntu-zesty-kernel.git] / arch / blackfin / kernel / traps.c
1 /*
2 * File: arch/blackfin/kernel/traps.c
3 * Based on:
4 * Author: Hamish Macdonald
5 *
6 * Created:
7 * Description: uses S/W interrupt 15 for the system calls
8 *
9 * Modified:
10 * Copyright 2004-2006 Analog Devices Inc.
11 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30 #include <linux/uaccess.h>
31 #include <linux/interrupt.h>
32 #include <linux/module.h>
33 #include <linux/kallsyms.h>
34 #include <linux/fs.h>
35 #include <asm/traps.h>
36 #include <asm/cacheflush.h>
37 #include <asm/cplb.h>
38 #include <asm/blackfin.h>
39 #include <asm/irq_handler.h>
40 #include <linux/irq.h>
41 #include <asm/trace.h>
42 #include <asm/fixed_code.h>
43 #include <asm/dma.h>
44
45 #ifdef CONFIG_KGDB
46 # include <linux/kgdb.h>
47
48 # define CHK_DEBUGGER_TRAP() \
49 do { \
50 kgdb_handle_exception(trapnr, sig, info.si_code, fp); \
51 } while (0)
52 # define CHK_DEBUGGER_TRAP_MAYBE() \
53 do { \
54 if (kgdb_connected) \
55 CHK_DEBUGGER_TRAP(); \
56 } while (0)
57 #else
58 # define CHK_DEBUGGER_TRAP() do { } while (0)
59 # define CHK_DEBUGGER_TRAP_MAYBE() do { } while (0)
60 #endif
61
62 /* Initiate the event table handler */
63 void __init trap_init(void)
64 {
65 CSYNC();
66 bfin_write_EVT3(trap);
67 CSYNC();
68 }
69
70 /*
71 * Used to save the RETX, SEQSTAT, I/D CPLB FAULT ADDR
72 * values across the transition from exception to IRQ5.
73 * We put these in L1, so they are going to be in a valid
74 * location during exception context
75 */
76 __attribute__((l1_data))
77 unsigned long saved_retx, saved_seqstat,
78 saved_icplb_fault_addr, saved_dcplb_fault_addr;
79
80 static void decode_address(char *buf, unsigned long address)
81 {
82 struct vm_list_struct *vml;
83 struct task_struct *p;
84 struct mm_struct *mm;
85 unsigned long flags, offset;
86 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
87
88 #ifdef CONFIG_KALLSYMS
89 unsigned long symsize;
90 const char *symname;
91 char *modname;
92 char *delim = ":";
93 char namebuf[128];
94
95 /* look up the address and see if we are in kernel space */
96 symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
97
98 if (symname) {
99 /* yeah! kernel space! */
100 if (!modname)
101 modname = delim = "";
102 sprintf(buf, "<0x%p> { %s%s%s%s + 0x%lx }",
103 (void *)address, delim, modname, delim, symname,
104 (unsigned long)offset);
105 return;
106
107 }
108 #endif
109
110 /* Problem in fixed code section? */
111 if (address >= FIXED_CODE_START && address < FIXED_CODE_END) {
112 sprintf(buf, "<0x%p> /* Maybe fixed code section */", (void *)address);
113 return;
114 }
115
116 /* Problem somewhere before the kernel start address */
117 if (address < CONFIG_BOOT_LOAD) {
118 sprintf(buf, "<0x%p> /* Maybe null pointer? */", (void *)address);
119 return;
120 }
121
122 /* looks like we're off in user-land, so let's walk all the
123 * mappings of all our processes and see if we can't be a whee
124 * bit more specific
125 */
126 write_lock_irqsave(&tasklist_lock, flags);
127 for_each_process(p) {
128 mm = (in_atomic ? p->mm : get_task_mm(p));
129 if (!mm)
130 continue;
131
132 vml = mm->context.vmlist;
133 while (vml) {
134 struct vm_area_struct *vma = vml->vma;
135
136 if (address >= vma->vm_start && address < vma->vm_end) {
137 char _tmpbuf[256];
138 char *name = p->comm;
139 struct file *file = vma->vm_file;
140
141 if (file)
142 name = d_path(&file->f_path, _tmpbuf,
143 sizeof(_tmpbuf));
144
145 /* FLAT does not have its text aligned to the start of
146 * the map while FDPIC ELF does ...
147 */
148
149 /* before we can check flat/fdpic, we need to
150 * make sure current is valid
151 */
152 if ((unsigned long)current >= FIXED_CODE_START &&
153 !((unsigned long)current & 0x3)) {
154 if (current->mm &&
155 (address > current->mm->start_code) &&
156 (address < current->mm->end_code))
157 offset = address - current->mm->start_code;
158 else
159 offset = (address - vma->vm_start) +
160 (vma->vm_pgoff << PAGE_SHIFT);
161
162 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
163 (void *)address, name, offset);
164 } else
165 sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
166 (void *)address, name,
167 vma->vm_start, vma->vm_end);
168
169 if (!in_atomic)
170 mmput(mm);
171
172 if (!strlen(buf))
173 sprintf(buf, "<0x%p> [ %s ] dynamic memory", (void *)address, name);
174
175 goto done;
176 }
177
178 vml = vml->next;
179 }
180 if (!in_atomic)
181 mmput(mm);
182 }
183
184 /* we were unable to find this address anywhere */
185 sprintf(buf, "<0x%p> /* kernel dynamic memory */", (void *)address);
186
187 done:
188 write_unlock_irqrestore(&tasklist_lock, flags);
189 }
190
191 asmlinkage void double_fault_c(struct pt_regs *fp)
192 {
193 console_verbose();
194 oops_in_progress = 1;
195 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
196 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
197 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) == VEC_UNCOV) {
198 char buf[150];
199 decode_address(buf, saved_retx);
200 printk(KERN_EMERG "While handling exception (EXCAUSE = 0x%x) at %s:\n",
201 (int)saved_seqstat & SEQSTAT_EXCAUSE, buf);
202 decode_address(buf, saved_dcplb_fault_addr);
203 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %s\n", buf);
204 decode_address(buf, saved_icplb_fault_addr);
205 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %s\n", buf);
206
207 decode_address(buf, fp->retx);
208 printk(KERN_NOTICE "The instruction at %s caused a double exception\n",
209 buf);
210 } else
211 #endif
212 {
213 dump_bfin_process(fp);
214 dump_bfin_mem(fp);
215 show_regs(fp);
216 }
217 panic("Double Fault - unrecoverable event\n");
218
219 }
220
221 asmlinkage void trap_c(struct pt_regs *fp)
222 {
223 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
224 int j;
225 #endif
226 int sig = 0;
227 siginfo_t info;
228 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
229
230 trace_buffer_save(j);
231
232 /* Important - be very careful dereferncing pointers - will lead to
233 * double faults if the stack has become corrupt
234 */
235
236 /* If the fault was caused by a kernel thread, or interrupt handler
237 * we will kernel panic, so the system reboots.
238 * If KGDB is enabled, don't set this for kernel breakpoints
239 */
240
241 /* TODO: check to see if we are in some sort of deferred HWERR
242 * that we should be able to recover from, not kernel panic
243 */
244 if ((bfin_read_IPEND() & 0xFFC0) && (trapnr != VEC_STEP)
245 #ifdef CONFIG_KGDB
246 && (trapnr != VEC_EXCPT02)
247 #endif
248 ){
249 console_verbose();
250 oops_in_progress = 1;
251 } else if (current) {
252 if (current->mm == NULL) {
253 console_verbose();
254 oops_in_progress = 1;
255 }
256 }
257
258 /* trap_c() will be called for exceptions. During exceptions
259 * processing, the pc value should be set with retx value.
260 * With this change we can cleanup some code in signal.c- TODO
261 */
262 fp->orig_pc = fp->retx;
263 /* printk("exception: 0x%x, ipend=%x, reti=%x, retx=%x\n",
264 trapnr, fp->ipend, fp->pc, fp->retx); */
265
266 /* send the appropriate signal to the user program */
267 switch (trapnr) {
268
269 /* This table works in conjuction with the one in ./mach-common/entry.S
270 * Some exceptions are handled there (in assembly, in exception space)
271 * Some are handled here, (in C, in interrupt space)
272 * Some, like CPLB, are handled in both, where the normal path is
273 * handled in assembly/exception space, and the error path is handled
274 * here
275 */
276
277 /* 0x00 - Linux Syscall, getting here is an error */
278 /* 0x01 - userspace gdb breakpoint, handled here */
279 case VEC_EXCPT01:
280 info.si_code = TRAP_ILLTRAP;
281 sig = SIGTRAP;
282 CHK_DEBUGGER_TRAP_MAYBE();
283 /* Check if this is a breakpoint in kernel space */
284 if (fp->ipend & 0xffc0)
285 return;
286 else
287 break;
288 #ifdef CONFIG_KGDB
289 case VEC_EXCPT02 : /* gdb connection */
290 info.si_code = TRAP_ILLTRAP;
291 sig = SIGTRAP;
292 CHK_DEBUGGER_TRAP();
293 return;
294 #else
295 /* 0x02 - User Defined, Caught by default */
296 #endif
297 /* 0x03 - User Defined, userspace stack overflow */
298 case VEC_EXCPT03:
299 info.si_code = SEGV_STACKFLOW;
300 sig = SIGSEGV;
301 printk(KERN_NOTICE EXC_0x03(KERN_NOTICE));
302 CHK_DEBUGGER_TRAP_MAYBE();
303 break;
304 /* 0x04 - User Defined, Caught by default */
305 /* 0x05 - User Defined, Caught by default */
306 /* 0x06 - User Defined, Caught by default */
307 /* 0x07 - User Defined, Caught by default */
308 /* 0x08 - User Defined, Caught by default */
309 /* 0x09 - User Defined, Caught by default */
310 /* 0x0A - User Defined, Caught by default */
311 /* 0x0B - User Defined, Caught by default */
312 /* 0x0C - User Defined, Caught by default */
313 /* 0x0D - User Defined, Caught by default */
314 /* 0x0E - User Defined, Caught by default */
315 /* 0x0F - User Defined, Caught by default */
316 /* 0x10 HW Single step, handled here */
317 case VEC_STEP:
318 info.si_code = TRAP_STEP;
319 sig = SIGTRAP;
320 CHK_DEBUGGER_TRAP_MAYBE();
321 /* Check if this is a single step in kernel space */
322 if (fp->ipend & 0xffc0)
323 return;
324 else
325 break;
326 /* 0x11 - Trace Buffer Full, handled here */
327 case VEC_OVFLOW:
328 info.si_code = TRAP_TRACEFLOW;
329 sig = SIGTRAP;
330 printk(KERN_NOTICE EXC_0x11(KERN_NOTICE));
331 CHK_DEBUGGER_TRAP_MAYBE();
332 break;
333 /* 0x12 - Reserved, Caught by default */
334 /* 0x13 - Reserved, Caught by default */
335 /* 0x14 - Reserved, Caught by default */
336 /* 0x15 - Reserved, Caught by default */
337 /* 0x16 - Reserved, Caught by default */
338 /* 0x17 - Reserved, Caught by default */
339 /* 0x18 - Reserved, Caught by default */
340 /* 0x19 - Reserved, Caught by default */
341 /* 0x1A - Reserved, Caught by default */
342 /* 0x1B - Reserved, Caught by default */
343 /* 0x1C - Reserved, Caught by default */
344 /* 0x1D - Reserved, Caught by default */
345 /* 0x1E - Reserved, Caught by default */
346 /* 0x1F - Reserved, Caught by default */
347 /* 0x20 - Reserved, Caught by default */
348 /* 0x21 - Undefined Instruction, handled here */
349 case VEC_UNDEF_I:
350 info.si_code = ILL_ILLOPC;
351 sig = SIGILL;
352 printk(KERN_NOTICE EXC_0x21(KERN_NOTICE));
353 CHK_DEBUGGER_TRAP_MAYBE();
354 break;
355 /* 0x22 - Illegal Instruction Combination, handled here */
356 case VEC_ILGAL_I:
357 info.si_code = ILL_ILLPARAOP;
358 sig = SIGILL;
359 printk(KERN_NOTICE EXC_0x22(KERN_NOTICE));
360 CHK_DEBUGGER_TRAP_MAYBE();
361 break;
362 /* 0x23 - Data CPLB protection violation, handled here */
363 case VEC_CPLB_VL:
364 info.si_code = ILL_CPLB_VI;
365 sig = SIGBUS;
366 printk(KERN_NOTICE EXC_0x23(KERN_NOTICE));
367 CHK_DEBUGGER_TRAP_MAYBE();
368 break;
369 /* 0x24 - Data access misaligned, handled here */
370 case VEC_MISALI_D:
371 info.si_code = BUS_ADRALN;
372 sig = SIGBUS;
373 printk(KERN_NOTICE EXC_0x24(KERN_NOTICE));
374 CHK_DEBUGGER_TRAP_MAYBE();
375 break;
376 /* 0x25 - Unrecoverable Event, handled here */
377 case VEC_UNCOV:
378 info.si_code = ILL_ILLEXCPT;
379 sig = SIGILL;
380 printk(KERN_NOTICE EXC_0x25(KERN_NOTICE));
381 CHK_DEBUGGER_TRAP_MAYBE();
382 break;
383 /* 0x26 - Data CPLB Miss, normal case is handled in _cplb_hdr,
384 error case is handled here */
385 case VEC_CPLB_M:
386 info.si_code = BUS_ADRALN;
387 sig = SIGBUS;
388 printk(KERN_NOTICE EXC_0x26(KERN_NOTICE));
389 break;
390 /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero, handled here */
391 case VEC_CPLB_MHIT:
392 info.si_code = ILL_CPLB_MULHIT;
393 sig = SIGSEGV;
394 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
395 if (saved_dcplb_fault_addr < FIXED_CODE_START)
396 printk(KERN_NOTICE "NULL pointer access\n");
397 else
398 #endif
399 printk(KERN_NOTICE EXC_0x27(KERN_NOTICE));
400 CHK_DEBUGGER_TRAP_MAYBE();
401 break;
402 /* 0x28 - Emulation Watchpoint, handled here */
403 case VEC_WATCH:
404 info.si_code = TRAP_WATCHPT;
405 sig = SIGTRAP;
406 pr_debug(EXC_0x28(KERN_DEBUG));
407 CHK_DEBUGGER_TRAP_MAYBE();
408 /* Check if this is a watchpoint in kernel space */
409 if (fp->ipend & 0xffc0)
410 return;
411 else
412 break;
413 #ifdef CONFIG_BF535
414 /* 0x29 - Instruction fetch access error (535 only) */
415 case VEC_ISTRU_VL: /* ADSP-BF535 only (MH) */
416 info.si_code = BUS_OPFETCH;
417 sig = SIGBUS;
418 printk(KERN_NOTICE "BF535: VEC_ISTRU_VL\n");
419 CHK_DEBUGGER_TRAP_MAYBE();
420 break;
421 #else
422 /* 0x29 - Reserved, Caught by default */
423 #endif
424 /* 0x2A - Instruction fetch misaligned, handled here */
425 case VEC_MISALI_I:
426 info.si_code = BUS_ADRALN;
427 sig = SIGBUS;
428 printk(KERN_NOTICE EXC_0x2A(KERN_NOTICE));
429 CHK_DEBUGGER_TRAP_MAYBE();
430 break;
431 /* 0x2B - Instruction CPLB protection violation, handled here */
432 case VEC_CPLB_I_VL:
433 info.si_code = ILL_CPLB_VI;
434 sig = SIGBUS;
435 printk(KERN_NOTICE EXC_0x2B(KERN_NOTICE));
436 CHK_DEBUGGER_TRAP_MAYBE();
437 break;
438 /* 0x2C - Instruction CPLB miss, handled in _cplb_hdr */
439 case VEC_CPLB_I_M:
440 info.si_code = ILL_CPLB_MISS;
441 sig = SIGBUS;
442 printk(KERN_NOTICE EXC_0x2C(KERN_NOTICE));
443 break;
444 /* 0x2D - Instruction CPLB Multiple Hits, handled here */
445 case VEC_CPLB_I_MHIT:
446 info.si_code = ILL_CPLB_MULHIT;
447 sig = SIGSEGV;
448 #ifdef CONFIG_DEBUG_HUNT_FOR_ZERO
449 if (saved_icplb_fault_addr < FIXED_CODE_START)
450 printk(KERN_NOTICE "Jump to NULL address\n");
451 else
452 #endif
453 printk(KERN_NOTICE EXC_0x2D(KERN_NOTICE));
454 CHK_DEBUGGER_TRAP_MAYBE();
455 break;
456 /* 0x2E - Illegal use of Supervisor Resource, handled here */
457 case VEC_ILL_RES:
458 info.si_code = ILL_PRVOPC;
459 sig = SIGILL;
460 printk(KERN_NOTICE EXC_0x2E(KERN_NOTICE));
461 CHK_DEBUGGER_TRAP_MAYBE();
462 break;
463 /* 0x2F - Reserved, Caught by default */
464 /* 0x30 - Reserved, Caught by default */
465 /* 0x31 - Reserved, Caught by default */
466 /* 0x32 - Reserved, Caught by default */
467 /* 0x33 - Reserved, Caught by default */
468 /* 0x34 - Reserved, Caught by default */
469 /* 0x35 - Reserved, Caught by default */
470 /* 0x36 - Reserved, Caught by default */
471 /* 0x37 - Reserved, Caught by default */
472 /* 0x38 - Reserved, Caught by default */
473 /* 0x39 - Reserved, Caught by default */
474 /* 0x3A - Reserved, Caught by default */
475 /* 0x3B - Reserved, Caught by default */
476 /* 0x3C - Reserved, Caught by default */
477 /* 0x3D - Reserved, Caught by default */
478 /* 0x3E - Reserved, Caught by default */
479 /* 0x3F - Reserved, Caught by default */
480 case VEC_HWERR:
481 info.si_code = BUS_ADRALN;
482 sig = SIGBUS;
483 switch (fp->seqstat & SEQSTAT_HWERRCAUSE) {
484 /* System MMR Error */
485 case (SEQSTAT_HWERRCAUSE_SYSTEM_MMR):
486 info.si_code = BUS_ADRALN;
487 sig = SIGBUS;
488 printk(KERN_NOTICE HWC_x2(KERN_NOTICE));
489 break;
490 /* External Memory Addressing Error */
491 case (SEQSTAT_HWERRCAUSE_EXTERN_ADDR):
492 info.si_code = BUS_ADRERR;
493 sig = SIGBUS;
494 printk(KERN_NOTICE HWC_x3(KERN_NOTICE));
495 break;
496 /* Performance Monitor Overflow */
497 case (SEQSTAT_HWERRCAUSE_PERF_FLOW):
498 printk(KERN_NOTICE HWC_x12(KERN_NOTICE));
499 break;
500 /* RAISE 5 instruction */
501 case (SEQSTAT_HWERRCAUSE_RAISE_5):
502 printk(KERN_NOTICE HWC_x18(KERN_NOTICE));
503 break;
504 default: /* Reserved */
505 printk(KERN_NOTICE HWC_default(KERN_NOTICE));
506 break;
507 }
508 CHK_DEBUGGER_TRAP_MAYBE();
509 break;
510 default:
511 info.si_code = TRAP_ILLTRAP;
512 sig = SIGTRAP;
513 printk(KERN_EMERG "Caught Unhandled Exception, code = %08lx\n",
514 (fp->seqstat & SEQSTAT_EXCAUSE));
515 CHK_DEBUGGER_TRAP_MAYBE();
516 break;
517 }
518
519 BUG_ON(sig == 0);
520
521 if (sig != SIGTRAP) {
522 unsigned long *stack;
523 dump_bfin_process(fp);
524 dump_bfin_mem(fp);
525 show_regs(fp);
526
527 /* Print out the trace buffer if it makes sense */
528 #ifndef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
529 if (trapnr == VEC_CPLB_I_M || trapnr == VEC_CPLB_M)
530 printk(KERN_NOTICE "No trace since you do not have "
531 "CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE enabled\n"
532 KERN_NOTICE "\n");
533 else
534 #endif
535 dump_bfin_trace_buffer();
536
537 if (oops_in_progress) {
538 /* Dump the current kernel stack */
539 printk(KERN_NOTICE "\n" KERN_NOTICE "Kernel Stack\n");
540 show_stack(current, NULL);
541
542 print_modules();
543 #ifndef CONFIG_ACCESS_CHECK
544 printk(KERN_EMERG "Please turn on "
545 "CONFIG_ACCESS_CHECK\n");
546 #endif
547 panic("Kernel exception");
548 } else {
549 /* Dump the user space stack */
550 stack = (unsigned long *)rdusp();
551 printk(KERN_NOTICE "Userspace Stack\n");
552 show_stack(NULL, stack);
553 }
554 }
555
556 info.si_signo = sig;
557 info.si_errno = 0;
558 info.si_addr = (void __user *)fp->pc;
559 force_sig_info(sig, &info, current);
560
561 trace_buffer_restore(j);
562 return;
563 }
564
565 /* Typical exception handling routines */
566
567 #define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
568
569 /*
570 * Similar to get_user, do some address checking, then dereference
571 * Return true on sucess, false on bad address
572 */
573 bool get_instruction(unsigned short *val, unsigned short *address)
574 {
575
576 unsigned long addr;
577
578 addr = (unsigned long)address;
579
580 /* Check for odd addresses */
581 if (addr & 0x1)
582 return false;
583
584 /* Check that things do not wrap around */
585 if (addr > (addr + 2))
586 return false;
587
588 /*
589 * Since we are in exception context, we need to do a little address checking
590 * We need to make sure we are only accessing valid memory, and
591 * we don't read something in the async space that can hang forever
592 */
593 if ((addr >= FIXED_CODE_START && (addr + 2) <= physical_mem_end) ||
594 #if L2_LENGTH != 0
595 (addr >= L2_START && (addr + 2) <= (L2_START + L2_LENGTH)) ||
596 #endif
597 (addr >= BOOT_ROM_START && (addr + 2) <= (BOOT_ROM_START + BOOT_ROM_LENGTH)) ||
598 #if L1_DATA_A_LENGTH != 0
599 (addr >= L1_DATA_A_START && (addr + 2) <= (L1_DATA_A_START + L1_DATA_A_LENGTH)) ||
600 #endif
601 #if L1_DATA_B_LENGTH != 0
602 (addr >= L1_DATA_B_START && (addr + 2) <= (L1_DATA_B_START + L1_DATA_B_LENGTH)) ||
603 #endif
604 (addr >= L1_SCRATCH_START && (addr + 2) <= (L1_SCRATCH_START + L1_SCRATCH_LENGTH)) ||
605 (!(bfin_read_EBIU_AMBCTL0() & B0RDYEN) &&
606 addr >= ASYNC_BANK0_BASE && (addr + 2) <= (ASYNC_BANK0_BASE + ASYNC_BANK0_SIZE)) ||
607 (!(bfin_read_EBIU_AMBCTL0() & B1RDYEN) &&
608 addr >= ASYNC_BANK1_BASE && (addr + 2) <= (ASYNC_BANK1_BASE + ASYNC_BANK1_SIZE)) ||
609 (!(bfin_read_EBIU_AMBCTL1() & B2RDYEN) &&
610 addr >= ASYNC_BANK2_BASE && (addr + 2) <= (ASYNC_BANK2_BASE + ASYNC_BANK1_SIZE)) ||
611 (!(bfin_read_EBIU_AMBCTL1() & B3RDYEN) &&
612 addr >= ASYNC_BANK3_BASE && (addr + 2) <= (ASYNC_BANK3_BASE + ASYNC_BANK1_SIZE))) {
613 *val = *address;
614 return true;
615 }
616
617 #if L1_CODE_LENGTH != 0
618 if (addr >= L1_CODE_START && (addr + 2) <= (L1_CODE_START + L1_CODE_LENGTH)) {
619 dma_memcpy(val, address, 2);
620 return true;
621 }
622 #endif
623
624
625 return false;
626 }
627
628 /*
629 * decode the instruction if we are printing out the trace, as it
630 * makes things easier to follow, without running it through objdump
631 * These are the normal instructions which cause change of flow, which
632 * would be at the source of the trace buffer
633 */
634 void decode_instruction(unsigned short *address)
635 {
636 unsigned short opcode;
637
638 if (get_instruction(&opcode, address)) {
639 if (opcode == 0x0010)
640 printk("RTS");
641 else if (opcode == 0x0011)
642 printk("RTI");
643 else if (opcode == 0x0012)
644 printk("RTX");
645 else if (opcode >= 0x0050 && opcode <= 0x0057)
646 printk("JUMP (P%i)", opcode & 7);
647 else if (opcode >= 0x0060 && opcode <= 0x0067)
648 printk("CALL (P%i)", opcode & 7);
649 else if (opcode >= 0x0070 && opcode <= 0x0077)
650 printk("CALL (PC+P%i)", opcode & 7);
651 else if (opcode >= 0x0080 && opcode <= 0x0087)
652 printk("JUMP (PC+P%i)", opcode & 7);
653 else if ((opcode >= 0x1000 && opcode <= 0x13FF) || (opcode >= 0x1800 && opcode <= 0x1BFF))
654 printk("IF !CC JUMP");
655 else if ((opcode >= 0x1400 && opcode <= 0x17ff) || (opcode >= 0x1c00 && opcode <= 0x1fff))
656 printk("IF CC JUMP");
657 else if (opcode >= 0x2000 && opcode <= 0x2fff)
658 printk("JUMP.S");
659 else if (opcode >= 0xe080 && opcode <= 0xe0ff)
660 printk("LSETUP");
661 else if (opcode >= 0xe200 && opcode <= 0xe2ff)
662 printk("JUMP.L");
663 else if (opcode >= 0xe300 && opcode <= 0xe3ff)
664 printk("CALL pcrel");
665 else
666 printk("0x%04x", opcode);
667 }
668
669 }
670
671 void dump_bfin_trace_buffer(void)
672 {
673 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
674 int tflags, i = 0;
675 char buf[150];
676 unsigned short *addr;
677 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
678 int j, index;
679 #endif
680
681 trace_buffer_save(tflags);
682
683 printk(KERN_NOTICE "Hardware Trace:\n");
684
685 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
686 printk(KERN_NOTICE "WARNING: Expanded trace turned on - can not trace exceptions\n");
687 #endif
688
689 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
690 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
691 decode_address(buf, (unsigned long)bfin_read_TBUF());
692 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
693 addr = (unsigned short *)bfin_read_TBUF();
694 decode_address(buf, (unsigned long)addr);
695 printk(KERN_NOTICE " Source : %s ", buf);
696 decode_instruction(addr);
697 printk("\n");
698 }
699 }
700
701 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
702 if (trace_buff_offset)
703 index = trace_buff_offset / 4;
704 else
705 index = EXPAND_LEN;
706
707 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
708 while (j) {
709 decode_address(buf, software_trace_buff[index]);
710 printk(KERN_NOTICE "%4i Target : %s\n", i, buf);
711 index -= 1;
712 if (index < 0 )
713 index = EXPAND_LEN;
714 decode_address(buf, software_trace_buff[index]);
715 printk(KERN_NOTICE " Source : %s ", buf);
716 decode_instruction((unsigned short *)software_trace_buff[index]);
717 printk("\n");
718 index -= 1;
719 if (index < 0)
720 index = EXPAND_LEN;
721 j--;
722 i++;
723 }
724 #endif
725
726 trace_buffer_restore(tflags);
727 #endif
728 }
729 EXPORT_SYMBOL(dump_bfin_trace_buffer);
730
731 /*
732 * Checks to see if the address pointed to is either a
733 * 16-bit CALL instruction, or a 32-bit CALL instruction
734 */
735 bool is_bfin_call(unsigned short *addr)
736 {
737 unsigned short opcode = 0, *ins_addr;
738 ins_addr = (unsigned short *)addr;
739
740 if (!get_instruction(&opcode, ins_addr))
741 return false;
742
743 if ((opcode >= 0x0060 && opcode <= 0x0067) ||
744 (opcode >= 0x0070 && opcode <= 0x0077))
745 return true;
746
747 ins_addr--;
748 if (!get_instruction(&opcode, ins_addr))
749 return false;
750
751 if (opcode >= 0xE300 && opcode <= 0xE3FF)
752 return true;
753
754 return false;
755
756 }
757 void show_stack(struct task_struct *task, unsigned long *stack)
758 {
759 unsigned int *addr, *endstack, *fp = 0, *frame;
760 unsigned short *ins_addr;
761 char buf[150];
762 unsigned int i, j, ret_addr, frame_no = 0;
763
764 /*
765 * If we have been passed a specific stack, use that one otherwise
766 * if we have been passed a task structure, use that, otherwise
767 * use the stack of where the variable "stack" exists
768 */
769
770 if (stack == NULL) {
771 if (task) {
772 /* We know this is a kernel stack, so this is the start/end */
773 stack = (unsigned long *)task->thread.ksp;
774 endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
775 } else {
776 /* print out the existing stack info */
777 stack = (unsigned long *)&stack;
778 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
779 }
780 } else
781 endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
782
783 decode_address(buf, (unsigned int)stack);
784 printk(KERN_NOTICE "Stack info:\n" KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
785 addr = (unsigned int *)((unsigned int)stack & ~0x3F);
786
787 /* First thing is to look for a frame pointer */
788 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
789 addr < endstack; addr++, i++) {
790 if (*addr & 0x1)
791 continue;
792 ins_addr = (unsigned short *)*addr;
793 ins_addr--;
794 if (is_bfin_call(ins_addr))
795 fp = addr - 1;
796
797 if (fp) {
798 /* Let's check to see if it is a frame pointer */
799 while (fp >= (addr - 1) && fp < endstack && fp)
800 fp = (unsigned int *)*fp;
801 if (fp == 0 || fp == endstack) {
802 fp = addr - 1;
803 break;
804 }
805 fp = 0;
806 }
807 }
808 if (fp) {
809 frame = fp;
810 printk(" FP: (0x%p)\n", fp);
811 } else
812 frame = 0;
813
814 /*
815 * Now that we think we know where things are, we
816 * walk the stack again, this time printing things out
817 * incase there is no frame pointer, we still look for
818 * valid return addresses
819 */
820
821 /* First time print out data, next time, print out symbols */
822 for (j = 0; j <= 1; j++) {
823 if (j)
824 printk(KERN_NOTICE "Return addresses in stack:\n");
825 else
826 printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
827
828 fp = frame;
829 frame_no = 0;
830
831 for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
832 addr <= endstack; addr++, i++) {
833
834 ret_addr = 0;
835 if (!j && i % 8 == 0)
836 printk("\n" KERN_NOTICE "%p:",addr);
837
838 /* if it is an odd address, or zero, just skip it */
839 if (*addr & 0x1 || !*addr)
840 goto print;
841
842 ins_addr = (unsigned short *)*addr;
843
844 /* Go back one instruction, and see if it is a CALL */
845 ins_addr--;
846 ret_addr = is_bfin_call(ins_addr);
847 print:
848 if (!j && stack == (unsigned long *)addr)
849 printk("[%08x]", *addr);
850 else if (ret_addr)
851 if (j) {
852 decode_address(buf, (unsigned int)*addr);
853 if (frame == addr) {
854 printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
855 continue;
856 }
857 printk(KERN_NOTICE " address : %s\n", buf);
858 } else
859 printk("<%08x>", *addr);
860 else if (fp == addr) {
861 if (j)
862 frame = addr+1;
863 else
864 printk("(%08x)", *addr);
865
866 fp = (unsigned int *)*addr;
867 frame_no++;
868
869 } else if (!j)
870 printk(" %08x ", *addr);
871 }
872 if (!j)
873 printk("\n");
874 }
875
876 }
877
878 void dump_stack(void)
879 {
880 unsigned long stack;
881 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
882 int tflags;
883 #endif
884 trace_buffer_save(tflags);
885 dump_bfin_trace_buffer();
886 show_stack(current, &stack);
887 trace_buffer_restore(tflags);
888 }
889 EXPORT_SYMBOL(dump_stack);
890
891 void dump_bfin_process(struct pt_regs *fp)
892 {
893 /* We should be able to look at fp->ipend, but we don't push it on the
894 * stack all the time, so do this until we fix that */
895 unsigned int context = bfin_read_IPEND();
896
897 if (oops_in_progress)
898 printk(KERN_EMERG "Kernel OOPS in progress\n");
899
900 if (context & 0x0020 && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)
901 printk(KERN_NOTICE "HW Error context\n");
902 else if (context & 0x0020)
903 printk(KERN_NOTICE "Deferred Exception context\n");
904 else if (context & 0x3FC0)
905 printk(KERN_NOTICE "Interrupt context\n");
906 else if (context & 0x4000)
907 printk(KERN_NOTICE "Deferred Interrupt context\n");
908 else if (context & 0x8000)
909 printk(KERN_NOTICE "Kernel process context\n");
910
911 /* Because we are crashing, and pointers could be bad, we check things
912 * pretty closely before we use them
913 */
914 if ((unsigned long)current >= FIXED_CODE_START &&
915 !((unsigned long)current & 0x3) && current->pid) {
916 printk(KERN_NOTICE "CURRENT PROCESS:\n");
917 if (current->comm >= (char *)FIXED_CODE_START)
918 printk(KERN_NOTICE "COMM=%s PID=%d\n",
919 current->comm, current->pid);
920 else
921 printk(KERN_NOTICE "COMM= invalid\n");
922
923 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
924 printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
925 KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
926 KERN_NOTICE "\n",
927 (void *)current->mm->start_code,
928 (void *)current->mm->end_code,
929 (void *)current->mm->start_data,
930 (void *)current->mm->end_data,
931 (void *)current->mm->end_data,
932 (void *)current->mm->brk,
933 (void *)current->mm->start_stack);
934 else
935 printk(KERN_NOTICE "invalid mm\n");
936 } else
937 printk(KERN_NOTICE "\n" KERN_NOTICE
938 "No Valid process in current context\n");
939 }
940
941 void dump_bfin_mem(struct pt_regs *fp)
942 {
943 unsigned short *addr, *erraddr, val = 0, err = 0;
944 char sti = 0, buf[6];
945
946 erraddr = (void *)fp->pc;
947
948 printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
949
950 for (addr = (unsigned short *)((unsigned long)erraddr & ~0xF) - 0x10;
951 addr < (unsigned short *)((unsigned long)erraddr & ~0xF) + 0x10;
952 addr++) {
953 if (!((unsigned long)addr & 0xF))
954 printk("\n" KERN_NOTICE "0x%p: ", addr);
955
956 if (get_instruction(&val, addr)) {
957 val = 0;
958 sprintf(buf, "????");
959 } else
960 sprintf(buf, "%04x", val);
961
962 if (addr == erraddr) {
963 printk("[%s]", buf);
964 err = val;
965 } else
966 printk(" %s ", buf);
967
968 /* Do any previous instructions turn on interrupts? */
969 if (addr <= erraddr && /* in the past */
970 ((val >= 0x0040 && val <= 0x0047) || /* STI instruction */
971 val == 0x017b)) /* [SP++] = RETI */
972 sti = 1;
973 }
974
975 printk("\n");
976
977 /* Hardware error interrupts can be deferred */
978 if (unlikely(sti && (fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR &&
979 oops_in_progress)){
980 printk(KERN_NOTICE "Looks like this was a deferred error - sorry\n");
981 #ifndef CONFIG_DEBUG_HWERR
982 printk(KERN_NOTICE "The remaining message may be meaningless\n"
983 KERN_NOTICE "You should enable CONFIG_DEBUG_HWERR to get a"
984 " better idea where it came from\n");
985 #else
986 /* If we are handling only one peripheral interrupt
987 * and current mm and pid are valid, and the last error
988 * was in that user space process's text area
989 * print it out - because that is where the problem exists
990 */
991 if ((!(((fp)->ipend & ~0x30) & (((fp)->ipend & ~0x30) - 1))) &&
992 (current->pid && current->mm)) {
993 /* And the last RETI points to the current userspace context */
994 if ((fp + 1)->pc >= current->mm->start_code &&
995 (fp + 1)->pc <= current->mm->end_code) {
996 printk(KERN_NOTICE "It might be better to look around here : \n");
997 printk(KERN_NOTICE "-------------------------------------------\n");
998 show_regs(fp + 1);
999 printk(KERN_NOTICE "-------------------------------------------\n");
1000 }
1001 }
1002 #endif
1003 }
1004 }
1005
1006 void show_regs(struct pt_regs *fp)
1007 {
1008 char buf [150];
1009 struct irqaction *action;
1010 unsigned int i;
1011 unsigned long flags;
1012
1013 printk(KERN_NOTICE "\n" KERN_NOTICE "SEQUENCER STATUS:\t\t%s\n", print_tainted());
1014 printk(KERN_NOTICE " SEQSTAT: %08lx IPEND: %04lx SYSCFG: %04lx\n",
1015 (long)fp->seqstat, fp->ipend, fp->syscfg);
1016 printk(KERN_NOTICE " HWERRCAUSE: 0x%lx\n",
1017 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14);
1018 printk(KERN_NOTICE " EXCAUSE : 0x%lx\n",
1019 fp->seqstat & SEQSTAT_EXCAUSE);
1020 for (i = 6; i <= 15 ; i++) {
1021 if (fp->ipend & (1 << i)) {
1022 decode_address(buf, bfin_read32(EVT0 + 4*i));
1023 printk(KERN_NOTICE " physical IVG%i asserted : %s\n", i, buf);
1024 }
1025 }
1026
1027 /* if no interrupts are going off, don't print this out */
1028 if (fp->ipend & ~0x3F) {
1029 for (i = 0; i < (NR_IRQS - 1); i++) {
1030 spin_lock_irqsave(&irq_desc[i].lock, flags);
1031 action = irq_desc[i].action;
1032 if (!action)
1033 goto unlock;
1034
1035 decode_address(buf, (unsigned int)action->handler);
1036 printk(KERN_NOTICE " logical irq %3d mapped : %s", i, buf);
1037 for (action = action->next; action; action = action->next) {
1038 decode_address(buf, (unsigned int)action->handler);
1039 printk(", %s", buf);
1040 }
1041 printk("\n");
1042 unlock:
1043 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
1044 }
1045 }
1046
1047 decode_address(buf, fp->rete);
1048 printk(KERN_NOTICE " RETE: %s\n", buf);
1049 decode_address(buf, fp->retn);
1050 printk(KERN_NOTICE " RETN: %s\n", buf);
1051 decode_address(buf, fp->retx);
1052 printk(KERN_NOTICE " RETX: %s\n", buf);
1053 decode_address(buf, fp->rets);
1054 printk(KERN_NOTICE " RETS: %s\n", buf);
1055 decode_address(buf, fp->pc);
1056 printk(KERN_NOTICE " PC : %s\n", buf);
1057
1058 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
1059 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
1060 decode_address(buf, saved_dcplb_fault_addr);
1061 printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
1062 decode_address(buf, saved_icplb_fault_addr);
1063 printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
1064 }
1065
1066 printk(KERN_NOTICE "\n" KERN_NOTICE "PROCESSOR STATE:\n");
1067 printk(KERN_NOTICE " R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
1068 fp->r0, fp->r1, fp->r2, fp->r3);
1069 printk(KERN_NOTICE " R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
1070 fp->r4, fp->r5, fp->r6, fp->r7);
1071 printk(KERN_NOTICE " P0 : %08lx P1 : %08lx P2 : %08lx P3 : %08lx\n",
1072 fp->p0, fp->p1, fp->p2, fp->p3);
1073 printk(KERN_NOTICE " P4 : %08lx P5 : %08lx FP : %08lx SP : %08lx\n",
1074 fp->p4, fp->p5, fp->fp, (long)fp);
1075 printk(KERN_NOTICE " LB0: %08lx LT0: %08lx LC0: %08lx\n",
1076 fp->lb0, fp->lt0, fp->lc0);
1077 printk(KERN_NOTICE " LB1: %08lx LT1: %08lx LC1: %08lx\n",
1078 fp->lb1, fp->lt1, fp->lc1);
1079 printk(KERN_NOTICE " B0 : %08lx L0 : %08lx M0 : %08lx I0 : %08lx\n",
1080 fp->b0, fp->l0, fp->m0, fp->i0);
1081 printk(KERN_NOTICE " B1 : %08lx L1 : %08lx M1 : %08lx I1 : %08lx\n",
1082 fp->b1, fp->l1, fp->m1, fp->i1);
1083 printk(KERN_NOTICE " B2 : %08lx L2 : %08lx M2 : %08lx I2 : %08lx\n",
1084 fp->b2, fp->l2, fp->m2, fp->i2);
1085 printk(KERN_NOTICE " B3 : %08lx L3 : %08lx M3 : %08lx I3 : %08lx\n",
1086 fp->b3, fp->l3, fp->m3, fp->i3);
1087 printk(KERN_NOTICE "A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
1088 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
1089
1090 printk(KERN_NOTICE "USP : %08lx ASTAT: %08lx\n",
1091 rdusp(), fp->astat);
1092
1093 printk(KERN_NOTICE "\n");
1094 }
1095
1096 #ifdef CONFIG_SYS_BFIN_SPINLOCK_L1
1097 asmlinkage int sys_bfin_spinlock(int *spinlock)__attribute__((l1_text));
1098 #endif
1099
1100 asmlinkage int sys_bfin_spinlock(int *spinlock)
1101 {
1102 int ret = 0;
1103 int tmp = 0;
1104
1105 local_irq_disable();
1106 ret = get_user(tmp, spinlock);
1107 if (ret == 0) {
1108 if (tmp)
1109 ret = 1;
1110 tmp = 1;
1111 put_user(tmp, spinlock);
1112 }
1113 local_irq_enable();
1114 return ret;
1115 }
1116
1117 int bfin_request_exception(unsigned int exception, void (*handler)(void))
1118 {
1119 void (*curr_handler)(void);
1120
1121 if (exception > 0x3F)
1122 return -EINVAL;
1123
1124 curr_handler = ex_table[exception];
1125
1126 if (curr_handler != ex_replaceable)
1127 return -EBUSY;
1128
1129 ex_table[exception] = handler;
1130
1131 return 0;
1132 }
1133 EXPORT_SYMBOL(bfin_request_exception);
1134
1135 int bfin_free_exception(unsigned int exception, void (*handler)(void))
1136 {
1137 void (*curr_handler)(void);
1138
1139 if (exception > 0x3F)
1140 return -EINVAL;
1141
1142 curr_handler = ex_table[exception];
1143
1144 if (curr_handler != handler)
1145 return -EBUSY;
1146
1147 ex_table[exception] = ex_replaceable;
1148
1149 return 0;
1150 }
1151 EXPORT_SYMBOL(bfin_free_exception);
1152
1153 void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
1154 {
1155 switch (cplb_panic) {
1156 case CPLB_NO_UNLOCKED:
1157 printk(KERN_EMERG "All CPLBs are locked\n");
1158 break;
1159 case CPLB_PROT_VIOL:
1160 return;
1161 case CPLB_NO_ADDR_MATCH:
1162 return;
1163 case CPLB_UNKNOWN_ERR:
1164 printk(KERN_EMERG "Unknown CPLB Exception\n");
1165 break;
1166 }
1167
1168 oops_in_progress = 1;
1169
1170 dump_bfin_process(fp);
1171 dump_bfin_mem(fp);
1172 show_regs(fp);
1173 dump_stack();
1174 panic("Unrecoverable event\n");
1175 }