mca.c 58 KB

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