cper.c 20.9 KB
Newer Older
1 2 3 4 5 6 7
/*
 * UEFI Common Platform Error Record (CPER) support
 *
 * Copyright (C) 2010, Intel Corp.
 *	Author: Huang Ying <ying.huang@intel.com>
 *
 * CPER is the format used to describe platform hardware error by
C
Chen, Gong 已提交
8
 * various tables, such as ERST, BERT and HEST etc.
9 10
 *
 * For more information about CPER, please refer to Appendix N of UEFI
11
 * Specification version 2.4.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version
 * 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/time.h>
#include <linux/cper.h>
31
#include <linux/dmi.h>
32
#include <linux/acpi.h>
L
Lance Ortiz 已提交
33
#include <linux/pci.h>
34
#include <linux/aer.h>
35 36
#include <linux/printk.h>
#include <linux/bcd.h>
37
#include <acpi/ghes.h>
38

39
#define INDENT_SP	" "
40 41 42

static char rcd_decode_str[CPER_REC_LEN];

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
/*
 * CPER record ID need to be unique even after reboot, because record
 * ID is used as index for ERST storage, while CPER records from
 * multiple boot may co-exist in ERST.
 */
u64 cper_next_record_id(void)
{
	static atomic64_t seq;

	if (!atomic64_read(&seq))
		atomic64_set(&seq, ((u64)get_seconds()) << 32);

	return atomic64_inc_return(&seq);
}
EXPORT_SYMBOL_GPL(cper_next_record_id);

59
static const char * const severity_strs[] = {
60 61 62 63 64 65
	"recoverable",
	"fatal",
	"corrected",
	"info",
};

66
const char *cper_severity_str(unsigned int severity)
67
{
68 69
	return severity < ARRAY_SIZE(severity_strs) ?
		severity_strs[severity] : "unknown";
70
}
71
EXPORT_SYMBOL_GPL(cper_severity_str);
72 73 74 75 76 77 78 79 80 81 82 83

/*
 * cper_print_bits - print strings for set bits
 * @pfx: prefix for each line, including log level and prefix string
 * @bits: bit mask
 * @strs: string array, indexed by bit position
 * @strs_size: size of the string array: @strs
 *
 * For each set bit in @bits, print the corresponding string in @strs.
 * If the output length is longer than 80, multiple line will be
 * printed, with @pfx is printed at the beginning of each line.
 */
84
void cper_print_bits(const char *pfx, unsigned int bits,
C
Chen, Gong 已提交
85
		     const char * const strs[], unsigned int strs_size)
86 87 88 89 90 91 92 93 94
{
	int i, len = 0;
	const char *str;
	char buf[84];

	for (i = 0; i < strs_size; i++) {
		if (!(bits & (1U << i)))
			continue;
		str = strs[i];
95 96
		if (!str)
			continue;
97 98 99 100 101 102 103 104 105 106 107 108 109
		if (len && len + strlen(str) + 2 > 80) {
			printk("%s\n", buf);
			len = 0;
		}
		if (!len)
			len = snprintf(buf, sizeof(buf), "%s%s", pfx, str);
		else
			len += snprintf(buf+len, sizeof(buf)-len, ", %s", str);
	}
	if (len)
		printk("%s\n", buf);
}

110
static const char * const proc_type_strs[] = {
111 112
	"IA32/X64",
	"IA64",
T
Tyler Baicar 已提交
113
	"ARM",
114 115
};

116
static const char * const proc_isa_strs[] = {
117 118 119
	"IA32",
	"IA64",
	"X64",
T
Tyler Baicar 已提交
120 121
	"ARM A32/T32",
	"ARM A64",
122 123
};

124
static const char * const proc_error_type_strs[] = {
125 126 127 128 129 130
	"cache error",
	"TLB error",
	"bus error",
	"micro-architectural error",
};

131
static const char * const proc_op_strs[] = {
132 133 134 135 136 137
	"unknown or generic",
	"data read",
	"data write",
	"instruction execution",
};

138
static const char * const proc_flag_strs[] = {
139 140 141 142 143 144 145 146 147 148 149
	"restartable",
	"precise IP",
	"overflow",
	"corrected",
};

