mca.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470
  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. #ifdef CONFIG_SMP
  434. /* read_trylock() would be handy... */
  435. if (!tasklist_lock.write_lock)
  436. read_lock(&tasklist_lock);
  437. #endif
  438. {
  439. struct task_struct *g, *t;
  440. do_each_thread (g, t) {
  441. if (t == current)
  442. continue;
  443. printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm);
  444. show_stack(t, NULL);
  445. } while_each_thread (g, t);
  446. }
  447. #ifdef CONFIG_SMP
  448. if (!tasklist_lock.write_lock)
  449. read_unlock(&tasklist_lock);
  450. #endif
  451. printk("\nINIT dump complete. Please reboot now.\n");
  452. while (1); /* hang city if no debugger */
  453. }
  454. #ifdef CONFIG_ACPI
  455. /*
  456. * ia64_mca_register_cpev
  457. *
  458. * Register the corrected platform error vector with SAL.
  459. *
  460. * Inputs
  461. * cpev Corrected Platform Error Vector number
  462. *
  463. * Outputs
  464. * None
  465. */
  466. static void
  467. ia64_mca_register_cpev (int cpev)
  468. {
  469. /* Register the CPE interrupt vector with SAL */
  470. struct ia64_sal_retval isrv;
  471. isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_CPE_INT, SAL_MC_PARAM_MECHANISM_INT, cpev, 0, 0);
  472. if (isrv.status) {
  473. printk(KERN_ERR "Failed to register Corrected Platform "
  474. "Error interrupt vector with SAL (status %ld)\n", isrv.status);
  475. return;
  476. }
  477. IA64_MCA_DEBUG("%s: corrected platform error "
  478. "vector %#x registered\n", __FUNCTION__, cpev);
  479. }
  480. #endif /* CONFIG_ACPI */
  481. #endif /* PLATFORM_MCA_HANDLERS */
  482. /*
  483. * ia64_mca_cmc_vector_setup
  484. *
  485. * Setup the corrected machine check vector register in the processor.
  486. * (The interrupt is masked on boot. ia64_mca_late_init unmask this.)
  487. * This function is invoked on a per-processor basis.
  488. *
  489. * Inputs
  490. * None
  491. *
  492. * Outputs
  493. * None
  494. */
  495. void
  496. ia64_mca_cmc_vector_setup (void)
  497. {
  498. cmcv_reg_t cmcv;
  499. cmcv.cmcv_regval = 0;
  500. cmcv.cmcv_mask = 1; /* Mask/disable interrupt at first */
  501. cmcv.cmcv_vector = IA64_CMC_VECTOR;
  502. ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
  503. IA64_MCA_DEBUG("%s: CPU %d corrected "
  504. "machine check vector %#x registered.\n",
  505. __FUNCTION__, smp_processor_id(), IA64_CMC_VECTOR);
  506. IA64_MCA_DEBUG("%s: CPU %d CMCV = %#016lx\n",
  507. __FUNCTION__, smp_processor_id(), ia64_getreg(_IA64_REG_CR_CMCV));
  508. }
  509. /*
  510. * ia64_mca_cmc_vector_disable
  511. *
  512. * Mask the corrected machine check vector register in the processor.
  513. * This function is invoked on a per-processor basis.
  514. *
  515. * Inputs
  516. * dummy(unused)
  517. *
  518. * Outputs
  519. * None
  520. */
  521. static void
  522. ia64_mca_cmc_vector_disable (void *dummy)
  523. {
  524. cmcv_reg_t cmcv;
  525. cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV);
  526. cmcv.cmcv_mask = 1; /* Mask/disable interrupt */
  527. ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
  528. IA64_MCA_DEBUG("%s: CPU %d corrected "
  529. "machine check vector %#x disabled.\n",
  530. __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector);
  531. }
  532. /*
  533. * ia64_mca_cmc_vector_enable
  534. *
  535. * Unmask the corrected machine check vector register in the processor.
  536. * This function is invoked on a per-processor basis.
  537. *
  538. * Inputs
  539. * dummy(unused)
  540. *
  541. * Outputs
  542. * None
  543. */
  544. static void
  545. ia64_mca_cmc_vector_enable (void *dummy)
  546. {
  547. cmcv_reg_t cmcv;
  548. cmcv.cmcv_regval = ia64_getreg(_IA64_REG_CR_CMCV);
  549. cmcv.cmcv_mask = 0; /* Unmask/enable interrupt */
  550. ia64_setreg(_IA64_REG_CR_CMCV, cmcv.cmcv_regval);
  551. IA64_MCA_DEBUG("%s: CPU %d corrected "
  552. "machine check vector %#x enabled.\n",
  553. __FUNCTION__, smp_processor_id(), cmcv.cmcv_vector);
  554. }
  555. /*
  556. * ia64_mca_cmc_vector_disable_keventd
  557. *
  558. * Called via keventd (smp_call_function() is not safe in interrupt context) to
  559. * disable the cmc interrupt vector.
  560. */
  561. static void
  562. ia64_mca_cmc_vector_disable_keventd(void *unused)
  563. {
  564. on_each_cpu(ia64_mca_cmc_vector_disable, NULL, 1, 0);
  565. }
  566. /*
  567. * ia64_mca_cmc_vector_enable_keventd
  568. *
  569. * Called via keventd (smp_call_function() is not safe in interrupt context) to
  570. * enable the cmc interrupt vector.
  571. */
  572. static void
  573. ia64_mca_cmc_vector_enable_keventd(void *unused)
  574. {
  575. on_each_cpu(ia64_mca_cmc_vector_enable, NULL, 1, 0);
  576. }
  577. /*
  578. * ia64_mca_wakeup_ipi_wait
  579. *
  580. * Wait for the inter-cpu interrupt to be sent by the
  581. * monarch processor once it is done with handling the
  582. * MCA.
  583. *
  584. * Inputs : None
  585. * Outputs : None
  586. */
  587. static void
  588. ia64_mca_wakeup_ipi_wait(void)
  589. {
  590. int irr_num = (IA64_MCA_WAKEUP_VECTOR >> 6);
  591. int irr_bit = (IA64_MCA_WAKEUP_VECTOR & 0x3f);
  592. u64 irr = 0;
  593. do {
  594. switch(irr_num) {
  595. case 0:
  596. irr = ia64_getreg(_IA64_REG_CR_IRR0);
  597. break;
  598. case 1:
  599. irr = ia64_getreg(_IA64_REG_CR_IRR1);
  600. break;
  601. case 2:
  602. irr = ia64_getreg(_IA64_REG_CR_IRR2);
  603. break;
  604. case 3:
  605. irr = ia64_getreg(_IA64_REG_CR_IRR3);
  606. break;
  607. }
  608. cpu_relax();
  609. } while (!(irr & (1UL << irr_bit))) ;
  610. }
  611. /*
  612. * ia64_mca_wakeup
  613. *
  614. * Send an inter-cpu interrupt to wake-up a particular cpu
  615. * and mark that cpu to be out of rendez.
  616. *
  617. * Inputs : cpuid
  618. * Outputs : None
  619. */
  620. static void
  621. ia64_mca_wakeup(int cpu)
  622. {
  623. platform_send_ipi(cpu, IA64_MCA_WAKEUP_VECTOR, IA64_IPI_DM_INT, 0);
  624. ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
  625. }
  626. /*
  627. * ia64_mca_wakeup_all
  628. *
  629. * Wakeup all the cpus which have rendez'ed previously.
  630. *
  631. * Inputs : None
  632. * Outputs : None
  633. */
  634. static void
  635. ia64_mca_wakeup_all(void)
  636. {
  637. int cpu;
  638. /* Clear the Rendez checkin flag for all cpus */
  639. for(cpu = 0; cpu < NR_CPUS; cpu++) {
  640. if (!cpu_online(cpu))
  641. continue;
  642. if (ia64_mc_info.imi_rendez_checkin[cpu] == IA64_MCA_RENDEZ_CHECKIN_DONE)
  643. ia64_mca_wakeup(cpu);
  644. }
  645. }
  646. /*
  647. * ia64_mca_rendez_interrupt_handler
  648. *
  649. * This is handler used to put slave processors into spinloop
  650. * while the monarch processor does the mca handling and later
  651. * wake each slave up once the monarch is done.
  652. *
  653. * Inputs : None
  654. * Outputs : None
  655. */
  656. static irqreturn_t
  657. ia64_mca_rendez_int_handler(int rendez_irq, void *arg, struct pt_regs *ptregs)
  658. {
  659. unsigned long flags;
  660. int cpu = smp_processor_id();
  661. /* Mask all interrupts */
  662. local_irq_save(flags);
  663. ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_DONE;
  664. /* Register with the SAL monarch that the slave has
  665. * reached SAL
  666. */
  667. ia64_sal_mc_rendez();
  668. /* Wait for the wakeup IPI from the monarch
  669. * This waiting is done by polling on the wakeup-interrupt
  670. * vector bit in the processor's IRRs
  671. */
  672. ia64_mca_wakeup_ipi_wait();
  673. /* Enable all interrupts */
  674. local_irq_restore(flags);
  675. return IRQ_HANDLED;
  676. }
  677. /*
  678. * ia64_mca_wakeup_int_handler
  679. *
  680. * The interrupt handler for processing the inter-cpu interrupt to the
  681. * slave cpu which was spinning in the rendez loop.
  682. * Since this spinning is done by turning off the interrupts and
  683. * polling on the wakeup-interrupt bit in the IRR, there is
  684. * nothing useful to be done in the handler.
  685. *
  686. * Inputs : wakeup_irq (Wakeup-interrupt bit)
  687. * arg (Interrupt handler specific argument)
  688. * ptregs (Exception frame at the time of the interrupt)
  689. * Outputs : None
  690. *
  691. */
  692. static irqreturn_t
  693. ia64_mca_wakeup_int_handler(int wakeup_irq, void *arg, struct pt_regs *ptregs)
  694. {
  695. return IRQ_HANDLED;
  696. }
  697. /*
  698. * ia64_return_to_sal_check
  699. *
  700. * This is function called before going back from the OS_MCA handler
  701. * to the OS_MCA dispatch code which finally takes the control back
  702. * to the SAL.
  703. * The main purpose of this routine is to setup the OS_MCA to SAL
  704. * return state which can be used by the OS_MCA dispatch code
  705. * just before going back to SAL.
  706. *
  707. * Inputs : None
  708. * Outputs : None
  709. */
  710. static void
  711. ia64_return_to_sal_check(int recover)
  712. {
  713. /* Copy over some relevant stuff from the sal_to_os_mca_handoff
  714. * so that it can be used at the time of os_mca_to_sal_handoff
  715. */
  716. ia64_os_to_sal_handoff_state.imots_sal_gp =
  717. ia64_sal_to_os_handoff_state.imsto_sal_gp;
  718. ia64_os_to_sal_handoff_state.imots_sal_check_ra =
  719. ia64_sal_to_os_handoff_state.imsto_sal_check_ra;
  720. if (recover)
  721. ia64_os_to_sal_handoff_state.imots_os_status = IA64_MCA_CORRECTED;
  722. else
  723. ia64_os_to_sal_handoff_state.imots_os_status = IA64_MCA_COLD_BOOT;
  724. /* Default = tell SAL to return to same context */
  725. ia64_os_to_sal_handoff_state.imots_context = IA64_MCA_SAME_CONTEXT;
  726. ia64_os_to_sal_handoff_state.imots_new_min_state =
  727. (u64 *)ia64_sal_to_os_handoff_state.pal_min_state;
  728. }
  729. /* Function pointer for extra MCA recovery */
  730. int (*ia64_mca_ucmc_extension)
  731. (void*,ia64_mca_sal_to_os_state_t*,ia64_mca_os_to_sal_state_t*)
  732. = NULL;
  733. int
  734. ia64_reg_MCA_extension(void *fn)
  735. {
  736. if (ia64_mca_ucmc_extension)
  737. return 1;
  738. ia64_mca_ucmc_extension = fn;
  739. return 0;
  740. }
  741. void
  742. ia64_unreg_MCA_extension(void)
  743. {
  744. if (ia64_mca_ucmc_extension)
  745. ia64_mca_ucmc_extension = NULL;
  746. }
  747. EXPORT_SYMBOL(ia64_reg_MCA_extension);
  748. EXPORT_SYMBOL(ia64_unreg_MCA_extension);
  749. /*
  750. * ia64_mca_ucmc_handler
  751. *
  752. * This is uncorrectable machine check handler called from OS_MCA
  753. * dispatch code which is in turn called from SAL_CHECK().
  754. * This is the place where the core of OS MCA handling is done.
  755. * Right now the logs are extracted and displayed in a well-defined
  756. * format. This handler code is supposed to be run only on the
  757. * monarch processor. Once the monarch is done with MCA handling
  758. * further MCA logging is enabled by clearing logs.
  759. * Monarch also has the duty of sending wakeup-IPIs to pull the
  760. * slave processors out of rendezvous spinloop.
  761. *
  762. * Inputs : None
  763. * Outputs : None
  764. */
  765. void
  766. ia64_mca_ucmc_handler(void)
  767. {
  768. pal_processor_state_info_t *psp = (pal_processor_state_info_t *)
  769. &ia64_sal_to_os_handoff_state.proc_state_param;
  770. int recover;
  771. /* Get the MCA error record and log it */
  772. ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA);
  773. /* TLB error is only exist in this SAL error record */
  774. recover = (psp->tc && !(psp->cc || psp->bc || psp->rc || psp->uc))
  775. /* other error recovery */
  776. || (ia64_mca_ucmc_extension
  777. && ia64_mca_ucmc_extension(
  778. IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA),
  779. &ia64_sal_to_os_handoff_state,
  780. &ia64_os_to_sal_handoff_state));
  781. if (recover) {
  782. sal_log_record_header_t *rh = IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_MCA);
  783. rh->severity = sal_log_severity_corrected;
  784. ia64_sal_clear_state_info(SAL_INFO_TYPE_MCA);
  785. }
  786. /*
  787. * Wakeup all the processors which are spinning in the rendezvous
  788. * loop.
  789. */
  790. ia64_mca_wakeup_all();
  791. /* Return to SAL */
  792. ia64_return_to_sal_check(recover);
  793. }
  794. static DECLARE_WORK(cmc_disable_work, ia64_mca_cmc_vector_disable_keventd, NULL);
  795. static DECLARE_WORK(cmc_enable_work, ia64_mca_cmc_vector_enable_keventd, NULL);
  796. /*
  797. * ia64_mca_cmc_int_handler
  798. *
  799. * This is corrected machine check interrupt handler.
  800. * Right now the logs are extracted and displayed in a well-defined
  801. * format.
  802. *
  803. * Inputs
  804. * interrupt number
  805. * client data arg ptr
  806. * saved registers ptr
  807. *
  808. * Outputs
  809. * None
  810. */
  811. static irqreturn_t
  812. ia64_mca_cmc_int_handler(int cmc_irq, void *arg, struct pt_regs *ptregs)
  813. {
  814. static unsigned long cmc_history[CMC_HISTORY_LENGTH];
  815. static int index;
  816. static DEFINE_SPINLOCK(cmc_history_lock);
  817. IA64_MCA_DEBUG("%s: received interrupt vector = %#x on CPU %d\n",
  818. __FUNCTION__, cmc_irq, smp_processor_id());
  819. /* SAL spec states this should run w/ interrupts enabled */
  820. local_irq_enable();
  821. /* Get the CMC error record and log it */
  822. ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC);
  823. spin_lock(&cmc_history_lock);
  824. if (!cmc_polling_enabled) {
  825. int i, count = 1; /* we know 1 happened now */
  826. unsigned long now = jiffies;
  827. for (i = 0; i < CMC_HISTORY_LENGTH; i++) {
  828. if (now - cmc_history[i] <= HZ)
  829. count++;
  830. }
  831. IA64_MCA_DEBUG(KERN_INFO "CMC threshold %d/%d\n", count, CMC_HISTORY_LENGTH);
  832. if (count >= CMC_HISTORY_LENGTH) {
  833. cmc_polling_enabled = 1;
  834. spin_unlock(&cmc_history_lock);
  835. schedule_work(&cmc_disable_work);
  836. /*
  837. * Corrected errors will still be corrected, but
  838. * make sure there's a log somewhere that indicates
  839. * something is generating more than we can handle.
  840. */
  841. printk(KERN_WARNING "WARNING: Switching to polling CMC handler; error records may be lost\n");
  842. mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
  843. /* lock already released, get out now */
  844. return IRQ_HANDLED;
  845. } else {
  846. cmc_history[index++] = now;
  847. if (index == CMC_HISTORY_LENGTH)
  848. index = 0;
  849. }
  850. }
  851. spin_unlock(&cmc_history_lock);
  852. return IRQ_HANDLED;
  853. }
  854. /*
  855. * ia64_mca_cmc_int_caller
  856. *
  857. * Triggered by sw interrupt from CMC polling routine. Calls
  858. * real interrupt handler and either triggers a sw interrupt
  859. * on the next cpu or does cleanup at the end.
  860. *
  861. * Inputs
  862. * interrupt number
  863. * client data arg ptr
  864. * saved registers ptr
  865. * Outputs
  866. * handled
  867. */
  868. static irqreturn_t
  869. ia64_mca_cmc_int_caller(int cmc_irq, void *arg, struct pt_regs *ptregs)
  870. {
  871. static int start_count = -1;
  872. unsigned int cpuid;
  873. cpuid = smp_processor_id();
  874. /* If first cpu, update count */
  875. if (start_count == -1)
  876. start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CMC);
  877. ia64_mca_cmc_int_handler(cmc_irq, arg, ptregs);
  878. for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
  879. if (cpuid < NR_CPUS) {
  880. platform_send_ipi(cpuid, IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
  881. } else {
  882. /* If no log record, switch out of polling mode */
  883. if (start_count == IA64_LOG_COUNT(SAL_INFO_TYPE_CMC)) {
  884. printk(KERN_WARNING "Returning to interrupt driven CMC handler\n");
  885. schedule_work(&cmc_enable_work);
  886. cmc_polling_enabled = 0;
  887. } else {
  888. mod_timer(&cmc_poll_timer, jiffies + CMC_POLL_INTERVAL);
  889. }
  890. start_count = -1;
  891. }
  892. return IRQ_HANDLED;
  893. }
  894. /*
  895. * ia64_mca_cmc_poll
  896. *
  897. * Poll for Corrected Machine Checks (CMCs)
  898. *
  899. * Inputs : dummy(unused)
  900. * Outputs : None
  901. *
  902. */
  903. static void
  904. ia64_mca_cmc_poll (unsigned long dummy)
  905. {
  906. /* Trigger a CMC interrupt cascade */
  907. platform_send_ipi(first_cpu(cpu_online_map), IA64_CMCP_VECTOR, IA64_IPI_DM_INT, 0);
  908. }
  909. /*
  910. * ia64_mca_cpe_int_caller
  911. *
  912. * Triggered by sw interrupt from CPE polling routine. Calls
  913. * real interrupt handler and either triggers a sw interrupt
  914. * on the next cpu or does cleanup at the end.
  915. *
  916. * Inputs
  917. * interrupt number
  918. * client data arg ptr
  919. * saved registers ptr
  920. * Outputs
  921. * handled
  922. */
  923. #ifdef CONFIG_ACPI
  924. static irqreturn_t
  925. ia64_mca_cpe_int_caller(int cpe_irq, void *arg, struct pt_regs *ptregs)
  926. {
  927. static int start_count = -1;
  928. static int poll_time = MIN_CPE_POLL_INTERVAL;
  929. unsigned int cpuid;
  930. cpuid = smp_processor_id();
  931. /* If first cpu, update count */
  932. if (start_count == -1)
  933. start_count = IA64_LOG_COUNT(SAL_INFO_TYPE_CPE);
  934. ia64_mca_cpe_int_handler(cpe_irq, arg, ptregs);
  935. for (++cpuid ; cpuid < NR_CPUS && !cpu_online(cpuid) ; cpuid++);
  936. if (cpuid < NR_CPUS) {
  937. platform_send_ipi(cpuid, IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
  938. } else {
  939. /*
  940. * If a log was recorded, increase our polling frequency,
  941. * otherwise, backoff or return to interrupt mode.
  942. */
  943. if (start_count != IA64_LOG_COUNT(SAL_INFO_TYPE_CPE)) {
  944. poll_time = max(MIN_CPE_POLL_INTERVAL, poll_time / 2);
  945. } else if (cpe_vector < 0) {
  946. poll_time = min(MAX_CPE_POLL_INTERVAL, poll_time * 2);
  947. } else {
  948. poll_time = MIN_CPE_POLL_INTERVAL;
  949. printk(KERN_WARNING "Returning to interrupt driven CPE handler\n");
  950. enable_irq(local_vector_to_irq(IA64_CPE_VECTOR));
  951. cpe_poll_enabled = 0;
  952. }
  953. if (cpe_poll_enabled)
  954. mod_timer(&cpe_poll_timer, jiffies + poll_time);
  955. start_count = -1;
  956. }
  957. return IRQ_HANDLED;
  958. }
  959. /*
  960. * ia64_mca_cpe_poll
  961. *
  962. * Poll for Corrected Platform Errors (CPEs), trigger interrupt
  963. * on first cpu, from there it will trickle through all the cpus.
  964. *
  965. * Inputs : dummy(unused)
  966. * Outputs : None
  967. *
  968. */
  969. static void
  970. ia64_mca_cpe_poll (unsigned long dummy)
  971. {
  972. /* Trigger a CPE interrupt cascade */
  973. platform_send_ipi(first_cpu(cpu_online_map), IA64_CPEP_VECTOR, IA64_IPI_DM_INT, 0);
  974. }
  975. #endif /* CONFIG_ACPI */
  976. /*
  977. * C portion of the OS INIT handler
  978. *
  979. * Called from ia64_monarch_init_handler
  980. *
  981. * Inputs: pointer to pt_regs where processor info was saved.
  982. *
  983. * Returns:
  984. * 0 if SAL must warm boot the System
  985. * 1 if SAL must return to interrupted context using PAL_MC_RESUME
  986. *
  987. */
  988. void
  989. ia64_init_handler (struct pt_regs *pt, struct switch_stack *sw)
  990. {
  991. pal_min_state_area_t *ms;
  992. oops_in_progress = 1; /* avoid deadlock in printk, but it makes recovery dodgy */
  993. console_loglevel = 15; /* make sure printks make it to console */
  994. printk(KERN_INFO "Entered OS INIT handler. PSP=%lx\n",
  995. ia64_sal_to_os_handoff_state.proc_state_param);
  996. /*
  997. * Address of minstate area provided by PAL is physical,
  998. * uncacheable (bit 63 set). Convert to Linux virtual
  999. * address in region 6.
  1000. */
  1001. ms = (pal_min_state_area_t *)(ia64_sal_to_os_handoff_state.pal_min_state | (6ul<<61));
  1002. init_handler_platform(ms, pt, sw); /* call platform specific routines */
  1003. }
  1004. static int __init
  1005. ia64_mca_disable_cpe_polling(char *str)
  1006. {
  1007. cpe_poll_enabled = 0;
  1008. return 1;
  1009. }
  1010. __setup("disable_cpe_poll", ia64_mca_disable_cpe_polling);
  1011. static struct irqaction cmci_irqaction = {
  1012. .handler = ia64_mca_cmc_int_handler,
  1013. .flags = SA_INTERRUPT,
  1014. .name = "cmc_hndlr"
  1015. };
  1016. static struct irqaction cmcp_irqaction = {
  1017. .handler = ia64_mca_cmc_int_caller,
  1018. .flags = SA_INTERRUPT,
  1019. .name = "cmc_poll"
  1020. };
  1021. static struct irqaction mca_rdzv_irqaction = {
  1022. .handler = ia64_mca_rendez_int_handler,
  1023. .flags = SA_INTERRUPT,
  1024. .name = "mca_rdzv"
  1025. };
  1026. static struct irqaction mca_wkup_irqaction = {
  1027. .handler = ia64_mca_wakeup_int_handler,
  1028. .flags = SA_INTERRUPT,
  1029. .name = "mca_wkup"
  1030. };
  1031. #ifdef CONFIG_ACPI
  1032. static struct irqaction mca_cpe_irqaction = {
  1033. .handler = ia64_mca_cpe_int_handler,
  1034. .flags = SA_INTERRUPT,
  1035. .name = "cpe_hndlr"
  1036. };
  1037. static struct irqaction mca_cpep_irqaction = {
  1038. .handler = ia64_mca_cpe_int_caller,
  1039. .flags = SA_INTERRUPT,
  1040. .name = "cpe_poll"
  1041. };
  1042. #endif /* CONFIG_ACPI */
  1043. /* Do per-CPU MCA-related initialization. */
  1044. void __devinit
  1045. ia64_mca_cpu_init(void *cpu_data)
  1046. {
  1047. void *pal_vaddr;
  1048. if (smp_processor_id() == 0) {
  1049. void *mca_data;
  1050. int cpu;
  1051. mca_data = alloc_bootmem(sizeof(struct ia64_mca_cpu)
  1052. * NR_CPUS);
  1053. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  1054. __per_cpu_mca[cpu] = __pa(mca_data);
  1055. mca_data += sizeof(struct ia64_mca_cpu);
  1056. }
  1057. }
  1058. /*
  1059. * The MCA info structure was allocated earlier and its
  1060. * physical address saved in __per_cpu_mca[cpu]. Copy that
  1061. * address * to ia64_mca_data so we can access it as a per-CPU
  1062. * variable.
  1063. */
  1064. __get_cpu_var(ia64_mca_data) = __per_cpu_mca[smp_processor_id()];
  1065. /*
  1066. * Stash away a copy of the PTE needed to map the per-CPU page.
  1067. * We may need it during MCA recovery.
  1068. */
  1069. __get_cpu_var(ia64_mca_per_cpu_pte) =
  1070. pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL));
  1071. /*
  1072. * Also, stash away a copy of the PAL address and the PTE
  1073. * needed to map it.
  1074. */
  1075. pal_vaddr = efi_get_pal_addr();
  1076. if (!pal_vaddr)
  1077. return;
  1078. __get_cpu_var(ia64_mca_pal_base) =
  1079. GRANULEROUNDDOWN((unsigned long) pal_vaddr);
  1080. __get_cpu_var(ia64_mca_pal_pte) = pte_val(mk_pte_phys(__pa(pal_vaddr),
  1081. PAGE_KERNEL));
  1082. }
  1083. /*
  1084. * ia64_mca_init
  1085. *
  1086. * Do all the system level mca specific initialization.
  1087. *
  1088. * 1. Register spinloop and wakeup request interrupt vectors
  1089. *
  1090. * 2. Register OS_MCA handler entry point
  1091. *
  1092. * 3. Register OS_INIT handler entry point
  1093. *
  1094. * 4. Initialize MCA/CMC/INIT related log buffers maintained by the OS.
  1095. *
  1096. * Note that this initialization is done very early before some kernel
  1097. * services are available.
  1098. *
  1099. * Inputs : None
  1100. *
  1101. * Outputs : None
  1102. */
  1103. void __init
  1104. ia64_mca_init(void)
  1105. {
  1106. ia64_fptr_t *mon_init_ptr = (ia64_fptr_t *)ia64_monarch_init_handler;
  1107. ia64_fptr_t *slave_init_ptr = (ia64_fptr_t *)ia64_slave_init_handler;
  1108. ia64_fptr_t *mca_hldlr_ptr = (ia64_fptr_t *)ia64_os_mca_dispatch;
  1109. int i;
  1110. s64 rc;
  1111. struct ia64_sal_retval isrv;
  1112. u64 timeout = IA64_MCA_RENDEZ_TIMEOUT; /* platform specific */
  1113. IA64_MCA_DEBUG("%s: begin\n", __FUNCTION__);
  1114. /* Clear the Rendez checkin flag for all cpus */
  1115. for(i = 0 ; i < NR_CPUS; i++)
  1116. ia64_mc_info.imi_rendez_checkin[i] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
  1117. /*
  1118. * Register the rendezvous spinloop and wakeup mechanism with SAL
  1119. */
  1120. /* Register the rendezvous interrupt vector with SAL */
  1121. while (1) {
  1122. isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_INT,
  1123. SAL_MC_PARAM_MECHANISM_INT,
  1124. IA64_MCA_RENDEZ_VECTOR,
  1125. timeout,
  1126. SAL_MC_PARAM_RZ_ALWAYS);
  1127. rc = isrv.status;
  1128. if (rc == 0)
  1129. break;
  1130. if (rc == -2) {
  1131. printk(KERN_INFO "Increasing MCA rendezvous timeout from "
  1132. "%ld to %ld milliseconds\n", timeout, isrv.v0);
  1133. timeout = isrv.v0;
  1134. continue;
  1135. }
  1136. printk(KERN_ERR "Failed to register rendezvous interrupt "
  1137. "with SAL (status %ld)\n", rc);
  1138. return;
  1139. }
  1140. /* Register the wakeup interrupt vector with SAL */
  1141. isrv = ia64_sal_mc_set_params(SAL_MC_PARAM_RENDEZ_WAKEUP,
  1142. SAL_MC_PARAM_MECHANISM_INT,
  1143. IA64_MCA_WAKEUP_VECTOR,
  1144. 0, 0);
  1145. rc = isrv.status;
  1146. if (rc) {
  1147. printk(KERN_ERR "Failed to register wakeup interrupt with SAL "
  1148. "(status %ld)\n", rc);
  1149. return;
  1150. }
  1151. IA64_MCA_DEBUG("%s: registered MCA rendezvous spinloop and wakeup mech.\n", __FUNCTION__);
  1152. ia64_mc_info.imi_mca_handler = ia64_tpa(mca_hldlr_ptr->fp);
  1153. /*
  1154. * XXX - disable SAL checksum by setting size to 0; should be
  1155. * ia64_tpa(ia64_os_mca_dispatch_end) - ia64_tpa(ia64_os_mca_dispatch);
  1156. */
  1157. ia64_mc_info.imi_mca_handler_size = 0;
  1158. /* Register the os mca handler with SAL */
  1159. if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_MCA,
  1160. ia64_mc_info.imi_mca_handler,
  1161. ia64_tpa(mca_hldlr_ptr->gp),
  1162. ia64_mc_info.imi_mca_handler_size,
  1163. 0, 0, 0)))
  1164. {
  1165. printk(KERN_ERR "Failed to register OS MCA handler with SAL "
  1166. "(status %ld)\n", rc);
  1167. return;
  1168. }
  1169. IA64_MCA_DEBUG("%s: registered OS MCA handler with SAL at 0x%lx, gp = 0x%lx\n", __FUNCTION__,
  1170. ia64_mc_info.imi_mca_handler, ia64_tpa(mca_hldlr_ptr->gp));
  1171. /*
  1172. * XXX - disable SAL checksum by setting size to 0, should be
  1173. * size of the actual init handler in mca_asm.S.
  1174. */
  1175. ia64_mc_info.imi_monarch_init_handler = ia64_tpa(mon_init_ptr->fp);
  1176. ia64_mc_info.imi_monarch_init_handler_size = 0;
  1177. ia64_mc_info.imi_slave_init_handler = ia64_tpa(slave_init_ptr->fp);
  1178. ia64_mc_info.imi_slave_init_handler_size = 0;
  1179. IA64_MCA_DEBUG("%s: OS INIT handler at %lx\n", __FUNCTION__,
  1180. ia64_mc_info.imi_monarch_init_handler);
  1181. /* Register the os init handler with SAL */
  1182. if ((rc = ia64_sal_set_vectors(SAL_VECTOR_OS_INIT,
  1183. ia64_mc_info.imi_monarch_init_handler,
  1184. ia64_tpa(ia64_getreg(_IA64_REG_GP)),
  1185. ia64_mc_info.imi_monarch_init_handler_size,
  1186. ia64_mc_info.imi_slave_init_handler,
  1187. ia64_tpa(ia64_getreg(_IA64_REG_GP)),
  1188. ia64_mc_info.imi_slave_init_handler_size)))
  1189. {
  1190. printk(KERN_ERR "Failed to register m/s INIT handlers with SAL "
  1191. "(status %ld)\n", rc);
  1192. return;
  1193. }
  1194. IA64_MCA_DEBUG("%s: registered OS INIT handler with SAL\n", __FUNCTION__);
  1195. /*
  1196. * Configure the CMCI/P vector and handler. Interrupts for CMC are
  1197. * per-processor, so AP CMC interrupts are setup in smp_callin() (smpboot.c).
  1198. */
  1199. register_percpu_irq(IA64_CMC_VECTOR, &cmci_irqaction);
  1200. register_percpu_irq(IA64_CMCP_VECTOR, &cmcp_irqaction);
  1201. ia64_mca_cmc_vector_setup(); /* Setup vector on BSP */
  1202. /* Setup the MCA rendezvous interrupt vector */
  1203. register_percpu_irq(IA64_MCA_RENDEZ_VECTOR, &mca_rdzv_irqaction);
  1204. /* Setup the MCA wakeup interrupt vector */
  1205. register_percpu_irq(IA64_MCA_WAKEUP_VECTOR, &mca_wkup_irqaction);
  1206. #ifdef CONFIG_ACPI
  1207. /* Setup the CPEI/P handler */
  1208. register_percpu_irq(IA64_CPEP_VECTOR, &mca_cpep_irqaction);
  1209. #endif
  1210. /* Initialize the areas set aside by the OS to buffer the
  1211. * platform/processor error states for MCA/INIT/CMC
  1212. * handling.
  1213. */
  1214. ia64_log_init(SAL_INFO_TYPE_MCA);
  1215. ia64_log_init(SAL_INFO_TYPE_INIT);
  1216. ia64_log_init(SAL_INFO_TYPE_CMC);
  1217. ia64_log_init(SAL_INFO_TYPE_CPE);
  1218. mca_init = 1;
  1219. printk(KERN_INFO "MCA related initialization done\n");
  1220. }
  1221. /*
  1222. * ia64_mca_late_init
  1223. *
  1224. * Opportunity to setup things that require initialization later
  1225. * than ia64_mca_init. Setup a timer to poll for CPEs if the
  1226. * platform doesn't support an interrupt driven mechanism.
  1227. *
  1228. * Inputs : None
  1229. * Outputs : Status
  1230. */
  1231. static int __init
  1232. ia64_mca_late_init(void)
  1233. {
  1234. if (!mca_init)
  1235. return 0;
  1236. /* Setup the CMCI/P vector and handler */
  1237. init_timer(&cmc_poll_timer);
  1238. cmc_poll_timer.function = ia64_mca_cmc_poll;
  1239. /* Unmask/enable the vector */
  1240. cmc_polling_enabled = 0;
  1241. schedule_work(&cmc_enable_work);
  1242. IA64_MCA_DEBUG("%s: CMCI/P setup and enabled.\n", __FUNCTION__);
  1243. #ifdef CONFIG_ACPI
  1244. /* Setup the CPEI/P vector and handler */
  1245. cpe_vector = acpi_request_vector(ACPI_INTERRUPT_CPEI);
  1246. init_timer(&cpe_poll_timer);
  1247. cpe_poll_timer.function = ia64_mca_cpe_poll;
  1248. {
  1249. irq_desc_t *desc;
  1250. unsigned int irq;
  1251. if (cpe_vector >= 0) {
  1252. /* If platform supports CPEI, enable the irq. */
  1253. cpe_poll_enabled = 0;
  1254. for (irq = 0; irq < NR_IRQS; ++irq)
  1255. if (irq_to_vector(irq) == cpe_vector) {
  1256. desc = irq_descp(irq);
  1257. desc->status |= IRQ_PER_CPU;
  1258. setup_irq(irq, &mca_cpe_irqaction);
  1259. }
  1260. ia64_mca_register_cpev(cpe_vector);
  1261. IA64_MCA_DEBUG("%s: CPEI/P setup and enabled.\n", __FUNCTION__);
  1262. } else {
  1263. /* If platform doesn't support CPEI, get the timer going. */
  1264. if (cpe_poll_enabled) {
  1265. ia64_mca_cpe_poll(0UL);
  1266. IA64_MCA_DEBUG("%s: CPEP setup and enabled.\n", __FUNCTION__);
  1267. }
  1268. }
  1269. }
  1270. #endif
  1271. return 0;
  1272. }
  1273. device_initcall(ia64_mca_late_init);