Lawrence Tang | db1b7ce | 2022-07-06 15:40:26 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Describes functions for converting VT-d 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" |
| 9 | #include "../edk/Cper.h" |
| 10 | #include "../cper-utils.h" |
| 11 | #include "cper-section-dmar-vtd.h" |
| 12 | |
| 13 | //Converts a single VT-d specific DMAr CPER section into JSON IR. |
| 14 | json_object* cper_section_dmar_vtd_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor) |
| 15 | { |
| 16 | EFI_DIRECTED_IO_DMAR_ERROR_DATA* vtd_error = (EFI_DIRECTED_IO_DMAR_ERROR_DATA*)section; |
| 17 | json_object* section_ir = json_object_new_object(); |
| 18 | |
| 19 | //Version, revision and OEM ID, as defined in the VT-d architecture. |
| 20 | UINT64 oem_id = (vtd_error->OemId[0] << 16) + (vtd_error->OemId[1] << 8) + vtd_error->OemId[2]; |
| 21 | json_object_object_add(section_ir, "version", json_object_new_int(vtd_error->Version)); |
| 22 | json_object_object_add(section_ir, "revision", json_object_new_int(vtd_error->Revision)); |
| 23 | json_object_object_add(section_ir, "oemID", json_object_new_uint64(oem_id)); |
| 24 | |
| 25 | //Registers. |
| 26 | json_object_object_add(section_ir, "capabilityRegister", json_object_new_uint64(vtd_error->Capability)); |
| 27 | json_object_object_add(section_ir, "extendedCapabilityRegister", json_object_new_uint64(vtd_error->CapabilityEx)); |
| 28 | json_object_object_add(section_ir, "globalCommandRegister", json_object_new_uint64(vtd_error->GlobalCommand)); |
| 29 | json_object_object_add(section_ir, "globalStatusRegister", json_object_new_uint64(vtd_error->GlobalStatus)); |
| 30 | json_object_object_add(section_ir, "faultStatusRegister", json_object_new_uint64(vtd_error->FaultStatus)); |
| 31 | |
| 32 | //Fault record, root and context entry. |
| 33 | //todo: Look at the VT-d specification and implement |
| 34 | |
| 35 | //PTE entry for all page levels. |
| 36 | json_object_object_add(section_ir, "pageTableEntry_Level6", json_object_new_uint64(vtd_error->PteL6)); |
| 37 | json_object_object_add(section_ir, "pageTableEntry_Level5", json_object_new_uint64(vtd_error->PteL5)); |
| 38 | json_object_object_add(section_ir, "pageTableEntry_Level4", json_object_new_uint64(vtd_error->PteL4)); |
| 39 | json_object_object_add(section_ir, "pageTableEntry_Level3", json_object_new_uint64(vtd_error->PteL3)); |
| 40 | json_object_object_add(section_ir, "pageTableEntry_Level2", json_object_new_uint64(vtd_error->PteL2)); |
| 41 | json_object_object_add(section_ir, "pageTableEntry_Level1", json_object_new_uint64(vtd_error->PteL1)); |
| 42 | |
| 43 | return section_ir; |
| 44 | } |