Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Feb 2023 10:14:13 GMT
From:      =?utf-8?Q?Corvin=20K=C3=B6hne?= <corvink@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: bd8366500e15 - stable/13 - bhyve: add emulation for the qemu fwcfg selector port
Message-ID:  <202302281014.31SAEDvN013819@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by corvink:

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

commit bd8366500e15e6aa840e80d21661d5f3bf4d835e
Author:     Corvin Köhne <corvink@FreeBSD.org>
AuthorDate: 2021-08-11 07:59:16 +0000
Commit:     Corvin Köhne <corvink@FreeBSD.org>
CommitDate: 2023-02-28 10:04:36 +0000

    bhyve: add emulation for the qemu fwcfg selector port
    
    The selector port is used to select the desired fwcfg item.
    
    Reviewed by:            markj
    MFC after:              1 week
    Sponsored by:           Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D38332
    
    (cherry picked from commit 151d8131a817e7a6a629e9bb7fde4d7a158e5211)
---
 usr.sbin/bhyve/qemu_fwcfg.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/usr.sbin/bhyve/qemu_fwcfg.c b/usr.sbin/bhyve/qemu_fwcfg.c
index 5d3070abf285..dec3fa83c493 100644
--- a/usr.sbin/bhyve/qemu_fwcfg.c
+++ b/usr.sbin/bhyve/qemu_fwcfg.c
@@ -29,8 +29,33 @@
 #define QEMU_FWCFG_DATA_PORT_FLAGS \
 	IOPORT_F_INOUT /* QEMU v2.4+ ignores writes */
 
+#define QEMU_FWCFG_ARCHITECTURE_MASK 0x0001
+#define QEMU_FWCFG_INDEX_MASK 0x3FFF
+
+#define QEMU_FWCFG_SELECT_READ 0
+#define QEMU_FWCFG_SELECT_WRITE 1
+
+#define QEMU_FWCFG_ARCHITECTURE_GENERIC 0
+#define QEMU_FWCFG_ARCHITECTURE_SPECIFIC 1
+
+#pragma pack(1)
+
+union qemu_fwcfg_selector {
+	struct {
+		uint16_t index : 14;
+		uint16_t writeable : 1;
+		uint16_t architecture : 1;
+	};
+	uint16_t bits;
+};
+
+#pragma pack()
+
 struct qemu_fwcfg_softc {
 	struct acpi_device *acpi_dev;
+
+	uint32_t data_offset;
+	union qemu_fwcfg_selector selector;
 };
 
 static struct qemu_fwcfg_softc fwcfg_sc;
@@ -40,6 +65,20 @@ qemu_fwcfg_selector_port_handler(struct vmctx *const ctx __unused, const int in,
     const int port __unused, const int bytes, uint32_t *const eax,
     void *const arg __unused)
 {
+	if (bytes != sizeof(uint16_t)) {
+		warnx("%s: invalid size (%d) of IO port access", __func__,
+		    bytes);
+		return (-1);
+	}
+
+	if (in) {
+		*eax = htole16(fwcfg_sc.selector.bits);
+		return (0);
+	}
+
+	fwcfg_sc.data_offset = 0;
+	fwcfg_sc.selector.bits = le16toh(*eax);
+
 	return (0);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202302281014.31SAEDvN013819>