blob: 338dbb8c2cfcb1ebe081165be2463ec64b53a43b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * File: mca.c
3 * Purpose: Generic MCA handling layer
4 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Copyright (C) 2003 Hewlett-Packard Co
6 * David Mosberger-Tang <davidm@hpl.hp.com>
7 *
8 * Copyright (C) 2002 Dell Inc.
Hidetoshi Setofe77efb2008-01-07 10:11:57 +09009 * Copyright (C) Matt Domsch <Matt_Domsch@dell.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * Copyright (C) 2002 Intel
Hidetoshi Setofe77efb2008-01-07 10:11:57 +090012 * Copyright (C) Jenna Hall <jenna.s.hall@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
14 * Copyright (C) 2001 Intel
Hidetoshi Setofe77efb2008-01-07 10:11:57 +090015 * Copyright (C) Fred Lewis <frederick.v.lewis@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 *
17 * Copyright (C) 2000 Intel
Hidetoshi Setofe77efb2008-01-07 10:11:57 +090018 * Copyright (C) Chuck Fleckenstein <cfleck@co.intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 *
Russ Anderson785285f2008-02-05 17:12:32 -060020 * Copyright (C) 1999, 2004-2008 Silicon Graphics, Inc.
Hidetoshi Setofe77efb2008-01-07 10:11:57 +090021 * Copyright (C) Vijay Chander <vijay@engr.sgi.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
Hidetoshi Setofe77efb2008-01-07 10:11:57 +090023 * Copyright (C) 2006 FUJITSU LIMITED
24 * Copyright (C) Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 *
Hidetoshi Setofe77efb2008-01-07 10:11:57 +090026 * 2000-03-29 Chuck Fleckenstein <cfleck@co.intel.com>
27 * Fixed PAL/SAL update issues, began MCA bug fixes, logging issues,
28 * added min save state dump, added INIT handler.
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 *
Hidetoshi Setofe77efb2008-01-07 10:11:57 +090030 * 2001-01-03 Fred Lewis <frederick.v.lewis@intel.com>
31 * Added setup of CMCI and CPEI IRQs, logging of corrected platform
32 * errors, completed code for logging of corrected & uncorrected
33 * machine check errors, and updated for conformance with Nov. 2000
34 * revision of the SAL 3.0 spec.
35 *
36 * 2002-01-04 Jenna Hall <jenna.s.hall@intel.com>
37 * Aligned MCA stack to 16 bytes, added platform vs. CPU error flag,
38 * set SAL default return values, changed error record structure to
39 * linked list, added init call to sal_get_state_info_size().
40 *
41 * 2002-03-25 Matt Domsch <Matt_Domsch@dell.com>
42 * GUID cleanups.
43 *
44 * 2003-04-15 David Mosberger-Tang <davidm@hpl.hp.com>
45 * Added INIT backtrace support.
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 *
47 * 2003-12-08 Keith Owens <kaos@sgi.com>
Hidetoshi Setofe77efb2008-01-07 10:11:57 +090048 * smp_call_function() must not be called from interrupt context
49 * (can deadlock on tasklist_lock).
50 * Use keventd to call smp_call_function().
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 *
52 * 2004-02-01 Keith Owens <kaos@sgi.com>
Hidetoshi Setofe77efb2008-01-07 10:11:57 +090053 * Avoid deadlock when using printk() for MCA and INIT records.
54 * Delete all record printing code, moved to salinfo_decode in user
55 * space. Mark variables and functions static where possible.
56 * Delete dead variables and functions. Reorder to remove the need
57 * for forward declarations and to consolidate related code.
Keith Owens7f613c72005-09-11 17:22:53 +100058 *
59 * 2005-08-12 Keith Owens <kaos@sgi.com>
Hidetoshi Setofe77efb2008-01-07 10:11:57 +090060 * Convert MCA/INIT handlers to use per event stacks and SAL/OS
61 * state.
Keith Owens9138d582005-11-07 11:27:13 -080062 *
63 * 2005-10-07 Keith Owens <kaos@sgi.com>
64 * Add notify_die() hooks.
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -070065 *
66 * 2006-09-15 Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Hidetoshi Setofe77efb2008-01-07 10:11:57 +090067 * Add printing support for MCA/INIT.
Russ Anderson1612b182007-05-18 17:17:17 -050068 *
69 * 2007-04-27 Russ Anderson <rja@sgi.com>
70 * Support multiple cpus going through OS_MCA in the same event.
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include <linux/types.h>
73#include <linux/init.h>
74#include <linux/sched.h>
75#include <linux/interrupt.h>
76#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#include <linux/bootmem.h>
78#include <linux/acpi.h>
79#include <linux/timer.h>
80#include <linux/module.h>
81#include <linux/kernel.h>
82#include <linux/smp.h>
83#include <linux/workqueue.h>
Akinobu Mita4668f0c2006-03-26 01:39:03 -080084#include <linux/cpumask.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070085#include <linux/kdebug.h>
Hidetoshi Setoed5d4022007-12-19 11:42:02 -080086#include <linux/cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88#include <asm/delay.h>
89#include <asm/machvec.h>
90#include <asm/meminit.h>
91#include <asm/page.h>
92#include <asm/ptrace.h>
93#include <asm/system.h>
94#include <asm/sal.h>
95#include <asm/mca.h>
Zou Nan haia7956112006-12-07 09:51:35 -080096#include <asm/kexec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98#include <asm/irq.h>
99#include <asm/hw_irq.h>
100
Russ Andersond2a28ad2006-03-24 09:49:52 -0800101#include "mca_drv.h"
Keith Owens7f613c72005-09-11 17:22:53 +1000102#include "entry.h"
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#if defined(IA64_MCA_DEBUG_INFO)
105# define IA64_MCA_DEBUG(fmt...) printk(fmt)
106#else
107# define IA64_MCA_DEBUG(fmt...)
108#endif
109
110/* Used by mca_asm.S */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111DEFINE_PER_CPU(u64, ia64_mca_data); /* == __per_cpu_mca[smp_processor_id()] */
112DEFINE_PER_CPU(u64, ia64_mca_per_cpu_pte); /* PTE to map per-CPU area */
113DEFINE_PER_CPU(u64, ia64_mca_pal_pte); /* PTE to map PAL code */
114DEFINE_PER_CPU(u64, ia64_mca_pal_base); /* vaddr PAL code granule */
115
116unsigned long __per_cpu_mca[NR_CPUS];
117
118/* In mca_asm.S */
Keith Owens7f613c72005-09-11 17:22:53 +1000119extern void ia64_os_init_dispatch_monarch (void);
120extern void ia64_os_init_dispatch_slave (void);
121
122static int monarch_cpu = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124static ia64_mc_info_t ia64_mc_info;
125
126#define MAX_CPE_POLL_INTERVAL (15*60*HZ) /* 15 minutes */
127#define MIN_CPE_POLL_INTERVAL (2*60*HZ) /* 2 minutes */
128#define CMC_POLL_INTERVAL (1*60*HZ) /* 1 minute */
129#define CPE_HISTORY_LENGTH 5
130#define CMC_HISTORY_LENGTH 5
131
Tony Luck34eac2a2007-05-10 13:20:19 -0700132#ifdef CONFIG_ACPI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133static struct timer_list cpe_poll_timer;
Tony Luck34eac2a2007-05-10 13:20:19 -0700134#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135static struct timer_list cmc_poll_timer;
136/*
137 * This variable tells whether we are currently in polling mode.
138 * Start with this in the wrong state so we won't play w/ timers
139 * before the system is ready.
140 */
141static int cmc_polling_enabled = 1;
142
143/*
144 * Clearing this variable prevents CPE polling from getting activated
145 * in mca_late_init. Use it if your system doesn't provide a CPEI,
146 * but encounters problems retrieving CPE logs. This should only be
147 * necessary for debugging.
148 */
149static int cpe_poll_enabled = 1;
150
151extern void salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe);
152
Chen, Kenneth W0881fc82006-03-12 08:52:20 -0800153static int mca_init __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700155/*
156 * limited & delayed printing support for MCA/INIT handler
157 */
158
159#define mprintk(fmt...) ia64_mca_printk(fmt)
160
161#define MLOGBUF_SIZE (512+256*NR_CPUS)
162#define MLOGBUF_MSGMAX 256
163static char mlogbuf[MLOGBUF_SIZE];
164static DEFINE_SPINLOCK(mlogbuf_wlock); /* mca context only */
165static DEFINE_SPINLOCK(mlogbuf_rlock); /* normal context only */
166static unsigned long mlogbuf_start;
167static unsigned long mlogbuf_end;
168static unsigned int mlogbuf_finished = 0;
169static unsigned long mlogbuf_timestamp = 0;
170
171static int loglevel_save = -1;
172#define BREAK_LOGLEVEL(__console_loglevel) \
173 oops_in_progress = 1; \
174 if (loglevel_save < 0) \
175 loglevel_save = __console_loglevel; \
176 __console_loglevel = 15;
177
178#define RESTORE_LOGLEVEL(__console_loglevel) \
179 if (loglevel_save >= 0) { \
180 __console_loglevel = loglevel_save; \
181 loglevel_save = -1; \
182 } \
183 mlogbuf_finished = 0; \
184 oops_in_progress = 0;
185
186/*
187 * Push messages into buffer, print them later if not urgent.
188 */
189void ia64_mca_printk(const char *fmt, ...)
190{
191 va_list args;
192 int printed_len;
193 char temp_buf[MLOGBUF_MSGMAX];
194 char *p;
195
196 va_start(args, fmt);
197 printed_len = vscnprintf(temp_buf, sizeof(temp_buf), fmt, args);
198 va_end(args);
199
200 /* Copy the output into mlogbuf */
201 if (oops_in_progress) {
202 /* mlogbuf was abandoned, use printk directly instead. */
203 printk(temp_buf);
204 } else {
205 spin_lock(&mlogbuf_wlock);
206 for (p = temp_buf; *p; p++) {
207 unsigned long next = (mlogbuf_end + 1) % MLOGBUF_SIZE;
208 if (next != mlogbuf_start) {
209 mlogbuf[mlogbuf_end] = *p;
210 mlogbuf_end = next;
211 } else {
212 /* buffer full */
213 break;
214 }
215 }
216 mlogbuf[mlogbuf_end] = '\0';
217 spin_unlock(&mlogbuf_wlock);
218 }
219}
220EXPORT_SYMBOL(ia64_mca_printk);
221
222/*
223 * Print buffered messages.
224 * NOTE: call this after returning normal context. (ex. from salinfod)
225 */
226void ia64_mlogbuf_dump(void)
227{
228 char temp_buf[MLOGBUF_MSGMAX];
229 char *p;
230 unsigned long index;
231 unsigned long flags;
232 unsigned int printed_len;
233
234 /* Get output from mlogbuf */
235 while (mlogbuf_start != mlogbuf_end) {
236 temp_buf[0] = '\0';
237 p = temp_buf;
238 printed_len = 0;
239
240 spin_lock_irqsave(&mlogbuf_rlock, flags);
241
242 index = mlogbuf_start;
243 while (index != mlogbuf_end) {
244 *p = mlogbuf[index];
245 index = (index + 1) % MLOGBUF_SIZE;
246 if (!*p)
247 break;
248 p++;
249 if (++printed_len >= MLOGBUF_MSGMAX - 1)
250 break;
251 }
252 *p = '\0';
253 if (temp_buf[0])
254 printk(temp_buf);
255 mlogbuf_start = index;
256
257 mlogbuf_timestamp = 0;
258 spin_unlock_irqrestore(&mlogbuf_rlock, flags);
259 }
260}
261EXPORT_SYMBOL(ia64_mlogbuf_dump);
262
263/*
264 * Call this if system is going to down or if immediate flushing messages to
265 * console is required. (ex. recovery was failed, crash dump is going to be
266 * invoked, long-wait rendezvous etc.)
267 * NOTE: this should be called from monarch.
268 */
269static void ia64_mlogbuf_finish(int wait)
270{
271 BREAK_LOGLEVEL(console_loglevel);
272
273 spin_lock_init(&mlogbuf_rlock);
274 ia64_mlogbuf_dump();
275 printk(KERN_EMERG "mlogbuf_finish: printing switched to urgent mode, "
276 "MCA/INIT might be dodgy or fail.\n");
277
278 if (!wait)
279 return;
280
281 /* wait for console */
282 printk("Delaying for 5 seconds...\n");
283 udelay(5*1000000);
284
285 mlogbuf_finished = 1;
286}
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700287
288/*
289 * Print buffered messages from INIT context.
290 */
291static void ia64_mlogbuf_dump_from_init(void)
292{
293 if (mlogbuf_finished)
294 return;
295
296 if (mlogbuf_timestamp && (mlogbuf_timestamp + 30*HZ > jiffies)) {
297 printk(KERN_ERR "INIT: mlogbuf_dump is interrupted by INIT "
298 " and the system seems to be messed up.\n");
299 ia64_mlogbuf_finish(0);
300 return;
301 }
302
303 if (!spin_trylock(&mlogbuf_rlock)) {
304 printk(KERN_ERR "INIT: mlogbuf_dump is interrupted by INIT. "
305 "Generated messages other than stack dump will be "
306 "buffered to mlogbuf and will be printed later.\n");
307 printk(KERN_ERR "INIT: If messages would not printed after "
308 "this INIT, wait 30sec and assert INIT again.\n");
309 if (!mlogbuf_timestamp)
310 mlogbuf_timestamp = jiffies;
311 return;
312 }
313 spin_unlock(&mlogbuf_rlock);
314 ia64_mlogbuf_dump();
315}
Keith Owens9138d582005-11-07 11:27:13 -0800316
317static void inline
318ia64_mca_spin(const char *func)
319{
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700320 if (monarch_cpu == smp_processor_id())
321 ia64_mlogbuf_finish(0);
322 mprintk(KERN_EMERG "%s: spinning here, not returning to SAL\n", func);
Keith Owens9138d582005-11-07 11:27:13 -0800323 while (1)
324 cpu_relax();
325}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326/*
327 * IA64_MCA log support
328 */
329#define IA64_MAX_LOGS 2 /* Double-buffering for nested MCAs */
330#define IA64_MAX_LOG_TYPES 4 /* MCA, INIT, CMC, CPE */
331
332typedef struct ia64_state_log_s
333{
334 spinlock_t isl_lock;
335 int isl_index;
336 unsigned long isl_count;
337 ia64_err_rec_t *isl_log[IA64_MAX_LOGS]; /* need space to store header + error log */
338} ia64_state_log_t;
339
340static ia64_state_log_t ia64_state_log[IA64_MAX_LOG_TYPES];
341
342#define IA64_LOG_ALLOCATE(it, size) \
343 {ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)] = \
344 (ia64_err_rec_t *)alloc_bootmem(size); \
345 ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)] = \
346 (ia64_err_rec_t *)alloc_bootmem(size);}
347#define IA64_LOG_LOCK_INIT(it) spin_lock_init(&ia64_state_log[it].isl_lock)
348#define IA64_LOG_LOCK(it) spin_lock_irqsave(&ia64_state_log[it].isl_lock, s)
349#define IA64_LOG_UNLOCK(it) spin_unlock_irqrestore(&ia64_state_log[it].isl_lock,s)
350#define IA64_LOG_NEXT_INDEX(it) ia64_state_log[it].isl_index
351#define IA64_LOG_CURR_INDEX(it) 1 - ia64_state_log[it].isl_index
352#define IA64_LOG_INDEX_INC(it) \
353 {ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index; \
354 ia64_state_log[it].isl_count++;}
355#define IA64_LOG_INDEX_DEC(it) \
356 ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index
357#define IA64_LOG_NEXT_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)]))
358#define IA64_LOG_CURR_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)]))
359#define IA64_LOG_COUNT(it) ia64_state_log[it].isl_count
360
361/*
362 * ia64_log_init
363 * Reset the OS ia64 log buffer
364 * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
365 * Outputs : None
366 */
Chen, Kenneth W0881fc82006-03-12 08:52:20 -0800367static void __init
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368ia64_log_init(int sal_info_type)
369{
370 u64 max_size = 0;
371
372 IA64_LOG_NEXT_INDEX(sal_info_type) = 0;
373 IA64_LOG_LOCK_INIT(sal_info_type);
374
375 // SAL will tell us the maximum size of any error record of this type
376 max_size = ia64_sal_get_state_info_size(sal_info_type);
377 if (!max_size)
378 /* alloc_bootmem() doesn't like zero-sized allocations! */
379 return;
380
381 // set up OS data structures to hold error info
382 IA64_LOG_ALLOCATE(sal_info_type, max_size);
383 memset(IA64_LOG_CURR_BUFFER(sal_info_type), 0, max_size);
384 memset(IA64_LOG_NEXT_BUFFER(sal_info_type), 0, max_size);
385}
386
387/*
388 * ia64_log_get
389 *
390 * Get the current MCA log from SAL and copy it into the OS log buffer.
391 *
392 * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
393 * irq_safe whether you can use printk at this point
394 * Outputs : size (total record length)
395 * *buffer (ptr to error record)
396 *
397 */
398static u64
399ia64_log_get(int sal_info_type, u8 **buffer, int irq_safe)
400{
401 sal_log_record_header_t *log_buffer;
402 u64 total_len = 0;
Alexey Dobriyanc53421b2006-09-30 23:27:37 -0700403 unsigned long s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 IA64_LOG_LOCK(sal_info_type);
406
407 /* Get the process state information */
408 log_buffer = IA64_LOG_NEXT_BUFFER(sal_info_type);
409
410 total_len = ia64_sal_get_state_info(sal_info_type, (u64 *)log_buffer);
411
412 if (total_len) {
413 IA64_LOG_INDEX_INC(sal_info_type);
414 IA64_LOG_UNLOCK(sal_info_type);
415 if (irq_safe) {
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800416 IA64_MCA_DEBUG("%s: SAL error record type %d retrieved. Record length = %ld\n",
417 __func__, sal_info_type, total_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 }
419 *buffer = (u8 *) log_buffer;
420 return total_len;
421 } else {
422 IA64_LOG_UNLOCK(sal_info_type);
423 return 0;
424 }
425}
426
427/*
428 * ia64_mca_log_sal_error_record
429 *
430 * This function retrieves a specified error record type from SAL
431 * and wakes up any processes waiting for error records.
432 *
Keith Owens7f613c72005-09-11 17:22:53 +1000433 * Inputs : sal_info_type (Type of error record MCA/CMC/CPE)
434 * FIXME: remove MCA and irq_safe.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 */
436static void
437ia64_mca_log_sal_error_record(int sal_info_type)
438{
439 u8 *buffer;
440 sal_log_record_header_t *rh;
441 u64 size;
Keith Owens7f613c72005-09-11 17:22:53 +1000442 int irq_safe = sal_info_type != SAL_INFO_TYPE_MCA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443#ifdef IA64_MCA_DEBUG_INFO
444 static const char * const rec_name[] = { "MCA", "INIT", "CMC", "CPE" };
445#endif
446
447 size = ia64_log_get(sal_info_type, &buffer, irq_safe);
448 if (!size)
449 return;
450
451 salinfo_log_wakeup(sal_info_type, buffer, size, irq_safe);
452
453 if (irq_safe)
454 IA64_MCA_DEBUG("CPU %d: SAL log contains %s error record\n",
455 smp_processor_id(),
456 sal_info_type < ARRAY_SIZE(rec_name) ? rec_name[sal_info_type] : "UNKNOWN");
457
458 /* Clear logs from corrected errors in case there's no user-level logger */
459 rh = (sal_log_record_header_t *)buffer;
460 if (rh->severity == sal_log_severity_corrected)
461 ia64_sal_clear_state_info(sal_info_type);
462}
463
Russ Andersond2a28ad2006-03-24 09:49:52 -0800464/*
465 * search_mca_table
466 * See if the MCA surfaced in an instruction range
467 * that has been tagged as recoverable.
468 *
469 * Inputs
470 * first First address range to check
471 * last Last address range to check
472 * ip Instruction pointer, address we are looking for
473 *
474 * Return value:
475 * 1 on Success (in the table)/ 0 on Failure (not in the table)
476 */
477int
478search_mca_table (const struct mca_table_entry *first,
479 const struct mca_table_entry *last,
480 unsigned long ip)
481{
482 const struct mca_table_entry *curr;
483 u64 curr_start, curr_end;
484
485 curr = first;
486 while (curr <= last) {
487 curr_start = (u64) &curr->start_addr + curr->start_addr;
488 curr_end = (u64) &curr->end_addr + curr->end_addr;
489
490 if ((ip >= curr_start) && (ip <= curr_end)) {
491 return 1;
492 }
493 curr++;
494 }
495 return 0;
496}
497
498/* Given an address, look for it in the mca tables. */
499int mca_recover_range(unsigned long addr)
500{
501 extern struct mca_table_entry __start___mca_table[];
502 extern struct mca_table_entry __stop___mca_table[];
503
504 return search_mca_table(__start___mca_table, __stop___mca_table-1, addr);
505}
506EXPORT_SYMBOL_GPL(mca_recover_range);
507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508#ifdef CONFIG_ACPI
509
Ashok Raj55e59c52005-03-31 22:51:10 -0500510int cpe_vector = -1;
Ashok Rajff741902005-11-11 14:32:40 -0800511int ia64_cpe_irq = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100514ia64_mca_cpe_int_handler (int cpe_irq, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
516 static unsigned long cpe_history[CPE_HISTORY_LENGTH];
517 static int index;
518 static DEFINE_SPINLOCK(cpe_history_lock);
519
520 IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800521 __func__, cpe_irq, smp_processor_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523 /* SAL spec states this should run w/ interrupts enabled */
524 local_irq_enable();
525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 spin_lock(&cpe_history_lock);
527 if (!cpe_poll_enabled && cpe_vector >= 0) {
528
529 int i, count = 1; /* we know 1 happened now */
530 unsigned long now = jiffies;
531
532 for (i = 0; i < CPE_HISTORY_LENGTH; i++) {
533 if (now - cpe_history[i] <= HZ)
534 count++;
535 }
536
537 IA64_MCA_DEBUG(KERN_INFO "CPE threshold %d/%d\n", count, CPE_HISTORY_LENGTH);
538 if (count >= CPE_HISTORY_LENGTH) {
539
540 cpe_poll_enabled = 1;
541 spin_unlock(&cpe_history_lock);
542 disable_irq_nosync(local_vector_to_irq(IA64_CPE_VECTOR));
543
544 /*
545 * Corrected errors will still be corrected, but
546 * make sure there's a log somewhere that indicates
547 * something is generating more than we can handle.
548 */
549 printk(KERN_WARNING "WARNING: Switching to polling CPE handler; error records may be lost\n");
550
551 mod_timer(&cpe_poll_timer, jiffies + MIN_CPE_POLL_INTERVAL);
552
553 /* lock already released, get out now */
Hidetoshi Setoddb4f0d2006-09-26 15:27:56 -0700554 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 } else {
556 cpe_history[index++] = now;
557 if (index == CPE_HISTORY_LENGTH)
558 index = 0;
559 }
560 }
561 spin_unlock(&cpe_history_lock);
Hidetoshi Setoddb4f0d2006-09-26 15:27:56 -0700562out:
563 /* Get the CPE error record and log it */
564 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE);
565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 return IRQ_HANDLED;
567}
568
569#endif /* CONFIG_ACPI */
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#ifdef CONFIG_ACPI
572/*
573 * ia64_mca_register_cpev
574 *
575 * Register the corrected platform error vector with SAL.
576 *
577 * Inputs
578 * cpev Corrected Platform Error Vector number
579 *
580 * Outputs
581 * None
582 */
Russ Anderson1f3b6042007-10-31 11:10:38 -0500583void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584ia64_mca_register_cpev (int cpev)
585{
586 /* Register the CPE interrupt vector with SAL */
587 struct ia64_sal_retval isrv;
588
589 isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_CPE_INT, SAL_MC_PARAM_MECHANISM_INT, cpev, 0, 0);
590 if (isrv.status) {
591 printk(KERN_ERR "Failed to register Corrected Platform "
592 "Error interrupt vector with SAL (status %ld)\n", isrv.status);
593 return;
594 }
595
596 IA64_MCA_DEBUG("%s: corrected platform error "
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800597 "vector %#x registered\n", __func__, cpev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598}
599#endif /* CONFIG_ACPI */
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601/*
602 * ia64_mca_cmc_vector_setup
603 *
604 * Setup the corrected machine check vector register in the processor.
605 * (The interrupt is masked on boot. ia64_mca_late_init unmask this.)
606 * This function is invoked on a per-processor basis.
607 *
608 * Inputs
609 * None
610 *
611 * Outputs
612 * None
613 */
Chen, Kenneth W0881fc82006-03-12 08:52:20 -0800614void __cpuinit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615ia64_mca_cmc_vector_setup (void)
616{
617 cmcv_reg_t cmcv;
618
619 cmcv.cmcv_regval = 0;
620 cmcv.cmcv_mask = 1; /* Mask/disable interrupt at first */
621 cmcv.cmcv_vector = IA64_CMC_VECTOR;
622 ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
623
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800624 IA64_MCA_DEBUG("%s: CPU %d corrected machine check vector %#x registered.\n",
625 __func__, smp_processor_id(), IA64_CMC_VECTOR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 IA64_MCA_DEBUG("%s: CPU %d CMCV = %#016lx\n",
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800628 __func__, smp_processor_id(), ia64_getreg(_IA64_REG_CR_CMCV));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629}
630
631/*
632 * ia64_mca_cmc_vector_disable
633 *
634 * Mask the corrected machine check vector register in the processor.
635 * This function is invoked on a per-processor basis.
636 *
637 * Inputs
638 * dummy(unused)
639 *
640 * Outputs
641 * None
642 */
643static void
644ia64_mca_cmc_vector_disable (void *dummy)
645{
646 cmcv_reg_t cmcv;
647
648 cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV);
649
650 cmcv.cmcv_mask = 1; /* Mask/disable interrupt */
651 ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
652
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800653 IA64_MCA_DEBUG("%s: CPU %d corrected machine check vector %#x disabled.\n",
654 __func__, smp_processor_id(), cmcv.cmcv_vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655}
656
657/*
658 * ia64_mca_cmc_vector_enable
659 *
660 * Unmask the corrected machine check vector register in the processor.
661 * This function is invoked on a per-processor basis.
662 *
663 * Inputs
664 * dummy(unused)
665 *
666 * Outputs
667 * None
668 */
669static void
670ia64_mca_cmc_vector_enable (void *dummy)
671{
672 cmcv_reg_t cmcv;
673
674 cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV);
675
676 cmcv.cmcv_mask = 0; /* Unmask/enable interrupt */
677 ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
678
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800679 IA64_MCA_DEBUG("%s: CPU %d corrected machine check vector %#x enabled.\n",
680 __func__, smp_processor_id(), cmcv.cmcv_vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
683/*
684 * ia64_mca_cmc_vector_disable_keventd
685 *
686 * Called via keventd (smp_call_function() is not safe in interrupt context) to
687 * disable the cmc interrupt vector.
688 */
689static void
David Howells6d5aefb2006-12-05 19:36:26 +0000690ia64_mca_cmc_vector_disable_keventd(struct work_struct *unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
692 on_each_cpu(ia64_mca_cmc_vector_disable, NULL, 1, 0);
693}
694
695/*
696 * ia64_mca_cmc_vector_enable_keventd
697 *
698 * Called via keventd (smp_call_function() is not safe in interrupt context) to
699 * enable the cmc interrupt vector.
700 */
701static void
David Howells6d5aefb2006-12-05 19:36:26 +0000702ia64_mca_cmc_vector_enable_keventd(struct work_struct *unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703{
704 on_each_cpu(ia64_mca_cmc_vector_enable, NULL, 1, 0);
705}
706
707/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 * ia64_mca_wakeup
709 *
Russ Andersone1b1eb02007-09-19 16:58:31 -0500710 * Send an inter-cpu interrupt to wake-up a particular cpu.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 *
712 * Inputs : cpuid
713 * Outputs : None
714 */
715static void
716ia64_mca_wakeup(int cpu)
717{
718 platform_send_ipi(cpu, IA64_MCA_WAKEUP_VECTOR, IA64_IPI_DM_INT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719}
720
721/*
722 * ia64_mca_wakeup_all
723 *
Russ Andersone1b1eb02007-09-19 16:58:31 -0500724 * Wakeup all the slave cpus which have rendez'ed previously.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 *
726 * Inputs : None
727 * Outputs : None
728 */
729static void
730ia64_mca_wakeup_all(void)
731{
732 int cpu;
733
734 /* Clear the Rendez checkin flag for all cpus */
hawkes@sgi.comddf6d0a2005-10-13 12:01:18 -0700735 for_each_online_cpu(cpu) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 if (ia64_mc_info.imi_rendez_checkin[cpu] == IA64_MCA_RENDEZ_CHECKIN_DONE)
737 ia64_mca_wakeup(cpu);
738 }
739
740}
741
742/*
743 * ia64_mca_rendez_interrupt_handler
744 *
745 * This is handler used to put slave processors into spinloop
746 * while the monarch processor does the mca handling and later
Russ Andersone1b1eb02007-09-19 16:58:31 -0500747 * wake each slave up once the monarch is done. The state
748 * IA64_MCA_RENDEZ_CHECKIN_DONE indicates the cpu is rendez'ed
749 * in SAL. The state IA64_MCA_RENDEZ_CHECKIN_NOTDONE indicates
750 * the cpu has come out of OS rendezvous.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 *
752 * Inputs : None
753 * Outputs : None
754 */
755static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100756ia64_mca_rendez_int_handler(int rendez_irq, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
758 unsigned long flags;
759 int cpu = smp_processor_id();
Keith Owens958b1662006-04-03 15:26:12 +1000760 struct ia64_mca_notify_die nd =
761 { .sos = NULL, .monarch_cpu = &monarch_cpu };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 /* Mask all interrupts */
764 local_irq_save(flags);
David Howells7d12e782006-10-05 14:55:46 +0100765 if (notify_die(DIE_MCA_RENDZVOUS_ENTER, "MCA", get_irq_regs(),
766 (long)&nd, 0, 0) == NOTIFY_STOP)
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800767 ia64_mca_spin(__func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_DONE;
770 /* Register with the SAL monarch that the slave has
771 * reached SAL
772 */
773 ia64_sal_mc_rendez();
774
David Howells7d12e782006-10-05 14:55:46 +0100775 if (notify_die(DIE_MCA_RENDZVOUS_PROCESS, "MCA", get_irq_regs(),
776 (long)&nd, 0, 0) == NOTIFY_STOP)
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800777 ia64_mca_spin(__func__);
Keith Owens9138d582005-11-07 11:27:13 -0800778
Keith Owens7f613c72005-09-11 17:22:53 +1000779 /* Wait for the monarch cpu to exit. */
780 while (monarch_cpu != -1)
781 cpu_relax(); /* spin until monarch leaves */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
David Howells7d12e782006-10-05 14:55:46 +0100783 if (notify_die(DIE_MCA_RENDZVOUS_LEAVE, "MCA", get_irq_regs(),
784 (long)&nd, 0, 0) == NOTIFY_STOP)
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800785 ia64_mca_spin(__func__);
Keith Owens9138d582005-11-07 11:27:13 -0800786
Russ Andersone1b1eb02007-09-19 16:58:31 -0500787 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 /* Enable all interrupts */
789 local_irq_restore(flags);
790 return IRQ_HANDLED;
791}
792
793/*
794 * ia64_mca_wakeup_int_handler
795 *
796 * The interrupt handler for processing the inter-cpu interrupt to the
797 * slave cpu which was spinning in the rendez loop.
798 * Since this spinning is done by turning off the interrupts and
799 * polling on the wakeup-interrupt bit in the IRR, there is
800 * nothing useful to be done in the handler.
801 *
802 * Inputs : wakeup_irq (Wakeup-interrupt bit)
803 * arg (Interrupt handler specific argument)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 * Outputs : None
805 *
806 */
807static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100808ia64_mca_wakeup_int_handler(int wakeup_irq, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809{
810 return IRQ_HANDLED;
811}
812
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813/* Function pointer for extra MCA recovery */
814int (*ia64_mca_ucmc_extension)
Keith Owens7f613c72005-09-11 17:22:53 +1000815 (void*,struct ia64_sal_os_state*)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 = NULL;
817
818int
Keith Owens7f613c72005-09-11 17:22:53 +1000819ia64_reg_MCA_extension(int (*fn)(void *, struct ia64_sal_os_state *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
821 if (ia64_mca_ucmc_extension)
822 return 1;
823
824 ia64_mca_ucmc_extension = fn;
825 return 0;
826}
827
828void
829ia64_unreg_MCA_extension(void)
830{
831 if (ia64_mca_ucmc_extension)
832 ia64_mca_ucmc_extension = NULL;
833}
834
835EXPORT_SYMBOL(ia64_reg_MCA_extension);
836EXPORT_SYMBOL(ia64_unreg_MCA_extension);
837
Keith Owens7f613c72005-09-11 17:22:53 +1000838
839static inline void
840copy_reg(const u64 *fr, u64 fnat, u64 *tr, u64 *tnat)
841{
842 u64 fslot, tslot, nat;
843 *tr = *fr;
844 fslot = ((unsigned long)fr >> 3) & 63;
845 tslot = ((unsigned long)tr >> 3) & 63;
846 *tnat &= ~(1UL << tslot);
847 nat = (fnat >> fslot) & 1;
848 *tnat |= (nat << tslot);
849}
850
Keith Owense9ac0542006-02-08 13:41:04 +1100851/* Change the comm field on the MCA/INT task to include the pid that
852 * was interrupted, it makes for easier debugging. If that pid was 0
853 * (swapper or nested MCA/INIT) then use the start of the previous comm
854 * field suffixed with its cpu.
855 */
856
857static void
Ingo Molnar36c8b582006-07-03 00:25:41 -0700858ia64_mca_modify_comm(const struct task_struct *previous_current)
Keith Owense9ac0542006-02-08 13:41:04 +1100859{
860 char *p, comm[sizeof(current->comm)];
861 if (previous_current->pid)
862 snprintf(comm, sizeof(comm), "%s %d",
863 current->comm, previous_current->pid);
864 else {
865 int l;
866 if ((p = strchr(previous_current->comm, ' ')))
867 l = p - previous_current->comm;
868 else
869 l = strlen(previous_current->comm);
870 snprintf(comm, sizeof(comm), "%s %*s %d",
871 current->comm, l, previous_current->comm,
872 task_thread_info(previous_current)->cpu);
873 }
874 memcpy(current->comm, comm, sizeof(current->comm));
875}
876
Keith Owens7f613c72005-09-11 17:22:53 +1000877/* On entry to this routine, we are running on the per cpu stack, see
878 * mca_asm.h. The original stack has not been touched by this event. Some of
879 * the original stack's registers will be in the RBS on this stack. This stack
880 * also contains a partial pt_regs and switch_stack, the rest of the data is in
881 * PAL minstate.
882 *
883 * The first thing to do is modify the original stack to look like a blocked
884 * task so we can run backtrace on the original task. Also mark the per cpu
885 * stack as current to ensure that we use the correct task state, it also means
886 * that we can do backtrace on the MCA/INIT handler code itself.
887 */
888
Ingo Molnar36c8b582006-07-03 00:25:41 -0700889static struct task_struct *
Keith Owens7f613c72005-09-11 17:22:53 +1000890ia64_mca_modify_original_stack(struct pt_regs *regs,
891 const struct switch_stack *sw,
892 struct ia64_sal_os_state *sos,
893 const char *type)
894{
Keith Owense9ac0542006-02-08 13:41:04 +1100895 char *p;
Keith Owens7f613c72005-09-11 17:22:53 +1000896 ia64_va va;
897 extern char ia64_leave_kernel[]; /* Need asm address, not function descriptor */
898 const pal_min_state_area_t *ms = sos->pal_min_state;
Ingo Molnar36c8b582006-07-03 00:25:41 -0700899 struct task_struct *previous_current;
Keith Owens7f613c72005-09-11 17:22:53 +1000900 struct pt_regs *old_regs;
901 struct switch_stack *old_sw;
902 unsigned size = sizeof(struct pt_regs) +
903 sizeof(struct switch_stack) + 16;
904 u64 *old_bspstore, *old_bsp;
905 u64 *new_bspstore, *new_bsp;
906 u64 old_unat, old_rnat, new_rnat, nat;
907 u64 slots, loadrs = regs->loadrs;
908 u64 r12 = ms->pmsa_gr[12-1], r13 = ms->pmsa_gr[13-1];
909 u64 ar_bspstore = regs->ar_bspstore;
910 u64 ar_bsp = regs->ar_bspstore + (loadrs >> 16);
911 const u64 *bank;
912 const char *msg;
913 int cpu = smp_processor_id();
914
915 previous_current = curr_task(cpu);
916 set_curr_task(cpu, current);
917 if ((p = strchr(current->comm, ' ')))
918 *p = '\0';
919
920 /* Best effort attempt to cope with MCA/INIT delivered while in
921 * physical mode.
922 */
923 regs->cr_ipsr = ms->pmsa_ipsr;
924 if (ia64_psr(regs)->dt == 0) {
925 va.l = r12;
926 if (va.f.reg == 0) {
927 va.f.reg = 7;
928 r12 = va.l;
929 }
930 va.l = r13;
931 if (va.f.reg == 0) {
932 va.f.reg = 7;
933 r13 = va.l;
934 }
935 }
936 if (ia64_psr(regs)->rt == 0) {
937 va.l = ar_bspstore;
938 if (va.f.reg == 0) {
939 va.f.reg = 7;
940 ar_bspstore = va.l;
941 }
942 va.l = ar_bsp;
943 if (va.f.reg == 0) {
944 va.f.reg = 7;
945 ar_bsp = va.l;
946 }
947 }
948
949 /* mca_asm.S ia64_old_stack() cannot assume that the dirty registers
950 * have been copied to the old stack, the old stack may fail the
951 * validation tests below. So ia64_old_stack() must restore the dirty
952 * registers from the new stack. The old and new bspstore probably
953 * have different alignments, so loadrs calculated on the old bsp
954 * cannot be used to restore from the new bsp. Calculate a suitable
955 * loadrs for the new stack and save it in the new pt_regs, where
956 * ia64_old_stack() can get it.
957 */
958 old_bspstore = (u64 *)ar_bspstore;
959 old_bsp = (u64 *)ar_bsp;
960 slots = ia64_rse_num_regs(old_bspstore, old_bsp);
961 new_bspstore = (u64 *)((u64)current + IA64_RBS_OFFSET);
962 new_bsp = ia64_rse_skip_regs(new_bspstore, slots);
963 regs->loadrs = (new_bsp - new_bspstore) * 8 << 16;
964
965 /* Verify the previous stack state before we change it */
966 if (user_mode(regs)) {
967 msg = "occurred in user space";
Keith Owense9ac0542006-02-08 13:41:04 +1100968 /* previous_current is guaranteed to be valid when the task was
969 * in user space, so ...
970 */
971 ia64_mca_modify_comm(previous_current);
Keith Owens7f613c72005-09-11 17:22:53 +1000972 goto no_mod;
973 }
Russ Andersond2a28ad2006-03-24 09:49:52 -0800974
Russ Anderson1612b182007-05-18 17:17:17 -0500975 if (r13 != sos->prev_IA64_KR_CURRENT) {
976 msg = "inconsistent previous current and r13";
977 goto no_mod;
978 }
979
Russ Andersond2a28ad2006-03-24 09:49:52 -0800980 if (!mca_recover_range(ms->pmsa_iip)) {
Russ Andersond2a28ad2006-03-24 09:49:52 -0800981 if ((r12 - r13) >= KERNEL_STACK_SIZE) {
982 msg = "inconsistent r12 and r13";
983 goto no_mod;
984 }
985 if ((ar_bspstore - r13) >= KERNEL_STACK_SIZE) {
986 msg = "inconsistent ar.bspstore and r13";
987 goto no_mod;
988 }
989 va.p = old_bspstore;
990 if (va.f.reg < 5) {
991 msg = "old_bspstore is in the wrong region";
992 goto no_mod;
993 }
994 if ((ar_bsp - r13) >= KERNEL_STACK_SIZE) {
995 msg = "inconsistent ar.bsp and r13";
996 goto no_mod;
997 }
998 size += (ia64_rse_skip_regs(old_bspstore, slots) - old_bspstore) * 8;
999 if (ar_bspstore + size > r12) {
1000 msg = "no room for blocked state";
1001 goto no_mod;
1002 }
Keith Owens7f613c72005-09-11 17:22:53 +10001003 }
1004
Keith Owense9ac0542006-02-08 13:41:04 +11001005 ia64_mca_modify_comm(previous_current);
Keith Owens7f613c72005-09-11 17:22:53 +10001006
1007 /* Make the original task look blocked. First stack a struct pt_regs,
1008 * describing the state at the time of interrupt. mca_asm.S built a
1009 * partial pt_regs, copy it and fill in the blanks using minstate.
1010 */
1011 p = (char *)r12 - sizeof(*regs);
1012 old_regs = (struct pt_regs *)p;
1013 memcpy(old_regs, regs, sizeof(*regs));
1014 /* If ipsr.ic then use pmsa_{iip,ipsr,ifs}, else use
1015 * pmsa_{xip,xpsr,xfs}
1016 */
1017 if (ia64_psr(regs)->ic) {
1018 old_regs->cr_iip = ms->pmsa_iip;
1019 old_regs->cr_ipsr = ms->pmsa_ipsr;
1020 old_regs->cr_ifs = ms->pmsa_ifs;
1021 } else {
1022 old_regs->cr_iip = ms->pmsa_xip;
1023 old_regs->cr_ipsr = ms->pmsa_xpsr;
1024 old_regs->cr_ifs = ms->pmsa_xfs;
1025 }
1026 old_regs->pr = ms->pmsa_pr;
1027 old_regs->b0 = ms->pmsa_br0;
1028 old_regs->loadrs = loadrs;
1029 old_regs->ar_rsc = ms->pmsa_rsc;
1030 old_unat = old_regs->ar_unat;
1031 copy_reg(&ms->pmsa_gr[1-1], ms->pmsa_nat_bits, &old_regs->r1, &old_unat);
1032 copy_reg(&ms->pmsa_gr[2-1], ms->pmsa_nat_bits, &old_regs->r2, &old_unat);
1033 copy_reg(&ms->pmsa_gr[3-1], ms->pmsa_nat_bits, &old_regs->r3, &old_unat);
1034 copy_reg(&ms->pmsa_gr[8-1], ms->pmsa_nat_bits, &old_regs->r8, &old_unat);
1035 copy_reg(&ms->pmsa_gr[9-1], ms->pmsa_nat_bits, &old_regs->r9, &old_unat);
1036 copy_reg(&ms->pmsa_gr[10-1], ms->pmsa_nat_bits, &old_regs->r10, &old_unat);
1037 copy_reg(&ms->pmsa_gr[11-1], ms->pmsa_nat_bits, &old_regs->r11, &old_unat);
1038 copy_reg(&ms->pmsa_gr[12-1], ms->pmsa_nat_bits, &old_regs->r12, &old_unat);
1039 copy_reg(&ms->pmsa_gr[13-1], ms->pmsa_nat_bits, &old_regs->r13, &old_unat);
1040 copy_reg(&ms->pmsa_gr[14-1], ms->pmsa_nat_bits, &old_regs->r14, &old_unat);
1041 copy_reg(&ms->pmsa_gr[15-1], ms->pmsa_nat_bits, &old_regs->r15, &old_unat);
1042 if (ia64_psr(old_regs)->bn)
1043 bank = ms->pmsa_bank1_gr;
1044 else
1045 bank = ms->pmsa_bank0_gr;
1046 copy_reg(&bank[16-16], ms->pmsa_nat_bits, &old_regs->r16, &old_unat);
1047 copy_reg(&bank[17-16], ms->pmsa_nat_bits, &old_regs->r17, &old_unat);
1048 copy_reg(&bank[18-16], ms->pmsa_nat_bits, &old_regs->r18, &old_unat);
1049 copy_reg(&bank[19-16], ms->pmsa_nat_bits, &old_regs->r19, &old_unat);
1050 copy_reg(&bank[20-16], ms->pmsa_nat_bits, &old_regs->r20, &old_unat);
1051 copy_reg(&bank[21-16], ms->pmsa_nat_bits, &old_regs->r21, &old_unat);
1052 copy_reg(&bank[22-16], ms->pmsa_nat_bits, &old_regs->r22, &old_unat);
1053 copy_reg(&bank[23-16], ms->pmsa_nat_bits, &old_regs->r23, &old_unat);
1054 copy_reg(&bank[24-16], ms->pmsa_nat_bits, &old_regs->r24, &old_unat);
1055 copy_reg(&bank[25-16], ms->pmsa_nat_bits, &old_regs->r25, &old_unat);
1056 copy_reg(&bank[26-16], ms->pmsa_nat_bits, &old_regs->r26, &old_unat);
1057 copy_reg(&bank[27-16], ms->pmsa_nat_bits, &old_regs->r27, &old_unat);
1058 copy_reg(&bank[28-16], ms->pmsa_nat_bits, &old_regs->r28, &old_unat);
1059 copy_reg(&bank[29-16], ms->pmsa_nat_bits, &old_regs->r29, &old_unat);
1060 copy_reg(&bank[30-16], ms->pmsa_nat_bits, &old_regs->r30, &old_unat);
1061 copy_reg(&bank[31-16], ms->pmsa_nat_bits, &old_regs->r31, &old_unat);
1062
1063 /* Next stack a struct switch_stack. mca_asm.S built a partial
1064 * switch_stack, copy it and fill in the blanks using pt_regs and
1065 * minstate.
1066 *
1067 * In the synthesized switch_stack, b0 points to ia64_leave_kernel,
1068 * ar.pfs is set to 0.
1069 *
1070 * unwind.c::unw_unwind() does special processing for interrupt frames.
1071 * It checks if the PRED_NON_SYSCALL predicate is set, if the predicate
1072 * is clear then unw_unwind() does _not_ adjust bsp over pt_regs. Not
1073 * that this is documented, of course. Set PRED_NON_SYSCALL in the
1074 * switch_stack on the original stack so it will unwind correctly when
1075 * unwind.c reads pt_regs.
1076 *
1077 * thread.ksp is updated to point to the synthesized switch_stack.
1078 */
1079 p -= sizeof(struct switch_stack);
1080 old_sw = (struct switch_stack *)p;
1081 memcpy(old_sw, sw, sizeof(*sw));
1082 old_sw->caller_unat = old_unat;
1083 old_sw->ar_fpsr = old_regs->ar_fpsr;
1084 copy_reg(&ms->pmsa_gr[4-1], ms->pmsa_nat_bits, &old_sw->r4, &old_unat);
1085 copy_reg(&ms->pmsa_gr[5-1], ms->pmsa_nat_bits, &old_sw->r5, &old_unat);
1086 copy_reg(&ms->pmsa_gr[6-1], ms->pmsa_nat_bits, &old_sw->r6, &old_unat);
1087 copy_reg(&ms->pmsa_gr[7-1], ms->pmsa_nat_bits, &old_sw->r7, &old_unat);
1088 old_sw->b0 = (u64)ia64_leave_kernel;
1089 old_sw->b1 = ms->pmsa_br1;
1090 old_sw->ar_pfs = 0;
1091 old_sw->ar_unat = old_unat;
1092 old_sw->pr = old_regs->pr | (1UL << PRED_NON_SYSCALL);
1093 previous_current->thread.ksp = (u64)p - 16;
1094
1095 /* Finally copy the original stack's registers back to its RBS.
1096 * Registers from ar.bspstore through ar.bsp at the time of the event
1097 * are in the current RBS, copy them back to the original stack. The
1098 * copy must be done register by register because the original bspstore
1099 * and the current one have different alignments, so the saved RNAT
1100 * data occurs at different places.
1101 *
1102 * mca_asm does cover, so the old_bsp already includes all registers at
1103 * the time of MCA/INIT. It also does flushrs, so all registers before
1104 * this function have been written to backing store on the MCA/INIT
1105 * stack.
1106 */
1107 new_rnat = ia64_get_rnat(ia64_rse_rnat_addr(new_bspstore));
1108 old_rnat = regs->ar_rnat;
1109 while (slots--) {
1110 if (ia64_rse_is_rnat_slot(new_bspstore)) {
1111 new_rnat = ia64_get_rnat(new_bspstore++);
1112 }
1113 if (ia64_rse_is_rnat_slot(old_bspstore)) {
1114 *old_bspstore++ = old_rnat;
1115 old_rnat = 0;
1116 }
1117 nat = (new_rnat >> ia64_rse_slot_num(new_bspstore)) & 1UL;
1118 old_rnat &= ~(1UL << ia64_rse_slot_num(old_bspstore));
1119 old_rnat |= (nat << ia64_rse_slot_num(old_bspstore));
1120 *old_bspstore++ = *new_bspstore++;
1121 }
1122 old_sw->ar_bspstore = (unsigned long)old_bspstore;
1123 old_sw->ar_rnat = old_rnat;
1124
1125 sos->prev_task = previous_current;
1126 return previous_current;
1127
1128no_mod:
1129 printk(KERN_INFO "cpu %d, %s %s, original stack not modified\n",
1130 smp_processor_id(), type, msg);
1131 return previous_current;
1132}
1133
1134/* The monarch/slave interaction is based on monarch_cpu and requires that all
1135 * slaves have entered rendezvous before the monarch leaves. If any cpu has
1136 * not entered rendezvous yet then wait a bit. The assumption is that any
1137 * slave that has not rendezvoused after a reasonable time is never going to do
1138 * so. In this context, slave includes cpus that respond to the MCA rendezvous
1139 * interrupt, as well as cpus that receive the INIT slave event.
1140 */
1141
1142static void
Keith Owens356a5c12006-04-11 14:59:41 +10001143ia64_wait_for_slaves(int monarch, const char *type)
Keith Owens7f613c72005-09-11 17:22:53 +10001144{
Russ Anderson2bc5c282007-09-20 13:59:12 -05001145 int c, i , wait;
1146
1147 /*
1148 * wait 5 seconds total for slaves (arbitrary)
1149 */
1150 for (i = 0; i < 5000; i++) {
1151 wait = 0;
1152 for_each_online_cpu(c) {
1153 if (c == monarch)
1154 continue;
1155 if (ia64_mc_info.imi_rendez_checkin[c]
1156 == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) {
1157 udelay(1000); /* short wait */
1158 wait = 1;
1159 break;
1160 }
Keith Owens7f613c72005-09-11 17:22:53 +10001161 }
Russ Anderson2bc5c282007-09-20 13:59:12 -05001162 if (!wait)
1163 goto all_in;
Keith Owens7f613c72005-09-11 17:22:53 +10001164 }
Russ Anderson2bc5c282007-09-20 13:59:12 -05001165
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001166 /*
1167 * Maybe slave(s) dead. Print buffered messages immediately.
1168 */
1169 ia64_mlogbuf_finish(0);
1170 mprintk(KERN_INFO "OS %s slave did not rendezvous on cpu", type);
Keith Owens9336b082006-02-08 13:40:59 +11001171 for_each_online_cpu(c) {
1172 if (c == monarch)
1173 continue;
1174 if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001175 mprintk(" %d", c);
Keith Owens9336b082006-02-08 13:40:59 +11001176 }
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001177 mprintk("\n");
Keith Owens9336b082006-02-08 13:40:59 +11001178 return;
1179
1180all_in:
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001181 mprintk(KERN_INFO "All OS %s slaves have reached rendezvous\n", type);
Keith Owens9336b082006-02-08 13:40:59 +11001182 return;
Keith Owens7f613c72005-09-11 17:22:53 +10001183}
1184
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185/*
Keith Owens7f613c72005-09-11 17:22:53 +10001186 * ia64_mca_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 *
1188 * This is uncorrectable machine check handler called from OS_MCA
1189 * dispatch code which is in turn called from SAL_CHECK().
1190 * This is the place where the core of OS MCA handling is done.
1191 * Right now the logs are extracted and displayed in a well-defined
1192 * format. This handler code is supposed to be run only on the
1193 * monarch processor. Once the monarch is done with MCA handling
1194 * further MCA logging is enabled by clearing logs.
1195 * Monarch also has the duty of sending wakeup-IPIs to pull the
1196 * slave processors out of rendezvous spinloop.
Russ Anderson1612b182007-05-18 17:17:17 -05001197 *
1198 * If multiple processors call into OS_MCA, the first will become
1199 * the monarch. Subsequent cpus will be recorded in the mca_cpu
1200 * bitmask. After the first monarch has processed its MCA, it
1201 * will wake up the next cpu in the mca_cpu bitmask and then go
1202 * into the rendezvous loop. When all processors have serviced
1203 * their MCA, the last monarch frees up the rest of the processors.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 */
1205void
Keith Owens7f613c72005-09-11 17:22:53 +10001206ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw,
1207 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208{
Keith Owens7f613c72005-09-11 17:22:53 +10001209 int recover, cpu = smp_processor_id();
Ingo Molnar36c8b582006-07-03 00:25:41 -07001210 struct task_struct *previous_current;
Keith Owens958b1662006-04-03 15:26:12 +10001211 struct ia64_mca_notify_die nd =
1212 { .sos = sos, .monarch_cpu = &monarch_cpu };
Russ Anderson1612b182007-05-18 17:17:17 -05001213 static atomic_t mca_count;
1214 static cpumask_t mca_cpu;
Keith Owens7f613c72005-09-11 17:22:53 +10001215
Russ Anderson1612b182007-05-18 17:17:17 -05001216 if (atomic_add_return(1, &mca_count) == 1) {
1217 monarch_cpu = cpu;
1218 sos->monarch = 1;
1219 } else {
1220 cpu_set(cpu, mca_cpu);
1221 sos->monarch = 0;
1222 }
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001223 mprintk(KERN_INFO "Entered OS MCA handler. PSP=%lx cpu=%d "
1224 "monarch=%ld\n", sos->proc_state_param, cpu, sos->monarch);
Keith Owens9336b082006-02-08 13:40:59 +11001225
Keith Owens7f613c72005-09-11 17:22:53 +10001226 previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "MCA");
Russ Anderson1612b182007-05-18 17:17:17 -05001227
Keith Owens958b1662006-04-03 15:26:12 +10001228 if (notify_die(DIE_MCA_MONARCH_ENTER, "MCA", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001229 == NOTIFY_STOP)
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001230 ia64_mca_spin(__func__);
Russ Andersone1b1eb02007-09-19 16:58:31 -05001231
1232 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_CONCURRENT_MCA;
Russ Anderson1612b182007-05-18 17:17:17 -05001233 if (sos->monarch) {
1234 ia64_wait_for_slaves(cpu, "MCA");
Russ Andersone1b1eb02007-09-19 16:58:31 -05001235
1236 /* Wakeup all the processors which are spinning in the
1237 * rendezvous loop. They will leave SAL, then spin in the OS
1238 * with interrupts disabled until this monarch cpu leaves the
1239 * MCA handler. That gets control back to the OS so we can
1240 * backtrace the other cpus, backtrace when spinning in SAL
1241 * does not work.
1242 */
1243 ia64_mca_wakeup_all();
1244 if (notify_die(DIE_MCA_MONARCH_PROCESS, "MCA", regs, (long)&nd, 0, 0)
1245 == NOTIFY_STOP)
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001246 ia64_mca_spin(__func__);
Russ Anderson1612b182007-05-18 17:17:17 -05001247 } else {
Russ Anderson1612b182007-05-18 17:17:17 -05001248 while (cpu_isset(cpu, mca_cpu))
1249 cpu_relax(); /* spin until monarch wakes us */
Russ Anderson1612b182007-05-18 17:17:17 -05001250 }
Keith Owens7f613c72005-09-11 17:22:53 +10001251
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 /* Get the MCA error record and log it */
1253 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA);
1254
Russ Anderson618b2062006-12-14 16:01:41 -06001255 /* MCA error recovery */
1256 recover = (ia64_mca_ucmc_extension
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 && ia64_mca_ucmc_extension(
1258 IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA),
Keith Owens7f613c72005-09-11 17:22:53 +10001259 sos));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
1261 if (recover) {
1262 sal_log_record_header_t *rh = IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA);
1263 rh->severity = sal_log_severity_corrected;
1264 ia64_sal_clear_state_info(SAL_INFO_TYPE_MCA);
Keith Owens7f613c72005-09-11 17:22:53 +10001265 sos->os_status = IA64_MCA_CORRECTED;
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001266 } else {
1267 /* Dump buffered message to console */
1268 ia64_mlogbuf_finish(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 }
Hidetoshi Setob0247a52008-04-08 13:31:47 +09001270
Keith Owens958b1662006-04-03 15:26:12 +10001271 if (notify_die(DIE_MCA_MONARCH_LEAVE, "MCA", regs, (long)&nd, 0, recover)
Keith Owens9138d582005-11-07 11:27:13 -08001272 == NOTIFY_STOP)
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001273 ia64_mca_spin(__func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
Russ Anderson1612b182007-05-18 17:17:17 -05001275 if (atomic_dec_return(&mca_count) > 0) {
1276 int i;
1277
1278 /* wake up the next monarch cpu,
1279 * and put this cpu in the rendez loop.
1280 */
Russ Anderson1612b182007-05-18 17:17:17 -05001281 for_each_online_cpu(i) {
1282 if (cpu_isset(i, mca_cpu)) {
1283 monarch_cpu = i;
1284 cpu_clear(i, mca_cpu); /* wake next cpu */
1285 while (monarch_cpu != -1)
1286 cpu_relax(); /* spin until last cpu leaves */
Russ Anderson1612b182007-05-18 17:17:17 -05001287 set_curr_task(cpu, previous_current);
Russ Andersone1b1eb02007-09-19 16:58:31 -05001288 ia64_mc_info.imi_rendez_checkin[cpu]
1289 = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
Russ Anderson1612b182007-05-18 17:17:17 -05001290 return;
1291 }
1292 }
1293 }
Keith Owens7f613c72005-09-11 17:22:53 +10001294 set_curr_task(cpu, previous_current);
Russ Andersone1b1eb02007-09-19 16:58:31 -05001295 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
1296 monarch_cpu = -1; /* This frees the slaves and previous monarchs */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297}
1298
David Howells6d5aefb2006-12-05 19:36:26 +00001299static DECLARE_WORK(cmc_disable_work, ia64_mca_cmc_vector_disable_keventd);
1300static DECLARE_WORK(cmc_enable_work, ia64_mca_cmc_vector_enable_keventd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
1302/*
1303 * ia64_mca_cmc_int_handler
1304 *
1305 * This is corrected machine check interrupt handler.
1306 * Right now the logs are extracted and displayed in a well-defined
1307 * format.
1308 *
1309 * Inputs
1310 * interrupt number
1311 * client data arg ptr
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 *
1313 * Outputs
1314 * None
1315 */
1316static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001317ia64_mca_cmc_int_handler(int cmc_irq, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318{
1319 static unsigned long cmc_history[CMC_HISTORY_LENGTH];
1320 static int index;
1321 static DEFINE_SPINLOCK(cmc_history_lock);
1322
1323 IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001324 __func__, cmc_irq, smp_processor_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
1326 /* SAL spec states this should run w/ interrupts enabled */
1327 local_irq_enable();
1328
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 spin_lock(&cmc_history_lock);
1330 if (!cmc_polling_enabled) {
1331 int i, count = 1; /* we know 1 happened now */
1332 unsigned long now = jiffies;
1333
1334 for (i = 0; i < CMC_HISTORY_LENGTH; i++) {
1335 if (now - cmc_history[i] <= HZ)
1336 count++;
1337 }
1338
1339 IA64_MCA_DEBUG(KERN_INFO "CMC threshold %d/%d\n", count, CMC_HISTORY_LENGTH);
1340 if (count >= CMC_HISTORY_LENGTH) {
1341
1342 cmc_polling_enabled = 1;
1343 spin_unlock(&cmc_history_lock);
Bryan Sutula76e677e2005-10-05 11:02:06 -06001344 /* If we're being hit with CMC interrupts, we won't
1345 * ever execute the schedule_work() below. Need to
1346 * disable CMC interrupts on this processor now.
1347 */
1348 ia64_mca_cmc_vector_disable(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 schedule_work(&cmc_disable_work);
1350
1351 /*
1352 * Corrected errors will still be corrected, but
1353 * make sure there's a log somewhere that indicates
1354 * something is generating more than we can handle.
1355 */
1356 printk(KERN_WARNING "WARNING: Switching to polling CMC handler; error records may be lost\n");
1357
1358 mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
1359
1360 /* lock already released, get out now */
Hidetoshi Setoddb4f0d2006-09-26 15:27:56 -07001361 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 } else {
1363 cmc_history[index++] = now;
1364 if (index == CMC_HISTORY_LENGTH)
1365 index = 0;
1366 }
1367 }
1368 spin_unlock(&cmc_history_lock);
Hidetoshi Setoddb4f0d2006-09-26 15:27:56 -07001369out:
1370 /* Get the CMC error record and log it */
1371 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC);
1372
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 return IRQ_HANDLED;
1374}
1375
1376/*
1377 * ia64_mca_cmc_int_caller
1378 *
1379 * Triggered by sw interrupt from CMC polling routine. Calls
1380 * real interrupt handler and either triggers a sw interrupt
1381 * on the next cpu or does cleanup at the end.
1382 *
1383 * Inputs
1384 * interrupt number
1385 * client data arg ptr
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 * Outputs
1387 * handled
1388 */
1389static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001390ia64_mca_cmc_int_caller(int cmc_irq, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391{
1392 static int start_count = -1;
1393 unsigned int cpuid;
1394
1395 cpuid = smp_processor_id();
1396
1397 /* If first cpu, update count */
1398 if (start_count == -1)
1399 start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CMC);
1400
David Howells7d12e782006-10-05 14:55:46 +01001401 ia64_mca_cmc_int_handler(cmc_irq, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
1403 for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
1404
1405 if (cpuid < NR_CPUS) {
1406 platform_send_ipi(cpuid, IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
1407 } else {
1408 /* If no log record, switch out of polling mode */
1409 if (start_count == IA64_LOG_COUNT(SAL_INFO_TYPE_CMC)) {
1410
1411 printk(KERN_WARNING "Returning to interrupt driven CMC handler\n");
1412 schedule_work(&cmc_enable_work);
1413 cmc_polling_enabled = 0;
1414
1415 } else {
1416
1417 mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
1418 }
1419
1420 start_count = -1;
1421 }
1422
1423 return IRQ_HANDLED;
1424}
1425
1426/*
1427 * ia64_mca_cmc_poll
1428 *
1429 * Poll for Corrected Machine Checks (CMCs)
1430 *
1431 * Inputs : dummy(unused)
1432 * Outputs : None
1433 *
1434 */
1435static void
1436ia64_mca_cmc_poll (unsigned long dummy)
1437{
1438 /* Trigger a CMC interrupt cascade */
1439 platform_send_ipi(first_cpu(cpu_online_map), IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
1440}
1441
1442/*
1443 * ia64_mca_cpe_int_caller
1444 *
1445 * Triggered by sw interrupt from CPE polling routine. Calls
1446 * real interrupt handler and either triggers a sw interrupt
1447 * on the next cpu or does cleanup at the end.
1448 *
1449 * Inputs
1450 * interrupt number
1451 * client data arg ptr
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 * Outputs
1453 * handled
1454 */
1455#ifdef CONFIG_ACPI
1456
1457static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001458ia64_mca_cpe_int_caller(int cpe_irq, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459{
1460 static int start_count = -1;
1461 static int poll_time = MIN_CPE_POLL_INTERVAL;
1462 unsigned int cpuid;
1463
1464 cpuid = smp_processor_id();
1465
1466 /* If first cpu, update count */
1467 if (start_count == -1)
1468 start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CPE);
1469
David Howells7d12e782006-10-05 14:55:46 +01001470 ia64_mca_cpe_int_handler(cpe_irq, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
1472 for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
1473
1474 if (cpuid < NR_CPUS) {
1475 platform_send_ipi(cpuid, IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
1476 } else {
1477 /*
1478 * If a log was recorded, increase our polling frequency,
1479 * otherwise, backoff or return to interrupt mode.
1480 */
1481 if (start_count != IA64_LOG_COUNT(SAL_INFO_TYPE_CPE)) {
1482 poll_time = max(MIN_CPE_POLL_INTERVAL, poll_time / 2);
1483 } else if (cpe_vector < 0) {
1484 poll_time = min(MAX_CPE_POLL_INTERVAL, poll_time * 2);
1485 } else {
1486 poll_time = MIN_CPE_POLL_INTERVAL;
1487
1488 printk(KERN_WARNING "Returning to interrupt driven CPE handler\n");
1489 enable_irq(local_vector_to_irq(IA64_CPE_VECTOR));
1490 cpe_poll_enabled = 0;
1491 }
1492
1493 if (cpe_poll_enabled)
1494 mod_timer(&cpe_poll_timer, jiffies + poll_time);
1495 start_count = -1;
1496 }
1497
1498 return IRQ_HANDLED;
1499}
1500
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501/*
1502 * ia64_mca_cpe_poll
1503 *
1504 * Poll for Corrected Platform Errors (CPEs), trigger interrupt
1505 * on first cpu, from there it will trickle through all the cpus.
1506 *
1507 * Inputs : dummy(unused)
1508 * Outputs : None
1509 *
1510 */
1511static void
1512ia64_mca_cpe_poll (unsigned long dummy)
1513{
1514 /* Trigger a CPE interrupt cascade */
1515 platform_send_ipi(first_cpu(cpu_online_map), IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
1516}
1517
Peter Chubbb6559132005-05-31 22:34:00 -07001518#endif /* CONFIG_ACPI */
1519
Keith Owens9138d582005-11-07 11:27:13 -08001520static int
1521default_monarch_init_process(struct notifier_block *self, unsigned long val, void *data)
1522{
1523 int c;
1524 struct task_struct *g, *t;
1525 if (val != DIE_INIT_MONARCH_PROCESS)
1526 return NOTIFY_DONE;
Jay Lan311f5942007-04-03 17:53:42 -07001527#ifdef CONFIG_KEXEC
1528 if (atomic_read(&kdump_in_progress))
1529 return NOTIFY_DONE;
1530#endif
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001531
1532 /*
1533 * FIXME: mlogbuf will brim over with INIT stack dumps.
1534 * To enable show_stack from INIT, we use oops_in_progress which should
1535 * be used in real oops. This would cause something wrong after INIT.
1536 */
1537 BREAK_LOGLEVEL(console_loglevel);
1538 ia64_mlogbuf_dump_from_init();
1539
Keith Owens9138d582005-11-07 11:27:13 -08001540 printk(KERN_ERR "Processes interrupted by INIT -");
1541 for_each_online_cpu(c) {
1542 struct ia64_sal_os_state *s;
1543 t = __va(__per_cpu_mca[c] + IA64_MCA_CPU_INIT_STACK_OFFSET);
1544 s = (struct ia64_sal_os_state *)((char *)t + MCA_SOS_OFFSET);
1545 g = s->prev_task;
1546 if (g) {
1547 if (g->pid)
1548 printk(" %d", g->pid);
1549 else
1550 printk(" %d (cpu %d task 0x%p)", g->pid, task_cpu(g), g);
1551 }
1552 }
1553 printk("\n\n");
1554 if (read_trylock(&tasklist_lock)) {
1555 do_each_thread (g, t) {
1556 printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm);
1557 show_stack(t, NULL);
1558 } while_each_thread (g, t);
1559 read_unlock(&tasklist_lock);
1560 }
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001561 /* FIXME: This will not restore zapped printk locks. */
1562 RESTORE_LOGLEVEL(console_loglevel);
Keith Owens9138d582005-11-07 11:27:13 -08001563 return NOTIFY_DONE;
1564}
1565
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566/*
1567 * C portion of the OS INIT handler
1568 *
Keith Owens7f613c72005-09-11 17:22:53 +10001569 * Called from ia64_os_init_dispatch
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 *
Keith Owens7f613c72005-09-11 17:22:53 +10001571 * Inputs: pointer to pt_regs where processor info was saved. SAL/OS state for
1572 * this event. This code is used for both monarch and slave INIT events, see
1573 * sos->monarch.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 *
Keith Owens7f613c72005-09-11 17:22:53 +10001575 * All INIT events switch to the INIT stack and change the previous process to
1576 * blocked status. If one of the INIT events is the monarch then we are
1577 * probably processing the nmi button/command. Use the monarch cpu to dump all
1578 * the processes. The slave INIT events all spin until the monarch cpu
1579 * returns. We can also get INIT slave events for MCA, in which case the MCA
1580 * process is the monarch.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Keith Owens7f613c72005-09-11 17:22:53 +10001583void
1584ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw,
1585 struct ia64_sal_os_state *sos)
1586{
1587 static atomic_t slaves;
1588 static atomic_t monarchs;
Ingo Molnar36c8b582006-07-03 00:25:41 -07001589 struct task_struct *previous_current;
Keith Owens9138d582005-11-07 11:27:13 -08001590 int cpu = smp_processor_id();
Keith Owens958b1662006-04-03 15:26:12 +10001591 struct ia64_mca_notify_die nd =
1592 { .sos = sos, .monarch_cpu = &monarch_cpu };
Keith Owens7f613c72005-09-11 17:22:53 +10001593
Keith Owens958b1662006-04-03 15:26:12 +10001594 (void) notify_die(DIE_INIT_ENTER, "INIT", regs, (long)&nd, 0, 0);
1595
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001596 mprintk(KERN_INFO "Entered OS INIT handler. PSP=%lx cpu=%d monarch=%ld\n",
Keith Owens7f613c72005-09-11 17:22:53 +10001597 sos->proc_state_param, cpu, sos->monarch);
1598 salinfo_log_wakeup(SAL_INFO_TYPE_INIT, NULL, 0, 0);
1599
1600 previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "INIT");
1601 sos->os_status = IA64_INIT_RESUME;
1602
1603 /* FIXME: Workaround for broken proms that drive all INIT events as
1604 * slaves. The last slave that enters is promoted to be a monarch.
1605 * Remove this code in September 2006, that gives platforms a year to
1606 * fix their proms and get their customers updated.
1607 */
1608 if (!sos->monarch && atomic_add_return(1, &slaves) == num_online_cpus()) {
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001609 mprintk(KERN_WARNING "%s: Promoting cpu %d to monarch.\n",
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001610 __func__, cpu);
Keith Owens7f613c72005-09-11 17:22:53 +10001611 atomic_dec(&slaves);
1612 sos->monarch = 1;
1613 }
1614
1615 /* FIXME: Workaround for broken proms that drive all INIT events as
1616 * monarchs. Second and subsequent monarchs are demoted to slaves.
1617 * Remove this code in September 2006, that gives platforms a year to
1618 * fix their proms and get their customers updated.
1619 */
1620 if (sos->monarch && atomic_add_return(1, &monarchs) > 1) {
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001621 mprintk(KERN_WARNING "%s: Demoting cpu %d to slave.\n",
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001622 __func__, cpu);
Keith Owens7f613c72005-09-11 17:22:53 +10001623 atomic_dec(&monarchs);
1624 sos->monarch = 0;
1625 }
1626
1627 if (!sos->monarch) {
1628 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_INIT;
1629 while (monarch_cpu == -1)
1630 cpu_relax(); /* spin until monarch enters */
Keith Owens958b1662006-04-03 15:26:12 +10001631 if (notify_die(DIE_INIT_SLAVE_ENTER, "INIT", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001632 == NOTIFY_STOP)
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001633 ia64_mca_spin(__func__);
Keith Owens958b1662006-04-03 15:26:12 +10001634 if (notify_die(DIE_INIT_SLAVE_PROCESS, "INIT", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001635 == NOTIFY_STOP)
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001636 ia64_mca_spin(__func__);
Keith Owens7f613c72005-09-11 17:22:53 +10001637 while (monarch_cpu != -1)
1638 cpu_relax(); /* spin until monarch leaves */
Keith Owens958b1662006-04-03 15:26:12 +10001639 if (notify_die(DIE_INIT_SLAVE_LEAVE, "INIT", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001640 == NOTIFY_STOP)
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001641 ia64_mca_spin(__func__);
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001642 mprintk("Slave on cpu %d returning to normal service.\n", cpu);
Keith Owens7f613c72005-09-11 17:22:53 +10001643 set_curr_task(cpu, previous_current);
1644 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
1645 atomic_dec(&slaves);
1646 return;
1647 }
1648
1649 monarch_cpu = cpu;
Keith Owens958b1662006-04-03 15:26:12 +10001650 if (notify_die(DIE_INIT_MONARCH_ENTER, "INIT", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001651 == NOTIFY_STOP)
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001652 ia64_mca_spin(__func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
1654 /*
Keith Owens7f613c72005-09-11 17:22:53 +10001655 * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be
1656 * generated via the BMC's command-line interface, but since the console is on the
1657 * same serial line, the user will need some time to switch out of the BMC before
1658 * the dump begins.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 */
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001660 mprintk("Delaying for 5 seconds...\n");
Keith Owens7f613c72005-09-11 17:22:53 +10001661 udelay(5*1000000);
Keith Owens356a5c12006-04-11 14:59:41 +10001662 ia64_wait_for_slaves(cpu, "INIT");
Keith Owens9138d582005-11-07 11:27:13 -08001663 /* If nobody intercepts DIE_INIT_MONARCH_PROCESS then we drop through
1664 * to default_monarch_init_process() above and just print all the
1665 * tasks.
1666 */
Keith Owens958b1662006-04-03 15:26:12 +10001667 if (notify_die(DIE_INIT_MONARCH_PROCESS, "INIT", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001668 == NOTIFY_STOP)
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001669 ia64_mca_spin(__func__);
Keith Owens958b1662006-04-03 15:26:12 +10001670 if (notify_die(DIE_INIT_MONARCH_LEAVE, "INIT", regs, (long)&nd, 0, 0)
Keith Owens9138d582005-11-07 11:27:13 -08001671 == NOTIFY_STOP)
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001672 ia64_mca_spin(__func__);
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -07001673 mprintk("\nINIT dump complete. Monarch on cpu %d returning to normal service.\n", cpu);
Keith Owens7f613c72005-09-11 17:22:53 +10001674 atomic_dec(&monarchs);
1675 set_curr_task(cpu, previous_current);
1676 monarch_cpu = -1;
1677 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678}
1679
1680static int __init
1681ia64_mca_disable_cpe_polling(char *str)
1682{
1683 cpe_poll_enabled = 0;
1684 return 1;
1685}
1686
1687__setup("disable_cpe_poll", ia64_mca_disable_cpe_polling);
1688
1689static struct irqaction cmci_irqaction = {
1690 .handler = ia64_mca_cmc_int_handler,
Thomas Gleixner121a4222006-07-01 19:29:17 -07001691 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 .name = "cmc_hndlr"
1693};
1694
1695static struct irqaction cmcp_irqaction = {
1696 .handler = ia64_mca_cmc_int_caller,
Thomas Gleixner121a4222006-07-01 19:29:17 -07001697 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 .name = "cmc_poll"
1699};
1700
1701static struct irqaction mca_rdzv_irqaction = {
1702 .handler = ia64_mca_rendez_int_handler,
Thomas Gleixner121a4222006-07-01 19:29:17 -07001703 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 .name = "mca_rdzv"
1705};
1706
1707static struct irqaction mca_wkup_irqaction = {
1708 .handler = ia64_mca_wakeup_int_handler,
Thomas Gleixner121a4222006-07-01 19:29:17 -07001709 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 .name = "mca_wkup"
1711};
1712
1713#ifdef CONFIG_ACPI
1714static struct irqaction mca_cpe_irqaction = {
1715 .handler = ia64_mca_cpe_int_handler,
Thomas Gleixner121a4222006-07-01 19:29:17 -07001716 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 .name = "cpe_hndlr"
1718};
1719
1720static struct irqaction mca_cpep_irqaction = {
1721 .handler = ia64_mca_cpe_int_caller,
Thomas Gleixner121a4222006-07-01 19:29:17 -07001722 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 .name = "cpe_poll"
1724};
1725#endif /* CONFIG_ACPI */
1726
Keith Owens7f613c72005-09-11 17:22:53 +10001727/* Minimal format of the MCA/INIT stacks. The pseudo processes that run on
1728 * these stacks can never sleep, they cannot return from the kernel to user
1729 * space, they do not appear in a normal ps listing. So there is no need to
1730 * format most of the fields.
1731 */
1732
Chen, Kenneth W0881fc82006-03-12 08:52:20 -08001733static void __cpuinit
Keith Owens7f613c72005-09-11 17:22:53 +10001734format_mca_init_stack(void *mca_data, unsigned long offset,
1735 const char *type, int cpu)
1736{
1737 struct task_struct *p = (struct task_struct *)((char *)mca_data + offset);
1738 struct thread_info *ti;
1739 memset(p, 0, KERNEL_STACK_SIZE);
Al Viroab035912006-01-12 01:06:05 -08001740 ti = task_thread_info(p);
Keith Owens7f613c72005-09-11 17:22:53 +10001741 ti->flags = _TIF_MCA_INIT;
1742 ti->preempt_count = 1;
1743 ti->task = p;
1744 ti->cpu = cpu;
Roman Zippelf7e42172007-05-09 02:35:17 -07001745 p->stack = ti;
Keith Owens7f613c72005-09-11 17:22:53 +10001746 p->state = TASK_UNINTERRUPTIBLE;
Akinobu Mita4668f0c2006-03-26 01:39:03 -08001747 cpu_set(cpu, p->cpus_allowed);
Keith Owens7f613c72005-09-11 17:22:53 +10001748 INIT_LIST_HEAD(&p->tasks);
1749 p->parent = p->real_parent = p->group_leader = p;
1750 INIT_LIST_HEAD(&p->children);
1751 INIT_LIST_HEAD(&p->sibling);
1752 strncpy(p->comm, type, sizeof(p->comm)-1);
1753}
1754
Sam Ravnborg056e6d82007-07-30 22:50:13 +02001755/* Caller prevents this from being called after init */
1756static void * __init_refok mca_bootmem(void)
1757{
Russ Anderson785285f2008-02-05 17:12:32 -06001758 return __alloc_bootmem(sizeof(struct ia64_mca_cpu),
1759 KERNEL_STACK_SIZE, 0);
Sam Ravnborg056e6d82007-07-30 22:50:13 +02001760}
1761
1762/* Do per-CPU MCA-related initialization. */
Chen, Kenneth W0881fc82006-03-12 08:52:20 -08001763void __cpuinit
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764ia64_mca_cpu_init(void *cpu_data)
1765{
1766 void *pal_vaddr;
Russ Anderson785285f2008-02-05 17:12:32 -06001767 void *data;
1768 long sz = sizeof(struct ia64_mca_cpu);
1769 int cpu = smp_processor_id();
Ashok Rajff741902005-11-11 14:32:40 -08001770 static int first_time = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
Keith Owens7f613c72005-09-11 17:22:53 +10001772 /*
Russ Anderson785285f2008-02-05 17:12:32 -06001773 * Structure will already be allocated if cpu has been online,
1774 * then offlined.
Keith Owens7f613c72005-09-11 17:22:53 +10001775 */
Russ Anderson785285f2008-02-05 17:12:32 -06001776 if (__per_cpu_mca[cpu]) {
1777 data = __va(__per_cpu_mca[cpu]);
1778 } else {
1779 if (first_time) {
1780 data = mca_bootmem();
1781 first_time = 0;
1782 } else
1783 data = page_address(alloc_pages_node(numa_node_id(),
1784 GFP_KERNEL, get_order(sz)));
1785 if (!data)
1786 panic("Could not allocate MCA memory for cpu %d\n",
1787 cpu);
1788 }
1789 format_mca_init_stack(data, offsetof(struct ia64_mca_cpu, mca_stack),
1790 "MCA", cpu);
1791 format_mca_init_stack(data, offsetof(struct ia64_mca_cpu, init_stack),
1792 "INIT", cpu);
1793 __get_cpu_var(ia64_mca_data) = __per_cpu_mca[cpu] = __pa(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
1795 /*
1796 * Stash away a copy of the PTE needed to map the per-CPU page.
1797 * We may need it during MCA recovery.
1798 */
1799 __get_cpu_var(ia64_mca_per_cpu_pte) =
1800 pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL));
1801
Keith Owens7f613c72005-09-11 17:22:53 +10001802 /*
1803 * Also, stash away a copy of the PAL address and the PTE
1804 * needed to map it.
1805 */
1806 pal_vaddr = efi_get_pal_addr();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 if (!pal_vaddr)
1808 return;
1809 __get_cpu_var(ia64_mca_pal_base) =
1810 GRANULEROUNDDOWN((unsigned long) pal_vaddr);
1811 __get_cpu_var(ia64_mca_pal_pte) = pte_val(mk_pte_phys(__pa(pal_vaddr),
1812 PAGE_KERNEL));
1813}
1814
Hidetoshi Setoed5d4022007-12-19 11:42:02 -08001815static void __cpuinit ia64_mca_cmc_vector_adjust(void *dummy)
1816{
1817 unsigned long flags;
1818
1819 local_irq_save(flags);
1820 if (!cmc_polling_enabled)
1821 ia64_mca_cmc_vector_enable(NULL);
1822 local_irq_restore(flags);
1823}
1824
1825static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
1826 unsigned long action,
1827 void *hcpu)
1828{
1829 int hotcpu = (unsigned long) hcpu;
1830
1831 switch (action) {
1832 case CPU_ONLINE:
1833 case CPU_ONLINE_FROZEN:
1834 smp_call_function_single(hotcpu, ia64_mca_cmc_vector_adjust,
1835 NULL, 1, 0);
1836 break;
1837 }
1838 return NOTIFY_OK;
1839}
1840
1841static struct notifier_block mca_cpu_notifier __cpuinitdata = {
1842 .notifier_call = mca_cpu_callback
1843};
1844
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845/*
1846 * ia64_mca_init
1847 *
1848 * Do all the system level mca specific initialization.
1849 *
1850 * 1. Register spinloop and wakeup request interrupt vectors
1851 *
1852 * 2. Register OS_MCA handler entry point
1853 *
1854 * 3. Register OS_INIT handler entry point
1855 *
1856 * 4. Initialize MCA/CMC/INIT related log buffers maintained by the OS.
1857 *
1858 * Note that this initialization is done very early before some kernel
1859 * services are available.
1860 *
1861 * Inputs : None
1862 *
1863 * Outputs : None
1864 */
1865void __init
1866ia64_mca_init(void)
1867{
Keith Owens7f613c72005-09-11 17:22:53 +10001868 ia64_fptr_t *init_hldlr_ptr_monarch = (ia64_fptr_t *)ia64_os_init_dispatch_monarch;
1869 ia64_fptr_t *init_hldlr_ptr_slave = (ia64_fptr_t *)ia64_os_init_dispatch_slave;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch;
1871 int i;
1872 s64 rc;
1873 struct ia64_sal_retval isrv;
1874 u64 timeout = IA64_MCA_RENDEZ_TIMEOUT; /* platform specific */
Keith Owens9138d582005-11-07 11:27:13 -08001875 static struct notifier_block default_init_monarch_nb = {
1876 .notifier_call = default_monarch_init_process,
1877 .priority = 0/* we need to notified last */
1878 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001880 IA64_MCA_DEBUG("%s: begin\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881
1882 /* Clear the Rendez checkin flag for all cpus */
1883 for(i = 0 ; i < NR_CPUS; i++)
1884 ia64_mc_info.imi_rendez_checkin[i] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
1885
1886 /*
1887 * Register the rendezvous spinloop and wakeup mechanism with SAL
1888 */
1889
1890 /* Register the rendezvous interrupt vector with SAL */
1891 while (1) {
1892 isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_INT,
1893 SAL_MC_PARAM_MECHANISM_INT,
1894 IA64_MCA_RENDEZ_VECTOR,
1895 timeout,
1896 SAL_MC_PARAM_RZ_ALWAYS);
1897 rc = isrv.status;
1898 if (rc == 0)
1899 break;
1900 if (rc == -2) {
1901 printk(KERN_INFO "Increasing MCA rendezvous timeout from "
1902 "%ld to %ld milliseconds\n", timeout, isrv.v0);
1903 timeout = isrv.v0;
Keith Owens958b1662006-04-03 15:26:12 +10001904 (void) notify_die(DIE_MCA_NEW_TIMEOUT, "MCA", NULL, timeout, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 continue;
1906 }
1907 printk(KERN_ERR "Failed to register rendezvous interrupt "
1908 "with SAL (status %ld)\n", rc);
1909 return;
1910 }
1911
1912 /* Register the wakeup interrupt vector with SAL */
1913 isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_WAKEUP,
1914 SAL_MC_PARAM_MECHANISM_INT,
1915 IA64_MCA_WAKEUP_VECTOR,
1916 0, 0);
1917 rc = isrv.status;
1918 if (rc) {
1919 printk(KERN_ERR "Failed to register wakeup interrupt with SAL "
1920 "(status %ld)\n", rc);
1921 return;
1922 }
1923
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001924 IA64_MCA_DEBUG("%s: registered MCA rendezvous spinloop and wakeup mech.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925
1926 ia64_mc_info.imi_mca_handler = ia64_tpa(mca_hldlr_ptr->fp);
1927 /*
1928 * XXX - disable SAL checksum by setting size to 0; should be
1929 * ia64_tpa(ia64_os_mca_dispatch_end) - ia64_tpa(ia64_os_mca_dispatch);
1930 */
1931 ia64_mc_info.imi_mca_handler_size = 0;
1932
1933 /* Register the os mca handler with SAL */
1934 if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_MCA,
1935 ia64_mc_info.imi_mca_handler,
1936 ia64_tpa(mca_hldlr_ptr->gp),
1937 ia64_mc_info.imi_mca_handler_size,
1938 0, 0, 0)))
1939 {
1940 printk(KERN_ERR "Failed to register OS MCA handler with SAL "
1941 "(status %ld)\n", rc);
1942 return;
1943 }
1944
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001945 IA64_MCA_DEBUG("%s: registered OS MCA handler with SAL at 0x%lx, gp = 0x%lx\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 ia64_mc_info.imi_mca_handler, ia64_tpa(mca_hldlr_ptr->gp));
1947
1948 /*
1949 * XXX - disable SAL checksum by setting size to 0, should be
1950 * size of the actual init handler in mca_asm.S.
1951 */
Keith Owens7f613c72005-09-11 17:22:53 +10001952 ia64_mc_info.imi_monarch_init_handler = ia64_tpa(init_hldlr_ptr_monarch->fp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 ia64_mc_info.imi_monarch_init_handler_size = 0;
Keith Owens7f613c72005-09-11 17:22:53 +10001954 ia64_mc_info.imi_slave_init_handler = ia64_tpa(init_hldlr_ptr_slave->fp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 ia64_mc_info.imi_slave_init_handler_size = 0;
1956
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001957 IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 ia64_mc_info.imi_monarch_init_handler);
1959
1960 /* Register the os init handler with SAL */
1961 if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_INIT,
1962 ia64_mc_info.imi_monarch_init_handler,
1963 ia64_tpa(ia64_getreg(_IA64_REG_GP)),
1964 ia64_mc_info.imi_monarch_init_handler_size,
1965 ia64_mc_info.imi_slave_init_handler,
1966 ia64_tpa(ia64_getreg(_IA64_REG_GP)),
1967 ia64_mc_info.imi_slave_init_handler_size)))
1968 {
1969 printk(KERN_ERR "Failed to register m/s INIT handlers with SAL "
1970 "(status %ld)\n", rc);
1971 return;
1972 }
Keith Owens9138d582005-11-07 11:27:13 -08001973 if (register_die_notifier(&default_init_monarch_nb)) {
1974 printk(KERN_ERR "Failed to register default monarch INIT process\n");
1975 return;
1976 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
Harvey Harrisond4ed8082008-03-04 15:15:00 -08001978 IA64_MCA_DEBUG("%s: registered OS INIT handler with SAL\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
1980 /*
1981 * Configure the CMCI/P vector and handler. Interrupts for CMC are
1982 * per-processor, so AP CMC interrupts are setup in smp_callin() (smpboot.c).
1983 */
1984 register_percpu_irq(IA64_CMC_VECTOR, &cmci_irqaction);
1985 register_percpu_irq(IA64_CMCP_VECTOR, &cmcp_irqaction);
1986 ia64_mca_cmc_vector_setup(); /* Setup vector on BSP */
1987
1988 /* Setup the MCA rendezvous interrupt vector */
1989 register_percpu_irq(IA64_MCA_RENDEZ_VECTOR, &mca_rdzv_irqaction);
1990
1991 /* Setup the MCA wakeup interrupt vector */
1992 register_percpu_irq(IA64_MCA_WAKEUP_VECTOR, &mca_wkup_irqaction);
1993
1994#ifdef CONFIG_ACPI
Russ Andersonbb68c122005-05-09 15:03:00 -07001995 /* Setup the CPEI/P handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 register_percpu_irq(IA64_CPEP_VECTOR, &mca_cpep_irqaction);
1997#endif
1998
1999 /* Initialize the areas set aside by the OS to buffer the
2000 * platform/processor error states for MCA/INIT/CMC
2001 * handling.
2002 */
2003 ia64_log_init(SAL_INFO_TYPE_MCA);
2004 ia64_log_init(SAL_INFO_TYPE_INIT);
2005 ia64_log_init(SAL_INFO_TYPE_CMC);
2006 ia64_log_init(SAL_INFO_TYPE_CPE);
2007
2008 mca_init = 1;
2009 printk(KERN_INFO "MCA related initialization done\n");
2010}
2011
2012/*
2013 * ia64_mca_late_init
2014 *
2015 * Opportunity to setup things that require initialization later
2016 * than ia64_mca_init. Setup a timer to poll for CPEs if the
2017 * platform doesn't support an interrupt driven mechanism.
2018 *
2019 * Inputs : None
2020 * Outputs : Status
2021 */
2022static int __init
2023ia64_mca_late_init(void)
2024{
2025 if (!mca_init)
2026 return 0;
2027
Hidetoshi Setoed5d4022007-12-19 11:42:02 -08002028 register_hotcpu_notifier(&mca_cpu_notifier);
2029
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 /* Setup the CMCI/P vector and handler */
2031 init_timer(&cmc_poll_timer);
2032 cmc_poll_timer.function = ia64_mca_cmc_poll;
2033
2034 /* Unmask/enable the vector */
2035 cmc_polling_enabled = 0;
2036 schedule_work(&cmc_enable_work);
2037
Harvey Harrisond4ed8082008-03-04 15:15:00 -08002038 IA64_MCA_DEBUG("%s: CMCI/P setup and enabled.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039
2040#ifdef CONFIG_ACPI
2041 /* Setup the CPEI/P vector and handler */
Russ Andersonbb68c122005-05-09 15:03:00 -07002042 cpe_vector = acpi_request_vector(ACPI_INTERRUPT_CPEI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 init_timer(&cpe_poll_timer);
2044 cpe_poll_timer.function = ia64_mca_cpe_poll;
2045
2046 {
2047 irq_desc_t *desc;
2048 unsigned int irq;
2049
2050 if (cpe_vector >= 0) {
2051 /* If platform supports CPEI, enable the irq. */
Russ Andersona1287472007-08-03 14:32:37 -05002052 irq = local_vector_to_irq(cpe_vector);
2053 if (irq > 0) {
2054 cpe_poll_enabled = 0;
2055 desc = irq_desc + irq;
2056 desc->status |= IRQ_PER_CPU;
2057 setup_irq(irq, &mca_cpe_irqaction);
2058 ia64_cpe_irq = irq;
2059 ia64_mca_register_cpev(cpe_vector);
2060 IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n",
Harvey Harrisond4ed8082008-03-04 15:15:00 -08002061 __func__);
Russ Andersona1287472007-08-03 14:32:37 -05002062 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 }
Russ Andersona1287472007-08-03 14:32:37 -05002064 printk(KERN_ERR "%s: Failed to find irq for CPE "
2065 "interrupt handler, vector %d\n",
Harvey Harrisond4ed8082008-03-04 15:15:00 -08002066 __func__, cpe_vector);
Russ Andersona1287472007-08-03 14:32:37 -05002067 }
2068 /* If platform doesn't support CPEI, get the timer going. */
2069 if (cpe_poll_enabled) {
2070 ia64_mca_cpe_poll(0UL);
Harvey Harrisond4ed8082008-03-04 15:15:00 -08002071 IA64_MCA_DEBUG("%s: CPEP setup and enabled.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 }
2073 }
2074#endif
2075
2076 return 0;
2077}
2078
2079device_initcall(ia64_mca_late_init);