diff mbox series

[1/2] acpi: skvl: add tests for ACPI SKVL table (mantis 2314)

Message ID 20240115033157.113046-1-ivan.hu@canonical.com
State Accepted
Headers show
Series [1/2] acpi: skvl: add tests for ACPI SKVL table (mantis 2314) | expand

Commit Message

Ivan Hu Jan. 15, 2024, 3:31 a.m. UTC
BugLink: https://bugs.launchpad.net/fwts/+bug/2047212
The ACPI SKVL(Storage Volume Key Location) table was added to ACPI6.5,
add tests for the SKVL table.

Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
---
 src/Makefile.am             |  3 +-
 src/acpi/skvl/skvl.c        | 80 +++++++++++++++++++++++++++++++++++++
 src/lib/include/fwts_acpi.h | 17 ++++++++
 3 files changed, 99 insertions(+), 1 deletion(-)
 create mode 100644 src/acpi/skvl/skvl.c
diff mbox series

Patch

diff --git a/src/Makefile.am b/src/Makefile.am
index ecb6d63a..0beb17f5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -144,7 +144,8 @@  fwts_SOURCES = main.c 				\
 	acpi/sbst/sbst.c			\
 	acpi/sdei/sdei.c			\
 	acpi/sdev/sdev.c			\
-	acpi/slic/slic.c 			\
+        acpi/skvl/skvl.c                        \
+        acpi/slic/slic.c                        \
 	acpi/slit/slit.c 			\
 	acpi/spcr/spcr.c 			\
 	acpi/spmi/spmi.c 			\
diff --git a/src/acpi/skvl/skvl.c b/src/acpi/skvl/skvl.c
new file mode 100644
index 00000000..9c4166b2
--- /dev/null
+++ b/src/acpi/skvl/skvl.c
@@ -0,0 +1,80 @@ 
+/*
+ * Copyright (C) 2024 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"
+
+#if defined(FWTS_HAS_ACPI)
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+static fwts_acpi_table_info *table;
+acpi_table_init(SKVL, &table)
+
+static int skvl_test1(fwts_framework *fw)
+{
+	fwts_acpi_skvl_key_struct *key_struct;
+	bool passed = true;
+	uint32_t offset;
+	fwts_acpi_table_skvl *skvl = (fwts_acpi_table_skvl *)table->data;
+
+	fwts_log_info_verbatim(fw, "Storage Volume Key Location Table:");
+	fwts_log_info_simp_int(fw, "  Key Count:    ", skvl->key_count);
+	fwts_log_nl(fw);
+
+	offset = sizeof(fwts_acpi_table_skvl);
+
+	for (uint32_t i = 0; i < skvl->key_count; i++) {
+		if ((offset + sizeof(fwts_acpi_skvl_key_struct)) > table->length) {
+			fwts_failed(fw, LOG_LEVEL_HIGH,
+			"SKVLOutOfRangeOffset",
+			"SKVL key structure offset is out of range.");
+			return FWTS_OK;
+		}
+		key_struct = (fwts_acpi_skvl_key_struct *)(table->data + offset);
+		fwts_log_info_verbatim(fw, "  Storage Volume Key Structure:     ");
+		fwts_log_info_simp_int(fw, "  Key Type:    ", key_struct->key_type);
+		fwts_acpi_fixed_value(fw, LOG_LEVEL_HIGH, "SKVL", "Key Type", key_struct->key_type, 0, &passed);
+		fwts_log_info_simp_int(fw, "  Key Format:  ", key_struct->key_format);
+		fwts_acpi_fixed_value(fw, LOG_LEVEL_HIGH, "SKVL", "Key Format", key_struct->key_format, 0, &passed);
+		fwts_log_info_simp_int(fw, "  Key Size:    ", key_struct->key_size);
+		fwts_log_info_simp_int(fw, "  Key Address: ", key_struct->key_address);
+
+		offset += sizeof(fwts_acpi_skvl_key_struct);
+		fwts_log_nl(fw);
+	}
+
+	if (passed)
+		fwts_passed(fw, "No issues found in SKVL table.");
+
+	return FWTS_OK;
+}
+
+static fwts_framework_minor_test skvl_tests[] = {
+	{ skvl_test1, "Validate SKVL table." },
+	{ NULL, NULL }
+};
+
+static fwts_framework_ops skvl_ops = {
+	.description = "SKVL Storage Volume Key Location Table test.",
+	.init        = SKVL_init,
+	.minor_tests = skvl_tests
+};
+
+FWTS_REGISTER("skvl", &skvl_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_BATCH | FWTS_FLAG_ACPI)
+
+#endif
diff --git a/src/lib/include/fwts_acpi.h b/src/lib/include/fwts_acpi.h
index e9d6b1dc..5ea01d35 100644
--- a/src/lib/include/fwts_acpi.h
+++ b/src/lib/include/fwts_acpi.h
@@ -2832,4 +2832,21 @@  typedef struct {
 	uint64_t		lasa;
 } __attribute__ ((packed)) fwts_acpi_table_ccel;
 
+/*
+ * Storage Volume Key Location Table
+ * ACPI6.5 5.2.35
+ */
+typedef struct {
+	uint16_t	key_type;
+	uint16_t	key_format;
+	uint32_t	key_size;
+	uint64_t	key_address;
+} __attribute__ ((packed)) fwts_acpi_skvl_key_struct;
+
+typedef struct {
+	fwts_acpi_table_header		header;
+	uint32_t			key_count;
+	fwts_acpi_skvl_key_struct 	key_struct[0];
+} __attribute__ ((packed)) fwts_acpi_table_skvl;
+
 #endif