mca.c 52 KB

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