blob: 92367faecbbff274c3396bdb9354a92f18bd393c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * File: mca.c
3 * Purpose: Generic MCA handling layer
4 *
5 * Updated for latest kernel
6 * Copyright (C) 2003 Hewlett-Packard Co
7 * David Mosberger-Tang <davidm@hpl.hp.com>
8 *
9 * Copyright (C) 2002 Dell Inc.
10 * Copyright (C) Matt Domsch (Matt_Domsch@dell.com)
11 *
12 * Copyright (C) 2002 Intel
13 * Copyright (C) Jenna Hall (jenna.s.hall@intel.com)
14 *
15 * Copyright (C) 2001 Intel
16 * Copyright (C) Fred Lewis (frederick.v.lewis@intel.com)
17 *
18 * Copyright (C) 2000 Intel
19 * Copyright (C) Chuck Fleckenstein (cfleck@co.intel.com)
20 *
21 * Copyright (C) 1999, 2004 Silicon Graphics, Inc.
22 * Copyright (C) Vijay Chander(vijay@engr.sgi.com)
23 *
24 * 03/04/15 D. Mosberger Added INIT backtrace support.
25 * 02/03/25 M. Domsch GUID cleanups
26 *
27 * 02/01/04 J. Hall Aligned MCA stack to 16 bytes, added platform vs. CPU
28 * error flag, set SAL default return values, changed
29 * error record structure to linked list, added init call
30 * to sal_get_state_info_size().
31 *
32 * 01/01/03 F. Lewis Added setup of CMCI and CPEI IRQs, logging of corrected
33 * platform errors, completed code for logging of
34 * corrected & uncorrected machine check errors, and
35 * updated for conformance with Nov. 2000 revision of the
36 * SAL 3.0 spec.
37 * 00/03/29 C. Fleckenstein Fixed PAL/SAL update issues, began MCA bug fixes, logging issues,
38 * added min save state dump, added INIT handler.
39 *
40 * 2003-12-08 Keith Owens <kaos@sgi.com>
41 * smp_call_function() must not be called from interrupt context (can
42 * deadlock on tasklist_lock). Use keventd to call smp_call_function().
43 *
44 * 2004-02-01 Keith Owens <kaos@sgi.com>
45 * Avoid deadlock when using printk() for MCA and INIT records.
46 * Delete all record printing code, moved to salinfo_decode in user space.
47 * Mark variables and functions static where possible.
48 * Delete dead variables and functions.
49 * Reorder to remove the need for forward declarations and to consolidate
50 * related code.
Keith Owens7f613c72005-09-11 17:22:53 +100051 *
52 * 2005-08-12 Keith Owens <kaos@sgi.com>
53 * Convert MCA/INIT handlers to use per event stacks and SAL/OS state.
Keith Owens9138d582005-11-07 11:27:13 -080054 *
55 * 2005-10-07 Keith Owens <kaos@sgi.com>
56 * Add notify_die() hooks.
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -070057 *
58 * 2006-09-15 Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
59 * Add printing support for MCA/INIT.
Russ Anderson1612b182007-05-18 17:17:17 -050060 *
61 * 2007-04-27 Russ Anderson <rja@sgi.com>
62 * Support multiple cpus going through OS_MCA in the same event.
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#include <linux/types.h>
65#include <linux/init.h>
66#include <linux/sched.h>
67#include <linux/interrupt.h>
68#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#include <linux/bootmem.h>
70#include <linux/acpi.h>
71#include <linux/timer.h>
72#include <linux/module.h>
73#include <linux/kernel.h>
74#include <linux/smp.h>
75#include <linux/workqueue.h>
Akinobu Mita4668f0c2006-03-26 01:39:03 -080076#include <linux/cpumask.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070077#include <linux/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79#include <asm/delay.h>
80#include <asm/machvec.h>
81#include <asm/meminit.h>
82#include <asm/page.h>
83#include <asm/ptrace.h>
84#include <asm/system.h>
85#include <asm/sal.h>
86#include <asm/mca.h>
Zou Nan haia79561132006-12-07 09:51:35 -080087#include <asm/kexec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89#include <asm/irq.h>
90#include <asm/hw_irq.h>
91
Russ Andersond2a28ad2006-03-24 09:49:52 -080092#include "mca_drv.h"
Keith Owens7f613c72005-09-11 17:22:53 +100093#include "entry.h"
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#if defined(IA64_MCA_DEBUG_INFO)
96# define IA64_MCA_DEBUG(fmt...) printk(fmt)
97#else
98# define IA64_MCA_DEBUG(fmt...)
99#endif
100
101/* Used by mca_asm.S */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102DEFINE_PER_CPU(u64, ia64_mca_data); /* == __per_cpu_mca[smp_processor_id()] */
103DEFINE_PER_CPU(u64, ia64_mca_per_cpu_pte); /* PTE to map per-CPU area */
104DEFINE_PER_CPU(u64, ia64_mca_pal_pte); /* PTE to map PAL code */
105DEFINE_PER_CPU(u64, ia64_mca_pal_base); /* vaddr PAL code granule */
106
107unsigned long __per_cpu_mca[NR_CPUS];
108
109/* In mca_asm.S */
Keith Owens7f613c72005-09-11 17:22:53 +1000110extern void ia64_os_init_dispatch_monarch (void);
111extern void ia64_os_init_dispatch_slave (void);
112
113static int monarch_cpu = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115static ia64_mc_info_t ia64_mc_info;
116
117#define MAX_CPE_POLL_INTERVAL (15*60*HZ) /* 15 minutes */
118#define MIN_CPE_POLL_INTERVAL (2*60*HZ) /* 2 minutes */
119#define CMC_POLL_INTERVAL (1*60*HZ) /* 1 minute */
120#define CPE_HISTORY_LENGTH 5
121#define CMC_HISTORY_LENGTH 5
122
Tony Luck34eac2a2007-05-10 13:20:19 -0700123#ifdef CONFIG_ACPI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124static struct timer_list cpe_poll_timer;
Tony Luck34eac2a2007-05-10 13:20:19 -0700125#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126static struct timer_list cmc_poll_timer;
127/*
128 * This variable tells whether we are currently in polling mode.
129 * Start with this in the wrong state so we won't play w/ timers
130 * before the system is ready.
131 */
132static int cmc_polling_enabled = 1;
133
134/*
135 * Clearing this variable prevents CPE polling from getting activated
136 * in mca_late_init. Use it if your system doesn't provide a CPEI,
137 * but encounters problems retrieving CPE logs. This should only be
138 * necessary for debugging.
139 */
140static int cpe_poll_enabled = 1;
141
142extern void salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe);
143
Chen, Kenneth W0881fc82006-03-12 08:52:20 -0800144static int mca_init __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700146/*
147 * limited & delayed printing support for MCA/INIT handler
148 */
149
150#define mprintk(fmt...) ia64_mca_printk(fmt)
151
152#define MLOGBUF_SIZE (512+256*NR_CPUS)
153#define MLOGBUF_MSGMAX 256
154static char mlogbuf[MLOGBUF_SIZE];
155static DEFINE_SPINLOCK(mlogbuf_wlock); /* mca context only */
156static DEFINE_SPINLOCK(mlogbuf_rlock); /* normal context only */
157static unsigned long mlogbuf_start;
158static unsigned long mlogbuf_end;
159static unsigned int mlogbuf_finished = 0;
160static unsigned long mlogbuf_timestamp = 0;
161
162static int loglevel_save = -1;
163#define BREAK_LOGLEVEL(__console_loglevel) \
164 oops_in_progress = 1; \
165 if (loglevel_save < 0) \
166 loglevel_save = __console_loglevel; \
167 __console_loglevel = 15;
168
169#define RESTORE_LOGLEVEL(__console_loglevel) \
170 if (loglevel_save >= 0) { \
171 __console_loglevel = loglevel_save; \
172 loglevel_save = -1; \
173 } \
174 mlogbuf_finished = 0; \
175 oops_in_progress = 0;
176
177/*
178 * Push messages into buffer, print them later if not urgent.
179 */
180void ia64_mca_printk(const char *fmt, ...)
181{
182 va_list args;
183 int printed_len;
184 char temp_buf[MLOGBUF_MSGMAX];
185 char *p;
186
187 va_start(args, fmt);
188 printed_len = vscnprintf(temp_buf, sizeof(temp_buf), fmt, args);
189 va_end(args);
190
191 /* Copy the output into mlogbuf */
192 if (oops_in_progress) {
193 /* mlogbuf was abandoned, use printk directly instead. */
194 printk(temp_buf);
195 } else {
196 spin_lock(&mlogbuf_wlock);
197 for (p = temp_buf; *p; p++) {
198 unsigned long next = (mlogbuf_end + 1) % MLOGBUF_SIZE;
199 if (next != mlogbuf_start) {
200 mlogbuf[mlogbuf_end] = *p;
201 mlogbuf_end = next;
202 } else {
203 /* buffer full */
204 break;
205 }
206 }
207 mlogbuf[mlogbuf_end] = '\0';
208 spin_unlock(&mlogbuf_wlock);
209 }
210}
211EXPORT_SYMBOL(ia64_mca_printk);
212
213/*
214 * Print buffered messages.
215 * NOTE: call this after returning normal context. (ex. from salinfod)
216 */
217void ia64_mlogbuf_dump(void)
218{
219 char temp_buf[MLOGBUF_MSGMAX];
220 char *p;
221 unsigned long index;
222 unsigned long flags;
223 unsigned int printed_len;
224
225 /* Get output from mlogbuf */
226 while (mlogbuf_start != mlogbuf_end) {
227 temp_buf[0] = '\0';
228 p = temp_buf;
229 printed_len = 0;
230
231 spin_lock_irqsave(&mlogbuf_rlock, flags);
232
233 index = mlogbuf_start;
234 while (index != mlogbuf_end) {
235 *p = mlogbuf[index];
236 index = (index + 1) % MLOGBUF_SIZE;
237 if (!*p)
238 break;
239 p++;
240 if (++printed_len >= MLOGBUF_MSGMAX - 1)
241 break;
242 }
243 *p = '\0';
244 if (temp_buf[0])
245 printk(temp_buf);
246 mlogbuf_start = index;
247
248 mlogbuf_timestamp = 0;
249 spin_unlock_irqrestore(&mlogbuf_rlock, flags);
250 }
251}
252EXPORT_SYMBOL(ia64_mlogbuf_dump);
253
254/*
255 * Call this if system is going to down or if immediate flushing messages to
256 * console is required. (ex. recovery was failed, crash dump is going to be
257 * invoked, long-wait rendezvous etc.)
258 * NOTE: this should be called from monarch.
259 */
260static void ia64_mlogbuf_finish(int wait)
261{
262 BREAK_LOGLEVEL(console_loglevel);
263
264 spin_lock_init(&mlogbuf_rlock);
265 ia64_mlogbuf_dump();
266 printk(KERN_EMERG "mlogbuf_finish: printing switched to urgent mode, "
267 "MCA/INIT might be dodgy or fail.\n");
268
269 if (!wait)
270 return;
271
272 /* wait for console */
273 printk("Delaying for 5 seconds...\n");
274 udelay(5*1000000);
275
276 mlogbuf_finished = 1;
277}
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700278
279/*
280 * Print buffered messages from INIT context.
281 */
282static void ia64_mlogbuf_dump_from_init(void)
283{
284 if (mlogbuf_finished)
285 return;
286
287 if (mlogbuf_timestamp && (mlogbuf_timestamp + 30*HZ > jiffies)) {
288 printk(KERN_ERR "INIT: mlogbuf_dump is interrupted by INIT "
289 " and the system seems to be messed up.\n");
290 ia64_mlogbuf_finish(0);
291 return;
292 }
293
294 if (!spin_trylock(&mlogbuf_rlock)) {
295 printk(KERN_ERR "INIT: mlogbuf_dump is interrupted by INIT. "
296 "Generated messages other than stack dump will be "
297 "buffered to mlogbuf and will be printed later.\n");
298 printk(KERN_ERR "INIT: If messages would not printed after "
299 "this INIT, wait 30sec and assert INIT again.\n");
300 if (!mlogbuf_timestamp)
301 mlogbuf_timestamp = jiffies;
302 return;
303 }
304 spin_unlock(&mlogbuf_rlock);
305 ia64_mlogbuf_dump();
306}
Keith Owens9138d582005-11-07 11:27:13 -0800307
308static void inline
309ia64_mca_spin(const char *func)
310{
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700311 if (monarch_cpu == smp_processor_id())
312 ia64_mlogbuf_finish(0);
313 mprintk(KERN_EMERG "%s: spinning here, not returning to SAL\n", func);
Keith Owens9138d582005-11-07 11:27:13 -0800314 while (1)
315 cpu_relax();
316}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317/*
318 * IA64_MCA log support
319 */
320#define IA64_MAX_LOGS 2 /* Double-buffering for nested MCAs */
321#define IA64_MAX_LOG_TYPES 4 /* MCA, INIT, CMC, CPE */
322
323typedef struct ia64_state_log_s
324{
325 spinlock_t isl_lock;
326 int isl_index;
327 unsigned long isl_count;
328 ia64_err_rec_t *isl_log[IA64_MAX_LOGS]; /* need space to store header + error log */
329} ia64_state_log_t;
330
331static ia64_state_log_t ia64_state_log[IA64_MAX_LOG_TYPES];
332
333#define IA64_LOG_ALLOCATE(it, size) \
334 {ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)] = \
335 (ia64_err_rec_t *)alloc_bootmem(size); \
336 ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)] = \
337 (ia64_err_rec_t *)alloc_bootmem(size);}
338#define IA64_LOG_LOCK_INIT(it) spin_lock_init(&ia64_state_log[it].isl_lock)
339#define IA64_LOG_LOCK(it) spin_lock_irqsave(&ia64_state_log[it].isl_lock, s)
340#define IA64_LOG_UNLOCK(it) spin_unlock_irqrestore(&ia64_state_log[it].isl_lock,s)
341#define IA64_LOG_NEXT_INDEX(it) ia64_state_log[it].isl_index
342#define IA64_LOG_CURR_INDEX(it) 1 - ia64_state_log[it].isl_index
343#define IA64_LOG_INDEX_INC(it) \
344 {ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index; \
345 ia64_state_log[it].isl_count++;}
346#define IA64_LOG_INDEX_DEC(it) \
347 ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index
348#define IA64_LOG_NEXT_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)]))
349#define IA64_LOG_CURR_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)]))
350#define IA64_LOG_COUNT(it) ia64_state_log[it].isl_count
351
352/*
353 * ia64_log_init
354 * Reset the OS ia64 log buffer
355 * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
356 * Outputs : None
357 */
Chen, Kenneth W0881fc82006-03-12 08:52:20 -0800358static void __init
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359ia64_log_init(int sal_info_type)
360{
361 u64 max_size = 0;
362
363 IA64_LOG_NEXT_INDEX(sal_info_type) = 0;
364 IA64_LOG_LOCK_INIT(sal_info_type);
365
366 // SAL will tell us the maximum size of any error record of this type
367 max_size = ia64_sal_get_state_info_size(sal_info_type);
368 if (!max_size)
369 /* alloc_bootmem() doesn't like zero-sized allocations! */
370 return;
371
372 // set up OS data structures to hold error info
373 IA64_LOG_ALLOCATE(sal_info_type, max_size);
374 memset(IA64_LOG_CURR_BUFFER(sal_info_type), 0, max_size);
375 memset(IA64_LOG_NEXT_BUFFER(sal_info_type), 0, max_size);
376}
377
378/*
379 * ia64_log_get
380 *
381 * Get the current MCA log from SAL and copy it into the OS log buffer.
382 *
383 * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
384 * irq_safe whether you can use printk at this point
385 * Outputs : size (total record length)
386 * *buffer (ptr to error record)
387 *
388 */
389static u64
390ia64_log_get(int sal_info_type, u8 **buffer, int irq_safe)
391{
392 sal_log_record_header_t *log_buffer;
393 u64 total_len = 0;
Alexey Dobriyanc53421b2006-09-30 23:27:37 -0700394 unsigned long s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396 IA64_LOG_LOCK(sal_info_type);
397
398 /* Get the process state information */
399 log_buffer = IA64_LOG_NEXT_BUFFER(sal_info_type);
400
401 total_len = ia64_sal_get_state_info(sal_info_type, (u64 *)log_buffer);
402
403 if (total_len) {
404 IA64_LOG_INDEX_INC(sal_info_type);
405 IA64_LOG_UNLOCK(sal_info_type);
406 if (irq_safe) {
407 IA64_MCA_DEBUG("%s: SAL error record type %d retrieved. "
408 "Record length = %ld\n", __FUNCTION__, sal_info_type, total_len);
409 }
410 *buffer = (u8 *) log_buffer;
411 return total_len;
412 } else {
413 IA64_LOG_UNLOCK(sal_info_type);
414 return 0;
415 }
416}
417
418/*
419 * ia64_mca_log_sal_error_record
420 *
421 * This function retrieves a specified error record type from SAL
422 * and wakes up any processes waiting for error records.
423 *
Keith Owens7f613c72005-09-11 17:22:53 +1000424 * Inputs : sal_info_type (Type of error record MCA/CMC/CPE)
425 * FIXME: remove MCA and irq_safe.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 */
427static void
428ia64_mca_log_sal_error_record(int sal_info_type)
429{
430 u8 *buffer;
431 sal_log_record_header_t *rh;
432 u64 size;
Keith Owens7f613c72005-09-11 17:22:53 +1000433 int irq_safe = sal_info_type != SAL_INFO_TYPE_MCA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434#ifdef IA64_MCA_DEBUG_INFO
435 static const char * const rec_name[] = { "MCA", "INIT", "CMC", "CPE" };
436#endif
437
438 size = ia64_log_get(sal_info_type, &buffer, irq_safe);
439 if (!size)
440 return;
441
442 salinfo_log_wakeup(sal_info_type, buffer, size, irq_safe);
443
444 if (irq_safe)
445 IA64_MCA_DEBUG("CPU %d: SAL log contains %s error record\n",
446 smp_processor_id(),
447 sal_info_type < ARRAY_SIZE(rec_name) ? rec_name[sal_info_type] : "UNKNOWN");
448
449 /* Clear logs from corrected errors in case there's no user-level logger */
450 rh = (sal_log_record_header_t *)buffer;
451 if (rh->severity == sal_log_severity_corrected)
452 ia64_sal_clear_state_info(sal_info_type);
453}
454
Russ Andersond2a28ad2006-03-24 09:49:52 -0800455/*
456 * search_mca_table
457 * See if the MCA surfaced in an instruction range
458 * that has been tagged as recoverable.
459 *
460 * Inputs
461 * first First address range to check
462 * last Last address range to check
463 * ip Instruction pointer, address we are looking for
464 *
465 * Return value:
466 * 1 on Success (in the table)/ 0 on Failure (not in the table)
467 */
468int
469search_mca_table (const struct mca_table_entry *first,
470 const struct mca_table_entry *last,
471 unsigned long ip)
472{
473 const struct mca_table_entry *curr;
474 u64 curr_start, curr_end;
475
476 curr = first;
477 while (curr <= last) {
478 curr_start = (u64) &curr->start_addr + curr->start_addr;
479 curr_end = (u64) &curr->end_addr + curr->end_addr;
480
481 if ((ip >= curr_start) && (ip <= curr_end)) {
482 return 1;
483 }
484 curr++;
485 }
486 return 0;
487}
488
489/* Given an address, look for it in the mca tables. */
490int mca_recover_range(unsigned long addr)
491{
492 extern struct mca_table_entry __start___mca_table[];
493 extern struct mca_table_entry __stop___mca_table[];
494
495 return search_mca_table(__start___mca_table, __stop___mca_table-1, addr);
496}
497EXPORT_SYMBOL_GPL(mca_recover_range);
498
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#ifdef CONFIG_ACPI
500
Ashok Raj55e59c52005-03-31 22:51:10 -0500501int cpe_vector = -1;
Ashok Rajff741902005-11-11 14:32:40 -0800502int ia64_cpe_irq = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100505ia64_mca_cpe_int_handler (int cpe_irq, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
507 static unsigned long cpe_history[CPE_HISTORY_LENGTH];
508 static int index;
509 static DEFINE_SPINLOCK(cpe_history_lock);
510
511 IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
512 __FUNCTION__, cpe_irq, smp_processor_id());
513
514 /* SAL spec states this should run w/ interrupts enabled */
515 local_irq_enable();
516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 spin_lock(&cpe_history_lock);
518 if (!cpe_poll_enabled && cpe_vector >= 0) {
519
520 int i, count = 1; /* we know 1 happened now */
521 unsigned long now = jiffies;
522
523 for (i = 0; i < CPE_HISTORY_LENGTH; i++) {
524 if (now - cpe_history[i] <= HZ)
525 count++;
526 }
527
528 IA64_MCA_DEBUG(KERN_INFO "CPE threshold %d/%d\n", count, CPE_HISTORY_LENGTH);
529 if (count >= CPE_HISTORY_LENGTH) {
530
531 cpe_poll_enabled = 1;
532 spin_unlock(&cpe_history_lock);
533 disable_irq_nosync(local_vector_to_irq(IA64_CPE_VECTOR));
534
535 /*
536 * Corrected errors will still be corrected, but
537 * make sure there's a log somewhere that indicates
538 * something is generating more than we can handle.
539 */
540 printk(KERN_WARNING "WARNING: Switching to polling CPE handler; error records may be lost\n");
541
542 mod_timer(&cpe_poll_timer, jiffies + MIN_CPE_POLL_INTERVAL);
543
544 /* lock already released, get out now */
Hidetoshi Setoddb4f0d2006-09-26 15:27:56 -0700545 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 } else {
547 cpe_history[index++] = now;
548 if (index == CPE_HISTORY_LENGTH)
549 index = 0;
550 }
551 }
552 spin_unlock(&cpe_history_lock);
Hidetoshi Setoddb4f0d2006-09-26 15:27:56 -0700553out:
554 /* Get the CPE error record and log it */
555 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE);
556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 return IRQ_HANDLED;
558}
559
560#endif /* CONFIG_ACPI */
561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562#ifdef CONFIG_ACPI
563/*
564 * ia64_mca_register_cpev
565 *
566 * Register the corrected platform error vector with SAL.
567 *
568 * Inputs
569 * cpev Corrected Platform Error Vector number
570 *
571 * Outputs
572 * None
573 */
Chen, Kenneth W0881fc82006-03-12 08:52:20 -0800574static void __init
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575ia64_mca_register_cpev (int cpev)
576{
577 /* Register the CPE interrupt vector with SAL */
578 struct ia64_sal_retval isrv;
579
580 isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_CPE_INT, SAL_MC_PARAM_MECHANISM_INT, cpev, 0, 0);
581 if (isrv.status) {
582 printk(KERN_ERR "Failed to register Corrected Platform "
583 "Error interrupt vector with SAL (status %ld)\n", isrv.status);
584 return;
585 }
586
587 IA64_MCA_DEBUG("%s: corrected platform error "
588 "vector %#x registered\n", __FUNCTION__, cpev);
589}
590#endif /* CONFIG_ACPI */
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592/*
593 * ia64_mca_cmc_vector_setup
594 *
595 * Setup the corrected machine check vector register in the processor.
596 * (The interrupt is masked on boot. ia64_mca_late_init unmask this.)
597 * This function is invoked on a per-processor basis.
598 *
599 * Inputs
600 * None
601 *
602 * Outputs
603 * None
604 */
Chen, Kenneth W0881fc82006-03-12 08:52:20 -0800605void __cpuinit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606ia64_mca_cmc_vector_setup (void)
607{
608 cmcv_reg_t cmcv;
609
610 cmcv.cmcv_regval = 0;
611 cmcv.cmcv_mask = 1; /* Mask/disable interrupt at first */
612 cmcv.cmcv_vector = IA64_CMC_VECTOR;
613 ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
614
615 IA64_MCA_DEBUG("%s: CPU %d corrected "
616 "machine check vector %#x registered.\n",
617 __FUNCTION__, smp_processor_id(), IA64_CMC_VECTOR);
618
619 IA64_MCA_DEBUG("%s: CPU %d CMCV = %#016lx\n",
620 __FUNCTION__, smp_processor_id(), ia64_getreg(_IA64_REG_CR_CMCV));
621}
622
623/*
624 * ia64_mca_cmc_vector_disable
625 *
626 * Mask the corrected machine check vector register in the processor.
627 * This function is invoked on a per-processor basis.
628 *
629 * Inputs
630 * dummy(unused)
631 *
632 * Outputs
633 * None
634 */
635static void
636ia64_mca_cmc_vector_disable (void *dummy)
637{
638 cmcv_reg_t cmcv;
639
640 cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV);
641
642 cmcv.cmcv_mask = 1; /* Mask/disable interrupt */
643 ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
644
645 IA64_MCA_DEBUG("%s: CPU %d corrected "
646 "machine check vector %#x disabled.\n",
647 __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector);
648}
649
650/*
651 * ia64_mca_cmc_vector_enable
652 *
653 * Unmask the corrected machine check vector register in the processor.
654 * This function is invoked on a per-processor basis.
655 *
656 * Inputs
657 * dummy(unused)
658 *
659 * Outputs
660 * None
661 */
662static void
663ia64_mca_cmc_vector_enable (void *dummy)
664{
665 cmcv_reg_t cmcv;
666
667 cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV);
668
669 cmcv.cmcv_mask = 0; /* Unmask/enable interrupt */
670 ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
671
672 IA64_MCA_DEBUG("%s: CPU %d corrected "
673 "machine check vector %#x enabled.\n",
674 __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector);
675}
676
677/*
678 * ia64_mca_cmc_vector_disable_keventd
679 *
680 * Called via keventd (smp_call_function() is not safe in interrupt context) to
681 * disable the cmc interrupt vector.
682 */
683static void
David Howells6d5aefb2006-12-05 19:36:26 +0000684ia64_mca_cmc_vector_disable_keventd(struct work_struct *unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685{
686 on_each_cpu(ia64_mca_cmc_vector_disable, NULL, 1, 0);
687}
688
689/*
690 * ia64_mca_cmc_vector_enable_keventd
691 *
692 * Called via keventd (smp_call_function() is not safe in interrupt context) to
693 * enable the cmc interrupt vector.
694 */
695static void
David Howells6d5aefb2006-12-05 19:36:26 +0000696ia64_mca_cmc_vector_enable_keventd(struct work_struct *unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697{
698 on_each_cpu(ia64_mca_cmc_vector_enable, NULL, 1, 0);
699}
700
701/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 * ia64_mca_wakeup
703 *
704 * Send an inter-cpu interrupt to wake-up a particular cpu
705 * and mark that cpu to be out of rendez.
706 *
707 * Inputs : cpuid
708 * Outputs : None
709 */
710static void
711ia64_mca_wakeup(int cpu)
712{
713 platform_send_ipi(cpu, IA64_MCA_WAKEUP_VECTOR, IA64_IPI_DM_INT, 0);
714 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
715
716}
717
718/*
719 * ia64_mca_wakeup_all
720 *
721 * Wakeup all the cpus which have rendez'ed previously.
722 *
723 * Inputs : None
724 * Outputs : None
725 */
726static void
727ia64_mca_wakeup_all(void)
728{
729 int cpu;
730
731 /* Clear the Rendez checkin flag for all cpus */
hawkes@sgi.comddf6d0a2005-10-13 12:01:18 -0700732 for_each_online_cpu(cpu) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 if (ia64_mc_info.imi_rendez_checkin[cpu] == IA64_MCA_RENDEZ_CHECKIN_DONE)
734 ia64_mca_wakeup(cpu);
735 }
736
737}
738
739/*
740 * ia64_mca_rendez_interrupt_handler
741 *
742 * This is handler used to put slave processors into spinloop
743 * while the monarch processor does the mca handling and later
744 * wake each slave up once the monarch is done.
745 *
746 * Inputs : None
747 * Outputs : None
748 */
749static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100750ia64_mca_rendez_int_handler(int rendez_irq, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751{
752 unsigned long flags;
753 int cpu = smp_processor_id();
Keith Owens958b1662006-04-03 15:26:12 +1000754 struct ia64_mca_notify_die nd =
755 { .sos = NULL, .monarch_cpu = &monarch_cpu };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757 /* Mask all interrupts */
758 local_irq_save(flags);
David Howells7d12e782006-10-05 14:55:46 +0100759 if (notify_die(DIE_MCA_RENDZVOUS_ENTER, "MCA", get_irq_regs(),
760 (long)&nd, 0, 0) == NOTIFY_STOP)
Keith Owens9138d582005-11-07 11:27:13 -0800761 ia64_mca_spin(__FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_DONE;
764 /* Register with the SAL monarch that the slave has
765 * reached SAL
766 */
767 ia64_sal_mc_rendez();
768
David Howells7d12e782006-10-05 14:55:46 +0100769 if (notify_die(DIE_MCA_RENDZVOUS_PROCESS, "MCA", get_irq_regs(),
770 (long)&nd, 0, 0) == NOTIFY_STOP)
Keith Owens9138d582005-11-07 11:27:13 -0800771 ia64_mca_spin(__FUNCTION__);
772
Keith Owens7f613c72005-09-11 17:22:53 +1000773 /* Wait for the monarch cpu to exit. */
774 while (monarch_cpu != -1)
775 cpu_relax(); /* spin until monarch leaves */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
David Howells7d12e782006-10-05 14:55:46 +0100777 if (notify_die(DIE_MCA_RENDZVOUS_LEAVE, "MCA", get_irq_regs(),
778 (long)&nd, 0, 0) == NOTIFY_STOP)
Keith Owens9138d582005-11-07 11:27:13 -0800779 ia64_mca_spin(__FUNCTION__);
780
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 /* Enable all interrupts */
782 local_irq_restore(flags);
783 return IRQ_HANDLED;
784}
785
786/*
787 * ia64_mca_wakeup_int_handler
788 *
789 * The interrupt handler for processing the inter-cpu interrupt to the
790 * slave cpu which was spinning in the rendez loop.
791 * Since this spinning is done by turning off the interrupts and
792 * polling on the wakeup-interrupt bit in the IRR, there is
793 * nothing useful to be done in the handler.
794 *
795 * Inputs : wakeup_irq (Wakeup-interrupt bit)
796 * arg (Interrupt handler specific argument)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 * Outputs : None
798 *
799 */
800static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100801ia64_mca_wakeup_int_handler(int wakeup_irq, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
803 return IRQ_HANDLED;
804}
805
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806/* Function pointer for extra MCA recovery */
807int (*ia64_mca_ucmc_extension)
Keith Owens7f613c72005-09-11 17:22:53 +1000808 (void*,struct ia64_sal_os_state*)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 = NULL;
810
811int
Keith Owens7f613c72005-09-11 17:22:53 +1000812ia64_reg_MCA_extension(int (*fn)(void *, struct ia64_sal_os_state *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
814 if (ia64_mca_ucmc_extension)
815 return 1;
816
817 ia64_mca_ucmc_extension = fn;
818 return 0;
819}
820
821void
822ia64_unreg_MCA_extension(void)
823{
824 if (ia64_mca_ucmc_extension)
825 ia64_mca_ucmc_extension = NULL;
826}
827
828EXPORT_SYMBOL(ia64_reg_MCA_extension);
829EXPORT_SYMBOL(ia64_unreg_MCA_extension);
830
Keith Owens7f613c72005-09-11 17:22:53 +1000831
832static inline void
833copy_reg(const u64 *fr, u64 fnat, u64 *tr, u64 *tnat)
834{
835 u64 fslot, tslot, nat;
836 *tr = *fr;
837 fslot = ((unsigned long)fr >> 3) & 63;
838 tslot = ((unsigned long)tr >> 3) & 63;
839 *tnat &= ~(1UL << tslot);
840 nat = (fnat >> fslot) & 1;
841 *tnat |= (nat << tslot);
842}
843
Keith Owense9ac0542006-02-08 13:41:04 +1100844/* Change the comm field on the MCA/INT task to include the pid that
845 * was interrupted, it makes for easier debugging. If that pid was 0
846 * (swapper or nested MCA/INIT) then use the start of the previous comm
847 * field suffixed with its cpu.
848 */
849
850static void
Ingo Molnar36c8b582006-07-03 00:25:41 -0700851ia64_mca_modify_comm(const struct task_struct *previous_current)
Keith Owense9ac0542006-02-08 13:41:04 +1100852{
853 char *p, comm[sizeof(current->comm)];
854 if (previous_current->pid)
855 snprintf(comm, sizeof(comm), "%s %d",
856 current->comm, previous_current->pid);
857 else {
858 int l;
859 if ((p = strchr(previous_current->comm, ' ')))
860 l = p - previous_current->comm;
861 else
862 l = strlen(previous_current->comm);
863 snprintf(comm, sizeof(comm), "%s %*s %d",
864 current->comm, l, previous_current->comm,
865 task_thread_info(previous_current)->cpu);
866 }
867 memcpy(current->comm, comm, sizeof(current->comm));
868}
869
Keith Owens7f613c72005-09-11 17:22:53 +1000870/* On entry to this routine, we are running on the per cpu stack, see
871 * mca_asm.h. The original stack has not been touched by this event. Some of
872 * the original stack's registers will be in the RBS on this stack. This stack
873 * also contains a partial pt_regs and switch_stack, the rest of the data is in
874 * PAL minstate.
875 *
876 * The first thing to do is modify the original stack to look like a blocked
877 * task so we can run backtrace on the original task. Also mark the per cpu
878 * stack as current to ensure that we use the correct task state, it also means
879 * that we can do backtrace on the MCA/INIT handler code itself.
880 */
881
Ingo Molnar36c8b582006-07-03 00:25:41 -0700882static struct task_struct *
Keith Owens7f613c72005-09-11 17:22:53 +1000883ia64_mca_modify_original_stack(struct pt_regs *regs,
884 const struct switch_stack *sw,
885 struct ia64_sal_os_state *sos,
886 const char *type)
887{
Keith Owense9ac0542006-02-08 13:41:04 +1100888 char *p;
Keith Owens7f613c72005-09-11 17:22:53 +1000889 ia64_va va;
890 extern char ia64_leave_kernel[]; /* Need asm address, not function descriptor */
891 const pal_min_state_area_t *ms = sos->pal_min_state;
Ingo Molnar36c8b582006-07-03 00:25:41 -0700892 struct task_struct *previous_current;
Keith Owens7f613c72005-09-11 17:22:53 +1000893 struct pt_regs *old_regs;
894 struct switch_stack *old_sw;
895 unsigned size = sizeof(struct pt_regs) +
896 sizeof(struct switch_stack) + 16;
897 u64 *old_bspstore, *old_bsp;
898 u64 *new_bspstore, *new_bsp;
899 u64 old_unat, old_rnat, new_rnat, nat;
900 u64 slots, loadrs = regs->loadrs;
901 u64 r12 = ms->pmsa_gr[12-1], r13 = ms->pmsa_gr[13-1];
902 u64 ar_bspstore = regs->ar_bspstore;
903 u64 ar_bsp = regs->ar_bspstore + (loadrs >> 16);
904 const u64 *bank;
905 const char *msg;
906 int cpu = smp_processor_id();
907
908 previous_current = curr_task(cpu);
909 set_curr_task(cpu, current);
910 if ((p = strchr(current->comm, ' ')))
911 *p = '\0';
912
913 /* Best effort attempt to cope with MCA/INIT delivered while in
914 * physical mode.
915 */
916 regs->cr_ipsr = ms->pmsa_ipsr;
917 if (ia64_psr(regs)->dt == 0) {
918 va.l = r12;
919 if (va.f.reg == 0) {
920 va.f.reg = 7;
921 r12 = va.l;
922 }
923 va.l = r13;
924 if (va.f.reg == 0) {
925 va.f.reg = 7;
926 r13 = va.l;
927 }
928 }
929 if (ia64_psr(regs)->rt == 0) {
930 va.l = ar_bspstore;
931 if (va.f.reg == 0) {
932 va.f.reg = 7;
933 ar_bspstore = va.l;
934 }
935 va.l = ar_bsp;
936 if (va.f.reg == 0) {
937 va.f.reg = 7;
938 ar_bsp = va.l;
939 }
940 }
941
942 /* mca_asm.S ia64_old_stack() cannot assume that the dirty registers
943 * have been copied to the old stack, the old stack may fail the
944 * validation tests below. So ia64_old_stack() must restore the dirty
945 * registers from the new stack. The old and new bspstore probably
946 * have different alignments, so loadrs calculated on the old bsp
947 * cannot be used to restore from the new bsp. Calculate a suitable
948 * loadrs for the new stack and save it in the new pt_regs, where
949 * ia64_old_stack() can get it.
950 */
951 old_bspstore = (u64 *)ar_bspstore;
952 old_bsp = (u64 *)ar_bsp;
953 slots = ia64_rse_num_regs(old_bspstore, old_bsp);
954 new_bspstore = (u64 *)((u64)current + IA64_RBS_OFFSET);
955 new_bsp = ia64_rse_skip_regs(new_bspstore, slots);
956 regs->loadrs = (new_bsp - new_bspstore) * 8 << 16;
957
958 /* Verify the previous stack state before we change it */
959 if (user_mode(regs)) {
960 msg = "occurred in user space";
Keith Owense9ac0542006-02-08 13:41:04 +1100961 /* previous_current is guaranteed to be valid when the task was
962 * in user space, so ...
963 */
964 ia64_mca_modify_comm(previous_current);
Keith Owens7f613c72005-09-11 17:22:53 +1000965 goto no_mod;
966 }
Russ Andersond2a28ad2006-03-24 09:49:52 -0800967
Russ Anderson1612b182007-05-18 17:17:17 -0500968 if (r13 != sos->prev_IA64_KR_CURRENT) {
969 msg = "inconsistent previous current and r13";
970 goto no_mod;
971 }
972
Russ Andersond2a28ad2006-03-24 09:49:52 -0800973 if (!mca_recover_range(ms->pmsa_iip)) {
Russ Andersond2a28ad2006-03-24 09:49:52 -0800974 if ((r12 - r13) >= KERNEL_STACK_SIZE) {
975 msg = "inconsistent r12 and r13";
976 goto no_mod;
977 }
978 if ((ar_bspstore - r13) >= KERNEL_STACK_SIZE) {
979 msg = "inconsistent ar.bspstore and r13";
980 goto no_mod;
981 }
982 va.p = old_bspstore;
983 if (va.f.reg < 5) {
984 msg = "old_bspstore is in the wrong region";
985 goto no_mod;
986 }
987 if ((ar_bsp - r13) >= KERNEL_STACK_SIZE) {
988 msg = "inconsistent ar.bsp and r13";
989 goto no_mod;
990 }
991 size += (ia64_rse_skip_regs(old_bspstore, slots) - old_bspstore) * 8;
992 if (ar_bspstore + size > r12) {
993 msg = "no room for blocked state";
994 goto no_mod;
995 }
Keith Owens7f613c72005-09-11 17:22:53 +1000996 }
997
Keith Owense9ac0542006-02-08 13:41:04 +1100998 ia64_mca_modify_comm(previous_current);
Keith Owens7f613c72005-09-11 17:22:53 +1000999
1000 /* Make the original task look blocked. First stack a struct pt_regs,
1001 * describing the state at the time of interrupt. mca_asm.S built a
1002 * partial pt_regs, copy it and fill in the blanks using minstate.
1003 */
1004 p = (char *)r12 - sizeof(*regs);
1005 old_regs = (struct pt_regs *)p;
1006 memcpy(old_regs, regs, sizeof(*regs));
1007 /* If ipsr.ic then use pmsa_{iip,ipsr,ifs}, else use
1008 * pmsa_{xip,xpsr,xfs}
1009 */
1010 if (ia64_psr(regs)->ic) {
1011 old_regs->cr_iip = ms->pmsa_iip;
1012 old_regs->cr_ipsr = ms->pmsa_ipsr;
1013 old_regs->cr_ifs = ms->pmsa_ifs;
1014 } else {
1015 old_regs->cr_iip = ms->pmsa_xip;
1016 old_regs->cr_ipsr = ms->pmsa_xpsr;
1017 old_regs->cr_ifs = ms->pmsa_xfs;
1018 }
1019 old_regs->pr = ms->pmsa_pr;
1020 old_regs->b0 = ms->pmsa_br0;
1021 old_regs->loadrs = loadrs;
1022 old_regs->ar_rsc = ms->pmsa_rsc;
1023 old_unat = old_regs->ar_unat;
1024 copy_reg(&ms->pmsa_gr[1-1], ms->pmsa_nat_bits, &old_regs->r1, &old_unat);
1025 copy_reg(&ms->pmsa_gr[2-1], ms->pmsa_nat_bits, &old_regs->r2, &old_unat);
1026 copy_reg(&ms->pmsa_gr[3-1], ms->pmsa_nat_bits, &old_regs->r3, &old_unat);
1027 copy_reg(&ms->pmsa_gr[8-1], ms->pmsa_nat_bits, &old_regs->r8, &old_unat);
1028 copy_reg(&ms->pmsa_gr[9-1], ms->pmsa_nat_bits, &old_regs->r9, &old_unat);
1029 copy_reg(&ms->pmsa_gr[10-1], ms->pmsa_nat_bits, &old_regs->r10, &old_unat);
1030 copy_reg(&ms->pmsa_gr[11-1], ms->pmsa_nat_bits, &old_regs->r11, &old_unat);
1031 copy_reg(&ms->pmsa_gr[12-1], ms->pmsa_nat_bits, &old_regs->r12, &old_unat);
1032 copy_reg(&ms->pmsa_gr[13-1], ms->pmsa_nat_bits, &old_regs->r13, &old_unat);
1033 copy_reg(&ms->pmsa_gr[14-1], ms->pmsa_nat_bits, &old_regs->r14, &old_unat);
1034 copy_reg(&ms->pmsa_gr[15-1], ms->pmsa_nat_bits, &old_regs->r15, &old_unat);
1035 if (ia64_psr(old_regs)->bn)
1036 bank = ms->pmsa_bank1_gr;
1037 else
1038 bank = ms->pmsa_bank0_gr;
1039 copy_reg(&bank[16-16], ms->pmsa_nat_bits, &old_regs->r16, &old_unat);
1040 copy_reg(&bank[17-16], ms->pmsa_nat_bits, &old_regs->r17, &old_unat);
1041 copy_reg(&bank[18-16], ms->pmsa_nat_bits, &old_regs->r18, &old_unat);
1042 copy_reg(&bank[19-16], ms->pmsa_nat_bits, &old_regs->r19, &old_unat);
1043 copy_reg(&bank[20-16], ms->pmsa_nat_bits, &old_regs->r20, &old_unat);
1044 copy_reg(&bank[21-16], ms->pmsa_nat_bits, &old_regs->r21, &old_unat);
1045 copy_reg(&bank[22-16], ms->pmsa_nat_bits, &old_regs->r22, &old_unat);
1046 copy_reg(&bank[23-16], ms->pmsa_nat_bits, &old_regs->r23, &old_unat);
1047 copy_reg(&bank[24-16], ms->pmsa_nat_bits, &old_regs->r24, &old_unat);
1048 copy_reg(&bank[25-16], ms->pmsa_nat_bits, &old_regs->r25, &old_unat);
1049 copy_reg(&bank[26-16], ms->pmsa_nat_bits, &old_regs->r26, &old_unat);
1050 copy_reg(&bank[27-16], ms->pmsa_nat_bits, &old_regs->r27, &old_unat);
1051 copy_reg(&bank[28-16], ms->pmsa_nat_bits, &old_regs->r28, &old_unat);
1052 copy_reg(&bank[29-16], ms->pmsa_nat_bits, &old_regs->r29, &old_unat);
1053 copy_reg(&bank[30-16], ms->pmsa_nat_bits, &old_regs->r30, &old_unat);
1054 copy_reg(&bank[31-16], ms->pmsa_nat_bits, &old_regs->r31, &old_unat);
1055
1056 /* Next stack a struct switch_stack. mca_asm.S built a partial
1057 * switch_stack, copy it and fill in the blanks using pt_regs and
1058 * minstate.
1059 *
1060 * In the synthesized switch_stack, b0 points to ia64_leave_kernel,
1061 * ar.pfs is set to 0.
1062 *
1063 * unwind.c::unw_unwind() does special processing for interrupt frames.
1064 * It checks if the PRED_NON_SYSCALL predicate is set, if the predicate
1065 * is clear then unw_unwind() does _not_ adjust bsp over pt_regs. Not
1066 * that this is documented, of course. Set PRED_NON_SYSCALL in the
1067 * switch_stack on the original stack so it will unwind correctly when
1068 * unwind.c reads pt_regs.
1069 *
1070 * thread.ksp is updated to point to the synthesized switch_stack.
1071 */
1072 p -= sizeof(struct switch_stack);
1073 old_sw = (struct switch_stack *)p;
1074 memcpy(old_sw, sw, sizeof(*sw));
1075 old_sw->caller_unat = old_unat;
1076 old_sw->ar_fpsr = old_regs->ar_fpsr;
1077 copy_reg(&ms->pmsa_gr[4-1], ms->pmsa_nat_bits, &old_sw->r4, &old_unat);
1078 copy_reg(&ms->pmsa_gr[5-1], ms->pmsa_nat_bits, &old_sw->r5, &old_unat);
1079 copy_reg(&ms->pmsa_gr[6-1], ms->pmsa_nat_bits, &old_sw->r6, &old_unat);
1080 copy_reg(&ms->pmsa_gr[7-1], ms->pmsa_nat_bits, &old_sw->r7, &old_unat);
1081 old_sw->b0 = (u64)ia64_leave_kernel;
1082 old_sw->b1 = ms->pmsa_br1;
1083 old_sw->ar_pfs = 0;
1084 old_sw->ar_unat = old_unat;
1085 old_sw->pr = old_regs->pr | (1UL << PRED_NON_SYSCALL);
1086 previous_current->thread.ksp = (u64)p - 16;
1087
1088 /* Finally copy the original stack's registers back to its RBS.
1089 * Registers from ar.bspstore through ar.bsp at the time of the event
1090 * are in the current RBS, copy them back to the original stack. The
1091 * copy must be done register by register because the original bspstore
1092 * and the current one have different alignments, so the saved RNAT
1093 * data occurs at different places.
1094 *
1095 * mca_asm does cover, so the old_bsp already includes all registers at
1096 * the time of MCA/INIT. It also does flushrs, so all registers before
1097 * this function have been written to backing store on the MCA/INIT
1098 * stack.
1099 */
1100 new_rnat = ia64_get_rnat(ia64_rse_rnat_addr(new_bspstore));
1101 old_rnat = regs->ar_rnat;
1102 while (slots--) {
1103 if (ia64_rse_is_rnat_slot(new_bspstore)) {
1104 new_rnat = ia64_get_rnat(new_bspstore++);
1105 }
1106 if (ia64_rse_is_rnat_slot(old_bspstore)) {
1107 *old_bspstore++ = old_rnat;
1108 old_rnat = 0;
1109 }
1110 nat = (new_rnat >> ia64_rse_slot_num(new_bspstore)) & 1UL;
1111 old_rnat &= ~(1UL << ia64_rse_slot_num(old_bspstore));
1112 old_rnat |= (nat << ia64_rse_slot_num(old_bspstore));
1113 *old_bspstore++ = *new_bspstore++;
1114 }
1115 old_sw->ar_bspstore = (unsigned long)old_bspstore;
1116 old_sw->ar_rnat = old_rnat;
1117
1118 sos->prev_task = previous_current;
1119 return previous_current;
1120
1121no_mod:
1122 printk(KERN_INFO "cpu %d, %s %s, original stack not modified\n",
1123 smp_processor_id(), type, msg);
1124 return previous_current;
1125}
1126
1127/* The monarch/slave interaction is based on monarch_cpu and requires that all
1128 * slaves have entered rendezvous before the monarch leaves. If any cpu has
1129 * not entered rendezvous yet then wait a bit. The assumption is that any
1130 * slave that has not rendezvoused after a reasonable time is never going to do
1131 * so. In this context, slave includes cpus that respond to the MCA rendezvous
1132 * interrupt, as well as cpus that receive the INIT slave event.
1133 */
1134
1135static void
Keith Owens356a5c12006-04-11 14:59:41 +10001136ia64_wait_for_slaves(int monarch, const char *type)
Keith Owens7f613c72005-09-11 17:22:53 +10001137{
Russ Anderson2bc5c282007-09-20 13:59:12 -05001138 int c, i , wait;
1139
1140 /*
1141 * wait 5 seconds total for slaves (arbitrary)
1142 */
1143 for (i = 0; i < 5000; i++) {
1144 wait = 0;
1145 for_each_online_cpu(c) {
1146 if (c == monarch)
1147 continue;
1148 if (ia64_mc_info.imi_rendez_checkin[c]
1149 == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) {
1150 udelay(1000); /* short wait */
1151 wait = 1;
1152 break;
1153 }
Keith Owens7f613c72005-09-11 17:22:53 +10001154 }
Russ Anderson2bc5c282007-09-20 13:59:12 -05001155 if (!wait)
1156 goto all_in;
Keith Owens7f613c72005-09-11 17:22:53 +10001157 }
Russ Anderson2bc5c282007-09-20 13:59:12 -05001158
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001159 /*
1160 * Maybe slave(s) dead. Print buffered messages immediately.
1161 */
1162 ia64_mlogbuf_finish(0);
1163 mprintk(KERN_INFO "OS %s slave did not rendezvous on cpu", type);
Keith Owens9336b082006-02-08 13:40:59 +11001164 for_each_online_cpu(c) {
1165 if (c == monarch)
1166 continue;
1167 if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001168 mprintk(" %d", c);
Keith Owens9336b082006-02-08 13:40:59 +11001169 }
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001170 mprintk("\n");
Keith Owens9336b082006-02-08 13:40:59 +11001171 return;
1172
1173all_in:
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001174 mprintk(KERN_INFO "All OS %s slaves have reached rendezvous\n", type);
Keith Owens9336b082006-02-08 13:40:59 +11001175 return;
Keith Owens7f613c72005-09-11 17:22:53 +10001176}
1177
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178/*
Keith Owens7f613c72005-09-11 17:22:53 +10001179 * ia64_mca_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 *
1181 * This is uncorrectable machine check handler called from OS_MCA
1182 * dispatch code which is in turn called from SAL_CHECK().
1183 * This is the place where the core of OS MCA handling is done.
1184 * Right now the logs are extracted and displayed in a well-defined
1185 * format. This handler code is supposed to be run only on the
1186 * monarch processor. Once the monarch is done with MCA handling
1187 * further MCA logging is enabled by clearing logs.
1188 * Monarch also has the duty of sending wakeup-IPIs to pull the
1189 * slave processors out of rendezvous spinloop.
Russ Anderson1612b182007-05-18 17:17:17 -05001190 *
1191 * If multiple processors call into OS_MCA, the first will become
1192 * the monarch. Subsequent cpus will be recorded in the mca_cpu
1193 * bitmask. After the first monarch has processed its MCA, it
1194 * will wake up the next cpu in the mca_cpu bitmask and then go
1195 * into the rendezvous loop. When all processors have serviced
1196 * their MCA, the last monarch frees up the rest of the processors.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 */
1198void
Keith Owens7f613c72005-09-11 17:22:53 +10001199ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw,
1200 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201{
Keith Owens7f613c72005-09-11 17:22:53 +10001202 int recover, cpu = smp_processor_id();
Ingo Molnar36c8b582006-07-03 00:25:41 -07001203 struct task_struct *previous_current;
Keith Owens958b1662006-04-03 15:26:12 +10001204 struct ia64_mca_notify_die nd =
1205 { .sos = sos, .monarch_cpu = &monarch_cpu };
Russ Anderson1612b182007-05-18 17:17:17 -05001206 static atomic_t mca_count;
1207 static cpumask_t mca_cpu;
Keith Owens7f613c72005-09-11 17:22:53 +10001208
Russ Anderson1612b182007-05-18 17:17:17 -05001209 if (atomic_add_return(1, &mca_count) == 1) {
1210 monarch_cpu = cpu;
1211 sos->monarch = 1;
1212 } else {
1213 cpu_set(cpu, mca_cpu);
1214 sos->monarch = 0;
1215 }
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001216 mprintk(KERN_INFO "Entered OS MCA handler. PSP=%lx cpu=%d "
1217 "monarch=%ld\n", sos->proc_state_param, cpu, sos->monarch);
Keith Owens9336b082006-02-08 13:40:59 +11001218
Keith Owens7f613c72005-09-11 17:22:53 +10001219 previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "MCA");
Russ Anderson1612b182007-05-18 17:17:17 -05001220
Keith Owens958b1662006-04-03 15:26:12 +10001221 if (notify_die(DIE_MCA_MONARCH_ENTER, "MCA", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001222 == NOTIFY_STOP)
1223 ia64_mca_spin(__FUNCTION__);
Russ Anderson1612b182007-05-18 17:17:17 -05001224 if (sos->monarch) {
1225 ia64_wait_for_slaves(cpu, "MCA");
1226 } else {
1227 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_CONCURRENT_MCA;
1228 while (cpu_isset(cpu, mca_cpu))
1229 cpu_relax(); /* spin until monarch wakes us */
1230 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
1231 }
Keith Owens7f613c72005-09-11 17:22:53 +10001232
1233 /* Wakeup all the processors which are spinning in the rendezvous loop.
1234 * They will leave SAL, then spin in the OS with interrupts disabled
1235 * until this monarch cpu leaves the MCA handler. That gets control
1236 * back to the OS so we can backtrace the other cpus, backtrace when
1237 * spinning in SAL does not work.
1238 */
1239 ia64_mca_wakeup_all();
Keith Owens958b1662006-04-03 15:26:12 +10001240 if (notify_die(DIE_MCA_MONARCH_PROCESS, "MCA", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001241 == NOTIFY_STOP)
1242 ia64_mca_spin(__FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
1244 /* Get the MCA error record and log it */
1245 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA);
1246
Russ Anderson618b2062006-12-14 16:01:41 -06001247 /* MCA error recovery */
1248 recover = (ia64_mca_ucmc_extension
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 && ia64_mca_ucmc_extension(
1250 IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA),
Keith Owens7f613c72005-09-11 17:22:53 +10001251 sos));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
1253 if (recover) {
1254 sal_log_record_header_t *rh = IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA);
1255 rh->severity = sal_log_severity_corrected;
1256 ia64_sal_clear_state_info(SAL_INFO_TYPE_MCA);
Keith Owens7f613c72005-09-11 17:22:53 +10001257 sos->os_status = IA64_MCA_CORRECTED;
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001258 } else {
1259 /* Dump buffered message to console */
1260 ia64_mlogbuf_finish(1);
Horms45a98fc2006-12-12 17:49:03 +09001261#ifdef CONFIG_KEXEC
Zou Nan haia79561132006-12-07 09:51:35 -08001262 atomic_set(&kdump_in_progress, 1);
1263 monarch_cpu = -1;
1264#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 }
Keith Owens958b1662006-04-03 15:26:12 +10001266 if (notify_die(DIE_MCA_MONARCH_LEAVE, "MCA", regs, (long)&nd, 0, recover)
Keith Owens9138d582005-11-07 11:27:13 -08001267 == NOTIFY_STOP)
1268 ia64_mca_spin(__FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
Russ Anderson1612b182007-05-18 17:17:17 -05001270
1271 if (atomic_dec_return(&mca_count) > 0) {
1272 int i;
1273
1274 /* wake up the next monarch cpu,
1275 * and put this cpu in the rendez loop.
1276 */
1277 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_CONCURRENT_MCA;
1278 for_each_online_cpu(i) {
1279 if (cpu_isset(i, mca_cpu)) {
1280 monarch_cpu = i;
1281 cpu_clear(i, mca_cpu); /* wake next cpu */
1282 while (monarch_cpu != -1)
1283 cpu_relax(); /* spin until last cpu leaves */
1284 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
1285 set_curr_task(cpu, previous_current);
1286 return;
1287 }
1288 }
1289 }
Keith Owens7f613c72005-09-11 17:22:53 +10001290 set_curr_task(cpu, previous_current);
1291 monarch_cpu = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292}
1293
David Howells6d5aefb2006-12-05 19:36:26 +00001294static DECLARE_WORK(cmc_disable_work, ia64_mca_cmc_vector_disable_keventd);
1295static DECLARE_WORK(cmc_enable_work, ia64_mca_cmc_vector_enable_keventd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
1297/*
1298 * ia64_mca_cmc_int_handler
1299 *
1300 * This is corrected machine check interrupt handler.
1301 * Right now the logs are extracted and displayed in a well-defined
1302 * format.
1303 *
1304 * Inputs
1305 * interrupt number
1306 * client data arg ptr
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 *
1308 * Outputs
1309 * None
1310 */
1311static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001312ia64_mca_cmc_int_handler(int cmc_irq, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313{
1314 static unsigned long cmc_history[CMC_HISTORY_LENGTH];
1315 static int index;
1316 static DEFINE_SPINLOCK(cmc_history_lock);
1317
1318 IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
1319 __FUNCTION__, cmc_irq, smp_processor_id());
1320
1321 /* SAL spec states this should run w/ interrupts enabled */
1322 local_irq_enable();
1323
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 spin_lock(&cmc_history_lock);
1325 if (!cmc_polling_enabled) {
1326 int i, count = 1; /* we know 1 happened now */
1327 unsigned long now = jiffies;
1328
1329 for (i = 0; i < CMC_HISTORY_LENGTH; i++) {
1330 if (now - cmc_history[i] <= HZ)
1331 count++;
1332 }
1333
1334 IA64_MCA_DEBUG(KERN_INFO "CMC threshold %d/%d\n", count, CMC_HISTORY_LENGTH);
1335 if (count >= CMC_HISTORY_LENGTH) {
1336
1337 cmc_polling_enabled = 1;
1338 spin_unlock(&cmc_history_lock);
Bryan Sutula76e677e2005-10-05 11:02:06 -06001339 /* If we're being hit with CMC interrupts, we won't
1340 * ever execute the schedule_work() below. Need to
1341 * disable CMC interrupts on this processor now.
1342 */
1343 ia64_mca_cmc_vector_disable(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 schedule_work(&cmc_disable_work);
1345
1346 /*
1347 * Corrected errors will still be corrected, but
1348 * make sure there's a log somewhere that indicates
1349 * something is generating more than we can handle.
1350 */
1351 printk(KERN_WARNING "WARNING: Switching to polling CMC handler; error records may be lost\n");
1352
1353 mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
1354
1355 /* lock already released, get out now */
Hidetoshi Setoddb4f0d2006-09-26 15:27:56 -07001356 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 } else {
1358 cmc_history[index++] = now;
1359 if (index == CMC_HISTORY_LENGTH)
1360 index = 0;
1361 }
1362 }
1363 spin_unlock(&cmc_history_lock);
Hidetoshi Setoddb4f0d2006-09-26 15:27:56 -07001364out:
1365 /* Get the CMC error record and log it */
1366 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC);
1367
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 return IRQ_HANDLED;
1369}
1370
1371/*
1372 * ia64_mca_cmc_int_caller
1373 *
1374 * Triggered by sw interrupt from CMC polling routine. Calls
1375 * real interrupt handler and either triggers a sw interrupt
1376 * on the next cpu or does cleanup at the end.
1377 *
1378 * Inputs
1379 * interrupt number
1380 * client data arg ptr
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 * Outputs
1382 * handled
1383 */
1384static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001385ia64_mca_cmc_int_caller(int cmc_irq, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386{
1387 static int start_count = -1;
1388 unsigned int cpuid;
1389
1390 cpuid = smp_processor_id();
1391
1392 /* If first cpu, update count */
1393 if (start_count == -1)
1394 start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CMC);
1395
David Howells7d12e782006-10-05 14:55:46 +01001396 ia64_mca_cmc_int_handler(cmc_irq, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
1398 for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
1399
1400 if (cpuid < NR_CPUS) {
1401 platform_send_ipi(cpuid, IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
1402 } else {
1403 /* If no log record, switch out of polling mode */
1404 if (start_count == IA64_LOG_COUNT(SAL_INFO_TYPE_CMC)) {
1405
1406 printk(KERN_WARNING "Returning to interrupt driven CMC handler\n");
1407 schedule_work(&cmc_enable_work);
1408 cmc_polling_enabled = 0;
1409
1410 } else {
1411
1412 mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
1413 }
1414
1415 start_count = -1;
1416 }
1417
1418 return IRQ_HANDLED;
1419}
1420
1421/*
1422 * ia64_mca_cmc_poll
1423 *
1424 * Poll for Corrected Machine Checks (CMCs)
1425 *
1426 * Inputs : dummy(unused)
1427 * Outputs : None
1428 *
1429 */
1430static void
1431ia64_mca_cmc_poll (unsigned long dummy)
1432{
1433 /* Trigger a CMC interrupt cascade */
1434 platform_send_ipi(first_cpu(cpu_online_map), IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
1435}
1436
1437/*
1438 * ia64_mca_cpe_int_caller
1439 *
1440 * Triggered by sw interrupt from CPE polling routine. Calls
1441 * real interrupt handler and either triggers a sw interrupt
1442 * on the next cpu or does cleanup at the end.
1443 *
1444 * Inputs
1445 * interrupt number
1446 * client data arg ptr
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 * Outputs
1448 * handled
1449 */
1450#ifdef CONFIG_ACPI
1451
1452static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001453ia64_mca_cpe_int_caller(int cpe_irq, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454{
1455 static int start_count = -1;
1456 static int poll_time = MIN_CPE_POLL_INTERVAL;
1457 unsigned int cpuid;
1458
1459 cpuid = smp_processor_id();
1460
1461 /* If first cpu, update count */
1462 if (start_count == -1)
1463 start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CPE);
1464
David Howells7d12e782006-10-05 14:55:46 +01001465 ia64_mca_cpe_int_handler(cpe_irq, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
1467 for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
1468
1469 if (cpuid < NR_CPUS) {
1470 platform_send_ipi(cpuid, IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
1471 } else {
1472 /*
1473 * If a log was recorded, increase our polling frequency,
1474 * otherwise, backoff or return to interrupt mode.
1475 */
1476 if (start_count != IA64_LOG_COUNT(SAL_INFO_TYPE_CPE)) {
1477 poll_time = max(MIN_CPE_POLL_INTERVAL, poll_time / 2);
1478 } else if (cpe_vector < 0) {
1479 poll_time = min(MAX_CPE_POLL_INTERVAL, poll_time * 2);
1480 } else {
1481 poll_time = MIN_CPE_POLL_INTERVAL;
1482
1483 printk(KERN_WARNING "Returning to interrupt driven CPE handler\n");
1484 enable_irq(local_vector_to_irq(IA64_CPE_VECTOR));
1485 cpe_poll_enabled = 0;
1486 }
1487
1488 if (cpe_poll_enabled)
1489 mod_timer(&cpe_poll_timer, jiffies + poll_time);
1490 start_count = -1;
1491 }
1492
1493 return IRQ_HANDLED;
1494}
1495
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496/*
1497 * ia64_mca_cpe_poll
1498 *
1499 * Poll for Corrected Platform Errors (CPEs), trigger interrupt
1500 * on first cpu, from there it will trickle through all the cpus.
1501 *
1502 * Inputs : dummy(unused)
1503 * Outputs : None
1504 *
1505 */
1506static void
1507ia64_mca_cpe_poll (unsigned long dummy)
1508{
1509 /* Trigger a CPE interrupt cascade */
1510 platform_send_ipi(first_cpu(cpu_online_map), IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
1511}
1512
Peter Chubbb6559132005-05-31 22:34:00 -07001513#endif /* CONFIG_ACPI */
1514
Keith Owens9138d582005-11-07 11:27:13 -08001515static int
1516default_monarch_init_process(struct notifier_block *self, unsigned long val, void *data)
1517{
1518 int c;
1519 struct task_struct *g, *t;
1520 if (val != DIE_INIT_MONARCH_PROCESS)
1521 return NOTIFY_DONE;
Jay Lan311f5942007-04-03 17:53:42 -07001522#ifdef CONFIG_KEXEC
1523 if (atomic_read(&kdump_in_progress))
1524 return NOTIFY_DONE;
1525#endif
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001526
1527 /*
1528 * FIXME: mlogbuf will brim over with INIT stack dumps.
1529 * To enable show_stack from INIT, we use oops_in_progress which should
1530 * be used in real oops. This would cause something wrong after INIT.
1531 */
1532 BREAK_LOGLEVEL(console_loglevel);
1533 ia64_mlogbuf_dump_from_init();
1534
Keith Owens9138d582005-11-07 11:27:13 -08001535 printk(KERN_ERR "Processes interrupted by INIT -");
1536 for_each_online_cpu(c) {
1537 struct ia64_sal_os_state *s;
1538 t = __va(__per_cpu_mca[c] + IA64_MCA_CPU_INIT_STACK_OFFSET);
1539 s = (struct ia64_sal_os_state *)((char *)t + MCA_SOS_OFFSET);
1540 g = s->prev_task;
1541 if (g) {
1542 if (g->pid)
1543 printk(" %d", g->pid);
1544 else
1545 printk(" %d (cpu %d task 0x%p)", g->pid, task_cpu(g), g);
1546 }
1547 }
1548 printk("\n\n");
1549 if (read_trylock(&tasklist_lock)) {
1550 do_each_thread (g, t) {
1551 printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm);
1552 show_stack(t, NULL);
1553 } while_each_thread (g, t);
1554 read_unlock(&tasklist_lock);
1555 }
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001556 /* FIXME: This will not restore zapped printk locks. */
1557 RESTORE_LOGLEVEL(console_loglevel);
Keith Owens9138d582005-11-07 11:27:13 -08001558 return NOTIFY_DONE;
1559}
1560
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561/*
1562 * C portion of the OS INIT handler
1563 *
Keith Owens7f613c72005-09-11 17:22:53 +10001564 * Called from ia64_os_init_dispatch
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 *
Keith Owens7f613c72005-09-11 17:22:53 +10001566 * Inputs: pointer to pt_regs where processor info was saved. SAL/OS state for
1567 * this event. This code is used for both monarch and slave INIT events, see
1568 * sos->monarch.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 *
Keith Owens7f613c72005-09-11 17:22:53 +10001570 * All INIT events switch to the INIT stack and change the previous process to
1571 * blocked status. If one of the INIT events is the monarch then we are
1572 * probably processing the nmi button/command. Use the monarch cpu to dump all
1573 * the processes. The slave INIT events all spin until the monarch cpu
1574 * returns. We can also get INIT slave events for MCA, in which case the MCA
1575 * process is the monarch.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Keith Owens7f613c72005-09-11 17:22:53 +10001578void
1579ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw,
1580 struct ia64_sal_os_state *sos)
1581{
1582 static atomic_t slaves;
1583 static atomic_t monarchs;
Ingo Molnar36c8b582006-07-03 00:25:41 -07001584 struct task_struct *previous_current;
Keith Owens9138d582005-11-07 11:27:13 -08001585 int cpu = smp_processor_id();
Keith Owens958b1662006-04-03 15:26:12 +10001586 struct ia64_mca_notify_die nd =
1587 { .sos = sos, .monarch_cpu = &monarch_cpu };
Keith Owens7f613c72005-09-11 17:22:53 +10001588
Keith Owens958b1662006-04-03 15:26:12 +10001589 (void) notify_die(DIE_INIT_ENTER, "INIT", regs, (long)&nd, 0, 0);
1590
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001591 mprintk(KERN_INFO "Entered OS INIT handler. PSP=%lx cpu=%d monarch=%ld\n",
Keith Owens7f613c72005-09-11 17:22:53 +10001592 sos->proc_state_param, cpu, sos->monarch);
1593 salinfo_log_wakeup(SAL_INFO_TYPE_INIT, NULL, 0, 0);
1594
1595 previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "INIT");
1596 sos->os_status = IA64_INIT_RESUME;
1597
1598 /* FIXME: Workaround for broken proms that drive all INIT events as
1599 * slaves. The last slave that enters is promoted to be a monarch.
1600 * Remove this code in September 2006, that gives platforms a year to
1601 * fix their proms and get their customers updated.
1602 */
1603 if (!sos->monarch && atomic_add_return(1, &slaves) == num_online_cpus()) {
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001604 mprintk(KERN_WARNING "%s: Promoting cpu %d to monarch.\n",
Keith Owens7f613c72005-09-11 17:22:53 +10001605 __FUNCTION__, cpu);
1606 atomic_dec(&slaves);
1607 sos->monarch = 1;
1608 }
1609
1610 /* FIXME: Workaround for broken proms that drive all INIT events as
1611 * monarchs. Second and subsequent monarchs are demoted to slaves.
1612 * Remove this code in September 2006, that gives platforms a year to
1613 * fix their proms and get their customers updated.
1614 */
1615 if (sos->monarch && atomic_add_return(1, &monarchs) > 1) {
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001616 mprintk(KERN_WARNING "%s: Demoting cpu %d to slave.\n",
Keith Owens7f613c72005-09-11 17:22:53 +10001617 __FUNCTION__, cpu);
1618 atomic_dec(&monarchs);
1619 sos->monarch = 0;
1620 }
1621
1622 if (!sos->monarch) {
1623 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_INIT;
1624 while (monarch_cpu == -1)
1625 cpu_relax(); /* spin until monarch enters */
Keith Owens958b1662006-04-03 15:26:12 +10001626 if (notify_die(DIE_INIT_SLAVE_ENTER, "INIT", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001627 == NOTIFY_STOP)
1628 ia64_mca_spin(__FUNCTION__);
Keith Owens958b1662006-04-03 15:26:12 +10001629 if (notify_die(DIE_INIT_SLAVE_PROCESS, "INIT", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001630 == NOTIFY_STOP)
1631 ia64_mca_spin(__FUNCTION__);
Keith Owens7f613c72005-09-11 17:22:53 +10001632 while (monarch_cpu != -1)
1633 cpu_relax(); /* spin until monarch leaves */
Keith Owens958b1662006-04-03 15:26:12 +10001634 if (notify_die(DIE_INIT_SLAVE_LEAVE, "INIT", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001635 == NOTIFY_STOP)
1636 ia64_mca_spin(__FUNCTION__);
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001637 mprintk("Slave on cpu %d returning to normal service.\n", cpu);
Keith Owens7f613c72005-09-11 17:22:53 +10001638 set_curr_task(cpu, previous_current);
1639 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
1640 atomic_dec(&slaves);
1641 return;
1642 }
1643
1644 monarch_cpu = cpu;
Keith Owens958b1662006-04-03 15:26:12 +10001645 if (notify_die(DIE_INIT_MONARCH_ENTER, "INIT", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001646 == NOTIFY_STOP)
1647 ia64_mca_spin(__FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
1649 /*
Keith Owens7f613c72005-09-11 17:22:53 +10001650 * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be
1651 * generated via the BMC's command-line interface, but since the console is on the
1652 * same serial line, the user will need some time to switch out of the BMC before
1653 * the dump begins.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 */
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001655 mprintk("Delaying for 5 seconds...\n");
Keith Owens7f613c72005-09-11 17:22:53 +10001656 udelay(5*1000000);
Keith Owens356a5c12006-04-11 14:59:41 +10001657 ia64_wait_for_slaves(cpu, "INIT");
Keith Owens9138d582005-11-07 11:27:13 -08001658 /* If nobody intercepts DIE_INIT_MONARCH_PROCESS then we drop through
1659 * to default_monarch_init_process() above and just print all the
1660 * tasks.
1661 */
Keith Owens958b1662006-04-03 15:26:12 +10001662 if (notify_die(DIE_INIT_MONARCH_PROCESS, "INIT", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001663 == NOTIFY_STOP)
1664 ia64_mca_spin(__FUNCTION__);
Keith Owens958b1662006-04-03 15:26:12 +10001665 if (notify_die(DIE_INIT_MONARCH_LEAVE, "INIT", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001666 == NOTIFY_STOP)
1667 ia64_mca_spin(__FUNCTION__);
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001668 mprintk("\nINIT dump complete. Monarch on cpu %d returning to normal service.\n", cpu);
Keith Owens7f613c72005-09-11 17:22:53 +10001669 atomic_dec(&monarchs);
1670 set_curr_task(cpu, previous_current);
1671 monarch_cpu = -1;
1672 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673}
1674
1675static int __init
1676ia64_mca_disable_cpe_polling(char *str)
1677{
1678 cpe_poll_enabled = 0;
1679 return 1;
1680}
1681
1682__setup("disable_cpe_poll", ia64_mca_disable_cpe_polling);
1683
1684static struct irqaction cmci_irqaction = {
1685 .handler = ia64_mca_cmc_int_handler,
Thomas Gleixner121a4222006-07-01 19:29:17 -07001686 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 .name = "cmc_hndlr"
1688};
1689
1690static struct irqaction cmcp_irqaction = {
1691 .handler = ia64_mca_cmc_int_caller,
Thomas Gleixner121a4222006-07-01 19:29:17 -07001692 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 .name = "cmc_poll"
1694};
1695
1696static struct irqaction mca_rdzv_irqaction = {
1697 .handler = ia64_mca_rendez_int_handler,
Thomas Gleixner121a4222006-07-01 19:29:17 -07001698 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 .name = "mca_rdzv"
1700};
1701
1702static struct irqaction mca_wkup_irqaction = {
1703 .handler = ia64_mca_wakeup_int_handler,
Thomas Gleixner121a4222006-07-01 19:29:17 -07001704 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 .name = "mca_wkup"
1706};
1707
1708#ifdef CONFIG_ACPI
1709static struct irqaction mca_cpe_irqaction = {
1710 .handler = ia64_mca_cpe_int_handler,
Thomas Gleixner121a4222006-07-01 19:29:17 -07001711 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 .name = "cpe_hndlr"
1713};
1714
1715static struct irqaction mca_cpep_irqaction = {
1716 .handler = ia64_mca_cpe_int_caller,
Thomas Gleixner121a4222006-07-01 19:29:17 -07001717 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 .name = "cpe_poll"
1719};
1720#endif /* CONFIG_ACPI */
1721
Keith Owens7f613c72005-09-11 17:22:53 +10001722/* Minimal format of the MCA/INIT stacks. The pseudo processes that run on
1723 * these stacks can never sleep, they cannot return from the kernel to user
1724 * space, they do not appear in a normal ps listing. So there is no need to
1725 * format most of the fields.
1726 */
1727
Chen, Kenneth W0881fc82006-03-12 08:52:20 -08001728static void __cpuinit
Keith Owens7f613c72005-09-11 17:22:53 +10001729format_mca_init_stack(void *mca_data, unsigned long offset,
1730 const char *type, int cpu)
1731{
1732 struct task_struct *p = (struct task_struct *)((char *)mca_data + offset);
1733 struct thread_info *ti;
1734 memset(p, 0, KERNEL_STACK_SIZE);
Al Viroab035912006-01-12 01:06:05 -08001735 ti = task_thread_info(p);
Keith Owens7f613c72005-09-11 17:22:53 +10001736 ti->flags = _TIF_MCA_INIT;
1737 ti->preempt_count = 1;
1738 ti->task = p;
1739 ti->cpu = cpu;
Roman Zippelf7e42172007-05-09 02:35:17 -07001740 p->stack = ti;
Keith Owens7f613c72005-09-11 17:22:53 +10001741 p->state = TASK_UNINTERRUPTIBLE;
Akinobu Mita4668f0c2006-03-26 01:39:03 -08001742 cpu_set(cpu, p->cpus_allowed);
Keith Owens7f613c72005-09-11 17:22:53 +10001743 INIT_LIST_HEAD(&p->tasks);
1744 p->parent = p->real_parent = p->group_leader = p;
1745 INIT_LIST_HEAD(&p->children);
1746 INIT_LIST_HEAD(&p->sibling);
1747 strncpy(p->comm, type, sizeof(p->comm)-1);
1748}
1749
Sam Ravnborg056e6d82007-07-30 22:50:13 +02001750/* Caller prevents this from being called after init */
1751static void * __init_refok mca_bootmem(void)
1752{
1753 void *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
Sam Ravnborg056e6d82007-07-30 22:50:13 +02001755 p = alloc_bootmem(sizeof(struct ia64_mca_cpu) * NR_CPUS +
1756 KERNEL_STACK_SIZE);
1757 return (void *)ALIGN((unsigned long)p, KERNEL_STACK_SIZE);
1758}
1759
1760/* Do per-CPU MCA-related initialization. */
Chen, Kenneth W0881fc82006-03-12 08:52:20 -08001761void __cpuinit
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762ia64_mca_cpu_init(void *cpu_data)
1763{
1764 void *pal_vaddr;
Ashok Rajff741902005-11-11 14:32:40 -08001765 static int first_time = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
Ashok Rajff741902005-11-11 14:32:40 -08001767 if (first_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 void *mca_data;
1769 int cpu;
1770
Ashok Rajff741902005-11-11 14:32:40 -08001771 first_time = 0;
Sam Ravnborg056e6d82007-07-30 22:50:13 +02001772 mca_data = mca_bootmem();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 for (cpu = 0; cpu < NR_CPUS; cpu++) {
Keith Owens7f613c72005-09-11 17:22:53 +10001774 format_mca_init_stack(mca_data,
1775 offsetof(struct ia64_mca_cpu, mca_stack),
1776 "MCA", cpu);
1777 format_mca_init_stack(mca_data,
1778 offsetof(struct ia64_mca_cpu, init_stack),
1779 "INIT", cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 __per_cpu_mca[cpu] = __pa(mca_data);
1781 mca_data += sizeof(struct ia64_mca_cpu);
1782 }
1783 }
1784
Keith Owens7f613c72005-09-11 17:22:53 +10001785 /*
1786 * The MCA info structure was allocated earlier and its
1787 * physical address saved in __per_cpu_mca[cpu]. Copy that
1788 * address * to ia64_mca_data so we can access it as a per-CPU
1789 * variable.
1790 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 __get_cpu_var(ia64_mca_data) = __per_cpu_mca[smp_processor_id()];
1792
1793 /*
1794 * Stash away a copy of the PTE needed to map the per-CPU page.
1795 * We may need it during MCA recovery.
1796 */
1797 __get_cpu_var(ia64_mca_per_cpu_pte) =
1798 pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL));
1799
Keith Owens7f613c72005-09-11 17:22:53 +10001800 /*
1801 * Also, stash away a copy of the PAL address and the PTE
1802 * needed to map it.
1803 */
1804 pal_vaddr = efi_get_pal_addr();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 if (!pal_vaddr)
1806 return;
1807 __get_cpu_var(ia64_mca_pal_base) =
1808 GRANULEROUNDDOWN((unsigned long) pal_vaddr);
1809 __get_cpu_var(ia64_mca_pal_pte) = pte_val(mk_pte_phys(__pa(pal_vaddr),
1810 PAGE_KERNEL));
1811}
1812
1813/*
1814 * ia64_mca_init
1815 *
1816 * Do all the system level mca specific initialization.
1817 *
1818 * 1. Register spinloop and wakeup request interrupt vectors
1819 *
1820 * 2. Register OS_MCA handler entry point
1821 *
1822 * 3. Register OS_INIT handler entry point
1823 *
1824 * 4. Initialize MCA/CMC/INIT related log buffers maintained by the OS.
1825 *
1826 * Note that this initialization is done very early before some kernel
1827 * services are available.
1828 *
1829 * Inputs : None
1830 *
1831 * Outputs : None
1832 */
1833void __init
1834ia64_mca_init(void)
1835{
Keith Owens7f613c72005-09-11 17:22:53 +10001836 ia64_fptr_t *init_hldlr_ptr_monarch = (ia64_fptr_t *)ia64_os_init_dispatch_monarch;
1837 ia64_fptr_t *init_hldlr_ptr_slave = (ia64_fptr_t *)ia64_os_init_dispatch_slave;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch;
1839 int i;
1840 s64 rc;
1841 struct ia64_sal_retval isrv;
1842 u64 timeout = IA64_MCA_RENDEZ_TIMEOUT; /* platform specific */
Keith Owens9138d582005-11-07 11:27:13 -08001843 static struct notifier_block default_init_monarch_nb = {
1844 .notifier_call = default_monarch_init_process,
1845 .priority = 0/* we need to notified last */
1846 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
1848 IA64_MCA_DEBUG("%s: begin\n", __FUNCTION__);
1849
1850 /* Clear the Rendez checkin flag for all cpus */
1851 for(i = 0 ; i < NR_CPUS; i++)
1852 ia64_mc_info.imi_rendez_checkin[i] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
1853
1854 /*
1855 * Register the rendezvous spinloop and wakeup mechanism with SAL
1856 */
1857
1858 /* Register the rendezvous interrupt vector with SAL */
1859 while (1) {
1860 isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_INT,
1861 SAL_MC_PARAM_MECHANISM_INT,
1862 IA64_MCA_RENDEZ_VECTOR,
1863 timeout,
1864 SAL_MC_PARAM_RZ_ALWAYS);
1865 rc = isrv.status;
1866 if (rc == 0)
1867 break;
1868 if (rc == -2) {
1869 printk(KERN_INFO "Increasing MCA rendezvous timeout from "
1870 "%ld to %ld milliseconds\n", timeout, isrv.v0);
1871 timeout = isrv.v0;
Keith Owens958b1662006-04-03 15:26:12 +10001872 (void) notify_die(DIE_MCA_NEW_TIMEOUT, "MCA", NULL, timeout, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 continue;
1874 }
1875 printk(KERN_ERR "Failed to register rendezvous interrupt "
1876 "with SAL (status %ld)\n", rc);
1877 return;
1878 }
1879
1880 /* Register the wakeup interrupt vector with SAL */
1881 isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_WAKEUP,
1882 SAL_MC_PARAM_MECHANISM_INT,
1883 IA64_MCA_WAKEUP_VECTOR,
1884 0, 0);
1885 rc = isrv.status;
1886 if (rc) {
1887 printk(KERN_ERR "Failed to register wakeup interrupt with SAL "
1888 "(status %ld)\n", rc);
1889 return;
1890 }
1891
1892 IA64_MCA_DEBUG("%s: registered MCA rendezvous spinloop and wakeup mech.\n", __FUNCTION__);
1893
1894 ia64_mc_info.imi_mca_handler = ia64_tpa(mca_hldlr_ptr->fp);
1895 /*
1896 * XXX - disable SAL checksum by setting size to 0; should be
1897 * ia64_tpa(ia64_os_mca_dispatch_end) - ia64_tpa(ia64_os_mca_dispatch);
1898 */
1899 ia64_mc_info.imi_mca_handler_size = 0;
1900
1901 /* Register the os mca handler with SAL */
1902 if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_MCA,
1903 ia64_mc_info.imi_mca_handler,
1904 ia64_tpa(mca_hldlr_ptr->gp),
1905 ia64_mc_info.imi_mca_handler_size,
1906 0, 0, 0)))
1907 {
1908 printk(KERN_ERR "Failed to register OS MCA handler with SAL "
1909 "(status %ld)\n", rc);
1910 return;
1911 }
1912
1913 IA64_MCA_DEBUG("%s: registered OS MCA handler with SAL at 0x%lx, gp = 0x%lx\n", __FUNCTION__,
1914 ia64_mc_info.imi_mca_handler, ia64_tpa(mca_hldlr_ptr->gp));
1915
1916 /*
1917 * XXX - disable SAL checksum by setting size to 0, should be
1918 * size of the actual init handler in mca_asm.S.
1919 */
Keith Owens7f613c72005-09-11 17:22:53 +10001920 ia64_mc_info.imi_monarch_init_handler = ia64_tpa(init_hldlr_ptr_monarch->fp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 ia64_mc_info.imi_monarch_init_handler_size = 0;
Keith Owens7f613c72005-09-11 17:22:53 +10001922 ia64_mc_info.imi_slave_init_handler = ia64_tpa(init_hldlr_ptr_slave->fp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 ia64_mc_info.imi_slave_init_handler_size = 0;
1924
1925 IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __FUNCTION__,
1926 ia64_mc_info.imi_monarch_init_handler);
1927
1928 /* Register the os init handler with SAL */
1929 if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_INIT,
1930 ia64_mc_info.imi_monarch_init_handler,
1931 ia64_tpa(ia64_getreg(_IA64_REG_GP)),
1932 ia64_mc_info.imi_monarch_init_handler_size,
1933 ia64_mc_info.imi_slave_init_handler,
1934 ia64_tpa(ia64_getreg(_IA64_REG_GP)),
1935 ia64_mc_info.imi_slave_init_handler_size)))
1936 {
1937 printk(KERN_ERR "Failed to register m/s INIT handlers with SAL "
1938 "(status %ld)\n", rc);
1939 return;
1940 }
Keith Owens9138d582005-11-07 11:27:13 -08001941 if (register_die_notifier(&default_init_monarch_nb)) {
1942 printk(KERN_ERR "Failed to register default monarch INIT process\n");
1943 return;
1944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945
1946 IA64_MCA_DEBUG("%s: registered OS INIT handler with SAL\n", __FUNCTION__);
1947
1948 /*
1949 * Configure the CMCI/P vector and handler. Interrupts for CMC are
1950 * per-processor, so AP CMC interrupts are setup in smp_callin() (smpboot.c).
1951 */
1952 register_percpu_irq(IA64_CMC_VECTOR, &cmci_irqaction);
1953 register_percpu_irq(IA64_CMCP_VECTOR, &cmcp_irqaction);
1954 ia64_mca_cmc_vector_setup(); /* Setup vector on BSP */
1955
1956 /* Setup the MCA rendezvous interrupt vector */
1957 register_percpu_irq(IA64_MCA_RENDEZ_VECTOR, &mca_rdzv_irqaction);
1958
1959 /* Setup the MCA wakeup interrupt vector */
1960 register_percpu_irq(IA64_MCA_WAKEUP_VECTOR, &mca_wkup_irqaction);
1961
1962#ifdef CONFIG_ACPI
Russ Andersonbb68c122005-05-09 15:03:00 -07001963 /* Setup the CPEI/P handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 register_percpu_irq(IA64_CPEP_VECTOR, &mca_cpep_irqaction);
1965#endif
1966
1967 /* Initialize the areas set aside by the OS to buffer the
1968 * platform/processor error states for MCA/INIT/CMC
1969 * handling.
1970 */
1971 ia64_log_init(SAL_INFO_TYPE_MCA);
1972 ia64_log_init(SAL_INFO_TYPE_INIT);
1973 ia64_log_init(SAL_INFO_TYPE_CMC);
1974 ia64_log_init(SAL_INFO_TYPE_CPE);
1975
1976 mca_init = 1;
1977 printk(KERN_INFO "MCA related initialization done\n");
1978}
1979
1980/*
1981 * ia64_mca_late_init
1982 *
1983 * Opportunity to setup things that require initialization later
1984 * than ia64_mca_init. Setup a timer to poll for CPEs if the
1985 * platform doesn't support an interrupt driven mechanism.
1986 *
1987 * Inputs : None
1988 * Outputs : Status
1989 */
1990static int __init
1991ia64_mca_late_init(void)
1992{
1993 if (!mca_init)
1994 return 0;
1995
1996 /* Setup the CMCI/P vector and handler */
1997 init_timer(&cmc_poll_timer);
1998 cmc_poll_timer.function = ia64_mca_cmc_poll;
1999
2000 /* Unmask/enable the vector */
2001 cmc_polling_enabled = 0;
2002 schedule_work(&cmc_enable_work);
2003
2004 IA64_MCA_DEBUG("%s: CMCI/P setup and enabled.\n", __FUNCTION__);
2005
2006#ifdef CONFIG_ACPI
2007 /* Setup the CPEI/P vector and handler */
Russ Andersonbb68c122005-05-09 15:03:00 -07002008 cpe_vector = acpi_request_vector(ACPI_INTERRUPT_CPEI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 init_timer(&cpe_poll_timer);
2010 cpe_poll_timer.function = ia64_mca_cpe_poll;
2011
2012 {
2013 irq_desc_t *desc;
2014 unsigned int irq;
2015
2016 if (cpe_vector >= 0) {
2017 /* If platform supports CPEI, enable the irq. */
Russ Andersona1287472007-08-03 14:32:37 -05002018 irq = local_vector_to_irq(cpe_vector);
2019 if (irq > 0) {
2020 cpe_poll_enabled = 0;
2021 desc = irq_desc + irq;
2022 desc->status |= IRQ_PER_CPU;
2023 setup_irq(irq, &mca_cpe_irqaction);
2024 ia64_cpe_irq = irq;
2025 ia64_mca_register_cpev(cpe_vector);
2026 IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n",
2027 __FUNCTION__);
2028 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 }
Russ Andersona1287472007-08-03 14:32:37 -05002030 printk(KERN_ERR "%s: Failed to find irq for CPE "
2031 "interrupt handler, vector %d\n",
2032 __FUNCTION__, cpe_vector);
2033 }
2034 /* If platform doesn't support CPEI, get the timer going. */
2035 if (cpe_poll_enabled) {
2036 ia64_mca_cpe_poll(0UL);
2037 IA64_MCA_DEBUG("%s: CPEP setup and enabled.\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 }
2039 }
2040#endif
2041
2042 return 0;
2043}
2044
2045device_initcall(ia64_mca_late_init);