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