mca.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650
  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. schedule_work(&cmc_disable_work);
  906. /*
  907. * Corrected errors will still be corrected, but
  908. * make sure there's a log somewhere that indicates
  909. * something is generating more than we can handle.
  910. */
  911. printk(KERN_WARNING "WARNING: Switching to polling CMC handler; error records may be lost\n");
  912. mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
  913. /* lock already released, get out now */
  914. return IRQ_HANDLED;
  915. } else {
  916. cmc_history[index++] = now;
  917. if (index == CMC_HISTORY_LENGTH)
  918. index = 0;
  919. }
  920. }
  921. spin_unlock(&cmc_history_lock);
  922. return IRQ_HANDLED;
  923. }
  924. /*
  925. * ia64_mca_cmc_int_caller
  926. *
  927. * Triggered by sw interrupt from CMC polling routine. Calls
  928. * real interrupt handler and either triggers a sw interrupt
  929. * on the next cpu or does cleanup at the end.
  930. *
  931. * Inputs
  932. * interrupt number
  933. * client data arg ptr
  934. * saved registers ptr
  935. * Outputs
  936. * handled
  937. */
  938. static irqreturn_t
  939. ia64_mca_cmc_int_caller(int cmc_irq, void *arg, struct pt_regs *ptregs)
  940. {
  941. static int start_count = -1;
  942. unsigned int cpuid;
  943. cpuid = smp_processor_id();
  944. /* If first cpu, update count */
  945. if (start_count == -1)
  946. start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CMC);
  947. ia64_mca_cmc_int_handler(cmc_irq, arg, ptregs);
  948. for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
  949. if (cpuid < NR_CPUS) {
  950. platform_send_ipi(cpuid, IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
  951. } else {
  952. /* If no log record, switch out of polling mode */
  953. if (start_count == IA64_LOG_COUNT(SAL_INFO_TYPE_CMC)) {
  954. printk(KERN_WARNING "Returning to interrupt driven CMC handler\n");
  955. schedule_work(&cmc_enable_work);
  956. cmc_polling_enabled = 0;
  957. } else {
  958. mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
  959. }
  960. start_count = -1;
  961. }
  962. return IRQ_HANDLED;
  963. }
  964. /*
  965. * ia64_mca_cmc_poll
  966. *
  967. * Poll for Corrected Machine Checks (CMCs)
  968. *
  969. * Inputs : dummy(unused)
  970. * Outputs : None
  971. *
  972. */
  973. static void
  974. ia64_mca_cmc_poll (unsigned long dummy)
  975. {
  976. /* Trigger a CMC interrupt cascade */
  977. platform_send_ipi(first_cpu(cpu_online_map), IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
  978. }
  979. /*
  980. * ia64_mca_cpe_int_caller
  981. *
  982. * Triggered by sw interrupt from CPE polling routine. Calls
  983. * real interrupt handler and either triggers a sw interrupt
  984. * on the next cpu or does cleanup at the end.
  985. *
  986. * Inputs
  987. * interrupt number
  988. * client data arg ptr
  989. * saved registers ptr
  990. * Outputs
  991. * handled
  992. */
  993. #ifdef CONFIG_ACPI
  994. static irqreturn_t
  995. ia64_mca_cpe_int_caller(int cpe_irq, void *arg, struct pt_regs *ptregs)
  996. {
  997. static int start_count = -1;
  998. static int poll_time = MIN_CPE_POLL_INTERVAL;
  999. unsigned int cpuid;
  1000. cpuid = smp_processor_id();
  1001. /* If first cpu, update count */
  1002. if (start_count == -1)
  1003. start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CPE);
  1004. ia64_mca_cpe_int_handler(cpe_irq, arg, ptregs);
  1005. for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
  1006. if (cpuid < NR_CPUS) {
  1007. platform_send_ipi(cpuid, IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
  1008. } else {
  1009. /*
  1010. * If a log was recorded, increase our polling frequency,
  1011. * otherwise, backoff or return to interrupt mode.
  1012. */
  1013. if (start_count != IA64_LOG_COUNT(SAL_INFO_TYPE_CPE)) {
  1014. poll_time = max(MIN_CPE_POLL_INTERVAL, poll_time / 2);
  1015. } else if (cpe_vector < 0) {
  1016. poll_time = min(MAX_CPE_POLL_INTERVAL, poll_time * 2);
  1017. } else {
  1018. poll_time = MIN_CPE_POLL_INTERVAL;
  1019. printk(KERN_WARNING "Returning to interrupt driven CPE handler\n");
  1020. enable_irq(local_vector_to_irq(IA64_CPE_VECTOR));
  1021. cpe_poll_enabled = 0;
  1022. }
  1023. if (cpe_poll_enabled)
  1024. mod_timer(&cpe_poll_timer, jiffies + poll_time);
  1025. start_count = -1;
  1026. }
  1027. return IRQ_HANDLED;
  1028. }
  1029. /*
  1030. * ia64_mca_cpe_poll
  1031. *
  1032. * Poll for Corrected Platform Errors (CPEs), trigger interrupt
  1033. * on first cpu, from there it will trickle through all the cpus.
  1034. *
  1035. * Inputs : dummy(unused)
  1036. * Outputs : None
  1037. *
  1038. */
  1039. static void
  1040. ia64_mca_cpe_poll (unsigned long dummy)
  1041. {
  1042. /* Trigger a CPE interrupt cascade */
  1043. platform_send_ipi(first_cpu(cpu_online_map), IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
  1044. }
  1045. #endif /* CONFIG_ACPI */
  1046. /*
  1047. * C portion of the OS INIT handler
  1048. *
  1049. * Called from ia64_os_init_dispatch
  1050. *
  1051. * Inputs: pointer to pt_regs where processor info was saved. SAL/OS state for
  1052. * this event. This code is used for both monarch and slave INIT events, see
  1053. * sos->monarch.
  1054. *
  1055. * All INIT events switch to the INIT stack and change the previous process to
  1056. * blocked status. If one of the INIT events is the monarch then we are
  1057. * probably processing the nmi button/command. Use the monarch cpu to dump all
  1058. * the processes. The slave INIT events all spin until the monarch cpu
  1059. * returns. We can also get INIT slave events for MCA, in which case the MCA
  1060. * process is the monarch.
  1061. */
  1062. void
  1063. ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw,
  1064. struct ia64_sal_os_state *sos)
  1065. {
  1066. static atomic_t slaves;
  1067. static atomic_t monarchs;
  1068. task_t *previous_current;
  1069. int cpu = smp_processor_id(), c;
  1070. struct task_struct *g, *t;
  1071. oops_in_progress = 1; /* FIXME: make printk NMI/MCA/INIT safe */
  1072. console_loglevel = 15; /* make sure printks make it to console */
  1073. printk(KERN_INFO "Entered OS INIT handler. PSP=%lx cpu=%d monarch=%ld\n",
  1074. sos->proc_state_param, cpu, sos->monarch);
  1075. salinfo_log_wakeup(SAL_INFO_TYPE_INIT, NULL, 0, 0);
  1076. previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "INIT");
  1077. sos->os_status = IA64_INIT_RESUME;
  1078. /* FIXME: Workaround for broken proms that drive all INIT events as
  1079. * slaves. The last slave that enters is promoted to be a monarch.
  1080. * Remove this code in September 2006, that gives platforms a year to
  1081. * fix their proms and get their customers updated.
  1082. */
  1083. if (!sos->monarch && atomic_add_return(1, &slaves) == num_online_cpus()) {
  1084. printk(KERN_WARNING "%s: Promoting cpu %d to monarch.\n",
  1085. __FUNCTION__, cpu);
  1086. atomic_dec(&slaves);
  1087. sos->monarch = 1;
  1088. }
  1089. /* FIXME: Workaround for broken proms that drive all INIT events as
  1090. * monarchs. Second and subsequent monarchs are demoted to slaves.
  1091. * Remove this code in September 2006, that gives platforms a year to
  1092. * fix their proms and get their customers updated.
  1093. */
  1094. if (sos->monarch && atomic_add_return(1, &monarchs) > 1) {
  1095. printk(KERN_WARNING "%s: Demoting cpu %d to slave.\n",
  1096. __FUNCTION__, cpu);
  1097. atomic_dec(&monarchs);
  1098. sos->monarch = 0;
  1099. }
  1100. if (!sos->monarch) {
  1101. ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_INIT;
  1102. while (monarch_cpu == -1)
  1103. cpu_relax(); /* spin until monarch enters */
  1104. while (monarch_cpu != -1)
  1105. cpu_relax(); /* spin until monarch leaves */
  1106. printk("Slave on cpu %d returning to normal service.\n", cpu);
  1107. set_curr_task(cpu, previous_current);
  1108. ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
  1109. atomic_dec(&slaves);
  1110. return;
  1111. }
  1112. monarch_cpu = cpu;
  1113. /*
  1114. * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be
  1115. * generated via the BMC's command-line interface, but since the console is on the
  1116. * same serial line, the user will need some time to switch out of the BMC before
  1117. * the dump begins.
  1118. */
  1119. printk("Delaying for 5 seconds...\n");
  1120. udelay(5*1000000);
  1121. ia64_wait_for_slaves(cpu);
  1122. printk(KERN_ERR "Processes interrupted by INIT -");
  1123. for_each_online_cpu(c) {
  1124. struct ia64_sal_os_state *s;
  1125. t = __va(__per_cpu_mca[c] + IA64_MCA_CPU_INIT_STACK_OFFSET);
  1126. s = (struct ia64_sal_os_state *)((char *)t + MCA_SOS_OFFSET);
  1127. g = s->prev_task;
  1128. if (g) {
  1129. if (g->pid)
  1130. printk(" %d", g->pid);
  1131. else
  1132. printk(" %d (cpu %d task 0x%p)", g->pid, task_cpu(g), g);
  1133. }
  1134. }
  1135. printk("\n\n");
  1136. if (read_trylock(&tasklist_lock)) {
  1137. do_each_thread (g, t) {
  1138. printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm);
  1139. show_stack(t, NULL);
  1140. } while_each_thread (g, t);
  1141. read_unlock(&tasklist_lock);
  1142. }
  1143. printk("\nINIT dump complete. Monarch on cpu %d returning to normal service.\n", cpu);
  1144. atomic_dec(&monarchs);
  1145. set_curr_task(cpu, previous_current);
  1146. monarch_cpu = -1;
  1147. return;
  1148. }
  1149. static int __init
  1150. ia64_mca_disable_cpe_polling(char *str)
  1151. {
  1152. cpe_poll_enabled = 0;
  1153. return 1;
  1154. }
  1155. __setup("disable_cpe_poll", ia64_mca_disable_cpe_polling);
  1156. static struct irqaction cmci_irqaction = {
  1157. .handler = ia64_mca_cmc_int_handler,
  1158. .flags = SA_INTERRUPT,
  1159. .name = "cmc_hndlr"
  1160. };
  1161. static struct irqaction cmcp_irqaction = {
  1162. .handler = ia64_mca_cmc_int_caller,
  1163. .flags = SA_INTERRUPT,
  1164. .name = "cmc_poll"
  1165. };
  1166. static struct irqaction mca_rdzv_irqaction = {
  1167. .handler = ia64_mca_rendez_int_handler,
  1168. .flags = SA_INTERRUPT,
  1169. .name = "mca_rdzv"
  1170. };
  1171. static struct irqaction mca_wkup_irqaction = {
  1172. .handler = ia64_mca_wakeup_int_handler,
  1173. .flags = SA_INTERRUPT,
  1174. .name = "mca_wkup"
  1175. };
  1176. #ifdef CONFIG_ACPI
  1177. static struct irqaction mca_cpe_irqaction = {
  1178. .handler = ia64_mca_cpe_int_handler,
  1179. .flags = SA_INTERRUPT,
  1180. .name = "cpe_hndlr"
  1181. };
  1182. static struct irqaction mca_cpep_irqaction = {
  1183. .handler = ia64_mca_cpe_int_caller,
  1184. .flags = SA_INTERRUPT,
  1185. .name = "cpe_poll"
  1186. };
  1187. #endif /* CONFIG_ACPI */
  1188. /* Minimal format of the MCA/INIT stacks. The pseudo processes that run on
  1189. * these stacks can never sleep, they cannot return from the kernel to user
  1190. * space, they do not appear in a normal ps listing. So there is no need to
  1191. * format most of the fields.
  1192. */
  1193. static void
  1194. format_mca_init_stack(void *mca_data, unsigned long offset,
  1195. const char *type, int cpu)
  1196. {
  1197. struct task_struct *p = (struct task_struct *)((char *)mca_data + offset);
  1198. struct thread_info *ti;
  1199. memset(p, 0, KERNEL_STACK_SIZE);
  1200. ti = (struct thread_info *)((char *)p + IA64_TASK_SIZE);
  1201. ti->flags = _TIF_MCA_INIT;
  1202. ti->preempt_count = 1;
  1203. ti->task = p;
  1204. ti->cpu = cpu;
  1205. p->thread_info = ti;
  1206. p->state = TASK_UNINTERRUPTIBLE;
  1207. __set_bit(cpu, &p->cpus_allowed);
  1208. INIT_LIST_HEAD(&p->tasks);
  1209. p->parent = p->real_parent = p->group_leader = p;
  1210. INIT_LIST_HEAD(&p->children);
  1211. INIT_LIST_HEAD(&p->sibling);
  1212. strncpy(p->comm, type, sizeof(p->comm)-1);
  1213. }
  1214. /* Do per-CPU MCA-related initialization. */
  1215. void __devinit
  1216. ia64_mca_cpu_init(void *cpu_data)
  1217. {
  1218. void *pal_vaddr;
  1219. if (smp_processor_id() == 0) {
  1220. void *mca_data;
  1221. int cpu;
  1222. mca_data = alloc_bootmem(sizeof(struct ia64_mca_cpu)
  1223. * NR_CPUS + KERNEL_STACK_SIZE);
  1224. mca_data = (void *)(((unsigned long)mca_data +
  1225. KERNEL_STACK_SIZE - 1) &
  1226. (-KERNEL_STACK_SIZE));
  1227. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  1228. format_mca_init_stack(mca_data,
  1229. offsetof(struct ia64_mca_cpu, mca_stack),
  1230. "MCA", cpu);
  1231. format_mca_init_stack(mca_data,
  1232. offsetof(struct ia64_mca_cpu, init_stack),
  1233. "INIT", cpu);
  1234. __per_cpu_mca[cpu] = __pa(mca_data);
  1235. mca_data += sizeof(struct ia64_mca_cpu);
  1236. }
  1237. }
  1238. /*
  1239. * The MCA info structure was allocated earlier and its
  1240. * physical address saved in __per_cpu_mca[cpu]. Copy that
  1241. * address * to ia64_mca_data so we can access it as a per-CPU
  1242. * variable.
  1243. */
  1244. __get_cpu_var(ia64_mca_data) = __per_cpu_mca[smp_processor_id()];
  1245. /*
  1246. * Stash away a copy of the PTE needed to map the per-CPU page.
  1247. * We may need it during MCA recovery.
  1248. */
  1249. __get_cpu_var(ia64_mca_per_cpu_pte) =
  1250. pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL));
  1251. /*
  1252. * Also, stash away a copy of the PAL address and the PTE
  1253. * needed to map it.
  1254. */
  1255. pal_vaddr = efi_get_pal_addr();
  1256. if (!pal_vaddr)
  1257. return;
  1258. __get_cpu_var(ia64_mca_pal_base) =
  1259. GRANULEROUNDDOWN((unsigned long) pal_vaddr);
  1260. __get_cpu_var(ia64_mca_pal_pte) = pte_val(mk_pte_phys(__pa(pal_vaddr),
  1261. PAGE_KERNEL));
  1262. }
  1263. /*
  1264. * ia64_mca_init
  1265. *
  1266. * Do all the system level mca specific initialization.
  1267. *
  1268. * 1. Register spinloop and wakeup request interrupt vectors
  1269. *
  1270. * 2. Register OS_MCA handler entry point
  1271. *
  1272. * 3. Register OS_INIT handler entry point
  1273. *
  1274. * 4. Initialize MCA/CMC/INIT related log buffers maintained by the OS.
  1275. *
  1276. * Note that this initialization is done very early before some kernel
  1277. * services are available.
  1278. *
  1279. * Inputs : None
  1280. *
  1281. * Outputs : None
  1282. */
  1283. void __init
  1284. ia64_mca_init(void)
  1285. {
  1286. ia64_fptr_t *init_hldlr_ptr_monarch = (ia64_fptr_t *)ia64_os_init_dispatch_monarch;
  1287. ia64_fptr_t *init_hldlr_ptr_slave = (ia64_fptr_t *)ia64_os_init_dispatch_slave;
  1288. ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch;
  1289. int i;
  1290. s64 rc;
  1291. struct ia64_sal_retval isrv;
  1292. u64 timeout = IA64_MCA_RENDEZ_TIMEOUT; /* platform specific */
  1293. IA64_MCA_DEBUG("%s: begin\n", __FUNCTION__);
  1294. /* Clear the Rendez checkin flag for all cpus */
  1295. for(i = 0 ; i < NR_CPUS; i++)
  1296. ia64_mc_info.imi_rendez_checkin[i] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
  1297. /*
  1298. * Register the rendezvous spinloop and wakeup mechanism with SAL
  1299. */
  1300. /* Register the rendezvous interrupt vector with SAL */
  1301. while (1) {
  1302. isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_INT,
  1303. SAL_MC_PARAM_MECHANISM_INT,
  1304. IA64_MCA_RENDEZ_VECTOR,
  1305. timeout,
  1306. SAL_MC_PARAM_RZ_ALWAYS);
  1307. rc = isrv.status;
  1308. if (rc == 0)
  1309. break;
  1310. if (rc == -2) {
  1311. printk(KERN_INFO "Increasing MCA rendezvous timeout from "
  1312. "%ld to %ld milliseconds\n", timeout, isrv.v0);
  1313. timeout = isrv.v0;
  1314. continue;
  1315. }
  1316. printk(KERN_ERR "Failed to register rendezvous interrupt "
  1317. "with SAL (status %ld)\n", rc);
  1318. return;
  1319. }
  1320. /* Register the wakeup interrupt vector with SAL */
  1321. isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_WAKEUP,
  1322. SAL_MC_PARAM_MECHANISM_INT,
  1323. IA64_MCA_WAKEUP_VECTOR,
  1324. 0, 0);
  1325. rc = isrv.status;
  1326. if (rc) {
  1327. printk(KERN_ERR "Failed to register wakeup interrupt with SAL "
  1328. "(status %ld)\n", rc);
  1329. return;
  1330. }
  1331. IA64_MCA_DEBUG("%s: registered MCA rendezvous spinloop and wakeup mech.\n", __FUNCTION__);
  1332. ia64_mc_info.imi_mca_handler = ia64_tpa(mca_hldlr_ptr->fp);
  1333. /*
  1334. * XXX - disable SAL checksum by setting size to 0; should be
  1335. * ia64_tpa(ia64_os_mca_dispatch_end) - ia64_tpa(ia64_os_mca_dispatch);
  1336. */
  1337. ia64_mc_info.imi_mca_handler_size = 0;
  1338. /* Register the os mca handler with SAL */
  1339. if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_MCA,
  1340. ia64_mc_info.imi_mca_handler,
  1341. ia64_tpa(mca_hldlr_ptr->gp),
  1342. ia64_mc_info.imi_mca_handler_size,
  1343. 0, 0, 0)))
  1344. {
  1345. printk(KERN_ERR "Failed to register OS MCA handler with SAL "
  1346. "(status %ld)\n", rc);
  1347. return;
  1348. }
  1349. IA64_MCA_DEBUG("%s: registered OS MCA handler with SAL at 0x%lx, gp = 0x%lx\n", __FUNCTION__,
  1350. ia64_mc_info.imi_mca_handler, ia64_tpa(mca_hldlr_ptr->gp));
  1351. /*
  1352. * XXX - disable SAL checksum by setting size to 0, should be
  1353. * size of the actual init handler in mca_asm.S.
  1354. */
  1355. ia64_mc_info.imi_monarch_init_handler = ia64_tpa(init_hldlr_ptr_monarch->fp);
  1356. ia64_mc_info.imi_monarch_init_handler_size = 0;
  1357. ia64_mc_info.imi_slave_init_handler = ia64_tpa(init_hldlr_ptr_slave->fp);
  1358. ia64_mc_info.imi_slave_init_handler_size = 0;
  1359. IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __FUNCTION__,
  1360. ia64_mc_info.imi_monarch_init_handler);
  1361. /* Register the os init handler with SAL */
  1362. if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_INIT,
  1363. ia64_mc_info.imi_monarch_init_handler,
  1364. ia64_tpa(ia64_getreg(_IA64_REG_GP)),
  1365. ia64_mc_info.imi_monarch_init_handler_size,
  1366. ia64_mc_info.imi_slave_init_handler,
  1367. ia64_tpa(ia64_getreg(_IA64_REG_GP)),
  1368. ia64_mc_info.imi_slave_init_handler_size)))
  1369. {
  1370. printk(KERN_ERR "Failed to register m/s INIT handlers with SAL "
  1371. "(status %ld)\n", rc);
  1372. return;
  1373. }
  1374. IA64_MCA_DEBUG("%s: registered OS INIT handler with SAL\n", __FUNCTION__);
  1375. /*
  1376. * Configure the CMCI/P vector and handler. Interrupts for CMC are
  1377. * per-processor, so AP CMC interrupts are setup in smp_callin() (smpboot.c).
  1378. */
  1379. register_percpu_irq(IA64_CMC_VECTOR, &cmci_irqaction);
  1380. register_percpu_irq(IA64_CMCP_VECTOR, &cmcp_irqaction);
  1381. ia64_mca_cmc_vector_setup(); /* Setup vector on BSP */
  1382. /* Setup the MCA rendezvous interrupt vector */
  1383. register_percpu_irq(IA64_MCA_RENDEZ_VECTOR, &mca_rdzv_irqaction);
  1384. /* Setup the MCA wakeup interrupt vector */
  1385. register_percpu_irq(IA64_MCA_WAKEUP_VECTOR, &mca_wkup_irqaction);
  1386. #ifdef CONFIG_ACPI
  1387. /* Setup the CPEI/P handler */
  1388. register_percpu_irq(IA64_CPEP_VECTOR, &mca_cpep_irqaction);
  1389. #endif
  1390. /* Initialize the areas set aside by the OS to buffer the
  1391. * platform/processor error states for MCA/INIT/CMC
  1392. * handling.
  1393. */
  1394. ia64_log_init(SAL_INFO_TYPE_MCA);
  1395. ia64_log_init(SAL_INFO_TYPE_INIT);
  1396. ia64_log_init(SAL_INFO_TYPE_CMC);
  1397. ia64_log_init(SAL_INFO_TYPE_CPE);
  1398. mca_init = 1;
  1399. printk(KERN_INFO "MCA related initialization done\n");
  1400. }
  1401. /*
  1402. * ia64_mca_late_init
  1403. *
  1404. * Opportunity to setup things that require initialization later
  1405. * than ia64_mca_init. Setup a timer to poll for CPEs if the
  1406. * platform doesn't support an interrupt driven mechanism.
  1407. *
  1408. * Inputs : None
  1409. * Outputs : Status
  1410. */
  1411. static int __init
  1412. ia64_mca_late_init(void)
  1413. {
  1414. if (!mca_init)
  1415. return 0;
  1416. /* Setup the CMCI/P vector and handler */
  1417. init_timer(&cmc_poll_timer);
  1418. cmc_poll_timer.function = ia64_mca_cmc_poll;
  1419. /* Unmask/enable the vector */
  1420. cmc_polling_enabled = 0;
  1421. schedule_work(&cmc_enable_work);
  1422. IA64_MCA_DEBUG("%s: CMCI/P setup and enabled.\n", __FUNCTION__);
  1423. #ifdef CONFIG_ACPI
  1424. /* Setup the CPEI/P vector and handler */
  1425. cpe_vector = acpi_request_vector(ACPI_INTERRUPT_CPEI);
  1426. init_timer(&cpe_poll_timer);
  1427. cpe_poll_timer.function = ia64_mca_cpe_poll;
  1428. {
  1429. irq_desc_t *desc;
  1430. unsigned int irq;
  1431. if (cpe_vector >= 0) {
  1432. /* If platform supports CPEI, enable the irq. */
  1433. cpe_poll_enabled = 0;
  1434. for (irq = 0; irq < NR_IRQS; ++irq)
  1435. if (irq_to_vector(irq) == cpe_vector) {
  1436. desc = irq_descp(irq);
  1437. desc->status |= IRQ_PER_CPU;
  1438. setup_irq(irq, &mca_cpe_irqaction);
  1439. }
  1440. ia64_mca_register_cpev(cpe_vector);
  1441. IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n", __FUNCTION__);
  1442. } else {
  1443. /* If platform doesn't support CPEI, get the timer going. */
  1444. if (cpe_poll_enabled) {
  1445. ia64_mca_cpe_poll(0UL);
  1446. IA64_MCA_DEBUG("%s: CPEP setup and enabled.\n", __FUNCTION__);
  1447. }
  1448. }
  1449. }
  1450. #endif
  1451. return 0;
  1452. }
  1453. device_initcall(ia64_mca_late_init);