Lawrence Tang | cc0f5f3 | 2022-07-06 17:17:26 +0100 | [diff] [blame] | 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 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 13 | json_object *cper_ipf_mod_error_read_array(EFI_IPF_MOD_ERROR_INFO **cur_error, |
| 14 | int num_to_read); |
| 15 | json_object *cper_ipf_mod_error_to_ir(EFI_IPF_MOD_ERROR_INFO *mod_error); |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 16 | |
Lawrence Tang | cc0f5f3 | 2022-07-06 17:17:26 +0100 | [diff] [blame] | 17 | //Converts a single Intel IPF error CPER section into JSON IR. |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 18 | json_object *cper_section_ipf_to_ir(void *section, |
| 19 | EFI_ERROR_SECTION_DESCRIPTOR *descriptor) |
Lawrence Tang | cc0f5f3 | 2022-07-06 17:17:26 +0100 | [diff] [blame] | 20 | { |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 21 | EFI_IPF_ERROR_INFO_HEADER *ipf_error = |
| 22 | (EFI_IPF_ERROR_INFO_HEADER *)section; |
| 23 | json_object *section_ir = json_object_new_object(); |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 24 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 25 | //Validation bits. |
| 26 | json_object *validation = json_object_new_object(); |
| 27 | json_object_object_add(validation, "errorMapValid", |
| 28 | json_object_new_boolean( |
| 29 | ipf_error->ValidBits.ProcErrorMapValid)); |
| 30 | json_object_object_add(validation, "stateParameterValid", |
| 31 | json_object_new_boolean( |
| 32 | ipf_error->ValidBits.ProcErrorMapValid)); |
| 33 | json_object_object_add( |
| 34 | validation, "crLIDValid", |
| 35 | json_object_new_boolean(ipf_error->ValidBits.ProcCrLidValid)); |
| 36 | json_object_object_add( |
| 37 | validation, "psiStaticStructValid", |
| 38 | json_object_new_boolean( |
| 39 | ipf_error->ValidBits.PsiStaticStructValid)); |
| 40 | json_object_object_add( |
| 41 | validation, "cpuInfoValid", |
| 42 | json_object_new_boolean(ipf_error->ValidBits.CpuIdInfoValid)); |
| 43 | json_object_object_add(section_ir, "validationBits", validation); |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 44 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 45 | //Numbers of various variable length segments. |
| 46 | json_object_object_add( |
| 47 | section_ir, "cacheCheckNum", |
| 48 | json_object_new_uint64(ipf_error->ValidBits.CacheCheckNum)); |
| 49 | json_object_object_add( |
| 50 | section_ir, "tlbCheckNum", |
| 51 | json_object_new_uint64(ipf_error->ValidBits.TlbCheckNum)); |
| 52 | json_object_object_add( |
| 53 | section_ir, "busCheckNum", |
| 54 | json_object_new_uint64(ipf_error->ValidBits.BusCheckNum)); |
| 55 | json_object_object_add( |
| 56 | section_ir, "regFileCheckNum", |
| 57 | json_object_new_uint64(ipf_error->ValidBits.RegFileCheckNum)); |
| 58 | json_object_object_add( |
| 59 | section_ir, "msCheckNum", |
| 60 | json_object_new_uint64(ipf_error->ValidBits.MsCheckNum)); |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 61 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 62 | //Process error map, state params/CR LID. |
| 63 | json_object_object_add(section_ir, "procErrorMap", |
| 64 | json_object_new_uint64(ipf_error->ProcErrorMap)); |
| 65 | json_object_object_add( |
| 66 | section_ir, "procStateParameter", |
| 67 | json_object_new_uint64(ipf_error->ProcStateParameter)); |
| 68 | json_object_object_add(section_ir, "procCRLID", |
| 69 | json_object_new_uint64(ipf_error->ProcCrLid)); |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 70 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 71 | //Read cache, TLB, bus, register file, MS errors. |
| 72 | EFI_IPF_MOD_ERROR_INFO *cur_error = |
| 73 | (EFI_IPF_MOD_ERROR_INFO *)(ipf_error + 1); |
| 74 | json_object_object_add(section_ir, "cacheErrors", |
| 75 | cper_ipf_mod_error_read_array( |
| 76 | &cur_error, |
| 77 | ipf_error->ValidBits.CacheCheckNum)); |
| 78 | json_object_object_add(section_ir, "tlbErrors", |
| 79 | cper_ipf_mod_error_read_array( |
| 80 | &cur_error, |
| 81 | ipf_error->ValidBits.TlbCheckNum)); |
| 82 | json_object_object_add(section_ir, "busErrors", |
| 83 | cper_ipf_mod_error_read_array( |
| 84 | &cur_error, |
| 85 | ipf_error->ValidBits.BusCheckNum)); |
| 86 | json_object_object_add(section_ir, "regFileErrors", |
| 87 | cper_ipf_mod_error_read_array( |
| 88 | &cur_error, |
| 89 | ipf_error->ValidBits.RegFileCheckNum)); |
| 90 | json_object_object_add( |
| 91 | section_ir, "msErrors", |
| 92 | cper_ipf_mod_error_read_array(&cur_error, |
| 93 | ipf_error->ValidBits.MsCheckNum)); |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 94 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 95 | //CPU ID information. |
| 96 | EFI_IPF_CPU_INFO *cpu_info = (EFI_IPF_CPU_INFO *)cur_error; |
| 97 | //stretch: find out how this is represented |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 98 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 99 | //Processor static information. |
| 100 | EFI_IPF_PSI_STATIC *psi_static = (EFI_IPF_PSI_STATIC *)(cpu_info + 1); |
| 101 | json_object *psi_static_ir = json_object_new_object(); |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 102 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 103 | //PSI validation bits. |
| 104 | json_object *psi_validation = |
| 105 | bitfield_to_ir(psi_static->ValidBits, 6, |
| 106 | IPF_PSI_STATIC_INFO_VALID_BITFIELD_NAMES); |
| 107 | json_object_object_add(psi_static_ir, "validationBits", psi_validation); |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 108 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 109 | //PSI minimal state save info. |
| 110 | //stretch: structure min save state area as in Intel Itanium Architecture Software Developer's Manual. |
| 111 | |
| 112 | //BRs, CRs, ARs, RRs, FRs. |
| 113 | json_object_object_add(psi_static_ir, "brs", |
| 114 | uint64_array_to_ir_array(psi_static->Brs, 8)); |
| 115 | json_object_object_add(psi_static_ir, "crs", |
| 116 | uint64_array_to_ir_array(psi_static->Crs, 128)); |
| 117 | json_object_object_add(psi_static_ir, "ars", |
| 118 | uint64_array_to_ir_array(psi_static->Ars, 128)); |
| 119 | json_object_object_add(psi_static_ir, "rrs", |
| 120 | uint64_array_to_ir_array(psi_static->Rrs, 8)); |
| 121 | json_object_object_add(psi_static_ir, "frs", |
| 122 | uint64_array_to_ir_array(psi_static->Frs, 256)); |
| 123 | json_object_object_add(section_ir, "psiStaticInfo", psi_static_ir); |
| 124 | |
| 125 | return section_ir; |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | //Reads a continuous stream of CPER IPF mod errors beginning from the given pointer, for n entries. |
| 129 | //Returns an array containing all read entries as JSON IR. |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 130 | json_object *cper_ipf_mod_error_read_array(EFI_IPF_MOD_ERROR_INFO **cur_error, |
| 131 | int num_to_read) |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 132 | { |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 133 | json_object *error_array = json_object_new_array(); |
| 134 | for (int i = 0; i < num_to_read; i++) { |
| 135 | json_object_array_add(error_array, |
| 136 | cper_ipf_mod_error_to_ir(*cur_error)); |
| 137 | *cur_error = *cur_error + 1; |
| 138 | } |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 139 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 140 | return error_array; |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | //Converts a single CPER IPF mod error info structure into JSON IR. |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 144 | json_object *cper_ipf_mod_error_to_ir(EFI_IPF_MOD_ERROR_INFO *mod_error) |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 145 | { |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 146 | json_object *mod_error_ir = json_object_new_object(); |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 147 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 148 | //Validation bits. |
| 149 | json_object *validation = bitfield_to_ir( |
| 150 | mod_error->ValidBits, 5, IPF_MOD_ERROR_VALID_BITFIELD_NAMES); |
| 151 | json_object_object_add(mod_error_ir, "validationBits", validation); |
Lawrence Tang | e18aaee | 2022-07-07 09:01:30 +0100 | [diff] [blame] | 152 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 153 | //Numeric fields. |
| 154 | json_object_object_add(mod_error_ir, "modCheckInfo", |
| 155 | json_object_new_uint64(mod_error->ModCheckInfo)); |
| 156 | json_object_object_add(mod_error_ir, "modTargetID", |
| 157 | json_object_new_uint64(mod_error->ModTargetId)); |
| 158 | json_object_object_add( |
| 159 | mod_error_ir, "modRequestorID", |
| 160 | json_object_new_uint64(mod_error->ModRequestorId)); |
| 161 | json_object_object_add( |
| 162 | mod_error_ir, "modResponderID", |
| 163 | json_object_new_uint64(mod_error->ModResponderId)); |
| 164 | json_object_object_add(mod_error_ir, "modPreciseIP", |
| 165 | json_object_new_uint64(mod_error->ModPreciseIp)); |
| 166 | |
| 167 | return mod_error_ir; |
Lawrence Tang | cc0f5f3 | 2022-07-06 17:17:26 +0100 | [diff] [blame] | 168 | } |