11b0b00e3SLawrence Tang /** 21b0b00e3SLawrence Tang * Describes functions for converting processor-generic CPER sections from binary and JSON format 31b0b00e3SLawrence Tang * into an intermediate 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-utils.h" 12*3c43f743SLawrence Tang #include "cper-section-generic.h" 131b0b00e3SLawrence Tang 141b0b00e3SLawrence Tang //Converts the given processor-generic CPER section into JSON IR. 151b0b00e3SLawrence Tang json_object* cper_section_generic_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor) 161b0b00e3SLawrence Tang { 17*3c43f743SLawrence Tang EFI_PROCESSOR_GENERIC_ERROR_DATA* section_generic = (EFI_PROCESSOR_GENERIC_ERROR_DATA*)section; 18*3c43f743SLawrence Tang json_object* section_ir = json_object_new_object(); 19*3c43f743SLawrence Tang 20*3c43f743SLawrence Tang //Validation bits. 21*3c43f743SLawrence Tang json_object* validation = json_object_new_object(); 22*3c43f743SLawrence Tang json_object_object_add(validation, "processorTypeValid", json_object_new_boolean(section_generic->ValidFields >> 63)); 23*3c43f743SLawrence Tang json_object_object_add(validation, "processorISAValid", json_object_new_boolean((section_generic->ValidFields >> 62) & 0x1)); 24*3c43f743SLawrence Tang json_object_object_add(validation, "processorErrorTypeValid", json_object_new_boolean((section_generic->ValidFields >> 61) & 0x1)); 25*3c43f743SLawrence Tang json_object_object_add(validation, "operationValid", json_object_new_boolean((section_generic->ValidFields >> 60) & 0x1)); 26*3c43f743SLawrence Tang json_object_object_add(validation, "flagsValid", json_object_new_boolean((section_generic->ValidFields >> 59) & 0x1)); 27*3c43f743SLawrence Tang json_object_object_add(validation, "levelValid", json_object_new_boolean((section_generic->ValidFields >> 58) & 0x1)); 28*3c43f743SLawrence Tang json_object_object_add(validation, "cpuVersionValid", json_object_new_boolean((section_generic->ValidFields >> 57) & 0x1)); 29*3c43f743SLawrence Tang json_object_object_add(validation, "cpuBrandInfoValid", json_object_new_boolean((section_generic->ValidFields >> 56) & 0x1)); 30*3c43f743SLawrence Tang json_object_object_add(validation, "cpuIDValid", json_object_new_boolean((section_generic->ValidFields >> 55) & 0x1)); 31*3c43f743SLawrence Tang json_object_object_add(validation, "targetAddressValid", json_object_new_boolean((section_generic->ValidFields >> 54) & 0x1)); 32*3c43f743SLawrence Tang json_object_object_add(validation, "requesterIDValid", json_object_new_boolean((section_generic->ValidFields >> 53) & 0x1)); 33*3c43f743SLawrence Tang json_object_object_add(validation, "responderIDValid", json_object_new_boolean((section_generic->ValidFields >> 52) & 0x1)); 34*3c43f743SLawrence Tang json_object_object_add(validation, "instructionIPValid", json_object_new_boolean((section_generic->ValidFields >> 51) & 0x1)); 35*3c43f743SLawrence Tang json_object_object_add(section_ir, "validationBits", validation); 36*3c43f743SLawrence Tang 37*3c43f743SLawrence Tang //Processor type, with human readable name if possible. 38*3c43f743SLawrence Tang json_object* processor_type = integer_to_readable_pair(section_generic->Type, 39*3c43f743SLawrence Tang sizeof(GENERIC_PROC_TYPES_KEYS) / sizeof(int), 40*3c43f743SLawrence Tang GENERIC_PROC_TYPES_KEYS, 41*3c43f743SLawrence Tang GENERIC_PROC_TYPES_VALUES, 42*3c43f743SLawrence Tang "Unknown (Reserved)"); 43*3c43f743SLawrence Tang json_object_object_add(section_ir, "processorType", processor_type); 44*3c43f743SLawrence Tang 45*3c43f743SLawrence Tang //Processor ISA, with human readable name if possible. 46*3c43f743SLawrence Tang json_object* processor_isa = integer_to_readable_pair(section_generic->Isa, 47*3c43f743SLawrence Tang sizeof(GENERIC_ISA_TYPES_KEYS) / sizeof(int), 48*3c43f743SLawrence Tang GENERIC_ISA_TYPES_KEYS, 49*3c43f743SLawrence Tang GENERIC_ISA_TYPES_VALUES, 50*3c43f743SLawrence Tang "Unknown (Reserved"); 51*3c43f743SLawrence Tang json_object_object_add(section_ir, "processorISA", processor_isa); 52*3c43f743SLawrence Tang 53*3c43f743SLawrence Tang //Processor error type, with human readable name if possible. 54*3c43f743SLawrence Tang json_object* processor_error_type = integer_to_readable_pair(section_generic->ErrorType, 55*3c43f743SLawrence Tang sizeof(GENERIC_ERROR_TYPES_KEYS) / sizeof(int), 56*3c43f743SLawrence Tang GENERIC_ERROR_TYPES_KEYS, 57*3c43f743SLawrence Tang GENERIC_ERROR_TYPES_VALUES, 58*3c43f743SLawrence Tang "Unknown (Reserved"); 59*3c43f743SLawrence Tang json_object_object_add(section_ir, "errorType", processor_error_type); 60*3c43f743SLawrence Tang 61*3c43f743SLawrence Tang //The operation performed, with a human readable name if possible. 62*3c43f743SLawrence Tang json_object* operation = integer_to_readable_pair(section_generic->Operation, 63*3c43f743SLawrence Tang sizeof(GENERIC_OPERATION_TYPES_KEYS) / sizeof(int), 64*3c43f743SLawrence Tang GENERIC_OPERATION_TYPES_KEYS, 65*3c43f743SLawrence Tang GENERIC_OPERATION_TYPES_VALUES, 66*3c43f743SLawrence Tang "Unknown (Reserved"); 67*3c43f743SLawrence Tang json_object_object_add(section_ir, "operation", operation); 68*3c43f743SLawrence Tang 69*3c43f743SLawrence Tang //Flags, additional information about the error. 70*3c43f743SLawrence Tang json_object* flags = json_object_new_object(); 71*3c43f743SLawrence Tang json_object_object_add(flags, "restartable", json_object_new_boolean(section_generic->Flags >> 7)); 72*3c43f743SLawrence Tang json_object_object_add(flags, "preciseIP", json_object_new_boolean((section_generic->Flags >> 6) & 0b1)); 73*3c43f743SLawrence Tang json_object_object_add(flags, "overflow", json_object_new_boolean((section_generic->Flags >> 5) & 0b1)); 74*3c43f743SLawrence Tang json_object_object_add(flags, "corrected", json_object_new_boolean((section_generic->Flags >> 4) & 0b1)); 75*3c43f743SLawrence Tang json_object_object_add(section_ir, "flags", flags); 76*3c43f743SLawrence Tang 77*3c43f743SLawrence Tang //The level of the error. 78*3c43f743SLawrence Tang json_object_object_add(section_ir, "level", json_object_new_int(section_generic->Level)); 79*3c43f743SLawrence Tang 80*3c43f743SLawrence Tang //CPU version information (todo) 81*3c43f743SLawrence Tang //... 82*3c43f743SLawrence Tang 83*3c43f743SLawrence Tang //CPU brand string. May not exist if on ARM. 84*3c43f743SLawrence Tang json_object_object_add(section_ir, "cpuBrandString", json_object_new_string(section_generic->BrandString)); 85*3c43f743SLawrence Tang 86*3c43f743SLawrence Tang //Remaining 64-bit fields. 87*3c43f743SLawrence Tang json_object_object_add(section_ir, "processorID", json_object_new_uint64(section_generic->ApicId)); 88*3c43f743SLawrence Tang json_object_object_add(section_ir, "targetAddress", json_object_new_uint64(section_generic->TargetAddr)); 89*3c43f743SLawrence Tang json_object_object_add(section_ir, "requestorID", json_object_new_uint64(section_generic->RequestorId)); 90*3c43f743SLawrence Tang json_object_object_add(section_ir, "responderID", json_object_new_uint64(section_generic->ResponderId)); 91*3c43f743SLawrence Tang json_object_object_add(section_ir, "instructionIP", json_object_new_uint64(section_generic->InstructionIP)); 92*3c43f743SLawrence Tang 93*3c43f743SLawrence Tang return section_ir; 941b0b00e3SLawrence Tang }