blob: fa2d7965a98f50c9a9d396d7da6ed31c46b238bb [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.
37json_object* cper_to_ir(const char* filename)
38{
39 //Get a handle for the log file.
40 FILE* cper_file = fopen(filename, "r");
41 if (cper_file == NULL) {
42 printf("Could not open CPER record, file handle returned null.");
43 return NULL;
44 }
45
46 //Ensure this is really a CPER log.
47 EFI_COMMON_ERROR_RECORD_HEADER header;
48 fseek(cper_file, 0, SEEK_SET);
49 if (fread(&header, sizeof(EFI_COMMON_ERROR_RECORD_HEADER), 1, cper_file) != 1)
50 {
51 printf("Invalid CPER file: Invalid length (log too short).");
52 return NULL;
53 }
54
55 //Check if the header contains the magic bytes ("CPER").
56 if (header.SignatureStart != EFI_ERROR_RECORD_SIGNATURE_START) {
57 printf("Invalid CPER file: Invalid header (incorrect signature).");
58 return NULL;
59 }
60
61 // //Print struct contents (debug).
62 // fpos_t file_pos;
63 // fgetpos(cper_file, &file_pos);
64 // printf("Stream is at position %d.\n", file_pos);
65 // printf("SignatureStart: %s\n", (char*)&header.SignatureStart);
66 // printf("Revision: %u\n", header.Revision);
67 // printf("SectionCount: %u\n", header.SectionCount);
68 // printf("Severity: %d\n", header.ErrorSeverity);
69 // printf("RecordLength: %d\n", header.RecordLength);
70
71 //Create the header JSON object from the read bytes.
72 json_object* header_ir = cper_header_to_ir(&header);
73
74 //Read the appropriate number of section descriptors & sections, and convert them into IR format.
75 json_object* section_descriptors_ir = json_object_new_array();
76 json_object* sections_ir = json_object_new_array();
77 for (int i=0; i<header.SectionCount; i++)
78 {
79 //Create the section descriptor.
80 EFI_ERROR_SECTION_DESCRIPTOR section_descriptor;
81 if (fread(&section_descriptor, sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1, cper_file) != 1)
82 {
83 printf("Invalid number of section headers: Header states %d sections, could not read section %d.", header.SectionCount, i+1);
84 return NULL;
85 }
86 json_object_array_add(section_descriptors_ir, cper_section_descriptor_to_ir(&section_descriptor));
87
88 //Read the section itself.
89 json_object_array_add(sections_ir, cper_section_to_ir(cper_file, &section_descriptor));
90 }
91
92 //Add the header, section descriptors, and sections to a parent object.
93 json_object* parent = json_object_new_object();
94 json_object_object_add(parent, "header", header_ir);
95 json_object_object_add(parent, "sectionDescriptors", section_descriptors_ir);
Lawrence Tang2800cd82022-07-05 16:08:20 +010096 json_object_object_add(parent, "sections", sections_ir);
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010097
98 //...
99 return parent;
100}
101
102//Converts a parsed CPER record header into intermediate JSON object format.
103json_object* cper_header_to_ir(EFI_COMMON_ERROR_RECORD_HEADER* header)
104{
105 json_object* header_ir = json_object_new_object();
106
107 //Revision/version information.
108 json_object_object_add(header_ir, "revision", revision_to_ir(header->Revision));
109
110 //Section count.
111 json_object_object_add(header_ir, "sectionCount", json_object_new_int(header->SectionCount));
112
113 //Error severity (with interpreted string version).
114 json_object* error_severity = json_object_new_object();
115 json_object_object_add(error_severity, "code", json_object_new_int(header->ErrorSeverity));
116 json_object_object_add(error_severity, "name", json_object_new_string(severity_to_string(header->ErrorSeverity)));
117 json_object_object_add(header_ir, "severity", error_severity);
118
119 //The validation bits for each section.
Lawrence Tang2800cd82022-07-05 16:08:20 +0100120 json_object* validation_bits = bitfield_to_ir(header->ValidationBits, 3, CPER_HEADER_VALID_BITFIELD_NAMES);
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100121 json_object_object_add(header_ir, "validationBits", validation_bits);
122
123 //Total length of the record (including headers) in bytes.
124 json_object_object_add(header_ir, "recordLength", json_object_new_int(header->RecordLength));
125
126 //If a timestamp exists according to validation bits, then add it.
127 if (header->ValidationBits & 0b10)
128 {
129 char timestamp_string[TIMESTAMP_LENGTH];
130 sprintf(timestamp_string, "%02d%02d-%02d-%02dT%02d:%02d:%02d.000",
131 header->TimeStamp.Century,
132 header->TimeStamp.Year,
133 header->TimeStamp.Month,
134 header->TimeStamp.Day,
135 header->TimeStamp.Hours,
136 header->TimeStamp.Minutes,
137 header->TimeStamp.Seconds);
138
139 json_object_object_add(header_ir, "timestamp", json_object_new_string(timestamp_string));
140 json_object_object_add(header_ir, "timestampIsPrecise", json_object_new_boolean(header->TimeStamp.Flag));
141 }
142
143 //If a platform ID exists according to the validation bits, then add it.
144 if (header->ValidationBits & 0b1)
145 {
146 char platform_string[GUID_STRING_LENGTH];
147 guid_to_string(platform_string, &header->PlatformID);
148 json_object_object_add(header_ir, "platformID", json_object_new_string(platform_string));
149 }
150
151 //If a partition ID exists according to the validation bits, then add it.
152 if (header->ValidationBits & 0b100)
153 {
154 char partition_string[GUID_STRING_LENGTH];
155 guid_to_string(partition_string, &header->PartitionID);
156 json_object_object_add(header_ir, "partitionID", json_object_new_string(partition_string));
157 }
158
159 //Creator ID of the header.
160 char creator_string[GUID_STRING_LENGTH];
161 guid_to_string(creator_string, &header->CreatorID);
162 json_object_object_add(header_ir, "creatorID", json_object_new_string(creator_string));
163
164 //Notification type for the header. Some defined types are available.
165 json_object* notification_type = json_object_new_object();
166 char notification_type_string[GUID_STRING_LENGTH];
167 guid_to_string(notification_type_string, &header->NotificationType);
168 json_object_object_add(notification_type, "guid", json_object_new_string(notification_type_string));
169
170 //Add the human readable notification type if possible.
171 char* notification_type_readable = "Unknown";
172 if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCmcGuid))
173 notification_type_readable = "CMC";
Lawrence Tang794312c2022-07-05 14:46:10 +0100174 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCpeGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100175 notification_type_readable = "CPE";
Lawrence Tang794312c2022-07-05 14:46:10 +0100176 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeMceGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100177 notification_type_readable = "MCE";
Lawrence Tang794312c2022-07-05 14:46:10 +0100178 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypePcieGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100179 notification_type_readable = "PCIe";
Lawrence Tang794312c2022-07-05 14:46:10 +0100180 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeInitGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100181 notification_type_readable = "INIT";
Lawrence Tang794312c2022-07-05 14:46:10 +0100182 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeNmiGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100183 notification_type_readable = "NMI";
Lawrence Tang794312c2022-07-05 14:46:10 +0100184 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeBootGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100185 notification_type_readable = "Boot";
Lawrence Tang794312c2022-07-05 14:46:10 +0100186 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeDmarGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100187 notification_type_readable = "DMAr";
Lawrence Tang794312c2022-07-05 14:46:10 +0100188 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeSeaGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100189 notification_type_readable = "SEA";
Lawrence Tang794312c2022-07-05 14:46:10 +0100190 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeSeiGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100191 notification_type_readable = "SEI";
Lawrence Tang794312c2022-07-05 14:46:10 +0100192 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypePeiGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100193 notification_type_readable = "PEI";
Lawrence Tang794312c2022-07-05 14:46:10 +0100194 else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCxlGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100195 notification_type_readable = "CXL Component";
196 json_object_object_add(notification_type, "type", json_object_new_string(notification_type_readable));
197 json_object_object_add(header_ir, "notificationType", notification_type);
198
199 //The record ID for this record, unique on a given system.
200 json_object_object_add(header_ir, "recordID", json_object_new_uint64(header->RecordID));
201
202 //Flag for the record, and a human readable form.
Lawrence Tang3c43f742022-07-05 11:37:17 +0100203 json_object* flags = integer_to_readable_pair(header->Flags,
204 sizeof(CPER_HEADER_FLAG_TYPES_KEYS) / sizeof(int),
205 CPER_HEADER_FLAG_TYPES_KEYS,
206 CPER_HEADER_FLAG_TYPES_VALUES,
207 "Unknown");
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100208 json_object_object_add(header_ir, "flags", flags);
209
210 //Persistence information. Outside the scope of specification, so just a uint32 here.
211 json_object_object_add(header_ir, "persistenceInformation", json_object_new_uint64(header->PersistenceInfo));
212 return header_ir;
213}
214
215//Converts the given EFI section descriptor into JSON IR format.
216json_object* cper_section_descriptor_to_ir(EFI_ERROR_SECTION_DESCRIPTOR* section_descriptor)
217{
218 json_object* section_descriptor_ir = json_object_new_object();
219
220 //The offset of the section from the base of the record header, length.
221 json_object_object_add(section_descriptor_ir, "sectionOffset", json_object_new_int(section_descriptor->SectionOffset));
222 json_object_object_add(section_descriptor_ir, "sectionLength", json_object_new_int(section_descriptor->SectionLength));
223
224 //Revision.
225 json_object_object_add(section_descriptor_ir, "revision", revision_to_ir(section_descriptor->Revision));
226
227 //Validation bits.
228 json_object* validation_bits = json_object_new_object();
229 json_object_object_add(validation_bits, "fruID", json_object_new_boolean(section_descriptor->SecValidMask & 0b1));
230 json_object_object_add(validation_bits, "fruString", json_object_new_boolean((section_descriptor->SecValidMask & 0b10) >> 1));
231 json_object_object_add(section_descriptor_ir, "validationBits", validation_bits);
232
233 //Flag bits.
Lawrence Tang2800cd82022-07-05 16:08:20 +0100234 json_object* flags = bitfield_to_ir(section_descriptor->SectionFlags, 8, CPER_SECTION_DESCRIPTOR_FLAGS_BITFIELD_NAMES);
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100235 json_object_object_add(section_descriptor_ir, "flags", flags);
236
237 //Section type (GUID).
238 json_object* section_type = json_object_new_object();
239 char section_type_string[GUID_STRING_LENGTH];
240 guid_to_string(section_type_string, &section_descriptor->SectionType);
241 json_object_object_add(section_type, "data", json_object_new_string(section_type_string));
242
243 //Readable section type, if possible.
244 char* section_type_readable = "Unknown";
245 if (guid_equal(&section_descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid))
246 section_type_readable = "Processor Generic";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100247 else if (guid_equal(&section_descriptor->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100248 section_type_readable = "IA32/X64";
Lawrence Tangcc0f5f32022-07-06 17:17:26 +0100249 else if (guid_equal(&section_descriptor->SectionType, &gEfiIpfProcessorErrorSectionGuid))
250 section_type_readable = "IPF";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100251 else if (guid_equal(&section_descriptor->SectionType, &gEfiArmProcessorErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100252 section_type_readable = "ARM";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100253 else if (guid_equal(&section_descriptor->SectionType, &gEfiPlatformMemoryErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100254 section_type_readable = "Platform Memory";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100255 else if (guid_equal(&section_descriptor->SectionType, &gEfiPcieErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100256 section_type_readable = "PCIe";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100257 else if (guid_equal(&section_descriptor->SectionType, &gEfiFirmwareErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100258 section_type_readable = "Firmware Error Record Reference";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100259 else if (guid_equal(&section_descriptor->SectionType, &gEfiPciBusErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100260 section_type_readable = "PCI/PCI-X Bus";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100261 else if (guid_equal(&section_descriptor->SectionType, &gEfiPciDevErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100262 section_type_readable = "PCI Component/Device";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100263 else if (guid_equal(&section_descriptor->SectionType, &gEfiDMArGenericErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100264 section_type_readable = "DMAr Generic";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100265 else if (guid_equal(&section_descriptor->SectionType, &gEfiDirectedIoDMArErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100266 section_type_readable = "Intel VT for Directed I/O specific DMAr section";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100267 else if (guid_equal(&section_descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid))
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100268 section_type_readable = "IOMMU specific DMAr section";
Lawrence Tang864c0da2022-07-06 15:55:40 +0100269 else if (guid_equal(&section_descriptor->SectionType, &gEfiCcixPerLogErrorSectionGuid))
270 section_type_readable = "CCIX PER Log Error";
Lawrence Tangb98ec662022-07-06 16:50:21 +0100271 else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlProtocolErrorSectionGuid))
272 section_type_readable = "CXL Protocol Error";
Lawrence Tangd7e8ca32022-07-07 10:25:53 +0100273 else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlGeneralMediaErrorSectionGuid))
274 section_type_readable = "CXL General Media Component Error";
275 else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlDramEventErrorSectionGuid))
276 section_type_readable = "CXL DRAM Component Error";
277 else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlPhysicalSwitchErrorSectionGuid))
278 section_type_readable = "CXL Physical Switch Component Error";
279 else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlVirtualSwitchErrorSectionGuid))
280 section_type_readable = "CXL Virtual Switch Component Error";
281 else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlMldPortErrorSectionGuid))
282 section_type_readable = "CXL MLD Port Component Error";
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100283
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100284 json_object_object_add(section_type, "type", json_object_new_string(section_type_readable));
285 json_object_object_add(section_descriptor_ir, "sectionType", section_type);
286
287 //If validation bits indicate it exists, add FRU ID.
288 if (section_descriptor->SecValidMask & 0b1)
289 {
290 char fru_id_string[GUID_STRING_LENGTH];
291 guid_to_string(fru_id_string, &section_descriptor->FruId);
292 json_object_object_add(section_descriptor_ir, "fruID", json_object_new_string(fru_id_string));
293 }
294
295 //If validation bits indicate it exists, add FRU text.
296 if ((section_descriptor->SecValidMask & 0b10) >> 1)
297 json_object_object_add(section_descriptor_ir, "fruText", json_object_new_string(section_descriptor->FruString));
298
299 //Section severity.
300 json_object* section_severity = json_object_new_object();
301 json_object_object_add(section_severity, "code", json_object_new_int(section_descriptor->Severity));
302 json_object_object_add(section_severity, "name", json_object_new_string(severity_to_string(section_descriptor->Severity)));
303 json_object_object_add(section_descriptor_ir, "severity", section_severity);
304
305 return section_descriptor_ir;
306}
307
308
309//Converts the section described by a single given section descriptor.
310json_object* cper_section_to_ir(FILE* handle, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
311{
312 //Read section as described by the section descriptor.
313 fseek(handle, descriptor->SectionOffset, SEEK_SET);
Lawrence Tange18aaee2022-07-07 09:01:30 +0100314 void* section = malloc(descriptor->SectionLength);
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100315 if (fread(section, descriptor->SectionLength, 1, handle) != 1)
316 {
317 printf("Section read failed: Could not read %d bytes from global offset %d.",
318 descriptor->SectionLength,
319 descriptor->SectionOffset);
Lawrence Tange18aaee2022-07-07 09:01:30 +0100320 free(section);
321 return NULL;
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100322 }
323
Lawrence Tangdb1b7ce2022-07-06 15:40:26 +0100324 //Parse section to IR based on GUID.
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100325 json_object* result = NULL;
326 if (guid_equal(&descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid))
Lawrence Tang2800cd82022-07-05 16:08:20 +0100327 result = cper_section_generic_to_ir(section, descriptor);
328 else if (guid_equal(&descriptor->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid))
329 result = cper_section_ia32x64_to_ir(section, descriptor);
Lawrence Tangcc0f5f32022-07-06 17:17:26 +0100330 else if (guid_equal(&descriptor->SectionType, &gEfiIpfProcessorErrorSectionGuid))
331 result = cper_section_ipf_to_ir(section, descriptor);
Lawrence Tang2800cd82022-07-05 16:08:20 +0100332 else if (guid_equal(&descriptor->SectionType, &gEfiArmProcessorErrorSectionGuid))
333 result = cper_section_arm_to_ir(section, descriptor);
Lawrence Tanga0865e32022-07-06 11:59:52 +0100334 else if (guid_equal(&descriptor->SectionType, &gEfiPlatformMemoryErrorSectionGuid))
335 result = cper_section_platform_memory_to_ir(section, descriptor);
Lawrence Tang54da4412022-07-06 13:14:58 +0100336 else if (guid_equal(&descriptor->SectionType, &gEfiPlatformMemoryError2SectionGuid))
337 result = cper_section_platform_memory2_to_ir(section, descriptor);
Lawrence Tang4dbe3d72022-07-06 13:51:01 +0100338 else if (guid_equal(&descriptor->SectionType, &gEfiPcieErrorSectionGuid))
339 result = cper_section_pcie_to_ir(section, descriptor);
Lawrence Tangc60a2432022-07-06 14:58:33 +0100340 else if (guid_equal(&descriptor->SectionType, &gEfiFirmwareErrorSectionGuid))
341 result = cper_section_firmware_to_ir(section, descriptor);
Lawrence Tang214a1542022-07-06 14:11:28 +0100342 else if (guid_equal(&descriptor->SectionType, &gEfiPciBusErrorSectionGuid))
343 result = cper_section_pci_bus_to_ir(section, descriptor);
Lawrence Tanga416ec92022-07-06 14:34:40 +0100344 else if (guid_equal(&descriptor->SectionType, &gEfiPciDevErrorSectionGuid))
345 result = cper_section_pci_dev_to_ir(section, descriptor);
Lawrence Tang4795d4a2022-07-06 15:19:31 +0100346 else if (guid_equal(&descriptor->SectionType, &gEfiDMArGenericErrorSectionGuid))
347 result = cper_section_dmar_generic_to_ir(section, descriptor);
Lawrence Tangdb1b7ce2022-07-06 15:40:26 +0100348 else if (guid_equal(&descriptor->SectionType, &gEfiDirectedIoDMArErrorSectionGuid))
349 result = cper_section_dmar_vtd_to_ir(section, descriptor);
350 else if (guid_equal(&descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid))
351 result = cper_section_dmar_iommu_to_ir(section, descriptor);
Lawrence Tang864c0da2022-07-06 15:55:40 +0100352 else if (guid_equal(&descriptor->SectionType, &gEfiCcixPerLogErrorSectionGuid))
353 result = cper_section_ccix_per_to_ir(section, descriptor);
Lawrence Tangb98ec662022-07-06 16:50:21 +0100354 else if (guid_equal(&descriptor->SectionType, &gEfiCxlProtocolErrorSectionGuid))
355 result = cper_section_cxl_protocol_to_ir(section, descriptor);
Lawrence Tangd7e8ca32022-07-07 10:25:53 +0100356 else if (guid_equal(&descriptor->SectionType, &gEfiCxlGeneralMediaErrorSectionGuid)
357 || guid_equal(&descriptor->SectionType, &gEfiCxlDramEventErrorSectionGuid)
358 || guid_equal(&descriptor->SectionType, &gEfiCxlPhysicalSwitchErrorSectionGuid)
359 || guid_equal(&descriptor->SectionType, &gEfiCxlVirtualSwitchErrorSectionGuid)
360 || guid_equal(&descriptor->SectionType, &gEfiCxlMldPortErrorSectionGuid))
361 {
362 result = cper_section_cxl_component_to_ir(section, descriptor);
363 }
Lawrence Tangdb1b7ce2022-07-06 15:40:26 +0100364 else
365 {
366 //Failed read, unknown GUID.
Lawrence Tangd7e8ca32022-07-07 10:25:53 +0100367 //Output the data as formatted base64.
368 result = json_object_new_object();
369 char* encoded = b64_encode((unsigned char*)section, descriptor->SectionLength);
370 json_object_object_add(result, "data", json_object_new_string(encoded));
371 free(encoded);
Lawrence Tangdb1b7ce2022-07-06 15:40:26 +0100372 }
Lawrence Tang1b0b00e2022-07-05 10:33:10 +0100373
374 //Free section memory, return result.
375 free(section);
376 return result;
377}