12800cd8eSLawrence Tang /** 22800cd8eSLawrence Tang * Describes functions for converting ARM CPER sections from binary and JSON format 32800cd8eSLawrence Tang * into an intermediate format. 42800cd8eSLawrence Tang * 52800cd8eSLawrence Tang * Author: Lawrence.Tang@arm.com 62800cd8eSLawrence Tang **/ 72800cd8eSLawrence Tang 82800cd8eSLawrence Tang #include <stdio.h> 92800cd8eSLawrence Tang #include "json.h" 102800cd8eSLawrence Tang #include "../edk/Cper.h" 112800cd8eSLawrence Tang #include "../cper-utils.h" 122800cd8eSLawrence Tang #include "cper-section-arm.h" 132800cd8eSLawrence Tang 14*3d0e4f24SLawrence Tang //Private pre-definitions. 15*3d0e4f24SLawrence Tang json_object* cper_arm_error_info_to_ir(EFI_ARM_PROCESSOR_ERROR_INFORMATION_ENTRY* error_info, void** cur_pos); 16*3d0e4f24SLawrence Tang json_object* cper_arm_cache_error_to_ir(EFI_ARM_PROCESSOR_CACHE_ERROR_STRUCTURE* cache_error); 17*3d0e4f24SLawrence Tang json_object* cper_arm_tlb_error_to_ir(EFI_ARM_PROCESSOR_TLB_ERROR_STRUCTURE* tlb_error); 18*3d0e4f24SLawrence Tang json_object* cper_arm_bus_error_to_ir(EFI_ARM_PROCESSOR_BUS_ERROR_STRUCTURE* bus_error); 19*3d0e4f24SLawrence Tang 202800cd8eSLawrence Tang //Converts the given processor-generic CPER section into JSON IR. 212800cd8eSLawrence Tang json_object* cper_section_arm_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor) 222800cd8eSLawrence Tang { 232800cd8eSLawrence Tang EFI_ARM_PROCESSOR_ERROR_RECORD* record = (EFI_ARM_PROCESSOR_ERROR_RECORD*)section; 242800cd8eSLawrence Tang json_object* section_ir = json_object_new_object(); 252800cd8eSLawrence Tang 262800cd8eSLawrence Tang //Validation bits. 272800cd8eSLawrence Tang json_object* validation = bitfield_to_ir(record->ValidFields, 4, ARM_PROCESSOR_ERROR_VALID_BITFIELD_NAMES); 282800cd8eSLawrence Tang json_object_object_add(section_ir, "validationBits", validation); 292800cd8eSLawrence Tang 302800cd8eSLawrence Tang //Number of error info and context info structures, and length. 312800cd8eSLawrence Tang json_object_object_add(section_ir, "errorInfoNum", json_object_new_int(record->ErrInfoNum)); 322800cd8eSLawrence Tang json_object_object_add(section_ir, "contextInfoNum", json_object_new_int(record->ContextInfoNum)); 332800cd8eSLawrence Tang json_object_object_add(section_ir, "sectionLength", json_object_new_int(record->SectionLength)); 342800cd8eSLawrence Tang 352800cd8eSLawrence Tang //Error affinity. 362800cd8eSLawrence Tang json_object* error_affinity = json_object_new_object(); 372800cd8eSLawrence Tang json_object_object_add(error_affinity, "value", json_object_new_int(record->ErrorAffinityLevel)); 382800cd8eSLawrence Tang json_object_object_add(error_affinity, "type", 392800cd8eSLawrence Tang json_object_new_string(record->ErrorAffinityLevel < 4 ? "Vendor Defined" : "Reserved")); 402800cd8eSLawrence Tang json_object_object_add(section_ir, "errorAffinity", error_affinity); 412800cd8eSLawrence Tang 422800cd8eSLawrence Tang //Processor ID (MPIDR_EL1) and chip ID (MIDR_EL1). 432800cd8eSLawrence Tang json_object_object_add(section_ir, "mpidrEl1", json_object_new_uint64(record->MPIDR_EL1)); 442800cd8eSLawrence Tang json_object_object_add(section_ir, "midrEl1", json_object_new_uint64(record->MIDR_EL1)); 452800cd8eSLawrence Tang 462800cd8eSLawrence Tang //Whether the processor is running, and the state of it if so. 472800cd8eSLawrence Tang json_object_object_add(section_ir, "running", json_object_new_boolean(record->RunningState)); 48*3d0e4f24SLawrence Tang if (record->RunningState >> 31) 492800cd8eSLawrence Tang { 50*3d0e4f24SLawrence Tang //Bit 32 of running state is on, so PSCI state information is included. 51*3d0e4f24SLawrence Tang //todo: Look at how to make this human readable from the ARM PSCI document. 52*3d0e4f24SLawrence Tang json_object_object_add(section_ir, "psciState", json_object_new_int(record->PsciState)); 532800cd8eSLawrence Tang } 542800cd8eSLawrence Tang 55*3d0e4f24SLawrence Tang //Processor error structures. 56*3d0e4f24SLawrence Tang json_object* error_info_array = json_object_new_array(); 57*3d0e4f24SLawrence Tang EFI_ARM_PROCESSOR_ERROR_INFORMATION_ENTRY* cur_error = (EFI_ARM_PROCESSOR_ERROR_INFORMATION_ENTRY*)(record + 1); 58*3d0e4f24SLawrence Tang for (int i=0; i<record->ErrInfoNum; i++) 59*3d0e4f24SLawrence Tang { 60*3d0e4f24SLawrence Tang json_object_array_add(error_info_array, cper_arm_error_info_to_ir(cur_error, (void*)&cur_error)); 61*3d0e4f24SLawrence Tang //Dynamically sized structure, so pointer is controlled within the above function. 62*3d0e4f24SLawrence Tang } 632800cd8eSLawrence Tang return section_ir; 642800cd8eSLawrence Tang } 65*3d0e4f24SLawrence Tang 66*3d0e4f24SLawrence Tang //Converts a single ARM Process Error Information structure into JSON IR. 67*3d0e4f24SLawrence Tang json_object* cper_arm_error_info_to_ir(EFI_ARM_PROCESSOR_ERROR_INFORMATION_ENTRY* error_info, void** cur_pos) 68*3d0e4f24SLawrence Tang { 69*3d0e4f24SLawrence Tang json_object* error_info_ir = json_object_new_object(); 70*3d0e4f24SLawrence Tang 71*3d0e4f24SLawrence Tang //Version, length. 72*3d0e4f24SLawrence Tang json_object_object_add(error_info_ir, "version", json_object_new_int(error_info->Version)); 73*3d0e4f24SLawrence Tang json_object_object_add(error_info_ir, "version", json_object_new_int(error_info->Length)); 74*3d0e4f24SLawrence Tang 75*3d0e4f24SLawrence Tang //Validation bitfield. 76*3d0e4f24SLawrence Tang json_object* validation = bitfield_to_ir(error_info->ValidationBits, 5, ARM_PROCESSOR_ERROR_INFO_ENTRY_VALID_BITFIELD_NAMES); 77*3d0e4f24SLawrence Tang json_object_object_add(error_info_ir, "validationBits", validation); 78*3d0e4f24SLawrence Tang 79*3d0e4f24SLawrence Tang //The type of error information in this log. 80*3d0e4f24SLawrence Tang //todo: The UEFI spec is ambiguous, what are the values for these?? 81*3d0e4f24SLawrence Tang json_object* error_type = integer_to_readable_pair(error_info->Type, 4, 82*3d0e4f24SLawrence Tang ARM_PROCESSOR_ERROR_INFO_ENTRY_INFO_TYPES_KEYS, 83*3d0e4f24SLawrence Tang ARM_PROCESSOR_ERROR_INFO_ENTRY_INFO_TYPES_VALUES, 84*3d0e4f24SLawrence Tang "Unknown (Reserved)"); 85*3d0e4f24SLawrence Tang json_object_object_add(error_info_ir, "errorType", error_type); 86*3d0e4f24SLawrence Tang 87*3d0e4f24SLawrence Tang //Multiple error count. 88*3d0e4f24SLawrence Tang json_object* multiple_error = json_object_object_create(); 89*3d0e4f24SLawrence Tang json_object_object_add(multiple_error, "value", json_object_new_int(error_info->MultipleError)); 90*3d0e4f24SLawrence Tang json_object_object_add(multiple_error, "type", 91*3d0e4f24SLawrence Tang json_object_new_string(error_info->MultipleError < 1 ? "Single Error" : "Multiple Errors")); 92*3d0e4f24SLawrence Tang json_object_object_add(error_info_ir, "multipleError", multiple_error); 93*3d0e4f24SLawrence Tang 94*3d0e4f24SLawrence Tang //Flags. 95*3d0e4f24SLawrence Tang json_object* flags = bitfield_to_ir(error_info->Flags, 4, ARM_PROCESSOR_ERROR_INFO_ENTRY_FLAGS_NAMES); 96*3d0e4f24SLawrence Tang json_object_object_add(error_info_ir, "flags", flags); 97*3d0e4f24SLawrence Tang 98*3d0e4f24SLawrence Tang //Error information, split by type. 99*3d0e4f24SLawrence Tang json_object* error_subinfo = NULL; 100*3d0e4f24SLawrence Tang switch (error_info->Type) 101*3d0e4f24SLawrence Tang { 102*3d0e4f24SLawrence Tang case 0: //Cache 103*3d0e4f24SLawrence Tang error_subinfo = cper_arm_cache_error_to_ir((EFI_ARM_PROCESSOR_CACHE_ERROR_STRUCTURE*)error_info->ErrorInformation); 104*3d0e4f24SLawrence Tang break; 105*3d0e4f24SLawrence Tang case 1: //TLB 106*3d0e4f24SLawrence Tang error_subinfo = cper_arm_tlb_error_to_ir((EFI_ARM_PROCESSOR_TLB_ERROR_STRUCTURE*)error_info->ErrorInformation); 107*3d0e4f24SLawrence Tang break; 108*3d0e4f24SLawrence Tang case 2: //Bus 109*3d0e4f24SLawrence Tang error_subinfo = cper_arm_bus_error_to_ir((EFI_ARM_PROCESSOR_BUS_ERROR_STRUCTURE*)error_info->ErrorInformation); 110*3d0e4f24SLawrence Tang break; 111*3d0e4f24SLawrence Tang } 112*3d0e4f24SLawrence Tang json_object_object_add(error_info_ir, "errorInformation", error_subinfo); 113*3d0e4f24SLawrence Tang 114*3d0e4f24SLawrence Tang return error_info_ir; 115*3d0e4f24SLawrence Tang } 116*3d0e4f24SLawrence Tang 117*3d0e4f24SLawrence Tang //Converts a single ARM cache error information structure into JSON IR format. 118*3d0e4f24SLawrence Tang json_object* cper_arm_cache_error_to_ir(EFI_ARM_PROCESSOR_CACHE_ERROR_STRUCTURE* cache_error) 119*3d0e4f24SLawrence Tang { 120*3d0e4f24SLawrence Tang //todo 121*3d0e4f24SLawrence Tang } 122*3d0e4f24SLawrence Tang 123*3d0e4f24SLawrence Tang //Converts a single ARM TLB error information structure into JSON IR format. 124*3d0e4f24SLawrence Tang json_object* cper_arm_tlb_error_to_ir(EFI_ARM_PROCESSOR_TLB_ERROR_STRUCTURE* tlb_error) 125*3d0e4f24SLawrence Tang { 126*3d0e4f24SLawrence Tang //todo 127*3d0e4f24SLawrence Tang } 128*3d0e4f24SLawrence Tang 129*3d0e4f24SLawrence Tang //Converts a single ARM bus error information structure into JSON IR format. 130*3d0e4f24SLawrence Tang json_object* cper_arm_bus_error_to_ir(EFI_ARM_PROCESSOR_BUS_ERROR_STRUCTURE* bus_error) 131*3d0e4f24SLawrence Tang { 132*3d0e4f24SLawrence Tang //todo 133*3d0e4f24SLawrence Tang }