xref: /openbmc/linux/arch/ia64/kernel/mca.c (revision 36c8b586896f60cb91a4fd526233190b34316baf)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * File:	mca.c
31da177e4SLinus Torvalds  * Purpose:	Generic MCA handling layer
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * Updated for latest kernel
61da177e4SLinus Torvalds  * Copyright (C) 2003 Hewlett-Packard Co
71da177e4SLinus Torvalds  *	David Mosberger-Tang <davidm@hpl.hp.com>
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  * Copyright (C) 2002 Dell Inc.
101da177e4SLinus Torvalds  * Copyright (C) Matt Domsch (Matt_Domsch@dell.com)
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  * Copyright (C) 2002 Intel
131da177e4SLinus Torvalds  * Copyright (C) Jenna Hall (jenna.s.hall@intel.com)
141da177e4SLinus Torvalds  *
151da177e4SLinus Torvalds  * Copyright (C) 2001 Intel
161da177e4SLinus Torvalds  * Copyright (C) Fred Lewis (frederick.v.lewis@intel.com)
171da177e4SLinus Torvalds  *
181da177e4SLinus Torvalds  * Copyright (C) 2000 Intel
191da177e4SLinus Torvalds  * Copyright (C) Chuck Fleckenstein (cfleck@co.intel.com)
201da177e4SLinus Torvalds  *
211da177e4SLinus Torvalds  * Copyright (C) 1999, 2004 Silicon Graphics, Inc.
221da177e4SLinus Torvalds  * Copyright (C) Vijay Chander(vijay@engr.sgi.com)
231da177e4SLinus Torvalds  *
241da177e4SLinus Torvalds  * 03/04/15 D. Mosberger Added INIT backtrace support.
251da177e4SLinus Torvalds  * 02/03/25 M. Domsch	GUID cleanups
261da177e4SLinus Torvalds  *
271da177e4SLinus Torvalds  * 02/01/04 J. Hall	Aligned MCA stack to 16 bytes, added platform vs. CPU
281da177e4SLinus Torvalds  *			error flag, set SAL default return values, changed
291da177e4SLinus Torvalds  *			error record structure to linked list, added init call
301da177e4SLinus Torvalds  *			to sal_get_state_info_size().
311da177e4SLinus Torvalds  *
321da177e4SLinus Torvalds  * 01/01/03 F. Lewis    Added setup of CMCI and CPEI IRQs, logging of corrected
331da177e4SLinus Torvalds  *                      platform errors, completed code for logging of
341da177e4SLinus Torvalds  *                      corrected & uncorrected machine check errors, and
351da177e4SLinus Torvalds  *                      updated for conformance with Nov. 2000 revision of the
361da177e4SLinus Torvalds  *                      SAL 3.0 spec.
371da177e4SLinus Torvalds  * 00/03/29 C. Fleckenstein  Fixed PAL/SAL update issues, began MCA bug fixes, logging issues,
381da177e4SLinus Torvalds  *                           added min save state dump, added INIT handler.
391da177e4SLinus Torvalds  *
401da177e4SLinus Torvalds  * 2003-12-08 Keith Owens <kaos@sgi.com>
411da177e4SLinus Torvalds  *            smp_call_function() must not be called from interrupt context (can
421da177e4SLinus Torvalds  *            deadlock on tasklist_lock).  Use keventd to call smp_call_function().
431da177e4SLinus Torvalds  *
441da177e4SLinus Torvalds  * 2004-02-01 Keith Owens <kaos@sgi.com>
451da177e4SLinus Torvalds  *            Avoid deadlock when using printk() for MCA and INIT records.
461da177e4SLinus Torvalds  *            Delete all record printing code, moved to salinfo_decode in user space.
471da177e4SLinus Torvalds  *            Mark variables and functions static where possible.
481da177e4SLinus Torvalds  *            Delete dead variables and functions.
491da177e4SLinus Torvalds  *            Reorder to remove the need for forward declarations and to consolidate
501da177e4SLinus Torvalds  *            related code.
517f613c7dSKeith Owens  *
527f613c7dSKeith Owens  * 2005-08-12 Keith Owens <kaos@sgi.com>
537f613c7dSKeith Owens  *	      Convert MCA/INIT handlers to use per event stacks and SAL/OS state.
549138d581SKeith Owens  *
559138d581SKeith Owens  * 2005-10-07 Keith Owens <kaos@sgi.com>
569138d581SKeith Owens  *	      Add notify_die() hooks.
571da177e4SLinus Torvalds  */
581da177e4SLinus Torvalds #include <linux/types.h>
591da177e4SLinus Torvalds #include <linux/init.h>
601da177e4SLinus Torvalds #include <linux/sched.h>
611da177e4SLinus Torvalds #include <linux/interrupt.h>
621da177e4SLinus Torvalds #include <linux/irq.h>
631da177e4SLinus Torvalds #include <linux/smp_lock.h>
641da177e4SLinus Torvalds #include <linux/bootmem.h>
651da177e4SLinus Torvalds #include <linux/acpi.h>
661da177e4SLinus Torvalds #include <linux/timer.h>
671da177e4SLinus Torvalds #include <linux/module.h>
681da177e4SLinus Torvalds #include <linux/kernel.h>
691da177e4SLinus Torvalds #include <linux/smp.h>
701da177e4SLinus Torvalds #include <linux/workqueue.h>
714668f0cdSAkinobu Mita #include <linux/cpumask.h>
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds #include <asm/delay.h>
749138d581SKeith Owens #include <asm/kdebug.h>
751da177e4SLinus Torvalds #include <asm/machvec.h>
761da177e4SLinus Torvalds #include <asm/meminit.h>
771da177e4SLinus Torvalds #include <asm/page.h>
781da177e4SLinus Torvalds #include <asm/ptrace.h>
791da177e4SLinus Torvalds #include <asm/system.h>
801da177e4SLinus Torvalds #include <asm/sal.h>
811da177e4SLinus Torvalds #include <asm/mca.h>
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds #include <asm/irq.h>
841da177e4SLinus Torvalds #include <asm/hw_irq.h>
851da177e4SLinus Torvalds 
86d2a28ad9SRuss Anderson #include "mca_drv.h"
877f613c7dSKeith Owens #include "entry.h"
887f613c7dSKeith Owens 
891da177e4SLinus Torvalds #if defined(IA64_MCA_DEBUG_INFO)
901da177e4SLinus Torvalds # define IA64_MCA_DEBUG(fmt...)	printk(fmt)
911da177e4SLinus Torvalds #else
921da177e4SLinus Torvalds # define IA64_MCA_DEBUG(fmt...)
931da177e4SLinus Torvalds #endif
941da177e4SLinus Torvalds 
951da177e4SLinus Torvalds /* Used by mca_asm.S */
967f613c7dSKeith Owens u32				ia64_mca_serialize;
971da177e4SLinus Torvalds DEFINE_PER_CPU(u64, ia64_mca_data); /* == __per_cpu_mca[smp_processor_id()] */
981da177e4SLinus Torvalds DEFINE_PER_CPU(u64, ia64_mca_per_cpu_pte); /* PTE to map per-CPU area */
991da177e4SLinus Torvalds DEFINE_PER_CPU(u64, ia64_mca_pal_pte);	    /* PTE to map PAL code */
1001da177e4SLinus Torvalds DEFINE_PER_CPU(u64, ia64_mca_pal_base);    /* vaddr PAL code granule */
1011da177e4SLinus Torvalds 
1021da177e4SLinus Torvalds unsigned long __per_cpu_mca[NR_CPUS];
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds /* In mca_asm.S */
1057f613c7dSKeith Owens extern void			ia64_os_init_dispatch_monarch (void);
1067f613c7dSKeith Owens extern void			ia64_os_init_dispatch_slave (void);
1077f613c7dSKeith Owens 
1087f613c7dSKeith Owens static int monarch_cpu = -1;
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds static ia64_mc_info_t		ia64_mc_info;
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds #define MAX_CPE_POLL_INTERVAL (15*60*HZ) /* 15 minutes */
1131da177e4SLinus Torvalds #define MIN_CPE_POLL_INTERVAL (2*60*HZ)  /* 2 minutes */
1141da177e4SLinus Torvalds #define CMC_POLL_INTERVAL     (1*60*HZ)  /* 1 minute */
1151da177e4SLinus Torvalds #define CPE_HISTORY_LENGTH    5
1161da177e4SLinus Torvalds #define CMC_HISTORY_LENGTH    5
1171da177e4SLinus Torvalds 
1181da177e4SLinus Torvalds static struct timer_list cpe_poll_timer;
1191da177e4SLinus Torvalds static struct timer_list cmc_poll_timer;
1201da177e4SLinus Torvalds /*
1211da177e4SLinus Torvalds  * This variable tells whether we are currently in polling mode.
1221da177e4SLinus Torvalds  * Start with this in the wrong state so we won't play w/ timers
1231da177e4SLinus Torvalds  * before the system is ready.
1241da177e4SLinus Torvalds  */
1251da177e4SLinus Torvalds static int cmc_polling_enabled = 1;
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds /*
1281da177e4SLinus Torvalds  * Clearing this variable prevents CPE polling from getting activated
1291da177e4SLinus Torvalds  * in mca_late_init.  Use it if your system doesn't provide a CPEI,
1301da177e4SLinus Torvalds  * but encounters problems retrieving CPE logs.  This should only be
1311da177e4SLinus Torvalds  * necessary for debugging.
1321da177e4SLinus Torvalds  */
1331da177e4SLinus Torvalds static int cpe_poll_enabled = 1;
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds extern void salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe);
1361da177e4SLinus Torvalds 
1370881fc8dSChen, Kenneth W static int mca_init __initdata;
1381da177e4SLinus Torvalds 
1399138d581SKeith Owens 
1409138d581SKeith Owens static void inline
1419138d581SKeith Owens ia64_mca_spin(const char *func)
1429138d581SKeith Owens {
1439138d581SKeith Owens 	printk(KERN_EMERG "%s: spinning here, not returning to SAL\n", func);
1449138d581SKeith Owens 	while (1)
1459138d581SKeith Owens 		cpu_relax();
1469138d581SKeith Owens }
1471da177e4SLinus Torvalds /*
1481da177e4SLinus Torvalds  * IA64_MCA log support
1491da177e4SLinus Torvalds  */
1501da177e4SLinus Torvalds #define IA64_MAX_LOGS		2	/* Double-buffering for nested MCAs */
1511da177e4SLinus Torvalds #define IA64_MAX_LOG_TYPES      4   /* MCA, INIT, CMC, CPE */
1521da177e4SLinus Torvalds 
1531da177e4SLinus Torvalds typedef struct ia64_state_log_s
1541da177e4SLinus Torvalds {
1551da177e4SLinus Torvalds 	spinlock_t	isl_lock;
1561da177e4SLinus Torvalds 	int		isl_index;
1571da177e4SLinus Torvalds 	unsigned long	isl_count;
1581da177e4SLinus Torvalds 	ia64_err_rec_t  *isl_log[IA64_MAX_LOGS]; /* need space to store header + error log */
1591da177e4SLinus Torvalds } ia64_state_log_t;
1601da177e4SLinus Torvalds 
1611da177e4SLinus Torvalds static ia64_state_log_t ia64_state_log[IA64_MAX_LOG_TYPES];
1621da177e4SLinus Torvalds 
1631da177e4SLinus Torvalds #define IA64_LOG_ALLOCATE(it, size) \
1641da177e4SLinus Torvalds 	{ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)] = \
1651da177e4SLinus Torvalds 		(ia64_err_rec_t *)alloc_bootmem(size); \
1661da177e4SLinus Torvalds 	ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)] = \
1671da177e4SLinus Torvalds 		(ia64_err_rec_t *)alloc_bootmem(size);}
1681da177e4SLinus Torvalds #define IA64_LOG_LOCK_INIT(it) spin_lock_init(&ia64_state_log[it].isl_lock)
1691da177e4SLinus Torvalds #define IA64_LOG_LOCK(it)      spin_lock_irqsave(&ia64_state_log[it].isl_lock, s)
1701da177e4SLinus Torvalds #define IA64_LOG_UNLOCK(it)    spin_unlock_irqrestore(&ia64_state_log[it].isl_lock,s)
1711da177e4SLinus Torvalds #define IA64_LOG_NEXT_INDEX(it)    ia64_state_log[it].isl_index
1721da177e4SLinus Torvalds #define IA64_LOG_CURR_INDEX(it)    1 - ia64_state_log[it].isl_index
1731da177e4SLinus Torvalds #define IA64_LOG_INDEX_INC(it) \
1741da177e4SLinus Torvalds     {ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index; \
1751da177e4SLinus Torvalds     ia64_state_log[it].isl_count++;}
1761da177e4SLinus Torvalds #define IA64_LOG_INDEX_DEC(it) \
1771da177e4SLinus Torvalds     ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index
1781da177e4SLinus Torvalds #define IA64_LOG_NEXT_BUFFER(it)   (void *)((ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)]))
1791da177e4SLinus Torvalds #define IA64_LOG_CURR_BUFFER(it)   (void *)((ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)]))
1801da177e4SLinus Torvalds #define IA64_LOG_COUNT(it)         ia64_state_log[it].isl_count
1811da177e4SLinus Torvalds 
1821da177e4SLinus Torvalds /*
1831da177e4SLinus Torvalds  * ia64_log_init
1841da177e4SLinus Torvalds  *	Reset the OS ia64 log buffer
1851da177e4SLinus Torvalds  * Inputs   :   info_type   (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
1861da177e4SLinus Torvalds  * Outputs	:	None
1871da177e4SLinus Torvalds  */
1880881fc8dSChen, Kenneth W static void __init
1891da177e4SLinus Torvalds ia64_log_init(int sal_info_type)
1901da177e4SLinus Torvalds {
1911da177e4SLinus Torvalds 	u64	max_size = 0;
1921da177e4SLinus Torvalds 
1931da177e4SLinus Torvalds 	IA64_LOG_NEXT_INDEX(sal_info_type) = 0;
1941da177e4SLinus Torvalds 	IA64_LOG_LOCK_INIT(sal_info_type);
1951da177e4SLinus Torvalds 
1961da177e4SLinus Torvalds 	// SAL will tell us the maximum size of any error record of this type
1971da177e4SLinus Torvalds 	max_size = ia64_sal_get_state_info_size(sal_info_type);
1981da177e4SLinus Torvalds 	if (!max_size)
1991da177e4SLinus Torvalds 		/* alloc_bootmem() doesn't like zero-sized allocations! */
2001da177e4SLinus Torvalds 		return;
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds 	// set up OS data structures to hold error info
2031da177e4SLinus Torvalds 	IA64_LOG_ALLOCATE(sal_info_type, max_size);
2041da177e4SLinus Torvalds 	memset(IA64_LOG_CURR_BUFFER(sal_info_type), 0, max_size);
2051da177e4SLinus Torvalds 	memset(IA64_LOG_NEXT_BUFFER(sal_info_type), 0, max_size);
2061da177e4SLinus Torvalds }
2071da177e4SLinus Torvalds 
2081da177e4SLinus Torvalds /*
2091da177e4SLinus Torvalds  * ia64_log_get
2101da177e4SLinus Torvalds  *
2111da177e4SLinus Torvalds  *	Get the current MCA log from SAL and copy it into the OS log buffer.
2121da177e4SLinus Torvalds  *
2131da177e4SLinus Torvalds  *  Inputs  :   info_type   (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
2141da177e4SLinus Torvalds  *              irq_safe    whether you can use printk at this point
2151da177e4SLinus Torvalds  *  Outputs :   size        (total record length)
2161da177e4SLinus Torvalds  *              *buffer     (ptr to error record)
2171da177e4SLinus Torvalds  *
2181da177e4SLinus Torvalds  */
2191da177e4SLinus Torvalds static u64
2201da177e4SLinus Torvalds ia64_log_get(int sal_info_type, u8 **buffer, int irq_safe)
2211da177e4SLinus Torvalds {
2221da177e4SLinus Torvalds 	sal_log_record_header_t     *log_buffer;
2231da177e4SLinus Torvalds 	u64                         total_len = 0;
2241da177e4SLinus Torvalds 	int                         s;
2251da177e4SLinus Torvalds 
2261da177e4SLinus Torvalds 	IA64_LOG_LOCK(sal_info_type);
2271da177e4SLinus Torvalds 
2281da177e4SLinus Torvalds 	/* Get the process state information */
2291da177e4SLinus Torvalds 	log_buffer = IA64_LOG_NEXT_BUFFER(sal_info_type);
2301da177e4SLinus Torvalds 
2311da177e4SLinus Torvalds 	total_len = ia64_sal_get_state_info(sal_info_type, (u64 *)log_buffer);
2321da177e4SLinus Torvalds 
2331da177e4SLinus Torvalds 	if (total_len) {
2341da177e4SLinus Torvalds 		IA64_LOG_INDEX_INC(sal_info_type);
2351da177e4SLinus Torvalds 		IA64_LOG_UNLOCK(sal_info_type);
2361da177e4SLinus Torvalds 		if (irq_safe) {
2371da177e4SLinus Torvalds 			IA64_MCA_DEBUG("%s: SAL error record type %d retrieved. "
2381da177e4SLinus Torvalds 				       "Record length = %ld\n", __FUNCTION__, sal_info_type, total_len);
2391da177e4SLinus Torvalds 		}
2401da177e4SLinus Torvalds 		*buffer = (u8 *) log_buffer;
2411da177e4SLinus Torvalds 		return total_len;
2421da177e4SLinus Torvalds 	} else {
2431da177e4SLinus Torvalds 		IA64_LOG_UNLOCK(sal_info_type);
2441da177e4SLinus Torvalds 		return 0;
2451da177e4SLinus Torvalds 	}
2461da177e4SLinus Torvalds }
2471da177e4SLinus Torvalds 
2481da177e4SLinus Torvalds /*
2491da177e4SLinus Torvalds  *  ia64_mca_log_sal_error_record
2501da177e4SLinus Torvalds  *
2511da177e4SLinus Torvalds  *  This function retrieves a specified error record type from SAL
2521da177e4SLinus Torvalds  *  and wakes up any processes waiting for error records.
2531da177e4SLinus Torvalds  *
2547f613c7dSKeith Owens  *  Inputs  :   sal_info_type   (Type of error record MCA/CMC/CPE)
2557f613c7dSKeith Owens  *              FIXME: remove MCA and irq_safe.
2561da177e4SLinus Torvalds  */
2571da177e4SLinus Torvalds static void
2581da177e4SLinus Torvalds ia64_mca_log_sal_error_record(int sal_info_type)
2591da177e4SLinus Torvalds {
2601da177e4SLinus Torvalds 	u8 *buffer;
2611da177e4SLinus Torvalds 	sal_log_record_header_t *rh;
2621da177e4SLinus Torvalds 	u64 size;
2637f613c7dSKeith Owens 	int irq_safe = sal_info_type != SAL_INFO_TYPE_MCA;
2641da177e4SLinus Torvalds #ifdef IA64_MCA_DEBUG_INFO
2651da177e4SLinus Torvalds 	static const char * const rec_name[] = { "MCA", "INIT", "CMC", "CPE" };
2661da177e4SLinus Torvalds #endif
2671da177e4SLinus Torvalds 
2681da177e4SLinus Torvalds 	size = ia64_log_get(sal_info_type, &buffer, irq_safe);
2691da177e4SLinus Torvalds 	if (!size)
2701da177e4SLinus Torvalds 		return;
2711da177e4SLinus Torvalds 
2721da177e4SLinus Torvalds 	salinfo_log_wakeup(sal_info_type, buffer, size, irq_safe);
2731da177e4SLinus Torvalds 
2741da177e4SLinus Torvalds 	if (irq_safe)
2751da177e4SLinus Torvalds 		IA64_MCA_DEBUG("CPU %d: SAL log contains %s error record\n",
2761da177e4SLinus Torvalds 			smp_processor_id(),
2771da177e4SLinus Torvalds 			sal_info_type < ARRAY_SIZE(rec_name) ? rec_name[sal_info_type] : "UNKNOWN");
2781da177e4SLinus Torvalds 
2791da177e4SLinus Torvalds 	/* Clear logs from corrected errors in case there's no user-level logger */
2801da177e4SLinus Torvalds 	rh = (sal_log_record_header_t *)buffer;
2811da177e4SLinus Torvalds 	if (rh->severity == sal_log_severity_corrected)
2821da177e4SLinus Torvalds 		ia64_sal_clear_state_info(sal_info_type);
2831da177e4SLinus Torvalds }
2841da177e4SLinus Torvalds 
285d2a28ad9SRuss Anderson /*
286d2a28ad9SRuss Anderson  * search_mca_table
287d2a28ad9SRuss Anderson  *  See if the MCA surfaced in an instruction range
288d2a28ad9SRuss Anderson  *  that has been tagged as recoverable.
289d2a28ad9SRuss Anderson  *
290d2a28ad9SRuss Anderson  *  Inputs
291d2a28ad9SRuss Anderson  *	first	First address range to check
292d2a28ad9SRuss Anderson  *	last	Last address range to check
293d2a28ad9SRuss Anderson  *	ip	Instruction pointer, address we are looking for
294d2a28ad9SRuss Anderson  *
295d2a28ad9SRuss Anderson  * Return value:
296d2a28ad9SRuss Anderson  *      1 on Success (in the table)/ 0 on Failure (not in the  table)
297d2a28ad9SRuss Anderson  */
298d2a28ad9SRuss Anderson int
299d2a28ad9SRuss Anderson search_mca_table (const struct mca_table_entry *first,
300d2a28ad9SRuss Anderson                 const struct mca_table_entry *last,
301d2a28ad9SRuss Anderson                 unsigned long ip)
302d2a28ad9SRuss Anderson {
303d2a28ad9SRuss Anderson         const struct mca_table_entry *curr;
304d2a28ad9SRuss Anderson         u64 curr_start, curr_end;
305d2a28ad9SRuss Anderson 
306d2a28ad9SRuss Anderson         curr = first;
307d2a28ad9SRuss Anderson         while (curr <= last) {
308d2a28ad9SRuss Anderson                 curr_start = (u64) &curr->start_addr + curr->start_addr;
309d2a28ad9SRuss Anderson                 curr_end = (u64) &curr->end_addr + curr->end_addr;
310d2a28ad9SRuss Anderson 
311d2a28ad9SRuss Anderson                 if ((ip >= curr_start) && (ip <= curr_end)) {
312d2a28ad9SRuss Anderson                         return 1;
313d2a28ad9SRuss Anderson                 }
314d2a28ad9SRuss Anderson                 curr++;
315d2a28ad9SRuss Anderson         }
316d2a28ad9SRuss Anderson         return 0;
317d2a28ad9SRuss Anderson }
318d2a28ad9SRuss Anderson 
319d2a28ad9SRuss Anderson /* Given an address, look for it in the mca tables. */
320d2a28ad9SRuss Anderson int mca_recover_range(unsigned long addr)
321d2a28ad9SRuss Anderson {
322d2a28ad9SRuss Anderson 	extern struct mca_table_entry __start___mca_table[];
323d2a28ad9SRuss Anderson 	extern struct mca_table_entry __stop___mca_table[];
324d2a28ad9SRuss Anderson 
325d2a28ad9SRuss Anderson 	return search_mca_table(__start___mca_table, __stop___mca_table-1, addr);
326d2a28ad9SRuss Anderson }
327d2a28ad9SRuss Anderson EXPORT_SYMBOL_GPL(mca_recover_range);
328d2a28ad9SRuss Anderson 
3291da177e4SLinus Torvalds #ifdef CONFIG_ACPI
3301da177e4SLinus Torvalds 
33155e59c51SAshok Raj int cpe_vector = -1;
332ff741906SAshok Raj int ia64_cpe_irq = -1;
3331da177e4SLinus Torvalds 
3341da177e4SLinus Torvalds static irqreturn_t
3351da177e4SLinus Torvalds ia64_mca_cpe_int_handler (int cpe_irq, void *arg, struct pt_regs *ptregs)
3361da177e4SLinus Torvalds {
3371da177e4SLinus Torvalds 	static unsigned long	cpe_history[CPE_HISTORY_LENGTH];
3381da177e4SLinus Torvalds 	static int		index;
3391da177e4SLinus Torvalds 	static DEFINE_SPINLOCK(cpe_history_lock);
3401da177e4SLinus Torvalds 
3411da177e4SLinus Torvalds 	IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
3421da177e4SLinus Torvalds 		       __FUNCTION__, cpe_irq, smp_processor_id());
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds 	/* SAL spec states this should run w/ interrupts enabled */
3451da177e4SLinus Torvalds 	local_irq_enable();
3461da177e4SLinus Torvalds 
3471da177e4SLinus Torvalds 	/* Get the CPE error record and log it */
3481da177e4SLinus Torvalds 	ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE);
3491da177e4SLinus Torvalds 
3501da177e4SLinus Torvalds 	spin_lock(&cpe_history_lock);
3511da177e4SLinus Torvalds 	if (!cpe_poll_enabled && cpe_vector >= 0) {
3521da177e4SLinus Torvalds 
3531da177e4SLinus Torvalds 		int i, count = 1; /* we know 1 happened now */
3541da177e4SLinus Torvalds 		unsigned long now = jiffies;
3551da177e4SLinus Torvalds 
3561da177e4SLinus Torvalds 		for (i = 0; i < CPE_HISTORY_LENGTH; i++) {
3571da177e4SLinus Torvalds 			if (now - cpe_history[i] <= HZ)
3581da177e4SLinus Torvalds 				count++;
3591da177e4SLinus Torvalds 		}
3601da177e4SLinus Torvalds 
3611da177e4SLinus Torvalds 		IA64_MCA_DEBUG(KERN_INFO "CPE threshold %d/%d\n", count, CPE_HISTORY_LENGTH);
3621da177e4SLinus Torvalds 		if (count >= CPE_HISTORY_LENGTH) {
3631da177e4SLinus Torvalds 
3641da177e4SLinus Torvalds 			cpe_poll_enabled = 1;
3651da177e4SLinus Torvalds 			spin_unlock(&cpe_history_lock);
3661da177e4SLinus Torvalds 			disable_irq_nosync(local_vector_to_irq(IA64_CPE_VECTOR));
3671da177e4SLinus Torvalds 
3681da177e4SLinus Torvalds 			/*
3691da177e4SLinus Torvalds 			 * Corrected errors will still be corrected, but
3701da177e4SLinus Torvalds 			 * make sure there's a log somewhere that indicates
3711da177e4SLinus Torvalds 			 * something is generating more than we can handle.
3721da177e4SLinus Torvalds 			 */
3731da177e4SLinus Torvalds 			printk(KERN_WARNING "WARNING: Switching to polling CPE handler; error records may be lost\n");
3741da177e4SLinus Torvalds 
3751da177e4SLinus Torvalds 			mod_timer(&cpe_poll_timer, jiffies + MIN_CPE_POLL_INTERVAL);
3761da177e4SLinus Torvalds 
3771da177e4SLinus Torvalds 			/* lock already released, get out now */
3781da177e4SLinus Torvalds 			return IRQ_HANDLED;
3791da177e4SLinus Torvalds 		} else {
3801da177e4SLinus Torvalds 			cpe_history[index++] = now;
3811da177e4SLinus Torvalds 			if (index == CPE_HISTORY_LENGTH)
3821da177e4SLinus Torvalds 				index = 0;
3831da177e4SLinus Torvalds 		}
3841da177e4SLinus Torvalds 	}
3851da177e4SLinus Torvalds 	spin_unlock(&cpe_history_lock);
3861da177e4SLinus Torvalds 	return IRQ_HANDLED;
3871da177e4SLinus Torvalds }
3881da177e4SLinus Torvalds 
3891da177e4SLinus Torvalds #endif /* CONFIG_ACPI */
3901da177e4SLinus Torvalds 
3911da177e4SLinus Torvalds #ifdef CONFIG_ACPI
3921da177e4SLinus Torvalds /*
3931da177e4SLinus Torvalds  * ia64_mca_register_cpev
3941da177e4SLinus Torvalds  *
3951da177e4SLinus Torvalds  *  Register the corrected platform error vector with SAL.
3961da177e4SLinus Torvalds  *
3971da177e4SLinus Torvalds  *  Inputs
3981da177e4SLinus Torvalds  *      cpev        Corrected Platform Error Vector number
3991da177e4SLinus Torvalds  *
4001da177e4SLinus Torvalds  *  Outputs
4011da177e4SLinus Torvalds  *      None
4021da177e4SLinus Torvalds  */
4030881fc8dSChen, Kenneth W static void __init
4041da177e4SLinus Torvalds ia64_mca_register_cpev (int cpev)
4051da177e4SLinus Torvalds {
4061da177e4SLinus Torvalds 	/* Register the CPE interrupt vector with SAL */
4071da177e4SLinus Torvalds 	struct ia64_sal_retval isrv;
4081da177e4SLinus Torvalds 
4091da177e4SLinus Torvalds 	isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_CPE_INT, SAL_MC_PARAM_MECHANISM_INT, cpev, 0, 0);
4101da177e4SLinus Torvalds 	if (isrv.status) {
4111da177e4SLinus Torvalds 		printk(KERN_ERR "Failed to register Corrected Platform "
4121da177e4SLinus Torvalds 		       "Error interrupt vector with SAL (status %ld)\n", isrv.status);
4131da177e4SLinus Torvalds 		return;
4141da177e4SLinus Torvalds 	}
4151da177e4SLinus Torvalds 
4161da177e4SLinus Torvalds 	IA64_MCA_DEBUG("%s: corrected platform error "
4171da177e4SLinus Torvalds 		       "vector %#x registered\n", __FUNCTION__, cpev);
4181da177e4SLinus Torvalds }
4191da177e4SLinus Torvalds #endif /* CONFIG_ACPI */
4201da177e4SLinus Torvalds 
4211da177e4SLinus Torvalds /*
4221da177e4SLinus Torvalds  * ia64_mca_cmc_vector_setup
4231da177e4SLinus Torvalds  *
4241da177e4SLinus Torvalds  *  Setup the corrected machine check vector register in the processor.
4251da177e4SLinus Torvalds  *  (The interrupt is masked on boot. ia64_mca_late_init unmask this.)
4261da177e4SLinus Torvalds  *  This function is invoked on a per-processor basis.
4271da177e4SLinus Torvalds  *
4281da177e4SLinus Torvalds  * Inputs
4291da177e4SLinus Torvalds  *      None
4301da177e4SLinus Torvalds  *
4311da177e4SLinus Torvalds  * Outputs
4321da177e4SLinus Torvalds  *	None
4331da177e4SLinus Torvalds  */
4340881fc8dSChen, Kenneth W void __cpuinit
4351da177e4SLinus Torvalds ia64_mca_cmc_vector_setup (void)
4361da177e4SLinus Torvalds {
4371da177e4SLinus Torvalds 	cmcv_reg_t	cmcv;
4381da177e4SLinus Torvalds 
4391da177e4SLinus Torvalds 	cmcv.cmcv_regval	= 0;
4401da177e4SLinus Torvalds 	cmcv.cmcv_mask		= 1;        /* Mask/disable interrupt at first */
4411da177e4SLinus Torvalds 	cmcv.cmcv_vector	= IA64_CMC_VECTOR;
4421da177e4SLinus Torvalds 	ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
4431da177e4SLinus Torvalds 
4441da177e4SLinus Torvalds 	IA64_MCA_DEBUG("%s: CPU %d corrected "
4451da177e4SLinus Torvalds 		       "machine check vector %#x registered.\n",
4461da177e4SLinus Torvalds 		       __FUNCTION__, smp_processor_id(), IA64_CMC_VECTOR);
4471da177e4SLinus Torvalds 
4481da177e4SLinus Torvalds 	IA64_MCA_DEBUG("%s: CPU %d CMCV = %#016lx\n",
4491da177e4SLinus Torvalds 		       __FUNCTION__, smp_processor_id(), ia64_getreg(_IA64_REG_CR_CMCV));
4501da177e4SLinus Torvalds }
4511da177e4SLinus Torvalds 
4521da177e4SLinus Torvalds /*
4531da177e4SLinus Torvalds  * ia64_mca_cmc_vector_disable
4541da177e4SLinus Torvalds  *
4551da177e4SLinus Torvalds  *  Mask the corrected machine check vector register in the processor.
4561da177e4SLinus Torvalds  *  This function is invoked on a per-processor basis.
4571da177e4SLinus Torvalds  *
4581da177e4SLinus Torvalds  * Inputs
4591da177e4SLinus Torvalds  *      dummy(unused)
4601da177e4SLinus Torvalds  *
4611da177e4SLinus Torvalds  * Outputs
4621da177e4SLinus Torvalds  *	None
4631da177e4SLinus Torvalds  */
4641da177e4SLinus Torvalds static void
4651da177e4SLinus Torvalds ia64_mca_cmc_vector_disable (void *dummy)
4661da177e4SLinus Torvalds {
4671da177e4SLinus Torvalds 	cmcv_reg_t	cmcv;
4681da177e4SLinus Torvalds 
4691da177e4SLinus Torvalds 	cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV);
4701da177e4SLinus Torvalds 
4711da177e4SLinus Torvalds 	cmcv.cmcv_mask = 1; /* Mask/disable interrupt */
4721da177e4SLinus Torvalds 	ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
4731da177e4SLinus Torvalds 
4741da177e4SLinus Torvalds 	IA64_MCA_DEBUG("%s: CPU %d corrected "
4751da177e4SLinus Torvalds 		       "machine check vector %#x disabled.\n",
4761da177e4SLinus Torvalds 		       __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector);
4771da177e4SLinus Torvalds }
4781da177e4SLinus Torvalds 
4791da177e4SLinus Torvalds /*
4801da177e4SLinus Torvalds  * ia64_mca_cmc_vector_enable
4811da177e4SLinus Torvalds  *
4821da177e4SLinus Torvalds  *  Unmask the corrected machine check vector register in the processor.
4831da177e4SLinus Torvalds  *  This function is invoked on a per-processor basis.
4841da177e4SLinus Torvalds  *
4851da177e4SLinus Torvalds  * Inputs
4861da177e4SLinus Torvalds  *      dummy(unused)
4871da177e4SLinus Torvalds  *
4881da177e4SLinus Torvalds  * Outputs
4891da177e4SLinus Torvalds  *	None
4901da177e4SLinus Torvalds  */
4911da177e4SLinus Torvalds static void
4921da177e4SLinus Torvalds ia64_mca_cmc_vector_enable (void *dummy)
4931da177e4SLinus Torvalds {
4941da177e4SLinus Torvalds 	cmcv_reg_t	cmcv;
4951da177e4SLinus Torvalds 
4961da177e4SLinus Torvalds 	cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV);
4971da177e4SLinus Torvalds 
4981da177e4SLinus Torvalds 	cmcv.cmcv_mask = 0; /* Unmask/enable interrupt */
4991da177e4SLinus Torvalds 	ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
5001da177e4SLinus Torvalds 
5011da177e4SLinus Torvalds 	IA64_MCA_DEBUG("%s: CPU %d corrected "
5021da177e4SLinus Torvalds 		       "machine check vector %#x enabled.\n",
5031da177e4SLinus Torvalds 		       __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector);
5041da177e4SLinus Torvalds }
5051da177e4SLinus Torvalds 
5061da177e4SLinus Torvalds /*
5071da177e4SLinus Torvalds  * ia64_mca_cmc_vector_disable_keventd
5081da177e4SLinus Torvalds  *
5091da177e4SLinus Torvalds  * Called via keventd (smp_call_function() is not safe in interrupt context) to
5101da177e4SLinus Torvalds  * disable the cmc interrupt vector.
5111da177e4SLinus Torvalds  */
5121da177e4SLinus Torvalds static void
5131da177e4SLinus Torvalds ia64_mca_cmc_vector_disable_keventd(void *unused)
5141da177e4SLinus Torvalds {
5151da177e4SLinus Torvalds 	on_each_cpu(ia64_mca_cmc_vector_disable, NULL, 1, 0);
5161da177e4SLinus Torvalds }
5171da177e4SLinus Torvalds 
5181da177e4SLinus Torvalds /*
5191da177e4SLinus Torvalds  * ia64_mca_cmc_vector_enable_keventd
5201da177e4SLinus Torvalds  *
5211da177e4SLinus Torvalds  * Called via keventd (smp_call_function() is not safe in interrupt context) to
5221da177e4SLinus Torvalds  * enable the cmc interrupt vector.
5231da177e4SLinus Torvalds  */
5241da177e4SLinus Torvalds static void
5251da177e4SLinus Torvalds ia64_mca_cmc_vector_enable_keventd(void *unused)
5261da177e4SLinus Torvalds {
5271da177e4SLinus Torvalds 	on_each_cpu(ia64_mca_cmc_vector_enable, NULL, 1, 0);
5281da177e4SLinus Torvalds }
5291da177e4SLinus Torvalds 
5301da177e4SLinus Torvalds /*
5311da177e4SLinus Torvalds  * ia64_mca_wakeup
5321da177e4SLinus Torvalds  *
5331da177e4SLinus Torvalds  *	Send an inter-cpu interrupt to wake-up a particular cpu
5341da177e4SLinus Torvalds  *	and mark that cpu to be out of rendez.
5351da177e4SLinus Torvalds  *
5361da177e4SLinus Torvalds  *  Inputs  :   cpuid
5371da177e4SLinus Torvalds  *  Outputs :   None
5381da177e4SLinus Torvalds  */
5391da177e4SLinus Torvalds static void
5401da177e4SLinus Torvalds ia64_mca_wakeup(int cpu)
5411da177e4SLinus Torvalds {
5421da177e4SLinus Torvalds 	platform_send_ipi(cpu, IA64_MCA_WAKEUP_VECTOR, IA64_IPI_DM_INT, 0);
5431da177e4SLinus Torvalds 	ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
5441da177e4SLinus Torvalds 
5451da177e4SLinus Torvalds }
5461da177e4SLinus Torvalds 
5471da177e4SLinus Torvalds /*
5481da177e4SLinus Torvalds  * ia64_mca_wakeup_all
5491da177e4SLinus Torvalds  *
5501da177e4SLinus Torvalds  *	Wakeup all the cpus which have rendez'ed previously.
5511da177e4SLinus Torvalds  *
5521da177e4SLinus Torvalds  *  Inputs  :   None
5531da177e4SLinus Torvalds  *  Outputs :   None
5541da177e4SLinus Torvalds  */
5551da177e4SLinus Torvalds static void
5561da177e4SLinus Torvalds ia64_mca_wakeup_all(void)
5571da177e4SLinus Torvalds {
5581da177e4SLinus Torvalds 	int cpu;
5591da177e4SLinus Torvalds 
5601da177e4SLinus Torvalds 	/* Clear the Rendez checkin flag for all cpus */
561ddf6d0a0Shawkes@sgi.com 	for_each_online_cpu(cpu) {
5621da177e4SLinus Torvalds 		if (ia64_mc_info.imi_rendez_checkin[cpu] == IA64_MCA_RENDEZ_CHECKIN_DONE)
5631da177e4SLinus Torvalds 			ia64_mca_wakeup(cpu);
5641da177e4SLinus Torvalds 	}
5651da177e4SLinus Torvalds 
5661da177e4SLinus Torvalds }
5671da177e4SLinus Torvalds 
5681da177e4SLinus Torvalds /*
5691da177e4SLinus Torvalds  * ia64_mca_rendez_interrupt_handler
5701da177e4SLinus Torvalds  *
5711da177e4SLinus Torvalds  *	This is handler used to put slave processors into spinloop
5721da177e4SLinus Torvalds  *	while the monarch processor does the mca handling and later
5731da177e4SLinus Torvalds  *	wake each slave up once the monarch is done.
5741da177e4SLinus Torvalds  *
5751da177e4SLinus Torvalds  *  Inputs  :   None
5761da177e4SLinus Torvalds  *  Outputs :   None
5771da177e4SLinus Torvalds  */
5781da177e4SLinus Torvalds static irqreturn_t
5799138d581SKeith Owens ia64_mca_rendez_int_handler(int rendez_irq, void *arg, struct pt_regs *regs)
5801da177e4SLinus Torvalds {
5811da177e4SLinus Torvalds 	unsigned long flags;
5821da177e4SLinus Torvalds 	int cpu = smp_processor_id();
583958b166cSKeith Owens 	struct ia64_mca_notify_die nd =
584958b166cSKeith Owens 		{ .sos = NULL, .monarch_cpu = &monarch_cpu };
5851da177e4SLinus Torvalds 
5861da177e4SLinus Torvalds 	/* Mask all interrupts */
5871da177e4SLinus Torvalds 	local_irq_save(flags);
588958b166cSKeith Owens 	if (notify_die(DIE_MCA_RENDZVOUS_ENTER, "MCA", regs, (long)&nd, 0, 0)
5899138d581SKeith Owens 			== NOTIFY_STOP)
5909138d581SKeith Owens 		ia64_mca_spin(__FUNCTION__);
5911da177e4SLinus Torvalds 
5921da177e4SLinus Torvalds 	ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_DONE;
5931da177e4SLinus Torvalds 	/* Register with the SAL monarch that the slave has
5941da177e4SLinus Torvalds 	 * reached SAL
5951da177e4SLinus Torvalds 	 */
5961da177e4SLinus Torvalds 	ia64_sal_mc_rendez();
5971da177e4SLinus Torvalds 
598958b166cSKeith Owens 	if (notify_die(DIE_MCA_RENDZVOUS_PROCESS, "MCA", regs, (long)&nd, 0, 0)
5999138d581SKeith Owens 			== NOTIFY_STOP)
6009138d581SKeith Owens 		ia64_mca_spin(__FUNCTION__);
6019138d581SKeith Owens 
6027f613c7dSKeith Owens 	/* Wait for the monarch cpu to exit. */
6037f613c7dSKeith Owens 	while (monarch_cpu != -1)
6047f613c7dSKeith Owens 	       cpu_relax();	/* spin until monarch leaves */
6051da177e4SLinus Torvalds 
606958b166cSKeith Owens 	if (notify_die(DIE_MCA_RENDZVOUS_LEAVE, "MCA", regs, (long)&nd, 0, 0)
6079138d581SKeith Owens 			== NOTIFY_STOP)
6089138d581SKeith Owens 		ia64_mca_spin(__FUNCTION__);
6099138d581SKeith Owens 
6101da177e4SLinus Torvalds 	/* Enable all interrupts */
6111da177e4SLinus Torvalds 	local_irq_restore(flags);
6121da177e4SLinus Torvalds 	return IRQ_HANDLED;
6131da177e4SLinus Torvalds }
6141da177e4SLinus Torvalds 
6151da177e4SLinus Torvalds /*
6161da177e4SLinus Torvalds  * ia64_mca_wakeup_int_handler
6171da177e4SLinus Torvalds  *
6181da177e4SLinus Torvalds  *	The interrupt handler for processing the inter-cpu interrupt to the
6191da177e4SLinus Torvalds  *	slave cpu which was spinning in the rendez loop.
6201da177e4SLinus Torvalds  *	Since this spinning is done by turning off the interrupts and
6211da177e4SLinus Torvalds  *	polling on the wakeup-interrupt bit in the IRR, there is
6221da177e4SLinus Torvalds  *	nothing useful to be done in the handler.
6231da177e4SLinus Torvalds  *
6241da177e4SLinus Torvalds  *  Inputs  :   wakeup_irq  (Wakeup-interrupt bit)
6251da177e4SLinus Torvalds  *	arg		(Interrupt handler specific argument)
6261da177e4SLinus Torvalds  *	ptregs		(Exception frame at the time of the interrupt)
6271da177e4SLinus Torvalds  *  Outputs :   None
6281da177e4SLinus Torvalds  *
6291da177e4SLinus Torvalds  */
6301da177e4SLinus Torvalds static irqreturn_t
6311da177e4SLinus Torvalds ia64_mca_wakeup_int_handler(int wakeup_irq, void *arg, struct pt_regs *ptregs)
6321da177e4SLinus Torvalds {
6331da177e4SLinus Torvalds 	return IRQ_HANDLED;
6341da177e4SLinus Torvalds }
6351da177e4SLinus Torvalds 
6361da177e4SLinus Torvalds /* Function pointer for extra MCA recovery */
6371da177e4SLinus Torvalds int (*ia64_mca_ucmc_extension)
6387f613c7dSKeith Owens 	(void*,struct ia64_sal_os_state*)
6391da177e4SLinus Torvalds 	= NULL;
6401da177e4SLinus Torvalds 
6411da177e4SLinus Torvalds int
6427f613c7dSKeith Owens ia64_reg_MCA_extension(int (*fn)(void *, struct ia64_sal_os_state *))
6431da177e4SLinus Torvalds {
6441da177e4SLinus Torvalds 	if (ia64_mca_ucmc_extension)
6451da177e4SLinus Torvalds 		return 1;
6461da177e4SLinus Torvalds 
6471da177e4SLinus Torvalds 	ia64_mca_ucmc_extension = fn;
6481da177e4SLinus Torvalds 	return 0;
6491da177e4SLinus Torvalds }
6501da177e4SLinus Torvalds 
6511da177e4SLinus Torvalds void
6521da177e4SLinus Torvalds ia64_unreg_MCA_extension(void)
6531da177e4SLinus Torvalds {
6541da177e4SLinus Torvalds 	if (ia64_mca_ucmc_extension)
6551da177e4SLinus Torvalds 		ia64_mca_ucmc_extension = NULL;
6561da177e4SLinus Torvalds }
6571da177e4SLinus Torvalds 
6581da177e4SLinus Torvalds EXPORT_SYMBOL(ia64_reg_MCA_extension);
6591da177e4SLinus Torvalds EXPORT_SYMBOL(ia64_unreg_MCA_extension);
6601da177e4SLinus Torvalds 
6617f613c7dSKeith Owens 
6627f613c7dSKeith Owens static inline void
6637f613c7dSKeith Owens copy_reg(const u64 *fr, u64 fnat, u64 *tr, u64 *tnat)
6647f613c7dSKeith Owens {
6657f613c7dSKeith Owens 	u64 fslot, tslot, nat;
6667f613c7dSKeith Owens 	*tr = *fr;
6677f613c7dSKeith Owens 	fslot = ((unsigned long)fr >> 3) & 63;
6687f613c7dSKeith Owens 	tslot = ((unsigned long)tr >> 3) & 63;
6697f613c7dSKeith Owens 	*tnat &= ~(1UL << tslot);
6707f613c7dSKeith Owens 	nat = (fnat >> fslot) & 1;
6717f613c7dSKeith Owens 	*tnat |= (nat << tslot);
6727f613c7dSKeith Owens }
6737f613c7dSKeith Owens 
674e9ac054dSKeith Owens /* Change the comm field on the MCA/INT task to include the pid that
675e9ac054dSKeith Owens  * was interrupted, it makes for easier debugging.  If that pid was 0
676e9ac054dSKeith Owens  * (swapper or nested MCA/INIT) then use the start of the previous comm
677e9ac054dSKeith Owens  * field suffixed with its cpu.
678e9ac054dSKeith Owens  */
679e9ac054dSKeith Owens 
680e9ac054dSKeith Owens static void
681*36c8b586SIngo Molnar ia64_mca_modify_comm(const struct task_struct *previous_current)
682e9ac054dSKeith Owens {
683e9ac054dSKeith Owens 	char *p, comm[sizeof(current->comm)];
684e9ac054dSKeith Owens 	if (previous_current->pid)
685e9ac054dSKeith Owens 		snprintf(comm, sizeof(comm), "%s %d",
686e9ac054dSKeith Owens 			current->comm, previous_current->pid);
687e9ac054dSKeith Owens 	else {
688e9ac054dSKeith Owens 		int l;
689e9ac054dSKeith Owens 		if ((p = strchr(previous_current->comm, ' ')))
690e9ac054dSKeith Owens 			l = p - previous_current->comm;
691e9ac054dSKeith Owens 		else
692e9ac054dSKeith Owens 			l = strlen(previous_current->comm);
693e9ac054dSKeith Owens 		snprintf(comm, sizeof(comm), "%s %*s %d",
694e9ac054dSKeith Owens 			current->comm, l, previous_current->comm,
695e9ac054dSKeith Owens 			task_thread_info(previous_current)->cpu);
696e9ac054dSKeith Owens 	}
697e9ac054dSKeith Owens 	memcpy(current->comm, comm, sizeof(current->comm));
698e9ac054dSKeith Owens }
699e9ac054dSKeith Owens 
7007f613c7dSKeith Owens /* On entry to this routine, we are running on the per cpu stack, see
7017f613c7dSKeith Owens  * mca_asm.h.  The original stack has not been touched by this event.  Some of
7027f613c7dSKeith Owens  * the original stack's registers will be in the RBS on this stack.  This stack
7037f613c7dSKeith Owens  * also contains a partial pt_regs and switch_stack, the rest of the data is in
7047f613c7dSKeith Owens  * PAL minstate.
7057f613c7dSKeith Owens  *
7067f613c7dSKeith Owens  * The first thing to do is modify the original stack to look like a blocked
7077f613c7dSKeith Owens  * task so we can run backtrace on the original task.  Also mark the per cpu
7087f613c7dSKeith Owens  * stack as current to ensure that we use the correct task state, it also means
7097f613c7dSKeith Owens  * that we can do backtrace on the MCA/INIT handler code itself.
7107f613c7dSKeith Owens  */
7117f613c7dSKeith Owens 
712*36c8b586SIngo Molnar static struct task_struct *
7137f613c7dSKeith Owens ia64_mca_modify_original_stack(struct pt_regs *regs,
7147f613c7dSKeith Owens 		const struct switch_stack *sw,
7157f613c7dSKeith Owens 		struct ia64_sal_os_state *sos,
7167f613c7dSKeith Owens 		const char *type)
7177f613c7dSKeith Owens {
718e9ac054dSKeith Owens 	char *p;
7197f613c7dSKeith Owens 	ia64_va va;
7207f613c7dSKeith Owens 	extern char ia64_leave_kernel[];	/* Need asm address, not function descriptor */
7217f613c7dSKeith Owens 	const pal_min_state_area_t *ms = sos->pal_min_state;
722*36c8b586SIngo Molnar 	struct task_struct *previous_current;
7237f613c7dSKeith Owens 	struct pt_regs *old_regs;
7247f613c7dSKeith Owens 	struct switch_stack *old_sw;
7257f613c7dSKeith Owens 	unsigned size = sizeof(struct pt_regs) +
7267f613c7dSKeith Owens 			sizeof(struct switch_stack) + 16;
7277f613c7dSKeith Owens 	u64 *old_bspstore, *old_bsp;
7287f613c7dSKeith Owens 	u64 *new_bspstore, *new_bsp;
7297f613c7dSKeith Owens 	u64 old_unat, old_rnat, new_rnat, nat;
7307f613c7dSKeith Owens 	u64 slots, loadrs = regs->loadrs;
7317f613c7dSKeith Owens 	u64 r12 = ms->pmsa_gr[12-1], r13 = ms->pmsa_gr[13-1];
7327f613c7dSKeith Owens 	u64 ar_bspstore = regs->ar_bspstore;
7337f613c7dSKeith Owens 	u64 ar_bsp = regs->ar_bspstore + (loadrs >> 16);
7347f613c7dSKeith Owens 	const u64 *bank;
7357f613c7dSKeith Owens 	const char *msg;
7367f613c7dSKeith Owens 	int cpu = smp_processor_id();
7377f613c7dSKeith Owens 
7387f613c7dSKeith Owens 	previous_current = curr_task(cpu);
7397f613c7dSKeith Owens 	set_curr_task(cpu, current);
7407f613c7dSKeith Owens 	if ((p = strchr(current->comm, ' ')))
7417f613c7dSKeith Owens 		*p = '\0';
7427f613c7dSKeith Owens 
7437f613c7dSKeith Owens 	/* Best effort attempt to cope with MCA/INIT delivered while in
7447f613c7dSKeith Owens 	 * physical mode.
7457f613c7dSKeith Owens 	 */
7467f613c7dSKeith Owens 	regs->cr_ipsr = ms->pmsa_ipsr;
7477f613c7dSKeith Owens 	if (ia64_psr(regs)->dt == 0) {
7487f613c7dSKeith Owens 		va.l = r12;
7497f613c7dSKeith Owens 		if (va.f.reg == 0) {
7507f613c7dSKeith Owens 			va.f.reg = 7;
7517f613c7dSKeith Owens 			r12 = va.l;
7527f613c7dSKeith Owens 		}
7537f613c7dSKeith Owens 		va.l = r13;
7547f613c7dSKeith Owens 		if (va.f.reg == 0) {
7557f613c7dSKeith Owens 			va.f.reg = 7;
7567f613c7dSKeith Owens 			r13 = va.l;
7577f613c7dSKeith Owens 		}
7587f613c7dSKeith Owens 	}
7597f613c7dSKeith Owens 	if (ia64_psr(regs)->rt == 0) {
7607f613c7dSKeith Owens 		va.l = ar_bspstore;
7617f613c7dSKeith Owens 		if (va.f.reg == 0) {
7627f613c7dSKeith Owens 			va.f.reg = 7;
7637f613c7dSKeith Owens 			ar_bspstore = va.l;
7647f613c7dSKeith Owens 		}
7657f613c7dSKeith Owens 		va.l = ar_bsp;
7667f613c7dSKeith Owens 		if (va.f.reg == 0) {
7677f613c7dSKeith Owens 			va.f.reg = 7;
7687f613c7dSKeith Owens 			ar_bsp = va.l;
7697f613c7dSKeith Owens 		}
7707f613c7dSKeith Owens 	}
7717f613c7dSKeith Owens 
7727f613c7dSKeith Owens 	/* mca_asm.S ia64_old_stack() cannot assume that the dirty registers
7737f613c7dSKeith Owens 	 * have been copied to the old stack, the old stack may fail the
7747f613c7dSKeith Owens 	 * validation tests below.  So ia64_old_stack() must restore the dirty
7757f613c7dSKeith Owens 	 * registers from the new stack.  The old and new bspstore probably
7767f613c7dSKeith Owens 	 * have different alignments, so loadrs calculated on the old bsp
7777f613c7dSKeith Owens 	 * cannot be used to restore from the new bsp.  Calculate a suitable
7787f613c7dSKeith Owens 	 * loadrs for the new stack and save it in the new pt_regs, where
7797f613c7dSKeith Owens 	 * ia64_old_stack() can get it.
7807f613c7dSKeith Owens 	 */
7817f613c7dSKeith Owens 	old_bspstore = (u64 *)ar_bspstore;
7827f613c7dSKeith Owens 	old_bsp = (u64 *)ar_bsp;
7837f613c7dSKeith Owens 	slots = ia64_rse_num_regs(old_bspstore, old_bsp);
7847f613c7dSKeith Owens 	new_bspstore = (u64 *)((u64)current + IA64_RBS_OFFSET);
7857f613c7dSKeith Owens 	new_bsp = ia64_rse_skip_regs(new_bspstore, slots);
7867f613c7dSKeith Owens 	regs->loadrs = (new_bsp - new_bspstore) * 8 << 16;
7877f613c7dSKeith Owens 
7887f613c7dSKeith Owens 	/* Verify the previous stack state before we change it */
7897f613c7dSKeith Owens 	if (user_mode(regs)) {
7907f613c7dSKeith Owens 		msg = "occurred in user space";
791e9ac054dSKeith Owens 		/* previous_current is guaranteed to be valid when the task was
792e9ac054dSKeith Owens 		 * in user space, so ...
793e9ac054dSKeith Owens 		 */
794e9ac054dSKeith Owens 		ia64_mca_modify_comm(previous_current);
7957f613c7dSKeith Owens 		goto no_mod;
7967f613c7dSKeith Owens 	}
797d2a28ad9SRuss Anderson 
798d2a28ad9SRuss Anderson 	if (!mca_recover_range(ms->pmsa_iip)) {
7997f613c7dSKeith Owens 		if (r13 != sos->prev_IA64_KR_CURRENT) {
8007f613c7dSKeith Owens 			msg = "inconsistent previous current and r13";
8017f613c7dSKeith Owens 			goto no_mod;
8027f613c7dSKeith Owens 		}
8037f613c7dSKeith Owens 		if ((r12 - r13) >= KERNEL_STACK_SIZE) {
8047f613c7dSKeith Owens 			msg = "inconsistent r12 and r13";
8057f613c7dSKeith Owens 			goto no_mod;
8067f613c7dSKeith Owens 		}
8077f613c7dSKeith Owens 		if ((ar_bspstore - r13) >= KERNEL_STACK_SIZE) {
8087f613c7dSKeith Owens 			msg = "inconsistent ar.bspstore and r13";
8097f613c7dSKeith Owens 			goto no_mod;
8107f613c7dSKeith Owens 		}
8117f613c7dSKeith Owens 		va.p = old_bspstore;
8127f613c7dSKeith Owens 		if (va.f.reg < 5) {
8137f613c7dSKeith Owens 			msg = "old_bspstore is in the wrong region";
8147f613c7dSKeith Owens 			goto no_mod;
8157f613c7dSKeith Owens 		}
8167f613c7dSKeith Owens 		if ((ar_bsp - r13) >= KERNEL_STACK_SIZE) {
8177f613c7dSKeith Owens 			msg = "inconsistent ar.bsp and r13";
8187f613c7dSKeith Owens 			goto no_mod;
8197f613c7dSKeith Owens 		}
8207f613c7dSKeith Owens 		size += (ia64_rse_skip_regs(old_bspstore, slots) - old_bspstore) * 8;
8217f613c7dSKeith Owens 		if (ar_bspstore + size > r12) {
8227f613c7dSKeith Owens 			msg = "no room for blocked state";
8237f613c7dSKeith Owens 			goto no_mod;
8247f613c7dSKeith Owens 		}
825d2a28ad9SRuss Anderson 	}
8267f613c7dSKeith Owens 
827e9ac054dSKeith Owens 	ia64_mca_modify_comm(previous_current);
8287f613c7dSKeith Owens 
8297f613c7dSKeith Owens 	/* Make the original task look blocked.  First stack a struct pt_regs,
8307f613c7dSKeith Owens 	 * describing the state at the time of interrupt.  mca_asm.S built a
8317f613c7dSKeith Owens 	 * partial pt_regs, copy it and fill in the blanks using minstate.
8327f613c7dSKeith Owens 	 */
8337f613c7dSKeith Owens 	p = (char *)r12 - sizeof(*regs);
8347f613c7dSKeith Owens 	old_regs = (struct pt_regs *)p;
8357f613c7dSKeith Owens 	memcpy(old_regs, regs, sizeof(*regs));
8367f613c7dSKeith Owens 	/* If ipsr.ic then use pmsa_{iip,ipsr,ifs}, else use
8377f613c7dSKeith Owens 	 * pmsa_{xip,xpsr,xfs}
8387f613c7dSKeith Owens 	 */
8397f613c7dSKeith Owens 	if (ia64_psr(regs)->ic) {
8407f613c7dSKeith Owens 		old_regs->cr_iip = ms->pmsa_iip;
8417f613c7dSKeith Owens 		old_regs->cr_ipsr = ms->pmsa_ipsr;
8427f613c7dSKeith Owens 		old_regs->cr_ifs = ms->pmsa_ifs;
8437f613c7dSKeith Owens 	} else {
8447f613c7dSKeith Owens 		old_regs->cr_iip = ms->pmsa_xip;
8457f613c7dSKeith Owens 		old_regs->cr_ipsr = ms->pmsa_xpsr;
8467f613c7dSKeith Owens 		old_regs->cr_ifs = ms->pmsa_xfs;
8477f613c7dSKeith Owens 	}
8487f613c7dSKeith Owens 	old_regs->pr = ms->pmsa_pr;
8497f613c7dSKeith Owens 	old_regs->b0 = ms->pmsa_br0;
8507f613c7dSKeith Owens 	old_regs->loadrs = loadrs;
8517f613c7dSKeith Owens 	old_regs->ar_rsc = ms->pmsa_rsc;
8527f613c7dSKeith Owens 	old_unat = old_regs->ar_unat;
8537f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[1-1], ms->pmsa_nat_bits, &old_regs->r1, &old_unat);
8547f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[2-1], ms->pmsa_nat_bits, &old_regs->r2, &old_unat);
8557f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[3-1], ms->pmsa_nat_bits, &old_regs->r3, &old_unat);
8567f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[8-1], ms->pmsa_nat_bits, &old_regs->r8, &old_unat);
8577f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[9-1], ms->pmsa_nat_bits, &old_regs->r9, &old_unat);
8587f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[10-1], ms->pmsa_nat_bits, &old_regs->r10, &old_unat);
8597f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[11-1], ms->pmsa_nat_bits, &old_regs->r11, &old_unat);
8607f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[12-1], ms->pmsa_nat_bits, &old_regs->r12, &old_unat);
8617f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[13-1], ms->pmsa_nat_bits, &old_regs->r13, &old_unat);
8627f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[14-1], ms->pmsa_nat_bits, &old_regs->r14, &old_unat);
8637f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[15-1], ms->pmsa_nat_bits, &old_regs->r15, &old_unat);
8647f613c7dSKeith Owens 	if (ia64_psr(old_regs)->bn)
8657f613c7dSKeith Owens 		bank = ms->pmsa_bank1_gr;
8667f613c7dSKeith Owens 	else
8677f613c7dSKeith Owens 		bank = ms->pmsa_bank0_gr;
8687f613c7dSKeith Owens 	copy_reg(&bank[16-16], ms->pmsa_nat_bits, &old_regs->r16, &old_unat);
8697f613c7dSKeith Owens 	copy_reg(&bank[17-16], ms->pmsa_nat_bits, &old_regs->r17, &old_unat);
8707f613c7dSKeith Owens 	copy_reg(&bank[18-16], ms->pmsa_nat_bits, &old_regs->r18, &old_unat);
8717f613c7dSKeith Owens 	copy_reg(&bank[19-16], ms->pmsa_nat_bits, &old_regs->r19, &old_unat);
8727f613c7dSKeith Owens 	copy_reg(&bank[20-16], ms->pmsa_nat_bits, &old_regs->r20, &old_unat);
8737f613c7dSKeith Owens 	copy_reg(&bank[21-16], ms->pmsa_nat_bits, &old_regs->r21, &old_unat);
8747f613c7dSKeith Owens 	copy_reg(&bank[22-16], ms->pmsa_nat_bits, &old_regs->r22, &old_unat);
8757f613c7dSKeith Owens 	copy_reg(&bank[23-16], ms->pmsa_nat_bits, &old_regs->r23, &old_unat);
8767f613c7dSKeith Owens 	copy_reg(&bank[24-16], ms->pmsa_nat_bits, &old_regs->r24, &old_unat);
8777f613c7dSKeith Owens 	copy_reg(&bank[25-16], ms->pmsa_nat_bits, &old_regs->r25, &old_unat);
8787f613c7dSKeith Owens 	copy_reg(&bank[26-16], ms->pmsa_nat_bits, &old_regs->r26, &old_unat);
8797f613c7dSKeith Owens 	copy_reg(&bank[27-16], ms->pmsa_nat_bits, &old_regs->r27, &old_unat);
8807f613c7dSKeith Owens 	copy_reg(&bank[28-16], ms->pmsa_nat_bits, &old_regs->r28, &old_unat);
8817f613c7dSKeith Owens 	copy_reg(&bank[29-16], ms->pmsa_nat_bits, &old_regs->r29, &old_unat);
8827f613c7dSKeith Owens 	copy_reg(&bank[30-16], ms->pmsa_nat_bits, &old_regs->r30, &old_unat);
8837f613c7dSKeith Owens 	copy_reg(&bank[31-16], ms->pmsa_nat_bits, &old_regs->r31, &old_unat);
8847f613c7dSKeith Owens 
8857f613c7dSKeith Owens 	/* Next stack a struct switch_stack.  mca_asm.S built a partial
8867f613c7dSKeith Owens 	 * switch_stack, copy it and fill in the blanks using pt_regs and
8877f613c7dSKeith Owens 	 * minstate.
8887f613c7dSKeith Owens 	 *
8897f613c7dSKeith Owens 	 * In the synthesized switch_stack, b0 points to ia64_leave_kernel,
8907f613c7dSKeith Owens 	 * ar.pfs is set to 0.
8917f613c7dSKeith Owens 	 *
8927f613c7dSKeith Owens 	 * unwind.c::unw_unwind() does special processing for interrupt frames.
8937f613c7dSKeith Owens 	 * It checks if the PRED_NON_SYSCALL predicate is set, if the predicate
8947f613c7dSKeith Owens 	 * is clear then unw_unwind() does _not_ adjust bsp over pt_regs.  Not
8957f613c7dSKeith Owens 	 * that this is documented, of course.  Set PRED_NON_SYSCALL in the
8967f613c7dSKeith Owens 	 * switch_stack on the original stack so it will unwind correctly when
8977f613c7dSKeith Owens 	 * unwind.c reads pt_regs.
8987f613c7dSKeith Owens 	 *
8997f613c7dSKeith Owens 	 * thread.ksp is updated to point to the synthesized switch_stack.
9007f613c7dSKeith Owens 	 */
9017f613c7dSKeith Owens 	p -= sizeof(struct switch_stack);
9027f613c7dSKeith Owens 	old_sw = (struct switch_stack *)p;
9037f613c7dSKeith Owens 	memcpy(old_sw, sw, sizeof(*sw));
9047f613c7dSKeith Owens 	old_sw->caller_unat = old_unat;
9057f613c7dSKeith Owens 	old_sw->ar_fpsr = old_regs->ar_fpsr;
9067f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[4-1], ms->pmsa_nat_bits, &old_sw->r4, &old_unat);
9077f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[5-1], ms->pmsa_nat_bits, &old_sw->r5, &old_unat);
9087f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[6-1], ms->pmsa_nat_bits, &old_sw->r6, &old_unat);
9097f613c7dSKeith Owens 	copy_reg(&ms->pmsa_gr[7-1], ms->pmsa_nat_bits, &old_sw->r7, &old_unat);
9107f613c7dSKeith Owens 	old_sw->b0 = (u64)ia64_leave_kernel;
9117f613c7dSKeith Owens 	old_sw->b1 = ms->pmsa_br1;
9127f613c7dSKeith Owens 	old_sw->ar_pfs = 0;
9137f613c7dSKeith Owens 	old_sw->ar_unat = old_unat;
9147f613c7dSKeith Owens 	old_sw->pr = old_regs->pr | (1UL << PRED_NON_SYSCALL);
9157f613c7dSKeith Owens 	previous_current->thread.ksp = (u64)p - 16;
9167f613c7dSKeith Owens 
9177f613c7dSKeith Owens 	/* Finally copy the original stack's registers back to its RBS.
9187f613c7dSKeith Owens 	 * Registers from ar.bspstore through ar.bsp at the time of the event
9197f613c7dSKeith Owens 	 * are in the current RBS, copy them back to the original stack.  The
9207f613c7dSKeith Owens 	 * copy must be done register by register because the original bspstore
9217f613c7dSKeith Owens 	 * and the current one have different alignments, so the saved RNAT
9227f613c7dSKeith Owens 	 * data occurs at different places.
9237f613c7dSKeith Owens 	 *
9247f613c7dSKeith Owens 	 * mca_asm does cover, so the old_bsp already includes all registers at
9257f613c7dSKeith Owens 	 * the time of MCA/INIT.  It also does flushrs, so all registers before
9267f613c7dSKeith Owens 	 * this function have been written to backing store on the MCA/INIT
9277f613c7dSKeith Owens 	 * stack.
9287f613c7dSKeith Owens 	 */
9297f613c7dSKeith Owens 	new_rnat = ia64_get_rnat(ia64_rse_rnat_addr(new_bspstore));
9307f613c7dSKeith Owens 	old_rnat = regs->ar_rnat;
9317f613c7dSKeith Owens 	while (slots--) {
9327f613c7dSKeith Owens 		if (ia64_rse_is_rnat_slot(new_bspstore)) {
9337f613c7dSKeith Owens 			new_rnat = ia64_get_rnat(new_bspstore++);
9347f613c7dSKeith Owens 		}
9357f613c7dSKeith Owens 		if (ia64_rse_is_rnat_slot(old_bspstore)) {
9367f613c7dSKeith Owens 			*old_bspstore++ = old_rnat;
9377f613c7dSKeith Owens 			old_rnat = 0;
9387f613c7dSKeith Owens 		}
9397f613c7dSKeith Owens 		nat = (new_rnat >> ia64_rse_slot_num(new_bspstore)) & 1UL;
9407f613c7dSKeith Owens 		old_rnat &= ~(1UL << ia64_rse_slot_num(old_bspstore));
9417f613c7dSKeith Owens 		old_rnat |= (nat << ia64_rse_slot_num(old_bspstore));
9427f613c7dSKeith Owens 		*old_bspstore++ = *new_bspstore++;
9437f613c7dSKeith Owens 	}
9447f613c7dSKeith Owens 	old_sw->ar_bspstore = (unsigned long)old_bspstore;
9457f613c7dSKeith Owens 	old_sw->ar_rnat = old_rnat;
9467f613c7dSKeith Owens 
9477f613c7dSKeith Owens 	sos->prev_task = previous_current;
9487f613c7dSKeith Owens 	return previous_current;
9497f613c7dSKeith Owens 
9507f613c7dSKeith Owens no_mod:
9517f613c7dSKeith Owens 	printk(KERN_INFO "cpu %d, %s %s, original stack not modified\n",
9527f613c7dSKeith Owens 			smp_processor_id(), type, msg);
9537f613c7dSKeith Owens 	return previous_current;
9547f613c7dSKeith Owens }
9557f613c7dSKeith Owens 
9567f613c7dSKeith Owens /* The monarch/slave interaction is based on monarch_cpu and requires that all
9577f613c7dSKeith Owens  * slaves have entered rendezvous before the monarch leaves.  If any cpu has
9587f613c7dSKeith Owens  * not entered rendezvous yet then wait a bit.  The assumption is that any
9597f613c7dSKeith Owens  * slave that has not rendezvoused after a reasonable time is never going to do
9607f613c7dSKeith Owens  * so.  In this context, slave includes cpus that respond to the MCA rendezvous
9617f613c7dSKeith Owens  * interrupt, as well as cpus that receive the INIT slave event.
9627f613c7dSKeith Owens  */
9637f613c7dSKeith Owens 
9647f613c7dSKeith Owens static void
965356a5c1cSKeith Owens ia64_wait_for_slaves(int monarch, const char *type)
9667f613c7dSKeith Owens {
9679336b083SKeith Owens 	int c, wait = 0, missing = 0;
9687f613c7dSKeith Owens 	for_each_online_cpu(c) {
9697f613c7dSKeith Owens 		if (c == monarch)
9707f613c7dSKeith Owens 			continue;
9717f613c7dSKeith Owens 		if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) {
9727f613c7dSKeith Owens 			udelay(1000);		/* short wait first */
9737f613c7dSKeith Owens 			wait = 1;
9747f613c7dSKeith Owens 			break;
9757f613c7dSKeith Owens 		}
9767f613c7dSKeith Owens 	}
9777f613c7dSKeith Owens 	if (!wait)
9789336b083SKeith Owens 		goto all_in;
9797f613c7dSKeith Owens 	for_each_online_cpu(c) {
9807f613c7dSKeith Owens 		if (c == monarch)
9817f613c7dSKeith Owens 			continue;
9827f613c7dSKeith Owens 		if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) {
9837f613c7dSKeith Owens 			udelay(5*1000000);	/* wait 5 seconds for slaves (arbitrary) */
9849336b083SKeith Owens 			if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE)
9859336b083SKeith Owens 				missing = 1;
9867f613c7dSKeith Owens 			break;
9877f613c7dSKeith Owens 		}
9887f613c7dSKeith Owens 	}
9899336b083SKeith Owens 	if (!missing)
9909336b083SKeith Owens 		goto all_in;
991356a5c1cSKeith Owens 	printk(KERN_INFO "OS %s slave did not rendezvous on cpu", type);
9929336b083SKeith Owens 	for_each_online_cpu(c) {
9939336b083SKeith Owens 		if (c == monarch)
9949336b083SKeith Owens 			continue;
9959336b083SKeith Owens 		if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE)
9969336b083SKeith Owens 			printk(" %d", c);
9979336b083SKeith Owens 	}
9989336b083SKeith Owens 	printk("\n");
9999336b083SKeith Owens 	return;
10009336b083SKeith Owens 
10019336b083SKeith Owens all_in:
1002356a5c1cSKeith Owens 	printk(KERN_INFO "All OS %s slaves have reached rendezvous\n", type);
10039336b083SKeith Owens 	return;
10047f613c7dSKeith Owens }
10057f613c7dSKeith Owens 
10061da177e4SLinus Torvalds /*
10077f613c7dSKeith Owens  * ia64_mca_handler
10081da177e4SLinus Torvalds  *
10091da177e4SLinus Torvalds  *	This is uncorrectable machine check handler called from OS_MCA
10101da177e4SLinus Torvalds  *	dispatch code which is in turn called from SAL_CHECK().
10111da177e4SLinus Torvalds  *	This is the place where the core of OS MCA handling is done.
10121da177e4SLinus Torvalds  *	Right now the logs are extracted and displayed in a well-defined
10131da177e4SLinus Torvalds  *	format. This handler code is supposed to be run only on the
10141da177e4SLinus Torvalds  *	monarch processor. Once the monarch is done with MCA handling
10151da177e4SLinus Torvalds  *	further MCA logging is enabled by clearing logs.
10161da177e4SLinus Torvalds  *	Monarch also has the duty of sending wakeup-IPIs to pull the
10171da177e4SLinus Torvalds  *	slave processors out of rendezvous spinloop.
10181da177e4SLinus Torvalds  */
10191da177e4SLinus Torvalds void
10207f613c7dSKeith Owens ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw,
10217f613c7dSKeith Owens 		 struct ia64_sal_os_state *sos)
10221da177e4SLinus Torvalds {
10231da177e4SLinus Torvalds 	pal_processor_state_info_t *psp = (pal_processor_state_info_t *)
10247f613c7dSKeith Owens 		&sos->proc_state_param;
10257f613c7dSKeith Owens 	int recover, cpu = smp_processor_id();
1026*36c8b586SIngo Molnar 	struct task_struct *previous_current;
1027958b166cSKeith Owens 	struct ia64_mca_notify_die nd =
1028958b166cSKeith Owens 		{ .sos = sos, .monarch_cpu = &monarch_cpu };
10297f613c7dSKeith Owens 
10307f613c7dSKeith Owens 	oops_in_progress = 1;	/* FIXME: make printk NMI/MCA/INIT safe */
10319336b083SKeith Owens 	console_loglevel = 15;	/* make sure printks make it to console */
10329336b083SKeith Owens 	printk(KERN_INFO "Entered OS MCA handler. PSP=%lx cpu=%d monarch=%ld\n",
10339336b083SKeith Owens 		sos->proc_state_param, cpu, sos->monarch);
10349336b083SKeith Owens 
10357f613c7dSKeith Owens 	previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "MCA");
10367f613c7dSKeith Owens 	monarch_cpu = cpu;
1037958b166cSKeith Owens 	if (notify_die(DIE_MCA_MONARCH_ENTER, "MCA", regs, (long)&nd, 0, 0)
10389138d581SKeith Owens 			== NOTIFY_STOP)
10399138d581SKeith Owens 		ia64_mca_spin(__FUNCTION__);
1040356a5c1cSKeith Owens 	ia64_wait_for_slaves(cpu, "MCA");
10417f613c7dSKeith Owens 
10427f613c7dSKeith Owens 	/* Wakeup all the processors which are spinning in the rendezvous loop.
10437f613c7dSKeith Owens 	 * They will leave SAL, then spin in the OS with interrupts disabled
10447f613c7dSKeith Owens 	 * until this monarch cpu leaves the MCA handler.  That gets control
10457f613c7dSKeith Owens 	 * back to the OS so we can backtrace the other cpus, backtrace when
10467f613c7dSKeith Owens 	 * spinning in SAL does not work.
10477f613c7dSKeith Owens 	 */
10487f613c7dSKeith Owens 	ia64_mca_wakeup_all();
1049958b166cSKeith Owens 	if (notify_die(DIE_MCA_MONARCH_PROCESS, "MCA", regs, (long)&nd, 0, 0)
10509138d581SKeith Owens 			== NOTIFY_STOP)
10519138d581SKeith Owens 		ia64_mca_spin(__FUNCTION__);
10521da177e4SLinus Torvalds 
10531da177e4SLinus Torvalds 	/* Get the MCA error record and log it */
10541da177e4SLinus Torvalds 	ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA);
10551da177e4SLinus Torvalds 
10561da177e4SLinus Torvalds 	/* TLB error is only exist in this SAL error record */
10571da177e4SLinus Torvalds 	recover = (psp->tc && !(psp->cc || psp->bc || psp->rc || psp->uc))
10581da177e4SLinus Torvalds 	/* other error recovery */
10591da177e4SLinus Torvalds 	   || (ia64_mca_ucmc_extension
10601da177e4SLinus Torvalds 		&& ia64_mca_ucmc_extension(
10611da177e4SLinus Torvalds 			IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA),
10627f613c7dSKeith Owens 			sos));
10631da177e4SLinus Torvalds 
10641da177e4SLinus Torvalds 	if (recover) {
10651da177e4SLinus Torvalds 		sal_log_record_header_t *rh = IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA);
10661da177e4SLinus Torvalds 		rh->severity = sal_log_severity_corrected;
10671da177e4SLinus Torvalds 		ia64_sal_clear_state_info(SAL_INFO_TYPE_MCA);
10687f613c7dSKeith Owens 		sos->os_status = IA64_MCA_CORRECTED;
10691da177e4SLinus Torvalds 	}
1070958b166cSKeith Owens 	if (notify_die(DIE_MCA_MONARCH_LEAVE, "MCA", regs, (long)&nd, 0, recover)
10719138d581SKeith Owens 			== NOTIFY_STOP)
10729138d581SKeith Owens 		ia64_mca_spin(__FUNCTION__);
10731da177e4SLinus Torvalds 
10747f613c7dSKeith Owens 	set_curr_task(cpu, previous_current);
10757f613c7dSKeith Owens 	monarch_cpu = -1;
10761da177e4SLinus Torvalds }
10771da177e4SLinus Torvalds 
10781da177e4SLinus Torvalds static DECLARE_WORK(cmc_disable_work, ia64_mca_cmc_vector_disable_keventd, NULL);
10791da177e4SLinus Torvalds static DECLARE_WORK(cmc_enable_work, ia64_mca_cmc_vector_enable_keventd, NULL);
10801da177e4SLinus Torvalds 
10811da177e4SLinus Torvalds /*
10821da177e4SLinus Torvalds  * ia64_mca_cmc_int_handler
10831da177e4SLinus Torvalds  *
10841da177e4SLinus Torvalds  *  This is corrected machine check interrupt handler.
10851da177e4SLinus Torvalds  *	Right now the logs are extracted and displayed in a well-defined
10861da177e4SLinus Torvalds  *	format.
10871da177e4SLinus Torvalds  *
10881da177e4SLinus Torvalds  * Inputs
10891da177e4SLinus Torvalds  *      interrupt number
10901da177e4SLinus Torvalds  *      client data arg ptr
10911da177e4SLinus Torvalds  *      saved registers ptr
10921da177e4SLinus Torvalds  *
10931da177e4SLinus Torvalds  * Outputs
10941da177e4SLinus Torvalds  *	None
10951da177e4SLinus Torvalds  */
10961da177e4SLinus Torvalds static irqreturn_t
10971da177e4SLinus Torvalds ia64_mca_cmc_int_handler(int cmc_irq, void *arg, struct pt_regs *ptregs)
10981da177e4SLinus Torvalds {
10991da177e4SLinus Torvalds 	static unsigned long	cmc_history[CMC_HISTORY_LENGTH];
11001da177e4SLinus Torvalds 	static int		index;
11011da177e4SLinus Torvalds 	static DEFINE_SPINLOCK(cmc_history_lock);
11021da177e4SLinus Torvalds 
11031da177e4SLinus Torvalds 	IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
11041da177e4SLinus Torvalds 		       __FUNCTION__, cmc_irq, smp_processor_id());
11051da177e4SLinus Torvalds 
11061da177e4SLinus Torvalds 	/* SAL spec states this should run w/ interrupts enabled */
11071da177e4SLinus Torvalds 	local_irq_enable();
11081da177e4SLinus Torvalds 
11091da177e4SLinus Torvalds 	/* Get the CMC error record and log it */
11101da177e4SLinus Torvalds 	ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC);
11111da177e4SLinus Torvalds 
11121da177e4SLinus Torvalds 	spin_lock(&cmc_history_lock);
11131da177e4SLinus Torvalds 	if (!cmc_polling_enabled) {
11141da177e4SLinus Torvalds 		int i, count = 1; /* we know 1 happened now */
11151da177e4SLinus Torvalds 		unsigned long now = jiffies;
11161da177e4SLinus Torvalds 
11171da177e4SLinus Torvalds 		for (i = 0; i < CMC_HISTORY_LENGTH; i++) {
11181da177e4SLinus Torvalds 			if (now - cmc_history[i] <= HZ)
11191da177e4SLinus Torvalds 				count++;
11201da177e4SLinus Torvalds 		}
11211da177e4SLinus Torvalds 
11221da177e4SLinus Torvalds 		IA64_MCA_DEBUG(KERN_INFO "CMC threshold %d/%d\n", count, CMC_HISTORY_LENGTH);
11231da177e4SLinus Torvalds 		if (count >= CMC_HISTORY_LENGTH) {
11241da177e4SLinus Torvalds 
11251da177e4SLinus Torvalds 			cmc_polling_enabled = 1;
11261da177e4SLinus Torvalds 			spin_unlock(&cmc_history_lock);
112776e677e2SBryan Sutula 			/* If we're being hit with CMC interrupts, we won't
112876e677e2SBryan Sutula 			 * ever execute the schedule_work() below.  Need to
112976e677e2SBryan Sutula 			 * disable CMC interrupts on this processor now.
113076e677e2SBryan Sutula 			 */
113176e677e2SBryan Sutula 			ia64_mca_cmc_vector_disable(NULL);
11321da177e4SLinus Torvalds 			schedule_work(&cmc_disable_work);
11331da177e4SLinus Torvalds 
11341da177e4SLinus Torvalds 			/*
11351da177e4SLinus Torvalds 			 * Corrected errors will still be corrected, but
11361da177e4SLinus Torvalds 			 * make sure there's a log somewhere that indicates
11371da177e4SLinus Torvalds 			 * something is generating more than we can handle.
11381da177e4SLinus Torvalds 			 */
11391da177e4SLinus Torvalds 			printk(KERN_WARNING "WARNING: Switching to polling CMC handler; error records may be lost\n");
11401da177e4SLinus Torvalds 
11411da177e4SLinus Torvalds 			mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
11421da177e4SLinus Torvalds 
11431da177e4SLinus Torvalds 			/* lock already released, get out now */
11441da177e4SLinus Torvalds 			return IRQ_HANDLED;
11451da177e4SLinus Torvalds 		} else {
11461da177e4SLinus Torvalds 			cmc_history[index++] = now;
11471da177e4SLinus Torvalds 			if (index == CMC_HISTORY_LENGTH)
11481da177e4SLinus Torvalds 				index = 0;
11491da177e4SLinus Torvalds 		}
11501da177e4SLinus Torvalds 	}
11511da177e4SLinus Torvalds 	spin_unlock(&cmc_history_lock);
11521da177e4SLinus Torvalds 	return IRQ_HANDLED;
11531da177e4SLinus Torvalds }
11541da177e4SLinus Torvalds 
11551da177e4SLinus Torvalds /*
11561da177e4SLinus Torvalds  *  ia64_mca_cmc_int_caller
11571da177e4SLinus Torvalds  *
11581da177e4SLinus Torvalds  * 	Triggered by sw interrupt from CMC polling routine.  Calls
11591da177e4SLinus Torvalds  * 	real interrupt handler and either triggers a sw interrupt
11601da177e4SLinus Torvalds  * 	on the next cpu or does cleanup at the end.
11611da177e4SLinus Torvalds  *
11621da177e4SLinus Torvalds  * Inputs
11631da177e4SLinus Torvalds  *	interrupt number
11641da177e4SLinus Torvalds  *	client data arg ptr
11651da177e4SLinus Torvalds  *	saved registers ptr
11661da177e4SLinus Torvalds  * Outputs
11671da177e4SLinus Torvalds  * 	handled
11681da177e4SLinus Torvalds  */
11691da177e4SLinus Torvalds static irqreturn_t
11701da177e4SLinus Torvalds ia64_mca_cmc_int_caller(int cmc_irq, void *arg, struct pt_regs *ptregs)
11711da177e4SLinus Torvalds {
11721da177e4SLinus Torvalds 	static int start_count = -1;
11731da177e4SLinus Torvalds 	unsigned int cpuid;
11741da177e4SLinus Torvalds 
11751da177e4SLinus Torvalds 	cpuid = smp_processor_id();
11761da177e4SLinus Torvalds 
11771da177e4SLinus Torvalds 	/* If first cpu, update count */
11781da177e4SLinus Torvalds 	if (start_count == -1)
11791da177e4SLinus Torvalds 		start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CMC);
11801da177e4SLinus Torvalds 
11811da177e4SLinus Torvalds 	ia64_mca_cmc_int_handler(cmc_irq, arg, ptregs);
11821da177e4SLinus Torvalds 
11831da177e4SLinus Torvalds 	for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
11841da177e4SLinus Torvalds 
11851da177e4SLinus Torvalds 	if (cpuid < NR_CPUS) {
11861da177e4SLinus Torvalds 		platform_send_ipi(cpuid, IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
11871da177e4SLinus Torvalds 	} else {
11881da177e4SLinus Torvalds 		/* If no log record, switch out of polling mode */
11891da177e4SLinus Torvalds 		if (start_count == IA64_LOG_COUNT(SAL_INFO_TYPE_CMC)) {
11901da177e4SLinus Torvalds 
11911da177e4SLinus Torvalds 			printk(KERN_WARNING "Returning to interrupt driven CMC handler\n");
11921da177e4SLinus Torvalds 			schedule_work(&cmc_enable_work);
11931da177e4SLinus Torvalds 			cmc_polling_enabled = 0;
11941da177e4SLinus Torvalds 
11951da177e4SLinus Torvalds 		} else {
11961da177e4SLinus Torvalds 
11971da177e4SLinus Torvalds 			mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
11981da177e4SLinus Torvalds 		}
11991da177e4SLinus Torvalds 
12001da177e4SLinus Torvalds 		start_count = -1;
12011da177e4SLinus Torvalds 	}
12021da177e4SLinus Torvalds 
12031da177e4SLinus Torvalds 	return IRQ_HANDLED;
12041da177e4SLinus Torvalds }
12051da177e4SLinus Torvalds 
12061da177e4SLinus Torvalds /*
12071da177e4SLinus Torvalds  *  ia64_mca_cmc_poll
12081da177e4SLinus Torvalds  *
12091da177e4SLinus Torvalds  *	Poll for Corrected Machine Checks (CMCs)
12101da177e4SLinus Torvalds  *
12111da177e4SLinus Torvalds  * Inputs   :   dummy(unused)
12121da177e4SLinus Torvalds  * Outputs  :   None
12131da177e4SLinus Torvalds  *
12141da177e4SLinus Torvalds  */
12151da177e4SLinus Torvalds static void
12161da177e4SLinus Torvalds ia64_mca_cmc_poll (unsigned long dummy)
12171da177e4SLinus Torvalds {
12181da177e4SLinus Torvalds 	/* Trigger a CMC interrupt cascade  */
12191da177e4SLinus Torvalds 	platform_send_ipi(first_cpu(cpu_online_map), IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
12201da177e4SLinus Torvalds }
12211da177e4SLinus Torvalds 
12221da177e4SLinus Torvalds /*
12231da177e4SLinus Torvalds  *  ia64_mca_cpe_int_caller
12241da177e4SLinus Torvalds  *
12251da177e4SLinus Torvalds  * 	Triggered by sw interrupt from CPE polling routine.  Calls
12261da177e4SLinus Torvalds  * 	real interrupt handler and either triggers a sw interrupt
12271da177e4SLinus Torvalds  * 	on the next cpu or does cleanup at the end.
12281da177e4SLinus Torvalds  *
12291da177e4SLinus Torvalds  * Inputs
12301da177e4SLinus Torvalds  *	interrupt number
12311da177e4SLinus Torvalds  *	client data arg ptr
12321da177e4SLinus Torvalds  *	saved registers ptr
12331da177e4SLinus Torvalds  * Outputs
12341da177e4SLinus Torvalds  * 	handled
12351da177e4SLinus Torvalds  */
12361da177e4SLinus Torvalds #ifdef CONFIG_ACPI
12371da177e4SLinus Torvalds 
12381da177e4SLinus Torvalds static irqreturn_t
12391da177e4SLinus Torvalds ia64_mca_cpe_int_caller(int cpe_irq, void *arg, struct pt_regs *ptregs)
12401da177e4SLinus Torvalds {
12411da177e4SLinus Torvalds 	static int start_count = -1;
12421da177e4SLinus Torvalds 	static int poll_time = MIN_CPE_POLL_INTERVAL;
12431da177e4SLinus Torvalds 	unsigned int cpuid;
12441da177e4SLinus Torvalds 
12451da177e4SLinus Torvalds 	cpuid = smp_processor_id();
12461da177e4SLinus Torvalds 
12471da177e4SLinus Torvalds 	/* If first cpu, update count */
12481da177e4SLinus Torvalds 	if (start_count == -1)
12491da177e4SLinus Torvalds 		start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CPE);
12501da177e4SLinus Torvalds 
12511da177e4SLinus Torvalds 	ia64_mca_cpe_int_handler(cpe_irq, arg, ptregs);
12521da177e4SLinus Torvalds 
12531da177e4SLinus Torvalds 	for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
12541da177e4SLinus Torvalds 
12551da177e4SLinus Torvalds 	if (cpuid < NR_CPUS) {
12561da177e4SLinus Torvalds 		platform_send_ipi(cpuid, IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
12571da177e4SLinus Torvalds 	} else {
12581da177e4SLinus Torvalds 		/*
12591da177e4SLinus Torvalds 		 * If a log was recorded, increase our polling frequency,
12601da177e4SLinus Torvalds 		 * otherwise, backoff or return to interrupt mode.
12611da177e4SLinus Torvalds 		 */
12621da177e4SLinus Torvalds 		if (start_count != IA64_LOG_COUNT(SAL_INFO_TYPE_CPE)) {
12631da177e4SLinus Torvalds 			poll_time = max(MIN_CPE_POLL_INTERVAL, poll_time / 2);
12641da177e4SLinus Torvalds 		} else if (cpe_vector < 0) {
12651da177e4SLinus Torvalds 			poll_time = min(MAX_CPE_POLL_INTERVAL, poll_time * 2);
12661da177e4SLinus Torvalds 		} else {
12671da177e4SLinus Torvalds 			poll_time = MIN_CPE_POLL_INTERVAL;
12681da177e4SLinus Torvalds 
12691da177e4SLinus Torvalds 			printk(KERN_WARNING "Returning to interrupt driven CPE handler\n");
12701da177e4SLinus Torvalds 			enable_irq(local_vector_to_irq(IA64_CPE_VECTOR));
12711da177e4SLinus Torvalds 			cpe_poll_enabled = 0;
12721da177e4SLinus Torvalds 		}
12731da177e4SLinus Torvalds 
12741da177e4SLinus Torvalds 		if (cpe_poll_enabled)
12751da177e4SLinus Torvalds 			mod_timer(&cpe_poll_timer, jiffies + poll_time);
12761da177e4SLinus Torvalds 		start_count = -1;
12771da177e4SLinus Torvalds 	}
12781da177e4SLinus Torvalds 
12791da177e4SLinus Torvalds 	return IRQ_HANDLED;
12801da177e4SLinus Torvalds }
12811da177e4SLinus Torvalds 
12821da177e4SLinus Torvalds /*
12831da177e4SLinus Torvalds  *  ia64_mca_cpe_poll
12841da177e4SLinus Torvalds  *
12851da177e4SLinus Torvalds  *	Poll for Corrected Platform Errors (CPEs), trigger interrupt
12861da177e4SLinus Torvalds  *	on first cpu, from there it will trickle through all the cpus.
12871da177e4SLinus Torvalds  *
12881da177e4SLinus Torvalds  * Inputs   :   dummy(unused)
12891da177e4SLinus Torvalds  * Outputs  :   None
12901da177e4SLinus Torvalds  *
12911da177e4SLinus Torvalds  */
12921da177e4SLinus Torvalds static void
12931da177e4SLinus Torvalds ia64_mca_cpe_poll (unsigned long dummy)
12941da177e4SLinus Torvalds {
12951da177e4SLinus Torvalds 	/* Trigger a CPE interrupt cascade  */
12961da177e4SLinus Torvalds 	platform_send_ipi(first_cpu(cpu_online_map), IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
12971da177e4SLinus Torvalds }
12981da177e4SLinus Torvalds 
1299b655913bSPeter Chubb #endif /* CONFIG_ACPI */
1300b655913bSPeter Chubb 
13019138d581SKeith Owens static int
13029138d581SKeith Owens default_monarch_init_process(struct notifier_block *self, unsigned long val, void *data)
13039138d581SKeith Owens {
13049138d581SKeith Owens 	int c;
13059138d581SKeith Owens 	struct task_struct *g, *t;
13069138d581SKeith Owens 	if (val != DIE_INIT_MONARCH_PROCESS)
13079138d581SKeith Owens 		return NOTIFY_DONE;
13089138d581SKeith Owens 	printk(KERN_ERR "Processes interrupted by INIT -");
13099138d581SKeith Owens 	for_each_online_cpu(c) {
13109138d581SKeith Owens 		struct ia64_sal_os_state *s;
13119138d581SKeith Owens 		t = __va(__per_cpu_mca[c] + IA64_MCA_CPU_INIT_STACK_OFFSET);
13129138d581SKeith Owens 		s = (struct ia64_sal_os_state *)((char *)t + MCA_SOS_OFFSET);
13139138d581SKeith Owens 		g = s->prev_task;
13149138d581SKeith Owens 		if (g) {
13159138d581SKeith Owens 			if (g->pid)
13169138d581SKeith Owens 				printk(" %d", g->pid);
13179138d581SKeith Owens 			else
13189138d581SKeith Owens 				printk(" %d (cpu %d task 0x%p)", g->pid, task_cpu(g), g);
13199138d581SKeith Owens 		}
13209138d581SKeith Owens 	}
13219138d581SKeith Owens 	printk("\n\n");
13229138d581SKeith Owens 	if (read_trylock(&tasklist_lock)) {
13239138d581SKeith Owens 		do_each_thread (g, t) {
13249138d581SKeith Owens 			printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm);
13259138d581SKeith Owens 			show_stack(t, NULL);
13269138d581SKeith Owens 		} while_each_thread (g, t);
13279138d581SKeith Owens 		read_unlock(&tasklist_lock);
13289138d581SKeith Owens 	}
13299138d581SKeith Owens 	return NOTIFY_DONE;
13309138d581SKeith Owens }
13319138d581SKeith Owens 
13321da177e4SLinus Torvalds /*
13331da177e4SLinus Torvalds  * C portion of the OS INIT handler
13341da177e4SLinus Torvalds  *
13357f613c7dSKeith Owens  * Called from ia64_os_init_dispatch
13361da177e4SLinus Torvalds  *
13377f613c7dSKeith Owens  * Inputs: pointer to pt_regs where processor info was saved.  SAL/OS state for
13387f613c7dSKeith Owens  * this event.  This code is used for both monarch and slave INIT events, see
13397f613c7dSKeith Owens  * sos->monarch.
13401da177e4SLinus Torvalds  *
13417f613c7dSKeith Owens  * All INIT events switch to the INIT stack and change the previous process to
13427f613c7dSKeith Owens  * blocked status.  If one of the INIT events is the monarch then we are
13437f613c7dSKeith Owens  * probably processing the nmi button/command.  Use the monarch cpu to dump all
13447f613c7dSKeith Owens  * the processes.  The slave INIT events all spin until the monarch cpu
13457f613c7dSKeith Owens  * returns.  We can also get INIT slave events for MCA, in which case the MCA
13467f613c7dSKeith Owens  * process is the monarch.
13471da177e4SLinus Torvalds  */
13481da177e4SLinus Torvalds 
13497f613c7dSKeith Owens void
13507f613c7dSKeith Owens ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw,
13517f613c7dSKeith Owens 		  struct ia64_sal_os_state *sos)
13527f613c7dSKeith Owens {
13537f613c7dSKeith Owens 	static atomic_t slaves;
13547f613c7dSKeith Owens 	static atomic_t monarchs;
1355*36c8b586SIngo Molnar 	struct task_struct *previous_current;
13569138d581SKeith Owens 	int cpu = smp_processor_id();
1357958b166cSKeith Owens 	struct ia64_mca_notify_die nd =
1358958b166cSKeith Owens 		{ .sos = sos, .monarch_cpu = &monarch_cpu };
13597f613c7dSKeith Owens 
13607f613c7dSKeith Owens 	oops_in_progress = 1;	/* FIXME: make printk NMI/MCA/INIT safe */
13611da177e4SLinus Torvalds 	console_loglevel = 15;	/* make sure printks make it to console */
13621da177e4SLinus Torvalds 
1363958b166cSKeith Owens 	(void) notify_die(DIE_INIT_ENTER, "INIT", regs, (long)&nd, 0, 0);
1364958b166cSKeith Owens 
13657f613c7dSKeith Owens 	printk(KERN_INFO "Entered OS INIT handler. PSP=%lx cpu=%d monarch=%ld\n",
13667f613c7dSKeith Owens 		sos->proc_state_param, cpu, sos->monarch);
13677f613c7dSKeith Owens 	salinfo_log_wakeup(SAL_INFO_TYPE_INIT, NULL, 0, 0);
13687f613c7dSKeith Owens 
13697f613c7dSKeith Owens 	previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "INIT");
13707f613c7dSKeith Owens 	sos->os_status = IA64_INIT_RESUME;
13717f613c7dSKeith Owens 
13727f613c7dSKeith Owens 	/* FIXME: Workaround for broken proms that drive all INIT events as
13737f613c7dSKeith Owens 	 * slaves.  The last slave that enters is promoted to be a monarch.
13747f613c7dSKeith Owens 	 * Remove this code in September 2006, that gives platforms a year to
13757f613c7dSKeith Owens 	 * fix their proms and get their customers updated.
13767f613c7dSKeith Owens 	 */
13777f613c7dSKeith Owens 	if (!sos->monarch && atomic_add_return(1, &slaves) == num_online_cpus()) {
13787f613c7dSKeith Owens 		printk(KERN_WARNING "%s: Promoting cpu %d to monarch.\n",
13797f613c7dSKeith Owens 		       __FUNCTION__, cpu);
13807f613c7dSKeith Owens 		atomic_dec(&slaves);
13817f613c7dSKeith Owens 		sos->monarch = 1;
13827f613c7dSKeith Owens 	}
13837f613c7dSKeith Owens 
13847f613c7dSKeith Owens 	/* FIXME: Workaround for broken proms that drive all INIT events as
13857f613c7dSKeith Owens 	 * monarchs.  Second and subsequent monarchs are demoted to slaves.
13867f613c7dSKeith Owens 	 * Remove this code in September 2006, that gives platforms a year to
13877f613c7dSKeith Owens 	 * fix their proms and get their customers updated.
13887f613c7dSKeith Owens 	 */
13897f613c7dSKeith Owens 	if (sos->monarch && atomic_add_return(1, &monarchs) > 1) {
13907f613c7dSKeith Owens 		printk(KERN_WARNING "%s: Demoting cpu %d to slave.\n",
13917f613c7dSKeith Owens 			       __FUNCTION__, cpu);
13927f613c7dSKeith Owens 		atomic_dec(&monarchs);
13937f613c7dSKeith Owens 		sos->monarch = 0;
13947f613c7dSKeith Owens 	}
13957f613c7dSKeith Owens 
13967f613c7dSKeith Owens 	if (!sos->monarch) {
13977f613c7dSKeith Owens 		ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_INIT;
13987f613c7dSKeith Owens 		while (monarch_cpu == -1)
13997f613c7dSKeith Owens 		       cpu_relax();	/* spin until monarch enters */
1400958b166cSKeith Owens 		if (notify_die(DIE_INIT_SLAVE_ENTER, "INIT", regs, (long)&nd, 0, 0)
14019138d581SKeith Owens 				== NOTIFY_STOP)
14029138d581SKeith Owens 			ia64_mca_spin(__FUNCTION__);
1403958b166cSKeith Owens 		if (notify_die(DIE_INIT_SLAVE_PROCESS, "INIT", regs, (long)&nd, 0, 0)
14049138d581SKeith Owens 				== NOTIFY_STOP)
14059138d581SKeith Owens 			ia64_mca_spin(__FUNCTION__);
14067f613c7dSKeith Owens 		while (monarch_cpu != -1)
14077f613c7dSKeith Owens 		       cpu_relax();	/* spin until monarch leaves */
1408958b166cSKeith Owens 		if (notify_die(DIE_INIT_SLAVE_LEAVE, "INIT", regs, (long)&nd, 0, 0)
14099138d581SKeith Owens 				== NOTIFY_STOP)
14109138d581SKeith Owens 			ia64_mca_spin(__FUNCTION__);
14117f613c7dSKeith Owens 		printk("Slave on cpu %d returning to normal service.\n", cpu);
14127f613c7dSKeith Owens 		set_curr_task(cpu, previous_current);
14137f613c7dSKeith Owens 		ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
14147f613c7dSKeith Owens 		atomic_dec(&slaves);
14157f613c7dSKeith Owens 		return;
14167f613c7dSKeith Owens 	}
14177f613c7dSKeith Owens 
14187f613c7dSKeith Owens 	monarch_cpu = cpu;
1419958b166cSKeith Owens 	if (notify_die(DIE_INIT_MONARCH_ENTER, "INIT", regs, (long)&nd, 0, 0)
14209138d581SKeith Owens 			== NOTIFY_STOP)
14219138d581SKeith Owens 		ia64_mca_spin(__FUNCTION__);
14221da177e4SLinus Torvalds 
14231da177e4SLinus Torvalds 	/*
14247f613c7dSKeith Owens 	 * Wait for a bit.  On some machines (e.g., HP's zx2000 and zx6000, INIT can be
14257f613c7dSKeith Owens 	 * generated via the BMC's command-line interface, but since the console is on the
14267f613c7dSKeith Owens 	 * same serial line, the user will need some time to switch out of the BMC before
14277f613c7dSKeith Owens 	 * the dump begins.
14281da177e4SLinus Torvalds 	 */
14297f613c7dSKeith Owens 	printk("Delaying for 5 seconds...\n");
14307f613c7dSKeith Owens 	udelay(5*1000000);
1431356a5c1cSKeith Owens 	ia64_wait_for_slaves(cpu, "INIT");
14329138d581SKeith Owens 	/* If nobody intercepts DIE_INIT_MONARCH_PROCESS then we drop through
14339138d581SKeith Owens 	 * to default_monarch_init_process() above and just print all the
14349138d581SKeith Owens 	 * tasks.
14359138d581SKeith Owens 	 */
1436958b166cSKeith Owens 	if (notify_die(DIE_INIT_MONARCH_PROCESS, "INIT", regs, (long)&nd, 0, 0)
14379138d581SKeith Owens 			== NOTIFY_STOP)
14389138d581SKeith Owens 		ia64_mca_spin(__FUNCTION__);
1439958b166cSKeith Owens 	if (notify_die(DIE_INIT_MONARCH_LEAVE, "INIT", regs, (long)&nd, 0, 0)
14409138d581SKeith Owens 			== NOTIFY_STOP)
14419138d581SKeith Owens 		ia64_mca_spin(__FUNCTION__);
14427f613c7dSKeith Owens 	printk("\nINIT dump complete.  Monarch on cpu %d returning to normal service.\n", cpu);
14437f613c7dSKeith Owens 	atomic_dec(&monarchs);
14447f613c7dSKeith Owens 	set_curr_task(cpu, previous_current);
14457f613c7dSKeith Owens 	monarch_cpu = -1;
14467f613c7dSKeith Owens 	return;
14471da177e4SLinus Torvalds }
14481da177e4SLinus Torvalds 
14491da177e4SLinus Torvalds static int __init
14501da177e4SLinus Torvalds ia64_mca_disable_cpe_polling(char *str)
14511da177e4SLinus Torvalds {
14521da177e4SLinus Torvalds 	cpe_poll_enabled = 0;
14531da177e4SLinus Torvalds 	return 1;
14541da177e4SLinus Torvalds }
14551da177e4SLinus Torvalds 
14561da177e4SLinus Torvalds __setup("disable_cpe_poll", ia64_mca_disable_cpe_polling);
14571da177e4SLinus Torvalds 
14581da177e4SLinus Torvalds static struct irqaction cmci_irqaction = {
14591da177e4SLinus Torvalds 	.handler =	ia64_mca_cmc_int_handler,
1460121a4226SThomas Gleixner 	.flags =	IRQF_DISABLED,
14611da177e4SLinus Torvalds 	.name =		"cmc_hndlr"
14621da177e4SLinus Torvalds };
14631da177e4SLinus Torvalds 
14641da177e4SLinus Torvalds static struct irqaction cmcp_irqaction = {
14651da177e4SLinus Torvalds 	.handler =	ia64_mca_cmc_int_caller,
1466121a4226SThomas Gleixner 	.flags =	IRQF_DISABLED,
14671da177e4SLinus Torvalds 	.name =		"cmc_poll"
14681da177e4SLinus Torvalds };
14691da177e4SLinus Torvalds 
14701da177e4SLinus Torvalds static struct irqaction mca_rdzv_irqaction = {
14711da177e4SLinus Torvalds 	.handler =	ia64_mca_rendez_int_handler,
1472121a4226SThomas Gleixner 	.flags =	IRQF_DISABLED,
14731da177e4SLinus Torvalds 	.name =		"mca_rdzv"
14741da177e4SLinus Torvalds };
14751da177e4SLinus Torvalds 
14761da177e4SLinus Torvalds static struct irqaction mca_wkup_irqaction = {
14771da177e4SLinus Torvalds 	.handler =	ia64_mca_wakeup_int_handler,
1478121a4226SThomas Gleixner 	.flags =	IRQF_DISABLED,
14791da177e4SLinus Torvalds 	.name =		"mca_wkup"
14801da177e4SLinus Torvalds };
14811da177e4SLinus Torvalds 
14821da177e4SLinus Torvalds #ifdef CONFIG_ACPI
14831da177e4SLinus Torvalds static struct irqaction mca_cpe_irqaction = {
14841da177e4SLinus Torvalds 	.handler =	ia64_mca_cpe_int_handler,
1485121a4226SThomas Gleixner 	.flags =	IRQF_DISABLED,
14861da177e4SLinus Torvalds 	.name =		"cpe_hndlr"
14871da177e4SLinus Torvalds };
14881da177e4SLinus Torvalds 
14891da177e4SLinus Torvalds static struct irqaction mca_cpep_irqaction = {
14901da177e4SLinus Torvalds 	.handler =	ia64_mca_cpe_int_caller,
1491121a4226SThomas Gleixner 	.flags =	IRQF_DISABLED,
14921da177e4SLinus Torvalds 	.name =		"cpe_poll"
14931da177e4SLinus Torvalds };
14941da177e4SLinus Torvalds #endif /* CONFIG_ACPI */
14951da177e4SLinus Torvalds 
14967f613c7dSKeith Owens /* Minimal format of the MCA/INIT stacks.  The pseudo processes that run on
14977f613c7dSKeith Owens  * these stacks can never sleep, they cannot return from the kernel to user
14987f613c7dSKeith Owens  * space, they do not appear in a normal ps listing.  So there is no need to
14997f613c7dSKeith Owens  * format most of the fields.
15007f613c7dSKeith Owens  */
15017f613c7dSKeith Owens 
15020881fc8dSChen, Kenneth W static void __cpuinit
15037f613c7dSKeith Owens format_mca_init_stack(void *mca_data, unsigned long offset,
15047f613c7dSKeith Owens 		const char *type, int cpu)
15057f613c7dSKeith Owens {
15067f613c7dSKeith Owens 	struct task_struct *p = (struct task_struct *)((char *)mca_data + offset);
15077f613c7dSKeith Owens 	struct thread_info *ti;
15087f613c7dSKeith Owens 	memset(p, 0, KERNEL_STACK_SIZE);
1509ab03591dSAl Viro 	ti = task_thread_info(p);
15107f613c7dSKeith Owens 	ti->flags = _TIF_MCA_INIT;
15117f613c7dSKeith Owens 	ti->preempt_count = 1;
15127f613c7dSKeith Owens 	ti->task = p;
15137f613c7dSKeith Owens 	ti->cpu = cpu;
15147f613c7dSKeith Owens 	p->thread_info = ti;
15157f613c7dSKeith Owens 	p->state = TASK_UNINTERRUPTIBLE;
15164668f0cdSAkinobu Mita 	cpu_set(cpu, p->cpus_allowed);
15177f613c7dSKeith Owens 	INIT_LIST_HEAD(&p->tasks);
15187f613c7dSKeith Owens 	p->parent = p->real_parent = p->group_leader = p;
15197f613c7dSKeith Owens 	INIT_LIST_HEAD(&p->children);
15207f613c7dSKeith Owens 	INIT_LIST_HEAD(&p->sibling);
15217f613c7dSKeith Owens 	strncpy(p->comm, type, sizeof(p->comm)-1);
15227f613c7dSKeith Owens }
15237f613c7dSKeith Owens 
15241da177e4SLinus Torvalds /* Do per-CPU MCA-related initialization.  */
15251da177e4SLinus Torvalds 
15260881fc8dSChen, Kenneth W void __cpuinit
15271da177e4SLinus Torvalds ia64_mca_cpu_init(void *cpu_data)
15281da177e4SLinus Torvalds {
15291da177e4SLinus Torvalds 	void *pal_vaddr;
1530ff741906SAshok Raj 	static int first_time = 1;
15311da177e4SLinus Torvalds 
1532ff741906SAshok Raj 	if (first_time) {
15331da177e4SLinus Torvalds 		void *mca_data;
15341da177e4SLinus Torvalds 		int cpu;
15351da177e4SLinus Torvalds 
1536ff741906SAshok Raj 		first_time = 0;
15371da177e4SLinus Torvalds 		mca_data = alloc_bootmem(sizeof(struct ia64_mca_cpu)
15387f613c7dSKeith Owens 					 * NR_CPUS + KERNEL_STACK_SIZE);
15397f613c7dSKeith Owens 		mca_data = (void *)(((unsigned long)mca_data +
15407f613c7dSKeith Owens 					KERNEL_STACK_SIZE - 1) &
15417f613c7dSKeith Owens 				(-KERNEL_STACK_SIZE));
15421da177e4SLinus Torvalds 		for (cpu = 0; cpu < NR_CPUS; cpu++) {
15437f613c7dSKeith Owens 			format_mca_init_stack(mca_data,
15447f613c7dSKeith Owens 					offsetof(struct ia64_mca_cpu, mca_stack),
15457f613c7dSKeith Owens 					"MCA", cpu);
15467f613c7dSKeith Owens 			format_mca_init_stack(mca_data,
15477f613c7dSKeith Owens 					offsetof(struct ia64_mca_cpu, init_stack),
15487f613c7dSKeith Owens 					"INIT", cpu);
15491da177e4SLinus Torvalds 			__per_cpu_mca[cpu] = __pa(mca_data);
15501da177e4SLinus Torvalds 			mca_data += sizeof(struct ia64_mca_cpu);
15511da177e4SLinus Torvalds 		}
15521da177e4SLinus Torvalds 	}
15531da177e4SLinus Torvalds 
15541da177e4SLinus Torvalds 	/*
15551da177e4SLinus Torvalds 	 * The MCA info structure was allocated earlier and its
15561da177e4SLinus Torvalds 	 * physical address saved in __per_cpu_mca[cpu].  Copy that
15571da177e4SLinus Torvalds 	 * address * to ia64_mca_data so we can access it as a per-CPU
15581da177e4SLinus Torvalds 	 * variable.
15591da177e4SLinus Torvalds 	 */
15601da177e4SLinus Torvalds 	__get_cpu_var(ia64_mca_data) = __per_cpu_mca[smp_processor_id()];
15611da177e4SLinus Torvalds 
15621da177e4SLinus Torvalds 	/*
15631da177e4SLinus Torvalds 	 * Stash away a copy of the PTE needed to map the per-CPU page.
15641da177e4SLinus Torvalds 	 * We may need it during MCA recovery.
15651da177e4SLinus Torvalds 	 */
15661da177e4SLinus Torvalds 	__get_cpu_var(ia64_mca_per_cpu_pte) =
15671da177e4SLinus Torvalds 		pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL));
15681da177e4SLinus Torvalds 
15691da177e4SLinus Torvalds 	/*
15701da177e4SLinus Torvalds 	 * Also, stash away a copy of the PAL address and the PTE
15711da177e4SLinus Torvalds 	 * needed to map it.
15721da177e4SLinus Torvalds 	 */
15731da177e4SLinus Torvalds 	pal_vaddr = efi_get_pal_addr();
15741da177e4SLinus Torvalds 	if (!pal_vaddr)
15751da177e4SLinus Torvalds 		return;
15761da177e4SLinus Torvalds 	__get_cpu_var(ia64_mca_pal_base) =
15771da177e4SLinus Torvalds 		GRANULEROUNDDOWN((unsigned long) pal_vaddr);
15781da177e4SLinus Torvalds 	__get_cpu_var(ia64_mca_pal_pte) = pte_val(mk_pte_phys(__pa(pal_vaddr),
15791da177e4SLinus Torvalds 							      PAGE_KERNEL));
15801da177e4SLinus Torvalds }
15811da177e4SLinus Torvalds 
15821da177e4SLinus Torvalds /*
15831da177e4SLinus Torvalds  * ia64_mca_init
15841da177e4SLinus Torvalds  *
15851da177e4SLinus Torvalds  *  Do all the system level mca specific initialization.
15861da177e4SLinus Torvalds  *
15871da177e4SLinus Torvalds  *	1. Register spinloop and wakeup request interrupt vectors
15881da177e4SLinus Torvalds  *
15891da177e4SLinus Torvalds  *	2. Register OS_MCA handler entry point
15901da177e4SLinus Torvalds  *
15911da177e4SLinus Torvalds  *	3. Register OS_INIT handler entry point
15921da177e4SLinus Torvalds  *
15931da177e4SLinus Torvalds  *  4. Initialize MCA/CMC/INIT related log buffers maintained by the OS.
15941da177e4SLinus Torvalds  *
15951da177e4SLinus Torvalds  *  Note that this initialization is done very early before some kernel
15961da177e4SLinus Torvalds  *  services are available.
15971da177e4SLinus Torvalds  *
15981da177e4SLinus Torvalds  *  Inputs  :   None
15991da177e4SLinus Torvalds  *
16001da177e4SLinus Torvalds  *  Outputs :   None
16011da177e4SLinus Torvalds  */
16021da177e4SLinus Torvalds void __init
16031da177e4SLinus Torvalds ia64_mca_init(void)
16041da177e4SLinus Torvalds {
16057f613c7dSKeith Owens 	ia64_fptr_t *init_hldlr_ptr_monarch = (ia64_fptr_t *)ia64_os_init_dispatch_monarch;
16067f613c7dSKeith Owens 	ia64_fptr_t *init_hldlr_ptr_slave = (ia64_fptr_t *)ia64_os_init_dispatch_slave;
16071da177e4SLinus Torvalds 	ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch;
16081da177e4SLinus Torvalds 	int i;
16091da177e4SLinus Torvalds 	s64 rc;
16101da177e4SLinus Torvalds 	struct ia64_sal_retval isrv;
16111da177e4SLinus Torvalds 	u64 timeout = IA64_MCA_RENDEZ_TIMEOUT;	/* platform specific */
16129138d581SKeith Owens 	static struct notifier_block default_init_monarch_nb = {
16139138d581SKeith Owens 		.notifier_call = default_monarch_init_process,
16149138d581SKeith Owens 		.priority = 0/* we need to notified last */
16159138d581SKeith Owens 	};
16161da177e4SLinus Torvalds 
16171da177e4SLinus Torvalds 	IA64_MCA_DEBUG("%s: begin\n", __FUNCTION__);
16181da177e4SLinus Torvalds 
16191da177e4SLinus Torvalds 	/* Clear the Rendez checkin flag for all cpus */
16201da177e4SLinus Torvalds 	for(i = 0 ; i < NR_CPUS; i++)
16211da177e4SLinus Torvalds 		ia64_mc_info.imi_rendez_checkin[i] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
16221da177e4SLinus Torvalds 
16231da177e4SLinus Torvalds 	/*
16241da177e4SLinus Torvalds 	 * Register the rendezvous spinloop and wakeup mechanism with SAL
16251da177e4SLinus Torvalds 	 */
16261da177e4SLinus Torvalds 
16271da177e4SLinus Torvalds 	/* Register the rendezvous interrupt vector with SAL */
16281da177e4SLinus Torvalds 	while (1) {
16291da177e4SLinus Torvalds 		isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_INT,
16301da177e4SLinus Torvalds 					      SAL_MC_PARAM_MECHANISM_INT,
16311da177e4SLinus Torvalds 					      IA64_MCA_RENDEZ_VECTOR,
16321da177e4SLinus Torvalds 					      timeout,
16331da177e4SLinus Torvalds 					      SAL_MC_PARAM_RZ_ALWAYS);
16341da177e4SLinus Torvalds 		rc = isrv.status;
16351da177e4SLinus Torvalds 		if (rc == 0)
16361da177e4SLinus Torvalds 			break;
16371da177e4SLinus Torvalds 		if (rc == -2) {
16381da177e4SLinus Torvalds 			printk(KERN_INFO "Increasing MCA rendezvous timeout from "
16391da177e4SLinus Torvalds 				"%ld to %ld milliseconds\n", timeout, isrv.v0);
16401da177e4SLinus Torvalds 			timeout = isrv.v0;
1641958b166cSKeith Owens 			(void) notify_die(DIE_MCA_NEW_TIMEOUT, "MCA", NULL, timeout, 0, 0);
16421da177e4SLinus Torvalds 			continue;
16431da177e4SLinus Torvalds 		}
16441da177e4SLinus Torvalds 		printk(KERN_ERR "Failed to register rendezvous interrupt "
16451da177e4SLinus Torvalds 		       "with SAL (status %ld)\n", rc);
16461da177e4SLinus Torvalds 		return;
16471da177e4SLinus Torvalds 	}
16481da177e4SLinus Torvalds 
16491da177e4SLinus Torvalds 	/* Register the wakeup interrupt vector with SAL */
16501da177e4SLinus Torvalds 	isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_WAKEUP,
16511da177e4SLinus Torvalds 				      SAL_MC_PARAM_MECHANISM_INT,
16521da177e4SLinus Torvalds 				      IA64_MCA_WAKEUP_VECTOR,
16531da177e4SLinus Torvalds 				      0, 0);
16541da177e4SLinus Torvalds 	rc = isrv.status;
16551da177e4SLinus Torvalds 	if (rc) {
16561da177e4SLinus Torvalds 		printk(KERN_ERR "Failed to register wakeup interrupt with SAL "
16571da177e4SLinus Torvalds 		       "(status %ld)\n", rc);
16581da177e4SLinus Torvalds 		return;
16591da177e4SLinus Torvalds 	}
16601da177e4SLinus Torvalds 
16611da177e4SLinus Torvalds 	IA64_MCA_DEBUG("%s: registered MCA rendezvous spinloop and wakeup mech.\n", __FUNCTION__);
16621da177e4SLinus Torvalds 
16631da177e4SLinus Torvalds 	ia64_mc_info.imi_mca_handler        = ia64_tpa(mca_hldlr_ptr->fp);
16641da177e4SLinus Torvalds 	/*
16651da177e4SLinus Torvalds 	 * XXX - disable SAL checksum by setting size to 0; should be
16661da177e4SLinus Torvalds 	 *	ia64_tpa(ia64_os_mca_dispatch_end) - ia64_tpa(ia64_os_mca_dispatch);
16671da177e4SLinus Torvalds 	 */
16681da177e4SLinus Torvalds 	ia64_mc_info.imi_mca_handler_size	= 0;
16691da177e4SLinus Torvalds 
16701da177e4SLinus Torvalds 	/* Register the os mca handler with SAL */
16711da177e4SLinus Torvalds 	if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_MCA,
16721da177e4SLinus Torvalds 				       ia64_mc_info.imi_mca_handler,
16731da177e4SLinus Torvalds 				       ia64_tpa(mca_hldlr_ptr->gp),
16741da177e4SLinus Torvalds 				       ia64_mc_info.imi_mca_handler_size,
16751da177e4SLinus Torvalds 				       0, 0, 0)))
16761da177e4SLinus Torvalds 	{
16771da177e4SLinus Torvalds 		printk(KERN_ERR "Failed to register OS MCA handler with SAL "
16781da177e4SLinus Torvalds 		       "(status %ld)\n", rc);
16791da177e4SLinus Torvalds 		return;
16801da177e4SLinus Torvalds 	}
16811da177e4SLinus Torvalds 
16821da177e4SLinus Torvalds 	IA64_MCA_DEBUG("%s: registered OS MCA handler with SAL at 0x%lx, gp = 0x%lx\n", __FUNCTION__,
16831da177e4SLinus Torvalds 		       ia64_mc_info.imi_mca_handler, ia64_tpa(mca_hldlr_ptr->gp));
16841da177e4SLinus Torvalds 
16851da177e4SLinus Torvalds 	/*
16861da177e4SLinus Torvalds 	 * XXX - disable SAL checksum by setting size to 0, should be
16871da177e4SLinus Torvalds 	 * size of the actual init handler in mca_asm.S.
16881da177e4SLinus Torvalds 	 */
16897f613c7dSKeith Owens 	ia64_mc_info.imi_monarch_init_handler		= ia64_tpa(init_hldlr_ptr_monarch->fp);
16901da177e4SLinus Torvalds 	ia64_mc_info.imi_monarch_init_handler_size	= 0;
16917f613c7dSKeith Owens 	ia64_mc_info.imi_slave_init_handler		= ia64_tpa(init_hldlr_ptr_slave->fp);
16921da177e4SLinus Torvalds 	ia64_mc_info.imi_slave_init_handler_size	= 0;
16931da177e4SLinus Torvalds 
16941da177e4SLinus Torvalds 	IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __FUNCTION__,
16951da177e4SLinus Torvalds 		       ia64_mc_info.imi_monarch_init_handler);
16961da177e4SLinus Torvalds 
16971da177e4SLinus Torvalds 	/* Register the os init handler with SAL */
16981da177e4SLinus Torvalds 	if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_INIT,
16991da177e4SLinus Torvalds 				       ia64_mc_info.imi_monarch_init_handler,
17001da177e4SLinus Torvalds 				       ia64_tpa(ia64_getreg(_IA64_REG_GP)),
17011da177e4SLinus Torvalds 				       ia64_mc_info.imi_monarch_init_handler_size,
17021da177e4SLinus Torvalds 				       ia64_mc_info.imi_slave_init_handler,
17031da177e4SLinus Torvalds 				       ia64_tpa(ia64_getreg(_IA64_REG_GP)),
17041da177e4SLinus Torvalds 				       ia64_mc_info.imi_slave_init_handler_size)))
17051da177e4SLinus Torvalds 	{
17061da177e4SLinus Torvalds 		printk(KERN_ERR "Failed to register m/s INIT handlers with SAL "
17071da177e4SLinus Torvalds 		       "(status %ld)\n", rc);
17081da177e4SLinus Torvalds 		return;
17091da177e4SLinus Torvalds 	}
17109138d581SKeith Owens 	if (register_die_notifier(&default_init_monarch_nb)) {
17119138d581SKeith Owens 		printk(KERN_ERR "Failed to register default monarch INIT process\n");
17129138d581SKeith Owens 		return;
17139138d581SKeith Owens 	}
17141da177e4SLinus Torvalds 
17151da177e4SLinus Torvalds 	IA64_MCA_DEBUG("%s: registered OS INIT handler with SAL\n", __FUNCTION__);
17161da177e4SLinus Torvalds 
17171da177e4SLinus Torvalds 	/*
17181da177e4SLinus Torvalds 	 *  Configure the CMCI/P vector and handler. Interrupts for CMC are
17191da177e4SLinus Torvalds 	 *  per-processor, so AP CMC interrupts are setup in smp_callin() (smpboot.c).
17201da177e4SLinus Torvalds 	 */
17211da177e4SLinus Torvalds 	register_percpu_irq(IA64_CMC_VECTOR, &cmci_irqaction);
17221da177e4SLinus Torvalds 	register_percpu_irq(IA64_CMCP_VECTOR, &cmcp_irqaction);
17231da177e4SLinus Torvalds 	ia64_mca_cmc_vector_setup();       /* Setup vector on BSP */
17241da177e4SLinus Torvalds 
17251da177e4SLinus Torvalds 	/* Setup the MCA rendezvous interrupt vector */
17261da177e4SLinus Torvalds 	register_percpu_irq(IA64_MCA_RENDEZ_VECTOR, &mca_rdzv_irqaction);
17271da177e4SLinus Torvalds 
17281da177e4SLinus Torvalds 	/* Setup the MCA wakeup interrupt vector */
17291da177e4SLinus Torvalds 	register_percpu_irq(IA64_MCA_WAKEUP_VECTOR, &mca_wkup_irqaction);
17301da177e4SLinus Torvalds 
17311da177e4SLinus Torvalds #ifdef CONFIG_ACPI
1732bb68c12bSRuss Anderson 	/* Setup the CPEI/P handler */
17331da177e4SLinus Torvalds 	register_percpu_irq(IA64_CPEP_VECTOR, &mca_cpep_irqaction);
17341da177e4SLinus Torvalds #endif
17351da177e4SLinus Torvalds 
17361da177e4SLinus Torvalds 	/* Initialize the areas set aside by the OS to buffer the
17371da177e4SLinus Torvalds 	 * platform/processor error states for MCA/INIT/CMC
17381da177e4SLinus Torvalds 	 * handling.
17391da177e4SLinus Torvalds 	 */
17401da177e4SLinus Torvalds 	ia64_log_init(SAL_INFO_TYPE_MCA);
17411da177e4SLinus Torvalds 	ia64_log_init(SAL_INFO_TYPE_INIT);
17421da177e4SLinus Torvalds 	ia64_log_init(SAL_INFO_TYPE_CMC);
17431da177e4SLinus Torvalds 	ia64_log_init(SAL_INFO_TYPE_CPE);
17441da177e4SLinus Torvalds 
17451da177e4SLinus Torvalds 	mca_init = 1;
17461da177e4SLinus Torvalds 	printk(KERN_INFO "MCA related initialization done\n");
17471da177e4SLinus Torvalds }
17481da177e4SLinus Torvalds 
17491da177e4SLinus Torvalds /*
17501da177e4SLinus Torvalds  * ia64_mca_late_init
17511da177e4SLinus Torvalds  *
17521da177e4SLinus Torvalds  *	Opportunity to setup things that require initialization later
17531da177e4SLinus Torvalds  *	than ia64_mca_init.  Setup a timer to poll for CPEs if the
17541da177e4SLinus Torvalds  *	platform doesn't support an interrupt driven mechanism.
17551da177e4SLinus Torvalds  *
17561da177e4SLinus Torvalds  *  Inputs  :   None
17571da177e4SLinus Torvalds  *  Outputs :   Status
17581da177e4SLinus Torvalds  */
17591da177e4SLinus Torvalds static int __init
17601da177e4SLinus Torvalds ia64_mca_late_init(void)
17611da177e4SLinus Torvalds {
17621da177e4SLinus Torvalds 	if (!mca_init)
17631da177e4SLinus Torvalds 		return 0;
17641da177e4SLinus Torvalds 
17651da177e4SLinus Torvalds 	/* Setup the CMCI/P vector and handler */
17661da177e4SLinus Torvalds 	init_timer(&cmc_poll_timer);
17671da177e4SLinus Torvalds 	cmc_poll_timer.function = ia64_mca_cmc_poll;
17681da177e4SLinus Torvalds 
17691da177e4SLinus Torvalds 	/* Unmask/enable the vector */
17701da177e4SLinus Torvalds 	cmc_polling_enabled = 0;
17711da177e4SLinus Torvalds 	schedule_work(&cmc_enable_work);
17721da177e4SLinus Torvalds 
17731da177e4SLinus Torvalds 	IA64_MCA_DEBUG("%s: CMCI/P setup and enabled.\n", __FUNCTION__);
17741da177e4SLinus Torvalds 
17751da177e4SLinus Torvalds #ifdef CONFIG_ACPI
17761da177e4SLinus Torvalds 	/* Setup the CPEI/P vector and handler */
1777bb68c12bSRuss Anderson 	cpe_vector = acpi_request_vector(ACPI_INTERRUPT_CPEI);
17781da177e4SLinus Torvalds 	init_timer(&cpe_poll_timer);
17791da177e4SLinus Torvalds 	cpe_poll_timer.function = ia64_mca_cpe_poll;
17801da177e4SLinus Torvalds 
17811da177e4SLinus Torvalds 	{
17821da177e4SLinus Torvalds 		irq_desc_t *desc;
17831da177e4SLinus Torvalds 		unsigned int irq;
17841da177e4SLinus Torvalds 
17851da177e4SLinus Torvalds 		if (cpe_vector >= 0) {
17861da177e4SLinus Torvalds 			/* If platform supports CPEI, enable the irq. */
17871da177e4SLinus Torvalds 			cpe_poll_enabled = 0;
17881da177e4SLinus Torvalds 			for (irq = 0; irq < NR_IRQS; ++irq)
17891da177e4SLinus Torvalds 				if (irq_to_vector(irq) == cpe_vector) {
1790a8553acdSIngo Molnar 					desc = irq_desc + irq;
17911da177e4SLinus Torvalds 					desc->status |= IRQ_PER_CPU;
17921da177e4SLinus Torvalds 					setup_irq(irq, &mca_cpe_irqaction);
1793ff741906SAshok Raj 					ia64_cpe_irq = irq;
17941da177e4SLinus Torvalds 				}
17951da177e4SLinus Torvalds 			ia64_mca_register_cpev(cpe_vector);
17961da177e4SLinus Torvalds 			IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n", __FUNCTION__);
17971da177e4SLinus Torvalds 		} else {
17981da177e4SLinus Torvalds 			/* If platform doesn't support CPEI, get the timer going. */
17991da177e4SLinus Torvalds 			if (cpe_poll_enabled) {
18001da177e4SLinus Torvalds 				ia64_mca_cpe_poll(0UL);
18011da177e4SLinus Torvalds 				IA64_MCA_DEBUG("%s: CPEP setup and enabled.\n", __FUNCTION__);
18021da177e4SLinus Torvalds 			}
18031da177e4SLinus Torvalds 		}
18041da177e4SLinus Torvalds 	}
18051da177e4SLinus Torvalds #endif
18061da177e4SLinus Torvalds 
18071da177e4SLinus Torvalds 	return 0;
18081da177e4SLinus Torvalds }
18091da177e4SLinus Torvalds 
18101da177e4SLinus Torvalds device_initcall(ia64_mca_late_init);
1811