linux/include/linux/cper.h

/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * UEFI Common Platform Error Record
 *
 * Copyright (C) 2010, Intel Corp.
 *	Author: Huang Ying <[email protected]>
 */

#ifndef LINUX_CPER_H
#define LINUX_CPER_H

#include <linux/uuid.h>
#include <linux/trace_seq.h>

/* CPER record signature and the size */
#define CPER_SIG_RECORD
#define CPER_SIG_SIZE
/* Used in signature_end field in struct cper_record_header */
#define CPER_SIG_END

/*
 * CPER record header revision, used in revision field in struct
 * cper_record_header
 */
#define CPER_RECORD_REV

/*
 * CPER record length contains the CPER fields which are relevant for further
 * handling of a memory error in userspace (we don't carry all the fields
 * defined in the UEFI spec because some of them don't make any sense.)
 * Currently, a length of 256 should be more than enough.
 */
#define CPER_REC_LEN
/*
 * Severity definition for error_severity in struct cper_record_header
 * and section_severity in struct cper_section_descriptor
 */
enum {};

/*
 * Validation bits definition for validation_bits in struct
 * cper_record_header. If set, corresponding fields in struct
 * cper_record_header contain valid information.
 */
#define CPER_VALID_PLATFORM_ID
#define CPER_VALID_TIMESTAMP
#define CPER_VALID_PARTITION_ID

/*
 * Notification type used to generate error record, used in
 * notification_type in struct cper_record_header.  These UUIDs are defined
 * in the UEFI spec v2.7, sec N.2.1.
 */

/* Corrected Machine Check */
#define CPER_NOTIFY_CMC
/* Corrected Platform Error */
#define CPER_NOTIFY_CPE
/* Machine Check Exception */
#define CPER_NOTIFY_MCE
/* PCI Express Error */
#define CPER_NOTIFY_PCIE
/* INIT Record (for IPF) */
#define CPER_NOTIFY_INIT
/* Non-Maskable Interrupt */
#define CPER_NOTIFY_NMI
/* BOOT Error Record */
#define CPER_NOTIFY_BOOT
/* DMA Remapping Error */
#define CPER_NOTIFY_DMAR

/* CXL Event record UUIDs are formatted as GUIDs and reported in section type */
/*
 * General Media Event Record
 * CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43
 */
#define CPER_SEC_CXL_GEN_MEDIA_GUID
/*
 * DRAM Event Record
 * CXL rev 3.0 section 8.2.9.2.1.2; Table 8-44
 */
#define CPER_SEC_CXL_DRAM_GUID
/*
 * Memory Module Event Record
 * CXL rev 3.0 section 8.2.9.2.1.3; Table 8-45
 */
#define CPER_SEC_CXL_MEM_MODULE_GUID

/*
 * Flags bits definitions for flags in struct cper_record_header
 * If set, the error has been recovered
 */
#define CPER_HW_ERROR_FLAGS_RECOVERED
/* If set, the error is for previous boot */
#define CPER_HW_ERROR_FLAGS_PREVERR
/* If set, the error is injected for testing */
#define CPER_HW_ERROR_FLAGS_SIMULATED

/*
 * CPER section header revision, used in revision field in struct
 * cper_section_descriptor
 */
#define CPER_SEC_REV

/*
 * Validation bits definition for validation_bits in struct
 * cper_section_descriptor. If set, corresponding fields in struct
 * cper_section_descriptor contain valid information.
 */
#define CPER_SEC_VALID_FRU_ID
#define CPER_SEC_VALID_FRU_TEXT

/*
 * Flags bits definitions for flags in struct cper_section_descriptor
 *
 * If set, the section is associated with the error condition
 * directly, and should be focused on
 */
#define CPER_SEC_PRIMARY
/*
 * If set, the error was not contained within the processor or memory
 * hierarchy and the error may have propagated to persistent storage
 * or network
 */
#define CPER_SEC_CONTAINMENT_WARNING
/* If set, the component must be re-initialized or re-enabled prior to use */
#define CPER_SEC_RESET
/* If set, Linux may choose to discontinue use of the resource */
#define CPER_SEC_ERROR_THRESHOLD_EXCEEDED
/*
 * If set, resource could not be queried for error information due to
 * conflicts with other system software or resources. Some fields of
 * the section will be invalid
 */
#define CPER_SEC_RESOURCE_NOT_ACCESSIBLE
/*
 * If set, action has been taken to ensure error containment (such as
 * poisoning data), but the error has not been fully corrected and the
 * data has not been consumed. Linux may choose to take further
 * corrective action before the data is consumed
 */
#define CPER_SEC_LATENT_ERROR

/*
 * Section type definitions, used in section_type field in struct
 * cper_section_descriptor.  These UUIDs are defined in the UEFI spec
 * v2.7, sec N.2.2.
 */

