Formatting .c/.h files and fix memory leakage issues
Signed-off-by: John Chung <john.chung@arm.com>
Change-Id: Id8328f412c2724992d80c0b3f895c8f85bc4ae68
diff --git a/sections/cper-section-arm.c b/sections/cper-section-arm.c
index 6537f40..e0f7cb5 100644
--- a/sections/cper-section-arm.c
+++ b/sections/cper-section-arm.c
@@ -7,7 +7,7 @@
#include <stdio.h>
#include <json.h>
-#include "b64.h"
+#include "libbase64.h"
#include "../edk/Cper.h"
#include "../cper-utils.h"
#include "cper-section-arm.h"
@@ -40,13 +40,10 @@
void ir_arm_aarch64_el2_to_cper(json_object *registers, FILE *out);
void ir_arm_aarch64_el3_to_cper(json_object *registers, FILE *out);
void ir_arm_misc_registers_to_cper(json_object *registers, FILE *out);
-void ir_arm_unknown_register_to_cper(json_object *registers,
- EFI_ARM_CONTEXT_INFORMATION_HEADER *header,
- FILE *out);
+void ir_arm_unknown_register_to_cper(json_object *registers, FILE *out);
//Converts the given processor-generic CPER section into JSON IR.
-json_object *cper_section_arm_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_arm_to_ir(void *section)
{
EFI_ARM_ERROR_RECORD *record = (EFI_ARM_ERROR_RECORD *)section;
json_object *section_ir = json_object_new_object();
@@ -71,8 +68,8 @@
json_object_object_add(
error_affinity, "type",
json_object_new_string(record->ErrorAffinityLevel < 4 ?
- "Vendor Defined" :
- "Reserved"));
+ "Vendor Defined" :
+ "Reserved"));
json_object_object_add(section_ir, "errorAffinity", error_affinity);
//Processor ID (MPIDR_EL1) and chip ID (MIDR_EL1).
@@ -84,7 +81,7 @@
//Whether the processor is running, and the state of it if so.
json_object_object_add(section_ir, "running",
json_object_new_boolean(record->RunningState &
- 0b1));
+ 0x1));
if (!(record->RunningState >> 31)) {
//Bit 32 of running state is on, so PSCI state information is included.
//This can't be made human readable, as it is unknown whether this will be the pre-PSCI 1.0 format
@@ -107,29 +104,38 @@
//Processor context structures.
//The current position is moved within the processing, as it is a dynamic size structure.
- void *cur_pos = (void *)cur_error;
+ uint8_t *cur_pos = (uint8_t *)cur_error;
json_object *context_info_array = json_object_new_array();
for (int i = 0; i < record->ContextInfoNum; i++) {
EFI_ARM_CONTEXT_INFORMATION_HEADER *header =
(EFI_ARM_CONTEXT_INFORMATION_HEADER *)cur_pos;
json_object *processor_context =
- cper_arm_processor_context_to_ir(header, &cur_pos);
+ cper_arm_processor_context_to_ir(header,
+ (void **)&cur_pos);
json_object_array_add(context_info_array, processor_context);
}
json_object_object_add(section_ir, "contextInfo", context_info_array);
//Is there any vendor-specific information following?
- if (cur_pos < section + record->SectionLength) {
+ if (cur_pos < (uint8_t *)section + record->SectionLength) {
json_object *vendor_specific = json_object_new_object();
- char *encoded =
- b64_encode((unsigned char *)cur_pos,
- section + record->SectionLength - cur_pos);
- json_object_object_add(vendor_specific, "data",
- json_object_new_string(encoded));
- free(encoded);
+ size_t input_size =
+ (uint8_t *)section + record->SectionLength - cur_pos;
+ char *encoded = malloc(2 * input_size);
+ size_t encoded_len = 0;
+ if (!encoded) {
+ printf("Failed to allocate encode output buffer. \n");
+ } else {
+ base64_encode((const char *)cur_pos, input_size,
+ encoded, &encoded_len, 0);
+ json_object_object_add(vendor_specific, "data",
+ json_object_new_string_len(
+ encoded, encoded_len));
+ free(encoded);
- json_object_object_add(section_ir, "vendorSpecificInfo",
- vendor_specific);
+ json_object_object_add(section_ir, "vendorSpecificInfo",
+ vendor_specific);
+ }
}
return section_ir;
@@ -166,8 +172,8 @@
json_object_object_add(
multiple_error, "type",
json_object_new_string(error_info->MultipleError < 1 ?
- "Single Error" :
- "Multiple Errors"));
+ "Single Error" :
+ "Multiple Errors"));
json_object_object_add(error_info_ir, "multipleError", multiple_error);
//Flags.
@@ -179,7 +185,7 @@
json_object *error_subinfo = NULL;
switch (error_info->Type) {
case ARM_ERROR_INFORMATION_TYPE_CACHE: //Cache
- case ARM_ERROR_INFORMATION_TYPE_TLB: //TLB
+ case ARM_ERROR_INFORMATION_TYPE_TLB: //TLB
error_subinfo = cper_arm_cache_tlb_error_to_ir(
(EFI_ARM_CACHE_ERROR_STRUCTURE *)&error_info
->ErrorInformation,
@@ -340,7 +346,7 @@
json_object_object_add(
access_mode, "name",
json_object_new_string(bus_error->AccessMode == 0 ? "Secure" :
- "Normal"));
+ "Normal"));
json_object_object_add(bus_error_ir, "accessMode", access_mode);
return bus_error_ir;
@@ -435,11 +441,19 @@
default:
//Unknown register array type, add as base64 data instead.
register_array = json_object_new_object();
- char *encoded = b64_encode((unsigned char *)cur_pos,
- header->RegisterArraySize);
- json_object_object_add(register_array, "data",
- json_object_new_string(encoded));
- free(encoded);
+ char *encoded = malloc(2 * header->RegisterArraySize);
+ size_t encoded_len = 0;
+ if (!encoded) {
+ printf("Failed to allocate encode output buffer. \n");
+ } else {
+ base64_encode((const char *)cur_pos,
+ header->RegisterArraySize, encoded,
+ &encoded_len, 0);
+ json_object_object_add(register_array, "data",
+ json_object_new_string_len(
+ encoded, encoded_len));
+ free(encoded);
+ }
break;
}
json_object_object_add(context_ir, "registerArray", register_array);
@@ -478,7 +492,6 @@
{
EFI_ARM_ERROR_RECORD *section_cper =
(EFI_ARM_ERROR_RECORD *)calloc(1, sizeof(EFI_ARM_ERROR_RECORD));
- long starting_stream_pos = ftell(out);
//Validation bits.
section_cper->ValidFields = ir_to_bitfield(
@@ -505,8 +518,9 @@
//Optional PSCI state.
json_object *psci_state = json_object_object_get(section, "psciState");
- if (psci_state != NULL)
+ if (psci_state != NULL) {
section_cper->PsciState = json_object_get_uint64(psci_state);
+ }
//Flush header to stream.
fwrite(section_cper, sizeof(EFI_ARM_ERROR_RECORD), 1, out);
@@ -514,16 +528,18 @@
//Error info structure array.
json_object *error_info = json_object_object_get(section, "errorInfo");
- for (int i = 0; i < section_cper->ErrInfoNum; i++)
+ for (int i = 0; i < section_cper->ErrInfoNum; i++) {
ir_arm_error_info_to_cper(
json_object_array_get_idx(error_info, i), out);
+ }
//Context info structure array.
json_object *context_info =
json_object_object_get(section, "contextInfo");
- for (int i = 0; i < section_cper->ContextInfoNum; i++)
+ for (int i = 0; i < section_cper->ContextInfoNum; i++) {
ir_arm_context_info_to_cper(
json_object_array_get_idx(context_info, i), out);
+ }
//Vendor specific error info.
json_object *vendor_specific_info =
@@ -533,18 +549,20 @@
json_object_object_get(vendor_specific_info, "data");
int vendor_specific_len =
json_object_get_string_len(vendor_info_string);
- UINT8 *decoded =
- b64_decode(json_object_get_string(vendor_info_string),
- vendor_specific_len);
+ char *decoded = malloc(vendor_specific_len);
+ size_t decoded_len = 0;
+ if (!decoded) {
+ printf("Failed to allocate decode output buffer. \n");
+ } else {
+ base64_decode(
+ json_object_get_string(vendor_info_string),
+ vendor_specific_len, decoded, &decoded_len, 0);
- //Write out to file.
- long cur_stream_pos = ftell(out);
- fwrite(decoded,
- starting_stream_pos + section_cper->SectionLength -
- cur_stream_pos,
- 1, out);
- fflush(out);
- free(decoded);
+ //Write out to file.
+ fwrite(decoded, decoded_len, 1, out);
+ fflush(out);
+ free(decoded);
+ }
}
//Free remaining resources.
@@ -730,8 +748,7 @@
break;
default:
//Unknown register structure.
- ir_arm_unknown_register_to_cper(register_array, &info_header,
- out);
+ ir_arm_unknown_register_to_cper(register_array, out);
break;
}
}
@@ -883,17 +900,22 @@
}
//Converts a single ARM unknown register CPER-JSON object to CPER binary, outputting to the given stream.
-void ir_arm_unknown_register_to_cper(json_object *registers,
- EFI_ARM_CONTEXT_INFORMATION_HEADER *header,
- FILE *out)
+void ir_arm_unknown_register_to_cper(json_object *registers, FILE *out)
{
//Get base64 represented data.
json_object *encoded = json_object_object_get(registers, "data");
- UINT8 *decoded = b64_decode(json_object_get_string(encoded),
- json_object_get_string_len(encoded));
+ char *decoded = malloc(json_object_get_string_len(encoded));
+ size_t decoded_len = 0;
+ if (!decoded) {
+ printf("Failed to allocate decode output buffer. \n");
+ } else {
+ base64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded), decoded,
+ &decoded_len, 0);
- //Flush out to stream.
- fwrite(&decoded, header->RegisterArraySize, 1, out);
- fflush(out);
- free(decoded);
-}
\ No newline at end of file
+ //Flush out to stream.
+ fwrite(&decoded, decoded_len, 1, out);
+ fflush(out);
+ free(decoded);
+ }
+}
diff --git a/sections/cper-section-arm.h b/sections/cper-section-arm.h
index 1468405..5ee18d8 100644
--- a/sections/cper-section-arm.h
+++ b/sections/cper-section-arm.h
@@ -4,332 +4,458 @@
#include <json.h>
#include "../edk/Cper.h"
-#define ARM_ERROR_VALID_BITFIELD_NAMES (const char*[]) \
- {"mpidrValid", "errorAffinityLevelValid", "runningStateValid", "vendorSpecificInfoValid"}
-#define ARM_ERROR_INFO_ENTRY_VALID_BITFIELD_NAMES (const char*[]) \
- {"multipleErrorValid", "flagsValid", "errorInformationValid", "virtualFaultAddressValid", "physicalFaultAddressValid"}
-#define ARM_ERROR_INFO_ENTRY_FLAGS_NAMES (const char*[]) \
- {"firstErrorCaptured", "lastErrorCaptured", "propagated", "overflow"}
-#define ARM_CACHE_TLB_ERROR_VALID_BITFIELD_NAMES (const char*[]) \
- {"transactionTypeValid", "operationValid", "levelValid", "processorContextCorruptValid", "correctedValid", \
- "precisePCValid", "restartablePCValid"}
-#define ARM_BUS_ERROR_VALID_BITFIELD_NAMES (const char*[]) \
- {"transactionTypeValid", "operationValid", "levelValid", "processorContextCorruptValid", "correctedValid", \
- "precisePCValid", "restartablePCValid", "participationTypeValid", "timedOutValid", "addressSpaceValid", \
- "memoryAttributesValid", "accessModeValid"}
-#define ARM_ERROR_TRANSACTION_TYPES_KEYS (int []){0, 1, 2}
-#define ARM_ERROR_TRANSACTION_TYPES_VALUES (const char*[]){"Instruction", "Data Access", "Generic"}
-#define ARM_ERROR_INFO_ENTRY_INFO_TYPES_KEYS (int []){0, 1, 2, 3}
-#define ARM_ERROR_INFO_ENTRY_INFO_TYPES_VALUES (const char*[]){"Cache Error", "TLB Error", \
- "Bus Error", "Micro-Architectural Error"}
-#define ARM_CACHE_BUS_OPERATION_TYPES_KEYS (int []){0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
-#define ARM_CACHE_BUS_OPERATION_TYPES_VALUES (const char*[]){"Generic Error", "Generic Read", "Generic Write", \
- "Data Read", "Data Write", "Instruction Fetch", "Prefetch", "Eviction", "Snooping", "Snooped", "Management"}
-#define ARM_TLB_OPERATION_TYPES_KEYS (int []){0, 1, 2, 3, 4, 5, 6, 7, 8}
-#define ARM_TLB_OPERATION_TYPES_VALUES (const char*[]){"Generic Error", "Generic Read", "Generic Write", \
- "Data Read", "Data Write", "Instruction Fetch", "Prefetch", "Local Management Operation", \
- "External Management Operation"}
-#define ARM_BUS_PARTICIPATION_TYPES_KEYS (int []){0, 1, 2, 3}
-#define ARM_BUS_PARTICIPATION_TYPES_VALUES (const char*[]){"Local Processor Originated Request", \
- "Local Processor Responded to Request", "Local Processor Observed", "Generic"}
-#define ARM_BUS_ADDRESS_SPACE_TYPES_KEYS (int []){0, 1, 3}
-#define ARM_BUS_ADDRESS_SPACE_TYPES_VALUES (const char*[]){"External Memory Access", "Internal Memory Access", \
- "Device Memory Access"}
-#define ARM_PROCESSOR_INFO_REGISTER_CONTEXT_TYPES_KEYS (int []){0, 1, 2, 3, 4, 5, 6, 7, 8}
-#define ARM_PROCESSOR_INFO_REGISTER_CONTEXT_TYPES_VALUES (const char*[]){"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", "Miscellaneous System Register Structure"}
-#define ARM_AARCH32_GPR_NAMES (const char*[]){"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", \
- "r10", "r11", "r12", "r13_sp", "r14_lr", "r15_pc"}
-#define ARM_AARCH32_EL1_REGISTER_NAMES (const char*[]){"dfar", "dfsr", "ifar", "isr", "mair0", "mair1", "midr", \
- "mpidr", "nmrr", "prrr", "sctlr_ns", "spsr", "spsr_abt", "spsr_fiq", "spsr_irq", "spsr_svc", "spsr_und", \
- "tpidrprw", "tpidruro", "tpidrurw", "ttbcr", "ttbr0", "ttbr1", "dacr"}
-#define ARM_AARCH32_EL2_REGISTER_NAMES (const char*[]){"elr_hyp", "hamair0", "hamair1", "hcr", "hcr2", "hdfar", \
- "hifar", "hpfar", "hsr", "htcr", "htpidr", "httbr", "spsr_hyp", "vtcr", "vttbr", "dacr32_el2"}
-#define ARM_AARCH32_SECURE_REGISTER_NAMES (const char*[]){"sctlr_s", "spsr_mon"}
-#define ARM_AARCH64_GPR_NAMES (const char*[]){"x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", \
- "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", "x24", "x25", "x26", \
- "x27", "x28", "x29", "x30", "sp"}
-#define ARM_AARCH64_EL1_REGISTER_NAMES (const char*[]){"elr_el1", "esr_el1", "far_el1", "isr_el1", "mair_el1", \
- "midr_el1", "mpidr_el1", "sctlr_el1", "sp_el0", "sp_el1", "spsr_el1", "tcr_el1", "tpidr_el0", "tpidr_el1", \
- "tpidrro_el0", "ttbr0_el1", "ttbr1_el1"}
-#define ARM_AARCH64_EL2_REGISTER_NAMES (const char*[]){"elr_el2", "esr_el2", "far_el2", "hacr_el2", "hcr_el2", \
- "hpfar_el2", "mair_el2", "sctlr_el2", "sp_el2", "spsr_el2", "tcr_el2", "tpidr_el2", "ttbr0_el2", "vtcr_el2", \
- "vttbr_el2"}
-#define ARM_AARCH64_EL3_REGISTER_NAMES (const char*[]){"elr_el3", "esr_el3", "far_el3", "mair_el3", "sctlr_el3", \
- "sp_el3", "spsr_el3", "tcr_el3", "tpidr_el3", "ttbr0_el3"}
+#define ARM_ERROR_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "mpidrValid", "errorAffinityLevelValid", "runningStateValid", \
+ "vendorSpecificInfoValid" \
+ }
+#define ARM_ERROR_INFO_ENTRY_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "multipleErrorValid", "flagsValid", "errorInformationValid", \
+ "virtualFaultAddressValid", \
+ "physicalFaultAddressValid" \
+ }
+#define ARM_ERROR_INFO_ENTRY_FLAGS_NAMES \
+ (const char *[]) \
+ { \
+ "firstErrorCaptured", "lastErrorCaptured", "propagated", \
+ "overflow" \
+ }
+#define ARM_CACHE_TLB_ERROR_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "transactionTypeValid", "operationValid", "levelValid", \
+ "processorContextCorruptValid", "correctedValid", \
+ "precisePCValid", "restartablePCValid" \
+ }
+#define ARM_BUS_ERROR_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "transactionTypeValid", "operationValid", "levelValid", \
+ "processorContextCorruptValid", "correctedValid", \
+ "precisePCValid", "restartablePCValid", \
+ "participationTypeValid", "timedOutValid", \
+ "addressSpaceValid", "memoryAttributesValid", \
+ "accessModeValid" \
+ }
+#define ARM_ERROR_TRANSACTION_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2 \
+ }
+#define ARM_ERROR_TRANSACTION_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Instruction", "Data Access", "Generic" \
+ }
+#define ARM_ERROR_INFO_ENTRY_INFO_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 3 \
+ }
+#define ARM_ERROR_INFO_ENTRY_INFO_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Cache Error", "TLB Error", "Bus Error", \
+ "Micro-Architectural Error" \
+ }
+#define ARM_CACHE_BUS_OPERATION_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 \
+ }
+#define ARM_CACHE_BUS_OPERATION_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Generic Error", "Generic Read", "Generic Write", "Data Read", \
+ "Data Write", "Instruction Fetch", "Prefetch", \
+ "Eviction", "Snooping", "Snooped", "Management" \
+ }
+#define ARM_TLB_OPERATION_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 3, 4, 5, 6, 7, 8 \
+ }
+#define ARM_TLB_OPERATION_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Generic Error", "Generic Read", "Generic Write", "Data Read", \
+ "Data Write", "Instruction Fetch", "Prefetch", \
+ "Local Management Operation", \
+ "External Management Operation" \
+ }
+#define ARM_BUS_PARTICIPATION_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 3 \
+ }
+#define ARM_BUS_PARTICIPATION_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Local Processor Originated Request", \
+ "Local Processor Responded to Request", \
+ "Local Processor Observed", "Generic" \
+ }
+#define ARM_BUS_ADDRESS_SPACE_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 3 \
+ }
+#define ARM_BUS_ADDRESS_SPACE_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "External Memory Access", "Internal Memory Access", \
+ "Device Memory Access" \
+ }
+#define ARM_PROCESSOR_INFO_REGISTER_CONTEXT_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 3, 4, 5, 6, 7, 8 \
+ }
+#define ARM_PROCESSOR_INFO_REGISTER_CONTEXT_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "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", \
+ "Miscellaneous System Register Structure" \
+ }
+#define ARM_AARCH32_GPR_NAMES \
+ (const char *[]) \
+ { \
+ "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", \
+ "r10", "r11", "r12", "r13_sp", "r14_lr", "r15_pc" \
+ }
+#define ARM_AARCH32_EL1_REGISTER_NAMES \
+ (const char *[]) \
+ { \
+ "dfar", "dfsr", "ifar", "isr", "mair0", "mair1", "midr", \
+ "mpidr", "nmrr", "prrr", "sctlr_ns", "spsr", \
+ "spsr_abt", "spsr_fiq", "spsr_irq", "spsr_svc", \
+ "spsr_und", "tpidrprw", "tpidruro", "tpidrurw", \
+ "ttbcr", "ttbr0", "ttbr1", "dacr" \
+ }
+#define ARM_AARCH32_EL2_REGISTER_NAMES \
+ (const char *[]) \
+ { \
+ "elr_hyp", "hamair0", "hamair1", "hcr", "hcr2", "hdfar", \
+ "hifar", "hpfar", "hsr", "htcr", "htpidr", "httbr", \
+ "spsr_hyp", "vtcr", "vttbr", "dacr32_el2" \
+ }
+#define ARM_AARCH32_SECURE_REGISTER_NAMES \
+ (const char *[]) \
+ { \
+ "sctlr_s", "spsr_mon" \
+ }
+#define ARM_AARCH64_GPR_NAMES \
+ (const char *[]) \
+ { \
+ "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", \
+ "x10", "x11", "x12", "x13", "x14", "x15", "x16", \
+ "x17", "x18", "x19", "x20", "x21", "x22", "x23", \
+ "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp" \
+ }
+#define ARM_AARCH64_EL1_REGISTER_NAMES \
+ (const char *[]) \
+ { \
+ "elr_el1", "esr_el1", "far_el1", "isr_el1", "mair_el1", \
+ "midr_el1", "mpidr_el1", "sctlr_el1", "sp_el0", \
+ "sp_el1", "spsr_el1", "tcr_el1", "tpidr_el0", \
+ "tpidr_el1", "tpidrro_el0", "ttbr0_el1", "ttbr1_el1" \
+ }
+#define ARM_AARCH64_EL2_REGISTER_NAMES \
+ (const char *[]) \
+ { \
+ "elr_el2", "esr_el2", "far_el2", "hacr_el2", "hcr_el2", \
+ "hpfar_el2", "mair_el2", "sctlr_el2", "sp_el2", \
+ "spsr_el2", "tcr_el2", "tpidr_el2", "ttbr0_el2", \
+ "vtcr_el2", "vttbr_el2" \
+ }
+#define ARM_AARCH64_EL3_REGISTER_NAMES \
+ (const char *[]) \
+ { \
+ "elr_el3", "esr_el3", "far_el3", "mair_el3", "sctlr_el3", \
+ "sp_el3", "spsr_el3", "tcr_el3", "tpidr_el3", \
+ "ttbr0_el3" \
+ }
///
/// ARM Processor Error Record
///
typedef struct {
- UINT32 ValidFields;
- UINT16 ErrInfoNum;
- UINT16 ContextInfoNum;
- UINT32 SectionLength;
- UINT32 ErrorAffinityLevel;
- UINT64 MPIDR_EL1;
- UINT64 MIDR_EL1;
- UINT32 RunningState;
- UINT32 PsciState;
+ UINT32 ValidFields;
+ UINT16 ErrInfoNum;
+ UINT16 ContextInfoNum;
+ UINT32 SectionLength;
+ UINT32 ErrorAffinityLevel;
+ UINT64 MPIDR_EL1;
+ UINT64 MIDR_EL1;
+ UINT32 RunningState;
+ UINT32 PsciState;
} __attribute__((packed, aligned(1))) EFI_ARM_ERROR_RECORD;
///
/// ARM Processor Error Information Structure
///
-#define ARM_ERROR_INFORMATION_TYPE_CACHE 0
-#define ARM_ERROR_INFORMATION_TYPE_TLB 1
-#define ARM_ERROR_INFORMATION_TYPE_BUS 2
+#define ARM_ERROR_INFORMATION_TYPE_CACHE 0
+#define ARM_ERROR_INFORMATION_TYPE_TLB 1
+#define ARM_ERROR_INFORMATION_TYPE_BUS 2
#define ARM_ERROR_INFORMATION_TYPE_MICROARCH 3
typedef struct {
- UINT64 ValidationBits : 16;
- UINT64 TransactionType : 2;
- UINT64 Operation : 4;
- UINT64 Level : 3;
- UINT64 ProcessorContextCorrupt : 1;
- UINT64 Corrected : 1;
- UINT64 PrecisePC : 1;
- UINT64 RestartablePC : 1;
- UINT64 Reserved : 34;
+ UINT64 ValidationBits : 16;
+ UINT64 TransactionType : 2;
+ UINT64 Operation : 4;
+ UINT64 Level : 3;
+ UINT64 ProcessorContextCorrupt : 1;
+ UINT64 Corrected : 1;
+ UINT64 PrecisePC : 1;
+ UINT64 RestartablePC : 1;
+ UINT64 Reserved : 34;
} EFI_ARM_CACHE_ERROR_STRUCTURE;
typedef struct {
- UINT64 ValidationBits : 16;
- UINT64 TransactionType : 2;
- UINT64 Operation : 4;
- UINT64 Level : 3;
- UINT64 ProcessorContextCorrupt : 1;
- UINT64 Corrected : 1;
- UINT64 PrecisePC : 1;
- UINT64 RestartablePC : 1;
- UINT64 Reserved : 34;
+ UINT64 ValidationBits : 16;
+ UINT64 TransactionType : 2;
+ UINT64 Operation : 4;
+ UINT64 Level : 3;
+ UINT64 ProcessorContextCorrupt : 1;
+ UINT64 Corrected : 1;
+ UINT64 PrecisePC : 1;
+ UINT64 RestartablePC : 1;
+ UINT64 Reserved : 34;
} EFI_ARM_TLB_ERROR_STRUCTURE;
typedef struct {
- UINT64 ValidationBits : 16;
- UINT64 TransactionType : 2;
- UINT64 Operation : 4;
- UINT64 Level : 3;
- UINT64 ProcessorContextCorrupt : 1;
- UINT64 Corrected : 1;
- UINT64 PrecisePC : 1;
- UINT64 RestartablePC : 1;
- UINT64 ParticipationType : 2;
- UINT64 TimeOut : 1;
- UINT64 AddressSpace : 2;
- UINT64 MemoryAddressAttributes : 8;
- UINT64 AccessMode : 1;
- UINT64 Reserved : 19;
+ UINT64 ValidationBits : 16;
+ UINT64 TransactionType : 2;
+ UINT64 Operation : 4;
+ UINT64 Level : 3;
+ UINT64 ProcessorContextCorrupt : 1;
+ UINT64 Corrected : 1;
+ UINT64 PrecisePC : 1;
+ UINT64 RestartablePC : 1;
+ UINT64 ParticipationType : 2;
+ UINT64 TimeOut : 1;
+ UINT64 AddressSpace : 2;
+ UINT64 MemoryAddressAttributes : 8;
+ UINT64 AccessMode : 1;
+ UINT64 Reserved : 19;
} EFI_ARM_BUS_ERROR_STRUCTURE;
typedef union {
- EFI_ARM_CACHE_ERROR_STRUCTURE CacheError;
- EFI_ARM_TLB_ERROR_STRUCTURE TlbError;
- EFI_ARM_BUS_ERROR_STRUCTURE BusError;
+ EFI_ARM_CACHE_ERROR_STRUCTURE CacheError;
+ EFI_ARM_TLB_ERROR_STRUCTURE TlbError;
+ EFI_ARM_BUS_ERROR_STRUCTURE BusError;
} EFI_ARM_ERROR_INFORMATION_STRUCTURE;
typedef struct {
- UINT8 Version;
- UINT8 Length;
- UINT16 ValidationBits;
- UINT8 Type;
- UINT16 MultipleError;
- UINT8 Flags;
- EFI_ARM_ERROR_INFORMATION_STRUCTURE ErrorInformation;
- UINT64 VirtualFaultAddress;
- UINT64 PhysicalFaultAddress;
+ UINT8 Version;
+ UINT8 Length;
+ UINT16 ValidationBits;
+ UINT8 Type;
+ UINT16 MultipleError;
+ UINT8 Flags;
+ EFI_ARM_ERROR_INFORMATION_STRUCTURE ErrorInformation;
+ UINT64 VirtualFaultAddress;
+ UINT64 PhysicalFaultAddress;
} __attribute__((packed, aligned(1))) EFI_ARM_ERROR_INFORMATION_ENTRY;
///
/// ARM Processor Context Information Structure
///
typedef struct {
- UINT16 Version;
- UINT16 RegisterContextType;
- UINT32 RegisterArraySize;
+ UINT16 Version;
+ UINT16 RegisterContextType;
+ UINT32 RegisterArraySize;
} __attribute__((packed, aligned(1))) EFI_ARM_CONTEXT_INFORMATION_HEADER;
///
/// ARM Processor Context Register Types
///
-#define EFI_ARM_CONTEXT_TYPE_AARCH32_GPR 0
-#define EFI_ARM_CONTEXT_TYPE_AARCH32_EL1 1
-#define EFI_ARM_CONTEXT_TYPE_AARCH32_EL2 2
+#define EFI_ARM_CONTEXT_TYPE_AARCH32_GPR 0
+#define EFI_ARM_CONTEXT_TYPE_AARCH32_EL1 1
+#define EFI_ARM_CONTEXT_TYPE_AARCH32_EL2 2
#define EFI_ARM_CONTEXT_TYPE_AARCH32_SECURE 3
-#define EFI_ARM_CONTEXT_TYPE_AARCH64_GPR 4
-#define EFI_ARM_CONTEXT_TYPE_AARCH64_EL1 5
-#define EFI_ARM_CONTEXT_TYPE_AARCH64_EL2 6
-#define EFI_ARM_CONTEXT_TYPE_AARCH64_EL3 7
-#define EFI_ARM_CONTEXT_TYPE_MISC 8
+#define EFI_ARM_CONTEXT_TYPE_AARCH64_GPR 4
+#define EFI_ARM_CONTEXT_TYPE_AARCH64_EL1 5
+#define EFI_ARM_CONTEXT_TYPE_AARCH64_EL2 6
+#define EFI_ARM_CONTEXT_TYPE_AARCH64_EL3 7
+#define EFI_ARM_CONTEXT_TYPE_MISC 8
typedef struct {
- UINT32 R0;
- UINT32 R1;
- UINT32 R2;
- UINT32 R3;
- UINT32 R4;
- UINT32 R5;
- UINT32 R6;
- UINT32 R7;
- UINT32 R8;
- UINT32 R9;
- UINT32 R10;
- UINT32 R11;
- UINT32 R12;
- UINT32 R13_sp;
- UINT32 R14_lr;
- UINT32 R15_pc;
+ UINT32 R0;
+ UINT32 R1;
+ UINT32 R2;
+ UINT32 R3;
+ UINT32 R4;
+ UINT32 R5;
+ UINT32 R6;
+ UINT32 R7;
+ UINT32 R8;
+ UINT32 R9;
+ UINT32 R10;
+ UINT32 R11;
+ UINT32 R12;
+ UINT32 R13_sp;
+ UINT32 R14_lr;
+ UINT32 R15_pc;
} EFI_ARM_V8_AARCH32_GPR;
typedef struct {
- UINT32 Dfar;
- UINT32 Dfsr;
- UINT32 Ifar;
- UINT32 Isr;
- UINT32 Mair0;
- UINT32 Mair1;
- UINT32 Midr;
- UINT32 Mpidr;
- UINT32 Nmrr;
- UINT32 Prrr;
- UINT32 Sctlr_Ns;
- UINT32 Spsr;
- UINT32 Spsr_Abt;
- UINT32 Spsr_Fiq;
- UINT32 Spsr_Irq;
- UINT32 Spsr_Svc;
- UINT32 Spsr_Und;
- UINT32 Tpidrprw;
- UINT32 Tpidruro;
- UINT32 Tpidrurw;
- UINT32 Ttbcr;
- UINT32 Ttbr0;
- UINT32 Ttbr1;
- UINT32 Dacr;
+ UINT32 Dfar;
+ UINT32 Dfsr;
+ UINT32 Ifar;
+ UINT32 Isr;
+ UINT32 Mair0;
+ UINT32 Mair1;
+ UINT32 Midr;
+ UINT32 Mpidr;
+ UINT32 Nmrr;
+ UINT32 Prrr;
+ UINT32 Sctlr_Ns;
+ UINT32 Spsr;
+ UINT32 Spsr_Abt;
+ UINT32 Spsr_Fiq;
+ UINT32 Spsr_Irq;
+ UINT32 Spsr_Svc;
+ UINT32 Spsr_Und;
+ UINT32 Tpidrprw;
+ UINT32 Tpidruro;
+ UINT32 Tpidrurw;
+ UINT32 Ttbcr;
+ UINT32 Ttbr0;
+ UINT32 Ttbr1;
+ UINT32 Dacr;
} EFI_ARM_AARCH32_EL1_CONTEXT_REGISTERS;
typedef struct {
- UINT32 Elr_Hyp;
- UINT32 Hamair0;
- UINT32 Hamair1;
- UINT32 Hcr;
- UINT32 Hcr2;
- UINT32 Hdfar;
- UINT32 Hifar;
- UINT32 Hpfar;
- UINT32 Hsr;
- UINT32 Htcr;
- UINT32 Htpidr;
- UINT32 Httbr;
- UINT32 Spsr_Hyp;
- UINT32 Vtcr;
- UINT32 Vttbr;
- UINT32 Dacr32_El2;
+ UINT32 Elr_Hyp;
+ UINT32 Hamair0;
+ UINT32 Hamair1;
+ UINT32 Hcr;
+ UINT32 Hcr2;
+ UINT32 Hdfar;
+ UINT32 Hifar;
+ UINT32 Hpfar;
+ UINT32 Hsr;
+ UINT32 Htcr;
+ UINT32 Htpidr;
+ UINT32 Httbr;
+ UINT32 Spsr_Hyp;
+ UINT32 Vtcr;
+ UINT32 Vttbr;
+ UINT32 Dacr32_El2;
} EFI_ARM_AARCH32_EL2_CONTEXT_REGISTERS;
typedef struct {
- UINT32 Sctlr_S;
- UINT32 Spsr_Mon;
+ UINT32 Sctlr_S;
+ UINT32 Spsr_Mon;
} EFI_ARM_AARCH32_SECURE_CONTEXT_REGISTERS;
typedef struct {
- UINT64 X0;
- UINT64 X1;
- UINT64 X2;
- UINT64 X3;
- UINT64 X4;
- UINT64 X5;
- UINT64 X6;
- UINT64 X7;
- UINT64 X8;
- UINT64 X9;
- UINT64 X10;
- UINT64 X11;
- UINT64 X12;
- UINT64 X13;
- UINT64 X14;
- UINT64 X15;
- UINT64 X16;
- UINT64 X17;
- UINT64 X18;
- UINT64 X19;
- UINT64 X20;
- UINT64 X21;
- UINT64 X22;
- UINT64 X23;
- UINT64 X24;
- UINT64 X25;
- UINT64 X26;
- UINT64 X27;
- UINT64 X28;
- UINT64 X29;
- UINT64 X30;
- UINT64 Sp;
+ UINT64 X0;
+ UINT64 X1;
+ UINT64 X2;
+ UINT64 X3;
+ UINT64 X4;
+ UINT64 X5;
+ UINT64 X6;
+ UINT64 X7;
+ UINT64 X8;
+ UINT64 X9;
+ UINT64 X10;
+ UINT64 X11;
+ UINT64 X12;
+ UINT64 X13;
+ UINT64 X14;
+ UINT64 X15;
+ UINT64 X16;
+ UINT64 X17;
+ UINT64 X18;
+ UINT64 X19;
+ UINT64 X20;
+ UINT64 X21;
+ UINT64 X22;
+ UINT64 X23;
+ UINT64 X24;
+ UINT64 X25;
+ UINT64 X26;
+ UINT64 X27;
+ UINT64 X28;
+ UINT64 X29;
+ UINT64 X30;
+ UINT64 Sp;
} EFI_ARM_V8_AARCH64_GPR;
typedef struct {
- UINT64 Elr_El1;
- UINT64 Esr_El1;
- UINT64 Far_El1;
- UINT64 Isr_El1;
- UINT64 Mair_El1;
- UINT64 Midr_El1;
- UINT64 Mpidr_El1;
- UINT64 Sctlr_El1;
- UINT64 Sp_El0;
- UINT64 Sp_El1;
- UINT64 Spsr_El1;
- UINT64 Tcr_El1;
- UINT64 Tpidr_El0;
- UINT64 Tpidr_El1;
- UINT64 Tpidrro_El0;
- UINT64 Ttbr0_El1;
- UINT64 Ttbr1_El1;
+ UINT64 Elr_El1;
+ UINT64 Esr_El1;
+ UINT64 Far_El1;
+ UINT64 Isr_El1;
+ UINT64 Mair_El1;
+ UINT64 Midr_El1;
+ UINT64 Mpidr_El1;
+ UINT64 Sctlr_El1;
+ UINT64 Sp_El0;
+ UINT64 Sp_El1;
+ UINT64 Spsr_El1;
+ UINT64 Tcr_El1;
+ UINT64 Tpidr_El0;
+ UINT64 Tpidr_El1;
+ UINT64 Tpidrro_El0;
+ UINT64 Ttbr0_El1;
+ UINT64 Ttbr1_El1;
} EFI_ARM_AARCH64_EL1_CONTEXT_REGISTERS;
typedef struct {
- UINT64 Elr_El2;
- UINT64 Esr_El2;
- UINT64 Far_El2;
- UINT64 Hacr_El2;
- UINT64 Hcr_El2;
- UINT64 Hpfar_El2;
- UINT64 Mair_El2;
- UINT64 Sctlr_El2;
- UINT64 Sp_El2;
- UINT64 Spsr_El2;
- UINT64 Tcr_El2;
- UINT64 Tpidr_El2;
- UINT64 Ttbr0_El2;
- UINT64 Vtcr_El2;
- UINT64 Vttbr_El2;
+ UINT64 Elr_El2;
+ UINT64 Esr_El2;
+ UINT64 Far_El2;
+ UINT64 Hacr_El2;
+ UINT64 Hcr_El2;
+ UINT64 Hpfar_El2;
+ UINT64 Mair_El2;
+ UINT64 Sctlr_El2;
+ UINT64 Sp_El2;
+ UINT64 Spsr_El2;
+ UINT64 Tcr_El2;
+ UINT64 Tpidr_El2;
+ UINT64 Ttbr0_El2;
+ UINT64 Vtcr_El2;
+ UINT64 Vttbr_El2;
} EFI_ARM_AARCH64_EL2_CONTEXT_REGISTERS;
typedef struct {
- UINT64 Elr_El3;
- UINT64 Esr_El3;
- UINT64 Far_El3;
- UINT64 Mair_El3;
- UINT64 Sctlr_El3;
- UINT64 Sp_El3;
- UINT64 Spsr_El3;
- UINT64 Tcr_El3;
- UINT64 Tpidr_El3;
- UINT64 Ttbr0_El3;
+ UINT64 Elr_El3;
+ UINT64 Esr_El3;
+ UINT64 Far_El3;
+ UINT64 Mair_El3;
+ UINT64 Sctlr_El3;
+ UINT64 Sp_El3;
+ UINT64 Spsr_El3;
+ UINT64 Tcr_El3;
+ UINT64 Tpidr_El3;
+ UINT64 Ttbr0_El3;
} EFI_ARM_AARCH64_EL3_CONTEXT_REGISTERS;
typedef struct {
- UINT64 MrsOp2 : 3;
- UINT64 MrsCrm : 4;
- UINT64 MrsCrn : 4;
- UINT64 MrsOp1 : 3;
- UINT64 MrsO0 : 1;
- UINT64 Value : 64;
+ UINT64 MrsOp2 : 3;
+ UINT64 MrsCrm : 4;
+ UINT64 MrsCrn : 4;
+ UINT64 MrsOp1 : 3;
+ UINT64 MrsO0 : 1;
+ UINT64 Value : 64;
} EFI_ARM_MISC_CONTEXT_REGISTER;
-json_object* cper_section_arm_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-void ir_section_arm_to_cper(json_object* section, FILE* out);
+json_object *cper_section_arm_to_ir(void *section);
+void ir_section_arm_to_cper(json_object *section, FILE *out);
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section-ccix-per.c b/sections/cper-section-ccix-per.c
index 4240afc..3b08cde 100644
--- a/sections/cper-section-ccix-per.c
+++ b/sections/cper-section-ccix-per.c
@@ -7,15 +7,13 @@
#include <stdio.h>
#include <string.h>
#include <json.h>
-#include "b64.h"
+#include "libbase64.h"
#include "../edk/Cper.h"
#include "../cper-utils.h"
#include "cper-section-ccix-per.h"
//Converts a single CCIX PER log CPER section into JSON IR.
-json_object *
-cper_section_ccix_per_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_ccix_per_to_ir(void *section)
{
EFI_CCIX_PER_LOG_DATA *ccix_error = (EFI_CCIX_PER_LOG_DATA *)section;
json_object *section_ir = json_object_new_object();
@@ -37,14 +35,22 @@
//CCIX PER Log.
//This is formatted as described in Section 7.3.2 of CCIX Base Specification (Rev 1.0).
- unsigned char *cur_pos = (unsigned char *)(ccix_error + 1);
+ const char *cur_pos = (const char *)(ccix_error + 1);
int remaining_length =
ccix_error->Length - sizeof(EFI_CCIX_PER_LOG_DATA);
if (remaining_length > 0) {
- char *encoded = b64_encode(cur_pos, remaining_length);
- json_object_object_add(section_ir, "ccixPERLog",
- json_object_new_string(encoded));
- free(encoded);
+ char *encoded = malloc(2 * remaining_length);
+ size_t encoded_len = 0;
+ if (!encoded) {
+ printf("Failed to allocate encode output buffer. \n");
+ } else {
+ base64_encode((const char *)cur_pos, remaining_length,
+ encoded, &encoded_len, 0);
+ json_object_object_add(section_ir, "ccixPERLog",
+ json_object_new_string_len(
+ encoded, encoded_len));
+ free(encoded);
+ }
}
return section_ir;
@@ -77,13 +83,19 @@
//Write CCIX PER log itself to stream.
json_object *encoded = json_object_object_get(section, "ccixPERLog");
- UINT8 *decoded = b64_decode(json_object_get_string(encoded),
- json_object_get_string_len(encoded));
- fwrite(decoded, section_cper->Length - sizeof(EFI_CCIX_PER_LOG_DATA), 1,
- out);
- fflush(out);
+ char *decoded = malloc(json_object_get_string_len(encoded));
+ size_t decoded_len = 0;
+ if (!decoded) {
+ printf("Failed to allocate decode output buffer. \n");
+ } else {
+ base64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded), decoded,
+ &decoded_len, 0);
+ fwrite(decoded, decoded_len, 1, out);
+ fflush(out);
+ }
//Free resources.
free(decoded);
free(section_cper);
-}
\ No newline at end of file
+}
diff --git a/sections/cper-section-ccix-per.h b/sections/cper-section-ccix-per.h
index a6a557c..86e277c 100644
--- a/sections/cper-section-ccix-per.h
+++ b/sections/cper-section-ccix-per.h
@@ -4,20 +4,24 @@
#include <json.h>
#include "../edk/Cper.h"
-#define CCIX_PER_ERROR_VALID_BITFIELD_NAMES (const char*[]) {"ccixSourceIDValid", "ccixPortIDValid", "ccixPERLogValid"}
+#define CCIX_PER_ERROR_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "ccixSourceIDValid", "ccixPortIDValid", "ccixPERLogValid" \
+ }
///
/// CCIX PER Log Error Section
///
typedef struct {
- UINT32 Length;
- UINT64 ValidBits;
- UINT8 CcixSourceId;
- UINT8 CcixPortId;
- UINT16 Reserved;
+ UINT32 Length;
+ UINT64 ValidBits;
+ UINT8 CcixSourceId;
+ UINT8 CcixPortId;
+ UINT16 Reserved;
} __attribute__((packed, aligned(1))) EFI_CCIX_PER_LOG_DATA;
-json_object* cper_section_ccix_per_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-void ir_section_ccix_per_to_cper(json_object* section, FILE* out);
+json_object *cper_section_ccix_per_to_ir(void *section);
+void ir_section_ccix_per_to_cper(json_object *section, FILE *out);
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section-cxl-component.c b/sections/cper-section-cxl-component.c
index 098b20d..aa5a0d2 100644
--- a/sections/cper-section-cxl-component.c
+++ b/sections/cper-section-cxl-component.c
@@ -6,15 +6,13 @@
**/
#include <stdio.h>
#include <json.h>
-#include "b64.h"
+#include "libbase64.h"
#include "../edk/Cper.h"
#include "../cper-utils.h"
#include "cper-section-cxl-component.h"
//Converts a single CXL component error CPER section into JSON IR.
-json_object *
-cper_section_cxl_component_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_cxl_component_to_ir(void *section)
{
EFI_CXL_COMPONENT_EVENT_HEADER *cxl_error =
(EFI_CXL_COMPONENT_EVENT_HEADER *)section;
@@ -60,16 +58,26 @@
json_object_new_uint64(cxl_error->DeviceSerial));
//The specification for this is defined within the CXL Specification Section 8.2.9.1.
- unsigned char *cur_pos = (unsigned char *)(cxl_error + 1);
- int remaining_len = cxl_error->Length - sizeof(cxl_error);
+ const char *cur_pos = (const char *)(cxl_error + 1);
+ int remaining_len =
+ cxl_error->Length - sizeof(EFI_CXL_COMPONENT_EVENT_HEADER);
if (remaining_len > 0) {
json_object *event_log = json_object_new_object();
- char *encoded = b64_encode(cur_pos, remaining_len);
- json_object_object_add(event_log, "data",
- json_object_new_string(encoded));
- free(encoded);
- json_object_object_add(section_ir, "cxlComponentEventLog",
- event_log);
+ char *encoded = malloc(2 * remaining_len);
+ size_t encoded_len = 0;
+ if (!encoded) {
+ printf("Failed to allocate encode output buffer. \n");
+ } else {
+ base64_encode((const char *)cur_pos, remaining_len,
+ encoded, &encoded_len, 0);
+ json_object_object_add(event_log, "data",
+ json_object_new_string_len(
+ encoded, encoded_len));
+
+ free(encoded);
+ json_object_object_add(
+ section_ir, "cxlComponentEventLog", event_log);
+ }
}
return section_ir;
@@ -121,13 +129,18 @@
json_object *event_log =
json_object_object_get(section, "cxlComponentEventLog");
json_object *encoded = json_object_object_get(event_log, "data");
- int log_length =
- section_cper->Length - sizeof(EFI_CXL_COMPONENT_EVENT_HEADER);
- char *decoded = b64_decode(json_object_get_string(encoded),
- json_object_get_string_len(encoded));
- fwrite(decoded, log_length, 1, out);
- fflush(out);
- free(decoded);
+ char *decoded = malloc(json_object_get_string_len(encoded));
+ size_t decoded_len = 0;
+ if (!decoded) {
+ printf("Failed to allocate decode output buffer. \n");
+ } else {
+ base64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded), decoded,
+ &decoded_len, 0);
+ fwrite(decoded, decoded_len, 1, out);
+ fflush(out);
+ free(decoded);
+ }
free(section_cper);
-}
\ No newline at end of file
+}
diff --git a/sections/cper-section-cxl-component.h b/sections/cper-section-cxl-component.h
index 21a1374..69b9066 100644
--- a/sections/cper-section-cxl-component.h
+++ b/sections/cper-section-cxl-component.h
@@ -4,32 +4,36 @@
#include <json.h>
#include "../edk/Cper.h"
-#define CXL_COMPONENT_ERROR_VALID_BITFIELD_NAMES (const char*[]) {"deviceIDValid", "deviceSerialValid", \
- "cxlComponentEventLogValid"}
+#define CXL_COMPONENT_ERROR_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "deviceIDValid", "deviceSerialValid", \
+ "cxlComponentEventLogValid" \
+ }
///
/// CXL Generic Component Error Section
///
typedef struct {
- UINT64 VendorId : 16;
- UINT64 DeviceId : 16;
- UINT64 FunctionNumber : 8;
- UINT64 DeviceNumber : 8;
- UINT64 BusNumber : 8;
- UINT64 SegmentNumber : 16;
- UINT64 Resv1 : 3;
- UINT64 SlotNumber : 13;
- UINT64 Resv2 : 8;
+ UINT64 VendorId : 16;
+ UINT64 DeviceId : 16;
+ UINT64 FunctionNumber : 8;
+ UINT64 DeviceNumber : 8;
+ UINT64 BusNumber : 8;
+ UINT64 SegmentNumber : 16;
+ UINT64 Resv1 : 3;
+ UINT64 SlotNumber : 13;
+ UINT64 Resv2 : 8;
} __attribute__((packed, aligned(1))) EFI_CXL_DEVICE_ID_INFO;
typedef struct {
- UINT32 Length;
- UINT64 ValidBits;
- EFI_CXL_DEVICE_ID_INFO DeviceId;
- UINT64 DeviceSerial;
+ UINT32 Length;
+ UINT64 ValidBits;
+ EFI_CXL_DEVICE_ID_INFO DeviceId;
+ UINT64 DeviceSerial;
} __attribute__((packed, aligned(1))) EFI_CXL_COMPONENT_EVENT_HEADER;
-json_object* cper_section_cxl_component_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-void ir_section_cxl_component_to_cper(json_object* section, FILE* out);
+json_object *cper_section_cxl_component_to_ir(void *section);
+void ir_section_cxl_component_to_cper(json_object *section, FILE *out);
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section-cxl-protocol.c b/sections/cper-section-cxl-protocol.c
index 7cb1bbe..277731a 100644
--- a/sections/cper-section-cxl-protocol.c
+++ b/sections/cper-section-cxl-protocol.c
@@ -6,16 +6,13 @@
**/
#include <stdio.h>
#include <string.h>
-#include <json.h>
-#include "b64.h"
+#include "libbase64.h"
#include "../edk/Cper.h"
#include "../cper-utils.h"
#include "cper-section-cxl-protocol.h"
//Converts a single CXL protocol error CPER section into JSON IR.
-json_object *
-cper_section_cxl_protocol_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_cxl_protocol_to_ir(void *section)
{
EFI_CXL_PROTOCOL_ERROR_DATA *cxl_protocol_error =
(EFI_CXL_PROTOCOL_ERROR_DATA *)section;
@@ -106,11 +103,20 @@
//The PCIe capability structure provided here could either be PCIe 1.1 Capability Structure
//(36-byte, padded to 60 bytes) or PCIe 2.0 Capability Structure (60-byte). There does not seem
//to be a way to differentiate these, so this is left as a b64 dump.
- char *encoded = b64_encode(
- cxl_protocol_error->CapabilityStructure.PcieCap, 60);
- json_object_object_add(section_ir, "capabilityStructure",
- json_object_new_string(encoded));
- free(encoded);
+ char *encoded = malloc(2 * 60);
+ size_t encoded_len = 0;
+ if (!encoded) {
+ printf("Failed to allocate encode output buffer. \n");
+ } else {
+ base64_encode((const char *)cxl_protocol_error
+ ->CapabilityStructure.PcieCap,
+ 60, encoded, &encoded_len, 0);
+ json_object_object_add(section_ir,
+ "capabilityStructure",
+ json_object_new_string_len(
+ encoded, encoded_len));
+ free(encoded);
+ }
}
//CXL DVSEC & error log length.
@@ -124,20 +130,36 @@
//CXL DVSEC
//For CXL 1.1 devices, this is the "CXL DVSEC For Flex Bus Device" structure as in CXL 1.1 spec.
//For CXL 1.1 host downstream ports, this is the "CXL DVSEC For Flex Bus Port" structure as in CXL 1.1 spec.
- unsigned char *cur_pos = (unsigned char *)(cxl_protocol_error + 1);
- char *encoded = b64_encode(cur_pos, cxl_protocol_error->CxlDvsecLength);
- json_object_object_add(section_ir, "cxlDVSEC",
- json_object_new_string(encoded));
- free(encoded);
+ const char *cur_pos = (const char *)(cxl_protocol_error + 1);
+ char *encoded = malloc(2 * cxl_protocol_error->CxlDvsecLength);
+ size_t encoded_len = 0;
+ if (!encoded) {
+ printf("Failed to allocate encode output buffer. \n");
+ } else {
+ base64_encode(cur_pos, cxl_protocol_error->CxlDvsecLength,
+ encoded, &encoded_len, 0);
+ json_object_object_add(section_ir, "cxlDVSEC",
+ json_object_new_string_len(encoded,
+ encoded_len));
+
+ free(encoded);
+ }
cur_pos += cxl_protocol_error->CxlDvsecLength;
//CXL Error Log
//This is the "CXL RAS Capability Structure" as in CXL 1.1 spec.
- encoded = b64_encode(cur_pos, cxl_protocol_error->CxlErrorLogLength);
- json_object_object_add(section_ir, "cxlErrorLog",
- json_object_new_string(encoded));
- free(encoded);
-
+ encoded = malloc(2 * cxl_protocol_error->CxlErrorLogLength);
+ encoded_len = 0;
+ if (!encoded) {
+ printf("Failed to allocate encode output buffer. \n");
+ } else {
+ base64_encode(cur_pos, cxl_protocol_error->CxlErrorLogLength,
+ encoded, &encoded_len, 0);
+ json_object_object_add(section_ir, "cxlErrorLog",
+ json_object_new_string_len(encoded,
+ encoded_len));
+ free(encoded);
+ }
return section_ir;
}
@@ -207,10 +229,18 @@
json_object *encoded =
json_object_object_get(section, "capabilityStructure");
- char *decoded = b64_decode(json_object_get_string(encoded),
- json_object_get_string_len(encoded));
- memcpy(section_cper->CapabilityStructure.PcieCap, decoded, 60);
- free(decoded);
+ char *decoded = malloc(json_object_get_string_len(encoded));
+ size_t decoded_len = 0;
+ if (!decoded) {
+ printf("Failed to allocate decode output buffer. \n");
+ } else {
+ base64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded),
+ decoded, &decoded_len, 0);
+ memcpy(section_cper->CapabilityStructure.PcieCap,
+ decoded, decoded_len);
+ free(decoded);
+ }
}
//DVSEC length & error log length.
@@ -225,19 +255,33 @@
//DVSEC out to stream.
json_object *encoded = json_object_object_get(section, "cxlDVSEC");
- char *decoded = b64_decode(json_object_get_string(encoded),
- json_object_get_string_len(encoded));
- fwrite(decoded, section_cper->CxlDvsecLength, 1, out);
- fflush(out);
- free(decoded);
+ char *decoded = malloc(json_object_get_string_len(encoded));
+ size_t decoded_len = 0;
+ if (!decoded) {
+ printf("Failed to allocate decode output buffer. \n");
+ } else {
+ base64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded), decoded,
+ &decoded_len, 0);
+ fwrite(decoded, decoded_len, 1, out);
+ fflush(out);
+ free(decoded);
+ }
//Error log out to stream.
encoded = json_object_object_get(section, "cxlErrorLog");
- decoded = b64_decode(json_object_get_string(encoded),
- json_object_get_string_len(encoded));
- fwrite(decoded, section_cper->CxlErrorLogLength, 1, out);
- fflush(out);
- free(decoded);
+ decoded = malloc(json_object_get_string_len(encoded));
+ decoded_len = 0;
+ if (!decoded) {
+ printf("Failed to allocate decode output buffer. \n");
+ } else {
+ base64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded), decoded,
+ &decoded_len, 0);
+ fwrite(decoded, decoded_len, 1, out);
+ fflush(out);
+ free(decoded);
+ }
free(section_cper);
-}
\ No newline at end of file
+}
diff --git a/sections/cper-section-cxl-protocol.h b/sections/cper-section-cxl-protocol.h
index c7c2c1c..9339f57 100644
--- a/sections/cper-section-cxl-protocol.h
+++ b/sections/cper-section-cxl-protocol.h
@@ -4,53 +4,67 @@
#include <json.h>
#include "../edk/Cper.h"
-#define CXL_PROTOCOL_ERROR_VALID_BITFIELD_NAMES (const char*[]) {"cxlAgentTypeValid", "cxlAgentAddressValid", \
- "deviceIDValid", "deviceSerialValid", "capabilityStructureValid", "cxlDVSECValid", "cxlErrorLogValid"}
-#define CXL_PROTOCOL_ERROR_AGENT_TYPES_KEYS (int []){0, 1}
-#define CXL_PROTOCOL_ERROR_AGENT_TYPES_VALUES (const char*[]){"CXL 1.1 Device", "CXL 1.1 Host Downstream Port"}
-#define CXL_PROTOCOL_ERROR_DEVICE_AGENT 0
+#define CXL_PROTOCOL_ERROR_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "cxlAgentTypeValid", "cxlAgentAddressValid", "deviceIDValid", \
+ "deviceSerialValid", "capabilityStructureValid", \
+ "cxlDVSECValid", "cxlErrorLogValid" \
+ }
+#define CXL_PROTOCOL_ERROR_AGENT_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1 \
+ }
+#define CXL_PROTOCOL_ERROR_AGENT_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "CXL 1.1 Device", "CXL 1.1 Host Downstream Port" \
+ }
+#define CXL_PROTOCOL_ERROR_DEVICE_AGENT 0
#define CXL_PROTOCOL_ERROR_HOST_DOWNSTREAM_PORT_AGENT 1
///
/// CXL Protocol Error Section
///
typedef struct {
- UINT64 VendorId : 16;
- UINT64 DeviceId : 16;
- UINT64 SubsystemVendorId : 16;
- UINT64 SubsystemDeviceId : 16;
- UINT64 ClassCode : 16;
- UINT64 Reserved1 : 3;
- UINT64 SlotNumber : 13;
- UINT64 Reserved2 : 32;
+ UINT64 VendorId : 16;
+ UINT64 DeviceId : 16;
+ UINT64 SubsystemVendorId : 16;
+ UINT64 SubsystemDeviceId : 16;
+ UINT64 ClassCode : 16;
+ UINT64 Reserved1 : 3;
+ UINT64 SlotNumber : 13;
+ UINT64 Reserved2 : 32;
} EFI_CXL_DEVICE_ID;
typedef struct {
- UINT64 FunctionNumber : 8;
- UINT64 DeviceNumber : 8;
- UINT64 BusNumber : 8;
- UINT64 SegmentNumber : 16;
- UINT64 Reserved : 24;
+ UINT64 FunctionNumber : 8;
+ UINT64 DeviceNumber : 8;
+ UINT64 BusNumber : 8;
+ UINT64 SegmentNumber : 16;
+ UINT64 Reserved : 24;
} EFI_CXL_DEVICE_AGENT_ADDRESS;
typedef union {
- EFI_CXL_DEVICE_AGENT_ADDRESS DeviceAddress; //Active when the agent is a CXL1.1 device in CxlAgentType.
- UINT64 PortRcrbBaseAddress; //Active when the agent is a CXL1.1 host downstream port in CxlAgentType.
+ EFI_CXL_DEVICE_AGENT_ADDRESS
+ DeviceAddress; //Active when the agent is a CXL1.1 device in CxlAgentType.
+ UINT64 PortRcrbBaseAddress; //Active when the agent is a CXL1.1 host downstream port in CxlAgentType.
} EFI_CXL_AGENT_ADDRESS;
typedef struct {
- UINT64 ValidBits;
- UINT64 CxlAgentType;
- EFI_CXL_AGENT_ADDRESS CxlAgentAddress;
- EFI_CXL_DEVICE_ID DeviceId;
- UINT64 DeviceSerial;
- EFI_PCIE_ERROR_DATA_CAPABILITY CapabilityStructure;
- UINT16 CxlDvsecLength;
- UINT16 CxlErrorLogLength;
- UINT32 Reserved;
+ UINT64 ValidBits;
+ UINT64 CxlAgentType;
+ EFI_CXL_AGENT_ADDRESS CxlAgentAddress;
+ EFI_CXL_DEVICE_ID DeviceId;
+ UINT64 DeviceSerial;
+ EFI_PCIE_ERROR_DATA_CAPABILITY CapabilityStructure;
+ UINT16 CxlDvsecLength;
+ UINT16 CxlErrorLogLength;
+ UINT32 Reserved;
} __attribute__((packed, aligned(1))) EFI_CXL_PROTOCOL_ERROR_DATA;
-json_object* cper_section_cxl_protocol_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-void ir_section_cxl_protocol_to_cper(json_object* section, FILE* out);
+json_object *cper_section_cxl_protocol_to_ir(void *section);
+void ir_section_cxl_protocol_to_cper(json_object *section, FILE *out);
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section-dmar-generic.c b/sections/cper-section-dmar-generic.c
index 6136232..affe16a 100644
--- a/sections/cper-section-dmar-generic.c
+++ b/sections/cper-section-dmar-generic.c
@@ -11,9 +11,7 @@
#include "cper-section-dmar-generic.h"
//Converts a single generic DMAr CPER section into JSON IR.
-json_object *
-cper_section_dmar_generic_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_dmar_generic_to_ir(void *section)
{
EFI_DMAR_GENERIC_ERROR_DATA *firmware_error =
(EFI_DMAR_GENERIC_ERROR_DATA *)section;
@@ -91,4 +89,4 @@
fwrite(section_cper, sizeof(EFI_DMAR_GENERIC_ERROR_DATA), 1, out);
fflush(out);
free(section_cper);
-}
\ No newline at end of file
+}
diff --git a/sections/cper-section-dmar-generic.h b/sections/cper-section-dmar-generic.h
index e9757b0..035b25d 100644
--- a/sections/cper-section-dmar-generic.h
+++ b/sections/cper-section-dmar-generic.h
@@ -4,31 +4,68 @@
#include <json.h>
#include "../edk/Cper.h"
-#define DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_KEYS (int []){0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB}
-#define DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_VALUES (const char*[]){"DMT Entry Missing", "DMT Entry Invalid", \
- "DMT Access Error", "DMT Reserved Bit Invalid", "DMA Address Out of Bounds", "Invalid Read/Write", \
- "Invalid Device Request", "ATT Access Error", "ATT Reserved Bit Invalid", "Illegal Command", "Command Buffer Access Error"}
-#define DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_DESCRIPTIONS (const char*[]){ \
- "Domain mapping table entry is not present.", \
- "Invalid domain mapping table entry.", \
- "DMAr unit's attempt to access the domain mapping table resulted in an error.", \
- "Reserved bit set to non-zero value in the domain mapping table.", \
- "DMA request to access an address beyond the device address width.", \
- "Invalid read or write access.", \
- "Invalid device request.", \
- "DMAr unit's attempt to access the address translation table resulted in an error.", \
- "Reserved bit set to non-zero value in the address translation table.", \
- "Illegal command error.", \
- "DMAr unit's attempt to access the command buffer resulted in an error."}
-#define DMAR_GENERIC_ERROR_ACCESS_TYPES_KEYS (int []){0x0, 0x1}
-#define DMAR_GENERIC_ERROR_ACCESS_TYPES_VALUES (const char*[]){"DMA Write", "DMA Read"}
-#define DMAR_GENERIC_ERROR_ADDRESS_TYPES_KEYS (int []){0x0, 0x1}
-#define DMAR_GENERIC_ERROR_ADDRESS_TYPES_VALUES (const char*[]){"Untranslated Request", "Translation Request"}
-#define DMAR_GENERIC_ERROR_ARCH_TYPES_KEYS (int []){0x0, 0x1}
-#define DMAR_GENERIC_ERROR_ARCH_TYPES_VALUES (const char*[]){"VT-d", "IOMMU"}
+#define DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB \
+ }
+#define DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "DMT Entry Missing", "DMT Entry Invalid", "DMT Access Error", \
+ "DMT Reserved Bit Invalid", \
+ "DMA Address Out of Bounds", "Invalid Read/Write", \
+ "Invalid Device Request", "ATT Access Error", \
+ "ATT Reserved Bit Invalid", "Illegal Command", \
+ "Command Buffer Access Error" \
+ }
+#define DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_DESCRIPTIONS \
+ (const char *[]) \
+ { \
+ "Domain mapping table entry is not present.", \
+ "Invalid domain mapping table entry.", \
+ "DMAr unit's attempt to access the domain mapping table resulted in an error.", \
+ "Reserved bit set to non-zero value in the domain mapping table.", \
+ "DMA request to access an address beyond the device address width.", \
+ "Invalid read or write access.", \
+ "Invalid device request.", \
+ "DMAr unit's attempt to access the address translation table resulted in an error.", \
+ "Reserved bit set to non-zero value in the address translation table.", \
+ "Illegal command error.", \
+ "DMAr unit's attempt to access the command buffer resulted in an error." \
+ }
+#define DMAR_GENERIC_ERROR_ACCESS_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0x0, 0x1 \
+ }
+#define DMAR_GENERIC_ERROR_ACCESS_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "DMA Write", "DMA Read" \
+ }
+#define DMAR_GENERIC_ERROR_ADDRESS_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0x0, 0x1 \
+ }
+#define DMAR_GENERIC_ERROR_ADDRESS_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Untranslated Request", "Translation Request" \
+ }
+#define DMAR_GENERIC_ERROR_ARCH_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0x0, 0x1 \
+ }
+#define DMAR_GENERIC_ERROR_ARCH_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "VT-d", "IOMMU" \
+ }
-json_object* cper_section_dmar_generic_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-void ir_section_dmar_generic_to_cper(json_object* section, FILE* out);
+json_object *cper_section_dmar_generic_to_ir(void *section);
+void ir_section_dmar_generic_to_cper(json_object *section, FILE *out);
-
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section-dmar-iommu.c b/sections/cper-section-dmar-iommu.c
index f33c4ec..1d077a9 100644
--- a/sections/cper-section-dmar-iommu.c
+++ b/sections/cper-section-dmar-iommu.c
@@ -7,15 +7,13 @@
#include <stdio.h>
#include <string.h>
#include <json.h>
-#include "b64.h"
+#include "libbase64.h"
#include "../edk/Cper.h"
#include "../cper-utils.h"
#include "cper-section-dmar-iommu.h"
//Converts a single IOMMU specific DMAr CPER section into JSON IR.
-json_object *
-cper_section_dmar_iommu_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_dmar_iommu_to_ir(void *section)
{
EFI_IOMMU_DMAR_ERROR_DATA *iommu_error =
(EFI_IOMMU_DMAR_ERROR_DATA *)section;
@@ -33,18 +31,32 @@
//IOMMU event log entry.
//The format of these entries differ widely by the type of error.
- char *encoded =
- b64_encode((unsigned char *)iommu_error->EventLogEntry, 16);
- json_object_object_add(section_ir, "eventLogEntry",
- json_object_new_string(encoded));
- free(encoded);
+ char *encoded = malloc(2 * 16);
+ size_t encoded_len = 0;
+ if (!encoded) {
+ printf("Failed to allocate encode output buffer. \n");
+ } else {
+ base64_encode((const char *)iommu_error->EventLogEntry, 16,
+ encoded, &encoded_len, 0);
+ json_object_object_add(section_ir, "eventLogEntry",
+ json_object_new_string_len(encoded,
+ encoded_len));
+ free(encoded);
+ }
//Device table entry (as base64).
- encoded =
- b64_encode((unsigned char *)iommu_error->DeviceTableEntry, 32);
- json_object_object_add(section_ir, "deviceTableEntry",
- json_object_new_string(encoded));
- free(encoded);
+ encoded = malloc(2 * 32);
+ encoded_len = 0;
+ if (!encoded) {
+ printf("Failed to allocate encode output buffer. \n");
+ } else {
+ base64_encode((const char *)iommu_error->DeviceTableEntry, 32,
+ encoded, &encoded_len, 0);
+ json_object_object_add(section_ir, "deviceTableEntry",
+ json_object_new_string_len(encoded,
+ encoded_len));
+ free(encoded);
+ }
//Page table entries.
json_object_object_add(section_ir, "pageTableEntry_Level6",
@@ -80,17 +92,31 @@
//IOMMU event log entry.
json_object *encoded = json_object_object_get(section, "eventLogEntry");
- UINT8 *decoded = b64_decode(json_object_get_string(encoded),
- json_object_get_string_len(encoded));
- memcpy(section_cper->EventLogEntry, decoded, 16);
- free(decoded);
+ char *decoded = malloc(json_object_get_string_len(encoded));
+ size_t decoded_len = 0;
+ if (!decoded) {
+ printf("Failed to allocate decode output buffer. \n");
+ } else {
+ base64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded), decoded,
+ &decoded_len, 0);
+ memcpy(section_cper->EventLogEntry, decoded, decoded_len);
+ free(decoded);
+ }
//Device table entry.
encoded = json_object_object_get(section, "deviceTableEntry");
- decoded = b64_decode(json_object_get_string(encoded),
- json_object_get_string_len(encoded));
- memcpy(section_cper->DeviceTableEntry, decoded, 32);
- free(decoded);
+ decoded = malloc(json_object_get_string_len(encoded));
+ decoded_len = 0;
+ if (!decoded) {
+ printf("Failed to allocate decode output buffer. \n");
+ } else {
+ base64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded), decoded,
+ &decoded_len, 0);
+ memcpy(section_cper->DeviceTableEntry, decoded, decoded_len);
+ free(decoded);
+ }
//Page table entries.
section_cper->PteL1 = json_object_get_uint64(
@@ -110,4 +136,4 @@
fwrite(section_cper, sizeof(EFI_IOMMU_DMAR_ERROR_DATA), 1, out);
fflush(out);
free(section_cper);
-}
\ No newline at end of file
+}
diff --git a/sections/cper-section-dmar-iommu.h b/sections/cper-section-dmar-iommu.h
index 0fec283..d15a9d1 100644
--- a/sections/cper-section-dmar-iommu.h
+++ b/sections/cper-section-dmar-iommu.h
@@ -4,7 +4,7 @@
#include <json.h>
#include "../edk/Cper.h"
-json_object* cper_section_dmar_iommu_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-void ir_section_dmar_iommu_to_cper(json_object* section, FILE* out);
+json_object *cper_section_dmar_iommu_to_ir(void *section);
+void ir_section_dmar_iommu_to_cper(json_object *section, FILE *out);
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section-dmar-vtd.c b/sections/cper-section-dmar-vtd.c
index 5d938f4..e51b335 100644
--- a/sections/cper-section-dmar-vtd.c
+++ b/sections/cper-section-dmar-vtd.c
@@ -7,15 +7,13 @@
#include <stdio.h>
#include <string.h>
#include <json.h>
-#include "b64.h"
+#include "libbase64.h"
#include "../edk/Cper.h"
#include "../cper-utils.h"
#include "cper-section-dmar-vtd.h"
//Converts a single VT-d specific DMAr CPER section into JSON IR.
-json_object *
-cper_section_dmar_vtd_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_dmar_vtd_to_ir(void *section)
{
EFI_DIRECTED_IO_DMAR_ERROR_DATA *vtd_error =
(EFI_DIRECTED_IO_DMAR_ERROR_DATA *)section;
@@ -23,8 +21,9 @@
//Version, revision and OEM ID, as defined in the VT-d architecture.
UINT64 oem_id = 0;
- for (int i = 0; i < 6; i++)
+ for (int i = 0; i < 6; i++) {
oem_id |= (UINT64)vtd_error->OemId[i] << (i * 8);
+ }
json_object_object_add(section_ir, "version",
json_object_new_int(vtd_error->Version));
json_object_object_add(section_ir, "revision",
@@ -83,16 +82,32 @@
json_object_object_add(section_ir, "faultRecord", fault_record_ir);
//Root entry.
- char *encoded = b64_encode((unsigned char *)vtd_error->RootEntry, 16);
- json_object_object_add(section_ir, "rootEntry",
- json_object_new_string(encoded));
- free(encoded);
+ char *encoded = malloc(2 * 16);
+ size_t encoded_len = 0;
+ if (!encoded) {
+ printf("Failed to allocate encode output buffer. \n");
+ } else {
+ base64_encode((const char *)vtd_error->RootEntry, 16, encoded,
+ &encoded_len, 0);
+ json_object_object_add(section_ir, "rootEntry",
+ json_object_new_string_len(encoded,
+ encoded_len));
+ free(encoded);
+ }
//Context entry.
- encoded = b64_encode((unsigned char *)vtd_error->ContextEntry, 16);
- json_object_object_add(section_ir, "contextEntry",
- json_object_new_string(encoded));
- free(encoded);
+ encoded = malloc(2 * 16);
+ encoded_len = 0;
+ if (!encoded) {
+ printf("Failed to allocate encode output buffer. \n");
+ } else {
+ base64_encode((const char *)vtd_error->ContextEntry, 16,
+ encoded, &encoded_len, 0);
+ json_object_object_add(section_ir, "contextEntry",
+ json_object_new_string_len(encoded,
+ encoded_len));
+ free(encoded);
+ }
//PTE entry for all page levels.
json_object_object_add(section_ir, "pageTableEntry_Level6",
@@ -121,8 +136,9 @@
//OEM ID.
UINT64 oem_id = json_object_get_uint64(
json_object_object_get(section, "oemID"));
- for (int i = 0; i < 6; i++)
+ for (int i = 0; i < 6; i++) {
section_cper->OemId[i] = (oem_id >> (i * 8)) & 0xFF;
+ }
//Registers & basic numeric fields.
section_cper->Version = (UINT8)json_object_get_int(
@@ -167,17 +183,30 @@
//Root entry.
json_object *encoded = json_object_object_get(section, "rootEntry");
- UINT8 *decoded = b64_decode(json_object_get_string(encoded),
- json_object_get_string_len(encoded));
- memcpy(section_cper->RootEntry, decoded, 16);
- free(decoded);
-
+ char *decoded = malloc(json_object_get_string_len(encoded));
+ size_t decoded_len = 0;
+ if (!decoded) {
+ printf("Failed to allocate decode output buffer. \n");
+ } else {
+ base64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded), decoded,
+ &decoded_len, 0);
+ memcpy(section_cper->RootEntry, decoded, decoded_len);
+ free(decoded);
+ }
//Context entry.
encoded = json_object_object_get(section, "contextEntry");
- decoded = b64_decode(json_object_get_string(encoded),
- json_object_get_string_len(encoded));
- memcpy(section_cper->ContextEntry, decoded, 16);
- free(decoded);
+ decoded = malloc(json_object_get_string_len(encoded));
+ decoded_len = 0;
+ if (!decoded) {
+ printf("Failed to allocate decode output buffer. \n");
+ } else {
+ base64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded), decoded,
+ &decoded_len, 0);
+ memcpy(section_cper->ContextEntry, decoded, decoded_len);
+ free(decoded);
+ }
//Page table entries.
section_cper->PteL1 = json_object_get_uint64(
@@ -197,4 +226,4 @@
fwrite(section_cper, sizeof(EFI_DIRECTED_IO_DMAR_ERROR_DATA), 1, out);
fflush(out);
free(section_cper);
-}
\ No newline at end of file
+}
diff --git a/sections/cper-section-dmar-vtd.h b/sections/cper-section-dmar-vtd.h
index 4f84657..f78b2d1 100644
--- a/sections/cper-section-dmar-vtd.h
+++ b/sections/cper-section-dmar-vtd.h
@@ -4,25 +4,33 @@
#include <json.h>
#include "../edk/Cper.h"
-#define VTD_FAULT_RECORD_TYPES_KEYS (int []){0, 1}
-#define VTD_FAULT_RECORD_TYPES_VALUES (const char*[]){"Write Request", "Read/AtomicOp Request"}
+#define VTD_FAULT_RECORD_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1 \
+ }
+#define VTD_FAULT_RECORD_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Write Request", "Read/AtomicOp Request" \
+ }
typedef struct {
- UINT64 Resv1 : 12;
- UINT64 FaultInformation : 52;
- UINT64 SourceIdentifier : 16;
- UINT64 Resv2 : 13;
- UINT64 PrivelegeModeRequested : 1;
- UINT64 ExecutePermissionRequested : 1;
- UINT64 PasidPresent : 1;
- UINT64 FaultReason : 8;
- UINT64 PasidValue : 20;
- UINT64 AddressType : 2;
- UINT64 Type : 1;
- UINT64 Resv3 : 1;
+ UINT64 Resv1 : 12;
+ UINT64 FaultInformation : 52;
+ UINT64 SourceIdentifier : 16;
+ UINT64 Resv2 : 13;
+ UINT64 PrivelegeModeRequested : 1;
+ UINT64 ExecutePermissionRequested : 1;
+ UINT64 PasidPresent : 1;
+ UINT64 FaultReason : 8;
+ UINT64 PasidValue : 20;
+ UINT64 AddressType : 2;
+ UINT64 Type : 1;
+ UINT64 Resv3 : 1;
} EFI_VTD_FAULT_RECORD;
-json_object* cper_section_dmar_vtd_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-void ir_section_dmar_vtd_to_cper(json_object* section, FILE* out);
+json_object *cper_section_dmar_vtd_to_ir(void *section);
+void ir_section_dmar_vtd_to_cper(json_object *section, FILE *out);
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section-firmware.c b/sections/cper-section-firmware.c
index e45015a..c82a28b 100644
--- a/sections/cper-section-firmware.c
+++ b/sections/cper-section-firmware.c
@@ -11,9 +11,7 @@
#include "cper-section-firmware.h"
//Converts a single firmware CPER section into JSON IR.
-json_object *
-cper_section_firmware_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_firmware_to_ir(void *section)
{
EFI_FIRMWARE_ERROR_DATA *firmware_error =
(EFI_FIRMWARE_ERROR_DATA *)section;
@@ -63,4 +61,4 @@
fwrite(section_cper, sizeof(EFI_FIRMWARE_ERROR_DATA), 1, out);
fflush(out);
free(section_cper);
-}
\ No newline at end of file
+}
diff --git a/sections/cper-section-firmware.h b/sections/cper-section-firmware.h
index 4e0f528..eab0e99 100644
--- a/sections/cper-section-firmware.h
+++ b/sections/cper-section-firmware.h
@@ -4,11 +4,20 @@
#include <json.h>
#include "../edk/Cper.h"
-#define FIRMWARE_ERROR_RECORD_TYPES_KEYS (int []){0, 1, 2}
-#define FIRMWARE_ERROR_RECORD_TYPES_VALUES (const char*[]){"IPF SAL Error Record", \
- "SOC Firmware Error Record (Type1 Legacy)", "SOC Firmware Error Record (Type2)"}
+#define FIRMWARE_ERROR_RECORD_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2 \
+ }
+#define FIRMWARE_ERROR_RECORD_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "IPF SAL Error Record", \
+ "SOC Firmware Error Record (Type1 Legacy)", \
+ "SOC Firmware Error Record (Type2)" \
+ }
-json_object* cper_section_firmware_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-void ir_section_firmware_to_cper(json_object* section, FILE* out);
+json_object *cper_section_firmware_to_ir(void *section);
+void ir_section_firmware_to_cper(json_object *section, FILE *out);
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section-generic.c b/sections/cper-section-generic.c
index 6a0de01..f9b1fdf 100644
--- a/sections/cper-section-generic.c
+++ b/sections/cper-section-generic.c
@@ -13,9 +13,7 @@
#include "cper-section-generic.h"
//Converts the given processor-generic CPER section into JSON IR.
-json_object *
-cper_section_generic_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_generic_to_ir(void *section)
{
EFI_PROCESSOR_GENERIC_ERROR_DATA *section_generic =
(EFI_PROCESSOR_GENERIC_ERROR_DATA *)section;
@@ -144,11 +142,12 @@
//CPU brand string.
const char *brand_string = json_object_get_string(
json_object_object_get(section, "cpuBrandString"));
- if (brand_string != NULL)
+ if (brand_string != NULL) {
strncpy(section_cper->BrandString, brand_string, 127);
+ }
//Write & flush out to file, free memory.
fwrite(section_cper, sizeof(EFI_PROCESSOR_GENERIC_ERROR_DATA), 1, out);
fflush(out);
free(section_cper);
-}
\ No newline at end of file
+}
diff --git a/sections/cper-section-generic.h b/sections/cper-section-generic.h
index 95ba66e..765794e 100644
--- a/sections/cper-section-generic.h
+++ b/sections/cper-section-generic.h
@@ -4,22 +4,65 @@
#include <json.h>
#include "../edk/Cper.h"
-#define GENERIC_PROC_TYPES_KEYS (int []){0, 1, 2}
-#define GENERIC_PROC_TYPES_VALUES (const char*[]){"IA32/X64", "IA64", "ARM"}
-#define GENERIC_ISA_TYPES_KEYS (int []){0, 1, 2, 3, 4}
-#define GENERIC_ISA_TYPES_VALUES (const char*[]){"IA32", "IA64", "X64", "ARM A32/T32", "ARM A64"}
-#define GENERIC_ERROR_TYPES_KEYS (int []){0, 1, 2, 4, 8}
-#define GENERIC_ERROR_TYPES_VALUES (const char*[]){"Unknown", "Cache Error", "TLB Error", "Bus Error", "Micro-Architectural Error"}
-#define GENERIC_OPERATION_TYPES_KEYS (int []){0, 1, 2, 3}
-#define GENERIC_OPERATION_TYPES_VALUES (const char*[]){"Unknown or Generic", "Data Read", "Data Write", "Instruction Execution"}
-#define GENERIC_VALIDATION_BITFIELD_NAMES (const char*[]) \
- {"processorTypeValid", "processorISAValid", "processorErrorTypeValid", "operationValid", "flagsValid", \
- "levelValid", "cpuVersionValid", "cpuBrandInfoValid", "cpuIDValid", "targetAddressValid", "requestorIDValid", \
- "responderIDValid", "instructionIPValid"}
-#define GENERIC_FLAGS_BITFIELD_NAMES (const char*[]) \
- {"restartable", "preciseIP", "overflow", "corrected"}
+#define GENERIC_PROC_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2 \
+ }
+#define GENERIC_PROC_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "IA32/X64", "IA64", "ARM" \
+ }
+#define GENERIC_ISA_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 3, 4 \
+ }
+#define GENERIC_ISA_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "IA32", "IA64", "X64", "ARM A32/T32", "ARM A64" \
+ }
+#define GENERIC_ERROR_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 4, 8 \
+ }
+#define GENERIC_ERROR_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Unknown", "Cache Error", "TLB Error", "Bus Error", \
+ "Micro-Architectural Error" \
+ }
+#define GENERIC_OPERATION_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 3 \
+ }
+#define GENERIC_OPERATION_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Unknown or Generic", "Data Read", "Data Write", \
+ "Instruction Execution" \
+ }
+#define GENERIC_VALIDATION_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "processorTypeValid", "processorISAValid", \
+ "processorErrorTypeValid", "operationValid", \
+ "flagsValid", "levelValid", "cpuVersionValid", \
+ "cpuBrandInfoValid", "cpuIDValid", \
+ "targetAddressValid", "requestorIDValid", \
+ "responderIDValid", "instructionIPValid" \
+ }
+#define GENERIC_FLAGS_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "restartable", "preciseIP", "overflow", "corrected" \
+ }
-json_object* cper_section_generic_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-void ir_section_generic_to_cper(json_object* section, FILE* out);
+json_object *cper_section_generic_to_ir(void *section);
+void ir_section_generic_to_cper(json_object *section, FILE *out);
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section-ia32x64.c b/sections/cper-section-ia32x64.c
index a7dcc18..7a94c3d 100644
--- a/sections/cper-section-ia32x64.c
+++ b/sections/cper-section-ia32x64.c
@@ -7,7 +7,7 @@
#include <stdio.h>
#include <json.h>
-#include "b64.h"
+#include "libbase64.h"
#include "../edk/Cper.h"
#include "../cper-utils.h"
#include "cper-section-ia32x64.h"
@@ -43,9 +43,7 @@
//////////////////
//Converts the IA32/x64 error section described in the given descriptor into intermediate format.
-json_object *
-cper_section_ia32x64_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_ia32x64_to_ir(void *section)
{
EFI_IA32_X64_PROCESSOR_ERROR_RECORD *record =
(EFI_IA32_X64_PROCESSOR_ERROR_RECORD *)section;
@@ -55,14 +53,14 @@
json_object *validationBits = json_object_new_object();
json_object_object_add(validationBits, "localAPICIDValid",
json_object_new_boolean(record->ValidFields &
- 0b1));
+ 0x1));
json_object_object_add(
validationBits, "cpuIDInfoValid",
- json_object_new_boolean((record->ValidFields >> 1) & 0b1));
- int processor_error_info_num = (record->ValidFields >> 2) & 0b111111;
+ json_object_new_boolean((record->ValidFields >> 1) & 0x1));
+ int processor_error_info_num = (record->ValidFields >> 2) & 0x3F;
json_object_object_add(validationBits, "processorErrorInfoNum",
json_object_new_int(processor_error_info_num));
- int processor_context_info_num = (record->ValidFields >> 8) & 0b111111;
+ int processor_context_info_num = (record->ValidFields >> 8) & 0x3F;
json_object_object_add(validationBits, "processorContextInfoNum",
json_object_new_int(processor_context_info_num));
json_object_object_add(record_ir, "validationBits", validationBits);
@@ -133,18 +131,20 @@
//Get the error structure type as a readable string.
const char *readable_type = "Unknown";
if (guid_equal(&error_info->ErrorType,
- &gEfiIa32x64ErrorTypeCacheCheckGuid))
+ &gEfiIa32x64ErrorTypeCacheCheckGuid)) {
readable_type = "Cache Check Error";
- else if (guid_equal(&error_info->ErrorType,
- &gEfiIa32x64ErrorTypeTlbCheckGuid))
+ } else if (guid_equal(&error_info->ErrorType,
+ &gEfiIa32x64ErrorTypeTlbCheckGuid)) {
readable_type = "TLB Check Error";
- else if (guid_equal(&error_info->ErrorType,
- &gEfiIa32x64ErrorTypeBusCheckGuid))
+ } else if (guid_equal(&error_info->ErrorType,
+ &gEfiIa32x64ErrorTypeBusCheckGuid)) {
readable_type = "Bus Check Error";
- else if (guid_equal(&error_info->ErrorType,
- &gEfiIa32x64ErrorTypeMsCheckGuid))
+ } else if (guid_equal(&error_info->ErrorType,
+ &gEfiIa32x64ErrorTypeMsCheckGuid)) {
readable_type = "MS Check Error";
- json_object_object_add(type, "name", json_object_new_string(readable_type));
+ }
+ json_object_object_add(type, "name",
+ json_object_new_string(readable_type));
json_object_object_add(error_info_ir, "type", type);
//Validation bits.
@@ -390,12 +390,21 @@
//No parseable data, just dump as base64 and shift the head to the next item.
*cur_pos = (void *)(context_info + 1);
- char *encoded = b64_encode((unsigned char *)*cur_pos,
- context_info->ArraySize);
- register_array = json_object_new_object();
- json_object_object_add(register_array, "data",
- json_object_new_string(encoded));
- free(encoded);
+ char *encoded = malloc(2 * context_info->ArraySize);
+ size_t encoded_len = 0;
+ if (!encoded) {
+ printf("Failed to allocate encode output buffer. \n");
+ } else {
+ base64_encode((const char *)*cur_pos,
+ context_info->ArraySize, encoded,
+ &encoded_len, 0);
+
+ register_array = json_object_new_object();
+ json_object_object_add(register_array, "data",
+ json_object_new_string_len(
+ encoded, encoded_len));
+ free(encoded);
+ }
*cur_pos =
(void *)(((char *)*cur_pos) + context_info->ArraySize);
@@ -574,11 +583,11 @@
int proc_error_info_num =
json_object_get_int(json_object_object_get(
validation, "processorErrorInfoNum")) &
- 0b111111;
+ 0x3F;
int proc_ctx_info_num =
json_object_get_int(json_object_object_get(
validation, "processorContextInfoNum")) &
- 0b111111;
+ 0x3F;
section_cper->ValidFields |= proc_error_info_num << 2;
section_cper->ValidFields |= proc_ctx_info_num << 8;
@@ -610,12 +619,14 @@
json_object_object_get(section, "processorErrorInfo");
json_object *context_info =
json_object_object_get(section, "processorContextInfo");
- for (int i = 0; i < proc_error_info_num; i++)
+ for (int i = 0; i < proc_error_info_num; i++) {
ir_ia32x64_error_info_to_cper(
json_object_array_get_idx(error_info, i), out);
- for (int i = 0; i < proc_ctx_info_num; i++)
+ }
+ for (int i = 0; i < proc_ctx_info_num; i++) {
ir_ia32x64_context_info_to_cper(
json_object_array_get_idx(context_info, i), out);
+ }
}
//Converts a single CPER-JSON IA32/x64 error information structure into CPER binary, outputting to the
@@ -649,17 +660,18 @@
(EFI_IA32_X64_CACHE_CHECK_INFO *)&error_info_cper
->CheckInfo);
} else if (guid_equal(&error_info_cper->ErrorType,
- &gEfiIa32x64ErrorTypeBusCheckGuid))
+ &gEfiIa32x64ErrorTypeBusCheckGuid)) {
ir_ia32x64_bus_check_error_to_cper(
check_info,
(EFI_IA32_X64_BUS_CHECK_INFO *)&error_info_cper
->CheckInfo);
- else if (guid_equal(&error_info_cper->ErrorType,
- &gEfiIa32x64ErrorTypeMsCheckGuid))
+ } else if (guid_equal(&error_info_cper->ErrorType,
+ &gEfiIa32x64ErrorTypeMsCheckGuid)) {
ir_ia32x64_ms_check_error_to_cper(
check_info,
(EFI_IA32_X64_MS_CHECK_INFO *)&error_info_cper
->CheckInfo);
+ }
//Miscellaneous numeric fields.
error_info_cper->TargetId = json_object_get_uint64(
@@ -807,10 +819,18 @@
//Unknown/structure is not defined.
json_object *encoded =
json_object_object_get(register_array, "data");
- char *decoded = b64_decode(json_object_get_string(encoded),
- json_object_get_string_len(encoded));
- fwrite(decoded, context_info_cper->ArraySize, 1, out);
- fflush(out);
+ char *decoded = malloc(json_object_get_string_len(encoded));
+ size_t decoded_len = 0;
+ if (!decoded) {
+ printf("Failed to allocate decode output buffer. \n");
+ } else {
+ base64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded),
+ decoded, &decoded_len, 0);
+ fwrite(decoded, decoded_len, 1, out);
+ fflush(out);
+ free(decoded);
+ }
}
//Free remaining resources.
@@ -967,4 +987,4 @@
//Write out to stream.
fwrite(®ister_state, sizeof(EFI_CONTEXT_X64_REGISTER_STATE), 1, out);
fflush(out);
-}
\ No newline at end of file
+}
diff --git a/sections/cper-section-ia32x64.h b/sections/cper-section-ia32x64.h
index 875681e..59a3e60 100644
--- a/sections/cper-section-ia32x64.h
+++ b/sections/cper-section-ia32x64.h
@@ -4,44 +4,110 @@
#include <json.h>
#include "../edk/Cper.h"
-#define IA32X64_PROCESSOR_ERROR_VALID_BITFIELD_NAMES (const char*[]) \
- {"checkInfoValid", "targetAddressIDValid", "requestorIDValid", "responderIDValid", \
- "instructionPointerValid"}
-#define IA32X64_CHECK_INFO_VALID_BITFIELD_NAMES (const char*[]) \
- {"transactionTypeValid", "operationValid", "levelValid", "processorContextCorruptValid", "uncorrectedValid", \
- "preciseIPValid", "restartableIPValid", "overflowValid", "participationTypeValid", "timedOutValid", \
- "addressSpaceValid"}
-#define IA32X64_CHECK_INFO_MS_CHECK_VALID_BITFIELD_NAMES (const char*[]) \
- {"errorTypeValid", "processorContextCorruptValid", "uncorrectedValid", "preciseIPValid", "restartableIPValid", \
- "overflowValid"}
-#define IA32X64_CHECK_INFO_TRANSACTION_TYPES_KEYS (int []){0, 1, 2}
-#define IA32X64_CHECK_INFO_TRANSACTION_TYPES_VALUES (const char*[]){"Instruction", "Data Access", "Generic"}
-#define IA32X64_CHECK_INFO_OPERATION_TYPES_KEYS (int []){0, 1, 2, 3, 4, 5, 6, 7, 8}
-#define IA32X64_CHECK_INFO_OPERATION_TYPES_VALUES (const char*[]){"Generic Error", "Generic Read", "Generic Write" \
- "Data Read", "Data Write", "Instruction Fetch", "Prefetch", "Eviction", "Snoop"}
-#define IA32X64_BUS_CHECK_INFO_PARTICIPATION_TYPES_KEYS (int []){0, 1, 2, 3}
-#define IA32X64_BUS_CHECK_INFO_PARTICIPATION_TYPES_VALUES (const char*[]){"Local processor originated request", \
- "Local processor responded to request", "Local processor observed", "Generic"}
-#define IA32X64_BUS_CHECK_INFO_ADDRESS_SPACE_TYPES_KEYS (int []){0, 1, 2, 3}
-#define IA32X64_BUS_CHECK_INFO_ADDRESS_SPACE_TYPES_VALUES (const char*[]){"Memory Access", "Reserved", "I/O", \
- "Other Transaction"}
-#define IA32X64_MS_CHECK_INFO_ERROR_TYPES_KEYS (int []){0, 1, 2, 3, 4, 5}
-#define IA32X64_MS_CHECK_INFO_ERROR_TYPES_VALUES (const char*[]){"No Error", "Unclassified", "Microcode ROM Parity Error", \
- "External Error", "FRC Error", "Internal Unclassified"}
-#define IA32X64_REGISTER_CONTEXT_TYPES_KEYS (int []){0, 1, 2, 3, 4, 5, 6, 7}
-#define IA32X64_REGISTER_CONTEXT_TYPES_VALUES (const char*[]){"Unclassified Data", "MSR Registers", \
- "32-bit Mode Execution Context", "64-bit Mode Execution Context", "FXSave Context", \
- "32-bit Mode Debug Registers", "64-bit Mode Debug Registers", "Memory Mapper Registers"}
+#define IA32X64_PROCESSOR_ERROR_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "checkInfoValid", "targetAddressIDValid", "requestorIDValid", \
+ "responderIDValid", "instructionPointerValid" \
+ }
+#define IA32X64_CHECK_INFO_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "transactionTypeValid", "operationValid", "levelValid", \
+ "processorContextCorruptValid", "uncorrectedValid", \
+ "preciseIPValid", "restartableIPValid", \
+ "overflowValid", "participationTypeValid", \
+ "timedOutValid", "addressSpaceValid" \
+ }
+#define IA32X64_CHECK_INFO_MS_CHECK_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "errorTypeValid", "processorContextCorruptValid", \
+ "uncorrectedValid", "preciseIPValid", \
+ "restartableIPValid", "overflowValid" \
+ }
+#define IA32X64_CHECK_INFO_TRANSACTION_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2 \
+ }
+#define IA32X64_CHECK_INFO_TRANSACTION_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Instruction", "Data Access", "Generic" \
+ }
+#define IA32X64_CHECK_INFO_OPERATION_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 3, 4, 5, 6, 7, 8 \
+ }
+#define IA32X64_CHECK_INFO_OPERATION_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Generic Error", "Generic Read", \
+ "Generic Write" \
+ "Data Read", \
+ "Data Write", "Instruction Fetch", "Prefetch", \
+ "Eviction", "Snoop" \
+ }
+#define IA32X64_BUS_CHECK_INFO_PARTICIPATION_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 3 \
+ }
+#define IA32X64_BUS_CHECK_INFO_PARTICIPATION_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Local processor originated request", \
+ "Local processor responded to request", \
+ "Local processor observed", "Generic" \
+ }
+#define IA32X64_BUS_CHECK_INFO_ADDRESS_SPACE_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 3 \
+ }
+#define IA32X64_BUS_CHECK_INFO_ADDRESS_SPACE_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Memory Access", "Reserved", "I/O", "Other Transaction" \
+ }
+#define IA32X64_MS_CHECK_INFO_ERROR_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 3, 4, 5 \
+ }
+#define IA32X64_MS_CHECK_INFO_ERROR_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "No Error", "Unclassified", "Microcode ROM Parity Error", \
+ "External Error", "FRC Error", "Internal Unclassified" \
+ }
+#define IA32X64_REGISTER_CONTEXT_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 3, 4, 5, 6, 7 \
+ }
+#define IA32X64_REGISTER_CONTEXT_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Unclassified Data", "MSR Registers", \
+ "32-bit Mode Execution Context", \
+ "64-bit Mode Execution Context", "FXSave Context", \
+ "32-bit Mode Debug Registers", \
+ "64-bit Mode Debug Registers", \
+ "Memory Mapper Registers" \
+ }
typedef struct {
- UINT64 Eax;
- UINT64 Ebx;
- UINT64 Ecx;
- UINT64 Edx;
- UINT64 Reserved[2];
+ UINT64 Eax;
+ UINT64 Ebx;
+ UINT64 Ecx;
+ UINT64 Edx;
+ UINT64 Reserved[2];
} EFI_IA32_X64_CPU_ID;
-json_object* cper_section_ia32x64_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-void ir_section_ia32x64_to_cper(json_object* section, FILE* out);
+json_object *cper_section_ia32x64_to_ir(void *section);
+void ir_section_ia32x64_to_cper(json_object *section, FILE *out);
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section-ipf.c b/sections/cper-section-ipf.c
index bc62493..71720d6 100644
--- a/sections/cper-section-ipf.c
+++ b/sections/cper-section-ipf.c
@@ -15,8 +15,7 @@
json_object *cper_ipf_mod_error_to_ir(EFI_IPF_MOD_ERROR_INFO *mod_error);
//Converts a single Intel IPF error CPER section into JSON IR.
-json_object *cper_section_ipf_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_ipf_to_ir(void *section)
{
EFI_IPF_ERROR_INFO_HEADER *ipf_error =
(EFI_IPF_ERROR_INFO_HEADER *)section;
@@ -165,4 +164,4 @@
json_object_new_uint64(mod_error->ModPreciseIp));
return mod_error_ir;
-}
\ No newline at end of file
+}
diff --git a/sections/cper-section-ipf.h b/sections/cper-section-ipf.h
index e90a16e..cf346ef 100644
--- a/sections/cper-section-ipf.h
+++ b/sections/cper-section-ipf.h
@@ -4,60 +4,69 @@
#include <json.h>
#include "../edk/Cper.h"
-#define IPF_MOD_ERROR_VALID_BITFIELD_NAMES (const char*[]) {"checkInfoValid", "requestorIdentifierValid", \
- "responderIdentifierValid", "targetIdentifierValid", "preciseIPValid"}
-#define IPF_PSI_STATIC_INFO_VALID_BITFIELD_NAMES (const char*[]) {"minstateValid", "brValid", "crValid", \
- "arValid", "rrValid", "frValid"}
+#define IPF_MOD_ERROR_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "checkInfoValid", "requestorIdentifierValid", \
+ "responderIdentifierValid", "targetIdentifierValid", \
+ "preciseIPValid" \
+ }
+#define IPF_PSI_STATIC_INFO_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "minstateValid", "brValid", "crValid", "arValid", "rrValid", \
+ "frValid" \
+ }
///
/// IPF Error Record Section
/// Defined as according to B.2.3 of the ItaniumTM Processor Family System Abstraction Layer (SAL) Specification.
///
typedef struct {
- UINT64 ProcErrorMapValid : 1;
- UINT64 ProcStateParameterValid : 1;
- UINT64 ProcCrLidValid : 1;
- UINT64 PsiStaticStructValid : 1;
- UINT64 CacheCheckNum : 4;
- UINT64 TlbCheckNum : 4;
- UINT64 BusCheckNum : 4;
- UINT64 RegFileCheckNum : 4;
- UINT64 MsCheckNum : 4;
- UINT64 CpuIdInfoValid : 1;
- UINT64 Reserved : 39;
+ UINT64 ProcErrorMapValid : 1;
+ UINT64 ProcStateParameterValid : 1;
+ UINT64 ProcCrLidValid : 1;
+ UINT64 PsiStaticStructValid : 1;
+ UINT64 CacheCheckNum : 4;
+ UINT64 TlbCheckNum : 4;
+ UINT64 BusCheckNum : 4;
+ UINT64 RegFileCheckNum : 4;
+ UINT64 MsCheckNum : 4;
+ UINT64 CpuIdInfoValid : 1;
+ UINT64 Reserved : 39;
} EPI_IPF_ERROR_VALID_BITS;
typedef struct {
- EPI_IPF_ERROR_VALID_BITS ValidBits;
- UINT64 ProcErrorMap;
- UINT64 ProcStateParameter;
- UINT64 ProcCrLid;
+ EPI_IPF_ERROR_VALID_BITS ValidBits;
+ UINT64 ProcErrorMap;
+ UINT64 ProcStateParameter;
+ UINT64 ProcCrLid;
} EFI_IPF_ERROR_INFO_HEADER;
typedef struct {
- UINT64 ValidBits;
- UINT64 ModCheckInfo;
- UINT64 ModTargetId;
- UINT64 ModRequestorId; //NOTE: The Intel Itanium specification contains a typo which makes the order
- UINT64 ModResponderId; // of these two fields undefined. This is a best guess and could be wrong.
- UINT64 ModPreciseIp;
+ UINT64 ValidBits;
+ UINT64 ModCheckInfo;
+ UINT64 ModTargetId;
+ UINT64 ModRequestorId; //NOTE: The Intel Itanium specification contains a typo which makes the order
+ UINT64 ModResponderId; // of these two fields undefined. This is a best guess and could be wrong.
+ UINT64 ModPreciseIp;
} EFI_IPF_MOD_ERROR_INFO;
typedef struct {
- UINT8 CpuIdInfo[40];
- UINT8 Reserved1[8];
+ UINT8 CpuIdInfo[40];
+ UINT8 Reserved1[8];
} EFI_IPF_CPU_INFO;
typedef struct {
- UINT64 ValidBits;
- UINT8 MinimalSaveStateInfo[1024];
- UINT64 Brs[8];
- UINT64 Crs[128];
- UINT64 Ars[128];
- UINT64 Rrs[8];
- UINT64 Frs[256];
+ UINT64 ValidBits;
+ UINT8 MinimalSaveStateInfo[1024];
+ UINT64 Brs[8];
+ UINT64 Crs[128];
+ UINT64 Ars[128];
+ UINT64 Rrs[8];
+ UINT64 Frs[256];
} EFI_IPF_PSI_STATIC;
-json_object* cper_section_ipf_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
+json_object *cper_section_ipf_to_ir(void *section);
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section-memory.c b/sections/cper-section-memory.c
index 1ed2b9b..3c27a52 100644
--- a/sections/cper-section-memory.c
+++ b/sections/cper-section-memory.c
@@ -11,9 +11,7 @@
#include "cper-section-memory.h"
//Converts a single memory error CPER section into JSON IR.
-json_object *
-cper_section_platform_memory_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_platform_memory_to_ir(void *section)
{
EFI_PLATFORM_MEMORY_ERROR_DATA *memory_error =
(EFI_PLATFORM_MEMORY_ERROR_DATA *)section;
@@ -59,10 +57,10 @@
json_object *extended = json_object_new_object();
json_object_object_add(extended, "rowBit16",
json_object_new_boolean(memory_error->Extended &
- 0b1));
+ 0x1));
json_object_object_add(
extended, "rowBit17",
- json_object_new_boolean((memory_error->Extended >> 1) & 0b1));
+ json_object_new_boolean((memory_error->Extended >> 1) & 0x1));
json_object_object_add(extended, "chipIdentification",
json_object_new_int(memory_error->Extended >>
5));
@@ -112,9 +110,7 @@
}
//Converts a single memory error 2 CPER section into JSON IR.
-json_object *
-cper_section_platform_memory2_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_platform_memory2_to_ir(void *section)
{
EFI_PLATFORM_MEMORY2_ERROR_DATA *memory_error =
(EFI_PLATFORM_MEMORY2_ERROR_DATA *)section;
@@ -160,11 +156,11 @@
json_object *status = json_object_new_object();
json_object_object_add(status, "value",
json_object_new_int(memory_error->Status));
- json_object_object_add(status, "state",
- json_object_new_string(memory_error->Status &
- 0b1 == 0 ?
- "Corrected" :
- "Uncorrected"));
+ json_object_object_add(
+ status, "state",
+ json_object_new_string((memory_error->Status & 0x1) == 0 ?
+ "Corrected" :
+ "Uncorrected"));
json_object_object_add(section_ir, "status", status);
//Miscellaneous numeric fields.
@@ -370,4 +366,4 @@
fwrite(section_cper, sizeof(EFI_PLATFORM_MEMORY2_ERROR_DATA), 1, out);
fflush(out);
free(section_cper);
-}
\ No newline at end of file
+}
diff --git a/sections/cper-section-memory.h b/sections/cper-section-memory.h
index 81be6ff..5134f6e 100644
--- a/sections/cper-section-memory.h
+++ b/sections/cper-section-memory.h
@@ -4,27 +4,54 @@
#include <json.h>
#include "../edk/Cper.h"
-#define MEMORY_ERROR_VALID_BITFIELD_NAMES (const char*[]) \
- {"errorStatusValid", "physicalAddressValid", "physicalAddressMaskValid", "nodeValid", "cardValid", "moduleValid", \
- "bankValid", "deviceValid", "rowValid", "columnValid", "bitPositionValid", "platformRequestorIDValid", \
- "platformResponderIDValid", "memoryPlatformTargetValid", "memoryErrorTypeValid", "rankNumberValid", \
- "cardHandleValid", "moduleHandleValid", "extendedRowBitsValid", "bankGroupValid", "bankAddressValid", \
- "chipIdentificationValid"}
-#define MEMORY_ERROR_TYPES_KEYS (int []){0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
-#define MEMORY_ERROR_TYPES_VALUES (const char*[]){"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", "Physical Memory Map-out Event"}
-#define MEMORY_ERROR_2_VALID_BITFIELD_NAMES (const char*[]) \
- {"errorStatusValid", "physicalAddressValid", "physicalAddressMaskValid", "nodeValid", "cardValid", "moduleValid", \
- "bankValid", "deviceValid", "rowValid", "columnValid", "rankValid", "bitPositionValid", "chipIDValid", \
- "memoryErrorTypeValid", "statusValid", "requestorIDValid", "responderIDValid", "targetIDValid", "cardHandleValid", \
- "moduleHandleValid", "bankGroupValid", "bankAddressValid"}
+#define MEMORY_ERROR_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "errorStatusValid", "physicalAddressValid", \
+ "physicalAddressMaskValid", "nodeValid", "cardValid", \
+ "moduleValid", "bankValid", "deviceValid", "rowValid", \
+ "columnValid", "bitPositionValid", \
+ "platformRequestorIDValid", \
+ "platformResponderIDValid", \
+ "memoryPlatformTargetValid", "memoryErrorTypeValid", \
+ "rankNumberValid", "cardHandleValid", \
+ "moduleHandleValid", "extendedRowBitsValid", \
+ "bankGroupValid", "bankAddressValid", \
+ "chipIdentificationValid" \
+ }
+#define MEMORY_ERROR_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 \
+ }
+#define MEMORY_ERROR_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "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", \
+ "Physical Memory Map-out Event" \
+ }
+#define MEMORY_ERROR_2_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "errorStatusValid", "physicalAddressValid", \
+ "physicalAddressMaskValid", "nodeValid", "cardValid", \
+ "moduleValid", "bankValid", "deviceValid", "rowValid", \
+ "columnValid", "rankValid", "bitPositionValid", \
+ "chipIDValid", "memoryErrorTypeValid", "statusValid", \
+ "requestorIDValid", "responderIDValid", \
+ "targetIDValid", "cardHandleValid", \
+ "moduleHandleValid", "bankGroupValid", \
+ "bankAddressValid" \
+ }
-json_object* cper_section_platform_memory_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-json_object* cper_section_platform_memory2_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-void ir_section_memory_to_cper(json_object* section, FILE* out);
-void ir_section_memory2_to_cper(json_object* section, FILE* out);
+json_object *cper_section_platform_memory_to_ir(void *section);
+json_object *cper_section_platform_memory2_to_ir(void *section);
+void ir_section_memory_to_cper(json_object *section, FILE *out);
+void ir_section_memory2_to_cper(json_object *section, FILE *out);
-
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section-pci-bus.c b/sections/cper-section-pci-bus.c
index 33d0d03..2636cd2 100644
--- a/sections/cper-section-pci-bus.c
+++ b/sections/cper-section-pci-bus.c
@@ -12,9 +12,7 @@
#include "cper-section-pci-bus.h"
//Converts a single PCI/PCI-X bus CPER section into JSON IR.
-json_object *
-cper_section_pci_bus_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_pci_bus_to_ir(void *section)
{
EFI_PCI_PCIX_BUS_ERROR_DATA *bus_error =
(EFI_PCI_PCIX_BUS_ERROR_DATA *)section;
@@ -46,7 +44,7 @@
//Miscellaneous numeric fields.
UINT8 command_type = (bus_error->BusCommand >> 56) &
- 0b1; //Byte 7, bit 0.
+ 0x1; //Byte 7, bit 0.
json_object_object_add(section_ir, "busAddress",
json_object_new_uint64(bus_error->BusAddress));
json_object_object_add(section_ir, "busData",
@@ -113,4 +111,4 @@
fwrite(section_cper, sizeof(EFI_PCI_PCIX_BUS_ERROR_DATA), 1, out);
fflush(out);
free(section_cper);
-}
\ No newline at end of file
+}
diff --git a/sections/cper-section-pci-bus.h b/sections/cper-section-pci-bus.h
index cf4371a..6a959e4 100644
--- a/sections/cper-section-pci-bus.h
+++ b/sections/cper-section-pci-bus.h
@@ -4,15 +4,30 @@
#include <json.h>
#include "../edk/Cper.h"
-#define PCI_BUS_ERROR_VALID_BITFIELD_NAMES (const char*[]) {"errorStatusValid", "errorTypeValid", \
- "busIDValid", "busAddressValid", "busDataValid", "commandValid", "requestorIDValid", "completerIDValid", \
- "targetIDValid"}
-#define PCI_BUS_ERROR_TYPES_KEYS (int []){0, 1, 2, 3, 4, 5, 6, 7}
-#define PCI_BUS_ERROR_TYPES_VALUES (const char*[]){"Unknown/OEM Specific Error", "Data Parity Error", \
- "System Error", "Master Abort", "Bus Timeout/No Device Present (No DEVSEL#)", \
- "Master Data Parity Error", "Address Parity Error", "Command Parity Error"}
+#define PCI_BUS_ERROR_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "errorStatusValid", "errorTypeValid", "busIDValid", \
+ "busAddressValid", "busDataValid", "commandValid", \
+ "requestorIDValid", "completerIDValid", \
+ "targetIDValid" \
+ }
+#define PCI_BUS_ERROR_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 2, 3, 4, 5, 6, 7 \
+ }
+#define PCI_BUS_ERROR_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "Unknown/OEM Specific Error", "Data Parity Error", \
+ "System Error", "Master Abort", \
+ "Bus Timeout/No Device Present (No DEVSEL#)", \
+ "Master Data Parity Error", "Address Parity Error", \
+ "Command Parity Error" \
+ }
-json_object* cper_section_pci_bus_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-void ir_section_pci_bus_to_cper(json_object* section, FILE* out);
+json_object *cper_section_pci_bus_to_ir(void *section);
+void ir_section_pci_bus_to_cper(json_object *section, FILE *out);
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section-pci-dev.c b/sections/cper-section-pci-dev.c
index 5f40183..f3bd983 100644
--- a/sections/cper-section-pci-dev.c
+++ b/sections/cper-section-pci-dev.c
@@ -11,9 +11,7 @@
#include "cper-section-pci-dev.h"
//Converts a single PCI/PCI-X device CPER section into JSON IR.
-json_object *
-cper_section_pci_dev_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_pci_dev_to_ir(void *section)
{
EFI_PCI_PCIX_DEVICE_ERROR_DATA *dev_error =
(EFI_PCI_PCIX_DEVICE_ERROR_DATA *)section;
@@ -149,4 +147,4 @@
fwrite(pair, sizeof(UINT64), 2, out);
fflush(out);
}
-}
\ No newline at end of file
+}
diff --git a/sections/cper-section-pci-dev.h b/sections/cper-section-pci-dev.h
index e261d44..5326a8c 100644
--- a/sections/cper-section-pci-dev.h
+++ b/sections/cper-section-pci-dev.h
@@ -4,32 +4,36 @@
#include <json.h>
#include "../edk/Cper.h"
-#define PCI_DEV_ERROR_VALID_BITFIELD_NAMES (const char*[]) {"errorStatusValid", "idInfoValid", "memoryNumberValid", \
- "ioNumberValid", "registerDataPairsValid"}
+#define PCI_DEV_ERROR_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "errorStatusValid", "idInfoValid", "memoryNumberValid", \
+ "ioNumberValid", "registerDataPairsValid" \
+ }
///
/// PCI/PCI-X Device Error Section
///
typedef struct {
- UINT64 VendorId : 16;
- UINT64 DeviceId : 16;
- UINT64 ClassCode : 24;
- UINT64 FunctionNumber : 8;
- UINT64 DeviceNumber : 8;
- UINT64 BusNumber : 8;
- UINT64 SegmentNumber : 8;
- UINT64 Reserved : 40;
+ UINT64 VendorId : 16;
+ UINT64 DeviceId : 16;
+ UINT64 ClassCode : 24;
+ UINT64 FunctionNumber : 8;
+ UINT64 DeviceNumber : 8;
+ UINT64 BusNumber : 8;
+ UINT64 SegmentNumber : 8;
+ UINT64 Reserved : 40;
} EFI_PCI_PCIX_DEVICE_ID_INFO;
typedef struct {
- UINT64 ValidFields;
- EFI_GENERIC_ERROR_STATUS ErrorStatus;
- EFI_PCI_PCIX_DEVICE_ID_INFO IdInfo;
- UINT32 MemoryNumber;
- UINT32 IoNumber;
+ UINT64 ValidFields;
+ EFI_GENERIC_ERROR_STATUS ErrorStatus;
+ EFI_PCI_PCIX_DEVICE_ID_INFO IdInfo;
+ UINT32 MemoryNumber;
+ UINT32 IoNumber;
} __attribute__((packed, aligned(1))) EFI_PCI_PCIX_DEVICE_ERROR_DATA;
-json_object* cper_section_pci_dev_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-void ir_section_pci_dev_to_cper(json_object* section, FILE* out);
+json_object *cper_section_pci_dev_to_ir(void *section);
+void ir_section_pci_dev_to_cper(json_object *section, FILE *out);
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section-pcie.c b/sections/cper-section-pcie.c
index cf68b3f..0642996 100644
--- a/sections/cper-section-pcie.c
+++ b/sections/cper-section-pcie.c
@@ -7,14 +7,13 @@
#include <stdio.h>
#include <string.h>
#include <json.h>
-#include "b64.h"
+#include "libbase64.h"
#include "../edk/Cper.h"
#include "../cper-utils.h"
#include "cper-section-pcie.h"
//Converts a single PCIe CPER section into JSON IR.
-json_object *cper_section_pcie_to_ir(void *section,
- EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
+json_object *cper_section_pcie_to_ir(void *section)
{
EFI_PCIE_ERROR_DATA *pcie_error = (EFI_PCIE_ERROR_DATA *)section;
json_object *section_ir = json_object_new_object();
@@ -104,21 +103,38 @@
//The PCIe capability structure provided here could either be PCIe 1.1 Capability Structure
//(36-byte, padded to 60 bytes) or PCIe 2.0 Capability Structure (60-byte). There does not seem
//to be a way to differentiate these, so this is left as a b64 dump.
- char *encoded =
- b64_encode((unsigned char *)pcie_error->Capability.PcieCap, 60);
- json_object *capability = json_object_new_object();
- json_object_object_add(capability, "data",
- json_object_new_string(encoded));
- free(encoded);
- json_object_object_add(section_ir, "capabilityStructure", capability);
+ char *encoded = malloc(2 * 60);
+ size_t encoded_len = 0;
+ if (!encoded) {
+ printf("Failed to allocate encode output buffer. \n");
+ } else {
+ base64_encode((const char *)pcie_error->Capability.PcieCap, 60,
+ encoded, &encoded_len, 0);
+ json_object *capability = json_object_new_object();
+ json_object_object_add(capability, "data",
+ json_object_new_string_len(encoded,
+ encoded_len));
+ free(encoded);
+ json_object_object_add(section_ir, "capabilityStructure",
+ capability);
+ }
//AER information.
json_object *aer_capability_ir = json_object_new_object();
- encoded = b64_encode((unsigned char *)pcie_error->AerInfo.PcieAer, 96);
- json_object_object_add(aer_capability_ir, "data",
- json_object_new_string(encoded));
- free(encoded);
- json_object_object_add(section_ir, "aerInfo", aer_capability_ir);
+ encoded = malloc(2 * 96);
+ encoded_len = 0;
+ if (!encoded) {
+ printf("Failed to allocate encode output buffer. \n");
+ } else {
+ base64_encode((const char *)pcie_error->AerInfo.PcieAer, 96,
+ encoded, &encoded_len, 0);
+ json_object_object_add(aer_capability_ir, "data",
+ json_object_new_string_len(encoded,
+ encoded_len));
+ free(encoded);
+ json_object_object_add(section_ir, "aerInfo",
+ aer_capability_ir);
+ }
return section_ir;
}
@@ -190,18 +206,32 @@
json_object *capability =
json_object_object_get(section, "capabilityStructure");
json_object *encoded = json_object_object_get(capability, "data");
- UINT8 *decoded = b64_decode(json_object_get_string(encoded),
- json_object_get_string_len(encoded));
- memcpy(section_cper->Capability.PcieCap, decoded, 60);
- free(decoded);
+ char *decoded = malloc(json_object_get_string_len(encoded));
+ size_t decoded_len = 0;
+ if (!decoded) {
+ printf("Failed to allocate decode output buffer. \n");
+ } else {
+ base64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded), decoded,
+ &decoded_len, 0);
+ memcpy(section_cper->Capability.PcieCap, decoded, decoded_len);
+ free(decoded);
+ }
//AER capability structure.
json_object *aer_info = json_object_object_get(section, "aerInfo");
encoded = json_object_object_get(aer_info, "data");
- decoded = b64_decode(json_object_get_string(encoded),
- json_object_get_string_len(encoded));
- memcpy(section_cper->AerInfo.PcieAer, decoded, 96);
- free(decoded);
+ decoded = malloc(json_object_get_string_len(encoded));
+ decoded_len = 0;
+ if (!decoded) {
+ printf("Failed to allocate decode output buffer. \n");
+ } else {
+ base64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded), decoded,
+ &decoded_len, 0);
+ memcpy(section_cper->AerInfo.PcieAer, decoded, decoded_len);
+ free(decoded);
+ }
//Miscellaneous value fields.
section_cper->PortType = (UINT32)readable_pair_to_integer(
@@ -213,4 +243,4 @@
fwrite(section_cper, sizeof(EFI_PCIE_ERROR_DATA), 1, out);
fflush(out);
free(section_cper);
-}
\ No newline at end of file
+}
diff --git a/sections/cper-section-pcie.h b/sections/cper-section-pcie.h
index a2a43a4..b0042c5 100644
--- a/sections/cper-section-pcie.h
+++ b/sections/cper-section-pcie.h
@@ -4,15 +4,32 @@
#include <json.h>
#include "../edk/Cper.h"
-#define PCIE_ERROR_VALID_BITFIELD_NAMES (const char*[]) {"portTypeValid", "versionValid", "commandStatusValid", \
- "deviceIDValid", "deviceSerialNumberValid", "bridgeControlStatusValid", "capabilityStructureStatusValid", \
- "aerInfoValid"}
-#define PCIE_ERROR_PORT_TYPES_KEYS (int []){0, 1, 4, 5, 6, 7, 8, 9, 10}
-#define PCIE_ERROR_PORT_TYPES_VALUES (const char*[]){"PCI Express End Point", "Legacy PCI End Point Device", \
- "Root Port", "Upstream Switch Port", "Downstream Switch Port", "PCI Express to PCI/PCI-X Bridge", \
- "PCI/PCI-X Bridge to PCI Express Bridge", "Root Complex Integrated Endpoint Device", "Root Complex Event Collector"}
+#define PCIE_ERROR_VALID_BITFIELD_NAMES \
+ (const char *[]) \
+ { \
+ "portTypeValid", "versionValid", "commandStatusValid", \
+ "deviceIDValid", "deviceSerialNumberValid", \
+ "bridgeControlStatusValid", \
+ "capabilityStructureStatusValid", "aerInfoValid" \
+ }
+#define PCIE_ERROR_PORT_TYPES_KEYS \
+ (int[]) \
+ { \
+ 0, 1, 4, 5, 6, 7, 8, 9, 10 \
+ }
+#define PCIE_ERROR_PORT_TYPES_VALUES \
+ (const char *[]) \
+ { \
+ "PCI Express End Point", "Legacy PCI End Point Device", \
+ "Root Port", "Upstream Switch Port", \
+ "Downstream Switch Port", \
+ "PCI Express to PCI/PCI-X Bridge", \
+ "PCI/PCI-X Bridge to PCI Express Bridge", \
+ "Root Complex Integrated Endpoint Device", \
+ "Root Complex Event Collector" \
+ }
-json_object* cper_section_pcie_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
-void ir_section_pcie_to_cper(json_object* section, FILE* out);
+json_object *cper_section_pcie_to_ir(void *section);
+void ir_section_pcie_to_cper(json_object *section, FILE *out);
-#endif
\ No newline at end of file
+#endif
diff --git a/sections/cper-section.c b/sections/cper-section.c
index 82a44a5..9bffdcb 100644
--- a/sections/cper-section.c
+++ b/sections/cper-section.c
@@ -23,26 +23,52 @@
//Definitions of all sections available to the CPER parser.
CPER_SECTION_DEFINITION section_definitions[] = {
- {&gEfiProcessorGenericErrorSectionGuid, "Processor Generic", cper_section_generic_to_ir, ir_section_generic_to_cper},
- {&gEfiIa32X64ProcessorErrorSectionGuid, "IA32/X64", cper_section_ia32x64_to_ir, ir_section_ia32x64_to_cper},
- {&gEfiIpfProcessorErrorSectionGuid, "IPF", NULL, NULL},
- {&gEfiArmProcessorErrorSectionGuid, "ARM", cper_section_arm_to_ir, ir_section_arm_to_cper},
- {&gEfiPlatformMemoryErrorSectionGuid, "Platform Memory", cper_section_platform_memory_to_ir, ir_section_memory_to_cper},
- {&gEfiPlatformMemoryError2SectionGuid, "Platform Memory 2", cper_section_platform_memory2_to_ir, ir_section_memory2_to_cper},
- {&gEfiPcieErrorSectionGuid, "PCIe", cper_section_pcie_to_ir, ir_section_pcie_to_cper},
- {&gEfiFirmwareErrorSectionGuid, "Firmware Error Record Reference", cper_section_firmware_to_ir, ir_section_firmware_to_cper},
- {&gEfiPciBusErrorSectionGuid, "PCI/PCI-X Bus", cper_section_pci_bus_to_ir, ir_section_pci_bus_to_cper},
- {&gEfiPciDevErrorSectionGuid, "PCI Component/Device", cper_section_pci_dev_to_ir, ir_section_pci_dev_to_cper},
- {&gEfiDMArGenericErrorSectionGuid, "DMAr Generic", cper_section_dmar_generic_to_ir, ir_section_dmar_generic_to_cper},
- {&gEfiDirectedIoDMArErrorSectionGuid, "Intel VT for Directed I/O Specific DMAr", cper_section_dmar_vtd_to_ir, ir_section_dmar_vtd_to_cper},
- {&gEfiIommuDMArErrorSectionGuid, "IOMMU Specific DMAr", cper_section_dmar_iommu_to_ir, ir_section_dmar_iommu_to_cper},
- {&gEfiCcixPerLogErrorSectionGuid, "CCIX PER Log Error", cper_section_ccix_per_to_ir, ir_section_ccix_per_to_cper},
- {&gEfiCxlProtocolErrorSectionGuid, "CXL Protocol Error", cper_section_cxl_protocol_to_ir, ir_section_cxl_protocol_to_cper},
- {&gEfiCxlGeneralMediaErrorSectionGuid, "CXL General Media Component Error", cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper},
- {&gEfiCxlDramEventErrorSectionGuid, "CXL DRAM Component Error", cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper},
- {&gEfiCxlMemoryModuleErrorSectionGuid, "CXL Memory Module Component Error", cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper},
- {&gEfiCxlPhysicalSwitchErrorSectionGuid, "CXL Physical Switch Component Error", cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper},
- {&gEfiCxlVirtualSwitchErrorSectionGuid, "CXL Virtual Switch Component Error", cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper},
- {&gEfiCxlMldPortErrorSectionGuid, "CXL MLD Port Component Error", cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper},
+ { &gEfiProcessorGenericErrorSectionGuid, "Processor Generic",
+ cper_section_generic_to_ir, ir_section_generic_to_cper },
+ { &gEfiIa32X64ProcessorErrorSectionGuid, "IA32/X64",
+ cper_section_ia32x64_to_ir, ir_section_ia32x64_to_cper },
+ { &gEfiIpfProcessorErrorSectionGuid, "IPF", NULL, NULL },
+ { &gEfiArmProcessorErrorSectionGuid, "ARM", cper_section_arm_to_ir,
+ ir_section_arm_to_cper },
+ { &gEfiPlatformMemoryErrorSectionGuid, "Platform Memory",
+ cper_section_platform_memory_to_ir, ir_section_memory_to_cper },
+ { &gEfiPlatformMemoryError2SectionGuid, "Platform Memory 2",
+ cper_section_platform_memory2_to_ir, ir_section_memory2_to_cper },
+ { &gEfiPcieErrorSectionGuid, "PCIe", cper_section_pcie_to_ir,
+ ir_section_pcie_to_cper },
+ { &gEfiFirmwareErrorSectionGuid, "Firmware Error Record Reference",
+ cper_section_firmware_to_ir, ir_section_firmware_to_cper },
+ { &gEfiPciBusErrorSectionGuid, "PCI/PCI-X Bus",
+ cper_section_pci_bus_to_ir, ir_section_pci_bus_to_cper },
+ { &gEfiPciDevErrorSectionGuid, "PCI Component/Device",
+ cper_section_pci_dev_to_ir, ir_section_pci_dev_to_cper },
+ { &gEfiDMArGenericErrorSectionGuid, "DMAr Generic",
+ cper_section_dmar_generic_to_ir, ir_section_dmar_generic_to_cper },
+ { &gEfiDirectedIoDMArErrorSectionGuid,
+ "Intel VT for Directed I/O Specific DMAr",
+ cper_section_dmar_vtd_to_ir, ir_section_dmar_vtd_to_cper },
+ { &gEfiIommuDMArErrorSectionGuid, "IOMMU Specific DMAr",
+ cper_section_dmar_iommu_to_ir, ir_section_dmar_iommu_to_cper },
+ { &gEfiCcixPerLogErrorSectionGuid, "CCIX PER Log Error",
+ cper_section_ccix_per_to_ir, ir_section_ccix_per_to_cper },
+ { &gEfiCxlProtocolErrorSectionGuid, "CXL Protocol Error",
+ cper_section_cxl_protocol_to_ir, ir_section_cxl_protocol_to_cper },
+ { &gEfiCxlGeneralMediaErrorSectionGuid,
+ "CXL General Media Component Error", cper_section_cxl_component_to_ir,
+ ir_section_cxl_component_to_cper },
+ { &gEfiCxlDramEventErrorSectionGuid, "CXL DRAM Component Error",
+ cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper },
+ { &gEfiCxlMemoryModuleErrorSectionGuid,
+ "CXL Memory Module Component Error", cper_section_cxl_component_to_ir,
+ ir_section_cxl_component_to_cper },
+ { &gEfiCxlPhysicalSwitchErrorSectionGuid,
+ "CXL Physical Switch Component Error",
+ cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper },
+ { &gEfiCxlVirtualSwitchErrorSectionGuid,
+ "CXL Virtual Switch Component Error",
+ cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper },
+ { &gEfiCxlMldPortErrorSectionGuid, "CXL MLD Port Component Error",
+ cper_section_cxl_component_to_ir, ir_section_cxl_component_to_cper },
};
-const size_t section_definitions_len = sizeof(section_definitions) / sizeof(CPER_SECTION_DEFINITION);
\ No newline at end of file
+const size_t section_definitions_len =
+ sizeof(section_definitions) / sizeof(CPER_SECTION_DEFINITION);
diff --git a/sections/cper-section.h b/sections/cper-section.h
index 4379f91..4ec8650 100644
--- a/sections/cper-section.h
+++ b/sections/cper-section.h
@@ -8,13 +8,13 @@
//Definition structure for a single CPER section type.
typedef struct {
- EFI_GUID* Guid;
- const char* ReadableName;
- json_object* (*ToIR)(void*, EFI_ERROR_SECTION_DESCRIPTOR*);
- void (*ToCPER)(json_object*, FILE*);
+ EFI_GUID *Guid;
+ const char *ReadableName;
+ json_object *(*ToIR)(void *);
+ void (*ToCPER)(json_object *, FILE *);
} CPER_SECTION_DEFINITION;
extern CPER_SECTION_DEFINITION section_definitions[];
extern const size_t section_definitions_len;
-#endif
\ No newline at end of file
+#endif