Add support for AMPERE CPERs
Support Ampere CPER entries
Change-Id: I607a89209138fa53914c55c07aba8b7d6f382e5e
Signed-off-by: Dung Cao <dung@os.amperecomputing.com>
diff --git a/sections/cper-section-ampere.c b/sections/cper-section-ampere.c
new file mode 100644
index 0000000..264c2f6
--- /dev/null
+++ b/sections/cper-section-ampere.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <json.h>
+#include "../edk/Cper.h"
+#include "../cper-utils.h"
+#include "cper-section-ampere.h"
+
+//Converts the given processor-generic CPER section into JSON IR.
+json_object *cper_section_ampere_to_ir(void *section)
+{
+ EFI_AMPERE_ERROR_DATA *record = (EFI_AMPERE_ERROR_DATA *)section;
+ json_object *section_ir = json_object_new_object();
+
+ json_object_object_add(section_ir, "typeId",
+ json_object_new_int(record->TypeId));
+ json_object_object_add(section_ir, "subTypeId",
+ json_object_new_int(record->SubtypeId));
+ json_object_object_add(section_ir, "instanceId",
+ json_object_new_int(record->InstanceId));
+
+ return section_ir;
+}
+
+//Converts a single CPER-JSON ARM error section into CPER binary, outputting to the given stream.
+void ir_section_ampere_to_cper(json_object *section, FILE *out)
+{
+ EFI_AMPERE_ERROR_DATA *section_cper = (EFI_AMPERE_ERROR_DATA *)calloc(
+ 1, sizeof(EFI_AMPERE_ERROR_DATA));
+
+ //Count of error/context info structures.
+ section_cper->TypeId =
+ json_object_get_int(json_object_object_get(section, "typeId"));
+ section_cper->SubtypeId = json_object_get_int(
+ json_object_object_get(section, "subTypeId"));
+ section_cper->InstanceId = json_object_get_int(
+ json_object_object_get(section, "instanceId"));
+
+ //Flush header to stream.
+ fwrite(section_cper, sizeof(EFI_AMPERE_ERROR_DATA), 1, out);
+ fflush(out);
+ free(section_cper);
+}