mca.c 58 KB

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