/* Processor Generic */
#define CPER_SEC_PROC_GENERIC
/* Processor Specific: X86/X86_64 */
#define CPER_SEC_PROC_IA
/* Processor Specific: IA64 */
#define CPER_SEC_PROC_IPF
/* Processor Specific: ARM */
#define CPER_SEC_PROC_ARM
/* Platform Memory */
#define CPER_SEC_PLATFORM_MEM
#define CPER_SEC_PCIE
/* Firmware Error Record Reference */
#define CPER_SEC_FW_ERR_REC_REF
/* PCI/PCI-X Bus */
#define CPER_SEC_PCI_X_BUS
/* PCI Component/Device */
#define CPER_SEC_PCI_DEV
#define CPER_SEC_DMAR_GENERIC
/* Intel VT for Directed I/O specific DMAr */
#define CPER_SEC_DMAR_VT
/* IOMMU specific DMAr */
#define CPER_SEC_DMAR_IOMMU

#define CPER_PROC_VALID_TYPE
#define CPER_PROC_VALID_ISA
#define CPER_PROC_VALID_ERROR_TYPE
#define CPER_PROC_VALID_OPERATION
#define CPER_PROC_VALID_FLAGS
#define CPER_PROC_VALID_LEVEL
#define CPER_PROC_VALID_VERSION
#define CPER_PROC_VALID_BRAND_INFO
#define CPER_PROC_VALID_ID
#define CPER_PROC_VALID_TARGET_ADDRESS
#define CPER_PROC_VALID_REQUESTOR_ID
#define CPER_PROC_VALID_RESPONDER_ID
#define CPER_PROC_VALID_IP

#define CPER_MEM_VALID_ERROR_STATUS
#define CPER_MEM_VALID_PA
#define CPER_MEM_VALID_PA_MASK
#define CPER_MEM_VALID_NODE
#define CPER_MEM_VALID_CARD
#define CPER_MEM_VALID_MODULE
#define CPER_MEM_VALID_BANK
#define CPER_MEM_VALID_DEVICE
#define CPER_MEM_VALID_ROW
#define CPER_MEM_VALID_COLUMN
#define CPER_MEM_VALID_BIT_POSITION
#define CPER_MEM_VALID_REQUESTOR_ID
#define CPER_MEM_VALID_RESPONDER_ID
#define CPER_MEM_VALID_TARGET_ID
#define CPER_MEM_VALID_ERROR_TYPE
#define CPER_MEM_VALID_RANK_NUMBER
#define CPER_MEM_VALID_CARD_HANDLE
#define CPER_MEM_VALID_MODULE_HANDLE
#define CPER_MEM_VALID_ROW_EXT
#define CPER_MEM_VALID_BANK_GROUP
#define CPER_MEM_VALID_BANK_ADDRESS
#define CPER_MEM_VALID_CHIP_ID

#define CPER_MEM_EXT_ROW_MASK
#define CPER_MEM_EXT_ROW_SHIFT

#define CPER_MEM_BANK_ADDRESS_MASK
#define CPER_MEM_BANK_GROUP_SHIFT

#define CPER_MEM_CHIP_ID_SHIFT

#define CPER_PCIE_VALID_PORT_TYPE
#define CPER_PCIE_VALID_VERSION
#define CPER_PCIE_VALID_COMMAND_STATUS
#define CPER_PCIE_VALID_DEVICE_ID
#define CPER_PCIE_VALID_SERIAL_NUMBER
#define CPER_PCIE_VALID_BRIDGE_CONTROL_STATUS
#define CPER_PCIE_VALID_CAPABILITY
#define CPER_PCIE_VALID_AER_INFO

#define CPER_PCIE_SLOT_SHIFT

#define CPER_ARM_VALID_MPIDR
#define CPER_ARM_VALID_AFFINITY_LEVEL
#define CPER_ARM_VALID_RUNNING_STATE
#define CPER_ARM_VALID_VENDOR_INFO

#define CPER_ARM_INFO_VALID_MULTI_ERR
#define CPER_ARM_INFO_VALID_FLAGS
#define CPER_ARM_INFO_VALID_ERR_INFO
#define CPER_ARM_INFO_VALID_VIRT_ADDR
#define CPER_ARM_INFO_VALID_PHYSICAL_ADDR

#define CPER_ARM_INFO_FLAGS_FIRST
#define CPER_ARM_INFO_FLAGS_LAST
#define CPER_ARM_INFO_FLAGS_PROPAGATED
#define CPER_ARM_INFO_FLAGS_OVERFLOW

#define CPER_ARM_CACHE_ERROR
#define CPER_ARM_TLB_ERROR
#define CPER_ARM_BUS_ERROR
#define CPER_ARM_VENDOR_ERROR
#define CPER_ARM_MAX_TYPE

#define CPER_ARM_ERR_VALID_TRANSACTION_TYPE
#define CPER_ARM_ERR_VALID_OPERATION_TYPE
#define CPER_ARM_ERR_VALID_LEVEL
#define CPER_ARM_ERR_VALID_PROC_CONTEXT_CORRUPT
#define CPER_ARM_ERR_VALID_CORRECTED
#define CPER_ARM_ERR_VALID_PRECISE_PC
#define CPER_ARM_ERR_VALID_RESTARTABLE_PC
#define CPER_ARM_ERR_VALID_PARTICIPATION_TYPE
#define CPER_ARM_ERR_VALID_TIME_OUT
#define CPER_ARM_ERR_VALID_ADDRESS_SPACE
#define CPER_ARM_ERR_VALID_MEM_ATTRIBUTES
#define CPER_ARM_ERR_VALID_ACCESS_MODE

