From nobody Tue Feb 14 07:29:12 2023 X-Original-To: dev-commits-src-all@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 4PGCWX4XhNz3rLB6; Tue, 14 Feb 2023 07:29:12 +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 4PGCWX2F5Wz4P2Y; Tue, 14 Feb 2023 07:29:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676359752; 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=UpkmOcBFHwXrtAI2yCvsSW9fh6G6yytzHM/jvb/0zT0=; b=eaviiDCdQu33dBHAG/I3RopGN5wEzNpRFBwHT0Mt9DXxOHkHpxR23MbjFAaww9LhEHEL5y QZNOmwUKLPZDel91aBoqIHl/SfEOMxTwoy0FQmg5iBpCPBZ+h9Nqfb7vRFQ9CAA+NO3zod mDw1R/xqMX6Ssp18ntVd7yu+f/LjK80Bn8xdWWsmzookz9bL+YeHYL/vaFl4DCztrFMCJo PYXq9yWkJnMdxh9bNa2l2zq3TfjPvSeC0d9r8tWhxecoixATHc1CCDywhLlW7u+yoy+qEL ebcJGVReNNDHem4H3mIgwoxPEsQeB2sFWnrgYIn5iofWdmLizbTGWTt0gCXzXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676359752; 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=UpkmOcBFHwXrtAI2yCvsSW9fh6G6yytzHM/jvb/0zT0=; b=h9GuA+6n6SeyfA/sMtQe6Z3EDWDSbVJ7SYl68YjPZe/qFaGw81S4vjt8mB1DJGViH7dH6E wY4sPMZsg2RM8M906TidrtONAhIDCnLEpFBR8uutjiJIuweGitHp9HS209FP6Ov6ah4EY3 WzAU9doXIB40uksv/GZXjeSbkPynf1e0SCjE4tE7ZNGPJzUoSuViYJBE5kdHe6dYT6otzY V65PaUusl5rkXrebB+RiCttWJKcz9sGjXI5VzBTj4RDYDEtT12nhVm2Icz000sb/W0/6Q9 ZBcE6LQt+amMNyFyQTQ9xc1gSuMkb8s7XZT+qJzjzqId2L8MwoyasTCy1HO2QA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676359752; a=rsa-sha256; cv=none; b=ImkrTiSVXtKGtV4iiE6CE0q79akhIn3xzOm50nPGCYV5bPJHAqShyZBXGm51zJCHXmQu/7 Ppanyu32wmdYa9eljT4CdzvpAXrqElEN/xa/Q0JGJBJVkZlizn4z6PK59Z/BiANbYaoChy UTUqC/PUVQi71G9kRN19awCTO17Y07cCCgOlwAY2F6fv5Eg3m9Z2XlHchJeY60URaMqMmn tI1qCnLFaoLIRoEBIoqJ+5HEK8zPS1cy2iS3e0lC8JUqkM//FSpqtSha8/PjEnl50jHp3D kBR4ff1Qn8wuSiXI/ZZBHind30lE1S2zj2AJi4phYK8fyXL6oK4gH1DtPgGI9Q== 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 4PGCWX1D6PzqSP; Tue, 14 Feb 2023 07:29:12 +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 31E7TCVG044068; Tue, 14 Feb 2023 07:29:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31E7TCwW044067; Tue, 14 Feb 2023 07:29:12 GMT (envelope-from git) Date: Tue, 14 Feb 2023 07:29:12 GMT Message-Id: <202302140729.31E7TCwW044067@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: 9b99de77f160 - main - bhyve: add basic qemu fwcfg implementation List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 9b99de77f16029dd55326e0210072b14ec1ad960 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=9b99de77f16029dd55326e0210072b14ec1ad960 commit 9b99de77f16029dd55326e0210072b14ec1ad960 Author: Corvin Köhne AuthorDate: 2021-08-11 07:58:15 +0000 Commit: Corvin Köhne CommitDate: 2023-02-14 07:28:37 +0000 bhyve: add basic qemu fwcfg implementation qemu's fwcfg and bhyve's fwctl are both used to configure ovmf. qemu's fwcfg is much more powerfull than bhyve's fwctl. For that reason, add support for qemu's fwcfg. Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D38331 --- usr.sbin/bhyve/qemu_fwcfg.c | 114 ++++++++++++++++++++++++++++++++++++++++++++ usr.sbin/bhyve/qemu_fwcfg.h | 12 +++++ 2 files changed, 126 insertions(+) diff --git a/usr.sbin/bhyve/qemu_fwcfg.c b/usr.sbin/bhyve/qemu_fwcfg.c new file mode 100644 index 000000000000..5d3070abf285 --- /dev/null +++ b/usr.sbin/bhyve/qemu_fwcfg.c @@ -0,0 +1,114 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 Beckhoff Automation GmbH & Co. KG + * Author: Corvin Köhne + */ + +#include + +#include + +#include +#include +#include +#include + +#include "acpi_device.h" +#include "inout.h" +#include "qemu_fwcfg.h" + +#define QEMU_FWCFG_ACPI_DEVICE_NAME "FWCF" +#define QEMU_FWCFG_ACPI_HARDWARE_ID "QEMU0002" + +#define QEMU_FWCFG_SELECTOR_PORT_NUMBER 0x510 +#define QEMU_FWCFG_SELECTOR_PORT_SIZE 1 +#define QEMU_FWCFG_SELECTOR_PORT_FLAGS IOPORT_F_INOUT +#define QEMU_FWCFG_DATA_PORT_NUMBER 0x511 +#define QEMU_FWCFG_DATA_PORT_SIZE 1 +#define QEMU_FWCFG_DATA_PORT_FLAGS \ + IOPORT_F_INOUT /* QEMU v2.4+ ignores writes */ + +struct qemu_fwcfg_softc { + struct acpi_device *acpi_dev; +}; + +static struct qemu_fwcfg_softc fwcfg_sc; + +static int +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) +{ + return (0); +} + +static int +qemu_fwcfg_data_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) +{ + 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) +{ + struct inout_port iop; + + bzero(&iop, sizeof(iop)); + iop.name = name; + iop.port = port; + iop.size = size; + iop.flags = flags; + iop.handler = handler; + + return (register_inout(&iop)); +} + +int +qemu_fwcfg_init(struct vmctx *const ctx) +{ + int error; + + error = acpi_device_create(&fwcfg_sc.acpi_dev, ctx, + QEMU_FWCFG_ACPI_DEVICE_NAME, QEMU_FWCFG_ACPI_HARDWARE_ID); + if (error) { + warnx("%s: failed to create ACPI device for QEMU FwCfg", + __func__); + goto done; + } + + error = acpi_device_add_res_fixed_ioport(fwcfg_sc.acpi_dev, + QEMU_FWCFG_SELECTOR_PORT_NUMBER, 2); + if (error) { + warnx("%s: failed to add fixed IO port for QEMU FwCfg", + __func__); + goto done; + } + + /* add handlers for fwcfg ports */ + if ((error = qemu_fwcfg_register_port("qemu_fwcfg_selector", + QEMU_FWCFG_SELECTOR_PORT_NUMBER, QEMU_FWCFG_SELECTOR_PORT_SIZE, + QEMU_FWCFG_SELECTOR_PORT_FLAGS, + qemu_fwcfg_selector_port_handler)) != 0) { + warnx("%s: Unable to register qemu fwcfg selector port 0x%x", + __func__, QEMU_FWCFG_SELECTOR_PORT_NUMBER); + goto done; + } + if ((error = qemu_fwcfg_register_port("qemu_fwcfg_data", + QEMU_FWCFG_DATA_PORT_NUMBER, QEMU_FWCFG_DATA_PORT_SIZE, + QEMU_FWCFG_DATA_PORT_FLAGS, qemu_fwcfg_data_port_handler)) != 0) { + warnx("%s: Unable to register qemu fwcfg data port 0x%x", + __func__, QEMU_FWCFG_DATA_PORT_NUMBER); + goto done; + } + +done: + if (error) { + acpi_device_destroy(fwcfg_sc.acpi_dev); + } + + return (error); +} diff --git a/usr.sbin/bhyve/qemu_fwcfg.h b/usr.sbin/bhyve/qemu_fwcfg.h new file mode 100644 index 000000000000..26c4db0ff71e --- /dev/null +++ b/usr.sbin/bhyve/qemu_fwcfg.h @@ -0,0 +1,12 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 Beckhoff Automation GmbH & Co. KG + * Author: Corvin Köhne + */ + +#pragma once + +#include + +int qemu_fwcfg_init(struct vmctx *const ctx);