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. 5743ed3bafSHidetoshi Seto * 5843ed3bafSHidetoshi Seto * 2006-09-15 Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com> 5943ed3bafSHidetoshi Seto * Add printing support for MCA/INIT. 601da177e4SLinus Torvalds */ 611da177e4SLinus Torvalds #include <linux/types.h> 621da177e4SLinus Torvalds #include <linux/init.h> 631da177e4SLinus Torvalds #include <linux/sched.h> 641da177e4SLinus Torvalds #include <linux/interrupt.h> 651da177e4SLinus Torvalds #include <linux/irq.h> 661da177e4SLinus Torvalds #include <linux/smp_lock.h> 671da177e4SLinus Torvalds #include <linux/bootmem.h> 681da177e4SLinus Torvalds #include <linux/acpi.h> 691da177e4SLinus Torvalds #include <linux/timer.h> 701da177e4SLinus Torvalds #include <linux/module.h> 711da177e4SLinus Torvalds #include <linux/kernel.h> 721da177e4SLinus Torvalds #include <linux/smp.h> 731da177e4SLinus Torvalds #include <linux/workqueue.h> 744668f0cdSAkinobu Mita #include <linux/cpumask.h> 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds #include <asm/delay.h> 779138d581SKeith Owens #include <asm/kdebug.h> 781da177e4SLinus Torvalds #include <asm/machvec.h> 791da177e4SLinus Torvalds #include <asm/meminit.h> 801da177e4SLinus Torvalds #include <asm/page.h> 811da177e4SLinus Torvalds #include <asm/ptrace.h> 821da177e4SLinus Torvalds #include <asm/system.h> 831da177e4SLinus Torvalds #include <asm/sal.h> 841da177e4SLinus Torvalds #include <asm/mca.h> 85*a7956113SZou Nan hai #include <asm/kexec.h> 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds #include <asm/irq.h> 881da177e4SLinus Torvalds #include <asm/hw_irq.h> 891da177e4SLinus Torvalds 90d2a28ad9SRuss Anderson #include "mca_drv.h" 917f613c7dSKeith Owens #include "entry.h" 927f613c7dSKeith Owens 931da177e4SLinus Torvalds #if defined(IA64_MCA_DEBUG_INFO) 941da177e4SLinus Torvalds # define IA64_MCA_DEBUG(fmt...) printk(fmt) 951da177e4SLinus Torvalds #else 961da177e4SLinus Torvalds # define IA64_MCA_DEBUG(fmt...) 971da177e4SLinus Torvalds #endif 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds /* Used by mca_asm.S */ 1007f613c7dSKeith Owens u32 ia64_mca_serialize; 1011da177e4SLinus Torvalds DEFINE_PER_CPU(u64, ia64_mca_data); /* == __per_cpu_mca[smp_processor_id()] */ 1021da177e4SLinus Torvalds DEFINE_PER_CPU(u64, ia64_mca_per_cpu_pte); /* PTE to map per-CPU area */ 1031da177e4SLinus Torvalds DEFINE_PER_CPU(u64, ia64_mca_pal_pte); /* PTE to map PAL code */ 1041da177e4SLinus Torvalds DEFINE_PER_CPU(u64, ia64_mca_pal_base); /* vaddr PAL code granule */ 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds unsigned long __per_cpu_mca[NR_CPUS]; 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds /* In mca_asm.S */ 1097f613c7dSKeith Owens extern void ia64_os_init_dispatch_monarch (void); 1107f613c7dSKeith Owens extern void ia64_os_init_dispatch_slave (void); 1117f613c7dSKeith Owens 1127f613c7dSKeith Owens static int monarch_cpu = -1; 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds static ia64_mc_info_t ia64_mc_info; 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds #define MAX_CPE_POLL_INTERVAL (15*60*HZ) /* 15 minutes */ 1171da177e4SLinus Torvalds #define MIN_CPE_POLL_INTERVAL (2*60*HZ) /* 2 minutes */ 1181da177e4SLinus Torvalds #define CMC_POLL_INTERVAL (1*60*HZ) /* 1 minute */ 1191da177e4SLinus Torvalds #define CPE_HISTORY_LENGTH 5 1201da177e4SLinus Torvalds #define CMC_HISTORY_LENGTH 5 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds static struct timer_list cpe_poll_timer; 1231da177e4SLinus Torvalds static struct timer_list cmc_poll_timer; 1241da177e4SLinus Torvalds /* 1251da177e4SLinus Torvalds * This variable tells whether we are currently in polling mode. 1261da177e4SLinus Torvalds * Start with this in the wrong state so we won't play w/ timers 1271da177e4SLinus Torvalds * before the system is ready. 1281da177e4SLinus Torvalds */ 1291da177e4SLinus Torvalds static int cmc_polling_enabled = 1; 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds /* 1321da177e4SLinus Torvalds * Clearing this variable prevents CPE polling from getting activated 1331da177e4SLinus Torvalds * in mca_late_init. Use it if your system doesn't provide a CPEI, 1341da177e4SLinus Torvalds * but encounters problems retrieving CPE logs. This should only be 1351da177e4SLinus Torvalds * necessary for debugging. 1361da177e4SLinus Torvalds */ 1371da177e4SLinus Torvalds static int cpe_poll_enabled = 1; 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds extern void salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe); 1401da177e4SLinus Torvalds 1410881fc8dSChen, Kenneth W static int mca_init __initdata; 1421da177e4SLinus Torvalds 14343ed3bafSHidetoshi Seto /* 14443ed3bafSHidetoshi Seto * limited & delayed printing support for MCA/INIT handler 14543ed3bafSHidetoshi Seto */ 14643ed3bafSHidetoshi Seto 14743ed3bafSHidetoshi Seto #define mprintk(fmt...) ia64_mca_printk(fmt) 14843ed3bafSHidetoshi Seto 14943ed3bafSHidetoshi Seto #define MLOGBUF_SIZE (512+256*NR_CPUS) 15043ed3bafSHidetoshi Seto #define MLOGBUF_MSGMAX 256 15143ed3bafSHidetoshi Seto static char mlogbuf[MLOGBUF_SIZE]; 15243ed3bafSHidetoshi Seto static DEFINE_SPINLOCK(mlogbuf_wlock); /* mca context only */ 15343ed3bafSHidetoshi Seto static DEFINE_SPINLOCK(mlogbuf_rlock); /* normal context only */ 15443ed3bafSHidetoshi Seto static unsigned long mlogbuf_start; 15543ed3bafSHidetoshi Seto static unsigned long mlogbuf_end; 15643ed3bafSHidetoshi Seto static unsigned int mlogbuf_finished = 0; 15743ed3bafSHidetoshi Seto static unsigned long mlogbuf_timestamp = 0; 15843ed3bafSHidetoshi Seto 15943ed3bafSHidetoshi Seto static int loglevel_save = -1; 16043ed3bafSHidetoshi Seto #define BREAK_LOGLEVEL(__console_loglevel) \ 16143ed3bafSHidetoshi Seto oops_in_progress = 1; \ 16243ed3bafSHidetoshi Seto if (loglevel_save < 0) \ 16343ed3bafSHidetoshi Seto loglevel_save = __console_loglevel; \ 16443ed3bafSHidetoshi Seto __console_loglevel = 15; 16543ed3bafSHidetoshi Seto 16643ed3bafSHidetoshi Seto #define RESTORE_LOGLEVEL(__console_loglevel) \ 16743ed3bafSHidetoshi Seto if (loglevel_save >= 0) { \ 16843ed3bafSHidetoshi Seto __console_loglevel = loglevel_save; \ 16943ed3bafSHidetoshi Seto loglevel_save = -1; \ 17043ed3bafSHidetoshi Seto } \ 17143ed3bafSHidetoshi Seto mlogbuf_finished = 0; \ 17243ed3bafSHidetoshi Seto oops_in_progress = 0; 17343ed3bafSHidetoshi Seto 17443ed3bafSHidetoshi Seto /* 17543ed3bafSHidetoshi Seto * Push messages into buffer, print them later if not urgent. 17643ed3bafSHidetoshi Seto */ 17743ed3bafSHidetoshi Seto void ia64_mca_printk(const char *fmt, ...) 17843ed3bafSHidetoshi Seto { 17943ed3bafSHidetoshi Seto va_list args; 18043ed3bafSHidetoshi Seto int printed_len; 18143ed3bafSHidetoshi Seto char temp_buf[MLOGBUF_MSGMAX]; 18243ed3bafSHidetoshi Seto char *p; 18343ed3bafSHidetoshi Seto 18443ed3bafSHidetoshi Seto va_start(args, fmt); 18543ed3bafSHidetoshi Seto printed_len = vscnprintf(temp_buf, sizeof(temp_buf), fmt, args); 18643ed3bafSHidetoshi Seto va_end(args); 18743ed3bafSHidetoshi Seto 18843ed3bafSHidetoshi Seto /* Copy the output into mlogbuf */ 18943ed3bafSHidetoshi Seto if (oops_in_progress) { 19043ed3bafSHidetoshi Seto /* mlogbuf was abandoned, use printk directly instead. */ 19143ed3bafSHidetoshi Seto printk(temp_buf); 19243ed3bafSHidetoshi Seto } else { 19343ed3bafSHidetoshi Seto spin_lock(&mlogbuf_wlock); 19443ed3bafSHidetoshi Seto for (p = temp_buf; *p; p++) { 19543ed3bafSHidetoshi Seto unsigned long next = (mlogbuf_end + 1) % MLOGBUF_SIZE; 19643ed3bafSHidetoshi Seto if (next != mlogbuf_start) { 19743ed3bafSHidetoshi Seto mlogbuf[mlogbuf_end] = *p; 19843ed3bafSHidetoshi Seto mlogbuf_end = next; 19943ed3bafSHidetoshi Seto } else { 20043ed3bafSHidetoshi Seto /* buffer full */ 20143ed3bafSHidetoshi Seto break; 20243ed3bafSHidetoshi Seto } 20343ed3bafSHidetoshi Seto } 20443ed3bafSHidetoshi Seto mlogbuf[mlogbuf_end] = '\0'; 20543ed3bafSHidetoshi Seto spin_unlock(&mlogbuf_wlock); 20643ed3bafSHidetoshi Seto } 20743ed3bafSHidetoshi Seto } 20843ed3bafSHidetoshi Seto EXPORT_SYMBOL(ia64_mca_printk); 20943ed3bafSHidetoshi Seto 21043ed3bafSHidetoshi Seto /* 21143ed3bafSHidetoshi Seto * Print buffered messages. 21243ed3bafSHidetoshi Seto * NOTE: call this after returning normal context. (ex. from salinfod) 21343ed3bafSHidetoshi Seto */ 21443ed3bafSHidetoshi Seto void ia64_mlogbuf_dump(void) 21543ed3bafSHidetoshi Seto { 21643ed3bafSHidetoshi Seto char temp_buf[MLOGBUF_MSGMAX]; 21743ed3bafSHidetoshi Seto char *p; 21843ed3bafSHidetoshi Seto unsigned long index; 21943ed3bafSHidetoshi Seto unsigned long flags; 22043ed3bafSHidetoshi Seto unsigned int printed_len; 22143ed3bafSHidetoshi Seto 22243ed3bafSHidetoshi Seto /* Get output from mlogbuf */ 22343ed3bafSHidetoshi Seto while (mlogbuf_start != mlogbuf_end) { 22443ed3bafSHidetoshi Seto temp_buf[0] = '\0'; 22543ed3bafSHidetoshi Seto p = temp_buf; 22643ed3bafSHidetoshi Seto printed_len = 0; 22743ed3bafSHidetoshi Seto 22843ed3bafSHidetoshi Seto spin_lock_irqsave(&mlogbuf_rlock, flags); 22943ed3bafSHidetoshi Seto 23043ed3bafSHidetoshi Seto index = mlogbuf_start; 23143ed3bafSHidetoshi Seto while (index != mlogbuf_end) { 23243ed3bafSHidetoshi Seto *p = mlogbuf[index]; 23343ed3bafSHidetoshi Seto index = (index + 1) % MLOGBUF_SIZE; 23443ed3bafSHidetoshi Seto if (!*p) 23543ed3bafSHidetoshi Seto break; 23643ed3bafSHidetoshi Seto p++; 23743ed3bafSHidetoshi Seto if (++printed_len >= MLOGBUF_MSGMAX - 1) 23843ed3bafSHidetoshi Seto break; 23943ed3bafSHidetoshi Seto } 24043ed3bafSHidetoshi Seto *p = '\0'; 24143ed3bafSHidetoshi Seto if (temp_buf[0]) 24243ed3bafSHidetoshi Seto printk(temp_buf); 24343ed3bafSHidetoshi Seto mlogbuf_start = index; 24443ed3bafSHidetoshi Seto 24543ed3bafSHidetoshi Seto mlogbuf_timestamp = 0; 24643ed3bafSHidetoshi Seto spin_unlock_irqrestore(&mlogbuf_rlock, flags); 24743ed3bafSHidetoshi Seto } 24843ed3bafSHidetoshi Seto } 24943ed3bafSHidetoshi Seto EXPORT_SYMBOL(ia64_mlogbuf_dump); 25043ed3bafSHidetoshi Seto 25143ed3bafSHidetoshi Seto /* 25243ed3bafSHidetoshi Seto * Call this if system is going to down or if immediate flushing messages to 25343ed3bafSHidetoshi Seto * console is required. (ex. recovery was failed, crash dump is going to be 25443ed3bafSHidetoshi Seto * invoked, long-wait rendezvous etc.) 25543ed3bafSHidetoshi Seto * NOTE: this should be called from monarch. 25643ed3bafSHidetoshi Seto */ 25743ed3bafSHidetoshi Seto static void ia64_mlogbuf_finish(int wait) 25843ed3bafSHidetoshi Seto { 25943ed3bafSHidetoshi Seto BREAK_LOGLEVEL(console_loglevel); 26043ed3bafSHidetoshi Seto 26143ed3bafSHidetoshi Seto spin_lock_init(&mlogbuf_rlock); 26243ed3bafSHidetoshi Seto ia64_mlogbuf_dump(); 26343ed3bafSHidetoshi Seto printk(KERN_EMERG "mlogbuf_finish: printing switched to urgent mode, " 26443ed3bafSHidetoshi Seto "MCA/INIT might be dodgy or fail.\n"); 26543ed3bafSHidetoshi Seto 26643ed3bafSHidetoshi Seto if (!wait) 26743ed3bafSHidetoshi Seto return; 26843ed3bafSHidetoshi Seto 26943ed3bafSHidetoshi Seto /* wait for console */ 27043ed3bafSHidetoshi Seto printk("Delaying for 5 seconds...\n"); 27143ed3bafSHidetoshi Seto udelay(5*1000000); 27243ed3bafSHidetoshi Seto 27343ed3bafSHidetoshi Seto mlogbuf_finished = 1; 27443ed3bafSHidetoshi Seto } 27543ed3bafSHidetoshi Seto EXPORT_SYMBOL(ia64_mlogbuf_finish); 27643ed3bafSHidetoshi Seto 27743ed3bafSHidetoshi Seto /* 27843ed3bafSHidetoshi Seto * Print buffered messages from INIT context. 27943ed3bafSHidetoshi Seto */ 28043ed3bafSHidetoshi Seto static void ia64_mlogbuf_dump_from_init(void) 28143ed3bafSHidetoshi Seto { 28243ed3bafSHidetoshi Seto if (mlogbuf_finished) 28343ed3bafSHidetoshi Seto return; 28443ed3bafSHidetoshi Seto 28543ed3bafSHidetoshi Seto if (mlogbuf_timestamp && (mlogbuf_timestamp + 30*HZ > jiffies)) { 28643ed3bafSHidetoshi Seto printk(KERN_ERR "INIT: mlogbuf_dump is interrupted by INIT " 28743ed3bafSHidetoshi Seto " and the system seems to be messed up.\n"); 28843ed3bafSHidetoshi Seto ia64_mlogbuf_finish(0); 28943ed3bafSHidetoshi Seto return; 29043ed3bafSHidetoshi Seto } 29143ed3bafSHidetoshi Seto 29243ed3bafSHidetoshi Seto if (!spin_trylock(&mlogbuf_rlock)) { 29343ed3bafSHidetoshi Seto printk(KERN_ERR "INIT: mlogbuf_dump is interrupted by INIT. " 29443ed3bafSHidetoshi Seto "Generated messages other than stack dump will be " 29543ed3bafSHidetoshi Seto "buffered to mlogbuf and will be printed later.\n"); 29643ed3bafSHidetoshi Seto printk(KERN_ERR "INIT: If messages would not printed after " 29743ed3bafSHidetoshi Seto "this INIT, wait 30sec and assert INIT again.\n"); 29843ed3bafSHidetoshi Seto if (!mlogbuf_timestamp) 29943ed3bafSHidetoshi Seto mlogbuf_timestamp = jiffies; 30043ed3bafSHidetoshi Seto return; 30143ed3bafSHidetoshi Seto } 30243ed3bafSHidetoshi Seto spin_unlock(&mlogbuf_rlock); 30343ed3bafSHidetoshi Seto ia64_mlogbuf_dump(); 30443ed3bafSHidetoshi Seto } 3059138d581SKeith Owens 3069138d581SKeith Owens static void inline 3079138d581SKeith Owens ia64_mca_spin(const char *func) 3089138d581SKeith Owens { 30943ed3bafSHidetoshi Seto if (monarch_cpu == smp_processor_id()) 31043ed3bafSHidetoshi Seto ia64_mlogbuf_finish(0); 31143ed3bafSHidetoshi Seto mprintk(KERN_EMERG "%s: spinning here, not returning to SAL\n", func); 3129138d581SKeith Owens while (1) 3139138d581SKeith Owens cpu_relax(); 3149138d581SKeith Owens } 3151da177e4SLinus Torvalds /* 3161da177e4SLinus Torvalds * IA64_MCA log support 3171da177e4SLinus Torvalds */ 3181da177e4SLinus Torvalds #define IA64_MAX_LOGS 2 /* Double-buffering for nested MCAs */ 3191da177e4SLinus Torvalds #define IA64_MAX_LOG_TYPES 4 /* MCA, INIT, CMC, CPE */ 3201da177e4SLinus Torvalds 3211da177e4SLinus Torvalds typedef struct ia64_state_log_s 3221da177e4SLinus Torvalds { 3231da177e4SLinus Torvalds spinlock_t isl_lock; 3241da177e4SLinus Torvalds int isl_index; 3251da177e4SLinus Torvalds unsigned long isl_count; 3261da177e4SLinus Torvalds ia64_err_rec_t *isl_log[IA64_MAX_LOGS]; /* need space to store header + error log */ 3271da177e4SLinus Torvalds } ia64_state_log_t; 3281da177e4SLinus Torvalds 3291da177e4SLinus Torvalds static ia64_state_log_t ia64_state_log[IA64_MAX_LOG_TYPES]; 3301da177e4SLinus Torvalds 3311da177e4SLinus Torvalds #define IA64_LOG_ALLOCATE(it, size) \ 3321da177e4SLinus Torvalds {ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)] = \ 3331da177e4SLinus Torvalds (ia64_err_rec_t *)alloc_bootmem(size); \ 3341da177e4SLinus Torvalds ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)] = \ 3351da177e4SLinus Torvalds (ia64_err_rec_t *)alloc_bootmem(size);} 3361da177e4SLinus Torvalds #define IA64_LOG_LOCK_INIT(it) spin_lock_init(&ia64_state_log[it].isl_lock) 3371da177e4SLinus Torvalds #define IA64_LOG_LOCK(it) spin_lock_irqsave(&ia64_state_log[it].isl_lock, s) 3381da177e4SLinus Torvalds #define IA64_LOG_UNLOCK(it) spin_unlock_irqrestore(&ia64_state_log[it].isl_lock,s) 3391da177e4SLinus Torvalds #define IA64_LOG_NEXT_INDEX(it) ia64_state_log[it].isl_index 3401da177e4SLinus Torvalds #define IA64_LOG_CURR_INDEX(it) 1 - ia64_state_log[it].isl_index 3411da177e4SLinus Torvalds #define IA64_LOG_INDEX_INC(it) \ 3421da177e4SLinus Torvalds {ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index; \ 3431da177e4SLinus Torvalds ia64_state_log[it].isl_count++;} 3441da177e4SLinus Torvalds #define IA64_LOG_INDEX_DEC(it) \ 3451da177e4SLinus Torvalds ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index 3461da177e4SLinus Torvalds #define IA64_LOG_NEXT_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)])) 3471da177e4SLinus Torvalds #define IA64_LOG_CURR_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)])) 3481da177e4SLinus Torvalds #define IA64_LOG_COUNT(it) ia64_state_log[it].isl_count 3491da177e4SLinus Torvalds 3501da177e4SLinus Torvalds /* 3511da177e4SLinus Torvalds * ia64_log_init 3521da177e4SLinus Torvalds * Reset the OS ia64 log buffer 3531da177e4SLinus Torvalds * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE}) 3541da177e4SLinus Torvalds * Outputs : None 3551da177e4SLinus Torvalds */ 3560881fc8dSChen, Kenneth W static void __init 3571da177e4SLinus Torvalds ia64_log_init(int sal_info_type) 3581da177e4SLinus Torvalds { 3591da177e4SLinus Torvalds u64 max_size = 0; 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds IA64_LOG_NEXT_INDEX(sal_info_type) = 0; 3621da177e4SLinus Torvalds IA64_LOG_LOCK_INIT(sal_info_type); 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds // SAL will tell us the maximum size of any error record of this type 3651da177e4SLinus Torvalds max_size = ia64_sal_get_state_info_size(sal_info_type); 3661da177e4SLinus Torvalds if (!max_size) 3671da177e4SLinus Torvalds /* alloc_bootmem() doesn't like zero-sized allocations! */ 3681da177e4SLinus Torvalds return; 3691da177e4SLinus Torvalds 3701da177e4SLinus Torvalds // set up OS data structures to hold error info 3711da177e4SLinus Torvalds IA64_LOG_ALLOCATE(sal_info_type, max_size); 3721da177e4SLinus Torvalds memset(IA64_LOG_CURR_BUFFER(sal_info_type), 0, max_size); 3731da177e4SLinus Torvalds memset(IA64_LOG_NEXT_BUFFER(sal_info_type), 0, max_size); 3741da177e4SLinus Torvalds } 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds /* 3771da177e4SLinus Torvalds * ia64_log_get 3781da177e4SLinus Torvalds * 3791da177e4SLinus Torvalds * Get the current MCA log from SAL and copy it into the OS log buffer. 3801da177e4SLinus Torvalds * 3811da177e4SLinus Torvalds * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE}) 3821da177e4SLinus Torvalds * irq_safe whether you can use printk at this point 3831da177e4SLinus Torvalds * Outputs : size (total record length) 3841da177e4SLinus Torvalds * *buffer (ptr to error record) 3851da177e4SLinus Torvalds * 3861da177e4SLinus Torvalds */ 3871da177e4SLinus Torvalds static u64 3881da177e4SLinus Torvalds ia64_log_get(int sal_info_type, u8 **buffer, int irq_safe) 3891da177e4SLinus Torvalds { 3901da177e4SLinus Torvalds sal_log_record_header_t *log_buffer; 3911da177e4SLinus Torvalds u64 total_len = 0; 392c53421b1SAlexey Dobriyan unsigned long s; 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds IA64_LOG_LOCK(sal_info_type); 3951da177e4SLinus Torvalds 3961da177e4SLinus Torvalds /* Get the process state information */ 3971da177e4SLinus Torvalds log_buffer = IA64_LOG_NEXT_BUFFER(sal_info_type); 3981da177e4SLinus Torvalds 3991da177e4SLinus Torvalds total_len = ia64_sal_get_state_info(sal_info_type, (u64 *)log_buffer); 4001da177e4SLinus Torvalds 4011da177e4SLinus Torvalds if (total_len) { 4021da177e4SLinus Torvalds IA64_LOG_INDEX_INC(sal_info_type); 4031da177e4SLinus Torvalds IA64_LOG_UNLOCK(sal_info_type); 4041da177e4SLinus Torvalds if (irq_safe) { 4051da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: SAL error record type %d retrieved. " 4061da177e4SLinus Torvalds "Record length = %ld\n", __FUNCTION__, sal_info_type, total_len); 4071da177e4SLinus Torvalds } 4081da177e4SLinus Torvalds *buffer = (u8 *) log_buffer; 4091da177e4SLinus Torvalds return total_len; 4101da177e4SLinus Torvalds } else { 4111da177e4SLinus Torvalds IA64_LOG_UNLOCK(sal_info_type); 4121da177e4SLinus Torvalds return 0; 4131da177e4SLinus Torvalds } 4141da177e4SLinus Torvalds } 4151da177e4SLinus Torvalds 4161da177e4SLinus Torvalds /* 4171da177e4SLinus Torvalds * ia64_mca_log_sal_error_record 4181da177e4SLinus Torvalds * 4191da177e4SLinus Torvalds * This function retrieves a specified error record type from SAL 4201da177e4SLinus Torvalds * and wakes up any processes waiting for error records. 4211da177e4SLinus Torvalds * 4227f613c7dSKeith Owens * Inputs : sal_info_type (Type of error record MCA/CMC/CPE) 4237f613c7dSKeith Owens * FIXME: remove MCA and irq_safe. 4241da177e4SLinus Torvalds */ 4251da177e4SLinus Torvalds static void 4261da177e4SLinus Torvalds ia64_mca_log_sal_error_record(int sal_info_type) 4271da177e4SLinus Torvalds { 4281da177e4SLinus Torvalds u8 *buffer; 4291da177e4SLinus Torvalds sal_log_record_header_t *rh; 4301da177e4SLinus Torvalds u64 size; 4317f613c7dSKeith Owens int irq_safe = sal_info_type != SAL_INFO_TYPE_MCA; 4321da177e4SLinus Torvalds #ifdef IA64_MCA_DEBUG_INFO 4331da177e4SLinus Torvalds static const char * const rec_name[] = { "MCA", "INIT", "CMC", "CPE" }; 4341da177e4SLinus Torvalds #endif 4351da177e4SLinus Torvalds 4361da177e4SLinus Torvalds size = ia64_log_get(sal_info_type, &buffer, irq_safe); 4371da177e4SLinus Torvalds if (!size) 4381da177e4SLinus Torvalds return; 4391da177e4SLinus Torvalds 4401da177e4SLinus Torvalds salinfo_log_wakeup(sal_info_type, buffer, size, irq_safe); 4411da177e4SLinus Torvalds 4421da177e4SLinus Torvalds if (irq_safe) 4431da177e4SLinus Torvalds IA64_MCA_DEBUG("CPU %d: SAL log contains %s error record\n", 4441da177e4SLinus Torvalds smp_processor_id(), 4451da177e4SLinus Torvalds sal_info_type < ARRAY_SIZE(rec_name) ? rec_name[sal_info_type] : "UNKNOWN"); 4461da177e4SLinus Torvalds 4471da177e4SLinus Torvalds /* Clear logs from corrected errors in case there's no user-level logger */ 4481da177e4SLinus Torvalds rh = (sal_log_record_header_t *)buffer; 4491da177e4SLinus Torvalds if (rh->severity == sal_log_severity_corrected) 4501da177e4SLinus Torvalds ia64_sal_clear_state_info(sal_info_type); 4511da177e4SLinus Torvalds } 4521da177e4SLinus Torvalds 453d2a28ad9SRuss Anderson /* 454d2a28ad9SRuss Anderson * search_mca_table 455d2a28ad9SRuss Anderson * See if the MCA surfaced in an instruction range 456d2a28ad9SRuss Anderson * that has been tagged as recoverable. 457d2a28ad9SRuss Anderson * 458d2a28ad9SRuss Anderson * Inputs 459d2a28ad9SRuss Anderson * first First address range to check 460d2a28ad9SRuss Anderson * last Last address range to check 461d2a28ad9SRuss Anderson * ip Instruction pointer, address we are looking for 462d2a28ad9SRuss Anderson * 463d2a28ad9SRuss Anderson * Return value: 464d2a28ad9SRuss Anderson * 1 on Success (in the table)/ 0 on Failure (not in the table) 465d2a28ad9SRuss Anderson */ 466d2a28ad9SRuss Anderson int 467d2a28ad9SRuss Anderson search_mca_table (const struct mca_table_entry *first, 468d2a28ad9SRuss Anderson const struct mca_table_entry *last, 469d2a28ad9SRuss Anderson unsigned long ip) 470d2a28ad9SRuss Anderson { 471d2a28ad9SRuss Anderson const struct mca_table_entry *curr; 472d2a28ad9SRuss Anderson u64 curr_start, curr_end; 473d2a28ad9SRuss Anderson 474d2a28ad9SRuss Anderson curr = first; 475d2a28ad9SRuss Anderson while (curr <= last) { 476d2a28ad9SRuss Anderson curr_start = (u64) &curr->start_addr + curr->start_addr; 477d2a28ad9SRuss Anderson curr_end = (u64) &curr->end_addr + curr->end_addr; 478d2a28ad9SRuss Anderson 479d2a28ad9SRuss Anderson if ((ip >= curr_start) && (ip <= curr_end)) { 480d2a28ad9SRuss Anderson return 1; 481d2a28ad9SRuss Anderson } 482d2a28ad9SRuss Anderson curr++; 483d2a28ad9SRuss Anderson } 484d2a28ad9SRuss Anderson return 0; 485d2a28ad9SRuss Anderson } 486d2a28ad9SRuss Anderson 487d2a28ad9SRuss Anderson /* Given an address, look for it in the mca tables. */ 488d2a28ad9SRuss Anderson int mca_recover_range(unsigned long addr) 489d2a28ad9SRuss Anderson { 490d2a28ad9SRuss Anderson extern struct mca_table_entry __start___mca_table[]; 491d2a28ad9SRuss Anderson extern struct mca_table_entry __stop___mca_table[]; 492d2a28ad9SRuss Anderson 493d2a28ad9SRuss Anderson return search_mca_table(__start___mca_table, __stop___mca_table-1, addr); 494d2a28ad9SRuss Anderson } 495d2a28ad9SRuss Anderson EXPORT_SYMBOL_GPL(mca_recover_range); 496d2a28ad9SRuss Anderson 4971da177e4SLinus Torvalds #ifdef CONFIG_ACPI 4981da177e4SLinus Torvalds 49955e59c51SAshok Raj int cpe_vector = -1; 500ff741906SAshok Raj int ia64_cpe_irq = -1; 5011da177e4SLinus Torvalds 5021da177e4SLinus Torvalds static irqreturn_t 5037d12e780SDavid Howells ia64_mca_cpe_int_handler (int cpe_irq, void *arg) 5041da177e4SLinus Torvalds { 5051da177e4SLinus Torvalds static unsigned long cpe_history[CPE_HISTORY_LENGTH]; 5061da177e4SLinus Torvalds static int index; 5071da177e4SLinus Torvalds static DEFINE_SPINLOCK(cpe_history_lock); 5081da177e4SLinus Torvalds 5091da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n", 5101da177e4SLinus Torvalds __FUNCTION__, cpe_irq, smp_processor_id()); 5111da177e4SLinus Torvalds 5121da177e4SLinus Torvalds /* SAL spec states this should run w/ interrupts enabled */ 5131da177e4SLinus Torvalds local_irq_enable(); 5141da177e4SLinus Torvalds 5151da177e4SLinus Torvalds spin_lock(&cpe_history_lock); 5161da177e4SLinus Torvalds if (!cpe_poll_enabled && cpe_vector >= 0) { 5171da177e4SLinus Torvalds 5181da177e4SLinus Torvalds int i, count = 1; /* we know 1 happened now */ 5191da177e4SLinus Torvalds unsigned long now = jiffies; 5201da177e4SLinus Torvalds 5211da177e4SLinus Torvalds for (i = 0; i < CPE_HISTORY_LENGTH; i++) { 5221da177e4SLinus Torvalds if (now - cpe_history[i] <= HZ) 5231da177e4SLinus Torvalds count++; 5241da177e4SLinus Torvalds } 5251da177e4SLinus Torvalds 5261da177e4SLinus Torvalds IA64_MCA_DEBUG(KERN_INFO "CPE threshold %d/%d\n", count, CPE_HISTORY_LENGTH); 5271da177e4SLinus Torvalds if (count >= CPE_HISTORY_LENGTH) { 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds cpe_poll_enabled = 1; 5301da177e4SLinus Torvalds spin_unlock(&cpe_history_lock); 5311da177e4SLinus Torvalds disable_irq_nosync(local_vector_to_irq(IA64_CPE_VECTOR)); 5321da177e4SLinus Torvalds 5331da177e4SLinus Torvalds /* 5341da177e4SLinus Torvalds * Corrected errors will still be corrected, but 5351da177e4SLinus Torvalds * make sure there's a log somewhere that indicates 5361da177e4SLinus Torvalds * something is generating more than we can handle. 5371da177e4SLinus Torvalds */ 5381da177e4SLinus Torvalds printk(KERN_WARNING "WARNING: Switching to polling CPE handler; error records may be lost\n"); 5391da177e4SLinus Torvalds 5401da177e4SLinus Torvalds mod_timer(&cpe_poll_timer, jiffies + MIN_CPE_POLL_INTERVAL); 5411da177e4SLinus Torvalds 5421da177e4SLinus Torvalds /* lock already released, get out now */ 543ddb4f0dfSHidetoshi Seto goto out; 5441da177e4SLinus Torvalds } else { 5451da177e4SLinus Torvalds cpe_history[index++] = now; 5461da177e4SLinus Torvalds if (index == CPE_HISTORY_LENGTH) 5471da177e4SLinus Torvalds index = 0; 5481da177e4SLinus Torvalds } 5491da177e4SLinus Torvalds } 5501da177e4SLinus Torvalds spin_unlock(&cpe_history_lock); 551ddb4f0dfSHidetoshi Seto out: 552ddb4f0dfSHidetoshi Seto /* Get the CPE error record and log it */ 553ddb4f0dfSHidetoshi Seto ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE); 554ddb4f0dfSHidetoshi Seto 5551da177e4SLinus Torvalds return IRQ_HANDLED; 5561da177e4SLinus Torvalds } 5571da177e4SLinus Torvalds 5581da177e4SLinus Torvalds #endif /* CONFIG_ACPI */ 5591da177e4SLinus Torvalds 5601da177e4SLinus Torvalds #ifdef CONFIG_ACPI 5611da177e4SLinus Torvalds /* 5621da177e4SLinus Torvalds * ia64_mca_register_cpev 5631da177e4SLinus Torvalds * 5641da177e4SLinus Torvalds * Register the corrected platform error vector with SAL. 5651da177e4SLinus Torvalds * 5661da177e4SLinus Torvalds * Inputs 5671da177e4SLinus Torvalds * cpev Corrected Platform Error Vector number 5681da177e4SLinus Torvalds * 5691da177e4SLinus Torvalds * Outputs 5701da177e4SLinus Torvalds * None 5711da177e4SLinus Torvalds */ 5720881fc8dSChen, Kenneth W static void __init 5731da177e4SLinus Torvalds ia64_mca_register_cpev (int cpev) 5741da177e4SLinus Torvalds { 5751da177e4SLinus Torvalds /* Register the CPE interrupt vector with SAL */ 5761da177e4SLinus Torvalds struct ia64_sal_retval isrv; 5771da177e4SLinus Torvalds 5781da177e4SLinus Torvalds isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_CPE_INT, SAL_MC_PARAM_MECHANISM_INT, cpev, 0, 0); 5791da177e4SLinus Torvalds if (isrv.status) { 5801da177e4SLinus Torvalds printk(KERN_ERR "Failed to register Corrected Platform " 5811da177e4SLinus Torvalds "Error interrupt vector with SAL (status %ld)\n", isrv.status); 5821da177e4SLinus Torvalds return; 5831da177e4SLinus Torvalds } 5841da177e4SLinus Torvalds 5851da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: corrected platform error " 5861da177e4SLinus Torvalds "vector %#x registered\n", __FUNCTION__, cpev); 5871da177e4SLinus Torvalds } 5881da177e4SLinus Torvalds #endif /* CONFIG_ACPI */ 5891da177e4SLinus Torvalds 5901da177e4SLinus Torvalds /* 5911da177e4SLinus Torvalds * ia64_mca_cmc_vector_setup 5921da177e4SLinus Torvalds * 5931da177e4SLinus Torvalds * Setup the corrected machine check vector register in the processor. 5941da177e4SLinus Torvalds * (The interrupt is masked on boot. ia64_mca_late_init unmask this.) 5951da177e4SLinus Torvalds * This function is invoked on a per-processor basis. 5961da177e4SLinus Torvalds * 5971da177e4SLinus Torvalds * Inputs 5981da177e4SLinus Torvalds * None 5991da177e4SLinus Torvalds * 6001da177e4SLinus Torvalds * Outputs 6011da177e4SLinus Torvalds * None 6021da177e4SLinus Torvalds */ 6030881fc8dSChen, Kenneth W void __cpuinit 6041da177e4SLinus Torvalds ia64_mca_cmc_vector_setup (void) 6051da177e4SLinus Torvalds { 6061da177e4SLinus Torvalds cmcv_reg_t cmcv; 6071da177e4SLinus Torvalds 6081da177e4SLinus Torvalds cmcv.cmcv_regval = 0; 6091da177e4SLinus Torvalds cmcv.cmcv_mask = 1; /* Mask/disable interrupt at first */ 6101da177e4SLinus Torvalds cmcv.cmcv_vector = IA64_CMC_VECTOR; 6111da177e4SLinus Torvalds ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval); 6121da177e4SLinus Torvalds 6131da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: CPU %d corrected " 6141da177e4SLinus Torvalds "machine check vector %#x registered.\n", 6151da177e4SLinus Torvalds __FUNCTION__, smp_processor_id(), IA64_CMC_VECTOR); 6161da177e4SLinus Torvalds 6171da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: CPU %d CMCV = %#016lx\n", 6181da177e4SLinus Torvalds __FUNCTION__, smp_processor_id(), ia64_getreg(_IA64_REG_CR_CMCV)); 6191da177e4SLinus Torvalds } 6201da177e4SLinus Torvalds 6211da177e4SLinus Torvalds /* 6221da177e4SLinus Torvalds * ia64_mca_cmc_vector_disable 6231da177e4SLinus Torvalds * 6241da177e4SLinus Torvalds * Mask the corrected machine check vector register in the processor. 6251da177e4SLinus Torvalds * This function is invoked on a per-processor basis. 6261da177e4SLinus Torvalds * 6271da177e4SLinus Torvalds * Inputs 6281da177e4SLinus Torvalds * dummy(unused) 6291da177e4SLinus Torvalds * 6301da177e4SLinus Torvalds * Outputs 6311da177e4SLinus Torvalds * None 6321da177e4SLinus Torvalds */ 6331da177e4SLinus Torvalds static void 6341da177e4SLinus Torvalds ia64_mca_cmc_vector_disable (void *dummy) 6351da177e4SLinus Torvalds { 6361da177e4SLinus Torvalds cmcv_reg_t cmcv; 6371da177e4SLinus Torvalds 6381da177e4SLinus Torvalds cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV); 6391da177e4SLinus Torvalds 6401da177e4SLinus Torvalds cmcv.cmcv_mask = 1; /* Mask/disable interrupt */ 6411da177e4SLinus Torvalds ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval); 6421da177e4SLinus Torvalds 6431da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: CPU %d corrected " 6441da177e4SLinus Torvalds "machine check vector %#x disabled.\n", 6451da177e4SLinus Torvalds __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector); 6461da177e4SLinus Torvalds } 6471da177e4SLinus Torvalds 6481da177e4SLinus Torvalds /* 6491da177e4SLinus Torvalds * ia64_mca_cmc_vector_enable 6501da177e4SLinus Torvalds * 6511da177e4SLinus Torvalds * Unmask the corrected machine check vector register in the processor. 6521da177e4SLinus Torvalds * This function is invoked on a per-processor basis. 6531da177e4SLinus Torvalds * 6541da177e4SLinus Torvalds * Inputs 6551da177e4SLinus Torvalds * dummy(unused) 6561da177e4SLinus Torvalds * 6571da177e4SLinus Torvalds * Outputs 6581da177e4SLinus Torvalds * None 6591da177e4SLinus Torvalds */ 6601da177e4SLinus Torvalds static void 6611da177e4SLinus Torvalds ia64_mca_cmc_vector_enable (void *dummy) 6621da177e4SLinus Torvalds { 6631da177e4SLinus Torvalds cmcv_reg_t cmcv; 6641da177e4SLinus Torvalds 6651da177e4SLinus Torvalds cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV); 6661da177e4SLinus Torvalds 6671da177e4SLinus Torvalds cmcv.cmcv_mask = 0; /* Unmask/enable interrupt */ 6681da177e4SLinus Torvalds ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval); 6691da177e4SLinus Torvalds 6701da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: CPU %d corrected " 6711da177e4SLinus Torvalds "machine check vector %#x enabled.\n", 6721da177e4SLinus Torvalds __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector); 6731da177e4SLinus Torvalds } 6741da177e4SLinus Torvalds 6751da177e4SLinus Torvalds /* 6761da177e4SLinus Torvalds * ia64_mca_cmc_vector_disable_keventd 6771da177e4SLinus Torvalds * 6781da177e4SLinus Torvalds * Called via keventd (smp_call_function() is not safe in interrupt context) to 6791da177e4SLinus Torvalds * disable the cmc interrupt vector. 6801da177e4SLinus Torvalds */ 6811da177e4SLinus Torvalds static void 6826d5aefb8SDavid Howells ia64_mca_cmc_vector_disable_keventd(struct work_struct *unused) 6831da177e4SLinus Torvalds { 6841da177e4SLinus Torvalds on_each_cpu(ia64_mca_cmc_vector_disable, NULL, 1, 0); 6851da177e4SLinus Torvalds } 6861da177e4SLinus Torvalds 6871da177e4SLinus Torvalds /* 6881da177e4SLinus Torvalds * ia64_mca_cmc_vector_enable_keventd 6891da177e4SLinus Torvalds * 6901da177e4SLinus Torvalds * Called via keventd (smp_call_function() is not safe in interrupt context) to 6911da177e4SLinus Torvalds * enable the cmc interrupt vector. 6921da177e4SLinus Torvalds */ 6931da177e4SLinus Torvalds static void 6946d5aefb8SDavid Howells ia64_mca_cmc_vector_enable_keventd(struct work_struct *unused) 6951da177e4SLinus Torvalds { 6961da177e4SLinus Torvalds on_each_cpu(ia64_mca_cmc_vector_enable, NULL, 1, 0); 6971da177e4SLinus Torvalds } 6981da177e4SLinus Torvalds 6991da177e4SLinus Torvalds /* 7001da177e4SLinus Torvalds * ia64_mca_wakeup 7011da177e4SLinus Torvalds * 7021da177e4SLinus Torvalds * Send an inter-cpu interrupt to wake-up a particular cpu 7031da177e4SLinus Torvalds * and mark that cpu to be out of rendez. 7041da177e4SLinus Torvalds * 7051da177e4SLinus Torvalds * Inputs : cpuid 7061da177e4SLinus Torvalds * Outputs : None 7071da177e4SLinus Torvalds */ 7081da177e4SLinus Torvalds static void 7091da177e4SLinus Torvalds ia64_mca_wakeup(int cpu) 7101da177e4SLinus Torvalds { 7111da177e4SLinus Torvalds platform_send_ipi(cpu, IA64_MCA_WAKEUP_VECTOR, IA64_IPI_DM_INT, 0); 7121da177e4SLinus Torvalds ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE; 7131da177e4SLinus Torvalds 7141da177e4SLinus Torvalds } 7151da177e4SLinus Torvalds 7161da177e4SLinus Torvalds /* 7171da177e4SLinus Torvalds * ia64_mca_wakeup_all 7181da177e4SLinus Torvalds * 7191da177e4SLinus Torvalds * Wakeup all the cpus which have rendez'ed previously. 7201da177e4SLinus Torvalds * 7211da177e4SLinus Torvalds * Inputs : None 7221da177e4SLinus Torvalds * Outputs : None 7231da177e4SLinus Torvalds */ 7241da177e4SLinus Torvalds static void 7251da177e4SLinus Torvalds ia64_mca_wakeup_all(void) 7261da177e4SLinus Torvalds { 7271da177e4SLinus Torvalds int cpu; 7281da177e4SLinus Torvalds 7291da177e4SLinus Torvalds /* Clear the Rendez checkin flag for all cpus */ 730ddf6d0a0Shawkes@sgi.com for_each_online_cpu(cpu) { 7311da177e4SLinus Torvalds if (ia64_mc_info.imi_rendez_checkin[cpu] == IA64_MCA_RENDEZ_CHECKIN_DONE) 7321da177e4SLinus Torvalds ia64_mca_wakeup(cpu); 7331da177e4SLinus Torvalds } 7341da177e4SLinus Torvalds 7351da177e4SLinus Torvalds } 7361da177e4SLinus Torvalds 7371da177e4SLinus Torvalds /* 7381da177e4SLinus Torvalds * ia64_mca_rendez_interrupt_handler 7391da177e4SLinus Torvalds * 7401da177e4SLinus Torvalds * This is handler used to put slave processors into spinloop 7411da177e4SLinus Torvalds * while the monarch processor does the mca handling and later 7421da177e4SLinus Torvalds * wake each slave up once the monarch is done. 7431da177e4SLinus Torvalds * 7441da177e4SLinus Torvalds * Inputs : None 7451da177e4SLinus Torvalds * Outputs : None 7461da177e4SLinus Torvalds */ 7471da177e4SLinus Torvalds static irqreturn_t 7487d12e780SDavid Howells ia64_mca_rendez_int_handler(int rendez_irq, void *arg) 7491da177e4SLinus Torvalds { 7501da177e4SLinus Torvalds unsigned long flags; 7511da177e4SLinus Torvalds int cpu = smp_processor_id(); 752958b166cSKeith Owens struct ia64_mca_notify_die nd = 753958b166cSKeith Owens { .sos = NULL, .monarch_cpu = &monarch_cpu }; 7541da177e4SLinus Torvalds 7551da177e4SLinus Torvalds /* Mask all interrupts */ 7561da177e4SLinus Torvalds local_irq_save(flags); 7577d12e780SDavid Howells if (notify_die(DIE_MCA_RENDZVOUS_ENTER, "MCA", get_irq_regs(), 7587d12e780SDavid Howells (long)&nd, 0, 0) == NOTIFY_STOP) 7599138d581SKeith Owens ia64_mca_spin(__FUNCTION__); 7601da177e4SLinus Torvalds 7611da177e4SLinus Torvalds ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_DONE; 7621da177e4SLinus Torvalds /* Register with the SAL monarch that the slave has 7631da177e4SLinus Torvalds * reached SAL 7641da177e4SLinus Torvalds */ 7651da177e4SLinus Torvalds ia64_sal_mc_rendez(); 7661da177e4SLinus Torvalds 7677d12e780SDavid Howells if (notify_die(DIE_MCA_RENDZVOUS_PROCESS, "MCA", get_irq_regs(), 7687d12e780SDavid Howells (long)&nd, 0, 0) == NOTIFY_STOP) 7699138d581SKeith Owens ia64_mca_spin(__FUNCTION__); 7709138d581SKeith Owens 7717f613c7dSKeith Owens /* Wait for the monarch cpu to exit. */ 7727f613c7dSKeith Owens while (monarch_cpu != -1) 7737f613c7dSKeith Owens cpu_relax(); /* spin until monarch leaves */ 7741da177e4SLinus Torvalds 7757d12e780SDavid Howells if (notify_die(DIE_MCA_RENDZVOUS_LEAVE, "MCA", get_irq_regs(), 7767d12e780SDavid Howells (long)&nd, 0, 0) == NOTIFY_STOP) 7779138d581SKeith Owens ia64_mca_spin(__FUNCTION__); 7789138d581SKeith Owens 7791da177e4SLinus Torvalds /* Enable all interrupts */ 7801da177e4SLinus Torvalds local_irq_restore(flags); 7811da177e4SLinus Torvalds return IRQ_HANDLED; 7821da177e4SLinus Torvalds } 7831da177e4SLinus Torvalds 7841da177e4SLinus Torvalds /* 7851da177e4SLinus Torvalds * ia64_mca_wakeup_int_handler 7861da177e4SLinus Torvalds * 7871da177e4SLinus Torvalds * The interrupt handler for processing the inter-cpu interrupt to the 7881da177e4SLinus Torvalds * slave cpu which was spinning in the rendez loop. 7891da177e4SLinus Torvalds * Since this spinning is done by turning off the interrupts and 7901da177e4SLinus Torvalds * polling on the wakeup-interrupt bit in the IRR, there is 7911da177e4SLinus Torvalds * nothing useful to be done in the handler. 7921da177e4SLinus Torvalds * 7931da177e4SLinus Torvalds * Inputs : wakeup_irq (Wakeup-interrupt bit) 7941da177e4SLinus Torvalds * arg (Interrupt handler specific argument) 7951da177e4SLinus Torvalds * Outputs : None 7961da177e4SLinus Torvalds * 7971da177e4SLinus Torvalds */ 7981da177e4SLinus Torvalds static irqreturn_t 7997d12e780SDavid Howells ia64_mca_wakeup_int_handler(int wakeup_irq, void *arg) 8001da177e4SLinus Torvalds { 8011da177e4SLinus Torvalds return IRQ_HANDLED; 8021da177e4SLinus Torvalds } 8031da177e4SLinus Torvalds 8041da177e4SLinus Torvalds /* Function pointer for extra MCA recovery */ 8051da177e4SLinus Torvalds int (*ia64_mca_ucmc_extension) 8067f613c7dSKeith Owens (void*,struct ia64_sal_os_state*) 8071da177e4SLinus Torvalds = NULL; 8081da177e4SLinus Torvalds 8091da177e4SLinus Torvalds int 8107f613c7dSKeith Owens ia64_reg_MCA_extension(int (*fn)(void *, struct ia64_sal_os_state *)) 8111da177e4SLinus Torvalds { 8121da177e4SLinus Torvalds if (ia64_mca_ucmc_extension) 8131da177e4SLinus Torvalds return 1; 8141da177e4SLinus Torvalds 8151da177e4SLinus Torvalds ia64_mca_ucmc_extension = fn; 8161da177e4SLinus Torvalds return 0; 8171da177e4SLinus Torvalds } 8181da177e4SLinus Torvalds 8191da177e4SLinus Torvalds void 8201da177e4SLinus Torvalds ia64_unreg_MCA_extension(void) 8211da177e4SLinus Torvalds { 8221da177e4SLinus Torvalds if (ia64_mca_ucmc_extension) 8231da177e4SLinus Torvalds ia64_mca_ucmc_extension = NULL; 8241da177e4SLinus Torvalds } 8251da177e4SLinus Torvalds 8261da177e4SLinus Torvalds EXPORT_SYMBOL(ia64_reg_MCA_extension); 8271da177e4SLinus Torvalds EXPORT_SYMBOL(ia64_unreg_MCA_extension); 8281da177e4SLinus Torvalds 8297f613c7dSKeith Owens 8307f613c7dSKeith Owens static inline void 8317f613c7dSKeith Owens copy_reg(const u64 *fr, u64 fnat, u64 *tr, u64 *tnat) 8327f613c7dSKeith Owens { 8337f613c7dSKeith Owens u64 fslot, tslot, nat; 8347f613c7dSKeith Owens *tr = *fr; 8357f613c7dSKeith Owens fslot = ((unsigned long)fr >> 3) & 63; 8367f613c7dSKeith Owens tslot = ((unsigned long)tr >> 3) & 63; 8377f613c7dSKeith Owens *tnat &= ~(1UL << tslot); 8387f613c7dSKeith Owens nat = (fnat >> fslot) & 1; 8397f613c7dSKeith Owens *tnat |= (nat << tslot); 8407f613c7dSKeith Owens } 8417f613c7dSKeith Owens 842e9ac054dSKeith Owens /* Change the comm field on the MCA/INT task to include the pid that 843e9ac054dSKeith Owens * was interrupted, it makes for easier debugging. If that pid was 0 844e9ac054dSKeith Owens * (swapper or nested MCA/INIT) then use the start of the previous comm 845e9ac054dSKeith Owens * field suffixed with its cpu. 846e9ac054dSKeith Owens */ 847e9ac054dSKeith Owens 848e9ac054dSKeith Owens static void 84936c8b586SIngo Molnar ia64_mca_modify_comm(const struct task_struct *previous_current) 850e9ac054dSKeith Owens { 851e9ac054dSKeith Owens char *p, comm[sizeof(current->comm)]; 852e9ac054dSKeith Owens if (previous_current->pid) 853e9ac054dSKeith Owens snprintf(comm, sizeof(comm), "%s %d", 854e9ac054dSKeith Owens current->comm, previous_current->pid); 855e9ac054dSKeith Owens else { 856e9ac054dSKeith Owens int l; 857e9ac054dSKeith Owens if ((p = strchr(previous_current->comm, ' '))) 858e9ac054dSKeith Owens l = p - previous_current->comm; 859e9ac054dSKeith Owens else 860e9ac054dSKeith Owens l = strlen(previous_current->comm); 861e9ac054dSKeith Owens snprintf(comm, sizeof(comm), "%s %*s %d", 862e9ac054dSKeith Owens current->comm, l, previous_current->comm, 863e9ac054dSKeith Owens task_thread_info(previous_current)->cpu); 864e9ac054dSKeith Owens } 865e9ac054dSKeith Owens memcpy(current->comm, comm, sizeof(current->comm)); 866e9ac054dSKeith Owens } 867e9ac054dSKeith Owens 8687f613c7dSKeith Owens /* On entry to this routine, we are running on the per cpu stack, see 8697f613c7dSKeith Owens * mca_asm.h. The original stack has not been touched by this event. Some of 8707f613c7dSKeith Owens * the original stack's registers will be in the RBS on this stack. This stack 8717f613c7dSKeith Owens * also contains a partial pt_regs and switch_stack, the rest of the data is in 8727f613c7dSKeith Owens * PAL minstate. 8737f613c7dSKeith Owens * 8747f613c7dSKeith Owens * The first thing to do is modify the original stack to look like a blocked 8757f613c7dSKeith Owens * task so we can run backtrace on the original task. Also mark the per cpu 8767f613c7dSKeith Owens * stack as current to ensure that we use the correct task state, it also means 8777f613c7dSKeith Owens * that we can do backtrace on the MCA/INIT handler code itself. 8787f613c7dSKeith Owens */ 8797f613c7dSKeith Owens 88036c8b586SIngo Molnar static struct task_struct * 8817f613c7dSKeith Owens ia64_mca_modify_original_stack(struct pt_regs *regs, 8827f613c7dSKeith Owens const struct switch_stack *sw, 8837f613c7dSKeith Owens struct ia64_sal_os_state *sos, 8847f613c7dSKeith Owens const char *type) 8857f613c7dSKeith Owens { 886e9ac054dSKeith Owens char *p; 8877f613c7dSKeith Owens ia64_va va; 8887f613c7dSKeith Owens extern char ia64_leave_kernel[]; /* Need asm address, not function descriptor */ 8897f613c7dSKeith Owens const pal_min_state_area_t *ms = sos->pal_min_state; 89036c8b586SIngo Molnar struct task_struct *previous_current; 8917f613c7dSKeith Owens struct pt_regs *old_regs; 8927f613c7dSKeith Owens struct switch_stack *old_sw; 8937f613c7dSKeith Owens unsigned size = sizeof(struct pt_regs) + 8947f613c7dSKeith Owens sizeof(struct switch_stack) + 16; 8957f613c7dSKeith Owens u64 *old_bspstore, *old_bsp; 8967f613c7dSKeith Owens u64 *new_bspstore, *new_bsp; 8977f613c7dSKeith Owens u64 old_unat, old_rnat, new_rnat, nat; 8987f613c7dSKeith Owens u64 slots, loadrs = regs->loadrs; 8997f613c7dSKeith Owens u64 r12 = ms->pmsa_gr[12-1], r13 = ms->pmsa_gr[13-1]; 9007f613c7dSKeith Owens u64 ar_bspstore = regs->ar_bspstore; 9017f613c7dSKeith Owens u64 ar_bsp = regs->ar_bspstore + (loadrs >> 16); 9027f613c7dSKeith Owens const u64 *bank; 9037f613c7dSKeith Owens const char *msg; 9047f613c7dSKeith Owens int cpu = smp_processor_id(); 9057f613c7dSKeith Owens 9067f613c7dSKeith Owens previous_current = curr_task(cpu); 9077f613c7dSKeith Owens set_curr_task(cpu, current); 9087f613c7dSKeith Owens if ((p = strchr(current->comm, ' '))) 9097f613c7dSKeith Owens *p = '\0'; 9107f613c7dSKeith Owens 9117f613c7dSKeith Owens /* Best effort attempt to cope with MCA/INIT delivered while in 9127f613c7dSKeith Owens * physical mode. 9137f613c7dSKeith Owens */ 9147f613c7dSKeith Owens regs->cr_ipsr = ms->pmsa_ipsr; 9157f613c7dSKeith Owens if (ia64_psr(regs)->dt == 0) { 9167f613c7dSKeith Owens va.l = r12; 9177f613c7dSKeith Owens if (va.f.reg == 0) { 9187f613c7dSKeith Owens va.f.reg = 7; 9197f613c7dSKeith Owens r12 = va.l; 9207f613c7dSKeith Owens } 9217f613c7dSKeith Owens va.l = r13; 9227f613c7dSKeith Owens if (va.f.reg == 0) { 9237f613c7dSKeith Owens va.f.reg = 7; 9247f613c7dSKeith Owens r13 = va.l; 9257f613c7dSKeith Owens } 9267f613c7dSKeith Owens } 9277f613c7dSKeith Owens if (ia64_psr(regs)->rt == 0) { 9287f613c7dSKeith Owens va.l = ar_bspstore; 9297f613c7dSKeith Owens if (va.f.reg == 0) { 9307f613c7dSKeith Owens va.f.reg = 7; 9317f613c7dSKeith Owens ar_bspstore = va.l; 9327f613c7dSKeith Owens } 9337f613c7dSKeith Owens va.l = ar_bsp; 9347f613c7dSKeith Owens if (va.f.reg == 0) { 9357f613c7dSKeith Owens va.f.reg = 7; 9367f613c7dSKeith Owens ar_bsp = va.l; 9377f613c7dSKeith Owens } 9387f613c7dSKeith Owens } 9397f613c7dSKeith Owens 9407f613c7dSKeith Owens /* mca_asm.S ia64_old_stack() cannot assume that the dirty registers 9417f613c7dSKeith Owens * have been copied to the old stack, the old stack may fail the 9427f613c7dSKeith Owens * validation tests below. So ia64_old_stack() must restore the dirty 9437f613c7dSKeith Owens * registers from the new stack. The old and new bspstore probably 9447f613c7dSKeith Owens * have different alignments, so loadrs calculated on the old bsp 9457f613c7dSKeith Owens * cannot be used to restore from the new bsp. Calculate a suitable 9467f613c7dSKeith Owens * loadrs for the new stack and save it in the new pt_regs, where 9477f613c7dSKeith Owens * ia64_old_stack() can get it. 9487f613c7dSKeith Owens */ 9497f613c7dSKeith Owens old_bspstore = (u64 *)ar_bspstore; 9507f613c7dSKeith Owens old_bsp = (u64 *)ar_bsp; 9517f613c7dSKeith Owens slots = ia64_rse_num_regs(old_bspstore, old_bsp); 9527f613c7dSKeith Owens new_bspstore = (u64 *)((u64)current + IA64_RBS_OFFSET); 9537f613c7dSKeith Owens new_bsp = ia64_rse_skip_regs(new_bspstore, slots); 9547f613c7dSKeith Owens regs->loadrs = (new_bsp - new_bspstore) * 8 << 16; 9557f613c7dSKeith Owens 9567f613c7dSKeith Owens /* Verify the previous stack state before we change it */ 9577f613c7dSKeith Owens if (user_mode(regs)) { 9587f613c7dSKeith Owens msg = "occurred in user space"; 959e9ac054dSKeith Owens /* previous_current is guaranteed to be valid when the task was 960e9ac054dSKeith Owens * in user space, so ... 961e9ac054dSKeith Owens */ 962e9ac054dSKeith Owens ia64_mca_modify_comm(previous_current); 9637f613c7dSKeith Owens goto no_mod; 9647f613c7dSKeith Owens } 965d2a28ad9SRuss Anderson 966d2a28ad9SRuss Anderson if (!mca_recover_range(ms->pmsa_iip)) { 9677f613c7dSKeith Owens if (r13 != sos->prev_IA64_KR_CURRENT) { 9687f613c7dSKeith Owens msg = "inconsistent previous current and r13"; 9697f613c7dSKeith Owens goto no_mod; 9707f613c7dSKeith Owens } 9717f613c7dSKeith Owens if ((r12 - r13) >= KERNEL_STACK_SIZE) { 9727f613c7dSKeith Owens msg = "inconsistent r12 and r13"; 9737f613c7dSKeith Owens goto no_mod; 9747f613c7dSKeith Owens } 9757f613c7dSKeith Owens if ((ar_bspstore - r13) >= KERNEL_STACK_SIZE) { 9767f613c7dSKeith Owens msg = "inconsistent ar.bspstore and r13"; 9777f613c7dSKeith Owens goto no_mod; 9787f613c7dSKeith Owens } 9797f613c7dSKeith Owens va.p = old_bspstore; 9807f613c7dSKeith Owens if (va.f.reg < 5) { 9817f613c7dSKeith Owens msg = "old_bspstore is in the wrong region"; 9827f613c7dSKeith Owens goto no_mod; 9837f613c7dSKeith Owens } 9847f613c7dSKeith Owens if ((ar_bsp - r13) >= KERNEL_STACK_SIZE) { 9857f613c7dSKeith Owens msg = "inconsistent ar.bsp and r13"; 9867f613c7dSKeith Owens goto no_mod; 9877f613c7dSKeith Owens } 9887f613c7dSKeith Owens size += (ia64_rse_skip_regs(old_bspstore, slots) - old_bspstore) * 8; 9897f613c7dSKeith Owens if (ar_bspstore + size > r12) { 9907f613c7dSKeith Owens msg = "no room for blocked state"; 9917f613c7dSKeith Owens goto no_mod; 9927f613c7dSKeith Owens } 993d2a28ad9SRuss Anderson } 9947f613c7dSKeith Owens 995e9ac054dSKeith Owens ia64_mca_modify_comm(previous_current); 9967f613c7dSKeith Owens 9977f613c7dSKeith Owens /* Make the original task look blocked. First stack a struct pt_regs, 9987f613c7dSKeith Owens * describing the state at the time of interrupt. mca_asm.S built a 9997f613c7dSKeith Owens * partial pt_regs, copy it and fill in the blanks using minstate. 10007f613c7dSKeith Owens */ 10017f613c7dSKeith Owens p = (char *)r12 - sizeof(*regs); 10027f613c7dSKeith Owens old_regs = (struct pt_regs *)p; 10037f613c7dSKeith Owens memcpy(old_regs, regs, sizeof(*regs)); 10047f613c7dSKeith Owens /* If ipsr.ic then use pmsa_{iip,ipsr,ifs}, else use 10057f613c7dSKeith Owens * pmsa_{xip,xpsr,xfs} 10067f613c7dSKeith Owens */ 10077f613c7dSKeith Owens if (ia64_psr(regs)->ic) { 10087f613c7dSKeith Owens old_regs->cr_iip = ms->pmsa_iip; 10097f613c7dSKeith Owens old_regs->cr_ipsr = ms->pmsa_ipsr; 10107f613c7dSKeith Owens old_regs->cr_ifs = ms->pmsa_ifs; 10117f613c7dSKeith Owens } else { 10127f613c7dSKeith Owens old_regs->cr_iip = ms->pmsa_xip; 10137f613c7dSKeith Owens old_regs->cr_ipsr = ms->pmsa_xpsr; 10147f613c7dSKeith Owens old_regs->cr_ifs = ms->pmsa_xfs; 10157f613c7dSKeith Owens } 10167f613c7dSKeith Owens old_regs->pr = ms->pmsa_pr; 10177f613c7dSKeith Owens old_regs->b0 = ms->pmsa_br0; 10187f613c7dSKeith Owens old_regs->loadrs = loadrs; 10197f613c7dSKeith Owens old_regs->ar_rsc = ms->pmsa_rsc; 10207f613c7dSKeith Owens old_unat = old_regs->ar_unat; 10217f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[1-1], ms->pmsa_nat_bits, &old_regs->r1, &old_unat); 10227f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[2-1], ms->pmsa_nat_bits, &old_regs->r2, &old_unat); 10237f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[3-1], ms->pmsa_nat_bits, &old_regs->r3, &old_unat); 10247f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[8-1], ms->pmsa_nat_bits, &old_regs->r8, &old_unat); 10257f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[9-1], ms->pmsa_nat_bits, &old_regs->r9, &old_unat); 10267f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[10-1], ms->pmsa_nat_bits, &old_regs->r10, &old_unat); 10277f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[11-1], ms->pmsa_nat_bits, &old_regs->r11, &old_unat); 10287f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[12-1], ms->pmsa_nat_bits, &old_regs->r12, &old_unat); 10297f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[13-1], ms->pmsa_nat_bits, &old_regs->r13, &old_unat); 10307f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[14-1], ms->pmsa_nat_bits, &old_regs->r14, &old_unat); 10317f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[15-1], ms->pmsa_nat_bits, &old_regs->r15, &old_unat); 10327f613c7dSKeith Owens if (ia64_psr(old_regs)->bn) 10337f613c7dSKeith Owens bank = ms->pmsa_bank1_gr; 10347f613c7dSKeith Owens else 10357f613c7dSKeith Owens bank = ms->pmsa_bank0_gr; 10367f613c7dSKeith Owens copy_reg(&bank[16-16], ms->pmsa_nat_bits, &old_regs->r16, &old_unat); 10377f613c7dSKeith Owens copy_reg(&bank[17-16], ms->pmsa_nat_bits, &old_regs->r17, &old_unat); 10387f613c7dSKeith Owens copy_reg(&bank[18-16], ms->pmsa_nat_bits, &old_regs->r18, &old_unat); 10397f613c7dSKeith Owens copy_reg(&bank[19-16], ms->pmsa_nat_bits, &old_regs->r19, &old_unat); 10407f613c7dSKeith Owens copy_reg(&bank[20-16], ms->pmsa_nat_bits, &old_regs->r20, &old_unat); 10417f613c7dSKeith Owens copy_reg(&bank[21-16], ms->pmsa_nat_bits, &old_regs->r21, &old_unat); 10427f613c7dSKeith Owens copy_reg(&bank[22-16], ms->pmsa_nat_bits, &old_regs->r22, &old_unat); 10437f613c7dSKeith Owens copy_reg(&bank[23-16], ms->pmsa_nat_bits, &old_regs->r23, &old_unat); 10447f613c7dSKeith Owens copy_reg(&bank[24-16], ms->pmsa_nat_bits, &old_regs->r24, &old_unat); 10457f613c7dSKeith Owens copy_reg(&bank[25-16], ms->pmsa_nat_bits, &old_regs->r25, &old_unat); 10467f613c7dSKeith Owens copy_reg(&bank[26-16], ms->pmsa_nat_bits, &old_regs->r26, &old_unat); 10477f613c7dSKeith Owens copy_reg(&bank[27-16], ms->pmsa_nat_bits, &old_regs->r27, &old_unat); 10487f613c7dSKeith Owens copy_reg(&bank[28-16], ms->pmsa_nat_bits, &old_regs->r28, &old_unat); 10497f613c7dSKeith Owens copy_reg(&bank[29-16], ms->pmsa_nat_bits, &old_regs->r29, &old_unat); 10507f613c7dSKeith Owens copy_reg(&bank[30-16], ms->pmsa_nat_bits, &old_regs->r30, &old_unat); 10517f613c7dSKeith Owens copy_reg(&bank[31-16], ms->pmsa_nat_bits, &old_regs->r31, &old_unat); 10527f613c7dSKeith Owens 10537f613c7dSKeith Owens /* Next stack a struct switch_stack. mca_asm.S built a partial 10547f613c7dSKeith Owens * switch_stack, copy it and fill in the blanks using pt_regs and 10557f613c7dSKeith Owens * minstate. 10567f613c7dSKeith Owens * 10577f613c7dSKeith Owens * In the synthesized switch_stack, b0 points to ia64_leave_kernel, 10587f613c7dSKeith Owens * ar.pfs is set to 0. 10597f613c7dSKeith Owens * 10607f613c7dSKeith Owens * unwind.c::unw_unwind() does special processing for interrupt frames. 10617f613c7dSKeith Owens * It checks if the PRED_NON_SYSCALL predicate is set, if the predicate 10627f613c7dSKeith Owens * is clear then unw_unwind() does _not_ adjust bsp over pt_regs. Not 10637f613c7dSKeith Owens * that this is documented, of course. Set PRED_NON_SYSCALL in the 10647f613c7dSKeith Owens * switch_stack on the original stack so it will unwind correctly when 10657f613c7dSKeith Owens * unwind.c reads pt_regs. 10667f613c7dSKeith Owens * 10677f613c7dSKeith Owens * thread.ksp is updated to point to the synthesized switch_stack. 10687f613c7dSKeith Owens */ 10697f613c7dSKeith Owens p -= sizeof(struct switch_stack); 10707f613c7dSKeith Owens old_sw = (struct switch_stack *)p; 10717f613c7dSKeith Owens memcpy(old_sw, sw, sizeof(*sw)); 10727f613c7dSKeith Owens old_sw->caller_unat = old_unat; 10737f613c7dSKeith Owens old_sw->ar_fpsr = old_regs->ar_fpsr; 10747f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[4-1], ms->pmsa_nat_bits, &old_sw->r4, &old_unat); 10757f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[5-1], ms->pmsa_nat_bits, &old_sw->r5, &old_unat); 10767f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[6-1], ms->pmsa_nat_bits, &old_sw->r6, &old_unat); 10777f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[7-1], ms->pmsa_nat_bits, &old_sw->r7, &old_unat); 10787f613c7dSKeith Owens old_sw->b0 = (u64)ia64_leave_kernel; 10797f613c7dSKeith Owens old_sw->b1 = ms->pmsa_br1; 10807f613c7dSKeith Owens old_sw->ar_pfs = 0; 10817f613c7dSKeith Owens old_sw->ar_unat = old_unat; 10827f613c7dSKeith Owens old_sw->pr = old_regs->pr | (1UL << PRED_NON_SYSCALL); 10837f613c7dSKeith Owens previous_current->thread.ksp = (u64)p - 16; 10847f613c7dSKeith Owens 10857f613c7dSKeith Owens /* Finally copy the original stack's registers back to its RBS. 10867f613c7dSKeith Owens * Registers from ar.bspstore through ar.bsp at the time of the event 10877f613c7dSKeith Owens * are in the current RBS, copy them back to the original stack. The 10887f613c7dSKeith Owens * copy must be done register by register because the original bspstore 10897f613c7dSKeith Owens * and the current one have different alignments, so the saved RNAT 10907f613c7dSKeith Owens * data occurs at different places. 10917f613c7dSKeith Owens * 10927f613c7dSKeith Owens * mca_asm does cover, so the old_bsp already includes all registers at 10937f613c7dSKeith Owens * the time of MCA/INIT. It also does flushrs, so all registers before 10947f613c7dSKeith Owens * this function have been written to backing store on the MCA/INIT 10957f613c7dSKeith Owens * stack. 10967f613c7dSKeith Owens */ 10977f613c7dSKeith Owens new_rnat = ia64_get_rnat(ia64_rse_rnat_addr(new_bspstore)); 10987f613c7dSKeith Owens old_rnat = regs->ar_rnat; 10997f613c7dSKeith Owens while (slots--) { 11007f613c7dSKeith Owens if (ia64_rse_is_rnat_slot(new_bspstore)) { 11017f613c7dSKeith Owens new_rnat = ia64_get_rnat(new_bspstore++); 11027f613c7dSKeith Owens } 11037f613c7dSKeith Owens if (ia64_rse_is_rnat_slot(old_bspstore)) { 11047f613c7dSKeith Owens *old_bspstore++ = old_rnat; 11057f613c7dSKeith Owens old_rnat = 0; 11067f613c7dSKeith Owens } 11077f613c7dSKeith Owens nat = (new_rnat >> ia64_rse_slot_num(new_bspstore)) & 1UL; 11087f613c7dSKeith Owens old_rnat &= ~(1UL << ia64_rse_slot_num(old_bspstore)); 11097f613c7dSKeith Owens old_rnat |= (nat << ia64_rse_slot_num(old_bspstore)); 11107f613c7dSKeith Owens *old_bspstore++ = *new_bspstore++; 11117f613c7dSKeith Owens } 11127f613c7dSKeith Owens old_sw->ar_bspstore = (unsigned long)old_bspstore; 11137f613c7dSKeith Owens old_sw->ar_rnat = old_rnat; 11147f613c7dSKeith Owens 11157f613c7dSKeith Owens sos->prev_task = previous_current; 11167f613c7dSKeith Owens return previous_current; 11177f613c7dSKeith Owens 11187f613c7dSKeith Owens no_mod: 11197f613c7dSKeith Owens printk(KERN_INFO "cpu %d, %s %s, original stack not modified\n", 11207f613c7dSKeith Owens smp_processor_id(), type, msg); 11217f613c7dSKeith Owens return previous_current; 11227f613c7dSKeith Owens } 11237f613c7dSKeith Owens 11247f613c7dSKeith Owens /* The monarch/slave interaction is based on monarch_cpu and requires that all 11257f613c7dSKeith Owens * slaves have entered rendezvous before the monarch leaves. If any cpu has 11267f613c7dSKeith Owens * not entered rendezvous yet then wait a bit. The assumption is that any 11277f613c7dSKeith Owens * slave that has not rendezvoused after a reasonable time is never going to do 11287f613c7dSKeith Owens * so. In this context, slave includes cpus that respond to the MCA rendezvous 11297f613c7dSKeith Owens * interrupt, as well as cpus that receive the INIT slave event. 11307f613c7dSKeith Owens */ 11317f613c7dSKeith Owens 11327f613c7dSKeith Owens static void 1133356a5c1cSKeith Owens ia64_wait_for_slaves(int monarch, const char *type) 11347f613c7dSKeith Owens { 11359336b083SKeith Owens int c, wait = 0, missing = 0; 11367f613c7dSKeith Owens for_each_online_cpu(c) { 11377f613c7dSKeith Owens if (c == monarch) 11387f613c7dSKeith Owens continue; 11397f613c7dSKeith Owens if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) { 11407f613c7dSKeith Owens udelay(1000); /* short wait first */ 11417f613c7dSKeith Owens wait = 1; 11427f613c7dSKeith Owens break; 11437f613c7dSKeith Owens } 11447f613c7dSKeith Owens } 11457f613c7dSKeith Owens if (!wait) 11469336b083SKeith Owens goto all_in; 11477f613c7dSKeith Owens for_each_online_cpu(c) { 11487f613c7dSKeith Owens if (c == monarch) 11497f613c7dSKeith Owens continue; 11507f613c7dSKeith Owens if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) { 11517f613c7dSKeith Owens udelay(5*1000000); /* wait 5 seconds for slaves (arbitrary) */ 11529336b083SKeith Owens if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) 11539336b083SKeith Owens missing = 1; 11547f613c7dSKeith Owens break; 11557f613c7dSKeith Owens } 11567f613c7dSKeith Owens } 11579336b083SKeith Owens if (!missing) 11589336b083SKeith Owens goto all_in; 115943ed3bafSHidetoshi Seto /* 116043ed3bafSHidetoshi Seto * Maybe slave(s) dead. Print buffered messages immediately. 116143ed3bafSHidetoshi Seto */ 116243ed3bafSHidetoshi Seto ia64_mlogbuf_finish(0); 116343ed3bafSHidetoshi Seto mprintk(KERN_INFO "OS %s slave did not rendezvous on cpu", type); 11649336b083SKeith Owens for_each_online_cpu(c) { 11659336b083SKeith Owens if (c == monarch) 11669336b083SKeith Owens continue; 11679336b083SKeith Owens if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) 116843ed3bafSHidetoshi Seto mprintk(" %d", c); 11699336b083SKeith Owens } 117043ed3bafSHidetoshi Seto mprintk("\n"); 11719336b083SKeith Owens return; 11729336b083SKeith Owens 11739336b083SKeith Owens all_in: 117443ed3bafSHidetoshi Seto mprintk(KERN_INFO "All OS %s slaves have reached rendezvous\n", type); 11759336b083SKeith Owens return; 11767f613c7dSKeith Owens } 11777f613c7dSKeith Owens 11781da177e4SLinus Torvalds /* 11797f613c7dSKeith Owens * ia64_mca_handler 11801da177e4SLinus Torvalds * 11811da177e4SLinus Torvalds * This is uncorrectable machine check handler called from OS_MCA 11821da177e4SLinus Torvalds * dispatch code which is in turn called from SAL_CHECK(). 11831da177e4SLinus Torvalds * This is the place where the core of OS MCA handling is done. 11841da177e4SLinus Torvalds * Right now the logs are extracted and displayed in a well-defined 11851da177e4SLinus Torvalds * format. This handler code is supposed to be run only on the 11861da177e4SLinus Torvalds * monarch processor. Once the monarch is done with MCA handling 11871da177e4SLinus Torvalds * further MCA logging is enabled by clearing logs. 11881da177e4SLinus Torvalds * Monarch also has the duty of sending wakeup-IPIs to pull the 11891da177e4SLinus Torvalds * slave processors out of rendezvous spinloop. 11901da177e4SLinus Torvalds */ 11911da177e4SLinus Torvalds void 11927f613c7dSKeith Owens ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw, 11937f613c7dSKeith Owens struct ia64_sal_os_state *sos) 11941da177e4SLinus Torvalds { 11951da177e4SLinus Torvalds pal_processor_state_info_t *psp = (pal_processor_state_info_t *) 11967f613c7dSKeith Owens &sos->proc_state_param; 11977f613c7dSKeith Owens int recover, cpu = smp_processor_id(); 119836c8b586SIngo Molnar struct task_struct *previous_current; 1199958b166cSKeith Owens struct ia64_mca_notify_die nd = 1200958b166cSKeith Owens { .sos = sos, .monarch_cpu = &monarch_cpu }; 12017f613c7dSKeith Owens 120243ed3bafSHidetoshi Seto mprintk(KERN_INFO "Entered OS MCA handler. PSP=%lx cpu=%d " 120343ed3bafSHidetoshi Seto "monarch=%ld\n", sos->proc_state_param, cpu, sos->monarch); 12049336b083SKeith Owens 12057f613c7dSKeith Owens previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "MCA"); 12067f613c7dSKeith Owens monarch_cpu = cpu; 1207958b166cSKeith Owens if (notify_die(DIE_MCA_MONARCH_ENTER, "MCA", regs, (long)&nd, 0, 0) 12089138d581SKeith Owens == NOTIFY_STOP) 12099138d581SKeith Owens ia64_mca_spin(__FUNCTION__); 1210356a5c1cSKeith Owens ia64_wait_for_slaves(cpu, "MCA"); 12117f613c7dSKeith Owens 12127f613c7dSKeith Owens /* Wakeup all the processors which are spinning in the rendezvous loop. 12137f613c7dSKeith Owens * They will leave SAL, then spin in the OS with interrupts disabled 12147f613c7dSKeith Owens * until this monarch cpu leaves the MCA handler. That gets control 12157f613c7dSKeith Owens * back to the OS so we can backtrace the other cpus, backtrace when 12167f613c7dSKeith Owens * spinning in SAL does not work. 12177f613c7dSKeith Owens */ 12187f613c7dSKeith Owens ia64_mca_wakeup_all(); 1219958b166cSKeith Owens if (notify_die(DIE_MCA_MONARCH_PROCESS, "MCA", regs, (long)&nd, 0, 0) 12209138d581SKeith Owens == NOTIFY_STOP) 12219138d581SKeith Owens ia64_mca_spin(__FUNCTION__); 12221da177e4SLinus Torvalds 12231da177e4SLinus Torvalds /* Get the MCA error record and log it */ 12241da177e4SLinus Torvalds ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA); 12251da177e4SLinus Torvalds 12261da177e4SLinus Torvalds /* TLB error is only exist in this SAL error record */ 12271da177e4SLinus Torvalds recover = (psp->tc && !(psp->cc || psp->bc || psp->rc || psp->uc)) 12281da177e4SLinus Torvalds /* other error recovery */ 12291da177e4SLinus Torvalds || (ia64_mca_ucmc_extension 12301da177e4SLinus Torvalds && ia64_mca_ucmc_extension( 12311da177e4SLinus Torvalds IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA), 12327f613c7dSKeith Owens sos)); 12331da177e4SLinus Torvalds 12341da177e4SLinus Torvalds if (recover) { 12351da177e4SLinus Torvalds sal_log_record_header_t *rh = IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA); 12361da177e4SLinus Torvalds rh->severity = sal_log_severity_corrected; 12371da177e4SLinus Torvalds ia64_sal_clear_state_info(SAL_INFO_TYPE_MCA); 12387f613c7dSKeith Owens sos->os_status = IA64_MCA_CORRECTED; 123943ed3bafSHidetoshi Seto } else { 124043ed3bafSHidetoshi Seto /* Dump buffered message to console */ 124143ed3bafSHidetoshi Seto ia64_mlogbuf_finish(1); 1242*a7956113SZou Nan hai #ifdef CONFIG_CRASH_DUMP 1243*a7956113SZou Nan hai atomic_set(&kdump_in_progress, 1); 1244*a7956113SZou Nan hai monarch_cpu = -1; 1245*a7956113SZou Nan hai #endif 12461da177e4SLinus Torvalds } 1247958b166cSKeith Owens if (notify_die(DIE_MCA_MONARCH_LEAVE, "MCA", regs, (long)&nd, 0, recover) 12489138d581SKeith Owens == NOTIFY_STOP) 12499138d581SKeith Owens ia64_mca_spin(__FUNCTION__); 12501da177e4SLinus Torvalds 12517f613c7dSKeith Owens set_curr_task(cpu, previous_current); 12527f613c7dSKeith Owens monarch_cpu = -1; 12531da177e4SLinus Torvalds } 12541da177e4SLinus Torvalds 12556d5aefb8SDavid Howells static DECLARE_WORK(cmc_disable_work, ia64_mca_cmc_vector_disable_keventd); 12566d5aefb8SDavid Howells static DECLARE_WORK(cmc_enable_work, ia64_mca_cmc_vector_enable_keventd); 12571da177e4SLinus Torvalds 12581da177e4SLinus Torvalds /* 12591da177e4SLinus Torvalds * ia64_mca_cmc_int_handler 12601da177e4SLinus Torvalds * 12611da177e4SLinus Torvalds * This is corrected machine check interrupt handler. 12621da177e4SLinus Torvalds * Right now the logs are extracted and displayed in a well-defined 12631da177e4SLinus Torvalds * format. 12641da177e4SLinus Torvalds * 12651da177e4SLinus Torvalds * Inputs 12661da177e4SLinus Torvalds * interrupt number 12671da177e4SLinus Torvalds * client data arg ptr 12681da177e4SLinus Torvalds * 12691da177e4SLinus Torvalds * Outputs 12701da177e4SLinus Torvalds * None 12711da177e4SLinus Torvalds */ 12721da177e4SLinus Torvalds static irqreturn_t 12737d12e780SDavid Howells ia64_mca_cmc_int_handler(int cmc_irq, void *arg) 12741da177e4SLinus Torvalds { 12751da177e4SLinus Torvalds static unsigned long cmc_history[CMC_HISTORY_LENGTH]; 12761da177e4SLinus Torvalds static int index; 12771da177e4SLinus Torvalds static DEFINE_SPINLOCK(cmc_history_lock); 12781da177e4SLinus Torvalds 12791da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n", 12801da177e4SLinus Torvalds __FUNCTION__, cmc_irq, smp_processor_id()); 12811da177e4SLinus Torvalds 12821da177e4SLinus Torvalds /* SAL spec states this should run w/ interrupts enabled */ 12831da177e4SLinus Torvalds local_irq_enable(); 12841da177e4SLinus Torvalds 12851da177e4SLinus Torvalds spin_lock(&cmc_history_lock); 12861da177e4SLinus Torvalds if (!cmc_polling_enabled) { 12871da177e4SLinus Torvalds int i, count = 1; /* we know 1 happened now */ 12881da177e4SLinus Torvalds unsigned long now = jiffies; 12891da177e4SLinus Torvalds 12901da177e4SLinus Torvalds for (i = 0; i < CMC_HISTORY_LENGTH; i++) { 12911da177e4SLinus Torvalds if (now - cmc_history[i] <= HZ) 12921da177e4SLinus Torvalds count++; 12931da177e4SLinus Torvalds } 12941da177e4SLinus Torvalds 12951da177e4SLinus Torvalds IA64_MCA_DEBUG(KERN_INFO "CMC threshold %d/%d\n", count, CMC_HISTORY_LENGTH); 12961da177e4SLinus Torvalds if (count >= CMC_HISTORY_LENGTH) { 12971da177e4SLinus Torvalds 12981da177e4SLinus Torvalds cmc_polling_enabled = 1; 12991da177e4SLinus Torvalds spin_unlock(&cmc_history_lock); 130076e677e2SBryan Sutula /* If we're being hit with CMC interrupts, we won't 130176e677e2SBryan Sutula * ever execute the schedule_work() below. Need to 130276e677e2SBryan Sutula * disable CMC interrupts on this processor now. 130376e677e2SBryan Sutula */ 130476e677e2SBryan Sutula ia64_mca_cmc_vector_disable(NULL); 13051da177e4SLinus Torvalds schedule_work(&cmc_disable_work); 13061da177e4SLinus Torvalds 13071da177e4SLinus Torvalds /* 13081da177e4SLinus Torvalds * Corrected errors will still be corrected, but 13091da177e4SLinus Torvalds * make sure there's a log somewhere that indicates 13101da177e4SLinus Torvalds * something is generating more than we can handle. 13111da177e4SLinus Torvalds */ 13121da177e4SLinus Torvalds printk(KERN_WARNING "WARNING: Switching to polling CMC handler; error records may be lost\n"); 13131da177e4SLinus Torvalds 13141da177e4SLinus Torvalds mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL); 13151da177e4SLinus Torvalds 13161da177e4SLinus Torvalds /* lock already released, get out now */ 1317ddb4f0dfSHidetoshi Seto goto out; 13181da177e4SLinus Torvalds } else { 13191da177e4SLinus Torvalds cmc_history[index++] = now; 13201da177e4SLinus Torvalds if (index == CMC_HISTORY_LENGTH) 13211da177e4SLinus Torvalds index = 0; 13221da177e4SLinus Torvalds } 13231da177e4SLinus Torvalds } 13241da177e4SLinus Torvalds spin_unlock(&cmc_history_lock); 1325ddb4f0dfSHidetoshi Seto out: 1326ddb4f0dfSHidetoshi Seto /* Get the CMC error record and log it */ 1327ddb4f0dfSHidetoshi Seto ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC); 1328ddb4f0dfSHidetoshi Seto 13291da177e4SLinus Torvalds return IRQ_HANDLED; 13301da177e4SLinus Torvalds } 13311da177e4SLinus Torvalds 13321da177e4SLinus Torvalds /* 13331da177e4SLinus Torvalds * ia64_mca_cmc_int_caller 13341da177e4SLinus Torvalds * 13351da177e4SLinus Torvalds * Triggered by sw interrupt from CMC polling routine. Calls 13361da177e4SLinus Torvalds * real interrupt handler and either triggers a sw interrupt 13371da177e4SLinus Torvalds * on the next cpu or does cleanup at the end. 13381da177e4SLinus Torvalds * 13391da177e4SLinus Torvalds * Inputs 13401da177e4SLinus Torvalds * interrupt number 13411da177e4SLinus Torvalds * client data arg ptr 13421da177e4SLinus Torvalds * Outputs 13431da177e4SLinus Torvalds * handled 13441da177e4SLinus Torvalds */ 13451da177e4SLinus Torvalds static irqreturn_t 13467d12e780SDavid Howells ia64_mca_cmc_int_caller(int cmc_irq, void *arg) 13471da177e4SLinus Torvalds { 13481da177e4SLinus Torvalds static int start_count = -1; 13491da177e4SLinus Torvalds unsigned int cpuid; 13501da177e4SLinus Torvalds 13511da177e4SLinus Torvalds cpuid = smp_processor_id(); 13521da177e4SLinus Torvalds 13531da177e4SLinus Torvalds /* If first cpu, update count */ 13541da177e4SLinus Torvalds if (start_count == -1) 13551da177e4SLinus Torvalds start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CMC); 13561da177e4SLinus Torvalds 13577d12e780SDavid Howells ia64_mca_cmc_int_handler(cmc_irq, arg); 13581da177e4SLinus Torvalds 13591da177e4SLinus Torvalds for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++); 13601da177e4SLinus Torvalds 13611da177e4SLinus Torvalds if (cpuid < NR_CPUS) { 13621da177e4SLinus Torvalds platform_send_ipi(cpuid, IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0); 13631da177e4SLinus Torvalds } else { 13641da177e4SLinus Torvalds /* If no log record, switch out of polling mode */ 13651da177e4SLinus Torvalds if (start_count == IA64_LOG_COUNT(SAL_INFO_TYPE_CMC)) { 13661da177e4SLinus Torvalds 13671da177e4SLinus Torvalds printk(KERN_WARNING "Returning to interrupt driven CMC handler\n"); 13681da177e4SLinus Torvalds schedule_work(&cmc_enable_work); 13691da177e4SLinus Torvalds cmc_polling_enabled = 0; 13701da177e4SLinus Torvalds 13711da177e4SLinus Torvalds } else { 13721da177e4SLinus Torvalds 13731da177e4SLinus Torvalds mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL); 13741da177e4SLinus Torvalds } 13751da177e4SLinus Torvalds 13761da177e4SLinus Torvalds start_count = -1; 13771da177e4SLinus Torvalds } 13781da177e4SLinus Torvalds 13791da177e4SLinus Torvalds return IRQ_HANDLED; 13801da177e4SLinus Torvalds } 13811da177e4SLinus Torvalds 13821da177e4SLinus Torvalds /* 13831da177e4SLinus Torvalds * ia64_mca_cmc_poll 13841da177e4SLinus Torvalds * 13851da177e4SLinus Torvalds * Poll for Corrected Machine Checks (CMCs) 13861da177e4SLinus Torvalds * 13871da177e4SLinus Torvalds * Inputs : dummy(unused) 13881da177e4SLinus Torvalds * Outputs : None 13891da177e4SLinus Torvalds * 13901da177e4SLinus Torvalds */ 13911da177e4SLinus Torvalds static void 13921da177e4SLinus Torvalds ia64_mca_cmc_poll (unsigned long dummy) 13931da177e4SLinus Torvalds { 13941da177e4SLinus Torvalds /* Trigger a CMC interrupt cascade */ 13951da177e4SLinus Torvalds platform_send_ipi(first_cpu(cpu_online_map), IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0); 13961da177e4SLinus Torvalds } 13971da177e4SLinus Torvalds 13981da177e4SLinus Torvalds /* 13991da177e4SLinus Torvalds * ia64_mca_cpe_int_caller 14001da177e4SLinus Torvalds * 14011da177e4SLinus Torvalds * Triggered by sw interrupt from CPE polling routine. Calls 14021da177e4SLinus Torvalds * real interrupt handler and either triggers a sw interrupt 14031da177e4SLinus Torvalds * on the next cpu or does cleanup at the end. 14041da177e4SLinus Torvalds * 14051da177e4SLinus Torvalds * Inputs 14061da177e4SLinus Torvalds * interrupt number 14071da177e4SLinus Torvalds * client data arg ptr 14081da177e4SLinus Torvalds * Outputs 14091da177e4SLinus Torvalds * handled 14101da177e4SLinus Torvalds */ 14111da177e4SLinus Torvalds #ifdef CONFIG_ACPI 14121da177e4SLinus Torvalds 14131da177e4SLinus Torvalds static irqreturn_t 14147d12e780SDavid Howells ia64_mca_cpe_int_caller(int cpe_irq, void *arg) 14151da177e4SLinus Torvalds { 14161da177e4SLinus Torvalds static int start_count = -1; 14171da177e4SLinus Torvalds static int poll_time = MIN_CPE_POLL_INTERVAL; 14181da177e4SLinus Torvalds unsigned int cpuid; 14191da177e4SLinus Torvalds 14201da177e4SLinus Torvalds cpuid = smp_processor_id(); 14211da177e4SLinus Torvalds 14221da177e4SLinus Torvalds /* If first cpu, update count */ 14231da177e4SLinus Torvalds if (start_count == -1) 14241da177e4SLinus Torvalds start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CPE); 14251da177e4SLinus Torvalds 14267d12e780SDavid Howells ia64_mca_cpe_int_handler(cpe_irq, arg); 14271da177e4SLinus Torvalds 14281da177e4SLinus Torvalds for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++); 14291da177e4SLinus Torvalds 14301da177e4SLinus Torvalds if (cpuid < NR_CPUS) { 14311da177e4SLinus Torvalds platform_send_ipi(cpuid, IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0); 14321da177e4SLinus Torvalds } else { 14331da177e4SLinus Torvalds /* 14341da177e4SLinus Torvalds * If a log was recorded, increase our polling frequency, 14351da177e4SLinus Torvalds * otherwise, backoff or return to interrupt mode. 14361da177e4SLinus Torvalds */ 14371da177e4SLinus Torvalds if (start_count != IA64_LOG_COUNT(SAL_INFO_TYPE_CPE)) { 14381da177e4SLinus Torvalds poll_time = max(MIN_CPE_POLL_INTERVAL, poll_time / 2); 14391da177e4SLinus Torvalds } else if (cpe_vector < 0) { 14401da177e4SLinus Torvalds poll_time = min(MAX_CPE_POLL_INTERVAL, poll_time * 2); 14411da177e4SLinus Torvalds } else { 14421da177e4SLinus Torvalds poll_time = MIN_CPE_POLL_INTERVAL; 14431da177e4SLinus Torvalds 14441da177e4SLinus Torvalds printk(KERN_WARNING "Returning to interrupt driven CPE handler\n"); 14451da177e4SLinus Torvalds enable_irq(local_vector_to_irq(IA64_CPE_VECTOR)); 14461da177e4SLinus Torvalds cpe_poll_enabled = 0; 14471da177e4SLinus Torvalds } 14481da177e4SLinus Torvalds 14491da177e4SLinus Torvalds if (cpe_poll_enabled) 14501da177e4SLinus Torvalds mod_timer(&cpe_poll_timer, jiffies + poll_time); 14511da177e4SLinus Torvalds start_count = -1; 14521da177e4SLinus Torvalds } 14531da177e4SLinus Torvalds 14541da177e4SLinus Torvalds return IRQ_HANDLED; 14551da177e4SLinus Torvalds } 14561da177e4SLinus Torvalds 14571da177e4SLinus Torvalds /* 14581da177e4SLinus Torvalds * ia64_mca_cpe_poll 14591da177e4SLinus Torvalds * 14601da177e4SLinus Torvalds * Poll for Corrected Platform Errors (CPEs), trigger interrupt 14611da177e4SLinus Torvalds * on first cpu, from there it will trickle through all the cpus. 14621da177e4SLinus Torvalds * 14631da177e4SLinus Torvalds * Inputs : dummy(unused) 14641da177e4SLinus Torvalds * Outputs : None 14651da177e4SLinus Torvalds * 14661da177e4SLinus Torvalds */ 14671da177e4SLinus Torvalds static void 14681da177e4SLinus Torvalds ia64_mca_cpe_poll (unsigned long dummy) 14691da177e4SLinus Torvalds { 14701da177e4SLinus Torvalds /* Trigger a CPE interrupt cascade */ 14711da177e4SLinus Torvalds platform_send_ipi(first_cpu(cpu_online_map), IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0); 14721da177e4SLinus Torvalds } 14731da177e4SLinus Torvalds 1474b655913bSPeter Chubb #endif /* CONFIG_ACPI */ 1475b655913bSPeter Chubb 14769138d581SKeith Owens static int 14779138d581SKeith Owens default_monarch_init_process(struct notifier_block *self, unsigned long val, void *data) 14789138d581SKeith Owens { 14799138d581SKeith Owens int c; 14809138d581SKeith Owens struct task_struct *g, *t; 14819138d581SKeith Owens if (val != DIE_INIT_MONARCH_PROCESS) 14829138d581SKeith Owens return NOTIFY_DONE; 148343ed3bafSHidetoshi Seto 148443ed3bafSHidetoshi Seto /* 148543ed3bafSHidetoshi Seto * FIXME: mlogbuf will brim over with INIT stack dumps. 148643ed3bafSHidetoshi Seto * To enable show_stack from INIT, we use oops_in_progress which should 148743ed3bafSHidetoshi Seto * be used in real oops. This would cause something wrong after INIT. 148843ed3bafSHidetoshi Seto */ 148943ed3bafSHidetoshi Seto BREAK_LOGLEVEL(console_loglevel); 149043ed3bafSHidetoshi Seto ia64_mlogbuf_dump_from_init(); 149143ed3bafSHidetoshi Seto 14929138d581SKeith Owens printk(KERN_ERR "Processes interrupted by INIT -"); 14939138d581SKeith Owens for_each_online_cpu(c) { 14949138d581SKeith Owens struct ia64_sal_os_state *s; 14959138d581SKeith Owens t = __va(__per_cpu_mca[c] + IA64_MCA_CPU_INIT_STACK_OFFSET); 14969138d581SKeith Owens s = (struct ia64_sal_os_state *)((char *)t + MCA_SOS_OFFSET); 14979138d581SKeith Owens g = s->prev_task; 14989138d581SKeith Owens if (g) { 14999138d581SKeith Owens if (g->pid) 15009138d581SKeith Owens printk(" %d", g->pid); 15019138d581SKeith Owens else 15029138d581SKeith Owens printk(" %d (cpu %d task 0x%p)", g->pid, task_cpu(g), g); 15039138d581SKeith Owens } 15049138d581SKeith Owens } 15059138d581SKeith Owens printk("\n\n"); 15069138d581SKeith Owens if (read_trylock(&tasklist_lock)) { 15079138d581SKeith Owens do_each_thread (g, t) { 15089138d581SKeith Owens printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm); 15099138d581SKeith Owens show_stack(t, NULL); 15109138d581SKeith Owens } while_each_thread (g, t); 15119138d581SKeith Owens read_unlock(&tasklist_lock); 15129138d581SKeith Owens } 151343ed3bafSHidetoshi Seto /* FIXME: This will not restore zapped printk locks. */ 151443ed3bafSHidetoshi Seto RESTORE_LOGLEVEL(console_loglevel); 15159138d581SKeith Owens return NOTIFY_DONE; 15169138d581SKeith Owens } 15179138d581SKeith Owens 15181da177e4SLinus Torvalds /* 15191da177e4SLinus Torvalds * C portion of the OS INIT handler 15201da177e4SLinus Torvalds * 15217f613c7dSKeith Owens * Called from ia64_os_init_dispatch 15221da177e4SLinus Torvalds * 15237f613c7dSKeith Owens * Inputs: pointer to pt_regs where processor info was saved. SAL/OS state for 15247f613c7dSKeith Owens * this event. This code is used for both monarch and slave INIT events, see 15257f613c7dSKeith Owens * sos->monarch. 15261da177e4SLinus Torvalds * 15277f613c7dSKeith Owens * All INIT events switch to the INIT stack and change the previous process to 15287f613c7dSKeith Owens * blocked status. If one of the INIT events is the monarch then we are 15297f613c7dSKeith Owens * probably processing the nmi button/command. Use the monarch cpu to dump all 15307f613c7dSKeith Owens * the processes. The slave INIT events all spin until the monarch cpu 15317f613c7dSKeith Owens * returns. We can also get INIT slave events for MCA, in which case the MCA 15327f613c7dSKeith Owens * process is the monarch. 15331da177e4SLinus Torvalds */ 15341da177e4SLinus Torvalds 15357f613c7dSKeith Owens void 15367f613c7dSKeith Owens ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw, 15377f613c7dSKeith Owens struct ia64_sal_os_state *sos) 15387f613c7dSKeith Owens { 15397f613c7dSKeith Owens static atomic_t slaves; 15407f613c7dSKeith Owens static atomic_t monarchs; 154136c8b586SIngo Molnar struct task_struct *previous_current; 15429138d581SKeith Owens int cpu = smp_processor_id(); 1543958b166cSKeith Owens struct ia64_mca_notify_die nd = 1544958b166cSKeith Owens { .sos = sos, .monarch_cpu = &monarch_cpu }; 15457f613c7dSKeith Owens 1546958b166cSKeith Owens (void) notify_die(DIE_INIT_ENTER, "INIT", regs, (long)&nd, 0, 0); 1547958b166cSKeith Owens 154843ed3bafSHidetoshi Seto mprintk(KERN_INFO "Entered OS INIT handler. PSP=%lx cpu=%d monarch=%ld\n", 15497f613c7dSKeith Owens sos->proc_state_param, cpu, sos->monarch); 15507f613c7dSKeith Owens salinfo_log_wakeup(SAL_INFO_TYPE_INIT, NULL, 0, 0); 15517f613c7dSKeith Owens 15527f613c7dSKeith Owens previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "INIT"); 15537f613c7dSKeith Owens sos->os_status = IA64_INIT_RESUME; 15547f613c7dSKeith Owens 15557f613c7dSKeith Owens /* FIXME: Workaround for broken proms that drive all INIT events as 15567f613c7dSKeith Owens * slaves. The last slave that enters is promoted to be a monarch. 15577f613c7dSKeith Owens * Remove this code in September 2006, that gives platforms a year to 15587f613c7dSKeith Owens * fix their proms and get their customers updated. 15597f613c7dSKeith Owens */ 15607f613c7dSKeith Owens if (!sos->monarch && atomic_add_return(1, &slaves) == num_online_cpus()) { 156143ed3bafSHidetoshi Seto mprintk(KERN_WARNING "%s: Promoting cpu %d to monarch.\n", 15627f613c7dSKeith Owens __FUNCTION__, cpu); 15637f613c7dSKeith Owens atomic_dec(&slaves); 15647f613c7dSKeith Owens sos->monarch = 1; 15657f613c7dSKeith Owens } 15667f613c7dSKeith Owens 15677f613c7dSKeith Owens /* FIXME: Workaround for broken proms that drive all INIT events as 15687f613c7dSKeith Owens * monarchs. Second and subsequent monarchs are demoted to slaves. 15697f613c7dSKeith Owens * Remove this code in September 2006, that gives platforms a year to 15707f613c7dSKeith Owens * fix their proms and get their customers updated. 15717f613c7dSKeith Owens */ 15727f613c7dSKeith Owens if (sos->monarch && atomic_add_return(1, &monarchs) > 1) { 157343ed3bafSHidetoshi Seto mprintk(KERN_WARNING "%s: Demoting cpu %d to slave.\n", 15747f613c7dSKeith Owens __FUNCTION__, cpu); 15757f613c7dSKeith Owens atomic_dec(&monarchs); 15767f613c7dSKeith Owens sos->monarch = 0; 15777f613c7dSKeith Owens } 15787f613c7dSKeith Owens 15797f613c7dSKeith Owens if (!sos->monarch) { 15807f613c7dSKeith Owens ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_INIT; 15817f613c7dSKeith Owens while (monarch_cpu == -1) 15827f613c7dSKeith Owens cpu_relax(); /* spin until monarch enters */ 1583958b166cSKeith Owens if (notify_die(DIE_INIT_SLAVE_ENTER, "INIT", regs, (long)&nd, 0, 0) 15849138d581SKeith Owens == NOTIFY_STOP) 15859138d581SKeith Owens ia64_mca_spin(__FUNCTION__); 1586958b166cSKeith Owens if (notify_die(DIE_INIT_SLAVE_PROCESS, "INIT", regs, (long)&nd, 0, 0) 15879138d581SKeith Owens == NOTIFY_STOP) 15889138d581SKeith Owens ia64_mca_spin(__FUNCTION__); 15897f613c7dSKeith Owens while (monarch_cpu != -1) 15907f613c7dSKeith Owens cpu_relax(); /* spin until monarch leaves */ 1591958b166cSKeith Owens if (notify_die(DIE_INIT_SLAVE_LEAVE, "INIT", regs, (long)&nd, 0, 0) 15929138d581SKeith Owens == NOTIFY_STOP) 15939138d581SKeith Owens ia64_mca_spin(__FUNCTION__); 159443ed3bafSHidetoshi Seto mprintk("Slave on cpu %d returning to normal service.\n", cpu); 15957f613c7dSKeith Owens set_curr_task(cpu, previous_current); 15967f613c7dSKeith Owens ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE; 15977f613c7dSKeith Owens atomic_dec(&slaves); 15987f613c7dSKeith Owens return; 15997f613c7dSKeith Owens } 16007f613c7dSKeith Owens 16017f613c7dSKeith Owens monarch_cpu = cpu; 1602958b166cSKeith Owens if (notify_die(DIE_INIT_MONARCH_ENTER, "INIT", regs, (long)&nd, 0, 0) 16039138d581SKeith Owens == NOTIFY_STOP) 16049138d581SKeith Owens ia64_mca_spin(__FUNCTION__); 16051da177e4SLinus Torvalds 16061da177e4SLinus Torvalds /* 16077f613c7dSKeith Owens * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be 16087f613c7dSKeith Owens * generated via the BMC's command-line interface, but since the console is on the 16097f613c7dSKeith Owens * same serial line, the user will need some time to switch out of the BMC before 16107f613c7dSKeith Owens * the dump begins. 16111da177e4SLinus Torvalds */ 161243ed3bafSHidetoshi Seto mprintk("Delaying for 5 seconds...\n"); 16137f613c7dSKeith Owens udelay(5*1000000); 1614356a5c1cSKeith Owens ia64_wait_for_slaves(cpu, "INIT"); 16159138d581SKeith Owens /* If nobody intercepts DIE_INIT_MONARCH_PROCESS then we drop through 16169138d581SKeith Owens * to default_monarch_init_process() above and just print all the 16179138d581SKeith Owens * tasks. 16189138d581SKeith Owens */ 1619958b166cSKeith Owens if (notify_die(DIE_INIT_MONARCH_PROCESS, "INIT", regs, (long)&nd, 0, 0) 16209138d581SKeith Owens == NOTIFY_STOP) 16219138d581SKeith Owens ia64_mca_spin(__FUNCTION__); 1622958b166cSKeith Owens if (notify_die(DIE_INIT_MONARCH_LEAVE, "INIT", regs, (long)&nd, 0, 0) 16239138d581SKeith Owens == NOTIFY_STOP) 16249138d581SKeith Owens ia64_mca_spin(__FUNCTION__); 162543ed3bafSHidetoshi Seto mprintk("\nINIT dump complete. Monarch on cpu %d returning to normal service.\n", cpu); 16267f613c7dSKeith Owens atomic_dec(&monarchs); 16277f613c7dSKeith Owens set_curr_task(cpu, previous_current); 16287f613c7dSKeith Owens monarch_cpu = -1; 16297f613c7dSKeith Owens return; 16301da177e4SLinus Torvalds } 16311da177e4SLinus Torvalds 16321da177e4SLinus Torvalds static int __init 16331da177e4SLinus Torvalds ia64_mca_disable_cpe_polling(char *str) 16341da177e4SLinus Torvalds { 16351da177e4SLinus Torvalds cpe_poll_enabled = 0; 16361da177e4SLinus Torvalds return 1; 16371da177e4SLinus Torvalds } 16381da177e4SLinus Torvalds 16391da177e4SLinus Torvalds __setup("disable_cpe_poll", ia64_mca_disable_cpe_polling); 16401da177e4SLinus Torvalds 16411da177e4SLinus Torvalds static struct irqaction cmci_irqaction = { 16421da177e4SLinus Torvalds .handler = ia64_mca_cmc_int_handler, 1643121a4226SThomas Gleixner .flags = IRQF_DISABLED, 16441da177e4SLinus Torvalds .name = "cmc_hndlr" 16451da177e4SLinus Torvalds }; 16461da177e4SLinus Torvalds 16471da177e4SLinus Torvalds static struct irqaction cmcp_irqaction = { 16481da177e4SLinus Torvalds .handler = ia64_mca_cmc_int_caller, 1649121a4226SThomas Gleixner .flags = IRQF_DISABLED, 16501da177e4SLinus Torvalds .name = "cmc_poll" 16511da177e4SLinus Torvalds }; 16521da177e4SLinus Torvalds 16531da177e4SLinus Torvalds static struct irqaction mca_rdzv_irqaction = { 16541da177e4SLinus Torvalds .handler = ia64_mca_rendez_int_handler, 1655121a4226SThomas Gleixner .flags = IRQF_DISABLED, 16561da177e4SLinus Torvalds .name = "mca_rdzv" 16571da177e4SLinus Torvalds }; 16581da177e4SLinus Torvalds 16591da177e4SLinus Torvalds static struct irqaction mca_wkup_irqaction = { 16601da177e4SLinus Torvalds .handler = ia64_mca_wakeup_int_handler, 1661121a4226SThomas Gleixner .flags = IRQF_DISABLED, 16621da177e4SLinus Torvalds .name = "mca_wkup" 16631da177e4SLinus Torvalds }; 16641da177e4SLinus Torvalds 16651da177e4SLinus Torvalds #ifdef CONFIG_ACPI 16661da177e4SLinus Torvalds static struct irqaction mca_cpe_irqaction = { 16671da177e4SLinus Torvalds .handler = ia64_mca_cpe_int_handler, 1668121a4226SThomas Gleixner .flags = IRQF_DISABLED, 16691da177e4SLinus Torvalds .name = "cpe_hndlr" 16701da177e4SLinus Torvalds }; 16711da177e4SLinus Torvalds 16721da177e4SLinus Torvalds static struct irqaction mca_cpep_irqaction = { 16731da177e4SLinus Torvalds .handler = ia64_mca_cpe_int_caller, 1674121a4226SThomas Gleixner .flags = IRQF_DISABLED, 16751da177e4SLinus Torvalds .name = "cpe_poll" 16761da177e4SLinus Torvalds }; 16771da177e4SLinus Torvalds #endif /* CONFIG_ACPI */ 16781da177e4SLinus Torvalds 16797f613c7dSKeith Owens /* Minimal format of the MCA/INIT stacks. The pseudo processes that run on 16807f613c7dSKeith Owens * these stacks can never sleep, they cannot return from the kernel to user 16817f613c7dSKeith Owens * space, they do not appear in a normal ps listing. So there is no need to 16827f613c7dSKeith Owens * format most of the fields. 16837f613c7dSKeith Owens */ 16847f613c7dSKeith Owens 16850881fc8dSChen, Kenneth W static void __cpuinit 16867f613c7dSKeith Owens format_mca_init_stack(void *mca_data, unsigned long offset, 16877f613c7dSKeith Owens const char *type, int cpu) 16887f613c7dSKeith Owens { 16897f613c7dSKeith Owens struct task_struct *p = (struct task_struct *)((char *)mca_data + offset); 16907f613c7dSKeith Owens struct thread_info *ti; 16917f613c7dSKeith Owens memset(p, 0, KERNEL_STACK_SIZE); 1692ab03591dSAl Viro ti = task_thread_info(p); 16937f613c7dSKeith Owens ti->flags = _TIF_MCA_INIT; 16947f613c7dSKeith Owens ti->preempt_count = 1; 16957f613c7dSKeith Owens ti->task = p; 16967f613c7dSKeith Owens ti->cpu = cpu; 16977f613c7dSKeith Owens p->thread_info = ti; 16987f613c7dSKeith Owens p->state = TASK_UNINTERRUPTIBLE; 16994668f0cdSAkinobu Mita cpu_set(cpu, p->cpus_allowed); 17007f613c7dSKeith Owens INIT_LIST_HEAD(&p->tasks); 17017f613c7dSKeith Owens p->parent = p->real_parent = p->group_leader = p; 17027f613c7dSKeith Owens INIT_LIST_HEAD(&p->children); 17037f613c7dSKeith Owens INIT_LIST_HEAD(&p->sibling); 17047f613c7dSKeith Owens strncpy(p->comm, type, sizeof(p->comm)-1); 17057f613c7dSKeith Owens } 17067f613c7dSKeith Owens 17071da177e4SLinus Torvalds /* Do per-CPU MCA-related initialization. */ 17081da177e4SLinus Torvalds 17090881fc8dSChen, Kenneth W void __cpuinit 17101da177e4SLinus Torvalds ia64_mca_cpu_init(void *cpu_data) 17111da177e4SLinus Torvalds { 17121da177e4SLinus Torvalds void *pal_vaddr; 1713ff741906SAshok Raj static int first_time = 1; 17141da177e4SLinus Torvalds 1715ff741906SAshok Raj if (first_time) { 17161da177e4SLinus Torvalds void *mca_data; 17171da177e4SLinus Torvalds int cpu; 17181da177e4SLinus Torvalds 1719ff741906SAshok Raj first_time = 0; 17201da177e4SLinus Torvalds mca_data = alloc_bootmem(sizeof(struct ia64_mca_cpu) 17217f613c7dSKeith Owens * NR_CPUS + KERNEL_STACK_SIZE); 17227f613c7dSKeith Owens mca_data = (void *)(((unsigned long)mca_data + 17237f613c7dSKeith Owens KERNEL_STACK_SIZE - 1) & 17247f613c7dSKeith Owens (-KERNEL_STACK_SIZE)); 17251da177e4SLinus Torvalds for (cpu = 0; cpu < NR_CPUS; cpu++) { 17267f613c7dSKeith Owens format_mca_init_stack(mca_data, 17277f613c7dSKeith Owens offsetof(struct ia64_mca_cpu, mca_stack), 17287f613c7dSKeith Owens "MCA", cpu); 17297f613c7dSKeith Owens format_mca_init_stack(mca_data, 17307f613c7dSKeith Owens offsetof(struct ia64_mca_cpu, init_stack), 17317f613c7dSKeith Owens "INIT", cpu); 17321da177e4SLinus Torvalds __per_cpu_mca[cpu] = __pa(mca_data); 17331da177e4SLinus Torvalds mca_data += sizeof(struct ia64_mca_cpu); 17341da177e4SLinus Torvalds } 17351da177e4SLinus Torvalds } 17361da177e4SLinus Torvalds 17371da177e4SLinus Torvalds /* 17381da177e4SLinus Torvalds * The MCA info structure was allocated earlier and its 17391da177e4SLinus Torvalds * physical address saved in __per_cpu_mca[cpu]. Copy that 17401da177e4SLinus Torvalds * address * to ia64_mca_data so we can access it as a per-CPU 17411da177e4SLinus Torvalds * variable. 17421da177e4SLinus Torvalds */ 17431da177e4SLinus Torvalds __get_cpu_var(ia64_mca_data) = __per_cpu_mca[smp_processor_id()]; 17441da177e4SLinus Torvalds 17451da177e4SLinus Torvalds /* 17461da177e4SLinus Torvalds * Stash away a copy of the PTE needed to map the per-CPU page. 17471da177e4SLinus Torvalds * We may need it during MCA recovery. 17481da177e4SLinus Torvalds */ 17491da177e4SLinus Torvalds __get_cpu_var(ia64_mca_per_cpu_pte) = 17501da177e4SLinus Torvalds pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL)); 17511da177e4SLinus Torvalds 17521da177e4SLinus Torvalds /* 17531da177e4SLinus Torvalds * Also, stash away a copy of the PAL address and the PTE 17541da177e4SLinus Torvalds * needed to map it. 17551da177e4SLinus Torvalds */ 17561da177e4SLinus Torvalds pal_vaddr = efi_get_pal_addr(); 17571da177e4SLinus Torvalds if (!pal_vaddr) 17581da177e4SLinus Torvalds return; 17591da177e4SLinus Torvalds __get_cpu_var(ia64_mca_pal_base) = 17601da177e4SLinus Torvalds GRANULEROUNDDOWN((unsigned long) pal_vaddr); 17611da177e4SLinus Torvalds __get_cpu_var(ia64_mca_pal_pte) = pte_val(mk_pte_phys(__pa(pal_vaddr), 17621da177e4SLinus Torvalds PAGE_KERNEL)); 17631da177e4SLinus Torvalds } 17641da177e4SLinus Torvalds 17651da177e4SLinus Torvalds /* 17661da177e4SLinus Torvalds * ia64_mca_init 17671da177e4SLinus Torvalds * 17681da177e4SLinus Torvalds * Do all the system level mca specific initialization. 17691da177e4SLinus Torvalds * 17701da177e4SLinus Torvalds * 1. Register spinloop and wakeup request interrupt vectors 17711da177e4SLinus Torvalds * 17721da177e4SLinus Torvalds * 2. Register OS_MCA handler entry point 17731da177e4SLinus Torvalds * 17741da177e4SLinus Torvalds * 3. Register OS_INIT handler entry point 17751da177e4SLinus Torvalds * 17761da177e4SLinus Torvalds * 4. Initialize MCA/CMC/INIT related log buffers maintained by the OS. 17771da177e4SLinus Torvalds * 17781da177e4SLinus Torvalds * Note that this initialization is done very early before some kernel 17791da177e4SLinus Torvalds * services are available. 17801da177e4SLinus Torvalds * 17811da177e4SLinus Torvalds * Inputs : None 17821da177e4SLinus Torvalds * 17831da177e4SLinus Torvalds * Outputs : None 17841da177e4SLinus Torvalds */ 17851da177e4SLinus Torvalds void __init 17861da177e4SLinus Torvalds ia64_mca_init(void) 17871da177e4SLinus Torvalds { 17887f613c7dSKeith Owens ia64_fptr_t *init_hldlr_ptr_monarch = (ia64_fptr_t *)ia64_os_init_dispatch_monarch; 17897f613c7dSKeith Owens ia64_fptr_t *init_hldlr_ptr_slave = (ia64_fptr_t *)ia64_os_init_dispatch_slave; 17901da177e4SLinus Torvalds ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch; 17911da177e4SLinus Torvalds int i; 17921da177e4SLinus Torvalds s64 rc; 17931da177e4SLinus Torvalds struct ia64_sal_retval isrv; 17941da177e4SLinus Torvalds u64 timeout = IA64_MCA_RENDEZ_TIMEOUT; /* platform specific */ 17959138d581SKeith Owens static struct notifier_block default_init_monarch_nb = { 17969138d581SKeith Owens .notifier_call = default_monarch_init_process, 17979138d581SKeith Owens .priority = 0/* we need to notified last */ 17989138d581SKeith Owens }; 17991da177e4SLinus Torvalds 18001da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: begin\n", __FUNCTION__); 18011da177e4SLinus Torvalds 18021da177e4SLinus Torvalds /* Clear the Rendez checkin flag for all cpus */ 18031da177e4SLinus Torvalds for(i = 0 ; i < NR_CPUS; i++) 18041da177e4SLinus Torvalds ia64_mc_info.imi_rendez_checkin[i] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE; 18051da177e4SLinus Torvalds 18061da177e4SLinus Torvalds /* 18071da177e4SLinus Torvalds * Register the rendezvous spinloop and wakeup mechanism with SAL 18081da177e4SLinus Torvalds */ 18091da177e4SLinus Torvalds 18101da177e4SLinus Torvalds /* Register the rendezvous interrupt vector with SAL */ 18111da177e4SLinus Torvalds while (1) { 18121da177e4SLinus Torvalds isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_INT, 18131da177e4SLinus Torvalds SAL_MC_PARAM_MECHANISM_INT, 18141da177e4SLinus Torvalds IA64_MCA_RENDEZ_VECTOR, 18151da177e4SLinus Torvalds timeout, 18161da177e4SLinus Torvalds SAL_MC_PARAM_RZ_ALWAYS); 18171da177e4SLinus Torvalds rc = isrv.status; 18181da177e4SLinus Torvalds if (rc == 0) 18191da177e4SLinus Torvalds break; 18201da177e4SLinus Torvalds if (rc == -2) { 18211da177e4SLinus Torvalds printk(KERN_INFO "Increasing MCA rendezvous timeout from " 18221da177e4SLinus Torvalds "%ld to %ld milliseconds\n", timeout, isrv.v0); 18231da177e4SLinus Torvalds timeout = isrv.v0; 1824958b166cSKeith Owens (void) notify_die(DIE_MCA_NEW_TIMEOUT, "MCA", NULL, timeout, 0, 0); 18251da177e4SLinus Torvalds continue; 18261da177e4SLinus Torvalds } 18271da177e4SLinus Torvalds printk(KERN_ERR "Failed to register rendezvous interrupt " 18281da177e4SLinus Torvalds "with SAL (status %ld)\n", rc); 18291da177e4SLinus Torvalds return; 18301da177e4SLinus Torvalds } 18311da177e4SLinus Torvalds 18321da177e4SLinus Torvalds /* Register the wakeup interrupt vector with SAL */ 18331da177e4SLinus Torvalds isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_WAKEUP, 18341da177e4SLinus Torvalds SAL_MC_PARAM_MECHANISM_INT, 18351da177e4SLinus Torvalds IA64_MCA_WAKEUP_VECTOR, 18361da177e4SLinus Torvalds 0, 0); 18371da177e4SLinus Torvalds rc = isrv.status; 18381da177e4SLinus Torvalds if (rc) { 18391da177e4SLinus Torvalds printk(KERN_ERR "Failed to register wakeup interrupt with SAL " 18401da177e4SLinus Torvalds "(status %ld)\n", rc); 18411da177e4SLinus Torvalds return; 18421da177e4SLinus Torvalds } 18431da177e4SLinus Torvalds 18441da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: registered MCA rendezvous spinloop and wakeup mech.\n", __FUNCTION__); 18451da177e4SLinus Torvalds 18461da177e4SLinus Torvalds ia64_mc_info.imi_mca_handler = ia64_tpa(mca_hldlr_ptr->fp); 18471da177e4SLinus Torvalds /* 18481da177e4SLinus Torvalds * XXX - disable SAL checksum by setting size to 0; should be 18491da177e4SLinus Torvalds * ia64_tpa(ia64_os_mca_dispatch_end) - ia64_tpa(ia64_os_mca_dispatch); 18501da177e4SLinus Torvalds */ 18511da177e4SLinus Torvalds ia64_mc_info.imi_mca_handler_size = 0; 18521da177e4SLinus Torvalds 18531da177e4SLinus Torvalds /* Register the os mca handler with SAL */ 18541da177e4SLinus Torvalds if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_MCA, 18551da177e4SLinus Torvalds ia64_mc_info.imi_mca_handler, 18561da177e4SLinus Torvalds ia64_tpa(mca_hldlr_ptr->gp), 18571da177e4SLinus Torvalds ia64_mc_info.imi_mca_handler_size, 18581da177e4SLinus Torvalds 0, 0, 0))) 18591da177e4SLinus Torvalds { 18601da177e4SLinus Torvalds printk(KERN_ERR "Failed to register OS MCA handler with SAL " 18611da177e4SLinus Torvalds "(status %ld)\n", rc); 18621da177e4SLinus Torvalds return; 18631da177e4SLinus Torvalds } 18641da177e4SLinus Torvalds 18651da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: registered OS MCA handler with SAL at 0x%lx, gp = 0x%lx\n", __FUNCTION__, 18661da177e4SLinus Torvalds ia64_mc_info.imi_mca_handler, ia64_tpa(mca_hldlr_ptr->gp)); 18671da177e4SLinus Torvalds 18681da177e4SLinus Torvalds /* 18691da177e4SLinus Torvalds * XXX - disable SAL checksum by setting size to 0, should be 18701da177e4SLinus Torvalds * size of the actual init handler in mca_asm.S. 18711da177e4SLinus Torvalds */ 18727f613c7dSKeith Owens ia64_mc_info.imi_monarch_init_handler = ia64_tpa(init_hldlr_ptr_monarch->fp); 18731da177e4SLinus Torvalds ia64_mc_info.imi_monarch_init_handler_size = 0; 18747f613c7dSKeith Owens ia64_mc_info.imi_slave_init_handler = ia64_tpa(init_hldlr_ptr_slave->fp); 18751da177e4SLinus Torvalds ia64_mc_info.imi_slave_init_handler_size = 0; 18761da177e4SLinus Torvalds 18771da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __FUNCTION__, 18781da177e4SLinus Torvalds ia64_mc_info.imi_monarch_init_handler); 18791da177e4SLinus Torvalds 18801da177e4SLinus Torvalds /* Register the os init handler with SAL */ 18811da177e4SLinus Torvalds if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_INIT, 18821da177e4SLinus Torvalds ia64_mc_info.imi_monarch_init_handler, 18831da177e4SLinus Torvalds ia64_tpa(ia64_getreg(_IA64_REG_GP)), 18841da177e4SLinus Torvalds ia64_mc_info.imi_monarch_init_handler_size, 18851da177e4SLinus Torvalds ia64_mc_info.imi_slave_init_handler, 18861da177e4SLinus Torvalds ia64_tpa(ia64_getreg(_IA64_REG_GP)), 18871da177e4SLinus Torvalds ia64_mc_info.imi_slave_init_handler_size))) 18881da177e4SLinus Torvalds { 18891da177e4SLinus Torvalds printk(KERN_ERR "Failed to register m/s INIT handlers with SAL " 18901da177e4SLinus Torvalds "(status %ld)\n", rc); 18911da177e4SLinus Torvalds return; 18921da177e4SLinus Torvalds } 18939138d581SKeith Owens if (register_die_notifier(&default_init_monarch_nb)) { 18949138d581SKeith Owens printk(KERN_ERR "Failed to register default monarch INIT process\n"); 18959138d581SKeith Owens return; 18969138d581SKeith Owens } 18971da177e4SLinus Torvalds 18981da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: registered OS INIT handler with SAL\n", __FUNCTION__); 18991da177e4SLinus Torvalds 19001da177e4SLinus Torvalds /* 19011da177e4SLinus Torvalds * Configure the CMCI/P vector and handler. Interrupts for CMC are 19021da177e4SLinus Torvalds * per-processor, so AP CMC interrupts are setup in smp_callin() (smpboot.c). 19031da177e4SLinus Torvalds */ 19041da177e4SLinus Torvalds register_percpu_irq(IA64_CMC_VECTOR, &cmci_irqaction); 19051da177e4SLinus Torvalds register_percpu_irq(IA64_CMCP_VECTOR, &cmcp_irqaction); 19061da177e4SLinus Torvalds ia64_mca_cmc_vector_setup(); /* Setup vector on BSP */ 19071da177e4SLinus Torvalds 19081da177e4SLinus Torvalds /* Setup the MCA rendezvous interrupt vector */ 19091da177e4SLinus Torvalds register_percpu_irq(IA64_MCA_RENDEZ_VECTOR, &mca_rdzv_irqaction); 19101da177e4SLinus Torvalds 19111da177e4SLinus Torvalds /* Setup the MCA wakeup interrupt vector */ 19121da177e4SLinus Torvalds register_percpu_irq(IA64_MCA_WAKEUP_VECTOR, &mca_wkup_irqaction); 19131da177e4SLinus Torvalds 19141da177e4SLinus Torvalds #ifdef CONFIG_ACPI 1915bb68c12bSRuss Anderson /* Setup the CPEI/P handler */ 19161da177e4SLinus Torvalds register_percpu_irq(IA64_CPEP_VECTOR, &mca_cpep_irqaction); 19171da177e4SLinus Torvalds #endif 19181da177e4SLinus Torvalds 19191da177e4SLinus Torvalds /* Initialize the areas set aside by the OS to buffer the 19201da177e4SLinus Torvalds * platform/processor error states for MCA/INIT/CMC 19211da177e4SLinus Torvalds * handling. 19221da177e4SLinus Torvalds */ 19231da177e4SLinus Torvalds ia64_log_init(SAL_INFO_TYPE_MCA); 19241da177e4SLinus Torvalds ia64_log_init(SAL_INFO_TYPE_INIT); 19251da177e4SLinus Torvalds ia64_log_init(SAL_INFO_TYPE_CMC); 19261da177e4SLinus Torvalds ia64_log_init(SAL_INFO_TYPE_CPE); 19271da177e4SLinus Torvalds 19281da177e4SLinus Torvalds mca_init = 1; 19291da177e4SLinus Torvalds printk(KERN_INFO "MCA related initialization done\n"); 19301da177e4SLinus Torvalds } 19311da177e4SLinus Torvalds 19321da177e4SLinus Torvalds /* 19331da177e4SLinus Torvalds * ia64_mca_late_init 19341da177e4SLinus Torvalds * 19351da177e4SLinus Torvalds * Opportunity to setup things that require initialization later 19361da177e4SLinus Torvalds * than ia64_mca_init. Setup a timer to poll for CPEs if the 19371da177e4SLinus Torvalds * platform doesn't support an interrupt driven mechanism. 19381da177e4SLinus Torvalds * 19391da177e4SLinus Torvalds * Inputs : None 19401da177e4SLinus Torvalds * Outputs : Status 19411da177e4SLinus Torvalds */ 19421da177e4SLinus Torvalds static int __init 19431da177e4SLinus Torvalds ia64_mca_late_init(void) 19441da177e4SLinus Torvalds { 19451da177e4SLinus Torvalds if (!mca_init) 19461da177e4SLinus Torvalds return 0; 19471da177e4SLinus Torvalds 19481da177e4SLinus Torvalds /* Setup the CMCI/P vector and handler */ 19491da177e4SLinus Torvalds init_timer(&cmc_poll_timer); 19501da177e4SLinus Torvalds cmc_poll_timer.function = ia64_mca_cmc_poll; 19511da177e4SLinus Torvalds 19521da177e4SLinus Torvalds /* Unmask/enable the vector */ 19531da177e4SLinus Torvalds cmc_polling_enabled = 0; 19541da177e4SLinus Torvalds schedule_work(&cmc_enable_work); 19551da177e4SLinus Torvalds 19561da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: CMCI/P setup and enabled.\n", __FUNCTION__); 19571da177e4SLinus Torvalds 19581da177e4SLinus Torvalds #ifdef CONFIG_ACPI 19591da177e4SLinus Torvalds /* Setup the CPEI/P vector and handler */ 1960bb68c12bSRuss Anderson cpe_vector = acpi_request_vector(ACPI_INTERRUPT_CPEI); 19611da177e4SLinus Torvalds init_timer(&cpe_poll_timer); 19621da177e4SLinus Torvalds cpe_poll_timer.function = ia64_mca_cpe_poll; 19631da177e4SLinus Torvalds 19641da177e4SLinus Torvalds { 19651da177e4SLinus Torvalds irq_desc_t *desc; 19661da177e4SLinus Torvalds unsigned int irq; 19671da177e4SLinus Torvalds 19681da177e4SLinus Torvalds if (cpe_vector >= 0) { 19691da177e4SLinus Torvalds /* If platform supports CPEI, enable the irq. */ 19701da177e4SLinus Torvalds cpe_poll_enabled = 0; 19711da177e4SLinus Torvalds for (irq = 0; irq < NR_IRQS; ++irq) 19721da177e4SLinus Torvalds if (irq_to_vector(irq) == cpe_vector) { 1973a8553acdSIngo Molnar desc = irq_desc + irq; 19741da177e4SLinus Torvalds desc->status |= IRQ_PER_CPU; 19751da177e4SLinus Torvalds setup_irq(irq, &mca_cpe_irqaction); 1976ff741906SAshok Raj ia64_cpe_irq = irq; 19771da177e4SLinus Torvalds } 19781da177e4SLinus Torvalds ia64_mca_register_cpev(cpe_vector); 19791da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n", __FUNCTION__); 19801da177e4SLinus Torvalds } else { 19811da177e4SLinus Torvalds /* If platform doesn't support CPEI, get the timer going. */ 19821da177e4SLinus Torvalds if (cpe_poll_enabled) { 19831da177e4SLinus Torvalds ia64_mca_cpe_poll(0UL); 19841da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: CPEP setup and enabled.\n", __FUNCTION__); 19851da177e4SLinus Torvalds } 19861da177e4SLinus Torvalds } 19871da177e4SLinus Torvalds } 19881da177e4SLinus Torvalds #endif 19891da177e4SLinus Torvalds 19901da177e4SLinus Torvalds return 0; 19911da177e4SLinus Torvalds } 19921da177e4SLinus Torvalds 19931da177e4SLinus Torvalds device_initcall(ia64_mca_late_init); 1994