[PATCH 2/3] acpi: add EINJ table sanity check

Alex Hung alex.hung at canonical.com
Fri Feb 26 08:37:15 UTC 2016


Signed-off-by: Alex Hung <alex.hung at canonical.com>
---
 src/Makefile.am      |   1 +
 src/acpi/einj/einj.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 138 insertions(+)
 create mode 100644 src/acpi/einj/einj.c

diff --git a/src/Makefile.am b/src/Makefile.am
index dbef055..7abe31b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -48,6 +48,7 @@ fwts_SOURCES = main.c 				\
 	acpi/dbg2/dbg2.c 			\
 	acpi/dmar/dmar.c 			\
 	acpi/ecdt/ecdt.c			\
+	acpi/einj/einj.c			\
 	acpi/erst/erst.c			\
 	acpi/facs/facs.c 			\
 	acpi/fadt/fadt.c 			\
diff --git a/src/acpi/einj/einj.c b/src/acpi/einj/einj.c
new file mode 100644
index 0000000..95f5950
--- /dev/null
+++ b/src/acpi/einj/einj.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2016 Canonical
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#include "fwts.h"
+#include "fwts_acpi_object_eval.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <string.h>
+#include <ctype.h>
+
+
+static fwts_acpi_table_info *table;
+
+static int einj_init(fwts_framework *fw)
+{
+	if (fwts_acpi_find_table(fw, "EINJ", 0, &table) != FWTS_OK) {
+		fwts_log_error(fw, "Cannot read ACPI tables.");
+		return FWTS_ERROR;
+	}
+	if (table == NULL || (table && table->length == 0)) {
+		fwts_log_error(fw, "ACPI EINJ table does not exist, skipping test");
+		return FWTS_SKIP;
+	}
+	return FWTS_OK;
+}
+
+/*
+ *  EINJ Error Injection Table
+ */
+static int einj_test1(fwts_framework *fw)
+{
+	ACPI_TABLE_EINJ *einj = (ACPI_TABLE_EINJ *)table->data;
+	uint32_t reserved = 0, i;
+	bool passed = true;
+
+	reserved = einj->Reserved[0] + (einj->Reserved[1] >> 1) + (einj->Reserved[2] >> 2);
+
+	fwts_log_info_verbatum(fw, "EINJ Error Injection Table:");
+	fwts_log_info_verbatum(fw, "  Injection Header Size: 0x%8.8" PRIX32, einj->HeaderLength);
+	fwts_log_info_verbatum(fw, "  Injection Flags:       0x%8.8" PRIX32, einj->Flags);
+	fwts_log_info_verbatum(fw, "  Reserved:              0x%8.8" PRIX32, reserved);
+	fwts_log_info_verbatum(fw, "  Injection Entry Count: 0x%8.8" PRIX32, einj->Entries);
+
+	if (einj->Flags) {
+		fwts_failed(fw, LOG_LEVEL_LOW,
+			"EINJFlagNonZero",
+			"EINJ Injection Flags field must be zero, got 0x%" PRIX8
+			" instead", einj->Flags);
+		passed = false;
+	}
+
+	if (reserved) {
+		fwts_failed(fw, LOG_LEVEL_LOW,
+			"EINJReservedNonZero",
+			"EINJ Reserved field must be zero, got 0x%" PRIX32 " instead", reserved);
+		passed = false;
+	}
+
+	fwts_log_nl(fw);
+
+	for (i = 0; i < einj->Entries; i++) {
+		ACPI_EINJ_ENTRY *entry = (ACPI_EINJ_ENTRY *)((char *) einj + 48 + i * sizeof(ACPI_EINJ_ENTRY));
+		ACPI_GENERIC_ADDRESS gas = entry->WheaHeader.RegisterRegion;
+		fwts_log_info_verbatum(fw, "  Injection Instruction Entry %2.2" PRId8, i);
+		fwts_log_info_verbatum(fw, "    Injection Action      : 0x%2.2" PRIX8, entry->WheaHeader.Action);
+		fwts_log_info_verbatum(fw, "    Instruction           : 0x%2.2" PRIX8, entry->WheaHeader.Instruction);
+		fwts_log_info_verbatum(fw, "    Flags                 : 0x%2.2" PRIX8, entry->WheaHeader.Flags);
+		fwts_log_info_verbatum(fw, "    Reserved              : 0x%2.2" PRIX8, entry->WheaHeader.Reserved);
+		fwts_log_info_verbatum(fw, "    Register Region       : [Generic Address Structure]");
+		fwts_log_info_verbatum(fw, "      Address Space ID    : 0x%2.2" PRIX8, gas.SpaceId);
+		fwts_log_info_verbatum(fw, "      Register Bit Width  : 0x%2.2" PRIX8, gas.BitWidth);
+		fwts_log_info_verbatum(fw, "      Register Bit Offset : 0x%2.2" PRIX8, gas.BitOffset);
+		fwts_log_info_verbatum(fw, "      Access Size         : 0x%2.2" PRIX8, gas.AccessWidth);
+		fwts_log_info_verbatum(fw, "      Address             : 0x%16.16" PRIX64, gas.Address);
+		fwts_log_info_verbatum(fw, "    Value                 : 0x%16.16" PRIX64, entry->WheaHeader.Value);
+		fwts_log_info_verbatum(fw, "    Mask                  : 0x%16.16" PRIX64, entry->WheaHeader.Mask);
+
+		if (entry->WheaHeader.Action > 0x8 && entry->WheaHeader.Action != 0xFF) {
+				fwts_failed(fw, LOG_LEVEL_MEDIUM,
+					"EINJBadInjectionAction",
+					"EINJ Injection Action must be within 0~8 or 0xFF, got 0x%" PRIX8
+					" instead", entry->WheaHeader.Action);
+				passed = false;
+		}
+
+		if (entry->WheaHeader.Instruction > 0x4) {
+				fwts_failed(fw, LOG_LEVEL_MEDIUM,
+					"EINJBadInstruction",
+					"EINJ Instruction must be within 0~4, got 0x%" PRIX8
+					" instead", entry->WheaHeader.Instruction);
+				passed = false;
+		}
+
+		if (gas.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY &&
+			  gas.SpaceId != ACPI_ADR_SPACE_SYSTEM_IO) {
+				fwts_failed(fw, LOG_LEVEL_MEDIUM,
+					"EINJBadSpaceId",
+					"EINJ Address_Space_ID must be within 0 or 1, got 0x%" PRIX8
+					" instead", gas.SpaceId);
+				passed = false;
+		}
+
+		fwts_log_nl(fw);
+	}
+
+	if (passed)
+		fwts_passed(fw, "No issues found in EINJ table.");
+
+	return FWTS_OK;
+}
+
+static fwts_framework_minor_test einj_tests[] = {
+	{ einj_test1, "EINJ Error Injection Table test." },
+	{ NULL, NULL }
+};
+
+static fwts_framework_ops einj_ops = {
+	.description = "EINJ Error Injection Table test.",
+	.init        = einj_init,
+	.minor_tests = einj_tests
+};
+
+FWTS_REGISTER("einj", &einj_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_BATCH | FWTS_FLAG_TEST_ACPI)
-- 
1.9.1




More information about the fwts-devel mailing list