Lawrence Tang | db1b7ce | 2022-07-06 15:40:26 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Describes functions for converting IOMMU specific DMAr 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 | d7e8ca3 | 2022-07-07 10:25:53 +0100 | [diff] [blame] | 9 | #include "b64.h" |
Lawrence Tang | db1b7ce | 2022-07-06 15:40:26 +0100 | [diff] [blame] | 10 | #include "../edk/Cper.h" |
| 11 | #include "../cper-utils.h" |
| 12 | #include "cper-section-dmar-iommu.h" |
| 13 | |
| 14 | //Converts a single IOMMU specific DMAr CPER section into JSON IR. |
| 15 | json_object* cper_section_dmar_iommu_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor) |
| 16 | { |
| 17 | EFI_IOMMU_DMAR_ERROR_DATA* iommu_error = (EFI_IOMMU_DMAR_ERROR_DATA*)section; |
| 18 | json_object* section_ir = json_object_new_object(); |
| 19 | |
| 20 | //Revision. |
| 21 | json_object_object_add(section_ir, "revision", json_object_new_int(iommu_error->Revision)); |
| 22 | |
| 23 | //IOMMU registers. |
| 24 | json_object_object_add(section_ir, "controlRegister", json_object_new_uint64(iommu_error->Control)); |
| 25 | json_object_object_add(section_ir, "statusRegister", json_object_new_uint64(iommu_error->Status)); |
| 26 | |
| 27 | //IOMMU event log entry. |
Lawrence Tang | ce0f82b | 2022-07-07 16:14:28 +0100 | [diff] [blame^] | 28 | //The format of these entries differ widely by the type of error. |
| 29 | char* encoded = b64_encode((unsigned char*)iommu_error->EventLogEntry, 16); |
| 30 | json_object_object_add(section_ir, "eventLogEntry", json_object_new_string(encoded)); |
| 31 | free(encoded); |
Lawrence Tang | db1b7ce | 2022-07-06 15:40:26 +0100 | [diff] [blame] | 32 | |
Lawrence Tang | d7e8ca3 | 2022-07-07 10:25:53 +0100 | [diff] [blame] | 33 | //Device table entry (as base64). |
Lawrence Tang | ce0f82b | 2022-07-07 16:14:28 +0100 | [diff] [blame^] | 34 | encoded = b64_encode((unsigned char*)iommu_error->DeviceTableEntry, 32); |
Lawrence Tang | d7e8ca3 | 2022-07-07 10:25:53 +0100 | [diff] [blame] | 35 | json_object_object_add(section_ir, "deviceTableEntry", json_object_new_string(encoded)); |
| 36 | free(encoded); |
Lawrence Tang | db1b7ce | 2022-07-06 15:40:26 +0100 | [diff] [blame] | 37 | |
| 38 | //Page table entries. |
| 39 | json_object_object_add(section_ir, "pageTableEntry_Level6", json_object_new_uint64(iommu_error->PteL6)); |
| 40 | json_object_object_add(section_ir, "pageTableEntry_Level5", json_object_new_uint64(iommu_error->PteL5)); |
| 41 | json_object_object_add(section_ir, "pageTableEntry_Level4", json_object_new_uint64(iommu_error->PteL4)); |
| 42 | json_object_object_add(section_ir, "pageTableEntry_Level3", json_object_new_uint64(iommu_error->PteL3)); |
| 43 | json_object_object_add(section_ir, "pageTableEntry_Level2", json_object_new_uint64(iommu_error->PteL2)); |
| 44 | json_object_object_add(section_ir, "pageTableEntry_Level1", json_object_new_uint64(iommu_error->PteL1)); |
| 45 | |
| 46 | return section_ir; |
| 47 | } |