mca.c 58 KB

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