mca.c 51 KB

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