mca.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  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. #include <linux/config.h>
  53. #include <linux/types.h>
  54. #include <linux/init.h>
  55. #include <linux/sched.h>
  56. #include <linux/interrupt.h>
  57. #include <linux/irq.h>
  58. #include <linux/kallsyms.h>
  59. #include <linux/smp_lock.h>
  60. #include <linux/bootmem.h>
  61. #include <linux/acpi.h>
  62. #include <linux/timer.h>
  63. #include <linux/module.h>
  64. #include <linux/kernel.h>
  65. #include <linux/smp.h>
  66. #include <linux/workqueue.h>
  67. #include <asm/delay.h>
  68. #include <asm/machvec.h>
  69. #include <asm/meminit.h>
  70. #include <asm/page.h>
  71. #include <asm/ptrace.h>
  72. #include <asm/system.h>
  73. #include <asm/sal.h>
  74. #include <asm/mca.h>
  75. #include <asm/irq.h>
  76. #include <asm/hw_irq.h>
  77. #if defined(IA64_MCA_DEBUG_INFO)
  78. # define IA64_MCA_DEBUG(fmt...) printk(fmt)
  79. #else
  80. # define IA64_MCA_DEBUG(fmt...)
  81. #endif
  82. /* Used by mca_asm.S */
  83. ia64_mca_sal_to_os_state_t ia64_sal_to_os_handoff_state;
  84. ia64_mca_os_to_sal_state_t ia64_os_to_sal_handoff_state;
  85. u64 ia64_mca_serialize;
  86. DEFINE_PER_CPU(u64, ia64_mca_data); /* == __per_cpu_mca[smp_processor_id()] */
  87. DEFINE_PER_CPU(u64, ia64_mca_per_cpu_pte); /* PTE to map per-CPU area */
  88. DEFINE_PER_CPU(u64, ia64_mca_pal_pte); /* PTE to map PAL code */
  89. DEFINE_PER_CPU(u64, ia64_mca_pal_base); /* vaddr PAL code granule */
  90. unsigned long __per_cpu_mca[NR_CPUS];
  91. /* In mca_asm.S */
  92. extern void ia64_monarch_init_handler (void);
  93. extern void ia64_slave_init_handler (void);
  94. static ia64_mc_info_t ia64_mc_info;
  95. #define MAX_CPE_POLL_INTERVAL (15*60*HZ) /* 15 minutes */
  96. #define MIN_CPE_POLL_INTERVAL (2*60*HZ) /* 2 minutes */
  97. #define CMC_POLL_INTERVAL (1*60*HZ) /* 1 minute */
  98. #define CPE_HISTORY_LENGTH 5
  99. #define CMC_HISTORY_LENGTH 5
  100. static struct timer_list cpe_poll_timer;
  101. static struct timer_list cmc_poll_timer;
  102. /*
  103. * This variable tells whether we are currently in polling mode.
  104. * Start with this in the wrong state so we won't play w/ timers
  105. * before the system is ready.
  106. */
  107. static int cmc_polling_enabled = 1;
  108. /*
  109. * Clearing this variable prevents CPE polling from getting activated
  110. * in mca_late_init. Use it if your system doesn't provide a CPEI,
  111. * but encounters problems retrieving CPE logs. This should only be
  112. * necessary for debugging.
  113. */
  114. static int cpe_poll_enabled = 1;
  115. extern void salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe);
  116. static int mca_init;
  117. /*
  118. * IA64_MCA log support
  119. */
  120. #define IA64_MAX_LOGS 2 /* Double-buffering for nested MCAs */
  121. #define IA64_MAX_LOG_TYPES 4 /* MCA, INIT, CMC, CPE */
  122. typedef struct ia64_state_log_s
  123. {
  124. spinlock_t isl_lock;
  125. int isl_index;
  126. unsigned long isl_count;
  127. ia64_err_rec_t *isl_log[IA64_MAX_LOGS]; /* need space to store header + error log */
  128. } ia64_state_log_t;
  129. static ia64_state_log_t ia64_state_log[IA64_MAX_LOG_TYPES];
  130. #define IA64_LOG_ALLOCATE(it, size) \
  131. {ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)] = \
  132. (ia64_err_rec_t *)alloc_bootmem(size); \
  133. ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)] = \
  134. (ia64_err_rec_t *)alloc_bootmem(size);}
  135. #define IA64_LOG_LOCK_INIT(it) spin_lock_init(&ia64_state_log[it].isl_lock)
  136. #define IA64_LOG_LOCK(it) spin_lock_irqsave(&ia64_state_log[it].isl_lock, s)
  137. #define IA64_LOG_UNLOCK(it) spin_unlock_irqrestore(&ia64_state_log[it].isl_lock,s)
  138. #define IA64_LOG_NEXT_INDEX(it) ia64_state_log[it].isl_index
  139. #define IA64_LOG_CURR_INDEX(it) 1 - ia64_state_log[it].isl_index
  140. #define IA64_LOG_INDEX_INC(it) \
  141. {ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index; \
  142. ia64_state_log[it].isl_count++;}
  143. #define IA64_LOG_INDEX_DEC(it) \
  144. ia64_state_log[it].isl_index = 1 - ia64_state_log[it].isl_index
  145. #define IA64_LOG_NEXT_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_NEXT_INDEX(it)]))
  146. #define IA64_LOG_CURR_BUFFER(it) (void *)((ia64_state_log[it].isl_log[IA64_LOG_CURR_INDEX(it)]))
  147. #define IA64_LOG_COUNT(it) ia64_state_log[it].isl_count
  148. /*
  149. * ia64_log_init
  150. * Reset the OS ia64 log buffer
  151. * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
  152. * Outputs : None
  153. */
  154. static void
  155. ia64_log_init(int sal_info_type)
  156. {
  157. u64 max_size = 0;
  158. IA64_LOG_NEXT_INDEX(sal_info_type) = 0;
  159. IA64_LOG_LOCK_INIT(sal_info_type);
  160. // SAL will tell us the maximum size of any error record of this type
  161. max_size = ia64_sal_get_state_info_size(sal_info_type);
  162. if (!max_size)
  163. /* alloc_bootmem() doesn't like zero-sized allocations! */
  164. return;
  165. // set up OS data structures to hold error info
  166. IA64_LOG_ALLOCATE(sal_info_type, max_size);
  167. memset(IA64_LOG_CURR_BUFFER(sal_info_type), 0, max_size);
  168. memset(IA64_LOG_NEXT_BUFFER(sal_info_type), 0, max_size);
  169. }
  170. /*
  171. * ia64_log_get
  172. *
  173. * Get the current MCA log from SAL and copy it into the OS log buffer.
  174. *
  175. * Inputs : info_type (SAL_INFO_TYPE_{MCA,INIT,CMC,CPE})
  176. * irq_safe whether you can use printk at this point
  177. * Outputs : size (total record length)
  178. * *buffer (ptr to error record)
  179. *
  180. */
  181. static u64
  182. ia64_log_get(int sal_info_type, u8 **buffer, int irq_safe)
  183. {
  184. sal_log_record_header_t *log_buffer;
  185. u64 total_len = 0;
  186. int s;
  187. IA64_LOG_LOCK(sal_info_type);
  188. /* Get the process state information */
  189. log_buffer = IA64_LOG_NEXT_BUFFER(sal_info_type);
  190. total_len = ia64_sal_get_state_info(sal_info_type, (u64 *)log_buffer);
  191. if (total_len) {
  192. IA64_LOG_INDEX_INC(sal_info_type);
  193. IA64_LOG_UNLOCK(sal_info_type);
  194. if (irq_safe) {
  195. IA64_MCA_DEBUG("%s: SAL error record type %d retrieved. "
  196. "Record length = %ld\n", __FUNCTION__, sal_info_type, total_len);
  197. }
  198. *buffer = (u8 *) log_buffer;
  199. return total_len;
  200. } else {
  201. IA64_LOG_UNLOCK(sal_info_type);
  202. return 0;
  203. }
  204. }
  205. /*
  206. * ia64_mca_log_sal_error_record
  207. *
  208. * This function retrieves a specified error record type from SAL
  209. * and wakes up any processes waiting for error records.
  210. *
  211. * Inputs : sal_info_type (Type of error record MCA/CMC/CPE/INIT)
  212. */
  213. static void
  214. ia64_mca_log_sal_error_record(int sal_info_type)
  215. {
  216. u8 *buffer;
  217. sal_log_record_header_t *rh;
  218. u64 size;
  219. int irq_safe = sal_info_type != SAL_INFO_TYPE_MCA && sal_info_type != SAL_INFO_TYPE_INIT;
  220. #ifdef IA64_MCA_DEBUG_INFO
  221. static const char * const rec_name[] = { "MCA", "INIT", "CMC", "CPE" };
  222. #endif
  223. size = ia64_log_get(sal_info_type, &buffer, irq_safe);
  224. if (!size)
  225. return;
  226. salinfo_log_wakeup(sal_info_type, buffer, size, irq_safe);
  227. if (irq_safe)
  228. IA64_MCA_DEBUG("CPU %d: SAL log contains %s error record\n",
  229. smp_processor_id(),
  230. sal_info_type < ARRAY_SIZE(rec_name) ? rec_name[sal_info_type] : "UNKNOWN");
  231. /* Clear logs from corrected errors in case there's no user-level logger */
  232. rh = (sal_log_record_header_t *)buffer;
  233. if (rh->severity == sal_log_severity_corrected)
  234. ia64_sal_clear_state_info(sal_info_type);
  235. }
  236. /*
  237. * platform dependent error handling
  238. */
  239. #ifndef PLATFORM_MCA_HANDLERS
  240. #ifdef CONFIG_ACPI
  241. int cpe_vector = -1;
  242. static irqreturn_t
  243. ia64_mca_cpe_int_handler (int cpe_irq, void *arg, struct pt_regs *ptregs)
  244. {
  245. static unsigned long cpe_history[CPE_HISTORY_LENGTH];
  246. static int index;
  247. static DEFINE_SPINLOCK(cpe_history_lock);
  248. IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
  249. __FUNCTION__, cpe_irq, smp_processor_id());
  250. /* SAL spec states this should run w/ interrupts enabled */
  251. local_irq_enable();
  252. /* Get the CPE error record and log it */
  253. ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE);
  254. spin_lock(&cpe_history_lock);
  255. if (!cpe_poll_enabled && cpe_vector >= 0) {
  256. int i, count = 1; /* we know 1 happened now */
  257. unsigned long now = jiffies;
  258. for (i = 0; i < CPE_HISTORY_LENGTH; i++) {
  259. if (now - cpe_history[i] <= HZ)
  260. count++;
  261. }
  262. IA64_MCA_DEBUG(KERN_INFO "CPE threshold %d/%d\n", count, CPE_HISTORY_LENGTH);
  263. if (count >= CPE_HISTORY_LENGTH) {
  264. cpe_poll_enabled = 1;
  265. spin_unlock(&cpe_history_lock);
  266. disable_irq_nosync(local_vector_to_irq(IA64_CPE_VECTOR));
  267. /*
  268. * Corrected errors will still be corrected, but
  269. * make sure there's a log somewhere that indicates
  270. * something is generating more than we can handle.
  271. */
  272. printk(KERN_WARNING "WARNING: Switching to polling CPE handler; error records may be lost\n");
  273. mod_timer(&cpe_poll_timer, jiffies + MIN_CPE_POLL_INTERVAL);
  274. /* lock already released, get out now */
  275. return IRQ_HANDLED;
  276. } else {
  277. cpe_history[index++] = now;
  278. if (index == CPE_HISTORY_LENGTH)
  279. index = 0;
  280. }
  281. }
  282. spin_unlock(&cpe_history_lock);
  283. return IRQ_HANDLED;
  284. }
  285. #endif /* CONFIG_ACPI */
  286. static void
  287. show_min_state (pal_min_state_area_t *minstate)
  288. {
  289. u64 iip = minstate->pmsa_iip + ((struct ia64_psr *)(&minstate->pmsa_ipsr))->ri;
  290. u64 xip = minstate->pmsa_xip + ((struct ia64_psr *)(&minstate->pmsa_xpsr))->ri;
  291. printk("NaT bits\t%016lx\n", minstate->pmsa_nat_bits);
  292. printk("pr\t\t%016lx\n", minstate->pmsa_pr);
  293. printk("b0\t\t%016lx ", minstate->pmsa_br0); print_symbol("%s\n", minstate->pmsa_br0);
  294. printk("ar.rsc\t\t%016lx\n", minstate->pmsa_rsc);
  295. printk("cr.iip\t\t%016lx ", iip); print_symbol("%s\n", iip);
  296. printk("cr.ipsr\t\t%016lx\n", minstate->pmsa_ipsr);
  297. printk("cr.ifs\t\t%016lx\n", minstate->pmsa_ifs);
  298. printk("xip\t\t%016lx ", xip); print_symbol("%s\n", xip);
  299. printk("xpsr\t\t%016lx\n", minstate->pmsa_xpsr);
  300. printk("xfs\t\t%016lx\n", minstate->pmsa_xfs);
  301. printk("b1\t\t%016lx ", minstate->pmsa_br1);
  302. print_symbol("%s\n", minstate->pmsa_br1);
  303. printk("\nstatic registers r0-r15:\n");
  304. printk(" r0- 3 %016lx %016lx %016lx %016lx\n",
  305. 0UL, minstate->pmsa_gr[0], minstate->pmsa_gr[1], minstate->pmsa_gr[2]);
  306. printk(" r4- 7 %016lx %016lx %016lx %016lx\n",
  307. minstate->pmsa_gr[3], minstate->pmsa_gr[4],
  308. minstate->pmsa_gr[5], minstate->pmsa_gr[6]);
  309. printk(" r8-11 %016lx %016lx %016lx %016lx\n",
  310. minstate->pmsa_gr[7], minstate->pmsa_gr[8],
  311. minstate->pmsa_gr[9], minstate->pmsa_gr[10]);
  312. printk("r12-15 %016lx %016lx %016lx %016lx\n",
  313. minstate->pmsa_gr[11], minstate->pmsa_gr[12],
  314. minstate->pmsa_gr[13], minstate->pmsa_gr[14]);
  315. printk("\nbank 0:\n");
  316. printk("r16-19 %016lx %016lx %016lx %016lx\n",
  317. minstate->pmsa_bank0_gr[0], minstate->pmsa_bank0_gr[1],
  318. minstate->pmsa_bank0_gr[2], minstate->pmsa_bank0_gr[3]);
  319. printk("r20-23 %016lx %016lx %016lx %016lx\n",
  320. minstate->pmsa_bank0_gr[4], minstate->pmsa_bank0_gr[5],
  321. minstate->pmsa_bank0_gr[6], minstate->pmsa_bank0_gr[7]);
  322. printk("r24-27 %016lx %016lx %016lx %016lx\n",
  323. minstate->pmsa_bank0_gr[8], minstate->pmsa_bank0_gr[9],
  324. minstate->pmsa_bank0_gr[10], minstate->pmsa_bank0_gr[11]);
  325. printk("r28-31 %016lx %016lx %016lx %016lx\n",
  326. minstate->pmsa_bank0_gr[12], minstate->pmsa_bank0_gr[13],
  327. minstate->pmsa_bank0_gr[14], minstate->pmsa_bank0_gr[15]);
  328. printk("\nbank 1:\n");
  329. printk("r16-19 %016lx %016lx %016lx %016lx\n",
  330. minstate->pmsa_bank1_gr[0], minstate->pmsa_bank1_gr[1],
  331. minstate->pmsa_bank1_gr[2], minstate->pmsa_bank1_gr[3]);
  332. printk("r20-23 %016lx %016lx %016lx %016lx\n",
  333. minstate->pmsa_bank1_gr[4], minstate->pmsa_bank1_gr[5],
  334. minstate->pmsa_bank1_gr[6], minstate->pmsa_bank1_gr[7]);
  335. printk("r24-27 %016lx %016lx %016lx %016lx\n",
  336. minstate->pmsa_bank1_gr[8], minstate->pmsa_bank1_gr[9],
  337. minstate->pmsa_bank1_gr[10], minstate->pmsa_bank1_gr[11]);
  338. printk("r28-31 %016lx %016lx %016lx %016lx\n",
  339. minstate->pmsa_bank1_gr[12], minstate->pmsa_bank1_gr[13],
  340. minstate->pmsa_bank1_gr[14], minstate->pmsa_bank1_gr[15]);
  341. }
  342. static void
  343. fetch_min_state (pal_min_state_area_t *ms, struct pt_regs *pt, struct switch_stack *sw)
  344. {
  345. u64 *dst_banked, *src_banked, bit, shift, nat_bits;
  346. int i;
  347. /*
  348. * First, update the pt-regs and switch-stack structures with the contents stored
  349. * in the min-state area:
  350. */
  351. if (((struct ia64_psr *) &ms->pmsa_ipsr)->ic == 0) {
  352. pt->cr_ipsr = ms->pmsa_xpsr;
  353. pt->cr_iip = ms->pmsa_xip;
  354. pt->cr_ifs = ms->pmsa_xfs;
  355. } else {
  356. pt->cr_ipsr = ms->pmsa_ipsr;
  357. pt->cr_iip = ms->pmsa_iip;
  358. pt->cr_ifs = ms->pmsa_ifs;
  359. }
  360. pt->ar_rsc = ms->pmsa_rsc;
  361. pt->pr = ms->pmsa_pr;
  362. pt->r1 = ms->pmsa_gr[0];
  363. pt->r2 = ms->pmsa_gr[1];
  364. pt->r3 = ms->pmsa_gr[2];
  365. sw->r4 = ms->pmsa_gr[3];
  366. sw->r5 = ms->pmsa_gr[4];
  367. sw->r6 = ms->pmsa_gr[5];
  368. sw->r7 = ms->pmsa_gr[6];
  369. pt->r8 = ms->pmsa_gr[7];
  370. pt->r9 = ms->pmsa_gr[8];
  371. pt->r10 = ms->pmsa_gr[9];
  372. pt->r11 = ms->pmsa_gr[10];
  373. pt->r12 = ms->pmsa_gr[11];
  374. pt->r13 = ms->pmsa_gr[12];
  375. pt->r14 = ms->pmsa_gr[13];
  376. pt->r15 = ms->pmsa_gr[14];
  377. dst_banked = &pt->r16; /* r16-r31 are contiguous in struct pt_regs */
  378. src_banked = ms->pmsa_bank1_gr;
  379. for (i = 0; i < 16; ++i)
  380. dst_banked[i] = src_banked[i];
  381. pt->b0 = ms->pmsa_br0;
  382. sw->b1 = ms->pmsa_br1;
  383. /* construct the NaT bits for the pt-regs structure: */
  384. # define PUT_NAT_BIT(dst, addr) \
  385. do { \
  386. bit = nat_bits & 1; nat_bits >>= 1; \
  387. shift = ((unsigned long) addr >> 3) & 0x3f; \
  388. dst = ((dst) & ~(1UL << shift)) | (bit << shift); \
  389. } while (0)
  390. /* Rotate the saved NaT bits such that bit 0 corresponds to pmsa_gr[0]: */
  391. shift = ((unsigned long) &ms->pmsa_gr[0] >> 3) & 0x3f;
  392. nat_bits = (ms->pmsa_nat_bits >> shift) | (ms->pmsa_nat_bits << (64 - shift));
  393. PUT_NAT_BIT(sw->caller_unat, &pt->r1);
  394. PUT_NAT_BIT(sw->caller_unat, &pt->r2);
  395. PUT_NAT_BIT(sw->caller_unat, &pt->r3);
  396. PUT_NAT_BIT(sw->ar_unat, &sw->r4);
  397. PUT_NAT_BIT(sw->ar_unat, &sw->r5);
  398. PUT_NAT_BIT(sw->ar_unat, &sw->r6);
  399. PUT_NAT_BIT(sw->ar_unat, &sw->r7);
  400. PUT_NAT_BIT(sw->caller_unat, &pt->r8); PUT_NAT_BIT(sw->caller_unat, &pt->r9);
  401. PUT_NAT_BIT(sw->caller_unat, &pt->r10); PUT_NAT_BIT(sw->caller_unat, &pt->r11);
  402. PUT_NAT_BIT(sw->caller_unat, &pt->r12); PUT_NAT_BIT(sw->caller_unat, &pt->r13);
  403. PUT_NAT_BIT(sw->caller_unat, &pt->r14); PUT_NAT_BIT(sw->caller_unat, &pt->r15);
  404. nat_bits >>= 16; /* skip over bank0 NaT bits */
  405. PUT_NAT_BIT(sw->caller_unat, &pt->r16); PUT_NAT_BIT(sw->caller_unat, &pt->r17);
  406. PUT_NAT_BIT(sw->caller_unat, &pt->r18); PUT_NAT_BIT(sw->caller_unat, &pt->r19);
  407. PUT_NAT_BIT(sw->caller_unat, &pt->r20); PUT_NAT_BIT(sw->caller_unat, &pt->r21);
  408. PUT_NAT_BIT(sw->caller_unat, &pt->r22); PUT_NAT_BIT(sw->caller_unat, &pt->r23);
  409. PUT_NAT_BIT(sw->caller_unat, &pt->r24); PUT_NAT_BIT(sw->caller_unat, &pt->r25);
  410. PUT_NAT_BIT(sw->caller_unat, &pt->r26); PUT_NAT_BIT(sw->caller_unat, &pt->r27);
  411. PUT_NAT_BIT(sw->caller_unat, &pt->r28); PUT_NAT_BIT(sw->caller_unat, &pt->r29);
  412. PUT_NAT_BIT(sw->caller_unat, &pt->r30); PUT_NAT_BIT(sw->caller_unat, &pt->r31);
  413. }
  414. static void
  415. init_handler_platform (pal_min_state_area_t *ms,
  416. struct pt_regs *pt, struct switch_stack *sw)
  417. {
  418. struct unw_frame_info info;
  419. /* if a kernel debugger is available call it here else just dump the registers */
  420. /*
  421. * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be
  422. * generated via the BMC's command-line interface, but since the console is on the
  423. * same serial line, the user will need some time to switch out of the BMC before
  424. * the dump begins.
  425. */
  426. printk("Delaying for 5 seconds...\n");
  427. udelay(5*1000000);
  428. show_min_state(ms);
  429. printk("Backtrace of current task (pid %d, %s)\n", current->pid, current->comm);
  430. fetch_min_state(ms, pt, sw);
  431. unw_init_from_interruption(&info, current, pt, sw);
  432. ia64_do_show_stack(&info, NULL);
  433. if (read_trylock(&tasklist_lock)) {
  434. struct task_struct *g, *t;
  435. do_each_thread (g, t) {
  436. if (t == current)
  437. continue;
  438. printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm);
  439. show_stack(t, NULL);
  440. } while_each_thread (g, t);
  441. }
  442. printk("\nINIT dump complete. Please reboot now.\n");
  443. while (1); /* hang city if no debugger */
  444. }
  445. #ifdef CONFIG_ACPI
  446. /*
  447. * ia64_mca_register_cpev
  448. *
  449. * Register the corrected platform error vector with SAL.
  450. *
  451. * Inputs
  452. * cpev Corrected Platform Error Vector number
  453. *
  454. * Outputs
  455. * None
  456. */
  457. static void
  458. ia64_mca_register_cpev (int cpev)
  459. {
  460. /* Register the CPE interrupt vector with SAL */
  461. struct ia64_sal_retval isrv;
  462. isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_CPE_INT, SAL_MC_PARAM_MECHANISM_INT, cpev, 0, 0);
  463. if (isrv.status) {
  464. printk(KERN_ERR "Failed to register Corrected Platform "
  465. "Error interrupt vector with SAL (status %ld)\n", isrv.status);
  466. return;
  467. }
  468. IA64_MCA_DEBUG("%s: corrected platform error "
  469. "vector %#x registered\n", __FUNCTION__, cpev);
  470. }
  471. #endif /* CONFIG_ACPI */
  472. #endif /* PLATFORM_MCA_HANDLERS */
  473. /*
  474. * ia64_mca_cmc_vector_setup
  475. *
  476. * Setup the corrected machine check vector register in the processor.
  477. * (The interrupt is masked on boot. ia64_mca_late_init unmask this.)
  478. * This function is invoked on a per-processor basis.
  479. *
  480. * Inputs
  481. * None
  482. *
  483. * Outputs
  484. * None
  485. */
  486. void
  487. ia64_mca_cmc_vector_setup (void)
  488. {
  489. cmcv_reg_t cmcv;
  490. cmcv.cmcv_regval = 0;
  491. cmcv.cmcv_mask = 1; /* Mask/disable interrupt at first */
  492. cmcv.cmcv_vector = IA64_CMC_VECTOR;
  493. ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
  494. IA64_MCA_DEBUG("%s: CPU %d corrected "
  495. "machine check vector %#x registered.\n",
  496. __FUNCTION__, smp_processor_id(), IA64_CMC_VECTOR);
  497. IA64_MCA_DEBUG("%s: CPU %d CMCV = %#016lx\n",
  498. __FUNCTION__, smp_processor_id(), ia64_getreg(_IA64_REG_CR_CMCV));
  499. }
  500. /*
  501. * ia64_mca_cmc_vector_disable
  502. *
  503. * Mask the corrected machine check vector register in the processor.
  504. * This function is invoked on a per-processor basis.
  505. *
  506. * Inputs
  507. * dummy(unused)
  508. *
  509. * Outputs
  510. * None
  511. */
  512. static void
  513. ia64_mca_cmc_vector_disable (void *dummy)
  514. {
  515. cmcv_reg_t cmcv;
  516. cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV);
  517. cmcv.cmcv_mask = 1; /* Mask/disable interrupt */
  518. ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
  519. IA64_MCA_DEBUG("%s: CPU %d corrected "
  520. "machine check vector %#x disabled.\n",
  521. __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector);
  522. }
  523. /*
  524. * ia64_mca_cmc_vector_enable
  525. *
  526. * Unmask the corrected machine check vector register in the processor.
  527. * This function is invoked on a per-processor basis.
  528. *
  529. * Inputs
  530. * dummy(unused)
  531. *
  532. * Outputs
  533. * None
  534. */
  535. static void
  536. ia64_mca_cmc_vector_enable (void *dummy)
  537. {
  538. cmcv_reg_t cmcv;
  539. cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV);
  540. cmcv.cmcv_mask = 0; /* Unmask/enable interrupt */
  541. ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
  542. IA64_MCA_DEBUG("%s: CPU %d corrected "
  543. "machine check vector %#x enabled.\n",
  544. __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector);
  545. }
  546. /*
  547. * ia64_mca_cmc_vector_disable_keventd
  548. *
  549. * Called via keventd (smp_call_function() is not safe in interrupt context) to
  550. * disable the cmc interrupt vector.
  551. */
  552. static void
  553. ia64_mca_cmc_vector_disable_keventd(void *unused)
  554. {
  555. on_each_cpu(ia64_mca_cmc_vector_disable, NULL, 1, 0);
  556. }
  557. /*
  558. * ia64_mca_cmc_vector_enable_keventd
  559. *
  560. * Called via keventd (smp_call_function() is not safe in interrupt context) to
  561. * enable the cmc interrupt vector.
  562. */
  563. static void
  564. ia64_mca_cmc_vector_enable_keventd(void *unused)
  565. {
  566. on_each_cpu(ia64_mca_cmc_vector_enable, NULL, 1, 0);
  567. }
  568. /*
  569. * ia64_mca_wakeup_ipi_wait
  570. *
  571. * Wait for the inter-cpu interrupt to be sent by the
  572. * monarch processor once it is done with handling the
  573. * MCA.
  574. *
  575. * Inputs : None
  576. * Outputs : None
  577. */
  578. static void
  579. ia64_mca_wakeup_ipi_wait(void)
  580. {
  581. int irr_num = (IA64_MCA_WAKEUP_VECTOR >> 6);
  582. int irr_bit = (IA64_MCA_WAKEUP_VECTOR & 0x3f);
  583. u64 irr = 0;
  584. do {
  585. switch(irr_num) {
  586. case 0:
  587. irr = ia64_getreg(_IA64_REG_CR_IRR0);
  588. break;
  589. case 1:
  590. irr = ia64_getreg(_IA64_REG_CR_IRR1);
  591. break;
  592. case 2:
  593. irr = ia64_getreg(_IA64_REG_CR_IRR2);
  594. break;
  595. case 3:
  596. irr = ia64_getreg(_IA64_REG_CR_IRR3);
  597. break;
  598. }
  599. cpu_relax();
  600. } while (!(irr & (1UL << irr_bit))) ;
  601. }
  602. /*
  603. * ia64_mca_wakeup
  604. *
  605. * Send an inter-cpu interrupt to wake-up a particular cpu
  606. * and mark that cpu to be out of rendez.
  607. *
  608. * Inputs : cpuid
  609. * Outputs : None
  610. */
  611. static void
  612. ia64_mca_wakeup(int cpu)
  613. {
  614. platform_send_ipi(cpu, IA64_MCA_WAKEUP_VECTOR, IA64_IPI_DM_INT, 0);
  615. ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
  616. }
  617. /*
  618. * ia64_mca_wakeup_all
  619. *
  620. * Wakeup all the cpus which have rendez'ed previously.
  621. *
  622. * Inputs : None
  623. * Outputs : None
  624. */
  625. static void
  626. ia64_mca_wakeup_all(void)
  627. {
  628. int cpu;
  629. /* Clear the Rendez checkin flag for all cpus */
  630. for(cpu = 0; cpu < NR_CPUS; cpu++) {
  631. if (!cpu_online(cpu))
  632. continue;
  633. if (ia64_mc_info.imi_rendez_checkin[cpu] == IA64_MCA_RENDEZ_CHECKIN_DONE)
  634. ia64_mca_wakeup(cpu);
  635. }
  636. }
  637. /*
  638. * ia64_mca_rendez_interrupt_handler
  639. *
  640. * This is handler used to put slave processors into spinloop
  641. * while the monarch processor does the mca handling and later
  642. * wake each slave up once the monarch is done.
  643. *
  644. * Inputs : None
  645. * Outputs : None
  646. */
  647. static irqreturn_t
  648. ia64_mca_rendez_int_handler(int rendez_irq, void *arg, struct pt_regs *ptregs)
  649. {
  650. unsigned long flags;
  651. int cpu = smp_processor_id();
  652. /* Mask all interrupts */
  653. local_irq_save(flags);
  654. ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_DONE;
  655. /* Register with the SAL monarch that the slave has
  656. * reached SAL
  657. */
  658. ia64_sal_mc_rendez();
  659. /* Wait for the wakeup IPI from the monarch
  660. * This waiting is done by polling on the wakeup-interrupt
  661. * vector bit in the processor's IRRs
  662. */
  663. ia64_mca_wakeup_ipi_wait();
  664. /* Enable all interrupts */
  665. local_irq_restore(flags);
  666. return IRQ_HANDLED;
  667. }
  668. /*
  669. * ia64_mca_wakeup_int_handler
  670. *
  671. * The interrupt handler for processing the inter-cpu interrupt to the
  672. * slave cpu which was spinning in the rendez loop.
  673. * Since this spinning is done by turning off the interrupts and
  674. * polling on the wakeup-interrupt bit in the IRR, there is
  675. * nothing useful to be done in the handler.
  676. *
  677. * Inputs : wakeup_irq (Wakeup-interrupt bit)
  678. * arg (Interrupt handler specific argument)
  679. * ptregs (Exception frame at the time of the interrupt)
  680. * Outputs : None
  681. *
  682. */
  683. static irqreturn_t
  684. ia64_mca_wakeup_int_handler(int wakeup_irq, void *arg, struct pt_regs *ptregs)
  685. {
  686. return IRQ_HANDLED;
  687. }
  688. /*
  689. * ia64_return_to_sal_check
  690. *
  691. * This is function called before going back from the OS_MCA handler
  692. * to the OS_MCA dispatch code which finally takes the control back
  693. * to the SAL.
  694. * The main purpose of this routine is to setup the OS_MCA to SAL
  695. * return state which can be used by the OS_MCA dispatch code
  696. * just before going back to SAL.
  697. *
  698. * Inputs : None
  699. * Outputs : None
  700. */
  701. static void
  702. ia64_return_to_sal_check(int recover)
  703. {
  704. /* Copy over some relevant stuff from the sal_to_os_mca_handoff
  705. * so that it can be used at the time of os_mca_to_sal_handoff
  706. */
  707. ia64_os_to_sal_handoff_state.imots_sal_gp =
  708. ia64_sal_to_os_handoff_state.imsto_sal_gp;
  709. ia64_os_to_sal_handoff_state.imots_sal_check_ra =
  710. ia64_sal_to_os_handoff_state.imsto_sal_check_ra;
  711. if (recover)
  712. ia64_os_to_sal_handoff_state.imots_os_status = IA64_MCA_CORRECTED;
  713. else
  714. ia64_os_to_sal_handoff_state.imots_os_status = IA64_MCA_COLD_BOOT;
  715. /* Default = tell SAL to return to same context */
  716. ia64_os_to_sal_handoff_state.imots_context = IA64_MCA_SAME_CONTEXT;
  717. ia64_os_to_sal_handoff_state.imots_new_min_state =
  718. (u64 *)ia64_sal_to_os_handoff_state.pal_min_state;
  719. }
  720. /* Function pointer for extra MCA recovery */
  721. int (*ia64_mca_ucmc_extension)
  722. (void*,ia64_mca_sal_to_os_state_t*,ia64_mca_os_to_sal_state_t*)
  723. = NULL;
  724. int
  725. ia64_reg_MCA_extension(void *fn)
  726. {
  727. if (ia64_mca_ucmc_extension)
  728. return 1;
  729. ia64_mca_ucmc_extension = fn;
  730. return 0;
  731. }
  732. void
  733. ia64_unreg_MCA_extension(void)
  734. {
  735. if (ia64_mca_ucmc_extension)
  736. ia64_mca_ucmc_extension = NULL;
  737. }
  738. EXPORT_SYMBOL(ia64_reg_MCA_extension);
  739. EXPORT_SYMBOL(ia64_unreg_MCA_extension);
  740. /*
  741. * ia64_mca_ucmc_handler
  742. *
  743. * This is uncorrectable machine check handler called from OS_MCA
  744. * dispatch code which is in turn called from SAL_CHECK().
  745. * This is the place where the core of OS MCA handling is done.
  746. * Right now the logs are extracted and displayed in a well-defined
  747. * format. This handler code is supposed to be run only on the
  748. * monarch processor. Once the monarch is done with MCA handling
  749. * further MCA logging is enabled by clearing logs.
  750. * Monarch also has the duty of sending wakeup-IPIs to pull the
  751. * slave processors out of rendezvous spinloop.
  752. *
  753. * Inputs : None
  754. * Outputs : None
  755. */
  756. void
  757. ia64_mca_ucmc_handler(void)
  758. {
  759. pal_processor_state_info_t *psp = (pal_processor_state_info_t *)
  760. &ia64_sal_to_os_handoff_state.proc_state_param;
  761. int recover;
  762. /* Get the MCA error record and log it */
  763. ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA);
  764. /* TLB error is only exist in this SAL error record */
  765. recover = (psp->tc && !(psp->cc || psp->bc || psp->rc || psp->uc))
  766. /* other error recovery */
  767. || (ia64_mca_ucmc_extension
  768. && ia64_mca_ucmc_extension(
  769. IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA),
  770. &ia64_sal_to_os_handoff_state,
  771. &ia64_os_to_sal_handoff_state));
  772. if (recover) {
  773. sal_log_record_header_t *rh = IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA);
  774. rh->severity = sal_log_severity_corrected;
  775. ia64_sal_clear_state_info(SAL_INFO_TYPE_MCA);
  776. }
  777. /*
  778. * Wakeup all the processors which are spinning in the rendezvous
  779. * loop.
  780. */
  781. ia64_mca_wakeup_all();
  782. /* Return to SAL */
  783. ia64_return_to_sal_check(recover);
  784. }
  785. static DECLARE_WORK(cmc_disable_work, ia64_mca_cmc_vector_disable_keventd, NULL);
  786. static DECLARE_WORK(cmc_enable_work, ia64_mca_cmc_vector_enable_keventd, NULL);
  787. /*
  788. * ia64_mca_cmc_int_handler
  789. *
  790. * This is corrected machine check interrupt handler.
  791. * Right now the logs are extracted and displayed in a well-defined
  792. * format.
  793. *
  794. * Inputs
  795. * interrupt number
  796. * client data arg ptr
  797. * saved registers ptr
  798. *
  799. * Outputs
  800. * None
  801. */
  802. static irqreturn_t
  803. ia64_mca_cmc_int_handler(int cmc_irq, void *arg, struct pt_regs *ptregs)
  804. {
  805. static unsigned long cmc_history[CMC_HISTORY_LENGTH];
  806. static int index;
  807. static DEFINE_SPINLOCK(cmc_history_lock);
  808. IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
  809. __FUNCTION__, cmc_irq, smp_processor_id());
  810. /* SAL spec states this should run w/ interrupts enabled */
  811. local_irq_enable();
  812. /* Get the CMC error record and log it */
  813. ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC);
  814. spin_lock(&cmc_history_lock);
  815. if (!cmc_polling_enabled) {
  816. int i, count = 1; /* we know 1 happened now */
  817. unsigned long now = jiffies;
  818. for (i = 0; i < CMC_HISTORY_LENGTH; i++) {
  819. if (now - cmc_history[i] <= HZ)
  820. count++;
  821. }
  822. IA64_MCA_DEBUG(KERN_INFO "CMC threshold %d/%d\n", count, CMC_HISTORY_LENGTH);
  823. if (count >= CMC_HISTORY_LENGTH) {
  824. cmc_polling_enabled = 1;
  825. spin_unlock(&cmc_history_lock);
  826. schedule_work(&cmc_disable_work);
  827. /*
  828. * Corrected errors will still be corrected, but
  829. * make sure there's a log somewhere that indicates
  830. * something is generating more than we can handle.
  831. */
  832. printk(KERN_WARNING "WARNING: Switching to polling CMC handler; error records may be lost\n");
  833. mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
  834. /* lock already released, get out now */
  835. return IRQ_HANDLED;
  836. } else {
  837. cmc_history[index++] = now;
  838. if (index == CMC_HISTORY_LENGTH)
  839. index = 0;
  840. }
  841. }
  842. spin_unlock(&cmc_history_lock);
  843. return IRQ_HANDLED;
  844. }
  845. /*
  846. * ia64_mca_cmc_int_caller
  847. *
  848. * Triggered by sw interrupt from CMC polling routine. Calls
  849. * real interrupt handler and either triggers a sw interrupt
  850. * on the next cpu or does cleanup at the end.
  851. *
  852. * Inputs
  853. * interrupt number
  854. * client data arg ptr
  855. * saved registers ptr
  856. * Outputs
  857. * handled
  858. */
  859. static irqreturn_t
  860. ia64_mca_cmc_int_caller(int cmc_irq, void *arg, struct pt_regs *ptregs)
  861. {
  862. static int start_count = -1;
  863. unsigned int cpuid;
  864. cpuid = smp_processor_id();
  865. /* If first cpu, update count */
  866. if (start_count == -1)
  867. start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CMC);
  868. ia64_mca_cmc_int_handler(cmc_irq, arg, ptregs);
  869. for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
  870. if (cpuid < NR_CPUS) {
  871. platform_send_ipi(cpuid, IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
  872. } else {
  873. /* If no log record, switch out of polling mode */
  874. if (start_count == IA64_LOG_COUNT(SAL_INFO_TYPE_CMC)) {
  875. printk(KERN_WARNING "Returning to interrupt driven CMC handler\n");
  876. schedule_work(&cmc_enable_work);
  877. cmc_polling_enabled = 0;
  878. } else {
  879. mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
  880. }
  881. start_count = -1;
  882. }
  883. return IRQ_HANDLED;
  884. }
  885. /*
  886. * ia64_mca_cmc_poll
  887. *
  888. * Poll for Corrected Machine Checks (CMCs)
  889. *
  890. * Inputs : dummy(unused)
  891. * Outputs : None
  892. *
  893. */
  894. static void
  895. ia64_mca_cmc_poll (unsigned long dummy)
  896. {
  897. /* Trigger a CMC interrupt cascade */
  898. platform_send_ipi(first_cpu(cpu_online_map), IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
  899. }
  900. /*
  901. * ia64_mca_cpe_int_caller
  902. *
  903. * Triggered by sw interrupt from CPE polling routine. Calls
  904. * real interrupt handler and either triggers a sw interrupt
  905. * on the next cpu or does cleanup at the end.
  906. *
  907. * Inputs
  908. * interrupt number
  909. * client data arg ptr
  910. * saved registers ptr
  911. * Outputs
  912. * handled
  913. */
  914. #ifdef CONFIG_ACPI
  915. static irqreturn_t
  916. ia64_mca_cpe_int_caller(int cpe_irq, void *arg, struct pt_regs *ptregs)
  917. {
  918. static int start_count = -1;
  919. static int poll_time = MIN_CPE_POLL_INTERVAL;
  920. unsigned int cpuid;
  921. cpuid = smp_processor_id();
  922. /* If first cpu, update count */
  923. if (start_count == -1)
  924. start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CPE);
  925. ia64_mca_cpe_int_handler(cpe_irq, arg, ptregs);
  926. for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
  927. if (cpuid < NR_CPUS) {
  928. platform_send_ipi(cpuid, IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
  929. } else {
  930. /*
  931. * If a log was recorded, increase our polling frequency,
  932. * otherwise, backoff or return to interrupt mode.
  933. */
  934. if (start_count != IA64_LOG_COUNT(SAL_INFO_TYPE_CPE)) {
  935. poll_time = max(MIN_CPE_POLL_INTERVAL, poll_time / 2);
  936. } else if (cpe_vector < 0) {
  937. poll_time = min(MAX_CPE_POLL_INTERVAL, poll_time * 2);
  938. } else {
  939. poll_time = MIN_CPE_POLL_INTERVAL;
  940. printk(KERN_WARNING "Returning to interrupt driven CPE handler\n");
  941. enable_irq(local_vector_to_irq(IA64_CPE_VECTOR));
  942. cpe_poll_enabled = 0;
  943. }
  944. if (cpe_poll_enabled)
  945. mod_timer(&cpe_poll_timer, jiffies + poll_time);
  946. start_count = -1;
  947. }
  948. return IRQ_HANDLED;
  949. }
  950. /*
  951. * ia64_mca_cpe_poll
  952. *
  953. * Poll for Corrected Platform Errors (CPEs), trigger interrupt
  954. * on first cpu, from there it will trickle through all the cpus.
  955. *
  956. * Inputs : dummy(unused)
  957. * Outputs : None
  958. *
  959. */
  960. static void
  961. ia64_mca_cpe_poll (unsigned long dummy)
  962. {
  963. /* Trigger a CPE interrupt cascade */
  964. platform_send_ipi(first_cpu(cpu_online_map), IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
  965. }
  966. #endif /* CONFIG_ACPI */
  967. /*
  968. * C portion of the OS INIT handler
  969. *
  970. * Called from ia64_monarch_init_handler
  971. *
  972. * Inputs: pointer to pt_regs where processor info was saved.
  973. *
  974. * Returns:
  975. * 0 if SAL must warm boot the System
  976. * 1 if SAL must return to interrupted context using PAL_MC_RESUME
  977. *
  978. */
  979. void
  980. ia64_init_handler (struct pt_regs *pt, struct switch_stack *sw)
  981. {
  982. pal_min_state_area_t *ms;
  983. oops_in_progress = 1; /* avoid deadlock in printk, but it makes recovery dodgy */
  984. console_loglevel = 15; /* make sure printks make it to console */
  985. printk(KERN_INFO "Entered OS INIT handler. PSP=%lx\n",
  986. ia64_sal_to_os_handoff_state.proc_state_param);
  987. /*
  988. * Address of minstate area provided by PAL is physical,
  989. * uncacheable (bit 63 set). Convert to Linux virtual
  990. * address in region 6.
  991. */
  992. ms = (pal_min_state_area_t *)(ia64_sal_to_os_handoff_state.pal_min_state | (6ul<<61));
  993. init_handler_platform(ms, pt, sw); /* call platform specific routines */
  994. }
  995. static int __init
  996. ia64_mca_disable_cpe_polling(char *str)
  997. {
  998. cpe_poll_enabled = 0;
  999. return 1;
  1000. }
  1001. __setup("disable_cpe_poll", ia64_mca_disable_cpe_polling);
  1002. static struct irqaction cmci_irqaction = {
  1003. .handler = ia64_mca_cmc_int_handler,
  1004. .flags = SA_INTERRUPT,
  1005. .name = "cmc_hndlr"
  1006. };
  1007. static struct irqaction cmcp_irqaction = {
  1008. .handler = ia64_mca_cmc_int_caller,
  1009. .flags = SA_INTERRUPT,
  1010. .name = "cmc_poll"
  1011. };
  1012. static struct irqaction mca_rdzv_irqaction = {
  1013. .handler = ia64_mca_rendez_int_handler,
  1014. .flags = SA_INTERRUPT,
  1015. .name = "mca_rdzv"
  1016. };
  1017. static struct irqaction mca_wkup_irqaction = {
  1018. .handler = ia64_mca_wakeup_int_handler,
  1019. .flags = SA_INTERRUPT,
  1020. .name = "mca_wkup"
  1021. };
  1022. #ifdef CONFIG_ACPI
  1023. static struct irqaction mca_cpe_irqaction = {
  1024. .handler = ia64_mca_cpe_int_handler,
  1025. .flags = SA_INTERRUPT,
  1026. .name = "cpe_hndlr"
  1027. };
  1028. static struct irqaction mca_cpep_irqaction = {
  1029. .handler = ia64_mca_cpe_int_caller,
  1030. .flags = SA_INTERRUPT,
  1031. .name = "cpe_poll"
  1032. };
  1033. #endif /* CONFIG_ACPI */
  1034. /* Do per-CPU MCA-related initialization. */
  1035. void __devinit
  1036. ia64_mca_cpu_init(void *cpu_data)
  1037. {
  1038. void *pal_vaddr;
  1039. if (smp_processor_id() == 0) {
  1040. void *mca_data;
  1041. int cpu;
  1042. mca_data = alloc_bootmem(sizeof(struct ia64_mca_cpu)
  1043. * NR_CPUS);
  1044. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  1045. __per_cpu_mca[cpu] = __pa(mca_data);
  1046. mca_data += sizeof(struct ia64_mca_cpu);
  1047. }
  1048. }
  1049. /*
  1050. * The MCA info structure was allocated earlier and its
  1051. * physical address saved in __per_cpu_mca[cpu]. Copy that
  1052. * address * to ia64_mca_data so we can access it as a per-CPU
  1053. * variable.
  1054. */
  1055. __get_cpu_var(ia64_mca_data) = __per_cpu_mca[smp_processor_id()];
  1056. /*
  1057. * Stash away a copy of the PTE needed to map the per-CPU page.
  1058. * We may need it during MCA recovery.
  1059. */
  1060. __get_cpu_var(ia64_mca_per_cpu_pte) =
  1061. pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL));
  1062. /*
  1063. * Also, stash away a copy of the PAL address and the PTE
  1064. * needed to map it.
  1065. */
  1066. pal_vaddr = efi_get_pal_addr();
  1067. if (!pal_vaddr)
  1068. return;
  1069. __get_cpu_var(ia64_mca_pal_base) =
  1070. GRANULEROUNDDOWN((unsigned long) pal_vaddr);
  1071. __get_cpu_var(ia64_mca_pal_pte) = pte_val(mk_pte_phys(__pa(pal_vaddr),
  1072. PAGE_KERNEL));
  1073. }
  1074. /*
  1075. * ia64_mca_init
  1076. *
  1077. * Do all the system level mca specific initialization.
  1078. *
  1079. * 1. Register spinloop and wakeup request interrupt vectors
  1080. *
  1081. * 2. Register OS_MCA handler entry point
  1082. *
  1083. * 3. Register OS_INIT handler entry point
  1084. *
  1085. * 4. Initialize MCA/CMC/INIT related log buffers maintained by the OS.
  1086. *
  1087. * Note that this initialization is done very early before some kernel
  1088. * services are available.
  1089. *
  1090. * Inputs : None
  1091. *
  1092. * Outputs : None
  1093. */
  1094. void __init
  1095. ia64_mca_init(void)
  1096. {
  1097. ia64_fptr_t *mon_init_ptr = (ia64_fptr_t *)ia64_monarch_init_handler;
  1098. ia64_fptr_t *slave_init_ptr = (ia64_fptr_t *)ia64_slave_init_handler;
  1099. ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch;
  1100. int i;
  1101. s64 rc;
  1102. struct ia64_sal_retval isrv;
  1103. u64 timeout = IA64_MCA_RENDEZ_TIMEOUT; /* platform specific */
  1104. IA64_MCA_DEBUG("%s: begin\n", __FUNCTION__);
  1105. /* Clear the Rendez checkin flag for all cpus */
  1106. for(i = 0 ; i < NR_CPUS; i++)
  1107. ia64_mc_info.imi_rendez_checkin[i] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
  1108. /*
  1109. * Register the rendezvous spinloop and wakeup mechanism with SAL
  1110. */
  1111. /* Register the rendezvous interrupt vector with SAL */
  1112. while (1) {
  1113. isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_INT,
  1114. SAL_MC_PARAM_MECHANISM_INT,
  1115. IA64_MCA_RENDEZ_VECTOR,
  1116. timeout,
  1117. SAL_MC_PARAM_RZ_ALWAYS);
  1118. rc = isrv.status;
  1119. if (rc == 0)
  1120. break;
  1121. if (rc == -2) {
  1122. printk(KERN_INFO "Increasing MCA rendezvous timeout from "
  1123. "%ld to %ld milliseconds\n", timeout, isrv.v0);
  1124. timeout = isrv.v0;
  1125. continue;
  1126. }
  1127. printk(KERN_ERR "Failed to register rendezvous interrupt "
  1128. "with SAL (status %ld)\n", rc);
  1129. return;
  1130. }
  1131. /* Register the wakeup interrupt vector with SAL */
  1132. isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_WAKEUP,
  1133. SAL_MC_PARAM_MECHANISM_INT,
  1134. IA64_MCA_WAKEUP_VECTOR,
  1135. 0, 0);
  1136. rc = isrv.status;
  1137. if (rc) {
  1138. printk(KERN_ERR "Failed to register wakeup interrupt with SAL "
  1139. "(status %ld)\n", rc);
  1140. return;
  1141. }
  1142. IA64_MCA_DEBUG("%s: registered MCA rendezvous spinloop and wakeup mech.\n", __FUNCTION__);
  1143. ia64_mc_info.imi_mca_handler = ia64_tpa(mca_hldlr_ptr->fp);
  1144. /*
  1145. * XXX - disable SAL checksum by setting size to 0; should be
  1146. * ia64_tpa(ia64_os_mca_dispatch_end) - ia64_tpa(ia64_os_mca_dispatch);
  1147. */
  1148. ia64_mc_info.imi_mca_handler_size = 0;
  1149. /* Register the os mca handler with SAL */
  1150. if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_MCA,
  1151. ia64_mc_info.imi_mca_handler,
  1152. ia64_tpa(mca_hldlr_ptr->gp),
  1153. ia64_mc_info.imi_mca_handler_size,
  1154. 0, 0, 0)))
  1155. {
  1156. printk(KERN_ERR "Failed to register OS MCA handler with SAL "
  1157. "(status %ld)\n", rc);
  1158. return;
  1159. }
  1160. IA64_MCA_DEBUG("%s: registered OS MCA handler with SAL at 0x%lx, gp = 0x%lx\n", __FUNCTION__,
  1161. ia64_mc_info.imi_mca_handler, ia64_tpa(mca_hldlr_ptr->gp));
  1162. /*
  1163. * XXX - disable SAL checksum by setting size to 0, should be
  1164. * size of the actual init handler in mca_asm.S.
  1165. */
  1166. ia64_mc_info.imi_monarch_init_handler = ia64_tpa(mon_init_ptr->fp);
  1167. ia64_mc_info.imi_monarch_init_handler_size = 0;
  1168. ia64_mc_info.imi_slave_init_handler = ia64_tpa(slave_init_ptr->fp);
  1169. ia64_mc_info.imi_slave_init_handler_size = 0;
  1170. IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __FUNCTION__,
  1171. ia64_mc_info.imi_monarch_init_handler);
  1172. /* Register the os init handler with SAL */
  1173. if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_INIT,
  1174. ia64_mc_info.imi_monarch_init_handler,
  1175. ia64_tpa(ia64_getreg(_IA64_REG_GP)),
  1176. ia64_mc_info.imi_monarch_init_handler_size,
  1177. ia64_mc_info.imi_slave_init_handler,
  1178. ia64_tpa(ia64_getreg(_IA64_REG_GP)),
  1179. ia64_mc_info.imi_slave_init_handler_size)))
  1180. {
  1181. printk(KERN_ERR "Failed to register m/s INIT handlers with SAL "
  1182. "(status %ld)\n", rc);
  1183. return;
  1184. }
  1185. IA64_MCA_DEBUG("%s: registered OS INIT handler with SAL\n", __FUNCTION__);
  1186. /*
  1187. * Configure the CMCI/P vector and handler. Interrupts for CMC are
  1188. * per-processor, so AP CMC interrupts are setup in smp_callin() (smpboot.c).
  1189. */
  1190. register_percpu_irq(IA64_CMC_VECTOR, &cmci_irqaction);
  1191. register_percpu_irq(IA64_CMCP_VECTOR, &cmcp_irqaction);
  1192. ia64_mca_cmc_vector_setup(); /* Setup vector on BSP */
  1193. /* Setup the MCA rendezvous interrupt vector */
  1194. register_percpu_irq(IA64_MCA_RENDEZ_VECTOR, &mca_rdzv_irqaction);
  1195. /* Setup the MCA wakeup interrupt vector */
  1196. register_percpu_irq(IA64_MCA_WAKEUP_VECTOR, &mca_wkup_irqaction);
  1197. #ifdef CONFIG_ACPI
  1198. /* Setup the CPEI/P handler */
  1199. register_percpu_irq(IA64_CPEP_VECTOR, &mca_cpep_irqaction);
  1200. #endif
  1201. /* Initialize the areas set aside by the OS to buffer the
  1202. * platform/processor error states for MCA/INIT/CMC
  1203. * handling.
  1204. */
  1205. ia64_log_init(SAL_INFO_TYPE_MCA);
  1206. ia64_log_init(SAL_INFO_TYPE_INIT);
  1207. ia64_log_init(SAL_INFO_TYPE_CMC);
  1208. ia64_log_init(SAL_INFO_TYPE_CPE);
  1209. mca_init = 1;
  1210. printk(KERN_INFO "MCA related initialization done\n");
  1211. }
  1212. /*
  1213. * ia64_mca_late_init
  1214. *
  1215. * Opportunity to setup things that require initialization later
  1216. * than ia64_mca_init. Setup a timer to poll for CPEs if the
  1217. * platform doesn't support an interrupt driven mechanism.
  1218. *
  1219. * Inputs : None
  1220. * Outputs : Status
  1221. */
  1222. static int __init
  1223. ia64_mca_late_init(void)
  1224. {
  1225. if (!mca_init)
  1226. return 0;
  1227. /* Setup the CMCI/P vector and handler */
  1228. init_timer(&cmc_poll_timer);
  1229. cmc_poll_timer.function = ia64_mca_cmc_poll;
  1230. /* Unmask/enable the vector */
  1231. cmc_polling_enabled = 0;
  1232. schedule_work(&cmc_enable_work);
  1233. IA64_MCA_DEBUG("%s: CMCI/P setup and enabled.\n", __FUNCTION__);
  1234. #ifdef CONFIG_ACPI
  1235. /* Setup the CPEI/P vector and handler */
  1236. cpe_vector = acpi_request_vector(ACPI_INTERRUPT_CPEI);
  1237. init_timer(&cpe_poll_timer);
  1238. cpe_poll_timer.function = ia64_mca_cpe_poll;
  1239. {
  1240. irq_desc_t *desc;
  1241. unsigned int irq;
  1242. if (cpe_vector >= 0) {
  1243. /* If platform supports CPEI, enable the irq. */
  1244. cpe_poll_enabled = 0;
  1245. for (irq = 0; irq < NR_IRQS; ++irq)
  1246. if (irq_to_vector(irq) == cpe_vector) {
  1247. desc = irq_descp(irq);
  1248. desc->status |= IRQ_PER_CPU;
  1249. setup_irq(irq, &mca_cpe_irqaction);
  1250. }
  1251. ia64_mca_register_cpev(cpe_vector);
  1252. IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n", __FUNCTION__);
  1253. } else {
  1254. /* If platform doesn't support CPEI, get the timer going. */
  1255. if (cpe_poll_enabled) {
  1256. ia64_mca_cpe_poll(0UL);
  1257. IA64_MCA_DEBUG("%s: CPEP setup and enabled.\n", __FUNCTION__);
  1258. }
  1259. }
  1260. }
  1261. #endif
  1262. return 0;
  1263. }
  1264. device_initcall(ia64_mca_late_init);