static void cper_print_proc_generic(const char *pfx,
				    const struct cper_sec_proc_generic *proc)
{
	if (proc->validation_bits & CPER_PROC_VALID_TYPE)
		printk("%s""processor_type: %d, %s\n", pfx, proc->proc_type,
150 151
		       proc->proc_type < ARRAY_SIZE(proc_type_strs) ?
		       proc_type_strs[proc->proc_type] : "unknown");
152 153
	if (proc->validation_bits & CPER_PROC_VALID_ISA)
		printk("%s""processor_isa: %d, %s\n", pfx, proc->proc_isa,
154 155
		       proc->proc_isa < ARRAY_SIZE(proc_isa_strs) ?
		       proc_isa_strs[proc->proc_isa] : "unknown");
156 157 158
	if (proc->validation_bits & CPER_PROC_VALID_ERROR_TYPE) {
		printk("%s""error_type: 0x%02x\n", pfx, proc->proc_error_type);
		cper_print_bits(pfx, proc->proc_error_type,
159 160
				proc_error_type_strs,
				ARRAY_SIZE(proc_error_type_strs));
161 162 163
	}
	if (proc->validation_bits & CPER_PROC_VALID_OPERATION)
		printk("%s""operation: %d, %s\n", pfx, proc->operation,
164 165
		       proc->operation < ARRAY_SIZE(proc_op_strs) ?
		       proc_op_strs[proc->operation] : "unknown");
166 167
	if (proc->validation_bits & CPER_PROC_VALID_FLAGS) {
		printk("%s""flags: 0x%02x\n", pfx, proc->flags);
168 169
		cper_print_bits(pfx, proc->flags, proc_flag_strs,
				ARRAY_SIZE(proc_flag_strs));
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
	}
	if (proc->validation_bits & CPER_PROC_VALID_LEVEL)
		printk("%s""level: %d\n", pfx, proc->level);
	if (proc->validation_bits & CPER_PROC_VALID_VERSION)
		printk("%s""version_info: 0x%016llx\n", pfx, proc->cpu_version);
	if (proc->validation_bits & CPER_PROC_VALID_ID)
		printk("%s""processor_id: 0x%016llx\n", pfx, proc->proc_id);
	if (proc->validation_bits & CPER_PROC_VALID_TARGET_ADDRESS)
		printk("%s""target_address: 0x%016llx\n",
		       pfx, proc->target_addr);
	if (proc->validation_bits & CPER_PROC_VALID_REQUESTOR_ID)
		printk("%s""requestor_id: 0x%016llx\n",
		       pfx, proc->requestor_id);
	if (proc->validation_bits & CPER_PROC_VALID_RESPONDER_ID)
		printk("%s""responder_id: 0x%016llx\n",
		       pfx, proc->responder_id);
	if (proc->validation_bits & CPER_PROC_VALID_IP)
		printk("%s""IP: 0x%016llx\n", pfx, proc->ip);
}

T
Tyler Baicar 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
#if defined(CONFIG_ARM64) || defined(CONFIG_ARM)
static const char * const arm_reg_ctx_strs[] = {
	"AArch32 general purpose registers",
	"AArch32 EL1 context registers",
	"AArch32 EL2 context registers",
	"AArch32 secure context registers",
	"AArch64 general purpose registers",
	"AArch64 EL1 context registers",
	"AArch64 EL2 context registers",
	"AArch64 EL3 context registers",
	"Misc. system register structure",
};

