From nobody Tue Feb 28 10:14:14 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 4PQtWV6QjFz3vGZ0; Tue, 28 Feb 2023 10:14:14 +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 4PQtWV5qlyz3r1m; Tue, 28 Feb 2023 10:14:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677579254; 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=BDPEhIMcPLOgUYvwthjYTOT1/02dG+J7758e+Zrl7XY=; b=WqslTRDhnALDhFXnZPTBrv0U2pdiam54vFKSqsiBWe4dD69rj/4yosx1WYdAmMf+HaLrxT 9ZlHxaTnjgkCM2M5xcBiWd5srZSZ6FhY4nd6KqeukuAO/LHgbp+6OgtlOm9vmRBEsv4PfB 1tRrUC83cYeF7lpTE2kSnPZBePfwl9mvU5HiONoBpEBYVB4yoGc2jFRCkapaPfaP07c/Fz AyargtUxLJ26MSGTCObfXkRmKO6N6QVIEx3VcwNHsHa+QlNO4qGk299PoMyfAyVYPEEFZf S/+W2SPgyaFa/9YPK4D1jvsUx7TaGsRRDS3ELXo+QDPKGslu7nqGi8nRcXNq/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677579254; 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=BDPEhIMcPLOgUYvwthjYTOT1/02dG+J7758e+Zrl7XY=; b=wcvdp4qii4boIK1Zpch9cx8uGUj2MdDM/r4yKnmxmFsgxOyalByvnIXZ+TaIDrEEjZDykP xej/ZPLWah3YAVjivk3ucZYYN0dXoitTzCMr/6QMv82Dicdk/RGRHWMU9E06G4i9WiLFJc OVNCmGuXFEu9qtCxWqae16CvSoW56LCd3bxxoqOPMg49+uhjGVbRBVUvU+PvyT1CYKwn7J zvXuxNdd6hr56fM3fxJurJbn8bLQwz/8HvyvfmhMzu/BVXrcWHDEXWWVVv3guVxtRM9LPg lSjDjWcOnfu7ec28NPEmIVMobpBg29Razh6F/jWSTorCercdh7UNhjxmT6t32g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677579254; a=rsa-sha256; cv=none; b=wJW9i2WStYfZy4JzhmmYDtBi1LDYMZcz0FnXZnWjaM8iysd18VJUfXS8U0pGm7kU8C5zxO SbgN6qg4hh1KOZEQs1mFVOnEvnKN9M7+PpmKScQDtRF0guN4gcjFeLerNTK5gNmlJtwRTv VHRL+ysjnEJAL22/pTdD/TzrMOvadOFIb+iaF8iW6awQZ+qw6GZFOfLhNe8PQppbfk0uay Bc4iSzjdQzINDjrjELm3rqq6axVChc/Dsn7e3ioZ/E7Z9UJ/dSF9qNUgcfF1C9pVmk7WOs 1p3gonWbe33Q3trSoHUcJ6xIVe36tet6XB6miRTH2YxS9S4n3jvAq2RScNBCPw== 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 4PQtWV4bLCz13p1; Tue, 28 Feb 2023 10:14:14 +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 31SAEE0B013844; Tue, 28 Feb 2023 10:14:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31SAEEEp013843; Tue, 28 Feb 2023 10:14:14 GMT (envelope-from git) Date: Tue, 28 Feb 2023 10:14:14 GMT Message-Id: <202302281014.31SAEEEp013843@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: 3c12bcba78ea - stable/13 - bhyve: add emulation for qemu's fwcfg data port 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 3c12bcba78ea2b6a9299f30f60c5988ba159ad44 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=3c12bcba78ea2b6a9299f30f60c5988ba159ad44 commit 3c12bcba78ea2b6a9299f30f60c5988ba159ad44 Author: Corvin Köhne AuthorDate: 2021-08-11 08:00:34 +0000 Commit: Corvin Köhne CommitDate: 2023-02-28 10:04:37 +0000 bhyve: add emulation for qemu's fwcfg data port The data port returns the data of the fwcfg item. Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D38333 (cherry picked from commit b11081dca76b8e283495632b86b41539ee013857) --- usr.sbin/bhyve/qemu_fwcfg.c | 40 ++++++++++++++++++++++++++++++++++++++++ usr.sbin/bhyve/qemu_fwcfg.h | 8 ++++++++ 2 files changed, 48 insertions(+) diff --git a/usr.sbin/bhyve/qemu_fwcfg.c b/usr.sbin/bhyve/qemu_fwcfg.c index dec3fa83c493..13e21daca7ff 100644 --- a/usr.sbin/bhyve/qemu_fwcfg.c +++ b/usr.sbin/bhyve/qemu_fwcfg.c @@ -56,6 +56,8 @@ struct qemu_fwcfg_softc { uint32_t data_offset; union qemu_fwcfg_selector selector; + struct qemu_fwcfg_item items[QEMU_FWCFG_MAX_ARCHS] + [QEMU_FWCFG_MAX_ENTRIES]; }; static struct qemu_fwcfg_softc fwcfg_sc; @@ -87,6 +89,44 @@ 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) { + if (bytes != sizeof(uint8_t)) { + warnx("%s: invalid size (%d) of IO port access", __func__, + bytes); + return (-1); + } + + if (!in) { + warnx("%s: Writes to qemu fwcfg data port aren't allowed", + __func__); + return (-1); + } + + /* get fwcfg item */ + struct qemu_fwcfg_item *const item = + &fwcfg_sc.items[fwcfg_sc.selector.architecture] + [fwcfg_sc.selector.index]; + if (item->data == NULL) { + warnx( + "%s: qemu fwcfg item doesn't exist (architecture %s index 0x%x)", + __func__, + fwcfg_sc.selector.architecture ? "specific" : "generic", + fwcfg_sc.selector.index); + *eax = 0x00; + return (0); + } else if (fwcfg_sc.data_offset >= item->size) { + warnx( + "%s: qemu fwcfg item read exceeds size (architecture %s index 0x%x size 0x%x offset 0x%x)", + __func__, + fwcfg_sc.selector.architecture ? "specific" : "generic", + fwcfg_sc.selector.index, item->size, fwcfg_sc.data_offset); + *eax = 0x00; + return (0); + } + + /* return item data */ + *eax = item->data[fwcfg_sc.data_offset]; + fwcfg_sc.data_offset++; + return (0); } diff --git a/usr.sbin/bhyve/qemu_fwcfg.h b/usr.sbin/bhyve/qemu_fwcfg.h index 26c4db0ff71e..58ef5ed3c6bf 100644 --- a/usr.sbin/bhyve/qemu_fwcfg.h +++ b/usr.sbin/bhyve/qemu_fwcfg.h @@ -9,4 +9,12 @@ #include +#define QEMU_FWCFG_MAX_ARCHS 0x2 +#define QEMU_FWCFG_MAX_ENTRIES 0x4000 + +struct qemu_fwcfg_item { + uint32_t size; + uint8_t *data; +}; + int qemu_fwcfg_init(struct vmctx *const ctx);