mca.c 58 KB

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