blob: 23d54413c0061b4e18a5e2851e1e195b86c15e07 [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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 */
58#include <linux/config.h>
59#include <linux/types.h>
60#include <linux/init.h>
61#include <linux/sched.h>
62#include <linux/interrupt.h>
63#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#include <linux/smp_lock.h>
65#include <linux/bootmem.h>
66#include <linux/acpi.h>
67#include <linux/timer.h>
68#include <linux/module.h>
69#include <linux/kernel.h>
70#include <linux/smp.h>
71#include <linux/workqueue.h>
72
73#include <asm/delay.h>
Keith Owens9138d582005-11-07 11:27:13 -080074#include <asm/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#include <asm/machvec.h>
76#include <asm/meminit.h>
77#include <asm/page.h>
78#include <asm/ptrace.h>
79#include <asm/system.h>
80#include <asm/sal.h>
81#include <asm/mca.h>
82
83#include <asm/irq.h>
84#include <asm/hw_irq.h>
85
Keith Owens7f613c72005-09-11 17:22:53 +100086#include "entry.h"
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#if defined(IA64_MCA_DEBUG_INFO)
89# define IA64_MCA_DEBUG(fmt...) printk(fmt)
90#else
91# define IA64_MCA_DEBUG(fmt...)
92#endif
93
94/* Used by mca_asm.S */
Keith Owens7f613c72005-09-11 17:22:53 +100095u32 ia64_mca_serialize;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096DEFINE_PER_CPU(u64, ia64_mca_data); /* == __per_cpu_mca[smp_processor_id()] */
97DEFINE_PER_CPU(u64, ia64_mca_per_cpu_pte); /* PTE to map per-CPU area */
98DEFINE_PER_CPU(u64, ia64_mca_pal_pte); /* PTE to map PAL code */
99DEFINE_PER_CPU(u64, ia64_mca_pal_base); /* vaddr PAL code granule */
100
101unsigned long __per_cpu_mca[NR_CPUS];
102
103/* In mca_asm.S */
Keith Owens7f613c72005-09-11 17:22:53 +1000104extern void ia64_os_init_dispatch_monarch (void);
105extern void ia64_os_init_dispatch_slave (void);
106
107static int monarch_cpu = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109static ia64_mc_info_t ia64_mc_info;
110
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 CPE_HISTORY_LENGTH 5
115#define CMC_HISTORY_LENGTH 5
116
117static struct timer_list cpe_poll_timer;
118static struct timer_list cmc_poll_timer;
119/*
120 * This variable tells whether we are currently in polling mode.
121 * Start with this in the wrong state so we won't play w/ timers
122 * before the system is ready.
123 */
124static int cmc_polling_enabled = 1;
125
126/*
127 * Clearing this variable prevents CPE polling from getting activated
128 * in mca_late_init. Use it if your system doesn't provide a CPEI,
129 * but encounters problems retrieving CPE logs. This should only be
130 * necessary for debugging.
131 */
132static int cpe_poll_enabled = 1;
133
134extern void salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe);
135
136static int mca_init;
137
Keith Owens9138d582005-11-07 11:27:13 -0800138
139static void inline
140ia64_mca_spin(const char *func)
141{
142 printk(KERN_EMERG "%s: spinning here, not returning to SAL\n", func);
143 while (1)
144 cpu_relax();
145}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146/*
147 * IA64_MCA log support
148 */
149#define IA64_MAX_LOGS 2 /* Double-buffering for nested MCAs */
150#define IA64_MAX_LOG_TYPES 4 /* MCA, INIT, CMC, CPE */
151
152typedef struct ia64_state_log_s
153{
154 spinlock_t isl_lock;
155 int isl_index;
156 unsigned long isl_count;
157 ia64_err_rec_t *isl_log[IA64_MAX_LOGS]; /* need space to store header + error log */
158} ia64_state_log_t;
159
160static ia64_state_log_t ia64_state_log[IA64_MAX_LOG_TYPES];
161
162#define IA64_LOG_ALLOCATE(it, size) \
163 {ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)] = \
164 (ia64_err_rec_t *)alloc_bootmem(size); \
165 ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)] = \
166 (ia64_err_rec_t *)alloc_bootmem(size);}
167#define IA64_LOG_LOCK_INIT(it) spin_lock_init(&ia64_state_log[it].isl_lock)
168#define IA64_LOG_LOCK(it) spin_lock_irqsave(&ia64_state_log[it].isl_lock, s)
169#define IA64_LOG_UNLOCK(it) spin_unlock_irqrestore(&ia64_state_log[it].isl_lock,s)
170#define IA64_LOG_NEXT_INDEX(it) ia64_state_log[it].isl_index
171#define IA64_LOG_CURR_INDEX(it) 1 - ia64_state_log[it].isl_index
172#define IA64_LOG_INDEX_INC(it) \
173 {ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index; \
174 ia64_state_log[it].isl_count++;}
175#define IA64_LOG_INDEX_DEC(it) \
176 ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index
177#define IA64_LOG_NEXT_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)]))
178#define IA64_LOG_CURR_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)]))
179#define IA64_LOG_COUNT(it) ia64_state_log[it].isl_count
180
181/*
182 * ia64_log_init
183 * Reset the OS ia64 log buffer
184 * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
185 * Outputs : None
186 */
187static void
188ia64_log_init(int sal_info_type)
189{
190 u64 max_size = 0;
191
192 IA64_LOG_NEXT_INDEX(sal_info_type) = 0;
193 IA64_LOG_LOCK_INIT(sal_info_type);
194
195 // SAL will tell us the maximum size of any error record of this type
196 max_size = ia64_sal_get_state_info_size(sal_info_type);
197 if (!max_size)
198 /* alloc_bootmem() doesn't like zero-sized allocations! */
199 return;
200
201 // set up OS data structures to hold error info
202 IA64_LOG_ALLOCATE(sal_info_type, max_size);
203 memset(IA64_LOG_CURR_BUFFER(sal_info_type), 0, max_size);
204 memset(IA64_LOG_NEXT_BUFFER(sal_info_type), 0, max_size);
205}
206
207/*
208 * ia64_log_get
209 *
210 * Get the current MCA log from SAL and copy it into the OS log buffer.
211 *
212 * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
213 * irq_safe whether you can use printk at this point
214 * Outputs : size (total record length)
215 * *buffer (ptr to error record)
216 *
217 */
218static u64
219ia64_log_get(int sal_info_type, u8 **buffer, int irq_safe)
220{
221 sal_log_record_header_t *log_buffer;
222 u64 total_len = 0;
223 int s;
224
225 IA64_LOG_LOCK(sal_info_type);
226
227 /* Get the process state information */
228 log_buffer = IA64_LOG_NEXT_BUFFER(sal_info_type);
229
230 total_len = ia64_sal_get_state_info(sal_info_type, (u64 *)log_buffer);
231
232 if (total_len) {
233 IA64_LOG_INDEX_INC(sal_info_type);
234 IA64_LOG_UNLOCK(sal_info_type);
235 if (irq_safe) {
236 IA64_MCA_DEBUG("%s: SAL error record type %d retrieved. "
237 "Record length = %ld\n", __FUNCTION__, sal_info_type, total_len);
238 }
239 *buffer = (u8 *) log_buffer;
240 return total_len;
241 } else {
242 IA64_LOG_UNLOCK(sal_info_type);
243 return 0;
244 }
245}
246
247/*
248 * ia64_mca_log_sal_error_record
249 *
250 * This function retrieves a specified error record type from SAL
251 * and wakes up any processes waiting for error records.
252 *
Keith Owens7f613c72005-09-11 17:22:53 +1000253 * Inputs : sal_info_type (Type of error record MCA/CMC/CPE)
254 * FIXME: remove MCA and irq_safe.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 */
256static void
257ia64_mca_log_sal_error_record(int sal_info_type)
258{
259 u8 *buffer;
260 sal_log_record_header_t *rh;
261 u64 size;
Keith Owens7f613c72005-09-11 17:22:53 +1000262 int irq_safe = sal_info_type != SAL_INFO_TYPE_MCA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#ifdef IA64_MCA_DEBUG_INFO
264 static const char * const rec_name[] = { "MCA", "INIT", "CMC", "CPE" };
265#endif
266
267 size = ia64_log_get(sal_info_type, &buffer, irq_safe);
268 if (!size)
269 return;
270
271 salinfo_log_wakeup(sal_info_type, buffer, size, irq_safe);
272
273 if (irq_safe)
274 IA64_MCA_DEBUG("CPU %d: SAL log contains %s error record\n",
275 smp_processor_id(),
276 sal_info_type < ARRAY_SIZE(rec_name) ? rec_name[sal_info_type] : "UNKNOWN");
277
278 /* Clear logs from corrected errors in case there's no user-level logger */
279 rh = (sal_log_record_header_t *)buffer;
280 if (rh->severity == sal_log_severity_corrected)
281 ia64_sal_clear_state_info(sal_info_type);
282}
283
284/*
285 * platform dependent error handling
286 */
287#ifndef PLATFORM_MCA_HANDLERS
288
289#ifdef CONFIG_ACPI
290
Ashok Raj55e59c52005-03-31 22:51:10 -0500291int cpe_vector = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293static irqreturn_t
294ia64_mca_cpe_int_handler (int cpe_irq, void *arg, struct pt_regs *ptregs)
295{
296 static unsigned long cpe_history[CPE_HISTORY_LENGTH];
297 static int index;
298 static DEFINE_SPINLOCK(cpe_history_lock);
299
300 IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
301 __FUNCTION__, cpe_irq, smp_processor_id());
302
303 /* SAL spec states this should run w/ interrupts enabled */
304 local_irq_enable();
305
306 /* Get the CPE error record and log it */
307 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE);
308
309 spin_lock(&cpe_history_lock);
310 if (!cpe_poll_enabled && cpe_vector >= 0) {
311
312 int i, count = 1; /* we know 1 happened now */
313 unsigned long now = jiffies;
314
315 for (i = 0; i < CPE_HISTORY_LENGTH; i++) {
316 if (now - cpe_history[i] <= HZ)
317 count++;
318 }
319
320 IA64_MCA_DEBUG(KERN_INFO "CPE threshold %d/%d\n", count, CPE_HISTORY_LENGTH);
321 if (count >= CPE_HISTORY_LENGTH) {
322
323 cpe_poll_enabled = 1;
324 spin_unlock(&cpe_history_lock);
325 disable_irq_nosync(local_vector_to_irq(IA64_CPE_VECTOR));
326
327 /*
328 * Corrected errors will still be corrected, but
329 * make sure there's a log somewhere that indicates
330 * something is generating more than we can handle.
331 */
332 printk(KERN_WARNING "WARNING: Switching to polling CPE handler; error records may be lost\n");
333
334 mod_timer(&cpe_poll_timer, jiffies + MIN_CPE_POLL_INTERVAL);
335
336 /* lock already released, get out now */
337 return IRQ_HANDLED;
338 } else {
339 cpe_history[index++] = now;
340 if (index == CPE_HISTORY_LENGTH)
341 index = 0;
342 }
343 }
344 spin_unlock(&cpe_history_lock);
345 return IRQ_HANDLED;
346}
347
348#endif /* CONFIG_ACPI */
349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350#ifdef CONFIG_ACPI
351/*
352 * ia64_mca_register_cpev
353 *
354 * Register the corrected platform error vector with SAL.
355 *
356 * Inputs
357 * cpev Corrected Platform Error Vector number
358 *
359 * Outputs
360 * None
361 */
362static void
363ia64_mca_register_cpev (int cpev)
364{
365 /* Register the CPE interrupt vector with SAL */
366 struct ia64_sal_retval isrv;
367
368 isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_CPE_INT, SAL_MC_PARAM_MECHANISM_INT, cpev, 0, 0);
369 if (isrv.status) {
370 printk(KERN_ERR "Failed to register Corrected Platform "
371 "Error interrupt vector with SAL (status %ld)\n", isrv.status);
372 return;
373 }
374
375 IA64_MCA_DEBUG("%s: corrected platform error "
376 "vector %#x registered\n", __FUNCTION__, cpev);
377}
378#endif /* CONFIG_ACPI */
379
380#endif /* PLATFORM_MCA_HANDLERS */
381
382/*
383 * ia64_mca_cmc_vector_setup
384 *
385 * Setup the corrected machine check vector register in the processor.
386 * (The interrupt is masked on boot. ia64_mca_late_init unmask this.)
387 * This function is invoked on a per-processor basis.
388 *
389 * Inputs
390 * None
391 *
392 * Outputs
393 * None
394 */
395void
396ia64_mca_cmc_vector_setup (void)
397{
398 cmcv_reg_t cmcv;
399
400 cmcv.cmcv_regval = 0;
401 cmcv.cmcv_mask = 1; /* Mask/disable interrupt at first */
402 cmcv.cmcv_vector = IA64_CMC_VECTOR;
403 ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
404
405 IA64_MCA_DEBUG("%s: CPU %d corrected "
406 "machine check vector %#x registered.\n",
407 __FUNCTION__, smp_processor_id(), IA64_CMC_VECTOR);
408
409 IA64_MCA_DEBUG("%s: CPU %d CMCV = %#016lx\n",
410 __FUNCTION__, smp_processor_id(), ia64_getreg(_IA64_REG_CR_CMCV));
411}
412
413/*
414 * ia64_mca_cmc_vector_disable
415 *
416 * Mask the corrected machine check vector register in the processor.
417 * This function is invoked on a per-processor basis.
418 *
419 * Inputs
420 * dummy(unused)
421 *
422 * Outputs
423 * None
424 */
425static void
426ia64_mca_cmc_vector_disable (void *dummy)
427{
428 cmcv_reg_t cmcv;
429
430 cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV);
431
432 cmcv.cmcv_mask = 1; /* Mask/disable interrupt */
433 ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
434
435 IA64_MCA_DEBUG("%s: CPU %d corrected "
436 "machine check vector %#x disabled.\n",
437 __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector);
438}
439
440/*
441 * ia64_mca_cmc_vector_enable
442 *
443 * Unmask the corrected machine check vector register in the processor.
444 * This function is invoked on a per-processor basis.
445 *
446 * Inputs
447 * dummy(unused)
448 *
449 * Outputs
450 * None
451 */
452static void
453ia64_mca_cmc_vector_enable (void *dummy)
454{
455 cmcv_reg_t cmcv;
456
457 cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV);
458
459 cmcv.cmcv_mask = 0; /* Unmask/enable interrupt */
460 ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
461
462 IA64_MCA_DEBUG("%s: CPU %d corrected "
463 "machine check vector %#x enabled.\n",
464 __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector);
465}
466
467/*
468 * ia64_mca_cmc_vector_disable_keventd
469 *
470 * Called via keventd (smp_call_function() is not safe in interrupt context) to
471 * disable the cmc interrupt vector.
472 */
473static void
474ia64_mca_cmc_vector_disable_keventd(void *unused)
475{
476 on_each_cpu(ia64_mca_cmc_vector_disable, NULL, 1, 0);
477}
478
479/*
480 * ia64_mca_cmc_vector_enable_keventd
481 *
482 * Called via keventd (smp_call_function() is not safe in interrupt context) to
483 * enable the cmc interrupt vector.
484 */
485static void
486ia64_mca_cmc_vector_enable_keventd(void *unused)
487{
488 on_each_cpu(ia64_mca_cmc_vector_enable, NULL, 1, 0);
489}
490
491/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 * ia64_mca_wakeup
493 *
494 * Send an inter-cpu interrupt to wake-up a particular cpu
495 * and mark that cpu to be out of rendez.
496 *
497 * Inputs : cpuid
498 * Outputs : None
499 */
500static void
501ia64_mca_wakeup(int cpu)
502{
503 platform_send_ipi(cpu, IA64_MCA_WAKEUP_VECTOR, IA64_IPI_DM_INT, 0);
504 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
505
506}
507
508/*
509 * ia64_mca_wakeup_all
510 *
511 * Wakeup all the cpus which have rendez'ed previously.
512 *
513 * Inputs : None
514 * Outputs : None
515 */
516static void
517ia64_mca_wakeup_all(void)
518{
519 int cpu;
520
521 /* Clear the Rendez checkin flag for all cpus */
hawkes@sgi.comddf6d0a2005-10-13 12:01:18 -0700522 for_each_online_cpu(cpu) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 if (ia64_mc_info.imi_rendez_checkin[cpu] == IA64_MCA_RENDEZ_CHECKIN_DONE)
524 ia64_mca_wakeup(cpu);
525 }
526
527}
528
529/*
530 * ia64_mca_rendez_interrupt_handler
531 *
532 * This is handler used to put slave processors into spinloop
533 * while the monarch processor does the mca handling and later
534 * wake each slave up once the monarch is done.
535 *
536 * Inputs : None
537 * Outputs : None
538 */
539static irqreturn_t
Keith Owens9138d582005-11-07 11:27:13 -0800540ia64_mca_rendez_int_handler(int rendez_irq, void *arg, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541{
542 unsigned long flags;
543 int cpu = smp_processor_id();
544
545 /* Mask all interrupts */
546 local_irq_save(flags);
Keith Owens9138d582005-11-07 11:27:13 -0800547 if (notify_die(DIE_MCA_RENDZVOUS_ENTER, "MCA", regs, 0, 0, 0)
548 == NOTIFY_STOP)
549 ia64_mca_spin(__FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_DONE;
552 /* Register with the SAL monarch that the slave has
553 * reached SAL
554 */
555 ia64_sal_mc_rendez();
556
Keith Owens9138d582005-11-07 11:27:13 -0800557 if (notify_die(DIE_MCA_RENDZVOUS_PROCESS, "MCA", regs, 0, 0, 0)
558 == NOTIFY_STOP)
559 ia64_mca_spin(__FUNCTION__);
560
Keith Owens7f613c72005-09-11 17:22:53 +1000561 /* Wait for the monarch cpu to exit. */
562 while (monarch_cpu != -1)
563 cpu_relax(); /* spin until monarch leaves */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
Keith Owens9138d582005-11-07 11:27:13 -0800565 if (notify_die(DIE_MCA_RENDZVOUS_LEAVE, "MCA", regs, 0, 0, 0)
566 == NOTIFY_STOP)
567 ia64_mca_spin(__FUNCTION__);
568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 /* Enable all interrupts */
570 local_irq_restore(flags);
571 return IRQ_HANDLED;
572}
573
574/*
575 * ia64_mca_wakeup_int_handler
576 *
577 * The interrupt handler for processing the inter-cpu interrupt to the
578 * slave cpu which was spinning in the rendez loop.
579 * Since this spinning is done by turning off the interrupts and
580 * polling on the wakeup-interrupt bit in the IRR, there is
581 * nothing useful to be done in the handler.
582 *
583 * Inputs : wakeup_irq (Wakeup-interrupt bit)
584 * arg (Interrupt handler specific argument)
585 * ptregs (Exception frame at the time of the interrupt)
586 * Outputs : None
587 *
588 */
589static irqreturn_t
590ia64_mca_wakeup_int_handler(int wakeup_irq, void *arg, struct pt_regs *ptregs)
591{
592 return IRQ_HANDLED;
593}
594
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595/* Function pointer for extra MCA recovery */
596int (*ia64_mca_ucmc_extension)
Keith Owens7f613c72005-09-11 17:22:53 +1000597 (void*,struct ia64_sal_os_state*)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 = NULL;
599
600int
Keith Owens7f613c72005-09-11 17:22:53 +1000601ia64_reg_MCA_extension(int (*fn)(void *, struct ia64_sal_os_state *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
603 if (ia64_mca_ucmc_extension)
604 return 1;
605
606 ia64_mca_ucmc_extension = fn;
607 return 0;
608}
609
610void
611ia64_unreg_MCA_extension(void)
612{
613 if (ia64_mca_ucmc_extension)
614 ia64_mca_ucmc_extension = NULL;
615}
616
617EXPORT_SYMBOL(ia64_reg_MCA_extension);
618EXPORT_SYMBOL(ia64_unreg_MCA_extension);
619
Keith Owens7f613c72005-09-11 17:22:53 +1000620
621static inline void
622copy_reg(const u64 *fr, u64 fnat, u64 *tr, u64 *tnat)
623{
624 u64 fslot, tslot, nat;
625 *tr = *fr;
626 fslot = ((unsigned long)fr >> 3) & 63;
627 tslot = ((unsigned long)tr >> 3) & 63;
628 *tnat &= ~(1UL << tslot);
629 nat = (fnat >> fslot) & 1;
630 *tnat |= (nat << tslot);
631}
632
633/* On entry to this routine, we are running on the per cpu stack, see
634 * mca_asm.h. The original stack has not been touched by this event. Some of
635 * the original stack's registers will be in the RBS on this stack. This stack
636 * also contains a partial pt_regs and switch_stack, the rest of the data is in
637 * PAL minstate.
638 *
639 * The first thing to do is modify the original stack to look like a blocked
640 * task so we can run backtrace on the original task. Also mark the per cpu
641 * stack as current to ensure that we use the correct task state, it also means
642 * that we can do backtrace on the MCA/INIT handler code itself.
643 */
644
645static task_t *
646ia64_mca_modify_original_stack(struct pt_regs *regs,
647 const struct switch_stack *sw,
648 struct ia64_sal_os_state *sos,
649 const char *type)
650{
651 char *p, comm[sizeof(current->comm)];
652 ia64_va va;
653 extern char ia64_leave_kernel[]; /* Need asm address, not function descriptor */
654 const pal_min_state_area_t *ms = sos->pal_min_state;
655 task_t *previous_current;
656 struct pt_regs *old_regs;
657 struct switch_stack *old_sw;
658 unsigned size = sizeof(struct pt_regs) +
659 sizeof(struct switch_stack) + 16;
660 u64 *old_bspstore, *old_bsp;
661 u64 *new_bspstore, *new_bsp;
662 u64 old_unat, old_rnat, new_rnat, nat;
663 u64 slots, loadrs = regs->loadrs;
664 u64 r12 = ms->pmsa_gr[12-1], r13 = ms->pmsa_gr[13-1];
665 u64 ar_bspstore = regs->ar_bspstore;
666 u64 ar_bsp = regs->ar_bspstore + (loadrs >> 16);
667 const u64 *bank;
668 const char *msg;
669 int cpu = smp_processor_id();
670
671 previous_current = curr_task(cpu);
672 set_curr_task(cpu, current);
673 if ((p = strchr(current->comm, ' ')))
674 *p = '\0';
675
676 /* Best effort attempt to cope with MCA/INIT delivered while in
677 * physical mode.
678 */
679 regs->cr_ipsr = ms->pmsa_ipsr;
680 if (ia64_psr(regs)->dt == 0) {
681 va.l = r12;
682 if (va.f.reg == 0) {
683 va.f.reg = 7;
684 r12 = va.l;
685 }
686 va.l = r13;
687 if (va.f.reg == 0) {
688 va.f.reg = 7;
689 r13 = va.l;
690 }
691 }
692 if (ia64_psr(regs)->rt == 0) {
693 va.l = ar_bspstore;
694 if (va.f.reg == 0) {
695 va.f.reg = 7;
696 ar_bspstore = va.l;
697 }
698 va.l = ar_bsp;
699 if (va.f.reg == 0) {
700 va.f.reg = 7;
701 ar_bsp = va.l;
702 }
703 }
704
705 /* mca_asm.S ia64_old_stack() cannot assume that the dirty registers
706 * have been copied to the old stack, the old stack may fail the
707 * validation tests below. So ia64_old_stack() must restore the dirty
708 * registers from the new stack. The old and new bspstore probably
709 * have different alignments, so loadrs calculated on the old bsp
710 * cannot be used to restore from the new bsp. Calculate a suitable
711 * loadrs for the new stack and save it in the new pt_regs, where
712 * ia64_old_stack() can get it.
713 */
714 old_bspstore = (u64 *)ar_bspstore;
715 old_bsp = (u64 *)ar_bsp;
716 slots = ia64_rse_num_regs(old_bspstore, old_bsp);
717 new_bspstore = (u64 *)((u64)current + IA64_RBS_OFFSET);
718 new_bsp = ia64_rse_skip_regs(new_bspstore, slots);
719 regs->loadrs = (new_bsp - new_bspstore) * 8 << 16;
720
721 /* Verify the previous stack state before we change it */
722 if (user_mode(regs)) {
723 msg = "occurred in user space";
724 goto no_mod;
725 }
726 if (r13 != sos->prev_IA64_KR_CURRENT) {
727 msg = "inconsistent previous current and r13";
728 goto no_mod;
729 }
730 if ((r12 - r13) >= KERNEL_STACK_SIZE) {
731 msg = "inconsistent r12 and r13";
732 goto no_mod;
733 }
734 if ((ar_bspstore - r13) >= KERNEL_STACK_SIZE) {
735 msg = "inconsistent ar.bspstore and r13";
736 goto no_mod;
737 }
738 va.p = old_bspstore;
739 if (va.f.reg < 5) {
740 msg = "old_bspstore is in the wrong region";
741 goto no_mod;
742 }
743 if ((ar_bsp - r13) >= KERNEL_STACK_SIZE) {
744 msg = "inconsistent ar.bsp and r13";
745 goto no_mod;
746 }
747 size += (ia64_rse_skip_regs(old_bspstore, slots) - old_bspstore) * 8;
748 if (ar_bspstore + size > r12) {
749 msg = "no room for blocked state";
750 goto no_mod;
751 }
752
753 /* Change the comm field on the MCA/INT task to include the pid that
754 * was interrupted, it makes for easier debugging. If that pid was 0
755 * (swapper or nested MCA/INIT) then use the start of the previous comm
756 * field suffixed with its cpu.
757 */
758 if (previous_current->pid)
759 snprintf(comm, sizeof(comm), "%s %d",
760 current->comm, previous_current->pid);
761 else {
762 int l;
763 if ((p = strchr(previous_current->comm, ' ')))
764 l = p - previous_current->comm;
765 else
766 l = strlen(previous_current->comm);
767 snprintf(comm, sizeof(comm), "%s %*s %d",
768 current->comm, l, previous_current->comm,
Al Viroab035912006-01-12 01:06:05 -0800769 task_thread_info(previous_current)->cpu);
Keith Owens7f613c72005-09-11 17:22:53 +1000770 }
771 memcpy(current->comm, comm, sizeof(current->comm));
772
773 /* Make the original task look blocked. First stack a struct pt_regs,
774 * describing the state at the time of interrupt. mca_asm.S built a
775 * partial pt_regs, copy it and fill in the blanks using minstate.
776 */
777 p = (char *)r12 - sizeof(*regs);
778 old_regs = (struct pt_regs *)p;
779 memcpy(old_regs, regs, sizeof(*regs));
780 /* If ipsr.ic then use pmsa_{iip,ipsr,ifs}, else use
781 * pmsa_{xip,xpsr,xfs}
782 */
783 if (ia64_psr(regs)->ic) {
784 old_regs->cr_iip = ms->pmsa_iip;
785 old_regs->cr_ipsr = ms->pmsa_ipsr;
786 old_regs->cr_ifs = ms->pmsa_ifs;
787 } else {
788 old_regs->cr_iip = ms->pmsa_xip;
789 old_regs->cr_ipsr = ms->pmsa_xpsr;
790 old_regs->cr_ifs = ms->pmsa_xfs;
791 }
792 old_regs->pr = ms->pmsa_pr;
793 old_regs->b0 = ms->pmsa_br0;
794 old_regs->loadrs = loadrs;
795 old_regs->ar_rsc = ms->pmsa_rsc;
796 old_unat = old_regs->ar_unat;
797 copy_reg(&ms->pmsa_gr[1-1], ms->pmsa_nat_bits, &old_regs->r1, &old_unat);
798 copy_reg(&ms->pmsa_gr[2-1], ms->pmsa_nat_bits, &old_regs->r2, &old_unat);
799 copy_reg(&ms->pmsa_gr[3-1], ms->pmsa_nat_bits, &old_regs->r3, &old_unat);
800 copy_reg(&ms->pmsa_gr[8-1], ms->pmsa_nat_bits, &old_regs->r8, &old_unat);
801 copy_reg(&ms->pmsa_gr[9-1], ms->pmsa_nat_bits, &old_regs->r9, &old_unat);
802 copy_reg(&ms->pmsa_gr[10-1], ms->pmsa_nat_bits, &old_regs->r10, &old_unat);
803 copy_reg(&ms->pmsa_gr[11-1], ms->pmsa_nat_bits, &old_regs->r11, &old_unat);
804 copy_reg(&ms->pmsa_gr[12-1], ms->pmsa_nat_bits, &old_regs->r12, &old_unat);
805 copy_reg(&ms->pmsa_gr[13-1], ms->pmsa_nat_bits, &old_regs->r13, &old_unat);
806 copy_reg(&ms->pmsa_gr[14-1], ms->pmsa_nat_bits, &old_regs->r14, &old_unat);
807 copy_reg(&ms->pmsa_gr[15-1], ms->pmsa_nat_bits, &old_regs->r15, &old_unat);
808 if (ia64_psr(old_regs)->bn)
809 bank = ms->pmsa_bank1_gr;
810 else
811 bank = ms->pmsa_bank0_gr;
812 copy_reg(&bank[16-16], ms->pmsa_nat_bits, &old_regs->r16, &old_unat);
813 copy_reg(&bank[17-16], ms->pmsa_nat_bits, &old_regs->r17, &old_unat);
814 copy_reg(&bank[18-16], ms->pmsa_nat_bits, &old_regs->r18, &old_unat);
815 copy_reg(&bank[19-16], ms->pmsa_nat_bits, &old_regs->r19, &old_unat);
816 copy_reg(&bank[20-16], ms->pmsa_nat_bits, &old_regs->r20, &old_unat);
817 copy_reg(&bank[21-16], ms->pmsa_nat_bits, &old_regs->r21, &old_unat);
818 copy_reg(&bank[22-16], ms->pmsa_nat_bits, &old_regs->r22, &old_unat);
819 copy_reg(&bank[23-16], ms->pmsa_nat_bits, &old_regs->r23, &old_unat);
820 copy_reg(&bank[24-16], ms->pmsa_nat_bits, &old_regs->r24, &old_unat);
821 copy_reg(&bank[25-16], ms->pmsa_nat_bits, &old_regs->r25, &old_unat);
822 copy_reg(&bank[26-16], ms->pmsa_nat_bits, &old_regs->r26, &old_unat);
823 copy_reg(&bank[27-16], ms->pmsa_nat_bits, &old_regs->r27, &old_unat);
824 copy_reg(&bank[28-16], ms->pmsa_nat_bits, &old_regs->r28, &old_unat);
825 copy_reg(&bank[29-16], ms->pmsa_nat_bits, &old_regs->r29, &old_unat);
826 copy_reg(&bank[30-16], ms->pmsa_nat_bits, &old_regs->r30, &old_unat);
827 copy_reg(&bank[31-16], ms->pmsa_nat_bits, &old_regs->r31, &old_unat);
828
829 /* Next stack a struct switch_stack. mca_asm.S built a partial
830 * switch_stack, copy it and fill in the blanks using pt_regs and
831 * minstate.
832 *
833 * In the synthesized switch_stack, b0 points to ia64_leave_kernel,
834 * ar.pfs is set to 0.
835 *
836 * unwind.c::unw_unwind() does special processing for interrupt frames.
837 * It checks if the PRED_NON_SYSCALL predicate is set, if the predicate
838 * is clear then unw_unwind() does _not_ adjust bsp over pt_regs. Not
839 * that this is documented, of course. Set PRED_NON_SYSCALL in the
840 * switch_stack on the original stack so it will unwind correctly when
841 * unwind.c reads pt_regs.
842 *
843 * thread.ksp is updated to point to the synthesized switch_stack.
844 */
845 p -= sizeof(struct switch_stack);
846 old_sw = (struct switch_stack *)p;
847 memcpy(old_sw, sw, sizeof(*sw));
848 old_sw->caller_unat = old_unat;
849 old_sw->ar_fpsr = old_regs->ar_fpsr;
850 copy_reg(&ms->pmsa_gr[4-1], ms->pmsa_nat_bits, &old_sw->r4, &old_unat);
851 copy_reg(&ms->pmsa_gr[5-1], ms->pmsa_nat_bits, &old_sw->r5, &old_unat);
852 copy_reg(&ms->pmsa_gr[6-1], ms->pmsa_nat_bits, &old_sw->r6, &old_unat);
853 copy_reg(&ms->pmsa_gr[7-1], ms->pmsa_nat_bits, &old_sw->r7, &old_unat);
854 old_sw->b0 = (u64)ia64_leave_kernel;
855 old_sw->b1 = ms->pmsa_br1;
856 old_sw->ar_pfs = 0;
857 old_sw->ar_unat = old_unat;
858 old_sw->pr = old_regs->pr | (1UL << PRED_NON_SYSCALL);
859 previous_current->thread.ksp = (u64)p - 16;
860
861 /* Finally copy the original stack's registers back to its RBS.
862 * Registers from ar.bspstore through ar.bsp at the time of the event
863 * are in the current RBS, copy them back to the original stack. The
864 * copy must be done register by register because the original bspstore
865 * and the current one have different alignments, so the saved RNAT
866 * data occurs at different places.
867 *
868 * mca_asm does cover, so the old_bsp already includes all registers at
869 * the time of MCA/INIT. It also does flushrs, so all registers before
870 * this function have been written to backing store on the MCA/INIT
871 * stack.
872 */
873 new_rnat = ia64_get_rnat(ia64_rse_rnat_addr(new_bspstore));
874 old_rnat = regs->ar_rnat;
875 while (slots--) {
876 if (ia64_rse_is_rnat_slot(new_bspstore)) {
877 new_rnat = ia64_get_rnat(new_bspstore++);
878 }
879 if (ia64_rse_is_rnat_slot(old_bspstore)) {
880 *old_bspstore++ = old_rnat;
881 old_rnat = 0;
882 }
883 nat = (new_rnat >> ia64_rse_slot_num(new_bspstore)) & 1UL;
884 old_rnat &= ~(1UL << ia64_rse_slot_num(old_bspstore));
885 old_rnat |= (nat << ia64_rse_slot_num(old_bspstore));
886 *old_bspstore++ = *new_bspstore++;
887 }
888 old_sw->ar_bspstore = (unsigned long)old_bspstore;
889 old_sw->ar_rnat = old_rnat;
890
891 sos->prev_task = previous_current;
892 return previous_current;
893
894no_mod:
895 printk(KERN_INFO "cpu %d, %s %s, original stack not modified\n",
896 smp_processor_id(), type, msg);
897 return previous_current;
898}
899
900/* The monarch/slave interaction is based on monarch_cpu and requires that all
901 * slaves have entered rendezvous before the monarch leaves. If any cpu has
902 * not entered rendezvous yet then wait a bit. The assumption is that any
903 * slave that has not rendezvoused after a reasonable time is never going to do
904 * so. In this context, slave includes cpus that respond to the MCA rendezvous
905 * interrupt, as well as cpus that receive the INIT slave event.
906 */
907
908static void
909ia64_wait_for_slaves(int monarch)
910{
Keith Owens9336b082006-02-08 13:40:59 +1100911 int c, wait = 0, missing = 0;
Keith Owens7f613c72005-09-11 17:22:53 +1000912 for_each_online_cpu(c) {
913 if (c == monarch)
914 continue;
915 if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) {
916 udelay(1000); /* short wait first */
917 wait = 1;
918 break;
919 }
920 }
921 if (!wait)
Keith Owens9336b082006-02-08 13:40:59 +1100922 goto all_in;
Keith Owens7f613c72005-09-11 17:22:53 +1000923 for_each_online_cpu(c) {
924 if (c == monarch)
925 continue;
926 if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) {
927 udelay(5*1000000); /* wait 5 seconds for slaves (arbitrary) */
Keith Owens9336b082006-02-08 13:40:59 +1100928 if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE)
929 missing = 1;
Keith Owens7f613c72005-09-11 17:22:53 +1000930 break;
931 }
932 }
Keith Owens9336b082006-02-08 13:40:59 +1100933 if (!missing)
934 goto all_in;
935 printk(KERN_INFO "OS MCA slave did not rendezvous on cpu");
936 for_each_online_cpu(c) {
937 if (c == monarch)
938 continue;
939 if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE)
940 printk(" %d", c);
941 }
942 printk("\n");
943 return;
944
945all_in:
946 printk(KERN_INFO "All OS MCA slaves have reached rendezvous\n");
947 return;
Keith Owens7f613c72005-09-11 17:22:53 +1000948}
949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950/*
Keith Owens7f613c72005-09-11 17:22:53 +1000951 * ia64_mca_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 *
953 * This is uncorrectable machine check handler called from OS_MCA
954 * dispatch code which is in turn called from SAL_CHECK().
955 * This is the place where the core of OS MCA handling is done.
956 * Right now the logs are extracted and displayed in a well-defined
957 * format. This handler code is supposed to be run only on the
958 * monarch processor. Once the monarch is done with MCA handling
959 * further MCA logging is enabled by clearing logs.
960 * Monarch also has the duty of sending wakeup-IPIs to pull the
961 * slave processors out of rendezvous spinloop.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 */
963void
Keith Owens7f613c72005-09-11 17:22:53 +1000964ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw,
965 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
967 pal_processor_state_info_t *psp = (pal_processor_state_info_t *)
Keith Owens7f613c72005-09-11 17:22:53 +1000968 &sos->proc_state_param;
969 int recover, cpu = smp_processor_id();
970 task_t *previous_current;
971
972 oops_in_progress = 1; /* FIXME: make printk NMI/MCA/INIT safe */
Keith Owens9336b082006-02-08 13:40:59 +1100973 console_loglevel = 15; /* make sure printks make it to console */
974 printk(KERN_INFO "Entered OS MCA handler. PSP=%lx cpu=%d monarch=%ld\n",
975 sos->proc_state_param, cpu, sos->monarch);
976
Keith Owens7f613c72005-09-11 17:22:53 +1000977 previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "MCA");
978 monarch_cpu = cpu;
Keith Owens9138d582005-11-07 11:27:13 -0800979 if (notify_die(DIE_MCA_MONARCH_ENTER, "MCA", regs, 0, 0, 0)
980 == NOTIFY_STOP)
981 ia64_mca_spin(__FUNCTION__);
Keith Owens7f613c72005-09-11 17:22:53 +1000982 ia64_wait_for_slaves(cpu);
983
984 /* Wakeup all the processors which are spinning in the rendezvous loop.
985 * They will leave SAL, then spin in the OS with interrupts disabled
986 * until this monarch cpu leaves the MCA handler. That gets control
987 * back to the OS so we can backtrace the other cpus, backtrace when
988 * spinning in SAL does not work.
989 */
990 ia64_mca_wakeup_all();
Keith Owens9138d582005-11-07 11:27:13 -0800991 if (notify_die(DIE_MCA_MONARCH_PROCESS, "MCA", regs, 0, 0, 0)
992 == NOTIFY_STOP)
993 ia64_mca_spin(__FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
995 /* Get the MCA error record and log it */
996 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA);
997
998 /* TLB error is only exist in this SAL error record */
999 recover = (psp->tc && !(psp->cc || psp->bc || psp->rc || psp->uc))
1000 /* other error recovery */
Keith Owens7f613c72005-09-11 17:22:53 +10001001 || (ia64_mca_ucmc_extension
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 && ia64_mca_ucmc_extension(
1003 IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA),
Keith Owens7f613c72005-09-11 17:22:53 +10001004 sos));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
1006 if (recover) {
1007 sal_log_record_header_t *rh = IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA);
1008 rh->severity = sal_log_severity_corrected;
1009 ia64_sal_clear_state_info(SAL_INFO_TYPE_MCA);
Keith Owens7f613c72005-09-11 17:22:53 +10001010 sos->os_status = IA64_MCA_CORRECTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
Keith Owens9138d582005-11-07 11:27:13 -08001012 if (notify_die(DIE_MCA_MONARCH_LEAVE, "MCA", regs, 0, 0, recover)
1013 == NOTIFY_STOP)
1014 ia64_mca_spin(__FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
Keith Owens7f613c72005-09-11 17:22:53 +10001016 set_curr_task(cpu, previous_current);
1017 monarch_cpu = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018}
1019
1020static DECLARE_WORK(cmc_disable_work, ia64_mca_cmc_vector_disable_keventd, NULL);
1021static DECLARE_WORK(cmc_enable_work, ia64_mca_cmc_vector_enable_keventd, NULL);
1022
1023/*
1024 * ia64_mca_cmc_int_handler
1025 *
1026 * This is corrected machine check interrupt handler.
1027 * Right now the logs are extracted and displayed in a well-defined
1028 * format.
1029 *
1030 * Inputs
1031 * interrupt number
1032 * client data arg ptr
1033 * saved registers ptr
1034 *
1035 * Outputs
1036 * None
1037 */
1038static irqreturn_t
1039ia64_mca_cmc_int_handler(int cmc_irq, void *arg, struct pt_regs *ptregs)
1040{
1041 static unsigned long cmc_history[CMC_HISTORY_LENGTH];
1042 static int index;
1043 static DEFINE_SPINLOCK(cmc_history_lock);
1044
1045 IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
1046 __FUNCTION__, cmc_irq, smp_processor_id());
1047
1048 /* SAL spec states this should run w/ interrupts enabled */
1049 local_irq_enable();
1050
1051 /* Get the CMC error record and log it */
1052 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC);
1053
1054 spin_lock(&cmc_history_lock);
1055 if (!cmc_polling_enabled) {
1056 int i, count = 1; /* we know 1 happened now */
1057 unsigned long now = jiffies;
1058
1059 for (i = 0; i < CMC_HISTORY_LENGTH; i++) {
1060 if (now - cmc_history[i] <= HZ)
1061 count++;
1062 }
1063
1064 IA64_MCA_DEBUG(KERN_INFO "CMC threshold %d/%d\n", count, CMC_HISTORY_LENGTH);
1065 if (count >= CMC_HISTORY_LENGTH) {
1066
1067 cmc_polling_enabled = 1;
1068 spin_unlock(&cmc_history_lock);
Bryan Sutula76e677e2005-10-05 11:02:06 -06001069 /* If we're being hit with CMC interrupts, we won't
1070 * ever execute the schedule_work() below. Need to
1071 * disable CMC interrupts on this processor now.
1072 */
1073 ia64_mca_cmc_vector_disable(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 schedule_work(&cmc_disable_work);
1075
1076 /*
1077 * Corrected errors will still be corrected, but
1078 * make sure there's a log somewhere that indicates
1079 * something is generating more than we can handle.
1080 */
1081 printk(KERN_WARNING "WARNING: Switching to polling CMC handler; error records may be lost\n");
1082
1083 mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
1084
1085 /* lock already released, get out now */
1086 return IRQ_HANDLED;
1087 } else {
1088 cmc_history[index++] = now;
1089 if (index == CMC_HISTORY_LENGTH)
1090 index = 0;
1091 }
1092 }
1093 spin_unlock(&cmc_history_lock);
1094 return IRQ_HANDLED;
1095}
1096
1097/*
1098 * ia64_mca_cmc_int_caller
1099 *
1100 * Triggered by sw interrupt from CMC polling routine. Calls
1101 * real interrupt handler and either triggers a sw interrupt
1102 * on the next cpu or does cleanup at the end.
1103 *
1104 * Inputs
1105 * interrupt number
1106 * client data arg ptr
1107 * saved registers ptr
1108 * Outputs
1109 * handled
1110 */
1111static irqreturn_t
1112ia64_mca_cmc_int_caller(int cmc_irq, void *arg, struct pt_regs *ptregs)
1113{
1114 static int start_count = -1;
1115 unsigned int cpuid;
1116
1117 cpuid = smp_processor_id();
1118
1119 /* If first cpu, update count */
1120 if (start_count == -1)
1121 start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CMC);
1122
1123 ia64_mca_cmc_int_handler(cmc_irq, arg, ptregs);
1124
1125 for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
1126
1127 if (cpuid < NR_CPUS) {
1128 platform_send_ipi(cpuid, IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
1129 } else {
1130 /* If no log record, switch out of polling mode */
1131 if (start_count == IA64_LOG_COUNT(SAL_INFO_TYPE_CMC)) {
1132
1133 printk(KERN_WARNING "Returning to interrupt driven CMC handler\n");
1134 schedule_work(&cmc_enable_work);
1135 cmc_polling_enabled = 0;
1136
1137 } else {
1138
1139 mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
1140 }
1141
1142 start_count = -1;
1143 }
1144
1145 return IRQ_HANDLED;
1146}
1147
1148/*
1149 * ia64_mca_cmc_poll
1150 *
1151 * Poll for Corrected Machine Checks (CMCs)
1152 *
1153 * Inputs : dummy(unused)
1154 * Outputs : None
1155 *
1156 */
1157static void
1158ia64_mca_cmc_poll (unsigned long dummy)
1159{
1160 /* Trigger a CMC interrupt cascade */
1161 platform_send_ipi(first_cpu(cpu_online_map), IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
1162}
1163
1164/*
1165 * ia64_mca_cpe_int_caller
1166 *
1167 * Triggered by sw interrupt from CPE polling routine. Calls
1168 * real interrupt handler and either triggers a sw interrupt
1169 * on the next cpu or does cleanup at the end.
1170 *
1171 * Inputs
1172 * interrupt number
1173 * client data arg ptr
1174 * saved registers ptr
1175 * Outputs
1176 * handled
1177 */
1178#ifdef CONFIG_ACPI
1179
1180static irqreturn_t
1181ia64_mca_cpe_int_caller(int cpe_irq, void *arg, struct pt_regs *ptregs)
1182{
1183 static int start_count = -1;
1184 static int poll_time = MIN_CPE_POLL_INTERVAL;
1185 unsigned int cpuid;
1186
1187 cpuid = smp_processor_id();
1188
1189 /* If first cpu, update count */
1190 if (start_count == -1)
1191 start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CPE);
1192
1193 ia64_mca_cpe_int_handler(cpe_irq, arg, ptregs);
1194
1195 for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
1196
1197 if (cpuid < NR_CPUS) {
1198 platform_send_ipi(cpuid, IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
1199 } else {
1200 /*
1201 * If a log was recorded, increase our polling frequency,
1202 * otherwise, backoff or return to interrupt mode.
1203 */
1204 if (start_count != IA64_LOG_COUNT(SAL_INFO_TYPE_CPE)) {
1205 poll_time = max(MIN_CPE_POLL_INTERVAL, poll_time / 2);
1206 } else if (cpe_vector < 0) {
1207 poll_time = min(MAX_CPE_POLL_INTERVAL, poll_time * 2);
1208 } else {
1209 poll_time = MIN_CPE_POLL_INTERVAL;
1210
1211 printk(KERN_WARNING "Returning to interrupt driven CPE handler\n");
1212 enable_irq(local_vector_to_irq(IA64_CPE_VECTOR));
1213 cpe_poll_enabled = 0;
1214 }
1215
1216 if (cpe_poll_enabled)
1217 mod_timer(&cpe_poll_timer, jiffies + poll_time);
1218 start_count = -1;
1219 }
1220
1221 return IRQ_HANDLED;
1222}
1223
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224/*
1225 * ia64_mca_cpe_poll
1226 *
1227 * Poll for Corrected Platform Errors (CPEs), trigger interrupt
1228 * on first cpu, from there it will trickle through all the cpus.
1229 *
1230 * Inputs : dummy(unused)
1231 * Outputs : None
1232 *
1233 */
1234static void
1235ia64_mca_cpe_poll (unsigned long dummy)
1236{
1237 /* Trigger a CPE interrupt cascade */
1238 platform_send_ipi(first_cpu(cpu_online_map), IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
1239}
1240
Peter Chubbb6559132005-05-31 22:34:00 -07001241#endif /* CONFIG_ACPI */
1242
Keith Owens9138d582005-11-07 11:27:13 -08001243static int
1244default_monarch_init_process(struct notifier_block *self, unsigned long val, void *data)
1245{
1246 int c;
1247 struct task_struct *g, *t;
1248 if (val != DIE_INIT_MONARCH_PROCESS)
1249 return NOTIFY_DONE;
1250 printk(KERN_ERR "Processes interrupted by INIT -");
1251 for_each_online_cpu(c) {
1252 struct ia64_sal_os_state *s;
1253 t = __va(__per_cpu_mca[c] + IA64_MCA_CPU_INIT_STACK_OFFSET);
1254 s = (struct ia64_sal_os_state *)((char *)t + MCA_SOS_OFFSET);
1255 g = s->prev_task;
1256 if (g) {
1257 if (g->pid)
1258 printk(" %d", g->pid);
1259 else
1260 printk(" %d (cpu %d task 0x%p)", g->pid, task_cpu(g), g);
1261 }
1262 }
1263 printk("\n\n");
1264 if (read_trylock(&tasklist_lock)) {
1265 do_each_thread (g, t) {
1266 printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm);
1267 show_stack(t, NULL);
1268 } while_each_thread (g, t);
1269 read_unlock(&tasklist_lock);
1270 }
1271 return NOTIFY_DONE;
1272}
1273
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274/*
1275 * C portion of the OS INIT handler
1276 *
Keith Owens7f613c72005-09-11 17:22:53 +10001277 * Called from ia64_os_init_dispatch
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 *
Keith Owens7f613c72005-09-11 17:22:53 +10001279 * Inputs: pointer to pt_regs where processor info was saved. SAL/OS state for
1280 * this event. This code is used for both monarch and slave INIT events, see
1281 * sos->monarch.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 *
Keith Owens7f613c72005-09-11 17:22:53 +10001283 * All INIT events switch to the INIT stack and change the previous process to
1284 * blocked status. If one of the INIT events is the monarch then we are
1285 * probably processing the nmi button/command. Use the monarch cpu to dump all
1286 * the processes. The slave INIT events all spin until the monarch cpu
1287 * returns. We can also get INIT slave events for MCA, in which case the MCA
1288 * process is the monarch.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Keith Owens7f613c72005-09-11 17:22:53 +10001291void
1292ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw,
1293 struct ia64_sal_os_state *sos)
1294{
1295 static atomic_t slaves;
1296 static atomic_t monarchs;
1297 task_t *previous_current;
Keith Owens9138d582005-11-07 11:27:13 -08001298 int cpu = smp_processor_id();
Keith Owens7f613c72005-09-11 17:22:53 +10001299
1300 oops_in_progress = 1; /* FIXME: make printk NMI/MCA/INIT safe */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 console_loglevel = 15; /* make sure printks make it to console */
1302
Keith Owens7f613c72005-09-11 17:22:53 +10001303 printk(KERN_INFO "Entered OS INIT handler. PSP=%lx cpu=%d monarch=%ld\n",
1304 sos->proc_state_param, cpu, sos->monarch);
1305 salinfo_log_wakeup(SAL_INFO_TYPE_INIT, NULL, 0, 0);
1306
1307 previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "INIT");
1308 sos->os_status = IA64_INIT_RESUME;
1309
1310 /* FIXME: Workaround for broken proms that drive all INIT events as
1311 * slaves. The last slave that enters is promoted to be a monarch.
1312 * Remove this code in September 2006, that gives platforms a year to
1313 * fix their proms and get their customers updated.
1314 */
1315 if (!sos->monarch && atomic_add_return(1, &slaves) == num_online_cpus()) {
1316 printk(KERN_WARNING "%s: Promoting cpu %d to monarch.\n",
1317 __FUNCTION__, cpu);
1318 atomic_dec(&slaves);
1319 sos->monarch = 1;
1320 }
1321
1322 /* FIXME: Workaround for broken proms that drive all INIT events as
1323 * monarchs. Second and subsequent monarchs are demoted to slaves.
1324 * Remove this code in September 2006, that gives platforms a year to
1325 * fix their proms and get their customers updated.
1326 */
1327 if (sos->monarch && atomic_add_return(1, &monarchs) > 1) {
1328 printk(KERN_WARNING "%s: Demoting cpu %d to slave.\n",
1329 __FUNCTION__, cpu);
1330 atomic_dec(&monarchs);
1331 sos->monarch = 0;
1332 }
1333
1334 if (!sos->monarch) {
1335 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_INIT;
1336 while (monarch_cpu == -1)
1337 cpu_relax(); /* spin until monarch enters */
Keith Owens9138d582005-11-07 11:27:13 -08001338 if (notify_die(DIE_INIT_SLAVE_ENTER, "INIT", regs, 0, 0, 0)
1339 == NOTIFY_STOP)
1340 ia64_mca_spin(__FUNCTION__);
1341 if (notify_die(DIE_INIT_SLAVE_PROCESS, "INIT", regs, 0, 0, 0)
1342 == NOTIFY_STOP)
1343 ia64_mca_spin(__FUNCTION__);
Keith Owens7f613c72005-09-11 17:22:53 +10001344 while (monarch_cpu != -1)
1345 cpu_relax(); /* spin until monarch leaves */
Keith Owens9138d582005-11-07 11:27:13 -08001346 if (notify_die(DIE_INIT_SLAVE_LEAVE, "INIT", regs, 0, 0, 0)
1347 == NOTIFY_STOP)
1348 ia64_mca_spin(__FUNCTION__);
Keith Owens7f613c72005-09-11 17:22:53 +10001349 printk("Slave on cpu %d returning to normal service.\n", cpu);
1350 set_curr_task(cpu, previous_current);
1351 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
1352 atomic_dec(&slaves);
1353 return;
1354 }
1355
1356 monarch_cpu = cpu;
Keith Owens9138d582005-11-07 11:27:13 -08001357 if (notify_die(DIE_INIT_MONARCH_ENTER, "INIT", regs, 0, 0, 0)
1358 == NOTIFY_STOP)
1359 ia64_mca_spin(__FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
1361 /*
Keith Owens7f613c72005-09-11 17:22:53 +10001362 * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be
1363 * generated via the BMC's command-line interface, but since the console is on the
1364 * same serial line, the user will need some time to switch out of the BMC before
1365 * the dump begins.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 */
Keith Owens7f613c72005-09-11 17:22:53 +10001367 printk("Delaying for 5 seconds...\n");
1368 udelay(5*1000000);
1369 ia64_wait_for_slaves(cpu);
Keith Owens9138d582005-11-07 11:27:13 -08001370 /* If nobody intercepts DIE_INIT_MONARCH_PROCESS then we drop through
1371 * to default_monarch_init_process() above and just print all the
1372 * tasks.
1373 */
1374 if (notify_die(DIE_INIT_MONARCH_PROCESS, "INIT", regs, 0, 0, 0)
1375 == NOTIFY_STOP)
1376 ia64_mca_spin(__FUNCTION__);
1377 if (notify_die(DIE_INIT_MONARCH_LEAVE, "INIT", regs, 0, 0, 0)
1378 == NOTIFY_STOP)
1379 ia64_mca_spin(__FUNCTION__);
Keith Owens7f613c72005-09-11 17:22:53 +10001380 printk("\nINIT dump complete. Monarch on cpu %d returning to normal service.\n", cpu);
1381 atomic_dec(&monarchs);
1382 set_curr_task(cpu, previous_current);
1383 monarch_cpu = -1;
1384 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385}
1386
1387static int __init
1388ia64_mca_disable_cpe_polling(char *str)
1389{
1390 cpe_poll_enabled = 0;
1391 return 1;
1392}
1393
1394__setup("disable_cpe_poll", ia64_mca_disable_cpe_polling);
1395
1396static struct irqaction cmci_irqaction = {
1397 .handler = ia64_mca_cmc_int_handler,
1398 .flags = SA_INTERRUPT,
1399 .name = "cmc_hndlr"
1400};
1401
1402static struct irqaction cmcp_irqaction = {
1403 .handler = ia64_mca_cmc_int_caller,
1404 .flags = SA_INTERRUPT,
1405 .name = "cmc_poll"
1406};
1407
1408static struct irqaction mca_rdzv_irqaction = {
1409 .handler = ia64_mca_rendez_int_handler,
1410 .flags = SA_INTERRUPT,
1411 .name = "mca_rdzv"
1412};
1413
1414static struct irqaction mca_wkup_irqaction = {
1415 .handler = ia64_mca_wakeup_int_handler,
1416 .flags = SA_INTERRUPT,
1417 .name = "mca_wkup"
1418};
1419
1420#ifdef CONFIG_ACPI
1421static struct irqaction mca_cpe_irqaction = {
1422 .handler = ia64_mca_cpe_int_handler,
1423 .flags = SA_INTERRUPT,
1424 .name = "cpe_hndlr"
1425};
1426
1427static struct irqaction mca_cpep_irqaction = {
1428 .handler = ia64_mca_cpe_int_caller,
1429 .flags = SA_INTERRUPT,
1430 .name = "cpe_poll"
1431};
1432#endif /* CONFIG_ACPI */
1433
Keith Owens7f613c72005-09-11 17:22:53 +10001434/* Minimal format of the MCA/INIT stacks. The pseudo processes that run on
1435 * these stacks can never sleep, they cannot return from the kernel to user
1436 * space, they do not appear in a normal ps listing. So there is no need to
1437 * format most of the fields.
1438 */
1439
1440static void
1441format_mca_init_stack(void *mca_data, unsigned long offset,
1442 const char *type, int cpu)
1443{
1444 struct task_struct *p = (struct task_struct *)((char *)mca_data + offset);
1445 struct thread_info *ti;
1446 memset(p, 0, KERNEL_STACK_SIZE);
Al Viroab035912006-01-12 01:06:05 -08001447 ti = task_thread_info(p);
Keith Owens7f613c72005-09-11 17:22:53 +10001448 ti->flags = _TIF_MCA_INIT;
1449 ti->preempt_count = 1;
1450 ti->task = p;
1451 ti->cpu = cpu;
1452 p->thread_info = ti;
1453 p->state = TASK_UNINTERRUPTIBLE;
1454 __set_bit(cpu, &p->cpus_allowed);
1455 INIT_LIST_HEAD(&p->tasks);
1456 p->parent = p->real_parent = p->group_leader = p;
1457 INIT_LIST_HEAD(&p->children);
1458 INIT_LIST_HEAD(&p->sibling);
1459 strncpy(p->comm, type, sizeof(p->comm)-1);
1460}
1461
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462/* Do per-CPU MCA-related initialization. */
1463
1464void __devinit
1465ia64_mca_cpu_init(void *cpu_data)
1466{
1467 void *pal_vaddr;
1468
1469 if (smp_processor_id() == 0) {
1470 void *mca_data;
1471 int cpu;
1472
1473 mca_data = alloc_bootmem(sizeof(struct ia64_mca_cpu)
Keith Owens7f613c72005-09-11 17:22:53 +10001474 * NR_CPUS + KERNEL_STACK_SIZE);
1475 mca_data = (void *)(((unsigned long)mca_data +
1476 KERNEL_STACK_SIZE - 1) &
1477 (-KERNEL_STACK_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 for (cpu = 0; cpu < NR_CPUS; cpu++) {
Keith Owens7f613c72005-09-11 17:22:53 +10001479 format_mca_init_stack(mca_data,
1480 offsetof(struct ia64_mca_cpu, mca_stack),
1481 "MCA", cpu);
1482 format_mca_init_stack(mca_data,
1483 offsetof(struct ia64_mca_cpu, init_stack),
1484 "INIT", cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 __per_cpu_mca[cpu] = __pa(mca_data);
1486 mca_data += sizeof(struct ia64_mca_cpu);
1487 }
1488 }
1489
Keith Owens7f613c72005-09-11 17:22:53 +10001490 /*
1491 * The MCA info structure was allocated earlier and its
1492 * physical address saved in __per_cpu_mca[cpu]. Copy that
1493 * address * to ia64_mca_data so we can access it as a per-CPU
1494 * variable.
1495 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 __get_cpu_var(ia64_mca_data) = __per_cpu_mca[smp_processor_id()];
1497
1498 /*
1499 * Stash away a copy of the PTE needed to map the per-CPU page.
1500 * We may need it during MCA recovery.
1501 */
1502 __get_cpu_var(ia64_mca_per_cpu_pte) =
1503 pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL));
1504
Keith Owens7f613c72005-09-11 17:22:53 +10001505 /*
1506 * Also, stash away a copy of the PAL address and the PTE
1507 * needed to map it.
1508 */
1509 pal_vaddr = efi_get_pal_addr();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 if (!pal_vaddr)
1511 return;
1512 __get_cpu_var(ia64_mca_pal_base) =
1513 GRANULEROUNDDOWN((unsigned long) pal_vaddr);
1514 __get_cpu_var(ia64_mca_pal_pte) = pte_val(mk_pte_phys(__pa(pal_vaddr),
1515 PAGE_KERNEL));
1516}
1517
1518/*
1519 * ia64_mca_init
1520 *
1521 * Do all the system level mca specific initialization.
1522 *
1523 * 1. Register spinloop and wakeup request interrupt vectors
1524 *
1525 * 2. Register OS_MCA handler entry point
1526 *
1527 * 3. Register OS_INIT handler entry point
1528 *
1529 * 4. Initialize MCA/CMC/INIT related log buffers maintained by the OS.
1530 *
1531 * Note that this initialization is done very early before some kernel
1532 * services are available.
1533 *
1534 * Inputs : None
1535 *
1536 * Outputs : None
1537 */
1538void __init
1539ia64_mca_init(void)
1540{
Keith Owens7f613c72005-09-11 17:22:53 +10001541 ia64_fptr_t *init_hldlr_ptr_monarch = (ia64_fptr_t *)ia64_os_init_dispatch_monarch;
1542 ia64_fptr_t *init_hldlr_ptr_slave = (ia64_fptr_t *)ia64_os_init_dispatch_slave;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch;
1544 int i;
1545 s64 rc;
1546 struct ia64_sal_retval isrv;
1547 u64 timeout = IA64_MCA_RENDEZ_TIMEOUT; /* platform specific */
Keith Owens9138d582005-11-07 11:27:13 -08001548 static struct notifier_block default_init_monarch_nb = {
1549 .notifier_call = default_monarch_init_process,
1550 .priority = 0/* we need to notified last */
1551 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
1553 IA64_MCA_DEBUG("%s: begin\n", __FUNCTION__);
1554
1555 /* Clear the Rendez checkin flag for all cpus */
1556 for(i = 0 ; i < NR_CPUS; i++)
1557 ia64_mc_info.imi_rendez_checkin[i] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
1558
1559 /*
1560 * Register the rendezvous spinloop and wakeup mechanism with SAL
1561 */
1562
1563 /* Register the rendezvous interrupt vector with SAL */
1564 while (1) {
1565 isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_INT,
1566 SAL_MC_PARAM_MECHANISM_INT,
1567 IA64_MCA_RENDEZ_VECTOR,
1568 timeout,
1569 SAL_MC_PARAM_RZ_ALWAYS);
1570 rc = isrv.status;
1571 if (rc == 0)
1572 break;
1573 if (rc == -2) {
1574 printk(KERN_INFO "Increasing MCA rendezvous timeout from "
1575 "%ld to %ld milliseconds\n", timeout, isrv.v0);
1576 timeout = isrv.v0;
1577 continue;
1578 }
1579 printk(KERN_ERR "Failed to register rendezvous interrupt "
1580 "with SAL (status %ld)\n", rc);
1581 return;
1582 }
1583
1584 /* Register the wakeup interrupt vector with SAL */
1585 isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_WAKEUP,
1586 SAL_MC_PARAM_MECHANISM_INT,
1587 IA64_MCA_WAKEUP_VECTOR,
1588 0, 0);
1589 rc = isrv.status;
1590 if (rc) {
1591 printk(KERN_ERR "Failed to register wakeup interrupt with SAL "
1592 "(status %ld)\n", rc);
1593 return;
1594 }
1595
1596 IA64_MCA_DEBUG("%s: registered MCA rendezvous spinloop and wakeup mech.\n", __FUNCTION__);
1597
1598 ia64_mc_info.imi_mca_handler = ia64_tpa(mca_hldlr_ptr->fp);
1599 /*
1600 * XXX - disable SAL checksum by setting size to 0; should be
1601 * ia64_tpa(ia64_os_mca_dispatch_end) - ia64_tpa(ia64_os_mca_dispatch);
1602 */
1603 ia64_mc_info.imi_mca_handler_size = 0;
1604
1605 /* Register the os mca handler with SAL */
1606 if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_MCA,
1607 ia64_mc_info.imi_mca_handler,
1608 ia64_tpa(mca_hldlr_ptr->gp),
1609 ia64_mc_info.imi_mca_handler_size,
1610 0, 0, 0)))
1611 {
1612 printk(KERN_ERR "Failed to register OS MCA handler with SAL "
1613 "(status %ld)\n", rc);
1614 return;
1615 }
1616
1617 IA64_MCA_DEBUG("%s: registered OS MCA handler with SAL at 0x%lx, gp = 0x%lx\n", __FUNCTION__,
1618 ia64_mc_info.imi_mca_handler, ia64_tpa(mca_hldlr_ptr->gp));
1619
1620 /*
1621 * XXX - disable SAL checksum by setting size to 0, should be
1622 * size of the actual init handler in mca_asm.S.
1623 */
Keith Owens7f613c72005-09-11 17:22:53 +10001624 ia64_mc_info.imi_monarch_init_handler = ia64_tpa(init_hldlr_ptr_monarch->fp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 ia64_mc_info.imi_monarch_init_handler_size = 0;
Keith Owens7f613c72005-09-11 17:22:53 +10001626 ia64_mc_info.imi_slave_init_handler = ia64_tpa(init_hldlr_ptr_slave->fp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 ia64_mc_info.imi_slave_init_handler_size = 0;
1628
1629 IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __FUNCTION__,
1630 ia64_mc_info.imi_monarch_init_handler);
1631
1632 /* Register the os init handler with SAL */
1633 if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_INIT,
1634 ia64_mc_info.imi_monarch_init_handler,
1635 ia64_tpa(ia64_getreg(_IA64_REG_GP)),
1636 ia64_mc_info.imi_monarch_init_handler_size,
1637 ia64_mc_info.imi_slave_init_handler,
1638 ia64_tpa(ia64_getreg(_IA64_REG_GP)),
1639 ia64_mc_info.imi_slave_init_handler_size)))
1640 {
1641 printk(KERN_ERR "Failed to register m/s INIT handlers with SAL "
1642 "(status %ld)\n", rc);
1643 return;
1644 }
Keith Owens9138d582005-11-07 11:27:13 -08001645 if (register_die_notifier(&default_init_monarch_nb)) {
1646 printk(KERN_ERR "Failed to register default monarch INIT process\n");
1647 return;
1648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
1650 IA64_MCA_DEBUG("%s: registered OS INIT handler with SAL\n", __FUNCTION__);
1651
1652 /*
1653 * Configure the CMCI/P vector and handler. Interrupts for CMC are
1654 * per-processor, so AP CMC interrupts are setup in smp_callin() (smpboot.c).
1655 */
1656 register_percpu_irq(IA64_CMC_VECTOR, &cmci_irqaction);
1657 register_percpu_irq(IA64_CMCP_VECTOR, &cmcp_irqaction);
1658 ia64_mca_cmc_vector_setup(); /* Setup vector on BSP */
1659
1660 /* Setup the MCA rendezvous interrupt vector */
1661 register_percpu_irq(IA64_MCA_RENDEZ_VECTOR, &mca_rdzv_irqaction);
1662
1663 /* Setup the MCA wakeup interrupt vector */
1664 register_percpu_irq(IA64_MCA_WAKEUP_VECTOR, &mca_wkup_irqaction);
1665
1666#ifdef CONFIG_ACPI
Russ Andersonbb68c122005-05-09 15:03:00 -07001667 /* Setup the CPEI/P handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 register_percpu_irq(IA64_CPEP_VECTOR, &mca_cpep_irqaction);
1669#endif
1670
1671 /* Initialize the areas set aside by the OS to buffer the
1672 * platform/processor error states for MCA/INIT/CMC
1673 * handling.
1674 */
1675 ia64_log_init(SAL_INFO_TYPE_MCA);
1676 ia64_log_init(SAL_INFO_TYPE_INIT);
1677 ia64_log_init(SAL_INFO_TYPE_CMC);
1678 ia64_log_init(SAL_INFO_TYPE_CPE);
1679
1680 mca_init = 1;
1681 printk(KERN_INFO "MCA related initialization done\n");
1682}
1683
1684/*
1685 * ia64_mca_late_init
1686 *
1687 * Opportunity to setup things that require initialization later
1688 * than ia64_mca_init. Setup a timer to poll for CPEs if the
1689 * platform doesn't support an interrupt driven mechanism.
1690 *
1691 * Inputs : None
1692 * Outputs : Status
1693 */
1694static int __init
1695ia64_mca_late_init(void)
1696{
1697 if (!mca_init)
1698 return 0;
1699
1700 /* Setup the CMCI/P vector and handler */
1701 init_timer(&cmc_poll_timer);
1702 cmc_poll_timer.function = ia64_mca_cmc_poll;
1703
1704 /* Unmask/enable the vector */
1705 cmc_polling_enabled = 0;
1706 schedule_work(&cmc_enable_work);
1707
1708 IA64_MCA_DEBUG("%s: CMCI/P setup and enabled.\n", __FUNCTION__);
1709
1710#ifdef CONFIG_ACPI
1711 /* Setup the CPEI/P vector and handler */
Russ Andersonbb68c122005-05-09 15:03:00 -07001712 cpe_vector = acpi_request_vector(ACPI_INTERRUPT_CPEI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 init_timer(&cpe_poll_timer);
1714 cpe_poll_timer.function = ia64_mca_cpe_poll;
1715
1716 {
1717 irq_desc_t *desc;
1718 unsigned int irq;
1719
1720 if (cpe_vector >= 0) {
1721 /* If platform supports CPEI, enable the irq. */
1722 cpe_poll_enabled = 0;
1723 for (irq = 0; irq < NR_IRQS; ++irq)
1724 if (irq_to_vector(irq) == cpe_vector) {
1725 desc = irq_descp(irq);
1726 desc->status |= IRQ_PER_CPU;
1727 setup_irq(irq, &mca_cpe_irqaction);
1728 }
1729 ia64_mca_register_cpev(cpe_vector);
1730 IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n", __FUNCTION__);
1731 } else {
1732 /* If platform doesn't support CPEI, get the timer going. */
1733 if (cpe_poll_enabled) {
1734 ia64_mca_cpe_poll(0UL);
1735 IA64_MCA_DEBUG("%s: CPEP setup and enabled.\n", __FUNCTION__);
1736 }
1737 }
1738 }
1739#endif
1740
1741 return 0;
1742}
1743
1744device_initcall(ia64_mca_late_init);