static void cper_print_proc_arm(const char *pfx,
				const struct cper_sec_proc_arm *proc)
{
	int i, len, max_ctx_type;
	struct cper_arm_err_info *err_info;
	struct cper_arm_ctx_info *ctx_info;
	char newpfx[64];

	printk("%sMIDR: 0x%016llx\n", pfx, proc->midr);

	len = proc->section_length - (sizeof(*proc) +
		proc->err_info_num * (sizeof(*err_info)));
	if (len < 0) {
		printk("%ssection length: %d\n", pfx, proc->section_length);
		printk("%ssection length is too small\n", pfx);
		printk("%sfirmware-generated error record is incorrect\n", pfx);
		printk("%sERR_INFO_NUM is %d\n", pfx, proc->err_info_num);
		return;
	}

	if (proc->validation_bits & CPER_ARM_VALID_MPIDR)
		printk("%sMultiprocessor Affinity Register (MPIDR): 0x%016llx\n",
			pfx, proc->mpidr);

	if (proc->validation_bits & CPER_ARM_VALID_AFFINITY_LEVEL)
		printk("%serror affinity level: %d\n", pfx,
			proc->affinity_level);

	if (proc->validation_bits & CPER_ARM_VALID_RUNNING_STATE) {
		printk("%srunning state: 0x%x\n", pfx, proc->running_state);
		printk("%sPower State Coordination Interface state: %d\n",
			pfx, proc->psci_state);
	}

	snprintf(newpfx, sizeof(newpfx), "%s%s", pfx, INDENT_SP);

	err_info = (struct cper_arm_err_info *)(proc + 1);
	for (i = 0; i < proc->err_info_num; i++) {
		printk("%sError info structure %d:\n", pfx, i);

		printk("%snum errors: %d\n", pfx, err_info->multiple_error + 1);

		if (err_info->validation_bits & CPER_ARM_INFO_VALID_FLAGS) {
			if (err_info->flags & CPER_ARM_INFO_FLAGS_FIRST)
				printk("%sfirst error captured\n", newpfx);
			if (err_info->flags & CPER_ARM_INFO_FLAGS_LAST)
				printk("%slast error captured\n", newpfx);
			if (err_info->flags & CPER_ARM_INFO_FLAGS_PROPAGATED)
				printk("%spropagated error captured\n",
				       newpfx);
			if (err_info->flags & CPER_ARM_INFO_FLAGS_OVERFLOW)
				printk("%soverflow occurred, error info is incomplete\n",
				       newpfx);
		}

		printk("%serror_type: %d, %s\n", newpfx, err_info->type,
			err_info->type < ARRAY_SIZE(proc_error_type_strs) ?
			proc_error_type_strs[err_info->type] : "unknown");
		if (err_info->validation_bits & CPER_ARM_INFO_VALID_ERR_INFO)
			printk("%serror_info: 0x%016llx\n", newpfx,
			       err_info->error_info);
		if (err_info->validation_bits & CPER_ARM_INFO_VALID_VIRT_ADDR)
			printk("%svirtual fault address: 0x%016llx\n",
				newpfx, err_info->virt_fault_addr);
		if (err_info->validation_bits & CPER_ARM_INFO_VALID_PHYSICAL_ADDR)
			printk("%sphysical fault address: 0x%016llx\n",
				newpfx, err_info->physical_fault_addr);
		err_info += 1;
	}

	ctx_info = (struct cper_arm_ctx_info *)err_info;
	max_ctx_type = ARRAY_SIZE(arm_reg_ctx_strs) - 1;
	for (i = 0; i < proc->context_info_num; i++) {
		int size = sizeof(*ctx_info) + ctx_info->size;

		printk("%sContext info structure %d:\n", pfx, i);
		if (len < size) {
			printk("%ssection length is too small\n", newpfx);
			printk("%sfirmware-generated error record is incorrect\n", pfx);
			return;
		}
		if (ctx_info->type > max_ctx_type) {
			printk("%sInvalid context type: %d (max: %d)\n",
				newpfx, ctx_info->type, max_ctx_type);
			return;
		}
		printk("%sregister context type: %s\n", newpfx,
			arm_reg_ctx_strs[ctx_info->type]);
		print_hex_dump(newpfx, "", DUMP_PREFIX_OFFSET, 16, 4,
				(ctx_info + 1), ctx_info->size, 0);
		len -= size;
		ctx_info = (struct cper_arm_ctx_info *)((long)ctx_info + size);
	}

	if (len > 0) {
		printk("%sVendor specific error info has %u bytes:\n", pfx,
		       len);
		print_hex_dump(newpfx, "", DUMP_PREFIX_OFFSET, 16, 4, ctx_info,
				len, true);
	}
}
#endif

306
static const char * const mem_err_type_strs[] = {
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
	"unknown",
	"no error",
	"single-bit ECC",
	"multi-bit ECC",
	"single-symbol chipkill ECC",
	"multi-symbol chipkill ECC",
	"master abort",
	"target abort",
	"parity error",
	"watchdog timeout",
	"invalid address",
	"mirror Broken",
	"memory sparing",
	"scrub corrected error",
	"scrub uncorrected error",
322
	"physical memory map-out event",
323 324
};

