cper.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * UEFI Common Platform Error Record (CPER) support
  4. *
  5. * Copyright (C) 2010, Intel Corp.
  6. * Author: Huang Ying <[email protected]>
  7. *
  8. * CPER is the format used to describe platform hardware error by
  9. * various tables, such as ERST, BERT and HEST etc.
  10. *
  11. * For more information about CPER, please refer to Appendix N of UEFI
  12. * Specification version 2.4.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/time.h>
  17. #include <linux/cper.h>
  18. #include <linux/dmi.h>
  19. #include <linux/acpi.h>
  20. #include <linux/pci.h>
  21. #include <linux/aer.h>
  22. #include <linux/printk.h>
  23. #include <linux/bcd.h>
  24. #include <acpi/ghes.h>
  25. #include <ras/ras_event.h>
  26. /*
  27. * CPER record ID need to be unique even after reboot, because record
  28. * ID is used as index for ERST storage, while CPER records from
  29. * multiple boot may co-exist in ERST.
  30. */
  31. u64 cper_next_record_id(void)
  32. {
  33. static atomic64_t seq;
  34. if (!atomic64_read(&seq)) {
  35. time64_t time = ktime_get_real_seconds();
  36. /*
  37. * This code is unlikely to still be needed in year 2106,
  38. * but just in case, let's use a few more bits for timestamps
  39. * after y2038 to be sure they keep increasing monotonically
  40. * for the next few hundred years...
  41. */
  42. if (time < 0x80000000)
  43. atomic64_set(&seq, (ktime_get_real_seconds()) << 32);
  44. else
  45. atomic64_set(&seq, 0x8000000000000000ull |
  46. ktime_get_real_seconds() << 24);
  47. }
  48. return atomic64_inc_return(&seq);
  49. }
  50. EXPORT_SYMBOL_GPL(cper_next_record_id);
  51. static const char * const severity_strs[] = {
  52. "recoverable",
  53. "fatal",
  54. "corrected",
  55. "info",
  56. };
  57. const char *cper_severity_str(unsigned int severity)
  58. {
  59. return severity < ARRAY_SIZE(severity_strs) ?
  60. severity_strs[severity] : "unknown";
  61. }
  62. EXPORT_SYMBOL_GPL(cper_severity_str);
  63. /*
  64. * cper_print_bits - print strings for set bits
  65. * @pfx: prefix for each line, including log level and prefix string
  66. * @bits: bit mask
  67. * @strs: string array, indexed by bit position
  68. * @strs_size: size of the string array: @strs
  69. *
  70. * For each set bit in @bits, print the corresponding string in @strs.
  71. * If the output length is longer than 80, multiple line will be
  72. * printed, with @pfx is printed at the beginning of each line.
  73. */
  74. void cper_print_bits(const char *pfx, unsigned int bits,
  75. const char * const strs[], unsigned int strs_size)
  76. {
  77. int i, len = 0;
  78. const char *str;
  79. char buf[84];
  80. for (i = 0; i < strs_size; i++) {
  81. if (!(bits & (1U << i)))
  82. continue;
  83. str = strs[i];
  84. if (!str)
  85. continue;
  86. if (len && len + strlen(str) + 2 > 80) {
  87. printk("%s\n", buf);
  88. len = 0;
  89. }
  90. if (!len)
  91. len = snprintf(buf, sizeof(buf), "%s%s", pfx, str);
  92. else
  93. len += scnprintf(buf+len, sizeof(buf)-len, ", %s", str);
  94. }
  95. if (len)
  96. printk("%s\n", buf);
  97. }
  98. static const char * const proc_type_strs[] = {
  99. "IA32/X64",
  100. "IA64",
  101. "ARM",
  102. };
  103. static const char * const proc_isa_strs[] = {
  104. "IA32",
  105. "IA64",
  106. "X64",
  107. "ARM A32/T32",
  108. "ARM A64",
  109. };
  110. const char * const cper_proc_error_type_strs[] = {
  111. "cache error",
  112. "TLB error",
  113. "bus error",
  114. "micro-architectural error",
  115. };
  116. static const char * const proc_op_strs[] = {
  117. "unknown or generic",
  118. "data read",
  119. "data write",
  120. "instruction execution",
  121. };
  122. static const char * const proc_flag_strs[] = {
  123. "restartable",
  124. "precise IP",
  125. "overflow",
  126. "corrected",
  127. };
  128. static void cper_print_proc_generic(const char *pfx,
  129. const struct cper_sec_proc_generic *proc)
  130. {
  131. if (proc->validation_bits & CPER_PROC_VALID_TYPE)
  132. printk("%s""processor_type: %d, %s\n", pfx, proc->proc_type,
  133. proc->proc_type < ARRAY_SIZE(proc_type_strs) ?
  134. proc_type_strs[proc->proc_type] : "unknown");
  135. if (proc->validation_bits & CPER_PROC_VALID_ISA)
  136. printk("%s""processor_isa: %d, %s\n", pfx, proc->proc_isa,
  137. proc->proc_isa < ARRAY_SIZE(proc_isa_strs) ?
  138. proc_isa_strs[proc->proc_isa] : "unknown");
  139. if (proc->validation_bits & CPER_PROC_VALID_ERROR_TYPE) {
  140. printk("%s""error_type: 0x%02x\n", pfx, proc->proc_error_type);
  141. cper_print_bits(pfx, proc->proc_error_type,
  142. cper_proc_error_type_strs,
  143. ARRAY_SIZE(cper_proc_error_type_strs));
  144. }
  145. if (proc->validation_bits & CPER_PROC_VALID_OPERATION)
  146. printk("%s""operation: %d, %s\n", pfx, proc->operation,
  147. proc->operation < ARRAY_SIZE(proc_op_strs) ?
  148. proc_op_strs[proc->operation] : "unknown");
  149. if (proc->validation_bits & CPER_PROC_VALID_FLAGS) {
  150. printk("%s""flags: 0x%02x\n", pfx, proc->flags);
  151. cper_print_bits(pfx, proc->flags, proc_flag_strs,
  152. ARRAY_SIZE(proc_flag_strs));
  153. }
  154. if (proc->validation_bits & CPER_PROC_VALID_LEVEL)
  155. printk("%s""level: %d\n", pfx, proc->level);
  156. if (proc->validation_bits & CPER_PROC_VALID_VERSION)
  157. printk("%s""version_info: 0x%016llx\n", pfx, proc->cpu_version);
  158. if (proc->validation_bits & CPER_PROC_VALID_ID)
  159. printk("%s""processor_id: 0x%016llx\n", pfx, proc->proc_id);
  160. if (proc->validation_bits & CPER_PROC_VALID_TARGET_ADDRESS)
  161. printk("%s""target_address: 0x%016llx\n",
  162. pfx, proc->target_addr);
  163. if (proc->validation_bits & CPER_PROC_VALID_REQUESTOR_ID)
  164. printk("%s""requestor_id: 0x%016llx\n",
  165. pfx, proc->requestor_id);
  166. if (proc->validation_bits & CPER_PROC_VALID_RESPONDER_ID)
  167. printk("%s""responder_id: 0x%016llx\n",
  168. pfx, proc->responder_id);
  169. if (proc->validation_bits & CPER_PROC_VALID_IP)
  170. printk("%s""IP: 0x%016llx\n", pfx, proc->ip);
  171. }
  172. static const char * const mem_err_type_strs[] = {
  173. "unknown",
  174. "no error",
  175. "single-bit ECC",
  176. "multi-bit ECC",
  177. "single-symbol chipkill ECC",
  178. "multi-symbol chipkill ECC",
  179. "master abort",
  180. "target abort",
  181. "parity error",
  182. "watchdog timeout",
  183. "invalid address",
  184. "mirror Broken",
  185. "memory sparing",
  186. "scrub corrected error",
  187. "scrub uncorrected error",
  188. "physical memory map-out event",
  189. };
  190. const char *cper_mem_err_type_str(unsigned int etype)
  191. {
  192. return etype < ARRAY_SIZE(mem_err_type_strs) ?
  193. mem_err_type_strs[etype] : "unknown";
  194. }
  195. EXPORT_SYMBOL_GPL(cper_mem_err_type_str);
  196. const char *cper_mem_err_status_str(u64 status)
  197. {
  198. switch ((status >> 8) & 0xff) {
  199. case 1: return "Error detected internal to the component";
  200. case 4: return "Storage error in DRAM memory";
  201. case 5: return "Storage error in TLB";
  202. case 6: return "Storage error in cache";
  203. case 7: return "Error in one or more functional units";
  204. case 8: return "Component failed self test";
  205. case 9: return "Overflow or undervalue of internal queue";
  206. case 16: return "Error detected in the bus";
  207. case 17: return "Virtual address not found on IO-TLB or IO-PDIR";
  208. case 18: return "Improper access error";
  209. case 19: return "Access to a memory address which is not mapped to any component";
  210. case 20: return "Loss of Lockstep";
  211. case 21: return "Response not associated with a request";
  212. case 22: return "Bus parity error - must also set the A, C, or D Bits";
  213. case 23: return "Detection of a protocol error";
  214. case 24: return "Detection of a PATH_ERROR";
  215. case 25: return "Bus operation timeout";
  216. case 26: return "A read was issued to data that has been poisoned";
  217. default: return "Reserved";
  218. }
  219. }
  220. EXPORT_SYMBOL_GPL(cper_mem_err_status_str);
  221. int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg)
  222. {
  223. u32 len, n;
  224. if (!msg)
  225. return 0;
  226. n = 0;
  227. len = CPER_REC_LEN;
  228. if (mem->validation_bits & CPER_MEM_VALID_NODE)
  229. n += scnprintf(msg + n, len - n, "node:%d ", mem->node);
  230. if (mem->validation_bits & CPER_MEM_VALID_CARD)
  231. n += scnprintf(msg + n, len - n, "card:%d ", mem->card);
  232. if (mem->validation_bits & CPER_MEM_VALID_MODULE)
  233. n += scnprintf(msg + n, len - n, "module:%d ", mem->module);
  234. if (mem->validation_bits & CPER_MEM_VALID_RANK_NUMBER)
  235. n += scnprintf(msg + n, len - n, "rank:%d ", mem->rank);
  236. if (mem->validation_bits & CPER_MEM_VALID_BANK)
  237. n += scnprintf(msg + n, len - n, "bank:%d ", mem->bank);
  238. if (mem->validation_bits & CPER_MEM_VALID_BANK_GROUP)
  239. n += scnprintf(msg + n, len - n, "bank_group:%d ",
  240. mem->bank >> CPER_MEM_BANK_GROUP_SHIFT);
  241. if (mem->validation_bits & CPER_MEM_VALID_BANK_ADDRESS)
  242. n += scnprintf(msg + n, len - n, "bank_address:%d ",
  243. mem->bank & CPER_MEM_BANK_ADDRESS_MASK);
  244. if (mem->validation_bits & CPER_MEM_VALID_DEVICE)
  245. n += scnprintf(msg + n, len - n, "device:%d ", mem->device);
  246. if (mem->validation_bits & (CPER_MEM_VALID_ROW | CPER_MEM_VALID_ROW_EXT)) {
  247. u32 row = mem->row;
  248. row |= cper_get_mem_extension(mem->validation_bits, mem->extended);
  249. n += scnprintf(msg + n, len - n, "row:%d ", row);
  250. }
  251. if (mem->validation_bits & CPER_MEM_VALID_COLUMN)
  252. n += scnprintf(msg + n, len - n, "column:%d ", mem->column);
  253. if (mem->validation_bits & CPER_MEM_VALID_BIT_POSITION)
  254. n += scnprintf(msg + n, len - n, "bit_position:%d ",
  255. mem->bit_pos);
  256. if (mem->validation_bits & CPER_MEM_VALID_REQUESTOR_ID)
  257. n += scnprintf(msg + n, len - n, "requestor_id:0x%016llx ",
  258. mem->requestor_id);
  259. if (mem->validation_bits & CPER_MEM_VALID_RESPONDER_ID)
  260. n += scnprintf(msg + n, len - n, "responder_id:0x%016llx ",
  261. mem->responder_id);
  262. if (mem->validation_bits & CPER_MEM_VALID_TARGET_ID)
  263. n += scnprintf(msg + n, len - n, "target_id:0x%016llx ",
  264. mem->target_id);
  265. if (mem->validation_bits & CPER_MEM_VALID_CHIP_ID)
  266. n += scnprintf(msg + n, len - n, "chip_id:%d ",
  267. mem->extended >> CPER_MEM_CHIP_ID_SHIFT);
  268. return n;
  269. }
  270. int cper_dimm_err_location(struct cper_mem_err_compact *mem, char *msg)
  271. {
  272. u32 len, n;
  273. const char *bank = NULL, *device = NULL;
  274. if (!msg || !(mem->validation_bits & CPER_MEM_VALID_MODULE_HANDLE))
  275. return 0;
  276. len = CPER_REC_LEN;
  277. dmi_memdev_name(mem->mem_dev_handle, &bank, &device);
  278. if (bank && device)
  279. n = snprintf(msg, len, "DIMM location: %s %s ", bank, device);
  280. else
  281. n = snprintf(msg, len,
  282. "DIMM location: not present. DMI handle: 0x%.4x ",
  283. mem->mem_dev_handle);
  284. return n;
  285. }
  286. void cper_mem_err_pack(const struct cper_sec_mem_err *mem,
  287. struct cper_mem_err_compact *cmem)
  288. {
  289. cmem->validation_bits = mem->validation_bits;
  290. cmem->node = mem->node;
  291. cmem->card = mem->card;
  292. cmem->module = mem->module;
  293. cmem->bank = mem->bank;
  294. cmem->device = mem->device;
  295. cmem->row = mem->row;
  296. cmem->column = mem->column;
  297. cmem->bit_pos = mem->bit_pos;
  298. cmem->requestor_id = mem->requestor_id;
  299. cmem->responder_id = mem->responder_id;
  300. cmem->target_id = mem->target_id;
  301. cmem->extended = mem->extended;
  302. cmem->rank = mem->rank;
  303. cmem->mem_array_handle = mem->mem_array_handle;
  304. cmem->mem_dev_handle = mem->mem_dev_handle;
  305. }
  306. const char *cper_mem_err_unpack(struct trace_seq *p,
  307. struct cper_mem_err_compact *cmem)
  308. {
  309. const char *ret = trace_seq_buffer_ptr(p);
  310. char rcd_decode_str[CPER_REC_LEN];
  311. if (cper_mem_err_location(cmem, rcd_decode_str))
  312. trace_seq_printf(p, "%s", rcd_decode_str);
  313. if (cper_dimm_err_location(cmem, rcd_decode_str))
  314. trace_seq_printf(p, "%s", rcd_decode_str);
  315. trace_seq_putc(p, '\0');
  316. return ret;
  317. }
  318. static void cper_print_mem(const char *pfx, const struct cper_sec_mem_err *mem,
  319. int len)
  320. {
  321. struct cper_mem_err_compact cmem;
  322. char rcd_decode_str[CPER_REC_LEN];
  323. /* Don't trust UEFI 2.1/2.2 structure with bad validation bits */
  324. if (len == sizeof(struct cper_sec_mem_err_old) &&
  325. (mem->validation_bits & ~(CPER_MEM_VALID_RANK_NUMBER - 1))) {
  326. pr_err(FW_WARN "valid bits set for fields beyond structure\n");
  327. return;
  328. }
  329. if (mem->validation_bits & CPER_MEM_VALID_ERROR_STATUS)
  330. printk("%s error_status: %s (0x%016llx)\n",
  331. pfx, cper_mem_err_status_str(mem->error_status),
  332. mem->error_status);
  333. if (mem->validation_bits & CPER_MEM_VALID_PA)
  334. printk("%s""physical_address: 0x%016llx\n",
  335. pfx, mem->physical_addr);
  336. if (mem->validation_bits & CPER_MEM_VALID_PA_MASK)
  337. printk("%s""physical_address_mask: 0x%016llx\n",
  338. pfx, mem->physical_addr_mask);
  339. cper_mem_err_pack(mem, &cmem);
  340. if (cper_mem_err_location(&cmem, rcd_decode_str))
  341. printk("%s%s\n", pfx, rcd_decode_str);
  342. if (mem->validation_bits & CPER_MEM_VALID_ERROR_TYPE) {
  343. u8 etype = mem->error_type;
  344. printk("%s""error_type: %d, %s\n", pfx, etype,
  345. cper_mem_err_type_str(etype));
  346. }
  347. if (cper_dimm_err_location(&cmem, rcd_decode_str))
  348. printk("%s%s\n", pfx, rcd_decode_str);
  349. }
  350. static const char * const pcie_port_type_strs[] = {
  351. "PCIe end point",
  352. "legacy PCI end point",
  353. "unknown",
  354. "unknown",
  355. "root port",
  356. "upstream switch port",
  357. "downstream switch port",
  358. "PCIe to PCI/PCI-X bridge",
  359. "PCI/PCI-X to PCIe bridge",
  360. "root complex integrated endpoint device",
  361. "root complex event collector",
  362. };
  363. static void cper_print_pcie(const char *pfx, const struct cper_sec_pcie *pcie,
  364. const struct acpi_hest_generic_data *gdata)
  365. {
  366. if (pcie->validation_bits & CPER_PCIE_VALID_PORT_TYPE)
  367. printk("%s""port_type: %d, %s\n", pfx, pcie->port_type,
  368. pcie->port_type < ARRAY_SIZE(pcie_port_type_strs) ?
  369. pcie_port_type_strs[pcie->port_type] : "unknown");
  370. if (pcie->validation_bits & CPER_PCIE_VALID_VERSION)
  371. printk("%s""version: %d.%d\n", pfx,
  372. pcie->version.major, pcie->version.minor);
  373. if (pcie->validation_bits & CPER_PCIE_VALID_COMMAND_STATUS)
  374. printk("%s""command: 0x%04x, status: 0x%04x\n", pfx,
  375. pcie->command, pcie->status);
  376. if (pcie->validation_bits & CPER_PCIE_VALID_DEVICE_ID) {
  377. const __u8 *p;
  378. printk("%s""device_id: %04x:%02x:%02x.%x\n", pfx,
  379. pcie->device_id.segment, pcie->device_id.bus,
  380. pcie->device_id.device, pcie->device_id.function);
  381. printk("%s""slot: %d\n", pfx,
  382. pcie->device_id.slot >> CPER_PCIE_SLOT_SHIFT);
  383. printk("%s""secondary_bus: 0x%02x\n", pfx,
  384. pcie->device_id.secondary_bus);
  385. printk("%s""vendor_id: 0x%04x, device_id: 0x%04x\n", pfx,
  386. pcie->device_id.vendor_id, pcie->device_id.device_id);
  387. p = pcie->device_id.class_code;
  388. printk("%s""class_code: %02x%02x%02x\n", pfx, p[2], p[1], p[0]);
  389. }
  390. if (pcie->validation_bits & CPER_PCIE_VALID_SERIAL_NUMBER)
  391. printk("%s""serial number: 0x%04x, 0x%04x\n", pfx,
  392. pcie->serial_number.lower, pcie->serial_number.upper);
  393. if (pcie->validation_bits & CPER_PCIE_VALID_BRIDGE_CONTROL_STATUS)
  394. printk(
  395. "%s""bridge: secondary_status: 0x%04x, control: 0x%04x\n",
  396. pfx, pcie->bridge.secondary_status, pcie->bridge.control);
  397. /* Fatal errors call __ghes_panic() before AER handler prints this */
  398. if ((pcie->validation_bits & CPER_PCIE_VALID_AER_INFO) &&
  399. (gdata->error_severity & CPER_SEV_FATAL)) {
  400. struct aer_capability_regs *aer;
  401. aer = (struct aer_capability_regs *)pcie->aer_info;
  402. printk("%saer_uncor_status: 0x%08x, aer_uncor_mask: 0x%08x\n",
  403. pfx, aer->uncor_status, aer->uncor_mask);
  404. printk("%saer_uncor_severity: 0x%08x\n",
  405. pfx, aer->uncor_severity);
  406. printk("%sTLP Header: %08x %08x %08x %08x\n", pfx,
  407. aer->header_log.dw0, aer->header_log.dw1,
  408. aer->header_log.dw2, aer->header_log.dw3);
  409. }
  410. }
  411. static const char * const fw_err_rec_type_strs[] = {
  412. "IPF SAL Error Record",
  413. "SOC Firmware Error Record Type1 (Legacy CrashLog Support)",
  414. "SOC Firmware Error Record Type2",
  415. };
  416. static void cper_print_fw_err(const char *pfx,
  417. struct acpi_hest_generic_data *gdata,
  418. const struct cper_sec_fw_err_rec_ref *fw_err)
  419. {
  420. void *buf = acpi_hest_get_payload(gdata);
  421. u32 offset, length = gdata->error_data_length;
  422. printk("%s""Firmware Error Record Type: %s\n", pfx,
  423. fw_err->record_type < ARRAY_SIZE(fw_err_rec_type_strs) ?
  424. fw_err_rec_type_strs[fw_err->record_type] : "unknown");
  425. printk("%s""Revision: %d\n", pfx, fw_err->revision);
  426. /* Record Type based on UEFI 2.7 */
  427. if (fw_err->revision == 0) {
  428. printk("%s""Record Identifier: %08llx\n", pfx,
  429. fw_err->record_identifier);
  430. } else if (fw_err->revision == 2) {
  431. printk("%s""Record Identifier: %pUl\n", pfx,
  432. &fw_err->record_identifier_guid);
  433. }
  434. /*
  435. * The FW error record may contain trailing data beyond the
  436. * structure defined by the specification. As the fields
  437. * defined (and hence the offset of any trailing data) vary
  438. * with the revision, set the offset to account for this
  439. * variation.
  440. */
  441. if (fw_err->revision == 0) {
  442. /* record_identifier_guid not defined */
  443. offset = offsetof(struct cper_sec_fw_err_rec_ref,
  444. record_identifier_guid);
  445. } else if (fw_err->revision == 1) {
  446. /* record_identifier not defined */
  447. offset = offsetof(struct cper_sec_fw_err_rec_ref,
  448. record_identifier);
  449. } else {
  450. offset = sizeof(*fw_err);
  451. }
  452. buf += offset;
  453. length -= offset;
  454. print_hex_dump(pfx, "", DUMP_PREFIX_OFFSET, 16, 4, buf, length, true);
  455. }
  456. static void cper_print_tstamp(const char *pfx,
  457. struct acpi_hest_generic_data_v300 *gdata)
  458. {
  459. __u8 hour, min, sec, day, mon, year, century, *timestamp;
  460. if (gdata->validation_bits & ACPI_HEST_GEN_VALID_TIMESTAMP) {
  461. timestamp = (__u8 *)&(gdata->time_stamp);
  462. sec = bcd2bin(timestamp[0]);
  463. min = bcd2bin(timestamp[1]);
  464. hour = bcd2bin(timestamp[2]);
  465. day = bcd2bin(timestamp[4]);
  466. mon = bcd2bin(timestamp[5]);
  467. year = bcd2bin(timestamp[6]);
  468. century = bcd2bin(timestamp[7]);
  469. printk("%s%ststamp: %02d%02d-%02d-%02d %02d:%02d:%02d\n", pfx,
  470. (timestamp[3] & 0x1 ? "precise " : "imprecise "),
  471. century, year, mon, day, hour, min, sec);
  472. }
  473. }
  474. static void
  475. cper_estatus_print_section(const char *pfx, struct acpi_hest_generic_data *gdata,
  476. int sec_no)
  477. {
  478. guid_t *sec_type = (guid_t *)gdata->section_type;
  479. __u16 severity;
  480. char newpfx[64];
  481. if (acpi_hest_get_version(gdata) >= 3)
  482. cper_print_tstamp(pfx, (struct acpi_hest_generic_data_v300 *)gdata);
  483. severity = gdata->error_severity;
  484. printk("%s""Error %d, type: %s\n", pfx, sec_no,
  485. cper_severity_str(severity));
  486. if (gdata->validation_bits & CPER_SEC_VALID_FRU_ID)
  487. printk("%s""fru_id: %pUl\n", pfx, gdata->fru_id);
  488. if (gdata->validation_bits & CPER_SEC_VALID_FRU_TEXT)
  489. printk("%s""fru_text: %.20s\n", pfx, gdata->fru_text);
  490. snprintf(newpfx, sizeof(newpfx), "%s ", pfx);
  491. if (guid_equal(sec_type, &CPER_SEC_PROC_GENERIC)) {
  492. struct cper_sec_proc_generic *proc_err = acpi_hest_get_payload(gdata);
  493. printk("%s""section_type: general processor error\n", newpfx);
  494. if (gdata->error_data_length >= sizeof(*proc_err))
  495. cper_print_proc_generic(newpfx, proc_err);
  496. else
  497. goto err_section_too_small;
  498. } else if (guid_equal(sec_type, &CPER_SEC_PLATFORM_MEM)) {
  499. struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata);
  500. printk("%s""section_type: memory error\n", newpfx);
  501. if (gdata->error_data_length >=
  502. sizeof(struct cper_sec_mem_err_old))
  503. cper_print_mem(newpfx, mem_err,
  504. gdata->error_data_length);
  505. else
  506. goto err_section_too_small;
  507. } else if (guid_equal(sec_type, &CPER_SEC_PCIE)) {
  508. struct cper_sec_pcie *pcie = acpi_hest_get_payload(gdata);
  509. printk("%s""section_type: PCIe error\n", newpfx);
  510. if (gdata->error_data_length >= sizeof(*pcie))
  511. cper_print_pcie(newpfx, pcie, gdata);
  512. else
  513. goto err_section_too_small;
  514. #if defined(CONFIG_ARM64) || defined(CONFIG_ARM)
  515. } else if (guid_equal(sec_type, &CPER_SEC_PROC_ARM)) {
  516. struct cper_sec_proc_arm *arm_err = acpi_hest_get_payload(gdata);
  517. printk("%ssection_type: ARM processor error\n", newpfx);
  518. if (gdata->error_data_length >= sizeof(*arm_err))
  519. cper_print_proc_arm(newpfx, arm_err);
  520. else
  521. goto err_section_too_small;
  522. #endif
  523. #if defined(CONFIG_UEFI_CPER_X86)
  524. } else if (guid_equal(sec_type, &CPER_SEC_PROC_IA)) {
  525. struct cper_sec_proc_ia *ia_err = acpi_hest_get_payload(gdata);
  526. printk("%ssection_type: IA32/X64 processor error\n", newpfx);
  527. if (gdata->error_data_length >= sizeof(*ia_err))
  528. cper_print_proc_ia(newpfx, ia_err);
  529. else
  530. goto err_section_too_small;
  531. #endif
  532. } else if (guid_equal(sec_type, &CPER_SEC_FW_ERR_REC_REF)) {
  533. struct cper_sec_fw_err_rec_ref *fw_err = acpi_hest_get_payload(gdata);
  534. printk("%ssection_type: Firmware Error Record Reference\n",
  535. newpfx);
  536. /* The minimal FW Error Record contains 16 bytes */
  537. if (gdata->error_data_length >= SZ_16)
  538. cper_print_fw_err(newpfx, gdata, fw_err);
  539. else
  540. goto err_section_too_small;
  541. } else {
  542. const void *err = acpi_hest_get_payload(gdata);
  543. printk("%ssection type: unknown, %pUl\n", newpfx, sec_type);
  544. printk("%ssection length: %#x\n", newpfx,
  545. gdata->error_data_length);
  546. print_hex_dump(newpfx, "", DUMP_PREFIX_OFFSET, 16, 4, err,
  547. gdata->error_data_length, true);
  548. }
  549. return;
  550. err_section_too_small:
  551. pr_err(FW_WARN "error section length is too small\n");
  552. }
  553. void cper_estatus_print(const char *pfx,
  554. const struct acpi_hest_generic_status *estatus)
  555. {
  556. struct acpi_hest_generic_data *gdata;
  557. int sec_no = 0;
  558. char newpfx[64];
  559. __u16 severity;
  560. severity = estatus->error_severity;
  561. if (severity == CPER_SEV_CORRECTED)
  562. printk("%s%s\n", pfx,
  563. "It has been corrected by h/w "
  564. "and requires no further action");
  565. printk("%s""event severity: %s\n", pfx, cper_severity_str(severity));
  566. snprintf(newpfx, sizeof(newpfx), "%s ", pfx);
  567. apei_estatus_for_each_section(estatus, gdata) {
  568. cper_estatus_print_section(newpfx, gdata, sec_no);
  569. sec_no++;
  570. }
  571. }
  572. EXPORT_SYMBOL_GPL(cper_estatus_print);
  573. int cper_estatus_check_header(const struct acpi_hest_generic_status *estatus)
  574. {
  575. if (estatus->data_length &&
  576. estatus->data_length < sizeof(struct acpi_hest_generic_data))
  577. return -EINVAL;
  578. if (estatus->raw_data_length &&
  579. estatus->raw_data_offset < sizeof(*estatus) + estatus->data_length)
  580. return -EINVAL;
  581. return 0;
  582. }
  583. EXPORT_SYMBOL_GPL(cper_estatus_check_header);
  584. int cper_estatus_check(const struct acpi_hest_generic_status *estatus)
  585. {
  586. struct acpi_hest_generic_data *gdata;
  587. unsigned int data_len, record_size;
  588. int rc;
  589. rc = cper_estatus_check_header(estatus);
  590. if (rc)
  591. return rc;
  592. data_len = estatus->data_length;
  593. apei_estatus_for_each_section(estatus, gdata) {
  594. if (acpi_hest_get_size(gdata) > data_len)
  595. return -EINVAL;
  596. record_size = acpi_hest_get_record_size(gdata);
  597. if (record_size > data_len)
  598. return -EINVAL;
  599. data_len -= record_size;
  600. }
  601. if (data_len)
  602. return -EINVAL;
  603. return 0;
  604. }
  605. EXPORT_SYMBOL_GPL(cper_estatus_check);