git: ac3c2b3e38fb - main - bhyve: add table dump functions for basl

From: Corvin Köhne <corvink_at_FreeBSD.org>
Date: Tue, 15 Nov 2022 07:28:04 UTC
The branch main has been updated by corvink:

URL: https://cgit.FreeBSD.org/src/commit/?id=ac3c2b3e38fb03b0d0e26ffa0527735575984ba2

commit ac3c2b3e38fb03b0d0e26ffa0527735575984ba2
Author:     Corvin Köhne <corvink@FreeBSD.org>
AuthorDate: 2022-11-04 11:26:34 +0000
Commit:     Corvin Köhne <corvink@FreeBSD.org>
CommitDate: 2022-11-15 07:27:04 +0000

    bhyve: add table dump functions for basl
    
    Developing an ACPI table compiler isn't quite easy. It's helpful if you
    can take a look at the ACPI tables created by the compiler.
    
    The dump functions can either dump a ACPI table which was copied into
    guest memory or a ACPI table provided for qemu's ACPI table loader.
    
    Reviewed by:            jhb, markj
    Approved by:            manu (mentor)
    MFC after:              2 weeks
    Sponsored by:           Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D36985
---
 usr.sbin/bhyve/basl.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/usr.sbin/bhyve/basl.c b/usr.sbin/bhyve/basl.c
index f24d8c009110..655c6e509dc4 100644
--- a/usr.sbin/bhyve/basl.c
+++ b/usr.sbin/bhyve/basl.c
@@ -14,6 +14,7 @@
 
 #include <assert.h>
 #include <err.h>
+#include <libutil.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <vmmapi.h>
@@ -32,6 +33,41 @@ struct basl_table {
 static STAILQ_HEAD(basl_table_list, basl_table) basl_tables = STAILQ_HEAD_INITIALIZER(
     basl_tables);
 
+static int
+basl_dump_table(const struct basl_table *const table, const bool mem)
+{
+	const ACPI_TABLE_HEADER *const header = table->data;
+	const uint8_t *data;
+
+	if (!mem) {
+		data = table->data;
+	} else {
+		data = vm_map_gpa(table->ctx, BHYVE_ACPI_BASE + table->off,
+		    table->len);
+		if (data == NULL) {
+			return (ENOMEM);
+		}
+	}
+
+	printf("%.4s @ %8x (%s)\n", header->Signature,
+	    BHYVE_ACPI_BASE + table->off, mem ? "Memory" : "FwCfg");
+	hexdump(data, table->len, NULL, 0);
+
+	return (0);
+}
+
+static int
+basl_dump(const bool mem)
+{
+	struct basl_table *table;
+
+	STAILQ_FOREACH(table, &basl_tables, chain) {
+		BASL_EXEC(basl_dump_table(table, mem));
+	}
+
+	return (0);
+}
+
 static int
 basl_finish_install_guest_tables(struct basl_table *const table)
 {