mca.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653
  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_each_online_cpu(cpu) {
  442. if (ia64_mc_info.imi_rendez_checkin[cpu] == IA64_MCA_RENDEZ_CHECKIN_DONE)
  443. ia64_mca_wakeup(cpu);
  444. }
  445. }
  446. /*
  447. * ia64_mca_rendez_interrupt_handler
  448. *
  449. * This is handler used to put slave processors into spinloop
  450. * while the monarch processor does the mca handling and later
  451. * wake each slave up once the monarch is done.
  452. *
  453. * Inputs : None
  454. * Outputs : None
  455. */
  456. static irqreturn_t
  457. ia64_mca_rendez_int_handler(int rendez_irq, void *arg, struct pt_regs *ptregs)
  458. {
  459. unsigned long flags;
  460. int cpu = smp_processor_id();
  461. /* Mask all interrupts */
  462. local_irq_save(flags);
  463. ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_DONE;
  464. /* Register with the SAL monarch that the slave has
  465. * reached SAL
  466. */
  467. ia64_sal_mc_rendez();
  468. /* Wait for the monarch cpu to exit. */
  469. while (monarch_cpu != -1)
  470. cpu_relax(); /* spin until monarch leaves */
  471. /* Enable all interrupts */
  472. local_irq_restore(flags);
  473. return IRQ_HANDLED;
  474. }
  475. /*
  476. * ia64_mca_wakeup_int_handler
  477. *
  478. * The interrupt handler for processing the inter-cpu interrupt to the
  479. * slave cpu which was spinning in the rendez loop.
  480. * Since this spinning is done by turning off the interrupts and
  481. * polling on the wakeup-interrupt bit in the IRR, there is
  482. * nothing useful to be done in the handler.
  483. *
  484. * Inputs : wakeup_irq (Wakeup-interrupt bit)
  485. * arg (Interrupt handler specific argument)
  486. * ptregs (Exception frame at the time of the interrupt)
  487. * Outputs : None
  488. *
  489. */
  490. static irqreturn_t
  491. ia64_mca_wakeup_int_handler(int wakeup_irq, void *arg, struct pt_regs *ptregs)
  492. {
  493. return IRQ_HANDLED;
  494. }
  495. /* Function pointer for extra MCA recovery */
  496. int (*ia64_mca_ucmc_extension)
  497. (void*,struct ia64_sal_os_state*)
  498. = NULL;
  499. int
  500. ia64_reg_MCA_extension(int (*fn)(void *, struct ia64_sal_os_state *))
  501. {
  502. if (ia64_mca_ucmc_extension)
  503. return 1;
  504. ia64_mca_ucmc_extension = fn;
  505. return 0;
  506. }
  507. void
  508. ia64_unreg_MCA_extension(void)
  509. {
  510. if (ia64_mca_ucmc_extension)
  511. ia64_mca_ucmc_extension = NULL;
  512. }
  513. EXPORT_SYMBOL(ia64_reg_MCA_extension);
  514. EXPORT_SYMBOL(ia64_unreg_MCA_extension);
  515. static inline void
  516. copy_reg(const u64 *fr, u64 fnat, u64 *tr, u64 *tnat)
  517. {
  518. u64 fslot, tslot, nat;
  519. *tr = *fr;
  520. fslot = ((unsigned long)fr >> 3) & 63;
  521. tslot = ((unsigned long)tr >> 3) & 63;
  522. *tnat &= ~(1UL << tslot);
  523. nat = (fnat >> fslot) & 1;
  524. *tnat |= (nat << tslot);
  525. }
  526. /* On entry to this routine, we are running on the per cpu stack, see
  527. * mca_asm.h. The original stack has not been touched by this event. Some of
  528. * the original stack's registers will be in the RBS on this stack. This stack
  529. * also contains a partial pt_regs and switch_stack, the rest of the data is in
  530. * PAL minstate.
  531. *
  532. * The first thing to do is modify the original stack to look like a blocked
  533. * task so we can run backtrace on the original task. Also mark the per cpu
  534. * stack as current to ensure that we use the correct task state, it also means
  535. * that we can do backtrace on the MCA/INIT handler code itself.
  536. */
  537. static task_t *
  538. ia64_mca_modify_original_stack(struct pt_regs *regs,
  539. const struct switch_stack *sw,
  540. struct ia64_sal_os_state *sos,
  541. const char *type)
  542. {
  543. char *p, comm[sizeof(current->comm)];
  544. ia64_va va;
  545. extern char ia64_leave_kernel[]; /* Need asm address, not function descriptor */
  546. const pal_min_state_area_t *ms = sos->pal_min_state;
  547. task_t *previous_current;
  548. struct pt_regs *old_regs;
  549. struct switch_stack *old_sw;
  550. unsigned size = sizeof(struct pt_regs) +
  551. sizeof(struct switch_stack) + 16;
  552. u64 *old_bspstore, *old_bsp;
  553. u64 *new_bspstore, *new_bsp;
  554. u64 old_unat, old_rnat, new_rnat, nat;
  555. u64 slots, loadrs = regs->loadrs;
  556. u64 r12 = ms->pmsa_gr[12-1], r13 = ms->pmsa_gr[13-1];
  557. u64 ar_bspstore = regs->ar_bspstore;
  558. u64 ar_bsp = regs->ar_bspstore + (loadrs >> 16);
  559. const u64 *bank;
  560. const char *msg;
  561. int cpu = smp_processor_id();
  562. previous_current = curr_task(cpu);
  563. set_curr_task(cpu, current);
  564. if ((p = strchr(current->comm, ' ')))
  565. *p = '\0';
  566. /* Best effort attempt to cope with MCA/INIT delivered while in
  567. * physical mode.
  568. */
  569. regs->cr_ipsr = ms->pmsa_ipsr;
  570. if (ia64_psr(regs)->dt == 0) {
  571. va.l = r12;
  572. if (va.f.reg == 0) {
  573. va.f.reg = 7;
  574. r12 = va.l;
  575. }
  576. va.l = r13;
  577. if (va.f.reg == 0) {
  578. va.f.reg = 7;
  579. r13 = va.l;
  580. }
  581. }
  582. if (ia64_psr(regs)->rt == 0) {
  583. va.l = ar_bspstore;
  584. if (va.f.reg == 0) {
  585. va.f.reg = 7;
  586. ar_bspstore = va.l;
  587. }
  588. va.l = ar_bsp;
  589. if (va.f.reg == 0) {
  590. va.f.reg = 7;
  591. ar_bsp = va.l;
  592. }
  593. }
  594. /* mca_asm.S ia64_old_stack() cannot assume that the dirty registers
  595. * have been copied to the old stack, the old stack may fail the
  596. * validation tests below. So ia64_old_stack() must restore the dirty
  597. * registers from the new stack. The old and new bspstore probably
  598. * have different alignments, so loadrs calculated on the old bsp
  599. * cannot be used to restore from the new bsp. Calculate a suitable
  600. * loadrs for the new stack and save it in the new pt_regs, where
  601. * ia64_old_stack() can get it.
  602. */
  603. old_bspstore = (u64 *)ar_bspstore;
  604. old_bsp = (u64 *)ar_bsp;
  605. slots = ia64_rse_num_regs(old_bspstore, old_bsp);
  606. new_bspstore = (u64 *)((u64)current + IA64_RBS_OFFSET);
  607. new_bsp = ia64_rse_skip_regs(new_bspstore, slots);
  608. regs->loadrs = (new_bsp - new_bspstore) * 8 << 16;
  609. /* Verify the previous stack state before we change it */
  610. if (user_mode(regs)) {
  611. msg = "occurred in user space";
  612. goto no_mod;
  613. }
  614. if (r13 != sos->prev_IA64_KR_CURRENT) {
  615. msg = "inconsistent previous current and r13";
  616. goto no_mod;
  617. }
  618. if ((r12 - r13) >= KERNEL_STACK_SIZE) {
  619. msg = "inconsistent r12 and r13";
  620. goto no_mod;
  621. }
  622. if ((ar_bspstore - r13) >= KERNEL_STACK_SIZE) {
  623. msg = "inconsistent ar.bspstore and r13";
  624. goto no_mod;
  625. }
  626. va.p = old_bspstore;
  627. if (va.f.reg < 5) {
  628. msg = "old_bspstore is in the wrong region";
  629. goto no_mod;
  630. }
  631. if ((ar_bsp - r13) >= KERNEL_STACK_SIZE) {
  632. msg = "inconsistent ar.bsp and r13";
  633. goto no_mod;
  634. }
  635. size += (ia64_rse_skip_regs(old_bspstore, slots) - old_bspstore) * 8;
  636. if (ar_bspstore + size > r12) {
  637. msg = "no room for blocked state";
  638. goto no_mod;
  639. }
  640. /* Change the comm field on the MCA/INT task to include the pid that
  641. * was interrupted, it makes for easier debugging. If that pid was 0
  642. * (swapper or nested MCA/INIT) then use the start of the previous comm
  643. * field suffixed with its cpu.
  644. */
  645. if (previous_current->pid)
  646. snprintf(comm, sizeof(comm), "%s %d",
  647. current->comm, previous_current->pid);
  648. else {
  649. int l;
  650. if ((p = strchr(previous_current->comm, ' ')))
  651. l = p - previous_current->comm;
  652. else
  653. l = strlen(previous_current->comm);
  654. snprintf(comm, sizeof(comm), "%s %*s %d",
  655. current->comm, l, previous_current->comm,
  656. previous_current->thread_info->cpu);
  657. }
  658. memcpy(current->comm, comm, sizeof(current->comm));
  659. /* Make the original task look blocked. First stack a struct pt_regs,
  660. * describing the state at the time of interrupt. mca_asm.S built a
  661. * partial pt_regs, copy it and fill in the blanks using minstate.
  662. */
  663. p = (char *)r12 - sizeof(*regs);
  664. old_regs = (struct pt_regs *)p;
  665. memcpy(old_regs, regs, sizeof(*regs));
  666. /* If ipsr.ic then use pmsa_{iip,ipsr,ifs}, else use
  667. * pmsa_{xip,xpsr,xfs}
  668. */
  669. if (ia64_psr(regs)->ic) {
  670. old_regs->cr_iip = ms->pmsa_iip;
  671. old_regs->cr_ipsr = ms->pmsa_ipsr;
  672. old_regs->cr_ifs = ms->pmsa_ifs;
  673. } else {
  674. old_regs->cr_iip = ms->pmsa_xip;
  675. old_regs->cr_ipsr = ms->pmsa_xpsr;
  676. old_regs->cr_ifs = ms->pmsa_xfs;
  677. }
  678. old_regs->pr = ms->pmsa_pr;
  679. old_regs->b0 = ms->pmsa_br0;
  680. old_regs->loadrs = loadrs;
  681. old_regs->ar_rsc = ms->pmsa_rsc;
  682. old_unat = old_regs->ar_unat;
  683. copy_reg(&ms->pmsa_gr[1-1], ms->pmsa_nat_bits, &old_regs->r1, &old_unat);
  684. copy_reg(&ms->pmsa_gr[2-1], ms->pmsa_nat_bits, &old_regs->r2, &old_unat);
  685. copy_reg(&ms->pmsa_gr[3-1], ms->pmsa_nat_bits, &old_regs->r3, &old_unat);
  686. copy_reg(&ms->pmsa_gr[8-1], ms->pmsa_nat_bits, &old_regs->r8, &old_unat);
  687. copy_reg(&ms->pmsa_gr[9-1], ms->pmsa_nat_bits, &old_regs->r9, &old_unat);
  688. copy_reg(&ms->pmsa_gr[10-1], ms->pmsa_nat_bits, &old_regs->r10, &old_unat);
  689. copy_reg(&ms->pmsa_gr[11-1], ms->pmsa_nat_bits, &old_regs->r11, &old_unat);
  690. copy_reg(&ms->pmsa_gr[12-1], ms->pmsa_nat_bits, &old_regs->r12, &old_unat);
  691. copy_reg(&ms->pmsa_gr[13-1], ms->pmsa_nat_bits, &old_regs->r13, &old_unat);
  692. copy_reg(&ms->pmsa_gr[14-1], ms->pmsa_nat_bits, &old_regs->r14, &old_unat);
  693. copy_reg(&ms->pmsa_gr[15-1], ms->pmsa_nat_bits, &old_regs->r15, &old_unat);
  694. if (ia64_psr(old_regs)->bn)
  695. bank = ms->pmsa_bank1_gr;
  696. else
  697. bank = ms->pmsa_bank0_gr;
  698. copy_reg(&bank[16-16], ms->pmsa_nat_bits, &old_regs->r16, &old_unat);
  699. copy_reg(&bank[17-16], ms->pmsa_nat_bits, &old_regs->r17, &old_unat);
  700. copy_reg(&bank[18-16], ms->pmsa_nat_bits, &old_regs->r18, &old_unat);
  701. copy_reg(&bank[19-16], ms->pmsa_nat_bits, &old_regs->r19, &old_unat);
  702. copy_reg(&bank[20-16], ms->pmsa_nat_bits, &old_regs->r20, &old_unat);
  703. copy_reg(&bank[21-16], ms->pmsa_nat_bits, &old_regs->r21, &old_unat);
  704. copy_reg(&bank[22-16], ms->pmsa_nat_bits, &old_regs->r22, &old_unat);
  705. copy_reg(&bank[23-16], ms->pmsa_nat_bits, &old_regs->r23, &old_unat);
  706. copy_reg(&bank[24-16], ms->pmsa_nat_bits, &old_regs->r24, &old_unat);
  707. copy_reg(&bank[25-16], ms->pmsa_nat_bits, &old_regs->r25, &old_unat);
  708. copy_reg(&bank[26-16], ms->pmsa_nat_bits, &old_regs->r26, &old_unat);
  709. copy_reg(&bank[27-16], ms->pmsa_nat_bits, &old_regs->r27, &old_unat);
  710. copy_reg(&bank[28-16], ms->pmsa_nat_bits, &old_regs->r28, &old_unat);
  711. copy_reg(&bank[29-16], ms->pmsa_nat_bits, &old_regs->r29, &old_unat);
  712. copy_reg(&bank[30-16], ms->pmsa_nat_bits, &old_regs->r30, &old_unat);
  713. copy_reg(&bank[31-16], ms->pmsa_nat_bits, &old_regs->r31, &old_unat);
  714. /* Next stack a struct switch_stack. mca_asm.S built a partial
  715. * switch_stack, copy it and fill in the blanks using pt_regs and
  716. * minstate.
  717. *
  718. * In the synthesized switch_stack, b0 points to ia64_leave_kernel,
  719. * ar.pfs is set to 0.
  720. *
  721. * unwind.c::unw_unwind() does special processing for interrupt frames.
  722. * It checks if the PRED_NON_SYSCALL predicate is set, if the predicate
  723. * is clear then unw_unwind() does _not_ adjust bsp over pt_regs. Not
  724. * that this is documented, of course. Set PRED_NON_SYSCALL in the
  725. * switch_stack on the original stack so it will unwind correctly when
  726. * unwind.c reads pt_regs.
  727. *
  728. * thread.ksp is updated to point to the synthesized switch_stack.
  729. */
  730. p -= sizeof(struct switch_stack);
  731. old_sw = (struct switch_stack *)p;
  732. memcpy(old_sw, sw, sizeof(*sw));
  733. old_sw->caller_unat = old_unat;
  734. old_sw->ar_fpsr = old_regs->ar_fpsr;
  735. copy_reg(&ms->pmsa_gr[4-1], ms->pmsa_nat_bits, &old_sw->r4, &old_unat);
  736. copy_reg(&ms->pmsa_gr[5-1], ms->pmsa_nat_bits, &old_sw->r5, &old_unat);
  737. copy_reg(&ms->pmsa_gr[6-1], ms->pmsa_nat_bits, &old_sw->r6, &old_unat);
  738. copy_reg(&ms->pmsa_gr[7-1], ms->pmsa_nat_bits, &old_sw->r7, &old_unat);
  739. old_sw->b0 = (u64)ia64_leave_kernel;
  740. old_sw->b1 = ms->pmsa_br1;
  741. old_sw->ar_pfs = 0;
  742. old_sw->ar_unat = old_unat;
  743. old_sw->pr = old_regs->pr | (1UL << PRED_NON_SYSCALL);
  744. previous_current->thread.ksp = (u64)p - 16;
  745. /* Finally copy the original stack's registers back to its RBS.
  746. * Registers from ar.bspstore through ar.bsp at the time of the event
  747. * are in the current RBS, copy them back to the original stack. The
  748. * copy must be done register by register because the original bspstore
  749. * and the current one have different alignments, so the saved RNAT
  750. * data occurs at different places.
  751. *
  752. * mca_asm does cover, so the old_bsp already includes all registers at
  753. * the time of MCA/INIT. It also does flushrs, so all registers before
  754. * this function have been written to backing store on the MCA/INIT
  755. * stack.
  756. */
  757. new_rnat = ia64_get_rnat(ia64_rse_rnat_addr(new_bspstore));
  758. old_rnat = regs->ar_rnat;
  759. while (slots--) {
  760. if (ia64_rse_is_rnat_slot(new_bspstore)) {
  761. new_rnat = ia64_get_rnat(new_bspstore++);
  762. }
  763. if (ia64_rse_is_rnat_slot(old_bspstore)) {
  764. *old_bspstore++ = old_rnat;
  765. old_rnat = 0;
  766. }
  767. nat = (new_rnat >> ia64_rse_slot_num(new_bspstore)) & 1UL;
  768. old_rnat &= ~(1UL << ia64_rse_slot_num(old_bspstore));
  769. old_rnat |= (nat << ia64_rse_slot_num(old_bspstore));
  770. *old_bspstore++ = *new_bspstore++;
  771. }
  772. old_sw->ar_bspstore = (unsigned long)old_bspstore;
  773. old_sw->ar_rnat = old_rnat;
  774. sos->prev_task = previous_current;
  775. return previous_current;
  776. no_mod:
  777. printk(KERN_INFO "cpu %d, %s %s, original stack not modified\n",
  778. smp_processor_id(), type, msg);
  779. return previous_current;
  780. }
  781. /* The monarch/slave interaction is based on monarch_cpu and requires that all
  782. * slaves have entered rendezvous before the monarch leaves. If any cpu has
  783. * not entered rendezvous yet then wait a bit. The assumption is that any
  784. * slave that has not rendezvoused after a reasonable time is never going to do
  785. * so. In this context, slave includes cpus that respond to the MCA rendezvous
  786. * interrupt, as well as cpus that receive the INIT slave event.
  787. */
  788. static void
  789. ia64_wait_for_slaves(int monarch)
  790. {
  791. int c, wait = 0;
  792. for_each_online_cpu(c) {
  793. if (c == monarch)
  794. continue;
  795. if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) {
  796. udelay(1000); /* short wait first */
  797. wait = 1;
  798. break;
  799. }
  800. }
  801. if (!wait)
  802. return;
  803. for_each_online_cpu(c) {
  804. if (c == monarch)
  805. continue;
  806. if (ia64_mc_info.imi_rendez_checkin[c] == IA64_MCA_RENDEZ_CHECKIN_NOTDONE) {
  807. udelay(5*1000000); /* wait 5 seconds for slaves (arbitrary) */
  808. break;
  809. }
  810. }
  811. }
  812. /*
  813. * ia64_mca_handler
  814. *
  815. * This is uncorrectable machine check handler called from OS_MCA
  816. * dispatch code which is in turn called from SAL_CHECK().
  817. * This is the place where the core of OS MCA handling is done.
  818. * Right now the logs are extracted and displayed in a well-defined
  819. * format. This handler code is supposed to be run only on the
  820. * monarch processor. Once the monarch is done with MCA handling
  821. * further MCA logging is enabled by clearing logs.
  822. * Monarch also has the duty of sending wakeup-IPIs to pull the
  823. * slave processors out of rendezvous spinloop.
  824. */
  825. void
  826. ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw,
  827. struct ia64_sal_os_state *sos)
  828. {
  829. pal_processor_state_info_t *psp = (pal_processor_state_info_t *)
  830. &sos->proc_state_param;
  831. int recover, cpu = smp_processor_id();
  832. task_t *previous_current;
  833. oops_in_progress = 1; /* FIXME: make printk NMI/MCA/INIT safe */
  834. previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "MCA");
  835. monarch_cpu = cpu;
  836. ia64_wait_for_slaves(cpu);
  837. /* Wakeup all the processors which are spinning in the rendezvous loop.
  838. * They will leave SAL, then spin in the OS with interrupts disabled
  839. * until this monarch cpu leaves the MCA handler. That gets control
  840. * back to the OS so we can backtrace the other cpus, backtrace when
  841. * spinning in SAL does not work.
  842. */
  843. ia64_mca_wakeup_all();
  844. /* Get the MCA error record and log it */
  845. ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA);
  846. /* TLB error is only exist in this SAL error record */
  847. recover = (psp->tc && !(psp->cc || psp->bc || psp->rc || psp->uc))
  848. /* other error recovery */
  849. || (ia64_mca_ucmc_extension
  850. && ia64_mca_ucmc_extension(
  851. IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA),
  852. sos));
  853. if (recover) {
  854. sal_log_record_header_t *rh = IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA);
  855. rh->severity = sal_log_severity_corrected;
  856. ia64_sal_clear_state_info(SAL_INFO_TYPE_MCA);
  857. sos->os_status = IA64_MCA_CORRECTED;
  858. }
  859. set_curr_task(cpu, previous_current);
  860. monarch_cpu = -1;
  861. }
  862. static DECLARE_WORK(cmc_disable_work, ia64_mca_cmc_vector_disable_keventd, NULL);
  863. static DECLARE_WORK(cmc_enable_work, ia64_mca_cmc_vector_enable_keventd, NULL);
  864. /*
  865. * ia64_mca_cmc_int_handler
  866. *
  867. * This is corrected machine check interrupt handler.
  868. * Right now the logs are extracted and displayed in a well-defined
  869. * format.
  870. *
  871. * Inputs
  872. * interrupt number
  873. * client data arg ptr
  874. * saved registers ptr
  875. *
  876. * Outputs
  877. * None
  878. */
  879. static irqreturn_t
  880. ia64_mca_cmc_int_handler(int cmc_irq, void *arg, struct pt_regs *ptregs)
  881. {
  882. static unsigned long cmc_history[CMC_HISTORY_LENGTH];
  883. static int index;
  884. static DEFINE_SPINLOCK(cmc_history_lock);
  885. IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
  886. __FUNCTION__, cmc_irq, smp_processor_id());
  887. /* SAL spec states this should run w/ interrupts enabled */
  888. local_irq_enable();
  889. /* Get the CMC error record and log it */
  890. ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC);
  891. spin_lock(&cmc_history_lock);
  892. if (!cmc_polling_enabled) {
  893. int i, count = 1; /* we know 1 happened now */
  894. unsigned long now = jiffies;
  895. for (i = 0; i < CMC_HISTORY_LENGTH; i++) {
  896. if (now - cmc_history[i] <= HZ)
  897. count++;
  898. }
  899. IA64_MCA_DEBUG(KERN_INFO "CMC threshold %d/%d\n", count, CMC_HISTORY_LENGTH);
  900. if (count >= CMC_HISTORY_LENGTH) {
  901. cmc_polling_enabled = 1;
  902. spin_unlock(&cmc_history_lock);
  903. /* If we're being hit with CMC interrupts, we won't
  904. * ever execute the schedule_work() below. Need to
  905. * disable CMC interrupts on this processor now.
  906. */
  907. ia64_mca_cmc_vector_disable(NULL);
  908. schedule_work(&cmc_disable_work);
  909. /*
  910. * Corrected errors will still be corrected, but
  911. * make sure there's a log somewhere that indicates
  912. * something is generating more than we can handle.
  913. */
  914. printk(KERN_WARNING "WARNING: Switching to polling CMC handler; error records may be lost\n");
  915. mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
  916. /* lock already released, get out now */
  917. return IRQ_HANDLED;
  918. } else {
  919. cmc_history[index++] = now;
  920. if (index == CMC_HISTORY_LENGTH)
  921. index = 0;
  922. }
  923. }
  924. spin_unlock(&cmc_history_lock);
  925. return IRQ_HANDLED;
  926. }
  927. /*
  928. * ia64_mca_cmc_int_caller
  929. *
  930. * Triggered by sw interrupt from CMC polling routine. Calls
  931. * real interrupt handler and either triggers a sw interrupt
  932. * on the next cpu or does cleanup at the end.
  933. *
  934. * Inputs
  935. * interrupt number
  936. * client data arg ptr
  937. * saved registers ptr
  938. * Outputs
  939. * handled
  940. */
  941. static irqreturn_t
  942. ia64_mca_cmc_int_caller(int cmc_irq, void *arg, struct pt_regs *ptregs)
  943. {
  944. static int start_count = -1;
  945. unsigned int cpuid;
  946. cpuid = smp_processor_id();
  947. /* If first cpu, update count */
  948. if (start_count == -1)
  949. start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CMC);
  950. ia64_mca_cmc_int_handler(cmc_irq, arg, ptregs);
  951. for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
  952. if (cpuid < NR_CPUS) {
  953. platform_send_ipi(cpuid, IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
  954. } else {
  955. /* If no log record, switch out of polling mode */
  956. if (start_count == IA64_LOG_COUNT(SAL_INFO_TYPE_CMC)) {
  957. printk(KERN_WARNING "Returning to interrupt driven CMC handler\n");
  958. schedule_work(&cmc_enable_work);
  959. cmc_polling_enabled = 0;
  960. } else {
  961. mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
  962. }
  963. start_count = -1;
  964. }
  965. return IRQ_HANDLED;
  966. }
  967. /*
  968. * ia64_mca_cmc_poll
  969. *
  970. * Poll for Corrected Machine Checks (CMCs)
  971. *
  972. * Inputs : dummy(unused)
  973. * Outputs : None
  974. *
  975. */
  976. static void
  977. ia64_mca_cmc_poll (unsigned long dummy)
  978. {
  979. /* Trigger a CMC interrupt cascade */
  980. platform_send_ipi(first_cpu(cpu_online_map), IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
  981. }
  982. /*
  983. * ia64_mca_cpe_int_caller
  984. *
  985. * Triggered by sw interrupt from CPE polling routine. Calls
  986. * real interrupt handler and either triggers a sw interrupt
  987. * on the next cpu or does cleanup at the end.
  988. *
  989. * Inputs
  990. * interrupt number
  991. * client data arg ptr
  992. * saved registers ptr
  993. * Outputs
  994. * handled
  995. */
  996. #ifdef CONFIG_ACPI
  997. static irqreturn_t
  998. ia64_mca_cpe_int_caller(int cpe_irq, void *arg, struct pt_regs *ptregs)
  999. {
  1000. static int start_count = -1;
  1001. static int poll_time = MIN_CPE_POLL_INTERVAL;
  1002. unsigned int cpuid;
  1003. cpuid = smp_processor_id();
  1004. /* If first cpu, update count */
  1005. if (start_count == -1)
  1006. start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CPE);
  1007. ia64_mca_cpe_int_handler(cpe_irq, arg, ptregs);
  1008. for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
  1009. if (cpuid < NR_CPUS) {
  1010. platform_send_ipi(cpuid, IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
  1011. } else {
  1012. /*
  1013. * If a log was recorded, increase our polling frequency,
  1014. * otherwise, backoff or return to interrupt mode.
  1015. */
  1016. if (start_count != IA64_LOG_COUNT(SAL_INFO_TYPE_CPE)) {
  1017. poll_time = max(MIN_CPE_POLL_INTERVAL, poll_time / 2);
  1018. } else if (cpe_vector < 0) {
  1019. poll_time = min(MAX_CPE_POLL_INTERVAL, poll_time * 2);
  1020. } else {
  1021. poll_time = MIN_CPE_POLL_INTERVAL;
  1022. printk(KERN_WARNING "Returning to interrupt driven CPE handler\n");
  1023. enable_irq(local_vector_to_irq(IA64_CPE_VECTOR));
  1024. cpe_poll_enabled = 0;
  1025. }
  1026. if (cpe_poll_enabled)
  1027. mod_timer(&cpe_poll_timer, jiffies + poll_time);
  1028. start_count = -1;
  1029. }
  1030. return IRQ_HANDLED;
  1031. }
  1032. /*
  1033. * ia64_mca_cpe_poll
  1034. *
  1035. * Poll for Corrected Platform Errors (CPEs), trigger interrupt
  1036. * on first cpu, from there it will trickle through all the cpus.
  1037. *
  1038. * Inputs : dummy(unused)
  1039. * Outputs : None
  1040. *
  1041. */
  1042. static void
  1043. ia64_mca_cpe_poll (unsigned long dummy)
  1044. {
  1045. /* Trigger a CPE interrupt cascade */
  1046. platform_send_ipi(first_cpu(cpu_online_map), IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
  1047. }
  1048. #endif /* CONFIG_ACPI */
  1049. /*
  1050. * C portion of the OS INIT handler
  1051. *
  1052. * Called from ia64_os_init_dispatch
  1053. *
  1054. * Inputs: pointer to pt_regs where processor info was saved. SAL/OS state for
  1055. * this event. This code is used for both monarch and slave INIT events, see
  1056. * sos->monarch.
  1057. *
  1058. * All INIT events switch to the INIT stack and change the previous process to
  1059. * blocked status. If one of the INIT events is the monarch then we are
  1060. * probably processing the nmi button/command. Use the monarch cpu to dump all
  1061. * the processes. The slave INIT events all spin until the monarch cpu
  1062. * returns. We can also get INIT slave events for MCA, in which case the MCA
  1063. * process is the monarch.
  1064. */
  1065. void
  1066. ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw,
  1067. struct ia64_sal_os_state *sos)
  1068. {
  1069. static atomic_t slaves;
  1070. static atomic_t monarchs;
  1071. task_t *previous_current;
  1072. int cpu = smp_processor_id(), c;
  1073. struct task_struct *g, *t;
  1074. oops_in_progress = 1; /* FIXME: make printk NMI/MCA/INIT safe */
  1075. console_loglevel = 15; /* make sure printks make it to console */
  1076. printk(KERN_INFO "Entered OS INIT handler. PSP=%lx cpu=%d monarch=%ld\n",
  1077. sos->proc_state_param, cpu, sos->monarch);
  1078. salinfo_log_wakeup(SAL_INFO_TYPE_INIT, NULL, 0, 0);
  1079. previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "INIT");
  1080. sos->os_status = IA64_INIT_RESUME;
  1081. /* FIXME: Workaround for broken proms that drive all INIT events as
  1082. * slaves. The last slave that enters is promoted to be a monarch.
  1083. * Remove this code in September 2006, that gives platforms a year to
  1084. * fix their proms and get their customers updated.
  1085. */
  1086. if (!sos->monarch && atomic_add_return(1, &slaves) == num_online_cpus()) {
  1087. printk(KERN_WARNING "%s: Promoting cpu %d to monarch.\n",
  1088. __FUNCTION__, cpu);
  1089. atomic_dec(&slaves);
  1090. sos->monarch = 1;
  1091. }
  1092. /* FIXME: Workaround for broken proms that drive all INIT events as
  1093. * monarchs. Second and subsequent monarchs are demoted to slaves.
  1094. * Remove this code in September 2006, that gives platforms a year to
  1095. * fix their proms and get their customers updated.
  1096. */
  1097. if (sos->monarch && atomic_add_return(1, &monarchs) > 1) {
  1098. printk(KERN_WARNING "%s: Demoting cpu %d to slave.\n",
  1099. __FUNCTION__, cpu);
  1100. atomic_dec(&monarchs);
  1101. sos->monarch = 0;
  1102. }
  1103. if (!sos->monarch) {
  1104. ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_INIT;
  1105. while (monarch_cpu == -1)
  1106. cpu_relax(); /* spin until monarch enters */
  1107. while (monarch_cpu != -1)
  1108. cpu_relax(); /* spin until monarch leaves */
  1109. printk("Slave on cpu %d returning to normal service.\n", cpu);
  1110. set_curr_task(cpu, previous_current);
  1111. ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
  1112. atomic_dec(&slaves);
  1113. return;
  1114. }
  1115. monarch_cpu = cpu;
  1116. /*
  1117. * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be
  1118. * generated via the BMC's command-line interface, but since the console is on the
  1119. * same serial line, the user will need some time to switch out of the BMC before
  1120. * the dump begins.
  1121. */
  1122. printk("Delaying for 5 seconds...\n");
  1123. udelay(5*1000000);
  1124. ia64_wait_for_slaves(cpu);
  1125. printk(KERN_ERR "Processes interrupted by INIT -");
  1126. for_each_online_cpu(c) {
  1127. struct ia64_sal_os_state *s;
  1128. t = __va(__per_cpu_mca[c] + IA64_MCA_CPU_INIT_STACK_OFFSET);
  1129. s = (struct ia64_sal_os_state *)((char *)t + MCA_SOS_OFFSET);
  1130. g = s->prev_task;
  1131. if (g) {
  1132. if (g->pid)
  1133. printk(" %d", g->pid);
  1134. else
  1135. printk(" %d (cpu %d task 0x%p)", g->pid, task_cpu(g), g);
  1136. }
  1137. }
  1138. printk("\n\n");
  1139. if (read_trylock(&tasklist_lock)) {
  1140. do_each_thread (g, t) {
  1141. printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm);
  1142. show_stack(t, NULL);
  1143. } while_each_thread (g, t);
  1144. read_unlock(&tasklist_lock);
  1145. }
  1146. printk("\nINIT dump complete. Monarch on cpu %d returning to normal service.\n", cpu);
  1147. atomic_dec(&monarchs);
  1148. set_curr_task(cpu, previous_current);
  1149. monarch_cpu = -1;
  1150. return;
  1151. }
  1152. static int __init
  1153. ia64_mca_disable_cpe_polling(char *str)
  1154. {
  1155. cpe_poll_enabled = 0;
  1156. return 1;
  1157. }
  1158. __setup("disable_cpe_poll", ia64_mca_disable_cpe_polling);
  1159. static struct irqaction cmci_irqaction = {
  1160. .handler = ia64_mca_cmc_int_handler,
  1161. .flags = SA_INTERRUPT,
  1162. .name = "cmc_hndlr"
  1163. };
  1164. static struct irqaction cmcp_irqaction = {
  1165. .handler = ia64_mca_cmc_int_caller,
  1166. .flags = SA_INTERRUPT,
  1167. .name = "cmc_poll"
  1168. };
  1169. static struct irqaction mca_rdzv_irqaction = {
  1170. .handler = ia64_mca_rendez_int_handler,
  1171. .flags = SA_INTERRUPT,
  1172. .name = "mca_rdzv"
  1173. };
  1174. static struct irqaction mca_wkup_irqaction = {
  1175. .handler = ia64_mca_wakeup_int_handler,
  1176. .flags = SA_INTERRUPT,
  1177. .name = "mca_wkup"
  1178. };
  1179. #ifdef CONFIG_ACPI
  1180. static struct irqaction mca_cpe_irqaction = {
  1181. .handler = ia64_mca_cpe_int_handler,
  1182. .flags = SA_INTERRUPT,
  1183. .name = "cpe_hndlr"
  1184. };
  1185. static struct irqaction mca_cpep_irqaction = {
  1186. .handler = ia64_mca_cpe_int_caller,
  1187. .flags = SA_INTERRUPT,
  1188. .name = "cpe_poll"
  1189. };
  1190. #endif /* CONFIG_ACPI */
  1191. /* Minimal format of the MCA/INIT stacks. The pseudo processes that run on
  1192. * these stacks can never sleep, they cannot return from the kernel to user
  1193. * space, they do not appear in a normal ps listing. So there is no need to
  1194. * format most of the fields.
  1195. */
  1196. static void
  1197. format_mca_init_stack(void *mca_data, unsigned long offset,
  1198. const char *type, int cpu)
  1199. {
  1200. struct task_struct *p = (struct task_struct *)((char *)mca_data + offset);
  1201. struct thread_info *ti;
  1202. memset(p, 0, KERNEL_STACK_SIZE);
  1203. ti = (struct thread_info *)((char *)p + IA64_TASK_SIZE);
  1204. ti->flags = _TIF_MCA_INIT;
  1205. ti->preempt_count = 1;
  1206. ti->task = p;
  1207. ti->cpu = cpu;
  1208. p->thread_info = ti;
  1209. p->state = TASK_UNINTERRUPTIBLE;
  1210. __set_bit(cpu, &p->cpus_allowed);
  1211. INIT_LIST_HEAD(&p->tasks);
  1212. p->parent = p->real_parent = p->group_leader = p;
  1213. INIT_LIST_HEAD(&p->children);
  1214. INIT_LIST_HEAD(&p->sibling);
  1215. strncpy(p->comm, type, sizeof(p->comm)-1);
  1216. }
  1217. /* Do per-CPU MCA-related initialization. */
  1218. void __devinit
  1219. ia64_mca_cpu_init(void *cpu_data)
  1220. {
  1221. void *pal_vaddr;
  1222. if (smp_processor_id() == 0) {
  1223. void *mca_data;
  1224. int cpu;
  1225. mca_data = alloc_bootmem(sizeof(struct ia64_mca_cpu)
  1226. * NR_CPUS + KERNEL_STACK_SIZE);
  1227. mca_data = (void *)(((unsigned long)mca_data +
  1228. KERNEL_STACK_SIZE - 1) &
  1229. (-KERNEL_STACK_SIZE));
  1230. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  1231. format_mca_init_stack(mca_data,
  1232. offsetof(struct ia64_mca_cpu, mca_stack),
  1233. "MCA", cpu);
  1234. format_mca_init_stack(mca_data,
  1235. offsetof(struct ia64_mca_cpu, init_stack),
  1236. "INIT", cpu);
  1237. __per_cpu_mca[cpu] = __pa(mca_data);
  1238. mca_data += sizeof(struct ia64_mca_cpu);
  1239. }
  1240. }
  1241. /*
  1242. * The MCA info structure was allocated earlier and its
  1243. * physical address saved in __per_cpu_mca[cpu]. Copy that
  1244. * address * to ia64_mca_data so we can access it as a per-CPU
  1245. * variable.
  1246. */
  1247. __get_cpu_var(ia64_mca_data) = __per_cpu_mca[smp_processor_id()];
  1248. /*
  1249. * Stash away a copy of the PTE needed to map the per-CPU page.
  1250. * We may need it during MCA recovery.
  1251. */
  1252. __get_cpu_var(ia64_mca_per_cpu_pte) =
  1253. pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL));
  1254. /*
  1255. * Also, stash away a copy of the PAL address and the PTE
  1256. * needed to map it.
  1257. */
  1258. pal_vaddr = efi_get_pal_addr();
  1259. if (!pal_vaddr)
  1260. return;
  1261. __get_cpu_var(ia64_mca_pal_base) =
  1262. GRANULEROUNDDOWN((unsigned long) pal_vaddr);
  1263. __get_cpu_var(ia64_mca_pal_pte) = pte_val(mk_pte_phys(__pa(pal_vaddr),
  1264. PAGE_KERNEL));
  1265. }
  1266. /*
  1267. * ia64_mca_init
  1268. *
  1269. * Do all the system level mca specific initialization.
  1270. *
  1271. * 1. Register spinloop and wakeup request interrupt vectors
  1272. *
  1273. * 2. Register OS_MCA handler entry point
  1274. *
  1275. * 3. Register OS_INIT handler entry point
  1276. *
  1277. * 4. Initialize MCA/CMC/INIT related log buffers maintained by the OS.
  1278. *
  1279. * Note that this initialization is done very early before some kernel
  1280. * services are available.
  1281. *
  1282. * Inputs : None
  1283. *
  1284. * Outputs : None
  1285. */
  1286. void __init
  1287. ia64_mca_init(void)
  1288. {
  1289. ia64_fptr_t *init_hldlr_ptr_monarch = (ia64_fptr_t *)ia64_os_init_dispatch_monarch;
  1290. ia64_fptr_t *init_hldlr_ptr_slave = (ia64_fptr_t *)ia64_os_init_dispatch_slave;
  1291. ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch;
  1292. int i;
  1293. s64 rc;
  1294. struct ia64_sal_retval isrv;
  1295. u64 timeout = IA64_MCA_RENDEZ_TIMEOUT; /* platform specific */
  1296. IA64_MCA_DEBUG("%s: begin\n", __FUNCTION__);
  1297. /* Clear the Rendez checkin flag for all cpus */
  1298. for(i = 0 ; i < NR_CPUS; i++)
  1299. ia64_mc_info.imi_rendez_checkin[i] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
  1300. /*
  1301. * Register the rendezvous spinloop and wakeup mechanism with SAL
  1302. */
  1303. /* Register the rendezvous interrupt vector with SAL */
  1304. while (1) {
  1305. isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_INT,
  1306. SAL_MC_PARAM_MECHANISM_INT,
  1307. IA64_MCA_RENDEZ_VECTOR,
  1308. timeout,
  1309. SAL_MC_PARAM_RZ_ALWAYS);
  1310. rc = isrv.status;
  1311. if (rc == 0)
  1312. break;
  1313. if (rc == -2) {
  1314. printk(KERN_INFO "Increasing MCA rendezvous timeout from "
  1315. "%ld to %ld milliseconds\n", timeout, isrv.v0);
  1316. timeout = isrv.v0;
  1317. continue;
  1318. }
  1319. printk(KERN_ERR "Failed to register rendezvous interrupt "
  1320. "with SAL (status %ld)\n", rc);
  1321. return;
  1322. }
  1323. /* Register the wakeup interrupt vector with SAL */
  1324. isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_WAKEUP,
  1325. SAL_MC_PARAM_MECHANISM_INT,
  1326. IA64_MCA_WAKEUP_VECTOR,
  1327. 0, 0);
  1328. rc = isrv.status;
  1329. if (rc) {
  1330. printk(KERN_ERR "Failed to register wakeup interrupt with SAL "
  1331. "(status %ld)\n", rc);
  1332. return;
  1333. }
  1334. IA64_MCA_DEBUG("%s: registered MCA rendezvous spinloop and wakeup mech.\n", __FUNCTION__);
  1335. ia64_mc_info.imi_mca_handler = ia64_tpa(mca_hldlr_ptr->fp);
  1336. /*
  1337. * XXX - disable SAL checksum by setting size to 0; should be
  1338. * ia64_tpa(ia64_os_mca_dispatch_end) - ia64_tpa(ia64_os_mca_dispatch);
  1339. */
  1340. ia64_mc_info.imi_mca_handler_size = 0;
  1341. /* Register the os mca handler with SAL */
  1342. if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_MCA,
  1343. ia64_mc_info.imi_mca_handler,
  1344. ia64_tpa(mca_hldlr_ptr->gp),
  1345. ia64_mc_info.imi_mca_handler_size,
  1346. 0, 0, 0)))
  1347. {
  1348. printk(KERN_ERR "Failed to register OS MCA handler with SAL "
  1349. "(status %ld)\n", rc);
  1350. return;
  1351. }
  1352. IA64_MCA_DEBUG("%s: registered OS MCA handler with SAL at 0x%lx, gp = 0x%lx\n", __FUNCTION__,
  1353. ia64_mc_info.imi_mca_handler, ia64_tpa(mca_hldlr_ptr->gp));
  1354. /*
  1355. * XXX - disable SAL checksum by setting size to 0, should be
  1356. * size of the actual init handler in mca_asm.S.
  1357. */
  1358. ia64_mc_info.imi_monarch_init_handler = ia64_tpa(init_hldlr_ptr_monarch->fp);
  1359. ia64_mc_info.imi_monarch_init_handler_size = 0;
  1360. ia64_mc_info.imi_slave_init_handler = ia64_tpa(init_hldlr_ptr_slave->fp);
  1361. ia64_mc_info.imi_slave_init_handler_size = 0;
  1362. IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __FUNCTION__,
  1363. ia64_mc_info.imi_monarch_init_handler);
  1364. /* Register the os init handler with SAL */
  1365. if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_INIT,
  1366. ia64_mc_info.imi_monarch_init_handler,
  1367. ia64_tpa(ia64_getreg(_IA64_REG_GP)),
  1368. ia64_mc_info.imi_monarch_init_handler_size,
  1369. ia64_mc_info.imi_slave_init_handler,
  1370. ia64_tpa(ia64_getreg(_IA64_REG_GP)),
  1371. ia64_mc_info.imi_slave_init_handler_size)))
  1372. {
  1373. printk(KERN_ERR "Failed to register m/s INIT handlers with SAL "
  1374. "(status %ld)\n", rc);
  1375. return;
  1376. }
  1377. IA64_MCA_DEBUG("%s: registered OS INIT handler with SAL\n", __FUNCTION__);
  1378. /*
  1379. * Configure the CMCI/P vector and handler. Interrupts for CMC are
  1380. * per-processor, so AP CMC interrupts are setup in smp_callin() (smpboot.c).
  1381. */
  1382. register_percpu_irq(IA64_CMC_VECTOR, &cmci_irqaction);
  1383. register_percpu_irq(IA64_CMCP_VECTOR, &cmcp_irqaction);
  1384. ia64_mca_cmc_vector_setup(); /* Setup vector on BSP */
  1385. /* Setup the MCA rendezvous interrupt vector */
  1386. register_percpu_irq(IA64_MCA_RENDEZ_VECTOR, &mca_rdzv_irqaction);
  1387. /* Setup the MCA wakeup interrupt vector */
  1388. register_percpu_irq(IA64_MCA_WAKEUP_VECTOR, &mca_wkup_irqaction);
  1389. #ifdef CONFIG_ACPI
  1390. /* Setup the CPEI/P handler */
  1391. register_percpu_irq(IA64_CPEP_VECTOR, &mca_cpep_irqaction);
  1392. #endif
  1393. /* Initialize the areas set aside by the OS to buffer the
  1394. * platform/processor error states for MCA/INIT/CMC
  1395. * handling.
  1396. */
  1397. ia64_log_init(SAL_INFO_TYPE_MCA);
  1398. ia64_log_init(SAL_INFO_TYPE_INIT);
  1399. ia64_log_init(SAL_INFO_TYPE_CMC);
  1400. ia64_log_init(SAL_INFO_TYPE_CPE);
  1401. mca_init = 1;
  1402. printk(KERN_INFO "MCA related initialization done\n");
  1403. }
  1404. /*
  1405. * ia64_mca_late_init
  1406. *
  1407. * Opportunity to setup things that require initialization later
  1408. * than ia64_mca_init. Setup a timer to poll for CPEs if the
  1409. * platform doesn't support an interrupt driven mechanism.
  1410. *
  1411. * Inputs : None
  1412. * Outputs : Status
  1413. */
  1414. static int __init
  1415. ia64_mca_late_init(void)
  1416. {
  1417. if (!mca_init)
  1418. return 0;
  1419. /* Setup the CMCI/P vector and handler */
  1420. init_timer(&cmc_poll_timer);
  1421. cmc_poll_timer.function = ia64_mca_cmc_poll;
  1422. /* Unmask/enable the vector */
  1423. cmc_polling_enabled = 0;
  1424. schedule_work(&cmc_enable_work);
  1425. IA64_MCA_DEBUG("%s: CMCI/P setup and enabled.\n", __FUNCTION__);
  1426. #ifdef CONFIG_ACPI
  1427. /* Setup the CPEI/P vector and handler */
  1428. cpe_vector = acpi_request_vector(ACPI_INTERRUPT_CPEI);
  1429. init_timer(&cpe_poll_timer);
  1430. cpe_poll_timer.function = ia64_mca_cpe_poll;
  1431. {
  1432. irq_desc_t *desc;
  1433. unsigned int irq;
  1434. if (cpe_vector >= 0) {
  1435. /* If platform supports CPEI, enable the irq. */
  1436. cpe_poll_enabled = 0;
  1437. for (irq = 0; irq < NR_IRQS; ++irq)
  1438. if (irq_to_vector(irq) == cpe_vector) {
  1439. desc = irq_descp(irq);
  1440. desc->status |= IRQ_PER_CPU;
  1441. setup_irq(irq, &mca_cpe_irqaction);
  1442. }
  1443. ia64_mca_register_cpev(cpe_vector);
  1444. IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n", __FUNCTION__);
  1445. } else {
  1446. /* If platform doesn't support CPEI, get the timer going. */
  1447. if (cpe_poll_enabled) {
  1448. ia64_mca_cpe_poll(0UL);
  1449. IA64_MCA_DEBUG("%s: CPEP setup and enabled.\n", __FUNCTION__);
  1450. }
  1451. }
  1452. }
  1453. #endif
  1454. return 0;
  1455. }
  1456. device_initcall(ia64_mca_late_init);