blob: 5f78eed5b1f40654ff731e1e40fdda7c35e1a3d5 [file] [log] [blame]
Lawrence Tang7f21db62022-07-06 11:09:39 +01001/**
2 * Describes functions for converting memory error 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-memory.h"
12
13//Converts a single memory error CPER section into JSON IR.
Lawrence Tanga0865e32022-07-06 11:59:52 +010014json_object* cper_section_platform_memory_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
Lawrence Tang7f21db62022-07-06 11:09:39 +010015{
16 EFI_PLATFORM_MEMORY_ERROR_DATA* memory_error = (EFI_PLATFORM_MEMORY_ERROR_DATA*)section;
17 json_object* section_ir = json_object_new_object();
18
19 //Validation bitfield.
20 json_object* validation = bitfield_to_ir(memory_error->ValidFields, 22, MEMORY_ERROR_VALID_BITFIELD_NAMES);
21 json_object_object_add(section_ir, "validationBits", validation);
22
23 //Error status.
Lawrence Tanga0865e32022-07-06 11:59:52 +010024 json_object* error_status = cper_generic_error_status_to_ir(&memory_error->ErrorStatus);
25 json_object_object_add(section_ir, "errorStatus", error_status);
26
Lawrence Tanga0865e32022-07-06 11:59:52 +010027 //Bank.
28 json_object* bank = json_object_new_object();
29 json_object_object_add(bank, "address", json_object_new_uint64(memory_error->Bank & 0xFF));
30 json_object_object_add(bank, "group", json_object_new_uint64(memory_error->Bank >> 8));
31 json_object_object_add(section_ir, "bank", bank);
32
33 //Memory error type.
34 json_object* memory_error_type = integer_to_readable_pair(memory_error->ErrorType, 16,
35 MEMORY_ERROR_TYPES_KEYS,
36 MEMORY_ERROR_TYPES_VALUES,
37 "Unknown (Reserved)");
38 json_object_object_add(section_ir, "memoryErrorType", memory_error_type);
39
40 //"Extended" row/column indication field + misc.
41 json_object* extended = json_object_new_object();
42 json_object_object_add(extended, "rowBit16", json_object_new_boolean(memory_error->Extended & 0b1));
43 json_object_object_add(extended, "rowBit17", json_object_new_boolean((memory_error->Extended >> 1) & 0b1));
44 json_object_object_add(extended, "chipIdentification", json_object_new_int(memory_error->Extended >> 5));
45 json_object_object_add(section_ir, "extended", extended);
46
Lawrence Tang54da4412022-07-06 13:14:58 +010047 //Miscellaneous numeric fields.
48 json_object_object_add(section_ir, "physicalAddress", json_object_new_uint64(memory_error->PhysicalAddress));
49 json_object_object_add(section_ir, "physicalAddressMask", json_object_new_uint64(memory_error->PhysicalAddressMask));
50 json_object_object_add(section_ir, "node", json_object_new_uint64(memory_error->Node));
51 json_object_object_add(section_ir, "card", json_object_new_uint64(memory_error->Card));
52 json_object_object_add(section_ir, "moduleRank", json_object_new_uint64(memory_error->ModuleRank));
53 json_object_object_add(section_ir, "device", json_object_new_uint64(memory_error->Device));
54 json_object_object_add(section_ir, "row", json_object_new_uint64(memory_error->Row));
55 json_object_object_add(section_ir, "column", json_object_new_uint64(memory_error->Column));
56 json_object_object_add(section_ir, "bitPosition", json_object_new_uint64(memory_error->BitPosition));
57 json_object_object_add(section_ir, "requestorID", json_object_new_uint64(memory_error->RequestorId));
58 json_object_object_add(section_ir, "responderID", json_object_new_uint64(memory_error->ResponderId));
59 json_object_object_add(section_ir, "targetID", json_object_new_uint64(memory_error->TargetId));
60 json_object_object_add(section_ir, "rankNumber", json_object_new_uint64(memory_error->RankNum));
61 json_object_object_add(section_ir, "cardSmbiosHandle", json_object_new_uint64(memory_error->CardHandle));
62 json_object_object_add(section_ir, "moduleSmbiosHandle", json_object_new_uint64(memory_error->ModuleHandle));
63
Lawrence Tanga0865e32022-07-06 11:59:52 +010064 return section_ir;
65}
66
67//Converts a single memory error 2 CPER section into JSON IR.
68json_object* cper_section_platform_memory2_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
69{
70 EFI_PLATFORM_MEMORY2_ERROR_DATA* memory_error = (EFI_PLATFORM_MEMORY2_ERROR_DATA*)section;
71 json_object* section_ir = json_object_new_object();
72
Lawrence Tang54da4412022-07-06 13:14:58 +010073 //Validation bits.
74 json_object* validation = bitfield_to_ir(memory_error->ValidFields, 22, MEMORY_ERROR_2_VALID_BITFIELD_NAMES);
75 json_object_object_add(section_ir, "validationBits", validation);
Lawrence Tanga0865e32022-07-06 11:59:52 +010076
Lawrence Tang54da4412022-07-06 13:14:58 +010077 //Error status.
78 json_object* error_status = cper_generic_error_status_to_ir(&memory_error->ErrorStatus);
79 json_object_object_add(section_ir, "errorStatus", error_status);
80
81 //Bank.
82 json_object* bank = json_object_new_object();
83 json_object_object_add(bank, "address", json_object_new_uint64(memory_error->Bank & 0xFF));
84 json_object_object_add(bank, "group", json_object_new_uint64(memory_error->Bank >> 8));
85 json_object_object_add(section_ir, "bank", bank);
86
87 //Memory error type.
88 json_object* memory_error_type = integer_to_readable_pair(memory_error->MemErrorType, 16,
89 MEMORY_ERROR_TYPES_KEYS,
90 MEMORY_ERROR_TYPES_VALUES,
91 "Unknown (Reserved)");
92 json_object_object_add(section_ir, "memoryErrorType", memory_error_type);
93
94 //Status.
95 json_object* status = json_object_new_object();
96 json_object_object_add(status, "value", json_object_new_int(memory_error->Status));
97 json_object_object_add(status, "state", json_object_new_string(memory_error->Status & 0b1 == 0 ? "Corrected" : "Uncorrected"));
98 json_object_object_add(section_ir, "status", status);
99
100 //Miscellaneous numeric fields.
101 json_object_object_add(section_ir, "physicalAddress", json_object_new_uint64(memory_error->PhysicalAddress));
102 json_object_object_add(section_ir, "physicalAddressMask", json_object_new_uint64(memory_error->PhysicalAddressMask));
103 json_object_object_add(section_ir, "node", json_object_new_uint64(memory_error->Node));
104 json_object_object_add(section_ir, "card", json_object_new_uint64(memory_error->Card));
105 json_object_object_add(section_ir, "module", json_object_new_uint64(memory_error->Module));
106 json_object_object_add(section_ir, "device", json_object_new_uint64(memory_error->Device));
107 json_object_object_add(section_ir, "row", json_object_new_uint64(memory_error->Row));
108 json_object_object_add(section_ir, "column", json_object_new_uint64(memory_error->Column));
109 json_object_object_add(section_ir, "rank", json_object_new_uint64(memory_error->Rank));
110 json_object_object_add(section_ir, "bitPosition", json_object_new_uint64(memory_error->BitPosition));
111 json_object_object_add(section_ir, "chipID", json_object_new_uint64(memory_error->ChipId));
112 json_object_object_add(section_ir, "requestorID", json_object_new_uint64(memory_error->RequestorId));
113 json_object_object_add(section_ir, "responderID", json_object_new_uint64(memory_error->ResponderId));
114 json_object_object_add(section_ir, "targetID", json_object_new_uint64(memory_error->TargetId));
115 json_object_object_add(section_ir, "cardSmbiosHandle", json_object_new_uint64(memory_error->CardHandle));
116 json_object_object_add(section_ir, "moduleSmbiosHandle", json_object_new_uint64(memory_error->ModuleHandle));
117
Lawrence Tanga0865e32022-07-06 11:59:52 +0100118 return section_ir;
Lawrence Tang7f21db62022-07-06 11:09:39 +0100119}