]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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. | |
7f613c7d KO |
51 | * |
52 | * 2005-08-12 Keith Owens <kaos@sgi.com> | |
53 | * Convert MCA/INIT handlers to use per event stacks and SAL/OS state. | |
9138d581 KO |
54 | * |
55 | * 2005-10-07 Keith Owens <kaos@sgi.com> | |
56 | * Add notify_die() hooks. | |
43ed3baf HS |
57 | * |
58 | * 2006-09-15 Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com> | |
59 | * Add printing support for MCA/INIT. | |
1da177e4 | 60 | */ |
1da177e4 LT |
61 | #include <linux/types.h> |
62 | #include <linux/init.h> | |
63 | #include <linux/sched.h> | |
64 | #include <linux/interrupt.h> | |
65 | #include <linux/irq.h> | |
1da177e4 LT |
66 | #include <linux/bootmem.h> |
67 | #include <linux/acpi.h> | |
68 | #include <linux/timer.h> | |
69 | #include <linux/module.h> | |
70 | #include <linux/kernel.h> | |
71 | #include <linux/smp.h> | |
72 | #include <linux/workqueue.h> | |
4668f0cd | 73 | #include <linux/cpumask.h> |
1eeb66a1 | 74 | #include <linux/kdebug.h> |
1da177e4 LT |
75 | |
76 | #include <asm/delay.h> | |
77 | #include <asm/machvec.h> | |
78 | #include <asm/meminit.h> | |
79 | #include <asm/page.h> | |
80 | #include <asm/ptrace.h> | |
81 | #include <asm/system.h> | |
82 | #include <asm/sal.h> | |
83 | #include <asm/mca.h> | |
a7956113 | 84 | #include <asm/kexec.h> |
1da177e4 LT |
85 | |
86 | #include <asm/irq.h> | |
87 | #include <asm/hw_irq.h> | |
88 | ||
d2a28ad9 | 89 | #include "mca_drv.h" |
7f613c7d KO |
90 | #include "entry.h" |
91 | ||
1da177e4 LT |
92 | #if defined(IA64_MCA_DEBUG_INFO) |
93 | # define IA64_MCA_DEBUG(fmt...) printk(fmt) | |
94 | #else | |
95 | # define IA64_MCA_DEBUG(fmt...) | |
96 | #endif | |
97 | ||
98 | /* Used by mca_asm.S */ | |
7f613c7d | 99 | u32 ia64_mca_serialize; |
1da177e4 LT |
100 | DEFINE_PER_CPU(u64, ia64_mca_data); /* == __per_cpu_mca[smp_processor_id()] */ |
101 | DEFINE_PER_CPU(u64, ia64_mca_per_cpu_pte); /* PTE to map per-CPU area */ | |
102 | DEFINE_PER_CPU(u64, ia64_mca_pal_pte); /* PTE to map PAL code */ | |
103 | DEFINE_PER_CPU(u64, ia64_mca_pal_base); /* vaddr PAL code granule */ | |
104 | ||
105 | unsigned long __per_cpu_mca[NR_CPUS]; | |
106 | ||
107 | /* In mca_asm.S */ | |
7f613c7d KO |
108 | extern void ia64_os_init_dispatch_monarch (void); |
109 | extern void ia64_os_init_dispatch_slave (void); | |
110 | ||
111 | static int monarch_cpu = -1; | |
1da177e4 LT |
112 | |
113 | static ia64_mc_info_t ia64_mc_info; | |
114 | ||
115 | #define MAX_CPE_POLL_INTERVAL (15*60*HZ) /* 15 minutes */ | |
116 | #define MIN_CPE_POLL_INTERVAL (2*60*HZ) /* 2 minutes */ | |
117 | #define CMC_POLL_INTERVAL (1*60*HZ) /* 1 minute */ | |
118 | #define CPE_HISTORY_LENGTH 5 | |
119 | #define CMC_HISTORY_LENGTH 5 | |
120 | ||
34eac2ab | 121 | #ifdef CONFIG_ACPI |
1da177e4 | 122 | static struct timer_list cpe_poll_timer; |
34eac2ab | 123 | #endif |
1da177e4 LT |
124 | static struct timer_list cmc_poll_timer; |
125 | /* | |
126 | * This variable tells whether we are currently in polling mode. | |
127 | * Start with this in the wrong state so we won't play w/ timers | |
128 | * before the system is ready. | |
129 | */ | |
130 | static int cmc_polling_enabled = 1; | |
131 | ||
132 | /* | |
133 | * Clearing this variable prevents CPE polling from getting activated | |
134 | * in mca_late_init. Use it if your system doesn't provide a CPEI, | |
135 | * but encounters problems retrieving CPE logs. This should only be | |
136 | * necessary for debugging. | |
137 | */ | |
138 | static int cpe_poll_enabled = 1; | |
139 | ||
140 | extern void salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe); | |
141 | ||
0881fc8d | 142 | static int mca_init __initdata; |
1da177e4 | 143 | |
43ed3baf HS |
144 | /* |
145 | * limited & delayed printing support for MCA/INIT handler | |
146 | */ | |
147 | ||
148 | #define mprintk(fmt...) ia64_mca_printk(fmt) | |
149 | ||
150 | #define MLOGBUF_SIZE (512+256*NR_CPUS) | |
151 | #define MLOGBUF_MSGMAX 256 | |
152 | static char mlogbuf[MLOGBUF_SIZE]; | |
153 | static DEFINE_SPINLOCK(mlogbuf_wlock); /* mca context only */ | |
154 | static DEFINE_SPINLOCK(mlogbuf_rlock); /* normal context only */ | |
155 | static unsigned long mlogbuf_start; | |
156 | static unsigned long mlogbuf_end; | |
157 | static unsigned int mlogbuf_finished = 0; | |
158 | static unsigned long mlogbuf_timestamp = 0; | |
159 | ||
160 | static int loglevel_save = -1; | |
161 | #define BREAK_LOGLEVEL(__console_loglevel) \ | |
162 | oops_in_progress = 1; \ | |
163 | if (loglevel_save < 0) \ | |
164 | loglevel_save = __console_loglevel; \ | |
165 | __console_loglevel = 15; | |
166 | ||
167 | #define RESTORE_LOGLEVEL(__console_loglevel) \ | |
168 | if (loglevel_save >= 0) { \ | |
169 | __console_loglevel = loglevel_save; \ | |
170 | loglevel_save = -1; \ | |
171 | } \ | |
172 | mlogbuf_finished = 0; \ | |
173 | oops_in_progress = 0; | |
174 | ||
175 | /* | |
176 | * Push messages into buffer, print them later if not urgent. | |
177 | */ | |
178 | void ia64_mca_printk(const char *fmt, ...) | |
179 | { | |
180 | va_list args; | |
181 | int printed_len; | |
182 | char temp_buf[MLOGBUF_MSGMAX]; | |
183 | char *p; | |
184 | ||
185 | va_start(args, fmt); | |
186 | printed_len = vscnprintf(temp_buf, sizeof(temp_buf), fmt, args); | |
187 | va_end(args); | |
188 | ||
189 | /* Copy the output into mlogbuf */ | |
190 | if (oops_in_progress) { | |
191 | /* mlogbuf was abandoned, use printk directly instead. */ | |
192 | printk(temp_buf); | |
193 | } else { | |
194 | spin_lock(&mlogbuf_wlock); | |
195 | for (p = temp_buf; *p; p++) { | |
196 | unsigned long next = (mlogbuf_end + 1) % MLOGBUF_SIZE; | |
197 | if (next != mlogbuf_start) { | |
198 | mlogbuf[mlogbuf_end] = *p; | |
199 | mlogbuf_end = next; | |
200 | } else { | |
201 | /* buffer full */ | |
202 | break; | |
203 | } | |
204 | } | |
205 | mlogbuf[mlogbuf_end] = '\0'; | |
206 | spin_unlock(&mlogbuf_wlock); | |
207 | } | |
208 | } | |
209 | EXPORT_SYMBOL(ia64_mca_printk); | |
210 | ||
211 | /* | |
212 | * Print buffered messages. | |
213 | * NOTE: call this after returning normal context. (ex. from salinfod) | |
214 | */ | |
215 | void ia64_mlogbuf_dump(void) | |
216 | { | |
217 | char temp_buf[MLOGBUF_MSGMAX]; | |
218 | char *p; | |
219 | unsigned long index; | |
220 | unsigned long flags; | |
221 | unsigned int printed_len; | |
222 | ||
223 | /* Get output from mlogbuf */ | |
224 | while (mlogbuf_start != mlogbuf_end) { | |
225 | temp_buf[0] = '\0'; | |
226 | p = temp_buf; | |
227 | printed_len = 0; | |
228 | ||
229 | spin_lock_irqsave(&mlogbuf_rlock, flags); | |
230 | ||
231 | index = mlogbuf_start; | |
232 | while (index != mlogbuf_end) { | |
233 | *p = mlogbuf[index]; | |
234 | index = (index + 1) % MLOGBUF_SIZE; | |
235 | if (!*p) | |
236 | break; | |
237 | p++; | |
238 | if (++printed_len >= MLOGBUF_MSGMAX - 1) | |
239 | break; | |
240 | } | |
241 | *p = '\0'; | |
242 | if (temp_buf[0]) | |
243 | printk(temp_buf); | |
244 | mlogbuf_start = index; | |
245 | ||
246 | mlogbuf_timestamp = 0; | |
247 | spin_unlock_irqrestore(&mlogbuf_rlock, flags); | |
248 | } | |
249 | } | |
250 | EXPORT_SYMBOL(ia64_mlogbuf_dump); | |
251 | ||
252 | /* | |
253 | * Call this if system is going to down or if immediate flushing messages to | |
254 | * console is required. (ex. recovery was failed, crash dump is going to be | |
255 | * invoked, long-wait rendezvous etc.) | |
256 | * NOTE: this should be called from monarch. | |
257 | */ | |
258 | static void ia64_mlogbuf_finish(int wait) | |
259 | { | |
260 | BREAK_LOGLEVEL(console_loglevel); | |
261 | ||
262 | spin_lock_init(&mlogbuf_rlock); | |
263 | ia64_mlogbuf_dump(); | |
264 | printk(KERN_EMERG "mlogbuf_finish: printing switched to urgent mode, " | |
265 | "MCA/INIT might be dodgy or fail.\n"); | |
266 | ||
267 | if (!wait) | |
268 | return; | |
269 | ||
270 | /* wait for console */ | |
271 | printk("Delaying for 5 seconds...\n"); | |
272 | udelay(5*1000000); | |
273 | ||
274 | mlogbuf_finished = 1; | |
275 | } | |
276 | EXPORT_SYMBOL(ia64_mlogbuf_finish); | |
277 | ||
278 | /* | |
279 | * Print buffered messages from INIT context. | |
280 | */ | |
281 | static void ia64_mlogbuf_dump_from_init(void) | |
282 | { | |
283 | if (mlogbuf_finished) | |
284 | return; | |
285 | ||
286 | if (mlogbuf_timestamp && (mlogbuf_timestamp + 30*HZ > jiffies)) { | |
287 | printk(KERN_ERR "INIT: mlogbuf_dump is interrupted by INIT " | |
288 | " and the system seems to be messed up.\n"); | |
289 | ia64_mlogbuf_finish(0); | |
290 | return; | |
291 | } | |
292 | ||
293 | if (!spin_trylock(&mlogbuf_rlock)) { | |
294 | printk(KERN_ERR "INIT: mlogbuf_dump is interrupted by INIT. " | |
295 | "Generated messages other than stack dump will be " | |
296 | "buffered to mlogbuf and will be printed later.\n"); | |
297 | printk(KERN_ERR "INIT: If messages would not printed after " | |
298 | "this INIT, wait 30sec and assert INIT again.\n"); | |
299 | if (!mlogbuf_timestamp) | |
300 | mlogbuf_timestamp = jiffies; | |
301 | return; | |
302 | } | |
303 | spin_unlock(&mlogbuf_rlock); | |
304 | ia64_mlogbuf_dump(); | |
305 | } | |
9138d581 KO |
306 | |
307 | static void inline | |
308 | ia64_mca_spin(const char *func) | |
309 | { | |
43ed3baf HS |
310 | if (monarch_cpu == smp_processor_id()) |
311 | ia64_mlogbuf_finish(0); | |
312 | mprintk(KERN_EMERG "%s: spinning here, not returning to SAL\n", func); | |
9138d581 KO |
313 | while (1) |
314 | cpu_relax(); | |
315 | } | |
1da177e4 LT |
316 | /* |
317 | * IA64_MCA log support | |
318 | */ | |
319 | #define IA64_MAX_LOGS 2 /* Double-buffering for nested MCAs */ | |
320 | #define IA64_MAX_LOG_TYPES 4 /* MCA, INIT, CMC, CPE */ | |
321 | ||
322 | typedef struct ia64_state_log_s | |
323 | { | |
324 | spinlock_t isl_lock; | |
325 | int isl_index; | |
326 | unsigned long isl_count; | |
327 | ia64_err_rec_t *isl_log[IA64_MAX_LOGS]; /* need space to store header + error log */ | |
328 | } ia64_state_log_t; | |
329 | ||
330 | static ia64_state_log_t ia64_state_log[IA64_MAX_LOG_TYPES]; | |
331 | ||
332 | #define IA64_LOG_ALLOCATE(it, size) \ | |
333 | {ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)] = \ | |
334 | (ia64_err_rec_t *)alloc_bootmem(size); \ | |
335 | ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)] = \ | |
336 | (ia64_err_rec_t *)alloc_bootmem(size);} | |
337 | #define IA64_LOG_LOCK_INIT(it) spin_lock_init(&ia64_state_log[it].isl_lock) | |
338 | #define IA64_LOG_LOCK(it) spin_lock_irqsave(&ia64_state_log[it].isl_lock, s) | |
339 | #define IA64_LOG_UNLOCK(it) spin_unlock_irqrestore(&ia64_state_log[it].isl_lock,s) | |
340 | #define IA64_LOG_NEXT_INDEX(it) ia64_state_log[it].isl_index | |
341 | #define IA64_LOG_CURR_INDEX(it) 1 - ia64_state_log[it].isl_index | |
342 | #define IA64_LOG_INDEX_INC(it) \ | |
343 | {ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index; \ | |
344 | ia64_state_log[it].isl_count++;} | |
345 | #define IA64_LOG_INDEX_DEC(it) \ | |
346 | ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index | |
347 | #define IA64_LOG_NEXT_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)])) | |
348 | #define IA64_LOG_CURR_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)])) | |
349 | #define IA64_LOG_COUNT(it) ia64_state_log[it].isl_count | |
350 | ||
351 | /* | |
352 | * ia64_log_init | |
353 | * Reset the OS ia64 log buffer | |
354 | * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE}) | |
355 | * Outputs : None | |
356 | */ | |
0881fc8d | 357 | static void __init |
1da177e4 LT |
358 | ia64_log_init(int sal_info_type) |
359 | { | |
360 | u64 max_size = 0; | |
361 | ||
362 | IA64_LOG_NEXT_INDEX(sal_info_type) = 0; | |
363 | IA64_LOG_LOCK_INIT(sal_info_type); | |
364 | ||
365 | // SAL will tell us the maximum size of any error record of this type | |
366 | max_size = ia64_sal_get_state_info_size(sal_info_type); | |
367 | if (!max_size) | |
368 | /* alloc_bootmem() doesn't like zero-sized allocations! */ | |
369 | return; | |
370 | ||
371 | // set up OS data structures to hold error info | |
372 | IA64_LOG_ALLOCATE(sal_info_type, max_size); | |
373 | memset(IA64_LOG_CURR_BUFFER(sal_info_type), 0, max_size); | |
374 | memset(IA64_LOG_NEXT_BUFFER(sal_info_type), 0, max_size); | |
375 | } | |
376 | ||
377 | /* | |
378 | * ia64_log_get | |
379 | * | |
380 | * Get the current MCA log from SAL and copy it into the OS log buffer. | |
381 | * | |
382 | * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE}) | |
383 | * irq_safe whether you can use printk at this point | |
384 | * Outputs : size (total record length) | |
385 | * *buffer (ptr to error record) | |
386 | * | |
387 | */ | |
388 | static u64 | |
389 | ia64_log_get(int sal_info_type, u8 **buffer, int irq_safe) | |
390 | { | |
391 | sal_log_record_header_t *log_buffer; | |
392 | u64 total_len = 0; | |
c53421b1 | 393 | unsigned long s; |
1da177e4 LT |
394 | |
395 | IA64_LOG_LOCK(sal_info_type); | |
396 | ||
397 | /* Get the process state information */ | |
398 | log_buffer = IA64_LOG_NEXT_BUFFER(sal_info_type); | |
399 | ||
400 | total_len = ia64_sal_get_state_info(sal_info_type, (u64 *)log_buffer); | |
401 | ||
402 | if (total_len) { | |
403 | IA64_LOG_INDEX_INC(sal_info_type); | |
404 | IA64_LOG_UNLOCK(sal_info_type); | |
405 | if (irq_safe) { | |
406 | IA64_MCA_DEBUG("%s: SAL error record type %d retrieved. " | |
407 | "Record length = %ld\n", __FUNCTION__, sal_info_type, total_len); | |
408 | } | |
409 | *buffer = (u8 *) log_buffer; | |
410 | return total_len; | |
411 | } else { | |
412 | IA64_LOG_UNLOCK(sal_info_type); | |
413 | return 0; | |
414 | } | |
415 | } | |
416 | ||
417 | /* | |
418 | * ia64_mca_log_sal_error_record | |
419 | * | |
420 | * This function retrieves a specified error record type from SAL | |
421 | * and wakes up any processes waiting for error records. | |
422 | * | |
7f613c7d KO |
423 | * Inputs : sal_info_type (Type of error record MCA/CMC/CPE) |
424 | * FIXME: remove MCA and irq_safe. | |
1da177e4 LT |
425 | */ |
426 | static void | |
427 | ia64_mca_log_sal_error_record(int sal_info_type) | |
428 | { | |
429 | u8 *buffer; | |
430 | sal_log_record_header_t *rh; | |
431 | u64 size; | |
7f613c7d | 432 | int irq_safe = sal_info_type != SAL_INFO_TYPE_MCA; |
1da177e4 LT |
433 | #ifdef IA64_MCA_DEBUG_INFO |
434 | static const char * const rec_name[] = { "MCA", "INIT", "CMC", "CPE" }; | |
435 | #endif | |
436 | ||
437 | size = ia64_log_get(sal_info_type, &buffer, irq_safe); | |
438 | if (!size) | |
439 | return; | |
440 | ||
441 | salinfo_log_wakeup(sal_info_type, buffer, size, irq_safe); | |
442 | ||
443 | if (irq_safe) | |
444 | IA64_MCA_DEBUG("CPU %d: SAL log contains %s error record\n", | |
445 | smp_processor_id(), | |
446 | sal_info_type < ARRAY_SIZE(rec_name) ? rec_name[sal_info_type] : "UNKNOWN"); | |
447 | ||
448 | /* Clear logs from corrected errors in case there's no user-level logger */ | |
449 | rh = (sal_log_record_header_t *)buffer; | |
450 | if (rh->severity == sal_log_severity_corrected) | |
451 | ia64_sal_clear_state_info(sal_info_type); | |
452 | } | |
453 | ||
d2a28ad9 RA |
454 | /* |
455 | * search_mca_table | |
456 | * See if the MCA surfaced in an instruction range | |
457 | * that has been tagged as recoverable. | |
458 | * | |
459 | * Inputs | |
460 | * first First address range to check | |
461 | * last Last address range to check | |
462 | * ip Instruction pointer, address we are looking for | |
463 | * | |
464 | * Return value: | |
465 | * 1 on Success (in the table)/ 0 on Failure (not in the table) | |
466 | */ | |
467 | int | |
468 | search_mca_table (const struct mca_table_entry *first, | |
469 | const struct mca_table_entry *last, | |
470 | unsigned long ip) | |
471 | { | |
472 | const struct mca_table_entry *curr; | |
473 | u64 curr_start, curr_end; | |
474 | ||
475 | curr = first; | |
476 | while (curr <= last) { | |
477 | curr_start = (u64) &curr->start_addr + curr->start_addr; | |
478 | curr_end = (u64) &curr->end_addr + curr->end_addr; | |
479 | ||
480 | if ((ip >= curr_start) && (ip <= curr_end)) { | |
481 | return 1; | |
482 | } | |
483 | curr++; | |
484 | } | |
485 | return 0; | |
486 | } | |
487 | ||
488 | /* Given an address, look for it in the mca tables. */ | |
489 | int mca_recover_range(unsigned long addr) | |
490 | { | |
491 | extern struct mca_table_entry __start___mca_table[]; | |
492 | extern struct mca_table_entry __stop___mca_table[]; | |
493 | ||
494 | return search_mca_table(__start___mca_table, __stop___mca_table-1, addr); | |
495 | } | |
496 | EXPORT_SYMBOL_GPL(mca_recover_range); | |
497 | ||
1da177e4 LT |
498 | #ifdef CONFIG_ACPI |
499 | ||
55e59c51 | 500 | int cpe_vector = -1; |
ff741906 | 501 | int ia64_cpe_irq = -1; |
1da177e4 LT |
502 | |
503 | static irqreturn_t | |
7d12e780 | 504 | ia64_mca_cpe_int_handler (int cpe_irq, void *arg) |
1da177e4 LT |
505 | { |
506 | static unsigned long cpe_history[CPE_HISTORY_LENGTH]; | |
507 | static int index; | |
508 | static DEFINE_SPINLOCK(cpe_history_lock); | |
509 | ||
510 | IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n", | |
511 | __FUNCTION__, cpe_irq, smp_processor_id()); | |
512 | ||
513 | /* SAL spec states this should run w/ interrupts enabled */ | |
514 | local_irq_enable(); | |
515 | ||
1da177e4 LT |
516 | spin_lock(&cpe_history_lock); |
517 | if (!cpe_poll_enabled && cpe_vector >= 0) { | |
518 | ||
519 | int i, count = 1; /* we know 1 happened now */ | |
520 | unsigned long now = jiffies; | |
521 | ||
522 | for (i = 0; i < CPE_HISTORY_LENGTH; i++) { | |
523 | if (now - cpe_history[i] <= HZ) | |
524 | count++; | |
525 | } | |
526 | ||
527 | IA64_MCA_DEBUG(KERN_INFO "CPE threshold %d/%d\n", count, CPE_HISTORY_LENGTH); | |
528 | if (count >= CPE_HISTORY_LENGTH) { | |
529 | ||
530 | cpe_poll_enabled = 1; | |
531 | spin_unlock(&cpe_history_lock); | |
532 | disable_irq_nosync(local_vector_to_irq(IA64_CPE_VECTOR)); | |
533 | ||
534 | /* | |
535 | * Corrected errors will still be corrected, but | |
536 | * make sure there's a log somewhere that indicates | |
537 | * something is generating more than we can handle. | |
538 | */ | |
539 | printk(KERN_WARNING "WARNING: Switching to polling CPE handler; error records may be lost\n"); | |
540 | ||
541 | mod_timer(&cpe_poll_timer, jiffies + MIN_CPE_POLL_INTERVAL); | |
542 | ||
543 | /* lock already released, get out now */ | |
ddb4f0df | 544 | goto out; |
1da177e4 LT |
545 | } else { |
546 | cpe_history[index++] = now; | |
547 | if (index == CPE_HISTORY_LENGTH) | |
548 | index = 0; | |
549 | } | |
550 | } | |
551 | spin_unlock(&cpe_history_lock); | |
ddb4f0df HS |
552 | out: |
553 | /* Get the CPE error record and log it */ | |
554 | ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE); | |
555 | ||
1da177e4 LT |
556 | return IRQ_HANDLED; |
557 | } | |
558 | ||
559 | #endif /* CONFIG_ACPI */ | |
560 | ||
1da177e4 LT |
561 | #ifdef CONFIG_ACPI |
562 | /* | |
563 | * ia64_mca_register_cpev | |
564 | * | |
565 | * Register the corrected platform error vector with SAL. | |
566 | * | |
567 | * Inputs | |
568 | * cpev Corrected Platform Error Vector number | |
569 | * | |
570 | * Outputs | |
571 | * None | |
572 | */ | |
0881fc8d | 573 | static void __init |
1da177e4 LT |
574 | ia64_mca_register_cpev (int cpev) |
575 | { | |
576 | /* Register the CPE interrupt vector with SAL */ | |
577 | struct ia64_sal_retval isrv; | |
578 | ||
579 | isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_CPE_INT, SAL_MC_PARAM_MECHANISM_INT, cpev, 0, 0); | |
580 | if (isrv.status) { | |
581 | printk(KERN_ERR "Failed to register Corrected Platform " | |
582 | "Error interrupt vector with SAL (status %ld)\n", isrv.status); | |
583 | return; | |
584 | } | |
585 | ||
586 | IA64_MCA_DEBUG("%s: corrected platform error " | |
587 | "vector %#x registered\n", __FUNCTION__, cpev); | |
588 | } | |
589 | #endif /* CONFIG_ACPI */ | |
590 | ||
1da177e4 LT |
591 | /* |
592 | * ia64_mca_cmc_vector_setup | |
593 | * | |
594 | * Setup the corrected machine check vector register in the processor. | |
595 | * (The interrupt is masked on boot. ia64_mca_late_init unmask this.) | |
596 | * This function is invoked on a per-processor basis. | |
597 | * | |
598 | * Inputs | |
599 | * None | |
600 | * | |
601 | * Outputs | |
602 | * None | |
603 | */ | |
0881fc8d | 604 | void __cpuinit |
1da177e4 LT |
605 | ia64_mca_cmc_vector_setup (void) |
606 | { | |
607 | cmcv_reg_t cmcv; | |
608 | ||
609 | cmcv.cmcv_regval = 0; | |
610 | cmcv.cmcv_mask = 1; /* Mask/disable interrupt at first */ | |
611 | cmcv.cmcv_vector = IA64_CMC_VECTOR; | |
612 | ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval); | |
613 | ||
614 | IA64_MCA_DEBUG("%s: CPU %d corrected " | |
615 | "machine check vector %#x registered.\n", | |
616 | __FUNCTION__, smp_processor_id(), IA64_CMC_VECTOR); | |
617 | ||
618 | IA64_MCA_DEBUG("%s: CPU %d CMCV = %#016lx\n", | |
619 | __FUNCTION__, smp_processor_id(), ia64_getreg(_IA64_REG_CR_CMCV)); | |
620 | } | |
621 | ||
622 | /* | |
623 | * ia64_mca_cmc_vector_disable | |
624 | * | |
625 | * Mask the corrected machine check vector register in the processor. | |
626 | * This function is invoked on a per-processor basis. | |
627 | * | |
628 | * Inputs | |
629 | * dummy(unused) | |
630 | * | |
631 | * Outputs | |
632 | * None | |
633 | */ | |
634 | static void | |
635 | ia64_mca_cmc_vector_disable (void *dummy) | |
636 | { | |
637 | cmcv_reg_t cmcv; | |
638 | ||
639 | cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV); | |
640 | ||
641 | cmcv.cmcv_mask = 1; /* Mask/disable interrupt */ | |
642 | ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval); | |
643 | ||
644 | IA64_MCA_DEBUG("%s: CPU %d corrected " | |
645 | "machine check vector %#x disabled.\n", | |
646 | __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector); | |
647 | } | |
648 | ||
649 | /* | |
650 | * ia64_mca_cmc_vector_enable | |
651 | * | |
652 | * Unmask the corrected machine check vector register in the processor. | |
653 | * This function is invoked on a per-processor basis. | |
654 | * | |
655 | * Inputs | |
656 | * dummy(unused) | |
657 | * | |
658 | * Outputs | |
659 | * None | |
660 | */ | |
661 | static void | |
662 | ia64_mca_cmc_vector_enable (void *dummy) | |
663 | { | |
664 | cmcv_reg_t cmcv; | |
665 | ||
666 | cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV); | |
667 | ||
668 | cmcv.cmcv_mask = 0; /* Unmask/enable interrupt */ | |
669 | ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval); | |
670 | ||
671 | IA64_MCA_DEBUG("%s: CPU %d corrected " | |
672 | "machine check vector %#x enabled.\n", | |
673 | __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector); | |
674 | } | |
675 | ||
676 | /* | |
677 | * ia64_mca_cmc_vector_disable_keventd | |
678 | * | |
679 | * Called via keventd (smp_call_function() is not safe in interrupt context) to | |
680 | * disable the cmc interrupt vector. | |
681 | */ | |
682 | static void | |
6d5aefb8 | 683 | ia64_mca_cmc_vector_disable_keventd(struct work_struct *unused) |
1da177e4 LT |
684 | { |
685 | on_each_cpu(ia64_mca_cmc_vector_disable, NULL, 1, 0); | |
686 | } | |
687 | ||
688 | /* | |
689 | * ia64_mca_cmc_vector_enable_keventd | |
690 | * | |
691 | * Called via keventd (smp_call_function() is not safe in interrupt context) to | |
692 | * enable the cmc interrupt vector. | |
693 | */ | |
694 | static void | |
6d5aefb8 | 695 | ia64_mca_cmc_vector_enable_keventd(struct work_struct *unused) |
1da177e4 LT |
696 | { |
697 | on_each_cpu(ia64_mca_cmc_vector_enable, NULL, 1, 0); | |
698 | } | |
699 | ||
1da177e4 LT |
700 | /* |
701 | * ia64_mca_wakeup | |
702 | * | |
703 | * Send an inter-cpu interrupt to wake-up a particular cpu | |
704 | * and mark that cpu to be out of rendez. | |
705 | * | |
706 | * Inputs : cpuid | |
707 | * Outputs : None | |
708 | */ | |
709 | static void | |
710 | ia64_mca_wakeup(int cpu) | |
711 | { | |
712 | platform_send_ipi(cpu, IA64_MCA_WAKEUP_VECTOR, IA64_IPI_DM_INT, 0); | |
713 | ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE; | |
714 | ||
715 | } | |
716 | ||
717 | /* | |
718 | * ia64_mca_wakeup_all | |
719 | * | |
720 | * Wakeup all the cpus which have rendez'ed previously. | |
721 | * | |
722 | * Inputs : None | |
723 | * Outputs : None | |
724 | */ | |
725 | static void | |
726 | ia64_mca_wakeup_all(void) | |
727 | { | |
728 | int cpu; | |
729 | ||
730 | /* Clear the Rendez checkin flag for all cpus */ | |
ddf6d0a0 | 731 | for_each_online_cpu(cpu) { |
1da177e4 LT |
732 | if (ia64_mc_info.imi_rendez_checkin[cpu] == IA64_MCA_RENDEZ_CHECKIN_DONE) |
733 | ia64_mca_wakeup(cpu); | |
734 | } | |
735 | ||
736 | } | |
737 | ||
738 | /* | |
739 | * ia64_mca_rendez_interrupt_handler | |
740 | * | |
741 | * This is handler used to put slave processors into spinloop | |
742 | * while the monarch processor does the mca handling and later | |
743 | * wake each slave up once the monarch is done. | |
744 | * | |
745 | * Inputs : None | |
746 | * Outputs : None | |
747 | */ | |
748 | static irqreturn_t | |
7d12e780 | 749 | ia64_mca_rendez_int_handler(int rendez_irq, void *arg) |
1da177e4 LT |
750 | { |
751 | unsigned long flags; | |
752 | int cpu = smp_processor_id(); | |
958b166c KO |
753 | struct ia64_mca_notify_die nd = |
754 | { .sos = NULL, .monarch_cpu = &monarch_cpu }; | |
1da177e4 LT |
755 | |
756 | /* Mask all interrupts */ | |
757 | local_irq_save(flags); | |
7d12e780 DH |
758 | if (notify_die(DIE_MCA_RENDZVOUS_ENTER, "MCA", get_irq_regs(), |
759 | (long)&nd, 0, 0) == NOTIFY_STOP) | |
9138d581 | 760 | ia64_mca_spin(__FUNCTION__); |
1da177e4 LT |
761 | |
762 | ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_DONE; | |
763 | /* Register with the SAL monarch that the slave has | |
764 | * reached SAL | |
765 | */ | |
766 | ia64_sal_mc_rendez(); | |
767 | ||
7d12e780 DH |
768 | if (notify_die(DIE_MCA_RENDZVOUS_PROCESS, "MCA", get_irq_regs(), |
769 | (long)&nd, 0, 0) == NOTIFY_STOP) | |
9138d581 KO |
770 | ia64_mca_spin(__FUNCTION__); |
771 | ||
7f613c7d KO |
772 | /* Wait for the monarch cpu to exit. */ |
773 | while (monarch_cpu != -1) | |
774 | cpu_relax(); /* spin until monarch leaves */ | |
1da177e4 | 775 | |
7d12e780 DH |
776 | if (notify_die(DIE_MCA_RENDZVOUS_LEAVE, "MCA", get_irq_regs(), |
777 | (long)&nd, 0, 0) == NOTIFY_STOP) | |
9138d581 KO |
778 | ia64_mca_spin(__FUNCTION__); |
779 | ||
1da177e4 LT |
780 | /* Enable all interrupts */ |
781 | local_irq_restore(flags); | |
782 | return IRQ_HANDLED; | |
783 | } | |
784 | ||
785 | /* | |
786 | * ia64_mca_wakeup_int_handler | |
787 | * | |
788 | * The interrupt handler for processing the inter-cpu interrupt to the | |
789 | * slave cpu which was spinning in the rendez loop. | |
790 | * Since this spinning is done by turning off the interrupts and | |
791 | * polling on the wakeup-interrupt bit in the IRR, there is | |
792 | * nothing useful to be done in the handler. | |
793 | * | |
794 | * Inputs : wakeup_irq (Wakeup-interrupt bit) | |
795 | * arg (Interrupt handler specific argument) | |
1da177e4 LT |
796 | * Outputs : None |
797 | * | |
798 | */ | |
799 | static irqreturn_t | |
7d12e780 | 800 | ia64_mca_wakeup_int_handler(int wakeup_irq, void *arg) |
1da177e4 LT |
801 | { |
802 | return IRQ_HANDLED; | |
803 | } | |
804 | ||
1da177e4 LT |
805 | /* Function pointer for extra MCA recovery */ |
806 | int (*ia64_mca_ucmc_extension) | |
7f613c7d | 807 | (void*,struct ia64_sal_os_state*) |
1da177e4 LT |
808 | = NULL; |
809 | ||
810 | int | |
7f613c7d | 811 | ia64_reg_MCA_extension(int (*fn)(void *, struct ia64_sal_os_state *)) |
1da177e4 LT |
812 | { |
813 | if (ia64_mca_ucmc_extension) | |
814 | return 1; | |
815 | ||
816 | ia64_mca_ucmc_extension = fn; | |
817 | return 0; | |
818 | } | |
819 | ||
820 | void | |
821 | ia64_unreg_MCA_extension(void) | |
822 | { | |
823 | if (ia64_mca_ucmc_extension) | |
824 | ia64_mca_ucmc_extension = NULL; | |
825 | } | |
826 | ||
827 | EXPORT_SYMBOL(ia64_reg_MCA_extension); | |
828 | EXPORT_SYMBOL(ia64_unreg_MCA_extension); | |
829 | ||
7f613c7d KO |
830 | |
831 | static inline void | |
832 | copy_reg(const u64 *fr, u64 fnat, u64 *tr, u64 *tnat) | |
833 | { | |
834 | u64 fslot, tslot, nat; | |
835 | *tr = *fr; | |
836 | fslot = ((unsigned long)fr >> 3) & 63; | |
837 | tslot = ((unsigned long)tr >> 3) & 63; | |
838 | *tnat &= ~(1UL << tslot); | |
839 | nat = (fnat >> fslot) & 1; | |
840 | *tnat |= (nat << tslot); | |
841 | } | |
842 | ||
e9ac054d KO |
843 | /* Change the comm field on the MCA/INT task to include the pid that |
844 | * was interrupted, it makes for easier debugging. If that pid was 0 | |
845 | * (swapper or nested MCA/INIT) then use the start of the previous comm | |
846 | * field suffixed with its cpu. | |
847 | */ | |
848 | ||
849 | static void | |
36c8b586 | 850 | ia64_mca_modify_comm(const struct task_struct *previous_current) |
e9ac054d KO |
851 | { |
852 | char *p, comm[sizeof(current->comm)]; | |
853 | if (previous_current->pid) | |
854 | snprintf(comm, sizeof(comm), "%s %d", | |
855 | current->comm, previous_current->pid); | |
856 | else { | |
857 | int l; | |
858 | if ((p = strchr(previous_current->comm, ' '))) | |
859 | l = p - previous_current->comm; | |
860 | else | |
861 | l = strlen(previous_current->comm); | |
862 | snprintf(comm, sizeof(comm), "%s %*s %d", | |
863 | current->comm, l, previous_current->comm, | |
864 | task_thread_info(previous_current)->cpu); | |
865 | } | |
866 | memcpy(current->comm, comm, sizeof(current->comm)); | |
867 | } | |
868 | ||
7f613c7d KO |
869 | /* On entry to this routine, we are running on the per cpu stack, see |
870 | * mca_asm.h. The original stack has not been touched by this event. Some of | |
871 | * the original stack's registers will be in the RBS on this stack. This stack | |
872 | * also contains a partial pt_regs and switch_stack, the rest of the data is in | |
873 | * PAL minstate. | |
874 | * | |
875 | * The first thing to do is modify the original stack to look like a blocked | |
876 | * task so we can run backtrace on the original task. Also mark the per cpu | |
877 | * stack as current to ensure that we use the correct task state, it also means | |
878 | * that we can do backtrace on the MCA/INIT handler code itself. | |
879 | */ | |
880 | ||
36c8b586 | 881 | static struct task_struct * |
7f613c7d KO |
882 | ia64_mca_modify_original_stack(struct pt_regs *regs, |
883 | const struct switch_stack *sw, | |
884 | struct ia64_sal_os_state *sos, | |
885 | const char *type) | |
886 | { | |
e9ac054d | 887 | char *p; |
7f613c7d KO |
888 | ia64_va va; |
889 | extern char ia64_leave_kernel[]; /* Need asm address, not function descriptor */ | |
890 | const pal_min_state_area_t *ms = sos->pal_min_state; | |
36c8b586 | 891 | struct task_struct *previous_current; |
7f613c7d KO |
892 | struct pt_regs *old_regs; |
893 | struct switch_stack *old_sw; | |
894 | unsigned size = sizeof(struct pt_regs) + | |
895 | sizeof(struct switch_stack) + 16; | |
896 | u64 *old_bspstore, *old_bsp; | |
897 | u64 *new_bspstore, *new_bsp; | |
898 | u64 old_unat, old_rnat, new_rnat, nat; | |
899 | u64 slots, loadrs = regs->loadrs; | |
900 | u64 r12 = ms->pmsa_gr[12-1], r13 = ms->pmsa_gr[13-1]; | |
901 | u64 ar_bspstore = regs->ar_bspstore; | |
902 | u64 ar_bsp = regs->ar_bspstore + (loadrs >> 16); | |
903 | const u64 *bank; | |
904 | const char *msg; | |
905 | int cpu = smp_processor_id(); | |
906 | ||
907 | previous_current = curr_task(cpu); | |
908 | set_curr_task(cpu, current); | |
909 | if ((p = strchr(current->comm, ' '))) | |
910 | *p = '\0'; | |
911 | ||
912 | /* Best effort attempt to cope with MCA/INIT delivered while in | |
913 | * physical mode. | |
914 | */ | |
915 | regs->cr_ipsr = ms->pmsa_ipsr; | |
916 | if (ia64_psr(regs)->dt == 0) { | |
917 | va.l = r12; | |
918 | if (va.f.reg == 0) { | |
919 | va.f.reg = 7; | |
920 | r12 = va.l; | |
921 | } | |
922 | va.l = r13; | |
923 | if (va.f.reg == 0) { | |
924 | va.f.reg = 7; | |
925 | r13 = va.l; | |
926 | } | |
927 | } | |
928 | if (ia64_psr(regs)->rt == 0) { | |
929 | va.l = ar_bspstore; | |
930 | if (va.f.reg == 0) { | |
931 | va.f.reg = 7; | |
932 | ar_bspstore = va.l; | |
933 | } | |
934 | va.l = ar_bsp; | |
935 | if (va.f.reg == 0) { | |
936 | va.f.reg = 7; | |
937 | ar_bsp = va.l; | |
938 | } | |
939 | } | |
940 | ||
941 | /* mca_asm.S ia64_old_stack() cannot assume that the dirty registers | |
942 | * have been copied to the old stack, the old stack may fail the | |
943 | * validation tests below. So ia64_old_stack() must restore the dirty | |
944 | * registers from the new stack. The old and new bspstore probably | |
945 | * have different alignments, so loadrs calculated on the old bsp | |
946 | * cannot be used to restore from the new bsp. Calculate a suitable | |
947 | * loadrs for the new stack and save it in the new pt_regs, where | |
948 | * ia64_old_stack() can get it. | |
949 | */ | |
950 | old_bspstore = (u64 *)ar_bspstore; | |
951 | old_bsp = (u64 *)ar_bsp; | |
952 | slots = ia64_rse_num_regs(old_bspstore, old_bsp); | |
953 | new_bspstore = (u64 *)((u64)current + IA64_RBS_OFFSET); | |
954 | new_bsp = ia64_rse_skip_regs(new_bspstore, slots); | |
955 | regs->loadrs = (new_bsp - new_bspstore) * 8 << 16; | |
956 | ||
957 | /* Verify the previous stack state before we change it */ | |
958 | if (user_mode(regs)) { | |
959 | msg = "occurred in user space"; | |
e9ac054d KO |
960 | /* previous_current is guaranteed to be valid when the task was |
961 | * in user space, so ... | |
962 | */ | |
963 | ia64_mca_modify_comm(previous_current); | |
7f613c7d KO |
964 | goto no_mod; |
965 | } | |
d2a28ad9 RA |
966 | |
967 | if (!mca_recover_range(ms->pmsa_iip)) { | |
968 | if (r13 != sos->prev_IA64_KR_CURRENT) { | |
969 | msg = "inconsistent previous current and r13"; | |
970 | goto no_mod; | |
971 | } | |
972 | if ((r12 - r13) >= KERNEL_STACK_SIZE) { | |
973 | msg = "inconsistent r12 and r13"; | |
974 | goto no_mod; | |
975 | } | |
976 | if ((ar_bspstore - r13) >= KERNEL_STACK_SIZE) { | |
977 | msg = "inconsistent ar.bspstore and r13"; | |
978 | goto no_mod; | |
979 | } | |
980 | va.p = old_bspstore; | |
981 | if (va.f.reg < 5) { | |
982 | msg = "old_bspstore is in the wrong region"; | |
983 | goto no_mod; | |
984 | } | |
985 | if ((ar_bsp - r13) >= KERNEL_STACK_SIZE) { | |
986 | msg = "inconsistent ar.bsp and r13"; | |
987 | goto no_mod; | |
988 | } | |
989 | size += (ia64_rse_skip_regs(old_bspstore, slots) - old_bspstore) * 8; | |
990 | if (ar_bspstore + size > r12) { | |
991 | msg = "no room for blocked state"; | |
992 | goto no_mod; | |
993 | } | |
7f613c7d KO |
994 | } |
995 | ||
e9ac054d | 996 | ia64_mca_modify_comm(previous_current); |
7f613c7d KO |
997 | |
998 | /* Make the original task look blocked. First stack a struct pt_regs, | |
999 | * describing the state at the time of interrupt. mca_asm.S built a | |
1000 | * partial pt_regs, copy it and fill in the blanks using minstate. | |
1001 | */ | |
1002 | p = (char *)r12 - sizeof(*regs); | |
1003 | old_regs = (struct pt_regs *)p; | |
1004 | memcpy(old_regs, regs, sizeof(*regs)); | |
1005 | /* If ipsr.ic then use pmsa_{iip,ipsr,ifs}, else use | |
1006 | * pmsa_{xip,xpsr,xfs} | |
1007 | */ | |
1008 | if (ia64_psr(regs)->ic) { | |
1009 | old_regs->cr_iip = ms->pmsa_iip; | |
1010 | old_regs->cr_ipsr = ms->pmsa_ipsr; | |
1011 | old_regs->cr_ifs = ms->pmsa_ifs; | |
1012 | } else { | |
1013 | old_regs->cr_iip = ms->pmsa_xip; | |
1014 | old_regs->cr_ipsr = ms->pmsa_xpsr; | |
1015 | old_regs->cr_ifs = ms->pmsa_xfs; | |
1016 | } | |
1017 | old_regs->pr = ms->pmsa_pr; | |
1018 | old_regs->b0 = ms->pmsa_br0; | |
1019 | old_regs->loadrs = loadrs; | |
1020 | old_regs->ar_rsc = ms->pmsa_rsc; | |
1021 | old_unat = old_regs->ar_unat; | |
1022 | copy_reg(&ms->pmsa_gr[1-1], ms->pmsa_nat_bits, &old_regs->r1, &old_unat); | |
1023 | copy_reg(&ms->pmsa_gr[2-1], ms->pmsa_nat_bits, &old_regs->r2, &old_unat); | |
1024 | copy_reg(&ms->pmsa_gr[3-1], ms->pmsa_nat_bits, &old_regs->r3, &old_unat); | |
1025 | copy_reg(&ms->pmsa_gr[8-1], ms->pmsa_nat_bits, &old_regs->r8, &old_unat); | |
1026 | copy_reg(&ms->pmsa_gr[9-1], ms->pmsa_nat_bits, &old_regs->r9, &old_unat); | |
1027 | copy_reg(&ms->pmsa_gr[10-1], ms->pmsa_nat_bits, &old_regs->r10, &old_unat); | |
1028 | copy_reg(&ms->pmsa_gr[11-1], ms->pmsa_nat_bits, &old_regs->r11, &old_unat); | |
1029 | copy_reg(&ms->pmsa_gr[12-1], ms->pmsa_nat_bits, &old_regs->r12, &old_unat); | |
1030 | copy_reg(&ms->pmsa_gr[13-1], ms->pmsa_nat_bits, &old_regs->r13, &old_unat); | |
1031 | copy_reg(&ms->pmsa_gr[14-1], ms->pmsa_nat_bits, &old_regs->r14, &old_unat); | |
1032 | copy_reg(&ms->pmsa_gr[15-1], ms->pmsa_nat_bits, &old_regs->r15, &old_unat); | |
1033 | if (ia64_psr(old_regs)->bn) | |
1034 | bank = ms->pmsa_bank1_gr; | |
1035 | else | |
1036 | bank = ms->pmsa_bank0_gr; | |
1037 | copy_reg(&bank[16-16], ms->pmsa_nat_bits, &old_regs->r16, &old_unat); | |
1038 | copy_reg(&bank[17-16], ms->pmsa_nat_bits, &old_regs->r17, &old_unat); | |
1039 | copy_reg(&bank[18-16], ms->pmsa_nat_bits, &old_regs->r18, &old_unat); | |
1040 | copy_reg(&bank[19-16], ms->pmsa_nat_bits, &old_regs->r19, &old_unat); | |
1041 | copy_reg(&bank[20-16], ms->pmsa_nat_bits, &old_regs->r20, &old_unat); | |
1042 | copy_reg(&bank[21-16], ms->pmsa_nat_bits, &old_regs->r21, &old_unat); | |
1043 | copy_reg(&bank[22-16], ms->pmsa_nat_bits, &old_regs->r22, &old_unat); | |
1044 | copy_reg(&bank[23-16], ms->pmsa_nat_bits, &old_regs->r23, &old_unat); | |
1045 | copy_reg(&bank[24-16], ms->pmsa_nat_bits, &old_regs->r24, &old_unat); | |
1046 | copy_reg(&bank[25-16], ms->pmsa_nat_bits, &old_regs->r25, &old_unat); | |
1047 | copy_reg(&bank[26-16], ms->pmsa_nat_bits, &old_regs->r26, &old_unat); | |
1048 | copy_reg(&bank[27-16], ms->pmsa_nat_bits, &old_regs->r27, &old_unat); | |
1049 | copy_reg(&bank[28-16], ms->pmsa_nat_bits, &old_regs->r28, &old_unat); | |
1050 | copy_reg(&bank[29-16], ms->pmsa_nat_bits, &old_regs->r29, &old_unat); | |
1051 | copy_reg(&bank[30-16], ms->pmsa_nat_bits, &old_regs->r30, &old_unat); | |
1052 | copy_reg(&bank[31-16], ms->pmsa_nat_bits, &old_regs->r31, &old_unat); | |
1053 | ||
1054 | /* Next stack a struct switch_stack. mca_asm.S built a partial | |
1055 | * switch_stack, copy it and fill in the blanks using pt_regs and | |
1056 | * minstate. | |
1057 | * | |
1058 | * In the synthesized switch_stack, b0 points to ia64_leave_kernel, | |
1059 | * ar.pfs is set to 0. | |
1060 | * | |
1061 | * unwind.c::unw_unwind() does special processing for interrupt frames. | |
1062 | * It checks if the PRED_NON_SYSCALL predicate is set, if the predicate | |
1063 | * is clear then unw_unwind() does _not_ adjust bsp over pt_regs. Not | |
1064 | * that this is documented, of course. Set PRED_NON_SYSCALL in the | |
1065 | * switch_stack on the original stack so it will unwind correctly when | |
1066 | * unwind.c reads pt_regs. | |
1067 | * | |
1068 | * thread.ksp is updated to point to the synthesized switch_stack. | |
1069 | */ | |
1070 | p -= sizeof(struct switch_stack); | |
1071 | old_sw = (struct switch_stack *)p; | |
1072 | memcpy(old_sw, sw, sizeof(*sw)); | |
1073 | old_sw->caller_unat = old_unat; | |
1074 | old_sw->ar_fpsr = old_regs->ar_fpsr; | |
1075 | copy_reg(&ms->pmsa_gr[4-1], ms->pmsa_nat_bits, &old_sw->r4, &old_unat); | |
1076 | copy_reg(&ms->pmsa_gr[5-1], ms->pmsa_nat_bits, &old_sw->r5, &old_unat); | |
1077 | copy_reg(&ms->pmsa_gr[6-1], ms->pmsa_nat_bits, &old_sw->r6, &old_unat); | |
1078 | copy_reg(&ms->pmsa_gr[7-1], ms->pmsa_nat_bits, &old_sw->r7, &old_unat); | |
1079 | old_sw->b0 = (u64)ia64_leave_kernel; | |
1080 | old_sw->b1 = ms->pmsa_br1; | |
1081 | old_sw->ar_pfs = 0; | |
1082 | old_sw->ar_unat = old_unat; | |
1083 | old_sw->pr = old_regs->pr | (1UL << PRED_NON_SYSCALL); | |
1084 | previous_current->thread.ksp = (u64)p - 16; | |
1085 | ||
1086 | /* Finally copy the original stack's registers back to its RBS. | |
1087 | * Registers from ar.bspstore through ar.bsp at the time of the event | |
1088 | * are in the current RBS, copy them back to the original stack. The | |
1089 | * copy must be done register by register because the original bspstore | |
1090 | * and the current one have different alignments, so the saved RNAT | |
1091 | * data occurs at different places. | |
1092 | * | |
1093 | * mca_asm does cover, so the old_bsp already includes all registers at | |
1094 | * the time of MCA/INIT. It also does flushrs, so all registers before | |
1095 | * this function have been written to backing store on the MCA/INIT | |
1096 | * stack. | |
1097 | */ | |
1098 | new_rnat = ia64_get_rnat(ia64_rse_rnat_addr(new_bspstore)); | |
1099 | old_rnat = regs->ar_rnat; | |
1100 | while (slots--) { | |
1101 | if (ia64_rse_is_rnat_slot(new_bspstore)) { | |
1102 | new_rnat = ia64_get_rnat(new_bspstore++); | |
1103 | } | |
1104 | if (ia64_rse_is_rnat_slot(old_bspstore)) { | |
1105 | *old_bspstore++ = old_rnat; | |
1106 | old_rnat = 0; | |
1107 | } | |
1108 | nat = (new_rnat >> ia64_rse_slot_num(new_bspstore)) & 1UL; | |
1109 | old_rnat &= ~(1UL << ia64_rse_slot_num(old_bspstore)); | |
1110 | old_rnat |= (nat << ia64_rse_slot_num(old_bspstore)); | |
1111 | *old_bspstore++ = *new_bspstore++; | |
1112 | } | |
1113 | old_sw->ar_bspstore = (unsigned long)old_bspstore; | |
1114 | old_sw->ar_rnat = old_rnat; | |
1115 | ||
1116 | sos->prev_task = previous_current; | |
1117 | return previous_current; | |
1118 | ||
1119 | no_mod: | |
1120 | printk(KERN_INFO "cpu %d, %s %s, original stack not modified\n", | |
1121 | smp_processor_id(), type, msg); | |
1122 | return previous_current; | |
1123 | } | |
1124 | ||
1125 | /* The monarch/slave interaction is based on monarch_cpu and requires that all | |
1126 | * slaves have entered rendezvous before the monarch leaves. If any cpu has | |
1127 | * not entered rendezvous yet then wait a bit. The assumption is that any | |
1128 | * slave that has not rendezvoused after a reasonable time is never going to do | |
1129 | * so. In this context, slave includes cpus that respond to the MCA rendezvous | |
1130 | * interrupt, as well as cpus that receive the INIT slave event. | |
1131 | */ | |
1132 | ||
1133 | static void | |
356a5c1c | 1134 | ia64_wait_for_slaves(int monarch, const char *type) |
7f613c7d | 1135 | { |
9336b083 | 1136 | int c, wait = 0, missing = 0; |
7f613c7d KO |
1137 | for_each_online_cpu(c) { |
1138 | if (c == monarch) | |
1139 | continue; | |
1140 | if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) { | |
1141 | udelay(1000); /* short wait first */ | |
1142 | wait = 1; | |
1143 | break; | |
1144 | } | |
1145 | } | |
1146 | if (!wait) | |
9336b083 | 1147 | goto all_in; |
7f613c7d KO |
1148 | for_each_online_cpu(c) { |
1149 | if (c == monarch) | |
1150 | continue; | |
1151 | if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) { | |
1152 | udelay(5*1000000); /* wait 5 seconds for slaves (arbitrary) */ | |
9336b083 KO |
1153 | if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) |
1154 | missing = 1; | |
7f613c7d KO |
1155 | break; |
1156 | } | |
1157 | } | |
9336b083 KO |
1158 | if (!missing) |
1159 | goto all_in; | |
43ed3baf HS |
1160 | /* |
1161 | * Maybe slave(s) dead. Print buffered messages immediately. | |
1162 | */ | |
1163 | ia64_mlogbuf_finish(0); | |
1164 | mprintk(KERN_INFO "OS %s slave did not rendezvous on cpu", type); | |
9336b083 KO |
1165 | for_each_online_cpu(c) { |
1166 | if (c == monarch) | |
1167 | continue; | |
1168 | if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) | |
43ed3baf | 1169 | mprintk(" %d", c); |
9336b083 | 1170 | } |
43ed3baf | 1171 | mprintk("\n"); |
9336b083 KO |
1172 | return; |
1173 | ||
1174 | all_in: | |
43ed3baf | 1175 | mprintk(KERN_INFO "All OS %s slaves have reached rendezvous\n", type); |
9336b083 | 1176 | return; |
7f613c7d KO |
1177 | } |
1178 | ||
1da177e4 | 1179 | /* |
7f613c7d | 1180 | * ia64_mca_handler |
1da177e4 LT |
1181 | * |
1182 | * This is uncorrectable machine check handler called from OS_MCA | |
1183 | * dispatch code which is in turn called from SAL_CHECK(). | |
1184 | * This is the place where the core of OS MCA handling is done. | |
1185 | * Right now the logs are extracted and displayed in a well-defined | |
1186 | * format. This handler code is supposed to be run only on the | |
1187 | * monarch processor. Once the monarch is done with MCA handling | |
1188 | * further MCA logging is enabled by clearing logs. | |
1189 | * Monarch also has the duty of sending wakeup-IPIs to pull the | |
1190 | * slave processors out of rendezvous spinloop. | |
1da177e4 LT |
1191 | */ |
1192 | void | |
7f613c7d KO |
1193 | ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw, |
1194 | struct ia64_sal_os_state *sos) | |
1da177e4 | 1195 | { |
7f613c7d | 1196 | int recover, cpu = smp_processor_id(); |
36c8b586 | 1197 | struct task_struct *previous_current; |
958b166c KO |
1198 | struct ia64_mca_notify_die nd = |
1199 | { .sos = sos, .monarch_cpu = &monarch_cpu }; | |
7f613c7d | 1200 | |
43ed3baf HS |
1201 | mprintk(KERN_INFO "Entered OS MCA handler. PSP=%lx cpu=%d " |
1202 | "monarch=%ld\n", sos->proc_state_param, cpu, sos->monarch); | |
9336b083 | 1203 | |
7f613c7d KO |
1204 | previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "MCA"); |
1205 | monarch_cpu = cpu; | |
958b166c | 1206 | if (notify_die(DIE_MCA_MONARCH_ENTER, "MCA", regs, (long)&nd, 0, 0) |
9138d581 KO |
1207 | == NOTIFY_STOP) |
1208 | ia64_mca_spin(__FUNCTION__); | |
356a5c1c | 1209 | ia64_wait_for_slaves(cpu, "MCA"); |
7f613c7d KO |
1210 | |
1211 | /* Wakeup all the processors which are spinning in the rendezvous loop. | |
1212 | * They will leave SAL, then spin in the OS with interrupts disabled | |
1213 | * until this monarch cpu leaves the MCA handler. That gets control | |
1214 | * back to the OS so we can backtrace the other cpus, backtrace when | |
1215 | * spinning in SAL does not work. | |
1216 | */ | |
1217 | ia64_mca_wakeup_all(); | |
958b166c | 1218 | if (notify_die(DIE_MCA_MONARCH_PROCESS, "MCA", regs, (long)&nd, 0, 0) |
9138d581 KO |
1219 | == NOTIFY_STOP) |
1220 | ia64_mca_spin(__FUNCTION__); | |
1da177e4 LT |
1221 | |
1222 | /* Get the MCA error record and log it */ | |
1223 | ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA); | |
1224 | ||
618b206f RA |
1225 | /* MCA error recovery */ |
1226 | recover = (ia64_mca_ucmc_extension | |
1da177e4 LT |
1227 | && ia64_mca_ucmc_extension( |
1228 | IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA), | |
7f613c7d | 1229 | sos)); |
1da177e4 LT |
1230 | |
1231 | if (recover) { | |
1232 | sal_log_record_header_t *rh = IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA); | |
1233 | rh->severity = sal_log_severity_corrected; | |
1234 | ia64_sal_clear_state_info(SAL_INFO_TYPE_MCA); | |
7f613c7d | 1235 | sos->os_status = IA64_MCA_CORRECTED; |
43ed3baf HS |
1236 | } else { |
1237 | /* Dump buffered message to console */ | |
1238 | ia64_mlogbuf_finish(1); | |
45a98fc6 | 1239 | #ifdef CONFIG_KEXEC |
a7956113 ZN |
1240 | atomic_set(&kdump_in_progress, 1); |
1241 | monarch_cpu = -1; | |
1242 | #endif | |
1da177e4 | 1243 | } |
958b166c | 1244 | if (notify_die(DIE_MCA_MONARCH_LEAVE, "MCA", regs, (long)&nd, 0, recover) |
9138d581 KO |
1245 | == NOTIFY_STOP) |
1246 | ia64_mca_spin(__FUNCTION__); | |
1da177e4 | 1247 | |
7f613c7d KO |
1248 | set_curr_task(cpu, previous_current); |
1249 | monarch_cpu = -1; | |
1da177e4 LT |
1250 | } |
1251 | ||
6d5aefb8 DH |
1252 | static DECLARE_WORK(cmc_disable_work, ia64_mca_cmc_vector_disable_keventd); |
1253 | static DECLARE_WORK(cmc_enable_work, ia64_mca_cmc_vector_enable_keventd); | |
1da177e4 LT |
1254 | |
1255 | /* | |
1256 | * ia64_mca_cmc_int_handler | |
1257 | * | |
1258 | * This is corrected machine check interrupt handler. | |
1259 | * Right now the logs are extracted and displayed in a well-defined | |
1260 | * format. | |
1261 | * | |
1262 | * Inputs | |
1263 | * interrupt number | |
1264 | * client data arg ptr | |
1da177e4 LT |
1265 | * |
1266 | * Outputs | |
1267 | * None | |
1268 | */ | |
1269 | static irqreturn_t | |
7d12e780 | 1270 | ia64_mca_cmc_int_handler(int cmc_irq, void *arg) |
1da177e4 LT |
1271 | { |
1272 | static unsigned long cmc_history[CMC_HISTORY_LENGTH]; | |
1273 | static int index; | |
1274 | static DEFINE_SPINLOCK(cmc_history_lock); | |
1275 | ||
1276 | IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n", | |
1277 | __FUNCTION__, cmc_irq, smp_processor_id()); | |
1278 | ||
1279 | /* SAL spec states this should run w/ interrupts enabled */ | |
1280 | local_irq_enable(); | |
1281 | ||
1da177e4 LT |
1282 | spin_lock(&cmc_history_lock); |
1283 | if (!cmc_polling_enabled) { | |
1284 | int i, count = 1; /* we know 1 happened now */ | |
1285 | unsigned long now = jiffies; | |
1286 | ||
1287 | for (i = 0; i < CMC_HISTORY_LENGTH; i++) { | |
1288 | if (now - cmc_history[i] <= HZ) | |
1289 | count++; | |
1290 | } | |
1291 | ||
1292 | IA64_MCA_DEBUG(KERN_INFO "CMC threshold %d/%d\n", count, CMC_HISTORY_LENGTH); | |
1293 | if (count >= CMC_HISTORY_LENGTH) { | |
1294 | ||
1295 | cmc_polling_enabled = 1; | |
1296 | spin_unlock(&cmc_history_lock); | |
76e677e2 BS |
1297 | /* If we're being hit with CMC interrupts, we won't |
1298 | * ever execute the schedule_work() below. Need to | |
1299 | * disable CMC interrupts on this processor now. | |
1300 | */ | |
1301 | ia64_mca_cmc_vector_disable(NULL); | |
1da177e4 LT |
1302 | schedule_work(&cmc_disable_work); |
1303 | ||
1304 | /* | |
1305 | * Corrected errors will still be corrected, but | |
1306 | * make sure there's a log somewhere that indicates | |
1307 | * something is generating more than we can handle. | |
1308 | */ | |
1309 | printk(KERN_WARNING "WARNING: Switching to polling CMC handler; error records may be lost\n"); | |
1310 | ||
1311 | mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL); | |
1312 | ||
1313 | /* lock already released, get out now */ | |
ddb4f0df | 1314 | goto out; |
1da177e4 LT |
1315 | } else { |
1316 | cmc_history[index++] = now; | |
1317 | if (index == CMC_HISTORY_LENGTH) | |
1318 | index = 0; | |
1319 | } | |
1320 | } | |
1321 | spin_unlock(&cmc_history_lock); | |
ddb4f0df HS |
1322 | out: |
1323 | /* Get the CMC error record and log it */ | |
1324 | ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC); | |
1325 | ||
1da177e4 LT |
1326 | return IRQ_HANDLED; |
1327 | } | |
1328 | ||
1329 | /* | |
1330 | * ia64_mca_cmc_int_caller | |
1331 | * | |
1332 | * Triggered by sw interrupt from CMC polling routine. Calls | |
1333 | * real interrupt handler and either triggers a sw interrupt | |
1334 | * on the next cpu or does cleanup at the end. | |
1335 | * | |
1336 | * Inputs | |
1337 | * interrupt number | |
1338 | * client data arg ptr | |
1da177e4 LT |
1339 | * Outputs |
1340 | * handled | |
1341 | */ | |
1342 | static irqreturn_t | |
7d12e780 | 1343 | ia64_mca_cmc_int_caller(int cmc_irq, void *arg) |
1da177e4 LT |
1344 | { |
1345 | static int start_count = -1; | |
1346 | unsigned int cpuid; | |
1347 | ||
1348 | cpuid = smp_processor_id(); | |
1349 | ||
1350 | /* If first cpu, update count */ | |
1351 | if (start_count == -1) | |
1352 | start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CMC); | |
1353 | ||
7d12e780 | 1354 | ia64_mca_cmc_int_handler(cmc_irq, arg); |
1da177e4 LT |
1355 | |
1356 | for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++); | |
1357 | ||
1358 | if (cpuid < NR_CPUS) { | |
1359 | platform_send_ipi(cpuid, IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0); | |
1360 | } else { | |
1361 | /* If no log record, switch out of polling mode */ | |
1362 | if (start_count == IA64_LOG_COUNT(SAL_INFO_TYPE_CMC)) { | |
1363 | ||
1364 | printk(KERN_WARNING "Returning to interrupt driven CMC handler\n"); | |
1365 | schedule_work(&cmc_enable_work); | |
1366 | cmc_polling_enabled = 0; | |
1367 | ||
1368 | } else { | |
1369 | ||
1370 | mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL); | |
1371 | } | |
1372 | ||
1373 | start_count = -1; | |
1374 | } | |
1375 | ||
1376 | return IRQ_HANDLED; | |
1377 | } | |
1378 | ||
1379 | /* | |
1380 | * ia64_mca_cmc_poll | |
1381 | * | |
1382 | * Poll for Corrected Machine Checks (CMCs) | |
1383 | * | |
1384 | * Inputs : dummy(unused) | |
1385 | * Outputs : None | |
1386 | * | |
1387 | */ | |
1388 | static void | |
1389 | ia64_mca_cmc_poll (unsigned long dummy) | |
1390 | { | |
1391 | /* Trigger a CMC interrupt cascade */ | |
1392 | platform_send_ipi(first_cpu(cpu_online_map), IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0); | |
1393 | } | |
1394 | ||
1395 | /* | |
1396 | * ia64_mca_cpe_int_caller | |
1397 | * | |
1398 | * Triggered by sw interrupt from CPE polling routine. Calls | |
1399 | * real interrupt handler and either triggers a sw interrupt | |
1400 | * on the next cpu or does cleanup at the end. | |
1401 | * | |
1402 | * Inputs | |
1403 | * interrupt number | |
1404 | * client data arg ptr | |
1da177e4 LT |
1405 | * Outputs |
1406 | * handled | |
1407 | */ | |
1408 | #ifdef CONFIG_ACPI | |
1409 | ||
1410 | static irqreturn_t | |
7d12e780 | 1411 | ia64_mca_cpe_int_caller(int cpe_irq, void *arg) |
1da177e4 LT |
1412 | { |
1413 | static int start_count = -1; | |
1414 | static int poll_time = MIN_CPE_POLL_INTERVAL; | |
1415 | unsigned int cpuid; | |
1416 | ||
1417 | cpuid = smp_processor_id(); | |
1418 | ||
1419 | /* If first cpu, update count */ | |
1420 | if (start_count == -1) | |
1421 | start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CPE); | |
1422 | ||
7d12e780 | 1423 | ia64_mca_cpe_int_handler(cpe_irq, arg); |
1da177e4 LT |
1424 | |
1425 | for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++); | |
1426 | ||
1427 | if (cpuid < NR_CPUS) { | |
1428 | platform_send_ipi(cpuid, IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0); | |
1429 | } else { | |
1430 | /* | |
1431 | * If a log was recorded, increase our polling frequency, | |
1432 | * otherwise, backoff or return to interrupt mode. | |
1433 | */ | |
1434 | if (start_count != IA64_LOG_COUNT(SAL_INFO_TYPE_CPE)) { | |
1435 | poll_time = max(MIN_CPE_POLL_INTERVAL, poll_time / 2); | |
1436 | } else if (cpe_vector < 0) { | |
1437 | poll_time = min(MAX_CPE_POLL_INTERVAL, poll_time * 2); | |
1438 | } else { | |
1439 | poll_time = MIN_CPE_POLL_INTERVAL; | |
1440 | ||
1441 | printk(KERN_WARNING "Returning to interrupt driven CPE handler\n"); | |
1442 | enable_irq(local_vector_to_irq(IA64_CPE_VECTOR)); | |
1443 | cpe_poll_enabled = 0; | |
1444 | } | |
1445 | ||
1446 | if (cpe_poll_enabled) | |
1447 | mod_timer(&cpe_poll_timer, jiffies + poll_time); | |
1448 | start_count = -1; | |
1449 | } | |
1450 | ||
1451 | return IRQ_HANDLED; | |
1452 | } | |
1453 | ||
1da177e4 LT |
1454 | /* |
1455 | * ia64_mca_cpe_poll | |
1456 | * | |
1457 | * Poll for Corrected Platform Errors (CPEs), trigger interrupt | |
1458 | * on first cpu, from there it will trickle through all the cpus. | |
1459 | * | |
1460 | * Inputs : dummy(unused) | |
1461 | * Outputs : None | |
1462 | * | |
1463 | */ | |
1464 | static void | |
1465 | ia64_mca_cpe_poll (unsigned long dummy) | |
1466 | { | |
1467 | /* Trigger a CPE interrupt cascade */ | |
1468 | platform_send_ipi(first_cpu(cpu_online_map), IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0); | |
1469 | } | |
1470 | ||
b655913b PC |
1471 | #endif /* CONFIG_ACPI */ |
1472 | ||
9138d581 KO |
1473 | static int |
1474 | default_monarch_init_process(struct notifier_block *self, unsigned long val, void *data) | |
1475 | { | |
1476 | int c; | |
1477 | struct task_struct *g, *t; | |
1478 | if (val != DIE_INIT_MONARCH_PROCESS) | |
1479 | return NOTIFY_DONE; | |
311f594d JL |
1480 | #ifdef CONFIG_KEXEC |
1481 | if (atomic_read(&kdump_in_progress)) | |
1482 | return NOTIFY_DONE; | |
1483 | #endif | |
43ed3baf HS |
1484 | |
1485 | /* | |
1486 | * FIXME: mlogbuf will brim over with INIT stack dumps. | |
1487 | * To enable show_stack from INIT, we use oops_in_progress which should | |
1488 | * be used in real oops. This would cause something wrong after INIT. | |
1489 | */ | |
1490 | BREAK_LOGLEVEL(console_loglevel); | |
1491 | ia64_mlogbuf_dump_from_init(); | |
1492 | ||
9138d581 KO |
1493 | printk(KERN_ERR "Processes interrupted by INIT -"); |
1494 | for_each_online_cpu(c) { | |
1495 | struct ia64_sal_os_state *s; | |
1496 | t = __va(__per_cpu_mca[c] + IA64_MCA_CPU_INIT_STACK_OFFSET); | |
1497 | s = (struct ia64_sal_os_state *)((char *)t + MCA_SOS_OFFSET); | |
1498 | g = s->prev_task; | |
1499 | if (g) { | |
1500 | if (g->pid) | |
1501 | printk(" %d", g->pid); | |
1502 | else | |
1503 | printk(" %d (cpu %d task 0x%p)", g->pid, task_cpu(g), g); | |
1504 | } | |
1505 | } | |
1506 | printk("\n\n"); | |
1507 | if (read_trylock(&tasklist_lock)) { | |
1508 | do_each_thread (g, t) { | |
1509 | printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm); | |
1510 | show_stack(t, NULL); | |
1511 | } while_each_thread (g, t); | |
1512 | read_unlock(&tasklist_lock); | |
1513 | } | |
43ed3baf HS |
1514 | /* FIXME: This will not restore zapped printk locks. */ |
1515 | RESTORE_LOGLEVEL(console_loglevel); | |
9138d581 KO |
1516 | return NOTIFY_DONE; |
1517 | } | |
1518 | ||
1da177e4 LT |
1519 | /* |
1520 | * C portion of the OS INIT handler | |
1521 | * | |
7f613c7d | 1522 | * Called from ia64_os_init_dispatch |
1da177e4 | 1523 | * |
7f613c7d KO |
1524 | * Inputs: pointer to pt_regs where processor info was saved. SAL/OS state for |
1525 | * this event. This code is used for both monarch and slave INIT events, see | |
1526 | * sos->monarch. | |
1da177e4 | 1527 | * |
7f613c7d KO |
1528 | * All INIT events switch to the INIT stack and change the previous process to |
1529 | * blocked status. If one of the INIT events is the monarch then we are | |
1530 | * probably processing the nmi button/command. Use the monarch cpu to dump all | |
1531 | * the processes. The slave INIT events all spin until the monarch cpu | |
1532 | * returns. We can also get INIT slave events for MCA, in which case the MCA | |
1533 | * process is the monarch. | |
1da177e4 | 1534 | */ |
7f613c7d | 1535 | |
1da177e4 | 1536 | void |
7f613c7d KO |
1537 | ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw, |
1538 | struct ia64_sal_os_state *sos) | |
1da177e4 | 1539 | { |
7f613c7d KO |
1540 | static atomic_t slaves; |
1541 | static atomic_t monarchs; | |
36c8b586 | 1542 | struct task_struct *previous_current; |
9138d581 | 1543 | int cpu = smp_processor_id(); |
958b166c KO |
1544 | struct ia64_mca_notify_die nd = |
1545 | { .sos = sos, .monarch_cpu = &monarch_cpu }; | |
1da177e4 | 1546 | |
958b166c KO |
1547 | (void) notify_die(DIE_INIT_ENTER, "INIT", regs, (long)&nd, 0, 0); |
1548 | ||
43ed3baf | 1549 | mprintk(KERN_INFO "Entered OS INIT handler. PSP=%lx cpu=%d monarch=%ld\n", |
7f613c7d KO |
1550 | sos->proc_state_param, cpu, sos->monarch); |
1551 | salinfo_log_wakeup(SAL_INFO_TYPE_INIT, NULL, 0, 0); | |
1da177e4 | 1552 | |
7f613c7d KO |
1553 | previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "INIT"); |
1554 | sos->os_status = IA64_INIT_RESUME; | |
1555 | ||
1556 | /* FIXME: Workaround for broken proms that drive all INIT events as | |
1557 | * slaves. The last slave that enters is promoted to be a monarch. | |
1558 | * Remove this code in September 2006, that gives platforms a year to | |
1559 | * fix their proms and get their customers updated. | |
1da177e4 | 1560 | */ |
7f613c7d | 1561 | if (!sos->monarch && atomic_add_return(1, &slaves) == num_online_cpus()) { |
43ed3baf | 1562 | mprintk(KERN_WARNING "%s: Promoting cpu %d to monarch.\n", |
7f613c7d KO |
1563 | __FUNCTION__, cpu); |
1564 | atomic_dec(&slaves); | |
1565 | sos->monarch = 1; | |
1566 | } | |
1da177e4 | 1567 | |
7f613c7d KO |
1568 | /* FIXME: Workaround for broken proms that drive all INIT events as |
1569 | * monarchs. Second and subsequent monarchs are demoted to slaves. | |
1570 | * Remove this code in September 2006, that gives platforms a year to | |
1571 | * fix their proms and get their customers updated. | |
1572 | */ | |
1573 | if (sos->monarch && atomic_add_return(1, &monarchs) > 1) { | |
43ed3baf | 1574 | mprintk(KERN_WARNING "%s: Demoting cpu %d to slave.\n", |
7f613c7d KO |
1575 | __FUNCTION__, cpu); |
1576 | atomic_dec(&monarchs); | |
1577 | sos->monarch = 0; | |
1578 | } | |
1579 | ||
1580 | if (!sos->monarch) { | |
1581 | ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_INIT; | |
1582 | while (monarch_cpu == -1) | |
1583 | cpu_relax(); /* spin until monarch enters */ | |
958b166c | 1584 | if (notify_die(DIE_INIT_SLAVE_ENTER, "INIT", regs, (long)&nd, 0, 0) |
9138d581 KO |
1585 | == NOTIFY_STOP) |
1586 | ia64_mca_spin(__FUNCTION__); | |
958b166c | 1587 | if (notify_die(DIE_INIT_SLAVE_PROCESS, "INIT", regs, (long)&nd, 0, 0) |
9138d581 KO |
1588 | == NOTIFY_STOP) |
1589 | ia64_mca_spin(__FUNCTION__); | |
7f613c7d KO |
1590 | while (monarch_cpu != -1) |
1591 | cpu_relax(); /* spin until monarch leaves */ | |
958b166c | 1592 | if (notify_die(DIE_INIT_SLAVE_LEAVE, "INIT", regs, (long)&nd, 0, 0) |
9138d581 KO |
1593 | == NOTIFY_STOP) |
1594 | ia64_mca_spin(__FUNCTION__); | |
43ed3baf | 1595 | mprintk("Slave on cpu %d returning to normal service.\n", cpu); |
7f613c7d KO |
1596 | set_curr_task(cpu, previous_current); |
1597 | ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE; | |
1598 | atomic_dec(&slaves); | |
1599 | return; | |
1600 | } | |
1601 | ||
1602 | monarch_cpu = cpu; | |
958b166c | 1603 | if (notify_die(DIE_INIT_MONARCH_ENTER, "INIT", regs, (long)&nd, 0, 0) |
9138d581 KO |
1604 | == NOTIFY_STOP) |
1605 | ia64_mca_spin(__FUNCTION__); | |
7f613c7d KO |
1606 | |
1607 | /* | |
1608 | * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be | |
1609 | * generated via the BMC's command-line interface, but since the console is on the | |
1610 | * same serial line, the user will need some time to switch out of the BMC before | |
1611 | * the dump begins. | |
1612 | */ | |
43ed3baf | 1613 | mprintk("Delaying for 5 seconds...\n"); |
7f613c7d | 1614 | udelay(5*1000000); |
356a5c1c | 1615 | ia64_wait_for_slaves(cpu, "INIT"); |
9138d581 KO |
1616 | /* If nobody intercepts DIE_INIT_MONARCH_PROCESS then we drop through |
1617 | * to default_monarch_init_process() above and just print all the | |
1618 | * tasks. | |
1619 | */ | |
958b166c | 1620 | if (notify_die(DIE_INIT_MONARCH_PROCESS, "INIT", regs, (long)&nd, 0, 0) |
9138d581 KO |
1621 | == NOTIFY_STOP) |
1622 | ia64_mca_spin(__FUNCTION__); | |
958b166c | 1623 | if (notify_die(DIE_INIT_MONARCH_LEAVE, "INIT", regs, (long)&nd, 0, 0) |
9138d581 KO |
1624 | == NOTIFY_STOP) |
1625 | ia64_mca_spin(__FUNCTION__); | |
43ed3baf | 1626 | mprintk("\nINIT dump complete. Monarch on cpu %d returning to normal service.\n", cpu); |
7f613c7d KO |
1627 | atomic_dec(&monarchs); |
1628 | set_curr_task(cpu, previous_current); | |
1629 | monarch_cpu = -1; | |
1630 | return; | |
1da177e4 LT |
1631 | } |
1632 | ||
1633 | static int __init | |
1634 | ia64_mca_disable_cpe_polling(char *str) | |
1635 | { | |
1636 | cpe_poll_enabled = 0; | |
1637 | return 1; | |
1638 | } | |
1639 | ||
1640 | __setup("disable_cpe_poll", ia64_mca_disable_cpe_polling); | |
1641 | ||
1642 | static struct irqaction cmci_irqaction = { | |
1643 | .handler = ia64_mca_cmc_int_handler, | |
121a4226 | 1644 | .flags = IRQF_DISABLED, |
1da177e4 LT |
1645 | .name = "cmc_hndlr" |
1646 | }; | |
1647 | ||
1648 | static struct irqaction cmcp_irqaction = { | |
1649 | .handler = ia64_mca_cmc_int_caller, | |
121a4226 | 1650 | .flags = IRQF_DISABLED, |
1da177e4 LT |
1651 | .name = "cmc_poll" |
1652 | }; | |
1653 | ||
1654 | static struct irqaction mca_rdzv_irqaction = { | |
1655 | .handler = ia64_mca_rendez_int_handler, | |
121a4226 | 1656 | .flags = IRQF_DISABLED, |
1da177e4 LT |
1657 | .name = "mca_rdzv" |
1658 | }; | |
1659 | ||
1660 | static struct irqaction mca_wkup_irqaction = { | |
1661 | .handler = ia64_mca_wakeup_int_handler, | |
121a4226 | 1662 | .flags = IRQF_DISABLED, |
1da177e4 LT |
1663 | .name = "mca_wkup" |
1664 | }; | |
1665 | ||
1666 | #ifdef CONFIG_ACPI | |
1667 | static struct irqaction mca_cpe_irqaction = { | |
1668 | .handler = ia64_mca_cpe_int_handler, | |
121a4226 | 1669 | .flags = IRQF_DISABLED, |
1da177e4 LT |
1670 | .name = "cpe_hndlr" |
1671 | }; | |
1672 | ||
1673 | static struct irqaction mca_cpep_irqaction = { | |
1674 | .handler = ia64_mca_cpe_int_caller, | |
121a4226 | 1675 | .flags = IRQF_DISABLED, |
1da177e4 LT |
1676 | .name = "cpe_poll" |
1677 | }; | |
1678 | #endif /* CONFIG_ACPI */ | |
1679 | ||
7f613c7d KO |
1680 | /* Minimal format of the MCA/INIT stacks. The pseudo processes that run on |
1681 | * these stacks can never sleep, they cannot return from the kernel to user | |
1682 | * space, they do not appear in a normal ps listing. So there is no need to | |
1683 | * format most of the fields. | |
1684 | */ | |
1685 | ||
0881fc8d | 1686 | static void __cpuinit |
7f613c7d KO |
1687 | format_mca_init_stack(void *mca_data, unsigned long offset, |
1688 | const char *type, int cpu) | |
1689 | { | |
1690 | struct task_struct *p = (struct task_struct *)((char *)mca_data + offset); | |
1691 | struct thread_info *ti; | |
1692 | memset(p, 0, KERNEL_STACK_SIZE); | |
ab03591d | 1693 | ti = task_thread_info(p); |
7f613c7d KO |
1694 | ti->flags = _TIF_MCA_INIT; |
1695 | ti->preempt_count = 1; | |
1696 | ti->task = p; | |
1697 | ti->cpu = cpu; | |
f7e4217b | 1698 | p->stack = ti; |
7f613c7d | 1699 | p->state = TASK_UNINTERRUPTIBLE; |
4668f0cd | 1700 | cpu_set(cpu, p->cpus_allowed); |
7f613c7d KO |
1701 | INIT_LIST_HEAD(&p->tasks); |
1702 | p->parent = p->real_parent = p->group_leader = p; | |
1703 | INIT_LIST_HEAD(&p->children); | |
1704 | INIT_LIST_HEAD(&p->sibling); | |
1705 | strncpy(p->comm, type, sizeof(p->comm)-1); | |
1706 | } | |
1707 | ||
1da177e4 LT |
1708 | /* Do per-CPU MCA-related initialization. */ |
1709 | ||
0881fc8d | 1710 | void __cpuinit |
1da177e4 LT |
1711 | ia64_mca_cpu_init(void *cpu_data) |
1712 | { | |
1713 | void *pal_vaddr; | |
ff741906 | 1714 | static int first_time = 1; |
1da177e4 | 1715 | |
ff741906 | 1716 | if (first_time) { |
1da177e4 LT |
1717 | void *mca_data; |
1718 | int cpu; | |
1719 | ||
ff741906 | 1720 | first_time = 0; |
1da177e4 | 1721 | mca_data = alloc_bootmem(sizeof(struct ia64_mca_cpu) |
7f613c7d KO |
1722 | * NR_CPUS + KERNEL_STACK_SIZE); |
1723 | mca_data = (void *)(((unsigned long)mca_data + | |
1724 | KERNEL_STACK_SIZE - 1) & | |
1725 | (-KERNEL_STACK_SIZE)); | |
1da177e4 | 1726 | for (cpu = 0; cpu < NR_CPUS; cpu++) { |
7f613c7d KO |
1727 | format_mca_init_stack(mca_data, |
1728 | offsetof(struct ia64_mca_cpu, mca_stack), | |
1729 | "MCA", cpu); | |
1730 | format_mca_init_stack(mca_data, | |
1731 | offsetof(struct ia64_mca_cpu, init_stack), | |
1732 | "INIT", cpu); | |
1da177e4 LT |
1733 | __per_cpu_mca[cpu] = __pa(mca_data); |
1734 | mca_data += sizeof(struct ia64_mca_cpu); | |
1735 | } | |
1736 | } | |
1737 | ||
7f613c7d KO |
1738 | /* |
1739 | * The MCA info structure was allocated earlier and its | |
1740 | * physical address saved in __per_cpu_mca[cpu]. Copy that | |
1741 | * address * to ia64_mca_data so we can access it as a per-CPU | |
1742 | * variable. | |
1743 | */ | |
1da177e4 LT |
1744 | __get_cpu_var(ia64_mca_data) = __per_cpu_mca[smp_processor_id()]; |
1745 | ||
1746 | /* | |
1747 | * Stash away a copy of the PTE needed to map the per-CPU page. | |
1748 | * We may need it during MCA recovery. | |
1749 | */ | |
1750 | __get_cpu_var(ia64_mca_per_cpu_pte) = | |
1751 | pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL)); | |
1752 | ||
7f613c7d KO |
1753 | /* |
1754 | * Also, stash away a copy of the PAL address and the PTE | |
1755 | * needed to map it. | |
1756 | */ | |
1757 | pal_vaddr = efi_get_pal_addr(); | |
1da177e4 LT |
1758 | if (!pal_vaddr) |
1759 | return; | |
1760 | __get_cpu_var(ia64_mca_pal_base) = | |
1761 | GRANULEROUNDDOWN((unsigned long) pal_vaddr); | |
1762 | __get_cpu_var(ia64_mca_pal_pte) = pte_val(mk_pte_phys(__pa(pal_vaddr), | |
1763 | PAGE_KERNEL)); | |
1764 | } | |
1765 | ||
1766 | /* | |
1767 | * ia64_mca_init | |
1768 | * | |
1769 | * Do all the system level mca specific initialization. | |
1770 | * | |
1771 | * 1. Register spinloop and wakeup request interrupt vectors | |
1772 | * | |
1773 | * 2. Register OS_MCA handler entry point | |
1774 | * | |
1775 | * 3. Register OS_INIT handler entry point | |
1776 | * | |
1777 | * 4. Initialize MCA/CMC/INIT related log buffers maintained by the OS. | |
1778 | * | |
1779 | * Note that this initialization is done very early before some kernel | |
1780 | * services are available. | |
1781 | * | |
1782 | * Inputs : None | |
1783 | * | |
1784 | * Outputs : None | |
1785 | */ | |
1786 | void __init | |
1787 | ia64_mca_init(void) | |
1788 | { | |
7f613c7d KO |
1789 | ia64_fptr_t *init_hldlr_ptr_monarch = (ia64_fptr_t *)ia64_os_init_dispatch_monarch; |
1790 | ia64_fptr_t *init_hldlr_ptr_slave = (ia64_fptr_t *)ia64_os_init_dispatch_slave; | |
1da177e4 LT |
1791 | ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch; |
1792 | int i; | |
1793 | s64 rc; | |
1794 | struct ia64_sal_retval isrv; | |
1795 | u64 timeout = IA64_MCA_RENDEZ_TIMEOUT; /* platform specific */ | |
9138d581 KO |
1796 | static struct notifier_block default_init_monarch_nb = { |
1797 | .notifier_call = default_monarch_init_process, | |
1798 | .priority = 0/* we need to notified last */ | |
1799 | }; | |
1da177e4 LT |
1800 | |
1801 | IA64_MCA_DEBUG("%s: begin\n", __FUNCTION__); | |
1802 | ||
1803 | /* Clear the Rendez checkin flag for all cpus */ | |
1804 | for(i = 0 ; i < NR_CPUS; i++) | |
1805 | ia64_mc_info.imi_rendez_checkin[i] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE; | |
1806 | ||
1807 | /* | |
1808 | * Register the rendezvous spinloop and wakeup mechanism with SAL | |
1809 | */ | |
1810 | ||
1811 | /* Register the rendezvous interrupt vector with SAL */ | |
1812 | while (1) { | |
1813 | isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_INT, | |
1814 | SAL_MC_PARAM_MECHANISM_INT, | |
1815 | IA64_MCA_RENDEZ_VECTOR, | |
1816 | timeout, | |
1817 | SAL_MC_PARAM_RZ_ALWAYS); | |
1818 | rc = isrv.status; | |
1819 | if (rc == 0) | |
1820 | break; | |
1821 | if (rc == -2) { | |
1822 | printk(KERN_INFO "Increasing MCA rendezvous timeout from " | |
1823 | "%ld to %ld milliseconds\n", timeout, isrv.v0); | |
1824 | timeout = isrv.v0; | |
958b166c | 1825 | (void) notify_die(DIE_MCA_NEW_TIMEOUT, "MCA", NULL, timeout, 0, 0); |
1da177e4 LT |
1826 | continue; |
1827 | } | |
1828 | printk(KERN_ERR "Failed to register rendezvous interrupt " | |
1829 | "with SAL (status %ld)\n", rc); | |
1830 | return; | |
1831 | } | |
1832 | ||
1833 | /* Register the wakeup interrupt vector with SAL */ | |
1834 | isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_WAKEUP, | |
1835 | SAL_MC_PARAM_MECHANISM_INT, | |
1836 | IA64_MCA_WAKEUP_VECTOR, | |
1837 | 0, 0); | |
1838 | rc = isrv.status; | |
1839 | if (rc) { | |
1840 | printk(KERN_ERR "Failed to register wakeup interrupt with SAL " | |
1841 | "(status %ld)\n", rc); | |
1842 | return; | |
1843 | } | |
1844 | ||
1845 | IA64_MCA_DEBUG("%s: registered MCA rendezvous spinloop and wakeup mech.\n", __FUNCTION__); | |
1846 | ||
1847 | ia64_mc_info.imi_mca_handler = ia64_tpa(mca_hldlr_ptr->fp); | |
1848 | /* | |
1849 | * XXX - disable SAL checksum by setting size to 0; should be | |
1850 | * ia64_tpa(ia64_os_mca_dispatch_end) - ia64_tpa(ia64_os_mca_dispatch); | |
1851 | */ | |
1852 | ia64_mc_info.imi_mca_handler_size = 0; | |
1853 | ||
1854 | /* Register the os mca handler with SAL */ | |
1855 | if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_MCA, | |
1856 | ia64_mc_info.imi_mca_handler, | |
1857 | ia64_tpa(mca_hldlr_ptr->gp), | |
1858 | ia64_mc_info.imi_mca_handler_size, | |
1859 | 0, 0, 0))) | |
1860 | { | |
1861 | printk(KERN_ERR "Failed to register OS MCA handler with SAL " | |
1862 | "(status %ld)\n", rc); | |
1863 | return; | |
1864 | } | |
1865 | ||
1866 | IA64_MCA_DEBUG("%s: registered OS MCA handler with SAL at 0x%lx, gp = 0x%lx\n", __FUNCTION__, | |
1867 | ia64_mc_info.imi_mca_handler, ia64_tpa(mca_hldlr_ptr->gp)); | |
1868 | ||
1869 | /* | |
1870 | * XXX - disable SAL checksum by setting size to 0, should be | |
1871 | * size of the actual init handler in mca_asm.S. | |
1872 | */ | |
7f613c7d | 1873 | ia64_mc_info.imi_monarch_init_handler = ia64_tpa(init_hldlr_ptr_monarch->fp); |
1da177e4 | 1874 | ia64_mc_info.imi_monarch_init_handler_size = 0; |
7f613c7d | 1875 | ia64_mc_info.imi_slave_init_handler = ia64_tpa(init_hldlr_ptr_slave->fp); |
1da177e4 LT |
1876 | ia64_mc_info.imi_slave_init_handler_size = 0; |
1877 | ||
1878 | IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __FUNCTION__, | |
1879 | ia64_mc_info.imi_monarch_init_handler); | |
1880 | ||
1881 | /* Register the os init handler with SAL */ | |
1882 | if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_INIT, | |
1883 | ia64_mc_info.imi_monarch_init_handler, | |
1884 | ia64_tpa(ia64_getreg(_IA64_REG_GP)), | |
1885 | ia64_mc_info.imi_monarch_init_handler_size, | |
1886 | ia64_mc_info.imi_slave_init_handler, | |
1887 | ia64_tpa(ia64_getreg(_IA64_REG_GP)), | |
1888 | ia64_mc_info.imi_slave_init_handler_size))) | |
1889 | { | |
1890 | printk(KERN_ERR "Failed to register m/s INIT handlers with SAL " | |
1891 | "(status %ld)\n", rc); | |
1892 | return; | |
1893 | } | |
9138d581 KO |
1894 | if (register_die_notifier(&default_init_monarch_nb)) { |
1895 | printk(KERN_ERR "Failed to register default monarch INIT process\n"); | |
1896 | return; | |
1897 | } | |
1da177e4 LT |
1898 | |
1899 | IA64_MCA_DEBUG("%s: registered OS INIT handler with SAL\n", __FUNCTION__); | |
1900 | ||
1901 | /* | |
1902 | * Configure the CMCI/P vector and handler. Interrupts for CMC are | |
1903 | * per-processor, so AP CMC interrupts are setup in smp_callin() (smpboot.c). | |
1904 | */ | |
1905 | register_percpu_irq(IA64_CMC_VECTOR, &cmci_irqaction); | |
1906 | register_percpu_irq(IA64_CMCP_VECTOR, &cmcp_irqaction); | |
1907 | ia64_mca_cmc_vector_setup(); /* Setup vector on BSP */ | |
1908 | ||
1909 | /* Setup the MCA rendezvous interrupt vector */ | |
1910 | register_percpu_irq(IA64_MCA_RENDEZ_VECTOR, &mca_rdzv_irqaction); | |
1911 | ||
1912 | /* Setup the MCA wakeup interrupt vector */ | |
1913 | register_percpu_irq(IA64_MCA_WAKEUP_VECTOR, &mca_wkup_irqaction); | |
1914 | ||
1915 | #ifdef CONFIG_ACPI | |
bb68c12b | 1916 | /* Setup the CPEI/P handler */ |
1da177e4 LT |
1917 | register_percpu_irq(IA64_CPEP_VECTOR, &mca_cpep_irqaction); |
1918 | #endif | |
1919 | ||
1920 | /* Initialize the areas set aside by the OS to buffer the | |
1921 | * platform/processor error states for MCA/INIT/CMC | |
1922 | * handling. | |
1923 | */ | |
1924 | ia64_log_init(SAL_INFO_TYPE_MCA); | |
1925 | ia64_log_init(SAL_INFO_TYPE_INIT); | |
1926 | ia64_log_init(SAL_INFO_TYPE_CMC); | |
1927 | ia64_log_init(SAL_INFO_TYPE_CPE); | |
1928 | ||
1929 | mca_init = 1; | |
1930 | printk(KERN_INFO "MCA related initialization done\n"); | |
1931 | } | |
1932 | ||
1933 | /* | |
1934 | * ia64_mca_late_init | |
1935 | * | |
1936 | * Opportunity to setup things that require initialization later | |
1937 | * than ia64_mca_init. Setup a timer to poll for CPEs if the | |
1938 | * platform doesn't support an interrupt driven mechanism. | |
1939 | * | |
1940 | * Inputs : None | |
1941 | * Outputs : Status | |
1942 | */ | |
1943 | static int __init | |
1944 | ia64_mca_late_init(void) | |
1945 | { | |
1946 | if (!mca_init) | |
1947 | return 0; | |
1948 | ||
1949 | /* Setup the CMCI/P vector and handler */ | |
1950 | init_timer(&cmc_poll_timer); | |
1951 | cmc_poll_timer.function = ia64_mca_cmc_poll; | |
1952 | ||
1953 | /* Unmask/enable the vector */ | |
1954 | cmc_polling_enabled = 0; | |
1955 | schedule_work(&cmc_enable_work); | |
1956 | ||
1957 | IA64_MCA_DEBUG("%s: CMCI/P setup and enabled.\n", __FUNCTION__); | |
1958 | ||
1959 | #ifdef CONFIG_ACPI | |
1960 | /* Setup the CPEI/P vector and handler */ | |
bb68c12b | 1961 | cpe_vector = acpi_request_vector(ACPI_INTERRUPT_CPEI); |
1da177e4 LT |
1962 | init_timer(&cpe_poll_timer); |
1963 | cpe_poll_timer.function = ia64_mca_cpe_poll; | |
1964 | ||
1965 | { | |
1966 | irq_desc_t *desc; | |
1967 | unsigned int irq; | |
1968 | ||
1969 | if (cpe_vector >= 0) { | |
1970 | /* If platform supports CPEI, enable the irq. */ | |
1971 | cpe_poll_enabled = 0; | |
1972 | for (irq = 0; irq < NR_IRQS; ++irq) | |
1973 | if (irq_to_vector(irq) == cpe_vector) { | |
a8553acd | 1974 | desc = irq_desc + irq; |
1da177e4 LT |
1975 | desc->status |= IRQ_PER_CPU; |
1976 | setup_irq(irq, &mca_cpe_irqaction); | |
ff741906 | 1977 | ia64_cpe_irq = irq; |
1da177e4 LT |
1978 | } |
1979 | ia64_mca_register_cpev(cpe_vector); | |
1980 | IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n", __FUNCTION__); | |
1981 | } else { | |
1982 | /* If platform doesn't support CPEI, get the timer going. */ | |
1983 | if (cpe_poll_enabled) { | |
1984 | ia64_mca_cpe_poll(0UL); | |
1985 | IA64_MCA_DEBUG("%s: CPEP setup and enabled.\n", __FUNCTION__); | |
1986 | } | |
1987 | } | |
1988 | } | |
1989 | #endif | |
1990 | ||
1991 | return 0; | |
1992 | } | |
1993 | ||
1994 | device_initcall(ia64_mca_late_init); |