mca.c 52 KB

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