/**
 * Describes functions for converting IOMMU specific DMAr CPER sections from binary and JSON format
 * into an intermediate format.
 *
 * Author: Lawrence.Tang@arm.com
 **/
#include <stdio.h>
#include <string.h>
#include <json.h>
#include <libcper/base64.h>
#include <libcper/Cper.h>
#include <libcper/cper-utils.h>
#include <libcper/sections/cper-section-dmar-iommu.h>

//Converts a single IOMMU specific DMAr CPER section into JSON IR.
json_object *cper_section_dmar_iommu_to_ir(void *section)
{
	EFI_IOMMU_DMAR_ERROR_DATA *iommu_error =
		(EFI_IOMMU_DMAR_ERROR_DATA *)section;
	json_object *section_ir = json_object_new_object();

	//Revision.
	json_object_object_add(section_ir, "revision",
			       json_object_new_int(iommu_error->Revision));

	//IOMMU registers.
	json_object_object_add(section_ir, "controlRegister",
			       json_object_new_uint64(iommu_error->Control));
	json_object_object_add(section_ir, "statusRegister",
			       json_object_new_uint64(iommu_error->Status));

	//IOMMU event log entry.
	//The format of these entries differ widely by the type of error.
	int32_t encoded_len = 0;

	char *encoded = base64_encode((UINT8 *)iommu_error->EventLogEntry, 16,
				      &encoded_len);
	if (encoded == NULL) {
		printf("Failed to allocate encode output buffer. \n");

		return NULL;
	}
	json_object_object_add(section_ir, "eventLogEntry",
			       json_object_new_string_len(encoded,
							  encoded_len));
	free(encoded);

	//Device table entry (as base64).
	encoded_len = 0;

	encoded = base64_encode((UINT8 *)iommu_error->DeviceTableEntry, 32,
				&encoded_len);
	if (encoded == NULL) {
		printf("Failed to allocate encode output buffer. \n");
		return NULL;
	}
	json_object_object_add(section_ir, "deviceTableEntry",
			       json_object_new_string_len(encoded,
							  encoded_len));
	free(encoded);

	//Page table entries.
	json_object_object_add(section_ir, "pageTableEntry_Level6",
			       json_object_new_uint64(iommu_error->PteL6));
	json_object_object_add(section_ir, "pageTableEntry_Level5",
			       json_object_new_uint64(iommu_error->PteL5));
	json_object_object_add(section_ir, "pageTableEntry_Level4",
			       json_object_new_uint64(iommu_error->PteL4));
	json_object_object_add(section_ir, "pageTableEntry_Level3",
			       json_object_new_uint64(iommu_error->PteL3));
	json_object_object_add(section_ir, "pageTableEntry_Level2",
			       json_object_new_uint64(iommu_error->PteL2));
	json_object_object_add(section_ir, "pageTableEntry_Level1",
			       json_object_new_uint64(iommu_error->PteL1));

	return section_ir;
}

//Converts a single DMAR IOMMU CPER-JSON section into CPER binary, outputting to the given stream.
void ir_section_dmar_iommu_to_cper(json_object *section, FILE *out)
{
	EFI_IOMMU_DMAR_ERROR_DATA *section_cper =
		(EFI_IOMMU_DMAR_ERROR_DATA *)calloc(
			1, sizeof(EFI_IOMMU_DMAR_ERROR_DATA));

	//Revision, registers.
	section_cper->Revision = (UINT8)json_object_get_int(
		json_object_object_get(section, "revision"));
	section_cper->Control = json_object_get_uint64(
		json_object_object_get(section, "controlRegister"));
	section_cper->Status = json_object_get_uint64(
		json_object_object_get(section, "statusRegister"));

	//IOMMU event log entry.
	json_object *encoded = json_object_object_get(section, "eventLogEntry");
	int32_t decoded_len = 0;

	UINT8 *decoded = base64_decode(json_object_get_string(encoded),
				       json_object_get_string_len(encoded),
				       &decoded_len);
	if (decoded == NULL) {
		printf("Failed to allocate decode output buffer. \n");
	} else {
		memcpy(section_cper->EventLogEntry, decoded, decoded_len);
		free(decoded);
	}
	//Device table entry.
	encoded = json_object_object_get(section, "deviceTableEntry");
	decoded_len = 0;

	decoded = base64_decode(json_object_get_string(encoded),
				json_object_get_string_len(encoded),
				&decoded_len);
	if (decoded == NULL) {
		printf("Failed to allocate decode output buffer. \n");
	} else {
		memcpy(section_cper->DeviceTableEntry, decoded, decoded_len);
		free(decoded);
	}

	//Page table entries.
	section_cper->PteL1 = json_object_get_uint64(
		json_object_object_get(section, "pageTableEntry_Level1"));
	section_cper->PteL2 = json_object_get_uint64(
		json_object_object_get(section, "pageTableEntry_Level2"));
	section_cper->PteL3 = json_object_get_uint64(
		json_object_object_get(section, "pageTableEntry_Level3"));
	section_cper->PteL4 = json_object_get_uint64(
		json_object_object_get(section, "pageTableEntry_Level4"));
	section_cper->PteL5 = json_object_get_uint64(
		json_object_object_get(section, "pageTableEntry_Level5"));
	section_cper->PteL6 = json_object_get_uint64(
		json_object_object_get(section, "pageTableEntry_Level6"));

	//Write to stream, free resources.
	fwrite(section_cper, sizeof(EFI_IOMMU_DMAR_ERROR_DATA), 1, out);
	fflush(out);
	free(section_cper);
}
