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

//Converts a single generic DMAr CPER section into JSON IR.
json_object *
cper_section_dmar_generic_to_ir(void *section,
				EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
	EFI_DMAR_GENERIC_ERROR_DATA *firmware_error =
		(EFI_DMAR_GENERIC_ERROR_DATA *)section;
	json_object *section_ir = json_object_new_object();

	//Requester ID, segment.
	json_object_object_add(
		section_ir, "requesterID",
		json_object_new_int(firmware_error->RequesterId));
	json_object_object_add(
		section_ir, "segmentNumber",
		json_object_new_int(firmware_error->SegmentNumber));

	//Fault reason.
	json_object *fault_reason = integer_to_readable_pair_with_desc(
		firmware_error->FaultReason, 11,
		DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_KEYS,
		DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_VALUES,
		DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_DESCRIPTIONS,
		"Unknown (Reserved)");
	json_object_object_add(section_ir, "faultReason", fault_reason);

	//Access type.
	json_object *access_type = integer_to_readable_pair(
		firmware_error->AccessType, 2,
		DMAR_GENERIC_ERROR_ACCESS_TYPES_KEYS,
		DMAR_GENERIC_ERROR_ACCESS_TYPES_VALUES, "Unknown (Reserved)");
	json_object_object_add(section_ir, "accessType", access_type);

	//Address type.
	json_object *address_type = integer_to_readable_pair(
		firmware_error->AddressType, 2,
		DMAR_GENERIC_ERROR_ADDRESS_TYPES_KEYS,
		DMAR_GENERIC_ERROR_ADDRESS_TYPES_VALUES, "Unknown (Reserved)");
	json_object_object_add(section_ir, "addressType", address_type);

	//Architecture type.
	json_object *arch_type = integer_to_readable_pair(
		firmware_error->ArchType, 2, DMAR_GENERIC_ERROR_ARCH_TYPES_KEYS,
		DMAR_GENERIC_ERROR_ARCH_TYPES_VALUES, "Unknown (Reserved)");
	json_object_object_add(section_ir, "architectureType", arch_type);

	//Device address.
	json_object_object_add(
		section_ir, "deviceAddress",
		json_object_new_uint64(firmware_error->DeviceAddr));

	return section_ir;
}

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

	//Record fields.
	section_cper->RequesterId = (UINT16)json_object_get_int(
		json_object_object_get(section, "requesterID"));
	section_cper->SegmentNumber = (UINT16)json_object_get_int(
		json_object_object_get(section, "segmentNumber"));
	section_cper->FaultReason = (UINT8)readable_pair_to_integer(
		json_object_object_get(section, "faultReason"));
	section_cper->AccessType = (UINT8)readable_pair_to_integer(
		json_object_object_get(section, "accessType"));
	section_cper->AddressType = (UINT8)readable_pair_to_integer(
		json_object_object_get(section, "addressType"));
	section_cper->ArchType = (UINT8)readable_pair_to_integer(
		json_object_object_get(section, "architectureType"));
	section_cper->DeviceAddr = json_object_get_uint64(
		json_object_object_get(section, "deviceAddress"));

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