18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * UEFI Common Platform Error Record
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2010, Intel Corp.
68c2ecf20Sopenharmony_ci *	Author: Huang Ying <ying.huang@intel.com>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef LINUX_CPER_H
108c2ecf20Sopenharmony_ci#define LINUX_CPER_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/uuid.h>
138c2ecf20Sopenharmony_ci#include <linux/trace_seq.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/* CPER record signature and the size */
168c2ecf20Sopenharmony_ci#define CPER_SIG_RECORD				"CPER"
178c2ecf20Sopenharmony_ci#define CPER_SIG_SIZE				4
188c2ecf20Sopenharmony_ci/* Used in signature_end field in struct cper_record_header */
198c2ecf20Sopenharmony_ci#define CPER_SIG_END				0xffffffff
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/*
228c2ecf20Sopenharmony_ci * CPER record header revision, used in revision field in struct
238c2ecf20Sopenharmony_ci * cper_record_header
248c2ecf20Sopenharmony_ci */
258c2ecf20Sopenharmony_ci#define CPER_RECORD_REV				0x0100
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/*
288c2ecf20Sopenharmony_ci * CPER record length contains the CPER fields which are relevant for further
298c2ecf20Sopenharmony_ci * handling of a memory error in userspace (we don't carry all the fields
308c2ecf20Sopenharmony_ci * defined in the UEFI spec because some of them don't make any sense.)
318c2ecf20Sopenharmony_ci * Currently, a length of 256 should be more than enough.
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci#define CPER_REC_LEN					256
348c2ecf20Sopenharmony_ci/*
358c2ecf20Sopenharmony_ci * Severity definition for error_severity in struct cper_record_header
368c2ecf20Sopenharmony_ci * and section_severity in struct cper_section_descriptor
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_cienum {
398c2ecf20Sopenharmony_ci	CPER_SEV_RECOVERABLE,
408c2ecf20Sopenharmony_ci	CPER_SEV_FATAL,
418c2ecf20Sopenharmony_ci	CPER_SEV_CORRECTED,
428c2ecf20Sopenharmony_ci	CPER_SEV_INFORMATIONAL,
438c2ecf20Sopenharmony_ci};
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/*
468c2ecf20Sopenharmony_ci * Validation bits definition for validation_bits in struct
478c2ecf20Sopenharmony_ci * cper_record_header. If set, corresponding fields in struct
488c2ecf20Sopenharmony_ci * cper_record_header contain valid information.
498c2ecf20Sopenharmony_ci */
508c2ecf20Sopenharmony_ci#define CPER_VALID_PLATFORM_ID			0x0001
518c2ecf20Sopenharmony_ci#define CPER_VALID_TIMESTAMP			0x0002
528c2ecf20Sopenharmony_ci#define CPER_VALID_PARTITION_ID			0x0004
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/*
558c2ecf20Sopenharmony_ci * Notification type used to generate error record, used in
568c2ecf20Sopenharmony_ci * notification_type in struct cper_record_header.  These UUIDs are defined
578c2ecf20Sopenharmony_ci * in the UEFI spec v2.7, sec N.2.1.
588c2ecf20Sopenharmony_ci */
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/* Corrected Machine Check */
618c2ecf20Sopenharmony_ci#define CPER_NOTIFY_CMC							\
628c2ecf20Sopenharmony_ci	GUID_INIT(0x2DCE8BB1, 0xBDD7, 0x450e, 0xB9, 0xAD, 0x9C, 0xF4,	\
638c2ecf20Sopenharmony_ci		  0xEB, 0xD4, 0xF8, 0x90)
648c2ecf20Sopenharmony_ci/* Corrected Platform Error */
658c2ecf20Sopenharmony_ci#define CPER_NOTIFY_CPE							\
668c2ecf20Sopenharmony_ci	GUID_INIT(0x4E292F96, 0xD843, 0x4a55, 0xA8, 0xC2, 0xD4, 0x81,	\
678c2ecf20Sopenharmony_ci		  0xF2, 0x7E, 0xBE, 0xEE)
688c2ecf20Sopenharmony_ci/* Machine Check Exception */
698c2ecf20Sopenharmony_ci#define CPER_NOTIFY_MCE							\
708c2ecf20Sopenharmony_ci	GUID_INIT(0xE8F56FFE, 0x919C, 0x4cc5, 0xBA, 0x88, 0x65, 0xAB,	\
718c2ecf20Sopenharmony_ci		  0xE1, 0x49, 0x13, 0xBB)
728c2ecf20Sopenharmony_ci/* PCI Express Error */
738c2ecf20Sopenharmony_ci#define CPER_NOTIFY_PCIE						\
748c2ecf20Sopenharmony_ci	GUID_INIT(0xCF93C01F, 0x1A16, 0x4dfc, 0xB8, 0xBC, 0x9C, 0x4D,	\
758c2ecf20Sopenharmony_ci		  0xAF, 0x67, 0xC1, 0x04)
768c2ecf20Sopenharmony_ci/* INIT Record (for IPF) */
778c2ecf20Sopenharmony_ci#define CPER_NOTIFY_INIT						\
788c2ecf20Sopenharmony_ci	GUID_INIT(0xCC5263E8, 0x9308, 0x454a, 0x89, 0xD0, 0x34, 0x0B,	\
798c2ecf20Sopenharmony_ci		  0xD3, 0x9B, 0xC9, 0x8E)
808c2ecf20Sopenharmony_ci/* Non-Maskable Interrupt */
818c2ecf20Sopenharmony_ci#define CPER_NOTIFY_NMI							\
828c2ecf20Sopenharmony_ci	GUID_INIT(0x5BAD89FF, 0xB7E6, 0x42c9, 0x81, 0x4A, 0xCF, 0x24,	\
838c2ecf20Sopenharmony_ci		  0x85, 0xD6, 0xE9, 0x8A)
848c2ecf20Sopenharmony_ci/* BOOT Error Record */
858c2ecf20Sopenharmony_ci#define CPER_NOTIFY_BOOT						\
868c2ecf20Sopenharmony_ci	GUID_INIT(0x3D61A466, 0xAB40, 0x409a, 0xA6, 0x98, 0xF3, 0x62,	\
878c2ecf20Sopenharmony_ci		  0xD4, 0x64, 0xB3, 0x8F)
888c2ecf20Sopenharmony_ci/* DMA Remapping Error */
898c2ecf20Sopenharmony_ci#define CPER_NOTIFY_DMAR						\
908c2ecf20Sopenharmony_ci	GUID_INIT(0x667DD791, 0xC6B3, 0x4c27, 0x8A, 0x6B, 0x0F, 0x8E,	\
918c2ecf20Sopenharmony_ci		  0x72, 0x2D, 0xEB, 0x41)
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/*
948c2ecf20Sopenharmony_ci * Flags bits definitions for flags in struct cper_record_header
958c2ecf20Sopenharmony_ci * If set, the error has been recovered
968c2ecf20Sopenharmony_ci */
978c2ecf20Sopenharmony_ci#define CPER_HW_ERROR_FLAGS_RECOVERED		0x1
988c2ecf20Sopenharmony_ci/* If set, the error is for previous boot */
998c2ecf20Sopenharmony_ci#define CPER_HW_ERROR_FLAGS_PREVERR		0x2
1008c2ecf20Sopenharmony_ci/* If set, the error is injected for testing */
1018c2ecf20Sopenharmony_ci#define CPER_HW_ERROR_FLAGS_SIMULATED		0x4
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/*
1048c2ecf20Sopenharmony_ci * CPER section header revision, used in revision field in struct
1058c2ecf20Sopenharmony_ci * cper_section_descriptor
1068c2ecf20Sopenharmony_ci */
1078c2ecf20Sopenharmony_ci#define CPER_SEC_REV				0x0100
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci/*
1108c2ecf20Sopenharmony_ci * Validation bits definition for validation_bits in struct
1118c2ecf20Sopenharmony_ci * cper_section_descriptor. If set, corresponding fields in struct
1128c2ecf20Sopenharmony_ci * cper_section_descriptor contain valid information.
1138c2ecf20Sopenharmony_ci */
1148c2ecf20Sopenharmony_ci#define CPER_SEC_VALID_FRU_ID			0x1
1158c2ecf20Sopenharmony_ci#define CPER_SEC_VALID_FRU_TEXT			0x2
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/*
1188c2ecf20Sopenharmony_ci * Flags bits definitions for flags in struct cper_section_descriptor
1198c2ecf20Sopenharmony_ci *
1208c2ecf20Sopenharmony_ci * If set, the section is associated with the error condition
1218c2ecf20Sopenharmony_ci * directly, and should be focused on
1228c2ecf20Sopenharmony_ci */
1238c2ecf20Sopenharmony_ci#define CPER_SEC_PRIMARY			0x0001
1248c2ecf20Sopenharmony_ci/*
1258c2ecf20Sopenharmony_ci * If set, the error was not contained within the processor or memory
1268c2ecf20Sopenharmony_ci * hierarchy and the error may have propagated to persistent storage
1278c2ecf20Sopenharmony_ci * or network
1288c2ecf20Sopenharmony_ci */
1298c2ecf20Sopenharmony_ci#define CPER_SEC_CONTAINMENT_WARNING		0x0002
1308c2ecf20Sopenharmony_ci/* If set, the component must be re-initialized or re-enabled prior to use */
1318c2ecf20Sopenharmony_ci#define CPER_SEC_RESET				0x0004
1328c2ecf20Sopenharmony_ci/* If set, Linux may choose to discontinue use of the resource */
1338c2ecf20Sopenharmony_ci#define CPER_SEC_ERROR_THRESHOLD_EXCEEDED	0x0008
1348c2ecf20Sopenharmony_ci/*
1358c2ecf20Sopenharmony_ci * If set, resource could not be queried for error information due to
1368c2ecf20Sopenharmony_ci * conflicts with other system software or resources. Some fields of
1378c2ecf20Sopenharmony_ci * the section will be invalid
1388c2ecf20Sopenharmony_ci */
1398c2ecf20Sopenharmony_ci#define CPER_SEC_RESOURCE_NOT_ACCESSIBLE	0x0010
1408c2ecf20Sopenharmony_ci/*
1418c2ecf20Sopenharmony_ci * If set, action has been taken to ensure error containment (such as
1428c2ecf20Sopenharmony_ci * poisoning data), but the error has not been fully corrected and the
1438c2ecf20Sopenharmony_ci * data has not been consumed. Linux may choose to take further
1448c2ecf20Sopenharmony_ci * corrective action before the data is consumed
1458c2ecf20Sopenharmony_ci */
1468c2ecf20Sopenharmony_ci#define CPER_SEC_LATENT_ERROR			0x0020
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci/*
1498c2ecf20Sopenharmony_ci * Section type definitions, used in section_type field in struct
1508c2ecf20Sopenharmony_ci * cper_section_descriptor.  These UUIDs are defined in the UEFI spec
1518c2ecf20Sopenharmony_ci * v2.7, sec N.2.2.
1528c2ecf20Sopenharmony_ci */
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci/* Processor Generic */
1558c2ecf20Sopenharmony_ci#define CPER_SEC_PROC_GENERIC						\
1568c2ecf20Sopenharmony_ci	GUID_INIT(0x9876CCAD, 0x47B4, 0x4bdb, 0xB6, 0x5E, 0x16, 0xF1,	\
1578c2ecf20Sopenharmony_ci		  0x93, 0xC4, 0xF3, 0xDB)
1588c2ecf20Sopenharmony_ci/* Processor Specific: X86/X86_64 */
1598c2ecf20Sopenharmony_ci#define CPER_SEC_PROC_IA						\
1608c2ecf20Sopenharmony_ci	GUID_INIT(0xDC3EA0B0, 0xA144, 0x4797, 0xB9, 0x5B, 0x53, 0xFA,	\
1618c2ecf20Sopenharmony_ci		  0x24, 0x2B, 0x6E, 0x1D)
1628c2ecf20Sopenharmony_ci/* Processor Specific: IA64 */
1638c2ecf20Sopenharmony_ci#define CPER_SEC_PROC_IPF						\
1648c2ecf20Sopenharmony_ci	GUID_INIT(0xE429FAF1, 0x3CB7, 0x11D4, 0x0B, 0xCA, 0x07, 0x00,	\
1658c2ecf20Sopenharmony_ci		  0x80, 0xC7, 0x3C, 0x88, 0x81)
1668c2ecf20Sopenharmony_ci/* Processor Specific: ARM */
1678c2ecf20Sopenharmony_ci#define CPER_SEC_PROC_ARM						\
1688c2ecf20Sopenharmony_ci	GUID_INIT(0xE19E3D16, 0xBC11, 0x11E4, 0x9C, 0xAA, 0xC2, 0x05,	\
1698c2ecf20Sopenharmony_ci		  0x1D, 0x5D, 0x46, 0xB0)
1708c2ecf20Sopenharmony_ci/* Platform Memory */
1718c2ecf20Sopenharmony_ci#define CPER_SEC_PLATFORM_MEM						\
1728c2ecf20Sopenharmony_ci	GUID_INIT(0xA5BC1114, 0x6F64, 0x4EDE, 0xB8, 0x63, 0x3E, 0x83,	\
1738c2ecf20Sopenharmony_ci		  0xED, 0x7C, 0x83, 0xB1)
1748c2ecf20Sopenharmony_ci#define CPER_SEC_PCIE							\
1758c2ecf20Sopenharmony_ci	GUID_INIT(0xD995E954, 0xBBC1, 0x430F, 0xAD, 0x91, 0xB4, 0x4D,	\
1768c2ecf20Sopenharmony_ci		  0xCB, 0x3C, 0x6F, 0x35)
1778c2ecf20Sopenharmony_ci/* Firmware Error Record Reference */
1788c2ecf20Sopenharmony_ci#define CPER_SEC_FW_ERR_REC_REF						\
1798c2ecf20Sopenharmony_ci	GUID_INIT(0x81212A96, 0x09ED, 0x4996, 0x94, 0x71, 0x8D, 0x72,	\
1808c2ecf20Sopenharmony_ci		  0x9C, 0x8E, 0x69, 0xED)
1818c2ecf20Sopenharmony_ci/* PCI/PCI-X Bus */
1828c2ecf20Sopenharmony_ci#define CPER_SEC_PCI_X_BUS						\
1838c2ecf20Sopenharmony_ci	GUID_INIT(0xC5753963, 0x3B84, 0x4095, 0xBF, 0x78, 0xED, 0xDA,	\
1848c2ecf20Sopenharmony_ci		  0xD3, 0xF9, 0xC9, 0xDD)
1858c2ecf20Sopenharmony_ci/* PCI Component/Device */
1868c2ecf20Sopenharmony_ci#define CPER_SEC_PCI_DEV						\
1878c2ecf20Sopenharmony_ci	GUID_INIT(0xEB5E4685, 0xCA66, 0x4769, 0xB6, 0xA2, 0x26, 0x06,	\
1888c2ecf20Sopenharmony_ci		  0x8B, 0x00, 0x13, 0x26)
1898c2ecf20Sopenharmony_ci#define CPER_SEC_DMAR_GENERIC						\
1908c2ecf20Sopenharmony_ci	GUID_INIT(0x5B51FEF7, 0xC79D, 0x4434, 0x8F, 0x1B, 0xAA, 0x62,	\
1918c2ecf20Sopenharmony_ci		  0xDE, 0x3E, 0x2C, 0x64)
1928c2ecf20Sopenharmony_ci/* Intel VT for Directed I/O specific DMAr */
1938c2ecf20Sopenharmony_ci#define CPER_SEC_DMAR_VT						\
1948c2ecf20Sopenharmony_ci	GUID_INIT(0x71761D37, 0x32B2, 0x45cd, 0xA7, 0xD0, 0xB0, 0xFE,	\
1958c2ecf20Sopenharmony_ci		  0xDD, 0x93, 0xE8, 0xCF)
1968c2ecf20Sopenharmony_ci/* IOMMU specific DMAr */
1978c2ecf20Sopenharmony_ci#define CPER_SEC_DMAR_IOMMU						\
1988c2ecf20Sopenharmony_ci	GUID_INIT(0x036F84E1, 0x7F37, 0x428c, 0xA7, 0x9E, 0x57, 0x5F,	\
1998c2ecf20Sopenharmony_ci		  0xDF, 0xAA, 0x84, 0xEC)
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci#define CPER_PROC_VALID_TYPE			0x0001
2028c2ecf20Sopenharmony_ci#define CPER_PROC_VALID_ISA			0x0002
2038c2ecf20Sopenharmony_ci#define CPER_PROC_VALID_ERROR_TYPE		0x0004
2048c2ecf20Sopenharmony_ci#define CPER_PROC_VALID_OPERATION		0x0008
2058c2ecf20Sopenharmony_ci#define CPER_PROC_VALID_FLAGS			0x0010
2068c2ecf20Sopenharmony_ci#define CPER_PROC_VALID_LEVEL			0x0020
2078c2ecf20Sopenharmony_ci#define CPER_PROC_VALID_VERSION			0x0040
2088c2ecf20Sopenharmony_ci#define CPER_PROC_VALID_BRAND_INFO		0x0080
2098c2ecf20Sopenharmony_ci#define CPER_PROC_VALID_ID			0x0100
2108c2ecf20Sopenharmony_ci#define CPER_PROC_VALID_TARGET_ADDRESS		0x0200
2118c2ecf20Sopenharmony_ci#define CPER_PROC_VALID_REQUESTOR_ID		0x0400
2128c2ecf20Sopenharmony_ci#define CPER_PROC_VALID_RESPONDER_ID		0x0800
2138c2ecf20Sopenharmony_ci#define CPER_PROC_VALID_IP			0x1000
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_ERROR_STATUS		0x0001
2168c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_PA			0x0002
2178c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_PA_MASK			0x0004
2188c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_NODE			0x0008
2198c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_CARD			0x0010
2208c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_MODULE			0x0020
2218c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_BANK			0x0040
2228c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_DEVICE			0x0080
2238c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_ROW			0x0100
2248c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_COLUMN			0x0200
2258c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_BIT_POSITION		0x0400
2268c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_REQUESTOR_ID		0x0800
2278c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_RESPONDER_ID		0x1000
2288c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_TARGET_ID		0x2000
2298c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_ERROR_TYPE		0x4000
2308c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_RANK_NUMBER		0x8000
2318c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_CARD_HANDLE		0x10000
2328c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_MODULE_HANDLE		0x20000
2338c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_ROW_EXT			0x40000
2348c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_BANK_GROUP		0x80000
2358c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_BANK_ADDRESS		0x100000
2368c2ecf20Sopenharmony_ci#define CPER_MEM_VALID_CHIP_ID			0x200000
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci#define CPER_MEM_EXT_ROW_MASK			0x3
2398c2ecf20Sopenharmony_ci#define CPER_MEM_EXT_ROW_SHIFT			16
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci#define CPER_MEM_BANK_ADDRESS_MASK		0xff
2428c2ecf20Sopenharmony_ci#define CPER_MEM_BANK_GROUP_SHIFT		8
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci#define CPER_MEM_CHIP_ID_SHIFT			5
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci#define CPER_PCIE_VALID_PORT_TYPE		0x0001
2478c2ecf20Sopenharmony_ci#define CPER_PCIE_VALID_VERSION			0x0002
2488c2ecf20Sopenharmony_ci#define CPER_PCIE_VALID_COMMAND_STATUS		0x0004
2498c2ecf20Sopenharmony_ci#define CPER_PCIE_VALID_DEVICE_ID		0x0008
2508c2ecf20Sopenharmony_ci#define CPER_PCIE_VALID_SERIAL_NUMBER		0x0010
2518c2ecf20Sopenharmony_ci#define CPER_PCIE_VALID_BRIDGE_CONTROL_STATUS	0x0020
2528c2ecf20Sopenharmony_ci#define CPER_PCIE_VALID_CAPABILITY		0x0040
2538c2ecf20Sopenharmony_ci#define CPER_PCIE_VALID_AER_INFO		0x0080
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci#define CPER_PCIE_SLOT_SHIFT			3
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci#define CPER_ARM_VALID_MPIDR			BIT(0)
2588c2ecf20Sopenharmony_ci#define CPER_ARM_VALID_AFFINITY_LEVEL		BIT(1)
2598c2ecf20Sopenharmony_ci#define CPER_ARM_VALID_RUNNING_STATE		BIT(2)
2608c2ecf20Sopenharmony_ci#define CPER_ARM_VALID_VENDOR_INFO		BIT(3)
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci#define CPER_ARM_INFO_VALID_MULTI_ERR		BIT(0)
2638c2ecf20Sopenharmony_ci#define CPER_ARM_INFO_VALID_FLAGS		BIT(1)
2648c2ecf20Sopenharmony_ci#define CPER_ARM_INFO_VALID_ERR_INFO		BIT(2)
2658c2ecf20Sopenharmony_ci#define CPER_ARM_INFO_VALID_VIRT_ADDR		BIT(3)
2668c2ecf20Sopenharmony_ci#define CPER_ARM_INFO_VALID_PHYSICAL_ADDR	BIT(4)
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci#define CPER_ARM_INFO_FLAGS_FIRST		BIT(0)
2698c2ecf20Sopenharmony_ci#define CPER_ARM_INFO_FLAGS_LAST		BIT(1)
2708c2ecf20Sopenharmony_ci#define CPER_ARM_INFO_FLAGS_PROPAGATED		BIT(2)
2718c2ecf20Sopenharmony_ci#define CPER_ARM_INFO_FLAGS_OVERFLOW		BIT(3)
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci#define CPER_ARM_CACHE_ERROR			0
2748c2ecf20Sopenharmony_ci#define CPER_ARM_TLB_ERROR			1
2758c2ecf20Sopenharmony_ci#define CPER_ARM_BUS_ERROR			2
2768c2ecf20Sopenharmony_ci#define CPER_ARM_VENDOR_ERROR			3
2778c2ecf20Sopenharmony_ci#define CPER_ARM_MAX_TYPE			CPER_ARM_VENDOR_ERROR
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_VALID_TRANSACTION_TYPE	BIT(0)
2808c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_VALID_OPERATION_TYPE	BIT(1)
2818c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_VALID_LEVEL		BIT(2)
2828c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_VALID_PROC_CONTEXT_CORRUPT	BIT(3)
2838c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_VALID_CORRECTED		BIT(4)
2848c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_VALID_PRECISE_PC		BIT(5)
2858c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_VALID_RESTARTABLE_PC	BIT(6)
2868c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_VALID_PARTICIPATION_TYPE	BIT(7)
2878c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_VALID_TIME_OUT		BIT(8)
2888c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_VALID_ADDRESS_SPACE	BIT(9)
2898c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_VALID_MEM_ATTRIBUTES	BIT(10)
2908c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_VALID_ACCESS_MODE		BIT(11)
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_TRANSACTION_SHIFT		16
2938c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_TRANSACTION_MASK		GENMASK(1,0)
2948c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_OPERATION_SHIFT		18
2958c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_OPERATION_MASK		GENMASK(3,0)
2968c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_LEVEL_SHIFT		22
2978c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_LEVEL_MASK			GENMASK(2,0)
2988c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_PC_CORRUPT_SHIFT		25
2998c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_PC_CORRUPT_MASK		GENMASK(0,0)
3008c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_CORRECTED_SHIFT		26
3018c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_CORRECTED_MASK		GENMASK(0,0)
3028c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_PRECISE_PC_SHIFT		27
3038c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_PRECISE_PC_MASK		GENMASK(0,0)
3048c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_RESTARTABLE_PC_SHIFT	28
3058c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_RESTARTABLE_PC_MASK	GENMASK(0,0)
3068c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_PARTICIPATION_TYPE_SHIFT	29
3078c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_PARTICIPATION_TYPE_MASK	GENMASK(1,0)
3088c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_TIME_OUT_SHIFT		31
3098c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_TIME_OUT_MASK		GENMASK(0,0)
3108c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_ADDRESS_SPACE_SHIFT	32
3118c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_ADDRESS_SPACE_MASK		GENMASK(1,0)
3128c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_MEM_ATTRIBUTES_SHIFT	34
3138c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_MEM_ATTRIBUTES_MASK	GENMASK(8,0)
3148c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_ACCESS_MODE_SHIFT		43
3158c2ecf20Sopenharmony_ci#define CPER_ARM_ERR_ACCESS_MODE_MASK		GENMASK(0,0)
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci/*
3188c2ecf20Sopenharmony_ci * All tables and structs must be byte-packed to match CPER
3198c2ecf20Sopenharmony_ci * specification, since the tables are provided by the system BIOS
3208c2ecf20Sopenharmony_ci */
3218c2ecf20Sopenharmony_ci#pragma pack(1)
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci/* Record Header, UEFI v2.7 sec N.2.1 */
3248c2ecf20Sopenharmony_cistruct cper_record_header {
3258c2ecf20Sopenharmony_ci	char	signature[CPER_SIG_SIZE];	/* must be CPER_SIG_RECORD */
3268c2ecf20Sopenharmony_ci	u16	revision;			/* must be CPER_RECORD_REV */
3278c2ecf20Sopenharmony_ci	u32	signature_end;			/* must be CPER_SIG_END */
3288c2ecf20Sopenharmony_ci	u16	section_count;
3298c2ecf20Sopenharmony_ci	u32	error_severity;
3308c2ecf20Sopenharmony_ci	u32	validation_bits;
3318c2ecf20Sopenharmony_ci	u32	record_length;
3328c2ecf20Sopenharmony_ci	u64	timestamp;
3338c2ecf20Sopenharmony_ci	guid_t	platform_id;
3348c2ecf20Sopenharmony_ci	guid_t	partition_id;
3358c2ecf20Sopenharmony_ci	guid_t	creator_id;
3368c2ecf20Sopenharmony_ci	guid_t	notification_type;
3378c2ecf20Sopenharmony_ci	u64	record_id;
3388c2ecf20Sopenharmony_ci	u32	flags;
3398c2ecf20Sopenharmony_ci	u64	persistence_information;
3408c2ecf20Sopenharmony_ci	u8	reserved[12];			/* must be zero */
3418c2ecf20Sopenharmony_ci};
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci/* Section Descriptor, UEFI v2.7 sec N.2.2 */
3448c2ecf20Sopenharmony_cistruct cper_section_descriptor {
3458c2ecf20Sopenharmony_ci	u32	section_offset;		/* Offset in bytes of the
3468c2ecf20Sopenharmony_ci					 *  section body from the base
3478c2ecf20Sopenharmony_ci					 *  of the record header */
3488c2ecf20Sopenharmony_ci	u32	section_length;
3498c2ecf20Sopenharmony_ci	u16	revision;		/* must be CPER_RECORD_REV */
3508c2ecf20Sopenharmony_ci	u8	validation_bits;
3518c2ecf20Sopenharmony_ci	u8	reserved;		/* must be zero */
3528c2ecf20Sopenharmony_ci	u32	flags;
3538c2ecf20Sopenharmony_ci	guid_t	section_type;
3548c2ecf20Sopenharmony_ci	guid_t	fru_id;
3558c2ecf20Sopenharmony_ci	u32	section_severity;
3568c2ecf20Sopenharmony_ci	u8	fru_text[20];
3578c2ecf20Sopenharmony_ci};
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci/* Generic Processor Error Section, UEFI v2.7 sec N.2.4.1 */
3608c2ecf20Sopenharmony_cistruct cper_sec_proc_generic {
3618c2ecf20Sopenharmony_ci	u64	validation_bits;
3628c2ecf20Sopenharmony_ci	u8	proc_type;
3638c2ecf20Sopenharmony_ci	u8	proc_isa;
3648c2ecf20Sopenharmony_ci	u8	proc_error_type;
3658c2ecf20Sopenharmony_ci	u8	operation;
3668c2ecf20Sopenharmony_ci	u8	flags;
3678c2ecf20Sopenharmony_ci	u8	level;
3688c2ecf20Sopenharmony_ci	u16	reserved;
3698c2ecf20Sopenharmony_ci	u64	cpu_version;
3708c2ecf20Sopenharmony_ci	char	cpu_brand[128];
3718c2ecf20Sopenharmony_ci	u64	proc_id;
3728c2ecf20Sopenharmony_ci	u64	target_addr;
3738c2ecf20Sopenharmony_ci	u64	requestor_id;
3748c2ecf20Sopenharmony_ci	u64	responder_id;
3758c2ecf20Sopenharmony_ci	u64	ip;
3768c2ecf20Sopenharmony_ci};
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci/* IA32/X64 Processor Error Section, UEFI v2.7 sec N.2.4.2 */
3798c2ecf20Sopenharmony_cistruct cper_sec_proc_ia {
3808c2ecf20Sopenharmony_ci	u64	validation_bits;
3818c2ecf20Sopenharmony_ci	u64	lapic_id;
3828c2ecf20Sopenharmony_ci	u8	cpuid[48];
3838c2ecf20Sopenharmony_ci};
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci/* IA32/X64 Processor Error Information Structure, UEFI v2.7 sec N.2.4.2.1 */
3868c2ecf20Sopenharmony_cistruct cper_ia_err_info {
3878c2ecf20Sopenharmony_ci	guid_t	err_type;
3888c2ecf20Sopenharmony_ci	u64	validation_bits;
3898c2ecf20Sopenharmony_ci	u64	check_info;
3908c2ecf20Sopenharmony_ci	u64	target_id;
3918c2ecf20Sopenharmony_ci	u64	requestor_id;
3928c2ecf20Sopenharmony_ci	u64	responder_id;
3938c2ecf20Sopenharmony_ci	u64	ip;
3948c2ecf20Sopenharmony_ci};
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci/* IA32/X64 Processor Context Information Structure, UEFI v2.7 sec N.2.4.2.2 */
3978c2ecf20Sopenharmony_cistruct cper_ia_proc_ctx {
3988c2ecf20Sopenharmony_ci	u16	reg_ctx_type;
3998c2ecf20Sopenharmony_ci	u16	reg_arr_size;
4008c2ecf20Sopenharmony_ci	u32	msr_addr;
4018c2ecf20Sopenharmony_ci	u64	mm_reg_addr;
4028c2ecf20Sopenharmony_ci};
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci/* ARM Processor Error Section, UEFI v2.7 sec N.2.4.4 */
4058c2ecf20Sopenharmony_cistruct cper_sec_proc_arm {
4068c2ecf20Sopenharmony_ci	u32	validation_bits;
4078c2ecf20Sopenharmony_ci	u16	err_info_num;		/* Number of Processor Error Info */
4088c2ecf20Sopenharmony_ci	u16	context_info_num;	/* Number of Processor Context Info Records*/
4098c2ecf20Sopenharmony_ci	u32	section_length;
4108c2ecf20Sopenharmony_ci	u8	affinity_level;
4118c2ecf20Sopenharmony_ci	u8	reserved[3];		/* must be zero */
4128c2ecf20Sopenharmony_ci	u64	mpidr;
4138c2ecf20Sopenharmony_ci	u64	midr;
4148c2ecf20Sopenharmony_ci	u32	running_state;		/* Bit 0 set - Processor running. PSCI = 0 */
4158c2ecf20Sopenharmony_ci	u32	psci_state;
4168c2ecf20Sopenharmony_ci};
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci/* ARM Processor Error Information Structure, UEFI v2.7 sec N.2.4.4.1 */
4198c2ecf20Sopenharmony_cistruct cper_arm_err_info {
4208c2ecf20Sopenharmony_ci	u8	version;
4218c2ecf20Sopenharmony_ci	u8	length;
4228c2ecf20Sopenharmony_ci	u16	validation_bits;
4238c2ecf20Sopenharmony_ci	u8	type;
4248c2ecf20Sopenharmony_ci	u16	multiple_error;
4258c2ecf20Sopenharmony_ci	u8	flags;
4268c2ecf20Sopenharmony_ci	u64	error_info;
4278c2ecf20Sopenharmony_ci	u64	virt_fault_addr;
4288c2ecf20Sopenharmony_ci	u64	physical_fault_addr;
4298c2ecf20Sopenharmony_ci};
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci/* ARM Processor Context Information Structure, UEFI v2.7 sec N.2.4.4.2 */
4328c2ecf20Sopenharmony_cistruct cper_arm_ctx_info {
4338c2ecf20Sopenharmony_ci	u16	version;
4348c2ecf20Sopenharmony_ci	u16	type;
4358c2ecf20Sopenharmony_ci	u32	size;
4368c2ecf20Sopenharmony_ci};
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci/* Old Memory Error Section, UEFI v2.1, v2.2 */
4398c2ecf20Sopenharmony_cistruct cper_sec_mem_err_old {
4408c2ecf20Sopenharmony_ci	u64	validation_bits;
4418c2ecf20Sopenharmony_ci	u64	error_status;
4428c2ecf20Sopenharmony_ci	u64	physical_addr;
4438c2ecf20Sopenharmony_ci	u64	physical_addr_mask;
4448c2ecf20Sopenharmony_ci	u16	node;
4458c2ecf20Sopenharmony_ci	u16	card;
4468c2ecf20Sopenharmony_ci	u16	module;
4478c2ecf20Sopenharmony_ci	u16	bank;
4488c2ecf20Sopenharmony_ci	u16	device;
4498c2ecf20Sopenharmony_ci	u16	row;
4508c2ecf20Sopenharmony_ci	u16	column;
4518c2ecf20Sopenharmony_ci	u16	bit_pos;
4528c2ecf20Sopenharmony_ci	u64	requestor_id;
4538c2ecf20Sopenharmony_ci	u64	responder_id;
4548c2ecf20Sopenharmony_ci	u64	target_id;
4558c2ecf20Sopenharmony_ci	u8	error_type;
4568c2ecf20Sopenharmony_ci};
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci/* Memory Error Section (UEFI >= v2.3), UEFI v2.8 sec N.2.5 */
4598c2ecf20Sopenharmony_cistruct cper_sec_mem_err {
4608c2ecf20Sopenharmony_ci	u64	validation_bits;
4618c2ecf20Sopenharmony_ci	u64	error_status;
4628c2ecf20Sopenharmony_ci	u64	physical_addr;
4638c2ecf20Sopenharmony_ci	u64	physical_addr_mask;
4648c2ecf20Sopenharmony_ci	u16	node;
4658c2ecf20Sopenharmony_ci	u16	card;
4668c2ecf20Sopenharmony_ci	u16	module;
4678c2ecf20Sopenharmony_ci	u16	bank;
4688c2ecf20Sopenharmony_ci	u16	device;
4698c2ecf20Sopenharmony_ci	u16	row;
4708c2ecf20Sopenharmony_ci	u16	column;
4718c2ecf20Sopenharmony_ci	u16	bit_pos;
4728c2ecf20Sopenharmony_ci	u64	requestor_id;
4738c2ecf20Sopenharmony_ci	u64	responder_id;
4748c2ecf20Sopenharmony_ci	u64	target_id;
4758c2ecf20Sopenharmony_ci	u8	error_type;
4768c2ecf20Sopenharmony_ci	u8	extended;
4778c2ecf20Sopenharmony_ci	u16	rank;
4788c2ecf20Sopenharmony_ci	u16	mem_array_handle;	/* "card handle" in UEFI 2.4 */
4798c2ecf20Sopenharmony_ci	u16	mem_dev_handle;		/* "module handle" in UEFI 2.4 */
4808c2ecf20Sopenharmony_ci};
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_cistruct cper_mem_err_compact {
4838c2ecf20Sopenharmony_ci	u64	validation_bits;
4848c2ecf20Sopenharmony_ci	u16	node;
4858c2ecf20Sopenharmony_ci	u16	card;
4868c2ecf20Sopenharmony_ci	u16	module;
4878c2ecf20Sopenharmony_ci	u16	bank;
4888c2ecf20Sopenharmony_ci	u16	device;
4898c2ecf20Sopenharmony_ci	u16	row;
4908c2ecf20Sopenharmony_ci	u16	column;
4918c2ecf20Sopenharmony_ci	u16	bit_pos;
4928c2ecf20Sopenharmony_ci	u64	requestor_id;
4938c2ecf20Sopenharmony_ci	u64	responder_id;
4948c2ecf20Sopenharmony_ci	u64	target_id;
4958c2ecf20Sopenharmony_ci	u16	rank;
4968c2ecf20Sopenharmony_ci	u16	mem_array_handle;
4978c2ecf20Sopenharmony_ci	u16	mem_dev_handle;
4988c2ecf20Sopenharmony_ci	u8      extended;
4998c2ecf20Sopenharmony_ci};
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_cistatic inline u32 cper_get_mem_extension(u64 mem_valid, u8 mem_extended)
5028c2ecf20Sopenharmony_ci{
5038c2ecf20Sopenharmony_ci	if (!(mem_valid & CPER_MEM_VALID_ROW_EXT))
5048c2ecf20Sopenharmony_ci		return 0;
5058c2ecf20Sopenharmony_ci	return (mem_extended & CPER_MEM_EXT_ROW_MASK) << CPER_MEM_EXT_ROW_SHIFT;
5068c2ecf20Sopenharmony_ci}
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ci/* PCI Express Error Section, UEFI v2.7 sec N.2.7 */
5098c2ecf20Sopenharmony_cistruct cper_sec_pcie {
5108c2ecf20Sopenharmony_ci	u64		validation_bits;
5118c2ecf20Sopenharmony_ci	u32		port_type;
5128c2ecf20Sopenharmony_ci	struct {
5138c2ecf20Sopenharmony_ci		u8	minor;
5148c2ecf20Sopenharmony_ci		u8	major;
5158c2ecf20Sopenharmony_ci		u8	reserved[2];
5168c2ecf20Sopenharmony_ci	}		version;
5178c2ecf20Sopenharmony_ci	u16		command;
5188c2ecf20Sopenharmony_ci	u16		status;
5198c2ecf20Sopenharmony_ci	u32		reserved;
5208c2ecf20Sopenharmony_ci	struct {
5218c2ecf20Sopenharmony_ci		u16	vendor_id;
5228c2ecf20Sopenharmony_ci		u16	device_id;
5238c2ecf20Sopenharmony_ci		u8	class_code[3];
5248c2ecf20Sopenharmony_ci		u8	function;
5258c2ecf20Sopenharmony_ci		u8	device;
5268c2ecf20Sopenharmony_ci		u16	segment;
5278c2ecf20Sopenharmony_ci		u8	bus;
5288c2ecf20Sopenharmony_ci		u8	secondary_bus;
5298c2ecf20Sopenharmony_ci		u16	slot;
5308c2ecf20Sopenharmony_ci		u8	reserved;
5318c2ecf20Sopenharmony_ci	}		device_id;
5328c2ecf20Sopenharmony_ci	struct {
5338c2ecf20Sopenharmony_ci		u32	lower;
5348c2ecf20Sopenharmony_ci		u32	upper;
5358c2ecf20Sopenharmony_ci	}		serial_number;
5368c2ecf20Sopenharmony_ci	struct {
5378c2ecf20Sopenharmony_ci		u16	secondary_status;
5388c2ecf20Sopenharmony_ci		u16	control;
5398c2ecf20Sopenharmony_ci	}		bridge;
5408c2ecf20Sopenharmony_ci	u8	capability[60];
5418c2ecf20Sopenharmony_ci	u8	aer_info[96];
5428c2ecf20Sopenharmony_ci};
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_ci/* Firmware Error Record Reference, UEFI v2.7 sec N.2.10  */
5458c2ecf20Sopenharmony_cistruct cper_sec_fw_err_rec_ref {
5468c2ecf20Sopenharmony_ci	u8 record_type;
5478c2ecf20Sopenharmony_ci	u8 revision;
5488c2ecf20Sopenharmony_ci	u8 reserved[6];
5498c2ecf20Sopenharmony_ci	u64 record_identifier;
5508c2ecf20Sopenharmony_ci	guid_t record_identifier_guid;
5518c2ecf20Sopenharmony_ci};
5528c2ecf20Sopenharmony_ci
5538c2ecf20Sopenharmony_ci/* Reset to default packing */
5548c2ecf20Sopenharmony_ci#pragma pack()
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_ciextern const char *const cper_proc_error_type_strs[4];
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ciu64 cper_next_record_id(void);
5598c2ecf20Sopenharmony_ciconst char *cper_severity_str(unsigned int);
5608c2ecf20Sopenharmony_ciconst char *cper_mem_err_type_str(unsigned int);
5618c2ecf20Sopenharmony_civoid cper_print_bits(const char *prefix, unsigned int bits,
5628c2ecf20Sopenharmony_ci		     const char * const strs[], unsigned int strs_size);
5638c2ecf20Sopenharmony_civoid cper_mem_err_pack(const struct cper_sec_mem_err *,
5648c2ecf20Sopenharmony_ci		       struct cper_mem_err_compact *);
5658c2ecf20Sopenharmony_ciconst char *cper_mem_err_unpack(struct trace_seq *,
5668c2ecf20Sopenharmony_ci				struct cper_mem_err_compact *);
5678c2ecf20Sopenharmony_civoid cper_print_proc_arm(const char *pfx,
5688c2ecf20Sopenharmony_ci			 const struct cper_sec_proc_arm *proc);
5698c2ecf20Sopenharmony_civoid cper_print_proc_ia(const char *pfx,
5708c2ecf20Sopenharmony_ci			const struct cper_sec_proc_ia *proc);
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_ci#endif
573