Lawrence Tang | 864c0da | 2022-07-06 15:55:40 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Describes functions for converting CCIX PER log 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" |
Lawrence Tang | 2721739 | 2022-07-07 11:55:39 +0100 | [diff] [blame] | 9 | #include "b64.h" |
Lawrence Tang | 864c0da | 2022-07-06 15:55:40 +0100 | [diff] [blame] | 10 | #include "../edk/Cper.h" |
| 11 | #include "../cper-utils.h" |
| 12 | #include "cper-section-ccix-per.h" |
| 13 | |
| 14 | //Converts a single CCIX PER log CPER section into JSON IR. |
| 15 | json_object* cper_section_ccix_per_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor) |
| 16 | { |
| 17 | EFI_CCIX_PER_LOG_DATA* ccix_error = (EFI_CCIX_PER_LOG_DATA*)section; |
| 18 | json_object* section_ir = json_object_new_object(); |
| 19 | |
| 20 | //Length (bytes) for the entire structure. |
| 21 | json_object_object_add(section_ir, "length", json_object_new_uint64(ccix_error->Length)); |
| 22 | |
| 23 | //Validation bits. |
| 24 | json_object* validation = bitfield_to_ir(ccix_error->ValidBits, 3, CCIX_PER_ERROR_VALID_BITFIELD_NAMES); |
| 25 | json_object_object_add(section_ir, "validationBits", validation); |
| 26 | |
| 27 | //CCIX source/port IDs. |
| 28 | json_object_object_add(section_ir, "ccixSourceID", json_object_new_int(ccix_error->CcixSourceId)); |
| 29 | json_object_object_add(section_ir, "ccixPortID", json_object_new_int(ccix_error->CcixPortId)); |
| 30 | |
| 31 | //CCIX PER Log. |
Lawrence Tang | 2721739 | 2022-07-07 11:55:39 +0100 | [diff] [blame] | 32 | //This is formatted as described in Section 7.3.2 of CCIX Base Specification (Rev 1.0). |
| 33 | unsigned char* cur_pos = (unsigned char*)(ccix_error + 1); |
| 34 | int remaining_length = section - (void*)cur_pos + ccix_error->Length; |
| 35 | if (remaining_length > 0) |
| 36 | { |
| 37 | char* encoded = b64_encode(cur_pos, remaining_length); |
| 38 | json_object_object_add(section_ir, "ccixPERLog", json_object_new_string(encoded)); |
| 39 | free(encoded); |
| 40 | } |
Lawrence Tang | 864c0da | 2022-07-06 15:55:40 +0100 | [diff] [blame] | 41 | |
| 42 | return section_ir; |
| 43 | } |