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
58 static void ras_epow_interrupt(int irq, void *dev_id, struct pt_regs * regs);
59 static void ras_error_interrupt(int irq, void *dev_id, struct pt_regs * regs);
60 void 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 */
init_ras_IRQ(void)68 void 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(irq_offset_up(*(ireg)),
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(irq_offset_up(*(ireg)),
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 */
102 static void
ras_epow_interrupt(int irq,void * dev_id,struct pt_regs * regs)103 ras_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 RTAS_EPOW_WARNING | RTAS_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 /* format and print the extended information */
121 log_error((char *)&log_entry, ERR_TYPE_RTAS_LOG, 0);
122 }
123
124 /*
125 * Handle hardware error interrupts.
126 *
127 * RTAS check-exception is called to collect data on the exception. If
128 * the error is deemed recoverable, we log a warning and return.
129 * For nonrecoverable errors, an error is logged and we stop all processing
130 * as quickly as possible in order to prevent propagation of the failure.
131 */
132 static void
ras_error_interrupt(int irq,void * dev_id,struct pt_regs * regs)133 ras_error_interrupt(int irq, void *dev_id, struct pt_regs * regs)
134 {
135 struct rtas_error_log log_entry;
136 unsigned int size = sizeof(log_entry);
137 long status = 0xdeadbeef;
138 int fatal;
139
140 status = rtas_call(rtas_token("check-exception"), 6, 1, NULL,
141 0x500, irq,
142 RTAS_INTERNAL_ERROR,
143 1, /* Time Critical */
144 __pa(&log_entry), size);
145
146 if ((status == 0) && (log_entry.severity >= SEVERITY_ERROR_SYNC))
147 fatal = 1;
148 else
149 fatal = 0;
150
151 /* format and print the extended information */
152 log_error((char *)&log_entry, ERR_TYPE_RTAS_LOG, fatal);
153
154 if (fatal) {
155 udbg_printf("HW Error <0x%lx 0x%lx>\n",
156 *((unsigned long *)&log_entry), status);
157 printk(KERN_EMERG
158 "Error: Fatal hardware error <0x%lx 0x%lx>\n",
159 *((unsigned long *)&log_entry), status);
160
161 #ifndef DEBUG
162 /* Don't actually power off when debugging so we can test
163 * without actually failing while injecting errors.
164 * Error data will not be logged to syslog.
165 */
166 ppc_md.power_off();
167 #endif
168 } else {
169 udbg_printf("Recoverable HW Error <0x%lx 0x%lx>\n",
170 *((unsigned long *)&log_entry), status);
171 printk(KERN_WARNING
172 "Warning: Recoverable hardware error <0x%lx 0x%lx>\n",
173 *((unsigned long *)&log_entry), status);
174
175 return;
176 }
177 }
178