mca.c 61 KB

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