/** * Describes functions for converting PCI/PCI-X device CPER sections from binary and JSON format * into an intermediate format. * * Author: Lawrence.Tang@arm.com **/ #include #include "json.h" #include "../edk/Cper.h" #include "../cper-utils.h" #include "cper-section-pci-dev.h" //Converts a single PCI/PCI-X device CPER section into JSON IR. json_object* cper_section_pci_dev_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor) { EFI_PCI_PCIX_DEVICE_ERROR_DATA* dev_error = (EFI_PCI_PCIX_DEVICE_ERROR_DATA*)section; json_object* section_ir = json_object_new_object(); //Validation bits. json_object* validation = bitfield_to_ir(dev_error->ValidFields, 5, PCI_DEV_ERROR_VALID_BITFIELD_NAMES); json_object_object_add(section_ir, "validationBits", validation); //Error status. json_object* error_status = cper_generic_error_status_to_ir(&dev_error->ErrorStatus); json_object_object_add(section_ir, "errorStatus", error_status); //ID information. json_object* id_info = json_object_new_object(); json_object_object_add(id_info, "vendorID", json_object_new_uint64(dev_error->IdInfo.VendorId)); json_object_object_add(id_info, "deviceID", json_object_new_uint64(dev_error->IdInfo.DeviceId)); json_object_object_add(id_info, "classCode", json_object_new_uint64(dev_error->IdInfo.ClassCode)); json_object_object_add(id_info, "functionNumber", json_object_new_uint64(dev_error->IdInfo.FunctionNumber)); json_object_object_add(id_info, "deviceNumber", json_object_new_uint64(dev_error->IdInfo.DeviceNumber)); json_object_object_add(id_info, "busNumber", json_object_new_uint64(dev_error->IdInfo.BusNumber)); json_object_object_add(id_info, "segmentNumber", json_object_new_uint64(dev_error->IdInfo.SegmentNumber)); json_object_object_add(section_ir, "idInfo", id_info); //Number of following register data pairs. json_object_object_add(section_ir, "memoryNumber", json_object_new_uint64(dev_error->MemoryNumber)); json_object_object_add(section_ir, "ioNumber", json_object_new_uint64(dev_error->IoNumber)); int num_data_pairs = dev_error->MemoryNumber + dev_error->IoNumber; //Register pairs, described by the numeric fields. //The actual "pairs" of address and data aren't necessarily 8 bytes long, so can't assume the contents. //Hence the naming "firstHalf" and "secondHalf" rather than "address" and "data". json_object* register_data_pair_array = json_object_new_array(); UINT64* cur_pos = (UINT64*)(dev_error + 1); for (int i=0; iValidFields = ir_to_bitfield(json_object_object_get(section, "validationBits"), 5, PCI_DEV_ERROR_VALID_BITFIELD_NAMES); //Error status. ir_generic_error_status_to_cper(json_object_object_get(section, "errorStatus"), §ion_cper->ErrorStatus); //Device ID information. json_object* id_info = json_object_object_get(section, "idInfo"); section_cper->IdInfo.VendorId = json_object_get_uint64(json_object_object_get(id_info, "vendorID")); section_cper->IdInfo.DeviceId = json_object_get_uint64(json_object_object_get(id_info, "deviceID")); section_cper->IdInfo.ClassCode = json_object_get_uint64(json_object_object_get(id_info, "classCode")); section_cper->IdInfo.FunctionNumber = json_object_get_uint64(json_object_object_get(id_info, "functionNumber")); section_cper->IdInfo.DeviceNumber = json_object_get_uint64(json_object_object_get(id_info, "deviceNumber")); section_cper->IdInfo.BusNumber = json_object_get_uint64(json_object_object_get(id_info, "busNumber")); section_cper->IdInfo.SegmentNumber = json_object_get_uint64(json_object_object_get(id_info, "segmentNumber")); //Amount of following data pairs. section_cper->MemoryNumber = (UINT32)json_object_get_uint64(json_object_object_get(section, "memoryNumber")); section_cper->IoNumber = (UINT32)json_object_get_uint64(json_object_object_get(section, "ioNumber")); //Write header out to stream, free it. fwrite(§ion_cper, sizeof(section_cper), 1, out); fflush(out); free(section_cper); //Begin writing register pairs. json_object* register_pairs = json_object_object_get(section, "registerPairs"); int num_pairs = json_object_array_length(register_pairs); for (int i=0; i