mca.c 49 KB

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