git: e46be58cca6b - main - bhyve: add QEMU_FWCFG_INDEX_NB_CPUS item

From: Corvin Köhne <corvink_at_FreeBSD.org>
Date: Tue, 04 Apr 2023 08:26:21 UTC
The branch main has been updated by corvink:

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

commit e46be58cca6bd180dadfb36e98a673ae6d8d2cd1
Author:     Corvin Köhne <corvink@FreeBSD.org>
AuthorDate: 2022-06-27 09:05:42 +0000
Commit:     Corvin Köhne <corvink@FreeBSD.org>
CommitDate: 2023-04-04 08:26:15 +0000

    bhyve: add QEMU_FWCFG_INDEX_NB_CPUS item
    
    Requested-by:           OVMF (qemu)
    Reviewed by:            markj
    MFC after:              1 week
    Sponsored by:           Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D39316
---
 usr.sbin/bhyve/qemu_fwcfg.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/usr.sbin/bhyve/qemu_fwcfg.c b/usr.sbin/bhyve/qemu_fwcfg.c
index 1da0a42819b8..01010a64d3f7 100644
--- a/usr.sbin/bhyve/qemu_fwcfg.c
+++ b/usr.sbin/bhyve/qemu_fwcfg.c
@@ -42,6 +42,7 @@
 
 #define QEMU_FWCFG_INDEX_SIGNATURE 0x00
 #define QEMU_FWCFG_INDEX_ID 0x01
+#define QEMU_FWCFG_INDEX_NB_CPUS 0x05
 #define QEMU_FWCFG_INDEX_FILE_DIR 0x19
 
 #define QEMU_FWCFG_FIRST_FILE_INDEX 0x20
@@ -225,6 +226,20 @@ qemu_fwcfg_add_item_id(void)
 	    (uint8_t *)fwcfg_id));
 }
 
+static int
+qemu_fwcfg_add_item_nb_cpus(void)
+{
+	uint16_t *fwcfg_max_cpus = calloc(1, sizeof(uint16_t));
+	if (fwcfg_max_cpus == NULL) {
+		return (ENOMEM);
+	}
+
+	*fwcfg_max_cpus = htole16(guest_ncpus);
+
+	return (qemu_fwcfg_add_item(QEMU_FWCFG_ARCHITECTURE_GENERIC,
+	    QEMU_FWCFG_INDEX_NB_CPUS, sizeof(uint16_t), fwcfg_max_cpus));
+}
+
 static int
 qemu_fwcfg_add_item_signature(void)
 {
@@ -408,6 +423,10 @@ qemu_fwcfg_init(struct vmctx *const ctx)
 		warnx("%s: Unable to add id item", __func__);
 		goto done;
 	}
+	if ((error = qemu_fwcfg_add_item_nb_cpus()) != 0) {
+		warnx("%s: Unable to add nb_cpus item", __func__);
+		goto done;
+	}
 	if ((error = qemu_fwcfg_add_item_file_dir()) != 0) {
 		warnx("%s: Unable to add file_dir item", __func__);
 		goto done;