325
const char *cper_mem_err_type_str(unsigned int etype)
326
{
327 328 329 330 331
	return etype < ARRAY_SIZE(mem_err_type_strs) ?
		mem_err_type_strs[etype] : "unknown";
}
EXPORT_SYMBOL_GPL(cper_mem_err_type_str);

332
static int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg)
333 334 335 336 337 338 339 340
{
	u32 len, n;

	if (!msg)
		return 0;

	n = 0;
	len = CPER_REC_LEN - 1;
341
	if (mem->validation_bits & CPER_MEM_VALID_NODE)
342
		n += scnprintf(msg + n, len - n, "node: %d ", mem->node);
343
	if (mem->validation_bits & CPER_MEM_VALID_CARD)
344
		n += scnprintf(msg + n, len - n, "card: %d ", mem->card);
345
	if (mem->validation_bits & CPER_MEM_VALID_MODULE)
346
		n += scnprintf(msg + n, len - n, "module: %d ", mem->module);
347
	if (mem->validation_bits & CPER_MEM_VALID_RANK_NUMBER)
348
		n += scnprintf(msg + n, len - n, "rank: %d ", mem->rank);
349
	if (mem->validation_bits & CPER_MEM_VALID_BANK)
350
		n += scnprintf(msg + n, len - n, "bank: %d ", mem->bank);
351
	if (mem->validation_bits & CPER_MEM_VALID_DEVICE)
352
		n += scnprintf(msg + n, len - n, "device: %d ", mem->device);
353
	if (mem->validation_bits & CPER_MEM_VALID_ROW)
354
		n += scnprintf(msg + n, len - n, "row: %d ", mem->row);
355
	if (mem->validation_bits & CPER_MEM_VALID_COLUMN)
356
		n += scnprintf(msg + n, len - n, "column: %d ", mem->column);
357
	if (mem->validation_bits & CPER_MEM_VALID_BIT_POSITION)
358 359
		n += scnprintf(msg + n, len - n, "bit_position: %d ",
			       mem->bit_pos);
360
	if (mem->validation_bits & CPER_MEM_VALID_REQUESTOR_ID)
361 362
		n += scnprintf(msg + n, len - n, "requestor_id: 0x%016llx ",
			       mem->requestor_id);
363
	if (mem->validation_bits & CPER_MEM_VALID_RESPONDER_ID)
364 365
		n += scnprintf(msg + n, len - n, "responder_id: 0x%016llx ",
			       mem->responder_id);
366
	if (mem->validation_bits & CPER_MEM_VALID_TARGET_ID)
367 368 369 370 371 372 373
		scnprintf(msg + n, len - n, "target_id: 0x%016llx ",
			  mem->target_id);

	msg[n] = '\0';
	return n;
}

374
static int cper_dimm_err_location(struct cper_mem_err_compact *mem, char *msg)
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
{
	u32 len, n;
	const char *bank = NULL, *device = NULL;

	if (!msg || !(mem->validation_bits & CPER_MEM_VALID_MODULE_HANDLE))
		return 0;

	n = 0;
	len = CPER_REC_LEN - 1;
	dmi_memdev_name(mem->mem_dev_handle, &bank, &device);
	if (bank && device)
		n = snprintf(msg, len, "DIMM location: %s %s ", bank, device);
	else
		n = snprintf(msg, len,
			     "DIMM location: not present. DMI handle: 0x%.4x ",
			     mem->mem_dev_handle);

	msg[n] = '\0';
	return n;
}

396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
void cper_mem_err_pack(const struct cper_sec_mem_err *mem,
		       struct cper_mem_err_compact *cmem)
{
	cmem->validation_bits = mem->validation_bits;
	cmem->node = mem->node;
	cmem->card = mem->card;
	cmem->module = mem->module;
	cmem->bank = mem->bank;
	cmem->device = mem->device;
	cmem->row = mem->row;
	cmem->column = mem->column;
	cmem->bit_pos = mem->bit_pos;
	cmem->requestor_id = mem->requestor_id;
	cmem->responder_id = mem->responder_id;
	cmem->target_id = mem->target_id;
	cmem->rank = mem->rank;
	cmem->mem_array_handle = mem->mem_array_handle;
	cmem->mem_dev_handle = mem->mem_dev_handle;
}

