mca.c 53 KB

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