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 * 2005-08-12 Keith Owens <kaos@sgi.com>
53 * Convert MCA/INIT handlers to use per event stacks and SAL/OS state.
55 * 2005-10-07 Keith Owens <kaos@sgi.com>
56 * Add notify_die() hooks.
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>
64 #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 #include <linux/cpumask.h>
74 #include <asm/delay.h>
75 #include <asm/kdebug.h>
76 #include <asm/machvec.h>
77 #include <asm/meminit.h>
79 #include <asm/ptrace.h>
80 #include <asm/system.h>
85 #include <asm/hw_irq.h>
90 #if defined(IA64_MCA_DEBUG_INFO)
91 # define IA64_MCA_DEBUG(fmt...) printk(fmt)
93 # define IA64_MCA_DEBUG(fmt...)
96 /* Used by mca_asm.S */
97 u32 ia64_mca_serialize
;
98 DEFINE_PER_CPU(u64
, ia64_mca_data
); /* == __per_cpu_mca[smp_processor_id()] */
99 DEFINE_PER_CPU(u64
, ia64_mca_per_cpu_pte
); /* PTE to map per-CPU area */
100 DEFINE_PER_CPU(u64
, ia64_mca_pal_pte
); /* PTE to map PAL code */
101 DEFINE_PER_CPU(u64
, ia64_mca_pal_base
); /* vaddr PAL code granule */
103 unsigned long __per_cpu_mca
[NR_CPUS
];
106 extern void ia64_os_init_dispatch_monarch (void);
107 extern void ia64_os_init_dispatch_slave (void);
109 static int monarch_cpu
= -1;
111 static ia64_mc_info_t ia64_mc_info
;
113 #define MAX_CPE_POLL_INTERVAL (15*60*HZ) /* 15 minutes */
114 #define MIN_CPE_POLL_INTERVAL (2*60*HZ) /* 2 minutes */
115 #define CMC_POLL_INTERVAL (1*60*HZ) /* 1 minute */
116 #define CPE_HISTORY_LENGTH 5
117 #define CMC_HISTORY_LENGTH 5
119 static struct timer_list cpe_poll_timer
;
120 static struct timer_list cmc_poll_timer
;
122 * This variable tells whether we are currently in polling mode.
123 * Start with this in the wrong state so we won't play w/ timers
124 * before the system is ready.
126 static int cmc_polling_enabled
= 1;
129 * Clearing this variable prevents CPE polling from getting activated
130 * in mca_late_init. Use it if your system doesn't provide a CPEI,
131 * but encounters problems retrieving CPE logs. This should only be
132 * necessary for debugging.
134 static int cpe_poll_enabled
= 1;
136 extern void salinfo_log_wakeup(int type
, u8
*buffer
, u64 size
, int irqsafe
);
138 static int mca_init __initdata
;
142 ia64_mca_spin(const char *func
)
144 printk(KERN_EMERG
"%s: spinning here, not returning to SAL\n", func
);
149 * IA64_MCA log support
151 #define IA64_MAX_LOGS 2 /* Double-buffering for nested MCAs */
152 #define IA64_MAX_LOG_TYPES 4 /* MCA, INIT, CMC, CPE */
154 typedef struct ia64_state_log_s
158 unsigned long isl_count
;
159 ia64_err_rec_t
*isl_log
[IA64_MAX_LOGS
]; /* need space to store header + error log */
162 static ia64_state_log_t ia64_state_log
[IA64_MAX_LOG_TYPES
];
164 #define IA64_LOG_ALLOCATE(it, size) \
165 {ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)] = \
166 (ia64_err_rec_t *)alloc_bootmem(size); \
167 ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)] = \
168 (ia64_err_rec_t *)alloc_bootmem(size);}
169 #define IA64_LOG_LOCK_INIT(it) spin_lock_init(&ia64_state_log[it].isl_lock)
170 #define IA64_LOG_LOCK(it) spin_lock_irqsave(&ia64_state_log[it].isl_lock, s)
171 #define IA64_LOG_UNLOCK(it) spin_unlock_irqrestore(&ia64_state_log[it].isl_lock,s)
172 #define IA64_LOG_NEXT_INDEX(it) ia64_state_log[it].isl_index
173 #define IA64_LOG_CURR_INDEX(it) 1 - ia64_state_log[it].isl_index
174 #define IA64_LOG_INDEX_INC(it) \
175 {ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index; \
176 ia64_state_log[it].isl_count++;}
177 #define IA64_LOG_INDEX_DEC(it) \
178 ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index
179 #define IA64_LOG_NEXT_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)]))
180 #define IA64_LOG_CURR_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)]))
181 #define IA64_LOG_COUNT(it) ia64_state_log[it].isl_count
185 * Reset the OS ia64 log buffer
186 * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
190 ia64_log_init(int sal_info_type
)
194 IA64_LOG_NEXT_INDEX(sal_info_type
) = 0;
195 IA64_LOG_LOCK_INIT(sal_info_type
);
197 // SAL will tell us the maximum size of any error record of this type
198 max_size
= ia64_sal_get_state_info_size(sal_info_type
);
200 /* alloc_bootmem() doesn't like zero-sized allocations! */
203 // set up OS data structures to hold error info
204 IA64_LOG_ALLOCATE(sal_info_type
, max_size
);
205 memset(IA64_LOG_CURR_BUFFER(sal_info_type
), 0, max_size
);
206 memset(IA64_LOG_NEXT_BUFFER(sal_info_type
), 0, max_size
);
212 * Get the current MCA log from SAL and copy it into the OS log buffer.
214 * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
215 * irq_safe whether you can use printk at this point
216 * Outputs : size (total record length)
217 * *buffer (ptr to error record)
221 ia64_log_get(int sal_info_type
, u8
**buffer
, int irq_safe
)
223 sal_log_record_header_t
*log_buffer
;
227 IA64_LOG_LOCK(sal_info_type
);
229 /* Get the process state information */
230 log_buffer
= IA64_LOG_NEXT_BUFFER(sal_info_type
);
232 total_len
= ia64_sal_get_state_info(sal_info_type
, (u64
*)log_buffer
);
235 IA64_LOG_INDEX_INC(sal_info_type
);
236 IA64_LOG_UNLOCK(sal_info_type
);
238 IA64_MCA_DEBUG("%s: SAL error record type %d retrieved. "
239 "Record length = %ld\n", __FUNCTION__
, sal_info_type
, total_len
);
241 *buffer
= (u8
*) log_buffer
;
244 IA64_LOG_UNLOCK(sal_info_type
);
250 * ia64_mca_log_sal_error_record
252 * This function retrieves a specified error record type from SAL
253 * and wakes up any processes waiting for error records.
255 * Inputs : sal_info_type (Type of error record MCA/CMC/CPE)
256 * FIXME: remove MCA and irq_safe.
259 ia64_mca_log_sal_error_record(int sal_info_type
)
262 sal_log_record_header_t
*rh
;
264 int irq_safe
= sal_info_type
!= SAL_INFO_TYPE_MCA
;
265 #ifdef IA64_MCA_DEBUG_INFO
266 static const char * const rec_name
[] = { "MCA", "INIT", "CMC", "CPE" };
269 size
= ia64_log_get(sal_info_type
, &buffer
, irq_safe
);
273 salinfo_log_wakeup(sal_info_type
, buffer
, size
, irq_safe
);
276 IA64_MCA_DEBUG("CPU %d: SAL log contains %s error record\n",
278 sal_info_type
< ARRAY_SIZE(rec_name
) ? rec_name
[sal_info_type
] : "UNKNOWN");
280 /* Clear logs from corrected errors in case there's no user-level logger */
281 rh
= (sal_log_record_header_t
*)buffer
;
282 if (rh
->severity
== sal_log_severity_corrected
)
283 ia64_sal_clear_state_info(sal_info_type
);
288 * See if the MCA surfaced in an instruction range
289 * that has been tagged as recoverable.
292 * first First address range to check
293 * last Last address range to check
294 * ip Instruction pointer, address we are looking for
297 * 1 on Success (in the table)/ 0 on Failure (not in the table)
300 search_mca_table (const struct mca_table_entry
*first
,
301 const struct mca_table_entry
*last
,
304 const struct mca_table_entry
*curr
;
305 u64 curr_start
, curr_end
;
308 while (curr
<= last
) {
309 curr_start
= (u64
) &curr
->start_addr
+ curr
->start_addr
;
310 curr_end
= (u64
) &curr
->end_addr
+ curr
->end_addr
;
312 if ((ip
>= curr_start
) && (ip
<= curr_end
)) {
320 /* Given an address, look for it in the mca tables. */
321 int mca_recover_range(unsigned long addr
)
323 extern struct mca_table_entry __start___mca_table
[];
324 extern struct mca_table_entry __stop___mca_table
[];
326 return search_mca_table(__start___mca_table
, __stop___mca_table
-1, addr
);
328 EXPORT_SYMBOL_GPL(mca_recover_range
);
333 int ia64_cpe_irq
= -1;
336 ia64_mca_cpe_int_handler (int cpe_irq
, void *arg
, struct pt_regs
*ptregs
)
338 static unsigned long cpe_history
[CPE_HISTORY_LENGTH
];
340 static DEFINE_SPINLOCK(cpe_history_lock
);
342 IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
343 __FUNCTION__
, cpe_irq
, smp_processor_id());
345 /* SAL spec states this should run w/ interrupts enabled */
348 /* Get the CPE error record and log it */
349 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE
);
351 spin_lock(&cpe_history_lock
);
352 if (!cpe_poll_enabled
&& cpe_vector
>= 0) {
354 int i
, count
= 1; /* we know 1 happened now */
355 unsigned long now
= jiffies
;
357 for (i
= 0; i
< CPE_HISTORY_LENGTH
; i
++) {
358 if (now
- cpe_history
[i
] <= HZ
)
362 IA64_MCA_DEBUG(KERN_INFO
"CPE threshold %d/%d\n", count
, CPE_HISTORY_LENGTH
);
363 if (count
>= CPE_HISTORY_LENGTH
) {
365 cpe_poll_enabled
= 1;
366 spin_unlock(&cpe_history_lock
);
367 disable_irq_nosync(local_vector_to_irq(IA64_CPE_VECTOR
));
370 * Corrected errors will still be corrected, but
371 * make sure there's a log somewhere that indicates
372 * something is generating more than we can handle.
374 printk(KERN_WARNING
"WARNING: Switching to polling CPE handler; error records may be lost\n");
376 mod_timer(&cpe_poll_timer
, jiffies
+ MIN_CPE_POLL_INTERVAL
);
378 /* lock already released, get out now */
381 cpe_history
[index
++] = now
;
382 if (index
== CPE_HISTORY_LENGTH
)
386 spin_unlock(&cpe_history_lock
);
390 #endif /* CONFIG_ACPI */
394 * ia64_mca_register_cpev
396 * Register the corrected platform error vector with SAL.
399 * cpev Corrected Platform Error Vector number
405 ia64_mca_register_cpev (int cpev
)
407 /* Register the CPE interrupt vector with SAL */
408 struct ia64_sal_retval isrv
;
410 isrv
= ia64_sal_mc_set_params(SAL_MC_PARAM_CPE_INT
, SAL_MC_PARAM_MECHANISM_INT
, cpev
, 0, 0);
412 printk(KERN_ERR
"Failed to register Corrected Platform "
413 "Error interrupt vector with SAL (status %ld)\n", isrv
.status
);
417 IA64_MCA_DEBUG("%s: corrected platform error "
418 "vector %#x registered\n", __FUNCTION__
, cpev
);
420 #endif /* CONFIG_ACPI */
423 * ia64_mca_cmc_vector_setup
425 * Setup the corrected machine check vector register in the processor.
426 * (The interrupt is masked on boot. ia64_mca_late_init unmask this.)
427 * This function is invoked on a per-processor basis.
436 ia64_mca_cmc_vector_setup (void)
440 cmcv
.cmcv_regval
= 0;
441 cmcv
.cmcv_mask
= 1; /* Mask/disable interrupt at first */
442 cmcv
.cmcv_vector
= IA64_CMC_VECTOR
;
443 ia64_setreg(_IA64_REG_CR_CMCV
, cmcv
.cmcv_regval
);
445 IA64_MCA_DEBUG("%s: CPU %d corrected "
446 "machine check vector %#x registered.\n",
447 __FUNCTION__
, smp_processor_id(), IA64_CMC_VECTOR
);
449 IA64_MCA_DEBUG("%s: CPU %d CMCV = %#016lx\n",
450 __FUNCTION__
, smp_processor_id(), ia64_getreg(_IA64_REG_CR_CMCV
));
454 * ia64_mca_cmc_vector_disable
456 * Mask the corrected machine check vector register in the processor.
457 * This function is invoked on a per-processor basis.
466 ia64_mca_cmc_vector_disable (void *dummy
)
470 cmcv
.cmcv_regval
= ia64_getreg(_IA64_REG_CR_CMCV
);
472 cmcv
.cmcv_mask
= 1; /* Mask/disable interrupt */
473 ia64_setreg(_IA64_REG_CR_CMCV
, cmcv
.cmcv_regval
);
475 IA64_MCA_DEBUG("%s: CPU %d corrected "
476 "machine check vector %#x disabled.\n",
477 __FUNCTION__
, smp_processor_id(), cmcv
.cmcv_vector
);
481 * ia64_mca_cmc_vector_enable
483 * Unmask the corrected machine check vector register in the processor.
484 * This function is invoked on a per-processor basis.
493 ia64_mca_cmc_vector_enable (void *dummy
)
497 cmcv
.cmcv_regval
= ia64_getreg(_IA64_REG_CR_CMCV
);
499 cmcv
.cmcv_mask
= 0; /* Unmask/enable interrupt */
500 ia64_setreg(_IA64_REG_CR_CMCV
, cmcv
.cmcv_regval
);
502 IA64_MCA_DEBUG("%s: CPU %d corrected "
503 "machine check vector %#x enabled.\n",
504 __FUNCTION__
, smp_processor_id(), cmcv
.cmcv_vector
);
508 * ia64_mca_cmc_vector_disable_keventd
510 * Called via keventd (smp_call_function() is not safe in interrupt context) to
511 * disable the cmc interrupt vector.
514 ia64_mca_cmc_vector_disable_keventd(void *unused
)
516 on_each_cpu(ia64_mca_cmc_vector_disable
, NULL
, 1, 0);
520 * ia64_mca_cmc_vector_enable_keventd
522 * Called via keventd (smp_call_function() is not safe in interrupt context) to
523 * enable the cmc interrupt vector.
526 ia64_mca_cmc_vector_enable_keventd(void *unused
)
528 on_each_cpu(ia64_mca_cmc_vector_enable
, NULL
, 1, 0);
534 * Send an inter-cpu interrupt to wake-up a particular cpu
535 * and mark that cpu to be out of rendez.
541 ia64_mca_wakeup(int cpu
)
543 platform_send_ipi(cpu
, IA64_MCA_WAKEUP_VECTOR
, IA64_IPI_DM_INT
, 0);
544 ia64_mc_info
.imi_rendez_checkin
[cpu
] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE
;
549 * ia64_mca_wakeup_all
551 * Wakeup all the cpus which have rendez'ed previously.
557 ia64_mca_wakeup_all(void)
561 /* Clear the Rendez checkin flag for all cpus */
562 for_each_online_cpu(cpu
) {
563 if (ia64_mc_info
.imi_rendez_checkin
[cpu
] == IA64_MCA_RENDEZ_CHECKIN_DONE
)
564 ia64_mca_wakeup(cpu
);
570 * ia64_mca_rendez_interrupt_handler
572 * This is handler used to put slave processors into spinloop
573 * while the monarch processor does the mca handling and later
574 * wake each slave up once the monarch is done.
580 ia64_mca_rendez_int_handler(int rendez_irq
, void *arg
, struct pt_regs
*regs
)
583 int cpu
= smp_processor_id();
585 /* Mask all interrupts */
586 local_irq_save(flags
);
587 if (notify_die(DIE_MCA_RENDZVOUS_ENTER
, "MCA", regs
, 0, 0, 0)
589 ia64_mca_spin(__FUNCTION__
);
591 ia64_mc_info
.imi_rendez_checkin
[cpu
] = IA64_MCA_RENDEZ_CHECKIN_DONE
;
592 /* Register with the SAL monarch that the slave has
595 ia64_sal_mc_rendez();
597 if (notify_die(DIE_MCA_RENDZVOUS_PROCESS
, "MCA", regs
, 0, 0, 0)
599 ia64_mca_spin(__FUNCTION__
);
601 /* Wait for the monarch cpu to exit. */
602 while (monarch_cpu
!= -1)
603 cpu_relax(); /* spin until monarch leaves */
605 if (notify_die(DIE_MCA_RENDZVOUS_LEAVE
, "MCA", regs
, 0, 0, 0)
607 ia64_mca_spin(__FUNCTION__
);
609 /* Enable all interrupts */
610 local_irq_restore(flags
);
615 * ia64_mca_wakeup_int_handler
617 * The interrupt handler for processing the inter-cpu interrupt to the
618 * slave cpu which was spinning in the rendez loop.
619 * Since this spinning is done by turning off the interrupts and
620 * polling on the wakeup-interrupt bit in the IRR, there is
621 * nothing useful to be done in the handler.
623 * Inputs : wakeup_irq (Wakeup-interrupt bit)
624 * arg (Interrupt handler specific argument)
625 * ptregs (Exception frame at the time of the interrupt)
630 ia64_mca_wakeup_int_handler(int wakeup_irq
, void *arg
, struct pt_regs
*ptregs
)
635 /* Function pointer for extra MCA recovery */
636 int (*ia64_mca_ucmc_extension
)
637 (void*,struct ia64_sal_os_state
*)
641 ia64_reg_MCA_extension(int (*fn
)(void *, struct ia64_sal_os_state
*))
643 if (ia64_mca_ucmc_extension
)
646 ia64_mca_ucmc_extension
= fn
;
651 ia64_unreg_MCA_extension(void)
653 if (ia64_mca_ucmc_extension
)
654 ia64_mca_ucmc_extension
= NULL
;
657 EXPORT_SYMBOL(ia64_reg_MCA_extension
);
658 EXPORT_SYMBOL(ia64_unreg_MCA_extension
);
662 copy_reg(const u64
*fr
, u64 fnat
, u64
*tr
, u64
*tnat
)
664 u64 fslot
, tslot
, nat
;
666 fslot
= ((unsigned long)fr
>> 3) & 63;
667 tslot
= ((unsigned long)tr
>> 3) & 63;
668 *tnat
&= ~(1UL << tslot
);
669 nat
= (fnat
>> fslot
) & 1;
670 *tnat
|= (nat
<< tslot
);
673 /* Change the comm field on the MCA/INT task to include the pid that
674 * was interrupted, it makes for easier debugging. If that pid was 0
675 * (swapper or nested MCA/INIT) then use the start of the previous comm
676 * field suffixed with its cpu.
680 ia64_mca_modify_comm(const task_t
*previous_current
)
682 char *p
, comm
[sizeof(current
->comm
)];
683 if (previous_current
->pid
)
684 snprintf(comm
, sizeof(comm
), "%s %d",
685 current
->comm
, previous_current
->pid
);
688 if ((p
= strchr(previous_current
->comm
, ' ')))
689 l
= p
- previous_current
->comm
;
691 l
= strlen(previous_current
->comm
);
692 snprintf(comm
, sizeof(comm
), "%s %*s %d",
693 current
->comm
, l
, previous_current
->comm
,
694 task_thread_info(previous_current
)->cpu
);
696 memcpy(current
->comm
, comm
, sizeof(current
->comm
));
699 /* On entry to this routine, we are running on the per cpu stack, see
700 * mca_asm.h. The original stack has not been touched by this event. Some of
701 * the original stack's registers will be in the RBS on this stack. This stack
702 * also contains a partial pt_regs and switch_stack, the rest of the data is in
705 * The first thing to do is modify the original stack to look like a blocked
706 * task so we can run backtrace on the original task. Also mark the per cpu
707 * stack as current to ensure that we use the correct task state, it also means
708 * that we can do backtrace on the MCA/INIT handler code itself.
712 ia64_mca_modify_original_stack(struct pt_regs
*regs
,
713 const struct switch_stack
*sw
,
714 struct ia64_sal_os_state
*sos
,
719 extern char ia64_leave_kernel
[]; /* Need asm address, not function descriptor */
720 const pal_min_state_area_t
*ms
= sos
->pal_min_state
;
721 task_t
*previous_current
;
722 struct pt_regs
*old_regs
;
723 struct switch_stack
*old_sw
;
724 unsigned size
= sizeof(struct pt_regs
) +
725 sizeof(struct switch_stack
) + 16;
726 u64
*old_bspstore
, *old_bsp
;
727 u64
*new_bspstore
, *new_bsp
;
728 u64 old_unat
, old_rnat
, new_rnat
, nat
;
729 u64 slots
, loadrs
= regs
->loadrs
;
730 u64 r12
= ms
->pmsa_gr
[12-1], r13
= ms
->pmsa_gr
[13-1];
731 u64 ar_bspstore
= regs
->ar_bspstore
;
732 u64 ar_bsp
= regs
->ar_bspstore
+ (loadrs
>> 16);
735 int cpu
= smp_processor_id();
737 previous_current
= curr_task(cpu
);
738 set_curr_task(cpu
, current
);
739 if ((p
= strchr(current
->comm
, ' ')))
742 /* Best effort attempt to cope with MCA/INIT delivered while in
745 regs
->cr_ipsr
= ms
->pmsa_ipsr
;
746 if (ia64_psr(regs
)->dt
== 0) {
758 if (ia64_psr(regs
)->rt
== 0) {
771 /* mca_asm.S ia64_old_stack() cannot assume that the dirty registers
772 * have been copied to the old stack, the old stack may fail the
773 * validation tests below. So ia64_old_stack() must restore the dirty
774 * registers from the new stack. The old and new bspstore probably
775 * have different alignments, so loadrs calculated on the old bsp
776 * cannot be used to restore from the new bsp. Calculate a suitable
777 * loadrs for the new stack and save it in the new pt_regs, where
778 * ia64_old_stack() can get it.
780 old_bspstore
= (u64
*)ar_bspstore
;
781 old_bsp
= (u64
*)ar_bsp
;
782 slots
= ia64_rse_num_regs(old_bspstore
, old_bsp
);
783 new_bspstore
= (u64
*)((u64
)current
+ IA64_RBS_OFFSET
);
784 new_bsp
= ia64_rse_skip_regs(new_bspstore
, slots
);
785 regs
->loadrs
= (new_bsp
- new_bspstore
) * 8 << 16;
787 /* Verify the previous stack state before we change it */
788 if (user_mode(regs
)) {
789 msg
= "occurred in user space";
790 /* previous_current is guaranteed to be valid when the task was
791 * in user space, so ...
793 ia64_mca_modify_comm(previous_current
);
797 if (!mca_recover_range(ms
->pmsa_iip
)) {
798 if (r13
!= sos
->prev_IA64_KR_CURRENT
) {
799 msg
= "inconsistent previous current and r13";
802 if ((r12
- r13
) >= KERNEL_STACK_SIZE
) {
803 msg
= "inconsistent r12 and r13";
806 if ((ar_bspstore
- r13
) >= KERNEL_STACK_SIZE
) {
807 msg
= "inconsistent ar.bspstore and r13";
812 msg
= "old_bspstore is in the wrong region";
815 if ((ar_bsp
- r13
) >= KERNEL_STACK_SIZE
) {
816 msg
= "inconsistent ar.bsp and r13";
819 size
+= (ia64_rse_skip_regs(old_bspstore
, slots
) - old_bspstore
) * 8;
820 if (ar_bspstore
+ size
> r12
) {
821 msg
= "no room for blocked state";
826 ia64_mca_modify_comm(previous_current
);
828 /* Make the original task look blocked. First stack a struct pt_regs,
829 * describing the state at the time of interrupt. mca_asm.S built a
830 * partial pt_regs, copy it and fill in the blanks using minstate.
832 p
= (char *)r12
- sizeof(*regs
);
833 old_regs
= (struct pt_regs
*)p
;
834 memcpy(old_regs
, regs
, sizeof(*regs
));
835 /* If ipsr.ic then use pmsa_{iip,ipsr,ifs}, else use
836 * pmsa_{xip,xpsr,xfs}
838 if (ia64_psr(regs
)->ic
) {
839 old_regs
->cr_iip
= ms
->pmsa_iip
;
840 old_regs
->cr_ipsr
= ms
->pmsa_ipsr
;
841 old_regs
->cr_ifs
= ms
->pmsa_ifs
;
843 old_regs
->cr_iip
= ms
->pmsa_xip
;
844 old_regs
->cr_ipsr
= ms
->pmsa_xpsr
;
845 old_regs
->cr_ifs
= ms
->pmsa_xfs
;
847 old_regs
->pr
= ms
->pmsa_pr
;
848 old_regs
->b0
= ms
->pmsa_br0
;
849 old_regs
->loadrs
= loadrs
;
850 old_regs
->ar_rsc
= ms
->pmsa_rsc
;
851 old_unat
= old_regs
->ar_unat
;
852 copy_reg(&ms
->pmsa_gr
[1-1], ms
->pmsa_nat_bits
, &old_regs
->r1
, &old_unat
);
853 copy_reg(&ms
->pmsa_gr
[2-1], ms
->pmsa_nat_bits
, &old_regs
->r2
, &old_unat
);
854 copy_reg(&ms
->pmsa_gr
[3-1], ms
->pmsa_nat_bits
, &old_regs
->r3
, &old_unat
);
855 copy_reg(&ms
->pmsa_gr
[8-1], ms
->pmsa_nat_bits
, &old_regs
->r8
, &old_unat
);
856 copy_reg(&ms
->pmsa_gr
[9-1], ms
->pmsa_nat_bits
, &old_regs
->r9
, &old_unat
);
857 copy_reg(&ms
->pmsa_gr
[10-1], ms
->pmsa_nat_bits
, &old_regs
->r10
, &old_unat
);
858 copy_reg(&ms
->pmsa_gr
[11-1], ms
->pmsa_nat_bits
, &old_regs
->r11
, &old_unat
);
859 copy_reg(&ms
->pmsa_gr
[12-1], ms
->pmsa_nat_bits
, &old_regs
->r12
, &old_unat
);
860 copy_reg(&ms
->pmsa_gr
[13-1], ms
->pmsa_nat_bits
, &old_regs
->r13
, &old_unat
);
861 copy_reg(&ms
->pmsa_gr
[14-1], ms
->pmsa_nat_bits
, &old_regs
->r14
, &old_unat
);
862 copy_reg(&ms
->pmsa_gr
[15-1], ms
->pmsa_nat_bits
, &old_regs
->r15
, &old_unat
);
863 if (ia64_psr(old_regs
)->bn
)
864 bank
= ms
->pmsa_bank1_gr
;
866 bank
= ms
->pmsa_bank0_gr
;
867 copy_reg(&bank
[16-16], ms
->pmsa_nat_bits
, &old_regs
->r16
, &old_unat
);
868 copy_reg(&bank
[17-16], ms
->pmsa_nat_bits
, &old_regs
->r17
, &old_unat
);
869 copy_reg(&bank
[18-16], ms
->pmsa_nat_bits
, &old_regs
->r18
, &old_unat
);
870 copy_reg(&bank
[19-16], ms
->pmsa_nat_bits
, &old_regs
->r19
, &old_unat
);
871 copy_reg(&bank
[20-16], ms
->pmsa_nat_bits
, &old_regs
->r20
, &old_unat
);
872 copy_reg(&bank
[21-16], ms
->pmsa_nat_bits
, &old_regs
->r21
, &old_unat
);
873 copy_reg(&bank
[22-16], ms
->pmsa_nat_bits
, &old_regs
->r22
, &old_unat
);
874 copy_reg(&bank
[23-16], ms
->pmsa_nat_bits
, &old_regs
->r23
, &old_unat
);
875 copy_reg(&bank
[24-16], ms
->pmsa_nat_bits
, &old_regs
->r24
, &old_unat
);
876 copy_reg(&bank
[25-16], ms
->pmsa_nat_bits
, &old_regs
->r25
, &old_unat
);
877 copy_reg(&bank
[26-16], ms
->pmsa_nat_bits
, &old_regs
->r26
, &old_unat
);
878 copy_reg(&bank
[27-16], ms
->pmsa_nat_bits
, &old_regs
->r27
, &old_unat
);
879 copy_reg(&bank
[28-16], ms
->pmsa_nat_bits
, &old_regs
->r28
, &old_unat
);
880 copy_reg(&bank
[29-16], ms
->pmsa_nat_bits
, &old_regs
->r29
, &old_unat
);
881 copy_reg(&bank
[30-16], ms
->pmsa_nat_bits
, &old_regs
->r30
, &old_unat
);
882 copy_reg(&bank
[31-16], ms
->pmsa_nat_bits
, &old_regs
->r31
, &old_unat
);
884 /* Next stack a struct switch_stack. mca_asm.S built a partial
885 * switch_stack, copy it and fill in the blanks using pt_regs and
888 * In the synthesized switch_stack, b0 points to ia64_leave_kernel,
889 * ar.pfs is set to 0.
891 * unwind.c::unw_unwind() does special processing for interrupt frames.
892 * It checks if the PRED_NON_SYSCALL predicate is set, if the predicate
893 * is clear then unw_unwind() does _not_ adjust bsp over pt_regs. Not
894 * that this is documented, of course. Set PRED_NON_SYSCALL in the
895 * switch_stack on the original stack so it will unwind correctly when
896 * unwind.c reads pt_regs.
898 * thread.ksp is updated to point to the synthesized switch_stack.
900 p
-= sizeof(struct switch_stack
);
901 old_sw
= (struct switch_stack
*)p
;
902 memcpy(old_sw
, sw
, sizeof(*sw
));
903 old_sw
->caller_unat
= old_unat
;
904 old_sw
->ar_fpsr
= old_regs
->ar_fpsr
;
905 copy_reg(&ms
->pmsa_gr
[4-1], ms
->pmsa_nat_bits
, &old_sw
->r4
, &old_unat
);
906 copy_reg(&ms
->pmsa_gr
[5-1], ms
->pmsa_nat_bits
, &old_sw
->r5
, &old_unat
);
907 copy_reg(&ms
->pmsa_gr
[6-1], ms
->pmsa_nat_bits
, &old_sw
->r6
, &old_unat
);
908 copy_reg(&ms
->pmsa_gr
[7-1], ms
->pmsa_nat_bits
, &old_sw
->r7
, &old_unat
);
909 old_sw
->b0
= (u64
)ia64_leave_kernel
;
910 old_sw
->b1
= ms
->pmsa_br1
;
912 old_sw
->ar_unat
= old_unat
;
913 old_sw
->pr
= old_regs
->pr
| (1UL << PRED_NON_SYSCALL
);
914 previous_current
->thread
.ksp
= (u64
)p
- 16;
916 /* Finally copy the original stack's registers back to its RBS.
917 * Registers from ar.bspstore through ar.bsp at the time of the event
918 * are in the current RBS, copy them back to the original stack. The
919 * copy must be done register by register because the original bspstore
920 * and the current one have different alignments, so the saved RNAT
921 * data occurs at different places.
923 * mca_asm does cover, so the old_bsp already includes all registers at
924 * the time of MCA/INIT. It also does flushrs, so all registers before
925 * this function have been written to backing store on the MCA/INIT
928 new_rnat
= ia64_get_rnat(ia64_rse_rnat_addr(new_bspstore
));
929 old_rnat
= regs
->ar_rnat
;
931 if (ia64_rse_is_rnat_slot(new_bspstore
)) {
932 new_rnat
= ia64_get_rnat(new_bspstore
++);
934 if (ia64_rse_is_rnat_slot(old_bspstore
)) {
935 *old_bspstore
++ = old_rnat
;
938 nat
= (new_rnat
>> ia64_rse_slot_num(new_bspstore
)) & 1UL;
939 old_rnat
&= ~(1UL << ia64_rse_slot_num(old_bspstore
));
940 old_rnat
|= (nat
<< ia64_rse_slot_num(old_bspstore
));
941 *old_bspstore
++ = *new_bspstore
++;
943 old_sw
->ar_bspstore
= (unsigned long)old_bspstore
;
944 old_sw
->ar_rnat
= old_rnat
;
946 sos
->prev_task
= previous_current
;
947 return previous_current
;
950 printk(KERN_INFO
"cpu %d, %s %s, original stack not modified\n",
951 smp_processor_id(), type
, msg
);
952 return previous_current
;
955 /* The monarch/slave interaction is based on monarch_cpu and requires that all
956 * slaves have entered rendezvous before the monarch leaves. If any cpu has
957 * not entered rendezvous yet then wait a bit. The assumption is that any
958 * slave that has not rendezvoused after a reasonable time is never going to do
959 * so. In this context, slave includes cpus that respond to the MCA rendezvous
960 * interrupt, as well as cpus that receive the INIT slave event.
964 ia64_wait_for_slaves(int monarch
)
966 int c
, wait
= 0, missing
= 0;
967 for_each_online_cpu(c
) {
970 if (ia64_mc_info
.imi_rendez_checkin
[c
] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE
) {
971 udelay(1000); /* short wait first */
978 for_each_online_cpu(c
) {
981 if (ia64_mc_info
.imi_rendez_checkin
[c
] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE
) {
982 udelay(5*1000000); /* wait 5 seconds for slaves (arbitrary) */
983 if (ia64_mc_info
.imi_rendez_checkin
[c
] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE
)
990 printk(KERN_INFO
"OS MCA slave did not rendezvous on cpu");
991 for_each_online_cpu(c
) {
994 if (ia64_mc_info
.imi_rendez_checkin
[c
] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE
)
1001 printk(KERN_INFO
"All OS MCA slaves have reached rendezvous\n");
1008 * This is uncorrectable machine check handler called from OS_MCA
1009 * dispatch code which is in turn called from SAL_CHECK().
1010 * This is the place where the core of OS MCA handling is done.
1011 * Right now the logs are extracted and displayed in a well-defined
1012 * format. This handler code is supposed to be run only on the
1013 * monarch processor. Once the monarch is done with MCA handling
1014 * further MCA logging is enabled by clearing logs.
1015 * Monarch also has the duty of sending wakeup-IPIs to pull the
1016 * slave processors out of rendezvous spinloop.
1019 ia64_mca_handler(struct pt_regs
*regs
, struct switch_stack
*sw
,
1020 struct ia64_sal_os_state
*sos
)
1022 pal_processor_state_info_t
*psp
= (pal_processor_state_info_t
*)
1023 &sos
->proc_state_param
;
1024 int recover
, cpu
= smp_processor_id();
1025 task_t
*previous_current
;
1027 oops_in_progress
= 1; /* FIXME: make printk NMI/MCA/INIT safe */
1028 console_loglevel
= 15; /* make sure printks make it to console */
1029 printk(KERN_INFO
"Entered OS MCA handler. PSP=%lx cpu=%d monarch=%ld\n",
1030 sos
->proc_state_param
, cpu
, sos
->monarch
);
1032 previous_current
= ia64_mca_modify_original_stack(regs
, sw
, sos
, "MCA");
1034 if (notify_die(DIE_MCA_MONARCH_ENTER
, "MCA", regs
, 0, 0, 0)
1036 ia64_mca_spin(__FUNCTION__
);
1037 ia64_wait_for_slaves(cpu
);
1039 /* Wakeup all the processors which are spinning in the rendezvous loop.
1040 * They will leave SAL, then spin in the OS with interrupts disabled
1041 * until this monarch cpu leaves the MCA handler. That gets control
1042 * back to the OS so we can backtrace the other cpus, backtrace when
1043 * spinning in SAL does not work.
1045 ia64_mca_wakeup_all();
1046 if (notify_die(DIE_MCA_MONARCH_PROCESS
, "MCA", regs
, 0, 0, 0)
1048 ia64_mca_spin(__FUNCTION__
);
1050 /* Get the MCA error record and log it */
1051 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA
);
1053 /* TLB error is only exist in this SAL error record */
1054 recover
= (psp
->tc
&& !(psp
->cc
|| psp
->bc
|| psp
->rc
|| psp
->uc
))
1055 /* other error recovery */
1056 || (ia64_mca_ucmc_extension
1057 && ia64_mca_ucmc_extension(
1058 IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA
),
1062 sal_log_record_header_t
*rh
= IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA
);
1063 rh
->severity
= sal_log_severity_corrected
;
1064 ia64_sal_clear_state_info(SAL_INFO_TYPE_MCA
);
1065 sos
->os_status
= IA64_MCA_CORRECTED
;
1067 if (notify_die(DIE_MCA_MONARCH_LEAVE
, "MCA", regs
, 0, 0, recover
)
1069 ia64_mca_spin(__FUNCTION__
);
1071 set_curr_task(cpu
, previous_current
);
1075 static DECLARE_WORK(cmc_disable_work
, ia64_mca_cmc_vector_disable_keventd
, NULL
);
1076 static DECLARE_WORK(cmc_enable_work
, ia64_mca_cmc_vector_enable_keventd
, NULL
);
1079 * ia64_mca_cmc_int_handler
1081 * This is corrected machine check interrupt handler.
1082 * Right now the logs are extracted and displayed in a well-defined
1087 * client data arg ptr
1088 * saved registers ptr
1094 ia64_mca_cmc_int_handler(int cmc_irq
, void *arg
, struct pt_regs
*ptregs
)
1096 static unsigned long cmc_history
[CMC_HISTORY_LENGTH
];
1098 static DEFINE_SPINLOCK(cmc_history_lock
);
1100 IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
1101 __FUNCTION__
, cmc_irq
, smp_processor_id());
1103 /* SAL spec states this should run w/ interrupts enabled */
1106 /* Get the CMC error record and log it */
1107 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC
);
1109 spin_lock(&cmc_history_lock
);
1110 if (!cmc_polling_enabled
) {
1111 int i
, count
= 1; /* we know 1 happened now */
1112 unsigned long now
= jiffies
;
1114 for (i
= 0; i
< CMC_HISTORY_LENGTH
; i
++) {
1115 if (now
- cmc_history
[i
] <= HZ
)
1119 IA64_MCA_DEBUG(KERN_INFO
"CMC threshold %d/%d\n", count
, CMC_HISTORY_LENGTH
);
1120 if (count
>= CMC_HISTORY_LENGTH
) {
1122 cmc_polling_enabled
= 1;
1123 spin_unlock(&cmc_history_lock
);
1124 /* If we're being hit with CMC interrupts, we won't
1125 * ever execute the schedule_work() below. Need to
1126 * disable CMC interrupts on this processor now.
1128 ia64_mca_cmc_vector_disable(NULL
);
1129 schedule_work(&cmc_disable_work
);
1132 * Corrected errors will still be corrected, but
1133 * make sure there's a log somewhere that indicates
1134 * something is generating more than we can handle.
1136 printk(KERN_WARNING
"WARNING: Switching to polling CMC handler; error records may be lost\n");
1138 mod_timer(&cmc_poll_timer
, jiffies
+ CMC_POLL_INTERVAL
);
1140 /* lock already released, get out now */
1143 cmc_history
[index
++] = now
;
1144 if (index
== CMC_HISTORY_LENGTH
)
1148 spin_unlock(&cmc_history_lock
);
1153 * ia64_mca_cmc_int_caller
1155 * Triggered by sw interrupt from CMC polling routine. Calls
1156 * real interrupt handler and either triggers a sw interrupt
1157 * on the next cpu or does cleanup at the end.
1161 * client data arg ptr
1162 * saved registers ptr
1167 ia64_mca_cmc_int_caller(int cmc_irq
, void *arg
, struct pt_regs
*ptregs
)
1169 static int start_count
= -1;
1172 cpuid
= smp_processor_id();
1174 /* If first cpu, update count */
1175 if (start_count
== -1)
1176 start_count
= IA64_LOG_COUNT(SAL_INFO_TYPE_CMC
);
1178 ia64_mca_cmc_int_handler(cmc_irq
, arg
, ptregs
);
1180 for (++cpuid
; cpuid
< NR_CPUS
&& !cpu_online(cpuid
) ; cpuid
++);
1182 if (cpuid
< NR_CPUS
) {
1183 platform_send_ipi(cpuid
, IA64_CMCP_VECTOR
, IA64_IPI_DM_INT
, 0);
1185 /* If no log record, switch out of polling mode */
1186 if (start_count
== IA64_LOG_COUNT(SAL_INFO_TYPE_CMC
)) {
1188 printk(KERN_WARNING
"Returning to interrupt driven CMC handler\n");
1189 schedule_work(&cmc_enable_work
);
1190 cmc_polling_enabled
= 0;
1194 mod_timer(&cmc_poll_timer
, jiffies
+ CMC_POLL_INTERVAL
);
1206 * Poll for Corrected Machine Checks (CMCs)
1208 * Inputs : dummy(unused)
1213 ia64_mca_cmc_poll (unsigned long dummy
)
1215 /* Trigger a CMC interrupt cascade */
1216 platform_send_ipi(first_cpu(cpu_online_map
), IA64_CMCP_VECTOR
, IA64_IPI_DM_INT
, 0);
1220 * ia64_mca_cpe_int_caller
1222 * Triggered by sw interrupt from CPE polling routine. Calls
1223 * real interrupt handler and either triggers a sw interrupt
1224 * on the next cpu or does cleanup at the end.
1228 * client data arg ptr
1229 * saved registers ptr
1236 ia64_mca_cpe_int_caller(int cpe_irq
, void *arg
, struct pt_regs
*ptregs
)
1238 static int start_count
= -1;
1239 static int poll_time
= MIN_CPE_POLL_INTERVAL
;
1242 cpuid
= smp_processor_id();
1244 /* If first cpu, update count */
1245 if (start_count
== -1)
1246 start_count
= IA64_LOG_COUNT(SAL_INFO_TYPE_CPE
);
1248 ia64_mca_cpe_int_handler(cpe_irq
, arg
, ptregs
);
1250 for (++cpuid
; cpuid
< NR_CPUS
&& !cpu_online(cpuid
) ; cpuid
++);
1252 if (cpuid
< NR_CPUS
) {
1253 platform_send_ipi(cpuid
, IA64_CPEP_VECTOR
, IA64_IPI_DM_INT
, 0);
1256 * If a log was recorded, increase our polling frequency,
1257 * otherwise, backoff or return to interrupt mode.
1259 if (start_count
!= IA64_LOG_COUNT(SAL_INFO_TYPE_CPE
)) {
1260 poll_time
= max(MIN_CPE_POLL_INTERVAL
, poll_time
/ 2);
1261 } else if (cpe_vector
< 0) {
1262 poll_time
= min(MAX_CPE_POLL_INTERVAL
, poll_time
* 2);
1264 poll_time
= MIN_CPE_POLL_INTERVAL
;
1266 printk(KERN_WARNING
"Returning to interrupt driven CPE handler\n");
1267 enable_irq(local_vector_to_irq(IA64_CPE_VECTOR
));
1268 cpe_poll_enabled
= 0;
1271 if (cpe_poll_enabled
)
1272 mod_timer(&cpe_poll_timer
, jiffies
+ poll_time
);
1282 * Poll for Corrected Platform Errors (CPEs), trigger interrupt
1283 * on first cpu, from there it will trickle through all the cpus.
1285 * Inputs : dummy(unused)
1290 ia64_mca_cpe_poll (unsigned long dummy
)
1292 /* Trigger a CPE interrupt cascade */
1293 platform_send_ipi(first_cpu(cpu_online_map
), IA64_CPEP_VECTOR
, IA64_IPI_DM_INT
, 0);
1296 #endif /* CONFIG_ACPI */
1299 default_monarch_init_process(struct notifier_block
*self
, unsigned long val
, void *data
)
1302 struct task_struct
*g
, *t
;
1303 if (val
!= DIE_INIT_MONARCH_PROCESS
)
1305 printk(KERN_ERR
"Processes interrupted by INIT -");
1306 for_each_online_cpu(c
) {
1307 struct ia64_sal_os_state
*s
;
1308 t
= __va(__per_cpu_mca
[c
] + IA64_MCA_CPU_INIT_STACK_OFFSET
);
1309 s
= (struct ia64_sal_os_state
*)((char *)t
+ MCA_SOS_OFFSET
);
1313 printk(" %d", g
->pid
);
1315 printk(" %d (cpu %d task 0x%p)", g
->pid
, task_cpu(g
), g
);
1319 if (read_trylock(&tasklist_lock
)) {
1320 do_each_thread (g
, t
) {
1321 printk("\nBacktrace of pid %d (%s)\n", t
->pid
, t
->comm
);
1322 show_stack(t
, NULL
);
1323 } while_each_thread (g
, t
);
1324 read_unlock(&tasklist_lock
);
1330 * C portion of the OS INIT handler
1332 * Called from ia64_os_init_dispatch
1334 * Inputs: pointer to pt_regs where processor info was saved. SAL/OS state for
1335 * this event. This code is used for both monarch and slave INIT events, see
1338 * All INIT events switch to the INIT stack and change the previous process to
1339 * blocked status. If one of the INIT events is the monarch then we are
1340 * probably processing the nmi button/command. Use the monarch cpu to dump all
1341 * the processes. The slave INIT events all spin until the monarch cpu
1342 * returns. We can also get INIT slave events for MCA, in which case the MCA
1343 * process is the monarch.
1347 ia64_init_handler(struct pt_regs
*regs
, struct switch_stack
*sw
,
1348 struct ia64_sal_os_state
*sos
)
1350 static atomic_t slaves
;
1351 static atomic_t monarchs
;
1352 task_t
*previous_current
;
1353 int cpu
= smp_processor_id();
1355 oops_in_progress
= 1; /* FIXME: make printk NMI/MCA/INIT safe */
1356 console_loglevel
= 15; /* make sure printks make it to console */
1358 printk(KERN_INFO
"Entered OS INIT handler. PSP=%lx cpu=%d monarch=%ld\n",
1359 sos
->proc_state_param
, cpu
, sos
->monarch
);
1360 salinfo_log_wakeup(SAL_INFO_TYPE_INIT
, NULL
, 0, 0);
1362 previous_current
= ia64_mca_modify_original_stack(regs
, sw
, sos
, "INIT");
1363 sos
->os_status
= IA64_INIT_RESUME
;
1365 /* FIXME: Workaround for broken proms that drive all INIT events as
1366 * slaves. The last slave that enters is promoted to be a monarch.
1367 * Remove this code in September 2006, that gives platforms a year to
1368 * fix their proms and get their customers updated.
1370 if (!sos
->monarch
&& atomic_add_return(1, &slaves
) == num_online_cpus()) {
1371 printk(KERN_WARNING
"%s: Promoting cpu %d to monarch.\n",
1373 atomic_dec(&slaves
);
1377 /* FIXME: Workaround for broken proms that drive all INIT events as
1378 * monarchs. Second and subsequent monarchs are demoted to slaves.
1379 * Remove this code in September 2006, that gives platforms a year to
1380 * fix their proms and get their customers updated.
1382 if (sos
->monarch
&& atomic_add_return(1, &monarchs
) > 1) {
1383 printk(KERN_WARNING
"%s: Demoting cpu %d to slave.\n",
1385 atomic_dec(&monarchs
);
1389 if (!sos
->monarch
) {
1390 ia64_mc_info
.imi_rendez_checkin
[cpu
] = IA64_MCA_RENDEZ_CHECKIN_INIT
;
1391 while (monarch_cpu
== -1)
1392 cpu_relax(); /* spin until monarch enters */
1393 if (notify_die(DIE_INIT_SLAVE_ENTER
, "INIT", regs
, 0, 0, 0)
1395 ia64_mca_spin(__FUNCTION__
);
1396 if (notify_die(DIE_INIT_SLAVE_PROCESS
, "INIT", regs
, 0, 0, 0)
1398 ia64_mca_spin(__FUNCTION__
);
1399 while (monarch_cpu
!= -1)
1400 cpu_relax(); /* spin until monarch leaves */
1401 if (notify_die(DIE_INIT_SLAVE_LEAVE
, "INIT", regs
, 0, 0, 0)
1403 ia64_mca_spin(__FUNCTION__
);
1404 printk("Slave on cpu %d returning to normal service.\n", cpu
);
1405 set_curr_task(cpu
, previous_current
);
1406 ia64_mc_info
.imi_rendez_checkin
[cpu
] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE
;
1407 atomic_dec(&slaves
);
1412 if (notify_die(DIE_INIT_MONARCH_ENTER
, "INIT", regs
, 0, 0, 0)
1414 ia64_mca_spin(__FUNCTION__
);
1417 * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be
1418 * generated via the BMC's command-line interface, but since the console is on the
1419 * same serial line, the user will need some time to switch out of the BMC before
1422 printk("Delaying for 5 seconds...\n");
1424 ia64_wait_for_slaves(cpu
);
1425 /* If nobody intercepts DIE_INIT_MONARCH_PROCESS then we drop through
1426 * to default_monarch_init_process() above and just print all the
1429 if (notify_die(DIE_INIT_MONARCH_PROCESS
, "INIT", regs
, 0, 0, 0)
1431 ia64_mca_spin(__FUNCTION__
);
1432 if (notify_die(DIE_INIT_MONARCH_LEAVE
, "INIT", regs
, 0, 0, 0)
1434 ia64_mca_spin(__FUNCTION__
);
1435 printk("\nINIT dump complete. Monarch on cpu %d returning to normal service.\n", cpu
);
1436 atomic_dec(&monarchs
);
1437 set_curr_task(cpu
, previous_current
);
1443 ia64_mca_disable_cpe_polling(char *str
)
1445 cpe_poll_enabled
= 0;
1449 __setup("disable_cpe_poll", ia64_mca_disable_cpe_polling
);
1451 static struct irqaction cmci_irqaction
= {
1452 .handler
= ia64_mca_cmc_int_handler
,
1453 .flags
= SA_INTERRUPT
,
1457 static struct irqaction cmcp_irqaction
= {
1458 .handler
= ia64_mca_cmc_int_caller
,
1459 .flags
= SA_INTERRUPT
,
1463 static struct irqaction mca_rdzv_irqaction
= {
1464 .handler
= ia64_mca_rendez_int_handler
,
1465 .flags
= SA_INTERRUPT
,
1469 static struct irqaction mca_wkup_irqaction
= {
1470 .handler
= ia64_mca_wakeup_int_handler
,
1471 .flags
= SA_INTERRUPT
,
1476 static struct irqaction mca_cpe_irqaction
= {
1477 .handler
= ia64_mca_cpe_int_handler
,
1478 .flags
= SA_INTERRUPT
,
1482 static struct irqaction mca_cpep_irqaction
= {
1483 .handler
= ia64_mca_cpe_int_caller
,
1484 .flags
= SA_INTERRUPT
,
1487 #endif /* CONFIG_ACPI */
1489 /* Minimal format of the MCA/INIT stacks. The pseudo processes that run on
1490 * these stacks can never sleep, they cannot return from the kernel to user
1491 * space, they do not appear in a normal ps listing. So there is no need to
1492 * format most of the fields.
1495 static void __cpuinit
1496 format_mca_init_stack(void *mca_data
, unsigned long offset
,
1497 const char *type
, int cpu
)
1499 struct task_struct
*p
= (struct task_struct
*)((char *)mca_data
+ offset
);
1500 struct thread_info
*ti
;
1501 memset(p
, 0, KERNEL_STACK_SIZE
);
1502 ti
= task_thread_info(p
);
1503 ti
->flags
= _TIF_MCA_INIT
;
1504 ti
->preempt_count
= 1;
1507 p
->thread_info
= ti
;
1508 p
->state
= TASK_UNINTERRUPTIBLE
;
1509 cpu_set(cpu
, p
->cpus_allowed
);
1510 INIT_LIST_HEAD(&p
->tasks
);
1511 p
->parent
= p
->real_parent
= p
->group_leader
= p
;
1512 INIT_LIST_HEAD(&p
->children
);
1513 INIT_LIST_HEAD(&p
->sibling
);
1514 strncpy(p
->comm
, type
, sizeof(p
->comm
)-1);
1517 /* Do per-CPU MCA-related initialization. */
1520 ia64_mca_cpu_init(void *cpu_data
)
1523 static int first_time
= 1;
1530 mca_data
= alloc_bootmem(sizeof(struct ia64_mca_cpu
)
1531 * NR_CPUS
+ KERNEL_STACK_SIZE
);
1532 mca_data
= (void *)(((unsigned long)mca_data
+
1533 KERNEL_STACK_SIZE
- 1) &
1534 (-KERNEL_STACK_SIZE
));
1535 for (cpu
= 0; cpu
< NR_CPUS
; cpu
++) {
1536 format_mca_init_stack(mca_data
,
1537 offsetof(struct ia64_mca_cpu
, mca_stack
),
1539 format_mca_init_stack(mca_data
,
1540 offsetof(struct ia64_mca_cpu
, init_stack
),
1542 __per_cpu_mca
[cpu
] = __pa(mca_data
);
1543 mca_data
+= sizeof(struct ia64_mca_cpu
);
1548 * The MCA info structure was allocated earlier and its
1549 * physical address saved in __per_cpu_mca[cpu]. Copy that
1550 * address * to ia64_mca_data so we can access it as a per-CPU
1553 __get_cpu_var(ia64_mca_data
) = __per_cpu_mca
[smp_processor_id()];
1556 * Stash away a copy of the PTE needed to map the per-CPU page.
1557 * We may need it during MCA recovery.
1559 __get_cpu_var(ia64_mca_per_cpu_pte
) =
1560 pte_val(mk_pte_phys(__pa(cpu_data
), PAGE_KERNEL
));
1563 * Also, stash away a copy of the PAL address and the PTE
1566 pal_vaddr
= efi_get_pal_addr();
1569 __get_cpu_var(ia64_mca_pal_base
) =
1570 GRANULEROUNDDOWN((unsigned long) pal_vaddr
);
1571 __get_cpu_var(ia64_mca_pal_pte
) = pte_val(mk_pte_phys(__pa(pal_vaddr
),
1578 * Do all the system level mca specific initialization.
1580 * 1. Register spinloop and wakeup request interrupt vectors
1582 * 2. Register OS_MCA handler entry point
1584 * 3. Register OS_INIT handler entry point
1586 * 4. Initialize MCA/CMC/INIT related log buffers maintained by the OS.
1588 * Note that this initialization is done very early before some kernel
1589 * services are available.
1598 ia64_fptr_t
*init_hldlr_ptr_monarch
= (ia64_fptr_t
*)ia64_os_init_dispatch_monarch
;
1599 ia64_fptr_t
*init_hldlr_ptr_slave
= (ia64_fptr_t
*)ia64_os_init_dispatch_slave
;
1600 ia64_fptr_t
*mca_hldlr_ptr
= (ia64_fptr_t
*)ia64_os_mca_dispatch
;
1603 struct ia64_sal_retval isrv
;
1604 u64 timeout
= IA64_MCA_RENDEZ_TIMEOUT
; /* platform specific */
1605 static struct notifier_block default_init_monarch_nb
= {
1606 .notifier_call
= default_monarch_init_process
,
1607 .priority
= 0/* we need to notified last */
1610 IA64_MCA_DEBUG("%s: begin\n", __FUNCTION__
);
1612 /* Clear the Rendez checkin flag for all cpus */
1613 for(i
= 0 ; i
< NR_CPUS
; i
++)
1614 ia64_mc_info
.imi_rendez_checkin
[i
] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE
;
1617 * Register the rendezvous spinloop and wakeup mechanism with SAL
1620 /* Register the rendezvous interrupt vector with SAL */
1622 isrv
= ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_INT
,
1623 SAL_MC_PARAM_MECHANISM_INT
,
1624 IA64_MCA_RENDEZ_VECTOR
,
1626 SAL_MC_PARAM_RZ_ALWAYS
);
1631 printk(KERN_INFO
"Increasing MCA rendezvous timeout from "
1632 "%ld to %ld milliseconds\n", timeout
, isrv
.v0
);
1636 printk(KERN_ERR
"Failed to register rendezvous interrupt "
1637 "with SAL (status %ld)\n", rc
);
1641 /* Register the wakeup interrupt vector with SAL */
1642 isrv
= ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_WAKEUP
,
1643 SAL_MC_PARAM_MECHANISM_INT
,
1644 IA64_MCA_WAKEUP_VECTOR
,
1648 printk(KERN_ERR
"Failed to register wakeup interrupt with SAL "
1649 "(status %ld)\n", rc
);
1653 IA64_MCA_DEBUG("%s: registered MCA rendezvous spinloop and wakeup mech.\n", __FUNCTION__
);
1655 ia64_mc_info
.imi_mca_handler
= ia64_tpa(mca_hldlr_ptr
->fp
);
1657 * XXX - disable SAL checksum by setting size to 0; should be
1658 * ia64_tpa(ia64_os_mca_dispatch_end) - ia64_tpa(ia64_os_mca_dispatch);
1660 ia64_mc_info
.imi_mca_handler_size
= 0;
1662 /* Register the os mca handler with SAL */
1663 if ((rc
= ia64_sal_set_vectors(SAL_VECTOR_OS_MCA
,
1664 ia64_mc_info
.imi_mca_handler
,
1665 ia64_tpa(mca_hldlr_ptr
->gp
),
1666 ia64_mc_info
.imi_mca_handler_size
,
1669 printk(KERN_ERR
"Failed to register OS MCA handler with SAL "
1670 "(status %ld)\n", rc
);
1674 IA64_MCA_DEBUG("%s: registered OS MCA handler with SAL at 0x%lx, gp = 0x%lx\n", __FUNCTION__
,
1675 ia64_mc_info
.imi_mca_handler
, ia64_tpa(mca_hldlr_ptr
->gp
));
1678 * XXX - disable SAL checksum by setting size to 0, should be
1679 * size of the actual init handler in mca_asm.S.
1681 ia64_mc_info
.imi_monarch_init_handler
= ia64_tpa(init_hldlr_ptr_monarch
->fp
);
1682 ia64_mc_info
.imi_monarch_init_handler_size
= 0;
1683 ia64_mc_info
.imi_slave_init_handler
= ia64_tpa(init_hldlr_ptr_slave
->fp
);
1684 ia64_mc_info
.imi_slave_init_handler_size
= 0;
1686 IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __FUNCTION__
,
1687 ia64_mc_info
.imi_monarch_init_handler
);
1689 /* Register the os init handler with SAL */
1690 if ((rc
= ia64_sal_set_vectors(SAL_VECTOR_OS_INIT
,
1691 ia64_mc_info
.imi_monarch_init_handler
,
1692 ia64_tpa(ia64_getreg(_IA64_REG_GP
)),
1693 ia64_mc_info
.imi_monarch_init_handler_size
,
1694 ia64_mc_info
.imi_slave_init_handler
,
1695 ia64_tpa(ia64_getreg(_IA64_REG_GP
)),
1696 ia64_mc_info
.imi_slave_init_handler_size
)))
1698 printk(KERN_ERR
"Failed to register m/s INIT handlers with SAL "
1699 "(status %ld)\n", rc
);
1702 if (register_die_notifier(&default_init_monarch_nb
)) {
1703 printk(KERN_ERR
"Failed to register default monarch INIT process\n");
1707 IA64_MCA_DEBUG("%s: registered OS INIT handler with SAL\n", __FUNCTION__
);
1710 * Configure the CMCI/P vector and handler. Interrupts for CMC are
1711 * per-processor, so AP CMC interrupts are setup in smp_callin() (smpboot.c).
1713 register_percpu_irq(IA64_CMC_VECTOR
, &cmci_irqaction
);
1714 register_percpu_irq(IA64_CMCP_VECTOR
, &cmcp_irqaction
);
1715 ia64_mca_cmc_vector_setup(); /* Setup vector on BSP */
1717 /* Setup the MCA rendezvous interrupt vector */
1718 register_percpu_irq(IA64_MCA_RENDEZ_VECTOR
, &mca_rdzv_irqaction
);
1720 /* Setup the MCA wakeup interrupt vector */
1721 register_percpu_irq(IA64_MCA_WAKEUP_VECTOR
, &mca_wkup_irqaction
);
1724 /* Setup the CPEI/P handler */
1725 register_percpu_irq(IA64_CPEP_VECTOR
, &mca_cpep_irqaction
);
1728 /* Initialize the areas set aside by the OS to buffer the
1729 * platform/processor error states for MCA/INIT/CMC
1732 ia64_log_init(SAL_INFO_TYPE_MCA
);
1733 ia64_log_init(SAL_INFO_TYPE_INIT
);
1734 ia64_log_init(SAL_INFO_TYPE_CMC
);
1735 ia64_log_init(SAL_INFO_TYPE_CPE
);
1738 printk(KERN_INFO
"MCA related initialization done\n");
1742 * ia64_mca_late_init
1744 * Opportunity to setup things that require initialization later
1745 * than ia64_mca_init. Setup a timer to poll for CPEs if the
1746 * platform doesn't support an interrupt driven mechanism.
1752 ia64_mca_late_init(void)
1757 /* Setup the CMCI/P vector and handler */
1758 init_timer(&cmc_poll_timer
);
1759 cmc_poll_timer
.function
= ia64_mca_cmc_poll
;
1761 /* Unmask/enable the vector */
1762 cmc_polling_enabled
= 0;
1763 schedule_work(&cmc_enable_work
);
1765 IA64_MCA_DEBUG("%s: CMCI/P setup and enabled.\n", __FUNCTION__
);
1768 /* Setup the CPEI/P vector and handler */
1769 cpe_vector
= acpi_request_vector(ACPI_INTERRUPT_CPEI
);
1770 init_timer(&cpe_poll_timer
);
1771 cpe_poll_timer
.function
= ia64_mca_cpe_poll
;
1777 if (cpe_vector
>= 0) {
1778 /* If platform supports CPEI, enable the irq. */
1779 cpe_poll_enabled
= 0;
1780 for (irq
= 0; irq
< NR_IRQS
; ++irq
)
1781 if (irq_to_vector(irq
) == cpe_vector
) {
1782 desc
= irq_descp(irq
);
1783 desc
->status
|= IRQ_PER_CPU
;
1784 setup_irq(irq
, &mca_cpe_irqaction
);
1787 ia64_mca_register_cpev(cpe_vector
);
1788 IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n", __FUNCTION__
);
1790 /* If platform doesn't support CPEI, get the timer going. */
1791 if (cpe_poll_enabled
) {
1792 ia64_mca_cpe_poll(0UL);
1793 IA64_MCA_DEBUG("%s: CPEP setup and enabled.\n", __FUNCTION__
);
1802 device_initcall(ia64_mca_late_init
);