1 2/* 3 * ras.c 4 * Copyright (C) 2001 Dave Engebretsen IBM Corporation 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 21/* Change Activity: 22 * 2001/09/21 : engebret : Created with minimal EPOW and HW exception support. 23 * End Change Activity 24 */ 25 26#include <linux/ptrace.h> 27#include <linux/errno.h> 28#include <linux/threads.h> 29#include <linux/kernel_stat.h> 30#include <linux/signal.h> 31#include <linux/sched.h> 32#include <linux/ioport.h> 33#include <linux/interrupt.h> 34#include <linux/timex.h> 35#include <linux/init.h> 36#include <linux/slab.h> 37#include <linux/pci.h> 38#include <linux/delay.h> 39#include <linux/irq.h> 40#include <linux/proc_fs.h> 41#include <linux/random.h> 42#include <linux/sysrq.h> 43 44#include <asm/uaccess.h> 45#include <asm/bitops.h> 46#include <asm/system.h> 47#include <asm/io.h> 48#include <asm/pgtable.h> 49#include <asm/irq.h> 50#include <asm/cache.h> 51#include <asm/prom.h> 52#include <asm/ptrace.h> 53#include <asm/iSeries/LparData.h> 54#include <asm/machdep.h> 55#include <asm/rtas.h> 56#include <asm/ppcdebug.h> 57 58static void ras_epow_interrupt(int irq, void *dev_id, struct pt_regs * regs); 59static void ras_error_interrupt(int irq, void *dev_id, struct pt_regs * regs); 60void init_ras_IRQ(void); 61 62/* #define DEBUG */ 63 64/* 65 * Initialize handlers for the set of interrupts caused by hardware errors 66 * and power system events. 67 */ 68void init_ras_IRQ(void) { 69 struct device_node *np; 70 unsigned int *ireg, len, i; 71 72 if((np = find_path_device("/event-sources/internal-errors")) && 73 (ireg = (unsigned int *)get_property(np, "open-pic-interrupt", 74 &len))) { 75 for(i=0; i<(len / sizeof(*ireg)); i++) { 76 request_irq(virt_irq_create_mapping(*(ireg)) + NUM_8259_INTERRUPTS, 77 &ras_error_interrupt, 0, 78 "RAS_ERROR", NULL); 79 ireg++; 80 } 81 } 82 83 if((np = find_path_device("/event-sources/epow-events")) && 84 (ireg = (unsigned int *)get_property(np, "open-pic-interrupt", 85 &len))) { 86 for(i=0; i<(len / sizeof(*ireg)); i++) { 87 request_irq(virt_irq_create_mapping(*(ireg)) + NUM_8259_INTERRUPTS, 88 &ras_epow_interrupt, 0, 89 "RAS_EPOW", NULL); 90 ireg++; 91 } 92 } 93} 94 95/* 96 * Handle power subsystem events (EPOW). 97 * 98 * Presently we just log the event has occured. This should be fixed 99 * to examine the type of power failure and take appropriate action where 100 * the time horizon permits something useful to be done. 101 */ 102static void 103ras_epow_interrupt(int irq, void *dev_id, struct pt_regs * regs) 104{ 105 struct rtas_error_log log_entry; 106 unsigned int size = sizeof(log_entry); 107 long status = 0xdeadbeef; 108 109 status = rtas_call(rtas_token("check-exception"), 6, 1, NULL, 110 0x500, irq, 111 EPOW_WARNING | POWERMGM_EVENTS, 112 1, /* Time Critical */ 113 __pa(&log_entry), size); 114 115 udbg_printf("EPOW <0x%lx 0x%lx>\n", 116 *((unsigned long *)&log_entry), status); 117 printk(KERN_WARNING 118 "EPOW <0x%lx 0x%lx>\n",*((unsigned long *)&log_entry), status); 119} 120 121/* 122 * Handle hardware error interrupts. 123 * 124 * RTAS check-exception is called to collect data on the exception. If 125 * the error is deemed recoverable, we log a warning and return. 126 * For nonrecoverable errors, an error is logged and we stop all processing 127 * as quickly as possible in order to prevent propagation of the failure. 128 */ 129static void 130ras_error_interrupt(int irq, void *dev_id, struct pt_regs * regs) 131{ 132 struct rtas_error_log log_entry; 133 unsigned int size = sizeof(log_entry); 134 long status = 0xdeadbeef; 135 136 status = rtas_call(rtas_token("check-exception"), 6, 1, NULL, 137 0x500, irq, 138 INTERNAL_ERROR, 139 1, /* Time Critical */ 140 __pa(&log_entry), size); 141 142 if((status != 1) && 143 (log_entry.severity >= SEVERITY_ERROR_SYNC)) { 144 udbg_printf("HW Error <0x%lx 0x%lx>\n", 145 *((unsigned long *)&log_entry), status); 146 printk(KERN_EMERG 147 "Error: Fatal hardware error <0x%lx 0x%lx>\n", 148 *((unsigned long *)&log_entry), status); 149 150#ifndef DEBUG 151 /* Don't actually power off when debugging so we can test 152 * without actually failing while injecting errors. 153 */ 154 ppc_md.power_off(); 155#endif 156 } else { 157 udbg_printf("Recoverable HW Error <0x%lx 0x%lx>\n", 158 *((unsigned long *)&log_entry), status); 159 printk(KERN_WARNING 160 "Warning: Recoverable hardware error <0x%lx 0x%lx>\n", 161 *((unsigned long *)&log_entry), status); 162 163 return; 164 } 165} 166