blob: 1f479aa8755146e7ceff9c91d05dcbc3c0bc8412 [file] [log] [blame]
Lawrence Tangdb1b7ce2022-07-06 15:40:26 +01001/**
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 Tangd7e8ca32022-07-07 10:25:53 +01009#include "b64.h"
Lawrence Tangdb1b7ce2022-07-06 15:40:26 +010010#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.
15json_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
Lawrence Tangd7e8ca32022-07-07 10:25:53 +010030 //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);
Lawrence Tangdb1b7ce2022-07-06 15:40:26 +010034
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}