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