From nobody Fri Mar 17 10:29:22 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PdL36442lz3yBYs; Fri, 17 Mar 2023 10:29:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PdL363Z5kz3GQ8; Fri, 17 Mar 2023 10:29:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679048962; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=llyASkX34nS7Sdu2R+GuZq0gWuMrQ4XOtt6niLsnrog=; b=KS0/zMghxQ0kqzpZgQP+tPe8LPA2p8CJc+u3wduXbQY3/pX+ciA4sjcR5K1/9KfrclQyLR E50thPDaON4o/qXCOnvwAzSnR6ohHpxv/2Pa2UxyZL2emIC0aAxkn7Snh0/WZASWB23q9h q5LrHrxXUdDdg7RQC7fr5rN6A5gdXalnSgwn8oTEYCrRKCBf87z68HrRgEfHyNuE8RoZhQ BfXW0Qsmm2nE2mafHreqKZLlnardaLYwIetEzaQdGXdOD5wNGzAQJp/TvMzU/zOi0w7VjY bP2K2OTqsajTTmXaDLSByOiSx1B8LYZlEmBqw/GiAcnu1fJxFNIOFcwUazmEMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679048962; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=llyASkX34nS7Sdu2R+GuZq0gWuMrQ4XOtt6niLsnrog=; b=tX7jOgFiZnLNfr7htVbB/JicUSGpzX3S/hCtCK30zfLAsY1Trotc3r9Mw8YbB12emmPzU5 Z+Z3v+T18wDoMAyqlSNl/3brLLOp1HvjywvnqLjRgrYur2ESpCmQoAn4TKbgfPynWwdFbV 4JKIiJ+EiOvbfWIYzLoqolSCrZkeuklJl3o85IHHZCAHmdnsvJ+rzCN6dNYzLeHkwIA12R Yu76yzRVCIf13UXPApOOIB2bP1pbSx499sjg7HzNoeWPqddX5umQuyoMz/aViiAMYPuvO/ gyWW/qaALJWjaMOBm5v+hzB4GMIF/QMa0XGn+AfxUmEEKuoqJ0UAU8InQAqmTA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679048962; a=rsa-sha256; cv=none; b=VQAIW7PBuIpRLCkNoh/czHB/qUPcmOZDSvhBsingrYV8HymnCJvch4W5lfQQLCB1LEG7a3 qeNe3pD6dB51b2MzaCJEFeto9r6hl+v1X2YX3cbtYCcV3sT1SrtYJe5To8CpQye4O3+JsG iL1b+fud7kpdb+9hjZ6oFNJtprMqrkyDcxrhF8/x4aa0nN7EBWUzzAhelKRprS0fIoA3A6 MqFCMdigYX8KkkbrIKaesMTvv5De6LJgyJ2EbJoxSE10+CrYKAqM3s+JQee5P5UPBgAgGU uMbiRzpwp2vkCbUMBRHlYQn622iLltdYW3tlwGfBDUN50mwrIR/Jzig3GvlZ/Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PdL362fhlzMZn; Fri, 17 Mar 2023 10:29:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32HATMC1067279; Fri, 17 Mar 2023 10:29:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32HATM81067277; Fri, 17 Mar 2023 10:29:22 GMT (envelope-from git) Date: Fri, 17 Mar 2023 10:29:22 GMT Message-Id: <202303171029.32HATM81067277@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: 02296919604f - stable/13 - bhyve: add common fwcfg items List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: corvink X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 02296919604f8df8e890d3c7f3b54e707270caf1 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=02296919604f8df8e890d3c7f3b54e707270caf1 commit 02296919604f8df8e890d3c7f3b54e707270caf1 Author: Corvin Köhne AuthorDate: 2021-08-11 08:02:57 +0000 Commit: Corvin Köhne CommitDate: 2023-03-17 10:26:32 +0000 bhyve: add common fwcfg items Qemu defines some common fwcfg items. We don't need to support all of them. Only a subset needs to be present for fwcfg to work properly. - signature The signature is used by the guest to check if qemu's fwcfg is available or not. - id The id is used by the guest to check which features are supported by the fwcfg implementation of the hypervisor. - file_dir The file dir reports all fwcfg items which don't have a fixed index. These are mostly user defined fwcfg items. Reviewed by: MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D38335 (cherry picked from commit 34f804e547e7c3b10b12f5450ff2e0a771000daf) --- usr.sbin/bhyve/qemu_fwcfg.c | 99 +++++++++++++++++++++++++++++++++++++++++++++ usr.sbin/bhyve/qemu_fwcfg.h | 1 + 2 files changed, 100 insertions(+) diff --git a/usr.sbin/bhyve/qemu_fwcfg.c b/usr.sbin/bhyve/qemu_fwcfg.c index 8cb71b819956..e1a67fd0d8ef 100644 --- a/usr.sbin/bhyve/qemu_fwcfg.c +++ b/usr.sbin/bhyve/qemu_fwcfg.c @@ -6,6 +6,7 @@ */ #include +#include #include @@ -38,6 +39,12 @@ #define QEMU_FWCFG_ARCHITECTURE_GENERIC 0 #define QEMU_FWCFG_ARCHITECTURE_SPECIFIC 1 +#define QEMU_FWCFG_INDEX_SIGNATURE 0x00 +#define QEMU_FWCFG_INDEX_ID 0x01 +#define QEMU_FWCFG_INDEX_FILE_DIR 0x19 + +#define QEMU_FWCFG_MIN_FILES 10 + #pragma pack(1) union qemu_fwcfg_selector { @@ -49,6 +56,28 @@ union qemu_fwcfg_selector { uint16_t bits; }; +struct qemu_fwcfg_signature { + uint8_t signature[4]; +}; + +struct qemu_fwcfg_id { + uint32_t interface : 1; /* always set */ + uint32_t DMA : 1; + uint32_t reserved : 30; +}; + +struct qemu_fwcfg_file { + uint32_t be_size; + uint16_t be_selector; + uint16_t reserved; + uint8_t name[QEMU_FWCFG_MAX_NAME]; +}; + +struct qemu_fwcfg_directory { + uint32_t be_count; + struct qemu_fwcfg_file files[0]; +}; + #pragma pack() struct qemu_fwcfg_softc { @@ -155,6 +184,62 @@ qemu_fwcfg_add_item(const uint16_t architecture, const uint16_t index, return (0); } +static int +qemu_fwcfg_add_item_file_dir(void) +{ + const size_t size = sizeof(struct qemu_fwcfg_directory) + + QEMU_FWCFG_MIN_FILES * sizeof(struct qemu_fwcfg_file); + struct qemu_fwcfg_directory *const fwcfg_directory = calloc(1, size); + if (fwcfg_directory == NULL) { + return (ENOMEM); + } + + fwcfg_sc.directory = fwcfg_directory; + + return (qemu_fwcfg_add_item(QEMU_FWCFG_ARCHITECTURE_GENERIC, + QEMU_FWCFG_INDEX_FILE_DIR, sizeof(struct qemu_fwcfg_directory), + (uint8_t *)fwcfg_sc.directory)); +} + +static int +qemu_fwcfg_add_item_id(void) +{ + struct qemu_fwcfg_id *const fwcfg_id = calloc(1, + sizeof(struct qemu_fwcfg_id)); + if (fwcfg_id == NULL) { + return (ENOMEM); + } + + fwcfg_id->interface = 1; + fwcfg_id->DMA = 0; + + uint32_t *const le_fwcfg_id_ptr = (uint32_t *)fwcfg_id; + *le_fwcfg_id_ptr = htole32(*le_fwcfg_id_ptr); + + return (qemu_fwcfg_add_item(QEMU_FWCFG_ARCHITECTURE_GENERIC, + QEMU_FWCFG_INDEX_ID, sizeof(struct qemu_fwcfg_id), + (uint8_t *)fwcfg_id)); +} + +static int +qemu_fwcfg_add_item_signature(void) +{ + struct qemu_fwcfg_signature *const fwcfg_signature = calloc(1, + sizeof(struct qemu_fwcfg_signature)); + if (fwcfg_signature == NULL) { + return (ENOMEM); + } + + fwcfg_signature->signature[0] = 'Q'; + fwcfg_signature->signature[1] = 'E'; + fwcfg_signature->signature[2] = 'M'; + fwcfg_signature->signature[3] = 'U'; + + return (qemu_fwcfg_add_item(QEMU_FWCFG_ARCHITECTURE_GENERIC, + QEMU_FWCFG_INDEX_SIGNATURE, sizeof(struct qemu_fwcfg_signature), + (uint8_t *)fwcfg_signature)); +} + static int qemu_fwcfg_register_port(const char *const name, const int port, const int size, const int flags, const inout_func_t handler) @@ -209,6 +294,20 @@ qemu_fwcfg_init(struct vmctx *const ctx) goto done; } + /* add common fwcfg items */ + if ((error = qemu_fwcfg_add_item_signature()) != 0) { + warnx("%s: Unable to add signature item", __func__); + goto done; + } + if ((error = qemu_fwcfg_add_item_id()) != 0) { + warnx("%s: Unable to add id item", __func__); + goto done; + } + if ((error = qemu_fwcfg_add_item_file_dir()) != 0) { + warnx("%s: Unable to add file_dir item", __func__); + goto done; + } + done: if (error) { acpi_device_destroy(fwcfg_sc.acpi_dev); diff --git a/usr.sbin/bhyve/qemu_fwcfg.h b/usr.sbin/bhyve/qemu_fwcfg.h index 58ef5ed3c6bf..b5454fa9977d 100644 --- a/usr.sbin/bhyve/qemu_fwcfg.h +++ b/usr.sbin/bhyve/qemu_fwcfg.h @@ -11,6 +11,7 @@ #define QEMU_FWCFG_MAX_ARCHS 0x2 #define QEMU_FWCFG_MAX_ENTRIES 0x4000 +#define QEMU_FWCFG_MAX_NAME 56 struct qemu_fwcfg_item { uint32_t size;