const char *cper_mem_err_unpack(struct trace_seq *p,
				struct cper_mem_err_compact *cmem)
{
419
	const char *ret = trace_seq_buffer_ptr(p);
420 421 422 423 424 425 426 427 428 429

	if (cper_mem_err_location(cmem, rcd_decode_str))
		trace_seq_printf(p, "%s", rcd_decode_str);
	if (cper_dimm_err_location(cmem, rcd_decode_str))
		trace_seq_printf(p, "%s", rcd_decode_str);
	trace_seq_putc(p, '\0');

	return ret;
}

430 431
static void cper_print_mem(const char *pfx, const struct cper_sec_mem_err *mem,
	int len)
432
{
433 434
	struct cper_mem_err_compact cmem;

435 436 437 438 439 440
	/* Don't trust UEFI 2.1/2.2 structure with bad validation bits */
	if (len == sizeof(struct cper_sec_mem_err_old) &&
	    (mem->validation_bits & ~(CPER_MEM_VALID_RANK_NUMBER - 1))) {
		pr_err(FW_WARN "valid bits set for fields beyond structure\n");
		return;
	}
441 442 443 444 445 446 447 448
	if (mem->validation_bits & CPER_MEM_VALID_ERROR_STATUS)
		printk("%s""error_status: 0x%016llx\n", pfx, mem->error_status);
	if (mem->validation_bits & CPER_MEM_VALID_PA)
		printk("%s""physical_address: 0x%016llx\n",
		       pfx, mem->physical_addr);
	if (mem->validation_bits & CPER_MEM_VALID_PA_MASK)
		printk("%s""physical_address_mask: 0x%016llx\n",
		       pfx, mem->physical_addr_mask);
449 450
	cper_mem_err_pack(mem, &cmem);
	if (cper_mem_err_location(&cmem, rcd_decode_str))
451
		printk("%s%s\n", pfx, rcd_decode_str);
452 453 454
	if (mem->validation_bits & CPER_MEM_VALID_ERROR_TYPE) {
		u8 etype = mem->error_type;
		printk("%s""error_type: %d, %s\n", pfx, etype,
455
		       cper_mem_err_type_str(etype));
456
	}
457
	if (cper_dimm_err_location(&cmem, rcd_decode_str))
458
		printk("%s%s\n", pfx, rcd_decode_str);
459 460
}

461
static const char * const pcie_port_type_strs[] = {
462 463 464 465 466 467 468 469 470 471 472 473 474
	"PCIe end point",
	"legacy PCI end point",
	"unknown",
	"unknown",
	"root port",
	"upstream switch port",
	"downstream switch port",
	"PCIe to PCI/PCI-X bridge",
	"PCI/PCI-X to PCIe bridge",
	"root complex integrated endpoint device",
	"root complex event collector",
};

475
static void cper_print_pcie(const char *pfx, const struct cper_sec_pcie *pcie,
476
			    const struct acpi_hest_generic_data *gdata)
