mca.c 61 KB

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