mca_drv.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /*
  2. * File: mca_drv.c
  3. * Purpose: Generic MCA handling layer
  4. *
  5. * Copyright (C) 2004 FUJITSU LIMITED
  6. * Copyright (C) Hidetoshi Seto (seto.hidetoshi@jp.fujitsu.com)
  7. * Copyright (C) 2005 Silicon Graphics, Inc
  8. * Copyright (C) 2005 Keith Owens <kaos@sgi.com>
  9. * Copyright (C) 2006 Russ Anderson <rja@sgi.com>
  10. */
  11. #include <linux/types.h>
  12. #include <linux/init.h>
  13. #include <linux/sched.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/irq.h>
  16. #include <linux/kallsyms.h>
  17. #include <linux/smp_lock.h>
  18. #include <linux/bootmem.h>
  19. #include <linux/acpi.h>
  20. #include <linux/timer.h>
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/smp.h>
  24. #include <linux/workqueue.h>
  25. #include <linux/mm.h>
  26. #include <asm/delay.h>
  27. #include <asm/machvec.h>
  28. #include <asm/page.h>
  29. #include <asm/ptrace.h>
  30. #include <asm/system.h>
  31. #include <asm/sal.h>
  32. #include <asm/mca.h>
  33. #include <asm/irq.h>
  34. #include <asm/hw_irq.h>
  35. #include "mca_drv.h"
  36. /* max size of SAL error record (default) */
  37. static int sal_rec_max = 10000;
  38. /* from mca_drv_asm.S */
  39. extern void *mca_handler_bhhook(void);
  40. static DEFINE_SPINLOCK(mca_bh_lock);
  41. typedef enum {
  42. MCA_IS_LOCAL = 0,
  43. MCA_IS_GLOBAL = 1
  44. } mca_type_t;
  45. #define MAX_PAGE_ISOLATE 1024
  46. static struct page *page_isolate[MAX_PAGE_ISOLATE];
  47. static int num_page_isolate = 0;
  48. typedef enum {
  49. ISOLATE_NG,
  50. ISOLATE_OK,
  51. ISOLATE_NONE
  52. } isolate_status_t;
  53. typedef enum {
  54. MCA_NOT_RECOVERED = 0,
  55. MCA_RECOVERED = 1
  56. } recovery_status_t;
  57. /*
  58. * This pool keeps pointers to the section part of SAL error record
  59. */
  60. static struct {
  61. slidx_list_t *buffer; /* section pointer list pool */
  62. int cur_idx; /* Current index of section pointer list pool */
  63. int max_idx; /* Maximum index of section pointer list pool */
  64. } slidx_pool;
  65. static int
  66. fatal_mca(const char *fmt, ...)
  67. {
  68. va_list args;
  69. char buf[256];
  70. va_start(args, fmt);
  71. vsnprintf(buf, sizeof(buf), fmt, args);
  72. va_end(args);
  73. ia64_mca_printk(KERN_ALERT "MCA: %s\n", buf);
  74. return MCA_NOT_RECOVERED;
  75. }
  76. static int
  77. mca_recovered(const char *fmt, ...)
  78. {
  79. va_list args;
  80. char buf[256];
  81. va_start(args, fmt);
  82. vsnprintf(buf, sizeof(buf), fmt, args);
  83. va_end(args);
  84. ia64_mca_printk(KERN_INFO "MCA: %s\n", buf);
  85. return MCA_RECOVERED;
  86. }
  87. /**
  88. * mca_page_isolate - isolate a poisoned page in order not to use it later
  89. * @paddr: poisoned memory location
  90. *
  91. * Return value:
  92. * one of isolate_status_t, ISOLATE_OK/NG/NONE.
  93. */
  94. static isolate_status_t
  95. mca_page_isolate(unsigned long paddr)
  96. {
  97. int i;
  98. struct page *p;
  99. /* whether physical address is valid or not */
  100. if (!ia64_phys_addr_valid(paddr))
  101. return ISOLATE_NONE;
  102. if (!pfn_valid(paddr >> PAGE_SHIFT))
  103. return ISOLATE_NONE;
  104. /* convert physical address to physical page number */
  105. p = pfn_to_page(paddr>>PAGE_SHIFT);
  106. /* check whether a page number have been already registered or not */
  107. for (i = 0; i < num_page_isolate; i++)
  108. if (page_isolate[i] == p)
  109. return ISOLATE_OK; /* already listed */
  110. /* limitation check */
  111. if (num_page_isolate == MAX_PAGE_ISOLATE)
  112. return ISOLATE_NG;
  113. /* kick pages having attribute 'SLAB' or 'Reserved' */
  114. if (PageSlab(p) || PageReserved(p))
  115. return ISOLATE_NG;
  116. /* add attribute 'Reserved' and register the page */
  117. get_page(p);
  118. SetPageReserved(p);
  119. page_isolate[num_page_isolate++] = p;
  120. return ISOLATE_OK;
  121. }
  122. /**
  123. * mca_hanlder_bh - Kill the process which occurred memory read error
  124. * @paddr: poisoned address received from MCA Handler
  125. */
  126. void
  127. mca_handler_bh(unsigned long paddr, void *iip, unsigned long ipsr)
  128. {
  129. ia64_mlogbuf_dump();
  130. printk(KERN_ERR "OS_MCA: process [cpu %d, pid: %d, uid: %d, "
  131. "iip: %p, psr: 0x%lx,paddr: 0x%lx](%s) encounters MCA.\n",
  132. raw_smp_processor_id(), current->pid, current->uid,
  133. iip, ipsr, paddr, current->comm);
  134. spin_lock(&mca_bh_lock);
  135. switch (mca_page_isolate(paddr)) {
  136. case ISOLATE_OK:
  137. printk(KERN_DEBUG "Page isolation: ( %lx ) success.\n", paddr);
  138. break;
  139. case ISOLATE_NG:
  140. printk(KERN_CRIT "Page isolation: ( %lx ) failure.\n", paddr);
  141. break;
  142. default:
  143. break;
  144. }
  145. spin_unlock(&mca_bh_lock);
  146. /* This process is about to be killed itself */
  147. do_exit(SIGKILL);
  148. }
  149. /**
  150. * mca_make_peidx - Make index of processor error section
  151. * @slpi: pointer to record of processor error section
  152. * @peidx: pointer to index of processor error section
  153. */
  154. static void
  155. mca_make_peidx(sal_log_processor_info_t *slpi, peidx_table_t *peidx)
  156. {
  157. /*
  158. * calculate the start address of
  159. * "struct cpuid_info" and "sal_processor_static_info_t".
  160. */
  161. u64 total_check_num = slpi->valid.num_cache_check
  162. + slpi->valid.num_tlb_check
  163. + slpi->valid.num_bus_check
  164. + slpi->valid.num_reg_file_check
  165. + slpi->valid.num_ms_check;
  166. u64 head_size = sizeof(sal_log_mod_error_info_t) * total_check_num
  167. + sizeof(sal_log_processor_info_t);
  168. u64 mid_size = slpi->valid.cpuid_info * sizeof(struct sal_cpuid_info);
  169. peidx_head(peidx) = slpi;
  170. peidx_mid(peidx) = (struct sal_cpuid_info *)
  171. (slpi->valid.cpuid_info ? ((char*)slpi + head_size) : NULL);
  172. peidx_bottom(peidx) = (sal_processor_static_info_t *)
  173. (slpi->valid.psi_static_struct ?
  174. ((char*)slpi + head_size + mid_size) : NULL);
  175. }
  176. /**
  177. * mca_make_slidx - Make index of SAL error record
  178. * @buffer: pointer to SAL error record
  179. * @slidx: pointer to index of SAL error record
  180. *
  181. * Return value:
  182. * 1 if record has platform error / 0 if not
  183. */
  184. #define LOG_INDEX_ADD_SECT_PTR(sect, ptr) \
  185. {slidx_list_t *hl = &slidx_pool.buffer[slidx_pool.cur_idx]; \
  186. hl->hdr = ptr; \
  187. list_add(&hl->list, &(sect)); \
  188. slidx_pool.cur_idx = (slidx_pool.cur_idx + 1)%slidx_pool.max_idx; }
  189. static int
  190. mca_make_slidx(void *buffer, slidx_table_t *slidx)
  191. {
  192. int platform_err = 0;
  193. int record_len = ((sal_log_record_header_t*)buffer)->len;
  194. u32 ercd_pos;
  195. int sects;
  196. sal_log_section_hdr_t *sp;
  197. /*
  198. * Initialize index referring current record
  199. */
  200. INIT_LIST_HEAD(&(slidx->proc_err));
  201. INIT_LIST_HEAD(&(slidx->mem_dev_err));
  202. INIT_LIST_HEAD(&(slidx->sel_dev_err));
  203. INIT_LIST_HEAD(&(slidx->pci_bus_err));
  204. INIT_LIST_HEAD(&(slidx->smbios_dev_err));
  205. INIT_LIST_HEAD(&(slidx->pci_comp_err));
  206. INIT_LIST_HEAD(&(slidx->plat_specific_err));
  207. INIT_LIST_HEAD(&(slidx->host_ctlr_err));
  208. INIT_LIST_HEAD(&(slidx->plat_bus_err));
  209. INIT_LIST_HEAD(&(slidx->unsupported));
  210. /*
  211. * Extract a Record Header
  212. */
  213. slidx->header = buffer;
  214. /*
  215. * Extract each section records
  216. * (arranged from "int ia64_log_platform_info_print()")
  217. */
  218. for (ercd_pos = sizeof(sal_log_record_header_t), sects = 0;
  219. ercd_pos < record_len; ercd_pos += sp->len, sects++) {
  220. sp = (sal_log_section_hdr_t *)((char*)buffer + ercd_pos);
  221. if (!efi_guidcmp(sp->guid, SAL_PROC_DEV_ERR_SECT_GUID)) {
  222. LOG_INDEX_ADD_SECT_PTR(slidx->proc_err, sp);
  223. } else if (!efi_guidcmp(sp->guid,
  224. SAL_PLAT_MEM_DEV_ERR_SECT_GUID)) {
  225. platform_err = 1;
  226. LOG_INDEX_ADD_SECT_PTR(slidx->mem_dev_err, sp);
  227. } else if (!efi_guidcmp(sp->guid,
  228. SAL_PLAT_SEL_DEV_ERR_SECT_GUID)) {
  229. platform_err = 1;
  230. LOG_INDEX_ADD_SECT_PTR(slidx->sel_dev_err, sp);
  231. } else if (!efi_guidcmp(sp->guid,
  232. SAL_PLAT_PCI_BUS_ERR_SECT_GUID)) {
  233. platform_err = 1;
  234. LOG_INDEX_ADD_SECT_PTR(slidx->pci_bus_err, sp);
  235. } else if (!efi_guidcmp(sp->guid,
  236. SAL_PLAT_SMBIOS_DEV_ERR_SECT_GUID)) {
  237. platform_err = 1;
  238. LOG_INDEX_ADD_SECT_PTR(slidx->smbios_dev_err, sp);
  239. } else if (!efi_guidcmp(sp->guid,
  240. SAL_PLAT_PCI_COMP_ERR_SECT_GUID)) {
  241. platform_err = 1;
  242. LOG_INDEX_ADD_SECT_PTR(slidx->pci_comp_err, sp);
  243. } else if (!efi_guidcmp(sp->guid,
  244. SAL_PLAT_SPECIFIC_ERR_SECT_GUID)) {
  245. platform_err = 1;
  246. LOG_INDEX_ADD_SECT_PTR(slidx->plat_specific_err, sp);
  247. } else if (!efi_guidcmp(sp->guid,
  248. SAL_PLAT_HOST_CTLR_ERR_SECT_GUID)) {
  249. platform_err = 1;
  250. LOG_INDEX_ADD_SECT_PTR(slidx->host_ctlr_err, sp);
  251. } else if (!efi_guidcmp(sp->guid,
  252. SAL_PLAT_BUS_ERR_SECT_GUID)) {
  253. platform_err = 1;
  254. LOG_INDEX_ADD_SECT_PTR(slidx->plat_bus_err, sp);
  255. } else {
  256. LOG_INDEX_ADD_SECT_PTR(slidx->unsupported, sp);
  257. }
  258. }
  259. slidx->n_sections = sects;
  260. return platform_err;
  261. }
  262. /**
  263. * init_record_index_pools - Initialize pool of lists for SAL record index
  264. *
  265. * Return value:
  266. * 0 on Success / -ENOMEM on Failure
  267. */
  268. static int
  269. init_record_index_pools(void)
  270. {
  271. int i;
  272. int rec_max_size; /* Maximum size of SAL error records */
  273. int sect_min_size; /* Minimum size of SAL error sections */
  274. /* minimum size table of each section */
  275. static int sal_log_sect_min_sizes[] = {
  276. sizeof(sal_log_processor_info_t)
  277. + sizeof(sal_processor_static_info_t),
  278. sizeof(sal_log_mem_dev_err_info_t),
  279. sizeof(sal_log_sel_dev_err_info_t),
  280. sizeof(sal_log_pci_bus_err_info_t),
  281. sizeof(sal_log_smbios_dev_err_info_t),
  282. sizeof(sal_log_pci_comp_err_info_t),
  283. sizeof(sal_log_plat_specific_err_info_t),
  284. sizeof(sal_log_host_ctlr_err_info_t),
  285. sizeof(sal_log_plat_bus_err_info_t),
  286. };
  287. /*
  288. * MCA handler cannot allocate new memory on flight,
  289. * so we preallocate enough memory to handle a SAL record.
  290. *
  291. * Initialize a handling set of slidx_pool:
  292. * 1. Pick up the max size of SAL error records
  293. * 2. Pick up the min size of SAL error sections
  294. * 3. Allocate the pool as enough to 2 SAL records
  295. * (now we can estimate the maxinum of section in a record.)
  296. */
  297. /* - 1 - */
  298. rec_max_size = sal_rec_max;
  299. /* - 2 - */
  300. sect_min_size = sal_log_sect_min_sizes[0];
  301. for (i = 1; i < sizeof sal_log_sect_min_sizes/sizeof(size_t); i++)
  302. if (sect_min_size > sal_log_sect_min_sizes[i])
  303. sect_min_size = sal_log_sect_min_sizes[i];
  304. /* - 3 - */
  305. slidx_pool.max_idx = (rec_max_size/sect_min_size) * 2 + 1;
  306. slidx_pool.buffer = (slidx_list_t *)
  307. kmalloc(slidx_pool.max_idx * sizeof(slidx_list_t), GFP_KERNEL);
  308. return slidx_pool.buffer ? 0 : -ENOMEM;
  309. }
  310. /*****************************************************************************
  311. * Recovery functions *
  312. *****************************************************************************/
  313. /**
  314. * is_mca_global - Check whether this MCA is global or not
  315. * @peidx: pointer of index of processor error section
  316. * @pbci: pointer to pal_bus_check_info_t
  317. * @sos: pointer to hand off struct between SAL and OS
  318. *
  319. * Return value:
  320. * MCA_IS_LOCAL / MCA_IS_GLOBAL
  321. */
  322. static mca_type_t
  323. is_mca_global(peidx_table_t *peidx, pal_bus_check_info_t *pbci,
  324. struct ia64_sal_os_state *sos)
  325. {
  326. pal_processor_state_info_t *psp =
  327. (pal_processor_state_info_t*)peidx_psp(peidx);
  328. /*
  329. * PAL can request a rendezvous, if the MCA has a global scope.
  330. * If "rz_always" flag is set, SAL requests MCA rendezvous
  331. * in spite of global MCA.
  332. * Therefore it is local MCA when rendezvous has not been requested.
  333. * Failed to rendezvous, the system must be down.
  334. */
  335. switch (sos->rv_rc) {
  336. case -1: /* SAL rendezvous unsuccessful */
  337. return MCA_IS_GLOBAL;
  338. case 0: /* SAL rendezvous not required */
  339. return MCA_IS_LOCAL;
  340. case 1: /* SAL rendezvous successful int */
  341. case 2: /* SAL rendezvous successful int with init */
  342. default:
  343. break;
  344. }
  345. /*
  346. * If One or more Cache/TLB/Reg_File/Uarch_Check is here,
  347. * it would be a local MCA. (i.e. processor internal error)
  348. */
  349. if (psp->tc || psp->cc || psp->rc || psp->uc)
  350. return MCA_IS_LOCAL;
  351. /*
  352. * Bus_Check structure with Bus_Check.ib (internal bus error) flag set
  353. * would be a global MCA. (e.g. a system bus address parity error)
  354. */
  355. if (!pbci || pbci->ib)
  356. return MCA_IS_GLOBAL;
  357. /*
  358. * Bus_Check structure with Bus_Check.eb (external bus error) flag set
  359. * could be either a local MCA or a global MCA.
  360. *
  361. * Referring Bus_Check.bsi:
  362. * 0: Unknown/unclassified
  363. * 1: BERR#
  364. * 2: BINIT#
  365. * 3: Hard Fail
  366. * (FIXME: Are these SGI specific or generic bsi values?)
  367. */
  368. if (pbci->eb)
  369. switch (pbci->bsi) {
  370. case 0:
  371. /* e.g. a load from poisoned memory */
  372. return MCA_IS_LOCAL;
  373. case 1:
  374. case 2:
  375. case 3:
  376. return MCA_IS_GLOBAL;
  377. }
  378. return MCA_IS_GLOBAL;
  379. }
  380. /**
  381. * recover_from_read_error - Try to recover the errors which type are "read"s.
  382. * @slidx: pointer of index of SAL error record
  383. * @peidx: pointer of index of processor error section
  384. * @pbci: pointer of pal_bus_check_info
  385. * @sos: pointer to hand off struct between SAL and OS
  386. *
  387. * Return value:
  388. * 1 on Success / 0 on Failure
  389. */
  390. static int
  391. recover_from_read_error(slidx_table_t *slidx,
  392. peidx_table_t *peidx, pal_bus_check_info_t *pbci,
  393. struct ia64_sal_os_state *sos)
  394. {
  395. sal_log_mod_error_info_t *smei;
  396. pal_min_state_area_t *pmsa;
  397. struct ia64_psr *psr1, *psr2;
  398. ia64_fptr_t *mca_hdlr_bh = (ia64_fptr_t*)mca_handler_bhhook;
  399. /* Is target address valid? */
  400. if (!pbci->tv)
  401. return fatal_mca("target address not valid");
  402. /*
  403. * cpu read or memory-mapped io read
  404. *
  405. * offending process affected process OS MCA do
  406. * kernel mode kernel mode down system
  407. * kernel mode user mode kill the process
  408. * user mode kernel mode down system (*)
  409. * user mode user mode kill the process
  410. *
  411. * (*) You could terminate offending user-mode process
  412. * if (pbci->pv && pbci->pl != 0) *and* if you sure
  413. * the process not have any locks of kernel.
  414. */
  415. /* Is minstate valid? */
  416. if (!peidx_bottom(peidx) || !(peidx_bottom(peidx)->valid.minstate))
  417. return fatal_mca("minstate not valid");
  418. psr1 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_ipsr);
  419. psr2 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_xpsr);
  420. /*
  421. * Check the privilege level of interrupted context.
  422. * If it is user-mode, then terminate affected process.
  423. */
  424. pmsa = sos->pal_min_state;
  425. if (psr1->cpl != 0 ||
  426. ((psr2->cpl != 0) && mca_recover_range(pmsa->pmsa_iip))) {
  427. smei = peidx_bus_check(peidx, 0);
  428. if (smei->valid.target_identifier) {
  429. /*
  430. * setup for resume to bottom half of MCA,
  431. * "mca_handler_bhhook"
  432. */
  433. /* pass to bhhook as argument (gr8, ...) */
  434. pmsa->pmsa_gr[8-1] = smei->target_identifier;
  435. pmsa->pmsa_gr[9-1] = pmsa->pmsa_iip;
  436. pmsa->pmsa_gr[10-1] = pmsa->pmsa_ipsr;
  437. /* set interrupted return address (but no use) */
  438. pmsa->pmsa_br0 = pmsa->pmsa_iip;
  439. /* change resume address to bottom half */
  440. pmsa->pmsa_iip = mca_hdlr_bh->fp;
  441. pmsa->pmsa_gr[1-1] = mca_hdlr_bh->gp;
  442. /* set cpl with kernel mode */
  443. psr2 = (struct ia64_psr *)&pmsa->pmsa_ipsr;
  444. psr2->cpl = 0;
  445. psr2->ri = 0;
  446. psr2->bn = 1;
  447. psr2->i = 0;
  448. return mca_recovered("user memory corruption. "
  449. "kill affected process - recovered.");
  450. }
  451. }
  452. return fatal_mca("kernel context not recovered, iip 0x%lx\n",
  453. pmsa->pmsa_iip);
  454. }
  455. /**
  456. * recover_from_platform_error - Recover from platform error.
  457. * @slidx: pointer of index of SAL error record
  458. * @peidx: pointer of index of processor error section
  459. * @pbci: pointer of pal_bus_check_info
  460. * @sos: pointer to hand off struct between SAL and OS
  461. *
  462. * Return value:
  463. * 1 on Success / 0 on Failure
  464. */
  465. static int
  466. recover_from_platform_error(slidx_table_t *slidx, peidx_table_t *peidx,
  467. pal_bus_check_info_t *pbci,
  468. struct ia64_sal_os_state *sos)
  469. {
  470. int status = 0;
  471. pal_processor_state_info_t *psp =
  472. (pal_processor_state_info_t*)peidx_psp(peidx);
  473. if (psp->bc && pbci->eb && pbci->bsi == 0) {
  474. switch(pbci->type) {
  475. case 1: /* partial read */
  476. case 3: /* full line(cpu) read */
  477. case 9: /* I/O space read */
  478. status = recover_from_read_error(slidx, peidx, pbci,
  479. sos);
  480. break;
  481. case 0: /* unknown */
  482. case 2: /* partial write */
  483. case 4: /* full line write */
  484. case 5: /* implicit or explicit write-back operation */
  485. case 6: /* snoop probe */
  486. case 7: /* incoming or outgoing ptc.g */
  487. case 8: /* write coalescing transactions */
  488. case 10: /* I/O space write */
  489. case 11: /* inter-processor interrupt message(IPI) */
  490. case 12: /* interrupt acknowledge or
  491. external task priority cycle */
  492. default:
  493. break;
  494. }
  495. }
  496. return status;
  497. }
  498. /**
  499. * recover_from_processor_error
  500. * @platform: whether there are some platform error section or not
  501. * @slidx: pointer of index of SAL error record
  502. * @peidx: pointer of index of processor error section
  503. * @pbci: pointer of pal_bus_check_info
  504. * @sos: pointer to hand off struct between SAL and OS
  505. *
  506. * Return value:
  507. * 1 on Success / 0 on Failure
  508. */
  509. /*
  510. * Later we try to recover when below all conditions are satisfied.
  511. * 1. Only one processor error section is exist.
  512. * 2. BUS_CHECK is exist and the others are not exist.(Except TLB_CHECK)
  513. * 3. The entry of BUS_CHECK_INFO is 1.
  514. * 4. "External bus error" flag is set and the others are not set.
  515. */
  516. static int
  517. recover_from_processor_error(int platform, slidx_table_t *slidx,
  518. peidx_table_t *peidx, pal_bus_check_info_t *pbci,
  519. struct ia64_sal_os_state *sos)
  520. {
  521. pal_processor_state_info_t *psp =
  522. (pal_processor_state_info_t*)peidx_psp(peidx);
  523. /*
  524. * Processor recovery status must key off of the PAL recovery
  525. * status in the Processor State Parameter.
  526. */
  527. /*
  528. * The machine check is corrected.
  529. */
  530. if (psp->cm == 1)
  531. return mca_recovered("machine check is already corrected.");
  532. /*
  533. * The error was not contained. Software must be reset.
  534. */
  535. if (psp->us || psp->ci == 0)
  536. return fatal_mca("error not contained");
  537. /*
  538. * The cache check and bus check bits have four possible states
  539. * cc bc
  540. * 0 0 Weird record, not recovered
  541. * 1 0 Cache error, not recovered
  542. * 0 1 I/O error, attempt recovery
  543. * 1 1 Memory error, attempt recovery
  544. */
  545. if (psp->bc == 0 || pbci == NULL)
  546. return fatal_mca("No bus check");
  547. /*
  548. * Sorry, we cannot handle so many.
  549. */
  550. if (peidx_bus_check_num(peidx) > 1)
  551. return fatal_mca("Too many bus checks");
  552. /*
  553. * Well, here is only one bus error.
  554. */
  555. if (pbci->ib)
  556. return fatal_mca("Internal Bus error");
  557. if (pbci->cc)
  558. return fatal_mca("Cache-cache error");
  559. if (pbci->eb && pbci->bsi > 0)
  560. return fatal_mca("External bus check fatal status");
  561. /*
  562. * This is a local MCA and estimated as recoverble external bus error.
  563. * (e.g. a load from poisoned memory)
  564. * This means "there are some platform errors".
  565. */
  566. if (platform)
  567. return recover_from_platform_error(slidx, peidx, pbci, sos);
  568. /*
  569. * On account of strange SAL error record, we cannot recover.
  570. */
  571. return fatal_mca("Strange SAL record");
  572. }
  573. /**
  574. * mca_try_to_recover - Try to recover from MCA
  575. * @rec: pointer to a SAL error record
  576. * @sos: pointer to hand off struct between SAL and OS
  577. *
  578. * Return value:
  579. * 1 on Success / 0 on Failure
  580. */
  581. static int
  582. mca_try_to_recover(void *rec, struct ia64_sal_os_state *sos)
  583. {
  584. int platform_err;
  585. int n_proc_err;
  586. slidx_table_t slidx;
  587. peidx_table_t peidx;
  588. pal_bus_check_info_t pbci;
  589. /* Make index of SAL error record */
  590. platform_err = mca_make_slidx(rec, &slidx);
  591. /* Count processor error sections */
  592. n_proc_err = slidx_count(&slidx, proc_err);
  593. /* Now, OS can recover when there is one processor error section */
  594. if (n_proc_err > 1)
  595. return fatal_mca("Too Many Errors");
  596. else if (n_proc_err == 0)
  597. /* Weird SAL record ... We can't do anything */
  598. return fatal_mca("Weird SAL record");
  599. /* Make index of processor error section */
  600. mca_make_peidx((sal_log_processor_info_t*)
  601. slidx_first_entry(&slidx.proc_err)->hdr, &peidx);
  602. /* Extract Processor BUS_CHECK[0] */
  603. *((u64*)&pbci) = peidx_check_info(&peidx, bus_check, 0);
  604. /* Check whether MCA is global or not */
  605. if (is_mca_global(&peidx, &pbci, sos))
  606. return fatal_mca("global MCA");
  607. /* Try to recover a processor error */
  608. return recover_from_processor_error(platform_err, &slidx, &peidx,
  609. &pbci, sos);
  610. }
  611. /*
  612. * =============================================================================
  613. */
  614. int __init mca_external_handler_init(void)
  615. {
  616. if (init_record_index_pools())
  617. return -ENOMEM;
  618. /* register external mca handlers */
  619. if (ia64_reg_MCA_extension(mca_try_to_recover)) {
  620. printk(KERN_ERR "ia64_reg_MCA_extension failed.\n");
  621. kfree(slidx_pool.buffer);
  622. return -EFAULT;
  623. }
  624. return 0;
  625. }
  626. void __exit mca_external_handler_exit(void)
  627. {
  628. /* unregister external mca handlers */
  629. ia64_unreg_MCA_extension();
  630. kfree(slidx_pool.buffer);
  631. }
  632. module_init(mca_external_handler_init);
  633. module_exit(mca_external_handler_exit);
  634. module_param(sal_rec_max, int, 0644);
  635. MODULE_PARM_DESC(sal_rec_max, "Max size of SAL error record");
  636. MODULE_DESCRIPTION("ia64 platform dependent mca handler driver");
  637. MODULE_LICENSE("GPL");