2 * Copyright (C) 2001 Dave Engebretsen IBM Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * 2001/09/21 : engebret : Created with minimal EPOW and HW exception support.
24 #include <linux/errno.h>
25 #include <linux/threads.h>
26 #include <linux/kernel_stat.h>
27 #include <linux/signal.h>
28 #include <linux/sched.h>
29 #include <linux/ioport.h>
30 #include <linux/interrupt.h>
31 #include <linux/timex.h>
32 #include <linux/init.h>
33 #include <linux/delay.h>
34 #include <linux/irq.h>
35 #include <linux/random.h>
36 #include <linux/sysrq.h>
37 #include <linux/bitops.h>
39 #include <asm/uaccess.h>
40 #include <asm/system.h>
42 #include <asm/pgtable.h>
44 #include <asm/cache.h>
46 #include <asm/ptrace.h>
47 #include <asm/machdep.h>
50 #include <asm/firmware.h>
54 static unsigned char ras_log_buf[RTAS_ERROR_LOG_MAX];
55 static DEFINE_SPINLOCK(ras_log_buf_lock);
57 static char mce_data_buf[RTAS_ERROR_LOG_MAX];
59 static int ras_get_sensor_state_token;
60 static int ras_check_exception_token;
62 #define EPOW_SENSOR_TOKEN 9
63 #define EPOW_SENSOR_INDEX 0
64 #define RAS_VECTOR_OFFSET 0x500
66 static irqreturn_t ras_epow_interrupt(int irq, void *dev_id);
67 static irqreturn_t ras_error_interrupt(int irq, void *dev_id);
71 * Initialize handlers for the set of interrupts caused by hardware errors
72 * and power system events.
74 static int __init init_ras_IRQ(void)
76 struct device_node *np;
78 ras_get_sensor_state_token = rtas_token("get-sensor-state");
79 ras_check_exception_token = rtas_token("check-exception");
82 np = of_find_node_by_path("/event-sources/internal-errors");
84 request_event_sources_irqs(np, ras_error_interrupt,
90 np = of_find_node_by_path("/event-sources/epow-events");
92 request_event_sources_irqs(np, ras_epow_interrupt, "RAS_EPOW");
98 __initcall(init_ras_IRQ);
101 * Handle power subsystem events (EPOW).
103 * Presently we just log the event has occurred. This should be fixed
104 * to examine the type of power failure and take appropriate action where
105 * the time horizon permits something useful to be done.
107 static irqreturn_t ras_epow_interrupt(int irq, void *dev_id)
109 int status = 0xdeadbeef;
113 status = rtas_call(ras_get_sensor_state_token, 2, 2, &state,
114 EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX);
117 critical = 1; /* Time Critical */
121 spin_lock(&ras_log_buf_lock);
123 status = rtas_call(ras_check_exception_token, 6, 1, NULL,
126 RTAS_EPOW_WARNING | RTAS_POWERMGM_EVENTS,
127 critical, __pa(&ras_log_buf),
128 rtas_get_error_log_max());
130 udbg_printf("EPOW <0x%lx 0x%x 0x%x>\n",
131 *((unsigned long *)&ras_log_buf), status, state);
132 printk(KERN_WARNING "EPOW <0x%lx 0x%x 0x%x>\n",
133 *((unsigned long *)&ras_log_buf), status, state);
135 /* format and print the extended information */
136 log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0);
138 spin_unlock(&ras_log_buf_lock);
143 * Handle hardware error interrupts.
145 * RTAS check-exception is called to collect data on the exception. If
146 * the error is deemed recoverable, we log a warning and return.
147 * For nonrecoverable errors, an error is logged and we stop all processing
148 * as quickly as possible in order to prevent propagation of the failure.
150 static irqreturn_t ras_error_interrupt(int irq, void *dev_id)
152 struct rtas_error_log *rtas_elog;
153 int status = 0xdeadbeef;
156 spin_lock(&ras_log_buf_lock);
158 status = rtas_call(ras_check_exception_token, 6, 1, NULL,
161 RTAS_INTERNAL_ERROR, 1 /*Time Critical */,
163 rtas_get_error_log_max());
165 rtas_elog = (struct rtas_error_log *)ras_log_buf;
167 if ((status == 0) && (rtas_elog->severity >= RTAS_SEVERITY_ERROR_SYNC))
172 /* format and print the extended information */
173 log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, fatal);
176 udbg_printf("Fatal HW Error <0x%lx 0x%x>\n",
177 *((unsigned long *)&ras_log_buf), status);
178 printk(KERN_EMERG "Error: Fatal hardware error <0x%lx 0x%x>\n",
179 *((unsigned long *)&ras_log_buf), status);
181 #ifndef DEBUG_RTAS_POWER_OFF
182 /* Don't actually power off when debugging so we can test
183 * without actually failing while injecting errors.
184 * Error data will not be logged to syslog.
189 udbg_printf("Recoverable HW Error <0x%lx 0x%x>\n",
190 *((unsigned long *)&ras_log_buf), status);
192 "Warning: Recoverable hardware error <0x%lx 0x%x>\n",
193 *((unsigned long *)&ras_log_buf), status);
196 spin_unlock(&ras_log_buf_lock);
200 /* Get the error information for errors coming through the
201 * FWNMI vectors. The pt_regs' r3 will be updated to reflect
202 * the actual r3 if possible, and a ptr to the error log entry
203 * will be returned if found.
205 * The mce_data_buf does not have any locks or protection around it,
206 * if a second machine check comes in, or a system reset is done
207 * before we have logged the error, then we will get corruption in the
208 * error log. This is preferable over holding off on calling
209 * ibm,nmi-interlock which would result in us checkstopping if a
210 * second machine check did come in.
212 static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
214 unsigned long errdata = regs->gpr[3];
215 struct rtas_error_log *errhdr = NULL;
216 unsigned long *savep;
218 if ((errdata >= 0x7000 && errdata < 0x7fff0) ||
219 (errdata >= rtas.base && errdata < rtas.base + rtas.size - 16)) {
220 savep = __va(errdata);
221 regs->gpr[3] = savep[0]; /* restore original r3 */
222 memset(mce_data_buf, 0, RTAS_ERROR_LOG_MAX);
223 memcpy(mce_data_buf, (char *)(savep + 1), RTAS_ERROR_LOG_MAX);
224 errhdr = (struct rtas_error_log *)mce_data_buf;
226 printk("FWNMI: corrupt r3\n");
231 /* Call this when done with the data returned by FWNMI_get_errinfo.
232 * It will release the saved data area for other CPUs in the
233 * partition to receive FWNMI errors.
235 static void fwnmi_release_errinfo(void)
237 int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL);
239 printk("FWNMI: nmi-interlock failed: %d\n", ret);
242 int pSeries_system_reset_exception(struct pt_regs *regs)
245 struct rtas_error_log *errhdr = fwnmi_get_errinfo(regs);
247 /* XXX Should look at FWNMI information */
249 fwnmi_release_errinfo();
251 return 0; /* need to perform reset */
255 * See if we can recover from a machine check exception.
256 * This is only called on power4 (or above) and only via
257 * the Firmware Non-Maskable Interrupts (fwnmi) handler
258 * which provides the error analysis for us.
260 * Return 1 if corrected (or delivered a signal).
261 * Return 0 if there is nothing we can do.
263 static int recover_mce(struct pt_regs *regs, struct rtas_error_log * err)
267 if (err->disposition == RTAS_DISP_FULLY_RECOVERED) {
268 /* Platform corrected itself */
270 } else if ((regs->msr & MSR_RI) &&
272 err->severity == RTAS_SEVERITY_ERROR_SYNC &&
273 err->disposition == RTAS_DISP_NOT_RECOVERED &&
274 err->target == RTAS_TARGET_MEMORY &&
275 err->type == RTAS_TYPE_ECC_UNCORR &&
276 !(current->pid == 0 || is_global_init(current))) {
277 /* Kill off a user process with an ECC error */
278 printk(KERN_ERR "MCE: uncorrectable ecc error for pid %d\n",
280 /* XXX something better for ECC error? */
281 _exception(SIGBUS, regs, BUS_ADRERR, regs->nip);
285 log_error((char *)err, ERR_TYPE_RTAS_LOG, !nonfatal);
291 * Handle a machine check.
293 * Note that on Power 4 and beyond Firmware Non-Maskable Interrupts (fwnmi)
294 * should be present. If so the handler which called us tells us if the
295 * error was recovered (never true if RI=0).
297 * On hardware prior to Power 4 these exceptions were asynchronous which
298 * means we can't tell exactly where it occurred and so we can't recover.
300 int pSeries_machine_check_exception(struct pt_regs *regs)
302 struct rtas_error_log *errp;
305 errp = fwnmi_get_errinfo(regs);
306 fwnmi_release_errinfo();
307 if (errp && recover_mce(regs, errp))