Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
Ralf Baechle | 36ccf1c | 2006-02-14 21:04:54 +0000 | [diff] [blame] | 6 | * Copyright (C) 1994 - 1999, 2000, 01, 06 Ralf Baechle |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Copyright (C) 1995, 1996 Paul M. Antoine |
| 8 | * Copyright (C) 1998 Ulf Carlsson |
| 9 | * Copyright (C) 1999 Silicon Graphics, Inc. |
| 10 | * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 11 | * Copyright (C) 2002, 2003, 2004, 2005, 2007 Maciej W. Rozycki |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 12 | * Copyright (C) 2000, 2001, 2012 MIPS Technologies, Inc. All rights reserved. |
Markos Chandras | b08a9c9 | 2013-12-04 16:20:08 +0000 | [diff] [blame] | 13 | * Copyright (C) 2014, Imagination Technologies Ltd. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | */ |
Maciej W. Rozycki | ed2d72c | 2015-04-03 23:27:06 +0100 | [diff] [blame] | 15 | #include <linux/bitops.h> |
Ralf Baechle | 8e8a52e | 2007-05-31 14:00:19 +0100 | [diff] [blame] | 16 | #include <linux/bug.h> |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 17 | #include <linux/compiler.h> |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 18 | #include <linux/context_tracking.h> |
James Hogan | ae4ce45 | 2014-03-04 10:20:43 +0000 | [diff] [blame] | 19 | #include <linux/cpu_pm.h> |
Ralf Baechle | 7aa1c8f | 2012-10-11 18:14:58 +0200 | [diff] [blame] | 20 | #include <linux/kexec.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/init.h> |
Nathan Lynch | 8742cd2 | 2011-09-30 13:49:35 -0500 | [diff] [blame] | 22 | #include <linux/kernel.h> |
Paul Gortmaker | f9ded56 | 2012-02-28 19:24:46 -0500 | [diff] [blame] | 23 | #include <linux/module.h> |
Paul Gortmaker | 9f3b808 | 2016-08-15 19:11:52 -0400 | [diff] [blame] | 24 | #include <linux/extable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/mm.h> |
Ingo Molnar | 68e21be | 2017-02-01 19:08:20 +0100 | [diff] [blame] | 26 | #include <linux/sched/mm.h> |
Ingo Molnar | b17b015 | 2017-02-08 18:51:35 +0100 | [diff] [blame] | 27 | #include <linux/sched/debug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/spinlock.h> |
| 30 | #include <linux/kallsyms.h> |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 31 | #include <linux/bootmem.h> |
Maxime Bizon | d4fd198 | 2006-07-20 18:52:02 +0200 | [diff] [blame] | 32 | #include <linux/interrupt.h> |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 33 | #include <linux/ptrace.h> |
Jason Wessel | 8854700 | 2008-07-29 15:58:53 -0500 | [diff] [blame] | 34 | #include <linux/kgdb.h> |
| 35 | #include <linux/kdebug.h> |
David Daney | c1bf207 | 2010-08-03 11:22:20 -0700 | [diff] [blame] | 36 | #include <linux/kprobes.h> |
Ralf Baechle | 69f3a7d | 2009-11-24 01:24:58 +0000 | [diff] [blame] | 37 | #include <linux/notifier.h> |
Jason Wessel | 5dd11d5 | 2010-05-20 21:04:26 -0500 | [diff] [blame] | 38 | #include <linux/kdb.h> |
David Howells | ca4d3e67 | 2010-10-07 14:08:54 +0100 | [diff] [blame] | 39 | #include <linux/irq.h> |
Deng-Cheng Zhu | 7f788d2 | 2010-10-12 19:37:21 +0800 | [diff] [blame] | 40 | #include <linux/perf_event.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Paul Burton | a13c996 | 2015-09-22 10:15:22 -0700 | [diff] [blame] | 42 | #include <asm/addrspace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <asm/bootinfo.h> |
| 44 | #include <asm/branch.h> |
| 45 | #include <asm/break.h> |
Ralf Baechle | 69f3a7d | 2009-11-24 01:24:58 +0000 | [diff] [blame] | 46 | #include <asm/cop2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <asm/cpu.h> |
Ralf Baechle | 69f24d1 | 2013-09-17 10:25:47 +0200 | [diff] [blame] | 48 | #include <asm/cpu-type.h> |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 49 | #include <asm/dsp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <asm/fpu.h> |
Ralf Baechle | ba3049e | 2008-10-28 17:38:42 +0000 | [diff] [blame] | 51 | #include <asm/fpu_emulator.h> |
Ralf Baechle | bdc92d74 | 2013-05-21 16:59:19 +0200 | [diff] [blame] | 52 | #include <asm/idle.h> |
Paul Burton | e83f7e0 | 2017-08-12 19:49:41 -0700 | [diff] [blame] | 53 | #include <asm/mips-cps.h> |
Leonid Yegoshin | b0a668f | 2014-12-03 15:47:03 +0000 | [diff] [blame] | 54 | #include <asm/mips-r2-to-r6-emul.h> |
Ralf Baechle | 340ee4b | 2005-08-17 17:44:08 +0000 | [diff] [blame] | 55 | #include <asm/mipsregs.h> |
| 56 | #include <asm/mipsmtregs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include <asm/module.h> |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 58 | #include <asm/msa.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #include <asm/pgtable.h> |
| 60 | #include <asm/ptrace.h> |
| 61 | #include <asm/sections.h> |
Maciej W. Rozycki | 3b143cc | 2016-03-04 01:44:28 +0000 | [diff] [blame] | 62 | #include <asm/siginfo.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #include <asm/tlbdebug.h> |
| 64 | #include <asm/traps.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 65 | #include <linux/uaccess.h> |
David Daney | b67b2b7 | 2008-09-23 00:08:45 -0700 | [diff] [blame] | 66 | #include <asm/watch.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #include <asm/mmu_context.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #include <asm/types.h> |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 69 | #include <asm/stacktrace.h> |
Paul Burton | 4bcb4ad | 2018-08-10 16:03:31 -0700 | [diff] [blame^] | 70 | #include <asm/tlbex.h> |
Florian Fainelli | 92bbe1b | 2010-01-28 15:22:37 +0100 | [diff] [blame] | 71 | #include <asm/uasm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Atsushi Nemoto | c65a548 | 2007-11-12 02:05:18 +0900 | [diff] [blame] | 73 | extern void check_wait(void); |
Atsushi Nemoto | c65a548 | 2007-11-12 02:05:18 +0900 | [diff] [blame] | 74 | extern asmlinkage void rollback_handle_int(void); |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 75 | extern asmlinkage void handle_int(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | extern asmlinkage void handle_adel(void); |
| 77 | extern asmlinkage void handle_ades(void); |
| 78 | extern asmlinkage void handle_ibe(void); |
| 79 | extern asmlinkage void handle_dbe(void); |
| 80 | extern asmlinkage void handle_sys(void); |
| 81 | extern asmlinkage void handle_bp(void); |
| 82 | extern asmlinkage void handle_ri(void); |
Huacai Chen | 5a34133 | 2017-03-16 21:00:26 +0800 | [diff] [blame] | 83 | extern asmlinkage void handle_ri_rdhwr_tlbp(void); |
Atsushi Nemoto | 5b10496 | 2006-09-11 17:50:29 +0900 | [diff] [blame] | 84 | extern asmlinkage void handle_ri_rdhwr(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | extern asmlinkage void handle_cpu(void); |
| 86 | extern asmlinkage void handle_ov(void); |
| 87 | extern asmlinkage void handle_tr(void); |
Paul Burton | 2bcb3fb | 2014-01-27 15:23:12 +0000 | [diff] [blame] | 88 | extern asmlinkage void handle_msa_fpe(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | extern asmlinkage void handle_fpe(void); |
Leonid Yegoshin | 75b5b5e | 2013-11-14 16:12:31 +0000 | [diff] [blame] | 90 | extern asmlinkage void handle_ftlb(void); |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 91 | extern asmlinkage void handle_msa(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | extern asmlinkage void handle_mdmx(void); |
| 93 | extern asmlinkage void handle_watch(void); |
Ralf Baechle | 340ee4b | 2005-08-17 17:44:08 +0000 | [diff] [blame] | 94 | extern asmlinkage void handle_mt(void); |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 95 | extern asmlinkage void handle_dsp(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | extern asmlinkage void handle_mcheck(void); |
| 97 | extern asmlinkage void handle_reserved(void); |
Leonid Yegoshin | 5890f70 | 2014-07-15 14:09:56 +0100 | [diff] [blame] | 98 | extern void tlb_do_page_fault_0(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | void (*board_be_init)(void); |
| 101 | int (*board_be_handler)(struct pt_regs *regs, int is_fixup); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 102 | void (*board_nmi_handler_setup)(void); |
| 103 | void (*board_ejtag_handler_setup)(void); |
| 104 | void (*board_bind_eic_interrupt)(int irq, int regset); |
Kevin Cernekee | 6fb97ef | 2011-11-16 01:25:45 +0000 | [diff] [blame] | 105 | void (*board_ebase_setup)(void); |
Paul Gortmaker | 078a55f | 2013-06-18 13:38:59 +0000 | [diff] [blame] | 106 | void(*board_cache_error_setup)(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Franck Bui-Huu | 4d157d5 | 2006-08-03 09:29:21 +0200 | [diff] [blame] | 108 | static void show_raw_backtrace(unsigned long reg29) |
Atsushi Nemoto | e889d78 | 2006-07-25 23:51:36 +0900 | [diff] [blame] | 109 | { |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 110 | unsigned long *sp = (unsigned long *)(reg29 & ~3); |
Atsushi Nemoto | e889d78 | 2006-07-25 23:51:36 +0900 | [diff] [blame] | 111 | unsigned long addr; |
| 112 | |
| 113 | printk("Call Trace:"); |
| 114 | #ifdef CONFIG_KALLSYMS |
| 115 | printk("\n"); |
| 116 | #endif |
Thomas Bogendoerfer | 10220c8 | 2008-05-12 17:58:48 +0200 | [diff] [blame] | 117 | while (!kstack_end(sp)) { |
| 118 | unsigned long __user *p = |
| 119 | (unsigned long __user *)(unsigned long)sp++; |
| 120 | if (__get_user(addr, p)) { |
| 121 | printk(" (Bad stack address)"); |
| 122 | break; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 123 | } |
Thomas Bogendoerfer | 10220c8 | 2008-05-12 17:58:48 +0200 | [diff] [blame] | 124 | if (__kernel_text_address(addr)) |
| 125 | print_ip_sym(addr); |
Atsushi Nemoto | e889d78 | 2006-07-25 23:51:36 +0900 | [diff] [blame] | 126 | } |
Thomas Bogendoerfer | 10220c8 | 2008-05-12 17:58:48 +0200 | [diff] [blame] | 127 | printk("\n"); |
Atsushi Nemoto | e889d78 | 2006-07-25 23:51:36 +0900 | [diff] [blame] | 128 | } |
| 129 | |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 130 | #ifdef CONFIG_KALLSYMS |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 131 | int raw_show_trace; |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 132 | static int __init set_raw_show_trace(char *str) |
| 133 | { |
| 134 | raw_show_trace = 1; |
| 135 | return 1; |
| 136 | } |
| 137 | __setup("raw_show_trace", set_raw_show_trace); |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 138 | #endif |
Franck Bui-Huu | 4d157d5 | 2006-08-03 09:29:21 +0200 | [diff] [blame] | 139 | |
Ralf Baechle | eae23f2 | 2007-10-14 23:27:21 +0100 | [diff] [blame] | 140 | static void show_backtrace(struct task_struct *task, const struct pt_regs *regs) |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 141 | { |
Franck Bui-Huu | 4d157d5 | 2006-08-03 09:29:21 +0200 | [diff] [blame] | 142 | unsigned long sp = regs->regs[29]; |
| 143 | unsigned long ra = regs->regs[31]; |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 144 | unsigned long pc = regs->cp0_epc; |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 145 | |
Vincent Wen | e909be8 | 2012-07-19 09:11:16 +0200 | [diff] [blame] | 146 | if (!task) |
| 147 | task = current; |
| 148 | |
James Hogan | 81a76d7 | 2015-12-04 22:25:02 +0000 | [diff] [blame] | 149 | if (raw_show_trace || user_mode(regs) || !__kernel_text_address(pc)) { |
Franck Bui-Huu | 87151ae | 2006-08-03 09:29:17 +0200 | [diff] [blame] | 150 | show_raw_backtrace(sp); |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 151 | return; |
| 152 | } |
| 153 | printk("Call Trace:\n"); |
Franck Bui-Huu | 4d157d5 | 2006-08-03 09:29:21 +0200 | [diff] [blame] | 154 | do { |
Franck Bui-Huu | 87151ae | 2006-08-03 09:29:17 +0200 | [diff] [blame] | 155 | print_ip_sym(pc); |
Atsushi Nemoto | 1924600 | 2006-09-29 18:02:51 +0900 | [diff] [blame] | 156 | pc = unwind_stack(task, &sp, pc, &ra); |
Franck Bui-Huu | 4d157d5 | 2006-08-03 09:29:21 +0200 | [diff] [blame] | 157 | } while (pc); |
Matt Redfearn | bcf084d | 2016-10-19 14:33:20 +0100 | [diff] [blame] | 158 | pr_cont("\n"); |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 159 | } |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | /* |
| 162 | * This routine abuses get_user()/put_user() to reference pointers |
| 163 | * with at least a bit of error checking ... |
| 164 | */ |
Ralf Baechle | eae23f2 | 2007-10-14 23:27:21 +0100 | [diff] [blame] | 165 | static void show_stacktrace(struct task_struct *task, |
| 166 | const struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
| 168 | const int field = 2 * sizeof(unsigned long); |
| 169 | long stackdata; |
| 170 | int i; |
Atsushi Nemoto | 5e0373b | 2007-07-13 23:02:42 +0900 | [diff] [blame] | 171 | unsigned long __user *sp = (unsigned long __user *)regs->regs[29]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | printk("Stack :"); |
| 174 | i = 0; |
| 175 | while ((unsigned long) sp & (PAGE_SIZE - 1)) { |
Matt Redfearn | fe4e09e | 2016-10-19 14:33:21 +0100 | [diff] [blame] | 176 | if (i && ((i % (64 / field)) == 0)) { |
| 177 | pr_cont("\n"); |
| 178 | printk(" "); |
| 179 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | if (i > 39) { |
Matt Redfearn | fe4e09e | 2016-10-19 14:33:21 +0100 | [diff] [blame] | 181 | pr_cont(" ..."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | break; |
| 183 | } |
| 184 | |
| 185 | if (__get_user(stackdata, sp++)) { |
Matt Redfearn | fe4e09e | 2016-10-19 14:33:21 +0100 | [diff] [blame] | 186 | pr_cont(" (Bad stack address)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | break; |
| 188 | } |
| 189 | |
Matt Redfearn | fe4e09e | 2016-10-19 14:33:21 +0100 | [diff] [blame] | 190 | pr_cont(" %0*lx", field, stackdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | i++; |
| 192 | } |
Matt Redfearn | fe4e09e | 2016-10-19 14:33:21 +0100 | [diff] [blame] | 193 | pr_cont("\n"); |
Franck Bui-Huu | 87151ae | 2006-08-03 09:29:17 +0200 | [diff] [blame] | 194 | show_backtrace(task, regs); |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 195 | } |
| 196 | |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 197 | void show_stack(struct task_struct *task, unsigned long *sp) |
| 198 | { |
| 199 | struct pt_regs regs; |
James Hogan | 1e77863 | 2015-07-27 13:50:22 +0100 | [diff] [blame] | 200 | mm_segment_t old_fs = get_fs(); |
James Hogan | 8542363 | 2017-06-29 15:05:04 +0100 | [diff] [blame] | 201 | |
| 202 | regs.cp0_status = KSU_KERNEL; |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 203 | if (sp) { |
| 204 | regs.regs[29] = (unsigned long)sp; |
| 205 | regs.regs[31] = 0; |
| 206 | regs.cp0_epc = 0; |
| 207 | } else { |
| 208 | if (task && task != current) { |
| 209 | regs.regs[29] = task->thread.reg29; |
| 210 | regs.regs[31] = 0; |
| 211 | regs.cp0_epc = task->thread.reg31; |
Jason Wessel | 5dd11d5 | 2010-05-20 21:04:26 -0500 | [diff] [blame] | 212 | #ifdef CONFIG_KGDB_KDB |
| 213 | } else if (atomic_read(&kgdb_active) != -1 && |
| 214 | kdb_current_regs) { |
| 215 | memcpy(®s, kdb_current_regs, sizeof(regs)); |
| 216 | #endif /* CONFIG_KGDB_KDB */ |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 217 | } else { |
| 218 | prepare_frametrace(®s); |
| 219 | } |
| 220 | } |
James Hogan | 1e77863 | 2015-07-27 13:50:22 +0100 | [diff] [blame] | 221 | /* |
| 222 | * show_stack() deals exclusively with kernel mode, so be sure to access |
| 223 | * the stack in the kernel (not user) address space. |
| 224 | */ |
| 225 | set_fs(KERNEL_DS); |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 226 | show_stacktrace(task, ®s); |
James Hogan | 1e77863 | 2015-07-27 13:50:22 +0100 | [diff] [blame] | 227 | set_fs(old_fs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Atsushi Nemoto | e1bb8289 | 2007-07-13 23:51:46 +0900 | [diff] [blame] | 230 | static void show_code(unsigned int __user *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | { |
| 232 | long i; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 233 | unsigned short __user *pc16 = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Matt Redfearn | 41000c5 | 2016-10-19 14:33:22 +0100 | [diff] [blame] | 235 | printk("Code:"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 237 | if ((unsigned long)pc & 1) |
| 238 | pc16 = (unsigned short __user *)((unsigned long)pc & ~1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | for(i = -3 ; i < 6 ; i++) { |
| 240 | unsigned int insn; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 241 | if (pc16 ? __get_user(insn, pc16 + i) : __get_user(insn, pc + i)) { |
Matt Redfearn | 41000c5 | 2016-10-19 14:33:22 +0100 | [diff] [blame] | 242 | pr_cont(" (Bad address in epc)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | break; |
| 244 | } |
Matt Redfearn | 41000c5 | 2016-10-19 14:33:22 +0100 | [diff] [blame] | 245 | pr_cont("%c%0*x%c", (i?' ':'<'), pc16 ? 4 : 8, insn, (i?' ':'>')); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } |
Matt Redfearn | 41000c5 | 2016-10-19 14:33:22 +0100 | [diff] [blame] | 247 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Ralf Baechle | eae23f2 | 2007-10-14 23:27:21 +0100 | [diff] [blame] | 250 | static void __show_regs(const struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | { |
| 252 | const int field = 2 * sizeof(unsigned long); |
| 253 | unsigned int cause = regs->cp0_cause; |
Petri Gynther | 37dd381 | 2015-05-08 15:10:10 -0700 | [diff] [blame] | 254 | unsigned int exccode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | int i; |
| 256 | |
Tejun Heo | a43cb95 | 2013-04-30 15:27:17 -0700 | [diff] [blame] | 257 | show_regs_print_info(KERN_DEFAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | /* |
| 260 | * Saved main processor registers |
| 261 | */ |
| 262 | for (i = 0; i < 32; ) { |
| 263 | if ((i % 4) == 0) |
| 264 | printk("$%2d :", i); |
| 265 | if (i == 0) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 266 | pr_cont(" %0*lx", field, 0UL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | else if (i == 26 || i == 27) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 268 | pr_cont(" %*s", field, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | else |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 270 | pr_cont(" %0*lx", field, regs->regs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | i++; |
| 273 | if ((i % 4) == 0) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 274 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Franck Bui-Huu | 9693a85 | 2007-02-02 17:41:47 +0100 | [diff] [blame] | 277 | #ifdef CONFIG_CPU_HAS_SMARTMIPS |
| 278 | printk("Acx : %0*lx\n", field, regs->acx); |
| 279 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | printk("Hi : %0*lx\n", field, regs->hi); |
| 281 | printk("Lo : %0*lx\n", field, regs->lo); |
| 282 | |
| 283 | /* |
| 284 | * Saved cp0 registers |
| 285 | */ |
Ralf Baechle | b012cff | 2008-07-15 18:44:33 +0100 | [diff] [blame] | 286 | printk("epc : %0*lx %pS\n", field, regs->cp0_epc, |
| 287 | (void *) regs->cp0_epc); |
Ralf Baechle | b012cff | 2008-07-15 18:44:33 +0100 | [diff] [blame] | 288 | printk("ra : %0*lx %pS\n", field, regs->regs[31], |
| 289 | (void *) regs->regs[31]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 291 | printk("Status: %08x ", (uint32_t) regs->cp0_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Ralf Baechle | 1990e54 | 2013-06-26 17:06:34 +0200 | [diff] [blame] | 293 | if (cpu_has_3kex) { |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 294 | if (regs->cp0_status & ST0_KUO) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 295 | pr_cont("KUo "); |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 296 | if (regs->cp0_status & ST0_IEO) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 297 | pr_cont("IEo "); |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 298 | if (regs->cp0_status & ST0_KUP) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 299 | pr_cont("KUp "); |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 300 | if (regs->cp0_status & ST0_IEP) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 301 | pr_cont("IEp "); |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 302 | if (regs->cp0_status & ST0_KUC) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 303 | pr_cont("KUc "); |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 304 | if (regs->cp0_status & ST0_IEC) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 305 | pr_cont("IEc "); |
Ralf Baechle | 1990e54 | 2013-06-26 17:06:34 +0200 | [diff] [blame] | 306 | } else if (cpu_has_4kex) { |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 307 | if (regs->cp0_status & ST0_KX) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 308 | pr_cont("KX "); |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 309 | if (regs->cp0_status & ST0_SX) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 310 | pr_cont("SX "); |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 311 | if (regs->cp0_status & ST0_UX) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 312 | pr_cont("UX "); |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 313 | switch (regs->cp0_status & ST0_KSU) { |
| 314 | case KSU_USER: |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 315 | pr_cont("USER "); |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 316 | break; |
| 317 | case KSU_SUPERVISOR: |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 318 | pr_cont("SUPERVISOR "); |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 319 | break; |
| 320 | case KSU_KERNEL: |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 321 | pr_cont("KERNEL "); |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 322 | break; |
| 323 | default: |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 324 | pr_cont("BAD_MODE "); |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 325 | break; |
| 326 | } |
| 327 | if (regs->cp0_status & ST0_ERL) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 328 | pr_cont("ERL "); |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 329 | if (regs->cp0_status & ST0_EXL) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 330 | pr_cont("EXL "); |
Maciej W. Rozycki | 3b2396d | 2005-06-22 20:43:29 +0000 | [diff] [blame] | 331 | if (regs->cp0_status & ST0_IE) |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 332 | pr_cont("IE "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } |
Paul Burton | 752f549 | 2016-10-19 14:33:23 +0100 | [diff] [blame] | 334 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
Petri Gynther | 37dd381 | 2015-05-08 15:10:10 -0700 | [diff] [blame] | 336 | exccode = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE; |
| 337 | printk("Cause : %08x (ExcCode %02x)\n", cause, exccode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Petri Gynther | 37dd381 | 2015-05-08 15:10:10 -0700 | [diff] [blame] | 339 | if (1 <= exccode && exccode <= 5) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | printk("BadVA : %0*lx\n", field, regs->cp0_badvaddr); |
| 341 | |
Ralf Baechle | 9966db25 | 2007-10-11 23:46:17 +0100 | [diff] [blame] | 342 | printk("PrId : %08x (%s)\n", read_c0_prid(), |
| 343 | cpu_name_string()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Ralf Baechle | eae23f2 | 2007-10-14 23:27:21 +0100 | [diff] [blame] | 346 | /* |
| 347 | * FIXME: really the generic show_regs should take a const pointer argument. |
| 348 | */ |
| 349 | void show_regs(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | { |
Ralf Baechle | eae23f2 | 2007-10-14 23:27:21 +0100 | [diff] [blame] | 351 | __show_regs((struct pt_regs *)regs); |
| 352 | } |
| 353 | |
David Daney | c1bf207 | 2010-08-03 11:22:20 -0700 | [diff] [blame] | 354 | void show_registers(struct pt_regs *regs) |
Ralf Baechle | eae23f2 | 2007-10-14 23:27:21 +0100 | [diff] [blame] | 355 | { |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 356 | const int field = 2 * sizeof(unsigned long); |
Leonid Yegoshin | 83e4da1 | 2013-10-08 12:39:31 +0100 | [diff] [blame] | 357 | mm_segment_t old_fs = get_fs(); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 358 | |
Ralf Baechle | eae23f2 | 2007-10-14 23:27:21 +0100 | [diff] [blame] | 359 | __show_regs(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | print_modules(); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 361 | printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n", |
| 362 | current->comm, current->pid, current_thread_info(), current, |
| 363 | field, current_thread_info()->tp_value); |
| 364 | if (cpu_has_userlocal) { |
| 365 | unsigned long tls; |
| 366 | |
| 367 | tls = read_c0_userlocal(); |
| 368 | if (tls != current_thread_info()->tp_value) |
| 369 | printk("*HwTLS: %0*lx\n", field, tls); |
| 370 | } |
| 371 | |
Leonid Yegoshin | 83e4da1 | 2013-10-08 12:39:31 +0100 | [diff] [blame] | 372 | if (!user_mode(regs)) |
| 373 | /* Necessary for getting the correct stack content */ |
| 374 | set_fs(KERNEL_DS); |
Atsushi Nemoto | f66686f | 2006-07-29 23:27:20 +0900 | [diff] [blame] | 375 | show_stacktrace(current, regs); |
Atsushi Nemoto | e1bb8289 | 2007-07-13 23:51:46 +0900 | [diff] [blame] | 376 | show_code((unsigned int __user *) regs->cp0_epc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | printk("\n"); |
Leonid Yegoshin | 83e4da1 | 2013-10-08 12:39:31 +0100 | [diff] [blame] | 378 | set_fs(old_fs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Wu Zhangjin | 4d85f6a | 2011-07-23 12:41:24 +0000 | [diff] [blame] | 381 | static DEFINE_RAW_SPINLOCK(die_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
David Daney | 70dc6f0 | 2010-08-03 15:44:43 -0700 | [diff] [blame] | 383 | void __noreturn die(const char *str, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { |
| 385 | static int die_counter; |
Yury Polyanskiy | ce384d8 | 2010-04-26 00:53:10 -0400 | [diff] [blame] | 386 | int sig = SIGSEGV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
Nathan Lynch | 8742cd2 | 2011-09-30 13:49:35 -0500 | [diff] [blame] | 388 | oops_enter(); |
| 389 | |
Ralf Baechle | e3b2883 | 2015-07-28 20:37:43 +0200 | [diff] [blame] | 390 | if (notify_die(DIE_OOPS, str, regs, 0, current->thread.trap_nr, |
Ralf Baechle | dc73e4c | 2013-10-09 08:54:15 +0200 | [diff] [blame] | 391 | SIGSEGV) == NOTIFY_STOP) |
Ralf Baechle | 10423c9 | 2011-05-13 10:33:28 +0100 | [diff] [blame] | 392 | sig = 0; |
Jason Wessel | 5dd11d5 | 2010-05-20 21:04:26 -0500 | [diff] [blame] | 393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | console_verbose(); |
Wu Zhangjin | 4d85f6a | 2011-07-23 12:41:24 +0000 | [diff] [blame] | 395 | raw_spin_lock_irq(&die_lock); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 396 | bust_spinlocks(1); |
Yury Polyanskiy | ce384d8 | 2010-04-26 00:53:10 -0400 | [diff] [blame] | 397 | |
Ralf Baechle | 178086c | 2005-10-13 17:07:54 +0100 | [diff] [blame] | 398 | printk("%s[#%d]:\n", str, ++die_counter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | show_registers(regs); |
Rusty Russell | 373d4d0 | 2013-01-21 17:17:39 +1030 | [diff] [blame] | 400 | add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE); |
Wu Zhangjin | 4d85f6a | 2011-07-23 12:41:24 +0000 | [diff] [blame] | 401 | raw_spin_unlock_irq(&die_lock); |
Maxime Bizon | d4fd198 | 2006-07-20 18:52:02 +0200 | [diff] [blame] | 402 | |
Nathan Lynch | 8742cd2 | 2011-09-30 13:49:35 -0500 | [diff] [blame] | 403 | oops_exit(); |
| 404 | |
Maxime Bizon | d4fd198 | 2006-07-20 18:52:02 +0200 | [diff] [blame] | 405 | if (in_interrupt()) |
| 406 | panic("Fatal exception in interrupt"); |
| 407 | |
Aaro Koskinen | 99a7a23 | 2016-03-09 22:08:42 +0200 | [diff] [blame] | 408 | if (panic_on_oops) |
Maxime Bizon | d4fd198 | 2006-07-20 18:52:02 +0200 | [diff] [blame] | 409 | panic("Fatal exception"); |
Maxime Bizon | d4fd198 | 2006-07-20 18:52:02 +0200 | [diff] [blame] | 410 | |
Ralf Baechle | 7aa1c8f | 2012-10-11 18:14:58 +0200 | [diff] [blame] | 411 | if (regs && kexec_should_crash(current)) |
| 412 | crash_kexec(regs); |
| 413 | |
Yury Polyanskiy | ce384d8 | 2010-04-26 00:53:10 -0400 | [diff] [blame] | 414 | do_exit(sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Thomas Bogendoerfer | 0510617 | 2008-08-04 19:44:34 +0200 | [diff] [blame] | 417 | extern struct exception_table_entry __start___dbe_table[]; |
| 418 | extern struct exception_table_entry __stop___dbe_table[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Ralf Baechle | b6dcec9 | 2007-02-18 15:57:09 +0000 | [diff] [blame] | 420 | __asm__( |
| 421 | " .section __dbe_table, \"a\"\n" |
| 422 | " .previous \n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
| 424 | /* Given an address, look for it in the exception tables. */ |
| 425 | static const struct exception_table_entry *search_dbe_tables(unsigned long addr) |
| 426 | { |
| 427 | const struct exception_table_entry *e; |
| 428 | |
Thomas Meyer | a94c33d | 2017-07-10 15:51:58 -0700 | [diff] [blame] | 429 | e = search_extable(__start___dbe_table, |
| 430 | __stop___dbe_table - __start___dbe_table, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | if (!e) |
| 432 | e = search_module_dbetables(addr); |
| 433 | return e; |
| 434 | } |
| 435 | |
| 436 | asmlinkage void do_be(struct pt_regs *regs) |
| 437 | { |
| 438 | const int field = 2 * sizeof(unsigned long); |
| 439 | const struct exception_table_entry *fixup = NULL; |
| 440 | int data = regs->cp0_cause & 4; |
| 441 | int action = MIPS_BE_FATAL; |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 442 | enum ctx_state prev_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 444 | prev_state = exception_enter(); |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 445 | /* XXX For now. Fixme, this searches the wrong table ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | if (data && !user_mode(regs)) |
| 447 | fixup = search_dbe_tables(exception_epc(regs)); |
| 448 | |
| 449 | if (fixup) |
| 450 | action = MIPS_BE_FIXUP; |
| 451 | |
| 452 | if (board_be_handler) |
Atsushi Nemoto | 28fc582 | 2007-07-13 01:49:49 +0900 | [diff] [blame] | 453 | action = board_be_handler(regs, fixup != NULL); |
Paul Burton | dabdc18 | 2016-10-05 18:18:17 +0100 | [diff] [blame] | 454 | else |
| 455 | mips_cm_error_report(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | |
| 457 | switch (action) { |
| 458 | case MIPS_BE_DISCARD: |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 459 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | case MIPS_BE_FIXUP: |
| 461 | if (fixup) { |
| 462 | regs->cp0_epc = fixup->nextinsn; |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 463 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | } |
| 465 | break; |
| 466 | default: |
| 467 | break; |
| 468 | } |
| 469 | |
| 470 | /* |
| 471 | * Assume it would be too dangerous to continue ... |
| 472 | */ |
| 473 | printk(KERN_ALERT "%s bus error, epc == %0*lx, ra == %0*lx\n", |
| 474 | data ? "Data" : "Instruction", |
| 475 | field, regs->cp0_epc, field, regs->regs[31]); |
Ralf Baechle | e3b2883 | 2015-07-28 20:37:43 +0200 | [diff] [blame] | 476 | if (notify_die(DIE_OOPS, "bus error", regs, 0, current->thread.trap_nr, |
Ralf Baechle | dc73e4c | 2013-10-09 08:54:15 +0200 | [diff] [blame] | 477 | SIGBUS) == NOTIFY_STOP) |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 478 | goto out; |
Jason Wessel | 8854700 | 2008-07-29 15:58:53 -0500 | [diff] [blame] | 479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | die_if_kernel("Oops", regs); |
| 481 | force_sig(SIGBUS, current); |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 482 | |
| 483 | out: |
| 484 | exception_exit(prev_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | /* |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 488 | * ll/sc, rdhwr, sync emulation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | */ |
| 490 | |
| 491 | #define OPCODE 0xfc000000 |
| 492 | #define BASE 0x03e00000 |
| 493 | #define RT 0x001f0000 |
| 494 | #define OFFSET 0x0000ffff |
| 495 | #define LL 0xc0000000 |
| 496 | #define SC 0xe0000000 |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 497 | #define SPEC0 0x00000000 |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 498 | #define SPEC3 0x7c000000 |
| 499 | #define RD 0x0000f800 |
| 500 | #define FUNC 0x0000003f |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 501 | #define SYNC 0x0000000f |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 502 | #define RDHWR 0x0000003b |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 504 | /* microMIPS definitions */ |
| 505 | #define MM_POOL32A_FUNC 0xfc00ffff |
| 506 | #define MM_RDHWR 0x00006b3c |
| 507 | #define MM_RS 0x001f0000 |
| 508 | #define MM_RT 0x03e00000 |
| 509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | /* |
| 511 | * The ll_bit is cleared by r*_switch.S |
| 512 | */ |
| 513 | |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 514 | unsigned int ll_bit; |
| 515 | struct task_struct *ll_task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 517 | static inline int simulate_ll(struct pt_regs *regs, unsigned int opcode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | { |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 519 | unsigned long value, __user *vaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | long offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
| 522 | /* |
| 523 | * analyse the ll instruction that just caused a ri exception |
| 524 | * and put the referenced address to addr. |
| 525 | */ |
| 526 | |
| 527 | /* sign extend offset */ |
| 528 | offset = opcode & OFFSET; |
| 529 | offset <<= 16; |
| 530 | offset >>= 16; |
| 531 | |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 532 | vaddr = (unsigned long __user *) |
Steven J. Hill | b968831 | 2013-01-12 23:29:27 +0000 | [diff] [blame] | 533 | ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 535 | if ((unsigned long)vaddr & 3) |
| 536 | return SIGBUS; |
| 537 | if (get_user(value, vaddr)) |
| 538 | return SIGSEGV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
| 540 | preempt_disable(); |
| 541 | |
| 542 | if (ll_task == NULL || ll_task == current) { |
| 543 | ll_bit = 1; |
| 544 | } else { |
| 545 | ll_bit = 0; |
| 546 | } |
| 547 | ll_task = current; |
| 548 | |
| 549 | preempt_enable(); |
| 550 | |
| 551 | regs->regs[(opcode & RT) >> 16] = value; |
| 552 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 553 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 556 | static inline int simulate_sc(struct pt_regs *regs, unsigned int opcode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | { |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 558 | unsigned long __user *vaddr; |
| 559 | unsigned long reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | long offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
| 562 | /* |
| 563 | * analyse the sc instruction that just caused a ri exception |
| 564 | * and put the referenced address to addr. |
| 565 | */ |
| 566 | |
| 567 | /* sign extend offset */ |
| 568 | offset = opcode & OFFSET; |
| 569 | offset <<= 16; |
| 570 | offset >>= 16; |
| 571 | |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 572 | vaddr = (unsigned long __user *) |
Steven J. Hill | b968831 | 2013-01-12 23:29:27 +0000 | [diff] [blame] | 573 | ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | reg = (opcode & RT) >> 16; |
| 575 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 576 | if ((unsigned long)vaddr & 3) |
| 577 | return SIGBUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
| 579 | preempt_disable(); |
| 580 | |
| 581 | if (ll_bit == 0 || ll_task != current) { |
| 582 | regs->regs[reg] = 0; |
| 583 | preempt_enable(); |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 584 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | preempt_enable(); |
| 588 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 589 | if (put_user(regs->regs[reg], vaddr)) |
| 590 | return SIGSEGV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
| 592 | regs->regs[reg] = 1; |
| 593 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 594 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /* |
| 598 | * ll uses the opcode of lwc0 and sc uses the opcode of swc0. That is both |
| 599 | * opcodes are supposed to result in coprocessor unusable exceptions if |
| 600 | * executed on ll/sc-less processors. That's the theory. In practice a |
| 601 | * few processors such as NEC's VR4100 throw reserved instruction exceptions |
| 602 | * instead, so we're doing the emulation thing in both exception handlers. |
| 603 | */ |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 604 | static int simulate_llsc(struct pt_regs *regs, unsigned int opcode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | { |
Deng-Cheng Zhu | 7f788d2 | 2010-10-12 19:37:21 +0800 | [diff] [blame] | 606 | if ((opcode & OPCODE) == LL) { |
| 607 | perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, |
Peter Zijlstra | a8b0ca1 | 2011-06-27 14:41:57 +0200 | [diff] [blame] | 608 | 1, regs, 0); |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 609 | return simulate_ll(regs, opcode); |
Deng-Cheng Zhu | 7f788d2 | 2010-10-12 19:37:21 +0800 | [diff] [blame] | 610 | } |
| 611 | if ((opcode & OPCODE) == SC) { |
| 612 | perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, |
Peter Zijlstra | a8b0ca1 | 2011-06-27 14:41:57 +0200 | [diff] [blame] | 613 | 1, regs, 0); |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 614 | return simulate_sc(regs, opcode); |
Deng-Cheng Zhu | 7f788d2 | 2010-10-12 19:37:21 +0800 | [diff] [blame] | 615 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 617 | return -1; /* Must be something else ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 620 | /* |
| 621 | * Simulate trapping 'rdhwr' instructions to provide user accessible |
Chris Dearman | 1f5826b | 2006-05-08 18:02:16 +0100 | [diff] [blame] | 622 | * registers not implemented in hardware. |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 623 | */ |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 624 | static int simulate_rdhwr(struct pt_regs *regs, int rd, int rt) |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 625 | { |
Al Viro | dc8f602 | 2006-01-12 01:06:07 -0800 | [diff] [blame] | 626 | struct thread_info *ti = task_thread_info(current); |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 627 | |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 628 | perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, |
| 629 | 1, regs, 0); |
| 630 | switch (rd) { |
James Hogan | aff565a | 2016-06-15 19:29:52 +0100 | [diff] [blame] | 631 | case MIPS_HWR_CPUNUM: /* CPU number */ |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 632 | regs->regs[rt] = smp_processor_id(); |
| 633 | return 0; |
James Hogan | aff565a | 2016-06-15 19:29:52 +0100 | [diff] [blame] | 634 | case MIPS_HWR_SYNCISTEP: /* SYNCI length */ |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 635 | regs->regs[rt] = min(current_cpu_data.dcache.linesz, |
| 636 | current_cpu_data.icache.linesz); |
| 637 | return 0; |
James Hogan | aff565a | 2016-06-15 19:29:52 +0100 | [diff] [blame] | 638 | case MIPS_HWR_CC: /* Read count register */ |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 639 | regs->regs[rt] = read_c0_count(); |
| 640 | return 0; |
James Hogan | aff565a | 2016-06-15 19:29:52 +0100 | [diff] [blame] | 641 | case MIPS_HWR_CCRES: /* Count register resolution */ |
Ralf Baechle | 69f24d1 | 2013-09-17 10:25:47 +0200 | [diff] [blame] | 642 | switch (current_cpu_type()) { |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 643 | case CPU_20KC: |
| 644 | case CPU_25KF: |
| 645 | regs->regs[rt] = 1; |
| 646 | break; |
| 647 | default: |
| 648 | regs->regs[rt] = 2; |
| 649 | } |
| 650 | return 0; |
James Hogan | aff565a | 2016-06-15 19:29:52 +0100 | [diff] [blame] | 651 | case MIPS_HWR_ULR: /* Read UserLocal register */ |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 652 | regs->regs[rt] = ti->tp_value; |
| 653 | return 0; |
| 654 | default: |
| 655 | return -1; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | static int simulate_rdhwr_normal(struct pt_regs *regs, unsigned int opcode) |
| 660 | { |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 661 | if ((opcode & OPCODE) == SPEC3 && (opcode & FUNC) == RDHWR) { |
| 662 | int rd = (opcode & RD) >> 11; |
| 663 | int rt = (opcode & RT) >> 16; |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 664 | |
| 665 | simulate_rdhwr(regs, rd, rt); |
| 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | /* Not ours. */ |
| 670 | return -1; |
| 671 | } |
| 672 | |
Maciej W. Rozycki | 7aa7047 | 2016-01-30 09:08:28 +0000 | [diff] [blame] | 673 | static int simulate_rdhwr_mm(struct pt_regs *regs, unsigned int opcode) |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 674 | { |
| 675 | if ((opcode & MM_POOL32A_FUNC) == MM_RDHWR) { |
| 676 | int rd = (opcode & MM_RS) >> 16; |
| 677 | int rt = (opcode & MM_RT) >> 21; |
| 678 | simulate_rdhwr(regs, rd, rt); |
| 679 | return 0; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 680 | } |
| 681 | |
Daniel Jacobowitz | 56ebd51 | 2005-11-26 22:34:41 -0500 | [diff] [blame] | 682 | /* Not ours. */ |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 683 | return -1; |
| 684 | } |
Ralf Baechle | e567988 | 2006-11-30 01:14:47 +0000 | [diff] [blame] | 685 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 686 | static int simulate_sync(struct pt_regs *regs, unsigned int opcode) |
| 687 | { |
Deng-Cheng Zhu | 7f788d2 | 2010-10-12 19:37:21 +0800 | [diff] [blame] | 688 | if ((opcode & OPCODE) == SPEC0 && (opcode & FUNC) == SYNC) { |
| 689 | perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, |
Peter Zijlstra | a8b0ca1 | 2011-06-27 14:41:57 +0200 | [diff] [blame] | 690 | 1, regs, 0); |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 691 | return 0; |
Deng-Cheng Zhu | 7f788d2 | 2010-10-12 19:37:21 +0800 | [diff] [blame] | 692 | } |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 693 | |
| 694 | return -1; /* Must be something else ... */ |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 695 | } |
| 696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | asmlinkage void do_ov(struct pt_regs *regs) |
| 698 | { |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 699 | enum ctx_state prev_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 701 | prev_state = exception_enter(); |
Ralf Baechle | 36ccf1c | 2006-02-14 21:04:54 +0000 | [diff] [blame] | 702 | die_if_kernel("Integer overflow", regs); |
| 703 | |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 704 | force_sig_fault(SIGFPE, FPE_INTOVF, (void __user *)regs->cp0_epc, current); |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 705 | exception_exit(prev_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 708 | /* |
| 709 | * Send SIGFPE according to FCSR Cause bits, which must have already |
| 710 | * been masked against Enable bits. This is impotant as Inexact can |
| 711 | * happen together with Overflow or Underflow, and `ptrace' can set |
| 712 | * any bits. |
| 713 | */ |
| 714 | void force_fcr31_sig(unsigned long fcr31, void __user *fault_addr, |
| 715 | struct task_struct *tsk) |
| 716 | { |
Guenter Roeck | 0bb0a11 | 2018-05-15 06:50:47 -0700 | [diff] [blame] | 717 | int si_code = FPE_FLTUNK; |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 718 | |
| 719 | if (fcr31 & FPU_CSR_INV_X) |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 720 | si_code = FPE_FLTINV; |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 721 | else if (fcr31 & FPU_CSR_DIV_X) |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 722 | si_code = FPE_FLTDIV; |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 723 | else if (fcr31 & FPU_CSR_OVF_X) |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 724 | si_code = FPE_FLTOVF; |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 725 | else if (fcr31 & FPU_CSR_UDF_X) |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 726 | si_code = FPE_FLTUND; |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 727 | else if (fcr31 & FPU_CSR_INE_X) |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 728 | si_code = FPE_FLTRES; |
Ralf Baechle | b123718 | 2017-08-07 21:14:18 +0200 | [diff] [blame] | 729 | |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 730 | force_sig_fault(SIGFPE, si_code, fault_addr, tsk); |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 731 | } |
| 732 | |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 733 | int process_fpemu_return(int sig, void __user *fault_addr, unsigned long fcr31) |
David Daney | 515b029 | 2010-10-21 16:32:26 -0700 | [diff] [blame] | 734 | { |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 735 | int si_code; |
Petar Jovanovic | bcfc8f0 | 2016-07-13 15:23:37 +0200 | [diff] [blame] | 736 | struct vm_area_struct *vma; |
Paul Burton | ad70c13 | 2015-01-30 12:09:35 +0000 | [diff] [blame] | 737 | |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 738 | switch (sig) { |
| 739 | case 0: |
| 740 | return 0; |
| 741 | |
| 742 | case SIGFPE: |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 743 | force_fcr31_sig(fcr31, fault_addr, current); |
David Daney | 515b029 | 2010-10-21 16:32:26 -0700 | [diff] [blame] | 744 | return 1; |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 745 | |
| 746 | case SIGBUS: |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 747 | force_sig_fault(SIGBUS, BUS_ADRERR, fault_addr, current); |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 748 | return 1; |
| 749 | |
| 750 | case SIGSEGV: |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 751 | down_read(¤t->mm->mmap_sem); |
Petar Jovanovic | bcfc8f0 | 2016-07-13 15:23:37 +0200 | [diff] [blame] | 752 | vma = find_vma(current->mm, (unsigned long)fault_addr); |
| 753 | if (vma && (vma->vm_start <= (unsigned long)fault_addr)) |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 754 | si_code = SEGV_ACCERR; |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 755 | else |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 756 | si_code = SEGV_MAPERR; |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 757 | up_read(¤t->mm->mmap_sem); |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 758 | force_sig_fault(SIGSEGV, si_code, fault_addr, current); |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 759 | return 1; |
| 760 | |
| 761 | default: |
David Daney | 515b029 | 2010-10-21 16:32:26 -0700 | [diff] [blame] | 762 | force_sig(sig, current); |
| 763 | return 1; |
David Daney | 515b029 | 2010-10-21 16:32:26 -0700 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
Paul Burton | 4227a2d | 2014-09-11 08:30:20 +0100 | [diff] [blame] | 767 | static int simulate_fp(struct pt_regs *regs, unsigned int opcode, |
| 768 | unsigned long old_epc, unsigned long old_ra) |
| 769 | { |
| 770 | union mips_instruction inst = { .word = opcode }; |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 771 | void __user *fault_addr; |
| 772 | unsigned long fcr31; |
Paul Burton | 4227a2d | 2014-09-11 08:30:20 +0100 | [diff] [blame] | 773 | int sig; |
| 774 | |
| 775 | /* If it's obviously not an FP instruction, skip it */ |
| 776 | switch (inst.i_format.opcode) { |
| 777 | case cop1_op: |
| 778 | case cop1x_op: |
| 779 | case lwc1_op: |
| 780 | case ldc1_op: |
| 781 | case swc1_op: |
| 782 | case sdc1_op: |
| 783 | break; |
| 784 | |
| 785 | default: |
| 786 | return -1; |
| 787 | } |
| 788 | |
| 789 | /* |
| 790 | * do_ri skipped over the instruction via compute_return_epc, undo |
| 791 | * that for the FPU emulator. |
| 792 | */ |
| 793 | regs->cp0_epc = old_epc; |
| 794 | regs->regs[31] = old_ra; |
| 795 | |
| 796 | /* Save the FP context to struct thread_struct */ |
| 797 | lose_fpu(1); |
| 798 | |
| 799 | /* Run the emulator */ |
| 800 | sig = fpu_emulator_cop1Handler(regs, ¤t->thread.fpu, 1, |
| 801 | &fault_addr); |
| 802 | |
Maciej W. Rozycki | 443c440 | 2015-04-03 23:27:10 +0100 | [diff] [blame] | 803 | /* |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 804 | * We can't allow the emulated instruction to leave any |
| 805 | * enabled Cause bits set in $fcr31. |
Maciej W. Rozycki | 443c440 | 2015-04-03 23:27:10 +0100 | [diff] [blame] | 806 | */ |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 807 | fcr31 = mask_fcr31_x(current->thread.fpu.fcr31); |
| 808 | current->thread.fpu.fcr31 &= ~fcr31; |
Paul Burton | 4227a2d | 2014-09-11 08:30:20 +0100 | [diff] [blame] | 809 | |
| 810 | /* Restore the hardware register state */ |
| 811 | own_fpu(1); |
| 812 | |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 813 | /* Send a signal if required. */ |
| 814 | process_fpemu_return(sig, fault_addr, fcr31); |
| 815 | |
Paul Burton | 4227a2d | 2014-09-11 08:30:20 +0100 | [diff] [blame] | 816 | return 0; |
| 817 | } |
| 818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | /* |
| 820 | * XXX Delayed fp exceptions when doing a lazy ctx switch XXX |
| 821 | */ |
| 822 | asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31) |
| 823 | { |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 824 | enum ctx_state prev_state; |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 825 | void __user *fault_addr; |
| 826 | int sig; |
Thiemo Seufer | 948a34c | 2007-08-22 01:42:04 +0100 | [diff] [blame] | 827 | |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 828 | prev_state = exception_enter(); |
Ralf Baechle | e3b2883 | 2015-07-28 20:37:43 +0200 | [diff] [blame] | 829 | if (notify_die(DIE_FP, "FP exception", regs, 0, current->thread.trap_nr, |
Ralf Baechle | dc73e4c | 2013-10-09 08:54:15 +0200 | [diff] [blame] | 830 | SIGFPE) == NOTIFY_STOP) |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 831 | goto out; |
James Hogan | 64bedff | 2014-12-02 13:44:13 +0000 | [diff] [blame] | 832 | |
| 833 | /* Clear FCSR.Cause before enabling interrupts */ |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 834 | write_32bit_cp1_register(CP1_STATUS, fcr31 & ~mask_fcr31_x(fcr31)); |
James Hogan | 64bedff | 2014-12-02 13:44:13 +0000 | [diff] [blame] | 835 | local_irq_enable(); |
| 836 | |
Chris Dearman | 57725f9 | 2006-06-30 23:35:28 +0100 | [diff] [blame] | 837 | die_if_kernel("FP exception in kernel code", regs); |
| 838 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | if (fcr31 & FPU_CSR_UNI_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | /* |
Ralf Baechle | a3dddd5 | 2006-03-11 08:18:41 +0000 | [diff] [blame] | 841 | * Unimplemented operation exception. If we've got the full |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | * software emulator on-board, let's use it... |
| 843 | * |
| 844 | * Force FPU to dump state into task/thread context. We're |
| 845 | * moving a lot of data here for what is probably a single |
| 846 | * instruction, but the alternative is to pre-decode the FP |
| 847 | * register operands before invoking the emulator, which seems |
| 848 | * a bit extreme for what should be an infrequent event. |
| 849 | */ |
Ralf Baechle | cd21dfc | 2005-04-28 13:39:10 +0000 | [diff] [blame] | 850 | /* Ensure 'resume' not overwrite saved fp context again. */ |
Atsushi Nemoto | 53dc802 | 2007-03-10 01:07:45 +0900 | [diff] [blame] | 851 | lose_fpu(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | |
| 853 | /* Run the emulator */ |
David Daney | 515b029 | 2010-10-21 16:32:26 -0700 | [diff] [blame] | 854 | sig = fpu_emulator_cop1Handler(regs, ¤t->thread.fpu, 1, |
| 855 | &fault_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
| 857 | /* |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 858 | * We can't allow the emulated instruction to leave any |
| 859 | * enabled Cause bits set in $fcr31. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | */ |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 861 | fcr31 = mask_fcr31_x(current->thread.fpu.fcr31); |
| 862 | current->thread.fpu.fcr31 &= ~fcr31; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
| 864 | /* Restore the hardware register state */ |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 865 | own_fpu(1); /* Using the FPU again. */ |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 866 | } else { |
| 867 | sig = SIGFPE; |
| 868 | fault_addr = (void __user *) regs->cp0_epc; |
Maciej W. Rozycki | ed2d72c | 2015-04-03 23:27:06 +0100 | [diff] [blame] | 869 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 871 | /* Send a signal if required. */ |
| 872 | process_fpemu_return(sig, fault_addr, fcr31); |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 873 | |
| 874 | out: |
| 875 | exception_exit(prev_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Maciej W. Rozycki | 3b143cc | 2016-03-04 01:44:28 +0000 | [diff] [blame] | 878 | void do_trap_or_bp(struct pt_regs *regs, unsigned int code, int si_code, |
Ralf Baechle | df27005 | 2008-04-20 16:28:54 +0100 | [diff] [blame] | 879 | const char *str) |
| 880 | { |
Ralf Baechle | df27005 | 2008-04-20 16:28:54 +0100 | [diff] [blame] | 881 | char b[40]; |
| 882 | |
Jason Wessel | 5dd11d5 | 2010-05-20 21:04:26 -0500 | [diff] [blame] | 883 | #ifdef CONFIG_KGDB_LOW_LEVEL_TRAP |
Ralf Baechle | e3b2883 | 2015-07-28 20:37:43 +0200 | [diff] [blame] | 884 | if (kgdb_ll_trap(DIE_TRAP, str, regs, code, current->thread.trap_nr, |
| 885 | SIGTRAP) == NOTIFY_STOP) |
Jason Wessel | 5dd11d5 | 2010-05-20 21:04:26 -0500 | [diff] [blame] | 886 | return; |
| 887 | #endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */ |
| 888 | |
Ralf Baechle | e3b2883 | 2015-07-28 20:37:43 +0200 | [diff] [blame] | 889 | if (notify_die(DIE_TRAP, str, regs, code, current->thread.trap_nr, |
Ralf Baechle | dc73e4c | 2013-10-09 08:54:15 +0200 | [diff] [blame] | 890 | SIGTRAP) == NOTIFY_STOP) |
Jason Wessel | 8854700 | 2008-07-29 15:58:53 -0500 | [diff] [blame] | 891 | return; |
| 892 | |
Ralf Baechle | df27005 | 2008-04-20 16:28:54 +0100 | [diff] [blame] | 893 | /* |
| 894 | * A short test says that IRIX 5.3 sends SIGTRAP for all trap |
| 895 | * insns, even for trap and break codes that indicate arithmetic |
| 896 | * failures. Weird ... |
| 897 | * But should we continue the brokenness??? --macro |
| 898 | */ |
| 899 | switch (code) { |
| 900 | case BRK_OVERFLOW: |
| 901 | case BRK_DIVZERO: |
| 902 | scnprintf(b, sizeof(b), "%s instruction in kernel code", str); |
| 903 | die_if_kernel(b, regs); |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 904 | force_sig_fault(SIGFPE, |
| 905 | code == BRK_DIVZERO ? FPE_INTDIV : FPE_INTOVF, |
| 906 | (void __user *) regs->cp0_epc, current); |
Ralf Baechle | df27005 | 2008-04-20 16:28:54 +0100 | [diff] [blame] | 907 | break; |
| 908 | case BRK_BUG: |
| 909 | die_if_kernel("Kernel bug detected", regs); |
| 910 | force_sig(SIGTRAP, current); |
| 911 | break; |
Ralf Baechle | ba3049e | 2008-10-28 17:38:42 +0000 | [diff] [blame] | 912 | case BRK_MEMU: |
| 913 | /* |
Maciej W. Rozycki | 1f44377 | 2015-04-03 23:24:14 +0100 | [diff] [blame] | 914 | * This breakpoint code is used by the FPU emulator to retake |
| 915 | * control of the CPU after executing the instruction from the |
| 916 | * delay slot of an emulated branch. |
Ralf Baechle | ba3049e | 2008-10-28 17:38:42 +0000 | [diff] [blame] | 917 | * |
| 918 | * Terminate if exception was recognized as a delay slot return |
| 919 | * otherwise handle as normal. |
| 920 | */ |
| 921 | if (do_dsemulret(regs)) |
| 922 | return; |
| 923 | |
| 924 | die_if_kernel("Math emu break/trap", regs); |
| 925 | force_sig(SIGTRAP, current); |
| 926 | break; |
Ralf Baechle | df27005 | 2008-04-20 16:28:54 +0100 | [diff] [blame] | 927 | default: |
| 928 | scnprintf(b, sizeof(b), "%s instruction in kernel code", str); |
| 929 | die_if_kernel(b, regs); |
Maciej W. Rozycki | 3b143cc | 2016-03-04 01:44:28 +0000 | [diff] [blame] | 930 | if (si_code) { |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 931 | force_sig_fault(SIGTRAP, si_code, NULL, current); |
Maciej W. Rozycki | 3b143cc | 2016-03-04 01:44:28 +0000 | [diff] [blame] | 932 | } else { |
| 933 | force_sig(SIGTRAP, current); |
| 934 | } |
Ralf Baechle | df27005 | 2008-04-20 16:28:54 +0100 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | asmlinkage void do_bp(struct pt_regs *regs) |
| 939 | { |
Maciej W. Rozycki | f6a31da | 2015-04-03 23:26:27 +0100 | [diff] [blame] | 940 | unsigned long epc = msk_isa16_mode(exception_epc(regs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | unsigned int opcode, bcode; |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 942 | enum ctx_state prev_state; |
Leonid Yegoshin | 078dde5 | 2013-12-04 16:39:34 +0000 | [diff] [blame] | 943 | mm_segment_t seg; |
| 944 | |
| 945 | seg = get_fs(); |
| 946 | if (!user_mode(regs)) |
| 947 | set_fs(KERNEL_DS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 949 | prev_state = exception_enter(); |
Ralf Baechle | e3b2883 | 2015-07-28 20:37:43 +0200 | [diff] [blame] | 950 | current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f; |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 951 | if (get_isa16_mode(regs->cp0_epc)) { |
Maciej W. Rozycki | f6a31da | 2015-04-03 23:26:27 +0100 | [diff] [blame] | 952 | u16 instr[2]; |
| 953 | |
| 954 | if (__get_user(instr[0], (u16 __user *)epc)) |
| 955 | goto out_sigsegv; |
| 956 | |
| 957 | if (!cpu_has_mmips) { |
| 958 | /* MIPS16e mode */ |
| 959 | bcode = (instr[0] >> 5) & 0x3f; |
| 960 | } else if (mm_insn_16bit(instr[0])) { |
| 961 | /* 16-bit microMIPS BREAK */ |
| 962 | bcode = instr[0] & 0xf; |
| 963 | } else { |
| 964 | /* 32-bit microMIPS BREAK */ |
| 965 | if (__get_user(instr[1], (u16 __user *)(epc + 2))) |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 966 | goto out_sigsegv; |
Markos Chandras | b08a9c9 | 2013-12-04 16:20:08 +0000 | [diff] [blame] | 967 | opcode = (instr[0] << 16) | instr[1]; |
Maciej W. Rozycki | f6a31da | 2015-04-03 23:26:27 +0100 | [diff] [blame] | 968 | bcode = (opcode >> 6) & ((1 << 20) - 1); |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 969 | } |
| 970 | } else { |
Maciej W. Rozycki | f6a31da | 2015-04-03 23:26:27 +0100 | [diff] [blame] | 971 | if (__get_user(opcode, (unsigned int __user *)epc)) |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 972 | goto out_sigsegv; |
Maciej W. Rozycki | f6a31da | 2015-04-03 23:26:27 +0100 | [diff] [blame] | 973 | bcode = (opcode >> 6) & ((1 << 20) - 1); |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 974 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | |
| 976 | /* |
| 977 | * There is the ancient bug in the MIPS assemblers that the break |
| 978 | * code starts left to bit 16 instead to bit 6 in the opcode. |
| 979 | * Gas is bug-compatible, but not always, grrr... |
| 980 | * We handle both cases with a simple heuristics. --macro |
| 981 | */ |
Ralf Baechle | df27005 | 2008-04-20 16:28:54 +0100 | [diff] [blame] | 982 | if (bcode >= (1 << 10)) |
Maciej W. Rozycki | c987503 | 2015-04-03 23:26:32 +0100 | [diff] [blame] | 983 | bcode = ((bcode & ((1 << 10) - 1)) << 10) | (bcode >> 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | |
David Daney | c1bf207 | 2010-08-03 11:22:20 -0700 | [diff] [blame] | 985 | /* |
| 986 | * notify the kprobe handlers, if instruction is likely to |
| 987 | * pertain to them. |
| 988 | */ |
| 989 | switch (bcode) { |
Ralf Baechle | 40e084a | 2015-07-29 22:44:53 +0200 | [diff] [blame] | 990 | case BRK_UPROBE: |
| 991 | if (notify_die(DIE_UPROBE, "uprobe", regs, bcode, |
| 992 | current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP) |
| 993 | goto out; |
| 994 | else |
| 995 | break; |
| 996 | case BRK_UPROBE_XOL: |
| 997 | if (notify_die(DIE_UPROBE_XOL, "uprobe_xol", regs, bcode, |
| 998 | current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP) |
| 999 | goto out; |
| 1000 | else |
| 1001 | break; |
David Daney | c1bf207 | 2010-08-03 11:22:20 -0700 | [diff] [blame] | 1002 | case BRK_KPROBE_BP: |
Ralf Baechle | dc73e4c | 2013-10-09 08:54:15 +0200 | [diff] [blame] | 1003 | if (notify_die(DIE_BREAK, "debug", regs, bcode, |
Ralf Baechle | e3b2883 | 2015-07-28 20:37:43 +0200 | [diff] [blame] | 1004 | current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP) |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1005 | goto out; |
David Daney | c1bf207 | 2010-08-03 11:22:20 -0700 | [diff] [blame] | 1006 | else |
| 1007 | break; |
| 1008 | case BRK_KPROBE_SSTEPBP: |
Ralf Baechle | dc73e4c | 2013-10-09 08:54:15 +0200 | [diff] [blame] | 1009 | if (notify_die(DIE_SSTEPBP, "single_step", regs, bcode, |
Ralf Baechle | e3b2883 | 2015-07-28 20:37:43 +0200 | [diff] [blame] | 1010 | current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP) |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1011 | goto out; |
David Daney | c1bf207 | 2010-08-03 11:22:20 -0700 | [diff] [blame] | 1012 | else |
| 1013 | break; |
| 1014 | default: |
| 1015 | break; |
| 1016 | } |
| 1017 | |
Maciej W. Rozycki | 3b143cc | 2016-03-04 01:44:28 +0000 | [diff] [blame] | 1018 | do_trap_or_bp(regs, bcode, TRAP_BRKPT, "Break"); |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1019 | |
| 1020 | out: |
Leonid Yegoshin | 078dde5 | 2013-12-04 16:39:34 +0000 | [diff] [blame] | 1021 | set_fs(seg); |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1022 | exception_exit(prev_state); |
Atsushi Nemoto | 90fccb1 | 2007-02-06 16:02:21 +0900 | [diff] [blame] | 1023 | return; |
Ralf Baechle | e567988 | 2006-11-30 01:14:47 +0000 | [diff] [blame] | 1024 | |
| 1025 | out_sigsegv: |
| 1026 | force_sig(SIGSEGV, current); |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1027 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | asmlinkage void do_tr(struct pt_regs *regs) |
| 1031 | { |
Maciej W. Rozycki | a9a6e7a | 2013-05-23 14:31:23 +0000 | [diff] [blame] | 1032 | u32 opcode, tcode = 0; |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1033 | enum ctx_state prev_state; |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1034 | u16 instr[2]; |
Leonid Yegoshin | 078dde5 | 2013-12-04 16:39:34 +0000 | [diff] [blame] | 1035 | mm_segment_t seg; |
Maciej W. Rozycki | a9a6e7a | 2013-05-23 14:31:23 +0000 | [diff] [blame] | 1036 | unsigned long epc = msk_isa16_mode(exception_epc(regs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
Leonid Yegoshin | 078dde5 | 2013-12-04 16:39:34 +0000 | [diff] [blame] | 1038 | seg = get_fs(); |
| 1039 | if (!user_mode(regs)) |
| 1040 | set_fs(get_ds()); |
| 1041 | |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1042 | prev_state = exception_enter(); |
Ralf Baechle | e3b2883 | 2015-07-28 20:37:43 +0200 | [diff] [blame] | 1043 | current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f; |
Maciej W. Rozycki | a9a6e7a | 2013-05-23 14:31:23 +0000 | [diff] [blame] | 1044 | if (get_isa16_mode(regs->cp0_epc)) { |
| 1045 | if (__get_user(instr[0], (u16 __user *)(epc + 0)) || |
| 1046 | __get_user(instr[1], (u16 __user *)(epc + 2))) |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1047 | goto out_sigsegv; |
Maciej W. Rozycki | a9a6e7a | 2013-05-23 14:31:23 +0000 | [diff] [blame] | 1048 | opcode = (instr[0] << 16) | instr[1]; |
| 1049 | /* Immediate versions don't provide a code. */ |
| 1050 | if (!(opcode & OPCODE)) |
| 1051 | tcode = (opcode >> 12) & ((1 << 4) - 1); |
| 1052 | } else { |
| 1053 | if (__get_user(opcode, (u32 __user *)epc)) |
| 1054 | goto out_sigsegv; |
| 1055 | /* Immediate versions don't provide a code. */ |
| 1056 | if (!(opcode & OPCODE)) |
| 1057 | tcode = (opcode >> 6) & ((1 << 10) - 1); |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1058 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | |
Maciej W. Rozycki | 3b143cc | 2016-03-04 01:44:28 +0000 | [diff] [blame] | 1060 | do_trap_or_bp(regs, tcode, 0, "Trap"); |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1061 | |
| 1062 | out: |
Leonid Yegoshin | 078dde5 | 2013-12-04 16:39:34 +0000 | [diff] [blame] | 1063 | set_fs(seg); |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1064 | exception_exit(prev_state); |
Atsushi Nemoto | 90fccb1 | 2007-02-06 16:02:21 +0900 | [diff] [blame] | 1065 | return; |
Ralf Baechle | e567988 | 2006-11-30 01:14:47 +0000 | [diff] [blame] | 1066 | |
| 1067 | out_sigsegv: |
| 1068 | force_sig(SIGSEGV, current); |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1069 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | asmlinkage void do_ri(struct pt_regs *regs) |
| 1073 | { |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 1074 | unsigned int __user *epc = (unsigned int __user *)exception_epc(regs); |
| 1075 | unsigned long old_epc = regs->cp0_epc; |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1076 | unsigned long old31 = regs->regs[31]; |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1077 | enum ctx_state prev_state; |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 1078 | unsigned int opcode = 0; |
| 1079 | int status = -1; |
| 1080 | |
Leonid Yegoshin | b0a668f | 2014-12-03 15:47:03 +0000 | [diff] [blame] | 1081 | /* |
| 1082 | * Avoid any kernel code. Just emulate the R2 instruction |
| 1083 | * as quickly as possible. |
| 1084 | */ |
| 1085 | if (mipsr2_emulation && cpu_has_mips_r6 && |
Maciej W. Rozycki | 4a7c237 | 2015-04-03 23:24:51 +0100 | [diff] [blame] | 1086 | likely(user_mode(regs)) && |
| 1087 | likely(get_user(opcode, epc) >= 0)) { |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 1088 | unsigned long fcr31 = 0; |
| 1089 | |
| 1090 | status = mipsr2_decoder(regs, opcode, &fcr31); |
Maciej W. Rozycki | 4a7c237 | 2015-04-03 23:24:51 +0100 | [diff] [blame] | 1091 | switch (status) { |
| 1092 | case 0: |
| 1093 | case SIGEMT: |
Maciej W. Rozycki | 4a7c237 | 2015-04-03 23:24:51 +0100 | [diff] [blame] | 1094 | return; |
| 1095 | case SIGILL: |
| 1096 | goto no_r2_instr; |
| 1097 | default: |
| 1098 | process_fpemu_return(status, |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 1099 | ¤t->thread.cp0_baduaddr, |
| 1100 | fcr31); |
Maciej W. Rozycki | 4a7c237 | 2015-04-03 23:24:51 +0100 | [diff] [blame] | 1101 | return; |
Leonid Yegoshin | b0a668f | 2014-12-03 15:47:03 +0000 | [diff] [blame] | 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | no_r2_instr: |
| 1106 | |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1107 | prev_state = exception_enter(); |
Ralf Baechle | e3b2883 | 2015-07-28 20:37:43 +0200 | [diff] [blame] | 1108 | current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f; |
Leonid Yegoshin | b0a668f | 2014-12-03 15:47:03 +0000 | [diff] [blame] | 1109 | |
Ralf Baechle | e3b2883 | 2015-07-28 20:37:43 +0200 | [diff] [blame] | 1110 | if (notify_die(DIE_RI, "RI Fault", regs, 0, current->thread.trap_nr, |
Ralf Baechle | dc73e4c | 2013-10-09 08:54:15 +0200 | [diff] [blame] | 1111 | SIGILL) == NOTIFY_STOP) |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1112 | goto out; |
Jason Wessel | 8854700 | 2008-07-29 15:58:53 -0500 | [diff] [blame] | 1113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | die_if_kernel("Reserved instruction in kernel code", regs); |
| 1115 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 1116 | if (unlikely(compute_return_epc(regs) < 0)) |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1117 | goto out; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 1118 | |
Maciej W. Rozycki | 3d50a7f | 2016-01-30 09:08:43 +0000 | [diff] [blame] | 1119 | if (!get_isa16_mode(regs->cp0_epc)) { |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1120 | if (unlikely(get_user(opcode, epc) < 0)) |
| 1121 | status = SIGSEGV; |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 1122 | |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1123 | if (!cpu_has_llsc && status < 0) |
| 1124 | status = simulate_llsc(regs, opcode); |
| 1125 | |
| 1126 | if (status < 0) |
| 1127 | status = simulate_rdhwr_normal(regs, opcode); |
| 1128 | |
| 1129 | if (status < 0) |
| 1130 | status = simulate_sync(regs, opcode); |
Paul Burton | 4227a2d | 2014-09-11 08:30:20 +0100 | [diff] [blame] | 1131 | |
| 1132 | if (status < 0) |
| 1133 | status = simulate_fp(regs, opcode, old_epc, old31); |
Maciej W. Rozycki | 3d50a7f | 2016-01-30 09:08:43 +0000 | [diff] [blame] | 1134 | } else if (cpu_has_mmips) { |
| 1135 | unsigned short mmop[2] = { 0 }; |
| 1136 | |
| 1137 | if (unlikely(get_user(mmop[0], (u16 __user *)epc + 0) < 0)) |
| 1138 | status = SIGSEGV; |
| 1139 | if (unlikely(get_user(mmop[1], (u16 __user *)epc + 1) < 0)) |
| 1140 | status = SIGSEGV; |
| 1141 | opcode = mmop[0]; |
| 1142 | opcode = (opcode << 16) | mmop[1]; |
| 1143 | |
| 1144 | if (status < 0) |
| 1145 | status = simulate_rdhwr_mm(regs, opcode); |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1146 | } |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 1147 | |
| 1148 | if (status < 0) |
| 1149 | status = SIGILL; |
| 1150 | |
| 1151 | if (unlikely(status > 0)) { |
| 1152 | regs->cp0_epc = old_epc; /* Undo skip-over. */ |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1153 | regs->regs[31] = old31; |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 1154 | force_sig(status, current); |
| 1155 | } |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1156 | |
| 1157 | out: |
| 1158 | exception_exit(prev_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
Ralf Baechle | d223a86 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 1161 | /* |
| 1162 | * MIPS MT processors may have fewer FPU contexts than CPU threads. If we've |
| 1163 | * emulated more than some threshold number of instructions, force migration to |
| 1164 | * a "CPU" that has FP support. |
| 1165 | */ |
| 1166 | static void mt_ase_fp_affinity(void) |
| 1167 | { |
| 1168 | #ifdef CONFIG_MIPS_MT_FPAFF |
| 1169 | if (mt_fpemul_threshold > 0 && |
| 1170 | ((current->thread.emulated_fp++ > mt_fpemul_threshold))) { |
| 1171 | /* |
| 1172 | * If there's no FPU present, or if the application has already |
| 1173 | * restricted the allowed set to exclude any CPUs with FPUs, |
| 1174 | * we'll skip the procedure. |
| 1175 | */ |
Rusty Russell | 8dd9289 | 2015-03-05 10:49:17 +1030 | [diff] [blame] | 1176 | if (cpumask_intersects(¤t->cpus_allowed, &mt_fpu_cpumask)) { |
Ralf Baechle | d223a86 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 1177 | cpumask_t tmask; |
| 1178 | |
Kevin D. Kissell | 9cc1236 | 2008-09-09 21:33:36 +0200 | [diff] [blame] | 1179 | current->thread.user_cpus_allowed |
| 1180 | = current->cpus_allowed; |
Rusty Russell | 8dd9289 | 2015-03-05 10:49:17 +1030 | [diff] [blame] | 1181 | cpumask_and(&tmask, ¤t->cpus_allowed, |
| 1182 | &mt_fpu_cpumask); |
Julia Lawall | ed1bbde | 2010-03-26 23:03:07 +0100 | [diff] [blame] | 1183 | set_cpus_allowed_ptr(current, &tmask); |
Ralf Baechle | 293c5bd | 2007-07-25 16:19:33 +0100 | [diff] [blame] | 1184 | set_thread_flag(TIF_FPUBOUND); |
Ralf Baechle | d223a86 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 1185 | } |
| 1186 | } |
| 1187 | #endif /* CONFIG_MIPS_MT_FPAFF */ |
| 1188 | } |
| 1189 | |
Ralf Baechle | 69f3a7d | 2009-11-24 01:24:58 +0000 | [diff] [blame] | 1190 | /* |
| 1191 | * No lock; only written during early bootup by CPU 0. |
| 1192 | */ |
| 1193 | static RAW_NOTIFIER_HEAD(cu2_chain); |
| 1194 | |
| 1195 | int __ref register_cu2_notifier(struct notifier_block *nb) |
| 1196 | { |
| 1197 | return raw_notifier_chain_register(&cu2_chain, nb); |
| 1198 | } |
| 1199 | |
| 1200 | int cu2_notifier_call_chain(unsigned long val, void *v) |
| 1201 | { |
| 1202 | return raw_notifier_call_chain(&cu2_chain, val, v); |
| 1203 | } |
| 1204 | |
| 1205 | static int default_cu2_call(struct notifier_block *nfb, unsigned long action, |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 1206 | void *data) |
Ralf Baechle | 69f3a7d | 2009-11-24 01:24:58 +0000 | [diff] [blame] | 1207 | { |
| 1208 | struct pt_regs *regs = data; |
| 1209 | |
Jayachandran C | 83bee79 | 2013-06-10 06:30:01 +0000 | [diff] [blame] | 1210 | die_if_kernel("COP2: Unhandled kernel unaligned access or invalid " |
Ralf Baechle | 69f3a7d | 2009-11-24 01:24:58 +0000 | [diff] [blame] | 1211 | "instruction", regs); |
Jayachandran C | 83bee79 | 2013-06-10 06:30:01 +0000 | [diff] [blame] | 1212 | force_sig(SIGILL, current); |
Ralf Baechle | 69f3a7d | 2009-11-24 01:24:58 +0000 | [diff] [blame] | 1213 | |
| 1214 | return NOTIFY_OK; |
| 1215 | } |
| 1216 | |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 1217 | static int enable_restore_fp_context(int msa) |
| 1218 | { |
Paul Burton | c901775 | 2014-07-30 08:53:20 +0100 | [diff] [blame] | 1219 | int err, was_fpu_owner, prior_msa; |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 1220 | |
| 1221 | if (!used_math()) { |
| 1222 | /* First time FP context user. */ |
Paul Burton | 762a1f4 | 2014-07-11 16:44:35 +0100 | [diff] [blame] | 1223 | preempt_disable(); |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 1224 | err = init_fpu(); |
Paul Burton | c901775 | 2014-07-30 08:53:20 +0100 | [diff] [blame] | 1225 | if (msa && !err) { |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 1226 | enable_msa(); |
Maciej W. Rozycki | e49d384 | 2016-05-17 06:12:27 +0100 | [diff] [blame] | 1227 | init_msa_upper(); |
Paul Burton | 732c0c3 | 2014-07-31 14:53:16 +0100 | [diff] [blame] | 1228 | set_thread_flag(TIF_USEDMSA); |
| 1229 | set_thread_flag(TIF_MSA_CTX_LIVE); |
Paul Burton | c901775 | 2014-07-30 08:53:20 +0100 | [diff] [blame] | 1230 | } |
Paul Burton | 762a1f4 | 2014-07-11 16:44:35 +0100 | [diff] [blame] | 1231 | preempt_enable(); |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 1232 | if (!err) |
| 1233 | set_used_math(); |
| 1234 | return err; |
| 1235 | } |
| 1236 | |
| 1237 | /* |
| 1238 | * This task has formerly used the FP context. |
| 1239 | * |
| 1240 | * If this thread has no live MSA vector context then we can simply |
| 1241 | * restore the scalar FP context. If it has live MSA vector context |
| 1242 | * (that is, it has or may have used MSA since last performing a |
| 1243 | * function call) then we'll need to restore the vector context. This |
| 1244 | * applies even if we're currently only executing a scalar FP |
| 1245 | * instruction. This is because if we were to later execute an MSA |
| 1246 | * instruction then we'd either have to: |
| 1247 | * |
| 1248 | * - Restore the vector context & clobber any registers modified by |
| 1249 | * scalar FP instructions between now & then. |
| 1250 | * |
| 1251 | * or |
| 1252 | * |
| 1253 | * - Not restore the vector context & lose the most significant bits |
| 1254 | * of all vector registers. |
| 1255 | * |
| 1256 | * Neither of those options is acceptable. We cannot restore the least |
| 1257 | * significant bits of the registers now & only restore the most |
| 1258 | * significant bits later because the most significant bits of any |
| 1259 | * vector registers whose aliased FP register is modified now will have |
| 1260 | * been zeroed. We'd have no way to know that when restoring the vector |
| 1261 | * context & thus may load an outdated value for the most significant |
| 1262 | * bits of a vector register. |
| 1263 | */ |
| 1264 | if (!msa && !thread_msa_context_live()) |
| 1265 | return own_fpu(1); |
| 1266 | |
| 1267 | /* |
| 1268 | * This task is using or has previously used MSA. Thus we require |
| 1269 | * that Status.FR == 1. |
| 1270 | */ |
Paul Burton | 762a1f4 | 2014-07-11 16:44:35 +0100 | [diff] [blame] | 1271 | preempt_disable(); |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 1272 | was_fpu_owner = is_fpu_owner(); |
Paul Burton | 762a1f4 | 2014-07-11 16:44:35 +0100 | [diff] [blame] | 1273 | err = own_fpu_inatomic(0); |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 1274 | if (err) |
Paul Burton | 762a1f4 | 2014-07-11 16:44:35 +0100 | [diff] [blame] | 1275 | goto out; |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 1276 | |
| 1277 | enable_msa(); |
| 1278 | write_msa_csr(current->thread.fpu.msacsr); |
| 1279 | set_thread_flag(TIF_USEDMSA); |
| 1280 | |
| 1281 | /* |
| 1282 | * If this is the first time that the task is using MSA and it has |
| 1283 | * previously used scalar FP in this time slice then we already nave |
Paul Burton | c901775 | 2014-07-30 08:53:20 +0100 | [diff] [blame] | 1284 | * FP context which we shouldn't clobber. We do however need to clear |
| 1285 | * the upper 64b of each vector register so that this task has no |
| 1286 | * opportunity to see data left behind by another. |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 1287 | */ |
Paul Burton | c901775 | 2014-07-30 08:53:20 +0100 | [diff] [blame] | 1288 | prior_msa = test_and_set_thread_flag(TIF_MSA_CTX_LIVE); |
| 1289 | if (!prior_msa && was_fpu_owner) { |
Maciej W. Rozycki | e49d384 | 2016-05-17 06:12:27 +0100 | [diff] [blame] | 1290 | init_msa_upper(); |
Paul Burton | 762a1f4 | 2014-07-11 16:44:35 +0100 | [diff] [blame] | 1291 | |
| 1292 | goto out; |
Paul Burton | c901775 | 2014-07-30 08:53:20 +0100 | [diff] [blame] | 1293 | } |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 1294 | |
Paul Burton | c901775 | 2014-07-30 08:53:20 +0100 | [diff] [blame] | 1295 | if (!prior_msa) { |
| 1296 | /* |
| 1297 | * Restore the least significant 64b of each vector register |
| 1298 | * from the existing scalar FP context. |
| 1299 | */ |
| 1300 | _restore_fp(current); |
Paul Burton | b834067 | 2014-07-11 16:44:29 +0100 | [diff] [blame] | 1301 | |
Paul Burton | c901775 | 2014-07-30 08:53:20 +0100 | [diff] [blame] | 1302 | /* |
| 1303 | * The task has not formerly used MSA, so clear the upper 64b |
| 1304 | * of each vector register such that it cannot see data left |
| 1305 | * behind by another task. |
| 1306 | */ |
Maciej W. Rozycki | e49d384 | 2016-05-17 06:12:27 +0100 | [diff] [blame] | 1307 | init_msa_upper(); |
Paul Burton | c901775 | 2014-07-30 08:53:20 +0100 | [diff] [blame] | 1308 | } else { |
| 1309 | /* We need to restore the vector context. */ |
| 1310 | restore_msa(current); |
Paul Burton | b834067 | 2014-07-11 16:44:29 +0100 | [diff] [blame] | 1311 | |
Paul Burton | c901775 | 2014-07-30 08:53:20 +0100 | [diff] [blame] | 1312 | /* Restore the scalar FP control & status register */ |
| 1313 | if (!was_fpu_owner) |
James Hogan | d76e9b9 | 2015-01-30 15:40:20 +0000 | [diff] [blame] | 1314 | write_32bit_cp1_register(CP1_STATUS, |
| 1315 | current->thread.fpu.fcr31); |
Paul Burton | c901775 | 2014-07-30 08:53:20 +0100 | [diff] [blame] | 1316 | } |
Paul Burton | 762a1f4 | 2014-07-11 16:44:35 +0100 | [diff] [blame] | 1317 | |
| 1318 | out: |
| 1319 | preempt_enable(); |
| 1320 | |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 1321 | return 0; |
| 1322 | } |
| 1323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | asmlinkage void do_cpu(struct pt_regs *regs) |
| 1325 | { |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1326 | enum ctx_state prev_state; |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 1327 | unsigned int __user *epc; |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1328 | unsigned long old_epc, old31; |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 1329 | void __user *fault_addr; |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 1330 | unsigned int opcode; |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 1331 | unsigned long fcr31; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | unsigned int cpid; |
Paul Burton | 597ce17 | 2013-11-22 13:12:07 +0000 | [diff] [blame] | 1333 | int status, err; |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 1334 | int sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1336 | prev_state = exception_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | cpid = (regs->cp0_cause >> CAUSEB_CE) & 3; |
| 1338 | |
Jayachandran C | 83bee79 | 2013-06-10 06:30:01 +0000 | [diff] [blame] | 1339 | if (cpid != 2) |
| 1340 | die_if_kernel("do_cpu invoked from kernel context!", regs); |
| 1341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | switch (cpid) { |
| 1343 | case 0: |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 1344 | epc = (unsigned int __user *)exception_epc(regs); |
| 1345 | old_epc = regs->cp0_epc; |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1346 | old31 = regs->regs[31]; |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 1347 | opcode = 0; |
| 1348 | status = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 1350 | if (unlikely(compute_return_epc(regs) < 0)) |
Maciej W. Rozycki | 27e28e8 | 2015-04-03 23:25:08 +0100 | [diff] [blame] | 1351 | break; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 1352 | |
Maciej W. Rozycki | 10f6d99f | 2016-01-30 09:08:16 +0000 | [diff] [blame] | 1353 | if (!get_isa16_mode(regs->cp0_epc)) { |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1354 | if (unlikely(get_user(opcode, epc) < 0)) |
| 1355 | status = SIGSEGV; |
| 1356 | |
| 1357 | if (!cpu_has_llsc && status < 0) |
| 1358 | status = simulate_llsc(regs, opcode); |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1359 | } |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 1360 | |
| 1361 | if (status < 0) |
| 1362 | status = SIGILL; |
| 1363 | |
| 1364 | if (unlikely(status > 0)) { |
| 1365 | regs->cp0_epc = old_epc; /* Undo skip-over. */ |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1366 | regs->regs[31] = old31; |
Maciej W. Rozycki | 60b0d65 | 2007-10-16 18:43:26 +0100 | [diff] [blame] | 1367 | force_sig(status, current); |
| 1368 | } |
| 1369 | |
Maciej W. Rozycki | 27e28e8 | 2015-04-03 23:25:08 +0100 | [diff] [blame] | 1370 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | |
Maciej W. Rozycki | 051ff44 | 2012-03-06 20:28:54 +0000 | [diff] [blame] | 1372 | case 3: |
| 1373 | /* |
Maciej W. Rozycki | 2d83fea | 2015-04-03 23:26:49 +0100 | [diff] [blame] | 1374 | * The COP3 opcode space and consequently the CP0.Status.CU3 |
| 1375 | * bit and the CP0.Cause.CE=3 encoding have been removed as |
| 1376 | * of the MIPS III ISA. From the MIPS IV and MIPS32r2 ISAs |
| 1377 | * up the space has been reused for COP1X instructions, that |
| 1378 | * are enabled by the CP0.Status.CU1 bit and consequently |
| 1379 | * use the CP0.Cause.CE=1 encoding for Coprocessor Unusable |
| 1380 | * exceptions. Some FPU-less processors that implement one |
| 1381 | * of these ISAs however use this code erroneously for COP1X |
| 1382 | * instructions. Therefore we redirect this trap to the FP |
| 1383 | * emulator too. |
Maciej W. Rozycki | 051ff44 | 2012-03-06 20:28:54 +0000 | [diff] [blame] | 1384 | */ |
Maciej W. Rozycki | 2d83fea | 2015-04-03 23:26:49 +0100 | [diff] [blame] | 1385 | if (raw_cpu_has_fpu || !cpu_has_mips_4_5_64_r2_r6) { |
Maciej W. Rozycki | 27e28e8 | 2015-04-03 23:25:08 +0100 | [diff] [blame] | 1386 | force_sig(SIGILL, current); |
Maciej W. Rozycki | 051ff44 | 2012-03-06 20:28:54 +0000 | [diff] [blame] | 1387 | break; |
Maciej W. Rozycki | 27e28e8 | 2015-04-03 23:25:08 +0100 | [diff] [blame] | 1388 | } |
Maciej W. Rozycki | 051ff44 | 2012-03-06 20:28:54 +0000 | [diff] [blame] | 1389 | /* Fall through. */ |
| 1390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | case 1: |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 1392 | err = enable_restore_fp_context(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 1394 | if (raw_cpu_has_fpu && !err) |
| 1395 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 1397 | sig = fpu_emulator_cop1Handler(regs, ¤t->thread.fpu, 0, |
| 1398 | &fault_addr); |
Maciej W. Rozycki | 443c440 | 2015-04-03 23:27:10 +0100 | [diff] [blame] | 1399 | |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 1400 | /* |
| 1401 | * We can't allow the emulated instruction to leave |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 1402 | * any enabled Cause bits set in $fcr31. |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 1403 | */ |
Maciej W. Rozycki | 5a1aca4 | 2016-10-28 08:21:03 +0100 | [diff] [blame] | 1404 | fcr31 = mask_fcr31_x(current->thread.fpu.fcr31); |
| 1405 | current->thread.fpu.fcr31 &= ~fcr31; |
Maciej W. Rozycki | 304acb7 | 2015-04-03 23:27:15 +0100 | [diff] [blame] | 1406 | |
| 1407 | /* Send a signal if required. */ |
| 1408 | if (!process_fpemu_return(sig, fault_addr, fcr31) && !err) |
| 1409 | mt_ase_fp_affinity(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | |
Maciej W. Rozycki | 27e28e8 | 2015-04-03 23:25:08 +0100 | [diff] [blame] | 1411 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | |
| 1413 | case 2: |
Ralf Baechle | 69f3a7d | 2009-11-24 01:24:58 +0000 | [diff] [blame] | 1414 | raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs); |
Maciej W. Rozycki | 27e28e8 | 2015-04-03 23:25:08 +0100 | [diff] [blame] | 1415 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1418 | exception_exit(prev_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
James Hogan | 64bedff | 2014-12-02 13:44:13 +0000 | [diff] [blame] | 1421 | asmlinkage void do_msa_fpe(struct pt_regs *regs, unsigned int msacsr) |
Paul Burton | 2bcb3fb | 2014-01-27 15:23:12 +0000 | [diff] [blame] | 1422 | { |
| 1423 | enum ctx_state prev_state; |
| 1424 | |
| 1425 | prev_state = exception_enter(); |
Ralf Baechle | e3b2883 | 2015-07-28 20:37:43 +0200 | [diff] [blame] | 1426 | current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f; |
James Hogan | 64bedff | 2014-12-02 13:44:13 +0000 | [diff] [blame] | 1427 | if (notify_die(DIE_MSAFP, "MSA FP exception", regs, 0, |
Ralf Baechle | e3b2883 | 2015-07-28 20:37:43 +0200 | [diff] [blame] | 1428 | current->thread.trap_nr, SIGFPE) == NOTIFY_STOP) |
James Hogan | 64bedff | 2014-12-02 13:44:13 +0000 | [diff] [blame] | 1429 | goto out; |
| 1430 | |
| 1431 | /* Clear MSACSR.Cause before enabling interrupts */ |
| 1432 | write_msa_csr(msacsr & ~MSA_CSR_CAUSEF); |
| 1433 | local_irq_enable(); |
| 1434 | |
Paul Burton | 2bcb3fb | 2014-01-27 15:23:12 +0000 | [diff] [blame] | 1435 | die_if_kernel("do_msa_fpe invoked from kernel context!", regs); |
| 1436 | force_sig(SIGFPE, current); |
James Hogan | 64bedff | 2014-12-02 13:44:13 +0000 | [diff] [blame] | 1437 | out: |
Paul Burton | 2bcb3fb | 2014-01-27 15:23:12 +0000 | [diff] [blame] | 1438 | exception_exit(prev_state); |
| 1439 | } |
| 1440 | |
Paul Burton | 1db1af8 | 2014-01-27 15:23:11 +0000 | [diff] [blame] | 1441 | asmlinkage void do_msa(struct pt_regs *regs) |
| 1442 | { |
| 1443 | enum ctx_state prev_state; |
| 1444 | int err; |
| 1445 | |
| 1446 | prev_state = exception_enter(); |
| 1447 | |
| 1448 | if (!cpu_has_msa || test_thread_flag(TIF_32BIT_FPREGS)) { |
| 1449 | force_sig(SIGILL, current); |
| 1450 | goto out; |
| 1451 | } |
| 1452 | |
| 1453 | die_if_kernel("do_msa invoked from kernel context!", regs); |
| 1454 | |
| 1455 | err = enable_restore_fp_context(1); |
| 1456 | if (err) |
| 1457 | force_sig(SIGILL, current); |
| 1458 | out: |
| 1459 | exception_exit(prev_state); |
| 1460 | } |
| 1461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | asmlinkage void do_mdmx(struct pt_regs *regs) |
| 1463 | { |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1464 | enum ctx_state prev_state; |
| 1465 | |
| 1466 | prev_state = exception_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | force_sig(SIGILL, current); |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1468 | exception_exit(prev_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
David Daney | 8bc6d05 | 2009-01-05 15:29:58 -0800 | [diff] [blame] | 1471 | /* |
| 1472 | * Called with interrupts disabled. |
| 1473 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | asmlinkage void do_watch(struct pt_regs *regs) |
| 1475 | { |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1476 | enum ctx_state prev_state; |
David Daney | b67b2b7 | 2008-09-23 00:08:45 -0700 | [diff] [blame] | 1477 | |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1478 | prev_state = exception_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | /* |
David Daney | b67b2b7 | 2008-09-23 00:08:45 -0700 | [diff] [blame] | 1480 | * Clear WP (bit 22) bit of cause register so we don't loop |
| 1481 | * forever. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | */ |
James Hogan | e233c73 | 2016-03-01 22:19:38 +0000 | [diff] [blame] | 1483 | clear_c0_cause(CAUSEF_WP); |
David Daney | b67b2b7 | 2008-09-23 00:08:45 -0700 | [diff] [blame] | 1484 | |
| 1485 | /* |
| 1486 | * If the current thread has the watch registers loaded, save |
| 1487 | * their values and send SIGTRAP. Otherwise another thread |
| 1488 | * left the registers set, clear them and continue. |
| 1489 | */ |
| 1490 | if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) { |
| 1491 | mips_read_watch_registers(); |
David Daney | 8bc6d05 | 2009-01-05 15:29:58 -0800 | [diff] [blame] | 1492 | local_irq_enable(); |
Eric W. Biederman | f43a54a | 2018-04-15 21:11:06 -0500 | [diff] [blame] | 1493 | force_sig_fault(SIGTRAP, TRAP_HWBKPT, NULL, current); |
David Daney | 8bc6d05 | 2009-01-05 15:29:58 -0800 | [diff] [blame] | 1494 | } else { |
David Daney | b67b2b7 | 2008-09-23 00:08:45 -0700 | [diff] [blame] | 1495 | mips_clear_watch_registers(); |
David Daney | 8bc6d05 | 2009-01-05 15:29:58 -0800 | [diff] [blame] | 1496 | local_irq_enable(); |
| 1497 | } |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1498 | exception_exit(prev_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | asmlinkage void do_mcheck(struct pt_regs *regs) |
| 1502 | { |
Ralf Baechle | cac4bcb | 2006-05-24 16:51:02 +0100 | [diff] [blame] | 1503 | int multi_match = regs->cp0_status & ST0_TS; |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1504 | enum ctx_state prev_state; |
James Hogan | 55c723e | 2015-07-27 13:50:21 +0100 | [diff] [blame] | 1505 | mm_segment_t old_fs = get_fs(); |
Ralf Baechle | cac4bcb | 2006-05-24 16:51:02 +0100 | [diff] [blame] | 1506 | |
Ralf Baechle | c3fc5cd | 2013-05-29 01:07:19 +0200 | [diff] [blame] | 1507 | prev_state = exception_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | show_regs(regs); |
Ralf Baechle | cac4bcb | 2006-05-24 16:51:02 +0100 | [diff] [blame] | 1509 | |
| 1510 | if (multi_match) { |
James Hogan | 3c865dd | 2015-07-15 16:17:43 +0100 | [diff] [blame] | 1511 | dump_tlb_regs(); |
| 1512 | pr_info("\n"); |
Ralf Baechle | cac4bcb | 2006-05-24 16:51:02 +0100 | [diff] [blame] | 1513 | dump_tlb_all(); |
| 1514 | } |
| 1515 | |
James Hogan | 55c723e | 2015-07-27 13:50:21 +0100 | [diff] [blame] | 1516 | if (!user_mode(regs)) |
| 1517 | set_fs(KERNEL_DS); |
| 1518 | |
Atsushi Nemoto | e1bb8289 | 2007-07-13 23:51:46 +0900 | [diff] [blame] | 1519 | show_code((unsigned int __user *) regs->cp0_epc); |
Ralf Baechle | cac4bcb | 2006-05-24 16:51:02 +0100 | [diff] [blame] | 1520 | |
James Hogan | 55c723e | 2015-07-27 13:50:21 +0100 | [diff] [blame] | 1521 | set_fs(old_fs); |
| 1522 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | /* |
| 1524 | * Some chips may have other causes of machine check (e.g. SB1 |
| 1525 | * graduation timer) |
| 1526 | */ |
| 1527 | panic("Caught Machine Check exception - %scaused by multiple " |
| 1528 | "matching entries in the TLB.", |
Ralf Baechle | cac4bcb | 2006-05-24 16:51:02 +0100 | [diff] [blame] | 1529 | (multi_match) ? "" : "not "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Ralf Baechle | 340ee4b | 2005-08-17 17:44:08 +0000 | [diff] [blame] | 1532 | asmlinkage void do_mt(struct pt_regs *regs) |
| 1533 | { |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1534 | int subcode; |
| 1535 | |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1536 | subcode = (read_vpe_c0_vpecontrol() & VPECONTROL_EXCPT) |
| 1537 | >> VPECONTROL_EXCPT_SHIFT; |
| 1538 | switch (subcode) { |
| 1539 | case 0: |
Chris Dearman | e35a5e3 | 2006-06-30 14:19:45 +0100 | [diff] [blame] | 1540 | printk(KERN_DEBUG "Thread Underflow\n"); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1541 | break; |
| 1542 | case 1: |
Chris Dearman | e35a5e3 | 2006-06-30 14:19:45 +0100 | [diff] [blame] | 1543 | printk(KERN_DEBUG "Thread Overflow\n"); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1544 | break; |
| 1545 | case 2: |
Chris Dearman | e35a5e3 | 2006-06-30 14:19:45 +0100 | [diff] [blame] | 1546 | printk(KERN_DEBUG "Invalid YIELD Qualifier\n"); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1547 | break; |
| 1548 | case 3: |
Chris Dearman | e35a5e3 | 2006-06-30 14:19:45 +0100 | [diff] [blame] | 1549 | printk(KERN_DEBUG "Gating Storage Exception\n"); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1550 | break; |
| 1551 | case 4: |
Chris Dearman | e35a5e3 | 2006-06-30 14:19:45 +0100 | [diff] [blame] | 1552 | printk(KERN_DEBUG "YIELD Scheduler Exception\n"); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1553 | break; |
| 1554 | case 5: |
Masanari Iida | f232c7e | 2012-02-08 21:53:14 +0900 | [diff] [blame] | 1555 | printk(KERN_DEBUG "Gating Storage Scheduler Exception\n"); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1556 | break; |
| 1557 | default: |
Chris Dearman | e35a5e3 | 2006-06-30 14:19:45 +0100 | [diff] [blame] | 1558 | printk(KERN_DEBUG "*** UNKNOWN THREAD EXCEPTION %d ***\n", |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1559 | subcode); |
| 1560 | break; |
| 1561 | } |
Ralf Baechle | 340ee4b | 2005-08-17 17:44:08 +0000 | [diff] [blame] | 1562 | die_if_kernel("MIPS MT Thread exception in kernel", regs); |
| 1563 | |
| 1564 | force_sig(SIGILL, current); |
| 1565 | } |
| 1566 | |
| 1567 | |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 1568 | asmlinkage void do_dsp(struct pt_regs *regs) |
| 1569 | { |
| 1570 | if (cpu_has_dsp) |
Ralf Baechle | ab75dc0 | 2011-11-17 15:07:31 +0000 | [diff] [blame] | 1571 | panic("Unexpected DSP exception"); |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 1572 | |
| 1573 | force_sig(SIGILL, current); |
| 1574 | } |
| 1575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | asmlinkage void do_reserved(struct pt_regs *regs) |
| 1577 | { |
| 1578 | /* |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 1579 | * Game over - no way to handle this if it ever occurs. Most probably |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | * caused by a new unknown cpu type or after another deadly |
| 1581 | * hard/software error. |
| 1582 | */ |
| 1583 | show_regs(regs); |
| 1584 | panic("Caught reserved exception %ld - should not happen.", |
| 1585 | (regs->cp0_cause & 0x7f) >> 2); |
| 1586 | } |
| 1587 | |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 1588 | static int __initdata l1parity = 1; |
| 1589 | static int __init nol1parity(char *s) |
| 1590 | { |
| 1591 | l1parity = 0; |
| 1592 | return 1; |
| 1593 | } |
| 1594 | __setup("nol1par", nol1parity); |
| 1595 | static int __initdata l2parity = 1; |
| 1596 | static int __init nol2parity(char *s) |
| 1597 | { |
| 1598 | l2parity = 0; |
| 1599 | return 1; |
| 1600 | } |
| 1601 | __setup("nol2par", nol2parity); |
| 1602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | /* |
| 1604 | * Some MIPS CPUs can enable/disable for cache parity detection, but do |
| 1605 | * it different ways. |
| 1606 | */ |
| 1607 | static inline void parity_protection_init(void) |
| 1608 | { |
Paul Burton | 35e6de3 | 2016-10-17 16:01:07 +0100 | [diff] [blame] | 1609 | #define ERRCTL_PE 0x80000000 |
| 1610 | #define ERRCTL_L2P 0x00800000 |
| 1611 | |
| 1612 | if (mips_cm_revision() >= CM_REV_CM3) { |
| 1613 | ulong gcr_ectl, cp0_ectl; |
| 1614 | |
| 1615 | /* |
| 1616 | * With CM3 systems we need to ensure that the L1 & L2 |
| 1617 | * parity enables are set to the same value, since this |
| 1618 | * is presumed by the hardware engineers. |
| 1619 | * |
| 1620 | * If the user disabled either of L1 or L2 ECC checking, |
| 1621 | * disable both. |
| 1622 | */ |
| 1623 | l1parity &= l2parity; |
| 1624 | l2parity &= l1parity; |
| 1625 | |
| 1626 | /* Probe L1 ECC support */ |
| 1627 | cp0_ectl = read_c0_ecc(); |
| 1628 | write_c0_ecc(cp0_ectl | ERRCTL_PE); |
| 1629 | back_to_back_c0_hazard(); |
| 1630 | cp0_ectl = read_c0_ecc(); |
| 1631 | |
| 1632 | /* Probe L2 ECC support */ |
| 1633 | gcr_ectl = read_gcr_err_control(); |
| 1634 | |
Paul Burton | 93c5bba5 | 2017-08-12 19:49:27 -0700 | [diff] [blame] | 1635 | if (!(gcr_ectl & CM_GCR_ERR_CONTROL_L2_ECC_SUPPORT) || |
Paul Burton | 35e6de3 | 2016-10-17 16:01:07 +0100 | [diff] [blame] | 1636 | !(cp0_ectl & ERRCTL_PE)) { |
| 1637 | /* |
| 1638 | * One of L1 or L2 ECC checking isn't supported, |
| 1639 | * so we cannot enable either. |
| 1640 | */ |
| 1641 | l1parity = l2parity = 0; |
| 1642 | } |
| 1643 | |
| 1644 | /* Configure L1 ECC checking */ |
| 1645 | if (l1parity) |
| 1646 | cp0_ectl |= ERRCTL_PE; |
| 1647 | else |
| 1648 | cp0_ectl &= ~ERRCTL_PE; |
| 1649 | write_c0_ecc(cp0_ectl); |
| 1650 | back_to_back_c0_hazard(); |
| 1651 | WARN_ON(!!(read_c0_ecc() & ERRCTL_PE) != l1parity); |
| 1652 | |
| 1653 | /* Configure L2 ECC checking */ |
| 1654 | if (l2parity) |
Paul Burton | 93c5bba5 | 2017-08-12 19:49:27 -0700 | [diff] [blame] | 1655 | gcr_ectl |= CM_GCR_ERR_CONTROL_L2_ECC_EN; |
Paul Burton | 35e6de3 | 2016-10-17 16:01:07 +0100 | [diff] [blame] | 1656 | else |
Paul Burton | 93c5bba5 | 2017-08-12 19:49:27 -0700 | [diff] [blame] | 1657 | gcr_ectl &= ~CM_GCR_ERR_CONTROL_L2_ECC_EN; |
Paul Burton | 35e6de3 | 2016-10-17 16:01:07 +0100 | [diff] [blame] | 1658 | write_gcr_err_control(gcr_ectl); |
| 1659 | gcr_ectl = read_gcr_err_control(); |
Paul Burton | 93c5bba5 | 2017-08-12 19:49:27 -0700 | [diff] [blame] | 1660 | gcr_ectl &= CM_GCR_ERR_CONTROL_L2_ECC_EN; |
Paul Burton | 35e6de3 | 2016-10-17 16:01:07 +0100 | [diff] [blame] | 1661 | WARN_ON(!!gcr_ectl != l2parity); |
| 1662 | |
| 1663 | pr_info("Cache parity protection %sabled\n", |
| 1664 | l1parity ? "en" : "dis"); |
| 1665 | return; |
| 1666 | } |
| 1667 | |
Ralf Baechle | 10cc352 | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1668 | switch (current_cpu_type()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | case CPU_24K: |
Nigel Stephens | 98a41de | 2006-04-27 15:50:32 +0100 | [diff] [blame] | 1670 | case CPU_34K: |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 1671 | case CPU_74K: |
| 1672 | case CPU_1004K: |
Steven J. Hill | 442e14a | 2014-01-17 15:03:50 -0600 | [diff] [blame] | 1673 | case CPU_1074K: |
Leonid Yegoshin | 26ab96d | 2013-11-27 10:07:53 +0000 | [diff] [blame] | 1674 | case CPU_INTERAPTIV: |
Leonid Yegoshin | 708ac4b | 2013-11-14 16:12:27 +0000 | [diff] [blame] | 1675 | case CPU_PROAPTIV: |
James Hogan | aced4cb | 2014-01-22 16:19:38 +0000 | [diff] [blame] | 1676 | case CPU_P5600: |
Leonid Yegoshin | 4695089 | 2014-11-24 12:59:01 +0000 | [diff] [blame] | 1677 | case CPU_QEMU_GENERIC: |
Paul Burton | 1091bfa | 2016-02-03 03:26:38 +0000 | [diff] [blame] | 1678 | case CPU_P6600: |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 1679 | { |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 1680 | unsigned long errctl; |
| 1681 | unsigned int l1parity_present, l2parity_present; |
| 1682 | |
| 1683 | errctl = read_c0_ecc(); |
| 1684 | errctl &= ~(ERRCTL_PE|ERRCTL_L2P); |
| 1685 | |
| 1686 | /* probe L1 parity support */ |
| 1687 | write_c0_ecc(errctl | ERRCTL_PE); |
| 1688 | back_to_back_c0_hazard(); |
| 1689 | l1parity_present = (read_c0_ecc() & ERRCTL_PE); |
| 1690 | |
| 1691 | /* probe L2 parity support */ |
| 1692 | write_c0_ecc(errctl|ERRCTL_L2P); |
| 1693 | back_to_back_c0_hazard(); |
| 1694 | l2parity_present = (read_c0_ecc() & ERRCTL_L2P); |
| 1695 | |
| 1696 | if (l1parity_present && l2parity_present) { |
| 1697 | if (l1parity) |
| 1698 | errctl |= ERRCTL_PE; |
| 1699 | if (l1parity ^ l2parity) |
| 1700 | errctl |= ERRCTL_L2P; |
| 1701 | } else if (l1parity_present) { |
| 1702 | if (l1parity) |
| 1703 | errctl |= ERRCTL_PE; |
| 1704 | } else if (l2parity_present) { |
| 1705 | if (l2parity) |
| 1706 | errctl |= ERRCTL_L2P; |
| 1707 | } else { |
| 1708 | /* No parity available */ |
| 1709 | } |
| 1710 | |
| 1711 | printk(KERN_INFO "Writing ErrCtl register=%08lx\n", errctl); |
| 1712 | |
| 1713 | write_c0_ecc(errctl); |
| 1714 | back_to_back_c0_hazard(); |
| 1715 | errctl = read_c0_ecc(); |
| 1716 | printk(KERN_INFO "Readback ErrCtl register=%08lx\n", errctl); |
| 1717 | |
| 1718 | if (l1parity_present) |
| 1719 | printk(KERN_INFO "Cache parity protection %sabled\n", |
| 1720 | (errctl & ERRCTL_PE) ? "en" : "dis"); |
| 1721 | |
| 1722 | if (l2parity_present) { |
| 1723 | if (l1parity_present && l1parity) |
| 1724 | errctl ^= ERRCTL_L2P; |
| 1725 | printk(KERN_INFO "L2 cache parity protection %sabled\n", |
| 1726 | (errctl & ERRCTL_L2P) ? "en" : "dis"); |
| 1727 | } |
| 1728 | } |
| 1729 | break; |
| 1730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | case CPU_5KC: |
Leonid Yegoshin | 78d4803 | 2012-07-06 21:56:01 +0200 | [diff] [blame] | 1732 | case CPU_5KE: |
Kelvin Cheung | 2fa3639 | 2012-06-20 20:05:32 +0100 | [diff] [blame] | 1733 | case CPU_LOONGSON1: |
Ralf Baechle | 14f18b7 | 2005-03-01 18:15:08 +0000 | [diff] [blame] | 1734 | write_c0_ecc(0x80000000); |
| 1735 | back_to_back_c0_hazard(); |
| 1736 | /* Set the PE bit (bit 31) in the c0_errctl register. */ |
| 1737 | printk(KERN_INFO "Cache parity protection %sabled\n", |
| 1738 | (read_c0_ecc() & 0x80000000) ? "en" : "dis"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | break; |
| 1740 | case CPU_20KC: |
| 1741 | case CPU_25KF: |
| 1742 | /* Clear the DE bit (bit 16) in the c0_status register. */ |
| 1743 | printk(KERN_INFO "Enable cache parity protection for " |
| 1744 | "MIPS 20KC/25KF CPUs.\n"); |
| 1745 | clear_c0_status(ST0_DE); |
| 1746 | break; |
| 1747 | default: |
| 1748 | break; |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | asmlinkage void cache_parity_error(void) |
| 1753 | { |
| 1754 | const int field = 2 * sizeof(unsigned long); |
| 1755 | unsigned int reg_val; |
| 1756 | |
| 1757 | /* For the moment, report the problem and hang. */ |
| 1758 | printk("Cache error exception:\n"); |
| 1759 | printk("cp0_errorepc == %0*lx\n", field, read_c0_errorepc()); |
| 1760 | reg_val = read_c0_cacheerr(); |
| 1761 | printk("c0_cacheerr == %08x\n", reg_val); |
| 1762 | |
| 1763 | printk("Decoded c0_cacheerr: %s cache fault in %s reference.\n", |
| 1764 | reg_val & (1<<30) ? "secondary" : "primary", |
| 1765 | reg_val & (1<<31) ? "data" : "insn"); |
Leonid Yegoshin | 9c7d576 | 2014-11-14 11:25:30 +0000 | [diff] [blame] | 1766 | if ((cpu_has_mips_r2_r6) && |
Markos Chandras | 721a920 | 2014-05-21 12:35:00 +0100 | [diff] [blame] | 1767 | ((current_cpu_data.processor_id & 0xff0000) == PRID_COMP_MIPS)) { |
Leonid Yegoshin | 6de2045 | 2013-10-10 09:58:59 +0100 | [diff] [blame] | 1768 | pr_err("Error bits: %s%s%s%s%s%s%s%s\n", |
| 1769 | reg_val & (1<<29) ? "ED " : "", |
| 1770 | reg_val & (1<<28) ? "ET " : "", |
| 1771 | reg_val & (1<<27) ? "ES " : "", |
| 1772 | reg_val & (1<<26) ? "EE " : "", |
| 1773 | reg_val & (1<<25) ? "EB " : "", |
| 1774 | reg_val & (1<<24) ? "EI " : "", |
| 1775 | reg_val & (1<<23) ? "E1 " : "", |
| 1776 | reg_val & (1<<22) ? "E0 " : ""); |
| 1777 | } else { |
| 1778 | pr_err("Error bits: %s%s%s%s%s%s%s\n", |
| 1779 | reg_val & (1<<29) ? "ED " : "", |
| 1780 | reg_val & (1<<28) ? "ET " : "", |
| 1781 | reg_val & (1<<26) ? "EE " : "", |
| 1782 | reg_val & (1<<25) ? "EB " : "", |
| 1783 | reg_val & (1<<24) ? "EI " : "", |
| 1784 | reg_val & (1<<23) ? "E1 " : "", |
| 1785 | reg_val & (1<<22) ? "E0 " : ""); |
| 1786 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | printk("IDX: 0x%08x\n", reg_val & ((1<<22)-1)); |
| 1788 | |
Ralf Baechle | ec917c2c | 2005-10-07 16:58:15 +0100 | [diff] [blame] | 1789 | #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | if (reg_val & (1<<22)) |
| 1791 | printk("DErrAddr0: 0x%0*lx\n", field, read_c0_derraddr0()); |
| 1792 | |
| 1793 | if (reg_val & (1<<23)) |
| 1794 | printk("DErrAddr1: 0x%0*lx\n", field, read_c0_derraddr1()); |
| 1795 | #endif |
| 1796 | |
| 1797 | panic("Can't handle the cache error!"); |
| 1798 | } |
| 1799 | |
Leonid Yegoshin | 75b5b5e | 2013-11-14 16:12:31 +0000 | [diff] [blame] | 1800 | asmlinkage void do_ftlb(void) |
| 1801 | { |
| 1802 | const int field = 2 * sizeof(unsigned long); |
| 1803 | unsigned int reg_val; |
| 1804 | |
| 1805 | /* For the moment, report the problem and hang. */ |
Leonid Yegoshin | 9c7d576 | 2014-11-14 11:25:30 +0000 | [diff] [blame] | 1806 | if ((cpu_has_mips_r2_r6) && |
Huacai Chen | b2edcfc | 2016-03-03 09:45:09 +0800 | [diff] [blame] | 1807 | (((current_cpu_data.processor_id & 0xff0000) == PRID_COMP_MIPS) || |
| 1808 | ((current_cpu_data.processor_id & 0xff0000) == PRID_COMP_LOONGSON))) { |
Leonid Yegoshin | 75b5b5e | 2013-11-14 16:12:31 +0000 | [diff] [blame] | 1809 | pr_err("FTLB error exception, cp0_ecc=0x%08x:\n", |
| 1810 | read_c0_ecc()); |
| 1811 | pr_err("cp0_errorepc == %0*lx\n", field, read_c0_errorepc()); |
| 1812 | reg_val = read_c0_cacheerr(); |
| 1813 | pr_err("c0_cacheerr == %08x\n", reg_val); |
| 1814 | |
| 1815 | if ((reg_val & 0xc0000000) == 0xc0000000) { |
| 1816 | pr_err("Decoded c0_cacheerr: FTLB parity error\n"); |
| 1817 | } else { |
| 1818 | pr_err("Decoded c0_cacheerr: %s cache fault in %s reference.\n", |
| 1819 | reg_val & (1<<30) ? "secondary" : "primary", |
| 1820 | reg_val & (1<<31) ? "data" : "insn"); |
| 1821 | } |
| 1822 | } else { |
| 1823 | pr_err("FTLB error exception\n"); |
| 1824 | } |
| 1825 | /* Just print the cacheerr bits for now */ |
| 1826 | cache_parity_error(); |
| 1827 | } |
| 1828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | /* |
| 1830 | * SDBBP EJTAG debug exception handler. |
| 1831 | * We skip the instruction and return to the next instruction. |
| 1832 | */ |
| 1833 | void ejtag_exception_handler(struct pt_regs *regs) |
| 1834 | { |
| 1835 | const int field = 2 * sizeof(unsigned long); |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1836 | unsigned long depc, old_epc, old_ra; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | unsigned int debug; |
| 1838 | |
Chris Dearman | 70ae612 | 2006-06-30 12:32:37 +0100 | [diff] [blame] | 1839 | printk(KERN_DEBUG "SDBBP EJTAG debug exception - not handled yet, just ignored!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | depc = read_c0_depc(); |
| 1841 | debug = read_c0_debug(); |
Chris Dearman | 70ae612 | 2006-06-30 12:32:37 +0100 | [diff] [blame] | 1842 | printk(KERN_DEBUG "c0_depc = %0*lx, DEBUG = %08x\n", field, depc, debug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | if (debug & 0x80000000) { |
| 1844 | /* |
| 1845 | * In branch delay slot. |
| 1846 | * We cheat a little bit here and use EPC to calculate the |
| 1847 | * debug return address (DEPC). EPC is restored after the |
| 1848 | * calculation. |
| 1849 | */ |
| 1850 | old_epc = regs->cp0_epc; |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1851 | old_ra = regs->regs[31]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | regs->cp0_epc = depc; |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1853 | compute_return_epc(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | depc = regs->cp0_epc; |
| 1855 | regs->cp0_epc = old_epc; |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1856 | regs->regs[31] = old_ra; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | } else |
| 1858 | depc += 4; |
| 1859 | write_c0_depc(depc); |
| 1860 | |
| 1861 | #if 0 |
Chris Dearman | 70ae612 | 2006-06-30 12:32:37 +0100 | [diff] [blame] | 1862 | printk(KERN_DEBUG "\n\n----- Enable EJTAG single stepping ----\n\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | write_c0_debug(debug | 0x100); |
| 1864 | #endif |
| 1865 | } |
| 1866 | |
| 1867 | /* |
| 1868 | * NMI exception handler. |
Kevin Cernekee | 34bd92e | 2011-11-16 01:25:44 +0000 | [diff] [blame] | 1869 | * No lock; only written during early bootup by CPU 0. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | */ |
Kevin Cernekee | 34bd92e | 2011-11-16 01:25:44 +0000 | [diff] [blame] | 1871 | static RAW_NOTIFIER_HEAD(nmi_chain); |
| 1872 | |
| 1873 | int register_nmi_notifier(struct notifier_block *nb) |
| 1874 | { |
| 1875 | return raw_notifier_chain_register(&nmi_chain, nb); |
| 1876 | } |
| 1877 | |
Joe Perches | ff2d8b1 | 2012-01-12 17:17:21 -0800 | [diff] [blame] | 1878 | void __noreturn nmi_exception_handler(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | { |
Leonid Yegoshin | 83e4da1 | 2013-10-08 12:39:31 +0100 | [diff] [blame] | 1880 | char str[100]; |
| 1881 | |
Petri Gynther | 7963b3f | 2015-10-19 11:49:52 -0700 | [diff] [blame] | 1882 | nmi_enter(); |
Kevin Cernekee | 34bd92e | 2011-11-16 01:25:44 +0000 | [diff] [blame] | 1883 | raw_notifier_call_chain(&nmi_chain, 0, regs); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1884 | bust_spinlocks(1); |
Leonid Yegoshin | 83e4da1 | 2013-10-08 12:39:31 +0100 | [diff] [blame] | 1885 | snprintf(str, 100, "CPU%d NMI taken, CP0_EPC=%lx\n", |
| 1886 | smp_processor_id(), regs->cp0_epc); |
| 1887 | regs->cp0_epc = read_c0_errorepc(); |
| 1888 | die(str, regs); |
Petri Gynther | 7963b3f | 2015-10-19 11:49:52 -0700 | [diff] [blame] | 1889 | nmi_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | } |
| 1891 | |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1892 | #define VECTORSPACING 0x100 /* for EI/VI mode */ |
| 1893 | |
| 1894 | unsigned long ebase; |
James Hogan | 878edf0 | 2016-06-09 14:19:14 +0100 | [diff] [blame] | 1895 | EXPORT_SYMBOL_GPL(ebase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | unsigned long exception_handlers[32]; |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1897 | unsigned long vi_handlers[64]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | |
Florian Fainelli | 2d1b6e9 | 2010-01-28 15:21:42 +0100 | [diff] [blame] | 1899 | void __init *set_except_vector(int n, void *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | { |
| 1901 | unsigned long handler = (unsigned long) addr; |
Ralf Baechle | b22d1b6 | 2013-05-09 17:57:30 +0200 | [diff] [blame] | 1902 | unsigned long old_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1904 | #ifdef CONFIG_CPU_MICROMIPS |
| 1905 | /* |
| 1906 | * Only the TLB handlers are cache aligned with an even |
| 1907 | * address. All other handlers are on an odd address and |
| 1908 | * require no modification. Otherwise, MIPS32 mode will |
| 1909 | * be entered when handling any TLB exceptions. That |
| 1910 | * would be bad...since we must stay in microMIPS mode. |
| 1911 | */ |
| 1912 | if (!(handler & 0x1)) |
| 1913 | handler |= 1; |
| 1914 | #endif |
Ralf Baechle | b22d1b6 | 2013-05-09 17:57:30 +0200 | [diff] [blame] | 1915 | old_handler = xchg(&exception_handlers[n], handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | if (n == 0 && cpu_has_divec) { |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1918 | #ifdef CONFIG_CPU_MICROMIPS |
| 1919 | unsigned long jump_mask = ~((1 << 27) - 1); |
| 1920 | #else |
Florian Fainelli | 92bbe1b | 2010-01-28 15:22:37 +0100 | [diff] [blame] | 1921 | unsigned long jump_mask = ~((1 << 28) - 1); |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1922 | #endif |
Florian Fainelli | 92bbe1b | 2010-01-28 15:22:37 +0100 | [diff] [blame] | 1923 | u32 *buf = (u32 *)(ebase + 0x200); |
| 1924 | unsigned int k0 = 26; |
| 1925 | if ((handler & jump_mask) == ((ebase + 0x200) & jump_mask)) { |
| 1926 | uasm_i_j(&buf, handler & ~jump_mask); |
| 1927 | uasm_i_nop(&buf); |
| 1928 | } else { |
| 1929 | UASM_i_LA(&buf, k0, handler); |
| 1930 | uasm_i_jr(&buf, k0); |
| 1931 | uasm_i_nop(&buf); |
| 1932 | } |
| 1933 | local_flush_icache_range(ebase + 0x200, (unsigned long)buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | } |
| 1935 | return (void *)old_handler; |
| 1936 | } |
| 1937 | |
Ralf Baechle | 86a1708 | 2013-02-08 01:21:34 +0100 | [diff] [blame] | 1938 | static void do_default_vi(void) |
Atsushi Nemoto | 6ba07e5 | 2007-05-21 23:45:38 +0900 | [diff] [blame] | 1939 | { |
| 1940 | show_regs(get_irq_regs()); |
| 1941 | panic("Caught unexpected vectored interrupt."); |
| 1942 | } |
| 1943 | |
Ralf Baechle | ef300e4 | 2007-05-06 18:31:18 +0100 | [diff] [blame] | 1944 | static void *set_vi_srs_handler(int n, vi_handler_t addr, int srs) |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1945 | { |
| 1946 | unsigned long handler; |
| 1947 | unsigned long old_handler = vi_handlers[n]; |
Ralf Baechle | f6771db | 2007-11-08 18:02:29 +0000 | [diff] [blame] | 1948 | int srssets = current_cpu_data.srsets; |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1949 | u16 *h; |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1950 | unsigned char *b; |
| 1951 | |
Ralf Baechle | b72b709 | 2009-03-30 14:49:44 +0200 | [diff] [blame] | 1952 | BUG_ON(!cpu_has_veic && !cpu_has_vint); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1953 | |
| 1954 | if (addr == NULL) { |
| 1955 | handler = (unsigned long) do_default_vi; |
| 1956 | srs = 0; |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1957 | } else |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1958 | handler = (unsigned long) addr; |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1959 | vi_handlers[n] = handler; |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1960 | |
| 1961 | b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING); |
| 1962 | |
Ralf Baechle | f6771db | 2007-11-08 18:02:29 +0000 | [diff] [blame] | 1963 | if (srs >= srssets) |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1964 | panic("Shadow register set %d not supported", srs); |
| 1965 | |
| 1966 | if (cpu_has_veic) { |
| 1967 | if (board_bind_eic_interrupt) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1968 | board_bind_eic_interrupt(n, srs); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 1969 | } else if (cpu_has_vint) { |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1970 | /* SRSMap is only defined if shadow sets are implemented */ |
Ralf Baechle | f6771db | 2007-11-08 18:02:29 +0000 | [diff] [blame] | 1971 | if (srssets > 1) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1972 | change_c0_srsmap(0xf << n*4, srs << n*4); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | if (srs == 0) { |
| 1976 | /* |
| 1977 | * If no shadow set is selected then use the default handler |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1978 | * that does normal register saving and standard interrupt exit |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1979 | */ |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1980 | extern char except_vec_vi, except_vec_vi_lui; |
| 1981 | extern char except_vec_vi_ori, except_vec_vi_end; |
Atsushi Nemoto | c65a548 | 2007-11-12 02:05:18 +0900 | [diff] [blame] | 1982 | extern char rollback_except_vec_vi; |
Ralf Baechle | f94d9a8 | 2013-05-21 17:30:36 +0200 | [diff] [blame] | 1983 | char *vec_start = using_rollback_handler() ? |
Atsushi Nemoto | c65a548 | 2007-11-12 02:05:18 +0900 | [diff] [blame] | 1984 | &rollback_except_vec_vi : &except_vec_vi; |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1985 | #if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN) |
| 1986 | const int lui_offset = &except_vec_vi_lui - vec_start + 2; |
| 1987 | const int ori_offset = &except_vec_vi_ori - vec_start + 2; |
| 1988 | #else |
Atsushi Nemoto | c65a548 | 2007-11-12 02:05:18 +0900 | [diff] [blame] | 1989 | const int lui_offset = &except_vec_vi_lui - vec_start; |
| 1990 | const int ori_offset = &except_vec_vi_ori - vec_start; |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 1991 | #endif |
| 1992 | const int handler_len = &except_vec_vi_end - vec_start; |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 1993 | |
| 1994 | if (handler_len > VECTORSPACING) { |
| 1995 | /* |
| 1996 | * Sigh... panicing won't help as the console |
| 1997 | * is probably not configured :( |
| 1998 | */ |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 1999 | panic("VECTORSPACING too small"); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2000 | } |
| 2001 | |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 2002 | set_handler(((unsigned long)b - ebase), vec_start, |
| 2003 | #ifdef CONFIG_CPU_MICROMIPS |
| 2004 | (handler_len - 1)); |
| 2005 | #else |
| 2006 | handler_len); |
| 2007 | #endif |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 2008 | h = (u16 *)(b + lui_offset); |
| 2009 | *h = (handler >> 16) & 0xffff; |
| 2010 | h = (u16 *)(b + ori_offset); |
| 2011 | *h = (handler & 0xffff); |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 2012 | local_flush_icache_range((unsigned long)b, |
| 2013 | (unsigned long)(b+handler_len)); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2014 | } |
| 2015 | else { |
| 2016 | /* |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 2017 | * In other cases jump directly to the interrupt handler. It |
| 2018 | * is the handler's responsibility to save registers if required |
| 2019 | * (eg hi/lo) and return from the exception using "eret". |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2020 | */ |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 2021 | u32 insn; |
| 2022 | |
| 2023 | h = (u16 *)b; |
| 2024 | /* j handler */ |
| 2025 | #ifdef CONFIG_CPU_MICROMIPS |
| 2026 | insn = 0xd4000000 | (((u32)handler & 0x07ffffff) >> 1); |
| 2027 | #else |
| 2028 | insn = 0x08000000 | (((u32)handler & 0x0fffffff) >> 2); |
| 2029 | #endif |
| 2030 | h[0] = (insn >> 16) & 0xffff; |
| 2031 | h[1] = insn & 0xffff; |
| 2032 | h[2] = 0; |
| 2033 | h[3] = 0; |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 2034 | local_flush_icache_range((unsigned long)b, |
| 2035 | (unsigned long)(b+8)); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | return (void *)old_handler; |
| 2039 | } |
| 2040 | |
Ralf Baechle | ef300e4 | 2007-05-06 18:31:18 +0100 | [diff] [blame] | 2041 | void *set_vi_handler(int n, vi_handler_t addr) |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2042 | { |
Ralf Baechle | ff3eab2 | 2006-03-29 14:12:58 +0100 | [diff] [blame] | 2043 | return set_vi_srs_handler(n, addr, 0); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2044 | } |
Ralf Baechle | f41ae0b | 2006-06-05 17:24:46 +0100 | [diff] [blame] | 2045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | extern void tlb_init(void); |
| 2047 | |
Ralf Baechle | 42f7754 | 2007-10-18 17:48:11 +0100 | [diff] [blame] | 2048 | /* |
| 2049 | * Timer interrupt |
| 2050 | */ |
| 2051 | int cp0_compare_irq; |
Ralf Baechle | 68b6352 | 2012-07-19 09:13:52 +0200 | [diff] [blame] | 2052 | EXPORT_SYMBOL_GPL(cp0_compare_irq); |
David VomLehn | 010c108 | 2009-12-21 17:49:22 -0800 | [diff] [blame] | 2053 | int cp0_compare_irq_shift; |
Ralf Baechle | 42f7754 | 2007-10-18 17:48:11 +0100 | [diff] [blame] | 2054 | |
| 2055 | /* |
| 2056 | * Performance counter IRQ or -1 if shared with timer |
| 2057 | */ |
| 2058 | int cp0_perfcount_irq; |
| 2059 | EXPORT_SYMBOL_GPL(cp0_perfcount_irq); |
| 2060 | |
James Hogan | 8f7ff02 | 2015-01-29 11:14:07 +0000 | [diff] [blame] | 2061 | /* |
| 2062 | * Fast debug channel IRQ or -1 if not present |
| 2063 | */ |
| 2064 | int cp0_fdc_irq; |
| 2065 | EXPORT_SYMBOL_GPL(cp0_fdc_irq); |
| 2066 | |
Paul Gortmaker | 078a55f | 2013-06-18 13:38:59 +0000 | [diff] [blame] | 2067 | static int noulri; |
Chris Dearman | bdc94eb | 2007-10-03 10:43:56 +0100 | [diff] [blame] | 2068 | |
| 2069 | static int __init ulri_disable(char *s) |
| 2070 | { |
| 2071 | pr_info("Disabling ulri\n"); |
| 2072 | noulri = 1; |
| 2073 | |
| 2074 | return 1; |
| 2075 | } |
| 2076 | __setup("noulri", ulri_disable); |
| 2077 | |
James Hogan | ae4ce45 | 2014-03-04 10:20:43 +0000 | [diff] [blame] | 2078 | /* configure STATUS register */ |
| 2079 | static void configure_status(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | /* |
| 2082 | * Disable coprocessors and select 32-bit or 64-bit addressing |
| 2083 | * and the 16/32 or 32/32 FPR register model. Reset the BEV |
| 2084 | * flag that some firmware may have left set and the TS bit (for |
| 2085 | * IP27). Set XX for ISA IV code to work. |
| 2086 | */ |
James Hogan | ae4ce45 | 2014-03-04 10:20:43 +0000 | [diff] [blame] | 2087 | unsigned int status_set = ST0_CU0; |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 2088 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | status_set |= ST0_FR|ST0_KX|ST0_SX|ST0_UX; |
| 2090 | #endif |
Deng-Cheng Zhu | adb3789 | 2013-04-01 18:14:28 +0000 | [diff] [blame] | 2091 | if (current_cpu_data.isa_level & MIPS_CPU_ISA_IV) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | status_set |= ST0_XX; |
Chris Dearman | bbaf238 | 2007-12-13 22:42:19 +0000 | [diff] [blame] | 2093 | if (cpu_has_dsp) |
| 2094 | status_set |= ST0_MX; |
| 2095 | |
Ralf Baechle | b38c739 | 2006-02-07 01:20:43 +0000 | [diff] [blame] | 2096 | change_c0_status(ST0_CU|ST0_MX|ST0_RE|ST0_FR|ST0_BEV|ST0_TS|ST0_KX|ST0_SX|ST0_UX, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | status_set); |
James Hogan | ae4ce45 | 2014-03-04 10:20:43 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
James Hogan | b937ff6 | 2016-06-15 19:29:53 +0100 | [diff] [blame] | 2100 | unsigned int hwrena; |
| 2101 | EXPORT_SYMBOL_GPL(hwrena); |
| 2102 | |
James Hogan | ae4ce45 | 2014-03-04 10:20:43 +0000 | [diff] [blame] | 2103 | /* configure HWRENA register */ |
| 2104 | static void configure_hwrena(void) |
| 2105 | { |
James Hogan | b937ff6 | 2016-06-15 19:29:53 +0100 | [diff] [blame] | 2106 | hwrena = cpu_hwrena_impl_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | |
Leonid Yegoshin | 9c7d576 | 2014-11-14 11:25:30 +0000 | [diff] [blame] | 2108 | if (cpu_has_mips_r2_r6) |
James Hogan | aff565a | 2016-06-15 19:29:52 +0100 | [diff] [blame] | 2109 | hwrena |= MIPS_HWRENA_CPUNUM | |
| 2110 | MIPS_HWRENA_SYNCISTEP | |
| 2111 | MIPS_HWRENA_CC | |
| 2112 | MIPS_HWRENA_CCRES; |
Ralf Baechle | a369202 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 2113 | |
Kevin Cernekee | 18d693b | 2010-10-16 14:22:38 -0700 | [diff] [blame] | 2114 | if (!noulri && cpu_has_userlocal) |
James Hogan | aff565a | 2016-06-15 19:29:52 +0100 | [diff] [blame] | 2115 | hwrena |= MIPS_HWRENA_ULR; |
Ralf Baechle | a369202 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 2116 | |
Kevin Cernekee | 18d693b | 2010-10-16 14:22:38 -0700 | [diff] [blame] | 2117 | if (hwrena) |
| 2118 | write_c0_hwrena(hwrena); |
James Hogan | ae4ce45 | 2014-03-04 10:20:43 +0000 | [diff] [blame] | 2119 | } |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2120 | |
James Hogan | ae4ce45 | 2014-03-04 10:20:43 +0000 | [diff] [blame] | 2121 | static void configure_exception_vector(void) |
| 2122 | { |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2123 | if (cpu_has_veic || cpu_has_vint) { |
Chris Dearman | 9fb4c2b9 | 2009-03-20 15:33:55 -0700 | [diff] [blame] | 2124 | unsigned long sr = set_c0_status(ST0_BEV); |
Matt Redfearn | 4b22c69 | 2016-09-01 17:30:09 +0100 | [diff] [blame] | 2125 | /* If available, use WG to set top bits of EBASE */ |
| 2126 | if (cpu_has_ebase_wg) { |
| 2127 | #ifdef CONFIG_64BIT |
| 2128 | write_c0_ebase_64(ebase | MIPS_EBASE_WG); |
| 2129 | #else |
| 2130 | write_c0_ebase(ebase | MIPS_EBASE_WG); |
| 2131 | #endif |
| 2132 | } |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 2133 | write_c0_ebase(ebase); |
Chris Dearman | 9fb4c2b9 | 2009-03-20 15:33:55 -0700 | [diff] [blame] | 2134 | write_c0_status(sr); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2135 | /* Setting vector spacing enables EI/VI mode */ |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 2136 | change_c0_intctl(0x3e0, VECTORSPACING); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2137 | } |
Ralf Baechle | d03d0a5 | 2005-08-17 13:44:26 +0000 | [diff] [blame] | 2138 | if (cpu_has_divec) { |
| 2139 | if (cpu_has_mipsmt) { |
| 2140 | unsigned int vpflags = dvpe(); |
| 2141 | set_c0_cause(CAUSEF_IV); |
| 2142 | evpe(vpflags); |
| 2143 | } else |
| 2144 | set_c0_cause(CAUSEF_IV); |
| 2145 | } |
James Hogan | ae4ce45 | 2014-03-04 10:20:43 +0000 | [diff] [blame] | 2146 | } |
| 2147 | |
| 2148 | void per_cpu_trap_init(bool is_boot_cpu) |
| 2149 | { |
| 2150 | unsigned int cpu = smp_processor_id(); |
James Hogan | ae4ce45 | 2014-03-04 10:20:43 +0000 | [diff] [blame] | 2151 | |
| 2152 | configure_status(); |
| 2153 | configure_hwrena(); |
| 2154 | |
James Hogan | ae4ce45 | 2014-03-04 10:20:43 +0000 | [diff] [blame] | 2155 | configure_exception_vector(); |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 2156 | |
| 2157 | /* |
| 2158 | * Before R2 both interrupt numbers were fixed to 7, so on R2 only: |
| 2159 | * |
| 2160 | * o read IntCtl.IPTI to determine the timer interrupt |
| 2161 | * o read IntCtl.IPPCI to determine the performance counter interrupt |
James Hogan | 8f7ff02 | 2015-01-29 11:14:07 +0000 | [diff] [blame] | 2162 | * o read IntCtl.IPFDC to determine the fast debug channel interrupt |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 2163 | */ |
Leonid Yegoshin | 9c7d576 | 2014-11-14 11:25:30 +0000 | [diff] [blame] | 2164 | if (cpu_has_mips_r2_r6) { |
Markos Chandras | 04d83f9 | 2016-02-03 03:15:22 +0000 | [diff] [blame] | 2165 | /* |
| 2166 | * We shouldn't trust a secondary core has a sane EBASE register |
| 2167 | * so use the one calculated by the boot CPU. |
| 2168 | */ |
Matt Redfearn | 4b22c69 | 2016-09-01 17:30:09 +0100 | [diff] [blame] | 2169 | if (!is_boot_cpu) { |
| 2170 | /* If available, use WG to set top bits of EBASE */ |
| 2171 | if (cpu_has_ebase_wg) { |
| 2172 | #ifdef CONFIG_64BIT |
| 2173 | write_c0_ebase_64(ebase | MIPS_EBASE_WG); |
| 2174 | #else |
| 2175 | write_c0_ebase(ebase | MIPS_EBASE_WG); |
| 2176 | #endif |
| 2177 | } |
Markos Chandras | 04d83f9 | 2016-02-03 03:15:22 +0000 | [diff] [blame] | 2178 | write_c0_ebase(ebase); |
Matt Redfearn | 4b22c69 | 2016-09-01 17:30:09 +0100 | [diff] [blame] | 2179 | } |
Markos Chandras | 04d83f9 | 2016-02-03 03:15:22 +0000 | [diff] [blame] | 2180 | |
David VomLehn | 010c108 | 2009-12-21 17:49:22 -0800 | [diff] [blame] | 2181 | cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP; |
| 2182 | cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7; |
| 2183 | cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7; |
James Hogan | 8f7ff02 | 2015-01-29 11:14:07 +0000 | [diff] [blame] | 2184 | cp0_fdc_irq = (read_c0_intctl() >> INTCTLB_IPFDC) & 7; |
| 2185 | if (!cp0_fdc_irq) |
| 2186 | cp0_fdc_irq = -1; |
| 2187 | |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 2188 | } else { |
| 2189 | cp0_compare_irq = CP0_LEGACY_COMPARE_IRQ; |
Ralf Baechle | c6a4ebb | 2012-07-06 23:56:00 +0200 | [diff] [blame] | 2190 | cp0_compare_irq_shift = CP0_LEGACY_PERFCNT_IRQ; |
Chris Dearman | c3e838a | 2007-06-21 12:59:57 +0100 | [diff] [blame] | 2191 | cp0_perfcount_irq = -1; |
James Hogan | 8f7ff02 | 2015-01-29 11:14:07 +0000 | [diff] [blame] | 2192 | cp0_fdc_irq = -1; |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 2193 | } |
| 2194 | |
David Daney | 48c4ac9 | 2013-05-13 13:56:44 -0700 | [diff] [blame] | 2195 | if (!cpu_data[cpu].asid_cache) |
Paul Burton | 4edf00a | 2016-05-06 14:36:23 +0100 | [diff] [blame] | 2196 | cpu_data[cpu].asid_cache = asid_first_version(cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | |
Vegard Nossum | f1f1007 | 2017-02-27 14:30:07 -0800 | [diff] [blame] | 2198 | mmgrab(&init_mm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | current->active_mm = &init_mm; |
| 2200 | BUG_ON(current->mm); |
| 2201 | enter_lazy_tlb(&init_mm, current); |
| 2202 | |
Markos Chandras | 761b449 | 2015-06-24 09:29:20 +0100 | [diff] [blame] | 2203 | /* Boot CPU's cache setup in setup_arch(). */ |
| 2204 | if (!is_boot_cpu) |
| 2205 | cpu_cache_init(); |
| 2206 | tlb_init(); |
David Daney | 3d8bfdd | 2010-12-21 14:19:11 -0800 | [diff] [blame] | 2207 | TLBMISS_HANDLER_SETUP(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | } |
| 2209 | |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2210 | /* Install CPU exception handler */ |
Paul Gortmaker | 078a55f | 2013-06-18 13:38:59 +0000 | [diff] [blame] | 2211 | void set_handler(unsigned long offset, void *addr, unsigned long size) |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2212 | { |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 2213 | #ifdef CONFIG_CPU_MICROMIPS |
| 2214 | memcpy((void *)(ebase + offset), ((unsigned char *)addr - 1), size); |
| 2215 | #else |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2216 | memcpy((void *)(ebase + offset), addr, size); |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 2217 | #endif |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 2218 | local_flush_icache_range(ebase + offset, ebase + offset + size); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2219 | } |
| 2220 | |
Kees Cook | 0632466 | 2017-05-08 15:59:05 -0700 | [diff] [blame] | 2221 | static const char panic_null_cerr[] = |
| 2222 | "Trying to set NULL cache error exception handler\n"; |
Ralf Baechle | 641e97f | 2007-10-11 23:46:05 +0100 | [diff] [blame] | 2223 | |
Ralf Baechle | 42fe7ee | 2009-01-28 18:48:23 +0000 | [diff] [blame] | 2224 | /* |
| 2225 | * Install uncached CPU exception handler. |
| 2226 | * This is suitable only for the cache error exception which is the only |
| 2227 | * exception handler that is being run uncached. |
| 2228 | */ |
Paul Gortmaker | 078a55f | 2013-06-18 13:38:59 +0000 | [diff] [blame] | 2229 | void set_uncached_handler(unsigned long offset, void *addr, |
Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 2230 | unsigned long size) |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2231 | { |
Sebastian Andrzej Siewior | 4f81b01 | 2010-04-27 22:53:30 +0200 | [diff] [blame] | 2232 | unsigned long uncached_ebase = CKSEG1ADDR(ebase); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2233 | |
Ralf Baechle | 641e97f | 2007-10-11 23:46:05 +0100 | [diff] [blame] | 2234 | if (!addr) |
| 2235 | panic(panic_null_cerr); |
| 2236 | |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2237 | memcpy((void *)(uncached_ebase + offset), addr, size); |
| 2238 | } |
| 2239 | |
Atsushi Nemoto | 5b10496 | 2006-09-11 17:50:29 +0900 | [diff] [blame] | 2240 | static int __initdata rdhwr_noopt; |
| 2241 | static int __init set_rdhwr_noopt(char *str) |
| 2242 | { |
| 2243 | rdhwr_noopt = 1; |
| 2244 | return 1; |
| 2245 | } |
| 2246 | |
| 2247 | __setup("rdhwr_noopt", set_rdhwr_noopt); |
| 2248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | void __init trap_init(void) |
| 2250 | { |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 2251 | extern char except_vec3_generic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | extern char except_vec4; |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 2253 | extern char except_vec3_r4000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | unsigned long i; |
Atsushi Nemoto | c65a548 | 2007-11-12 02:05:18 +0900 | [diff] [blame] | 2255 | |
| 2256 | check_wait(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | |
Chris Dearman | 9fb4c2b9 | 2009-03-20 15:33:55 -0700 | [diff] [blame] | 2258 | if (cpu_has_veic || cpu_has_vint) { |
| 2259 | unsigned long size = 0x200 + VECTORSPACING*64; |
James Hogan | c195e07 | 2016-09-01 17:30:08 +0100 | [diff] [blame] | 2260 | phys_addr_t ebase_pa; |
| 2261 | |
Chris Dearman | 9fb4c2b9 | 2009-03-20 15:33:55 -0700 | [diff] [blame] | 2262 | ebase = (unsigned long) |
| 2263 | __alloc_bootmem(size, 1 << fls(size), 0); |
James Hogan | c195e07 | 2016-09-01 17:30:08 +0100 | [diff] [blame] | 2264 | |
| 2265 | /* |
| 2266 | * Try to ensure ebase resides in KSeg0 if possible. |
| 2267 | * |
| 2268 | * It shouldn't generally be in XKPhys on MIPS64 to avoid |
| 2269 | * hitting a poorly defined exception base for Cache Errors. |
| 2270 | * The allocation is likely to be in the low 512MB of physical, |
| 2271 | * in which case we should be able to convert to KSeg0. |
| 2272 | * |
| 2273 | * EVA is special though as it allows segments to be rearranged |
| 2274 | * and to become uncached during cache error handling. |
| 2275 | */ |
| 2276 | ebase_pa = __pa(ebase); |
| 2277 | if (!IS_ENABLED(CONFIG_EVA) && !WARN_ON(ebase_pa >= 0x20000000)) |
| 2278 | ebase = CKSEG0ADDR(ebase_pa); |
Chris Dearman | 9fb4c2b9 | 2009-03-20 15:33:55 -0700 | [diff] [blame] | 2279 | } else { |
Paul Burton | a13c996 | 2015-09-22 10:15:22 -0700 | [diff] [blame] | 2280 | ebase = CAC_BASE; |
| 2281 | |
James Hogan | 1802289 | 2016-09-01 17:30:07 +0100 | [diff] [blame] | 2282 | if (cpu_has_mips_r2_r6) { |
| 2283 | if (cpu_has_ebase_wg) { |
| 2284 | #ifdef CONFIG_64BIT |
| 2285 | ebase = (read_c0_ebase_64() & ~0xfff); |
| 2286 | #else |
| 2287 | ebase = (read_c0_ebase() & ~0xfff); |
| 2288 | #endif |
| 2289 | } else { |
| 2290 | ebase += (read_c0_ebase() & 0x3ffff000); |
| 2291 | } |
| 2292 | } |
David Daney | 566f74f | 2008-10-23 17:56:35 -0700 | [diff] [blame] | 2293 | } |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2294 | |
Steven J. Hill | c6213c6 | 2013-06-05 21:25:17 +0000 | [diff] [blame] | 2295 | if (cpu_has_mmips) { |
| 2296 | unsigned int config3 = read_c0_config3(); |
| 2297 | |
| 2298 | if (IS_ENABLED(CONFIG_CPU_MICROMIPS)) |
| 2299 | write_c0_config3(config3 | MIPS_CONF3_ISA_OE); |
| 2300 | else |
| 2301 | write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE); |
| 2302 | } |
| 2303 | |
Kevin Cernekee | 6fb97ef | 2011-11-16 01:25:45 +0000 | [diff] [blame] | 2304 | if (board_ebase_setup) |
| 2305 | board_ebase_setup(); |
David Daney | 6650df3 | 2012-05-15 00:04:50 -0700 | [diff] [blame] | 2306 | per_cpu_trap_init(true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | |
| 2308 | /* |
| 2309 | * Copy the generic exception handlers to their final destination. |
Adam Buchbinder | 92a76f6 | 2016-02-25 00:44:58 -0800 | [diff] [blame] | 2310 | * This will be overridden later as suitable for a particular |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | * configuration. |
| 2312 | */ |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2313 | set_handler(0x180, &except_vec3_generic, 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | |
| 2315 | /* |
| 2316 | * Setup default vectors |
| 2317 | */ |
| 2318 | for (i = 0; i <= 31; i++) |
| 2319 | set_except_vector(i, handle_reserved); |
| 2320 | |
| 2321 | /* |
| 2322 | * Copy the EJTAG debug exception vector handler code to it's final |
| 2323 | * destination. |
| 2324 | */ |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2325 | if (cpu_has_ejtag && board_ejtag_handler_setup) |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 2326 | board_ejtag_handler_setup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | |
| 2328 | /* |
| 2329 | * Only some CPUs have the watch exceptions. |
| 2330 | */ |
| 2331 | if (cpu_has_watch) |
James Hogan | 1b505de | 2015-12-16 23:49:35 +0000 | [diff] [blame] | 2332 | set_except_vector(EXCCODE_WATCH, handle_watch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | |
| 2334 | /* |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2335 | * Initialise interrupt handlers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | */ |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2337 | if (cpu_has_veic || cpu_has_vint) { |
| 2338 | int nvec = cpu_has_veic ? 64 : 8; |
| 2339 | for (i = 0; i < nvec; i++) |
Ralf Baechle | ff3eab2 | 2006-03-29 14:12:58 +0100 | [diff] [blame] | 2340 | set_vi_handler(i, NULL); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2341 | } |
| 2342 | else if (cpu_has_divec) |
| 2343 | set_handler(0x200, &except_vec4, 0x8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | |
| 2345 | /* |
| 2346 | * Some CPUs can enable/disable for cache parity detection, but does |
| 2347 | * it different ways. |
| 2348 | */ |
| 2349 | parity_protection_init(); |
| 2350 | |
| 2351 | /* |
| 2352 | * The Data Bus Errors / Instruction Bus Errors are signaled |
| 2353 | * by external hardware. Therefore these two exceptions |
| 2354 | * may have board specific handlers. |
| 2355 | */ |
| 2356 | if (board_be_init) |
| 2357 | board_be_init(); |
| 2358 | |
James Hogan | 1b505de | 2015-12-16 23:49:35 +0000 | [diff] [blame] | 2359 | set_except_vector(EXCCODE_INT, using_rollback_handler() ? |
| 2360 | rollback_handle_int : handle_int); |
| 2361 | set_except_vector(EXCCODE_MOD, handle_tlbm); |
| 2362 | set_except_vector(EXCCODE_TLBL, handle_tlbl); |
| 2363 | set_except_vector(EXCCODE_TLBS, handle_tlbs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | |
James Hogan | 1b505de | 2015-12-16 23:49:35 +0000 | [diff] [blame] | 2365 | set_except_vector(EXCCODE_ADEL, handle_adel); |
| 2366 | set_except_vector(EXCCODE_ADES, handle_ades); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | |
James Hogan | 1b505de | 2015-12-16 23:49:35 +0000 | [diff] [blame] | 2368 | set_except_vector(EXCCODE_IBE, handle_ibe); |
| 2369 | set_except_vector(EXCCODE_DBE, handle_dbe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | |
James Hogan | 1b505de | 2015-12-16 23:49:35 +0000 | [diff] [blame] | 2371 | set_except_vector(EXCCODE_SYS, handle_sys); |
| 2372 | set_except_vector(EXCCODE_BP, handle_bp); |
Huacai Chen | 5a34133 | 2017-03-16 21:00:26 +0800 | [diff] [blame] | 2373 | |
| 2374 | if (rdhwr_noopt) |
| 2375 | set_except_vector(EXCCODE_RI, handle_ri); |
| 2376 | else { |
| 2377 | if (cpu_has_vtag_icache) |
| 2378 | set_except_vector(EXCCODE_RI, handle_ri_rdhwr_tlbp); |
| 2379 | else if (current_cpu_type() == CPU_LOONGSON3) |
| 2380 | set_except_vector(EXCCODE_RI, handle_ri_rdhwr_tlbp); |
| 2381 | else |
| 2382 | set_except_vector(EXCCODE_RI, handle_ri_rdhwr); |
| 2383 | } |
| 2384 | |
James Hogan | 1b505de | 2015-12-16 23:49:35 +0000 | [diff] [blame] | 2385 | set_except_vector(EXCCODE_CPU, handle_cpu); |
| 2386 | set_except_vector(EXCCODE_OV, handle_ov); |
| 2387 | set_except_vector(EXCCODE_TR, handle_tr); |
| 2388 | set_except_vector(EXCCODE_MSAFPE, handle_msa_fpe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 2390 | if (board_nmi_handler_setup) |
| 2391 | board_nmi_handler_setup(); |
| 2392 | |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 2393 | if (cpu_has_fpu && !cpu_has_nofpuex) |
James Hogan | 1b505de | 2015-12-16 23:49:35 +0000 | [diff] [blame] | 2394 | set_except_vector(EXCCODE_FPE, handle_fpe); |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 2395 | |
James Hogan | 1b505de | 2015-12-16 23:49:35 +0000 | [diff] [blame] | 2396 | set_except_vector(MIPS_EXCCODE_TLBPAR, handle_ftlb); |
Leonid Yegoshin | 5890f70 | 2014-07-15 14:09:56 +0100 | [diff] [blame] | 2397 | |
| 2398 | if (cpu_has_rixiex) { |
James Hogan | 1b505de | 2015-12-16 23:49:35 +0000 | [diff] [blame] | 2399 | set_except_vector(EXCCODE_TLBRI, tlb_do_page_fault_0); |
| 2400 | set_except_vector(EXCCODE_TLBXI, tlb_do_page_fault_0); |
Leonid Yegoshin | 5890f70 | 2014-07-15 14:09:56 +0100 | [diff] [blame] | 2401 | } |
| 2402 | |
James Hogan | 1b505de | 2015-12-16 23:49:35 +0000 | [diff] [blame] | 2403 | set_except_vector(EXCCODE_MSADIS, handle_msa); |
| 2404 | set_except_vector(EXCCODE_MDMX, handle_mdmx); |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 2405 | |
| 2406 | if (cpu_has_mcheck) |
James Hogan | 1b505de | 2015-12-16 23:49:35 +0000 | [diff] [blame] | 2407 | set_except_vector(EXCCODE_MCHECK, handle_mcheck); |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 2408 | |
Ralf Baechle | 340ee4b | 2005-08-17 17:44:08 +0000 | [diff] [blame] | 2409 | if (cpu_has_mipsmt) |
James Hogan | 1b505de | 2015-12-16 23:49:35 +0000 | [diff] [blame] | 2410 | set_except_vector(EXCCODE_THREAD, handle_mt); |
Ralf Baechle | 340ee4b | 2005-08-17 17:44:08 +0000 | [diff] [blame] | 2411 | |
James Hogan | 1b505de | 2015-12-16 23:49:35 +0000 | [diff] [blame] | 2412 | set_except_vector(EXCCODE_DSPDIS, handle_dsp); |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 2413 | |
David Daney | fcbf1df | 2012-05-15 00:04:46 -0700 | [diff] [blame] | 2414 | if (board_cache_error_setup) |
| 2415 | board_cache_error_setup(); |
| 2416 | |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 2417 | if (cpu_has_vce) |
| 2418 | /* Special exception: R4[04]00 uses also the divec space. */ |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 2419 | set_handler(0x180, &except_vec3_r4000, 0x100); |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 2420 | else if (cpu_has_4kex) |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 2421 | set_handler(0x180, &except_vec3_generic, 0x80); |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 2422 | else |
Steven J. Hill | 2a0b24f | 2013-03-25 12:15:55 -0500 | [diff] [blame] | 2423 | set_handler(0x080, &except_vec3_generic, 0x80); |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 2424 | |
Thomas Bogendoerfer | e0cee3e | 2008-08-04 20:53:57 +0200 | [diff] [blame] | 2425 | local_flush_icache_range(ebase, ebase + 0x400); |
Thomas Bogendoerfer | 0510617 | 2008-08-04 19:44:34 +0200 | [diff] [blame] | 2426 | |
| 2427 | sort_extable(__start___dbe_table, __stop___dbe_table); |
Ralf Baechle | 69f3a7d | 2009-11-24 01:24:58 +0000 | [diff] [blame] | 2428 | |
Ralf Baechle | 4483b15 | 2010-08-05 13:25:59 +0100 | [diff] [blame] | 2429 | cu2_notifier(default_cu2_call, 0x80000000); /* Run last */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | } |
James Hogan | ae4ce45 | 2014-03-04 10:20:43 +0000 | [diff] [blame] | 2431 | |
| 2432 | static int trap_pm_notifier(struct notifier_block *self, unsigned long cmd, |
| 2433 | void *v) |
| 2434 | { |
| 2435 | switch (cmd) { |
| 2436 | case CPU_PM_ENTER_FAILED: |
| 2437 | case CPU_PM_EXIT: |
| 2438 | configure_status(); |
| 2439 | configure_hwrena(); |
| 2440 | configure_exception_vector(); |
| 2441 | |
| 2442 | /* Restore register with CPU number for TLB handlers */ |
| 2443 | TLBMISS_HANDLER_RESTORE(); |
| 2444 | |
| 2445 | break; |
| 2446 | } |
| 2447 | |
| 2448 | return NOTIFY_OK; |
| 2449 | } |
| 2450 | |
| 2451 | static struct notifier_block trap_pm_notifier_block = { |
| 2452 | .notifier_call = trap_pm_notifier, |
| 2453 | }; |
| 2454 | |
| 2455 | static int __init trap_pm_init(void) |
| 2456 | { |
| 2457 | return cpu_pm_register_notifier(&trap_pm_notifier_block); |
| 2458 | } |
| 2459 | arch_initcall(trap_pm_init); |