1 /**
2  * Describes functions for converting ARM CPER sections from binary and JSON format
3  * into an intermediate format.
4  *
5  * Author: Lawrence.Tang@arm.com
6  **/
7 
8 #include <stdio.h>
9 #include "json.h"
10 #include "../edk/Cper.h"
11 #include "../cper-utils.h"
12 #include "cper-section-arm.h"
13 
14 //Converts the given processor-generic CPER section into JSON IR.
15 json_object* cper_section_arm_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
16 {
17     EFI_ARM_PROCESSOR_ERROR_RECORD* record = (EFI_ARM_PROCESSOR_ERROR_RECORD*)section;
18     json_object* section_ir = json_object_new_object();
19 
20     //Validation bits.
21     json_object* validation = bitfield_to_ir(record->ValidFields, 4, ARM_PROCESSOR_ERROR_VALID_BITFIELD_NAMES);
22     json_object_object_add(section_ir, "validationBits", validation);
23 
24     //Number of error info and context info structures, and length.
25     json_object_object_add(section_ir, "errorInfoNum", json_object_new_int(record->ErrInfoNum));
26     json_object_object_add(section_ir, "contextInfoNum", json_object_new_int(record->ContextInfoNum));
27     json_object_object_add(section_ir, "sectionLength", json_object_new_int(record->SectionLength));
28 
29     //Error affinity.
30     json_object* error_affinity = json_object_new_object();
31     json_object_object_add(error_affinity, "value", json_object_new_int(record->ErrorAffinityLevel));
32     json_object_object_add(error_affinity, "type",
33         json_object_new_string(record->ErrorAffinityLevel < 4 ? "Vendor Defined" : "Reserved"));
34     json_object_object_add(section_ir, "errorAffinity", error_affinity);
35 
36     //Processor ID (MPIDR_EL1) and chip ID (MIDR_EL1).
37     json_object_object_add(section_ir, "mpidrEl1", json_object_new_uint64(record->MPIDR_EL1));
38     json_object_object_add(section_ir, "midrEl1", json_object_new_uint64(record->MIDR_EL1));
39 
40     //Whether the processor is running, and the state of it if so.
41     json_object_object_add(section_ir, "running", json_object_new_boolean(record->RunningState));
42     if (record->RunningState)
43     {
44         //...
45     }
46 
47     return section_ir;
48 }