Lawrence Tang | 7f21db6 | 2022-07-06 11:09:39 +0100 | [diff] [blame] | 1 | /** |
| 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 Tang | a0865e3 | 2022-07-06 11:59:52 +0100 | [diff] [blame^] | 14 | json_object* cper_section_platform_memory_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor) |
Lawrence Tang | 7f21db6 | 2022-07-06 11:09:39 +0100 | [diff] [blame] | 15 | { |
| 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 Tang | a0865e3 | 2022-07-06 11:59:52 +0100 | [diff] [blame^] | 24 | json_object* error_status = cper_generic_error_status_to_ir(&memory_error->ErrorStatus); |
| 25 | json_object_object_add(section_ir, "errorStatus", error_status); |
| 26 | |
| 27 | //Miscellaneous numeric fields. |
| 28 | json_object_object_add(section_ir, "physicalAddress", json_object_new_uint64(memory_error->PhysicalAddress)); |
| 29 | json_object_object_add(section_ir, "physicalAddressMask", json_object_new_uint64(memory_error->PhysicalAddressMask)); |
| 30 | json_object_object_add(section_ir, "node", json_object_new_uint64(memory_error->Node)); |
| 31 | json_object_object_add(section_ir, "card", json_object_new_uint64(memory_error->Card)); |
| 32 | json_object_object_add(section_ir, "moduleRank", json_object_new_uint64(memory_error->ModuleRank)); |
| 33 | json_object_object_add(section_ir, "device", json_object_new_uint64(memory_error->Device)); |
| 34 | json_object_object_add(section_ir, "row", json_object_new_uint64(memory_error->Row)); |
| 35 | json_object_object_add(section_ir, "column", json_object_new_uint64(memory_error->Column)); |
| 36 | json_object_object_add(section_ir, "bitPosition", json_object_new_uint64(memory_error->BitPosition)); |
| 37 | json_object_object_add(section_ir, "requestorID", json_object_new_uint64(memory_error->RequestorId)); |
| 38 | json_object_object_add(section_ir, "responderID", json_object_new_uint64(memory_error->ResponderId)); |
| 39 | json_object_object_add(section_ir, "targetID", json_object_new_uint64(memory_error->TargetId)); |
| 40 | json_object_object_add(section_ir, "rankNumber", json_object_new_uint64(memory_error->RankNum)); |
| 41 | json_object_object_add(section_ir, "cardSmbiosHandle", json_object_new_uint64(memory_error->CardHandle)); |
| 42 | json_object_object_add(section_ir, "moduleSmbiosHandle", json_object_new_uint64(memory_error->ModuleHandle)); |
| 43 | |
| 44 | //Bank. |
| 45 | json_object* bank = json_object_new_object(); |
| 46 | json_object_object_add(bank, "address", json_object_new_uint64(memory_error->Bank & 0xFF)); |
| 47 | json_object_object_add(bank, "group", json_object_new_uint64(memory_error->Bank >> 8)); |
| 48 | json_object_object_add(section_ir, "bank", bank); |
| 49 | |
| 50 | //Memory error type. |
| 51 | json_object* memory_error_type = integer_to_readable_pair(memory_error->ErrorType, 16, |
| 52 | MEMORY_ERROR_TYPES_KEYS, |
| 53 | MEMORY_ERROR_TYPES_VALUES, |
| 54 | "Unknown (Reserved)"); |
| 55 | json_object_object_add(section_ir, "memoryErrorType", memory_error_type); |
| 56 | |
| 57 | //"Extended" row/column indication field + misc. |
| 58 | json_object* extended = json_object_new_object(); |
| 59 | json_object_object_add(extended, "rowBit16", json_object_new_boolean(memory_error->Extended & 0b1)); |
| 60 | json_object_object_add(extended, "rowBit17", json_object_new_boolean((memory_error->Extended >> 1) & 0b1)); |
| 61 | json_object_object_add(extended, "chipIdentification", json_object_new_int(memory_error->Extended >> 5)); |
| 62 | json_object_object_add(section_ir, "extended", extended); |
| 63 | |
| 64 | return section_ir; |
| 65 | } |
| 66 | |
| 67 | //Converts a single memory error 2 CPER section into JSON IR. |
| 68 | json_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 | |
| 73 | //... todo |
| 74 | |
| 75 | return section_ir; |
Lawrence Tang | 7f21db6 | 2022-07-06 11:09:39 +0100 | [diff] [blame] | 76 | } |