477 478 479
{
	if (pcie->validation_bits & CPER_PCIE_VALID_PORT_TYPE)
		printk("%s""port_type: %d, %s\n", pfx, pcie->port_type,
480 481
		       pcie->port_type < ARRAY_SIZE(pcie_port_type_strs) ?
		       pcie_port_type_strs[pcie->port_type] : "unknown");
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
	if (pcie->validation_bits & CPER_PCIE_VALID_VERSION)
		printk("%s""version: %d.%d\n", pfx,
		       pcie->version.major, pcie->version.minor);
	if (pcie->validation_bits & CPER_PCIE_VALID_COMMAND_STATUS)
		printk("%s""command: 0x%04x, status: 0x%04x\n", pfx,
		       pcie->command, pcie->status);
	if (pcie->validation_bits & CPER_PCIE_VALID_DEVICE_ID) {
		const __u8 *p;
		printk("%s""device_id: %04x:%02x:%02x.%x\n", pfx,
		       pcie->device_id.segment, pcie->device_id.bus,
		       pcie->device_id.device, pcie->device_id.function);
		printk("%s""slot: %d\n", pfx,
		       pcie->device_id.slot >> CPER_PCIE_SLOT_SHIFT);
		printk("%s""secondary_bus: 0x%02x\n", pfx,
		       pcie->device_id.secondary_bus);
		printk("%s""vendor_id: 0x%04x, device_id: 0x%04x\n", pfx,
		       pcie->device_id.vendor_id, pcie->device_id.device_id);
		p = pcie->device_id.class_code;
		printk("%s""class_code: %02x%02x%02x\n", pfx, p[0], p[1], p[2]);
	}
	if (pcie->validation_bits & CPER_PCIE_VALID_SERIAL_NUMBER)
		printk("%s""serial number: 0x%04x, 0x%04x\n", pfx,
		       pcie->serial_number.lower, pcie->serial_number.upper);
	if (pcie->validation_bits & CPER_PCIE_VALID_BRIDGE_CONTROL_STATUS)
		printk(
	"%s""bridge: secondary_status: 0x%04x, control: 0x%04x\n",
	pfx, pcie->bridge.secondary_status, pcie->bridge.control);
}

511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
static void cper_print_tstamp(const char *pfx,
				   struct acpi_hest_generic_data_v300 *gdata)
{
	__u8 hour, min, sec, day, mon, year, century, *timestamp;

	if (gdata->validation_bits & ACPI_HEST_GEN_VALID_TIMESTAMP) {
		timestamp = (__u8 *)&(gdata->time_stamp);
		sec       = bcd2bin(timestamp[0]);
		min       = bcd2bin(timestamp[1]);
		hour      = bcd2bin(timestamp[2]);
		day       = bcd2bin(timestamp[4]);
		mon       = bcd2bin(timestamp[5]);
		year      = bcd2bin(timestamp[6]);
		century   = bcd2bin(timestamp[7]);

		printk("%s%ststamp: %02d%02d-%02d-%02d %02d:%02d:%02d\n", pfx,
		       (timestamp[3] & 0x1 ? "precise " : "imprecise "),
		       century, year, mon, day, hour, min, sec);
	}
}

532 533 534
static void
cper_estatus_print_section(const char *pfx, struct acpi_hest_generic_data *gdata,
			   int sec_no)
535 536 537
{
	uuid_le *sec_type = (uuid_le *)gdata->section_type;
	__u16 severity;
538
	char newpfx[64];
539

540 541 542
	if (acpi_hest_get_version(gdata) >= 3)
		cper_print_tstamp(pfx, (struct acpi_hest_generic_data_v300 *)gdata);

543
	severity = gdata->error_severity;
544
	printk("%s""Error %d, type: %s\n", pfx, sec_no,
545 546 547 548 549 550
	       cper_severity_str(severity));
	if (gdata->validation_bits & CPER_SEC_VALID_FRU_ID)
		printk("%s""fru_id: %pUl\n", pfx, (uuid_le *)gdata->fru_id);
	if (gdata->validation_bits & CPER_SEC_VALID_FRU_TEXT)
		printk("%s""fru_text: %.20s\n", pfx, gdata->fru_text);

551
	snprintf(newpfx, sizeof(newpfx), "%s%s", pfx, INDENT_SP);
552
	if (!uuid_le_cmp(*sec_type, CPER_SEC_PROC_GENERIC)) {
553 554
		struct cper_sec_proc_generic *proc_err = acpi_hest_get_payload(gdata);

555
		printk("%s""section_type: general processor error\n", newpfx);
556
		if (gdata->error_data_length >= sizeof(*proc_err))
557
			cper_print_proc_generic(newpfx, proc_err);
558 559 560
		else
			goto err_section_too_small;
	} else if (!uuid_le_cmp(*sec_type, CPER_SEC_PLATFORM_MEM)) {
561 562
		struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata);

563
		printk("%s""section_type: memory error\n", newpfx);
564 565 566 567
		if (gdata->error_data_length >=
		    sizeof(struct cper_sec_mem_err_old))
			cper_print_mem(newpfx, mem_err,
				       gdata->error_data_length);
568 569 570
		else
			goto err_section_too_small;
	} else if (!uuid_le_cmp(*sec_type, CPER_SEC_PCIE)) {
571 572
		struct cper_sec_pcie *pcie = acpi_hest_get_payload(gdata);

573
		printk("%s""section_type: PCIe error\n", newpfx);
574
		if (gdata->error_data_length >= sizeof(*pcie))
575
			cper_print_pcie(newpfx, pcie, gdata);
576 577
		else
			goto err_section_too_small;
T
Tyler Baicar 已提交
578 579 580 581 582 583 584 585 586 587
#if defined(CONFIG_ARM64) || defined(CONFIG_ARM)
	} else if (!uuid_le_cmp(*sec_type, CPER_SEC_PROC_ARM)) {
		struct cper_sec_proc_arm *arm_err = acpi_hest_get_payload(gdata);

		printk("%ssection_type: ARM processor error\n", newpfx);
		if (gdata->error_data_length >= sizeof(*arm_err))
			cper_print_proc_arm(newpfx, arm_err);
		else
			goto err_section_too_small;
#endif
588
	} else
