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 unsigned char ras_log_buf[RTAS_ERROR_LOG_MAX];
56 static spinlock_t ras_log_buf_lock = SPIN_LOCK_UNLOCKED;
58 static int ras_get_sensor_state_token;
59 static int ras_check_exception_token;
61 #define EPOW_SENSOR_TOKEN 9
62 #define EPOW_SENSOR_INDEX 0
63 #define RAS_VECTOR_OFFSET 0x500
65 static irqreturn_t ras_epow_interrupt(int irq, void *dev_id,
66 struct pt_regs * regs);
67 static irqreturn_t ras_error_interrupt(int irq, void *dev_id,
68 struct pt_regs * regs);
72 static void request_ras_irqs(struct device_node *np, char *propname,
73 irqreturn_t (*handler)(int, void *, struct pt_regs *),
76 unsigned int *ireg, len, i;
79 ireg = (unsigned int *)get_property(np, propname, &len);
82 n_intr = prom_n_intr_cells(np);
83 len /= n_intr * sizeof(*ireg);
85 for (i = 0; i < len; i++) {
86 virq = virt_irq_create_mapping(*ireg);
88 printk(KERN_ERR "Unable to allocate interrupt "
89 "number for %s\n", np->full_name);
92 if (request_irq(irq_offset_up(virq), handler, 0, name, NULL)) {
93 printk(KERN_ERR "Unable to request interrupt %d for "
94 "%s\n", irq_offset_up(virq), np->full_name);
102 * Initialize handlers for the set of interrupts caused by hardware errors
103 * and power system events.
105 static int __init init_ras_IRQ(void)
107 struct device_node *np;
109 ras_get_sensor_state_token = rtas_token("get-sensor-state");
110 ras_check_exception_token = rtas_token("check-exception");
112 /* Internal Errors */
113 np = of_find_node_by_path("/event-sources/internal-errors");
115 request_ras_irqs(np, "open-pic-interrupt", ras_error_interrupt,
117 request_ras_irqs(np, "interrupts", ras_error_interrupt,
123 np = of_find_node_by_path("/event-sources/epow-events");
125 request_ras_irqs(np, "open-pic-interrupt", ras_epow_interrupt,
127 request_ras_irqs(np, "interrupts", ras_epow_interrupt,
134 __initcall(init_ras_IRQ);
137 * Handle power subsystem events (EPOW).
139 * Presently we just log the event has occurred. This should be fixed
140 * to examine the type of power failure and take appropriate action where
141 * the time horizon permits something useful to be done.
144 ras_epow_interrupt(int irq, void *dev_id, struct pt_regs * regs)
146 int status = 0xdeadbeef;
150 status = rtas_call(ras_get_sensor_state_token, 2, 2, &state,
151 EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX);
154 critical = 1; /* Time Critical */
158 spin_lock(&ras_log_buf_lock);
160 status = rtas_call(ras_check_exception_token, 6, 1, NULL,
162 virt_irq_to_real(irq_offset_down(irq)),
163 RTAS_EPOW_WARNING | RTAS_POWERMGM_EVENTS,
164 critical, __pa(&ras_log_buf), RTAS_ERROR_LOG_MAX);
166 udbg_printf("EPOW <0x%lx 0x%x 0x%x>\n",
167 *((unsigned long *)&ras_log_buf), status, state);
168 printk(KERN_WARNING "EPOW <0x%lx 0x%x 0x%x>\n",
169 *((unsigned long *)&ras_log_buf), status, state);
171 /* format and print the extended information */
172 log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0);
174 spin_unlock(&ras_log_buf_lock);
179 * Handle hardware error interrupts.
181 * RTAS check-exception is called to collect data on the exception. If
182 * the error is deemed recoverable, we log a warning and return.
183 * For nonrecoverable errors, an error is logged and we stop all processing
184 * as quickly as possible in order to prevent propagation of the failure.
187 ras_error_interrupt(int irq, void *dev_id, struct pt_regs * regs)
189 struct rtas_error_log *rtas_elog;
190 int status = 0xdeadbeef;
193 spin_lock(&ras_log_buf_lock);
195 status = rtas_call(ras_check_exception_token, 6, 1, NULL,
197 virt_irq_to_real(irq_offset_down(irq)),
198 RTAS_INTERNAL_ERROR, 1 /*Time Critical */,
199 __pa(&ras_log_buf), RTAS_ERROR_LOG_MAX);
201 rtas_elog = (struct rtas_error_log *)ras_log_buf;
203 if ((status == 0) && (rtas_elog->severity >= SEVERITY_ERROR_SYNC))
208 /* format and print the extended information */
209 log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, fatal);
212 udbg_printf("Fatal HW Error <0x%lx 0x%x>\n",
213 *((unsigned long *)&ras_log_buf), status);
214 printk(KERN_EMERG "Error: Fatal hardware error <0x%lx 0x%x>\n",
215 *((unsigned long *)&ras_log_buf), status);
218 /* Don't actually power off when debugging so we can test
219 * without actually failing while injecting errors.
220 * Error data will not be logged to syslog.
225 udbg_printf("Recoverable HW Error <0x%lx 0x%x>\n",
226 *((unsigned long *)&ras_log_buf), status);
228 "Warning: Recoverable hardware error <0x%lx 0x%x>\n",
229 *((unsigned long *)&ras_log_buf), status);
232 spin_unlock(&ras_log_buf_lock);