diff options
author | Corvin Köhne <corvink@FreeBSD.org> | 2021-08-11 08:01:19 +0000 |
---|---|---|
committer | Corvin Köhne <corvink@FreeBSD.org> | 2023-02-28 12:37:03 +0000 |
commit | 3ef46195ac37111ab247cfabed735d3ee5e7f5b5 (patch) | |
tree | ee64edabbfcff51d09e5d70e65e03d5396503647 | |
parent | 2c33b456ff24d04d83690327a777d21a6a0a0a33 (diff) | |
download | src-3ef46195ac37111ab247cfabed735d3ee5e7f5b5.tar.gz src-3ef46195ac37111ab247cfabed735d3ee5e7f5b5.zip |
bhyve: add helper to add fwcfg items
This helper makes it easier to add multiple fwcfg items. You can pass an
index and some data to the helper. The helper adds these information to
the fwcfg emulation so that the guest reads the given data on the
specified index.
Reviewed by: <If someone else reviewed your modification.>
MFC after: 1 week
Sponsored by: Beckhoff Automation GmbH & Co. KG
Differential Revision: https://reviews.freebsd.org/D38334
-rw-r--r-- | usr.sbin/bhyve/qemu_fwcfg.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/usr.sbin/bhyve/qemu_fwcfg.c b/usr.sbin/bhyve/qemu_fwcfg.c index 13e21daca7ff..8cb71b819956 100644 --- a/usr.sbin/bhyve/qemu_fwcfg.c +++ b/usr.sbin/bhyve/qemu_fwcfg.c @@ -131,6 +131,31 @@ qemu_fwcfg_data_port_handler(struct vmctx *const ctx __unused, const int in, } static int +qemu_fwcfg_add_item(const uint16_t architecture, const uint16_t index, + const uint32_t size, void *const data) +{ + /* truncate architecture and index to their desired size */ + const uint16_t arch = architecture & QEMU_FWCFG_ARCHITECTURE_MASK; + const uint16_t idx = index & QEMU_FWCFG_INDEX_MASK; + + /* get pointer to item specified by selector */ + struct qemu_fwcfg_item *const fwcfg_item = &fwcfg_sc.items[arch][idx]; + + /* check if item is already used */ + if (fwcfg_item->data != NULL) { + warnx("%s: qemu fwcfg item exists (architecture %s index 0x%x)", + __func__, arch ? "specific" : "generic", idx); + return (-1); + } + + /* save data of the item */ + fwcfg_item->size = size; + fwcfg_item->data = data; + + return (0); +} + +static int qemu_fwcfg_register_port(const char *const name, const int port, const int size, const int flags, const inout_func_t handler) { |