589
		printk("%s""section type: unknown, %pUl\n", newpfx, sec_type);
590 591 592 593 594 595 596

	return;

err_section_too_small:
	pr_err(FW_WARN "error section length is too small\n");
}

C
Chen, Gong 已提交
597
void cper_estatus_print(const char *pfx,
598
			const struct acpi_hest_generic_status *estatus)
599
{
600
	struct acpi_hest_generic_data *gdata;
601
	unsigned int data_len;
602
	int sec_no = 0;
603
	char newpfx[64];
604 605 606
	__u16 severity;

	severity = estatus->error_severity;
607 608 609 610 611
	if (severity == CPER_SEV_CORRECTED)
		printk("%s%s\n", pfx,
		       "It has been corrected by h/w "
		       "and requires no further action");
	printk("%s""event severity: %s\n", pfx, cper_severity_str(severity));
612
	data_len = estatus->data_length;
613
	gdata = (struct acpi_hest_generic_data *)(estatus + 1);
614
	snprintf(newpfx, sizeof(newpfx), "%s%s", pfx, INDENT_SP);
615 616

	while (data_len >= acpi_hest_get_size(gdata)) {
617
		cper_estatus_print_section(newpfx, gdata, sec_no);
618 619
		data_len -= acpi_hest_get_record_size(gdata);
		gdata = acpi_hest_get_next(gdata);
620 621 622
		sec_no++;
	}
}
C
Chen, Gong 已提交
623
EXPORT_SYMBOL_GPL(cper_estatus_print);
624

625
int cper_estatus_check_header(const struct acpi_hest_generic_status *estatus)
626 627
{
	if (estatus->data_length &&
628
	    estatus->data_length < sizeof(struct acpi_hest_generic_data))
629 630 631 632 633 634 635
		return -EINVAL;
	if (estatus->raw_data_length &&
	    estatus->raw_data_offset < sizeof(*estatus) + estatus->data_length)
		return -EINVAL;

	return 0;
}
C
Chen, Gong 已提交
636
EXPORT_SYMBOL_GPL(cper_estatus_check_header);
637

638
int cper_estatus_check(const struct acpi_hest_generic_status *estatus)
639
{
640
	struct acpi_hest_generic_data *gdata;
641 642 643
	unsigned int data_len, gedata_len;
	int rc;

C
Chen, Gong 已提交
644
	rc = cper_estatus_check_header(estatus);
645 646 647
	if (rc)
		return rc;
	data_len = estatus->data_length;
648
	gdata = (struct acpi_hest_generic_data *)(estatus + 1);
649 650 651 652

	while (data_len >= acpi_hest_get_size(gdata)) {
		gedata_len = acpi_hest_get_error_length(gdata);
		if (gedata_len > data_len - acpi_hest_get_size(gdata))
653
			return -EINVAL;
654 655 656

		data_len -= acpi_hest_get_record_size(gdata);
		gdata = acpi_hest_get_next(gdata);
657 658 659 660 661 662
	}
	if (data_len)
		return -EINVAL;

	return 0;
}
C
Chen, Gong 已提交
663
EXPORT_SYMBOL_GPL(cper_estatus_check);