3 * Purpose: Generic MCA handling layer
5 * Updated for latest kernel
6 * Copyright (C) 2003 Hewlett-Packard Co
7 * David Mosberger-Tang <davidm@hpl.hp.com>
9 * Copyright (C) 2002 Dell Inc.
10 * Copyright (C) Matt Domsch (Matt_Domsch@dell.com)
12 * Copyright (C) 2002 Intel
13 * Copyright (C) Jenna Hall (jenna.s.hall@intel.com)
15 * Copyright (C) 2001 Intel
16 * Copyright (C) Fred Lewis (frederick.v.lewis@intel.com)
18 * Copyright (C) 2000 Intel
19 * Copyright (C) Chuck Fleckenstein (cfleck@co.intel.com)
21 * Copyright (C) 1999, 2004 Silicon Graphics, Inc.
22 * Copyright (C) Vijay Chander(vijay@engr.sgi.com)
24 * 03/04/15 D. Mosberger Added INIT backtrace support.
25 * 02/03/25 M. Domsch GUID cleanups
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().
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
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.
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().
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
52 #include <linux/config.h>
53 #include <linux/types.h>
54 #include <linux/init.h>
55 #include <linux/sched.h>
56 #include <linux/interrupt.h>
57 #include <linux/irq.h>
58 #include <linux/smp_lock.h>
59 #include <linux/bootmem.h>
60 #include <linux/acpi.h>
61 #include <linux/timer.h>
62 #include <linux/module.h>
63 #include <linux/kernel.h>
64 #include <linux/smp.h>
65 #include <linux/tqueue.h>
67 #include <asm/delay.h>
68 #include <asm/machvec.h>
70 #include <asm/ptrace.h>
71 #include <asm/system.h>
76 #include <asm/hw_irq.h>
78 #if defined(IA64_MCA_DEBUG_INFO)
79 # define IA64_MCA_DEBUG(fmt...) printk(fmt)
81 # define IA64_MCA_DEBUG(fmt...)
84 extern void show_stack(struct task_struct *);
86 typedef struct ia64_fptr {
91 /* Used by mca_asm.S */
92 ia64_mca_sal_to_os_state_t ia64_sal_to_os_handoff_state;
93 ia64_mca_os_to_sal_state_t ia64_os_to_sal_handoff_state;
94 u64 ia64_mca_proc_state_dump[512];
95 u64 ia64_mca_stack[1024] __attribute__((aligned(16)));
96 u64 ia64_mca_stackframe[32];
97 u64 ia64_mca_bspstore[1024];
98 u64 ia64_init_stack[INIT_TASK_SIZE/8] __attribute__((aligned(16)));
99 u64 ia64_mca_serialize;
102 extern void ia64_monarch_init_handler (void);
103 extern void ia64_slave_init_handler (void);
105 static ia64_mc_info_t ia64_mc_info;
107 extern struct hw_interrupt_type irq_type_iosapic_level;
109 struct ia64_mca_tlb_info ia64_mca_tlb_list[NR_CPUS];
111 #define MAX_CPE_POLL_INTERVAL (15*60*HZ) /* 15 minutes */
112 #define MIN_CPE_POLL_INTERVAL (2*60*HZ) /* 2 minutes */
113 #define CMC_POLL_INTERVAL (1*60*HZ) /* 1 minute */
114 #define CMC_HISTORY_LENGTH 5
116 static struct timer_list cpe_poll_timer;
117 static struct timer_list cmc_poll_timer;
119 * This variable tells whether we are currently in polling mode.
120 * Start with this in the wrong state so we won't play w/ timers
121 * before the system is ready.
123 static int cmc_polling_enabled = 1;
126 * Clearing this variable prevents CPE polling from getting activated
127 * in mca_late_init. Use it if your system doesn't provide a CPEI,
128 * but encounters problems retrieving CPE logs. This should only be
129 * necessary for debugging.
131 static int cpe_poll_enabled = 1;
133 extern void salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe);
135 static struct tq_struct cmc_disable_tq, cmc_enable_tq;
138 * IA64_MCA log support
140 #define IA64_MAX_LOGS 2 /* Double-buffering for nested MCAs */
141 #define IA64_MAX_LOG_TYPES 4 /* MCA, INIT, CMC, CPE */
143 typedef struct ia64_state_log_s
147 unsigned long isl_count;
148 ia64_err_rec_t *isl_log[IA64_MAX_LOGS]; /* need space to store header + error log */
151 static ia64_state_log_t ia64_state_log[IA64_MAX_LOG_TYPES];
153 #define IA64_LOG_ALLOCATE(it, size) \
154 {ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)] = \
155 (ia64_err_rec_t *)alloc_bootmem(size); \
156 ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)] = \
157 (ia64_err_rec_t *)alloc_bootmem(size);}
158 #define IA64_LOG_LOCK_INIT(it) spin_lock_init(&ia64_state_log[it].isl_lock)
159 #define IA64_LOG_LOCK(it) spin_lock_irqsave(&ia64_state_log[it].isl_lock, s)
160 #define IA64_LOG_UNLOCK(it) spin_unlock_irqrestore(&ia64_state_log[it].isl_lock,s)
161 #define IA64_LOG_NEXT_INDEX(it) ia64_state_log[it].isl_index
162 #define IA64_LOG_CURR_INDEX(it) 1 - ia64_state_log[it].isl_index
163 #define IA64_LOG_INDEX_INC(it) \
164 {ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index; \
165 ia64_state_log[it].isl_count++;}
166 #define IA64_LOG_INDEX_DEC(it) \
167 ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index
168 #define IA64_LOG_NEXT_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)]))
169 #define IA64_LOG_CURR_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)]))
170 #define IA64_LOG_COUNT(it) ia64_state_log[it].isl_count
174 * Reset the OS ia64 log buffer
175 * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
179 ia64_log_init(int sal_info_type)
183 IA64_LOG_NEXT_INDEX(sal_info_type) = 0;
184 IA64_LOG_LOCK_INIT(sal_info_type);
186 // SAL will tell us the maximum size of any error record of this type
187 max_size = ia64_sal_get_state_info_size(sal_info_type);
189 /* alloc_bootmem() doesn't like zero-sized allocations! */
192 // set up OS data structures to hold error info
193 IA64_LOG_ALLOCATE(sal_info_type, max_size);
194 memset(IA64_LOG_CURR_BUFFER(sal_info_type), 0, max_size);
195 memset(IA64_LOG_NEXT_BUFFER(sal_info_type), 0, max_size);
201 * Get the current MCA log from SAL and copy it into the OS log buffer.
203 * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
204 * irq_safe whether you can use printk at this point
205 * Outputs : size (total record length)
206 * *buffer (ptr to error record)
210 ia64_log_get(int sal_info_type, u8 **buffer, int irq_safe)
212 sal_log_record_header_t *log_buffer;
216 IA64_LOG_LOCK(sal_info_type);
218 /* Get the process state information */
219 log_buffer = IA64_LOG_NEXT_BUFFER(sal_info_type);
221 total_len = ia64_sal_get_state_info(sal_info_type, (u64 *)log_buffer);
224 IA64_LOG_INDEX_INC(sal_info_type);
225 IA64_LOG_UNLOCK(sal_info_type);
227 IA64_MCA_DEBUG("%s: SAL error record type %d retrieved. "
228 "Record length = %ld\n", __FUNCTION__, sal_info_type, total_len);
230 *buffer = (u8 *) log_buffer;
233 IA64_LOG_UNLOCK(sal_info_type);
239 * ia64_mca_log_sal_error_record
241 * This function retrieves a specified error record type from SAL
242 * and wakes up any processes waiting for error records.
244 * Inputs : sal_info_type (Type of error record MCA/CMC/CPE/INIT)
247 ia64_mca_log_sal_error_record(int sal_info_type)
251 int irq_safe = sal_info_type != SAL_INFO_TYPE_MCA && sal_info_type != SAL_INFO_TYPE_INIT;
252 static const char * const rec_name[] = { "MCA", "INIT", "CMC", "CPE" };
254 size = ia64_log_get(sal_info_type, &buffer, irq_safe);
258 salinfo_log_wakeup(sal_info_type, buffer, size, irq_safe);
261 printk(KERN_INFO "CPU %d: SAL log contains %s error record\n",
263 sal_info_type < ARRAY_SIZE(rec_name) ? rec_name[sal_info_type] : "UNKNOWN");
265 /* Clear logs from corrected errors in case there's no user-level logger */
266 if (sal_info_type == SAL_INFO_TYPE_CPE || sal_info_type == SAL_INFO_TYPE_CMC)
267 ia64_sal_clear_state_info(sal_info_type);
271 * platform dependent error handling
273 #ifndef PLATFORM_MCA_HANDLERS
276 ia64_mca_cpe_int_handler (int cpe_irq, void *arg, struct pt_regs *ptregs)
278 IA64_MCA_DEBUG("%s: received interrupt. CPU:%d vector = %#x\n",
279 __FUNCTION__, smp_processor_id(), cpe_irq);
281 /* SAL spec states this should run w/ interrupts enabled */
284 /* Get the CMC error record and log it */
285 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE);
288 #define print_symbol(fmt, addr) printk(fmt, "(no symbol)");
291 show_min_state (pal_min_state_area_t *minstate)
293 u64 iip = minstate->pmsa_iip + ((struct ia64_psr *)(&minstate->pmsa_ipsr))->ri;
294 u64 xip = minstate->pmsa_xip + ((struct ia64_psr *)(&minstate->pmsa_xpsr))->ri;
296 printk("NaT bits\t%016lx\n", minstate->pmsa_nat_bits);
297 printk("pr\t\t%016lx\n", minstate->pmsa_pr);
298 printk("b0\t\t%016lx ", minstate->pmsa_br0); print_symbol("%s\n", minstate->pmsa_br0);
299 printk("ar.rsc\t\t%016lx\n", minstate->pmsa_rsc);
300 printk("cr.iip\t\t%016lx ", iip); print_symbol("%s\n", iip);
301 printk("cr.ipsr\t\t%016lx\n", minstate->pmsa_ipsr);
302 printk("cr.ifs\t\t%016lx\n", minstate->pmsa_ifs);
303 printk("xip\t\t%016lx ", xip); print_symbol("%s\n", xip);
304 printk("xpsr\t\t%016lx\n", minstate->pmsa_xpsr);
305 printk("xfs\t\t%016lx\n", minstate->pmsa_xfs);
306 printk("b1\t\t%016lx ", minstate->pmsa_br1);
307 print_symbol("%s\n", minstate->pmsa_br1);
309 printk("\nstatic registers r0-r15:\n");
310 printk(" r0- 3 %016lx %016lx %016lx %016lx\n",
311 0UL, minstate->pmsa_gr[0], minstate->pmsa_gr[1], minstate->pmsa_gr[2]);
312 printk(" r4- 7 %016lx %016lx %016lx %016lx\n",
313 minstate->pmsa_gr[3], minstate->pmsa_gr[4],
314 minstate->pmsa_gr[5], minstate->pmsa_gr[6]);
315 printk(" r8-11 %016lx %016lx %016lx %016lx\n",
316 minstate->pmsa_gr[7], minstate->pmsa_gr[8],
317 minstate->pmsa_gr[9], minstate->pmsa_gr[10]);
318 printk("r12-15 %016lx %016lx %016lx %016lx\n",
319 minstate->pmsa_gr[11], minstate->pmsa_gr[12],
320 minstate->pmsa_gr[13], minstate->pmsa_gr[14]);
322 printk("\nbank 0:\n");
323 printk("r16-19 %016lx %016lx %016lx %016lx\n",
324 minstate->pmsa_bank0_gr[0], minstate->pmsa_bank0_gr[1],
325 minstate->pmsa_bank0_gr[2], minstate->pmsa_bank0_gr[3]);
326 printk("r20-23 %016lx %016lx %016lx %016lx\n",
327 minstate->pmsa_bank0_gr[4], minstate->pmsa_bank0_gr[5],
328 minstate->pmsa_bank0_gr[6], minstate->pmsa_bank0_gr[7]);
329 printk("r24-27 %016lx %016lx %016lx %016lx\n",
330 minstate->pmsa_bank0_gr[8], minstate->pmsa_bank0_gr[9],
331 minstate->pmsa_bank0_gr[10], minstate->pmsa_bank0_gr[11]);
332 printk("r28-31 %016lx %016lx %016lx %016lx\n",
333 minstate->pmsa_bank0_gr[12], minstate->pmsa_bank0_gr[13],
334 minstate->pmsa_bank0_gr[14], minstate->pmsa_bank0_gr[15]);
336 printk("\nbank 1:\n");
337 printk("r16-19 %016lx %016lx %016lx %016lx\n",
338 minstate->pmsa_bank1_gr[0], minstate->pmsa_bank1_gr[1],
339 minstate->pmsa_bank1_gr[2], minstate->pmsa_bank1_gr[3]);
340 printk("r20-23 %016lx %016lx %016lx %016lx\n",
341 minstate->pmsa_bank1_gr[4], minstate->pmsa_bank1_gr[5],
342 minstate->pmsa_bank1_gr[6], minstate->pmsa_bank1_gr[7]);
343 printk("r24-27 %016lx %016lx %016lx %016lx\n",
344 minstate->pmsa_bank1_gr[8], minstate->pmsa_bank1_gr[9],
345 minstate->pmsa_bank1_gr[10], minstate->pmsa_bank1_gr[11]);
346 printk("r28-31 %016lx %016lx %016lx %016lx\n",
347 minstate->pmsa_bank1_gr[12], minstate->pmsa_bank1_gr[13],
348 minstate->pmsa_bank1_gr[14], minstate->pmsa_bank1_gr[15]);
352 fetch_min_state (pal_min_state_area_t *ms, struct pt_regs *pt, struct switch_stack *sw)
354 u64 *dst_banked, *src_banked, bit, shift, nat_bits;
358 * First, update the pt-regs and switch-stack structures with the contents stored
359 * in the min-state area:
361 if (((struct ia64_psr *) &ms->pmsa_ipsr)->ic == 0) {
362 pt->cr_ipsr = ms->pmsa_xpsr;
363 pt->cr_iip = ms->pmsa_xip;
364 pt->cr_ifs = ms->pmsa_xfs;
366 pt->cr_ipsr = ms->pmsa_ipsr;
367 pt->cr_iip = ms->pmsa_iip;
368 pt->cr_ifs = ms->pmsa_ifs;
370 pt->ar_rsc = ms->pmsa_rsc;
371 pt->pr = ms->pmsa_pr;
372 pt->r1 = ms->pmsa_gr[0];
373 pt->r2 = ms->pmsa_gr[1];
374 pt->r3 = ms->pmsa_gr[2];
375 sw->r4 = ms->pmsa_gr[3];
376 sw->r5 = ms->pmsa_gr[4];
377 sw->r6 = ms->pmsa_gr[5];
378 sw->r7 = ms->pmsa_gr[6];
379 pt->r8 = ms->pmsa_gr[7];
380 pt->r9 = ms->pmsa_gr[8];
381 pt->r10 = ms->pmsa_gr[9];
382 pt->r11 = ms->pmsa_gr[10];
383 pt->r12 = ms->pmsa_gr[11];
384 pt->r13 = ms->pmsa_gr[12];
385 pt->r14 = ms->pmsa_gr[13];
386 pt->r15 = ms->pmsa_gr[14];
387 dst_banked = &pt->r16; /* r16-r31 are contiguous in struct pt_regs */
388 src_banked = ms->pmsa_bank1_gr;
389 for (i = 0; i < 16; ++i)
390 dst_banked[i] = src_banked[i];
391 pt->b0 = ms->pmsa_br0;
392 sw->b1 = ms->pmsa_br1;
394 /* construct the NaT bits for the pt-regs structure: */
395 # define PUT_NAT_BIT(dst, addr) \
397 bit = nat_bits & 1; nat_bits >>= 1; \
398 shift = ((unsigned long) addr >> 3) & 0x3f; \
399 dst = ((dst) & ~(1UL << shift)) | (bit << shift); \
402 /* Rotate the saved NaT bits such that bit 0 corresponds to pmsa_gr[0]: */
403 shift = ((unsigned long) &ms->pmsa_gr[0] >> 3) & 0x3f;
404 nat_bits = (ms->pmsa_nat_bits >> shift) | (ms->pmsa_nat_bits << (64 - shift));
406 PUT_NAT_BIT(sw->caller_unat, &pt->r1);
407 PUT_NAT_BIT(sw->caller_unat, &pt->r2);
408 PUT_NAT_BIT(sw->caller_unat, &pt->r3);
409 PUT_NAT_BIT(sw->ar_unat, &sw->r4);
410 PUT_NAT_BIT(sw->ar_unat, &sw->r5);
411 PUT_NAT_BIT(sw->ar_unat, &sw->r6);
412 PUT_NAT_BIT(sw->ar_unat, &sw->r7);
413 PUT_NAT_BIT(sw->caller_unat, &pt->r8); PUT_NAT_BIT(sw->caller_unat, &pt->r9);
414 PUT_NAT_BIT(sw->caller_unat, &pt->r10); PUT_NAT_BIT(sw->caller_unat, &pt->r11);
415 PUT_NAT_BIT(sw->caller_unat, &pt->r12); PUT_NAT_BIT(sw->caller_unat, &pt->r13);
416 PUT_NAT_BIT(sw->caller_unat, &pt->r14); PUT_NAT_BIT(sw->caller_unat, &pt->r15);
417 nat_bits >>= 16; /* skip over bank0 NaT bits */
418 PUT_NAT_BIT(sw->caller_unat, &pt->r16); PUT_NAT_BIT(sw->caller_unat, &pt->r17);
419 PUT_NAT_BIT(sw->caller_unat, &pt->r18); PUT_NAT_BIT(sw->caller_unat, &pt->r19);
420 PUT_NAT_BIT(sw->caller_unat, &pt->r20); PUT_NAT_BIT(sw->caller_unat, &pt->r21);
421 PUT_NAT_BIT(sw->caller_unat, &pt->r22); PUT_NAT_BIT(sw->caller_unat, &pt->r23);
422 PUT_NAT_BIT(sw->caller_unat, &pt->r24); PUT_NAT_BIT(sw->caller_unat, &pt->r25);
423 PUT_NAT_BIT(sw->caller_unat, &pt->r26); PUT_NAT_BIT(sw->caller_unat, &pt->r27);
424 PUT_NAT_BIT(sw->caller_unat, &pt->r28); PUT_NAT_BIT(sw->caller_unat, &pt->r29);
425 PUT_NAT_BIT(sw->caller_unat, &pt->r30); PUT_NAT_BIT(sw->caller_unat, &pt->r31);
429 init_handler_platform (pal_min_state_area_t *ms,
430 struct pt_regs *pt, struct switch_stack *sw)
432 struct unw_frame_info info;
434 /* if a kernel debugger is available call it here else just dump the registers */
437 * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be
438 * generated via the BMC's command-line interface, but since the console is on the
439 * same serial line, the user will need some time to switch out of the BMC before
442 printk("Delaying for 5 seconds...\n");
446 printk("Backtrace of current task (pid %d, %s)\n", current->pid, current->comm);
447 fetch_min_state(ms, pt, sw);
448 unw_init_from_interruption(&info, current, pt, sw);
449 ia64_do_show_stack(&info, NULL);
452 /* read_trylock() would be handy... */
453 if (!tasklist_lock.write_lock)
454 read_lock(&tasklist_lock);
457 struct task_struct *t;
462 printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm);
467 if (!tasklist_lock.write_lock)
468 read_unlock(&tasklist_lock);
471 printk("\nINIT dump complete. Please reboot now.\n");
472 while (1); /* hang city if no debugger */
477 * ia64_mca_register_cpev
479 * Register the corrected platform error vector with SAL.
482 * cpev Corrected Platform Error Vector number
488 ia64_mca_register_cpev (int cpev)
490 /* Register the CPE interrupt vector with SAL */
491 struct ia64_sal_retval isrv;
493 isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_CPE_INT, SAL_MC_PARAM_MECHANISM_INT, cpev, 0, 0);
495 printk(KERN_ERR "Failed to register Corrected Platform "
496 "Error interrupt vector with SAL (status %ld)\n", isrv.status);
500 IA64_MCA_DEBUG("%s: corrected platform error "
501 "vector %#x setup and enabled\n", __FUNCTION__, cpev);
503 #endif /* CONFIG_ACPI */
505 #endif /* PLATFORM_MCA_HANDLERS */
508 * ia64_mca_cmc_vector_setup
510 * Setup the corrected machine check vector register in the processor and
511 * unmask interrupt. This function is invoked on a per-processor basis.
520 ia64_mca_cmc_vector_setup (void)
524 cmcv.cmcv_regval = 0;
525 cmcv.cmcv_mask = 0; /* Unmask/enable interrupt */
526 cmcv.cmcv_vector = IA64_CMC_VECTOR;
527 ia64_set_cmcv(cmcv.cmcv_regval);
529 IA64_MCA_DEBUG("%s: CPU %d corrected "
530 "machine check vector %#x setup and enabled.\n",
531 __FUNCTION__, smp_processor_id(), IA64_CMC_VECTOR);
533 IA64_MCA_DEBUG("%s: CPU %d CMCV = %#016lx\n",
534 __FUNCTION__, smp_processor_id(), ia64_get_cmcv());
538 * ia64_mca_cmc_vector_disable
540 * Mask the corrected machine check vector register in the processor.
541 * This function is invoked on a per-processor basis.
550 ia64_mca_cmc_vector_disable (void *dummy)
554 cmcv = (cmcv_reg_t)ia64_get_cmcv();
556 cmcv.cmcv_mask = 1; /* Mask/disable interrupt */
557 ia64_set_cmcv(cmcv.cmcv_regval);
559 IA64_MCA_DEBUG("%s: CPU %d corrected "
560 "machine check vector %#x disabled.\n",
561 __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector);
565 * ia64_mca_cmc_vector_enable
567 * Unmask the corrected machine check vector register in the processor.
568 * This function is invoked on a per-processor basis.
577 ia64_mca_cmc_vector_enable (void *dummy)
581 cmcv = (cmcv_reg_t)ia64_get_cmcv();
583 cmcv.cmcv_mask = 0; /* Unmask/enable interrupt */
584 ia64_set_cmcv(cmcv.cmcv_regval);
586 IA64_MCA_DEBUG("%s: CPU %d corrected "
587 "machine check vector %#x enabled.\n",
588 __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector);
592 * ia64_mca_cmc_vector_disable_keventd
594 * Called via keventd (smp_call_function() is not safe in interrupt context) to
595 * disable the cmc interrupt vector.
597 * Note: needs preempt_disable() if you apply the preempt patch to 2.4.
600 ia64_mca_cmc_vector_disable_keventd(void *unused)
602 ia64_mca_cmc_vector_disable(NULL);
603 smp_call_function(ia64_mca_cmc_vector_disable, NULL, 1, 0);
607 * ia64_mca_cmc_vector_enable_keventd
609 * Called via keventd (smp_call_function() is not safe in interrupt context) to
610 * enable the cmc interrupt vector.
612 * Note: needs preempt_disable() if you apply the preempt patch to 2.4.
615 ia64_mca_cmc_vector_enable_keventd(void *unused)
617 smp_call_function(ia64_mca_cmc_vector_enable, NULL, 1, 0);
618 ia64_mca_cmc_vector_enable(NULL);
622 * ia64_mca_wakeup_ipi_wait
624 * Wait for the inter-cpu interrupt to be sent by the
625 * monarch processor once it is done with handling the
632 ia64_mca_wakeup_ipi_wait(void)
634 int irr_num = (IA64_MCA_WAKEUP_VECTOR >> 6);
635 int irr_bit = (IA64_MCA_WAKEUP_VECTOR & 0x3f);
641 irr = ia64_get_irr0();
644 irr = ia64_get_irr1();
647 irr = ia64_get_irr2();
650 irr = ia64_get_irr3();
653 } while (!(irr & (1UL << irr_bit))) ;
659 * Send an inter-cpu interrupt to wake-up a particular cpu
660 * and mark that cpu to be out of rendez.
666 ia64_mca_wakeup(int cpu)
668 platform_send_ipi(cpu, IA64_MCA_WAKEUP_VECTOR, IA64_IPI_DM_INT, 0);
669 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
674 * ia64_mca_wakeup_all
676 * Wakeup all the cpus which have rendez'ed previously.
682 ia64_mca_wakeup_all(void)
686 /* Clear the Rendez checkin flag for all cpus */
687 for(cpu = 0; cpu < NR_CPUS; cpu++) {
688 if (!cpu_online(cpu))
690 if (ia64_mc_info.imi_rendez_checkin[cpu] == IA64_MCA_RENDEZ_CHECKIN_DONE)
691 ia64_mca_wakeup(cpu);
697 * ia64_mca_rendez_interrupt_handler
699 * This is handler used to put slave processors into spinloop
700 * while the monarch processor does the mca handling and later
701 * wake each slave up once the monarch is done.
707 ia64_mca_rendez_int_handler(int rendez_irq, void *arg, struct pt_regs *ptregs)
710 int cpu = smp_processor_id();
712 /* Mask all interrupts */
713 local_irq_save(flags);
715 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_DONE;
716 /* Register with the SAL monarch that the slave has
719 ia64_sal_mc_rendez();
721 /* Wait for the wakeup IPI from the monarch
722 * This waiting is done by polling on the wakeup-interrupt
723 * vector bit in the processor's IRRs
725 ia64_mca_wakeup_ipi_wait();
727 /* Enable all interrupts */
728 local_irq_restore(flags);
732 * ia64_mca_wakeup_int_handler
734 * The interrupt handler for processing the inter-cpu interrupt to the
735 * slave cpu which was spinning in the rendez loop.
736 * Since this spinning is done by turning off the interrupts and
737 * polling on the wakeup-interrupt bit in the IRR, there is
738 * nothing useful to be done in the handler.
740 * Inputs : wakeup_irq (Wakeup-interrupt bit)
741 * arg (Interrupt handler specific argument)
742 * ptregs (Exception frame at the time of the interrupt)
747 ia64_mca_wakeup_int_handler(int wakeup_irq, void *arg, struct pt_regs *ptregs)
752 * ia64_return_to_sal_check
754 * This is function called before going back from the OS_MCA handler
755 * to the OS_MCA dispatch code which finally takes the control back
757 * The main purpose of this routine is to setup the OS_MCA to SAL
758 * return state which can be used by the OS_MCA dispatch code
759 * just before going back to SAL.
766 ia64_return_to_sal_check(int recover)
769 /* Copy over some relevant stuff from the sal_to_os_mca_handoff
770 * so that it can be used at the time of os_mca_to_sal_handoff
772 ia64_os_to_sal_handoff_state.imots_sal_gp =
773 ia64_sal_to_os_handoff_state.imsto_sal_gp;
775 ia64_os_to_sal_handoff_state.imots_sal_check_ra =
776 ia64_sal_to_os_handoff_state.imsto_sal_check_ra;
779 ia64_os_to_sal_handoff_state.imots_os_status = IA64_MCA_CORRECTED;
781 ia64_os_to_sal_handoff_state.imots_os_status = IA64_MCA_COLD_BOOT;
783 /* Default = tell SAL to return to same context */
784 ia64_os_to_sal_handoff_state.imots_context = IA64_MCA_SAME_CONTEXT;
786 ia64_os_to_sal_handoff_state.imots_new_min_state =
787 (u64 *)ia64_sal_to_os_handoff_state.pal_min_state;
792 * ia64_mca_ucmc_handler
794 * This is uncorrectable machine check handler called from OS_MCA
795 * dispatch code which is in turn called from SAL_CHECK().
796 * This is the place where the core of OS MCA handling is done.
797 * Right now the logs are extracted and displayed in a well-defined
798 * format. This handler code is supposed to be run only on the
799 * monarch processor. Once the monarch is done with MCA handling
800 * further MCA logging is enabled by clearing logs.
801 * Monarch also has the duty of sending wakeup-IPIs to pull the
802 * slave processors out of rendezvous spinloop.
808 ia64_mca_ucmc_handler(void)
810 pal_processor_state_info_t *psp = (pal_processor_state_info_t *)
811 &ia64_sal_to_os_handoff_state.proc_state_param;
812 int recover = psp->tc && !(psp->cc || psp->bc || psp->rc || psp->uc);
814 /* Get the MCA error record and log it */
815 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA);
818 * Wakeup all the processors which are spinning in the rendezvous
821 ia64_mca_wakeup_all();
824 ia64_return_to_sal_check(recover);
828 * ia64_mca_cmc_int_handler
830 * This is corrected machine check interrupt handler.
831 * Right now the logs are extracted and displayed in a well-defined
836 * client data arg ptr
837 * saved registers ptr
843 ia64_mca_cmc_int_handler(int cmc_irq, void *arg, struct pt_regs *ptregs)
845 static unsigned long cmc_history[CMC_HISTORY_LENGTH];
847 static spinlock_t cmc_history_lock = SPIN_LOCK_UNLOCKED;
849 IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
850 __FUNCTION__, cmc_irq, smp_processor_id());
852 /* SAL spec states this should run w/ interrupts enabled */
855 /* Get the CMC error record and log it */
856 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC);
858 spin_lock(&cmc_history_lock);
859 if (!cmc_polling_enabled) {
860 int i, count = 1; /* we know 1 happened now */
861 unsigned long now = jiffies;
863 for (i = 0; i < CMC_HISTORY_LENGTH; i++) {
864 if (now - cmc_history[i] <= HZ)
868 IA64_MCA_DEBUG(KERN_INFO "CMC threshold %d/%d\n", count, CMC_HISTORY_LENGTH);
869 if (count >= CMC_HISTORY_LENGTH) {
871 cmc_polling_enabled = 1;
872 spin_unlock(&cmc_history_lock);
873 schedule_task(&cmc_disable_tq);
876 * Corrected errors will still be corrected, but
877 * make sure there's a log somewhere that indicates
878 * something is generating more than we can handle.
880 printk(KERN_WARNING "WARNING: Switching to polling CMC handler; error records may be lost\n");
882 mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
884 /* lock already released, get out now */
887 cmc_history[index++] = now;
888 if (index == CMC_HISTORY_LENGTH)
892 spin_unlock(&cmc_history_lock);
896 * ia64_mca_cmc_int_caller
898 * Triggered by sw interrupt from CMC polling routine. Calls
899 * real interrupt handler and either triggers a sw interrupt
900 * on the next cpu or does cleanup at the end.
904 * client data arg ptr
905 * saved registers ptr
910 ia64_mca_cmc_int_caller(int cpe_irq, void *arg, struct pt_regs *ptregs)
912 static int start_count = -1;
915 cpuid = smp_processor_id();
917 /* If first cpu, update count */
918 if (start_count == -1)
919 start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CMC);
921 ia64_mca_cmc_int_handler(cpe_irq, arg, ptregs);
923 for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
925 if (cpuid < NR_CPUS) {
926 platform_send_ipi(cpuid, IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
928 /* If no log record, switch out of polling mode */
929 if (start_count == IA64_LOG_COUNT(SAL_INFO_TYPE_CMC)) {
931 printk(KERN_WARNING "Returning to interrupt driven CMC handler\n");
932 schedule_task(&cmc_enable_tq);
933 cmc_polling_enabled = 0;
937 mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
947 * Poll for Corrected Machine Checks (CMCs)
949 * Inputs : dummy(unused)
954 ia64_mca_cmc_poll (unsigned long dummy)
956 /* Trigger a CMC interrupt cascade */
957 platform_send_ipi(__ffs(cpu_online_map), IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
961 * ia64_mca_cpe_int_caller
963 * Triggered by sw interrupt from CPE polling routine. Calls
964 * real interrupt handler and either triggers a sw interrupt
965 * on the next cpu or does cleanup at the end.
969 * client data arg ptr
970 * saved registers ptr
975 ia64_mca_cpe_int_caller(int cpe_irq, void *arg, struct pt_regs *ptregs)
977 static int start_count = -1;
978 static int poll_time = MAX_CPE_POLL_INTERVAL;
981 cpuid = smp_processor_id();
983 /* If first cpu, update count */
984 if (start_count == -1)
985 start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CPE);
987 ia64_mca_cpe_int_handler(cpe_irq, arg, ptregs);
989 for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
991 if (cpuid < NR_CPUS) {
992 platform_send_ipi(cpuid, IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
995 * If a log was recorded, increase our polling frequency,
996 * otherwise, backoff.
998 if (start_count != IA64_LOG_COUNT(SAL_INFO_TYPE_CPE)) {
999 poll_time = max(MIN_CPE_POLL_INTERVAL, poll_time / 2);
1001 poll_time = min(MAX_CPE_POLL_INTERVAL, poll_time * 2);
1004 mod_timer(&cpe_poll_timer, jiffies + poll_time);
1011 * Poll for Corrected Platform Errors (CPEs), trigger interrupt
1012 * on first cpu, from there it will trickle through all the cpus.
1014 * Inputs : dummy(unused)
1019 ia64_mca_cpe_poll (unsigned long dummy)
1021 /* Trigger a CPE interrupt cascade */
1022 platform_send_ipi(__ffs(cpu_online_map), IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
1026 * C portion of the OS INIT handler
1028 * Called from ia64_monarch_init_handler
1030 * Inputs: pointer to pt_regs where processor info was saved.
1033 * 0 if SAL must warm boot the System
1034 * 1 if SAL must return to interrupted context using PAL_MC_RESUME
1038 ia64_init_handler (struct pt_regs *pt, struct switch_stack *sw)
1040 pal_min_state_area_t *ms;
1042 oops_in_progress = 1; /* avoid deadlock in printk, but it makes recovery dodgy */
1044 printk(KERN_INFO "Entered OS INIT handler. PSP=%lx\n",
1045 ia64_sal_to_os_handoff_state.proc_state_param);
1048 * Address of minstate area provided by PAL is physical,
1049 * uncacheable (bit 63 set). Convert to Linux virtual
1050 * address in region 6.
1052 ms = (pal_min_state_area_t *)(ia64_sal_to_os_handoff_state.pal_min_state | (6ul<<61));
1054 init_handler_platform(ms, pt, sw); /* call platform specific routines */
1058 ia64_mca_disable_cpe_polling(char *str)
1060 cpe_poll_enabled = 0;
1064 __setup("disable_cpe_poll", ia64_mca_disable_cpe_polling);
1066 static struct irqaction cmci_irqaction = {
1067 .handler = ia64_mca_cmc_int_handler,
1068 .flags = SA_INTERRUPT,
1072 static struct irqaction cmcp_irqaction = {
1073 .handler = ia64_mca_cmc_int_caller,
1074 .flags = SA_INTERRUPT,
1078 static struct irqaction mca_rdzv_irqaction = {
1079 .handler = ia64_mca_rendez_int_handler,
1080 .flags = SA_INTERRUPT,
1084 static struct irqaction mca_wkup_irqaction = {
1085 .handler = ia64_mca_wakeup_int_handler,
1086 .flags = SA_INTERRUPT,
1091 static struct irqaction mca_cpe_irqaction = {
1092 .handler = ia64_mca_cpe_int_handler,
1093 .flags = SA_INTERRUPT,
1097 static struct irqaction mca_cpep_irqaction = {
1098 .handler = ia64_mca_cpe_int_caller,
1099 .flags = SA_INTERRUPT,
1102 #endif /* CONFIG_ACPI */
1107 * Do all the system level mca specific initialization.
1109 * 1. Register spinloop and wakeup request interrupt vectors
1111 * 2. Register OS_MCA handler entry point
1113 * 3. Register OS_INIT handler entry point
1115 * 4. Initialize MCA/CMC/INIT related log buffers maintained by the OS.
1117 * Note that this initialization is done very early before some kernel
1118 * services are available.
1127 ia64_fptr_t *mon_init_ptr = (ia64_fptr_t *)ia64_monarch_init_handler;
1128 ia64_fptr_t *slave_init_ptr = (ia64_fptr_t *)ia64_slave_init_handler;
1129 ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch;
1132 struct ia64_sal_retval isrv;
1133 u64 timeout = IA64_MCA_RENDEZ_TIMEOUT; /* platform specific */
1135 IA64_MCA_DEBUG("%s: begin\n", __FUNCTION__);
1137 INIT_TQUEUE(&cmc_disable_tq, ia64_mca_cmc_vector_disable_keventd, NULL);
1138 INIT_TQUEUE(&cmc_enable_tq, ia64_mca_cmc_vector_enable_keventd, NULL);
1140 /* Clear the Rendez checkin flag for all cpus */
1141 for(i = 0 ; i < NR_CPUS; i++)
1142 ia64_mc_info.imi_rendez_checkin[i] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
1145 * Register the rendezvous spinloop and wakeup mechanism with SAL
1148 /* Register the rendezvous interrupt vector with SAL */
1150 isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_INT,
1151 SAL_MC_PARAM_MECHANISM_INT,
1152 IA64_MCA_RENDEZ_VECTOR,
1154 SAL_MC_PARAM_RZ_ALWAYS);
1159 printk(KERN_INFO "Increasing MCA rendezvous timeout from "
1160 "%ld to %ld milliseconds\n", timeout, isrv.v0);
1164 printk(KERN_ERR "Failed to register rendezvous interrupt "
1165 "with SAL (status %ld)\n", rc);
1169 /* Register the wakeup interrupt vector with SAL */
1170 isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_WAKEUP,
1171 SAL_MC_PARAM_MECHANISM_INT,
1172 IA64_MCA_WAKEUP_VECTOR,
1176 printk(KERN_ERR "Failed to register wakeup interrupt with SAL "
1177 "(status %ld)\n", rc);
1181 IA64_MCA_DEBUG("%s: registered MCA rendezvous spinloop and wakeup mech.\n", __FUNCTION__);
1183 ia64_mc_info.imi_mca_handler = ia64_tpa(mca_hldlr_ptr->fp);
1185 * XXX - disable SAL checksum by setting size to 0; should be
1186 * ia64_tpa(ia64_os_mca_dispatch_end) - ia64_tpa(ia64_os_mca_dispatch);
1188 ia64_mc_info.imi_mca_handler_size = 0;
1190 /* Register the os mca handler with SAL */
1191 if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_MCA,
1192 ia64_mc_info.imi_mca_handler,
1193 ia64_tpa(mca_hldlr_ptr->gp),
1194 ia64_mc_info.imi_mca_handler_size,
1197 printk(KERN_ERR "Failed to register OS MCA handler with SAL "
1198 "(status %ld)\n", rc);
1202 IA64_MCA_DEBUG("%s: registered OS MCA handler with SAL at 0x%lx, gp = 0x%lx\n", __FUNCTION__,
1203 ia64_mc_info.imi_mca_handler, ia64_tpa(mca_hldlr_ptr->gp));
1206 * XXX - disable SAL checksum by setting size to 0, should be
1207 * size of the actual init handler in mca_asm.S.
1209 ia64_mc_info.imi_monarch_init_handler = ia64_tpa(mon_init_ptr->fp);
1210 ia64_mc_info.imi_monarch_init_handler_size = 0;
1211 ia64_mc_info.imi_slave_init_handler = ia64_tpa(slave_init_ptr->fp);
1212 ia64_mc_info.imi_slave_init_handler_size = 0;
1214 IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __FUNCTION__,
1215 ia64_mc_info.imi_monarch_init_handler);
1217 /* Register the os init handler with SAL */
1218 if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_INIT,
1219 ia64_mc_info.imi_monarch_init_handler,
1220 ia64_tpa(ia64_get_gp()),
1221 ia64_mc_info.imi_monarch_init_handler_size,
1222 ia64_mc_info.imi_slave_init_handler,
1223 ia64_tpa(ia64_get_gp()),
1224 ia64_mc_info.imi_slave_init_handler_size)))
1226 printk(KERN_ERR "Failed to register m/s INIT handlers with SAL "
1227 "(status %ld)\n", rc);
1231 IA64_MCA_DEBUG("%s: registered OS INIT handler with SAL\n", __FUNCTION__);
1234 * Configure the CMCI/P vector and handler. Interrupts for CMC are
1235 * per-processor, so AP CMC interrupts are setup in smp_callin() (smpboot.c).
1237 register_percpu_irq(IA64_CMC_VECTOR, &cmci_irqaction);
1238 register_percpu_irq(IA64_CMCP_VECTOR, &cmcp_irqaction);
1239 ia64_mca_cmc_vector_setup(); /* Setup vector on BSP & enable */
1241 /* Setup the MCA rendezvous interrupt vector */
1242 register_percpu_irq(IA64_MCA_RENDEZ_VECTOR, &mca_rdzv_irqaction);
1244 /* Setup the MCA wakeup interrupt vector */
1245 register_percpu_irq(IA64_MCA_WAKEUP_VECTOR, &mca_wkup_irqaction);
1248 /* Setup the CPE interrupt vector */
1252 int cpev = acpi_request_vector(ACPI_INTERRUPT_CPEI);
1255 for (irq = 0; irq < NR_IRQS; ++irq)
1256 if (irq_to_vector(irq) == cpev) {
1257 desc = irq_desc(irq);
1258 desc->status |= IRQ_PER_CPU;
1259 desc->handler = &irq_type_iosapic_level;
1260 setup_irq(irq, &mca_cpe_irqaction);
1262 ia64_mca_register_cpev(cpev);
1267 /* Initialize the areas set aside by the OS to buffer the
1268 * platform/processor error states for MCA/INIT/CMC
1271 ia64_log_init(SAL_INFO_TYPE_MCA);
1272 ia64_log_init(SAL_INFO_TYPE_INIT);
1273 ia64_log_init(SAL_INFO_TYPE_CMC);
1274 ia64_log_init(SAL_INFO_TYPE_CPE);
1276 printk(KERN_INFO "MCA related initialization done\n");
1280 * ia64_mca_late_init
1282 * Opportunity to setup things that require initialization later
1283 * than ia64_mca_init. Setup a timer to poll for CPEs if the
1284 * platform doesn't support an interrupt driven mechanism.
1290 ia64_mca_late_init(void)
1292 init_timer(&cmc_poll_timer);
1293 cmc_poll_timer.function = ia64_mca_cmc_poll;
1295 /* Reset to the correct state */
1296 cmc_polling_enabled = 0;
1298 init_timer(&cpe_poll_timer);
1299 cpe_poll_timer.function = ia64_mca_cpe_poll;
1302 /* If platform doesn't support CPEI, get the timer going. */
1303 if (acpi_request_vector(ACPI_INTERRUPT_CPEI) < 0 && cpe_poll_enabled) {
1304 register_percpu_irq(IA64_CPEP_VECTOR, &mca_cpep_irqaction);
1305 ia64_mca_cpe_poll(0UL);
1312 module_init(ia64_mca_late_init);