1 /** 2 * Describes functions for converting Intel IPF 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-ipf.h" 12 13 json_object* cper_ipf_mod_error_read_array(EFI_IPF_MOD_ERROR_INFO** cur_error, int num_to_read); 14 json_object* cper_ipf_mod_error_to_ir(EFI_IPF_MOD_ERROR_INFO* mod_error); 15 16 //Converts a single Intel IPF error CPER section into JSON IR. 17 json_object* cper_section_ipf_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor) 18 { 19 EFI_IPF_ERROR_INFO_HEADER* ipf_error = (EFI_IPF_ERROR_INFO_HEADER*)section; 20 json_object* section_ir = json_object_new_object(); 21 22 //Validation bits. 23 json_object* validation = json_object_new_object(); 24 json_object_object_add(validation, "errorMapValid", json_object_new_boolean(ipf_error->ValidBits.ProcErrorMapValid)); 25 json_object_object_add(validation, "stateParameterValid", json_object_new_boolean(ipf_error->ValidBits.ProcErrorMapValid)); 26 json_object_object_add(validation, "crLIDValid", json_object_new_boolean(ipf_error->ValidBits.ProcCrLidValid)); 27 json_object_object_add(validation, "psiStaticStructValid", json_object_new_boolean(ipf_error->ValidBits.PsiStaticStructValid)); 28 json_object_object_add(validation, "cpuInfoValid", json_object_new_boolean(ipf_error->ValidBits.CpuIdInfoValid)); 29 json_object_object_add(section_ir, "validationBits", validation); 30 31 //Numbers of various variable length segments. 32 json_object_object_add(section_ir, "cacheCheckNum", json_object_new_uint64(ipf_error->ValidBits.CacheCheckNum)); 33 json_object_object_add(section_ir, "tlbCheckNum", json_object_new_uint64(ipf_error->ValidBits.TlbCheckNum)); 34 json_object_object_add(section_ir, "busCheckNum", json_object_new_uint64(ipf_error->ValidBits.BusCheckNum)); 35 json_object_object_add(section_ir, "regFileCheckNum", json_object_new_uint64(ipf_error->ValidBits.RegFileCheckNum)); 36 json_object_object_add(section_ir, "msCheckNum", json_object_new_uint64(ipf_error->ValidBits.MsCheckNum)); 37 38 //Process error map, state params/CR LID. 39 json_object_object_add(section_ir, "procErrorMap", json_object_new_uint64(ipf_error->ProcErrorMap)); 40 json_object_object_add(section_ir, "procStateParameter", json_object_new_uint64(ipf_error->ProcStateParameter)); 41 json_object_object_add(section_ir, "procCRLID", json_object_new_uint64(ipf_error->ProcCrLid)); 42 43 //Read cache, TLB, bus, register file, MS errors. 44 EFI_IPF_MOD_ERROR_INFO* cur_error = (EFI_IPF_MOD_ERROR_INFO*)(ipf_error + 1); 45 json_object_object_add(section_ir, "cacheErrors", cper_ipf_mod_error_read_array(&cur_error, ipf_error->ValidBits.CacheCheckNum)); 46 json_object_object_add(section_ir, "tlbErrors", cper_ipf_mod_error_read_array(&cur_error, ipf_error->ValidBits.TlbCheckNum)); 47 json_object_object_add(section_ir, "busErrors", cper_ipf_mod_error_read_array(&cur_error, ipf_error->ValidBits.BusCheckNum)); 48 json_object_object_add(section_ir, "regFileErrors", cper_ipf_mod_error_read_array(&cur_error, ipf_error->ValidBits.RegFileCheckNum)); 49 json_object_object_add(section_ir, "msErrors", cper_ipf_mod_error_read_array(&cur_error, ipf_error->ValidBits.MsCheckNum)); 50 51 //CPU ID information. 52 EFI_IPF_CPU_INFO* cpu_info = (EFI_IPF_CPU_INFO*)cur_error; 53 //todo: find out how this is represented 54 55 //Processor static information. 56 EFI_IPF_PSI_STATIC* psi_static = (EFI_IPF_PSI_STATIC*)(cpu_info + 1); 57 json_object* psi_static_ir = json_object_new_object(); 58 59 //PSI validation bits. 60 json_object* psi_validation = bitfield_to_ir(psi_static->ValidBits, 6, IPF_PSI_STATIC_INFO_VALID_BITFIELD_NAMES); 61 json_object_object_add(psi_static_ir, "validationBits", psi_validation); 62 63 //PSI minimal state save info. 64 //todo: structure min save state area as in Intel Itanium Architecture Software Developer's Manual. 65 66 //BRs, CRs, ARs, RRs, FRs. 67 json_object_object_add(psi_static_ir, "brs", uint64_array_to_ir_array(psi_static->Brs, 8)); 68 json_object_object_add(psi_static_ir, "crs", uint64_array_to_ir_array(psi_static->Crs, 128)); 69 json_object_object_add(psi_static_ir, "ars", uint64_array_to_ir_array(psi_static->Ars, 128)); 70 json_object_object_add(psi_static_ir, "rrs", uint64_array_to_ir_array(psi_static->Rrs, 8)); 71 json_object_object_add(psi_static_ir, "frs", uint64_array_to_ir_array(psi_static->Frs, 256)); 72 json_object_object_add(section_ir, "psiStaticInfo", psi_static_ir); 73 74 return section_ir; 75 } 76 77 //Reads a continuous stream of CPER IPF mod errors beginning from the given pointer, for n entries. 78 //Returns an array containing all read entries as JSON IR. 79 json_object* cper_ipf_mod_error_read_array(EFI_IPF_MOD_ERROR_INFO** cur_error, int num_to_read) 80 { 81 json_object* error_array = json_object_new_array(); 82 for (int i=0; i<num_to_read; i++) 83 { 84 json_object_array_add(error_array, cper_ipf_mod_error_to_ir(*cur_error)); 85 *cur_error = *cur_error + 1; 86 } 87 88 return error_array; 89 } 90 91 //Converts a single CPER IPF mod error info structure into JSON IR. 92 json_object* cper_ipf_mod_error_to_ir(EFI_IPF_MOD_ERROR_INFO* mod_error) 93 { 94 json_object* mod_error_ir = json_object_new_object(); 95 96 //Validation bits. 97 json_object* validation = bitfield_to_ir(mod_error->ValidBits, 5, IPF_MOD_ERROR_VALID_BITFIELD_NAMES); 98 json_object_object_add(mod_error_ir, "validationBits", validation); 99 100 //Numeric fields. 101 json_object_object_add(mod_error_ir, "modCheckInfo", json_object_new_uint64(mod_error->ModCheckInfo)); 102 json_object_object_add(mod_error_ir, "modTargetID", json_object_new_uint64(mod_error->ModTargetId)); 103 json_object_object_add(mod_error_ir, "modRequestorID", json_object_new_uint64(mod_error->ModRequestorId)); 104 json_object_object_add(mod_error_ir, "modResponderID", json_object_new_uint64(mod_error->ModResponderId)); 105 json_object_object_add(mod_error_ir, "modPreciseIP", json_object_new_uint64(mod_error->ModPreciseIp)); 106 107 return mod_error_ir; 108 }