114cf11afSPaul Mackerras /* 214cf11afSPaul Mackerras * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 3fe04b112SScott Wood * Copyright 2007-2010 Freescale Semiconductor, Inc. 414cf11afSPaul Mackerras * 514cf11afSPaul Mackerras * This program is free software; you can redistribute it and/or 614cf11afSPaul Mackerras * modify it under the terms of the GNU General Public License 714cf11afSPaul Mackerras * as published by the Free Software Foundation; either version 814cf11afSPaul Mackerras * 2 of the License, or (at your option) any later version. 914cf11afSPaul Mackerras * 1014cf11afSPaul Mackerras * Modified by Cort Dougan (cort@cs.nmt.edu) 1114cf11afSPaul Mackerras * and Paul Mackerras (paulus@samba.org) 1214cf11afSPaul Mackerras */ 1314cf11afSPaul Mackerras 1414cf11afSPaul Mackerras /* 1514cf11afSPaul Mackerras * This file handles the architecture-dependent parts of hardware exceptions 1614cf11afSPaul Mackerras */ 1714cf11afSPaul Mackerras 1814cf11afSPaul Mackerras #include <linux/errno.h> 1914cf11afSPaul Mackerras #include <linux/sched.h> 20b17b0153SIngo Molnar #include <linux/sched/debug.h> 2114cf11afSPaul Mackerras #include <linux/kernel.h> 2214cf11afSPaul Mackerras #include <linux/mm.h> 2399cd1302SRam Pai #include <linux/pkeys.h> 2414cf11afSPaul Mackerras #include <linux/stddef.h> 2514cf11afSPaul Mackerras #include <linux/unistd.h> 268dad3f92SPaul Mackerras #include <linux/ptrace.h> 2714cf11afSPaul Mackerras #include <linux/user.h> 2814cf11afSPaul Mackerras #include <linux/interrupt.h> 2914cf11afSPaul Mackerras #include <linux/init.h> 308a39b05fSPaul Gortmaker #include <linux/extable.h> 318a39b05fSPaul Gortmaker #include <linux/module.h> /* print_modules */ 328dad3f92SPaul Mackerras #include <linux/prctl.h> 3314cf11afSPaul Mackerras #include <linux/delay.h> 3414cf11afSPaul Mackerras #include <linux/kprobes.h> 35cc532915SMichael Ellerman #include <linux/kexec.h> 365474c120SMichael Hanselmann #include <linux/backlight.h> 3773c9ceabSJeremy Fitzhardinge #include <linux/bug.h> 381eeb66a1SChristoph Hellwig #include <linux/kdebug.h> 3976462232SChristian Dietrich #include <linux/ratelimit.h> 40ba12eedeSLi Zhong #include <linux/context_tracking.h> 415080332cSMichael Neuling #include <linux/smp.h> 42*35adacd6SNicholas Piggin #include <linux/console.h> 43*35adacd6SNicholas Piggin #include <linux/kmsg_dump.h> 4414cf11afSPaul Mackerras 4580947e7cSGeert Uytterhoeven #include <asm/emulated_ops.h> 4614cf11afSPaul Mackerras #include <asm/pgtable.h> 477c0f6ba6SLinus Torvalds #include <linux/uaccess.h> 487644d581SMichael Ellerman #include <asm/debugfs.h> 4914cf11afSPaul Mackerras #include <asm/io.h> 5086417780SPaul Mackerras #include <asm/machdep.h> 5186417780SPaul Mackerras #include <asm/rtas.h> 52f7f6f4feSDavid Gibson #include <asm/pmc.h> 5314cf11afSPaul Mackerras #include <asm/reg.h> 5414cf11afSPaul Mackerras #ifdef CONFIG_PMAC_BACKLIGHT 5514cf11afSPaul Mackerras #include <asm/backlight.h> 5614cf11afSPaul Mackerras #endif 57dc1c1ca3SStephen Rothwell #ifdef CONFIG_PPC64 5886417780SPaul Mackerras #include <asm/firmware.h> 59dc1c1ca3SStephen Rothwell #include <asm/processor.h> 606ce6c629SMichael Neuling #include <asm/tm.h> 61dc1c1ca3SStephen Rothwell #endif 62c0ce7d08SDavid Wilder #include <asm/kexec.h> 6316c57b36SKumar Gala #include <asm/ppc-opcode.h> 64cce1f106SShaohui Xie #include <asm/rio.h> 65ebaeb5aeSMahesh Salgaonkar #include <asm/fadump.h> 66ae3a197eSDavid Howells #include <asm/switch_to.h> 67f54db641SMichael Neuling #include <asm/tm.h> 68ae3a197eSDavid Howells #include <asm/debug.h> 6942f5b4caSDaniel Axtens #include <asm/asm-prototypes.h> 70fd7bacbcSMahesh Salgaonkar #include <asm/hmi.h> 714e0e3435SHongtao Jia #include <sysdev/fsl_pci.h> 726cc89badSNaveen N. Rao #include <asm/kprobes.h> 73dc1c1ca3SStephen Rothwell 74da665885SThiago Jung Bauermann #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC_CORE) 755be3492fSAnton Blanchard int (*__debugger)(struct pt_regs *regs) __read_mostly; 765be3492fSAnton Blanchard int (*__debugger_ipi)(struct pt_regs *regs) __read_mostly; 775be3492fSAnton Blanchard int (*__debugger_bpt)(struct pt_regs *regs) __read_mostly; 785be3492fSAnton Blanchard int (*__debugger_sstep)(struct pt_regs *regs) __read_mostly; 795be3492fSAnton Blanchard int (*__debugger_iabr_match)(struct pt_regs *regs) __read_mostly; 809422de3eSMichael Neuling int (*__debugger_break_match)(struct pt_regs *regs) __read_mostly; 815be3492fSAnton Blanchard int (*__debugger_fault_handler)(struct pt_regs *regs) __read_mostly; 8214cf11afSPaul Mackerras 8314cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger); 8414cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_ipi); 8514cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_bpt); 8614cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_sstep); 8714cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_iabr_match); 889422de3eSMichael Neuling EXPORT_SYMBOL(__debugger_break_match); 8914cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_fault_handler); 9014cf11afSPaul Mackerras #endif 9114cf11afSPaul Mackerras 928b3c34cfSMichael Neuling /* Transactional Memory trap debug */ 938b3c34cfSMichael Neuling #ifdef TM_DEBUG_SW 948b3c34cfSMichael Neuling #define TM_DEBUG(x...) printk(KERN_INFO x) 958b3c34cfSMichael Neuling #else 968b3c34cfSMichael Neuling #define TM_DEBUG(x...) do { } while(0) 978b3c34cfSMichael Neuling #endif 988b3c34cfSMichael Neuling 9914cf11afSPaul Mackerras /* 10014cf11afSPaul Mackerras * Trap & Exception support 10114cf11afSPaul Mackerras */ 10214cf11afSPaul Mackerras 1036031d9d9Santon@samba.org #ifdef CONFIG_PMAC_BACKLIGHT 1046031d9d9Santon@samba.org static void pmac_backlight_unblank(void) 1056031d9d9Santon@samba.org { 1066031d9d9Santon@samba.org mutex_lock(&pmac_backlight_mutex); 1076031d9d9Santon@samba.org if (pmac_backlight) { 1086031d9d9Santon@samba.org struct backlight_properties *props; 1096031d9d9Santon@samba.org 1106031d9d9Santon@samba.org props = &pmac_backlight->props; 1116031d9d9Santon@samba.org props->brightness = props->max_brightness; 1126031d9d9Santon@samba.org props->power = FB_BLANK_UNBLANK; 1136031d9d9Santon@samba.org backlight_update_status(pmac_backlight); 1146031d9d9Santon@samba.org } 1156031d9d9Santon@samba.org mutex_unlock(&pmac_backlight_mutex); 1166031d9d9Santon@samba.org } 1176031d9d9Santon@samba.org #else 1186031d9d9Santon@samba.org static inline void pmac_backlight_unblank(void) { } 1196031d9d9Santon@samba.org #endif 1206031d9d9Santon@samba.org 1216fcd6baaSNicholas Piggin /* 1226fcd6baaSNicholas Piggin * If oops/die is expected to crash the machine, return true here. 1236fcd6baaSNicholas Piggin * 1246fcd6baaSNicholas Piggin * This should not be expected to be 100% accurate, there may be 1256fcd6baaSNicholas Piggin * notifiers registered or other unexpected conditions that may bring 1266fcd6baaSNicholas Piggin * down the kernel. Or if the current process in the kernel is holding 1276fcd6baaSNicholas Piggin * locks or has other critical state, the kernel may become effectively 1286fcd6baaSNicholas Piggin * unusable anyway. 1296fcd6baaSNicholas Piggin */ 1306fcd6baaSNicholas Piggin bool die_will_crash(void) 1316fcd6baaSNicholas Piggin { 1326fcd6baaSNicholas Piggin if (should_fadump_crash()) 1336fcd6baaSNicholas Piggin return true; 1346fcd6baaSNicholas Piggin if (kexec_should_crash(current)) 1356fcd6baaSNicholas Piggin return true; 1366fcd6baaSNicholas Piggin if (in_interrupt() || panic_on_oops || 1376fcd6baaSNicholas Piggin !current->pid || is_global_init(current)) 1386fcd6baaSNicholas Piggin return true; 1396fcd6baaSNicholas Piggin 1406fcd6baaSNicholas Piggin return false; 1416fcd6baaSNicholas Piggin } 1426fcd6baaSNicholas Piggin 143760ca4dcSAnton Blanchard static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED; 144760ca4dcSAnton Blanchard static int die_owner = -1; 145760ca4dcSAnton Blanchard static unsigned int die_nest_count; 146c0ce7d08SDavid Wilder static int die_counter; 147760ca4dcSAnton Blanchard 148*35adacd6SNicholas Piggin extern void panic_flush_kmsg_start(void) 149*35adacd6SNicholas Piggin { 150*35adacd6SNicholas Piggin /* 151*35adacd6SNicholas Piggin * These are mostly taken from kernel/panic.c, but tries to do 152*35adacd6SNicholas Piggin * relatively minimal work. Don't use delay functions (TB may 153*35adacd6SNicholas Piggin * be broken), don't crash dump (need to set a firmware log), 154*35adacd6SNicholas Piggin * don't run notifiers. We do want to get some information to 155*35adacd6SNicholas Piggin * Linux console. 156*35adacd6SNicholas Piggin */ 157*35adacd6SNicholas Piggin console_verbose(); 158*35adacd6SNicholas Piggin bust_spinlocks(1); 159*35adacd6SNicholas Piggin } 160*35adacd6SNicholas Piggin 161*35adacd6SNicholas Piggin extern void panic_flush_kmsg_end(void) 162*35adacd6SNicholas Piggin { 163*35adacd6SNicholas Piggin printk_safe_flush_on_panic(); 164*35adacd6SNicholas Piggin kmsg_dump(KMSG_DUMP_PANIC); 165*35adacd6SNicholas Piggin bust_spinlocks(0); 166*35adacd6SNicholas Piggin debug_locks_off(); 167*35adacd6SNicholas Piggin console_flush_on_panic(); 168*35adacd6SNicholas Piggin } 169*35adacd6SNicholas Piggin 17003465f89SNicholas Piggin static unsigned long oops_begin(struct pt_regs *regs) 171760ca4dcSAnton Blanchard { 172760ca4dcSAnton Blanchard int cpu; 17334c2a14fSanton@samba.org unsigned long flags; 17414cf11afSPaul Mackerras 175293e4688Santon@samba.org oops_enter(); 176293e4688Santon@samba.org 177760ca4dcSAnton Blanchard /* racy, but better than risking deadlock. */ 178760ca4dcSAnton Blanchard raw_local_irq_save(flags); 179760ca4dcSAnton Blanchard cpu = smp_processor_id(); 180760ca4dcSAnton Blanchard if (!arch_spin_trylock(&die_lock)) { 181760ca4dcSAnton Blanchard if (cpu == die_owner) 182760ca4dcSAnton Blanchard /* nested oops. should stop eventually */; 183760ca4dcSAnton Blanchard else 184760ca4dcSAnton Blanchard arch_spin_lock(&die_lock); 185760ca4dcSAnton Blanchard } 186760ca4dcSAnton Blanchard die_nest_count++; 187760ca4dcSAnton Blanchard die_owner = cpu; 18814cf11afSPaul Mackerras console_verbose(); 18914cf11afSPaul Mackerras bust_spinlocks(1); 1906031d9d9Santon@samba.org if (machine_is(powermac)) 1916031d9d9Santon@samba.org pmac_backlight_unblank(); 192760ca4dcSAnton Blanchard return flags; 19334c2a14fSanton@samba.org } 19403465f89SNicholas Piggin NOKPROBE_SYMBOL(oops_begin); 1955474c120SMichael Hanselmann 19603465f89SNicholas Piggin static void oops_end(unsigned long flags, struct pt_regs *regs, 197760ca4dcSAnton Blanchard int signr) 198760ca4dcSAnton Blanchard { 19914cf11afSPaul Mackerras bust_spinlocks(0); 200373d4d09SRusty Russell add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE); 201760ca4dcSAnton Blanchard die_nest_count--; 20258154c8cSAnton Blanchard oops_exit(); 20358154c8cSAnton Blanchard printk("\n"); 2047458e8b2SNicholas Piggin if (!die_nest_count) { 205760ca4dcSAnton Blanchard /* Nest count reaches zero, release the lock. */ 2067458e8b2SNicholas Piggin die_owner = -1; 207760ca4dcSAnton Blanchard arch_spin_unlock(&die_lock); 2087458e8b2SNicholas Piggin } 209760ca4dcSAnton Blanchard raw_local_irq_restore(flags); 210cc532915SMichael Ellerman 211ebaeb5aeSMahesh Salgaonkar crash_fadump(regs, "die oops"); 212ebaeb5aeSMahesh Salgaonkar 2134388c9b3SNicholas Piggin if (kexec_should_crash(current)) 214cc532915SMichael Ellerman crash_kexec(regs); 2159b00ac06SAnton Blanchard 216760ca4dcSAnton Blanchard if (!signr) 217760ca4dcSAnton Blanchard return; 218760ca4dcSAnton Blanchard 21958154c8cSAnton Blanchard /* 22058154c8cSAnton Blanchard * While our oops output is serialised by a spinlock, output 22158154c8cSAnton Blanchard * from panic() called below can race and corrupt it. If we 22258154c8cSAnton Blanchard * know we are going to panic, delay for 1 second so we have a 22358154c8cSAnton Blanchard * chance to get clean backtraces from all CPUs that are oopsing. 22458154c8cSAnton Blanchard */ 22558154c8cSAnton Blanchard if (in_interrupt() || panic_on_oops || !current->pid || 22658154c8cSAnton Blanchard is_global_init(current)) { 22758154c8cSAnton Blanchard mdelay(MSEC_PER_SEC); 22858154c8cSAnton Blanchard } 22958154c8cSAnton Blanchard 23014cf11afSPaul Mackerras if (in_interrupt()) 23114cf11afSPaul Mackerras panic("Fatal exception in interrupt"); 232cea6a4baSHorms if (panic_on_oops) 233012c437dSHorms panic("Fatal exception"); 234760ca4dcSAnton Blanchard do_exit(signr); 235760ca4dcSAnton Blanchard } 23603465f89SNicholas Piggin NOKPROBE_SYMBOL(oops_end); 237cea6a4baSHorms 23803465f89SNicholas Piggin static int __die(const char *str, struct pt_regs *regs, long err) 239760ca4dcSAnton Blanchard { 240760ca4dcSAnton Blanchard printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter); 2412e82ca3cSMichael Ellerman 2422e82ca3cSMichael Ellerman if (IS_ENABLED(CONFIG_CPU_LITTLE_ENDIAN)) 2432e82ca3cSMichael Ellerman printk("LE "); 2442e82ca3cSMichael Ellerman else 2452e82ca3cSMichael Ellerman printk("BE "); 2462e82ca3cSMichael Ellerman 2471c56cd8eSMichael Ellerman if (IS_ENABLED(CONFIG_PREEMPT)) 24872c0d9eeSMichael Ellerman pr_cont("PREEMPT "); 2491c56cd8eSMichael Ellerman 2501c56cd8eSMichael Ellerman if (IS_ENABLED(CONFIG_SMP)) 25172c0d9eeSMichael Ellerman pr_cont("SMP NR_CPUS=%d ", NR_CPUS); 2521c56cd8eSMichael Ellerman 253e7df0d88SJoonsoo Kim if (debug_pagealloc_enabled()) 25472c0d9eeSMichael Ellerman pr_cont("DEBUG_PAGEALLOC "); 2551c56cd8eSMichael Ellerman 2561c56cd8eSMichael Ellerman if (IS_ENABLED(CONFIG_NUMA)) 25772c0d9eeSMichael Ellerman pr_cont("NUMA "); 2581c56cd8eSMichael Ellerman 25972c0d9eeSMichael Ellerman pr_cont("%s\n", ppc_md.name ? ppc_md.name : ""); 260760ca4dcSAnton Blanchard 261760ca4dcSAnton Blanchard if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV) == NOTIFY_STOP) 262760ca4dcSAnton Blanchard return 1; 263760ca4dcSAnton Blanchard 264760ca4dcSAnton Blanchard print_modules(); 265760ca4dcSAnton Blanchard show_regs(regs); 26614cf11afSPaul Mackerras 26714cf11afSPaul Mackerras return 0; 26814cf11afSPaul Mackerras } 26903465f89SNicholas Piggin NOKPROBE_SYMBOL(__die); 27014cf11afSPaul Mackerras 271760ca4dcSAnton Blanchard void die(const char *str, struct pt_regs *regs, long err) 272760ca4dcSAnton Blanchard { 2736f44b20eSNicholas Piggin unsigned long flags; 274760ca4dcSAnton Blanchard 2756f44b20eSNicholas Piggin if (debugger(regs)) 2766f44b20eSNicholas Piggin return; 2776f44b20eSNicholas Piggin 2786f44b20eSNicholas Piggin flags = oops_begin(regs); 279760ca4dcSAnton Blanchard if (__die(str, regs, err)) 280760ca4dcSAnton Blanchard err = 0; 281760ca4dcSAnton Blanchard oops_end(flags, regs, err); 282760ca4dcSAnton Blanchard } 28315770a13SNaveen N. Rao NOKPROBE_SYMBOL(die); 284760ca4dcSAnton Blanchard 28525baa35bSOleg Nesterov void user_single_step_siginfo(struct task_struct *tsk, 28625baa35bSOleg Nesterov struct pt_regs *regs, siginfo_t *info) 28725baa35bSOleg Nesterov { 28825baa35bSOleg Nesterov memset(info, 0, sizeof(*info)); 28925baa35bSOleg Nesterov info->si_signo = SIGTRAP; 29025baa35bSOleg Nesterov info->si_code = TRAP_TRACE; 29125baa35bSOleg Nesterov info->si_addr = (void __user *)regs->nip; 29225baa35bSOleg Nesterov } 29325baa35bSOleg Nesterov 29499cd1302SRam Pai 29599cd1302SRam Pai void _exception_pkey(int signr, struct pt_regs *regs, int code, 29699cd1302SRam Pai unsigned long addr, int key) 29714cf11afSPaul Mackerras { 29814cf11afSPaul Mackerras siginfo_t info; 299d0c3d534SOlof Johansson const char fmt32[] = KERN_INFO "%s[%d]: unhandled signal %d " \ 300d0c3d534SOlof Johansson "at %08lx nip %08lx lr %08lx code %x\n"; 301d0c3d534SOlof Johansson const char fmt64[] = KERN_INFO "%s[%d]: unhandled signal %d " \ 302d0c3d534SOlof Johansson "at %016lx nip %016lx lr %016lx code %x\n"; 30314cf11afSPaul Mackerras 30414cf11afSPaul Mackerras if (!user_mode(regs)) { 305760ca4dcSAnton Blanchard die("Exception in kernel mode", regs, signr); 30614cf11afSPaul Mackerras return; 307760ca4dcSAnton Blanchard } 308760ca4dcSAnton Blanchard 309760ca4dcSAnton Blanchard if (show_unhandled_signals && unhandled_signal(current, signr)) { 31076462232SChristian Dietrich printk_ratelimited(regs->msr & MSR_64BIT ? fmt64 : fmt32, 311d0c3d534SOlof Johansson current->comm, current->pid, signr, 312d0c3d534SOlof Johansson addr, regs->nip, regs->link, code); 31314cf11afSPaul Mackerras } 31414cf11afSPaul Mackerras 315a3512b2dSBenjamin Herrenschmidt if (arch_irqs_disabled() && !arch_irq_disabled_regs(regs)) 3169f2f79e3SBenjamin Herrenschmidt local_irq_enable(); 3179f2f79e3SBenjamin Herrenschmidt 31841ab5266SAnanth N Mavinakayanahalli current->thread.trap_nr = code; 319c5cc1f4dSThiago Jung Bauermann 320c5cc1f4dSThiago Jung Bauermann /* 321c5cc1f4dSThiago Jung Bauermann * Save all the pkey registers AMR/IAMR/UAMOR. Eg: Core dumps need 322c5cc1f4dSThiago Jung Bauermann * to capture the content, if the task gets killed. 323c5cc1f4dSThiago Jung Bauermann */ 324c5cc1f4dSThiago Jung Bauermann thread_pkey_regs_save(¤t->thread); 325c5cc1f4dSThiago Jung Bauermann 32614cf11afSPaul Mackerras memset(&info, 0, sizeof(info)); 32714cf11afSPaul Mackerras info.si_signo = signr; 32814cf11afSPaul Mackerras info.si_code = code; 32914cf11afSPaul Mackerras info.si_addr = (void __user *) addr; 33099cd1302SRam Pai info.si_pkey = key; 33199cd1302SRam Pai 33214cf11afSPaul Mackerras force_sig_info(signr, &info, current); 33314cf11afSPaul Mackerras } 33414cf11afSPaul Mackerras 33599cd1302SRam Pai void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr) 33699cd1302SRam Pai { 33799cd1302SRam Pai _exception_pkey(signr, regs, code, addr, 0); 33899cd1302SRam Pai } 33999cd1302SRam Pai 34014cf11afSPaul Mackerras void system_reset_exception(struct pt_regs *regs) 34114cf11afSPaul Mackerras { 3422b4f3ac5SNicholas Piggin /* 3432b4f3ac5SNicholas Piggin * Avoid crashes in case of nested NMI exceptions. Recoverability 3442b4f3ac5SNicholas Piggin * is determined by RI and in_nmi 3452b4f3ac5SNicholas Piggin */ 3462b4f3ac5SNicholas Piggin bool nested = in_nmi(); 3472b4f3ac5SNicholas Piggin if (!nested) 3482b4f3ac5SNicholas Piggin nmi_enter(); 3492b4f3ac5SNicholas Piggin 350ca41ad43SNicholas Piggin __this_cpu_inc(irq_stat.sreset_irqs); 351ca41ad43SNicholas Piggin 35214cf11afSPaul Mackerras /* See if any machine dependent calls */ 353c902be71SArnd Bergmann if (ppc_md.system_reset_exception) { 354c902be71SArnd Bergmann if (ppc_md.system_reset_exception(regs)) 355c4f3b52cSNicholas Piggin goto out; 356c902be71SArnd Bergmann } 35714cf11afSPaul Mackerras 3584388c9b3SNicholas Piggin if (debugger(regs)) 3594388c9b3SNicholas Piggin goto out; 3604388c9b3SNicholas Piggin 3614388c9b3SNicholas Piggin /* 3624388c9b3SNicholas Piggin * A system reset is a request to dump, so we always send 3634388c9b3SNicholas Piggin * it through the crashdump code (if fadump or kdump are 3644388c9b3SNicholas Piggin * registered). 3654388c9b3SNicholas Piggin */ 3664388c9b3SNicholas Piggin crash_fadump(regs, "System Reset"); 3674388c9b3SNicholas Piggin 3684388c9b3SNicholas Piggin crash_kexec(regs); 3694388c9b3SNicholas Piggin 3704388c9b3SNicholas Piggin /* 3714388c9b3SNicholas Piggin * We aren't the primary crash CPU. We need to send it 3724388c9b3SNicholas Piggin * to a holding pattern to avoid it ending up in the panic 3734388c9b3SNicholas Piggin * code. 3744388c9b3SNicholas Piggin */ 3754388c9b3SNicholas Piggin crash_kexec_secondary(regs); 3764388c9b3SNicholas Piggin 3774388c9b3SNicholas Piggin /* 3784388c9b3SNicholas Piggin * No debugger or crash dump registered, print logs then 3794388c9b3SNicholas Piggin * panic. 3804388c9b3SNicholas Piggin */ 3814552d128SNicholas Piggin die("System Reset", regs, SIGABRT); 3824388c9b3SNicholas Piggin 3834388c9b3SNicholas Piggin mdelay(2*MSEC_PER_SEC); /* Wait a little while for others to print */ 3844388c9b3SNicholas Piggin add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE); 3854388c9b3SNicholas Piggin nmi_panic(regs, "System Reset"); 38614cf11afSPaul Mackerras 387c4f3b52cSNicholas Piggin out: 388c4f3b52cSNicholas Piggin #ifdef CONFIG_PPC_BOOK3S_64 389c4f3b52cSNicholas Piggin BUG_ON(get_paca()->in_nmi == 0); 390c4f3b52cSNicholas Piggin if (get_paca()->in_nmi > 1) 3914388c9b3SNicholas Piggin nmi_panic(regs, "Unrecoverable nested System Reset"); 392c4f3b52cSNicholas Piggin #endif 39314cf11afSPaul Mackerras /* Must die if the interrupt is not recoverable */ 39414cf11afSPaul Mackerras if (!(regs->msr & MSR_RI)) 3954388c9b3SNicholas Piggin nmi_panic(regs, "Unrecoverable System Reset"); 39614cf11afSPaul Mackerras 3972b4f3ac5SNicholas Piggin if (!nested) 3982b4f3ac5SNicholas Piggin nmi_exit(); 3992b4f3ac5SNicholas Piggin 40014cf11afSPaul Mackerras /* What should we do here? We could issue a shutdown or hard reset. */ 40114cf11afSPaul Mackerras } 4021e9b4507SMahesh Salgaonkar 40314cf11afSPaul Mackerras /* 40414cf11afSPaul Mackerras * I/O accesses can cause machine checks on powermacs. 40514cf11afSPaul Mackerras * Check if the NIP corresponds to the address of a sync 40614cf11afSPaul Mackerras * instruction for which there is an entry in the exception 40714cf11afSPaul Mackerras * table. 40814cf11afSPaul Mackerras * Note that the 601 only takes a machine check on TEA 40914cf11afSPaul Mackerras * (transfer error ack) signal assertion, and does not 41014cf11afSPaul Mackerras * set any of the top 16 bits of SRR1. 41114cf11afSPaul Mackerras * -- paulus. 41214cf11afSPaul Mackerras */ 41314cf11afSPaul Mackerras static inline int check_io_access(struct pt_regs *regs) 41414cf11afSPaul Mackerras { 41568a64357SBenjamin Herrenschmidt #ifdef CONFIG_PPC32 41614cf11afSPaul Mackerras unsigned long msr = regs->msr; 41714cf11afSPaul Mackerras const struct exception_table_entry *entry; 41814cf11afSPaul Mackerras unsigned int *nip = (unsigned int *)regs->nip; 41914cf11afSPaul Mackerras 42014cf11afSPaul Mackerras if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000))) 42114cf11afSPaul Mackerras && (entry = search_exception_tables(regs->nip)) != NULL) { 42214cf11afSPaul Mackerras /* 42314cf11afSPaul Mackerras * Check that it's a sync instruction, or somewhere 42414cf11afSPaul Mackerras * in the twi; isync; nop sequence that inb/inw/inl uses. 42514cf11afSPaul Mackerras * As the address is in the exception table 42614cf11afSPaul Mackerras * we should be able to read the instr there. 42714cf11afSPaul Mackerras * For the debug message, we look at the preceding 42814cf11afSPaul Mackerras * load or store. 42914cf11afSPaul Mackerras */ 430ddc6cd0dSChristophe Leroy if (*nip == PPC_INST_NOP) 43114cf11afSPaul Mackerras nip -= 2; 432ddc6cd0dSChristophe Leroy else if (*nip == PPC_INST_ISYNC) 43314cf11afSPaul Mackerras --nip; 434ddc6cd0dSChristophe Leroy if (*nip == PPC_INST_SYNC || (*nip >> 26) == OP_TRAP) { 43514cf11afSPaul Mackerras unsigned int rb; 43614cf11afSPaul Mackerras 43714cf11afSPaul Mackerras --nip; 43814cf11afSPaul Mackerras rb = (*nip >> 11) & 0x1f; 43914cf11afSPaul Mackerras printk(KERN_DEBUG "%s bad port %lx at %p\n", 44014cf11afSPaul Mackerras (*nip & 0x100)? "OUT to": "IN from", 44114cf11afSPaul Mackerras regs->gpr[rb] - _IO_BASE, nip); 44214cf11afSPaul Mackerras regs->msr |= MSR_RI; 44361a92f70SNicholas Piggin regs->nip = extable_fixup(entry); 44414cf11afSPaul Mackerras return 1; 44514cf11afSPaul Mackerras } 44614cf11afSPaul Mackerras } 44768a64357SBenjamin Herrenschmidt #endif /* CONFIG_PPC32 */ 44814cf11afSPaul Mackerras return 0; 44914cf11afSPaul Mackerras } 45014cf11afSPaul Mackerras 451172ae2e7SDave Kleikamp #ifdef CONFIG_PPC_ADV_DEBUG_REGS 45214cf11afSPaul Mackerras /* On 4xx, the reason for the machine check or program exception 45314cf11afSPaul Mackerras is in the ESR. */ 45414cf11afSPaul Mackerras #define get_reason(regs) ((regs)->dsisr) 45514cf11afSPaul Mackerras #define REASON_FP ESR_FP 45614cf11afSPaul Mackerras #define REASON_ILLEGAL (ESR_PIL | ESR_PUO) 45714cf11afSPaul Mackerras #define REASON_PRIVILEGED ESR_PPR 45814cf11afSPaul Mackerras #define REASON_TRAP ESR_PTR 45914cf11afSPaul Mackerras 46014cf11afSPaul Mackerras /* single-step stuff */ 46151ae8d4aSBharat Bhushan #define single_stepping(regs) (current->thread.debug.dbcr0 & DBCR0_IC) 46251ae8d4aSBharat Bhushan #define clear_single_step(regs) (current->thread.debug.dbcr0 &= ~DBCR0_IC) 46314cf11afSPaul Mackerras 46414cf11afSPaul Mackerras #else 46514cf11afSPaul Mackerras /* On non-4xx, the reason for the machine check or program 46614cf11afSPaul Mackerras exception is in the MSR. */ 46714cf11afSPaul Mackerras #define get_reason(regs) ((regs)->msr) 468d30a5a52SMichael Ellerman #define REASON_TM SRR1_PROGTM 469d30a5a52SMichael Ellerman #define REASON_FP SRR1_PROGFPE 470d30a5a52SMichael Ellerman #define REASON_ILLEGAL SRR1_PROGILL 471d30a5a52SMichael Ellerman #define REASON_PRIVILEGED SRR1_PROGPRIV 472d30a5a52SMichael Ellerman #define REASON_TRAP SRR1_PROGTRAP 47314cf11afSPaul Mackerras 47414cf11afSPaul Mackerras #define single_stepping(regs) ((regs)->msr & MSR_SE) 47514cf11afSPaul Mackerras #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE) 47614cf11afSPaul Mackerras #endif 47714cf11afSPaul Mackerras 4780d0935b3SMichael Ellerman #if defined(CONFIG_E500) 479fe04b112SScott Wood int machine_check_e500mc(struct pt_regs *regs) 480fe04b112SScott Wood { 481fe04b112SScott Wood unsigned long mcsr = mfspr(SPRN_MCSR); 482a4e89ffbSMatt Weber unsigned long pvr = mfspr(SPRN_PVR); 483fe04b112SScott Wood unsigned long reason = mcsr; 484fe04b112SScott Wood int recoverable = 1; 485fe04b112SScott Wood 48682a9a480SScott Wood if (reason & MCSR_LD) { 487cce1f106SShaohui Xie recoverable = fsl_rio_mcheck_exception(regs); 488cce1f106SShaohui Xie if (recoverable == 1) 489cce1f106SShaohui Xie goto silent_out; 490cce1f106SShaohui Xie } 491cce1f106SShaohui Xie 492fe04b112SScott Wood printk("Machine check in kernel mode.\n"); 493fe04b112SScott Wood printk("Caused by (from MCSR=%lx): ", reason); 494fe04b112SScott Wood 495fe04b112SScott Wood if (reason & MCSR_MCP) 496fe04b112SScott Wood printk("Machine Check Signal\n"); 497fe04b112SScott Wood 498fe04b112SScott Wood if (reason & MCSR_ICPERR) { 499fe04b112SScott Wood printk("Instruction Cache Parity Error\n"); 500fe04b112SScott Wood 501fe04b112SScott Wood /* 502fe04b112SScott Wood * This is recoverable by invalidating the i-cache. 503fe04b112SScott Wood */ 504fe04b112SScott Wood mtspr(SPRN_L1CSR1, mfspr(SPRN_L1CSR1) | L1CSR1_ICFI); 505fe04b112SScott Wood while (mfspr(SPRN_L1CSR1) & L1CSR1_ICFI) 506fe04b112SScott Wood ; 507fe04b112SScott Wood 508fe04b112SScott Wood /* 509fe04b112SScott Wood * This will generally be accompanied by an instruction 510fe04b112SScott Wood * fetch error report -- only treat MCSR_IF as fatal 511fe04b112SScott Wood * if it wasn't due to an L1 parity error. 512fe04b112SScott Wood */ 513fe04b112SScott Wood reason &= ~MCSR_IF; 514fe04b112SScott Wood } 515fe04b112SScott Wood 516fe04b112SScott Wood if (reason & MCSR_DCPERR_MC) { 517fe04b112SScott Wood printk("Data Cache Parity Error\n"); 51837caf9f2SKumar Gala 51937caf9f2SKumar Gala /* 52037caf9f2SKumar Gala * In write shadow mode we auto-recover from the error, but it 52137caf9f2SKumar Gala * may still get logged and cause a machine check. We should 52237caf9f2SKumar Gala * only treat the non-write shadow case as non-recoverable. 52337caf9f2SKumar Gala */ 524a4e89ffbSMatt Weber /* On e6500 core, L1 DCWS (Data cache write shadow mode) bit 525a4e89ffbSMatt Weber * is not implemented but L1 data cache always runs in write 526a4e89ffbSMatt Weber * shadow mode. Hence on data cache parity errors HW will 527a4e89ffbSMatt Weber * automatically invalidate the L1 Data Cache. 528a4e89ffbSMatt Weber */ 529a4e89ffbSMatt Weber if (PVR_VER(pvr) != PVR_VER_E6500) { 53037caf9f2SKumar Gala if (!(mfspr(SPRN_L1CSR2) & L1CSR2_DCWS)) 531fe04b112SScott Wood recoverable = 0; 532fe04b112SScott Wood } 533a4e89ffbSMatt Weber } 534fe04b112SScott Wood 535fe04b112SScott Wood if (reason & MCSR_L2MMU_MHIT) { 536fe04b112SScott Wood printk("Hit on multiple TLB entries\n"); 537fe04b112SScott Wood recoverable = 0; 538fe04b112SScott Wood } 539fe04b112SScott Wood 540fe04b112SScott Wood if (reason & MCSR_NMI) 541fe04b112SScott Wood printk("Non-maskable interrupt\n"); 542fe04b112SScott Wood 543fe04b112SScott Wood if (reason & MCSR_IF) { 544fe04b112SScott Wood printk("Instruction Fetch Error Report\n"); 545fe04b112SScott Wood recoverable = 0; 546fe04b112SScott Wood } 547fe04b112SScott Wood 548fe04b112SScott Wood if (reason & MCSR_LD) { 549fe04b112SScott Wood printk("Load Error Report\n"); 550fe04b112SScott Wood recoverable = 0; 551fe04b112SScott Wood } 552fe04b112SScott Wood 553fe04b112SScott Wood if (reason & MCSR_ST) { 554fe04b112SScott Wood printk("Store Error Report\n"); 555fe04b112SScott Wood recoverable = 0; 556fe04b112SScott Wood } 557fe04b112SScott Wood 558fe04b112SScott Wood if (reason & MCSR_LDG) { 559fe04b112SScott Wood printk("Guarded Load Error Report\n"); 560fe04b112SScott Wood recoverable = 0; 561fe04b112SScott Wood } 562fe04b112SScott Wood 563fe04b112SScott Wood if (reason & MCSR_TLBSYNC) 564fe04b112SScott Wood printk("Simultaneous tlbsync operations\n"); 565fe04b112SScott Wood 566fe04b112SScott Wood if (reason & MCSR_BSL2_ERR) { 567fe04b112SScott Wood printk("Level 2 Cache Error\n"); 568fe04b112SScott Wood recoverable = 0; 569fe04b112SScott Wood } 570fe04b112SScott Wood 571fe04b112SScott Wood if (reason & MCSR_MAV) { 572fe04b112SScott Wood u64 addr; 573fe04b112SScott Wood 574fe04b112SScott Wood addr = mfspr(SPRN_MCAR); 575fe04b112SScott Wood addr |= (u64)mfspr(SPRN_MCARU) << 32; 576fe04b112SScott Wood 577fe04b112SScott Wood printk("Machine Check %s Address: %#llx\n", 578fe04b112SScott Wood reason & MCSR_MEA ? "Effective" : "Physical", addr); 579fe04b112SScott Wood } 580fe04b112SScott Wood 581cce1f106SShaohui Xie silent_out: 582fe04b112SScott Wood mtspr(SPRN_MCSR, mcsr); 583fe04b112SScott Wood return mfspr(SPRN_MCSR) == 0 && recoverable; 584fe04b112SScott Wood } 585fe04b112SScott Wood 58647c0bd1aSBenjamin Herrenschmidt int machine_check_e500(struct pt_regs *regs) 58747c0bd1aSBenjamin Herrenschmidt { 58842bff234SMichael Ellerman unsigned long reason = mfspr(SPRN_MCSR); 58947c0bd1aSBenjamin Herrenschmidt 590cce1f106SShaohui Xie if (reason & MCSR_BUS_RBERR) { 591cce1f106SShaohui Xie if (fsl_rio_mcheck_exception(regs)) 592cce1f106SShaohui Xie return 1; 5934e0e3435SHongtao Jia if (fsl_pci_mcheck_exception(regs)) 5944e0e3435SHongtao Jia return 1; 595cce1f106SShaohui Xie } 596cce1f106SShaohui Xie 59714cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 59814cf11afSPaul Mackerras printk("Caused by (from MCSR=%lx): ", reason); 59914cf11afSPaul Mackerras 60014cf11afSPaul Mackerras if (reason & MCSR_MCP) 60114cf11afSPaul Mackerras printk("Machine Check Signal\n"); 60214cf11afSPaul Mackerras if (reason & MCSR_ICPERR) 60314cf11afSPaul Mackerras printk("Instruction Cache Parity Error\n"); 60414cf11afSPaul Mackerras if (reason & MCSR_DCP_PERR) 60514cf11afSPaul Mackerras printk("Data Cache Push Parity Error\n"); 60614cf11afSPaul Mackerras if (reason & MCSR_DCPERR) 60714cf11afSPaul Mackerras printk("Data Cache Parity Error\n"); 60814cf11afSPaul Mackerras if (reason & MCSR_BUS_IAERR) 60914cf11afSPaul Mackerras printk("Bus - Instruction Address Error\n"); 61014cf11afSPaul Mackerras if (reason & MCSR_BUS_RAERR) 61114cf11afSPaul Mackerras printk("Bus - Read Address Error\n"); 61214cf11afSPaul Mackerras if (reason & MCSR_BUS_WAERR) 61314cf11afSPaul Mackerras printk("Bus - Write Address Error\n"); 61414cf11afSPaul Mackerras if (reason & MCSR_BUS_IBERR) 61514cf11afSPaul Mackerras printk("Bus - Instruction Data Error\n"); 61614cf11afSPaul Mackerras if (reason & MCSR_BUS_RBERR) 61714cf11afSPaul Mackerras printk("Bus - Read Data Bus Error\n"); 61814cf11afSPaul Mackerras if (reason & MCSR_BUS_WBERR) 619c1528339SWladislav Wiebe printk("Bus - Write Data Bus Error\n"); 62014cf11afSPaul Mackerras if (reason & MCSR_BUS_IPERR) 62114cf11afSPaul Mackerras printk("Bus - Instruction Parity Error\n"); 62214cf11afSPaul Mackerras if (reason & MCSR_BUS_RPERR) 62314cf11afSPaul Mackerras printk("Bus - Read Parity Error\n"); 62447c0bd1aSBenjamin Herrenschmidt 62547c0bd1aSBenjamin Herrenschmidt return 0; 62647c0bd1aSBenjamin Herrenschmidt } 6274490c06bSKumar Gala 6284490c06bSKumar Gala int machine_check_generic(struct pt_regs *regs) 6294490c06bSKumar Gala { 6304490c06bSKumar Gala return 0; 6314490c06bSKumar Gala } 63214cf11afSPaul Mackerras #elif defined(CONFIG_E200) 63347c0bd1aSBenjamin Herrenschmidt int machine_check_e200(struct pt_regs *regs) 63447c0bd1aSBenjamin Herrenschmidt { 63542bff234SMichael Ellerman unsigned long reason = mfspr(SPRN_MCSR); 63647c0bd1aSBenjamin Herrenschmidt 63714cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 63814cf11afSPaul Mackerras printk("Caused by (from MCSR=%lx): ", reason); 63914cf11afSPaul Mackerras 64014cf11afSPaul Mackerras if (reason & MCSR_MCP) 64114cf11afSPaul Mackerras printk("Machine Check Signal\n"); 64214cf11afSPaul Mackerras if (reason & MCSR_CP_PERR) 64314cf11afSPaul Mackerras printk("Cache Push Parity Error\n"); 64414cf11afSPaul Mackerras if (reason & MCSR_CPERR) 64514cf11afSPaul Mackerras printk("Cache Parity Error\n"); 64614cf11afSPaul Mackerras if (reason & MCSR_EXCP_ERR) 64714cf11afSPaul Mackerras printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n"); 64814cf11afSPaul Mackerras if (reason & MCSR_BUS_IRERR) 64914cf11afSPaul Mackerras printk("Bus - Read Bus Error on instruction fetch\n"); 65014cf11afSPaul Mackerras if (reason & MCSR_BUS_DRERR) 65114cf11afSPaul Mackerras printk("Bus - Read Bus Error on data load\n"); 65214cf11afSPaul Mackerras if (reason & MCSR_BUS_WRERR) 65314cf11afSPaul Mackerras printk("Bus - Write Bus Error on buffered store or cache line push\n"); 65447c0bd1aSBenjamin Herrenschmidt 65547c0bd1aSBenjamin Herrenschmidt return 0; 65647c0bd1aSBenjamin Herrenschmidt } 6577f3f819eSMichael Ellerman #elif defined(CONFIG_PPC32) 65847c0bd1aSBenjamin Herrenschmidt int machine_check_generic(struct pt_regs *regs) 65947c0bd1aSBenjamin Herrenschmidt { 66042bff234SMichael Ellerman unsigned long reason = regs->msr; 66147c0bd1aSBenjamin Herrenschmidt 66214cf11afSPaul Mackerras printk("Machine check in kernel mode.\n"); 66314cf11afSPaul Mackerras printk("Caused by (from SRR1=%lx): ", reason); 66414cf11afSPaul Mackerras switch (reason & 0x601F0000) { 66514cf11afSPaul Mackerras case 0x80000: 66614cf11afSPaul Mackerras printk("Machine check signal\n"); 66714cf11afSPaul Mackerras break; 66814cf11afSPaul Mackerras case 0: /* for 601 */ 66914cf11afSPaul Mackerras case 0x40000: 67014cf11afSPaul Mackerras case 0x140000: /* 7450 MSS error and TEA */ 67114cf11afSPaul Mackerras printk("Transfer error ack signal\n"); 67214cf11afSPaul Mackerras break; 67314cf11afSPaul Mackerras case 0x20000: 67414cf11afSPaul Mackerras printk("Data parity error signal\n"); 67514cf11afSPaul Mackerras break; 67614cf11afSPaul Mackerras case 0x10000: 67714cf11afSPaul Mackerras printk("Address parity error signal\n"); 67814cf11afSPaul Mackerras break; 67914cf11afSPaul Mackerras case 0x20000000: 68014cf11afSPaul Mackerras printk("L1 Data Cache error\n"); 68114cf11afSPaul Mackerras break; 68214cf11afSPaul Mackerras case 0x40000000: 68314cf11afSPaul Mackerras printk("L1 Instruction Cache error\n"); 68414cf11afSPaul Mackerras break; 68514cf11afSPaul Mackerras case 0x00100000: 68614cf11afSPaul Mackerras printk("L2 data cache parity error\n"); 68714cf11afSPaul Mackerras break; 68814cf11afSPaul Mackerras default: 68914cf11afSPaul Mackerras printk("Unknown values in msr\n"); 69014cf11afSPaul Mackerras } 69175918a4bSOlof Johansson return 0; 69275918a4bSOlof Johansson } 69347c0bd1aSBenjamin Herrenschmidt #endif /* everything else */ 69475918a4bSOlof Johansson 69575918a4bSOlof Johansson void machine_check_exception(struct pt_regs *regs) 69675918a4bSOlof Johansson { 69775918a4bSOlof Johansson int recover = 0; 698b96672ddSNicholas Piggin bool nested = in_nmi(); 699b96672ddSNicholas Piggin if (!nested) 700b96672ddSNicholas Piggin nmi_enter(); 70175918a4bSOlof Johansson 702f886f0f6SNicholas Piggin /* 64s accounts the mce in machine_check_early when in HVMODE */ 703f886f0f6SNicholas Piggin if (!IS_ENABLED(CONFIG_PPC_BOOK3S_64) || !cpu_has_feature(CPU_FTR_HVMODE)) 70469111bacSChristoph Lameter __this_cpu_inc(irq_stat.mce_exceptions); 70589713ed1SAnton Blanchard 706d93b0ac0SMahesh Salgaonkar add_taint(TAINT_MACHINE_CHECK, LOCKDEP_NOW_UNRELIABLE); 707d93b0ac0SMahesh Salgaonkar 70847c0bd1aSBenjamin Herrenschmidt /* See if any machine dependent calls. In theory, we would want 70947c0bd1aSBenjamin Herrenschmidt * to call the CPU first, and call the ppc_md. one if the CPU 71047c0bd1aSBenjamin Herrenschmidt * one returns a positive number. However there is existing code 71147c0bd1aSBenjamin Herrenschmidt * that assumes the board gets a first chance, so let's keep it 71247c0bd1aSBenjamin Herrenschmidt * that way for now and fix things later. --BenH. 71347c0bd1aSBenjamin Herrenschmidt */ 71475918a4bSOlof Johansson if (ppc_md.machine_check_exception) 71575918a4bSOlof Johansson recover = ppc_md.machine_check_exception(regs); 71647c0bd1aSBenjamin Herrenschmidt else if (cur_cpu_spec->machine_check) 71747c0bd1aSBenjamin Herrenschmidt recover = cur_cpu_spec->machine_check(regs); 71875918a4bSOlof Johansson 71947c0bd1aSBenjamin Herrenschmidt if (recover > 0) 720ba12eedeSLi Zhong goto bail; 72175918a4bSOlof Johansson 722a443506bSAnton Blanchard if (debugger_fault_handler(regs)) 723ba12eedeSLi Zhong goto bail; 72475918a4bSOlof Johansson 72575918a4bSOlof Johansson if (check_io_access(regs)) 726ba12eedeSLi Zhong goto bail; 72775918a4bSOlof Johansson 7288dad3f92SPaul Mackerras die("Machine check", regs, SIGBUS); 72914cf11afSPaul Mackerras 73014cf11afSPaul Mackerras /* Must die if the interrupt is not recoverable */ 73114cf11afSPaul Mackerras if (!(regs->msr & MSR_RI)) 732b96672ddSNicholas Piggin nmi_panic(regs, "Unrecoverable Machine check"); 733ba12eedeSLi Zhong 734ba12eedeSLi Zhong bail: 735b96672ddSNicholas Piggin if (!nested) 736b96672ddSNicholas Piggin nmi_exit(); 73714cf11afSPaul Mackerras } 73814cf11afSPaul Mackerras 73914cf11afSPaul Mackerras void SMIException(struct pt_regs *regs) 74014cf11afSPaul Mackerras { 74114cf11afSPaul Mackerras die("System Management Interrupt", regs, SIGABRT); 74214cf11afSPaul Mackerras } 74314cf11afSPaul Mackerras 7445080332cSMichael Neuling #ifdef CONFIG_VSX 7455080332cSMichael Neuling static void p9_hmi_special_emu(struct pt_regs *regs) 7465080332cSMichael Neuling { 7475080332cSMichael Neuling unsigned int ra, rb, t, i, sel, instr, rc; 7485080332cSMichael Neuling const void __user *addr; 7495080332cSMichael Neuling u8 vbuf[16], *vdst; 7505080332cSMichael Neuling unsigned long ea, msr, msr_mask; 7515080332cSMichael Neuling bool swap; 7525080332cSMichael Neuling 7535080332cSMichael Neuling if (__get_user_inatomic(instr, (unsigned int __user *)regs->nip)) 7545080332cSMichael Neuling return; 7555080332cSMichael Neuling 7565080332cSMichael Neuling /* 7575080332cSMichael Neuling * lxvb16x opcode: 0x7c0006d8 7585080332cSMichael Neuling * lxvd2x opcode: 0x7c000698 7595080332cSMichael Neuling * lxvh8x opcode: 0x7c000658 7605080332cSMichael Neuling * lxvw4x opcode: 0x7c000618 7615080332cSMichael Neuling */ 7625080332cSMichael Neuling if ((instr & 0xfc00073e) != 0x7c000618) { 7635080332cSMichael Neuling pr_devel("HMI vec emu: not vector CI %i:%s[%d] nip=%016lx" 7645080332cSMichael Neuling " instr=%08x\n", 7655080332cSMichael Neuling smp_processor_id(), current->comm, current->pid, 7665080332cSMichael Neuling regs->nip, instr); 7675080332cSMichael Neuling return; 7685080332cSMichael Neuling } 7695080332cSMichael Neuling 7705080332cSMichael Neuling /* Grab vector registers into the task struct */ 7715080332cSMichael Neuling msr = regs->msr; /* Grab msr before we flush the bits */ 7725080332cSMichael Neuling flush_vsx_to_thread(current); 7735080332cSMichael Neuling enable_kernel_altivec(); 7745080332cSMichael Neuling 7755080332cSMichael Neuling /* 7765080332cSMichael Neuling * Is userspace running with a different endian (this is rare but 7775080332cSMichael Neuling * not impossible) 7785080332cSMichael Neuling */ 7795080332cSMichael Neuling swap = (msr & MSR_LE) != (MSR_KERNEL & MSR_LE); 7805080332cSMichael Neuling 7815080332cSMichael Neuling /* Decode the instruction */ 7825080332cSMichael Neuling ra = (instr >> 16) & 0x1f; 7835080332cSMichael Neuling rb = (instr >> 11) & 0x1f; 7845080332cSMichael Neuling t = (instr >> 21) & 0x1f; 7855080332cSMichael Neuling if (instr & 1) 7865080332cSMichael Neuling vdst = (u8 *)¤t->thread.vr_state.vr[t]; 7875080332cSMichael Neuling else 7885080332cSMichael Neuling vdst = (u8 *)¤t->thread.fp_state.fpr[t][0]; 7895080332cSMichael Neuling 7905080332cSMichael Neuling /* Grab the vector address */ 7915080332cSMichael Neuling ea = regs->gpr[rb] + (ra ? regs->gpr[ra] : 0); 7925080332cSMichael Neuling if (is_32bit_task()) 7935080332cSMichael Neuling ea &= 0xfffffffful; 7945080332cSMichael Neuling addr = (__force const void __user *)ea; 7955080332cSMichael Neuling 7965080332cSMichael Neuling /* Check it */ 7975080332cSMichael Neuling if (!access_ok(VERIFY_READ, addr, 16)) { 7985080332cSMichael Neuling pr_devel("HMI vec emu: bad access %i:%s[%d] nip=%016lx" 7995080332cSMichael Neuling " instr=%08x addr=%016lx\n", 8005080332cSMichael Neuling smp_processor_id(), current->comm, current->pid, 8015080332cSMichael Neuling regs->nip, instr, (unsigned long)addr); 8025080332cSMichael Neuling return; 8035080332cSMichael Neuling } 8045080332cSMichael Neuling 8055080332cSMichael Neuling /* Read the vector */ 8065080332cSMichael Neuling rc = 0; 8075080332cSMichael Neuling if ((unsigned long)addr & 0xfUL) 8085080332cSMichael Neuling /* unaligned case */ 8095080332cSMichael Neuling rc = __copy_from_user_inatomic(vbuf, addr, 16); 8105080332cSMichael Neuling else 8115080332cSMichael Neuling __get_user_atomic_128_aligned(vbuf, addr, rc); 8125080332cSMichael Neuling if (rc) { 8135080332cSMichael Neuling pr_devel("HMI vec emu: page fault %i:%s[%d] nip=%016lx" 8145080332cSMichael Neuling " instr=%08x addr=%016lx\n", 8155080332cSMichael Neuling smp_processor_id(), current->comm, current->pid, 8165080332cSMichael Neuling regs->nip, instr, (unsigned long)addr); 8175080332cSMichael Neuling return; 8185080332cSMichael Neuling } 8195080332cSMichael Neuling 8205080332cSMichael Neuling pr_devel("HMI vec emu: emulated vector CI %i:%s[%d] nip=%016lx" 8215080332cSMichael Neuling " instr=%08x addr=%016lx\n", 8225080332cSMichael Neuling smp_processor_id(), current->comm, current->pid, regs->nip, 8235080332cSMichael Neuling instr, (unsigned long) addr); 8245080332cSMichael Neuling 8255080332cSMichael Neuling /* Grab instruction "selector" */ 8265080332cSMichael Neuling sel = (instr >> 6) & 3; 8275080332cSMichael Neuling 8285080332cSMichael Neuling /* 8295080332cSMichael Neuling * Check to make sure the facility is actually enabled. This 8305080332cSMichael Neuling * could happen if we get a false positive hit. 8315080332cSMichael Neuling * 8325080332cSMichael Neuling * lxvd2x/lxvw4x always check MSR VSX sel = 0,2 8335080332cSMichael Neuling * lxvh8x/lxvb16x check MSR VSX or VEC depending on VSR used sel = 1,3 8345080332cSMichael Neuling */ 8355080332cSMichael Neuling msr_mask = MSR_VSX; 8365080332cSMichael Neuling if ((sel & 1) && (instr & 1)) /* lxvh8x & lxvb16x + VSR >= 32 */ 8375080332cSMichael Neuling msr_mask = MSR_VEC; 8385080332cSMichael Neuling if (!(msr & msr_mask)) { 8395080332cSMichael Neuling pr_devel("HMI vec emu: MSR fac clear %i:%s[%d] nip=%016lx" 8405080332cSMichael Neuling " instr=%08x msr:%016lx\n", 8415080332cSMichael Neuling smp_processor_id(), current->comm, current->pid, 8425080332cSMichael Neuling regs->nip, instr, msr); 8435080332cSMichael Neuling return; 8445080332cSMichael Neuling } 8455080332cSMichael Neuling 8465080332cSMichael Neuling /* Do logging here before we modify sel based on endian */ 8475080332cSMichael Neuling switch (sel) { 8485080332cSMichael Neuling case 0: /* lxvw4x */ 8495080332cSMichael Neuling PPC_WARN_EMULATED(lxvw4x, regs); 8505080332cSMichael Neuling break; 8515080332cSMichael Neuling case 1: /* lxvh8x */ 8525080332cSMichael Neuling PPC_WARN_EMULATED(lxvh8x, regs); 8535080332cSMichael Neuling break; 8545080332cSMichael Neuling case 2: /* lxvd2x */ 8555080332cSMichael Neuling PPC_WARN_EMULATED(lxvd2x, regs); 8565080332cSMichael Neuling break; 8575080332cSMichael Neuling case 3: /* lxvb16x */ 8585080332cSMichael Neuling PPC_WARN_EMULATED(lxvb16x, regs); 8595080332cSMichael Neuling break; 8605080332cSMichael Neuling } 8615080332cSMichael Neuling 8625080332cSMichael Neuling #ifdef __LITTLE_ENDIAN__ 8635080332cSMichael Neuling /* 8645080332cSMichael Neuling * An LE kernel stores the vector in the task struct as an LE 8655080332cSMichael Neuling * byte array (effectively swapping both the components and 8665080332cSMichael Neuling * the content of the components). Those instructions expect 8675080332cSMichael Neuling * the components to remain in ascending address order, so we 8685080332cSMichael Neuling * swap them back. 8695080332cSMichael Neuling * 8705080332cSMichael Neuling * If we are running a BE user space, the expectation is that 8715080332cSMichael Neuling * of a simple memcpy, so forcing the emulation to look like 8725080332cSMichael Neuling * a lxvb16x should do the trick. 8735080332cSMichael Neuling */ 8745080332cSMichael Neuling if (swap) 8755080332cSMichael Neuling sel = 3; 8765080332cSMichael Neuling 8775080332cSMichael Neuling switch (sel) { 8785080332cSMichael Neuling case 0: /* lxvw4x */ 8795080332cSMichael Neuling for (i = 0; i < 4; i++) 8805080332cSMichael Neuling ((u32 *)vdst)[i] = ((u32 *)vbuf)[3-i]; 8815080332cSMichael Neuling break; 8825080332cSMichael Neuling case 1: /* lxvh8x */ 8835080332cSMichael Neuling for (i = 0; i < 8; i++) 8845080332cSMichael Neuling ((u16 *)vdst)[i] = ((u16 *)vbuf)[7-i]; 8855080332cSMichael Neuling break; 8865080332cSMichael Neuling case 2: /* lxvd2x */ 8875080332cSMichael Neuling for (i = 0; i < 2; i++) 8885080332cSMichael Neuling ((u64 *)vdst)[i] = ((u64 *)vbuf)[1-i]; 8895080332cSMichael Neuling break; 8905080332cSMichael Neuling case 3: /* lxvb16x */ 8915080332cSMichael Neuling for (i = 0; i < 16; i++) 8925080332cSMichael Neuling vdst[i] = vbuf[15-i]; 8935080332cSMichael Neuling break; 8945080332cSMichael Neuling } 8955080332cSMichael Neuling #else /* __LITTLE_ENDIAN__ */ 8965080332cSMichael Neuling /* On a big endian kernel, a BE userspace only needs a memcpy */ 8975080332cSMichael Neuling if (!swap) 8985080332cSMichael Neuling sel = 3; 8995080332cSMichael Neuling 9005080332cSMichael Neuling /* Otherwise, we need to swap the content of the components */ 9015080332cSMichael Neuling switch (sel) { 9025080332cSMichael Neuling case 0: /* lxvw4x */ 9035080332cSMichael Neuling for (i = 0; i < 4; i++) 9045080332cSMichael Neuling ((u32 *)vdst)[i] = cpu_to_le32(((u32 *)vbuf)[i]); 9055080332cSMichael Neuling break; 9065080332cSMichael Neuling case 1: /* lxvh8x */ 9075080332cSMichael Neuling for (i = 0; i < 8; i++) 9085080332cSMichael Neuling ((u16 *)vdst)[i] = cpu_to_le16(((u16 *)vbuf)[i]); 9095080332cSMichael Neuling break; 9105080332cSMichael Neuling case 2: /* lxvd2x */ 9115080332cSMichael Neuling for (i = 0; i < 2; i++) 9125080332cSMichael Neuling ((u64 *)vdst)[i] = cpu_to_le64(((u64 *)vbuf)[i]); 9135080332cSMichael Neuling break; 9145080332cSMichael Neuling case 3: /* lxvb16x */ 9155080332cSMichael Neuling memcpy(vdst, vbuf, 16); 9165080332cSMichael Neuling break; 9175080332cSMichael Neuling } 9185080332cSMichael Neuling #endif /* !__LITTLE_ENDIAN__ */ 9195080332cSMichael Neuling 9205080332cSMichael Neuling /* Go to next instruction */ 9215080332cSMichael Neuling regs->nip += 4; 9225080332cSMichael Neuling } 9235080332cSMichael Neuling #endif /* CONFIG_VSX */ 9245080332cSMichael Neuling 9250869b6fdSMahesh Salgaonkar void handle_hmi_exception(struct pt_regs *regs) 9260869b6fdSMahesh Salgaonkar { 9270869b6fdSMahesh Salgaonkar struct pt_regs *old_regs; 9280869b6fdSMahesh Salgaonkar 9290869b6fdSMahesh Salgaonkar old_regs = set_irq_regs(regs); 9300869b6fdSMahesh Salgaonkar irq_enter(); 9310869b6fdSMahesh Salgaonkar 9325080332cSMichael Neuling #ifdef CONFIG_VSX 9335080332cSMichael Neuling /* Real mode flagged P9 special emu is needed */ 9345080332cSMichael Neuling if (local_paca->hmi_p9_special_emu) { 9355080332cSMichael Neuling local_paca->hmi_p9_special_emu = 0; 9365080332cSMichael Neuling 9375080332cSMichael Neuling /* 9385080332cSMichael Neuling * We don't want to take page faults while doing the 9395080332cSMichael Neuling * emulation, we just replay the instruction if necessary. 9405080332cSMichael Neuling */ 9415080332cSMichael Neuling pagefault_disable(); 9425080332cSMichael Neuling p9_hmi_special_emu(regs); 9435080332cSMichael Neuling pagefault_enable(); 9445080332cSMichael Neuling } 9455080332cSMichael Neuling #endif /* CONFIG_VSX */ 9465080332cSMichael Neuling 9470869b6fdSMahesh Salgaonkar if (ppc_md.handle_hmi_exception) 9480869b6fdSMahesh Salgaonkar ppc_md.handle_hmi_exception(regs); 9490869b6fdSMahesh Salgaonkar 9500869b6fdSMahesh Salgaonkar irq_exit(); 9510869b6fdSMahesh Salgaonkar set_irq_regs(old_regs); 9520869b6fdSMahesh Salgaonkar } 9530869b6fdSMahesh Salgaonkar 954dc1c1ca3SStephen Rothwell void unknown_exception(struct pt_regs *regs) 95514cf11afSPaul Mackerras { 956ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 957ba12eedeSLi Zhong 95814cf11afSPaul Mackerras printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", 95914cf11afSPaul Mackerras regs->nip, regs->msr, regs->trap); 96014cf11afSPaul Mackerras 96114cf11afSPaul Mackerras _exception(SIGTRAP, regs, 0, 0); 962ba12eedeSLi Zhong 963ba12eedeSLi Zhong exception_exit(prev_state); 96414cf11afSPaul Mackerras } 96514cf11afSPaul Mackerras 966dc1c1ca3SStephen Rothwell void instruction_breakpoint_exception(struct pt_regs *regs) 96714cf11afSPaul Mackerras { 968ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 969ba12eedeSLi Zhong 97014cf11afSPaul Mackerras if (notify_die(DIE_IABR_MATCH, "iabr_match", regs, 5, 97114cf11afSPaul Mackerras 5, SIGTRAP) == NOTIFY_STOP) 972ba12eedeSLi Zhong goto bail; 97314cf11afSPaul Mackerras if (debugger_iabr_match(regs)) 974ba12eedeSLi Zhong goto bail; 97514cf11afSPaul Mackerras _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); 976ba12eedeSLi Zhong 977ba12eedeSLi Zhong bail: 978ba12eedeSLi Zhong exception_exit(prev_state); 97914cf11afSPaul Mackerras } 98014cf11afSPaul Mackerras 98114cf11afSPaul Mackerras void RunModeException(struct pt_regs *regs) 98214cf11afSPaul Mackerras { 98314cf11afSPaul Mackerras _exception(SIGTRAP, regs, 0, 0); 98414cf11afSPaul Mackerras } 98514cf11afSPaul Mackerras 98603465f89SNicholas Piggin void single_step_exception(struct pt_regs *regs) 98714cf11afSPaul Mackerras { 988ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 989ba12eedeSLi Zhong 9902538c2d0SK.Prasad clear_single_step(regs); 99114cf11afSPaul Mackerras 9926cc89badSNaveen N. Rao if (kprobe_post_handler(regs)) 9936cc89badSNaveen N. Rao return; 9946cc89badSNaveen N. Rao 99514cf11afSPaul Mackerras if (notify_die(DIE_SSTEP, "single_step", regs, 5, 99614cf11afSPaul Mackerras 5, SIGTRAP) == NOTIFY_STOP) 997ba12eedeSLi Zhong goto bail; 99814cf11afSPaul Mackerras if (debugger_sstep(regs)) 999ba12eedeSLi Zhong goto bail; 100014cf11afSPaul Mackerras 100114cf11afSPaul Mackerras _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip); 1002ba12eedeSLi Zhong 1003ba12eedeSLi Zhong bail: 1004ba12eedeSLi Zhong exception_exit(prev_state); 100514cf11afSPaul Mackerras } 100603465f89SNicholas Piggin NOKPROBE_SYMBOL(single_step_exception); 100714cf11afSPaul Mackerras 100814cf11afSPaul Mackerras /* 100914cf11afSPaul Mackerras * After we have successfully emulated an instruction, we have to 101014cf11afSPaul Mackerras * check if the instruction was being single-stepped, and if so, 101114cf11afSPaul Mackerras * pretend we got a single-step exception. This was pointed out 101214cf11afSPaul Mackerras * by Kumar Gala. -- paulus 101314cf11afSPaul Mackerras */ 10148dad3f92SPaul Mackerras static void emulate_single_step(struct pt_regs *regs) 101514cf11afSPaul Mackerras { 10162538c2d0SK.Prasad if (single_stepping(regs)) 10172538c2d0SK.Prasad single_step_exception(regs); 101814cf11afSPaul Mackerras } 101914cf11afSPaul Mackerras 10205fad293bSKumar Gala static inline int __parse_fpscr(unsigned long fpscr) 1021dc1c1ca3SStephen Rothwell { 10225fad293bSKumar Gala int ret = 0; 1023dc1c1ca3SStephen Rothwell 1024dc1c1ca3SStephen Rothwell /* Invalid operation */ 1025dc1c1ca3SStephen Rothwell if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX)) 10265fad293bSKumar Gala ret = FPE_FLTINV; 1027dc1c1ca3SStephen Rothwell 1028dc1c1ca3SStephen Rothwell /* Overflow */ 1029dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_OE) && (fpscr & FPSCR_OX)) 10305fad293bSKumar Gala ret = FPE_FLTOVF; 1031dc1c1ca3SStephen Rothwell 1032dc1c1ca3SStephen Rothwell /* Underflow */ 1033dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_UE) && (fpscr & FPSCR_UX)) 10345fad293bSKumar Gala ret = FPE_FLTUND; 1035dc1c1ca3SStephen Rothwell 1036dc1c1ca3SStephen Rothwell /* Divide by zero */ 1037dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_ZE) && (fpscr & FPSCR_ZX)) 10385fad293bSKumar Gala ret = FPE_FLTDIV; 1039dc1c1ca3SStephen Rothwell 1040dc1c1ca3SStephen Rothwell /* Inexact result */ 1041dc1c1ca3SStephen Rothwell else if ((fpscr & FPSCR_XE) && (fpscr & FPSCR_XX)) 10425fad293bSKumar Gala ret = FPE_FLTRES; 10435fad293bSKumar Gala 10445fad293bSKumar Gala return ret; 10455fad293bSKumar Gala } 10465fad293bSKumar Gala 10475fad293bSKumar Gala static void parse_fpe(struct pt_regs *regs) 10485fad293bSKumar Gala { 10495fad293bSKumar Gala int code = 0; 10505fad293bSKumar Gala 10515fad293bSKumar Gala flush_fp_to_thread(current); 10525fad293bSKumar Gala 1053de79f7b9SPaul Mackerras code = __parse_fpscr(current->thread.fp_state.fpscr); 1054dc1c1ca3SStephen Rothwell 1055dc1c1ca3SStephen Rothwell _exception(SIGFPE, regs, code, regs->nip); 1056dc1c1ca3SStephen Rothwell } 1057dc1c1ca3SStephen Rothwell 1058dc1c1ca3SStephen Rothwell /* 1059dc1c1ca3SStephen Rothwell * Illegal instruction emulation support. Originally written to 106014cf11afSPaul Mackerras * provide the PVR to user applications using the mfspr rd, PVR. 106114cf11afSPaul Mackerras * Return non-zero if we can't emulate, or -EFAULT if the associated 106214cf11afSPaul Mackerras * memory access caused an access fault. Return zero on success. 106314cf11afSPaul Mackerras * 106414cf11afSPaul Mackerras * There are a couple of ways to do this, either "decode" the instruction 106514cf11afSPaul Mackerras * or directly match lots of bits. In this case, matching lots of 106614cf11afSPaul Mackerras * bits is faster and easier. 106786417780SPaul Mackerras * 106814cf11afSPaul Mackerras */ 106914cf11afSPaul Mackerras static int emulate_string_inst(struct pt_regs *regs, u32 instword) 107014cf11afSPaul Mackerras { 107114cf11afSPaul Mackerras u8 rT = (instword >> 21) & 0x1f; 107214cf11afSPaul Mackerras u8 rA = (instword >> 16) & 0x1f; 107314cf11afSPaul Mackerras u8 NB_RB = (instword >> 11) & 0x1f; 107414cf11afSPaul Mackerras u32 num_bytes; 107514cf11afSPaul Mackerras unsigned long EA; 107614cf11afSPaul Mackerras int pos = 0; 107714cf11afSPaul Mackerras 107814cf11afSPaul Mackerras /* Early out if we are an invalid form of lswx */ 107916c57b36SKumar Gala if ((instword & PPC_INST_STRING_MASK) == PPC_INST_LSWX) 108014cf11afSPaul Mackerras if ((rT == rA) || (rT == NB_RB)) 108114cf11afSPaul Mackerras return -EINVAL; 108214cf11afSPaul Mackerras 108314cf11afSPaul Mackerras EA = (rA == 0) ? 0 : regs->gpr[rA]; 108414cf11afSPaul Mackerras 108516c57b36SKumar Gala switch (instword & PPC_INST_STRING_MASK) { 108616c57b36SKumar Gala case PPC_INST_LSWX: 108716c57b36SKumar Gala case PPC_INST_STSWX: 108814cf11afSPaul Mackerras EA += NB_RB; 108914cf11afSPaul Mackerras num_bytes = regs->xer & 0x7f; 109014cf11afSPaul Mackerras break; 109116c57b36SKumar Gala case PPC_INST_LSWI: 109216c57b36SKumar Gala case PPC_INST_STSWI: 109314cf11afSPaul Mackerras num_bytes = (NB_RB == 0) ? 32 : NB_RB; 109414cf11afSPaul Mackerras break; 109514cf11afSPaul Mackerras default: 109614cf11afSPaul Mackerras return -EINVAL; 109714cf11afSPaul Mackerras } 109814cf11afSPaul Mackerras 109914cf11afSPaul Mackerras while (num_bytes != 0) 110014cf11afSPaul Mackerras { 110114cf11afSPaul Mackerras u8 val; 110214cf11afSPaul Mackerras u32 shift = 8 * (3 - (pos & 0x3)); 110314cf11afSPaul Mackerras 110480aa0fb4SJames Yang /* if process is 32-bit, clear upper 32 bits of EA */ 110580aa0fb4SJames Yang if ((regs->msr & MSR_64BIT) == 0) 110680aa0fb4SJames Yang EA &= 0xFFFFFFFF; 110780aa0fb4SJames Yang 110816c57b36SKumar Gala switch ((instword & PPC_INST_STRING_MASK)) { 110916c57b36SKumar Gala case PPC_INST_LSWX: 111016c57b36SKumar Gala case PPC_INST_LSWI: 111114cf11afSPaul Mackerras if (get_user(val, (u8 __user *)EA)) 111214cf11afSPaul Mackerras return -EFAULT; 111314cf11afSPaul Mackerras /* first time updating this reg, 111414cf11afSPaul Mackerras * zero it out */ 111514cf11afSPaul Mackerras if (pos == 0) 111614cf11afSPaul Mackerras regs->gpr[rT] = 0; 111714cf11afSPaul Mackerras regs->gpr[rT] |= val << shift; 111814cf11afSPaul Mackerras break; 111916c57b36SKumar Gala case PPC_INST_STSWI: 112016c57b36SKumar Gala case PPC_INST_STSWX: 112114cf11afSPaul Mackerras val = regs->gpr[rT] >> shift; 112214cf11afSPaul Mackerras if (put_user(val, (u8 __user *)EA)) 112314cf11afSPaul Mackerras return -EFAULT; 112414cf11afSPaul Mackerras break; 112514cf11afSPaul Mackerras } 112614cf11afSPaul Mackerras /* move EA to next address */ 112714cf11afSPaul Mackerras EA += 1; 112814cf11afSPaul Mackerras num_bytes--; 112914cf11afSPaul Mackerras 113014cf11afSPaul Mackerras /* manage our position within the register */ 113114cf11afSPaul Mackerras if (++pos == 4) { 113214cf11afSPaul Mackerras pos = 0; 113314cf11afSPaul Mackerras if (++rT == 32) 113414cf11afSPaul Mackerras rT = 0; 113514cf11afSPaul Mackerras } 113614cf11afSPaul Mackerras } 113714cf11afSPaul Mackerras 113814cf11afSPaul Mackerras return 0; 113914cf11afSPaul Mackerras } 114014cf11afSPaul Mackerras 1141c3412dcbSWill Schmidt static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword) 1142c3412dcbSWill Schmidt { 1143c3412dcbSWill Schmidt u32 ra,rs; 1144c3412dcbSWill Schmidt unsigned long tmp; 1145c3412dcbSWill Schmidt 1146c3412dcbSWill Schmidt ra = (instword >> 16) & 0x1f; 1147c3412dcbSWill Schmidt rs = (instword >> 21) & 0x1f; 1148c3412dcbSWill Schmidt 1149c3412dcbSWill Schmidt tmp = regs->gpr[rs]; 1150c3412dcbSWill Schmidt tmp = tmp - ((tmp >> 1) & 0x5555555555555555ULL); 1151c3412dcbSWill Schmidt tmp = (tmp & 0x3333333333333333ULL) + ((tmp >> 2) & 0x3333333333333333ULL); 1152c3412dcbSWill Schmidt tmp = (tmp + (tmp >> 4)) & 0x0f0f0f0f0f0f0f0fULL; 1153c3412dcbSWill Schmidt regs->gpr[ra] = tmp; 1154c3412dcbSWill Schmidt 1155c3412dcbSWill Schmidt return 0; 1156c3412dcbSWill Schmidt } 1157c3412dcbSWill Schmidt 1158c1469f13SKumar Gala static int emulate_isel(struct pt_regs *regs, u32 instword) 1159c1469f13SKumar Gala { 1160c1469f13SKumar Gala u8 rT = (instword >> 21) & 0x1f; 1161c1469f13SKumar Gala u8 rA = (instword >> 16) & 0x1f; 1162c1469f13SKumar Gala u8 rB = (instword >> 11) & 0x1f; 1163c1469f13SKumar Gala u8 BC = (instword >> 6) & 0x1f; 1164c1469f13SKumar Gala u8 bit; 1165c1469f13SKumar Gala unsigned long tmp; 1166c1469f13SKumar Gala 1167c1469f13SKumar Gala tmp = (rA == 0) ? 0 : regs->gpr[rA]; 1168c1469f13SKumar Gala bit = (regs->ccr >> (31 - BC)) & 0x1; 1169c1469f13SKumar Gala 1170c1469f13SKumar Gala regs->gpr[rT] = bit ? tmp : regs->gpr[rB]; 1171c1469f13SKumar Gala 1172c1469f13SKumar Gala return 0; 1173c1469f13SKumar Gala } 1174c1469f13SKumar Gala 11756ce6c629SMichael Neuling #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 11766ce6c629SMichael Neuling static inline bool tm_abort_check(struct pt_regs *regs, int cause) 11776ce6c629SMichael Neuling { 11786ce6c629SMichael Neuling /* If we're emulating a load/store in an active transaction, we cannot 11796ce6c629SMichael Neuling * emulate it as the kernel operates in transaction suspended context. 11806ce6c629SMichael Neuling * We need to abort the transaction. This creates a persistent TM 11816ce6c629SMichael Neuling * abort so tell the user what caused it with a new code. 11826ce6c629SMichael Neuling */ 11836ce6c629SMichael Neuling if (MSR_TM_TRANSACTIONAL(regs->msr)) { 11846ce6c629SMichael Neuling tm_enable(); 11856ce6c629SMichael Neuling tm_abort(cause); 11866ce6c629SMichael Neuling return true; 11876ce6c629SMichael Neuling } 11886ce6c629SMichael Neuling return false; 11896ce6c629SMichael Neuling } 11906ce6c629SMichael Neuling #else 11916ce6c629SMichael Neuling static inline bool tm_abort_check(struct pt_regs *regs, int reason) 11926ce6c629SMichael Neuling { 11936ce6c629SMichael Neuling return false; 11946ce6c629SMichael Neuling } 11956ce6c629SMichael Neuling #endif 11966ce6c629SMichael Neuling 119714cf11afSPaul Mackerras static int emulate_instruction(struct pt_regs *regs) 119814cf11afSPaul Mackerras { 119914cf11afSPaul Mackerras u32 instword; 120014cf11afSPaul Mackerras u32 rd; 120114cf11afSPaul Mackerras 12024288e343SAnton Blanchard if (!user_mode(regs)) 120314cf11afSPaul Mackerras return -EINVAL; 120414cf11afSPaul Mackerras CHECK_FULL_REGS(regs); 120514cf11afSPaul Mackerras 120614cf11afSPaul Mackerras if (get_user(instword, (u32 __user *)(regs->nip))) 120714cf11afSPaul Mackerras return -EFAULT; 120814cf11afSPaul Mackerras 120914cf11afSPaul Mackerras /* Emulate the mfspr rD, PVR. */ 121016c57b36SKumar Gala if ((instword & PPC_INST_MFSPR_PVR_MASK) == PPC_INST_MFSPR_PVR) { 1211eecff81dSAnton Blanchard PPC_WARN_EMULATED(mfpvr, regs); 121214cf11afSPaul Mackerras rd = (instword >> 21) & 0x1f; 121314cf11afSPaul Mackerras regs->gpr[rd] = mfspr(SPRN_PVR); 121414cf11afSPaul Mackerras return 0; 121514cf11afSPaul Mackerras } 121614cf11afSPaul Mackerras 121714cf11afSPaul Mackerras /* Emulating the dcba insn is just a no-op. */ 121880947e7cSGeert Uytterhoeven if ((instword & PPC_INST_DCBA_MASK) == PPC_INST_DCBA) { 1219eecff81dSAnton Blanchard PPC_WARN_EMULATED(dcba, regs); 122014cf11afSPaul Mackerras return 0; 122180947e7cSGeert Uytterhoeven } 122214cf11afSPaul Mackerras 122314cf11afSPaul Mackerras /* Emulate the mcrxr insn. */ 122416c57b36SKumar Gala if ((instword & PPC_INST_MCRXR_MASK) == PPC_INST_MCRXR) { 122586417780SPaul Mackerras int shift = (instword >> 21) & 0x1c; 122614cf11afSPaul Mackerras unsigned long msk = 0xf0000000UL >> shift; 122714cf11afSPaul Mackerras 1228eecff81dSAnton Blanchard PPC_WARN_EMULATED(mcrxr, regs); 122914cf11afSPaul Mackerras regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk); 123014cf11afSPaul Mackerras regs->xer &= ~0xf0000000UL; 123114cf11afSPaul Mackerras return 0; 123214cf11afSPaul Mackerras } 123314cf11afSPaul Mackerras 123414cf11afSPaul Mackerras /* Emulate load/store string insn. */ 123580947e7cSGeert Uytterhoeven if ((instword & PPC_INST_STRING_GEN_MASK) == PPC_INST_STRING) { 12366ce6c629SMichael Neuling if (tm_abort_check(regs, 12376ce6c629SMichael Neuling TM_CAUSE_EMULATE | TM_CAUSE_PERSISTENT)) 12386ce6c629SMichael Neuling return -EINVAL; 1239eecff81dSAnton Blanchard PPC_WARN_EMULATED(string, regs); 124014cf11afSPaul Mackerras return emulate_string_inst(regs, instword); 124180947e7cSGeert Uytterhoeven } 124214cf11afSPaul Mackerras 1243c3412dcbSWill Schmidt /* Emulate the popcntb (Population Count Bytes) instruction. */ 124416c57b36SKumar Gala if ((instword & PPC_INST_POPCNTB_MASK) == PPC_INST_POPCNTB) { 1245eecff81dSAnton Blanchard PPC_WARN_EMULATED(popcntb, regs); 1246c3412dcbSWill Schmidt return emulate_popcntb_inst(regs, instword); 1247c3412dcbSWill Schmidt } 1248c3412dcbSWill Schmidt 1249c1469f13SKumar Gala /* Emulate isel (Integer Select) instruction */ 125016c57b36SKumar Gala if ((instword & PPC_INST_ISEL_MASK) == PPC_INST_ISEL) { 1251eecff81dSAnton Blanchard PPC_WARN_EMULATED(isel, regs); 1252c1469f13SKumar Gala return emulate_isel(regs, instword); 1253c1469f13SKumar Gala } 1254c1469f13SKumar Gala 12559863c28aSJames Yang /* Emulate sync instruction variants */ 12569863c28aSJames Yang if ((instword & PPC_INST_SYNC_MASK) == PPC_INST_SYNC) { 12579863c28aSJames Yang PPC_WARN_EMULATED(sync, regs); 12589863c28aSJames Yang asm volatile("sync"); 12599863c28aSJames Yang return 0; 12609863c28aSJames Yang } 12619863c28aSJames Yang 1262efcac658SAlexey Kardashevskiy #ifdef CONFIG_PPC64 1263efcac658SAlexey Kardashevskiy /* Emulate the mfspr rD, DSCR. */ 126473d2fb75SAnton Blanchard if ((((instword & PPC_INST_MFSPR_DSCR_USER_MASK) == 126573d2fb75SAnton Blanchard PPC_INST_MFSPR_DSCR_USER) || 126673d2fb75SAnton Blanchard ((instword & PPC_INST_MFSPR_DSCR_MASK) == 126773d2fb75SAnton Blanchard PPC_INST_MFSPR_DSCR)) && 1268efcac658SAlexey Kardashevskiy cpu_has_feature(CPU_FTR_DSCR)) { 1269efcac658SAlexey Kardashevskiy PPC_WARN_EMULATED(mfdscr, regs); 1270efcac658SAlexey Kardashevskiy rd = (instword >> 21) & 0x1f; 1271efcac658SAlexey Kardashevskiy regs->gpr[rd] = mfspr(SPRN_DSCR); 1272efcac658SAlexey Kardashevskiy return 0; 1273efcac658SAlexey Kardashevskiy } 1274efcac658SAlexey Kardashevskiy /* Emulate the mtspr DSCR, rD. */ 127573d2fb75SAnton Blanchard if ((((instword & PPC_INST_MTSPR_DSCR_USER_MASK) == 127673d2fb75SAnton Blanchard PPC_INST_MTSPR_DSCR_USER) || 127773d2fb75SAnton Blanchard ((instword & PPC_INST_MTSPR_DSCR_MASK) == 127873d2fb75SAnton Blanchard PPC_INST_MTSPR_DSCR)) && 1279efcac658SAlexey Kardashevskiy cpu_has_feature(CPU_FTR_DSCR)) { 1280efcac658SAlexey Kardashevskiy PPC_WARN_EMULATED(mtdscr, regs); 1281efcac658SAlexey Kardashevskiy rd = (instword >> 21) & 0x1f; 128200ca0de0SAnton Blanchard current->thread.dscr = regs->gpr[rd]; 1283efcac658SAlexey Kardashevskiy current->thread.dscr_inherit = 1; 128400ca0de0SAnton Blanchard mtspr(SPRN_DSCR, current->thread.dscr); 1285efcac658SAlexey Kardashevskiy return 0; 1286efcac658SAlexey Kardashevskiy } 1287efcac658SAlexey Kardashevskiy #endif 1288efcac658SAlexey Kardashevskiy 128914cf11afSPaul Mackerras return -EINVAL; 129014cf11afSPaul Mackerras } 129114cf11afSPaul Mackerras 129273c9ceabSJeremy Fitzhardinge int is_valid_bugaddr(unsigned long addr) 129314cf11afSPaul Mackerras { 129473c9ceabSJeremy Fitzhardinge return is_kernel_addr(addr); 129514cf11afSPaul Mackerras } 129614cf11afSPaul Mackerras 12973a3b5aa6SKevin Hao #ifdef CONFIG_MATH_EMULATION 12983a3b5aa6SKevin Hao static int emulate_math(struct pt_regs *regs) 12993a3b5aa6SKevin Hao { 13003a3b5aa6SKevin Hao int ret; 13013a3b5aa6SKevin Hao extern int do_mathemu(struct pt_regs *regs); 13023a3b5aa6SKevin Hao 13033a3b5aa6SKevin Hao ret = do_mathemu(regs); 13043a3b5aa6SKevin Hao if (ret >= 0) 13053a3b5aa6SKevin Hao PPC_WARN_EMULATED(math, regs); 13063a3b5aa6SKevin Hao 13073a3b5aa6SKevin Hao switch (ret) { 13083a3b5aa6SKevin Hao case 0: 13093a3b5aa6SKevin Hao emulate_single_step(regs); 13103a3b5aa6SKevin Hao return 0; 13113a3b5aa6SKevin Hao case 1: { 13123a3b5aa6SKevin Hao int code = 0; 1313de79f7b9SPaul Mackerras code = __parse_fpscr(current->thread.fp_state.fpscr); 13143a3b5aa6SKevin Hao _exception(SIGFPE, regs, code, regs->nip); 13153a3b5aa6SKevin Hao return 0; 13163a3b5aa6SKevin Hao } 13173a3b5aa6SKevin Hao case -EFAULT: 13183a3b5aa6SKevin Hao _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); 13193a3b5aa6SKevin Hao return 0; 13203a3b5aa6SKevin Hao } 13213a3b5aa6SKevin Hao 13223a3b5aa6SKevin Hao return -1; 13233a3b5aa6SKevin Hao } 13243a3b5aa6SKevin Hao #else 13253a3b5aa6SKevin Hao static inline int emulate_math(struct pt_regs *regs) { return -1; } 13263a3b5aa6SKevin Hao #endif 13273a3b5aa6SKevin Hao 132803465f89SNicholas Piggin void program_check_exception(struct pt_regs *regs) 132914cf11afSPaul Mackerras { 1330ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 133114cf11afSPaul Mackerras unsigned int reason = get_reason(regs); 133214cf11afSPaul Mackerras 1333aa42c69cSKim Phillips /* We can now get here via a FP Unavailable exception if the core 133404903a30SKumar Gala * has no FPU, in that case the reason flags will be 0 */ 133514cf11afSPaul Mackerras 133614cf11afSPaul Mackerras if (reason & REASON_FP) { 133714cf11afSPaul Mackerras /* IEEE FP exception */ 1338dc1c1ca3SStephen Rothwell parse_fpe(regs); 1339ba12eedeSLi Zhong goto bail; 13408dad3f92SPaul Mackerras } 13418dad3f92SPaul Mackerras if (reason & REASON_TRAP) { 1342a4c3f909SBalbir Singh unsigned long bugaddr; 1343ba797b28SJason Wessel /* Debugger is first in line to stop recursive faults in 1344ba797b28SJason Wessel * rcu_lock, notify_die, or atomic_notifier_call_chain */ 1345ba797b28SJason Wessel if (debugger_bpt(regs)) 1346ba12eedeSLi Zhong goto bail; 1347ba797b28SJason Wessel 13486cc89badSNaveen N. Rao if (kprobe_handler(regs)) 13496cc89badSNaveen N. Rao goto bail; 13506cc89badSNaveen N. Rao 135114cf11afSPaul Mackerras /* trap exception */ 1352dc1c1ca3SStephen Rothwell if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP) 1353dc1c1ca3SStephen Rothwell == NOTIFY_STOP) 1354ba12eedeSLi Zhong goto bail; 135573c9ceabSJeremy Fitzhardinge 1356a4c3f909SBalbir Singh bugaddr = regs->nip; 1357a4c3f909SBalbir Singh /* 1358a4c3f909SBalbir Singh * Fixup bugaddr for BUG_ON() in real mode 1359a4c3f909SBalbir Singh */ 1360a4c3f909SBalbir Singh if (!is_kernel_addr(bugaddr) && !(regs->msr & MSR_IR)) 1361a4c3f909SBalbir Singh bugaddr += PAGE_OFFSET; 1362a4c3f909SBalbir Singh 136373c9ceabSJeremy Fitzhardinge if (!(regs->msr & MSR_PR) && /* not user-mode */ 1364a4c3f909SBalbir Singh report_bug(bugaddr, regs) == BUG_TRAP_TYPE_WARN) { 136514cf11afSPaul Mackerras regs->nip += 4; 1366ba12eedeSLi Zhong goto bail; 136714cf11afSPaul Mackerras } 13688dad3f92SPaul Mackerras _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); 1369ba12eedeSLi Zhong goto bail; 13708dad3f92SPaul Mackerras } 1371bc2a9408SMichael Neuling #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1372bc2a9408SMichael Neuling if (reason & REASON_TM) { 1373bc2a9408SMichael Neuling /* This is a TM "Bad Thing Exception" program check. 1374bc2a9408SMichael Neuling * This occurs when: 1375bc2a9408SMichael Neuling * - An rfid/hrfid/mtmsrd attempts to cause an illegal 1376bc2a9408SMichael Neuling * transition in TM states. 1377bc2a9408SMichael Neuling * - A trechkpt is attempted when transactional. 1378bc2a9408SMichael Neuling * - A treclaim is attempted when non transactional. 1379bc2a9408SMichael Neuling * - A tend is illegally attempted. 1380bc2a9408SMichael Neuling * - writing a TM SPR when transactional. 1381632f0574SMichael Ellerman * 1382632f0574SMichael Ellerman * If usermode caused this, it's done something illegal and 1383bc2a9408SMichael Neuling * gets a SIGILL slap on the wrist. We call it an illegal 1384bc2a9408SMichael Neuling * operand to distinguish from the instruction just being bad 1385bc2a9408SMichael Neuling * (e.g. executing a 'tend' on a CPU without TM!); it's an 1386bc2a9408SMichael Neuling * illegal /placement/ of a valid instruction. 1387bc2a9408SMichael Neuling */ 1388bc2a9408SMichael Neuling if (user_mode(regs)) { 1389bc2a9408SMichael Neuling _exception(SIGILL, regs, ILL_ILLOPN, regs->nip); 1390ba12eedeSLi Zhong goto bail; 1391bc2a9408SMichael Neuling } else { 1392bc2a9408SMichael Neuling printk(KERN_EMERG "Unexpected TM Bad Thing exception " 1393bc2a9408SMichael Neuling "at %lx (msr 0x%x)\n", regs->nip, reason); 1394bc2a9408SMichael Neuling die("Unrecoverable exception", regs, SIGABRT); 1395bc2a9408SMichael Neuling } 1396bc2a9408SMichael Neuling } 1397bc2a9408SMichael Neuling #endif 13988dad3f92SPaul Mackerras 1399b3f6a459SMichael Ellerman /* 1400b3f6a459SMichael Ellerman * If we took the program check in the kernel skip down to sending a 1401b3f6a459SMichael Ellerman * SIGILL. The subsequent cases all relate to emulating instructions 1402b3f6a459SMichael Ellerman * which we should only do for userspace. We also do not want to enable 1403b3f6a459SMichael Ellerman * interrupts for kernel faults because that might lead to further 1404b3f6a459SMichael Ellerman * faults, and loose the context of the original exception. 1405b3f6a459SMichael Ellerman */ 1406b3f6a459SMichael Ellerman if (!user_mode(regs)) 1407b3f6a459SMichael Ellerman goto sigill; 1408b3f6a459SMichael Ellerman 1409a3512b2dSBenjamin Herrenschmidt /* We restore the interrupt state now */ 1410a3512b2dSBenjamin Herrenschmidt if (!arch_irq_disabled_regs(regs)) 1411cd8a5673SPaul Mackerras local_irq_enable(); 1412cd8a5673SPaul Mackerras 141304903a30SKumar Gala /* (reason & REASON_ILLEGAL) would be the obvious thing here, 141404903a30SKumar Gala * but there seems to be a hardware bug on the 405GP (RevD) 141504903a30SKumar Gala * that means ESR is sometimes set incorrectly - either to 141604903a30SKumar Gala * ESR_DST (!?) or 0. In the process of chasing this with the 141704903a30SKumar Gala * hardware people - not sure if it can happen on any illegal 141804903a30SKumar Gala * instruction or only on FP instructions, whether there is a 14194e63f8edSBenjamin Herrenschmidt * pattern to occurrences etc. -dgibson 31/Mar/2003 14204e63f8edSBenjamin Herrenschmidt */ 14213a3b5aa6SKevin Hao if (!emulate_math(regs)) 1422ba12eedeSLi Zhong goto bail; 142304903a30SKumar Gala 14248dad3f92SPaul Mackerras /* Try to emulate it if we should. */ 14258dad3f92SPaul Mackerras if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) { 142614cf11afSPaul Mackerras switch (emulate_instruction(regs)) { 142714cf11afSPaul Mackerras case 0: 142814cf11afSPaul Mackerras regs->nip += 4; 142914cf11afSPaul Mackerras emulate_single_step(regs); 1430ba12eedeSLi Zhong goto bail; 143114cf11afSPaul Mackerras case -EFAULT: 143214cf11afSPaul Mackerras _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); 1433ba12eedeSLi Zhong goto bail; 14348dad3f92SPaul Mackerras } 14358dad3f92SPaul Mackerras } 14368dad3f92SPaul Mackerras 1437b3f6a459SMichael Ellerman sigill: 143814cf11afSPaul Mackerras if (reason & REASON_PRIVILEGED) 143914cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_PRVOPC, regs->nip); 144014cf11afSPaul Mackerras else 144114cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1442ba12eedeSLi Zhong 1443ba12eedeSLi Zhong bail: 1444ba12eedeSLi Zhong exception_exit(prev_state); 144514cf11afSPaul Mackerras } 144603465f89SNicholas Piggin NOKPROBE_SYMBOL(program_check_exception); 144714cf11afSPaul Mackerras 1448bf593907SPaul Mackerras /* 1449bf593907SPaul Mackerras * This occurs when running in hypervisor mode on POWER6 or later 1450bf593907SPaul Mackerras * and an illegal instruction is encountered. 1451bf593907SPaul Mackerras */ 145203465f89SNicholas Piggin void emulation_assist_interrupt(struct pt_regs *regs) 1453bf593907SPaul Mackerras { 1454bf593907SPaul Mackerras regs->msr |= REASON_ILLEGAL; 1455bf593907SPaul Mackerras program_check_exception(regs); 1456bf593907SPaul Mackerras } 145703465f89SNicholas Piggin NOKPROBE_SYMBOL(emulation_assist_interrupt); 1458bf593907SPaul Mackerras 1459dc1c1ca3SStephen Rothwell void alignment_exception(struct pt_regs *regs) 146014cf11afSPaul Mackerras { 1461ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 14624393c4f6SBenjamin Herrenschmidt int sig, code, fixed = 0; 146314cf11afSPaul Mackerras 1464a3512b2dSBenjamin Herrenschmidt /* We restore the interrupt state now */ 1465a3512b2dSBenjamin Herrenschmidt if (!arch_irq_disabled_regs(regs)) 1466a3512b2dSBenjamin Herrenschmidt local_irq_enable(); 1467a3512b2dSBenjamin Herrenschmidt 14686ce6c629SMichael Neuling if (tm_abort_check(regs, TM_CAUSE_ALIGNMENT | TM_CAUSE_PERSISTENT)) 14696ce6c629SMichael Neuling goto bail; 14706ce6c629SMichael Neuling 1471e9370ae1SPaul Mackerras /* we don't implement logging of alignment exceptions */ 1472e9370ae1SPaul Mackerras if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS)) 147314cf11afSPaul Mackerras fixed = fix_alignment(regs); 147414cf11afSPaul Mackerras 147514cf11afSPaul Mackerras if (fixed == 1) { 147614cf11afSPaul Mackerras regs->nip += 4; /* skip over emulated instruction */ 147714cf11afSPaul Mackerras emulate_single_step(regs); 1478ba12eedeSLi Zhong goto bail; 147914cf11afSPaul Mackerras } 148014cf11afSPaul Mackerras 148114cf11afSPaul Mackerras /* Operand address was bad */ 148214cf11afSPaul Mackerras if (fixed == -EFAULT) { 14834393c4f6SBenjamin Herrenschmidt sig = SIGSEGV; 14844393c4f6SBenjamin Herrenschmidt code = SEGV_ACCERR; 14854393c4f6SBenjamin Herrenschmidt } else { 14864393c4f6SBenjamin Herrenschmidt sig = SIGBUS; 14874393c4f6SBenjamin Herrenschmidt code = BUS_ADRALN; 148814cf11afSPaul Mackerras } 14894393c4f6SBenjamin Herrenschmidt if (user_mode(regs)) 14904393c4f6SBenjamin Herrenschmidt _exception(sig, regs, code, regs->dar); 14914393c4f6SBenjamin Herrenschmidt else 14924393c4f6SBenjamin Herrenschmidt bad_page_fault(regs, regs->dar, sig); 1493ba12eedeSLi Zhong 1494ba12eedeSLi Zhong bail: 1495ba12eedeSLi Zhong exception_exit(prev_state); 149614cf11afSPaul Mackerras } 149714cf11afSPaul Mackerras 1498f0f558b1SPaul Mackerras void slb_miss_bad_addr(struct pt_regs *regs) 1499f0f558b1SPaul Mackerras { 1500f0f558b1SPaul Mackerras enum ctx_state prev_state = exception_enter(); 1501f0f558b1SPaul Mackerras 1502f0f558b1SPaul Mackerras if (user_mode(regs)) 1503f0f558b1SPaul Mackerras _exception(SIGSEGV, regs, SEGV_BNDERR, regs->dar); 1504f0f558b1SPaul Mackerras else 1505f0f558b1SPaul Mackerras bad_page_fault(regs, regs->dar, SIGSEGV); 1506f0f558b1SPaul Mackerras 1507f0f558b1SPaul Mackerras exception_exit(prev_state); 1508f0f558b1SPaul Mackerras } 1509f0f558b1SPaul Mackerras 151014cf11afSPaul Mackerras void StackOverflow(struct pt_regs *regs) 151114cf11afSPaul Mackerras { 151214cf11afSPaul Mackerras printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n", 151314cf11afSPaul Mackerras current, regs->gpr[1]); 151414cf11afSPaul Mackerras debugger(regs); 151514cf11afSPaul Mackerras show_regs(regs); 151614cf11afSPaul Mackerras panic("kernel stack overflow"); 151714cf11afSPaul Mackerras } 151814cf11afSPaul Mackerras 151914cf11afSPaul Mackerras void nonrecoverable_exception(struct pt_regs *regs) 152014cf11afSPaul Mackerras { 152114cf11afSPaul Mackerras printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n", 152214cf11afSPaul Mackerras regs->nip, regs->msr); 152314cf11afSPaul Mackerras debugger(regs); 152414cf11afSPaul Mackerras die("nonrecoverable exception", regs, SIGKILL); 152514cf11afSPaul Mackerras } 152614cf11afSPaul Mackerras 1527dc1c1ca3SStephen Rothwell void kernel_fp_unavailable_exception(struct pt_regs *regs) 1528dc1c1ca3SStephen Rothwell { 1529ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 1530ba12eedeSLi Zhong 1531dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable FP Unavailable Exception " 1532dc1c1ca3SStephen Rothwell "%lx at %lx\n", regs->trap, regs->nip); 1533dc1c1ca3SStephen Rothwell die("Unrecoverable FP Unavailable Exception", regs, SIGABRT); 1534ba12eedeSLi Zhong 1535ba12eedeSLi Zhong exception_exit(prev_state); 1536dc1c1ca3SStephen Rothwell } 1537dc1c1ca3SStephen Rothwell 1538dc1c1ca3SStephen Rothwell void altivec_unavailable_exception(struct pt_regs *regs) 1539dc1c1ca3SStephen Rothwell { 1540ba12eedeSLi Zhong enum ctx_state prev_state = exception_enter(); 1541ba12eedeSLi Zhong 1542dc1c1ca3SStephen Rothwell if (user_mode(regs)) { 1543dc1c1ca3SStephen Rothwell /* A user program has executed an altivec instruction, 1544dc1c1ca3SStephen Rothwell but this kernel doesn't support altivec. */ 1545dc1c1ca3SStephen Rothwell _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1546ba12eedeSLi Zhong goto bail; 1547dc1c1ca3SStephen Rothwell } 15486c4841c2SAnton Blanchard 1549dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception " 1550dc1c1ca3SStephen Rothwell "%lx at %lx\n", regs->trap, regs->nip); 1551dc1c1ca3SStephen Rothwell die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT); 1552ba12eedeSLi Zhong 1553ba12eedeSLi Zhong bail: 1554ba12eedeSLi Zhong exception_exit(prev_state); 1555dc1c1ca3SStephen Rothwell } 1556dc1c1ca3SStephen Rothwell 1557ce48b210SMichael Neuling void vsx_unavailable_exception(struct pt_regs *regs) 1558ce48b210SMichael Neuling { 1559ce48b210SMichael Neuling if (user_mode(regs)) { 1560ce48b210SMichael Neuling /* A user program has executed an vsx instruction, 1561ce48b210SMichael Neuling but this kernel doesn't support vsx. */ 1562ce48b210SMichael Neuling _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1563ce48b210SMichael Neuling return; 1564ce48b210SMichael Neuling } 1565ce48b210SMichael Neuling 1566ce48b210SMichael Neuling printk(KERN_EMERG "Unrecoverable VSX Unavailable Exception " 1567ce48b210SMichael Neuling "%lx at %lx\n", regs->trap, regs->nip); 1568ce48b210SMichael Neuling die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT); 1569ce48b210SMichael Neuling } 1570ce48b210SMichael Neuling 15712517617eSMichael Neuling #ifdef CONFIG_PPC64 1572172f7aaaSCyril Bur static void tm_unavailable(struct pt_regs *regs) 1573172f7aaaSCyril Bur { 15745d176f75SCyril Bur #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 15755d176f75SCyril Bur if (user_mode(regs)) { 15765d176f75SCyril Bur current->thread.load_tm++; 15775d176f75SCyril Bur regs->msr |= MSR_TM; 15785d176f75SCyril Bur tm_enable(); 15795d176f75SCyril Bur tm_restore_sprs(¤t->thread); 15805d176f75SCyril Bur return; 15815d176f75SCyril Bur } 15825d176f75SCyril Bur #endif 1583172f7aaaSCyril Bur pr_emerg("Unrecoverable TM Unavailable Exception " 1584172f7aaaSCyril Bur "%lx at %lx\n", regs->trap, regs->nip); 1585172f7aaaSCyril Bur die("Unrecoverable TM Unavailable Exception", regs, SIGABRT); 1586172f7aaaSCyril Bur } 1587172f7aaaSCyril Bur 1588021424a1SMichael Ellerman void facility_unavailable_exception(struct pt_regs *regs) 1589d0c0c9a1SMichael Neuling { 1590021424a1SMichael Ellerman static char *facility_strings[] = { 15912517617eSMichael Neuling [FSCR_FP_LG] = "FPU", 15922517617eSMichael Neuling [FSCR_VECVSX_LG] = "VMX/VSX", 15932517617eSMichael Neuling [FSCR_DSCR_LG] = "DSCR", 15942517617eSMichael Neuling [FSCR_PM_LG] = "PMU SPRs", 15952517617eSMichael Neuling [FSCR_BHRB_LG] = "BHRB", 15962517617eSMichael Neuling [FSCR_TM_LG] = "TM", 15972517617eSMichael Neuling [FSCR_EBB_LG] = "EBB", 15982517617eSMichael Neuling [FSCR_TAR_LG] = "TAR", 1599794464f4SNicholas Piggin [FSCR_MSGP_LG] = "MSGP", 16009b7ff0c6SNicholas Piggin [FSCR_SCV_LG] = "SCV", 1601021424a1SMichael Ellerman }; 16022517617eSMichael Neuling char *facility = "unknown"; 1603021424a1SMichael Ellerman u64 value; 1604c952c1c4SAnshuman Khandual u32 instword, rd; 16052517617eSMichael Neuling u8 status; 16062517617eSMichael Neuling bool hv; 1607021424a1SMichael Ellerman 16082271db20SBenjamin Herrenschmidt hv = (TRAP(regs) == 0xf80); 16092517617eSMichael Neuling if (hv) 1610b14b6260SMichael Ellerman value = mfspr(SPRN_HFSCR); 16112517617eSMichael Neuling else 16122517617eSMichael Neuling value = mfspr(SPRN_FSCR); 16132517617eSMichael Neuling 16142517617eSMichael Neuling status = value >> 56; 16152517617eSMichael Neuling if (status == FSCR_DSCR_LG) { 1616c952c1c4SAnshuman Khandual /* 1617c952c1c4SAnshuman Khandual * User is accessing the DSCR register using the problem 1618c952c1c4SAnshuman Khandual * state only SPR number (0x03) either through a mfspr or 1619c952c1c4SAnshuman Khandual * a mtspr instruction. If it is a write attempt through 1620c952c1c4SAnshuman Khandual * a mtspr, then we set the inherit bit. This also allows 1621c952c1c4SAnshuman Khandual * the user to write or read the register directly in the 1622c952c1c4SAnshuman Khandual * future by setting via the FSCR DSCR bit. But in case it 1623c952c1c4SAnshuman Khandual * is a read DSCR attempt through a mfspr instruction, we 1624c952c1c4SAnshuman Khandual * just emulate the instruction instead. This code path will 1625c952c1c4SAnshuman Khandual * always emulate all the mfspr instructions till the user 1626c952c1c4SAnshuman Khandual * has attempted at least one mtspr instruction. This way it 1627c952c1c4SAnshuman Khandual * preserves the same behaviour when the user is accessing 1628c952c1c4SAnshuman Khandual * the DSCR through privilege level only SPR number (0x11) 1629c952c1c4SAnshuman Khandual * which is emulated through illegal instruction exception. 1630c952c1c4SAnshuman Khandual * We always leave HFSCR DSCR set. 16312517617eSMichael Neuling */ 1632c952c1c4SAnshuman Khandual if (get_user(instword, (u32 __user *)(regs->nip))) { 1633c952c1c4SAnshuman Khandual pr_err("Failed to fetch the user instruction\n"); 1634c952c1c4SAnshuman Khandual return; 1635c952c1c4SAnshuman Khandual } 1636c952c1c4SAnshuman Khandual 1637c952c1c4SAnshuman Khandual /* Write into DSCR (mtspr 0x03, RS) */ 1638c952c1c4SAnshuman Khandual if ((instword & PPC_INST_MTSPR_DSCR_USER_MASK) 1639c952c1c4SAnshuman Khandual == PPC_INST_MTSPR_DSCR_USER) { 1640c952c1c4SAnshuman Khandual rd = (instword >> 21) & 0x1f; 1641c952c1c4SAnshuman Khandual current->thread.dscr = regs->gpr[rd]; 16422517617eSMichael Neuling current->thread.dscr_inherit = 1; 1643b57bd2deSMichael Neuling current->thread.fscr |= FSCR_DSCR; 1644b57bd2deSMichael Neuling mtspr(SPRN_FSCR, current->thread.fscr); 1645c952c1c4SAnshuman Khandual } 1646c952c1c4SAnshuman Khandual 1647c952c1c4SAnshuman Khandual /* Read from DSCR (mfspr RT, 0x03) */ 1648c952c1c4SAnshuman Khandual if ((instword & PPC_INST_MFSPR_DSCR_USER_MASK) 1649c952c1c4SAnshuman Khandual == PPC_INST_MFSPR_DSCR_USER) { 1650c952c1c4SAnshuman Khandual if (emulate_instruction(regs)) { 1651c952c1c4SAnshuman Khandual pr_err("DSCR based mfspr emulation failed\n"); 1652c952c1c4SAnshuman Khandual return; 1653c952c1c4SAnshuman Khandual } 1654c952c1c4SAnshuman Khandual regs->nip += 4; 1655c952c1c4SAnshuman Khandual emulate_single_step(regs); 1656c952c1c4SAnshuman Khandual } 16572517617eSMichael Neuling return; 1658b14b6260SMichael Ellerman } 1659b14b6260SMichael Ellerman 1660172f7aaaSCyril Bur if (status == FSCR_TM_LG) { 1661172f7aaaSCyril Bur /* 1662172f7aaaSCyril Bur * If we're here then the hardware is TM aware because it 1663172f7aaaSCyril Bur * generated an exception with FSRM_TM set. 1664172f7aaaSCyril Bur * 1665172f7aaaSCyril Bur * If cpu_has_feature(CPU_FTR_TM) is false, then either firmware 1666172f7aaaSCyril Bur * told us not to do TM, or the kernel is not built with TM 1667172f7aaaSCyril Bur * support. 1668172f7aaaSCyril Bur * 1669172f7aaaSCyril Bur * If both of those things are true, then userspace can spam the 1670172f7aaaSCyril Bur * console by triggering the printk() below just by continually 1671172f7aaaSCyril Bur * doing tbegin (or any TM instruction). So in that case just 1672172f7aaaSCyril Bur * send the process a SIGILL immediately. 1673172f7aaaSCyril Bur */ 1674172f7aaaSCyril Bur if (!cpu_has_feature(CPU_FTR_TM)) 1675172f7aaaSCyril Bur goto out; 1676172f7aaaSCyril Bur 1677172f7aaaSCyril Bur tm_unavailable(regs); 1678172f7aaaSCyril Bur return; 1679172f7aaaSCyril Bur } 1680172f7aaaSCyril Bur 168193c2ec0fSBalbir Singh if ((hv || status >= 2) && 168293c2ec0fSBalbir Singh (status < ARRAY_SIZE(facility_strings)) && 16832517617eSMichael Neuling facility_strings[status]) 16842517617eSMichael Neuling facility = facility_strings[status]; 1685021424a1SMichael Ellerman 1686d0c0c9a1SMichael Neuling /* We restore the interrupt state now */ 1687d0c0c9a1SMichael Neuling if (!arch_irq_disabled_regs(regs)) 1688d0c0c9a1SMichael Neuling local_irq_enable(); 1689d0c0c9a1SMichael Neuling 169093c2ec0fSBalbir Singh pr_err_ratelimited("%sFacility '%s' unavailable (%d), exception at 0x%lx, MSR=%lx\n", 169193c2ec0fSBalbir Singh hv ? "Hypervisor " : "", facility, status, regs->nip, regs->msr); 1692d0c0c9a1SMichael Neuling 1693172f7aaaSCyril Bur out: 1694d0c0c9a1SMichael Neuling if (user_mode(regs)) { 1695d0c0c9a1SMichael Neuling _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); 1696d0c0c9a1SMichael Neuling return; 1697d0c0c9a1SMichael Neuling } 1698d0c0c9a1SMichael Neuling 1699021424a1SMichael Ellerman die("Unexpected facility unavailable exception", regs, SIGABRT); 1700d0c0c9a1SMichael Neuling } 17012517617eSMichael Neuling #endif 1702d0c0c9a1SMichael Neuling 1703f54db641SMichael Neuling #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1704f54db641SMichael Neuling 1705f54db641SMichael Neuling void fp_unavailable_tm(struct pt_regs *regs) 1706f54db641SMichael Neuling { 1707f54db641SMichael Neuling /* Note: This does not handle any kind of FP laziness. */ 1708f54db641SMichael Neuling 1709f54db641SMichael Neuling TM_DEBUG("FP Unavailable trap whilst transactional at 0x%lx, MSR=%lx\n", 1710f54db641SMichael Neuling regs->nip, regs->msr); 1711f54db641SMichael Neuling 1712f54db641SMichael Neuling /* We can only have got here if the task started using FP after 1713f54db641SMichael Neuling * beginning the transaction. So, the transactional regs are just a 1714f54db641SMichael Neuling * copy of the checkpointed ones. But, we still need to recheckpoint 1715f54db641SMichael Neuling * as we're enabling FP for the process; it will return, abort the 1716f54db641SMichael Neuling * transaction, and probably retry but now with FP enabled. So the 1717f54db641SMichael Neuling * checkpointed FP registers need to be loaded. 1718f54db641SMichael Neuling */ 1719d31626f7SPaul Mackerras tm_reclaim_current(TM_CAUSE_FAC_UNAV); 1720f54db641SMichael Neuling /* Reclaim didn't save out any FPRs to transact_fprs. */ 1721f54db641SMichael Neuling 1722f54db641SMichael Neuling /* Enable FP for the task: */ 1723a7771176SCyril Bur current->thread.load_fp = 1; 1724f54db641SMichael Neuling 1725f54db641SMichael Neuling /* This loads and recheckpoints the FP registers from 1726f54db641SMichael Neuling * thread.fpr[]. They will remain in registers after the 1727f54db641SMichael Neuling * checkpoint so we don't need to reload them after. 17283ac8ff1cSPaul Mackerras * If VMX is in use, the VRs now hold checkpointed values, 17293ac8ff1cSPaul Mackerras * so we don't want to load the VRs from the thread_struct. 1730f54db641SMichael Neuling */ 1731eb5c3f1cSCyril Bur tm_recheckpoint(¤t->thread); 1732f54db641SMichael Neuling } 1733f54db641SMichael Neuling 1734f54db641SMichael Neuling void altivec_unavailable_tm(struct pt_regs *regs) 1735f54db641SMichael Neuling { 1736f54db641SMichael Neuling /* See the comments in fp_unavailable_tm(). This function operates 1737f54db641SMichael Neuling * the same way. 1738f54db641SMichael Neuling */ 1739f54db641SMichael Neuling 1740f54db641SMichael Neuling TM_DEBUG("Vector Unavailable trap whilst transactional at 0x%lx," 1741f54db641SMichael Neuling "MSR=%lx\n", 1742f54db641SMichael Neuling regs->nip, regs->msr); 1743d31626f7SPaul Mackerras tm_reclaim_current(TM_CAUSE_FAC_UNAV); 1744a7771176SCyril Bur current->thread.load_vec = 1; 1745eb5c3f1cSCyril Bur tm_recheckpoint(¤t->thread); 1746f54db641SMichael Neuling current->thread.used_vr = 1; 17473ac8ff1cSPaul Mackerras } 17483ac8ff1cSPaul Mackerras 1749f54db641SMichael Neuling void vsx_unavailable_tm(struct pt_regs *regs) 1750f54db641SMichael Neuling { 1751f54db641SMichael Neuling /* See the comments in fp_unavailable_tm(). This works similarly, 1752f54db641SMichael Neuling * though we're loading both FP and VEC registers in here. 1753f54db641SMichael Neuling * 1754f54db641SMichael Neuling * If FP isn't in use, load FP regs. If VEC isn't in use, load VEC 1755f54db641SMichael Neuling * regs. Either way, set MSR_VSX. 1756f54db641SMichael Neuling */ 1757f54db641SMichael Neuling 1758f54db641SMichael Neuling TM_DEBUG("VSX Unavailable trap whilst transactional at 0x%lx," 1759f54db641SMichael Neuling "MSR=%lx\n", 1760f54db641SMichael Neuling regs->nip, regs->msr); 1761f54db641SMichael Neuling 17623ac8ff1cSPaul Mackerras current->thread.used_vsr = 1; 17633ac8ff1cSPaul Mackerras 1764f54db641SMichael Neuling /* This reclaims FP and/or VR regs if they're already enabled */ 1765d31626f7SPaul Mackerras tm_reclaim_current(TM_CAUSE_FAC_UNAV); 1766f54db641SMichael Neuling 1767a7771176SCyril Bur current->thread.load_vec = 1; 1768a7771176SCyril Bur current->thread.load_fp = 1; 17693ac8ff1cSPaul Mackerras 1770eb5c3f1cSCyril Bur tm_recheckpoint(¤t->thread); 1771f54db641SMichael Neuling } 1772f54db641SMichael Neuling #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ 1773f54db641SMichael Neuling 1774dc1c1ca3SStephen Rothwell void performance_monitor_exception(struct pt_regs *regs) 1775dc1c1ca3SStephen Rothwell { 177669111bacSChristoph Lameter __this_cpu_inc(irq_stat.pmu_irqs); 177789713ed1SAnton Blanchard 1778dc1c1ca3SStephen Rothwell perf_irq(regs); 1779dc1c1ca3SStephen Rothwell } 1780dc1c1ca3SStephen Rothwell 1781172ae2e7SDave Kleikamp #ifdef CONFIG_PPC_ADV_DEBUG_REGS 17823bffb652SDave Kleikamp static void handle_debug(struct pt_regs *regs, unsigned long debug_status) 17833bffb652SDave Kleikamp { 17843bffb652SDave Kleikamp int changed = 0; 17853bffb652SDave Kleikamp /* 17863bffb652SDave Kleikamp * Determine the cause of the debug event, clear the 17873bffb652SDave Kleikamp * event flags and send a trap to the handler. Torez 17883bffb652SDave Kleikamp */ 17893bffb652SDave Kleikamp if (debug_status & (DBSR_DAC1R | DBSR_DAC1W)) { 17903bffb652SDave Kleikamp dbcr_dac(current) &= ~(DBCR_DAC1R | DBCR_DAC1W); 17913bffb652SDave Kleikamp #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE 179251ae8d4aSBharat Bhushan current->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE; 17933bffb652SDave Kleikamp #endif 17943bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_DAC1), debug_status, TRAP_HWBKPT, 17953bffb652SDave Kleikamp 5); 17963bffb652SDave Kleikamp changed |= 0x01; 17973bffb652SDave Kleikamp } else if (debug_status & (DBSR_DAC2R | DBSR_DAC2W)) { 17983bffb652SDave Kleikamp dbcr_dac(current) &= ~(DBCR_DAC2R | DBCR_DAC2W); 17993bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_DAC2), debug_status, TRAP_HWBKPT, 18003bffb652SDave Kleikamp 6); 18013bffb652SDave Kleikamp changed |= 0x01; 18023bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC1) { 180351ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IAC1; 18043bffb652SDave Kleikamp dbcr_iac_range(current) &= ~DBCR_IAC12MODE; 18053bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC1), debug_status, TRAP_HWBKPT, 18063bffb652SDave Kleikamp 1); 18073bffb652SDave Kleikamp changed |= 0x01; 18083bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC2) { 180951ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IAC2; 18103bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC2), debug_status, TRAP_HWBKPT, 18113bffb652SDave Kleikamp 2); 18123bffb652SDave Kleikamp changed |= 0x01; 18133bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC3) { 181451ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IAC3; 18153bffb652SDave Kleikamp dbcr_iac_range(current) &= ~DBCR_IAC34MODE; 18163bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC3), debug_status, TRAP_HWBKPT, 18173bffb652SDave Kleikamp 3); 18183bffb652SDave Kleikamp changed |= 0x01; 18193bffb652SDave Kleikamp } else if (debug_status & DBSR_IAC4) { 182051ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IAC4; 18213bffb652SDave Kleikamp do_send_trap(regs, mfspr(SPRN_IAC4), debug_status, TRAP_HWBKPT, 18223bffb652SDave Kleikamp 4); 18233bffb652SDave Kleikamp changed |= 0x01; 18243bffb652SDave Kleikamp } 18253bffb652SDave Kleikamp /* 18263bffb652SDave Kleikamp * At the point this routine was called, the MSR(DE) was turned off. 18273bffb652SDave Kleikamp * Check all other debug flags and see if that bit needs to be turned 18283bffb652SDave Kleikamp * back on or not. 18293bffb652SDave Kleikamp */ 183051ae8d4aSBharat Bhushan if (DBCR_ACTIVE_EVENTS(current->thread.debug.dbcr0, 183151ae8d4aSBharat Bhushan current->thread.debug.dbcr1)) 18323bffb652SDave Kleikamp regs->msr |= MSR_DE; 18333bffb652SDave Kleikamp else 18343bffb652SDave Kleikamp /* Make sure the IDM flag is off */ 183551ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IDM; 18363bffb652SDave Kleikamp 18373bffb652SDave Kleikamp if (changed & 0x01) 183851ae8d4aSBharat Bhushan mtspr(SPRN_DBCR0, current->thread.debug.dbcr0); 18393bffb652SDave Kleikamp } 184014cf11afSPaul Mackerras 184103465f89SNicholas Piggin void DebugException(struct pt_regs *regs, unsigned long debug_status) 184214cf11afSPaul Mackerras { 184351ae8d4aSBharat Bhushan current->thread.debug.dbsr = debug_status; 18443bffb652SDave Kleikamp 1845ec097c84SRoland McGrath /* Hack alert: On BookE, Branch Taken stops on the branch itself, while 1846ec097c84SRoland McGrath * on server, it stops on the target of the branch. In order to simulate 1847ec097c84SRoland McGrath * the server behaviour, we thus restart right away with a single step 1848ec097c84SRoland McGrath * instead of stopping here when hitting a BT 1849ec097c84SRoland McGrath */ 1850ec097c84SRoland McGrath if (debug_status & DBSR_BT) { 1851ec097c84SRoland McGrath regs->msr &= ~MSR_DE; 1852ec097c84SRoland McGrath 1853ec097c84SRoland McGrath /* Disable BT */ 1854ec097c84SRoland McGrath mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_BT); 1855ec097c84SRoland McGrath /* Clear the BT event */ 1856ec097c84SRoland McGrath mtspr(SPRN_DBSR, DBSR_BT); 1857ec097c84SRoland McGrath 1858ec097c84SRoland McGrath /* Do the single step trick only when coming from userspace */ 1859ec097c84SRoland McGrath if (user_mode(regs)) { 186051ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_BT; 186151ae8d4aSBharat Bhushan current->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC; 1862ec097c84SRoland McGrath regs->msr |= MSR_DE; 1863ec097c84SRoland McGrath return; 1864ec097c84SRoland McGrath } 1865ec097c84SRoland McGrath 18666cc89badSNaveen N. Rao if (kprobe_post_handler(regs)) 18676cc89badSNaveen N. Rao return; 18686cc89badSNaveen N. Rao 1869ec097c84SRoland McGrath if (notify_die(DIE_SSTEP, "block_step", regs, 5, 1870ec097c84SRoland McGrath 5, SIGTRAP) == NOTIFY_STOP) { 1871ec097c84SRoland McGrath return; 1872ec097c84SRoland McGrath } 1873ec097c84SRoland McGrath if (debugger_sstep(regs)) 1874ec097c84SRoland McGrath return; 1875ec097c84SRoland McGrath } else if (debug_status & DBSR_IC) { /* Instruction complete */ 187614cf11afSPaul Mackerras regs->msr &= ~MSR_DE; 1877f8279621SKumar Gala 187814cf11afSPaul Mackerras /* Disable instruction completion */ 187914cf11afSPaul Mackerras mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC); 188014cf11afSPaul Mackerras /* Clear the instruction completion event */ 188114cf11afSPaul Mackerras mtspr(SPRN_DBSR, DBSR_IC); 1882f8279621SKumar Gala 18836cc89badSNaveen N. Rao if (kprobe_post_handler(regs)) 18846cc89badSNaveen N. Rao return; 18856cc89badSNaveen N. Rao 1886f8279621SKumar Gala if (notify_die(DIE_SSTEP, "single_step", regs, 5, 1887f8279621SKumar Gala 5, SIGTRAP) == NOTIFY_STOP) { 188814cf11afSPaul Mackerras return; 188914cf11afSPaul Mackerras } 1890f8279621SKumar Gala 1891f8279621SKumar Gala if (debugger_sstep(regs)) 1892f8279621SKumar Gala return; 1893f8279621SKumar Gala 18943bffb652SDave Kleikamp if (user_mode(regs)) { 189551ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IC; 189651ae8d4aSBharat Bhushan if (DBCR_ACTIVE_EVENTS(current->thread.debug.dbcr0, 189751ae8d4aSBharat Bhushan current->thread.debug.dbcr1)) 18983bffb652SDave Kleikamp regs->msr |= MSR_DE; 18993bffb652SDave Kleikamp else 19003bffb652SDave Kleikamp /* Make sure the IDM bit is off */ 190151ae8d4aSBharat Bhushan current->thread.debug.dbcr0 &= ~DBCR0_IDM; 19023bffb652SDave Kleikamp } 1903f8279621SKumar Gala 1904f8279621SKumar Gala _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip); 19053bffb652SDave Kleikamp } else 19063bffb652SDave Kleikamp handle_debug(regs, debug_status); 190714cf11afSPaul Mackerras } 190803465f89SNicholas Piggin NOKPROBE_SYMBOL(DebugException); 1909172ae2e7SDave Kleikamp #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ 191014cf11afSPaul Mackerras 191114cf11afSPaul Mackerras #if !defined(CONFIG_TAU_INT) 191214cf11afSPaul Mackerras void TAUException(struct pt_regs *regs) 191314cf11afSPaul Mackerras { 191414cf11afSPaul Mackerras printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n", 191514cf11afSPaul Mackerras regs->nip, regs->msr, regs->trap, print_tainted()); 191614cf11afSPaul Mackerras } 191714cf11afSPaul Mackerras #endif /* CONFIG_INT_TAU */ 191814cf11afSPaul Mackerras 191914cf11afSPaul Mackerras #ifdef CONFIG_ALTIVEC 1920dc1c1ca3SStephen Rothwell void altivec_assist_exception(struct pt_regs *regs) 192114cf11afSPaul Mackerras { 192214cf11afSPaul Mackerras int err; 192314cf11afSPaul Mackerras 192414cf11afSPaul Mackerras if (!user_mode(regs)) { 192514cf11afSPaul Mackerras printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode" 192614cf11afSPaul Mackerras " at %lx\n", regs->nip); 19278dad3f92SPaul Mackerras die("Kernel VMX/Altivec assist exception", regs, SIGILL); 192814cf11afSPaul Mackerras } 192914cf11afSPaul Mackerras 1930dc1c1ca3SStephen Rothwell flush_altivec_to_thread(current); 1931dc1c1ca3SStephen Rothwell 1932eecff81dSAnton Blanchard PPC_WARN_EMULATED(altivec, regs); 193314cf11afSPaul Mackerras err = emulate_altivec(regs); 193414cf11afSPaul Mackerras if (err == 0) { 193514cf11afSPaul Mackerras regs->nip += 4; /* skip emulated instruction */ 193614cf11afSPaul Mackerras emulate_single_step(regs); 193714cf11afSPaul Mackerras return; 193814cf11afSPaul Mackerras } 193914cf11afSPaul Mackerras 194014cf11afSPaul Mackerras if (err == -EFAULT) { 194114cf11afSPaul Mackerras /* got an error reading the instruction */ 194214cf11afSPaul Mackerras _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); 194314cf11afSPaul Mackerras } else { 194414cf11afSPaul Mackerras /* didn't recognize the instruction */ 194514cf11afSPaul Mackerras /* XXX quick hack for now: set the non-Java bit in the VSCR */ 194676462232SChristian Dietrich printk_ratelimited(KERN_ERR "Unrecognized altivec instruction " 194714cf11afSPaul Mackerras "in %s at %lx\n", current->comm, regs->nip); 1948de79f7b9SPaul Mackerras current->thread.vr_state.vscr.u[3] |= 0x10000; 194914cf11afSPaul Mackerras } 195014cf11afSPaul Mackerras } 195114cf11afSPaul Mackerras #endif /* CONFIG_ALTIVEC */ 195214cf11afSPaul Mackerras 195314cf11afSPaul Mackerras #ifdef CONFIG_FSL_BOOKE 195414cf11afSPaul Mackerras void CacheLockingException(struct pt_regs *regs, unsigned long address, 195514cf11afSPaul Mackerras unsigned long error_code) 195614cf11afSPaul Mackerras { 195714cf11afSPaul Mackerras /* We treat cache locking instructions from the user 195814cf11afSPaul Mackerras * as priv ops, in the future we could try to do 195914cf11afSPaul Mackerras * something smarter 196014cf11afSPaul Mackerras */ 196114cf11afSPaul Mackerras if (error_code & (ESR_DLK|ESR_ILK)) 196214cf11afSPaul Mackerras _exception(SIGILL, regs, ILL_PRVOPC, regs->nip); 196314cf11afSPaul Mackerras return; 196414cf11afSPaul Mackerras } 196514cf11afSPaul Mackerras #endif /* CONFIG_FSL_BOOKE */ 196614cf11afSPaul Mackerras 196714cf11afSPaul Mackerras #ifdef CONFIG_SPE 196814cf11afSPaul Mackerras void SPEFloatingPointException(struct pt_regs *regs) 196914cf11afSPaul Mackerras { 19706a800f36SLiu Yu extern int do_spe_mathemu(struct pt_regs *regs); 197114cf11afSPaul Mackerras unsigned long spefscr; 197214cf11afSPaul Mackerras int fpexc_mode; 197314cf11afSPaul Mackerras int code = 0; 19746a800f36SLiu Yu int err; 19756a800f36SLiu Yu 1976685659eeSyu liu flush_spe_to_thread(current); 197714cf11afSPaul Mackerras 197814cf11afSPaul Mackerras spefscr = current->thread.spefscr; 197914cf11afSPaul Mackerras fpexc_mode = current->thread.fpexc_mode; 198014cf11afSPaul Mackerras 198114cf11afSPaul Mackerras if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) { 198214cf11afSPaul Mackerras code = FPE_FLTOVF; 198314cf11afSPaul Mackerras } 198414cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) { 198514cf11afSPaul Mackerras code = FPE_FLTUND; 198614cf11afSPaul Mackerras } 198714cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV)) 198814cf11afSPaul Mackerras code = FPE_FLTDIV; 198914cf11afSPaul Mackerras else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) { 199014cf11afSPaul Mackerras code = FPE_FLTINV; 199114cf11afSPaul Mackerras } 199214cf11afSPaul Mackerras else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES)) 199314cf11afSPaul Mackerras code = FPE_FLTRES; 199414cf11afSPaul Mackerras 19956a800f36SLiu Yu err = do_spe_mathemu(regs); 19966a800f36SLiu Yu if (err == 0) { 19976a800f36SLiu Yu regs->nip += 4; /* skip emulated instruction */ 19986a800f36SLiu Yu emulate_single_step(regs); 199914cf11afSPaul Mackerras return; 200014cf11afSPaul Mackerras } 20016a800f36SLiu Yu 20026a800f36SLiu Yu if (err == -EFAULT) { 20036a800f36SLiu Yu /* got an error reading the instruction */ 20046a800f36SLiu Yu _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); 20056a800f36SLiu Yu } else if (err == -EINVAL) { 20066a800f36SLiu Yu /* didn't recognize the instruction */ 20076a800f36SLiu Yu printk(KERN_ERR "unrecognized spe instruction " 20086a800f36SLiu Yu "in %s at %lx\n", current->comm, regs->nip); 20096a800f36SLiu Yu } else { 20106a800f36SLiu Yu _exception(SIGFPE, regs, code, regs->nip); 20116a800f36SLiu Yu } 20126a800f36SLiu Yu 20136a800f36SLiu Yu return; 20146a800f36SLiu Yu } 20156a800f36SLiu Yu 20166a800f36SLiu Yu void SPEFloatingPointRoundException(struct pt_regs *regs) 20176a800f36SLiu Yu { 20186a800f36SLiu Yu extern int speround_handler(struct pt_regs *regs); 20196a800f36SLiu Yu int err; 20206a800f36SLiu Yu 20216a800f36SLiu Yu preempt_disable(); 20226a800f36SLiu Yu if (regs->msr & MSR_SPE) 20236a800f36SLiu Yu giveup_spe(current); 20246a800f36SLiu Yu preempt_enable(); 20256a800f36SLiu Yu 20266a800f36SLiu Yu regs->nip -= 4; 20276a800f36SLiu Yu err = speround_handler(regs); 20286a800f36SLiu Yu if (err == 0) { 20296a800f36SLiu Yu regs->nip += 4; /* skip emulated instruction */ 20306a800f36SLiu Yu emulate_single_step(regs); 20316a800f36SLiu Yu return; 20326a800f36SLiu Yu } 20336a800f36SLiu Yu 20346a800f36SLiu Yu if (err == -EFAULT) { 20356a800f36SLiu Yu /* got an error reading the instruction */ 20366a800f36SLiu Yu _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); 20376a800f36SLiu Yu } else if (err == -EINVAL) { 20386a800f36SLiu Yu /* didn't recognize the instruction */ 20396a800f36SLiu Yu printk(KERN_ERR "unrecognized spe instruction " 20406a800f36SLiu Yu "in %s at %lx\n", current->comm, regs->nip); 20416a800f36SLiu Yu } else { 20426a800f36SLiu Yu _exception(SIGFPE, regs, 0, regs->nip); 20436a800f36SLiu Yu return; 20446a800f36SLiu Yu } 20456a800f36SLiu Yu } 204614cf11afSPaul Mackerras #endif 204714cf11afSPaul Mackerras 2048dc1c1ca3SStephen Rothwell /* 2049dc1c1ca3SStephen Rothwell * We enter here if we get an unrecoverable exception, that is, one 2050dc1c1ca3SStephen Rothwell * that happened at a point where the RI (recoverable interrupt) bit 2051dc1c1ca3SStephen Rothwell * in the MSR is 0. This indicates that SRR0/1 are live, and that 2052dc1c1ca3SStephen Rothwell * we therefore lost state by taking this exception. 2053dc1c1ca3SStephen Rothwell */ 2054dc1c1ca3SStephen Rothwell void unrecoverable_exception(struct pt_regs *regs) 2055dc1c1ca3SStephen Rothwell { 2056dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n", 2057dc1c1ca3SStephen Rothwell regs->trap, regs->nip); 2058dc1c1ca3SStephen Rothwell die("Unrecoverable exception", regs, SIGABRT); 2059dc1c1ca3SStephen Rothwell } 206015770a13SNaveen N. Rao NOKPROBE_SYMBOL(unrecoverable_exception); 2061dc1c1ca3SStephen Rothwell 20621e18c17aSJason Gunthorpe #if defined(CONFIG_BOOKE_WDT) || defined(CONFIG_40x) 206314cf11afSPaul Mackerras /* 206414cf11afSPaul Mackerras * Default handler for a Watchdog exception, 206514cf11afSPaul Mackerras * spins until a reboot occurs 206614cf11afSPaul Mackerras */ 206714cf11afSPaul Mackerras void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs) 206814cf11afSPaul Mackerras { 206914cf11afSPaul Mackerras /* Generic WatchdogHandler, implement your own */ 207014cf11afSPaul Mackerras mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE)); 207114cf11afSPaul Mackerras return; 207214cf11afSPaul Mackerras } 207314cf11afSPaul Mackerras 207414cf11afSPaul Mackerras void WatchdogException(struct pt_regs *regs) 207514cf11afSPaul Mackerras { 207614cf11afSPaul Mackerras printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n"); 207714cf11afSPaul Mackerras WatchdogHandler(regs); 207814cf11afSPaul Mackerras } 207914cf11afSPaul Mackerras #endif 2080dc1c1ca3SStephen Rothwell 2081dc1c1ca3SStephen Rothwell /* 2082dc1c1ca3SStephen Rothwell * We enter here if we discover during exception entry that we are 2083dc1c1ca3SStephen Rothwell * running in supervisor mode with a userspace value in the stack pointer. 2084dc1c1ca3SStephen Rothwell */ 2085dc1c1ca3SStephen Rothwell void kernel_bad_stack(struct pt_regs *regs) 2086dc1c1ca3SStephen Rothwell { 2087dc1c1ca3SStephen Rothwell printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n", 2088dc1c1ca3SStephen Rothwell regs->gpr[1], regs->nip); 2089dc1c1ca3SStephen Rothwell die("Bad kernel stack pointer", regs, SIGABRT); 2090dc1c1ca3SStephen Rothwell } 209115770a13SNaveen N. Rao NOKPROBE_SYMBOL(kernel_bad_stack); 209214cf11afSPaul Mackerras 209314cf11afSPaul Mackerras void __init trap_init(void) 209414cf11afSPaul Mackerras { 209514cf11afSPaul Mackerras } 209680947e7cSGeert Uytterhoeven 209780947e7cSGeert Uytterhoeven 209880947e7cSGeert Uytterhoeven #ifdef CONFIG_PPC_EMULATED_STATS 209980947e7cSGeert Uytterhoeven 210080947e7cSGeert Uytterhoeven #define WARN_EMULATED_SETUP(type) .type = { .name = #type } 210180947e7cSGeert Uytterhoeven 210280947e7cSGeert Uytterhoeven struct ppc_emulated ppc_emulated = { 210380947e7cSGeert Uytterhoeven #ifdef CONFIG_ALTIVEC 210480947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(altivec), 210580947e7cSGeert Uytterhoeven #endif 210680947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(dcba), 210780947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(dcbz), 210880947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(fp_pair), 210980947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(isel), 211080947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(mcrxr), 211180947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(mfpvr), 211280947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(multiple), 211380947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(popcntb), 211480947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(spe), 211580947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(string), 2116a3821b2aSScott Wood WARN_EMULATED_SETUP(sync), 211780947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(unaligned), 211880947e7cSGeert Uytterhoeven #ifdef CONFIG_MATH_EMULATION 211980947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(math), 212080947e7cSGeert Uytterhoeven #endif 212180947e7cSGeert Uytterhoeven #ifdef CONFIG_VSX 212280947e7cSGeert Uytterhoeven WARN_EMULATED_SETUP(vsx), 212380947e7cSGeert Uytterhoeven #endif 2124efcac658SAlexey Kardashevskiy #ifdef CONFIG_PPC64 2125efcac658SAlexey Kardashevskiy WARN_EMULATED_SETUP(mfdscr), 2126efcac658SAlexey Kardashevskiy WARN_EMULATED_SETUP(mtdscr), 2127f83319d7SAnton Blanchard WARN_EMULATED_SETUP(lq_stq), 21285080332cSMichael Neuling WARN_EMULATED_SETUP(lxvw4x), 21295080332cSMichael Neuling WARN_EMULATED_SETUP(lxvh8x), 21305080332cSMichael Neuling WARN_EMULATED_SETUP(lxvd2x), 21315080332cSMichael Neuling WARN_EMULATED_SETUP(lxvb16x), 2132efcac658SAlexey Kardashevskiy #endif 213380947e7cSGeert Uytterhoeven }; 213480947e7cSGeert Uytterhoeven 213580947e7cSGeert Uytterhoeven u32 ppc_warn_emulated; 213680947e7cSGeert Uytterhoeven 213780947e7cSGeert Uytterhoeven void ppc_warn_emulated_print(const char *type) 213880947e7cSGeert Uytterhoeven { 213976462232SChristian Dietrich pr_warn_ratelimited("%s used emulated %s instruction\n", current->comm, 214080947e7cSGeert Uytterhoeven type); 214180947e7cSGeert Uytterhoeven } 214280947e7cSGeert Uytterhoeven 214380947e7cSGeert Uytterhoeven static int __init ppc_warn_emulated_init(void) 214480947e7cSGeert Uytterhoeven { 214580947e7cSGeert Uytterhoeven struct dentry *dir, *d; 214680947e7cSGeert Uytterhoeven unsigned int i; 214780947e7cSGeert Uytterhoeven struct ppc_emulated_entry *entries = (void *)&ppc_emulated; 214880947e7cSGeert Uytterhoeven 214980947e7cSGeert Uytterhoeven if (!powerpc_debugfs_root) 215080947e7cSGeert Uytterhoeven return -ENODEV; 215180947e7cSGeert Uytterhoeven 215280947e7cSGeert Uytterhoeven dir = debugfs_create_dir("emulated_instructions", 215380947e7cSGeert Uytterhoeven powerpc_debugfs_root); 215480947e7cSGeert Uytterhoeven if (!dir) 215580947e7cSGeert Uytterhoeven return -ENOMEM; 215680947e7cSGeert Uytterhoeven 215757ad583fSRussell Currey d = debugfs_create_u32("do_warn", 0644, dir, 215880947e7cSGeert Uytterhoeven &ppc_warn_emulated); 215980947e7cSGeert Uytterhoeven if (!d) 216080947e7cSGeert Uytterhoeven goto fail; 216180947e7cSGeert Uytterhoeven 216280947e7cSGeert Uytterhoeven for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++) { 216357ad583fSRussell Currey d = debugfs_create_u32(entries[i].name, 0644, dir, 216480947e7cSGeert Uytterhoeven (u32 *)&entries[i].val.counter); 216580947e7cSGeert Uytterhoeven if (!d) 216680947e7cSGeert Uytterhoeven goto fail; 216780947e7cSGeert Uytterhoeven } 216880947e7cSGeert Uytterhoeven 216980947e7cSGeert Uytterhoeven return 0; 217080947e7cSGeert Uytterhoeven 217180947e7cSGeert Uytterhoeven fail: 217280947e7cSGeert Uytterhoeven debugfs_remove_recursive(dir); 217380947e7cSGeert Uytterhoeven return -ENOMEM; 217480947e7cSGeert Uytterhoeven } 217580947e7cSGeert Uytterhoeven 217680947e7cSGeert Uytterhoeven device_initcall(ppc_warn_emulated_init); 217780947e7cSGeert Uytterhoeven 217880947e7cSGeert Uytterhoeven #endif /* CONFIG_PPC_EMULATED_STATS */ 2179