git: 995374a6553d - main - bhyve: add basl support for generic addresses

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

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

commit 995374a6553dbdfbdaffbc5f5a5ceff08a437cd7
Author:     Corvin Köhne <corvink@FreeBSD.org>
AuthorDate: 2022-11-04 13:30:53 +0000
Commit:     Corvin Köhne <corvink@FreeBSD.org>
CommitDate: 2022-11-15 07:27:08 +0000

    bhyve: add basl support for generic addresses
    
    In upcoming commits, bhyve will build some ACPI tables by it's own.
    Therefore, it should be capable of appending GENERIC_ADDRESS structs to
    ACPI tables.
    
    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/D36988
---
 usr.sbin/bhyve/basl.c | 16 ++++++++++++++++
 usr.sbin/bhyve/basl.h | 10 ++++++++++
 2 files changed, 26 insertions(+)

diff --git a/usr.sbin/bhyve/basl.c b/usr.sbin/bhyve/basl.c
index b3a561f51571..7dfeb8d2acb3 100644
--- a/usr.sbin/bhyve/basl.c
+++ b/usr.sbin/bhyve/basl.c
@@ -156,6 +156,22 @@ basl_table_append_bytes(struct basl_table *const table, const void *const bytes,
 	return (0);
 }
 
+int
+basl_table_append_gas(struct basl_table *const table, const uint8_t space_id,
+    const uint8_t bit_width, const uint8_t bit_offset,
+    const uint8_t access_width, const uint64_t address)
+{
+	ACPI_GENERIC_ADDRESS gas_le = {
+		.SpaceId = space_id,
+		.BitWidth = bit_width,
+		.BitOffset = bit_offset,
+		.AccessWidth = access_width,
+		.Address = htole64(address),
+	};
+
+	return (basl_table_append_bytes(table, &gas_le, sizeof(gas_le)));
+}
+
 int
 basl_table_append_int(struct basl_table *const table, const uint64_t val,
     const uint8_t size)
diff --git a/usr.sbin/bhyve/basl.h b/usr.sbin/bhyve/basl.h
index 3ce33dea63e0..95164e98ed7a 100644
--- a/usr.sbin/bhyve/basl.h
+++ b/usr.sbin/bhyve/basl.h
@@ -8,6 +8,13 @@
 
 #include <contrib/dev/acpica/include/acpi.h>
 
+#define ACPI_GAS_ACCESS_WIDTH_LEGACY 0
+#define ACPI_GAS_ACCESS_WIDTH_UNDEFINED 0
+#define ACPI_GAS_ACCESS_WIDTH_BYTE 1
+#define ACPI_GAS_ACCESS_WIDTH_WORD 2
+#define ACPI_GAS_ACCESS_WIDTH_DWORD 3
+#define ACPI_GAS_ACCESS_WIDTH_QWORD 4
+
 #define BHYVE_ACPI_BASE 0xf2400
 
 #define BASL_TABLE_ALIGNMENT 0x10
@@ -32,6 +39,9 @@ int basl_finish(void);
 int basl_init(void);
 int basl_table_append_bytes(struct basl_table *table, const void *bytes,
     uint32_t len);
+int basl_table_append_gas(struct basl_table *table, uint8_t space_id,
+    uint8_t bit_width, uint8_t bit_offset, uint8_t access_width,
+    uint64_t address);
 int basl_table_append_int(struct basl_table *table, uint64_t val, uint8_t size);
 int basl_table_create(struct basl_table **table, struct vmctx *ctx,
     const uint8_t *name, uint32_t alignment, uint32_t off);