1 /**
2  * Describes functions for converting PCI/PCI-X bus 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"
9 #include "../edk/Cper.h"
10 #include "../cper-utils.h"
11 #include "cper-section-pci-bus.h"
12 
13 //Converts a single PCI/PCI-X bus CPER section into JSON IR.
14 json_object* cper_section_pci_bus_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
15 {
16     EFI_PCI_PCIX_BUS_ERROR_DATA* bus_error = (EFI_PCI_PCIX_BUS_ERROR_DATA*)section;
17     json_object* section_ir = json_object_new_object();
18 
19     //Validation bits.
20     json_object* validation = bitfield_to_ir(bus_error->ValidFields, 9, PCI_BUS_ERROR_VALID_BITFIELD_NAMES);
21     json_object_object_add(section_ir, "validationBits", validation);
22 
23     //Error status.
24     json_object* error_status = cper_generic_error_status_to_ir(&bus_error->ErrorStatus);
25     json_object_object_add(section_ir, "errorStatus", error_status);
26 
27     //PCI bus error type.
28     json_object* error_type = integer_to_readable_pair(bus_error->Type, 8,
29         PCI_BUS_ERROR_TYPES_KEYS,
30         PCI_BUS_ERROR_TYPES_VALUES,
31         "Unknown (Reserved)");
32     json_object_object_add(section_ir, "errorType", error_type);
33 
34     //Bus ID.
35     json_object* bus_id = json_object_new_object();
36     json_object_object_add(bus_id, "busNumber", json_object_new_int(bus_error->BusId & 0xFF));
37     json_object_object_add(bus_id, "segmentNumber", json_object_new_int(bus_error->BusId >> 8));
38     json_object_object_add(section_ir, "busID", bus_id);
39 
40     //Miscellaneous numeric fields.
41     json_object_object_add(section_ir, "busAddress", json_object_new_uint64(bus_error->BusAddress));
42     json_object_object_add(section_ir, "busData", json_object_new_uint64(bus_error->BusData));
43     json_object_object_add(section_ir, "busCommandType", json_object_new_string(bus_error->BusCommand == 0 ? "PCI" : "PCI-X"));
44     json_object_object_add(section_ir, "busRequestorID", json_object_new_uint64(bus_error->RequestorId));
45     json_object_object_add(section_ir, "busCompleterID", json_object_new_uint64(bus_error->ResponderId));
46     json_object_object_add(section_ir, "targetID", json_object_new_uint64(bus_error->TargetId));
47 
48     return section_ir;
49 }