/**
 * Describes functions for converting PCI/PCI-X bus 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 "../edk/Cper.h"
#include "../cper-utils.h"
#include "cper-section-pci-bus.h"

//Converts a single PCI/PCI-X bus CPER section into JSON IR.
json_object *
cper_section_pci_bus_to_ir(void *section,
			   EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
	EFI_PCI_PCIX_BUS_ERROR_DATA *bus_error =
		(EFI_PCI_PCIX_BUS_ERROR_DATA *)section;
	json_object *section_ir = json_object_new_object();

	//Validation bits.
	json_object *validation = bitfield_to_ir(
		bus_error->ValidFields, 9, PCI_BUS_ERROR_VALID_BITFIELD_NAMES);
	json_object_object_add(section_ir, "validationBits", validation);

	//Error status.
	json_object *error_status =
		cper_generic_error_status_to_ir(&bus_error->ErrorStatus);
	json_object_object_add(section_ir, "errorStatus", error_status);

	//PCI bus error type.
	json_object *error_type = integer_to_readable_pair(
		bus_error->Type, 8, PCI_BUS_ERROR_TYPES_KEYS,
		PCI_BUS_ERROR_TYPES_VALUES, "Unknown (Reserved)");
	json_object_object_add(section_ir, "errorType", error_type);

	//Bus ID.
	json_object *bus_id = json_object_new_object();
	json_object_object_add(bus_id, "busNumber",
			       json_object_new_int(bus_error->BusId & 0xFF));
	json_object_object_add(bus_id, "segmentNumber",
			       json_object_new_int(bus_error->BusId >> 8));
	json_object_object_add(section_ir, "busID", bus_id);

	//Miscellaneous numeric fields.
	UINT8 command_type = (bus_error->BusCommand >> 56) &
			     0b1; //Byte 7, bit 0.
	json_object_object_add(section_ir, "busAddress",
			       json_object_new_uint64(bus_error->BusAddress));
	json_object_object_add(section_ir, "busData",
			       json_object_new_uint64(bus_error->BusData));
	json_object_object_add(
		section_ir, "busCommandType",
		json_object_new_string(command_type == 0 ? "PCI" : "PCI-X"));
	json_object_object_add(section_ir, "busRequestorID",
			       json_object_new_uint64(bus_error->RequestorId));
	json_object_object_add(section_ir, "busCompleterID",
			       json_object_new_uint64(bus_error->ResponderId));
	json_object_object_add(section_ir, "targetID",
			       json_object_new_uint64(bus_error->TargetId));

	return section_ir;
}

//Converts a single provided PCI/PCI-X bus CPER-JSON section into CPER binary, outputting to the
//provided stream.
void ir_section_pci_bus_to_cper(json_object *section, FILE *out)
{
	EFI_PCI_PCIX_BUS_ERROR_DATA *section_cper =
		(EFI_PCI_PCIX_BUS_ERROR_DATA *)calloc(
			1, sizeof(EFI_PCI_PCIX_BUS_ERROR_DATA));

	//Validation bits.
	section_cper->ValidFields = ir_to_bitfield(
		json_object_object_get(section, "validationBits"), 9,
		PCI_BUS_ERROR_VALID_BITFIELD_NAMES);

	//Error status.
	ir_generic_error_status_to_cper(json_object_object_get(section,
							       "errorStatus"),
					&section_cper->ErrorStatus);

	//Bus ID.
	json_object *bus_id = json_object_object_get(section, "busID");
	UINT16 bus_number = (UINT8)json_object_get_int(
		json_object_object_get(bus_id, "busNumber"));
	UINT16 segment_number = (UINT8)json_object_get_int(
		json_object_object_get(bus_id, "segmentNumber"));
	section_cper->BusId = bus_number + (segment_number << 8);

	//Remaining fields.
	UINT64 pcix_command = (UINT64)0x1 << 56;
	const char *bus_command = json_object_get_string(
		json_object_object_get(section, "busCommandType"));
	section_cper->Type = (UINT16)readable_pair_to_integer(
		json_object_object_get(section, "errorType"));
	section_cper->BusAddress = json_object_get_uint64(
		json_object_object_get(section, "busAddress"));
	section_cper->BusData = json_object_get_uint64(
		json_object_object_get(section, "busData"));
	section_cper->BusCommand =
		strcmp(bus_command, "PCI") == 0 ? 0 : pcix_command;
	section_cper->RequestorId = json_object_get_uint64(
		json_object_object_get(section, "busRequestorID"));
	section_cper->ResponderId = json_object_get_uint64(
		json_object_object_get(section, "busCompleterID"));
	section_cper->TargetId = json_object_get_uint64(
		json_object_object_get(section, "targetID"));

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