blob: 6ef6a6f9488769bddbeaf1f5d1ffdf78de54b12f [file] [log] [blame]
Lawrence Tang1b0b00e2022-07-05 10:33:10 +01001/**
Lawrence Tang2800cd82022-07-05 16:08:20 +01002 * Describes high level functions for converting an entire CPER log, and functions for parsing
3 * CPER headers and section descriptions into an intermediate JSON format.
Lawrence Tang1b0b00e2022-07-05 10:33:10 +01004 *
5 * Author: Lawrence.Tang@arm.com
6 **/
7
8#include <stdio.h>
9#include "json.h"
Lawrence Tangd7e8ca32022-07-07 10:25:53 +010010#include "b64.h"
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010011#include "edk/Cper.h"
12#include "cper-parse.h"
13#include "cper-utils.h"
14#include "sections/cper-section-generic.h"
Lawrence Tang794312c2022-07-05 14:46:10 +010015#include "sections/cper-section-ia32x64.h"
Lawrence Tang2800cd82022-07-05 16:08:20 +010016#include "sections/cper-section-arm.h"
Lawrence Tanga0865e32022-07-06 11:59:52 +010017#include "sections/cper-section-memory.h"
Lawrence Tang4dbe3d72022-07-06 13:51:01 +010018#include "sections/cper-section-pcie.h"
Lawrence Tang214a1542022-07-06 14:11:28 +010019#include "sections/cper-section-pci-bus.h"
Lawrence Tanga416ec92022-07-06 14:34:40 +010020#include "sections/cper-section-pci-dev.h"
Lawrence Tangc60a2432022-07-06 14:58:33 +010021#include "sections/cper-section-firmware.h"
Lawrence Tang4795d4a2022-07-06 15:19:31 +010022#include "sections/cper-section-dmar-generic.h"
Lawrence Tangdb1b7ce2022-07-06 15:40:26 +010023#include "sections/cper-section-dmar-vtd.h"
24#include "sections/cper-section-dmar-iommu.h"
Lawrence Tang864c0da2022-07-06 15:55:40 +010025#include "sections/cper-section-ccix-per.h"
Lawrence Tangb98ec662022-07-06 16:50:21 +010026#include "sections/cper-section-cxl-protocol.h"
Lawrence Tangcc0f5f32022-07-06 17:17:26 +010027#include "sections/cper-section-ipf.h"
Lawrence Tangd7e8ca32022-07-07 10:25:53 +010028#include "sections/cper-section-cxl-component.h"
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010029
30//Private pre-definitions.
31json_object* cper_header_to_ir(EFI_COMMON_ERROR_RECORD_HEADER* header);
32json_object* cper_section_descriptor_to_ir(EFI_ERROR_SECTION_DESCRIPTOR* section_descriptor);
33json_object* cper_section_to_ir(FILE* handle, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
34
35//Reads a CPER log file at the given file location, and returns an intermediate
36//JSON representation of this CPER record.
Lawrence Tangf0f95572022-07-07 16:56:22 +010037json_object* cper_to_ir(FILE* cper_file)
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010038{
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010039 //Ensure this is really a CPER log.
40 EFI_COMMON_ERROR_RECORD_HEADER header;
41 fseek(cper_file, 0, SEEK_SET);
42 if (fread(&header, sizeof(EFI_COMMON_ERROR_RECORD_HEADER), 1, cper_file) != 1)
43 {
Lawrence Tang02c801a2022-07-18 14:43:52 +010044 printf("Invalid CPER file: Invalid length (log too short).\n");
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010045 return NULL;
46 }
47
48 //Check if the header contains the magic bytes ("CPER").
49 if (header.SignatureStart != EFI_ERROR_RECORD_SIGNATURE_START) {
Lawrence Tang02c801a2022-07-18 14:43:52 +010050 printf("Invalid CPER file: Invalid header (incorrect signature).\n");
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010051 return NULL;
52 }
53
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010054 //Create the header JSON object from the read bytes.
55 json_object* header_ir = cper_header_to_ir(&header);
56
57 //Read the appropriate number of section descriptors & sections, and convert them into IR format.
58 json_object* section_descriptors_ir = json_object_new_array();
59 json_object* sections_ir = json_object_new_array();
60 for (int i=0; i<header.SectionCount; i++)
61 {
62 //Create the section descriptor.
63 EFI_ERROR_SECTION_DESCRIPTOR section_descriptor;
64 if (fread(&section_descriptor, sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1, cper_file) != 1)
65 {
Lawrence Tang02c801a2022-07-18 14:43:52 +010066 printf("Invalid number of section headers: Header states %d sections, could not read section %d.\n", header.SectionCount, i+1);
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010067 return NULL;
68 }
69 json_object_array_add(section_descriptors_ir, cper_section_descriptor_to_ir(&section_descriptor));
70
71 //Read the section itself.
72 json_object_array_add(sections_ir, cper_section_to_ir(cper_file, &section_descriptor));
73 }
74
75 //Add the header, section descriptors, and sections to a parent object.
76 json_object* parent = json_object_new_object();
77 json_object_object_add(parent, "header", header_ir);
78 json_object_object_add(parent, "sectionDescriptors", section_descriptors_ir);
Lawrence Tang2800cd82022-07-05 16:08:20 +010079 json_object_object_add(parent, "sections", sections_ir);
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010080
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010081 return parent;
82}
83
84//Converts a parsed CPER record header into intermediate JSON object format.
85json_object* cper_header_to_ir(EFI_COMMON_ERROR_RECORD_HEADER* header)
86{
87 json_object* header_ir = json_object_new_object();
88
89 //Revision/version information.
90 json_object_object_add(header_ir, "revision", revision_to_ir(header->Revision));
91
92 //Section count.
93 json_object_object_add(header_ir, "sectionCount", json_object_new_int(header->SectionCount));
94
95 //Error severity (with interpreted string version).
96 json_object* error_severity = json_object_new_object();
Lawrence Tang3c878352022-07-08 14:04:50 +010097 json_object_object_add(error_severity, "code", json_object_new_uint64(header->ErrorSeverity));
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010098 json_object_object_add(error_severity, "name", json_object_new_string(severity_to_string(header->ErrorSeverity)));
99 json_object_object_add(header_ir, "severity", error_severity);
100
101 //The validation bits for each section.
Lawrence Tang2800cd82022-07-05 16:08:20 +0100102 json_object* validation_bits = bitfield_to_ir(header->ValidationBits, 3, CPER_HEADER_VALID_BITFIELD_NAMES);
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100103 json_object_object_add(header_ir, "validationBits", validation_bits);
104
105 //Total length of the record (including headers) in bytes.
Lawrence Tang3c878352022-07-08 14:04:50 +0100106 json_object_object_add(header_ir, "recordLength", json_object_new_uint64(header->RecordLength));
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100107
108 //If a timestamp exists according to validation bits, then add it.
109 if (header->ValidationBits & 0b10)
110 {
111 char timestamp_string[TIMESTAMP_LENGTH];
Lawrence Tangaacf0e22022-07-20 13:28:52 +0100112 timestamp_to_string(timestamp_string, &header->TimeStamp);
113
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100114 json_object_object_add(header_ir, "timestamp", json_object_new_string(timestamp_string));
115 json_object_object_add(header_ir, "timestampIsPrecise", json_object_new_boolean(header->TimeStamp.Flag));
116 }
117
118 //If a platform ID exists according to the validation bits, then add it.
119 if (header->ValidationBits & 0b1)
120 {
121 char platform_string[GUID_STRING_LENGTH];
122 guid_to_string(platform_string, &header->PlatformID);
123 json_object_object_add(header_ir, "platformID", json_object_new_string(platform_string));
124 }
125
126 //If a partition ID exists according to the validation bits, then add it.
127 if (header->ValidationBits & 0b100)
128 {
129 char partition_string[GUID_STRING_LENGTH];
130 guid_to_string(partition_string, &header->PartitionID);
131 json_object_object_add(header_ir, "partitionID", json_object_new_string(partition_string));
132 }
133
134 //Creator ID of the header.
135 char creator_string[GUID_STRING_LENGTH];
136 guid_to_string(creator_string, &header->CreatorID);
137 json_object_object_add(header_ir, "creatorID", json_object_new_string(creator_string));
138
139 //Notification type for the header. Some defined types are available.
140 json_object* notification_type = json_object_new_object();
141 char notification_type_string[GUID_STRING_LENGTH];
142 guid_to_string(notification_type_string, &header->NotificationType);
143 json_object_object_add(notification_type, "guid", json_object_new_string(notification_type_string));
144
145 //Add the human readable notification type if possible.
146 char* notification_type_readable = "Unknown";
147 if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCmcGuid))
148 notification_type_readable = "CMC";
Lawrence Tang794312c2022-07-05 14:46:10 +0100149 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCpeGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100150 notification_type_readable = "CPE";
Lawrence Tang794312c2022-07-05 14:46:10 +0100151 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeMceGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100152 notification_type_readable = "MCE";
Lawrence Tang794312c2022-07-05 14:46:10 +0100153 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypePcieGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100154 notification_type_readable = "PCIe";
Lawrence Tang794312c2022-07-05 14:46:10 +0100155 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeInitGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100156 notification_type_readable = "INIT";
Lawrence Tang794312c2022-07-05 14:46:10 +0100157 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeNmiGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100158 notification_type_readable = "NMI";
Lawrence Tang794312c2022-07-05 14:46:10 +0100159 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeBootGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100160 notification_type_readable = "Boot";
Lawrence Tang794312c2022-07-05 14:46:10 +0100161 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeDmarGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100162 notification_type_readable = "DMAr";
Lawrence Tang794312c2022-07-05 14:46:10 +0100163 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeSeaGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100164 notification_type_readable = "SEA";
Lawrence Tang794312c2022-07-05 14:46:10 +0100165 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeSeiGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100166 notification_type_readable = "SEI";
Lawrence Tang794312c2022-07-05 14:46:10 +0100167 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypePeiGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100168 notification_type_readable = "PEI";
Lawrence Tang794312c2022-07-05 14:46:10 +0100169 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCxlGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100170 notification_type_readable = "CXL Component";
171 json_object_object_add(notification_type, "type", json_object_new_string(notification_type_readable));
172 json_object_object_add(header_ir, "notificationType", notification_type);
173
174 //The record ID for this record, unique on a given system.
175 json_object_object_add(header_ir, "recordID", json_object_new_uint64(header->RecordID));
176
177 //Flag for the record, and a human readable form.
Lawrence Tang3c43f742022-07-05 11:37:17 +0100178 json_object* flags = integer_to_readable_pair(header->Flags,
179 sizeof(CPER_HEADER_FLAG_TYPES_KEYS) / sizeof(int),
180 CPER_HEADER_FLAG_TYPES_KEYS,
181 CPER_HEADER_FLAG_TYPES_VALUES,
182 "Unknown");
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100183 json_object_object_add(header_ir, "flags", flags);
184
185 //Persistence information. Outside the scope of specification, so just a uint32 here.
Lawrence Tang3c878352022-07-08 14:04:50 +0100186 json_object_object_add(header_ir, "persistenceInfo", json_object_new_uint64(header->PersistenceInfo));
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100187 return header_ir;
188}
189
190//Converts the given EFI section descriptor into JSON IR format.
191json_object* cper_section_descriptor_to_ir(EFI_ERROR_SECTION_DESCRIPTOR* section_descriptor)
192{
193 json_object* section_descriptor_ir = json_object_new_object();
194
195 //The offset of the section from the base of the record header, length.
Lawrence Tang3c878352022-07-08 14:04:50 +0100196 json_object_object_add(section_descriptor_ir, "sectionOffset", json_object_new_uint64(section_descriptor->SectionOffset));
197 json_object_object_add(section_descriptor_ir, "sectionLength", json_object_new_uint64(section_descriptor->SectionLength));
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100198
199 //Revision.
200 json_object_object_add(section_descriptor_ir, "revision", revision_to_ir(section_descriptor->Revision));
201
202 //Validation bits.
Lawrence Tang0cb33792022-07-13 13:51:39 +0100203 json_object* validation_bits = bitfield_to_ir(section_descriptor->SecValidMask, 2, CPER_SECTION_DESCRIPTOR_VALID_BITFIELD_NAMES);
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100204 json_object_object_add(section_descriptor_ir, "validationBits", validation_bits);
205
206 //Flag bits.
Lawrence Tang2800cd82022-07-05 16:08:20 +0100207 json_object* flags = bitfield_to_ir(section_descriptor->SectionFlags, 8, CPER_SECTION_DESCRIPTOR_FLAGS_BITFIELD_NAMES);
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100208 json_object_object_add(section_descriptor_ir, "flags", flags);
209
210 //Section type (GUID).
211 json_object* section_type = json_object_new_object();
212 char section_type_string[GUID_STRING_LENGTH];
213 guid_to_string(section_type_string, &section_descriptor->SectionType);
214 json_object_object_add(section_type, "data", json_object_new_string(section_type_string));
215
216 //Readable section type, if possible.
217 char* section_type_readable = "Unknown";
218 if (guid_equal(&section_descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid))
219 section_type_readable = "Processor Generic";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100220 else if (guid_equal(&section_descriptor->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100221 section_type_readable = "IA32/X64";
Lawrence Tangcc0f5f32022-07-06 17:17:26 +0100222 else if (guid_equal(&section_descriptor->SectionType, &gEfiIpfProcessorErrorSectionGuid))
223 section_type_readable = "IPF";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100224 else if (guid_equal(&section_descriptor->SectionType, &gEfiArmProcessorErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100225 section_type_readable = "ARM";
Lawrence Tang02c801a2022-07-18 14:43:52 +0100226 else if (guid_equal(&section_descriptor->SectionType, &gEfiPlatformMemoryErrorSectionGuid)
227 || guid_equal(&section_descriptor->SectionType, &gEfiPlatformMemoryError2SectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100228 section_type_readable = "Platform Memory";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100229 else if (guid_equal(&section_descriptor->SectionType, &gEfiPcieErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100230 section_type_readable = "PCIe";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100231 else if (guid_equal(&section_descriptor->SectionType, &gEfiFirmwareErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100232 section_type_readable = "Firmware Error Record Reference";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100233 else if (guid_equal(&section_descriptor->SectionType, &gEfiPciBusErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100234 section_type_readable = "PCI/PCI-X Bus";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100235 else if (guid_equal(&section_descriptor->SectionType, &gEfiPciDevErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100236 section_type_readable = "PCI Component/Device";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100237 else if (guid_equal(&section_descriptor->SectionType, &gEfiDMArGenericErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100238 section_type_readable = "DMAr Generic";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100239 else if (guid_equal(&section_descriptor->SectionType, &gEfiDirectedIoDMArErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100240 section_type_readable = "Intel VT for Directed I/O specific DMAr section";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100241 else if (guid_equal(&section_descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100242 section_type_readable = "IOMMU specific DMAr section";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100243 else if (guid_equal(&section_descriptor->SectionType, &gEfiCcixPerLogErrorSectionGuid))
244 section_type_readable = "CCIX PER Log Error";
Lawrence Tangb98ec662022-07-06 16:50:21 +0100245 else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlProtocolErrorSectionGuid))
246 section_type_readable = "CXL Protocol Error";
Lawrence Tangd7e8ca32022-07-07 10:25:53 +0100247 else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlGeneralMediaErrorSectionGuid))
248 section_type_readable = "CXL General Media Component Error";
249 else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlDramEventErrorSectionGuid))
250 section_type_readable = "CXL DRAM Component Error";
251 else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlPhysicalSwitchErrorSectionGuid))
252 section_type_readable = "CXL Physical Switch Component Error";
253 else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlVirtualSwitchErrorSectionGuid))
254 section_type_readable = "CXL Virtual Switch Component Error";
255 else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlMldPortErrorSectionGuid))
256 section_type_readable = "CXL MLD Port Component Error";
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100257
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100258 json_object_object_add(section_type, "type", json_object_new_string(section_type_readable));
259 json_object_object_add(section_descriptor_ir, "sectionType", section_type);
260
261 //If validation bits indicate it exists, add FRU ID.
262 if (section_descriptor->SecValidMask & 0b1)
263 {
264 char fru_id_string[GUID_STRING_LENGTH];
265 guid_to_string(fru_id_string, &section_descriptor->FruId);
266 json_object_object_add(section_descriptor_ir, "fruID", json_object_new_string(fru_id_string));
267 }
268
269 //If validation bits indicate it exists, add FRU text.
270 if ((section_descriptor->SecValidMask & 0b10) >> 1)
271 json_object_object_add(section_descriptor_ir, "fruText", json_object_new_string(section_descriptor->FruString));
272
273 //Section severity.
274 json_object* section_severity = json_object_new_object();
Lawrence Tang3c878352022-07-08 14:04:50 +0100275 json_object_object_add(section_severity, "code", json_object_new_uint64(section_descriptor->Severity));
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100276 json_object_object_add(section_severity, "name", json_object_new_string(severity_to_string(section_descriptor->Severity)));
277 json_object_object_add(section_descriptor_ir, "severity", section_severity);
278
279 return section_descriptor_ir;
280}
281
282
283//Converts the section described by a single given section descriptor.
284json_object* cper_section_to_ir(FILE* handle, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
285{
Lawrence Tangde9707f2022-07-19 10:54:31 +0100286 //Save our current position in the stream.
287 long position = ftell(handle);
288
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100289 //Read section as described by the section descriptor.
290 fseek(handle, descriptor->SectionOffset, SEEK_SET);
Lawrence Tange18aaee2022-07-07 09:01:30 +0100291 void* section = malloc(descriptor->SectionLength);
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100292 if (fread(section, descriptor->SectionLength, 1, handle) != 1)
293 {
Lawrence Tang02c801a2022-07-18 14:43:52 +0100294 printf("Section read failed: Could not read %d bytes from global offset %d.\n",
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100295 descriptor->SectionLength,
296 descriptor->SectionOffset);
Lawrence Tange18aaee2022-07-07 09:01:30 +0100297 free(section);
298 return NULL;
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100299 }
300
Lawrence Tangde9707f2022-07-19 10:54:31 +0100301 //Seek back to our original position.
302 fseek(handle, position, SEEK_SET);
303
Lawrence Tangdb1b7ce2022-07-06 15:40:26 +0100304 //Parse section to IR based on GUID.
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100305 json_object* result = NULL;
306 if (guid_equal(&descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid))
Lawrence Tang2800cd82022-07-05 16:08:20 +0100307 result = cper_section_generic_to_ir(section, descriptor);
308 else if (guid_equal(&descriptor->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid))
309 result = cper_section_ia32x64_to_ir(section, descriptor);
Lawrence Tangcc0f5f32022-07-06 17:17:26 +0100310 else if (guid_equal(&descriptor->SectionType, &gEfiIpfProcessorErrorSectionGuid))
311 result = cper_section_ipf_to_ir(section, descriptor);
Lawrence Tang2800cd82022-07-05 16:08:20 +0100312 else if (guid_equal(&descriptor->SectionType, &gEfiArmProcessorErrorSectionGuid))
313 result = cper_section_arm_to_ir(section, descriptor);
Lawrence Tanga0865e32022-07-06 11:59:52 +0100314 else if (guid_equal(&descriptor->SectionType, &gEfiPlatformMemoryErrorSectionGuid))
315 result = cper_section_platform_memory_to_ir(section, descriptor);
Lawrence Tang54da4412022-07-06 13:14:58 +0100316 else if (guid_equal(&descriptor->SectionType, &gEfiPlatformMemoryError2SectionGuid))
317 result = cper_section_platform_memory2_to_ir(section, descriptor);
Lawrence Tang4dbe3d72022-07-06 13:51:01 +0100318 else if (guid_equal(&descriptor->SectionType, &gEfiPcieErrorSectionGuid))
319 result = cper_section_pcie_to_ir(section, descriptor);
Lawrence Tangc60a2432022-07-06 14:58:33 +0100320 else if (guid_equal(&descriptor->SectionType, &gEfiFirmwareErrorSectionGuid))
321 result = cper_section_firmware_to_ir(section, descriptor);
Lawrence Tang214a1542022-07-06 14:11:28 +0100322 else if (guid_equal(&descriptor->SectionType, &gEfiPciBusErrorSectionGuid))
323 result = cper_section_pci_bus_to_ir(section, descriptor);
Lawrence Tanga416ec92022-07-06 14:34:40 +0100324 else if (guid_equal(&descriptor->SectionType, &gEfiPciDevErrorSectionGuid))
325 result = cper_section_pci_dev_to_ir(section, descriptor);
Lawrence Tang4795d4a2022-07-06 15:19:31 +0100326 else if (guid_equal(&descriptor->SectionType, &gEfiDMArGenericErrorSectionGuid))
327 result = cper_section_dmar_generic_to_ir(section, descriptor);
Lawrence Tangdb1b7ce2022-07-06 15:40:26 +0100328 else if (guid_equal(&descriptor->SectionType, &gEfiDirectedIoDMArErrorSectionGuid))
329 result = cper_section_dmar_vtd_to_ir(section, descriptor);
330 else if (guid_equal(&descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid))
331 result = cper_section_dmar_iommu_to_ir(section, descriptor);
Lawrence Tang864c0da2022-07-06 15:55:40 +0100332 else if (guid_equal(&descriptor->SectionType, &gEfiCcixPerLogErrorSectionGuid))
333 result = cper_section_ccix_per_to_ir(section, descriptor);
Lawrence Tangb98ec662022-07-06 16:50:21 +0100334 else if (guid_equal(&descriptor->SectionType, &gEfiCxlProtocolErrorSectionGuid))
335 result = cper_section_cxl_protocol_to_ir(section, descriptor);
Lawrence Tangd7e8ca32022-07-07 10:25:53 +0100336 else if (guid_equal(&descriptor->SectionType, &gEfiCxlGeneralMediaErrorSectionGuid)
337 || guid_equal(&descriptor->SectionType, &gEfiCxlDramEventErrorSectionGuid)
338 || guid_equal(&descriptor->SectionType, &gEfiCxlPhysicalSwitchErrorSectionGuid)
339 || guid_equal(&descriptor->SectionType, &gEfiCxlVirtualSwitchErrorSectionGuid)
340 || guid_equal(&descriptor->SectionType, &gEfiCxlMldPortErrorSectionGuid))
341 {
342 result = cper_section_cxl_component_to_ir(section, descriptor);
343 }
Lawrence Tangdb1b7ce2022-07-06 15:40:26 +0100344 else
345 {
346 //Failed read, unknown GUID.
Lawrence Tangd7e8ca32022-07-07 10:25:53 +0100347 //Output the data as formatted base64.
348 result = json_object_new_object();
349 char* encoded = b64_encode((unsigned char*)section, descriptor->SectionLength);
350 json_object_object_add(result, "data", json_object_new_string(encoded));
351 free(encoded);
Lawrence Tangdb1b7ce2022-07-06 15:40:26 +0100352 }
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100353
354 //Free section memory, return result.
355 free(section);
356 return result;
357}