blob: 69b150a62122fb80984a5d15d60d8a190188c60b [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.
Lawrence Tangce0f82b2022-07-07 16:14:28 +010028 //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 Tangdb1b7ce2022-07-06 15:40:26 +010032
Lawrence Tangd7e8ca32022-07-07 10:25:53 +010033 //Device table entry (as base64).
Lawrence Tangce0f82b2022-07-07 16:14:28 +010034 encoded = b64_encode((unsigned char*)iommu_error->DeviceTableEntry, 32);
Lawrence Tangd7e8ca32022-07-07 10:25:53 +010035 json_object_object_add(section_ir, "deviceTableEntry", json_object_new_string(encoded));
36 free(encoded);
Lawrence Tangdb1b7ce2022-07-06 15:40:26 +010037
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}