mca.c 60 KB

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