11b0b00e3SLawrence Tang /** 22800cd8eSLawrence Tang * Describes high level functions for converting an entire CPER log, and functions for parsing 32800cd8eSLawrence Tang * CPER headers and section descriptions into an intermediate JSON format. 41b0b00e3SLawrence Tang * 51b0b00e3SLawrence Tang * Author: Lawrence.Tang@arm.com 61b0b00e3SLawrence Tang **/ 71b0b00e3SLawrence Tang 81b0b00e3SLawrence Tang #include <stdio.h> 91b0b00e3SLawrence Tang #include "json.h" 101b0b00e3SLawrence Tang #include "edk/Cper.h" 111b0b00e3SLawrence Tang #include "cper-parse.h" 121b0b00e3SLawrence Tang #include "cper-utils.h" 131b0b00e3SLawrence Tang #include "sections/cper-section-generic.h" 14794312c8SLawrence Tang #include "sections/cper-section-ia32x64.h" 152800cd8eSLawrence Tang #include "sections/cper-section-arm.h" 16a0865e38SLawrence Tang #include "sections/cper-section-memory.h" 174dbe3d72SLawrence Tang #include "sections/cper-section-pcie.h" 18214a1542SLawrence Tang #include "sections/cper-section-pci-bus.h" 19a416ec93SLawrence Tang #include "sections/cper-section-pci-dev.h" 20*c60a243eSLawrence Tang #include "sections/cper-section-firmware.h" 211b0b00e3SLawrence Tang 221b0b00e3SLawrence Tang //Private pre-definitions. 231b0b00e3SLawrence Tang json_object* cper_header_to_ir(EFI_COMMON_ERROR_RECORD_HEADER* header); 241b0b00e3SLawrence Tang json_object* cper_section_descriptor_to_ir(EFI_ERROR_SECTION_DESCRIPTOR* section_descriptor); 251b0b00e3SLawrence Tang json_object* cper_section_to_ir(FILE* handle, EFI_ERROR_SECTION_DESCRIPTOR* descriptor); 261b0b00e3SLawrence Tang 271b0b00e3SLawrence Tang //Reads a CPER log file at the given file location, and returns an intermediate 281b0b00e3SLawrence Tang //JSON representation of this CPER record. 291b0b00e3SLawrence Tang json_object* cper_to_ir(const char* filename) 301b0b00e3SLawrence Tang { 311b0b00e3SLawrence Tang //Get a handle for the log file. 321b0b00e3SLawrence Tang FILE* cper_file = fopen(filename, "r"); 331b0b00e3SLawrence Tang if (cper_file == NULL) { 341b0b00e3SLawrence Tang printf("Could not open CPER record, file handle returned null."); 351b0b00e3SLawrence Tang return NULL; 361b0b00e3SLawrence Tang } 371b0b00e3SLawrence Tang 381b0b00e3SLawrence Tang //Ensure this is really a CPER log. 391b0b00e3SLawrence Tang EFI_COMMON_ERROR_RECORD_HEADER header; 401b0b00e3SLawrence Tang fseek(cper_file, 0, SEEK_SET); 411b0b00e3SLawrence Tang if (fread(&header, sizeof(EFI_COMMON_ERROR_RECORD_HEADER), 1, cper_file) != 1) 421b0b00e3SLawrence Tang { 431b0b00e3SLawrence Tang printf("Invalid CPER file: Invalid length (log too short)."); 441b0b00e3SLawrence Tang return NULL; 451b0b00e3SLawrence Tang } 461b0b00e3SLawrence Tang 471b0b00e3SLawrence Tang //Check if the header contains the magic bytes ("CPER"). 481b0b00e3SLawrence Tang if (header.SignatureStart != EFI_ERROR_RECORD_SIGNATURE_START) { 491b0b00e3SLawrence Tang printf("Invalid CPER file: Invalid header (incorrect signature)."); 501b0b00e3SLawrence Tang return NULL; 511b0b00e3SLawrence Tang } 521b0b00e3SLawrence Tang 531b0b00e3SLawrence Tang // //Print struct contents (debug). 541b0b00e3SLawrence Tang // fpos_t file_pos; 551b0b00e3SLawrence Tang // fgetpos(cper_file, &file_pos); 561b0b00e3SLawrence Tang // printf("Stream is at position %d.\n", file_pos); 571b0b00e3SLawrence Tang // printf("SignatureStart: %s\n", (char*)&header.SignatureStart); 581b0b00e3SLawrence Tang // printf("Revision: %u\n", header.Revision); 591b0b00e3SLawrence Tang // printf("SectionCount: %u\n", header.SectionCount); 601b0b00e3SLawrence Tang // printf("Severity: %d\n", header.ErrorSeverity); 611b0b00e3SLawrence Tang // printf("RecordLength: %d\n", header.RecordLength); 621b0b00e3SLawrence Tang 631b0b00e3SLawrence Tang //Create the header JSON object from the read bytes. 641b0b00e3SLawrence Tang json_object* header_ir = cper_header_to_ir(&header); 651b0b00e3SLawrence Tang 661b0b00e3SLawrence Tang //Read the appropriate number of section descriptors & sections, and convert them into IR format. 671b0b00e3SLawrence Tang json_object* section_descriptors_ir = json_object_new_array(); 681b0b00e3SLawrence Tang json_object* sections_ir = json_object_new_array(); 691b0b00e3SLawrence Tang for (int i=0; i<header.SectionCount; i++) 701b0b00e3SLawrence Tang { 711b0b00e3SLawrence Tang //Create the section descriptor. 721b0b00e3SLawrence Tang EFI_ERROR_SECTION_DESCRIPTOR section_descriptor; 731b0b00e3SLawrence Tang if (fread(§ion_descriptor, sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1, cper_file) != 1) 741b0b00e3SLawrence Tang { 751b0b00e3SLawrence Tang printf("Invalid number of section headers: Header states %d sections, could not read section %d.", header.SectionCount, i+1); 761b0b00e3SLawrence Tang return NULL; 771b0b00e3SLawrence Tang } 781b0b00e3SLawrence Tang json_object_array_add(section_descriptors_ir, cper_section_descriptor_to_ir(§ion_descriptor)); 791b0b00e3SLawrence Tang 801b0b00e3SLawrence Tang //Read the section itself. 811b0b00e3SLawrence Tang json_object_array_add(sections_ir, cper_section_to_ir(cper_file, §ion_descriptor)); 821b0b00e3SLawrence Tang } 831b0b00e3SLawrence Tang 841b0b00e3SLawrence Tang //Add the header, section descriptors, and sections to a parent object. 851b0b00e3SLawrence Tang json_object* parent = json_object_new_object(); 861b0b00e3SLawrence Tang json_object_object_add(parent, "header", header_ir); 871b0b00e3SLawrence Tang json_object_object_add(parent, "sectionDescriptors", section_descriptors_ir); 882800cd8eSLawrence Tang json_object_object_add(parent, "sections", sections_ir); 891b0b00e3SLawrence Tang 901b0b00e3SLawrence Tang //... 911b0b00e3SLawrence Tang return parent; 921b0b00e3SLawrence Tang } 931b0b00e3SLawrence Tang 941b0b00e3SLawrence Tang //Converts a parsed CPER record header into intermediate JSON object format. 951b0b00e3SLawrence Tang json_object* cper_header_to_ir(EFI_COMMON_ERROR_RECORD_HEADER* header) 961b0b00e3SLawrence Tang { 971b0b00e3SLawrence Tang json_object* header_ir = json_object_new_object(); 981b0b00e3SLawrence Tang 991b0b00e3SLawrence Tang //Revision/version information. 1001b0b00e3SLawrence Tang json_object_object_add(header_ir, "revision", revision_to_ir(header->Revision)); 1011b0b00e3SLawrence Tang 1021b0b00e3SLawrence Tang //Section count. 1031b0b00e3SLawrence Tang json_object_object_add(header_ir, "sectionCount", json_object_new_int(header->SectionCount)); 1041b0b00e3SLawrence Tang 1051b0b00e3SLawrence Tang //Error severity (with interpreted string version). 1061b0b00e3SLawrence Tang json_object* error_severity = json_object_new_object(); 1071b0b00e3SLawrence Tang json_object_object_add(error_severity, "code", json_object_new_int(header->ErrorSeverity)); 1081b0b00e3SLawrence Tang json_object_object_add(error_severity, "name", json_object_new_string(severity_to_string(header->ErrorSeverity))); 1091b0b00e3SLawrence Tang json_object_object_add(header_ir, "severity", error_severity); 1101b0b00e3SLawrence Tang 1111b0b00e3SLawrence Tang //The validation bits for each section. 1122800cd8eSLawrence Tang json_object* validation_bits = bitfield_to_ir(header->ValidationBits, 3, CPER_HEADER_VALID_BITFIELD_NAMES); 1131b0b00e3SLawrence Tang json_object_object_add(header_ir, "validationBits", validation_bits); 1141b0b00e3SLawrence Tang 1151b0b00e3SLawrence Tang //Total length of the record (including headers) in bytes. 1161b0b00e3SLawrence Tang json_object_object_add(header_ir, "recordLength", json_object_new_int(header->RecordLength)); 1171b0b00e3SLawrence Tang 1181b0b00e3SLawrence Tang //If a timestamp exists according to validation bits, then add it. 1191b0b00e3SLawrence Tang if (header->ValidationBits & 0b10) 1201b0b00e3SLawrence Tang { 1211b0b00e3SLawrence Tang char timestamp_string[TIMESTAMP_LENGTH]; 1221b0b00e3SLawrence Tang sprintf(timestamp_string, "%02d%02d-%02d-%02dT%02d:%02d:%02d.000", 1231b0b00e3SLawrence Tang header->TimeStamp.Century, 1241b0b00e3SLawrence Tang header->TimeStamp.Year, 1251b0b00e3SLawrence Tang header->TimeStamp.Month, 1261b0b00e3SLawrence Tang header->TimeStamp.Day, 1271b0b00e3SLawrence Tang header->TimeStamp.Hours, 1281b0b00e3SLawrence Tang header->TimeStamp.Minutes, 1291b0b00e3SLawrence Tang header->TimeStamp.Seconds); 1301b0b00e3SLawrence Tang 1311b0b00e3SLawrence Tang json_object_object_add(header_ir, "timestamp", json_object_new_string(timestamp_string)); 1321b0b00e3SLawrence Tang json_object_object_add(header_ir, "timestampIsPrecise", json_object_new_boolean(header->TimeStamp.Flag)); 1331b0b00e3SLawrence Tang } 1341b0b00e3SLawrence Tang 1351b0b00e3SLawrence Tang //If a platform ID exists according to the validation bits, then add it. 1361b0b00e3SLawrence Tang if (header->ValidationBits & 0b1) 1371b0b00e3SLawrence Tang { 1381b0b00e3SLawrence Tang char platform_string[GUID_STRING_LENGTH]; 1391b0b00e3SLawrence Tang guid_to_string(platform_string, &header->PlatformID); 1401b0b00e3SLawrence Tang json_object_object_add(header_ir, "platformID", json_object_new_string(platform_string)); 1411b0b00e3SLawrence Tang } 1421b0b00e3SLawrence Tang 1431b0b00e3SLawrence Tang //If a partition ID exists according to the validation bits, then add it. 1441b0b00e3SLawrence Tang if (header->ValidationBits & 0b100) 1451b0b00e3SLawrence Tang { 1461b0b00e3SLawrence Tang char partition_string[GUID_STRING_LENGTH]; 1471b0b00e3SLawrence Tang guid_to_string(partition_string, &header->PartitionID); 1481b0b00e3SLawrence Tang json_object_object_add(header_ir, "partitionID", json_object_new_string(partition_string)); 1491b0b00e3SLawrence Tang } 1501b0b00e3SLawrence Tang 1511b0b00e3SLawrence Tang //Creator ID of the header. 1521b0b00e3SLawrence Tang char creator_string[GUID_STRING_LENGTH]; 1531b0b00e3SLawrence Tang guid_to_string(creator_string, &header->CreatorID); 1541b0b00e3SLawrence Tang json_object_object_add(header_ir, "creatorID", json_object_new_string(creator_string)); 1551b0b00e3SLawrence Tang 1561b0b00e3SLawrence Tang //Notification type for the header. Some defined types are available. 1571b0b00e3SLawrence Tang json_object* notification_type = json_object_new_object(); 1581b0b00e3SLawrence Tang char notification_type_string[GUID_STRING_LENGTH]; 1591b0b00e3SLawrence Tang guid_to_string(notification_type_string, &header->NotificationType); 1601b0b00e3SLawrence Tang json_object_object_add(notification_type, "guid", json_object_new_string(notification_type_string)); 1611b0b00e3SLawrence Tang 1621b0b00e3SLawrence Tang //Add the human readable notification type if possible. 1631b0b00e3SLawrence Tang char* notification_type_readable = "Unknown"; 1641b0b00e3SLawrence Tang if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCmcGuid)) 1651b0b00e3SLawrence Tang notification_type_readable = "CMC"; 166794312c8SLawrence Tang else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCpeGuid)) 1671b0b00e3SLawrence Tang notification_type_readable = "CPE"; 168794312c8SLawrence Tang else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeMceGuid)) 1691b0b00e3SLawrence Tang notification_type_readable = "MCE"; 170794312c8SLawrence Tang else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypePcieGuid)) 1711b0b00e3SLawrence Tang notification_type_readable = "PCIe"; 172794312c8SLawrence Tang else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeInitGuid)) 1731b0b00e3SLawrence Tang notification_type_readable = "INIT"; 174794312c8SLawrence Tang else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeNmiGuid)) 1751b0b00e3SLawrence Tang notification_type_readable = "NMI"; 176794312c8SLawrence Tang else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeBootGuid)) 1771b0b00e3SLawrence Tang notification_type_readable = "Boot"; 178794312c8SLawrence Tang else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeDmarGuid)) 1791b0b00e3SLawrence Tang notification_type_readable = "DMAr"; 180794312c8SLawrence Tang else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeSeaGuid)) 1811b0b00e3SLawrence Tang notification_type_readable = "SEA"; 182794312c8SLawrence Tang else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeSeiGuid)) 1831b0b00e3SLawrence Tang notification_type_readable = "SEI"; 184794312c8SLawrence Tang else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypePeiGuid)) 1851b0b00e3SLawrence Tang notification_type_readable = "PEI"; 186794312c8SLawrence Tang else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCxlGuid)) 1871b0b00e3SLawrence Tang notification_type_readable = "CXL Component"; 1881b0b00e3SLawrence Tang json_object_object_add(notification_type, "type", json_object_new_string(notification_type_readable)); 1891b0b00e3SLawrence Tang json_object_object_add(header_ir, "notificationType", notification_type); 1901b0b00e3SLawrence Tang 1911b0b00e3SLawrence Tang //The record ID for this record, unique on a given system. 1921b0b00e3SLawrence Tang json_object_object_add(header_ir, "recordID", json_object_new_uint64(header->RecordID)); 1931b0b00e3SLawrence Tang 1941b0b00e3SLawrence Tang //Flag for the record, and a human readable form. 1953c43f743SLawrence Tang json_object* flags = integer_to_readable_pair(header->Flags, 1963c43f743SLawrence Tang sizeof(CPER_HEADER_FLAG_TYPES_KEYS) / sizeof(int), 1973c43f743SLawrence Tang CPER_HEADER_FLAG_TYPES_KEYS, 1983c43f743SLawrence Tang CPER_HEADER_FLAG_TYPES_VALUES, 1993c43f743SLawrence Tang "Unknown"); 2001b0b00e3SLawrence Tang json_object_object_add(header_ir, "flags", flags); 2011b0b00e3SLawrence Tang 2021b0b00e3SLawrence Tang //Persistence information. Outside the scope of specification, so just a uint32 here. 2031b0b00e3SLawrence Tang json_object_object_add(header_ir, "persistenceInformation", json_object_new_uint64(header->PersistenceInfo)); 2041b0b00e3SLawrence Tang return header_ir; 2051b0b00e3SLawrence Tang } 2061b0b00e3SLawrence Tang 2071b0b00e3SLawrence Tang //Converts the given EFI section descriptor into JSON IR format. 2081b0b00e3SLawrence Tang json_object* cper_section_descriptor_to_ir(EFI_ERROR_SECTION_DESCRIPTOR* section_descriptor) 2091b0b00e3SLawrence Tang { 2101b0b00e3SLawrence Tang json_object* section_descriptor_ir = json_object_new_object(); 2111b0b00e3SLawrence Tang 2121b0b00e3SLawrence Tang //The offset of the section from the base of the record header, length. 2131b0b00e3SLawrence Tang json_object_object_add(section_descriptor_ir, "sectionOffset", json_object_new_int(section_descriptor->SectionOffset)); 2141b0b00e3SLawrence Tang json_object_object_add(section_descriptor_ir, "sectionLength", json_object_new_int(section_descriptor->SectionLength)); 2151b0b00e3SLawrence Tang 2161b0b00e3SLawrence Tang //Revision. 2171b0b00e3SLawrence Tang json_object_object_add(section_descriptor_ir, "revision", revision_to_ir(section_descriptor->Revision)); 2181b0b00e3SLawrence Tang 2191b0b00e3SLawrence Tang //Validation bits. 2201b0b00e3SLawrence Tang json_object* validation_bits = json_object_new_object(); 2211b0b00e3SLawrence Tang json_object_object_add(validation_bits, "fruID", json_object_new_boolean(section_descriptor->SecValidMask & 0b1)); 2221b0b00e3SLawrence Tang json_object_object_add(validation_bits, "fruString", json_object_new_boolean((section_descriptor->SecValidMask & 0b10) >> 1)); 2231b0b00e3SLawrence Tang json_object_object_add(section_descriptor_ir, "validationBits", validation_bits); 2241b0b00e3SLawrence Tang 2251b0b00e3SLawrence Tang //Flag bits. 2262800cd8eSLawrence Tang json_object* flags = bitfield_to_ir(section_descriptor->SectionFlags, 8, CPER_SECTION_DESCRIPTOR_FLAGS_BITFIELD_NAMES); 2271b0b00e3SLawrence Tang json_object_object_add(section_descriptor_ir, "flags", flags); 2281b0b00e3SLawrence Tang 2291b0b00e3SLawrence Tang //Section type (GUID). 2301b0b00e3SLawrence Tang json_object* section_type = json_object_new_object(); 2311b0b00e3SLawrence Tang char section_type_string[GUID_STRING_LENGTH]; 2321b0b00e3SLawrence Tang guid_to_string(section_type_string, §ion_descriptor->SectionType); 2331b0b00e3SLawrence Tang json_object_object_add(section_type, "data", json_object_new_string(section_type_string)); 2341b0b00e3SLawrence Tang 2351b0b00e3SLawrence Tang //Readable section type, if possible. 2361b0b00e3SLawrence Tang char* section_type_readable = "Unknown"; 2371b0b00e3SLawrence Tang if (guid_equal(§ion_descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid)) 2381b0b00e3SLawrence Tang section_type_readable = "Processor Generic"; 2391b0b00e3SLawrence Tang if (guid_equal(§ion_descriptor->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid)) 2401b0b00e3SLawrence Tang section_type_readable = "IA32/X64"; 2411b0b00e3SLawrence Tang //todo: Why does IPF have an overly long GUID? 2421b0b00e3SLawrence Tang // if (guid_equal(§ion_descriptor->SectionType, &gEfiIpfProcessorErrorSectionGuid)) 2431b0b00e3SLawrence Tang // section_type_readable = "IPF"; 2441b0b00e3SLawrence Tang if (guid_equal(§ion_descriptor->SectionType, &gEfiArmProcessorErrorSectionGuid)) 2451b0b00e3SLawrence Tang section_type_readable = "ARM"; 2461b0b00e3SLawrence Tang if (guid_equal(§ion_descriptor->SectionType, &gEfiPlatformMemoryErrorSectionGuid)) 2471b0b00e3SLawrence Tang section_type_readable = "Platform Memory"; 2481b0b00e3SLawrence Tang if (guid_equal(§ion_descriptor->SectionType, &gEfiPcieErrorSectionGuid)) 2491b0b00e3SLawrence Tang section_type_readable = "PCIe"; 2501b0b00e3SLawrence Tang if (guid_equal(§ion_descriptor->SectionType, &gEfiFirmwareErrorSectionGuid)) 2511b0b00e3SLawrence Tang section_type_readable = "Firmware Error Record Reference"; 2521b0b00e3SLawrence Tang if (guid_equal(§ion_descriptor->SectionType, &gEfiPciBusErrorSectionGuid)) 2531b0b00e3SLawrence Tang section_type_readable = "PCI/PCI-X Bus"; 2541b0b00e3SLawrence Tang if (guid_equal(§ion_descriptor->SectionType, &gEfiPciDevErrorSectionGuid)) 2551b0b00e3SLawrence Tang section_type_readable = "PCI Component/Device"; 2561b0b00e3SLawrence Tang if (guid_equal(§ion_descriptor->SectionType, &gEfiDMArGenericErrorSectionGuid)) 2571b0b00e3SLawrence Tang section_type_readable = "DMAr Generic"; 2581b0b00e3SLawrence Tang if (guid_equal(§ion_descriptor->SectionType, &gEfiDirectedIoDMArErrorSectionGuid)) 2591b0b00e3SLawrence Tang section_type_readable = "Intel VT for Directed I/O specific DMAr section"; 2601b0b00e3SLawrence Tang if (guid_equal(§ion_descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid)) 2611b0b00e3SLawrence Tang section_type_readable = "IOMMU specific DMAr section"; 2621b0b00e3SLawrence Tang 2631b0b00e3SLawrence Tang //todo: How do you determine if this is a CXL component event? 2641b0b00e3SLawrence Tang // if (guid_equal(§ion_descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid)) 2651b0b00e3SLawrence Tang // section_type_readable = "CXL Component Event"; 2661b0b00e3SLawrence Tang 2671b0b00e3SLawrence Tang json_object_object_add(section_type, "type", json_object_new_string(section_type_readable)); 2681b0b00e3SLawrence Tang json_object_object_add(section_descriptor_ir, "sectionType", section_type); 2691b0b00e3SLawrence Tang 2701b0b00e3SLawrence Tang //If validation bits indicate it exists, add FRU ID. 2711b0b00e3SLawrence Tang if (section_descriptor->SecValidMask & 0b1) 2721b0b00e3SLawrence Tang { 2731b0b00e3SLawrence Tang char fru_id_string[GUID_STRING_LENGTH]; 2741b0b00e3SLawrence Tang guid_to_string(fru_id_string, §ion_descriptor->FruId); 2751b0b00e3SLawrence Tang json_object_object_add(section_descriptor_ir, "fruID", json_object_new_string(fru_id_string)); 2761b0b00e3SLawrence Tang } 2771b0b00e3SLawrence Tang 2781b0b00e3SLawrence Tang //If validation bits indicate it exists, add FRU text. 2791b0b00e3SLawrence Tang if ((section_descriptor->SecValidMask & 0b10) >> 1) 2801b0b00e3SLawrence Tang json_object_object_add(section_descriptor_ir, "fruText", json_object_new_string(section_descriptor->FruString)); 2811b0b00e3SLawrence Tang 2821b0b00e3SLawrence Tang //Section severity. 2831b0b00e3SLawrence Tang json_object* section_severity = json_object_new_object(); 2841b0b00e3SLawrence Tang json_object_object_add(section_severity, "code", json_object_new_int(section_descriptor->Severity)); 2851b0b00e3SLawrence Tang json_object_object_add(section_severity, "name", json_object_new_string(severity_to_string(section_descriptor->Severity))); 2861b0b00e3SLawrence Tang json_object_object_add(section_descriptor_ir, "severity", section_severity); 2871b0b00e3SLawrence Tang 2881b0b00e3SLawrence Tang return section_descriptor_ir; 2891b0b00e3SLawrence Tang } 2901b0b00e3SLawrence Tang 2911b0b00e3SLawrence Tang 2921b0b00e3SLawrence Tang //Converts the section described by a single given section descriptor. 2931b0b00e3SLawrence Tang json_object* cper_section_to_ir(FILE* handle, EFI_ERROR_SECTION_DESCRIPTOR* descriptor) 2941b0b00e3SLawrence Tang { 2951b0b00e3SLawrence Tang //Read section as described by the section descriptor. 2961b0b00e3SLawrence Tang fseek(handle, descriptor->SectionOffset, SEEK_SET); 2972800cd8eSLawrence Tang void* section = calloc(1, descriptor->SectionLength); 2981b0b00e3SLawrence Tang if (fread(section, descriptor->SectionLength, 1, handle) != 1) 2991b0b00e3SLawrence Tang { 3001b0b00e3SLawrence Tang printf("Section read failed: Could not read %d bytes from global offset %d.", 3011b0b00e3SLawrence Tang descriptor->SectionLength, 3021b0b00e3SLawrence Tang descriptor->SectionOffset); 3031b0b00e3SLawrence Tang } 3041b0b00e3SLawrence Tang 3051b0b00e3SLawrence Tang json_object* result = NULL; 3061b0b00e3SLawrence Tang if (guid_equal(&descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid)) 3072800cd8eSLawrence Tang result = cper_section_generic_to_ir(section, descriptor); 3082800cd8eSLawrence Tang else if (guid_equal(&descriptor->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid)) 3092800cd8eSLawrence Tang result = cper_section_ia32x64_to_ir(section, descriptor); 3101b0b00e3SLawrence Tang // //todo: Why does IPF have an overly long GUID? 3111b0b00e3SLawrence Tang // // if (guid_equal(&descriptor->SectionType, &gEfiIpfProcessorErrorSectionGuid)) 3122800cd8eSLawrence Tang else if (guid_equal(&descriptor->SectionType, &gEfiArmProcessorErrorSectionGuid)) 3132800cd8eSLawrence Tang result = cper_section_arm_to_ir(section, descriptor); 314a0865e38SLawrence Tang else if (guid_equal(&descriptor->SectionType, &gEfiPlatformMemoryErrorSectionGuid)) 315a0865e38SLawrence Tang result = cper_section_platform_memory_to_ir(section, descriptor); 31654da4414SLawrence Tang else if (guid_equal(&descriptor->SectionType, &gEfiPlatformMemoryError2SectionGuid)) 31754da4414SLawrence Tang result = cper_section_platform_memory2_to_ir(section, descriptor); 3184dbe3d72SLawrence Tang else if (guid_equal(&descriptor->SectionType, &gEfiPcieErrorSectionGuid)) 3194dbe3d72SLawrence Tang result = cper_section_pcie_to_ir(section, descriptor); 320*c60a243eSLawrence Tang else if (guid_equal(&descriptor->SectionType, &gEfiFirmwareErrorSectionGuid)) 321*c60a243eSLawrence Tang result = cper_section_firmware_to_ir(section, descriptor); 322214a1542SLawrence Tang else if (guid_equal(&descriptor->SectionType, &gEfiPciBusErrorSectionGuid)) 323214a1542SLawrence Tang result = cper_section_pci_bus_to_ir(section, descriptor); 324a416ec93SLawrence Tang else if (guid_equal(&descriptor->SectionType, &gEfiPciDevErrorSectionGuid)) 325a416ec93SLawrence Tang result = cper_section_pci_dev_to_ir(section, descriptor); 3261b0b00e3SLawrence Tang // if (guid_equal(&descriptor->SectionType, &gEfiDMArGenericErrorSectionGuid)) 3272800cd8eSLawrence Tang // result = cper_section_dmar_generic_to_ir(section); 3281b0b00e3SLawrence Tang // if (guid_equal(&descriptor->SectionType, &gEfiDirectedIoDMArErrorSectionGuid)) 3292800cd8eSLawrence Tang // result = cper_section_intel_io_dma_to_ir(section); 3301b0b00e3SLawrence Tang // if (guid_equal(&descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid)) 3312800cd8eSLawrence Tang // result = cper_section_iommu_dma_to_ir(section); 3321b0b00e3SLawrence Tang 3331b0b00e3SLawrence Tang //Free section memory, return result. 3341b0b00e3SLawrence Tang free(section); 3351b0b00e3SLawrence Tang return result; 3361b0b00e3SLawrence Tang }