1db1b7ce2SLawrence Tang /** 2db1b7ce2SLawrence Tang * Describes functions for converting IOMMU specific DMAr CPER sections from binary and JSON format 3db1b7ce2SLawrence Tang * into an intermediate format. 4db1b7ce2SLawrence Tang * 5db1b7ce2SLawrence Tang * Author: Lawrence.Tang@arm.com 6db1b7ce2SLawrence Tang **/ 7db1b7ce2SLawrence Tang #include <stdio.h> 8db1b7ce2SLawrence Tang #include "json.h" 9*d7e8ca34SLawrence Tang #include "b64.h" 10db1b7ce2SLawrence Tang #include "../edk/Cper.h" 11db1b7ce2SLawrence Tang #include "../cper-utils.h" 12db1b7ce2SLawrence Tang #include "cper-section-dmar-iommu.h" 13db1b7ce2SLawrence Tang 14db1b7ce2SLawrence Tang //Converts a single IOMMU specific DMAr CPER section into JSON IR. 15db1b7ce2SLawrence Tang json_object* cper_section_dmar_iommu_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor) 16db1b7ce2SLawrence Tang { 17db1b7ce2SLawrence Tang EFI_IOMMU_DMAR_ERROR_DATA* iommu_error = (EFI_IOMMU_DMAR_ERROR_DATA*)section; 18db1b7ce2SLawrence Tang json_object* section_ir = json_object_new_object(); 19db1b7ce2SLawrence Tang 20db1b7ce2SLawrence Tang //Revision. 21db1b7ce2SLawrence Tang json_object_object_add(section_ir, "revision", json_object_new_int(iommu_error->Revision)); 22db1b7ce2SLawrence Tang 23db1b7ce2SLawrence Tang //IOMMU registers. 24db1b7ce2SLawrence Tang json_object_object_add(section_ir, "controlRegister", json_object_new_uint64(iommu_error->Control)); 25db1b7ce2SLawrence Tang json_object_object_add(section_ir, "statusRegister", json_object_new_uint64(iommu_error->Status)); 26db1b7ce2SLawrence Tang 27db1b7ce2SLawrence Tang //IOMMU event log entry. 28db1b7ce2SLawrence Tang //todo: implement as specified in the IOMMU specification 29db1b7ce2SLawrence Tang 30*d7e8ca34SLawrence Tang //Device table entry (as base64). 31*d7e8ca34SLawrence Tang char* encoded = b64_encode((unsigned char*)iommu_error->DeviceTableEntry, 32); 32*d7e8ca34SLawrence Tang json_object_object_add(section_ir, "deviceTableEntry", json_object_new_string(encoded)); 33*d7e8ca34SLawrence Tang free(encoded); 34db1b7ce2SLawrence Tang 35db1b7ce2SLawrence Tang //Page table entries. 36db1b7ce2SLawrence Tang json_object_object_add(section_ir, "pageTableEntry_Level6", json_object_new_uint64(iommu_error->PteL6)); 37db1b7ce2SLawrence Tang json_object_object_add(section_ir, "pageTableEntry_Level5", json_object_new_uint64(iommu_error->PteL5)); 38db1b7ce2SLawrence Tang json_object_object_add(section_ir, "pageTableEntry_Level4", json_object_new_uint64(iommu_error->PteL4)); 39db1b7ce2SLawrence Tang json_object_object_add(section_ir, "pageTableEntry_Level3", json_object_new_uint64(iommu_error->PteL3)); 40db1b7ce2SLawrence Tang json_object_object_add(section_ir, "pageTableEntry_Level2", json_object_new_uint64(iommu_error->PteL2)); 41db1b7ce2SLawrence Tang json_object_object_add(section_ir, "pageTableEntry_Level1", json_object_new_uint64(iommu_error->PteL1)); 42db1b7ce2SLawrence Tang 43db1b7ce2SLawrence Tang return section_ir; 44db1b7ce2SLawrence Tang }