blob: b014d5d1aba17256f7d8ca6d1e4db80b9e14a42c [file] [log] [blame]
Lawrence Tangcc0f5f32022-07-06 17:17:26 +01001/**
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 Tange407b4c2022-07-21 13:54:01 +010013json_object *cper_ipf_mod_error_read_array(EFI_IPF_MOD_ERROR_INFO **cur_error,
14 int num_to_read);
15json_object *cper_ipf_mod_error_to_ir(EFI_IPF_MOD_ERROR_INFO *mod_error);
Lawrence Tange18aaee2022-07-07 09:01:30 +010016
Lawrence Tangcc0f5f32022-07-06 17:17:26 +010017//Converts a single Intel IPF error CPER section into JSON IR.
Lawrence Tange407b4c2022-07-21 13:54:01 +010018json_object *cper_section_ipf_to_ir(void *section,
19 EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
Lawrence Tangcc0f5f32022-07-06 17:17:26 +010020{
Lawrence Tange407b4c2022-07-21 13:54:01 +010021 EFI_IPF_ERROR_INFO_HEADER *ipf_error =
22 (EFI_IPF_ERROR_INFO_HEADER *)section;
23 json_object *section_ir = json_object_new_object();
Lawrence Tange18aaee2022-07-07 09:01:30 +010024
Lawrence Tange407b4c2022-07-21 13:54:01 +010025 //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 Tange18aaee2022-07-07 09:01:30 +010044
Lawrence Tange407b4c2022-07-21 13:54:01 +010045 //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 Tange18aaee2022-07-07 09:01:30 +010061
Lawrence Tange407b4c2022-07-21 13:54:01 +010062 //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 Tange18aaee2022-07-07 09:01:30 +010070
Lawrence Tange407b4c2022-07-21 13:54:01 +010071 //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 Tange18aaee2022-07-07 09:01:30 +010094
Lawrence Tange407b4c2022-07-21 13:54:01 +010095 //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 Tange18aaee2022-07-07 09:01:30 +010098
Lawrence Tange407b4c2022-07-21 13:54:01 +010099 //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 Tange18aaee2022-07-07 09:01:30 +0100102
Lawrence Tange407b4c2022-07-21 13:54:01 +0100103 //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 Tange18aaee2022-07-07 09:01:30 +0100108
Lawrence Tange407b4c2022-07-21 13:54:01 +0100109 //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 Tange18aaee2022-07-07 09:01:30 +0100126}
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 Tange407b4c2022-07-21 13:54:01 +0100130json_object *cper_ipf_mod_error_read_array(EFI_IPF_MOD_ERROR_INFO **cur_error,
131 int num_to_read)
Lawrence Tange18aaee2022-07-07 09:01:30 +0100132{
Lawrence Tange407b4c2022-07-21 13:54:01 +0100133 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 Tange18aaee2022-07-07 09:01:30 +0100139
Lawrence Tange407b4c2022-07-21 13:54:01 +0100140 return error_array;
Lawrence Tange18aaee2022-07-07 09:01:30 +0100141}
142
143//Converts a single CPER IPF mod error info structure into JSON IR.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100144json_object *cper_ipf_mod_error_to_ir(EFI_IPF_MOD_ERROR_INFO *mod_error)
Lawrence Tange18aaee2022-07-07 09:01:30 +0100145{
Lawrence Tange407b4c2022-07-21 13:54:01 +0100146 json_object *mod_error_ir = json_object_new_object();
Lawrence Tange18aaee2022-07-07 09:01:30 +0100147
Lawrence Tange407b4c2022-07-21 13:54:01 +0100148 //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 Tange18aaee2022-07-07 09:01:30 +0100152
Lawrence Tange407b4c2022-07-21 13:54:01 +0100153 //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 Tangcc0f5f32022-07-06 17:17:26 +0100168}