mca.c 61 KB

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