dmaengine: driver for the iop32x, iop33x, and iop13xx raid engines
[pv_ops_mirror.git] / arch / avr32 / kernel / traps.c
blob86d107511dd4dc1290e765714a2b560432e85a17
1 /*
2 * Copyright (C) 2004-2006 Atmel Corporation
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 */
9 #include <linux/bug.h>
10 #include <linux/init.h>
11 #include <linux/kallsyms.h>
12 #include <linux/module.h>
13 #include <linux/notifier.h>
14 #include <linux/sched.h>
15 #include <linux/uaccess.h>
17 #include <asm/addrspace.h>
18 #include <asm/mmu_context.h>
19 #include <asm/ocd.h>
20 #include <asm/sysreg.h>
21 #include <asm/traps.h>
23 static DEFINE_SPINLOCK(die_lock);
25 void NORET_TYPE die(const char *str, struct pt_regs *regs, long err)
27 static int die_counter;
29 console_verbose();
30 spin_lock_irq(&die_lock);
31 bust_spinlocks(1);
33 printk(KERN_ALERT "Oops: %s, sig: %ld [#%d]\n" KERN_EMERG,
34 str, err, ++die_counter);
35 #ifdef CONFIG_PREEMPT
36 printk("PREEMPT ");
37 #endif
38 #ifdef CONFIG_FRAME_POINTER
39 printk("FRAME_POINTER ");
40 #endif
41 if (current_cpu_data.features & AVR32_FEATURE_OCD) {
42 unsigned long did = __mfdr(DBGREG_DID);
43 printk("chip: 0x%03lx:0x%04lx rev %lu\n",
44 (did >> 1) & 0x7ff,
45 (did >> 12) & 0x7fff,
46 (did >> 28) & 0xf);
47 } else {
48 printk("cpu: arch %u r%u / core %u r%u\n",
49 current_cpu_data.arch_type,
50 current_cpu_data.arch_revision,
51 current_cpu_data.cpu_type,
52 current_cpu_data.cpu_revision);
55 print_modules();
56 show_regs_log_lvl(regs, KERN_EMERG);
57 show_stack_log_lvl(current, regs->sp, regs, KERN_EMERG);
58 bust_spinlocks(0);
59 spin_unlock_irq(&die_lock);
61 if (in_interrupt())
62 panic("Fatal exception in interrupt");
64 if (panic_on_oops)
65 panic("Fatal exception");
67 do_exit(err);
70 void _exception(long signr, struct pt_regs *regs, int code,
71 unsigned long addr)
73 siginfo_t info;
75 if (!user_mode(regs))
76 die("Unhandled exception in kernel mode", regs, signr);
78 memset(&info, 0, sizeof(info));
79 info.si_signo = signr;
80 info.si_code = code;
81 info.si_addr = (void __user *)addr;
82 force_sig_info(signr, &info, current);
85 * Init gets no signals that it doesn't have a handler for.
86 * That's all very well, but if it has caused a synchronous
87 * exception and we ignore the resulting signal, it will just
88 * generate the same exception over and over again and we get
89 * nowhere. Better to kill it and let the kernel panic.
91 if (is_init(current)) {
92 __sighandler_t handler;
94 spin_lock_irq(&current->sighand->siglock);
95 handler = current->sighand->action[signr-1].sa.sa_handler;
96 spin_unlock_irq(&current->sighand->siglock);
97 if (handler == SIG_DFL) {
98 /* init has generated a synchronous exception
99 and it doesn't have a handler for the signal */
100 printk(KERN_CRIT "init has generated signal %ld "
101 "but has no handler for it\n", signr);
102 do_exit(signr);
107 asmlinkage void do_nmi(unsigned long ecr, struct pt_regs *regs)
109 printk(KERN_ALERT "Got Non-Maskable Interrupt, dumping regs\n");
110 show_regs_log_lvl(regs, KERN_ALERT);
111 show_stack_log_lvl(current, regs->sp, regs, KERN_ALERT);
114 asmlinkage void do_critical_exception(unsigned long ecr, struct pt_regs *regs)
116 die("Critical exception", regs, SIGKILL);
119 asmlinkage void do_address_exception(unsigned long ecr, struct pt_regs *regs)
121 _exception(SIGBUS, regs, BUS_ADRALN, regs->pc);
124 /* This way of handling undefined instructions is stolen from ARM */
125 static LIST_HEAD(undef_hook);
126 static DEFINE_SPINLOCK(undef_lock);
128 void register_undef_hook(struct undef_hook *hook)
130 spin_lock_irq(&undef_lock);
131 list_add(&hook->node, &undef_hook);
132 spin_unlock_irq(&undef_lock);
135 void unregister_undef_hook(struct undef_hook *hook)
137 spin_lock_irq(&undef_lock);
138 list_del(&hook->node);
139 spin_unlock_irq(&undef_lock);
142 static int do_cop_absent(u32 insn)
144 int cop_nr;
145 u32 cpucr;
147 if ((insn & 0xfdf00000) == 0xf1900000)
148 /* LDC0 */
149 cop_nr = 0;
150 else
151 cop_nr = (insn >> 13) & 0x7;
153 /* Try enabling the coprocessor */
154 cpucr = sysreg_read(CPUCR);
155 cpucr |= (1 << (24 + cop_nr));
156 sysreg_write(CPUCR, cpucr);
158 cpucr = sysreg_read(CPUCR);
159 if (!(cpucr & (1 << (24 + cop_nr))))
160 return -ENODEV;
162 return 0;
165 int is_valid_bugaddr(unsigned long pc)
167 unsigned short opcode;
169 if (pc < PAGE_OFFSET)
170 return 0;
171 if (probe_kernel_address((u16 *)pc, opcode))
172 return 0;
174 return opcode == AVR32_BUG_OPCODE;
177 asmlinkage void do_illegal_opcode(unsigned long ecr, struct pt_regs *regs)
179 u32 insn;
180 struct undef_hook *hook;
181 void __user *pc;
182 long code;
184 if (!user_mode(regs) && (ecr == ECR_ILLEGAL_OPCODE)) {
185 enum bug_trap_type type;
187 type = report_bug(regs->pc);
188 switch (type) {
189 case BUG_TRAP_TYPE_NONE:
190 break;
191 case BUG_TRAP_TYPE_WARN:
192 regs->pc += 2;
193 return;
194 case BUG_TRAP_TYPE_BUG:
195 die("Kernel BUG", regs, SIGKILL);
199 local_irq_enable();
201 if (user_mode(regs)) {
202 pc = (void __user *)instruction_pointer(regs);
203 if (get_user(insn, (u32 __user *)pc))
204 goto invalid_area;
206 if (ecr == ECR_COPROC_ABSENT && !do_cop_absent(insn))
207 return;
209 spin_lock_irq(&undef_lock);
210 list_for_each_entry(hook, &undef_hook, node) {
211 if ((insn & hook->insn_mask) == hook->insn_val) {
212 if (hook->fn(regs, insn) == 0) {
213 spin_unlock_irq(&undef_lock);
214 return;
218 spin_unlock_irq(&undef_lock);
221 switch (ecr) {
222 case ECR_PRIVILEGE_VIOLATION:
223 code = ILL_PRVOPC;
224 break;
225 case ECR_COPROC_ABSENT:
226 code = ILL_COPROC;
227 break;
228 default:
229 code = ILL_ILLOPC;
230 break;
233 _exception(SIGILL, regs, code, regs->pc);
234 return;
236 invalid_area:
237 _exception(SIGSEGV, regs, SEGV_MAPERR, regs->pc);
240 asmlinkage void do_fpe(unsigned long ecr, struct pt_regs *regs)
242 /* We have no FPU yet */
243 _exception(SIGILL, regs, ILL_COPROC, regs->pc);
247 void __init trap_init(void)