[PATCH 1/3][v2] acpi: add MSCT table sanity check

Alex Hung alex.hung at canonical.com
Tue Apr 19 13:30:16 UTC 2016


Signed-off-by: Alex Hung <alex.hung at canonical.com>
---
 src/Makefile.am             |   1 +
 src/acpi/msct/msct.c        | 132 ++++++++++++++++++++++++++++++++++++++++++++
 src/lib/include/fwts_acpi.h |  22 ++++++++
 3 files changed, 155 insertions(+)
 create mode 100644 src/acpi/msct/msct.c

diff --git a/src/Makefile.am b/src/Makefile.am
index afe7323..9688f0e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -63,6 +63,7 @@ fwts_SOURCES = main.c 				\
 	acpi/madt/madt.c			\
 	acpi/mcfg/mcfg.c 			\
 	acpi/mchi/mchi.c 			\
+	acpi/msct/msct.c 			\
 	acpi/msdm/msdm.c 			\
 	acpi/method/method.c 			\
 	acpi/osilinux/osilinux.c 		\
diff --git a/src/acpi/msct/msct.c b/src/acpi/msct/msct.c
new file mode 100644
index 0000000..9432cf6
--- /dev/null
+++ b/src/acpi/msct/msct.c
@@ -0,0 +1,132 @@
+/*
+ * 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 msct_init(fwts_framework *fw)
+{
+	if (fwts_acpi_find_table(fw, "MSCT", 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 MSCT table does not exist, skipping test");
+		return FWTS_SKIP;
+	}
+	return FWTS_OK;
+}
+
+/*
+ *  MSCT Maximum System Characteristics Table
+ */
+static int msct_test1(fwts_framework *fw)
+{
+	fwts_acpi_table_msct *msct = (fwts_acpi_table_msct*) table->data;
+	fwts_acpi_msct_proximity *proximity;
+	uint32_t num_proximity = 0, offset_proximity = 0;
+	uint32_t i;
+	bool passed = true;
+
+	fwts_log_info_verbatum(fw, "MSCT Max System Characteristics Table:");
+	fwts_log_info_verbatum(fw, "  Proximity Offset:      0x%8.8" PRIx32,
+			msct->proximity_offset);
+	fwts_log_info_verbatum(fw, "  Max Proximity Domains: 0x%8.8" PRIx32,
+			msct->max_proximity_domains);
+	fwts_log_info_verbatum(fw, "  Max Clock Domains:     0x%8.8" PRIx32,
+			msct->max_clock_domains);
+	fwts_log_info_verbatum(fw, "  Max Physical Address:  0x%16.16" PRIx64,
+			msct->max_address);
+
+	if (msct->proximity_offset < 0x38) {
+		fwts_failed(fw, LOG_LEVEL_MEDIUM,
+			"MSCTBadProximityOffset",
+			"Proximity Domain Information Structures need to be at "
+			"Offset 0x38 or after, but Proximity Offsetis is 0x%"
+			PRIx32, msct->proximity_offset);
+		offset_proximity = 0x38;
+		passed = false;
+	} else
+		offset_proximity = msct->proximity_offset;
+
+	if (offset_proximity + sizeof(fwts_acpi_msct_proximity) *
+		msct->max_proximity_domains > msct->header.length) {
+		fwts_failed(fw, LOG_LEVEL_MEDIUM,
+			"MSCTBadTableLength",
+			"MSCT Table is too small to include maximum number of "
+			"Proximity Domains");
+		passed = false;
+	}
+
+	num_proximity = (msct->header.length - offset_proximity) /
+			sizeof(fwts_acpi_msct_proximity);
+
+	if (num_proximity > msct->max_proximity_domains + 1) {
+		fwts_failed(fw, LOG_LEVEL_MEDIUM,
+			"MSCTBadProimityDomains",
+			"MSCT's max number of proximity domains is 0x%" PRIx32
+			", but it has 0x%" PRIx32 " Proximity Domain "
+			"Information Structures",
+			msct->max_proximity_domains, num_proximity);
+		passed = false;
+	}
+
+	fwts_log_nl(fw);
+
+	proximity = (fwts_acpi_msct_proximity *)((char *) msct + offset_proximity);
+	for (i = 0; i < num_proximity; i++, proximity++) {
+		fwts_log_info_verbatum(fw, "  Proximity Domain %2.2" PRIu8, i);
+		fwts_log_info_verbatum(fw, "    Revision:               0x%2.2"
+				PRIx8, proximity->revision);
+		fwts_log_info_verbatum(fw, "    Length:                 0x%2.2"
+				PRIx8,	proximity->length);
+		fwts_log_info_verbatum(fw, "    Domain Range (low):     0x%8.8"
+				PRIx32, proximity->range_start);
+		fwts_log_info_verbatum(fw, "    Domain Range (high):    0x%8.8"
+				PRIx32, proximity->range_end);
+		fwts_log_info_verbatum(fw, "    Max Processor Capacity: 0x%8.8"
+				PRIx32, proximity->processor_capacity);
+		fwts_log_info_verbatum(fw, "    Max Memory Capacity:    "
+				"0x%16.16" PRIx64, proximity->memory_capacity);
+		fwts_log_nl(fw);
+	}
+
+	if (passed)
+		fwts_passed(fw, "No issues found in MSCT table.");
+
+	return FWTS_OK;
+}
+
+static fwts_framework_minor_test msct_tests[] = {
+	{ msct_test1, "MSCT Maximum System Characteristics Table test." },
+	{ NULL, NULL }
+};
+
+static fwts_framework_ops msct_ops = {
+	.description = "MSCT Maximum System Characteristics Table test.",
+	.init        = msct_init,
+	.minor_tests = msct_tests
+};
+
+FWTS_REGISTER("msct", &msct_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_BATCH |
+	      FWTS_FLAG_TEST_ACPI)
diff --git a/src/lib/include/fwts_acpi.h b/src/lib/include/fwts_acpi.h
index 64dcd91..666b6cd 100644
--- a/src/lib/include/fwts_acpi.h
+++ b/src/lib/include/fwts_acpi.h
@@ -166,6 +166,28 @@ typedef struct {
 } __attribute__ ((packed)) fwts_acpi_table_cpep;
 
 /*
+ * ACPI MSCT (Maximum System Characteristics Table), 5.2.19
+ */
+
+typedef struct {
+	uint8_t		revision;
+	uint8_t		length;
+	uint32_t	range_start;
+	uint32_t	range_end;
+	uint32_t	processor_capacity;
+	uint64_t	memory_capacity;
+} __attribute__ ((packed)) fwts_acpi_msct_proximity;
+
+typedef struct {
+	fwts_acpi_table_header	 header;
+	uint32_t		 proximity_offset;
+	uint32_t		 max_proximity_domains;
+	uint32_t		 max_clock_domains;
+	uint64_t		 max_address;
+	fwts_acpi_msct_proximity msct_proximity[0];
+} __attribute__ ((packed)) fwts_acpi_table_msct;
+
+/*
  * ACPI ECDT (Embedded Controller Boot Resources Table), 5.2.15
  */
 typedef struct {
-- 
2.5.0




More information about the fwts-devel mailing list