3 * Copyright (C) 2001 Dave Engebretsen IBM Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * 2001/09/21 : engebret : Created with minimal EPOW and HW exception support.
25 #include <linux/errno.h>
26 #include <linux/threads.h>
27 #include <linux/kernel_stat.h>
28 #include <linux/signal.h>
29 #include <linux/sched.h>
30 #include <linux/ioport.h>
31 #include <linux/interrupt.h>
32 #include <linux/timex.h>
33 #include <linux/init.h>
34 #include <linux/slab.h>
35 #include <linux/pci.h>
36 #include <linux/delay.h>
37 #include <linux/irq.h>
38 #include <linux/random.h>
39 #include <linux/sysrq.h>
41 #include <asm/uaccess.h>
42 #include <asm/bitops.h>
43 #include <asm/system.h>
45 #include <asm/pgtable.h>
47 #include <asm/cache.h>
49 #include <asm/ptrace.h>
50 #include <asm/iSeries/LparData.h>
51 #include <asm/machdep.h>
53 #include <asm/ppcdebug.h>
55 static irqreturn_t ras_epow_interrupt(int irq, void *dev_id,
56 struct pt_regs * regs);
57 static irqreturn_t ras_error_interrupt(int irq, void *dev_id,
58 struct pt_regs * regs);
63 * Initialize handlers for the set of interrupts caused by hardware errors
64 * and power system events.
66 static int __init init_ras_IRQ(void)
68 struct device_node *np;
69 unsigned int *ireg, len, i;
72 if ((np = of_find_node_by_path("/event-sources/internal-errors")) &&
73 (ireg = (unsigned int *)get_property(np, "open-pic-interrupt",
75 for (i=0; i<(len / sizeof(*ireg)); i++) {
76 virq = virt_irq_create_mapping(*(ireg));
78 printk(KERN_ERR "Unable to allocate interrupt "
79 "number for %s\n", np->full_name);
82 request_irq(irq_offset_up(virq),
83 ras_error_interrupt, 0,
90 if ((np = of_find_node_by_path("/event-sources/epow-events")) &&
91 (ireg = (unsigned int *)get_property(np, "open-pic-interrupt",
93 for (i=0; i<(len / sizeof(*ireg)); i++) {
94 virq = virt_irq_create_mapping(*(ireg));
96 printk(KERN_ERR "Unable to allocate interrupt "
97 " number for %s\n", np->full_name);
100 request_irq(irq_offset_up(virq),
101 ras_epow_interrupt, 0,
110 __initcall(init_ras_IRQ);
112 static struct rtas_error_log log_buf;
113 static spinlock_t log_lock = SPIN_LOCK_UNLOCKED;
116 * Handle power subsystem events (EPOW).
118 * Presently we just log the event has occurred. This should be fixed
119 * to examine the type of power failure and take appropriate action where
120 * the time horizon permits something useful to be done.
123 ras_epow_interrupt(int irq, void *dev_id, struct pt_regs * regs)
125 struct rtas_error_log log_entry;
126 unsigned int size = sizeof(log_entry);
127 long status = 0xdeadbeef;
129 spin_lock(&log_lock);
131 status = rtas_call(rtas_token("check-exception"), 6, 1, NULL,
133 RTAS_EPOW_WARNING | RTAS_POWERMGM_EVENTS,
134 1, /* Time Critical */
135 __pa(&log_buf), size);
139 spin_unlock(&log_lock);
141 udbg_printf("EPOW <0x%lx 0x%lx>\n",
142 *((unsigned long *)&log_entry), status);
144 "EPOW <0x%lx 0x%lx>\n",*((unsigned long *)&log_entry), status);
146 /* format and print the extended information */
147 log_error((char *)&log_entry, ERR_TYPE_RTAS_LOG, 0);
153 * Handle hardware error interrupts.
155 * RTAS check-exception is called to collect data on the exception. If
156 * the error is deemed recoverable, we log a warning and return.
157 * For nonrecoverable errors, an error is logged and we stop all processing
158 * as quickly as possible in order to prevent propagation of the failure.
161 ras_error_interrupt(int irq, void *dev_id, struct pt_regs * regs)
163 struct rtas_error_log log_entry;
164 unsigned int size = sizeof(log_entry);
165 long status = 0xdeadbeef;
168 spin_lock(&log_lock);
170 status = rtas_call(rtas_token("check-exception"), 6, 1, NULL,
173 1, /* Time Critical */
174 __pa(&log_buf), size);
178 spin_unlock(&log_lock);
180 if ((status == 0) && (log_entry.severity >= SEVERITY_ERROR_SYNC))
185 /* format and print the extended information */
186 log_error((char *)&log_entry, ERR_TYPE_RTAS_LOG, fatal);
189 udbg_printf("HW Error <0x%lx 0x%lx>\n",
190 *((unsigned long *)&log_entry), status);
192 "Error: Fatal hardware error <0x%lx 0x%lx>\n",
193 *((unsigned long *)&log_entry), status);
196 /* Don't actually power off when debugging so we can test
197 * without actually failing while injecting errors.
198 * Error data will not be logged to syslog.
203 udbg_printf("Recoverable HW Error <0x%lx 0x%lx>\n",
204 *((unsigned long *)&log_entry), status);
206 "Warning: Recoverable hardware error <0x%lx 0x%lx>\n",
207 *((unsigned long *)&log_entry), status);