1 #include <stdio.h>
2 #include <json.h>
3 #include "../edk/Cper.h"
4 #include "../cper-utils.h"
5 #include "cper-section-ampere.h"
6 
7 //Converts the given processor-generic CPER section into JSON IR.
8 json_object *cper_section_ampere_to_ir(void *section)
9 {
10 	EFI_AMPERE_ERROR_DATA *record = (EFI_AMPERE_ERROR_DATA *)section;
11 	json_object *section_ir = json_object_new_object();
12 
13 	json_object_object_add(section_ir, "typeId",
14 			       json_object_new_int(record->TypeId));
15 	json_object_object_add(section_ir, "subTypeId",
16 			       json_object_new_int(record->SubtypeId));
17 	json_object_object_add(section_ir, "instanceId",
18 			       json_object_new_int(record->InstanceId));
19 
20 	return section_ir;
21 }
22 
23 //Converts a single CPER-JSON ARM error section into CPER binary, outputting to the given stream.
24 void ir_section_ampere_to_cper(json_object *section, FILE *out)
25 {
26 	EFI_AMPERE_ERROR_DATA *section_cper = (EFI_AMPERE_ERROR_DATA *)calloc(
27 		1, sizeof(EFI_AMPERE_ERROR_DATA));
28 
29 	//Count of error/context info structures.
30 	section_cper->TypeId =
31 		json_object_get_int(json_object_object_get(section, "typeId"));
32 	section_cper->SubtypeId = json_object_get_int(
33 		json_object_object_get(section, "subTypeId"));
34 	section_cper->InstanceId = json_object_get_int(
35 		json_object_object_get(section, "instanceId"));
36 
37 	//Flush header to stream.
38 	fwrite(section_cper, sizeof(EFI_AMPERE_ERROR_DATA), 1, out);
39 	fflush(out);
40 	free(section_cper);
41 }
42