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