11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * File: mca.c 31da177e4SLinus Torvalds * Purpose: Generic MCA handling layer 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Copyright (C) 2003 Hewlett-Packard Co 61da177e4SLinus Torvalds * David Mosberger-Tang <davidm@hpl.hp.com> 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * Copyright (C) 2002 Dell Inc. 9fe77efb8SHidetoshi Seto * Copyright (C) Matt Domsch <Matt_Domsch@dell.com> 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds * Copyright (C) 2002 Intel 12fe77efb8SHidetoshi Seto * Copyright (C) Jenna Hall <jenna.s.hall@intel.com> 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds * Copyright (C) 2001 Intel 15fe77efb8SHidetoshi Seto * Copyright (C) Fred Lewis <frederick.v.lewis@intel.com> 161da177e4SLinus Torvalds * 171da177e4SLinus Torvalds * Copyright (C) 2000 Intel 18fe77efb8SHidetoshi Seto * Copyright (C) Chuck Fleckenstein <cfleck@co.intel.com> 191da177e4SLinus Torvalds * 20785285fcSRuss Anderson * Copyright (C) 1999, 2004-2008 Silicon Graphics, Inc. 21fe77efb8SHidetoshi Seto * Copyright (C) Vijay Chander <vijay@engr.sgi.com> 221da177e4SLinus Torvalds * 23fe77efb8SHidetoshi Seto * Copyright (C) 2006 FUJITSU LIMITED 24fe77efb8SHidetoshi Seto * Copyright (C) Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com> 251da177e4SLinus Torvalds * 26fe77efb8SHidetoshi Seto * 2000-03-29 Chuck Fleckenstein <cfleck@co.intel.com> 27fe77efb8SHidetoshi Seto * Fixed PAL/SAL update issues, began MCA bug fixes, logging issues, 281da177e4SLinus Torvalds * added min save state dump, added INIT handler. 291da177e4SLinus Torvalds * 30fe77efb8SHidetoshi Seto * 2001-01-03 Fred Lewis <frederick.v.lewis@intel.com> 31fe77efb8SHidetoshi Seto * Added setup of CMCI and CPEI IRQs, logging of corrected platform 32fe77efb8SHidetoshi Seto * errors, completed code for logging of corrected & uncorrected 33fe77efb8SHidetoshi Seto * machine check errors, and updated for conformance with Nov. 2000 34fe77efb8SHidetoshi Seto * revision of the SAL 3.0 spec. 35fe77efb8SHidetoshi Seto * 36fe77efb8SHidetoshi Seto * 2002-01-04 Jenna Hall <jenna.s.hall@intel.com> 37fe77efb8SHidetoshi Seto * Aligned MCA stack to 16 bytes, added platform vs. CPU error flag, 38fe77efb8SHidetoshi Seto * set SAL default return values, changed error record structure to 39fe77efb8SHidetoshi Seto * linked list, added init call to sal_get_state_info_size(). 40fe77efb8SHidetoshi Seto * 41fe77efb8SHidetoshi Seto * 2002-03-25 Matt Domsch <Matt_Domsch@dell.com> 42fe77efb8SHidetoshi Seto * GUID cleanups. 43fe77efb8SHidetoshi Seto * 44fe77efb8SHidetoshi Seto * 2003-04-15 David Mosberger-Tang <davidm@hpl.hp.com> 45fe77efb8SHidetoshi Seto * Added INIT backtrace support. 46fe77efb8SHidetoshi Seto * 471da177e4SLinus Torvalds * 2003-12-08 Keith Owens <kaos@sgi.com> 48fe77efb8SHidetoshi Seto * smp_call_function() must not be called from interrupt context 49fe77efb8SHidetoshi Seto * (can deadlock on tasklist_lock). 50fe77efb8SHidetoshi Seto * Use keventd to call smp_call_function(). 511da177e4SLinus Torvalds * 521da177e4SLinus Torvalds * 2004-02-01 Keith Owens <kaos@sgi.com> 531da177e4SLinus Torvalds * Avoid deadlock when using printk() for MCA and INIT records. 54fe77efb8SHidetoshi Seto * Delete all record printing code, moved to salinfo_decode in user 55fe77efb8SHidetoshi Seto * space. Mark variables and functions static where possible. 56fe77efb8SHidetoshi Seto * Delete dead variables and functions. Reorder to remove the need 57fe77efb8SHidetoshi Seto * for forward declarations and to consolidate related code. 587f613c7dSKeith Owens * 597f613c7dSKeith Owens * 2005-08-12 Keith Owens <kaos@sgi.com> 60fe77efb8SHidetoshi Seto * Convert MCA/INIT handlers to use per event stacks and SAL/OS 61fe77efb8SHidetoshi Seto * state. 629138d581SKeith Owens * 639138d581SKeith Owens * 2005-10-07 Keith Owens <kaos@sgi.com> 649138d581SKeith Owens * Add notify_die() hooks. 6543ed3bafSHidetoshi Seto * 6643ed3bafSHidetoshi Seto * 2006-09-15 Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com> 6743ed3bafSHidetoshi Seto * Add printing support for MCA/INIT. 681612b18cSRuss Anderson * 691612b18cSRuss Anderson * 2007-04-27 Russ Anderson <rja@sgi.com> 701612b18cSRuss Anderson * Support multiple cpus going through OS_MCA in the same event. 711da177e4SLinus Torvalds */ 721da177e4SLinus Torvalds #include <linux/types.h> 731da177e4SLinus Torvalds #include <linux/init.h> 741da177e4SLinus Torvalds #include <linux/sched.h> 751da177e4SLinus Torvalds #include <linux/interrupt.h> 761da177e4SLinus Torvalds #include <linux/irq.h> 771da177e4SLinus Torvalds #include <linux/bootmem.h> 781da177e4SLinus Torvalds #include <linux/acpi.h> 791da177e4SLinus Torvalds #include <linux/timer.h> 801da177e4SLinus Torvalds #include <linux/module.h> 811da177e4SLinus Torvalds #include <linux/kernel.h> 821da177e4SLinus Torvalds #include <linux/smp.h> 831da177e4SLinus Torvalds #include <linux/workqueue.h> 844668f0cdSAkinobu Mita #include <linux/cpumask.h> 851eeb66a1SChristoph Hellwig #include <linux/kdebug.h> 86ed5d4026SHidetoshi Seto #include <linux/cpu.h> 871da177e4SLinus Torvalds 881da177e4SLinus Torvalds #include <asm/delay.h> 891da177e4SLinus Torvalds #include <asm/machvec.h> 901da177e4SLinus Torvalds #include <asm/meminit.h> 911da177e4SLinus Torvalds #include <asm/page.h> 921da177e4SLinus Torvalds #include <asm/ptrace.h> 931da177e4SLinus Torvalds #include <asm/system.h> 941da177e4SLinus Torvalds #include <asm/sal.h> 951da177e4SLinus Torvalds #include <asm/mca.h> 96a7956113SZou Nan hai #include <asm/kexec.h> 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds #include <asm/irq.h> 991da177e4SLinus Torvalds #include <asm/hw_irq.h> 1001da177e4SLinus Torvalds 101d2a28ad9SRuss Anderson #include "mca_drv.h" 1027f613c7dSKeith Owens #include "entry.h" 1037f613c7dSKeith Owens 1041da177e4SLinus Torvalds #if defined(IA64_MCA_DEBUG_INFO) 1051da177e4SLinus Torvalds # define IA64_MCA_DEBUG(fmt...) printk(fmt) 1061da177e4SLinus Torvalds #else 1071da177e4SLinus Torvalds # define IA64_MCA_DEBUG(fmt...) 1081da177e4SLinus Torvalds #endif 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds /* Used by mca_asm.S */ 1111da177e4SLinus Torvalds DEFINE_PER_CPU(u64, ia64_mca_data); /* == __per_cpu_mca[smp_processor_id()] */ 1121da177e4SLinus Torvalds DEFINE_PER_CPU(u64, ia64_mca_per_cpu_pte); /* PTE to map per-CPU area */ 1131da177e4SLinus Torvalds DEFINE_PER_CPU(u64, ia64_mca_pal_pte); /* PTE to map PAL code */ 1141da177e4SLinus Torvalds DEFINE_PER_CPU(u64, ia64_mca_pal_base); /* vaddr PAL code granule */ 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds unsigned long __per_cpu_mca[NR_CPUS]; 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds /* In mca_asm.S */ 1197f613c7dSKeith Owens extern void ia64_os_init_dispatch_monarch (void); 1207f613c7dSKeith Owens extern void ia64_os_init_dispatch_slave (void); 1217f613c7dSKeith Owens 1227f613c7dSKeith Owens static int monarch_cpu = -1; 1231da177e4SLinus Torvalds 1241da177e4SLinus Torvalds static ia64_mc_info_t ia64_mc_info; 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds #define MAX_CPE_POLL_INTERVAL (15*60*HZ) /* 15 minutes */ 1271da177e4SLinus Torvalds #define MIN_CPE_POLL_INTERVAL (2*60*HZ) /* 2 minutes */ 1281da177e4SLinus Torvalds #define CMC_POLL_INTERVAL (1*60*HZ) /* 1 minute */ 1291da177e4SLinus Torvalds #define CPE_HISTORY_LENGTH 5 1301da177e4SLinus Torvalds #define CMC_HISTORY_LENGTH 5 1311da177e4SLinus Torvalds 13234eac2abSTony Luck #ifdef CONFIG_ACPI 1331da177e4SLinus Torvalds static struct timer_list cpe_poll_timer; 13434eac2abSTony Luck #endif 1351da177e4SLinus Torvalds static struct timer_list cmc_poll_timer; 1361da177e4SLinus Torvalds /* 1371da177e4SLinus Torvalds * This variable tells whether we are currently in polling mode. 1381da177e4SLinus Torvalds * Start with this in the wrong state so we won't play w/ timers 1391da177e4SLinus Torvalds * before the system is ready. 1401da177e4SLinus Torvalds */ 1411da177e4SLinus Torvalds static int cmc_polling_enabled = 1; 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds /* 1441da177e4SLinus Torvalds * Clearing this variable prevents CPE polling from getting activated 1451da177e4SLinus Torvalds * in mca_late_init. Use it if your system doesn't provide a CPEI, 1461da177e4SLinus Torvalds * but encounters problems retrieving CPE logs. This should only be 1471da177e4SLinus Torvalds * necessary for debugging. 1481da177e4SLinus Torvalds */ 1491da177e4SLinus Torvalds static int cpe_poll_enabled = 1; 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds extern void salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe); 1521da177e4SLinus Torvalds 1530881fc8dSChen, Kenneth W static int mca_init __initdata; 1541da177e4SLinus Torvalds 15543ed3bafSHidetoshi Seto /* 15643ed3bafSHidetoshi Seto * limited & delayed printing support for MCA/INIT handler 15743ed3bafSHidetoshi Seto */ 15843ed3bafSHidetoshi Seto 15943ed3bafSHidetoshi Seto #define mprintk(fmt...) ia64_mca_printk(fmt) 16043ed3bafSHidetoshi Seto 16143ed3bafSHidetoshi Seto #define MLOGBUF_SIZE (512+256*NR_CPUS) 16243ed3bafSHidetoshi Seto #define MLOGBUF_MSGMAX 256 16343ed3bafSHidetoshi Seto static char mlogbuf[MLOGBUF_SIZE]; 16443ed3bafSHidetoshi Seto static DEFINE_SPINLOCK(mlogbuf_wlock); /* mca context only */ 16543ed3bafSHidetoshi Seto static DEFINE_SPINLOCK(mlogbuf_rlock); /* normal context only */ 16643ed3bafSHidetoshi Seto static unsigned long mlogbuf_start; 16743ed3bafSHidetoshi Seto static unsigned long mlogbuf_end; 16843ed3bafSHidetoshi Seto static unsigned int mlogbuf_finished = 0; 16943ed3bafSHidetoshi Seto static unsigned long mlogbuf_timestamp = 0; 17043ed3bafSHidetoshi Seto 17143ed3bafSHidetoshi Seto static int loglevel_save = -1; 17243ed3bafSHidetoshi Seto #define BREAK_LOGLEVEL(__console_loglevel) \ 17343ed3bafSHidetoshi Seto oops_in_progress = 1; \ 17443ed3bafSHidetoshi Seto if (loglevel_save < 0) \ 17543ed3bafSHidetoshi Seto loglevel_save = __console_loglevel; \ 17643ed3bafSHidetoshi Seto __console_loglevel = 15; 17743ed3bafSHidetoshi Seto 17843ed3bafSHidetoshi Seto #define RESTORE_LOGLEVEL(__console_loglevel) \ 17943ed3bafSHidetoshi Seto if (loglevel_save >= 0) { \ 18043ed3bafSHidetoshi Seto __console_loglevel = loglevel_save; \ 18143ed3bafSHidetoshi Seto loglevel_save = -1; \ 18243ed3bafSHidetoshi Seto } \ 18343ed3bafSHidetoshi Seto mlogbuf_finished = 0; \ 18443ed3bafSHidetoshi Seto oops_in_progress = 0; 18543ed3bafSHidetoshi Seto 18643ed3bafSHidetoshi Seto /* 18743ed3bafSHidetoshi Seto * Push messages into buffer, print them later if not urgent. 18843ed3bafSHidetoshi Seto */ 18943ed3bafSHidetoshi Seto void ia64_mca_printk(const char *fmt, ...) 19043ed3bafSHidetoshi Seto { 19143ed3bafSHidetoshi Seto va_list args; 19243ed3bafSHidetoshi Seto int printed_len; 19343ed3bafSHidetoshi Seto char temp_buf[MLOGBUF_MSGMAX]; 19443ed3bafSHidetoshi Seto char *p; 19543ed3bafSHidetoshi Seto 19643ed3bafSHidetoshi Seto va_start(args, fmt); 19743ed3bafSHidetoshi Seto printed_len = vscnprintf(temp_buf, sizeof(temp_buf), fmt, args); 19843ed3bafSHidetoshi Seto va_end(args); 19943ed3bafSHidetoshi Seto 20043ed3bafSHidetoshi Seto /* Copy the output into mlogbuf */ 20143ed3bafSHidetoshi Seto if (oops_in_progress) { 20243ed3bafSHidetoshi Seto /* mlogbuf was abandoned, use printk directly instead. */ 20343ed3bafSHidetoshi Seto printk(temp_buf); 20443ed3bafSHidetoshi Seto } else { 20543ed3bafSHidetoshi Seto spin_lock(&mlogbuf_wlock); 20643ed3bafSHidetoshi Seto for (p = temp_buf; *p; p++) { 20743ed3bafSHidetoshi Seto unsigned long next = (mlogbuf_end + 1) % MLOGBUF_SIZE; 20843ed3bafSHidetoshi Seto if (next != mlogbuf_start) { 20943ed3bafSHidetoshi Seto mlogbuf[mlogbuf_end] = *p; 21043ed3bafSHidetoshi Seto mlogbuf_end = next; 21143ed3bafSHidetoshi Seto } else { 21243ed3bafSHidetoshi Seto /* buffer full */ 21343ed3bafSHidetoshi Seto break; 21443ed3bafSHidetoshi Seto } 21543ed3bafSHidetoshi Seto } 21643ed3bafSHidetoshi Seto mlogbuf[mlogbuf_end] = '\0'; 21743ed3bafSHidetoshi Seto spin_unlock(&mlogbuf_wlock); 21843ed3bafSHidetoshi Seto } 21943ed3bafSHidetoshi Seto } 22043ed3bafSHidetoshi Seto EXPORT_SYMBOL(ia64_mca_printk); 22143ed3bafSHidetoshi Seto 22243ed3bafSHidetoshi Seto /* 22343ed3bafSHidetoshi Seto * Print buffered messages. 22443ed3bafSHidetoshi Seto * NOTE: call this after returning normal context. (ex. from salinfod) 22543ed3bafSHidetoshi Seto */ 22643ed3bafSHidetoshi Seto void ia64_mlogbuf_dump(void) 22743ed3bafSHidetoshi Seto { 22843ed3bafSHidetoshi Seto char temp_buf[MLOGBUF_MSGMAX]; 22943ed3bafSHidetoshi Seto char *p; 23043ed3bafSHidetoshi Seto unsigned long index; 23143ed3bafSHidetoshi Seto unsigned long flags; 23243ed3bafSHidetoshi Seto unsigned int printed_len; 23343ed3bafSHidetoshi Seto 23443ed3bafSHidetoshi Seto /* Get output from mlogbuf */ 23543ed3bafSHidetoshi Seto while (mlogbuf_start != mlogbuf_end) { 23643ed3bafSHidetoshi Seto temp_buf[0] = '\0'; 23743ed3bafSHidetoshi Seto p = temp_buf; 23843ed3bafSHidetoshi Seto printed_len = 0; 23943ed3bafSHidetoshi Seto 24043ed3bafSHidetoshi Seto spin_lock_irqsave(&mlogbuf_rlock, flags); 24143ed3bafSHidetoshi Seto 24243ed3bafSHidetoshi Seto index = mlogbuf_start; 24343ed3bafSHidetoshi Seto while (index != mlogbuf_end) { 24443ed3bafSHidetoshi Seto *p = mlogbuf[index]; 24543ed3bafSHidetoshi Seto index = (index + 1) % MLOGBUF_SIZE; 24643ed3bafSHidetoshi Seto if (!*p) 24743ed3bafSHidetoshi Seto break; 24843ed3bafSHidetoshi Seto p++; 24943ed3bafSHidetoshi Seto if (++printed_len >= MLOGBUF_MSGMAX - 1) 25043ed3bafSHidetoshi Seto break; 25143ed3bafSHidetoshi Seto } 25243ed3bafSHidetoshi Seto *p = '\0'; 25343ed3bafSHidetoshi Seto if (temp_buf[0]) 25443ed3bafSHidetoshi Seto printk(temp_buf); 25543ed3bafSHidetoshi Seto mlogbuf_start = index; 25643ed3bafSHidetoshi Seto 25743ed3bafSHidetoshi Seto mlogbuf_timestamp = 0; 25843ed3bafSHidetoshi Seto spin_unlock_irqrestore(&mlogbuf_rlock, flags); 25943ed3bafSHidetoshi Seto } 26043ed3bafSHidetoshi Seto } 26143ed3bafSHidetoshi Seto EXPORT_SYMBOL(ia64_mlogbuf_dump); 26243ed3bafSHidetoshi Seto 26343ed3bafSHidetoshi Seto /* 26443ed3bafSHidetoshi Seto * Call this if system is going to down or if immediate flushing messages to 26543ed3bafSHidetoshi Seto * console is required. (ex. recovery was failed, crash dump is going to be 26643ed3bafSHidetoshi Seto * invoked, long-wait rendezvous etc.) 26743ed3bafSHidetoshi Seto * NOTE: this should be called from monarch. 26843ed3bafSHidetoshi Seto */ 26943ed3bafSHidetoshi Seto static void ia64_mlogbuf_finish(int wait) 27043ed3bafSHidetoshi Seto { 27143ed3bafSHidetoshi Seto BREAK_LOGLEVEL(console_loglevel); 27243ed3bafSHidetoshi Seto 27343ed3bafSHidetoshi Seto spin_lock_init(&mlogbuf_rlock); 27443ed3bafSHidetoshi Seto ia64_mlogbuf_dump(); 27543ed3bafSHidetoshi Seto printk(KERN_EMERG "mlogbuf_finish: printing switched to urgent mode, " 27643ed3bafSHidetoshi Seto "MCA/INIT might be dodgy or fail.\n"); 27743ed3bafSHidetoshi Seto 27843ed3bafSHidetoshi Seto if (!wait) 27943ed3bafSHidetoshi Seto return; 28043ed3bafSHidetoshi Seto 28143ed3bafSHidetoshi Seto /* wait for console */ 28243ed3bafSHidetoshi Seto printk("Delaying for 5 seconds...\n"); 28343ed3bafSHidetoshi Seto udelay(5*1000000); 28443ed3bafSHidetoshi Seto 28543ed3bafSHidetoshi Seto mlogbuf_finished = 1; 28643ed3bafSHidetoshi Seto } 28743ed3bafSHidetoshi Seto 28843ed3bafSHidetoshi Seto /* 28943ed3bafSHidetoshi Seto * Print buffered messages from INIT context. 29043ed3bafSHidetoshi Seto */ 29143ed3bafSHidetoshi Seto static void ia64_mlogbuf_dump_from_init(void) 29243ed3bafSHidetoshi Seto { 29343ed3bafSHidetoshi Seto if (mlogbuf_finished) 29443ed3bafSHidetoshi Seto return; 29543ed3bafSHidetoshi Seto 29643ed3bafSHidetoshi Seto if (mlogbuf_timestamp && (mlogbuf_timestamp + 30*HZ > jiffies)) { 29743ed3bafSHidetoshi Seto printk(KERN_ERR "INIT: mlogbuf_dump is interrupted by INIT " 29843ed3bafSHidetoshi Seto " and the system seems to be messed up.\n"); 29943ed3bafSHidetoshi Seto ia64_mlogbuf_finish(0); 30043ed3bafSHidetoshi Seto return; 30143ed3bafSHidetoshi Seto } 30243ed3bafSHidetoshi Seto 30343ed3bafSHidetoshi Seto if (!spin_trylock(&mlogbuf_rlock)) { 30443ed3bafSHidetoshi Seto printk(KERN_ERR "INIT: mlogbuf_dump is interrupted by INIT. " 30543ed3bafSHidetoshi Seto "Generated messages other than stack dump will be " 30643ed3bafSHidetoshi Seto "buffered to mlogbuf and will be printed later.\n"); 30743ed3bafSHidetoshi Seto printk(KERN_ERR "INIT: If messages would not printed after " 30843ed3bafSHidetoshi Seto "this INIT, wait 30sec and assert INIT again.\n"); 30943ed3bafSHidetoshi Seto if (!mlogbuf_timestamp) 31043ed3bafSHidetoshi Seto mlogbuf_timestamp = jiffies; 31143ed3bafSHidetoshi Seto return; 31243ed3bafSHidetoshi Seto } 31343ed3bafSHidetoshi Seto spin_unlock(&mlogbuf_rlock); 31443ed3bafSHidetoshi Seto ia64_mlogbuf_dump(); 31543ed3bafSHidetoshi Seto } 3169138d581SKeith Owens 3179138d581SKeith Owens static void inline 3189138d581SKeith Owens ia64_mca_spin(const char *func) 3199138d581SKeith Owens { 32043ed3bafSHidetoshi Seto if (monarch_cpu == smp_processor_id()) 32143ed3bafSHidetoshi Seto ia64_mlogbuf_finish(0); 32243ed3bafSHidetoshi Seto mprintk(KERN_EMERG "%s: spinning here, not returning to SAL\n", func); 3239138d581SKeith Owens while (1) 3249138d581SKeith Owens cpu_relax(); 3259138d581SKeith Owens } 3261da177e4SLinus Torvalds /* 3271da177e4SLinus Torvalds * IA64_MCA log support 3281da177e4SLinus Torvalds */ 3291da177e4SLinus Torvalds #define IA64_MAX_LOGS 2 /* Double-buffering for nested MCAs */ 3301da177e4SLinus Torvalds #define IA64_MAX_LOG_TYPES 4 /* MCA, INIT, CMC, CPE */ 3311da177e4SLinus Torvalds 3321da177e4SLinus Torvalds typedef struct ia64_state_log_s 3331da177e4SLinus Torvalds { 3341da177e4SLinus Torvalds spinlock_t isl_lock; 3351da177e4SLinus Torvalds int isl_index; 3361da177e4SLinus Torvalds unsigned long isl_count; 3371da177e4SLinus Torvalds ia64_err_rec_t *isl_log[IA64_MAX_LOGS]; /* need space to store header + error log */ 3381da177e4SLinus Torvalds } ia64_state_log_t; 3391da177e4SLinus Torvalds 3401da177e4SLinus Torvalds static ia64_state_log_t ia64_state_log[IA64_MAX_LOG_TYPES]; 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvalds #define IA64_LOG_ALLOCATE(it, size) \ 3431da177e4SLinus Torvalds {ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)] = \ 3441da177e4SLinus Torvalds (ia64_err_rec_t *)alloc_bootmem(size); \ 3451da177e4SLinus Torvalds ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)] = \ 3461da177e4SLinus Torvalds (ia64_err_rec_t *)alloc_bootmem(size);} 3471da177e4SLinus Torvalds #define IA64_LOG_LOCK_INIT(it) spin_lock_init(&ia64_state_log[it].isl_lock) 3481da177e4SLinus Torvalds #define IA64_LOG_LOCK(it) spin_lock_irqsave(&ia64_state_log[it].isl_lock, s) 3491da177e4SLinus Torvalds #define IA64_LOG_UNLOCK(it) spin_unlock_irqrestore(&ia64_state_log[it].isl_lock,s) 3501da177e4SLinus Torvalds #define IA64_LOG_NEXT_INDEX(it) ia64_state_log[it].isl_index 3511da177e4SLinus Torvalds #define IA64_LOG_CURR_INDEX(it) 1 - ia64_state_log[it].isl_index 3521da177e4SLinus Torvalds #define IA64_LOG_INDEX_INC(it) \ 3531da177e4SLinus Torvalds {ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index; \ 3541da177e4SLinus Torvalds ia64_state_log[it].isl_count++;} 3551da177e4SLinus Torvalds #define IA64_LOG_INDEX_DEC(it) \ 3561da177e4SLinus Torvalds ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index 3571da177e4SLinus Torvalds #define IA64_LOG_NEXT_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)])) 3581da177e4SLinus Torvalds #define IA64_LOG_CURR_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)])) 3591da177e4SLinus Torvalds #define IA64_LOG_COUNT(it) ia64_state_log[it].isl_count 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds /* 3621da177e4SLinus Torvalds * ia64_log_init 3631da177e4SLinus Torvalds * Reset the OS ia64 log buffer 3641da177e4SLinus Torvalds * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE}) 3651da177e4SLinus Torvalds * Outputs : None 3661da177e4SLinus Torvalds */ 3670881fc8dSChen, Kenneth W static void __init 3681da177e4SLinus Torvalds ia64_log_init(int sal_info_type) 3691da177e4SLinus Torvalds { 3701da177e4SLinus Torvalds u64 max_size = 0; 3711da177e4SLinus Torvalds 3721da177e4SLinus Torvalds IA64_LOG_NEXT_INDEX(sal_info_type) = 0; 3731da177e4SLinus Torvalds IA64_LOG_LOCK_INIT(sal_info_type); 3741da177e4SLinus Torvalds 3751da177e4SLinus Torvalds // SAL will tell us the maximum size of any error record of this type 3761da177e4SLinus Torvalds max_size = ia64_sal_get_state_info_size(sal_info_type); 3771da177e4SLinus Torvalds if (!max_size) 3781da177e4SLinus Torvalds /* alloc_bootmem() doesn't like zero-sized allocations! */ 3791da177e4SLinus Torvalds return; 3801da177e4SLinus Torvalds 3811da177e4SLinus Torvalds // set up OS data structures to hold error info 3821da177e4SLinus Torvalds IA64_LOG_ALLOCATE(sal_info_type, max_size); 3831da177e4SLinus Torvalds memset(IA64_LOG_CURR_BUFFER(sal_info_type), 0, max_size); 3841da177e4SLinus Torvalds memset(IA64_LOG_NEXT_BUFFER(sal_info_type), 0, max_size); 3851da177e4SLinus Torvalds } 3861da177e4SLinus Torvalds 3871da177e4SLinus Torvalds /* 3881da177e4SLinus Torvalds * ia64_log_get 3891da177e4SLinus Torvalds * 3901da177e4SLinus Torvalds * Get the current MCA log from SAL and copy it into the OS log buffer. 3911da177e4SLinus Torvalds * 3921da177e4SLinus Torvalds * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE}) 3931da177e4SLinus Torvalds * irq_safe whether you can use printk at this point 3941da177e4SLinus Torvalds * Outputs : size (total record length) 3951da177e4SLinus Torvalds * *buffer (ptr to error record) 3961da177e4SLinus Torvalds * 3971da177e4SLinus Torvalds */ 3981da177e4SLinus Torvalds static u64 3991da177e4SLinus Torvalds ia64_log_get(int sal_info_type, u8 **buffer, int irq_safe) 4001da177e4SLinus Torvalds { 4011da177e4SLinus Torvalds sal_log_record_header_t *log_buffer; 4021da177e4SLinus Torvalds u64 total_len = 0; 403c53421b1SAlexey Dobriyan unsigned long s; 4041da177e4SLinus Torvalds 4051da177e4SLinus Torvalds IA64_LOG_LOCK(sal_info_type); 4061da177e4SLinus Torvalds 4071da177e4SLinus Torvalds /* Get the process state information */ 4081da177e4SLinus Torvalds log_buffer = IA64_LOG_NEXT_BUFFER(sal_info_type); 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvalds total_len = ia64_sal_get_state_info(sal_info_type, (u64 *)log_buffer); 4111da177e4SLinus Torvalds 4121da177e4SLinus Torvalds if (total_len) { 4131da177e4SLinus Torvalds IA64_LOG_INDEX_INC(sal_info_type); 4141da177e4SLinus Torvalds IA64_LOG_UNLOCK(sal_info_type); 4151da177e4SLinus Torvalds if (irq_safe) { 416*d4ed8084SHarvey Harrison IA64_MCA_DEBUG("%s: SAL error record type %d retrieved. Record length = %ld\n", 417*d4ed8084SHarvey Harrison __func__, sal_info_type, total_len); 4181da177e4SLinus Torvalds } 4191da177e4SLinus Torvalds *buffer = (u8 *) log_buffer; 4201da177e4SLinus Torvalds return total_len; 4211da177e4SLinus Torvalds } else { 4221da177e4SLinus Torvalds IA64_LOG_UNLOCK(sal_info_type); 4231da177e4SLinus Torvalds return 0; 4241da177e4SLinus Torvalds } 4251da177e4SLinus Torvalds } 4261da177e4SLinus Torvalds 4271da177e4SLinus Torvalds /* 4281da177e4SLinus Torvalds * ia64_mca_log_sal_error_record 4291da177e4SLinus Torvalds * 4301da177e4SLinus Torvalds * This function retrieves a specified error record type from SAL 4311da177e4SLinus Torvalds * and wakes up any processes waiting for error records. 4321da177e4SLinus Torvalds * 4337f613c7dSKeith Owens * Inputs : sal_info_type (Type of error record MCA/CMC/CPE) 4347f613c7dSKeith Owens * FIXME: remove MCA and irq_safe. 4351da177e4SLinus Torvalds */ 4361da177e4SLinus Torvalds static void 4371da177e4SLinus Torvalds ia64_mca_log_sal_error_record(int sal_info_type) 4381da177e4SLinus Torvalds { 4391da177e4SLinus Torvalds u8 *buffer; 4401da177e4SLinus Torvalds sal_log_record_header_t *rh; 4411da177e4SLinus Torvalds u64 size; 4427f613c7dSKeith Owens int irq_safe = sal_info_type != SAL_INFO_TYPE_MCA; 4431da177e4SLinus Torvalds #ifdef IA64_MCA_DEBUG_INFO 4441da177e4SLinus Torvalds static const char * const rec_name[] = { "MCA", "INIT", "CMC", "CPE" }; 4451da177e4SLinus Torvalds #endif 4461da177e4SLinus Torvalds 4471da177e4SLinus Torvalds size = ia64_log_get(sal_info_type, &buffer, irq_safe); 4481da177e4SLinus Torvalds if (!size) 4491da177e4SLinus Torvalds return; 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds salinfo_log_wakeup(sal_info_type, buffer, size, irq_safe); 4521da177e4SLinus Torvalds 4531da177e4SLinus Torvalds if (irq_safe) 4541da177e4SLinus Torvalds IA64_MCA_DEBUG("CPU %d: SAL log contains %s error record\n", 4551da177e4SLinus Torvalds smp_processor_id(), 4561da177e4SLinus Torvalds sal_info_type < ARRAY_SIZE(rec_name) ? rec_name[sal_info_type] : "UNKNOWN"); 4571da177e4SLinus Torvalds 4581da177e4SLinus Torvalds /* Clear logs from corrected errors in case there's no user-level logger */ 4591da177e4SLinus Torvalds rh = (sal_log_record_header_t *)buffer; 4601da177e4SLinus Torvalds if (rh->severity == sal_log_severity_corrected) 4611da177e4SLinus Torvalds ia64_sal_clear_state_info(sal_info_type); 4621da177e4SLinus Torvalds } 4631da177e4SLinus Torvalds 464d2a28ad9SRuss Anderson /* 465d2a28ad9SRuss Anderson * search_mca_table 466d2a28ad9SRuss Anderson * See if the MCA surfaced in an instruction range 467d2a28ad9SRuss Anderson * that has been tagged as recoverable. 468d2a28ad9SRuss Anderson * 469d2a28ad9SRuss Anderson * Inputs 470d2a28ad9SRuss Anderson * first First address range to check 471d2a28ad9SRuss Anderson * last Last address range to check 472d2a28ad9SRuss Anderson * ip Instruction pointer, address we are looking for 473d2a28ad9SRuss Anderson * 474d2a28ad9SRuss Anderson * Return value: 475d2a28ad9SRuss Anderson * 1 on Success (in the table)/ 0 on Failure (not in the table) 476d2a28ad9SRuss Anderson */ 477d2a28ad9SRuss Anderson int 478d2a28ad9SRuss Anderson search_mca_table (const struct mca_table_entry *first, 479d2a28ad9SRuss Anderson const struct mca_table_entry *last, 480d2a28ad9SRuss Anderson unsigned long ip) 481d2a28ad9SRuss Anderson { 482d2a28ad9SRuss Anderson const struct mca_table_entry *curr; 483d2a28ad9SRuss Anderson u64 curr_start, curr_end; 484d2a28ad9SRuss Anderson 485d2a28ad9SRuss Anderson curr = first; 486d2a28ad9SRuss Anderson while (curr <= last) { 487d2a28ad9SRuss Anderson curr_start = (u64) &curr->start_addr + curr->start_addr; 488d2a28ad9SRuss Anderson curr_end = (u64) &curr->end_addr + curr->end_addr; 489d2a28ad9SRuss Anderson 490d2a28ad9SRuss Anderson if ((ip >= curr_start) && (ip <= curr_end)) { 491d2a28ad9SRuss Anderson return 1; 492d2a28ad9SRuss Anderson } 493d2a28ad9SRuss Anderson curr++; 494d2a28ad9SRuss Anderson } 495d2a28ad9SRuss Anderson return 0; 496d2a28ad9SRuss Anderson } 497d2a28ad9SRuss Anderson 498d2a28ad9SRuss Anderson /* Given an address, look for it in the mca tables. */ 499d2a28ad9SRuss Anderson int mca_recover_range(unsigned long addr) 500d2a28ad9SRuss Anderson { 501d2a28ad9SRuss Anderson extern struct mca_table_entry __start___mca_table[]; 502d2a28ad9SRuss Anderson extern struct mca_table_entry __stop___mca_table[]; 503d2a28ad9SRuss Anderson 504d2a28ad9SRuss Anderson return search_mca_table(__start___mca_table, __stop___mca_table-1, addr); 505d2a28ad9SRuss Anderson } 506d2a28ad9SRuss Anderson EXPORT_SYMBOL_GPL(mca_recover_range); 507d2a28ad9SRuss Anderson 5081da177e4SLinus Torvalds #ifdef CONFIG_ACPI 5091da177e4SLinus Torvalds 51055e59c51SAshok Raj int cpe_vector = -1; 511ff741906SAshok Raj int ia64_cpe_irq = -1; 5121da177e4SLinus Torvalds 5131da177e4SLinus Torvalds static irqreturn_t 5147d12e780SDavid Howells ia64_mca_cpe_int_handler (int cpe_irq, void *arg) 5151da177e4SLinus Torvalds { 5161da177e4SLinus Torvalds static unsigned long cpe_history[CPE_HISTORY_LENGTH]; 5171da177e4SLinus Torvalds static int index; 5181da177e4SLinus Torvalds static DEFINE_SPINLOCK(cpe_history_lock); 5191da177e4SLinus Torvalds 5201da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n", 521*d4ed8084SHarvey Harrison __func__, cpe_irq, smp_processor_id()); 5221da177e4SLinus Torvalds 5231da177e4SLinus Torvalds /* SAL spec states this should run w/ interrupts enabled */ 5241da177e4SLinus Torvalds local_irq_enable(); 5251da177e4SLinus Torvalds 5261da177e4SLinus Torvalds spin_lock(&cpe_history_lock); 5271da177e4SLinus Torvalds if (!cpe_poll_enabled && cpe_vector >= 0) { 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds int i, count = 1; /* we know 1 happened now */ 5301da177e4SLinus Torvalds unsigned long now = jiffies; 5311da177e4SLinus Torvalds 5321da177e4SLinus Torvalds for (i = 0; i < CPE_HISTORY_LENGTH; i++) { 5331da177e4SLinus Torvalds if (now - cpe_history[i] <= HZ) 5341da177e4SLinus Torvalds count++; 5351da177e4SLinus Torvalds } 5361da177e4SLinus Torvalds 5371da177e4SLinus Torvalds IA64_MCA_DEBUG(KERN_INFO "CPE threshold %d/%d\n", count, CPE_HISTORY_LENGTH); 5381da177e4SLinus Torvalds if (count >= CPE_HISTORY_LENGTH) { 5391da177e4SLinus Torvalds 5401da177e4SLinus Torvalds cpe_poll_enabled = 1; 5411da177e4SLinus Torvalds spin_unlock(&cpe_history_lock); 5421da177e4SLinus Torvalds disable_irq_nosync(local_vector_to_irq(IA64_CPE_VECTOR)); 5431da177e4SLinus Torvalds 5441da177e4SLinus Torvalds /* 5451da177e4SLinus Torvalds * Corrected errors will still be corrected, but 5461da177e4SLinus Torvalds * make sure there's a log somewhere that indicates 5471da177e4SLinus Torvalds * something is generating more than we can handle. 5481da177e4SLinus Torvalds */ 5491da177e4SLinus Torvalds printk(KERN_WARNING "WARNING: Switching to polling CPE handler; error records may be lost\n"); 5501da177e4SLinus Torvalds 5511da177e4SLinus Torvalds mod_timer(&cpe_poll_timer, jiffies + MIN_CPE_POLL_INTERVAL); 5521da177e4SLinus Torvalds 5531da177e4SLinus Torvalds /* lock already released, get out now */ 554ddb4f0dfSHidetoshi Seto goto out; 5551da177e4SLinus Torvalds } else { 5561da177e4SLinus Torvalds cpe_history[index++] = now; 5571da177e4SLinus Torvalds if (index == CPE_HISTORY_LENGTH) 5581da177e4SLinus Torvalds index = 0; 5591da177e4SLinus Torvalds } 5601da177e4SLinus Torvalds } 5611da177e4SLinus Torvalds spin_unlock(&cpe_history_lock); 562ddb4f0dfSHidetoshi Seto out: 563ddb4f0dfSHidetoshi Seto /* Get the CPE error record and log it */ 564ddb4f0dfSHidetoshi Seto ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE); 565ddb4f0dfSHidetoshi Seto 5661da177e4SLinus Torvalds return IRQ_HANDLED; 5671da177e4SLinus Torvalds } 5681da177e4SLinus Torvalds 5691da177e4SLinus Torvalds #endif /* CONFIG_ACPI */ 5701da177e4SLinus Torvalds 5711da177e4SLinus Torvalds #ifdef CONFIG_ACPI 5721da177e4SLinus Torvalds /* 5731da177e4SLinus Torvalds * ia64_mca_register_cpev 5741da177e4SLinus Torvalds * 5751da177e4SLinus Torvalds * Register the corrected platform error vector with SAL. 5761da177e4SLinus Torvalds * 5771da177e4SLinus Torvalds * Inputs 5781da177e4SLinus Torvalds * cpev Corrected Platform Error Vector number 5791da177e4SLinus Torvalds * 5801da177e4SLinus Torvalds * Outputs 5811da177e4SLinus Torvalds * None 5821da177e4SLinus Torvalds */ 5831f3b6045SRuss Anderson void 5841da177e4SLinus Torvalds ia64_mca_register_cpev (int cpev) 5851da177e4SLinus Torvalds { 5861da177e4SLinus Torvalds /* Register the CPE interrupt vector with SAL */ 5871da177e4SLinus Torvalds struct ia64_sal_retval isrv; 5881da177e4SLinus Torvalds 5891da177e4SLinus Torvalds isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_CPE_INT, SAL_MC_PARAM_MECHANISM_INT, cpev, 0, 0); 5901da177e4SLinus Torvalds if (isrv.status) { 5911da177e4SLinus Torvalds printk(KERN_ERR "Failed to register Corrected Platform " 5921da177e4SLinus Torvalds "Error interrupt vector with SAL (status %ld)\n", isrv.status); 5931da177e4SLinus Torvalds return; 5941da177e4SLinus Torvalds } 5951da177e4SLinus Torvalds 5961da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: corrected platform error " 597*d4ed8084SHarvey Harrison "vector %#x registered\n", __func__, cpev); 5981da177e4SLinus Torvalds } 5991da177e4SLinus Torvalds #endif /* CONFIG_ACPI */ 6001da177e4SLinus Torvalds 6011da177e4SLinus Torvalds /* 6021da177e4SLinus Torvalds * ia64_mca_cmc_vector_setup 6031da177e4SLinus Torvalds * 6041da177e4SLinus Torvalds * Setup the corrected machine check vector register in the processor. 6051da177e4SLinus Torvalds * (The interrupt is masked on boot. ia64_mca_late_init unmask this.) 6061da177e4SLinus Torvalds * This function is invoked on a per-processor basis. 6071da177e4SLinus Torvalds * 6081da177e4SLinus Torvalds * Inputs 6091da177e4SLinus Torvalds * None 6101da177e4SLinus Torvalds * 6111da177e4SLinus Torvalds * Outputs 6121da177e4SLinus Torvalds * None 6131da177e4SLinus Torvalds */ 6140881fc8dSChen, Kenneth W void __cpuinit 6151da177e4SLinus Torvalds ia64_mca_cmc_vector_setup (void) 6161da177e4SLinus Torvalds { 6171da177e4SLinus Torvalds cmcv_reg_t cmcv; 6181da177e4SLinus Torvalds 6191da177e4SLinus Torvalds cmcv.cmcv_regval = 0; 6201da177e4SLinus Torvalds cmcv.cmcv_mask = 1; /* Mask/disable interrupt at first */ 6211da177e4SLinus Torvalds cmcv.cmcv_vector = IA64_CMC_VECTOR; 6221da177e4SLinus Torvalds ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval); 6231da177e4SLinus Torvalds 624*d4ed8084SHarvey Harrison IA64_MCA_DEBUG("%s: CPU %d corrected machine check vector %#x registered.\n", 625*d4ed8084SHarvey Harrison __func__, smp_processor_id(), IA64_CMC_VECTOR); 6261da177e4SLinus Torvalds 6271da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: CPU %d CMCV = %#016lx\n", 628*d4ed8084SHarvey Harrison __func__, smp_processor_id(), ia64_getreg(_IA64_REG_CR_CMCV)); 6291da177e4SLinus Torvalds } 6301da177e4SLinus Torvalds 6311da177e4SLinus Torvalds /* 6321da177e4SLinus Torvalds * ia64_mca_cmc_vector_disable 6331da177e4SLinus Torvalds * 6341da177e4SLinus Torvalds * Mask the corrected machine check vector register in the processor. 6351da177e4SLinus Torvalds * This function is invoked on a per-processor basis. 6361da177e4SLinus Torvalds * 6371da177e4SLinus Torvalds * Inputs 6381da177e4SLinus Torvalds * dummy(unused) 6391da177e4SLinus Torvalds * 6401da177e4SLinus Torvalds * Outputs 6411da177e4SLinus Torvalds * None 6421da177e4SLinus Torvalds */ 6431da177e4SLinus Torvalds static void 6441da177e4SLinus Torvalds ia64_mca_cmc_vector_disable (void *dummy) 6451da177e4SLinus Torvalds { 6461da177e4SLinus Torvalds cmcv_reg_t cmcv; 6471da177e4SLinus Torvalds 6481da177e4SLinus Torvalds cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV); 6491da177e4SLinus Torvalds 6501da177e4SLinus Torvalds cmcv.cmcv_mask = 1; /* Mask/disable interrupt */ 6511da177e4SLinus Torvalds ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval); 6521da177e4SLinus Torvalds 653*d4ed8084SHarvey Harrison IA64_MCA_DEBUG("%s: CPU %d corrected machine check vector %#x disabled.\n", 654*d4ed8084SHarvey Harrison __func__, smp_processor_id(), cmcv.cmcv_vector); 6551da177e4SLinus Torvalds } 6561da177e4SLinus Torvalds 6571da177e4SLinus Torvalds /* 6581da177e4SLinus Torvalds * ia64_mca_cmc_vector_enable 6591da177e4SLinus Torvalds * 6601da177e4SLinus Torvalds * Unmask the corrected machine check vector register in the processor. 6611da177e4SLinus Torvalds * This function is invoked on a per-processor basis. 6621da177e4SLinus Torvalds * 6631da177e4SLinus Torvalds * Inputs 6641da177e4SLinus Torvalds * dummy(unused) 6651da177e4SLinus Torvalds * 6661da177e4SLinus Torvalds * Outputs 6671da177e4SLinus Torvalds * None 6681da177e4SLinus Torvalds */ 6691da177e4SLinus Torvalds static void 6701da177e4SLinus Torvalds ia64_mca_cmc_vector_enable (void *dummy) 6711da177e4SLinus Torvalds { 6721da177e4SLinus Torvalds cmcv_reg_t cmcv; 6731da177e4SLinus Torvalds 6741da177e4SLinus Torvalds cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV); 6751da177e4SLinus Torvalds 6761da177e4SLinus Torvalds cmcv.cmcv_mask = 0; /* Unmask/enable interrupt */ 6771da177e4SLinus Torvalds ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval); 6781da177e4SLinus Torvalds 679*d4ed8084SHarvey Harrison IA64_MCA_DEBUG("%s: CPU %d corrected machine check vector %#x enabled.\n", 680*d4ed8084SHarvey Harrison __func__, smp_processor_id(), cmcv.cmcv_vector); 6811da177e4SLinus Torvalds } 6821da177e4SLinus Torvalds 6831da177e4SLinus Torvalds /* 6841da177e4SLinus Torvalds * ia64_mca_cmc_vector_disable_keventd 6851da177e4SLinus Torvalds * 6861da177e4SLinus Torvalds * Called via keventd (smp_call_function() is not safe in interrupt context) to 6871da177e4SLinus Torvalds * disable the cmc interrupt vector. 6881da177e4SLinus Torvalds */ 6891da177e4SLinus Torvalds static void 6906d5aefb8SDavid Howells ia64_mca_cmc_vector_disable_keventd(struct work_struct *unused) 6911da177e4SLinus Torvalds { 6921da177e4SLinus Torvalds on_each_cpu(ia64_mca_cmc_vector_disable, NULL, 1, 0); 6931da177e4SLinus Torvalds } 6941da177e4SLinus Torvalds 6951da177e4SLinus Torvalds /* 6961da177e4SLinus Torvalds * ia64_mca_cmc_vector_enable_keventd 6971da177e4SLinus Torvalds * 6981da177e4SLinus Torvalds * Called via keventd (smp_call_function() is not safe in interrupt context) to 6991da177e4SLinus Torvalds * enable the cmc interrupt vector. 7001da177e4SLinus Torvalds */ 7011da177e4SLinus Torvalds static void 7026d5aefb8SDavid Howells ia64_mca_cmc_vector_enable_keventd(struct work_struct *unused) 7031da177e4SLinus Torvalds { 7041da177e4SLinus Torvalds on_each_cpu(ia64_mca_cmc_vector_enable, NULL, 1, 0); 7051da177e4SLinus Torvalds } 7061da177e4SLinus Torvalds 7071da177e4SLinus Torvalds /* 7081da177e4SLinus Torvalds * ia64_mca_wakeup 7091da177e4SLinus Torvalds * 710e1b1eb01SRuss Anderson * Send an inter-cpu interrupt to wake-up a particular cpu. 7111da177e4SLinus Torvalds * 7121da177e4SLinus Torvalds * Inputs : cpuid 7131da177e4SLinus Torvalds * Outputs : None 7141da177e4SLinus Torvalds */ 7151da177e4SLinus Torvalds static void 7161da177e4SLinus Torvalds ia64_mca_wakeup(int cpu) 7171da177e4SLinus Torvalds { 7181da177e4SLinus Torvalds platform_send_ipi(cpu, IA64_MCA_WAKEUP_VECTOR, IA64_IPI_DM_INT, 0); 7191da177e4SLinus Torvalds } 7201da177e4SLinus Torvalds 7211da177e4SLinus Torvalds /* 7221da177e4SLinus Torvalds * ia64_mca_wakeup_all 7231da177e4SLinus Torvalds * 724e1b1eb01SRuss Anderson * Wakeup all the slave cpus which have rendez'ed previously. 7251da177e4SLinus Torvalds * 7261da177e4SLinus Torvalds * Inputs : None 7271da177e4SLinus Torvalds * Outputs : None 7281da177e4SLinus Torvalds */ 7291da177e4SLinus Torvalds static void 7301da177e4SLinus Torvalds ia64_mca_wakeup_all(void) 7311da177e4SLinus Torvalds { 7321da177e4SLinus Torvalds int cpu; 7331da177e4SLinus Torvalds 7341da177e4SLinus Torvalds /* Clear the Rendez checkin flag for all cpus */ 735ddf6d0a0Shawkes@sgi.com for_each_online_cpu(cpu) { 7361da177e4SLinus Torvalds if (ia64_mc_info.imi_rendez_checkin[cpu] == IA64_MCA_RENDEZ_CHECKIN_DONE) 7371da177e4SLinus Torvalds ia64_mca_wakeup(cpu); 7381da177e4SLinus Torvalds } 7391da177e4SLinus Torvalds 7401da177e4SLinus Torvalds } 7411da177e4SLinus Torvalds 7421da177e4SLinus Torvalds /* 7431da177e4SLinus Torvalds * ia64_mca_rendez_interrupt_handler 7441da177e4SLinus Torvalds * 7451da177e4SLinus Torvalds * This is handler used to put slave processors into spinloop 7461da177e4SLinus Torvalds * while the monarch processor does the mca handling and later 747e1b1eb01SRuss Anderson * wake each slave up once the monarch is done. The state 748e1b1eb01SRuss Anderson * IA64_MCA_RENDEZ_CHECKIN_DONE indicates the cpu is rendez'ed 749e1b1eb01SRuss Anderson * in SAL. The state IA64_MCA_RENDEZ_CHECKIN_NOTDONE indicates 750e1b1eb01SRuss Anderson * the cpu has come out of OS rendezvous. 7511da177e4SLinus Torvalds * 7521da177e4SLinus Torvalds * Inputs : None 7531da177e4SLinus Torvalds * Outputs : None 7541da177e4SLinus Torvalds */ 7551da177e4SLinus Torvalds static irqreturn_t 7567d12e780SDavid Howells ia64_mca_rendez_int_handler(int rendez_irq, void *arg) 7571da177e4SLinus Torvalds { 7581da177e4SLinus Torvalds unsigned long flags; 7591da177e4SLinus Torvalds int cpu = smp_processor_id(); 760958b166cSKeith Owens struct ia64_mca_notify_die nd = 761958b166cSKeith Owens { .sos = NULL, .monarch_cpu = &monarch_cpu }; 7621da177e4SLinus Torvalds 7631da177e4SLinus Torvalds /* Mask all interrupts */ 7641da177e4SLinus Torvalds local_irq_save(flags); 7657d12e780SDavid Howells if (notify_die(DIE_MCA_RENDZVOUS_ENTER, "MCA", get_irq_regs(), 7667d12e780SDavid Howells (long)&nd, 0, 0) == NOTIFY_STOP) 767*d4ed8084SHarvey Harrison ia64_mca_spin(__func__); 7681da177e4SLinus Torvalds 7691da177e4SLinus Torvalds ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_DONE; 7701da177e4SLinus Torvalds /* Register with the SAL monarch that the slave has 7711da177e4SLinus Torvalds * reached SAL 7721da177e4SLinus Torvalds */ 7731da177e4SLinus Torvalds ia64_sal_mc_rendez(); 7741da177e4SLinus Torvalds 7757d12e780SDavid Howells if (notify_die(DIE_MCA_RENDZVOUS_PROCESS, "MCA", get_irq_regs(), 7767d12e780SDavid Howells (long)&nd, 0, 0) == NOTIFY_STOP) 777*d4ed8084SHarvey Harrison ia64_mca_spin(__func__); 7789138d581SKeith Owens 7797f613c7dSKeith Owens /* Wait for the monarch cpu to exit. */ 7807f613c7dSKeith Owens while (monarch_cpu != -1) 7817f613c7dSKeith Owens cpu_relax(); /* spin until monarch leaves */ 7821da177e4SLinus Torvalds 7837d12e780SDavid Howells if (notify_die(DIE_MCA_RENDZVOUS_LEAVE, "MCA", get_irq_regs(), 7847d12e780SDavid Howells (long)&nd, 0, 0) == NOTIFY_STOP) 785*d4ed8084SHarvey Harrison ia64_mca_spin(__func__); 7869138d581SKeith Owens 787e1b1eb01SRuss Anderson ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE; 7881da177e4SLinus Torvalds /* Enable all interrupts */ 7891da177e4SLinus Torvalds local_irq_restore(flags); 7901da177e4SLinus Torvalds return IRQ_HANDLED; 7911da177e4SLinus Torvalds } 7921da177e4SLinus Torvalds 7931da177e4SLinus Torvalds /* 7941da177e4SLinus Torvalds * ia64_mca_wakeup_int_handler 7951da177e4SLinus Torvalds * 7961da177e4SLinus Torvalds * The interrupt handler for processing the inter-cpu interrupt to the 7971da177e4SLinus Torvalds * slave cpu which was spinning in the rendez loop. 7981da177e4SLinus Torvalds * Since this spinning is done by turning off the interrupts and 7991da177e4SLinus Torvalds * polling on the wakeup-interrupt bit in the IRR, there is 8001da177e4SLinus Torvalds * nothing useful to be done in the handler. 8011da177e4SLinus Torvalds * 8021da177e4SLinus Torvalds * Inputs : wakeup_irq (Wakeup-interrupt bit) 8031da177e4SLinus Torvalds * arg (Interrupt handler specific argument) 8041da177e4SLinus Torvalds * Outputs : None 8051da177e4SLinus Torvalds * 8061da177e4SLinus Torvalds */ 8071da177e4SLinus Torvalds static irqreturn_t 8087d12e780SDavid Howells ia64_mca_wakeup_int_handler(int wakeup_irq, void *arg) 8091da177e4SLinus Torvalds { 8101da177e4SLinus Torvalds return IRQ_HANDLED; 8111da177e4SLinus Torvalds } 8121da177e4SLinus Torvalds 8131da177e4SLinus Torvalds /* Function pointer for extra MCA recovery */ 8141da177e4SLinus Torvalds int (*ia64_mca_ucmc_extension) 8157f613c7dSKeith Owens (void*,struct ia64_sal_os_state*) 8161da177e4SLinus Torvalds = NULL; 8171da177e4SLinus Torvalds 8181da177e4SLinus Torvalds int 8197f613c7dSKeith Owens ia64_reg_MCA_extension(int (*fn)(void *, struct ia64_sal_os_state *)) 8201da177e4SLinus Torvalds { 8211da177e4SLinus Torvalds if (ia64_mca_ucmc_extension) 8221da177e4SLinus Torvalds return 1; 8231da177e4SLinus Torvalds 8241da177e4SLinus Torvalds ia64_mca_ucmc_extension = fn; 8251da177e4SLinus Torvalds return 0; 8261da177e4SLinus Torvalds } 8271da177e4SLinus Torvalds 8281da177e4SLinus Torvalds void 8291da177e4SLinus Torvalds ia64_unreg_MCA_extension(void) 8301da177e4SLinus Torvalds { 8311da177e4SLinus Torvalds if (ia64_mca_ucmc_extension) 8321da177e4SLinus Torvalds ia64_mca_ucmc_extension = NULL; 8331da177e4SLinus Torvalds } 8341da177e4SLinus Torvalds 8351da177e4SLinus Torvalds EXPORT_SYMBOL(ia64_reg_MCA_extension); 8361da177e4SLinus Torvalds EXPORT_SYMBOL(ia64_unreg_MCA_extension); 8371da177e4SLinus Torvalds 8387f613c7dSKeith Owens 8397f613c7dSKeith Owens static inline void 8407f613c7dSKeith Owens copy_reg(const u64 *fr, u64 fnat, u64 *tr, u64 *tnat) 8417f613c7dSKeith Owens { 8427f613c7dSKeith Owens u64 fslot, tslot, nat; 8437f613c7dSKeith Owens *tr = *fr; 8447f613c7dSKeith Owens fslot = ((unsigned long)fr >> 3) & 63; 8457f613c7dSKeith Owens tslot = ((unsigned long)tr >> 3) & 63; 8467f613c7dSKeith Owens *tnat &= ~(1UL << tslot); 8477f613c7dSKeith Owens nat = (fnat >> fslot) & 1; 8487f613c7dSKeith Owens *tnat |= (nat << tslot); 8497f613c7dSKeith Owens } 8507f613c7dSKeith Owens 851e9ac054dSKeith Owens /* Change the comm field on the MCA/INT task to include the pid that 852e9ac054dSKeith Owens * was interrupted, it makes for easier debugging. If that pid was 0 853e9ac054dSKeith Owens * (swapper or nested MCA/INIT) then use the start of the previous comm 854e9ac054dSKeith Owens * field suffixed with its cpu. 855e9ac054dSKeith Owens */ 856e9ac054dSKeith Owens 857e9ac054dSKeith Owens static void 85836c8b586SIngo Molnar ia64_mca_modify_comm(const struct task_struct *previous_current) 859e9ac054dSKeith Owens { 860e9ac054dSKeith Owens char *p, comm[sizeof(current->comm)]; 861e9ac054dSKeith Owens if (previous_current->pid) 862e9ac054dSKeith Owens snprintf(comm, sizeof(comm), "%s %d", 863e9ac054dSKeith Owens current->comm, previous_current->pid); 864e9ac054dSKeith Owens else { 865e9ac054dSKeith Owens int l; 866e9ac054dSKeith Owens if ((p = strchr(previous_current->comm, ' '))) 867e9ac054dSKeith Owens l = p - previous_current->comm; 868e9ac054dSKeith Owens else 869e9ac054dSKeith Owens l = strlen(previous_current->comm); 870e9ac054dSKeith Owens snprintf(comm, sizeof(comm), "%s %*s %d", 871e9ac054dSKeith Owens current->comm, l, previous_current->comm, 872e9ac054dSKeith Owens task_thread_info(previous_current)->cpu); 873e9ac054dSKeith Owens } 874e9ac054dSKeith Owens memcpy(current->comm, comm, sizeof(current->comm)); 875e9ac054dSKeith Owens } 876e9ac054dSKeith Owens 8777f613c7dSKeith Owens /* On entry to this routine, we are running on the per cpu stack, see 8787f613c7dSKeith Owens * mca_asm.h. The original stack has not been touched by this event. Some of 8797f613c7dSKeith Owens * the original stack's registers will be in the RBS on this stack. This stack 8807f613c7dSKeith Owens * also contains a partial pt_regs and switch_stack, the rest of the data is in 8817f613c7dSKeith Owens * PAL minstate. 8827f613c7dSKeith Owens * 8837f613c7dSKeith Owens * The first thing to do is modify the original stack to look like a blocked 8847f613c7dSKeith Owens * task so we can run backtrace on the original task. Also mark the per cpu 8857f613c7dSKeith Owens * stack as current to ensure that we use the correct task state, it also means 8867f613c7dSKeith Owens * that we can do backtrace on the MCA/INIT handler code itself. 8877f613c7dSKeith Owens */ 8887f613c7dSKeith Owens 88936c8b586SIngo Molnar static struct task_struct * 8907f613c7dSKeith Owens ia64_mca_modify_original_stack(struct pt_regs *regs, 8917f613c7dSKeith Owens const struct switch_stack *sw, 8927f613c7dSKeith Owens struct ia64_sal_os_state *sos, 8937f613c7dSKeith Owens const char *type) 8947f613c7dSKeith Owens { 895e9ac054dSKeith Owens char *p; 8967f613c7dSKeith Owens ia64_va va; 8977f613c7dSKeith Owens extern char ia64_leave_kernel[]; /* Need asm address, not function descriptor */ 8987f613c7dSKeith Owens const pal_min_state_area_t *ms = sos->pal_min_state; 89936c8b586SIngo Molnar struct task_struct *previous_current; 9007f613c7dSKeith Owens struct pt_regs *old_regs; 9017f613c7dSKeith Owens struct switch_stack *old_sw; 9027f613c7dSKeith Owens unsigned size = sizeof(struct pt_regs) + 9037f613c7dSKeith Owens sizeof(struct switch_stack) + 16; 9047f613c7dSKeith Owens u64 *old_bspstore, *old_bsp; 9057f613c7dSKeith Owens u64 *new_bspstore, *new_bsp; 9067f613c7dSKeith Owens u64 old_unat, old_rnat, new_rnat, nat; 9077f613c7dSKeith Owens u64 slots, loadrs = regs->loadrs; 9087f613c7dSKeith Owens u64 r12 = ms->pmsa_gr[12-1], r13 = ms->pmsa_gr[13-1]; 9097f613c7dSKeith Owens u64 ar_bspstore = regs->ar_bspstore; 9107f613c7dSKeith Owens u64 ar_bsp = regs->ar_bspstore + (loadrs >> 16); 9117f613c7dSKeith Owens const u64 *bank; 9127f613c7dSKeith Owens const char *msg; 9137f613c7dSKeith Owens int cpu = smp_processor_id(); 9147f613c7dSKeith Owens 9157f613c7dSKeith Owens previous_current = curr_task(cpu); 9167f613c7dSKeith Owens set_curr_task(cpu, current); 9177f613c7dSKeith Owens if ((p = strchr(current->comm, ' '))) 9187f613c7dSKeith Owens *p = '\0'; 9197f613c7dSKeith Owens 9207f613c7dSKeith Owens /* Best effort attempt to cope with MCA/INIT delivered while in 9217f613c7dSKeith Owens * physical mode. 9227f613c7dSKeith Owens */ 9237f613c7dSKeith Owens regs->cr_ipsr = ms->pmsa_ipsr; 9247f613c7dSKeith Owens if (ia64_psr(regs)->dt == 0) { 9257f613c7dSKeith Owens va.l = r12; 9267f613c7dSKeith Owens if (va.f.reg == 0) { 9277f613c7dSKeith Owens va.f.reg = 7; 9287f613c7dSKeith Owens r12 = va.l; 9297f613c7dSKeith Owens } 9307f613c7dSKeith Owens va.l = r13; 9317f613c7dSKeith Owens if (va.f.reg == 0) { 9327f613c7dSKeith Owens va.f.reg = 7; 9337f613c7dSKeith Owens r13 = va.l; 9347f613c7dSKeith Owens } 9357f613c7dSKeith Owens } 9367f613c7dSKeith Owens if (ia64_psr(regs)->rt == 0) { 9377f613c7dSKeith Owens va.l = ar_bspstore; 9387f613c7dSKeith Owens if (va.f.reg == 0) { 9397f613c7dSKeith Owens va.f.reg = 7; 9407f613c7dSKeith Owens ar_bspstore = va.l; 9417f613c7dSKeith Owens } 9427f613c7dSKeith Owens va.l = ar_bsp; 9437f613c7dSKeith Owens if (va.f.reg == 0) { 9447f613c7dSKeith Owens va.f.reg = 7; 9457f613c7dSKeith Owens ar_bsp = va.l; 9467f613c7dSKeith Owens } 9477f613c7dSKeith Owens } 9487f613c7dSKeith Owens 9497f613c7dSKeith Owens /* mca_asm.S ia64_old_stack() cannot assume that the dirty registers 9507f613c7dSKeith Owens * have been copied to the old stack, the old stack may fail the 9517f613c7dSKeith Owens * validation tests below. So ia64_old_stack() must restore the dirty 9527f613c7dSKeith Owens * registers from the new stack. The old and new bspstore probably 9537f613c7dSKeith Owens * have different alignments, so loadrs calculated on the old bsp 9547f613c7dSKeith Owens * cannot be used to restore from the new bsp. Calculate a suitable 9557f613c7dSKeith Owens * loadrs for the new stack and save it in the new pt_regs, where 9567f613c7dSKeith Owens * ia64_old_stack() can get it. 9577f613c7dSKeith Owens */ 9587f613c7dSKeith Owens old_bspstore = (u64 *)ar_bspstore; 9597f613c7dSKeith Owens old_bsp = (u64 *)ar_bsp; 9607f613c7dSKeith Owens slots = ia64_rse_num_regs(old_bspstore, old_bsp); 9617f613c7dSKeith Owens new_bspstore = (u64 *)((u64)current + IA64_RBS_OFFSET); 9627f613c7dSKeith Owens new_bsp = ia64_rse_skip_regs(new_bspstore, slots); 9637f613c7dSKeith Owens regs->loadrs = (new_bsp - new_bspstore) * 8 << 16; 9647f613c7dSKeith Owens 9657f613c7dSKeith Owens /* Verify the previous stack state before we change it */ 9667f613c7dSKeith Owens if (user_mode(regs)) { 9677f613c7dSKeith Owens msg = "occurred in user space"; 968e9ac054dSKeith Owens /* previous_current is guaranteed to be valid when the task was 969e9ac054dSKeith Owens * in user space, so ... 970e9ac054dSKeith Owens */ 971e9ac054dSKeith Owens ia64_mca_modify_comm(previous_current); 9727f613c7dSKeith Owens goto no_mod; 9737f613c7dSKeith Owens } 974d2a28ad9SRuss Anderson 9757f613c7dSKeith Owens if (r13 != sos->prev_IA64_KR_CURRENT) { 9767f613c7dSKeith Owens msg = "inconsistent previous current and r13"; 9777f613c7dSKeith Owens goto no_mod; 9787f613c7dSKeith Owens } 9791612b18cSRuss Anderson 9801612b18cSRuss Anderson if (!mca_recover_range(ms->pmsa_iip)) { 9817f613c7dSKeith Owens if ((r12 - r13) >= KERNEL_STACK_SIZE) { 9827f613c7dSKeith Owens msg = "inconsistent r12 and r13"; 9837f613c7dSKeith Owens goto no_mod; 9847f613c7dSKeith Owens } 9857f613c7dSKeith Owens if ((ar_bspstore - r13) >= KERNEL_STACK_SIZE) { 9867f613c7dSKeith Owens msg = "inconsistent ar.bspstore and r13"; 9877f613c7dSKeith Owens goto no_mod; 9887f613c7dSKeith Owens } 9897f613c7dSKeith Owens va.p = old_bspstore; 9907f613c7dSKeith Owens if (va.f.reg < 5) { 9917f613c7dSKeith Owens msg = "old_bspstore is in the wrong region"; 9927f613c7dSKeith Owens goto no_mod; 9937f613c7dSKeith Owens } 9947f613c7dSKeith Owens if ((ar_bsp - r13) >= KERNEL_STACK_SIZE) { 9957f613c7dSKeith Owens msg = "inconsistent ar.bsp and r13"; 9967f613c7dSKeith Owens goto no_mod; 9977f613c7dSKeith Owens } 9987f613c7dSKeith Owens size += (ia64_rse_skip_regs(old_bspstore, slots) - old_bspstore) * 8; 9997f613c7dSKeith Owens if (ar_bspstore + size > r12) { 10007f613c7dSKeith Owens msg = "no room for blocked state"; 10017f613c7dSKeith Owens goto no_mod; 10027f613c7dSKeith Owens } 1003d2a28ad9SRuss Anderson } 10047f613c7dSKeith Owens 1005e9ac054dSKeith Owens ia64_mca_modify_comm(previous_current); 10067f613c7dSKeith Owens 10077f613c7dSKeith Owens /* Make the original task look blocked. First stack a struct pt_regs, 10087f613c7dSKeith Owens * describing the state at the time of interrupt. mca_asm.S built a 10097f613c7dSKeith Owens * partial pt_regs, copy it and fill in the blanks using minstate. 10107f613c7dSKeith Owens */ 10117f613c7dSKeith Owens p = (char *)r12 - sizeof(*regs); 10127f613c7dSKeith Owens old_regs = (struct pt_regs *)p; 10137f613c7dSKeith Owens memcpy(old_regs, regs, sizeof(*regs)); 10147f613c7dSKeith Owens /* If ipsr.ic then use pmsa_{iip,ipsr,ifs}, else use 10157f613c7dSKeith Owens * pmsa_{xip,xpsr,xfs} 10167f613c7dSKeith Owens */ 10177f613c7dSKeith Owens if (ia64_psr(regs)->ic) { 10187f613c7dSKeith Owens old_regs->cr_iip = ms->pmsa_iip; 10197f613c7dSKeith Owens old_regs->cr_ipsr = ms->pmsa_ipsr; 10207f613c7dSKeith Owens old_regs->cr_ifs = ms->pmsa_ifs; 10217f613c7dSKeith Owens } else { 10227f613c7dSKeith Owens old_regs->cr_iip = ms->pmsa_xip; 10237f613c7dSKeith Owens old_regs->cr_ipsr = ms->pmsa_xpsr; 10247f613c7dSKeith Owens old_regs->cr_ifs = ms->pmsa_xfs; 10257f613c7dSKeith Owens } 10267f613c7dSKeith Owens old_regs->pr = ms->pmsa_pr; 10277f613c7dSKeith Owens old_regs->b0 = ms->pmsa_br0; 10287f613c7dSKeith Owens old_regs->loadrs = loadrs; 10297f613c7dSKeith Owens old_regs->ar_rsc = ms->pmsa_rsc; 10307f613c7dSKeith Owens old_unat = old_regs->ar_unat; 10317f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[1-1], ms->pmsa_nat_bits, &old_regs->r1, &old_unat); 10327f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[2-1], ms->pmsa_nat_bits, &old_regs->r2, &old_unat); 10337f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[3-1], ms->pmsa_nat_bits, &old_regs->r3, &old_unat); 10347f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[8-1], ms->pmsa_nat_bits, &old_regs->r8, &old_unat); 10357f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[9-1], ms->pmsa_nat_bits, &old_regs->r9, &old_unat); 10367f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[10-1], ms->pmsa_nat_bits, &old_regs->r10, &old_unat); 10377f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[11-1], ms->pmsa_nat_bits, &old_regs->r11, &old_unat); 10387f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[12-1], ms->pmsa_nat_bits, &old_regs->r12, &old_unat); 10397f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[13-1], ms->pmsa_nat_bits, &old_regs->r13, &old_unat); 10407f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[14-1], ms->pmsa_nat_bits, &old_regs->r14, &old_unat); 10417f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[15-1], ms->pmsa_nat_bits, &old_regs->r15, &old_unat); 10427f613c7dSKeith Owens if (ia64_psr(old_regs)->bn) 10437f613c7dSKeith Owens bank = ms->pmsa_bank1_gr; 10447f613c7dSKeith Owens else 10457f613c7dSKeith Owens bank = ms->pmsa_bank0_gr; 10467f613c7dSKeith Owens copy_reg(&bank[16-16], ms->pmsa_nat_bits, &old_regs->r16, &old_unat); 10477f613c7dSKeith Owens copy_reg(&bank[17-16], ms->pmsa_nat_bits, &old_regs->r17, &old_unat); 10487f613c7dSKeith Owens copy_reg(&bank[18-16], ms->pmsa_nat_bits, &old_regs->r18, &old_unat); 10497f613c7dSKeith Owens copy_reg(&bank[19-16], ms->pmsa_nat_bits, &old_regs->r19, &old_unat); 10507f613c7dSKeith Owens copy_reg(&bank[20-16], ms->pmsa_nat_bits, &old_regs->r20, &old_unat); 10517f613c7dSKeith Owens copy_reg(&bank[21-16], ms->pmsa_nat_bits, &old_regs->r21, &old_unat); 10527f613c7dSKeith Owens copy_reg(&bank[22-16], ms->pmsa_nat_bits, &old_regs->r22, &old_unat); 10537f613c7dSKeith Owens copy_reg(&bank[23-16], ms->pmsa_nat_bits, &old_regs->r23, &old_unat); 10547f613c7dSKeith Owens copy_reg(&bank[24-16], ms->pmsa_nat_bits, &old_regs->r24, &old_unat); 10557f613c7dSKeith Owens copy_reg(&bank[25-16], ms->pmsa_nat_bits, &old_regs->r25, &old_unat); 10567f613c7dSKeith Owens copy_reg(&bank[26-16], ms->pmsa_nat_bits, &old_regs->r26, &old_unat); 10577f613c7dSKeith Owens copy_reg(&bank[27-16], ms->pmsa_nat_bits, &old_regs->r27, &old_unat); 10587f613c7dSKeith Owens copy_reg(&bank[28-16], ms->pmsa_nat_bits, &old_regs->r28, &old_unat); 10597f613c7dSKeith Owens copy_reg(&bank[29-16], ms->pmsa_nat_bits, &old_regs->r29, &old_unat); 10607f613c7dSKeith Owens copy_reg(&bank[30-16], ms->pmsa_nat_bits, &old_regs->r30, &old_unat); 10617f613c7dSKeith Owens copy_reg(&bank[31-16], ms->pmsa_nat_bits, &old_regs->r31, &old_unat); 10627f613c7dSKeith Owens 10637f613c7dSKeith Owens /* Next stack a struct switch_stack. mca_asm.S built a partial 10647f613c7dSKeith Owens * switch_stack, copy it and fill in the blanks using pt_regs and 10657f613c7dSKeith Owens * minstate. 10667f613c7dSKeith Owens * 10677f613c7dSKeith Owens * In the synthesized switch_stack, b0 points to ia64_leave_kernel, 10687f613c7dSKeith Owens * ar.pfs is set to 0. 10697f613c7dSKeith Owens * 10707f613c7dSKeith Owens * unwind.c::unw_unwind() does special processing for interrupt frames. 10717f613c7dSKeith Owens * It checks if the PRED_NON_SYSCALL predicate is set, if the predicate 10727f613c7dSKeith Owens * is clear then unw_unwind() does _not_ adjust bsp over pt_regs. Not 10737f613c7dSKeith Owens * that this is documented, of course. Set PRED_NON_SYSCALL in the 10747f613c7dSKeith Owens * switch_stack on the original stack so it will unwind correctly when 10757f613c7dSKeith Owens * unwind.c reads pt_regs. 10767f613c7dSKeith Owens * 10777f613c7dSKeith Owens * thread.ksp is updated to point to the synthesized switch_stack. 10787f613c7dSKeith Owens */ 10797f613c7dSKeith Owens p -= sizeof(struct switch_stack); 10807f613c7dSKeith Owens old_sw = (struct switch_stack *)p; 10817f613c7dSKeith Owens memcpy(old_sw, sw, sizeof(*sw)); 10827f613c7dSKeith Owens old_sw->caller_unat = old_unat; 10837f613c7dSKeith Owens old_sw->ar_fpsr = old_regs->ar_fpsr; 10847f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[4-1], ms->pmsa_nat_bits, &old_sw->r4, &old_unat); 10857f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[5-1], ms->pmsa_nat_bits, &old_sw->r5, &old_unat); 10867f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[6-1], ms->pmsa_nat_bits, &old_sw->r6, &old_unat); 10877f613c7dSKeith Owens copy_reg(&ms->pmsa_gr[7-1], ms->pmsa_nat_bits, &old_sw->r7, &old_unat); 10887f613c7dSKeith Owens old_sw->b0 = (u64)ia64_leave_kernel; 10897f613c7dSKeith Owens old_sw->b1 = ms->pmsa_br1; 10907f613c7dSKeith Owens old_sw->ar_pfs = 0; 10917f613c7dSKeith Owens old_sw->ar_unat = old_unat; 10927f613c7dSKeith Owens old_sw->pr = old_regs->pr | (1UL << PRED_NON_SYSCALL); 10937f613c7dSKeith Owens previous_current->thread.ksp = (u64)p - 16; 10947f613c7dSKeith Owens 10957f613c7dSKeith Owens /* Finally copy the original stack's registers back to its RBS. 10967f613c7dSKeith Owens * Registers from ar.bspstore through ar.bsp at the time of the event 10977f613c7dSKeith Owens * are in the current RBS, copy them back to the original stack. The 10987f613c7dSKeith Owens * copy must be done register by register because the original bspstore 10997f613c7dSKeith Owens * and the current one have different alignments, so the saved RNAT 11007f613c7dSKeith Owens * data occurs at different places. 11017f613c7dSKeith Owens * 11027f613c7dSKeith Owens * mca_asm does cover, so the old_bsp already includes all registers at 11037f613c7dSKeith Owens * the time of MCA/INIT. It also does flushrs, so all registers before 11047f613c7dSKeith Owens * this function have been written to backing store on the MCA/INIT 11057f613c7dSKeith Owens * stack. 11067f613c7dSKeith Owens */ 11077f613c7dSKeith Owens new_rnat = ia64_get_rnat(ia64_rse_rnat_addr(new_bspstore)); 11087f613c7dSKeith Owens old_rnat = regs->ar_rnat; 11097f613c7dSKeith Owens while (slots--) { 11107f613c7dSKeith Owens if (ia64_rse_is_rnat_slot(new_bspstore)) { 11117f613c7dSKeith Owens new_rnat = ia64_get_rnat(new_bspstore++); 11127f613c7dSKeith Owens } 11137f613c7dSKeith Owens if (ia64_rse_is_rnat_slot(old_bspstore)) { 11147f613c7dSKeith Owens *old_bspstore++ = old_rnat; 11157f613c7dSKeith Owens old_rnat = 0; 11167f613c7dSKeith Owens } 11177f613c7dSKeith Owens nat = (new_rnat >> ia64_rse_slot_num(new_bspstore)) & 1UL; 11187f613c7dSKeith Owens old_rnat &= ~(1UL << ia64_rse_slot_num(old_bspstore)); 11197f613c7dSKeith Owens old_rnat |= (nat << ia64_rse_slot_num(old_bspstore)); 11207f613c7dSKeith Owens *old_bspstore++ = *new_bspstore++; 11217f613c7dSKeith Owens } 11227f613c7dSKeith Owens old_sw->ar_bspstore = (unsigned long)old_bspstore; 11237f613c7dSKeith Owens old_sw->ar_rnat = old_rnat; 11247f613c7dSKeith Owens 11257f613c7dSKeith Owens sos->prev_task = previous_current; 11267f613c7dSKeith Owens return previous_current; 11277f613c7dSKeith Owens 11287f613c7dSKeith Owens no_mod: 11297f613c7dSKeith Owens printk(KERN_INFO "cpu %d, %s %s, original stack not modified\n", 11307f613c7dSKeith Owens smp_processor_id(), type, msg); 11317f613c7dSKeith Owens return previous_current; 11327f613c7dSKeith Owens } 11337f613c7dSKeith Owens 11347f613c7dSKeith Owens /* The monarch/slave interaction is based on monarch_cpu and requires that all 11357f613c7dSKeith Owens * slaves have entered rendezvous before the monarch leaves. If any cpu has 11367f613c7dSKeith Owens * not entered rendezvous yet then wait a bit. The assumption is that any 11377f613c7dSKeith Owens * slave that has not rendezvoused after a reasonable time is never going to do 11387f613c7dSKeith Owens * so. In this context, slave includes cpus that respond to the MCA rendezvous 11397f613c7dSKeith Owens * interrupt, as well as cpus that receive the INIT slave event. 11407f613c7dSKeith Owens */ 11417f613c7dSKeith Owens 11427f613c7dSKeith Owens static void 1143356a5c1cSKeith Owens ia64_wait_for_slaves(int monarch, const char *type) 11447f613c7dSKeith Owens { 11452bc5c282SRuss Anderson int c, i , wait; 11462bc5c282SRuss Anderson 11472bc5c282SRuss Anderson /* 11482bc5c282SRuss Anderson * wait 5 seconds total for slaves (arbitrary) 11492bc5c282SRuss Anderson */ 11502bc5c282SRuss Anderson for (i = 0; i < 5000; i++) { 11512bc5c282SRuss Anderson wait = 0; 11527f613c7dSKeith Owens for_each_online_cpu(c) { 11537f613c7dSKeith Owens if (c == monarch) 11547f613c7dSKeith Owens continue; 11552bc5c282SRuss Anderson if (ia64_mc_info.imi_rendez_checkin[c] 11562bc5c282SRuss Anderson == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) { 11572bc5c282SRuss Anderson udelay(1000); /* short wait */ 11587f613c7dSKeith Owens wait = 1; 11597f613c7dSKeith Owens break; 11607f613c7dSKeith Owens } 11617f613c7dSKeith Owens } 11627f613c7dSKeith Owens if (!wait) 11639336b083SKeith Owens goto all_in; 11647f613c7dSKeith Owens } 11652bc5c282SRuss Anderson 116643ed3bafSHidetoshi Seto /* 116743ed3bafSHidetoshi Seto * Maybe slave(s) dead. Print buffered messages immediately. 116843ed3bafSHidetoshi Seto */ 116943ed3bafSHidetoshi Seto ia64_mlogbuf_finish(0); 117043ed3bafSHidetoshi Seto mprintk(KERN_INFO "OS %s slave did not rendezvous on cpu", type); 11719336b083SKeith Owens for_each_online_cpu(c) { 11729336b083SKeith Owens if (c == monarch) 11739336b083SKeith Owens continue; 11749336b083SKeith Owens if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) 117543ed3bafSHidetoshi Seto mprintk(" %d", c); 11769336b083SKeith Owens } 117743ed3bafSHidetoshi Seto mprintk("\n"); 11789336b083SKeith Owens return; 11799336b083SKeith Owens 11809336b083SKeith Owens all_in: 118143ed3bafSHidetoshi Seto mprintk(KERN_INFO "All OS %s slaves have reached rendezvous\n", type); 11829336b083SKeith Owens return; 11837f613c7dSKeith Owens } 11847f613c7dSKeith Owens 11851da177e4SLinus Torvalds /* 11867f613c7dSKeith Owens * ia64_mca_handler 11871da177e4SLinus Torvalds * 11881da177e4SLinus Torvalds * This is uncorrectable machine check handler called from OS_MCA 11891da177e4SLinus Torvalds * dispatch code which is in turn called from SAL_CHECK(). 11901da177e4SLinus Torvalds * This is the place where the core of OS MCA handling is done. 11911da177e4SLinus Torvalds * Right now the logs are extracted and displayed in a well-defined 11921da177e4SLinus Torvalds * format. This handler code is supposed to be run only on the 11931da177e4SLinus Torvalds * monarch processor. Once the monarch is done with MCA handling 11941da177e4SLinus Torvalds * further MCA logging is enabled by clearing logs. 11951da177e4SLinus Torvalds * Monarch also has the duty of sending wakeup-IPIs to pull the 11961da177e4SLinus Torvalds * slave processors out of rendezvous spinloop. 11971612b18cSRuss Anderson * 11981612b18cSRuss Anderson * If multiple processors call into OS_MCA, the first will become 11991612b18cSRuss Anderson * the monarch. Subsequent cpus will be recorded in the mca_cpu 12001612b18cSRuss Anderson * bitmask. After the first monarch has processed its MCA, it 12011612b18cSRuss Anderson * will wake up the next cpu in the mca_cpu bitmask and then go 12021612b18cSRuss Anderson * into the rendezvous loop. When all processors have serviced 12031612b18cSRuss Anderson * their MCA, the last monarch frees up the rest of the processors. 12041da177e4SLinus Torvalds */ 12051da177e4SLinus Torvalds void 12067f613c7dSKeith Owens ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw, 12077f613c7dSKeith Owens struct ia64_sal_os_state *sos) 12081da177e4SLinus Torvalds { 12097f613c7dSKeith Owens int recover, cpu = smp_processor_id(); 121036c8b586SIngo Molnar struct task_struct *previous_current; 1211958b166cSKeith Owens struct ia64_mca_notify_die nd = 1212958b166cSKeith Owens { .sos = sos, .monarch_cpu = &monarch_cpu }; 12131612b18cSRuss Anderson static atomic_t mca_count; 12141612b18cSRuss Anderson static cpumask_t mca_cpu; 12157f613c7dSKeith Owens 12161612b18cSRuss Anderson if (atomic_add_return(1, &mca_count) == 1) { 12171612b18cSRuss Anderson monarch_cpu = cpu; 12181612b18cSRuss Anderson sos->monarch = 1; 12191612b18cSRuss Anderson } else { 12201612b18cSRuss Anderson cpu_set(cpu, mca_cpu); 12211612b18cSRuss Anderson sos->monarch = 0; 12221612b18cSRuss Anderson } 122343ed3bafSHidetoshi Seto mprintk(KERN_INFO "Entered OS MCA handler. PSP=%lx cpu=%d " 122443ed3bafSHidetoshi Seto "monarch=%ld\n", sos->proc_state_param, cpu, sos->monarch); 12259336b083SKeith Owens 12267f613c7dSKeith Owens previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "MCA"); 12271612b18cSRuss Anderson 1228958b166cSKeith Owens if (notify_die(DIE_MCA_MONARCH_ENTER, "MCA", regs, (long)&nd, 0, 0) 12299138d581SKeith Owens == NOTIFY_STOP) 1230*d4ed8084SHarvey Harrison ia64_mca_spin(__func__); 1231e1b1eb01SRuss Anderson 1232e1b1eb01SRuss Anderson ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_CONCURRENT_MCA; 12331612b18cSRuss Anderson if (sos->monarch) { 1234356a5c1cSKeith Owens ia64_wait_for_slaves(cpu, "MCA"); 12357f613c7dSKeith Owens 1236e1b1eb01SRuss Anderson /* Wakeup all the processors which are spinning in the 1237e1b1eb01SRuss Anderson * rendezvous loop. They will leave SAL, then spin in the OS 1238e1b1eb01SRuss Anderson * with interrupts disabled until this monarch cpu leaves the 1239e1b1eb01SRuss Anderson * MCA handler. That gets control back to the OS so we can 1240e1b1eb01SRuss Anderson * backtrace the other cpus, backtrace when spinning in SAL 1241e1b1eb01SRuss Anderson * does not work. 12427f613c7dSKeith Owens */ 12437f613c7dSKeith Owens ia64_mca_wakeup_all(); 1244958b166cSKeith Owens if (notify_die(DIE_MCA_MONARCH_PROCESS, "MCA", regs, (long)&nd, 0, 0) 12459138d581SKeith Owens == NOTIFY_STOP) 1246*d4ed8084SHarvey Harrison ia64_mca_spin(__func__); 1247e1b1eb01SRuss Anderson } else { 1248e1b1eb01SRuss Anderson while (cpu_isset(cpu, mca_cpu)) 1249e1b1eb01SRuss Anderson cpu_relax(); /* spin until monarch wakes us */ 1250e1b1eb01SRuss Anderson } 12511da177e4SLinus Torvalds 12521da177e4SLinus Torvalds /* Get the MCA error record and log it */ 12531da177e4SLinus Torvalds ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA); 12541da177e4SLinus Torvalds 1255618b206fSRuss Anderson /* MCA error recovery */ 1256618b206fSRuss Anderson recover = (ia64_mca_ucmc_extension 12571da177e4SLinus Torvalds && ia64_mca_ucmc_extension( 12581da177e4SLinus Torvalds IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA), 12597f613c7dSKeith Owens sos)); 12601da177e4SLinus Torvalds 12611da177e4SLinus Torvalds if (recover) { 12621da177e4SLinus Torvalds sal_log_record_header_t *rh = IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA); 12631da177e4SLinus Torvalds rh->severity = sal_log_severity_corrected; 12641da177e4SLinus Torvalds ia64_sal_clear_state_info(SAL_INFO_TYPE_MCA); 12657f613c7dSKeith Owens sos->os_status = IA64_MCA_CORRECTED; 126643ed3bafSHidetoshi Seto } else { 126743ed3bafSHidetoshi Seto /* Dump buffered message to console */ 126843ed3bafSHidetoshi Seto ia64_mlogbuf_finish(1); 126945a98fc6SHorms #ifdef CONFIG_KEXEC 1270a7956113SZou Nan hai atomic_set(&kdump_in_progress, 1); 1271a7956113SZou Nan hai monarch_cpu = -1; 1272a7956113SZou Nan hai #endif 12731da177e4SLinus Torvalds } 1274958b166cSKeith Owens if (notify_die(DIE_MCA_MONARCH_LEAVE, "MCA", regs, (long)&nd, 0, recover) 12759138d581SKeith Owens == NOTIFY_STOP) 1276*d4ed8084SHarvey Harrison ia64_mca_spin(__func__); 12771da177e4SLinus Torvalds 12781612b18cSRuss Anderson 12791612b18cSRuss Anderson if (atomic_dec_return(&mca_count) > 0) { 12801612b18cSRuss Anderson int i; 12811612b18cSRuss Anderson 12821612b18cSRuss Anderson /* wake up the next monarch cpu, 12831612b18cSRuss Anderson * and put this cpu in the rendez loop. 12841612b18cSRuss Anderson */ 12851612b18cSRuss Anderson for_each_online_cpu(i) { 12861612b18cSRuss Anderson if (cpu_isset(i, mca_cpu)) { 12871612b18cSRuss Anderson monarch_cpu = i; 12881612b18cSRuss Anderson cpu_clear(i, mca_cpu); /* wake next cpu */ 12891612b18cSRuss Anderson while (monarch_cpu != -1) 12901612b18cSRuss Anderson cpu_relax(); /* spin until last cpu leaves */ 12911612b18cSRuss Anderson set_curr_task(cpu, previous_current); 1292e1b1eb01SRuss Anderson ia64_mc_info.imi_rendez_checkin[cpu] 1293e1b1eb01SRuss Anderson = IA64_MCA_RENDEZ_CHECKIN_NOTDONE; 12941612b18cSRuss Anderson return; 12951612b18cSRuss Anderson } 12961612b18cSRuss Anderson } 12971612b18cSRuss Anderson } 12987f613c7dSKeith Owens set_curr_task(cpu, previous_current); 1299e1b1eb01SRuss Anderson ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE; 1300e1b1eb01SRuss Anderson monarch_cpu = -1; /* This frees the slaves and previous monarchs */ 13011da177e4SLinus Torvalds } 13021da177e4SLinus Torvalds 13036d5aefb8SDavid Howells static DECLARE_WORK(cmc_disable_work, ia64_mca_cmc_vector_disable_keventd); 13046d5aefb8SDavid Howells static DECLARE_WORK(cmc_enable_work, ia64_mca_cmc_vector_enable_keventd); 13051da177e4SLinus Torvalds 13061da177e4SLinus Torvalds /* 13071da177e4SLinus Torvalds * ia64_mca_cmc_int_handler 13081da177e4SLinus Torvalds * 13091da177e4SLinus Torvalds * This is corrected machine check interrupt handler. 13101da177e4SLinus Torvalds * Right now the logs are extracted and displayed in a well-defined 13111da177e4SLinus Torvalds * format. 13121da177e4SLinus Torvalds * 13131da177e4SLinus Torvalds * Inputs 13141da177e4SLinus Torvalds * interrupt number 13151da177e4SLinus Torvalds * client data arg ptr 13161da177e4SLinus Torvalds * 13171da177e4SLinus Torvalds * Outputs 13181da177e4SLinus Torvalds * None 13191da177e4SLinus Torvalds */ 13201da177e4SLinus Torvalds static irqreturn_t 13217d12e780SDavid Howells ia64_mca_cmc_int_handler(int cmc_irq, void *arg) 13221da177e4SLinus Torvalds { 13231da177e4SLinus Torvalds static unsigned long cmc_history[CMC_HISTORY_LENGTH]; 13241da177e4SLinus Torvalds static int index; 13251da177e4SLinus Torvalds static DEFINE_SPINLOCK(cmc_history_lock); 13261da177e4SLinus Torvalds 13271da177e4SLinus Torvalds IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n", 1328*d4ed8084SHarvey Harrison __func__, cmc_irq, smp_processor_id()); 13291da177e4SLinus Torvalds 13301da177e4SLinus Torvalds /* SAL spec states this should run w/ interrupts enabled */ 13311da177e4SLinus Torvalds local_irq_enable(); 13321da177e4SLinus Torvalds 13331da177e4SLinus Torvalds spin_lock(&cmc_history_lock); 13341da177e4SLinus Torvalds if (!cmc_polling_enabled) { 13351da177e4SLinus Torvalds int i, count = 1; /* we know 1 happened now */ 13361da177e4SLinus Torvalds unsigned long now = jiffies; 13371da177e4SLinus Torvalds 13381da177e4SLinus Torvalds for (i = 0; i < CMC_HISTORY_LENGTH; i++) { 13391da177e4SLinus Torvalds if (now - cmc_history[i] <= HZ) 13401da177e4SLinus Torvalds count++; 13411da177e4SLinus Torvalds } 13421da177e4SLinus Torvalds 13431da177e4SLinus Torvalds IA64_MCA_DEBUG(KERN_INFO "CMC threshold %d/%d\n", count, CMC_HISTORY_LENGTH); 13441da177e4SLinus Torvalds if (count >= CMC_HISTORY_LENGTH) { 13451da177e4SLinus Torvalds 13461da177e4SLinus Torvalds cmc_polling_enabled = 1; 13471da177e4SLinus Torvalds spin_unlock(&cmc_history_lock); 134876e677e2SBryan Sutula /* If we're being hit with CMC interrupts, we won't 134976e677e2SBryan Sutula * ever execute the schedule_work() below. Need to 135076e677e2SBryan Sutula * disable CMC interrupts on this processor now. 135176e677e2SBryan Sutula */ 135276e677e2SBryan Sutula ia64_mca_cmc_vector_disable(NULL); 13531da177e4SLinus Torvalds schedule_work(&cmc_disable_work); 13541da177e4SLinus Torvalds 13551da177e4SLinus Torvalds /* 13561da177e4SLinus Torvalds * Corrected errors will still be corrected, but 13571da177e4SLinus Torvalds * make sure there's a log somewhere that indicates 13581da177e4SLinus Torvalds * something is generating more than we can handle. 13591da177e4SLinus Torvalds */ 13601da177e4SLinus Torvalds printk(KERN_WARNING "WARNING: Switching to polling CMC handler; error records may be lost\n"); 13611da177e4SLinus Torvalds 13621da177e4SLinus Torvalds mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL); 13631da177e4SLinus Torvalds 13641da177e4SLinus Torvalds /* lock already released, get out now */ 1365ddb4f0dfSHidetoshi Seto goto out; 13661da177e4SLinus Torvalds } else { 13671da177e4SLinus Torvalds cmc_history[index++] = now; 13681da177e4SLinus Torvalds if (index == CMC_HISTORY_LENGTH) 13691da177e4SLinus Torvalds index = 0; 13701da177e4SLinus Torvalds } 13711da177e4SLinus Torvalds } 13721da177e4SLinus Torvalds spin_unlock(&cmc_history_lock); 1373ddb4f0dfSHidetoshi Seto out: 1374ddb4f0dfSHidetoshi Seto /* Get the CMC error record and log it */ 1375ddb4f0dfSHidetoshi Seto ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC); 1376ddb4f0dfSHidetoshi Seto 13771da177e4SLinus Torvalds return IRQ_HANDLED; 13781da177e4SLinus Torvalds } 13791da177e4SLinus Torvalds 13801da177e4SLinus Torvalds /* 13811da177e4SLinus Torvalds * ia64_mca_cmc_int_caller 13821da177e4SLinus Torvalds * 13831da177e4SLinus Torvalds * Triggered by sw interrupt from CMC polling routine. Calls 13841da177e4SLinus Torvalds * real interrupt handler and either triggers a sw interrupt 13851da177e4SLinus Torvalds * on the next cpu or does cleanup at the end. 13861da177e4SLinus Torvalds * 13871da177e4SLinus Torvalds * Inputs 13881da177e4SLinus Torvalds * interrupt number 13891da177e4SLinus Torvalds * client data arg ptr 13901da177e4SLinus Torvalds * Outputs 13911da177e4SLinus Torvalds * handled 13921da177e4SLinus Torvalds */ 13931da177e4SLinus Torvalds static irqreturn_t 13947d12e780SDavid Howells ia64_mca_cmc_int_caller(int cmc_irq, void *arg) 13951da177e4SLinus Torvalds { 13961da177e4SLinus Torvalds static int start_count = -1; 13971da177e4SLinus Torvalds unsigned int cpuid; 13981da177e4SLinus Torvalds 13991da177e4SLinus Torvalds cpuid = smp_processor_id(); 14001da177e4SLinus Torvalds 14011da177e4SLinus Torvalds /* If first cpu, update count */ 14021da177e4SLinus Torvalds if (start_count == -1) 14031da177e4SLinus Torvalds start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CMC); 14041da177e4SLinus Torvalds 14057d12e780SDavid Howells ia64_mca_cmc_int_handler(cmc_irq, arg); 14061da177e4SLinus Torvalds 14071da177e4SLinus Torvalds for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++); 14081da177e4SLinus Torvalds 14091da177e4SLinus Torvalds if (cpuid < NR_CPUS) { 14101da177e4SLinus Torvalds platform_send_ipi(cpuid, IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0); 14111da177e4SLinus Torvalds } else { 14121da177e4SLinus Torvalds /* If no log record, switch out of polling mode */ 14131da177e4SLinus Torvalds if (start_count == IA64_LOG_COUNT(SAL_INFO_TYPE_CMC)) { 14141da177e4SLinus Torvalds 14151da177e4SLinus Torvalds printk(KERN_WARNING "Returning to interrupt driven CMC handler\n"); 14161da177e4SLinus Torvalds schedule_work(&cmc_enable_work); 14171da177e4SLinus Torvalds cmc_polling_enabled = 0; 14181da177e4SLinus Torvalds 14191da177e4SLinus Torvalds } else { 14201da177e4SLinus Torvalds 14211da177e4SLinus Torvalds mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL); 14221da177e4SLinus Torvalds } 14231da177e4SLinus Torvalds 14241da177e4SLinus Torvalds start_count = -1; 14251da177e4SLinus Torvalds } 14261da177e4SLinus Torvalds 14271da177e4SLinus Torvalds return IRQ_HANDLED; 14281da177e4SLinus Torvalds } 14291da177e4SLinus Torvalds 14301da177e4SLinus Torvalds /* 14311da177e4SLinus Torvalds * ia64_mca_cmc_poll 14321da177e4SLinus Torvalds * 14331da177e4SLinus Torvalds * Poll for Corrected Machine Checks (CMCs) 14341da177e4SLinus Torvalds * 14351da177e4SLinus Torvalds * Inputs : dummy(unused) 14361da177e4SLinus Torvalds * Outputs : None 14371da177e4SLinus Torvalds * 14381da177e4SLinus Torvalds */ 14391da177e4SLinus Torvalds static void 14401da177e4SLinus Torvalds ia64_mca_cmc_poll (unsigned long dummy) 14411da177e4SLinus Torvalds { 14421da177e4SLinus Torvalds /* Trigger a CMC interrupt cascade */ 14431da177e4SLinus Torvalds platform_send_ipi(first_cpu(cpu_online_map), IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0); 14441da177e4SLinus Torvalds } 14451da177e4SLinus Torvalds 14461da177e4SLinus Torvalds /* 14471da177e4SLinus Torvalds * ia64_mca_cpe_int_caller 14481da177e4SLinus Torvalds * 14491da177e4SLinus Torvalds * Triggered by sw interrupt from CPE polling routine. Calls 14501da177e4SLinus Torvalds * real interrupt handler and either triggers a sw interrupt 14511da177e4SLinus Torvalds * on the next cpu or does cleanup at the end. 14521da177e4SLinus Torvalds * 14531da177e4SLinus Torvalds * Inputs 14541da177e4SLinus Torvalds * interrupt number 14551da177e4SLinus Torvalds * client data arg ptr 14561da177e4SLinus Torvalds * Outputs 14571da177e4SLinus Torvalds * handled 14581da177e4SLinus Torvalds */ 14591da177e4SLinus Torvalds #ifdef CONFIG_ACPI 14601da177e4SLinus Torvalds 14611da177e4SLinus Torvalds static irqreturn_t 14627d12e780SDavid Howells ia64_mca_cpe_int_caller(int cpe_irq, void *arg) 14631da177e4SLinus Torvalds { 14641da177e4SLinus Torvalds static int start_count = -1; 14651da177e4SLinus Torvalds static int poll_time = MIN_CPE_POLL_INTERVAL; 14661da177e4SLinus Torvalds unsigned int cpuid; 14671da177e4SLinus Torvalds 14681da177e4SLinus Torvalds cpuid = smp_processor_id(); 14691da177e4SLinus Torvalds 14701da177e4SLinus Torvalds /* If first cpu, update count */ 14711da177e4SLinus Torvalds if (start_count == -1) 14721da177e4SLinus Torvalds start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CPE); 14731da177e4SLinus Torvalds 14747d12e780SDavid Howells ia64_mca_cpe_int_handler(cpe_irq, arg); 14751da177e4SLinus Torvalds 14761da177e4SLinus Torvalds for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++); 14771da177e4SLinus Torvalds 14781da177e4SLinus Torvalds if (cpuid < NR_CPUS) { 14791da177e4SLinus Torvalds platform_send_ipi(cpuid, IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0); 14801da177e4SLinus Torvalds } else { 14811da177e4SLinus Torvalds /* 14821da177e4SLinus Torvalds * If a log was recorded, increase our polling frequency, 14831da177e4SLinus Torvalds * otherwise, backoff or return to interrupt mode. 14841da177e4SLinus Torvalds */ 14851da177e4SLinus Torvalds if (start_count != IA64_LOG_COUNT(SAL_INFO_TYPE_CPE)) { 14861da177e4SLinus Torvalds poll_time = max(MIN_CPE_POLL_INTERVAL, poll_time / 2); 14871da177e4SLinus Torvalds } else if (cpe_vector < 0) { 14881da177e4SLinus Torvalds poll_time = min(MAX_CPE_POLL_INTERVAL, poll_time * 2); 14891da177e4SLinus Torvalds } else { 14901da177e4SLinus Torvalds poll_time = MIN_CPE_POLL_INTERVAL; 14911da177e4SLinus Torvalds 14921da177e4SLinus Torvalds printk(KERN_WARNING "Returning to interrupt driven CPE handler\n"); 14931da177e4SLinus Torvalds enable_irq(local_vector_to_irq(IA64_CPE_VECTOR)); 14941da177e4SLinus Torvalds cpe_poll_enabled = 0; 14951da177e4SLinus Torvalds } 14961da177e4SLinus Torvalds 14971da177e4SLinus Torvalds if (cpe_poll_enabled) 14981da177e4SLinus Torvalds mod_timer(&cpe_poll_timer, jiffies + poll_time); 14991da177e4SLinus Torvalds start_count = -1; 15001da177e4SLinus Torvalds } 15011da177e4SLinus Torvalds 15021da177e4SLinus Torvalds return IRQ_HANDLED; 15031da177e4SLinus Torvalds } 15041da177e4SLinus Torvalds 15051da177e4SLinus Torvalds /* 15061da177e4SLinus Torvalds * ia64_mca_cpe_poll 15071da177e4SLinus Torvalds * 15081da177e4SLinus Torvalds * Poll for Corrected Platform Errors (CPEs), trigger interrupt 15091da177e4SLinus Torvalds * on first cpu, from there it will trickle through all the cpus. 15101da177e4SLinus Torvalds * 15111da177e4SLinus Torvalds * Inputs : dummy(unused) 15121da177e4SLinus Torvalds * Outputs : None 15131da177e4SLinus Torvalds * 15141da177e4SLinus Torvalds */ 15151da177e4SLinus Torvalds static void 15161da177e4SLinus Torvalds ia64_mca_cpe_poll (unsigned long dummy) 15171da177e4SLinus Torvalds { 15181da177e4SLinus Torvalds /* Trigger a CPE interrupt cascade */ 15191da177e4SLinus Torvalds platform_send_ipi(first_cpu(cpu_online_map), IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0); 15201da177e4SLinus Torvalds } 15211da177e4SLinus Torvalds 1522b655913bSPeter Chubb #endif /* CONFIG_ACPI */ 1523b655913bSPeter Chubb 15249138d581SKeith Owens static int 15259138d581SKeith Owens default_monarch_init_process(struct notifier_block *self, unsigned long val, void *data) 15269138d581SKeith Owens { 15279138d581SKeith Owens int c; 15289138d581SKeith Owens struct task_struct *g, *t; 15299138d581SKeith Owens if (val != DIE_INIT_MONARCH_PROCESS) 15309138d581SKeith Owens return NOTIFY_DONE; 1531311f594dSJay Lan #ifdef CONFIG_KEXEC 1532311f594dSJay Lan if (atomic_read(&kdump_in_progress)) 1533311f594dSJay Lan return NOTIFY_DONE; 1534311f594dSJay Lan #endif 153543ed3bafSHidetoshi Seto 153643ed3bafSHidetoshi Seto /* 153743ed3bafSHidetoshi Seto * FIXME: mlogbuf will brim over with INIT stack dumps. 153843ed3bafSHidetoshi Seto * To enable show_stack from INIT, we use oops_in_progress which should 153943ed3bafSHidetoshi Seto * be used in real oops. This would cause something wrong after INIT. 154043ed3bafSHidetoshi Seto */ 154143ed3bafSHidetoshi Seto BREAK_LOGLEVEL(console_loglevel); 154243ed3bafSHidetoshi Seto ia64_mlogbuf_dump_from_init(); 154343ed3bafSHidetoshi Seto 15449138d581SKeith Owens printk(KERN_ERR "Processes interrupted by INIT -"); 15459138d581SKeith Owens for_each_online_cpu(c) { 15469138d581SKeith Owens struct ia64_sal_os_state *s; 15479138d581SKeith Owens t = __va(__per_cpu_mca[c] + IA64_MCA_CPU_INIT_STACK_OFFSET); 15489138d581SKeith Owens s = (struct ia64_sal_os_state *)((char *)t + MCA_SOS_OFFSET); 15499138d581SKeith Owens g = s->prev_task; 15509138d581SKeith Owens if (g) { 15519138d581SKeith Owens if (g->pid) 15529138d581SKeith Owens printk(" %d", g->pid); 15539138d581SKeith Owens else 15549138d581SKeith Owens printk(" %d (cpu %d task 0x%p)", g->pid, task_cpu(g), g); 15559138d581SKeith Owens } 15569138d581SKeith Owens } 15579138d581SKeith Owens printk("\n\n"); 15589138d581SKeith Owens if (read_trylock(&tasklist_lock)) { 15599138d581SKeith Owens do_each_thread (g, t) { 15609138d581SKeith Owens printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm); 15619138d581SKeith Owens show_stack(t, NULL); 15629138d581SKeith Owens } while_each_thread (g, t); 15639138d581SKeith Owens read_unlock(&tasklist_lock); 15649138d581SKeith Owens } 156543ed3bafSHidetoshi Seto /* FIXME: This will not restore zapped printk locks. */ 156643ed3bafSHidetoshi Seto RESTORE_LOGLEVEL(console_loglevel); 15679138d581SKeith Owens return NOTIFY_DONE; 15689138d581SKeith Owens } 15699138d581SKeith Owens 15701da177e4SLinus Torvalds /* 15711da177e4SLinus Torvalds * C portion of the OS INIT handler 15721da177e4SLinus Torvalds * 15737f613c7dSKeith Owens * Called from ia64_os_init_dispatch 15741da177e4SLinus Torvalds * 15757f613c7dSKeith Owens * Inputs: pointer to pt_regs where processor info was saved. SAL/OS state for 15767f613c7dSKeith Owens * this event. This code is used for both monarch and slave INIT events, see 15777f613c7dSKeith Owens * sos->monarch. 15781da177e4SLinus Torvalds * 15797f613c7dSKeith Owens * All INIT events switch to the INIT stack and change the previous process to 15807f613c7dSKeith Owens * blocked status. If one of the INIT events is the monarch then we are 15817f613c7dSKeith Owens * probably processing the nmi button/command. Use the monarch cpu to dump all 15827f613c7dSKeith Owens * the processes. The slave INIT events all spin until the monarch cpu 15837f613c7dSKeith Owens * returns. We can also get INIT slave events for MCA, in which case the MCA 15847f613c7dSKeith Owens * process is the monarch. 15851da177e4SLinus Torvalds */ 15861da177e4SLinus Torvalds 15877f613c7dSKeith Owens void 15887f613c7dSKeith Owens ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw, 15897f613c7dSKeith Owens struct ia64_sal_os_state *sos) 15907f613c7dSKeith Owens { 15917f613c7dSKeith Owens static atomic_t slaves; 15927f613c7dSKeith Owens static atomic_t monarchs; 159336c8b586SIngo Molnar struct task_struct *previous_current; 15949138d581SKeith Owens int cpu = smp_processor_id(); 1595958b166cSKeith Owens struct ia64_mca_notify_die nd = 1596958b166cSKeith Owens { .sos = sos, .monarch_cpu = &monarch_cpu }; 15977f613c7dSKeith Owens 1598958b166cSKeith Owens (void) notify_die(DIE_INIT_ENTER, "INIT", regs, (long)&nd, 0, 0); 1599958b166cSKeith Owens 160043ed3bafSHidetoshi Seto mprintk(KERN_INFO "Entered OS INIT handler. PSP=%lx cpu=%d monarch=%ld\n", 16017f613c7dSKeith Owens sos->proc_state_param, cpu, sos->monarch); 16027f613c7dSKeith Owens salinfo_log_wakeup(SAL_INFO_TYPE_INIT, NULL, 0, 0); 16037f613c7dSKeith Owens 16047f613c7dSKeith Owens previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "INIT"); 16057f613c7dSKeith Owens sos->os_status = IA64_INIT_RESUME; 16067f613c7dSKeith Owens 16077f613c7dSKeith Owens /* FIXME: Workaround for broken proms that drive all INIT events as 16087f613c7dSKeith Owens * slaves. The last slave that enters is promoted to be a monarch. 16097f613c7dSKeith Owens * Remove this code in September 2006, that gives platforms a year to 16107f613c7dSKeith Owens * fix their proms and get their customers updated. 16117f613c7dSKeith Owens */ 16127f613c7dSKeith Owens if (!sos->monarch && atomic_add_return(1, &slaves) == num_online_cpus()) { 161343ed3bafSHidetoshi Seto mprintk(KERN_WARNING "%s: Promoting cpu %d to monarch.\n", 1614*d4ed8084SHarvey Harrison __func__, cpu); 16157f613c7dSKeith Owens atomic_dec(&slaves); 16167f613c7dSKeith Owens sos->monarch = 1; 16177f613c7dSKeith Owens } 16187f613c7dSKeith Owens 16197f613c7dSKeith Owens /* FIXME: Workaround for broken proms that drive all INIT events as 16207f613c7dSKeith Owens * monarchs. Second and subsequent monarchs are demoted to slaves. 16217f613c7dSKeith Owens * Remove this code in September 2006, that gives platforms a year to 16227f613c7dSKeith Owens * fix their proms and get their customers updated. 16237f613c7dSKeith Owens */ 16247f613c7dSKeith Owens if (sos->monarch && atomic_add_return(1, &monarchs) > 1) { 162543ed3bafSHidetoshi Seto mprintk(KERN_WARNING "%s: Demoting cpu %d to slave.\n", 1626*d4ed8084SHarvey Harrison __func__, cpu); 16277f613c7dSKeith Owens atomic_dec(&monarchs); 16287f613c7dSKeith Owens sos->monarch = 0; 16297f613c7dSKeith Owens } 16307f613c7dSKeith Owens 16317f613c7dSKeith Owens if (!sos->monarch) { 16327f613c7dSKeith Owens ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_INIT; 16337f613c7dSKeith Owens while (monarch_cpu == -1) 16347f613c7dSKeith Owens cpu_relax(); /* spin until monarch enters */ 1635958b166cSKeith Owens if (notify_die(DIE_INIT_SLAVE_ENTER, "INIT", regs, (long)&nd, 0, 0) 16369138d581SKeith Owens == NOTIFY_STOP) 1637*d4ed8084SHarvey Harrison ia64_mca_spin(__func__); 1638958b166cSKeith Owens if (notify_die(DIE_INIT_SLAVE_PROCESS, "INIT", regs, (long)&nd, 0, 0) 16399138d581SKeith Owens == NOTIFY_STOP) 1640*d4ed8084SHarvey Harrison ia64_mca_spin(__func__); 16417f613c7dSKeith Owens while (monarch_cpu != -1) 16427f613c7dSKeith Owens cpu_relax(); /* spin until monarch leaves */ 1643958b166cSKeith Owens if (notify_die(DIE_INIT_SLAVE_LEAVE, "INIT", regs, (long)&nd, 0, 0) 16449138d581SKeith Owens == NOTIFY_STOP) 1645*d4ed8084SHarvey Harrison ia64_mca_spin(__func__); 164643ed3bafSHidetoshi Seto mprintk("Slave on cpu %d returning to normal service.\n", cpu); 16477f613c7dSKeith Owens set_curr_task(cpu, previous_current); 16487f613c7dSKeith Owens ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE; 16497f613c7dSKeith Owens atomic_dec(&slaves); 16507f613c7dSKeith Owens return; 16517f613c7dSKeith Owens } 16527f613c7dSKeith Owens 16537f613c7dSKeith Owens monarch_cpu = cpu; 1654958b166cSKeith Owens if (notify_die(DIE_INIT_MONARCH_ENTER, "INIT", regs, (long)&nd, 0, 0) 16559138d581SKeith Owens == NOTIFY_STOP) 1656*d4ed8084SHarvey Harrison ia64_mca_spin(__func__); 16571da177e4SLinus Torvalds 16581da177e4SLinus Torvalds /* 16597f613c7dSKeith Owens * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be 16607f613c7dSKeith Owens * generated via the BMC's command-line interface, but since the console is on the 16617f613c7dSKeith Owens * same serial line, the user will need some time to switch out of the BMC before 16627f613c7dSKeith Owens * the dump begins. 16631da177e4SLinus Torvalds */ 166443ed3bafSHidetoshi Seto mprintk("Delaying for 5 seconds...\n"); 16657f613c7dSKeith Owens udelay(5*1000000); 1666356a5c1cSKeith Owens ia64_wait_for_slaves(cpu, "INIT"); 16679138d581SKeith Owens /* If nobody intercepts DIE_INIT_MONARCH_PROCESS then we drop through 16689138d581SKeith Owens * to default_monarch_init_process() above and just print all the 16699138d581SKeith Owens * tasks. 16709138d581SKeith Owens */ 1671958b166cSKeith Owens if (notify_die(DIE_INIT_MONARCH_PROCESS, "INIT", regs, (long)&nd, 0, 0) 16729138d581SKeith Owens == NOTIFY_STOP) 1673*d4ed8084SHarvey Harrison ia64_mca_spin(__func__); 1674958b166cSKeith Owens if (notify_die(DIE_INIT_MONARCH_LEAVE, "INIT", regs, (long)&nd, 0, 0) 16759138d581SKeith Owens == NOTIFY_STOP) 1676*d4ed8084SHarvey Harrison ia64_mca_spin(__func__); 167743ed3bafSHidetoshi Seto mprintk("\nINIT dump complete. Monarch on cpu %d returning to normal service.\n", cpu); 16787f613c7dSKeith Owens atomic_dec(&monarchs); 16797f613c7dSKeith Owens set_curr_task(cpu, previous_current); 16807f613c7dSKeith Owens monarch_cpu = -1; 16817f613c7dSKeith Owens return; 16821da177e4SLinus Torvalds } 16831da177e4SLinus Torvalds 16841da177e4SLinus Torvalds static int __init 16851da177e4SLinus Torvalds ia64_mca_disable_cpe_polling(char *str) 16861da177e4SLinus Torvalds { 16871da177e4SLinus Torvalds cpe_poll_enabled = 0; 16881da177e4SLinus Torvalds return 1; 16891da177e4SLinus Torvalds } 16901da177e4SLinus Torvalds 16911da177e4SLinus Torvalds __setup("disable_cpe_poll", ia64_mca_disable_cpe_polling); 16921da177e4SLinus Torvalds 16931da177e4SLinus Torvalds static struct irqaction cmci_irqaction = { 16941da177e4SLinus Torvalds .handler = ia64_mca_cmc_int_handler, 1695121a4226SThomas Gleixner .flags = IRQF_DISABLED, 16961da177e4SLinus Torvalds .name = "cmc_hndlr" 16971da177e4SLinus Torvalds }; 16981da177e4SLinus Torvalds 16991da177e4SLinus Torvalds static struct irqaction cmcp_irqaction = { 17001da177e4SLinus Torvalds .handler = ia64_mca_cmc_int_caller, 1701121a4226SThomas Gleixner .flags = IRQF_DISABLED, 17021da177e4SLinus Torvalds .name = "cmc_poll" 17031da177e4SLinus Torvalds }; 17041da177e4SLinus Torvalds 17051da177e4SLinus Torvalds static struct irqaction mca_rdzv_irqaction = { 17061da177e4SLinus Torvalds .handler = ia64_mca_rendez_int_handler, 1707121a4226SThomas Gleixner .flags = IRQF_DISABLED, 17081da177e4SLinus Torvalds .name = "mca_rdzv" 17091da177e4SLinus Torvalds }; 17101da177e4SLinus Torvalds 17111da177e4SLinus Torvalds static struct irqaction mca_wkup_irqaction = { 17121da177e4SLinus Torvalds .handler = ia64_mca_wakeup_int_handler, 1713121a4226SThomas Gleixner .flags = IRQF_DISABLED, 17141da177e4SLinus Torvalds .name = "mca_wkup" 17151da177e4SLinus Torvalds }; 17161da177e4SLinus Torvalds 17171da177e4SLinus Torvalds #ifdef CONFIG_ACPI 17181da177e4SLinus Torvalds static struct irqaction mca_cpe_irqaction = { 17191da177e4SLinus Torvalds .handler = ia64_mca_cpe_int_handler, 1720121a4226SThomas Gleixner .flags = IRQF_DISABLED, 17211da177e4SLinus Torvalds .name = "cpe_hndlr" 17221da177e4SLinus Torvalds }; 17231da177e4SLinus Torvalds 17241da177e4SLinus Torvalds static struct irqaction mca_cpep_irqaction = { 17251da177e4SLinus Torvalds .handler = ia64_mca_cpe_int_caller, 1726121a4226SThomas Gleixner .flags = IRQF_DISABLED, 17271da177e4SLinus Torvalds .name = "cpe_poll" 17281da177e4SLinus Torvalds }; 17291da177e4SLinus Torvalds #endif /* CONFIG_ACPI */ 17301da177e4SLinus Torvalds 17317f613c7dSKeith Owens /* Minimal format of the MCA/INIT stacks. The pseudo processes that run on 17327f613c7dSKeith Owens * these stacks can never sleep, they cannot return from the kernel to user 17337f613c7dSKeith Owens * space, they do not appear in a normal ps listing. So there is no need to 17347f613c7dSKeith Owens * format most of the fields. 17357f613c7dSKeith Owens */ 17367f613c7dSKeith Owens 17370881fc8dSChen, Kenneth W static void __cpuinit 17387f613c7dSKeith Owens format_mca_init_stack(void *mca_data, unsigned long offset, 17397f613c7dSKeith Owens const char *type, int cpu) 17407f613c7dSKeith Owens { 17417f613c7dSKeith Owens struct task_struct *p = (struct task_struct *)((char *)mca_data + offset); 17427f613c7dSKeith Owens struct thread_info *ti; 17437f613c7dSKeith Owens memset(p, 0, KERNEL_STACK_SIZE); 1744ab03591dSAl Viro ti = task_thread_info(p); 17457f613c7dSKeith Owens ti->flags = _TIF_MCA_INIT; 17467f613c7dSKeith Owens ti->preempt_count = 1; 17477f613c7dSKeith Owens ti->task = p; 17487f613c7dSKeith Owens ti->cpu = cpu; 1749f7e4217bSRoman Zippel p->stack = ti; 17507f613c7dSKeith Owens p->state = TASK_UNINTERRUPTIBLE; 17514668f0cdSAkinobu Mita cpu_set(cpu, p->cpus_allowed); 17527f613c7dSKeith Owens INIT_LIST_HEAD(&p->tasks); 17537f613c7dSKeith Owens p->parent = p->real_parent = p->group_leader = p; 17547f613c7dSKeith Owens INIT_LIST_HEAD(&p->children); 17557f613c7dSKeith Owens INIT_LIST_HEAD(&p->sibling); 17567f613c7dSKeith Owens strncpy(p->comm, type, sizeof(p->comm)-1); 17577f613c7dSKeith Owens } 17587f613c7dSKeith Owens 1759056e6d89SSam Ravnborg /* Caller prevents this from being called after init */ 1760056e6d89SSam Ravnborg static void * __init_refok mca_bootmem(void) 1761056e6d89SSam Ravnborg { 1762785285fcSRuss Anderson return __alloc_bootmem(sizeof(struct ia64_mca_cpu), 1763785285fcSRuss Anderson KERNEL_STACK_SIZE, 0); 1764056e6d89SSam Ravnborg } 1765056e6d89SSam Ravnborg 1766056e6d89SSam Ravnborg /* Do per-CPU MCA-related initialization. */ 17670881fc8dSChen, Kenneth W void __cpuinit 17681da177e4SLinus Torvalds ia64_mca_cpu_init(void *cpu_data) 17691da177e4SLinus Torvalds { 17701da177e4SLinus Torvalds void *pal_vaddr; 1771785285fcSRuss Anderson void *data; 1772785285fcSRuss Anderson long sz = sizeof(struct ia64_mca_cpu); 1773785285fcSRuss Anderson int cpu = smp_processor_id(); 1774ff741906SAshok Raj static int first_time = 1; 17751da177e4SLinus Torvalds 17761da177e4SLinus Torvalds /* 1777785285fcSRuss Anderson * Structure will already be allocated if cpu has been online, 1778785285fcSRuss Anderson * then offlined. 17791da177e4SLinus Torvalds */ 1780785285fcSRuss Anderson if (__per_cpu_mca[cpu]) { 1781785285fcSRuss Anderson data = __va(__per_cpu_mca[cpu]); 1782785285fcSRuss Anderson } else { 1783785285fcSRuss Anderson if (first_time) { 1784785285fcSRuss Anderson data = mca_bootmem(); 1785785285fcSRuss Anderson first_time = 0; 1786785285fcSRuss Anderson } else 1787785285fcSRuss Anderson data = page_address(alloc_pages_node(numa_node_id(), 1788785285fcSRuss Anderson GFP_KERNEL, get_order(sz))); 1789785285fcSRuss Anderson if (!data) 1790785285fcSRuss Anderson panic("Could not allocate MCA memory for cpu %d\n", 1791785285fcSRuss Anderson cpu); 1792785285fcSRuss Anderson } 1793785285fcSRuss Anderson format_mca_init_stack(data, offsetof(struct ia64_mca_cpu, mca_stack), 1794785285fcSRuss Anderson "MCA", cpu); 1795785285fcSRuss Anderson format_mca_init_stack(data, offsetof(struct ia64_mca_cpu, init_stack), 1796785285fcSRuss Anderson "INIT", cpu); 1797785285fcSRuss Anderson __get_cpu_var(ia64_mca_data) = __per_cpu_mca[cpu] = __pa(data); 17981da177e4SLinus Torvalds 17991da177e4SLinus Torvalds /* 18001da177e4SLinus Torvalds * Stash away a copy of the PTE needed to map the per-CPU page. 18011da177e4SLinus Torvalds * We may need it during MCA recovery. 18021da177e4SLinus Torvalds */ 18031da177e4SLinus Torvalds __get_cpu_var(ia64_mca_per_cpu_pte) = 18041da177e4SLinus Torvalds pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL)); 18051da177e4SLinus Torvalds 18061da177e4SLinus Torvalds /* 18071da177e4SLinus Torvalds * Also, stash away a copy of the PAL address and the PTE 18081da177e4SLinus Torvalds * needed to map it. 18091da177e4SLinus Torvalds */ 18101da177e4SLinus Torvalds pal_vaddr = efi_get_pal_addr(); 18111da177e4SLinus Torvalds if (!pal_vaddr) 18121da177e4SLinus Torvalds return; 18131da177e4SLinus Torvalds __get_cpu_var(ia64_mca_pal_base) = 18141da177e4SLinus Torvalds GRANULEROUNDDOWN((unsigned long) pal_vaddr); 18151da177e4SLinus Torvalds __get_cpu_var(ia64_mca_pal_pte) = pte_val(mk_pte_phys(__pa(pal_vaddr), 18161da177e4SLinus Torvalds PAGE_KERNEL)); 18171da177e4SLinus Torvalds } 18181da177e4SLinus Torvalds 1819ed5d4026SHidetoshi Seto static void __cpuinit ia64_mca_cmc_vector_adjust(void *dummy) 1820ed5d4026SHidetoshi Seto { 1821ed5d4026SHidetoshi Seto unsigned long flags; 1822ed5d4026SHidetoshi Seto 1823ed5d4026SHidetoshi Seto local_irq_save(flags); 1824ed5d4026SHidetoshi Seto if (!cmc_polling_enabled) 1825ed5d4026SHidetoshi Seto ia64_mca_cmc_vector_enable(NULL); 1826ed5d4026SHidetoshi Seto local_irq_restore(flags); 1827ed5d4026SHidetoshi Seto } 1828ed5d4026SHidetoshi Seto 1829ed5d4026SHidetoshi Seto static int __cpuinit mca_cpu_callback(struct notifier_block *nfb, 1830ed5d4026SHidetoshi Seto unsigned long action, 1831ed5d4026SHidetoshi Seto void *hcpu) 1832ed5d4026SHidetoshi Seto { 1833ed5d4026SHidetoshi Seto int hotcpu = (unsigned long) hcpu; 1834ed5d4026SHidetoshi Seto 1835ed5d4026SHidetoshi Seto switch (action) { 1836ed5d4026SHidetoshi Seto case CPU_ONLINE: 1837ed5d4026SHidetoshi Seto case CPU_ONLINE_FROZEN: 1838ed5d4026SHidetoshi Seto smp_call_function_single(hotcpu, ia64_mca_cmc_vector_adjust, 1839ed5d4026SHidetoshi Seto NULL, 1, 0); 1840ed5d4026SHidetoshi Seto break; 1841ed5d4026SHidetoshi Seto } 1842ed5d4026SHidetoshi Seto return NOTIFY_OK; 1843ed5d4026SHidetoshi Seto } 1844ed5d4026SHidetoshi Seto 1845ed5d4026SHidetoshi Seto static struct notifier_block mca_cpu_notifier __cpuinitdata = { 1846ed5d4026SHidetoshi Seto .notifier_call = mca_cpu_callback 1847ed5d4026SHidetoshi Seto }; 1848ed5d4026SHidetoshi Seto 18491da177e4SLinus Torvalds /* 18501da177e4SLinus Torvalds * ia64_mca_init 18511da177e4SLinus Torvalds * 18521da177e4SLinus Torvalds * Do all the system level mca specific initialization. 18531da177e4SLinus Torvalds * 18541da177e4SLinus Torvalds * 1. Register spinloop and wakeup request interrupt vectors 18551da177e4SLinus Torvalds * 18561da177e4SLinus Torvalds * 2. Register OS_MCA handler entry point 18571da177e4SLinus Torvalds * 18581da177e4SLinus Torvalds * 3. Register OS_INIT handler entry point 18591da177e4SLinus Torvalds * 18601da177e4SLinus Torvalds * 4. Initialize MCA/CMC/INIT related log buffers maintained by the OS. 18611da177e4SLinus Torvalds * 18621da177e4SLinus Torvalds * Note that this initialization is done very early before some kernel 18631da177e4SLinus Torvalds * services are available. 18641da177e4SLinus Torvalds * 18651da177e4SLinus Torvalds * Inputs : None 18661da177e4SLinus Torvalds * 18671da177e4SLinus Torvalds * Outputs : None 18681da177e4SLinus Torvalds */ 18691da177e4SLinus Torvalds void __init 18701da177e4SLinus Torvalds ia64_mca_init(void) 18711da177e4SLinus Torvalds { 18727f613c7dSKeith Owens ia64_fptr_t *init_hldlr_ptr_monarch = (ia64_fptr_t *)ia64_os_init_dispatch_monarch; 18737f613c7dSKeith Owens ia64_fptr_t *init_hldlr_ptr_slave = (ia64_fptr_t *)ia64_os_init_dispatch_slave; 18741da177e4SLinus Torvalds ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch; 18751da177e4SLinus Torvalds int i; 18761da177e4SLinus Torvalds s64 rc; 18771da177e4SLinus Torvalds struct ia64_sal_retval isrv; 18781da177e4SLinus Torvalds u64 timeout = IA64_MCA_RENDEZ_TIMEOUT; /* platform specific */ 18799138d581SKeith Owens static struct notifier_block default_init_monarch_nb = { 18809138d581SKeith Owens .notifier_call = default_monarch_init_process, 18819138d581SKeith Owens .priority = 0/* we need to notified last */ 18829138d581SKeith Owens }; 18831da177e4SLinus Torvalds 1884*d4ed8084SHarvey Harrison IA64_MCA_DEBUG("%s: begin\n", __func__); 18851da177e4SLinus Torvalds 18861da177e4SLinus Torvalds /* Clear the Rendez checkin flag for all cpus */ 18871da177e4SLinus Torvalds for(i = 0 ; i < NR_CPUS; i++) 18881da177e4SLinus Torvalds ia64_mc_info.imi_rendez_checkin[i] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE; 18891da177e4SLinus Torvalds 18901da177e4SLinus Torvalds /* 18911da177e4SLinus Torvalds * Register the rendezvous spinloop and wakeup mechanism with SAL 18921da177e4SLinus Torvalds */ 18931da177e4SLinus Torvalds 18941da177e4SLinus Torvalds /* Register the rendezvous interrupt vector with SAL */ 18951da177e4SLinus Torvalds while (1) { 18961da177e4SLinus Torvalds isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_INT, 18971da177e4SLinus Torvalds SAL_MC_PARAM_MECHANISM_INT, 18981da177e4SLinus Torvalds IA64_MCA_RENDEZ_VECTOR, 18991da177e4SLinus Torvalds timeout, 19001da177e4SLinus Torvalds SAL_MC_PARAM_RZ_ALWAYS); 19011da177e4SLinus Torvalds rc = isrv.status; 19021da177e4SLinus Torvalds if (rc == 0) 19031da177e4SLinus Torvalds break; 19041da177e4SLinus Torvalds if (rc == -2) { 19051da177e4SLinus Torvalds printk(KERN_INFO "Increasing MCA rendezvous timeout from " 19061da177e4SLinus Torvalds "%ld to %ld milliseconds\n", timeout, isrv.v0); 19071da177e4SLinus Torvalds timeout = isrv.v0; 1908958b166cSKeith Owens (void) notify_die(DIE_MCA_NEW_TIMEOUT, "MCA", NULL, timeout, 0, 0); 19091da177e4SLinus Torvalds continue; 19101da177e4SLinus Torvalds } 19111da177e4SLinus Torvalds printk(KERN_ERR "Failed to register rendezvous interrupt " 19121da177e4SLinus Torvalds "with SAL (status %ld)\n", rc); 19131da177e4SLinus Torvalds return; 19141da177e4SLinus Torvalds } 19151da177e4SLinus Torvalds 19161da177e4SLinus Torvalds /* Register the wakeup interrupt vector with SAL */ 19171da177e4SLinus Torvalds isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_WAKEUP, 19181da177e4SLinus Torvalds SAL_MC_PARAM_MECHANISM_INT, 19191da177e4SLinus Torvalds IA64_MCA_WAKEUP_VECTOR, 19201da177e4SLinus Torvalds 0, 0); 19211da177e4SLinus Torvalds rc = isrv.status; 19221da177e4SLinus Torvalds if (rc) { 19231da177e4SLinus Torvalds printk(KERN_ERR "Failed to register wakeup interrupt with SAL " 19241da177e4SLinus Torvalds "(status %ld)\n", rc); 19251da177e4SLinus Torvalds return; 19261da177e4SLinus Torvalds } 19271da177e4SLinus Torvalds 1928*d4ed8084SHarvey Harrison IA64_MCA_DEBUG("%s: registered MCA rendezvous spinloop and wakeup mech.\n", __func__); 19291da177e4SLinus Torvalds 19301da177e4SLinus Torvalds ia64_mc_info.imi_mca_handler = ia64_tpa(mca_hldlr_ptr->fp); 19311da177e4SLinus Torvalds /* 19321da177e4SLinus Torvalds * XXX - disable SAL checksum by setting size to 0; should be 19331da177e4SLinus Torvalds * ia64_tpa(ia64_os_mca_dispatch_end) - ia64_tpa(ia64_os_mca_dispatch); 19341da177e4SLinus Torvalds */ 19351da177e4SLinus Torvalds ia64_mc_info.imi_mca_handler_size = 0; 19361da177e4SLinus Torvalds 19371da177e4SLinus Torvalds /* Register the os mca handler with SAL */ 19381da177e4SLinus Torvalds if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_MCA, 19391da177e4SLinus Torvalds ia64_mc_info.imi_mca_handler, 19401da177e4SLinus Torvalds ia64_tpa(mca_hldlr_ptr->gp), 19411da177e4SLinus Torvalds ia64_mc_info.imi_mca_handler_size, 19421da177e4SLinus Torvalds 0, 0, 0))) 19431da177e4SLinus Torvalds { 19441da177e4SLinus Torvalds printk(KERN_ERR "Failed to register OS MCA handler with SAL " 19451da177e4SLinus Torvalds "(status %ld)\n", rc); 19461da177e4SLinus Torvalds return; 19471da177e4SLinus Torvalds } 19481da177e4SLinus Torvalds 1949*d4ed8084SHarvey Harrison IA64_MCA_DEBUG("%s: registered OS MCA handler with SAL at 0x%lx, gp = 0x%lx\n", __func__, 19501da177e4SLinus Torvalds ia64_mc_info.imi_mca_handler, ia64_tpa(mca_hldlr_ptr->gp)); 19511da177e4SLinus Torvalds 19521da177e4SLinus Torvalds /* 19531da177e4SLinus Torvalds * XXX - disable SAL checksum by setting size to 0, should be 19541da177e4SLinus Torvalds * size of the actual init handler in mca_asm.S. 19551da177e4SLinus Torvalds */ 19567f613c7dSKeith Owens ia64_mc_info.imi_monarch_init_handler = ia64_tpa(init_hldlr_ptr_monarch->fp); 19571da177e4SLinus Torvalds ia64_mc_info.imi_monarch_init_handler_size = 0; 19587f613c7dSKeith Owens ia64_mc_info.imi_slave_init_handler = ia64_tpa(init_hldlr_ptr_slave->fp); 19591da177e4SLinus Torvalds ia64_mc_info.imi_slave_init_handler_size = 0; 19601da177e4SLinus Torvalds 1961*d4ed8084SHarvey Harrison IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __func__, 19621da177e4SLinus Torvalds ia64_mc_info.imi_monarch_init_handler); 19631da177e4SLinus Torvalds 19641da177e4SLinus Torvalds /* Register the os init handler with SAL */ 19651da177e4SLinus Torvalds if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_INIT, 19661da177e4SLinus Torvalds ia64_mc_info.imi_monarch_init_handler, 19671da177e4SLinus Torvalds ia64_tpa(ia64_getreg(_IA64_REG_GP)), 19681da177e4SLinus Torvalds ia64_mc_info.imi_monarch_init_handler_size, 19691da177e4SLinus Torvalds ia64_mc_info.imi_slave_init_handler, 19701da177e4SLinus Torvalds ia64_tpa(ia64_getreg(_IA64_REG_GP)), 19711da177e4SLinus Torvalds ia64_mc_info.imi_slave_init_handler_size))) 19721da177e4SLinus Torvalds { 19731da177e4SLinus Torvalds printk(KERN_ERR "Failed to register m/s INIT handlers with SAL " 19741da177e4SLinus Torvalds "(status %ld)\n", rc); 19751da177e4SLinus Torvalds return; 19761da177e4SLinus Torvalds } 19779138d581SKeith Owens if (register_die_notifier(&default_init_monarch_nb)) { 19789138d581SKeith Owens printk(KERN_ERR "Failed to register default monarch INIT process\n"); 19799138d581SKeith Owens return; 19809138d581SKeith Owens } 19811da177e4SLinus Torvalds 1982*d4ed8084SHarvey Harrison IA64_MCA_DEBUG("%s: registered OS INIT handler with SAL\n", __func__); 19831da177e4SLinus Torvalds 19841da177e4SLinus Torvalds /* 19851da177e4SLinus Torvalds * Configure the CMCI/P vector and handler. Interrupts for CMC are 19861da177e4SLinus Torvalds * per-processor, so AP CMC interrupts are setup in smp_callin() (smpboot.c). 19871da177e4SLinus Torvalds */ 19881da177e4SLinus Torvalds register_percpu_irq(IA64_CMC_VECTOR, &cmci_irqaction); 19891da177e4SLinus Torvalds register_percpu_irq(IA64_CMCP_VECTOR, &cmcp_irqaction); 19901da177e4SLinus Torvalds ia64_mca_cmc_vector_setup(); /* Setup vector on BSP */ 19911da177e4SLinus Torvalds 19921da177e4SLinus Torvalds /* Setup the MCA rendezvous interrupt vector */ 19931da177e4SLinus Torvalds register_percpu_irq(IA64_MCA_RENDEZ_VECTOR, &mca_rdzv_irqaction); 19941da177e4SLinus Torvalds 19951da177e4SLinus Torvalds /* Setup the MCA wakeup interrupt vector */ 19961da177e4SLinus Torvalds register_percpu_irq(IA64_MCA_WAKEUP_VECTOR, &mca_wkup_irqaction); 19971da177e4SLinus Torvalds 19981da177e4SLinus Torvalds #ifdef CONFIG_ACPI 1999bb68c12bSRuss Anderson /* Setup the CPEI/P handler */ 20001da177e4SLinus Torvalds register_percpu_irq(IA64_CPEP_VECTOR, &mca_cpep_irqaction); 20011da177e4SLinus Torvalds #endif 20021da177e4SLinus Torvalds 20031da177e4SLinus Torvalds /* Initialize the areas set aside by the OS to buffer the 20041da177e4SLinus Torvalds * platform/processor error states for MCA/INIT/CMC 20051da177e4SLinus Torvalds * handling. 20061da177e4SLinus Torvalds */ 20071da177e4SLinus Torvalds ia64_log_init(SAL_INFO_TYPE_MCA); 20081da177e4SLinus Torvalds ia64_log_init(SAL_INFO_TYPE_INIT); 20091da177e4SLinus Torvalds ia64_log_init(SAL_INFO_TYPE_CMC); 20101da177e4SLinus Torvalds ia64_log_init(SAL_INFO_TYPE_CPE); 20111da177e4SLinus Torvalds 20121da177e4SLinus Torvalds mca_init = 1; 20131da177e4SLinus Torvalds printk(KERN_INFO "MCA related initialization done\n"); 20141da177e4SLinus Torvalds } 20151da177e4SLinus Torvalds 20161da177e4SLinus Torvalds /* 20171da177e4SLinus Torvalds * ia64_mca_late_init 20181da177e4SLinus Torvalds * 20191da177e4SLinus Torvalds * Opportunity to setup things that require initialization later 20201da177e4SLinus Torvalds * than ia64_mca_init. Setup a timer to poll for CPEs if the 20211da177e4SLinus Torvalds * platform doesn't support an interrupt driven mechanism. 20221da177e4SLinus Torvalds * 20231da177e4SLinus Torvalds * Inputs : None 20241da177e4SLinus Torvalds * Outputs : Status 20251da177e4SLinus Torvalds */ 20261da177e4SLinus Torvalds static int __init 20271da177e4SLinus Torvalds ia64_mca_late_init(void) 20281da177e4SLinus Torvalds { 20291da177e4SLinus Torvalds if (!mca_init) 20301da177e4SLinus Torvalds return 0; 20311da177e4SLinus Torvalds 2032ed5d4026SHidetoshi Seto register_hotcpu_notifier(&mca_cpu_notifier); 2033ed5d4026SHidetoshi Seto 20341da177e4SLinus Torvalds /* Setup the CMCI/P vector and handler */ 20351da177e4SLinus Torvalds init_timer(&cmc_poll_timer); 20361da177e4SLinus Torvalds cmc_poll_timer.function = ia64_mca_cmc_poll; 20371da177e4SLinus Torvalds 20381da177e4SLinus Torvalds /* Unmask/enable the vector */ 20391da177e4SLinus Torvalds cmc_polling_enabled = 0; 20401da177e4SLinus Torvalds schedule_work(&cmc_enable_work); 20411da177e4SLinus Torvalds 2042*d4ed8084SHarvey Harrison IA64_MCA_DEBUG("%s: CMCI/P setup and enabled.\n", __func__); 20431da177e4SLinus Torvalds 20441da177e4SLinus Torvalds #ifdef CONFIG_ACPI 20451da177e4SLinus Torvalds /* Setup the CPEI/P vector and handler */ 2046bb68c12bSRuss Anderson cpe_vector = acpi_request_vector(ACPI_INTERRUPT_CPEI); 20471da177e4SLinus Torvalds init_timer(&cpe_poll_timer); 20481da177e4SLinus Torvalds cpe_poll_timer.function = ia64_mca_cpe_poll; 20491da177e4SLinus Torvalds 20501da177e4SLinus Torvalds { 20511da177e4SLinus Torvalds irq_desc_t *desc; 20521da177e4SLinus Torvalds unsigned int irq; 20531da177e4SLinus Torvalds 20541da177e4SLinus Torvalds if (cpe_vector >= 0) { 20551da177e4SLinus Torvalds /* If platform supports CPEI, enable the irq. */ 2056a1287476SRuss Anderson irq = local_vector_to_irq(cpe_vector); 2057a1287476SRuss Anderson if (irq > 0) { 20581da177e4SLinus Torvalds cpe_poll_enabled = 0; 2059a8553acdSIngo Molnar desc = irq_desc + irq; 20601da177e4SLinus Torvalds desc->status |= IRQ_PER_CPU; 20611da177e4SLinus Torvalds setup_irq(irq, &mca_cpe_irqaction); 2062ff741906SAshok Raj ia64_cpe_irq = irq; 20631da177e4SLinus Torvalds ia64_mca_register_cpev(cpe_vector); 2064a1287476SRuss Anderson IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n", 2065*d4ed8084SHarvey Harrison __func__); 2066a1287476SRuss Anderson return 0; 2067a1287476SRuss Anderson } 2068a1287476SRuss Anderson printk(KERN_ERR "%s: Failed to find irq for CPE " 2069a1287476SRuss Anderson "interrupt handler, vector %d\n", 2070*d4ed8084SHarvey Harrison __func__, cpe_vector); 2071a1287476SRuss Anderson } 20721da177e4SLinus Torvalds /* If platform doesn't support CPEI, get the timer going. */ 20731da177e4SLinus Torvalds if (cpe_poll_enabled) { 20741da177e4SLinus Torvalds ia64_mca_cpe_poll(0UL); 2075*d4ed8084SHarvey Harrison IA64_MCA_DEBUG("%s: CPEP setup and enabled.\n", __func__); 20761da177e4SLinus Torvalds } 20771da177e4SLinus Torvalds } 20781da177e4SLinus Torvalds #endif 20791da177e4SLinus Torvalds 20801da177e4SLinus Torvalds return 0; 20811da177e4SLinus Torvalds } 20821da177e4SLinus Torvalds 20831da177e4SLinus Torvalds device_initcall(ia64_mca_late_init); 2084