#define CPER_ARM_ERR_TRANSACTION_SHIFT
#define CPER_ARM_ERR_TRANSACTION_MASK
#define CPER_ARM_ERR_OPERATION_SHIFT
#define CPER_ARM_ERR_OPERATION_MASK
#define CPER_ARM_ERR_LEVEL_SHIFT
#define CPER_ARM_ERR_LEVEL_MASK
#define CPER_ARM_ERR_PC_CORRUPT_SHIFT
#define CPER_ARM_ERR_PC_CORRUPT_MASK
#define CPER_ARM_ERR_CORRECTED_SHIFT
#define CPER_ARM_ERR_CORRECTED_MASK
#define CPER_ARM_ERR_PRECISE_PC_SHIFT
#define CPER_ARM_ERR_PRECISE_PC_MASK
#define CPER_ARM_ERR_RESTARTABLE_PC_SHIFT
#define CPER_ARM_ERR_RESTARTABLE_PC_MASK
#define CPER_ARM_ERR_PARTICIPATION_TYPE_SHIFT
#define CPER_ARM_ERR_PARTICIPATION_TYPE_MASK
#define CPER_ARM_ERR_TIME_OUT_SHIFT
#define CPER_ARM_ERR_TIME_OUT_MASK
#define CPER_ARM_ERR_ADDRESS_SPACE_SHIFT
#define CPER_ARM_ERR_ADDRESS_SPACE_MASK
#define CPER_ARM_ERR_MEM_ATTRIBUTES_SHIFT
#define CPER_ARM_ERR_MEM_ATTRIBUTES_MASK
#define CPER_ARM_ERR_ACCESS_MODE_SHIFT
#define CPER_ARM_ERR_ACCESS_MODE_MASK

/*
 * All tables and structs must be byte-packed to match CPER
 * specification, since the tables are provided by the system BIOS
 */
#pragma pack(1)

/* Record Header, UEFI v2.7 sec N.2.1 */
struct cper_record_header {};

/* Section Descriptor, UEFI v2.7 sec N.2.2 */
struct cper_section_descriptor {};

/* Generic Processor Error Section, UEFI v2.7 sec N.2.4.1 */
struct cper_sec_proc_generic {};

/* IA32/X64 Processor Error Section, UEFI v2.7 sec N.2.4.2 */
struct cper_sec_proc_ia {};

/* IA32/X64 Processor Error Information Structure, UEFI v2.7 sec N.2.4.2.1 */
struct cper_ia_err_info {};

/* IA32/X64 Processor Context Information Structure, UEFI v2.7 sec N.2.4.2.2 */
struct cper_ia_proc_ctx {};

/* ARM Processor Error Section, UEFI v2.7 sec N.2.4.4 */
struct cper_sec_proc_arm {};

/* ARM Processor Error Information Structure, UEFI v2.7 sec N.2.4.4.1 */
struct cper_arm_err_info {};

/* ARM Processor Context Information Structure, UEFI v2.7 sec N.2.4.4.2 */
struct cper_arm_ctx_info {};

/* Old Memory Error Section, UEFI v2.1, v2.2 */
struct cper_sec_mem_err_old {};

/* Memory Error Section (UEFI >= v2.3), UEFI v2.8 sec N.2.5 */
struct cper_sec_mem_err {};

struct cper_mem_err_compact {};

static inline u32 cper_get_mem_extension(u64 mem_valid, u8 mem_extended)
{}

/* PCI Express Error Section, UEFI v2.7 sec N.2.7 */
struct cper_sec_pcie {};

/* Firmware Error Record Reference, UEFI v2.7 sec N.2.10  */
struct cper_sec_fw_err_rec_ref {};

/* Reset to default packing */
#pragma pack()

extern const char *const cper_proc_error_type_strs[4];

u64 cper_next_record_id(void);
const char *cper_severity_str(unsigned int);
const char *cper_mem_err_type_str(unsigned int);
const char *cper_mem_err_status_str(u64 status);
void cper_print_bits(const char *prefix, unsigned int bits,
		     const char * const strs[], unsigned int strs_size);
void cper_mem_err_pack(const struct cper_sec_mem_err *,
		       struct cper_mem_err_compact *);
const char *cper_mem_err_unpack(struct trace_seq *,
				struct cper_mem_err_compact *);
void cper_print_proc_arm(const char *pfx,
			 const struct cper_sec_proc_arm *proc);
void cper_print_proc_ia(const char *pfx,
			const struct cper_sec_proc_ia *proc);
int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg);
int cper_dimm_err_location(struct cper_mem_err_compact *mem, char *msg);

struct acpi_hest_generic_status;
void cper_estatus_print(const char *pfx,
			const struct acpi_hest_generic_status *estatus);
int cper_estatus_check_header(const struct acpi_hest_generic_status *estatus);
int cper_estatus_check(const struct acpi_hest_generic_status *estatus);

#endif