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