1 /** 2 * Describes functions for converting ARM CPER sections from binary and JSON format 3 * into an intermediate format. 4 * 5 * Author: Lawrence.Tang@arm.com 6 **/ 7 8 #include <stdio.h> 9 #include "json.h" 10 #include "../edk/Cper.h" 11 #include "../cper-utils.h" 12 #include "cper-section-arm.h" 13 14 //Private pre-definitions. 15 json_object* cper_arm_error_info_to_ir(EFI_ARM_PROCESSOR_ERROR_INFORMATION_ENTRY* error_info, void** cur_pos); 16 json_object* cper_arm_cache_error_to_ir(EFI_ARM_PROCESSOR_CACHE_ERROR_STRUCTURE* cache_error); 17 json_object* cper_arm_tlb_error_to_ir(EFI_ARM_PROCESSOR_TLB_ERROR_STRUCTURE* tlb_error); 18 json_object* cper_arm_bus_error_to_ir(EFI_ARM_PROCESSOR_BUS_ERROR_STRUCTURE* bus_error); 19 20 //Converts the given processor-generic CPER section into JSON IR. 21 json_object* cper_section_arm_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor) 22 { 23 EFI_ARM_PROCESSOR_ERROR_RECORD* record = (EFI_ARM_PROCESSOR_ERROR_RECORD*)section; 24 json_object* section_ir = json_object_new_object(); 25 26 //Validation bits. 27 json_object* validation = bitfield_to_ir(record->ValidFields, 4, ARM_PROCESSOR_ERROR_VALID_BITFIELD_NAMES); 28 json_object_object_add(section_ir, "validationBits", validation); 29 30 //Number of error info and context info structures, and length. 31 json_object_object_add(section_ir, "errorInfoNum", json_object_new_int(record->ErrInfoNum)); 32 json_object_object_add(section_ir, "contextInfoNum", json_object_new_int(record->ContextInfoNum)); 33 json_object_object_add(section_ir, "sectionLength", json_object_new_int(record->SectionLength)); 34 35 //Error affinity. 36 json_object* error_affinity = json_object_new_object(); 37 json_object_object_add(error_affinity, "value", json_object_new_int(record->ErrorAffinityLevel)); 38 json_object_object_add(error_affinity, "type", 39 json_object_new_string(record->ErrorAffinityLevel < 4 ? "Vendor Defined" : "Reserved")); 40 json_object_object_add(section_ir, "errorAffinity", error_affinity); 41 42 //Processor ID (MPIDR_EL1) and chip ID (MIDR_EL1). 43 json_object_object_add(section_ir, "mpidrEl1", json_object_new_uint64(record->MPIDR_EL1)); 44 json_object_object_add(section_ir, "midrEl1", json_object_new_uint64(record->MIDR_EL1)); 45 46 //Whether the processor is running, and the state of it if so. 47 json_object_object_add(section_ir, "running", json_object_new_boolean(record->RunningState)); 48 if (record->RunningState >> 31) 49 { 50 //Bit 32 of running state is on, so PSCI state information is included. 51 //todo: Look at how to make this human readable from the ARM PSCI document. 52 json_object_object_add(section_ir, "psciState", json_object_new_int(record->PsciState)); 53 } 54 55 //Processor error structures. 56 json_object* error_info_array = json_object_new_array(); 57 EFI_ARM_PROCESSOR_ERROR_INFORMATION_ENTRY* cur_error = (EFI_ARM_PROCESSOR_ERROR_INFORMATION_ENTRY*)(record + 1); 58 for (int i=0; i<record->ErrInfoNum; i++) 59 { 60 json_object_array_add(error_info_array, cper_arm_error_info_to_ir(cur_error, (void*)&cur_error)); 61 //Dynamically sized structure, so pointer is controlled within the above function. 62 } 63 return section_ir; 64 } 65 66 //Converts a single ARM Process Error Information structure into JSON IR. 67 json_object* cper_arm_error_info_to_ir(EFI_ARM_PROCESSOR_ERROR_INFORMATION_ENTRY* error_info, void** cur_pos) 68 { 69 json_object* error_info_ir = json_object_new_object(); 70 71 //Version, length. 72 json_object_object_add(error_info_ir, "version", json_object_new_int(error_info->Version)); 73 json_object_object_add(error_info_ir, "version", json_object_new_int(error_info->Length)); 74 75 //Validation bitfield. 76 json_object* validation = bitfield_to_ir(error_info->ValidationBits, 5, ARM_PROCESSOR_ERROR_INFO_ENTRY_VALID_BITFIELD_NAMES); 77 json_object_object_add(error_info_ir, "validationBits", validation); 78 79 //The type of error information in this log. 80 //todo: The UEFI spec is ambiguous, what are the values for these?? 81 json_object* error_type = integer_to_readable_pair(error_info->Type, 4, 82 ARM_PROCESSOR_ERROR_INFO_ENTRY_INFO_TYPES_KEYS, 83 ARM_PROCESSOR_ERROR_INFO_ENTRY_INFO_TYPES_VALUES, 84 "Unknown (Reserved)"); 85 json_object_object_add(error_info_ir, "errorType", error_type); 86 87 //Multiple error count. 88 json_object* multiple_error = json_object_object_create(); 89 json_object_object_add(multiple_error, "value", json_object_new_int(error_info->MultipleError)); 90 json_object_object_add(multiple_error, "type", 91 json_object_new_string(error_info->MultipleError < 1 ? "Single Error" : "Multiple Errors")); 92 json_object_object_add(error_info_ir, "multipleError", multiple_error); 93 94 //Flags. 95 json_object* flags = bitfield_to_ir(error_info->Flags, 4, ARM_PROCESSOR_ERROR_INFO_ENTRY_FLAGS_NAMES); 96 json_object_object_add(error_info_ir, "flags", flags); 97 98 //Error information, split by type. 99 json_object* error_subinfo = NULL; 100 switch (error_info->Type) 101 { 102 case 0: //Cache 103 error_subinfo = cper_arm_cache_error_to_ir((EFI_ARM_PROCESSOR_CACHE_ERROR_STRUCTURE*)error_info->ErrorInformation); 104 break; 105 case 1: //TLB 106 error_subinfo = cper_arm_tlb_error_to_ir((EFI_ARM_PROCESSOR_TLB_ERROR_STRUCTURE*)error_info->ErrorInformation); 107 break; 108 case 2: //Bus 109 error_subinfo = cper_arm_bus_error_to_ir((EFI_ARM_PROCESSOR_BUS_ERROR_STRUCTURE*)error_info->ErrorInformation); 110 break; 111 } 112 json_object_object_add(error_info_ir, "errorInformation", error_subinfo); 113 114 return error_info_ir; 115 } 116 117 //Converts a single ARM cache error information structure into JSON IR format. 118 json_object* cper_arm_cache_error_to_ir(EFI_ARM_PROCESSOR_CACHE_ERROR_STRUCTURE* cache_error) 119 { 120 //todo 121 } 122 123 //Converts a single ARM TLB error information structure into JSON IR format. 124 json_object* cper_arm_tlb_error_to_ir(EFI_ARM_PROCESSOR_TLB_ERROR_STRUCTURE* tlb_error) 125 { 126 //todo 127 } 128 129 //Converts a single ARM bus error information structure into JSON IR format. 130 json_object* cper_arm_bus_error_to_ir(EFI_ARM_PROCESSOR_BUS_ERROR_STRUCTURE* bus_error) 131 { 132 //todo 133 }