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" 9 #include "b64.h" 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. 28 //todo: implement as specified in the IOMMU specification 29 30 //Device table entry (as base64). 31 char* encoded = b64_encode((unsigned char*)iommu_error->DeviceTableEntry, 32); 32 json_object_object_add(section_ir, "deviceTableEntry", json_object_new_string(encoded)); 33 free(encoded); 34 35 //Page table entries. 36 json_object_object_add(section_ir, "pageTableEntry_Level6", json_object_new_uint64(iommu_error->PteL6)); 37 json_object_object_add(section_ir, "pageTableEntry_Level5", json_object_new_uint64(iommu_error->PteL5)); 38 json_object_object_add(section_ir, "pageTableEntry_Level4", json_object_new_uint64(iommu_error->PteL4)); 39 json_object_object_add(section_ir, "pageTableEntry_Level3", json_object_new_uint64(iommu_error->PteL3)); 40 json_object_object_add(section_ir, "pageTableEntry_Level2", json_object_new_uint64(iommu_error->PteL2)); 41 json_object_object_add(section_ir, "pageTableEntry_Level1", json_object_new_uint64(iommu_error->PteL1)); 42 43 return section_ir; 44 }