1 /** 2 * Describes functions for converting generic DMAr CPER sections from binary and JSON format 3 * into an intermediate format. 4 * 5 * Author: Lawrence.Tang@arm.com 6 **/ 7 #include <stdio.h> 8 #include "json.h" 9 #include "../edk/Cper.h" 10 #include "../cper-utils.h" 11 #include "cper-section-dmar-generic.h" 12 13 //Converts a single generic DMAr CPER section into JSON IR. 14 json_object* cper_section_dmar_generic_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor) 15 { 16 EFI_DMAR_GENERIC_ERROR_DATA* firmware_error = (EFI_DMAR_GENERIC_ERROR_DATA*)section; 17 json_object* section_ir = json_object_new_object(); 18 19 //Requester ID, segment. 20 json_object_object_add(section_ir, "requesterID", json_object_new_int(firmware_error->RequesterId)); 21 json_object_object_add(section_ir, "segmentNumber", json_object_new_int(firmware_error->SegmentNumber)); 22 23 //Fault reason. 24 json_object* fault_reason = integer_to_readable_pair_with_desc(firmware_error->FaultReason, 11, 25 DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_KEYS, 26 DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_VALUES, 27 DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_DESCRIPTIONS, 28 "Unknown (Reserved)"); 29 json_object_object_add(section_ir, "faultReason", fault_reason); 30 31 //Access type. 32 json_object* access_type = integer_to_readable_pair(firmware_error->AccessType, 2, 33 DMAR_GENERIC_ERROR_ACCESS_TYPES_KEYS, 34 DMAR_GENERIC_ERROR_ACCESS_TYPES_VALUES, 35 "Unknown (Reserved)"); 36 json_object_object_add(section_ir, "accessType", access_type); 37 38 //Address type. 39 json_object* address_type = integer_to_readable_pair(firmware_error->AddressType, 2, 40 DMAR_GENERIC_ERROR_ADDRESS_TYPES_KEYS, 41 DMAR_GENERIC_ERROR_ADDRESS_TYPES_VALUES, 42 "Unknown (Reserved)"); 43 json_object_object_add(section_ir, "addressType", address_type); 44 45 //Architecture type. 46 json_object* arch_type = integer_to_readable_pair(firmware_error->ArchType, 2, 47 DMAR_GENERIC_ERROR_ARCH_TYPES_KEYS, 48 DMAR_GENERIC_ERROR_ARCH_TYPES_VALUES, 49 "Unknown (Reserved)"); 50 json_object_object_add(section_ir, "architectureType", arch_type); 51 52 //Device address. 53 json_object_object_add(section_ir, "deviceAddress", json_object_new_uint64(firmware_error->DeviceAddr)); 54 55 return section_ir; 56 }