mca.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727
  1. /*
  2. * File: mca.c
  3. * Purpose: Generic MCA handling layer
  4. *
  5. * Updated for latest kernel
  6. * Copyright (C) 2003 Hewlett-Packard Co
  7. * David Mosberger-Tang <davidm@hpl.hp.com>
  8. *
  9. * Copyright (C) 2002 Dell Inc.
  10. * Copyright (C) Matt Domsch (Matt_Domsch@dell.com)
  11. *
  12. * Copyright (C) 2002 Intel
  13. * Copyright (C) Jenna Hall (jenna.s.hall@intel.com)
  14. *
  15. * Copyright (C) 2001 Intel
  16. * Copyright (C) Fred Lewis (frederick.v.lewis@intel.com)
  17. *
  18. * Copyright (C) 2000 Intel
  19. * Copyright (C) Chuck Fleckenstein (cfleck@co.intel.com)
  20. *
  21. * Copyright (C) 1999, 2004 Silicon Graphics, Inc.
  22. * Copyright (C) Vijay Chander(vijay@engr.sgi.com)
  23. *
  24. * 03/04/15 D. Mosberger Added INIT backtrace support.
  25. * 02/03/25 M. Domsch GUID cleanups
  26. *
  27. * 02/01/04 J. Hall Aligned MCA stack to 16 bytes, added platform vs. CPU
  28. * error flag, set SAL default return values, changed
  29. * error record structure to linked list, added init call
  30. * to sal_get_state_info_size().
  31. *
  32. * 01/01/03 F. Lewis Added setup of CMCI and CPEI IRQs, logging of corrected
  33. * platform errors, completed code for logging of
  34. * corrected & uncorrected machine check errors, and
  35. * updated for conformance with Nov. 2000 revision of the
  36. * SAL 3.0 spec.
  37. * 00/03/29 C. Fleckenstein Fixed PAL/SAL update issues, began MCA bug fixes, logging issues,
  38. * added min save state dump, added INIT handler.
  39. *
  40. * 2003-12-08 Keith Owens <kaos@sgi.com>
  41. * smp_call_function() must not be called from interrupt context (can
  42. * deadlock on tasklist_lock). Use keventd to call smp_call_function().
  43. *
  44. * 2004-02-01 Keith Owens <kaos@sgi.com>
  45. * Avoid deadlock when using printk() for MCA and INIT records.
  46. * Delete all record printing code, moved to salinfo_decode in user space.
  47. * Mark variables and functions static where possible.
  48. * Delete dead variables and functions.
  49. * Reorder to remove the need for forward declarations and to consolidate
  50. * related code.
  51. *
  52. * 2005-08-12 Keith Owens <kaos@sgi.com>
  53. * Convert MCA/INIT handlers to use per event stacks and SAL/OS state.
  54. *
  55. * 2005-10-07 Keith Owens <kaos@sgi.com>
  56. * Add notify_die() hooks.
  57. */
  58. #include <linux/config.h>
  59. #include <linux/types.h>
  60. #include <linux/init.h>
  61. #include <linux/sched.h>
  62. #include <linux/interrupt.h>
  63. #include <linux/irq.h>
  64. #include <linux/smp_lock.h>
  65. #include <linux/bootmem.h>
  66. #include <linux/acpi.h>
  67. #include <linux/timer.h>
  68. #include <linux/module.h>
  69. #include <linux/kernel.h>
  70. #include <linux/smp.h>
  71. #include <linux/workqueue.h>
  72. #include <asm/delay.h>
  73. #include <asm/kdebug.h>
  74. #include <asm/machvec.h>
  75. #include <asm/meminit.h>
  76. #include <asm/page.h>
  77. #include <asm/ptrace.h>
  78. #include <asm/system.h>
  79. #include <asm/sal.h>
  80. #include <asm/mca.h>
  81. #include <asm/irq.h>
  82. #include <asm/hw_irq.h>
  83. #include "entry.h"
  84. #if defined(IA64_MCA_DEBUG_INFO)
  85. # define IA64_MCA_DEBUG(fmt...) printk(fmt)
  86. #else
  87. # define IA64_MCA_DEBUG(fmt...)
  88. #endif
  89. /* Used by mca_asm.S */
  90. u32 ia64_mca_serialize;
  91. DEFINE_PER_CPU(u64, ia64_mca_data); /* == __per_cpu_mca[smp_processor_id()] */
  92. DEFINE_PER_CPU(u64, ia64_mca_per_cpu_pte); /* PTE to map per-CPU area */
  93. DEFINE_PER_CPU(u64, ia64_mca_pal_pte); /* PTE to map PAL code */
  94. DEFINE_PER_CPU(u64, ia64_mca_pal_base); /* vaddr PAL code granule */
  95. unsigned long __per_cpu_mca[NR_CPUS];
  96. /* In mca_asm.S */
  97. extern void ia64_os_init_dispatch_monarch (void);
  98. extern void ia64_os_init_dispatch_slave (void);
  99. static int monarch_cpu = -1;
  100. static ia64_mc_info_t ia64_mc_info;
  101. #define MAX_CPE_POLL_INTERVAL (15*60*HZ) /* 15 minutes */
  102. #define MIN_CPE_POLL_INTERVAL (2*60*HZ) /* 2 minutes */
  103. #define CMC_POLL_INTERVAL (1*60*HZ) /* 1 minute */
  104. #define CPE_HISTORY_LENGTH 5
  105. #define CMC_HISTORY_LENGTH 5
  106. static struct timer_list cpe_poll_timer;
  107. static struct timer_list cmc_poll_timer;
  108. /*
  109. * This variable tells whether we are currently in polling mode.
  110. * Start with this in the wrong state so we won't play w/ timers
  111. * before the system is ready.
  112. */
  113. static int cmc_polling_enabled = 1;
  114. /*
  115. * Clearing this variable prevents CPE polling from getting activated
  116. * in mca_late_init. Use it if your system doesn't provide a CPEI,
  117. * but encounters problems retrieving CPE logs. This should only be
  118. * necessary for debugging.
  119. */
  120. static int cpe_poll_enabled = 1;
  121. extern void salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe);
  122. static int mca_init;
  123. static void inline
  124. ia64_mca_spin(const char *func)
  125. {
  126. printk(KERN_EMERG "%s: spinning here, not returning to SAL\n", func);
  127. while (1)
  128. cpu_relax();
  129. }
  130. /*
  131. * IA64_MCA log support
  132. */
  133. #define IA64_MAX_LOGS 2 /* Double-buffering for nested MCAs */
  134. #define IA64_MAX_LOG_TYPES 4 /* MCA, INIT, CMC, CPE */
  135. typedef struct ia64_state_log_s
  136. {
  137. spinlock_t isl_lock;
  138. int isl_index;
  139. unsigned long isl_count;
  140. ia64_err_rec_t *isl_log[IA64_MAX_LOGS]; /* need space to store header + error log */
  141. } ia64_state_log_t;
  142. static ia64_state_log_t ia64_state_log[IA64_MAX_LOG_TYPES];
  143. #define IA64_LOG_ALLOCATE(it, size) \
  144. {ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)] = \
  145. (ia64_err_rec_t *)alloc_bootmem(size); \
  146. ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)] = \
  147. (ia64_err_rec_t *)alloc_bootmem(size);}
  148. #define IA64_LOG_LOCK_INIT(it) spin_lock_init(&ia64_state_log[it].isl_lock)
  149. #define IA64_LOG_LOCK(it) spin_lock_irqsave(&ia64_state_log[it].isl_lock, s)
  150. #define IA64_LOG_UNLOCK(it) spin_unlock_irqrestore(&ia64_state_log[it].isl_lock,s)
  151. #define IA64_LOG_NEXT_INDEX(it) ia64_state_log[it].isl_index
  152. #define IA64_LOG_CURR_INDEX(it) 1 - ia64_state_log[it].isl_index
  153. #define IA64_LOG_INDEX_INC(it) \
  154. {ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index; \
  155. ia64_state_log[it].isl_count++;}
  156. #define IA64_LOG_INDEX_DEC(it) \
  157. ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index
  158. #define IA64_LOG_NEXT_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)]))
  159. #define IA64_LOG_CURR_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)]))
  160. #define IA64_LOG_COUNT(it) ia64_state_log[it].isl_count
  161. /*
  162. * ia64_log_init
  163. * Reset the OS ia64 log buffer
  164. * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
  165. * Outputs : None
  166. */
  167. static void
  168. ia64_log_init(int sal_info_type)
  169. {
  170. u64 max_size = 0;
  171. IA64_LOG_NEXT_INDEX(sal_info_type) = 0;
  172. IA64_LOG_LOCK_INIT(sal_info_type);
  173. // SAL will tell us the maximum size of any error record of this type
  174. max_size = ia64_sal_get_state_info_size(sal_info_type);
  175. if (!max_size)
  176. /* alloc_bootmem() doesn't like zero-sized allocations! */
  177. return;
  178. // set up OS data structures to hold error info
  179. IA64_LOG_ALLOCATE(sal_info_type, max_size);
  180. memset(IA64_LOG_CURR_BUFFER(sal_info_type), 0, max_size);
  181. memset(IA64_LOG_NEXT_BUFFER(sal_info_type), 0, max_size);
  182. }
  183. /*
  184. * ia64_log_get
  185. *
  186. * Get the current MCA log from SAL and copy it into the OS log buffer.
  187. *
  188. * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
  189. * irq_safe whether you can use printk at this point
  190. * Outputs : size (total record length)
  191. * *buffer (ptr to error record)
  192. *
  193. */
  194. static u64
  195. ia64_log_get(int sal_info_type, u8 **buffer, int irq_safe)
  196. {
  197. sal_log_record_header_t *log_buffer;
  198. u64 total_len = 0;
  199. int s;
  200. IA64_LOG_LOCK(sal_info_type);
  201. /* Get the process state information */
  202. log_buffer = IA64_LOG_NEXT_BUFFER(sal_info_type);
  203. total_len = ia64_sal_get_state_info(sal_info_type, (u64 *)log_buffer);
  204. if (total_len) {
  205. IA64_LOG_INDEX_INC(sal_info_type);
  206. IA64_LOG_UNLOCK(sal_info_type);
  207. if (irq_safe) {
  208. IA64_MCA_DEBUG("%s: SAL error record type %d retrieved. "
  209. "Record length = %ld\n", __FUNCTION__, sal_info_type, total_len);
  210. }
  211. *buffer = (u8 *) log_buffer;
  212. return total_len;
  213. } else {
  214. IA64_LOG_UNLOCK(sal_info_type);
  215. return 0;
  216. }
  217. }
  218. /*
  219. * ia64_mca_log_sal_error_record
  220. *
  221. * This function retrieves a specified error record type from SAL
  222. * and wakes up any processes waiting for error records.
  223. *
  224. * Inputs : sal_info_type (Type of error record MCA/CMC/CPE)
  225. * FIXME: remove MCA and irq_safe.
  226. */
  227. static void
  228. ia64_mca_log_sal_error_record(int sal_info_type)
  229. {
  230. u8 *buffer;
  231. sal_log_record_header_t *rh;
  232. u64 size;
  233. int irq_safe = sal_info_type != SAL_INFO_TYPE_MCA;
  234. #ifdef IA64_MCA_DEBUG_INFO
  235. static const char * const rec_name[] = { "MCA", "INIT", "CMC", "CPE" };
  236. #endif
  237. size = ia64_log_get(sal_info_type, &buffer, irq_safe);
  238. if (!size)
  239. return;
  240. salinfo_log_wakeup(sal_info_type, buffer, size, irq_safe);
  241. if (irq_safe)
  242. IA64_MCA_DEBUG("CPU %d: SAL log contains %s error record\n",
  243. smp_processor_id(),
  244. sal_info_type < ARRAY_SIZE(rec_name) ? rec_name[sal_info_type] : "UNKNOWN");
  245. /* Clear logs from corrected errors in case there's no user-level logger */
  246. rh = (sal_log_record_header_t *)buffer;
  247. if (rh->severity == sal_log_severity_corrected)
  248. ia64_sal_clear_state_info(sal_info_type);
  249. }
  250. /*
  251. * platform dependent error handling
  252. */
  253. #ifndef PLATFORM_MCA_HANDLERS
  254. #ifdef CONFIG_ACPI
  255. int cpe_vector = -1;
  256. int ia64_cpe_irq = -1;
  257. static irqreturn_t
  258. ia64_mca_cpe_int_handler (int cpe_irq, void *arg, struct pt_regs *ptregs)
  259. {
  260. static unsigned long cpe_history[CPE_HISTORY_LENGTH];
  261. static int index;
  262. static DEFINE_SPINLOCK(cpe_history_lock);
  263. IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
  264. __FUNCTION__, cpe_irq, smp_processor_id());
  265. /* SAL spec states this should run w/ interrupts enabled */
  266. local_irq_enable();
  267. /* Get the CPE error record and log it */
  268. ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE);
  269. spin_lock(&cpe_history_lock);
  270. if (!cpe_poll_enabled && cpe_vector >= 0) {
  271. int i, count = 1; /* we know 1 happened now */
  272. unsigned long now = jiffies;
  273. for (i = 0; i < CPE_HISTORY_LENGTH; i++) {
  274. if (now - cpe_history[i] <= HZ)
  275. count++;
  276. }
  277. IA64_MCA_DEBUG(KERN_INFO "CPE threshold %d/%d\n", count, CPE_HISTORY_LENGTH);
  278. if (count >= CPE_HISTORY_LENGTH) {
  279. cpe_poll_enabled = 1;
  280. spin_unlock(&cpe_history_lock);
  281. disable_irq_nosync(local_vector_to_irq(IA64_CPE_VECTOR));
  282. /*
  283. * Corrected errors will still be corrected, but
  284. * make sure there's a log somewhere that indicates
  285. * something is generating more than we can handle.
  286. */
  287. printk(KERN_WARNING "WARNING: Switching to polling CPE handler; error records may be lost\n");
  288. mod_timer(&cpe_poll_timer, jiffies + MIN_CPE_POLL_INTERVAL);
  289. /* lock already released, get out now */
  290. return IRQ_HANDLED;
  291. } else {
  292. cpe_history[index++] = now;
  293. if (index == CPE_HISTORY_LENGTH)
  294. index = 0;
  295. }
  296. }
  297. spin_unlock(&cpe_history_lock);
  298. return IRQ_HANDLED;
  299. }
  300. #endif /* CONFIG_ACPI */
  301. #ifdef CONFIG_ACPI
  302. /*
  303. * ia64_mca_register_cpev
  304. *
  305. * Register the corrected platform error vector with SAL.
  306. *
  307. * Inputs
  308. * cpev Corrected Platform Error Vector number
  309. *
  310. * Outputs
  311. * None
  312. */
  313. static void
  314. ia64_mca_register_cpev (int cpev)
  315. {
  316. /* Register the CPE interrupt vector with SAL */
  317. struct ia64_sal_retval isrv;
  318. isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_CPE_INT, SAL_MC_PARAM_MECHANISM_INT, cpev, 0, 0);
  319. if (isrv.status) {
  320. printk(KERN_ERR "Failed to register Corrected Platform "
  321. "Error interrupt vector with SAL (status %ld)\n", isrv.status);
  322. return;
  323. }
  324. IA64_MCA_DEBUG("%s: corrected platform error "
  325. "vector %#x registered\n", __FUNCTION__, cpev);
  326. }
  327. #endif /* CONFIG_ACPI */
  328. #endif /* PLATFORM_MCA_HANDLERS */
  329. /*
  330. * ia64_mca_cmc_vector_setup
  331. *
  332. * Setup the corrected machine check vector register in the processor.
  333. * (The interrupt is masked on boot. ia64_mca_late_init unmask this.)
  334. * This function is invoked on a per-processor basis.
  335. *
  336. * Inputs
  337. * None
  338. *
  339. * Outputs
  340. * None
  341. */
  342. void
  343. ia64_mca_cmc_vector_setup (void)
  344. {
  345. cmcv_reg_t cmcv;
  346. cmcv.cmcv_regval = 0;
  347. cmcv.cmcv_mask = 1; /* Mask/disable interrupt at first */
  348. cmcv.cmcv_vector = IA64_CMC_VECTOR;
  349. ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
  350. IA64_MCA_DEBUG("%s: CPU %d corrected "
  351. "machine check vector %#x registered.\n",
  352. __FUNCTION__, smp_processor_id(), IA64_CMC_VECTOR);
  353. IA64_MCA_DEBUG("%s: CPU %d CMCV = %#016lx\n",
  354. __FUNCTION__, smp_processor_id(), ia64_getreg(_IA64_REG_CR_CMCV));
  355. }
  356. /*
  357. * ia64_mca_cmc_vector_disable
  358. *
  359. * Mask the corrected machine check vector register in the processor.
  360. * This function is invoked on a per-processor basis.
  361. *
  362. * Inputs
  363. * dummy(unused)
  364. *
  365. * Outputs
  366. * None
  367. */
  368. static void
  369. ia64_mca_cmc_vector_disable (void *dummy)
  370. {
  371. cmcv_reg_t cmcv;
  372. cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV);
  373. cmcv.cmcv_mask = 1; /* Mask/disable interrupt */
  374. ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
  375. IA64_MCA_DEBUG("%s: CPU %d corrected "
  376. "machine check vector %#x disabled.\n",
  377. __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector);
  378. }
  379. /*
  380. * ia64_mca_cmc_vector_enable
  381. *
  382. * Unmask the corrected machine check vector register in the processor.
  383. * This function is invoked on a per-processor basis.
  384. *
  385. * Inputs
  386. * dummy(unused)
  387. *
  388. * Outputs
  389. * None
  390. */
  391. static void
  392. ia64_mca_cmc_vector_enable (void *dummy)
  393. {
  394. cmcv_reg_t cmcv;
  395. cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV);
  396. cmcv.cmcv_mask = 0; /* Unmask/enable interrupt */
  397. ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
  398. IA64_MCA_DEBUG("%s: CPU %d corrected "
  399. "machine check vector %#x enabled.\n",
  400. __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector);
  401. }
  402. /*
  403. * ia64_mca_cmc_vector_disable_keventd
  404. *
  405. * Called via keventd (smp_call_function() is not safe in interrupt context) to
  406. * disable the cmc interrupt vector.
  407. */
  408. static void
  409. ia64_mca_cmc_vector_disable_keventd(void *unused)
  410. {
  411. on_each_cpu(ia64_mca_cmc_vector_disable, NULL, 1, 0);
  412. }
  413. /*
  414. * ia64_mca_cmc_vector_enable_keventd
  415. *
  416. * Called via keventd (smp_call_function() is not safe in interrupt context) to
  417. * enable the cmc interrupt vector.
  418. */
  419. static void
  420. ia64_mca_cmc_vector_enable_keventd(void *unused)
  421. {
  422. on_each_cpu(ia64_mca_cmc_vector_enable, NULL, 1, 0);
  423. }
  424. /*
  425. * ia64_mca_wakeup
  426. *
  427. * Send an inter-cpu interrupt to wake-up a particular cpu
  428. * and mark that cpu to be out of rendez.
  429. *
  430. * Inputs : cpuid
  431. * Outputs : None
  432. */
  433. static void
  434. ia64_mca_wakeup(int cpu)
  435. {
  436. platform_send_ipi(cpu, IA64_MCA_WAKEUP_VECTOR, IA64_IPI_DM_INT, 0);
  437. ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
  438. }
  439. /*
  440. * ia64_mca_wakeup_all
  441. *
  442. * Wakeup all the cpus which have rendez'ed previously.
  443. *
  444. * Inputs : None
  445. * Outputs : None
  446. */
  447. static void
  448. ia64_mca_wakeup_all(void)
  449. {
  450. int cpu;
  451. /* Clear the Rendez checkin flag for all cpus */
  452. for_each_online_cpu(cpu) {
  453. if (ia64_mc_info.imi_rendez_checkin[cpu] == IA64_MCA_RENDEZ_CHECKIN_DONE)
  454. ia64_mca_wakeup(cpu);
  455. }
  456. }
  457. /*
  458. * ia64_mca_rendez_interrupt_handler
  459. *
  460. * This is handler used to put slave processors into spinloop
  461. * while the monarch processor does the mca handling and later
  462. * wake each slave up once the monarch is done.
  463. *
  464. * Inputs : None
  465. * Outputs : None
  466. */
  467. static irqreturn_t
  468. ia64_mca_rendez_int_handler(int rendez_irq, void *arg, struct pt_regs *regs)
  469. {
  470. unsigned long flags;
  471. int cpu = smp_processor_id();
  472. /* Mask all interrupts */
  473. local_irq_save(flags);
  474. if (notify_die(DIE_MCA_RENDZVOUS_ENTER, "MCA", regs, 0, 0, 0)
  475. == NOTIFY_STOP)
  476. ia64_mca_spin(__FUNCTION__);
  477. ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_DONE;
  478. /* Register with the SAL monarch that the slave has
  479. * reached SAL
  480. */
  481. ia64_sal_mc_rendez();
  482. if (notify_die(DIE_MCA_RENDZVOUS_PROCESS, "MCA", regs, 0, 0, 0)
  483. == NOTIFY_STOP)
  484. ia64_mca_spin(__FUNCTION__);
  485. /* Wait for the monarch cpu to exit. */
  486. while (monarch_cpu != -1)
  487. cpu_relax(); /* spin until monarch leaves */
  488. if (notify_die(DIE_MCA_RENDZVOUS_LEAVE, "MCA", regs, 0, 0, 0)
  489. == NOTIFY_STOP)
  490. ia64_mca_spin(__FUNCTION__);
  491. /* Enable all interrupts */
  492. local_irq_restore(flags);
  493. return IRQ_HANDLED;
  494. }
  495. /*
  496. * ia64_mca_wakeup_int_handler
  497. *
  498. * The interrupt handler for processing the inter-cpu interrupt to the
  499. * slave cpu which was spinning in the rendez loop.
  500. * Since this spinning is done by turning off the interrupts and
  501. * polling on the wakeup-interrupt bit in the IRR, there is
  502. * nothing useful to be done in the handler.
  503. *
  504. * Inputs : wakeup_irq (Wakeup-interrupt bit)
  505. * arg (Interrupt handler specific argument)
  506. * ptregs (Exception frame at the time of the interrupt)
  507. * Outputs : None
  508. *
  509. */
  510. static irqreturn_t
  511. ia64_mca_wakeup_int_handler(int wakeup_irq, void *arg, struct pt_regs *ptregs)
  512. {
  513. return IRQ_HANDLED;
  514. }
  515. /* Function pointer for extra MCA recovery */
  516. int (*ia64_mca_ucmc_extension)
  517. (void*,struct ia64_sal_os_state*)
  518. = NULL;
  519. int
  520. ia64_reg_MCA_extension(int (*fn)(void *, struct ia64_sal_os_state *))
  521. {
  522. if (ia64_mca_ucmc_extension)
  523. return 1;
  524. ia64_mca_ucmc_extension = fn;
  525. return 0;
  526. }
  527. void
  528. ia64_unreg_MCA_extension(void)
  529. {
  530. if (ia64_mca_ucmc_extension)
  531. ia64_mca_ucmc_extension = NULL;
  532. }
  533. EXPORT_SYMBOL(ia64_reg_MCA_extension);
  534. EXPORT_SYMBOL(ia64_unreg_MCA_extension);
  535. static inline void
  536. copy_reg(const u64 *fr, u64 fnat, u64 *tr, u64 *tnat)
  537. {
  538. u64 fslot, tslot, nat;
  539. *tr = *fr;
  540. fslot = ((unsigned long)fr >> 3) & 63;
  541. tslot = ((unsigned long)tr >> 3) & 63;
  542. *tnat &= ~(1UL << tslot);
  543. nat = (fnat >> fslot) & 1;
  544. *tnat |= (nat << tslot);
  545. }
  546. /* On entry to this routine, we are running on the per cpu stack, see
  547. * mca_asm.h. The original stack has not been touched by this event. Some of
  548. * the original stack's registers will be in the RBS on this stack. This stack
  549. * also contains a partial pt_regs and switch_stack, the rest of the data is in
  550. * PAL minstate.
  551. *
  552. * The first thing to do is modify the original stack to look like a blocked
  553. * task so we can run backtrace on the original task. Also mark the per cpu
  554. * stack as current to ensure that we use the correct task state, it also means
  555. * that we can do backtrace on the MCA/INIT handler code itself.
  556. */
  557. static task_t *
  558. ia64_mca_modify_original_stack(struct pt_regs *regs,
  559. const struct switch_stack *sw,
  560. struct ia64_sal_os_state *sos,
  561. const char *type)
  562. {
  563. char *p, comm[sizeof(current->comm)];
  564. ia64_va va;
  565. extern char ia64_leave_kernel[]; /* Need asm address, not function descriptor */
  566. const pal_min_state_area_t *ms = sos->pal_min_state;
  567. task_t *previous_current;
  568. struct pt_regs *old_regs;
  569. struct switch_stack *old_sw;
  570. unsigned size = sizeof(struct pt_regs) +
  571. sizeof(struct switch_stack) + 16;
  572. u64 *old_bspstore, *old_bsp;
  573. u64 *new_bspstore, *new_bsp;
  574. u64 old_unat, old_rnat, new_rnat, nat;
  575. u64 slots, loadrs = regs->loadrs;
  576. u64 r12 = ms->pmsa_gr[12-1], r13 = ms->pmsa_gr[13-1];
  577. u64 ar_bspstore = regs->ar_bspstore;
  578. u64 ar_bsp = regs->ar_bspstore + (loadrs >> 16);
  579. const u64 *bank;
  580. const char *msg;
  581. int cpu = smp_processor_id();
  582. previous_current = curr_task(cpu);
  583. set_curr_task(cpu, current);
  584. if ((p = strchr(current->comm, ' ')))
  585. *p = '\0';
  586. /* Best effort attempt to cope with MCA/INIT delivered while in
  587. * physical mode.
  588. */
  589. regs->cr_ipsr = ms->pmsa_ipsr;
  590. if (ia64_psr(regs)->dt == 0) {
  591. va.l = r12;
  592. if (va.f.reg == 0) {
  593. va.f.reg = 7;
  594. r12 = va.l;
  595. }
  596. va.l = r13;
  597. if (va.f.reg == 0) {
  598. va.f.reg = 7;
  599. r13 = va.l;
  600. }
  601. }
  602. if (ia64_psr(regs)->rt == 0) {
  603. va.l = ar_bspstore;
  604. if (va.f.reg == 0) {
  605. va.f.reg = 7;
  606. ar_bspstore = va.l;
  607. }
  608. va.l = ar_bsp;
  609. if (va.f.reg == 0) {
  610. va.f.reg = 7;
  611. ar_bsp = va.l;
  612. }
  613. }
  614. /* mca_asm.S ia64_old_stack() cannot assume that the dirty registers
  615. * have been copied to the old stack, the old stack may fail the
  616. * validation tests below. So ia64_old_stack() must restore the dirty
  617. * registers from the new stack. The old and new bspstore probably
  618. * have different alignments, so loadrs calculated on the old bsp
  619. * cannot be used to restore from the new bsp. Calculate a suitable
  620. * loadrs for the new stack and save it in the new pt_regs, where
  621. * ia64_old_stack() can get it.
  622. */
  623. old_bspstore = (u64 *)ar_bspstore;
  624. old_bsp = (u64 *)ar_bsp;
  625. slots = ia64_rse_num_regs(old_bspstore, old_bsp);
  626. new_bspstore = (u64 *)((u64)current + IA64_RBS_OFFSET);
  627. new_bsp = ia64_rse_skip_regs(new_bspstore, slots);
  628. regs->loadrs = (new_bsp - new_bspstore) * 8 << 16;
  629. /* Verify the previous stack state before we change it */
  630. if (user_mode(regs)) {
  631. msg = "occurred in user space";
  632. goto no_mod;
  633. }
  634. if (r13 != sos->prev_IA64_KR_CURRENT) {
  635. msg = "inconsistent previous current and r13";
  636. goto no_mod;
  637. }
  638. if ((r12 - r13) >= KERNEL_STACK_SIZE) {
  639. msg = "inconsistent r12 and r13";
  640. goto no_mod;
  641. }
  642. if ((ar_bspstore - r13) >= KERNEL_STACK_SIZE) {
  643. msg = "inconsistent ar.bspstore and r13";
  644. goto no_mod;
  645. }
  646. va.p = old_bspstore;
  647. if (va.f.reg < 5) {
  648. msg = "old_bspstore is in the wrong region";
  649. goto no_mod;
  650. }
  651. if ((ar_bsp - r13) >= KERNEL_STACK_SIZE) {
  652. msg = "inconsistent ar.bsp and r13";
  653. goto no_mod;
  654. }
  655. size += (ia64_rse_skip_regs(old_bspstore, slots) - old_bspstore) * 8;
  656. if (ar_bspstore + size > r12) {
  657. msg = "no room for blocked state";
  658. goto no_mod;
  659. }
  660. /* Change the comm field on the MCA/INT task to include the pid that
  661. * was interrupted, it makes for easier debugging. If that pid was 0
  662. * (swapper or nested MCA/INIT) then use the start of the previous comm
  663. * field suffixed with its cpu.
  664. */
  665. if (previous_current->pid)
  666. snprintf(comm, sizeof(comm), "%s %d",
  667. current->comm, previous_current->pid);
  668. else {
  669. int l;
  670. if ((p = strchr(previous_current->comm, ' ')))
  671. l = p - previous_current->comm;
  672. else
  673. l = strlen(previous_current->comm);
  674. snprintf(comm, sizeof(comm), "%s %*s %d",
  675. current->comm, l, previous_current->comm,
  676. task_thread_info(previous_current)->cpu);
  677. }
  678. memcpy(current->comm, comm, sizeof(current->comm));
  679. /* Make the original task look blocked. First stack a struct pt_regs,
  680. * describing the state at the time of interrupt. mca_asm.S built a
  681. * partial pt_regs, copy it and fill in the blanks using minstate.
  682. */
  683. p = (char *)r12 - sizeof(*regs);
  684. old_regs = (struct pt_regs *)p;
  685. memcpy(old_regs, regs, sizeof(*regs));
  686. /* If ipsr.ic then use pmsa_{iip,ipsr,ifs}, else use
  687. * pmsa_{xip,xpsr,xfs}
  688. */
  689. if (ia64_psr(regs)->ic) {
  690. old_regs->cr_iip = ms->pmsa_iip;
  691. old_regs->cr_ipsr = ms->pmsa_ipsr;
  692. old_regs->cr_ifs = ms->pmsa_ifs;
  693. } else {
  694. old_regs->cr_iip = ms->pmsa_xip;
  695. old_regs->cr_ipsr = ms->pmsa_xpsr;
  696. old_regs->cr_ifs = ms->pmsa_xfs;
  697. }
  698. old_regs->pr = ms->pmsa_pr;
  699. old_regs->b0 = ms->pmsa_br0;
  700. old_regs->loadrs = loadrs;
  701. old_regs->ar_rsc = ms->pmsa_rsc;
  702. old_unat = old_regs->ar_unat;
  703. copy_reg(&ms->pmsa_gr[1-1], ms->pmsa_nat_bits, &old_regs->r1, &old_unat);
  704. copy_reg(&ms->pmsa_gr[2-1], ms->pmsa_nat_bits, &old_regs->r2, &old_unat);
  705. copy_reg(&ms->pmsa_gr[3-1], ms->pmsa_nat_bits, &old_regs->r3, &old_unat);
  706. copy_reg(&ms->pmsa_gr[8-1], ms->pmsa_nat_bits, &old_regs->r8, &old_unat);
  707. copy_reg(&ms->pmsa_gr[9-1], ms->pmsa_nat_bits, &old_regs->r9, &old_unat);
  708. copy_reg(&ms->pmsa_gr[10-1], ms->pmsa_nat_bits, &old_regs->r10, &old_unat);
  709. copy_reg(&ms->pmsa_gr[11-1], ms->pmsa_nat_bits, &old_regs->r11, &old_unat);
  710. copy_reg(&ms->pmsa_gr[12-1], ms->pmsa_nat_bits, &old_regs->r12, &old_unat);
  711. copy_reg(&ms->pmsa_gr[13-1], ms->pmsa_nat_bits, &old_regs->r13, &old_unat);
  712. copy_reg(&ms->pmsa_gr[14-1], ms->pmsa_nat_bits, &old_regs->r14, &old_unat);
  713. copy_reg(&ms->pmsa_gr[15-1], ms->pmsa_nat_bits, &old_regs->r15, &old_unat);
  714. if (ia64_psr(old_regs)->bn)
  715. bank = ms->pmsa_bank1_gr;
  716. else
  717. bank = ms->pmsa_bank0_gr;
  718. copy_reg(&bank[16-16], ms->pmsa_nat_bits, &old_regs->r16, &old_unat);
  719. copy_reg(&bank[17-16], ms->pmsa_nat_bits, &old_regs->r17, &old_unat);
  720. copy_reg(&bank[18-16], ms->pmsa_nat_bits, &old_regs->r18, &old_unat);
  721. copy_reg(&bank[19-16], ms->pmsa_nat_bits, &old_regs->r19, &old_unat);
  722. copy_reg(&bank[20-16], ms->pmsa_nat_bits, &old_regs->r20, &old_unat);
  723. copy_reg(&bank[21-16], ms->pmsa_nat_bits, &old_regs->r21, &old_unat);
  724. copy_reg(&bank[22-16], ms->pmsa_nat_bits, &old_regs->r22, &old_unat);
  725. copy_reg(&bank[23-16], ms->pmsa_nat_bits, &old_regs->r23, &old_unat);
  726. copy_reg(&bank[24-16], ms->pmsa_nat_bits, &old_regs->r24, &old_unat);
  727. copy_reg(&bank[25-16], ms->pmsa_nat_bits, &old_regs->r25, &old_unat);
  728. copy_reg(&bank[26-16], ms->pmsa_nat_bits, &old_regs->r26, &old_unat);
  729. copy_reg(&bank[27-16], ms->pmsa_nat_bits, &old_regs->r27, &old_unat);
  730. copy_reg(&bank[28-16], ms->pmsa_nat_bits, &old_regs->r28, &old_unat);
  731. copy_reg(&bank[29-16], ms->pmsa_nat_bits, &old_regs->r29, &old_unat);
  732. copy_reg(&bank[30-16], ms->pmsa_nat_bits, &old_regs->r30, &old_unat);
  733. copy_reg(&bank[31-16], ms->pmsa_nat_bits, &old_regs->r31, &old_unat);
  734. /* Next stack a struct switch_stack. mca_asm.S built a partial
  735. * switch_stack, copy it and fill in the blanks using pt_regs and
  736. * minstate.
  737. *
  738. * In the synthesized switch_stack, b0 points to ia64_leave_kernel,
  739. * ar.pfs is set to 0.
  740. *
  741. * unwind.c::unw_unwind() does special processing for interrupt frames.
  742. * It checks if the PRED_NON_SYSCALL predicate is set, if the predicate
  743. * is clear then unw_unwind() does _not_ adjust bsp over pt_regs. Not
  744. * that this is documented, of course. Set PRED_NON_SYSCALL in the
  745. * switch_stack on the original stack so it will unwind correctly when
  746. * unwind.c reads pt_regs.
  747. *
  748. * thread.ksp is updated to point to the synthesized switch_stack.
  749. */
  750. p -= sizeof(struct switch_stack);
  751. old_sw = (struct switch_stack *)p;
  752. memcpy(old_sw, sw, sizeof(*sw));
  753. old_sw->caller_unat = old_unat;
  754. old_sw->ar_fpsr = old_regs->ar_fpsr;
  755. copy_reg(&ms->pmsa_gr[4-1], ms->pmsa_nat_bits, &old_sw->r4, &old_unat);
  756. copy_reg(&ms->pmsa_gr[5-1], ms->pmsa_nat_bits, &old_sw->r5, &old_unat);
  757. copy_reg(&ms->pmsa_gr[6-1], ms->pmsa_nat_bits, &old_sw->r6, &old_unat);
  758. copy_reg(&ms->pmsa_gr[7-1], ms->pmsa_nat_bits, &old_sw->r7, &old_unat);
  759. old_sw->b0 = (u64)ia64_leave_kernel;
  760. old_sw->b1 = ms->pmsa_br1;
  761. old_sw->ar_pfs = 0;
  762. old_sw->ar_unat = old_unat;
  763. old_sw->pr = old_regs->pr | (1UL << PRED_NON_SYSCALL);
  764. previous_current->thread.ksp = (u64)p - 16;
  765. /* Finally copy the original stack's registers back to its RBS.
  766. * Registers from ar.bspstore through ar.bsp at the time of the event
  767. * are in the current RBS, copy them back to the original stack. The
  768. * copy must be done register by register because the original bspstore
  769. * and the current one have different alignments, so the saved RNAT
  770. * data occurs at different places.
  771. *
  772. * mca_asm does cover, so the old_bsp already includes all registers at
  773. * the time of MCA/INIT. It also does flushrs, so all registers before
  774. * this function have been written to backing store on the MCA/INIT
  775. * stack.
  776. */
  777. new_rnat = ia64_get_rnat(ia64_rse_rnat_addr(new_bspstore));
  778. old_rnat = regs->ar_rnat;
  779. while (slots--) {
  780. if (ia64_rse_is_rnat_slot(new_bspstore)) {
  781. new_rnat = ia64_get_rnat(new_bspstore++);
  782. }
  783. if (ia64_rse_is_rnat_slot(old_bspstore)) {
  784. *old_bspstore++ = old_rnat;
  785. old_rnat = 0;
  786. }
  787. nat = (new_rnat >> ia64_rse_slot_num(new_bspstore)) & 1UL;
  788. old_rnat &= ~(1UL << ia64_rse_slot_num(old_bspstore));
  789. old_rnat |= (nat << ia64_rse_slot_num(old_bspstore));
  790. *old_bspstore++ = *new_bspstore++;
  791. }
  792. old_sw->ar_bspstore = (unsigned long)old_bspstore;
  793. old_sw->ar_rnat = old_rnat;
  794. sos->prev_task = previous_current;
  795. return previous_current;
  796. no_mod:
  797. printk(KERN_INFO "cpu %d, %s %s, original stack not modified\n",
  798. smp_processor_id(), type, msg);
  799. return previous_current;
  800. }
  801. /* The monarch/slave interaction is based on monarch_cpu and requires that all
  802. * slaves have entered rendezvous before the monarch leaves. If any cpu has
  803. * not entered rendezvous yet then wait a bit. The assumption is that any
  804. * slave that has not rendezvoused after a reasonable time is never going to do
  805. * so. In this context, slave includes cpus that respond to the MCA rendezvous
  806. * interrupt, as well as cpus that receive the INIT slave event.
  807. */
  808. static void
  809. ia64_wait_for_slaves(int monarch)
  810. {
  811. int c, wait = 0;
  812. for_each_online_cpu(c) {
  813. if (c == monarch)
  814. continue;
  815. if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) {
  816. udelay(1000); /* short wait first */
  817. wait = 1;
  818. break;
  819. }
  820. }
  821. if (!wait)
  822. return;
  823. for_each_online_cpu(c) {
  824. if (c == monarch)
  825. continue;
  826. if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) {
  827. udelay(5*1000000); /* wait 5 seconds for slaves (arbitrary) */
  828. break;
  829. }
  830. }
  831. }
  832. /*
  833. * ia64_mca_handler
  834. *
  835. * This is uncorrectable machine check handler called from OS_MCA
  836. * dispatch code which is in turn called from SAL_CHECK().
  837. * This is the place where the core of OS MCA handling is done.
  838. * Right now the logs are extracted and displayed in a well-defined
  839. * format. This handler code is supposed to be run only on the
  840. * monarch processor. Once the monarch is done with MCA handling
  841. * further MCA logging is enabled by clearing logs.
  842. * Monarch also has the duty of sending wakeup-IPIs to pull the
  843. * slave processors out of rendezvous spinloop.
  844. */
  845. void
  846. ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw,
  847. struct ia64_sal_os_state *sos)
  848. {
  849. pal_processor_state_info_t *psp = (pal_processor_state_info_t *)
  850. &sos->proc_state_param;
  851. int recover, cpu = smp_processor_id();
  852. task_t *previous_current;
  853. oops_in_progress = 1; /* FIXME: make printk NMI/MCA/INIT safe */
  854. previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "MCA");
  855. monarch_cpu = cpu;
  856. if (notify_die(DIE_MCA_MONARCH_ENTER, "MCA", regs, 0, 0, 0)
  857. == NOTIFY_STOP)
  858. ia64_mca_spin(__FUNCTION__);
  859. ia64_wait_for_slaves(cpu);
  860. /* Wakeup all the processors which are spinning in the rendezvous loop.
  861. * They will leave SAL, then spin in the OS with interrupts disabled
  862. * until this monarch cpu leaves the MCA handler. That gets control
  863. * back to the OS so we can backtrace the other cpus, backtrace when
  864. * spinning in SAL does not work.
  865. */
  866. ia64_mca_wakeup_all();
  867. if (notify_die(DIE_MCA_MONARCH_PROCESS, "MCA", regs, 0, 0, 0)
  868. == NOTIFY_STOP)
  869. ia64_mca_spin(__FUNCTION__);
  870. /* Get the MCA error record and log it */
  871. ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA);
  872. /* TLB error is only exist in this SAL error record */
  873. recover = (psp->tc && !(psp->cc || psp->bc || psp->rc || psp->uc))
  874. /* other error recovery */
  875. || (ia64_mca_ucmc_extension
  876. && ia64_mca_ucmc_extension(
  877. IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA),
  878. sos));
  879. if (recover) {
  880. sal_log_record_header_t *rh = IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA);
  881. rh->severity = sal_log_severity_corrected;
  882. ia64_sal_clear_state_info(SAL_INFO_TYPE_MCA);
  883. sos->os_status = IA64_MCA_CORRECTED;
  884. }
  885. if (notify_die(DIE_MCA_MONARCH_LEAVE, "MCA", regs, 0, 0, recover)
  886. == NOTIFY_STOP)
  887. ia64_mca_spin(__FUNCTION__);
  888. set_curr_task(cpu, previous_current);
  889. monarch_cpu = -1;
  890. }
  891. static DECLARE_WORK(cmc_disable_work, ia64_mca_cmc_vector_disable_keventd, NULL);
  892. static DECLARE_WORK(cmc_enable_work, ia64_mca_cmc_vector_enable_keventd, NULL);
  893. /*
  894. * ia64_mca_cmc_int_handler
  895. *
  896. * This is corrected machine check interrupt handler.
  897. * Right now the logs are extracted and displayed in a well-defined
  898. * format.
  899. *
  900. * Inputs
  901. * interrupt number
  902. * client data arg ptr
  903. * saved registers ptr
  904. *
  905. * Outputs
  906. * None
  907. */
  908. static irqreturn_t
  909. ia64_mca_cmc_int_handler(int cmc_irq, void *arg, struct pt_regs *ptregs)
  910. {
  911. static unsigned long cmc_history[CMC_HISTORY_LENGTH];
  912. static int index;
  913. static DEFINE_SPINLOCK(cmc_history_lock);
  914. IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
  915. __FUNCTION__, cmc_irq, smp_processor_id());
  916. /* SAL spec states this should run w/ interrupts enabled */
  917. local_irq_enable();
  918. /* Get the CMC error record and log it */
  919. ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC);
  920. spin_lock(&cmc_history_lock);
  921. if (!cmc_polling_enabled) {
  922. int i, count = 1; /* we know 1 happened now */
  923. unsigned long now = jiffies;
  924. for (i = 0; i < CMC_HISTORY_LENGTH; i++) {
  925. if (now - cmc_history[i] <= HZ)
  926. count++;
  927. }
  928. IA64_MCA_DEBUG(KERN_INFO "CMC threshold %d/%d\n", count, CMC_HISTORY_LENGTH);
  929. if (count >= CMC_HISTORY_LENGTH) {
  930. cmc_polling_enabled = 1;
  931. spin_unlock(&cmc_history_lock);
  932. /* If we're being hit with CMC interrupts, we won't
  933. * ever execute the schedule_work() below. Need to
  934. * disable CMC interrupts on this processor now.
  935. */
  936. ia64_mca_cmc_vector_disable(NULL);
  937. schedule_work(&cmc_disable_work);
  938. /*
  939. * Corrected errors will still be corrected, but
  940. * make sure there's a log somewhere that indicates
  941. * something is generating more than we can handle.
  942. */
  943. printk(KERN_WARNING "WARNING: Switching to polling CMC handler; error records may be lost\n");
  944. mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
  945. /* lock already released, get out now */
  946. return IRQ_HANDLED;
  947. } else {
  948. cmc_history[index++] = now;
  949. if (index == CMC_HISTORY_LENGTH)
  950. index = 0;
  951. }
  952. }
  953. spin_unlock(&cmc_history_lock);
  954. return IRQ_HANDLED;
  955. }
  956. /*
  957. * ia64_mca_cmc_int_caller
  958. *
  959. * Triggered by sw interrupt from CMC polling routine. Calls
  960. * real interrupt handler and either triggers a sw interrupt
  961. * on the next cpu or does cleanup at the end.
  962. *
  963. * Inputs
  964. * interrupt number
  965. * client data arg ptr
  966. * saved registers ptr
  967. * Outputs
  968. * handled
  969. */
  970. static irqreturn_t
  971. ia64_mca_cmc_int_caller(int cmc_irq, void *arg, struct pt_regs *ptregs)
  972. {
  973. static int start_count = -1;
  974. unsigned int cpuid;
  975. cpuid = smp_processor_id();
  976. /* If first cpu, update count */
  977. if (start_count == -1)
  978. start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CMC);
  979. ia64_mca_cmc_int_handler(cmc_irq, arg, ptregs);
  980. for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
  981. if (cpuid < NR_CPUS) {
  982. platform_send_ipi(cpuid, IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
  983. } else {
  984. /* If no log record, switch out of polling mode */
  985. if (start_count == IA64_LOG_COUNT(SAL_INFO_TYPE_CMC)) {
  986. printk(KERN_WARNING "Returning to interrupt driven CMC handler\n");
  987. schedule_work(&cmc_enable_work);
  988. cmc_polling_enabled = 0;
  989. } else {
  990. mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
  991. }
  992. start_count = -1;
  993. }
  994. return IRQ_HANDLED;
  995. }
  996. /*
  997. * ia64_mca_cmc_poll
  998. *
  999. * Poll for Corrected Machine Checks (CMCs)
  1000. *
  1001. * Inputs : dummy(unused)
  1002. * Outputs : None
  1003. *
  1004. */
  1005. static void
  1006. ia64_mca_cmc_poll (unsigned long dummy)
  1007. {
  1008. /* Trigger a CMC interrupt cascade */
  1009. platform_send_ipi(first_cpu(cpu_online_map), IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
  1010. }
  1011. /*
  1012. * ia64_mca_cpe_int_caller
  1013. *
  1014. * Triggered by sw interrupt from CPE polling routine. Calls
  1015. * real interrupt handler and either triggers a sw interrupt
  1016. * on the next cpu or does cleanup at the end.
  1017. *
  1018. * Inputs
  1019. * interrupt number
  1020. * client data arg ptr
  1021. * saved registers ptr
  1022. * Outputs
  1023. * handled
  1024. */
  1025. #ifdef CONFIG_ACPI
  1026. static irqreturn_t
  1027. ia64_mca_cpe_int_caller(int cpe_irq, void *arg, struct pt_regs *ptregs)
  1028. {
  1029. static int start_count = -1;
  1030. static int poll_time = MIN_CPE_POLL_INTERVAL;
  1031. unsigned int cpuid;
  1032. cpuid = smp_processor_id();
  1033. /* If first cpu, update count */
  1034. if (start_count == -1)
  1035. start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CPE);
  1036. ia64_mca_cpe_int_handler(cpe_irq, arg, ptregs);
  1037. for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
  1038. if (cpuid < NR_CPUS) {
  1039. platform_send_ipi(cpuid, IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
  1040. } else {
  1041. /*
  1042. * If a log was recorded, increase our polling frequency,
  1043. * otherwise, backoff or return to interrupt mode.
  1044. */
  1045. if (start_count != IA64_LOG_COUNT(SAL_INFO_TYPE_CPE)) {
  1046. poll_time = max(MIN_CPE_POLL_INTERVAL, poll_time / 2);
  1047. } else if (cpe_vector < 0) {
  1048. poll_time = min(MAX_CPE_POLL_INTERVAL, poll_time * 2);
  1049. } else {
  1050. poll_time = MIN_CPE_POLL_INTERVAL;
  1051. printk(KERN_WARNING "Returning to interrupt driven CPE handler\n");
  1052. enable_irq(local_vector_to_irq(IA64_CPE_VECTOR));
  1053. cpe_poll_enabled = 0;
  1054. }
  1055. if (cpe_poll_enabled)
  1056. mod_timer(&cpe_poll_timer, jiffies + poll_time);
  1057. start_count = -1;
  1058. }
  1059. return IRQ_HANDLED;
  1060. }
  1061. /*
  1062. * ia64_mca_cpe_poll
  1063. *
  1064. * Poll for Corrected Platform Errors (CPEs), trigger interrupt
  1065. * on first cpu, from there it will trickle through all the cpus.
  1066. *
  1067. * Inputs : dummy(unused)
  1068. * Outputs : None
  1069. *
  1070. */
  1071. static void
  1072. ia64_mca_cpe_poll (unsigned long dummy)
  1073. {
  1074. /* Trigger a CPE interrupt cascade */
  1075. platform_send_ipi(first_cpu(cpu_online_map), IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
  1076. }
  1077. #endif /* CONFIG_ACPI */
  1078. static int
  1079. default_monarch_init_process(struct notifier_block *self, unsigned long val, void *data)
  1080. {
  1081. int c;
  1082. struct task_struct *g, *t;
  1083. if (val != DIE_INIT_MONARCH_PROCESS)
  1084. return NOTIFY_DONE;
  1085. printk(KERN_ERR "Processes interrupted by INIT -");
  1086. for_each_online_cpu(c) {
  1087. struct ia64_sal_os_state *s;
  1088. t = __va(__per_cpu_mca[c] + IA64_MCA_CPU_INIT_STACK_OFFSET);
  1089. s = (struct ia64_sal_os_state *)((char *)t + MCA_SOS_OFFSET);
  1090. g = s->prev_task;
  1091. if (g) {
  1092. if (g->pid)
  1093. printk(" %d", g->pid);
  1094. else
  1095. printk(" %d (cpu %d task 0x%p)", g->pid, task_cpu(g), g);
  1096. }
  1097. }
  1098. printk("\n\n");
  1099. if (read_trylock(&tasklist_lock)) {
  1100. do_each_thread (g, t) {
  1101. printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm);
  1102. show_stack(t, NULL);
  1103. } while_each_thread (g, t);
  1104. read_unlock(&tasklist_lock);
  1105. }
  1106. return NOTIFY_DONE;
  1107. }
  1108. /*
  1109. * C portion of the OS INIT handler
  1110. *
  1111. * Called from ia64_os_init_dispatch
  1112. *
  1113. * Inputs: pointer to pt_regs where processor info was saved. SAL/OS state for
  1114. * this event. This code is used for both monarch and slave INIT events, see
  1115. * sos->monarch.
  1116. *
  1117. * All INIT events switch to the INIT stack and change the previous process to
  1118. * blocked status. If one of the INIT events is the monarch then we are
  1119. * probably processing the nmi button/command. Use the monarch cpu to dump all
  1120. * the processes. The slave INIT events all spin until the monarch cpu
  1121. * returns. We can also get INIT slave events for MCA, in which case the MCA
  1122. * process is the monarch.
  1123. */
  1124. void
  1125. ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw,
  1126. struct ia64_sal_os_state *sos)
  1127. {
  1128. static atomic_t slaves;
  1129. static atomic_t monarchs;
  1130. task_t *previous_current;
  1131. int cpu = smp_processor_id();
  1132. oops_in_progress = 1; /* FIXME: make printk NMI/MCA/INIT safe */
  1133. console_loglevel = 15; /* make sure printks make it to console */
  1134. printk(KERN_INFO "Entered OS INIT handler. PSP=%lx cpu=%d monarch=%ld\n",
  1135. sos->proc_state_param, cpu, sos->monarch);
  1136. salinfo_log_wakeup(SAL_INFO_TYPE_INIT, NULL, 0, 0);
  1137. previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "INIT");
  1138. sos->os_status = IA64_INIT_RESUME;
  1139. /* FIXME: Workaround for broken proms that drive all INIT events as
  1140. * slaves. The last slave that enters is promoted to be a monarch.
  1141. * Remove this code in September 2006, that gives platforms a year to
  1142. * fix their proms and get their customers updated.
  1143. */
  1144. if (!sos->monarch && atomic_add_return(1, &slaves) == num_online_cpus()) {
  1145. printk(KERN_WARNING "%s: Promoting cpu %d to monarch.\n",
  1146. __FUNCTION__, cpu);
  1147. atomic_dec(&slaves);
  1148. sos->monarch = 1;
  1149. }
  1150. /* FIXME: Workaround for broken proms that drive all INIT events as
  1151. * monarchs. Second and subsequent monarchs are demoted to slaves.
  1152. * Remove this code in September 2006, that gives platforms a year to
  1153. * fix their proms and get their customers updated.
  1154. */
  1155. if (sos->monarch && atomic_add_return(1, &monarchs) > 1) {
  1156. printk(KERN_WARNING "%s: Demoting cpu %d to slave.\n",
  1157. __FUNCTION__, cpu);
  1158. atomic_dec(&monarchs);
  1159. sos->monarch = 0;
  1160. }
  1161. if (!sos->monarch) {
  1162. ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_INIT;
  1163. while (monarch_cpu == -1)
  1164. cpu_relax(); /* spin until monarch enters */
  1165. if (notify_die(DIE_INIT_SLAVE_ENTER, "INIT", regs, 0, 0, 0)
  1166. == NOTIFY_STOP)
  1167. ia64_mca_spin(__FUNCTION__);
  1168. if (notify_die(DIE_INIT_SLAVE_PROCESS, "INIT", regs, 0, 0, 0)
  1169. == NOTIFY_STOP)
  1170. ia64_mca_spin(__FUNCTION__);
  1171. while (monarch_cpu != -1)
  1172. cpu_relax(); /* spin until monarch leaves */
  1173. if (notify_die(DIE_INIT_SLAVE_LEAVE, "INIT", regs, 0, 0, 0)
  1174. == NOTIFY_STOP)
  1175. ia64_mca_spin(__FUNCTION__);
  1176. printk("Slave on cpu %d returning to normal service.\n", cpu);
  1177. set_curr_task(cpu, previous_current);
  1178. ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
  1179. atomic_dec(&slaves);
  1180. return;
  1181. }
  1182. monarch_cpu = cpu;
  1183. if (notify_die(DIE_INIT_MONARCH_ENTER, "INIT", regs, 0, 0, 0)
  1184. == NOTIFY_STOP)
  1185. ia64_mca_spin(__FUNCTION__);
  1186. /*
  1187. * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be
  1188. * generated via the BMC's command-line interface, but since the console is on the
  1189. * same serial line, the user will need some time to switch out of the BMC before
  1190. * the dump begins.
  1191. */
  1192. printk("Delaying for 5 seconds...\n");
  1193. udelay(5*1000000);
  1194. ia64_wait_for_slaves(cpu);
  1195. /* If nobody intercepts DIE_INIT_MONARCH_PROCESS then we drop through
  1196. * to default_monarch_init_process() above and just print all the
  1197. * tasks.
  1198. */
  1199. if (notify_die(DIE_INIT_MONARCH_PROCESS, "INIT", regs, 0, 0, 0)
  1200. == NOTIFY_STOP)
  1201. ia64_mca_spin(__FUNCTION__);
  1202. if (notify_die(DIE_INIT_MONARCH_LEAVE, "INIT", regs, 0, 0, 0)
  1203. == NOTIFY_STOP)
  1204. ia64_mca_spin(__FUNCTION__);
  1205. printk("\nINIT dump complete. Monarch on cpu %d returning to normal service.\n", cpu);
  1206. atomic_dec(&monarchs);
  1207. set_curr_task(cpu, previous_current);
  1208. monarch_cpu = -1;
  1209. return;
  1210. }
  1211. static int __init
  1212. ia64_mca_disable_cpe_polling(char *str)
  1213. {
  1214. cpe_poll_enabled = 0;
  1215. return 1;
  1216. }
  1217. __setup("disable_cpe_poll", ia64_mca_disable_cpe_polling);
  1218. static struct irqaction cmci_irqaction = {
  1219. .handler = ia64_mca_cmc_int_handler,
  1220. .flags = SA_INTERRUPT,
  1221. .name = "cmc_hndlr"
  1222. };
  1223. static struct irqaction cmcp_irqaction = {
  1224. .handler = ia64_mca_cmc_int_caller,
  1225. .flags = SA_INTERRUPT,
  1226. .name = "cmc_poll"
  1227. };
  1228. static struct irqaction mca_rdzv_irqaction = {
  1229. .handler = ia64_mca_rendez_int_handler,
  1230. .flags = SA_INTERRUPT,
  1231. .name = "mca_rdzv"
  1232. };
  1233. static struct irqaction mca_wkup_irqaction = {
  1234. .handler = ia64_mca_wakeup_int_handler,
  1235. .flags = SA_INTERRUPT,
  1236. .name = "mca_wkup"
  1237. };
  1238. #ifdef CONFIG_ACPI
  1239. static struct irqaction mca_cpe_irqaction = {
  1240. .handler = ia64_mca_cpe_int_handler,
  1241. .flags = SA_INTERRUPT,
  1242. .name = "cpe_hndlr"
  1243. };
  1244. static struct irqaction mca_cpep_irqaction = {
  1245. .handler = ia64_mca_cpe_int_caller,
  1246. .flags = SA_INTERRUPT,
  1247. .name = "cpe_poll"
  1248. };
  1249. #endif /* CONFIG_ACPI */
  1250. /* Minimal format of the MCA/INIT stacks. The pseudo processes that run on
  1251. * these stacks can never sleep, they cannot return from the kernel to user
  1252. * space, they do not appear in a normal ps listing. So there is no need to
  1253. * format most of the fields.
  1254. */
  1255. static void
  1256. format_mca_init_stack(void *mca_data, unsigned long offset,
  1257. const char *type, int cpu)
  1258. {
  1259. struct task_struct *p = (struct task_struct *)((char *)mca_data + offset);
  1260. struct thread_info *ti;
  1261. memset(p, 0, KERNEL_STACK_SIZE);
  1262. ti = task_thread_info(p);
  1263. ti->flags = _TIF_MCA_INIT;
  1264. ti->preempt_count = 1;
  1265. ti->task = p;
  1266. ti->cpu = cpu;
  1267. p->thread_info = ti;
  1268. p->state = TASK_UNINTERRUPTIBLE;
  1269. __set_bit(cpu, &p->cpus_allowed);
  1270. INIT_LIST_HEAD(&p->tasks);
  1271. p->parent = p->real_parent = p->group_leader = p;
  1272. INIT_LIST_HEAD(&p->children);
  1273. INIT_LIST_HEAD(&p->sibling);
  1274. strncpy(p->comm, type, sizeof(p->comm)-1);
  1275. }
  1276. /* Do per-CPU MCA-related initialization. */
  1277. void __devinit
  1278. ia64_mca_cpu_init(void *cpu_data)
  1279. {
  1280. void *pal_vaddr;
  1281. static int first_time = 1;
  1282. if (first_time) {
  1283. void *mca_data;
  1284. int cpu;
  1285. first_time = 0;
  1286. mca_data = alloc_bootmem(sizeof(struct ia64_mca_cpu)
  1287. * NR_CPUS + KERNEL_STACK_SIZE);
  1288. mca_data = (void *)(((unsigned long)mca_data +
  1289. KERNEL_STACK_SIZE - 1) &
  1290. (-KERNEL_STACK_SIZE));
  1291. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  1292. format_mca_init_stack(mca_data,
  1293. offsetof(struct ia64_mca_cpu, mca_stack),
  1294. "MCA", cpu);
  1295. format_mca_init_stack(mca_data,
  1296. offsetof(struct ia64_mca_cpu, init_stack),
  1297. "INIT", cpu);
  1298. __per_cpu_mca[cpu] = __pa(mca_data);
  1299. mca_data += sizeof(struct ia64_mca_cpu);
  1300. }
  1301. }
  1302. /*
  1303. * The MCA info structure was allocated earlier and its
  1304. * physical address saved in __per_cpu_mca[cpu]. Copy that
  1305. * address * to ia64_mca_data so we can access it as a per-CPU
  1306. * variable.
  1307. */
  1308. __get_cpu_var(ia64_mca_data) = __per_cpu_mca[smp_processor_id()];
  1309. /*
  1310. * Stash away a copy of the PTE needed to map the per-CPU page.
  1311. * We may need it during MCA recovery.
  1312. */
  1313. __get_cpu_var(ia64_mca_per_cpu_pte) =
  1314. pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL));
  1315. /*
  1316. * Also, stash away a copy of the PAL address and the PTE
  1317. * needed to map it.
  1318. */
  1319. pal_vaddr = efi_get_pal_addr();
  1320. if (!pal_vaddr)
  1321. return;
  1322. __get_cpu_var(ia64_mca_pal_base) =
  1323. GRANULEROUNDDOWN((unsigned long) pal_vaddr);
  1324. __get_cpu_var(ia64_mca_pal_pte) = pte_val(mk_pte_phys(__pa(pal_vaddr),
  1325. PAGE_KERNEL));
  1326. }
  1327. /*
  1328. * ia64_mca_init
  1329. *
  1330. * Do all the system level mca specific initialization.
  1331. *
  1332. * 1. Register spinloop and wakeup request interrupt vectors
  1333. *
  1334. * 2. Register OS_MCA handler entry point
  1335. *
  1336. * 3. Register OS_INIT handler entry point
  1337. *
  1338. * 4. Initialize MCA/CMC/INIT related log buffers maintained by the OS.
  1339. *
  1340. * Note that this initialization is done very early before some kernel
  1341. * services are available.
  1342. *
  1343. * Inputs : None
  1344. *
  1345. * Outputs : None
  1346. */
  1347. void __init
  1348. ia64_mca_init(void)
  1349. {
  1350. ia64_fptr_t *init_hldlr_ptr_monarch = (ia64_fptr_t *)ia64_os_init_dispatch_monarch;
  1351. ia64_fptr_t *init_hldlr_ptr_slave = (ia64_fptr_t *)ia64_os_init_dispatch_slave;
  1352. ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch;
  1353. int i;
  1354. s64 rc;
  1355. struct ia64_sal_retval isrv;
  1356. u64 timeout = IA64_MCA_RENDEZ_TIMEOUT; /* platform specific */
  1357. static struct notifier_block default_init_monarch_nb = {
  1358. .notifier_call = default_monarch_init_process,
  1359. .priority = 0/* we need to notified last */
  1360. };
  1361. IA64_MCA_DEBUG("%s: begin\n", __FUNCTION__);
  1362. /* Clear the Rendez checkin flag for all cpus */
  1363. for(i = 0 ; i < NR_CPUS; i++)
  1364. ia64_mc_info.imi_rendez_checkin[i] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
  1365. /*
  1366. * Register the rendezvous spinloop and wakeup mechanism with SAL
  1367. */
  1368. /* Register the rendezvous interrupt vector with SAL */
  1369. while (1) {
  1370. isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_INT,
  1371. SAL_MC_PARAM_MECHANISM_INT,
  1372. IA64_MCA_RENDEZ_VECTOR,
  1373. timeout,
  1374. SAL_MC_PARAM_RZ_ALWAYS);
  1375. rc = isrv.status;
  1376. if (rc == 0)
  1377. break;
  1378. if (rc == -2) {
  1379. printk(KERN_INFO "Increasing MCA rendezvous timeout from "
  1380. "%ld to %ld milliseconds\n", timeout, isrv.v0);
  1381. timeout = isrv.v0;
  1382. continue;
  1383. }
  1384. printk(KERN_ERR "Failed to register rendezvous interrupt "
  1385. "with SAL (status %ld)\n", rc);
  1386. return;
  1387. }
  1388. /* Register the wakeup interrupt vector with SAL */
  1389. isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_WAKEUP,
  1390. SAL_MC_PARAM_MECHANISM_INT,
  1391. IA64_MCA_WAKEUP_VECTOR,
  1392. 0, 0);
  1393. rc = isrv.status;
  1394. if (rc) {
  1395. printk(KERN_ERR "Failed to register wakeup interrupt with SAL "
  1396. "(status %ld)\n", rc);
  1397. return;
  1398. }
  1399. IA64_MCA_DEBUG("%s: registered MCA rendezvous spinloop and wakeup mech.\n", __FUNCTION__);
  1400. ia64_mc_info.imi_mca_handler = ia64_tpa(mca_hldlr_ptr->fp);
  1401. /*
  1402. * XXX - disable SAL checksum by setting size to 0; should be
  1403. * ia64_tpa(ia64_os_mca_dispatch_end) - ia64_tpa(ia64_os_mca_dispatch);
  1404. */
  1405. ia64_mc_info.imi_mca_handler_size = 0;
  1406. /* Register the os mca handler with SAL */
  1407. if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_MCA,
  1408. ia64_mc_info.imi_mca_handler,
  1409. ia64_tpa(mca_hldlr_ptr->gp),
  1410. ia64_mc_info.imi_mca_handler_size,
  1411. 0, 0, 0)))
  1412. {
  1413. printk(KERN_ERR "Failed to register OS MCA handler with SAL "
  1414. "(status %ld)\n", rc);
  1415. return;
  1416. }
  1417. IA64_MCA_DEBUG("%s: registered OS MCA handler with SAL at 0x%lx, gp = 0x%lx\n", __FUNCTION__,
  1418. ia64_mc_info.imi_mca_handler, ia64_tpa(mca_hldlr_ptr->gp));
  1419. /*
  1420. * XXX - disable SAL checksum by setting size to 0, should be
  1421. * size of the actual init handler in mca_asm.S.
  1422. */
  1423. ia64_mc_info.imi_monarch_init_handler = ia64_tpa(init_hldlr_ptr_monarch->fp);
  1424. ia64_mc_info.imi_monarch_init_handler_size = 0;
  1425. ia64_mc_info.imi_slave_init_handler = ia64_tpa(init_hldlr_ptr_slave->fp);
  1426. ia64_mc_info.imi_slave_init_handler_size = 0;
  1427. IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __FUNCTION__,
  1428. ia64_mc_info.imi_monarch_init_handler);
  1429. /* Register the os init handler with SAL */
  1430. if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_INIT,
  1431. ia64_mc_info.imi_monarch_init_handler,
  1432. ia64_tpa(ia64_getreg(_IA64_REG_GP)),
  1433. ia64_mc_info.imi_monarch_init_handler_size,
  1434. ia64_mc_info.imi_slave_init_handler,
  1435. ia64_tpa(ia64_getreg(_IA64_REG_GP)),
  1436. ia64_mc_info.imi_slave_init_handler_size)))
  1437. {
  1438. printk(KERN_ERR "Failed to register m/s INIT handlers with SAL "
  1439. "(status %ld)\n", rc);
  1440. return;
  1441. }
  1442. if (register_die_notifier(&default_init_monarch_nb)) {
  1443. printk(KERN_ERR "Failed to register default monarch INIT process\n");
  1444. return;
  1445. }
  1446. IA64_MCA_DEBUG("%s: registered OS INIT handler with SAL\n", __FUNCTION__);
  1447. /*
  1448. * Configure the CMCI/P vector and handler. Interrupts for CMC are
  1449. * per-processor, so AP CMC interrupts are setup in smp_callin() (smpboot.c).
  1450. */
  1451. register_percpu_irq(IA64_CMC_VECTOR, &cmci_irqaction);
  1452. register_percpu_irq(IA64_CMCP_VECTOR, &cmcp_irqaction);
  1453. ia64_mca_cmc_vector_setup(); /* Setup vector on BSP */
  1454. /* Setup the MCA rendezvous interrupt vector */
  1455. register_percpu_irq(IA64_MCA_RENDEZ_VECTOR, &mca_rdzv_irqaction);
  1456. /* Setup the MCA wakeup interrupt vector */
  1457. register_percpu_irq(IA64_MCA_WAKEUP_VECTOR, &mca_wkup_irqaction);
  1458. #ifdef CONFIG_ACPI
  1459. /* Setup the CPEI/P handler */
  1460. register_percpu_irq(IA64_CPEP_VECTOR, &mca_cpep_irqaction);
  1461. #endif
  1462. /* Initialize the areas set aside by the OS to buffer the
  1463. * platform/processor error states for MCA/INIT/CMC
  1464. * handling.
  1465. */
  1466. ia64_log_init(SAL_INFO_TYPE_MCA);
  1467. ia64_log_init(SAL_INFO_TYPE_INIT);
  1468. ia64_log_init(SAL_INFO_TYPE_CMC);
  1469. ia64_log_init(SAL_INFO_TYPE_CPE);
  1470. mca_init = 1;
  1471. printk(KERN_INFO "MCA related initialization done\n");
  1472. }
  1473. /*
  1474. * ia64_mca_late_init
  1475. *
  1476. * Opportunity to setup things that require initialization later
  1477. * than ia64_mca_init. Setup a timer to poll for CPEs if the
  1478. * platform doesn't support an interrupt driven mechanism.
  1479. *
  1480. * Inputs : None
  1481. * Outputs : Status
  1482. */
  1483. static int __init
  1484. ia64_mca_late_init(void)
  1485. {
  1486. if (!mca_init)
  1487. return 0;
  1488. /* Setup the CMCI/P vector and handler */
  1489. init_timer(&cmc_poll_timer);
  1490. cmc_poll_timer.function = ia64_mca_cmc_poll;
  1491. /* Unmask/enable the vector */
  1492. cmc_polling_enabled = 0;
  1493. schedule_work(&cmc_enable_work);
  1494. IA64_MCA_DEBUG("%s: CMCI/P setup and enabled.\n", __FUNCTION__);
  1495. #ifdef CONFIG_ACPI
  1496. /* Setup the CPEI/P vector and handler */
  1497. cpe_vector = acpi_request_vector(ACPI_INTERRUPT_CPEI);
  1498. init_timer(&cpe_poll_timer);
  1499. cpe_poll_timer.function = ia64_mca_cpe_poll;
  1500. {
  1501. irq_desc_t *desc;
  1502. unsigned int irq;
  1503. if (cpe_vector >= 0) {
  1504. /* If platform supports CPEI, enable the irq. */
  1505. cpe_poll_enabled = 0;
  1506. for (irq = 0; irq < NR_IRQS; ++irq)
  1507. if (irq_to_vector(irq) == cpe_vector) {
  1508. desc = irq_descp(irq);
  1509. desc->status |= IRQ_PER_CPU;
  1510. setup_irq(irq, &mca_cpe_irqaction);
  1511. ia64_cpe_irq = irq;
  1512. }
  1513. ia64_mca_register_cpev(cpe_vector);
  1514. IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n", __FUNCTION__);
  1515. } else {
  1516. /* If platform doesn't support CPEI, get the timer going. */
  1517. if (cpe_poll_enabled) {
  1518. ia64_mca_cpe_poll(0UL);
  1519. IA64_MCA_DEBUG("%s: CPEP setup and enabled.\n", __FUNCTION__);
  1520. }
  1521. }
  1522. }
  1523. #endif
  1524. return 0;
  1525. }
  1526. device_initcall(ia64_mca_late_init);