From nobody Tue Feb 28 10:14:07 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 4PQtWN2QcPz3vGwZ; Tue, 28 Feb 2023 10:14:08 +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 4PQtWN0RCfz3qkx; Tue, 28 Feb 2023 10:14:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677579248; 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=4E33uvyPgLXQ3NBgCCPL5+BrjZrNeeUQjy3COaZfumM=; b=rhxMXctgCvkWXRlCqb68qNbYMA48Vd18CpY/eEW/wtTzcstfrr5yYBeK01H6760gVDA3Yp JR6SfP2+Bo84WdR+Wd1Kwu5v2lygWmNDYC/woZ3wHu2AoTkfylV0kgbV2LY8KgJKCd8MJY mq+95zzFtE0m8WELKKYOcv1p5X9y/xgr7P6wsygAdsT+CLkgp0VFcAJXL21WEw0bII/f3B /jUQ/ZJItApIGgcv0s7iE2Ffmc+nAAU2wk4nDWya157LVBPl/01Gl94Gv2us+8tZiUAENe yw1bdFgQsV3mU61MXGD0zOlR8J8/gNhm5BDBT8QLEzPSX7DZArEwAQC/y6JSTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677579248; 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=4E33uvyPgLXQ3NBgCCPL5+BrjZrNeeUQjy3COaZfumM=; b=SpTyZzahx1AMyykRowcgtRwI4bPORWTgNSznpW+1gYsNEqkJUbBgVeZ6r4rZ68Ld/voDbR OjA5Gf6176EJcJ6oMejYny2N+OcnpVbCJjvRBhXb9ucVwV7DPsxHoYg9HFoSrsNnYjwWVd vC/DDxw5gjA1QaPYg8fjJKfa7Jzkzz/F26mLFC+Q1xbxSMONNT9xLiqk+izosKOT+JYvQ9 YoR5TetBssf8Q3gpZb42XzvnKj35OzyOcIpN9K/+3iBy97fZ7GYHv6GXM+vQp5JOd1EFBE /weYaO5cd1Vnc96VPuhLtIRXKmmOjrWdP8hwqoI4SOXP+D7RyLYysyCJ3D2cIQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677579248; a=rsa-sha256; cv=none; b=Yscx2LSaYK6fUlIe7CTurlF4wRYNreusoN7AIhpV4HLatqDbt3xNDHS+sCnIyOohibGlLo +9IVjhUZJqe6RRA8VJTpIujBjoExvakjaJQ/kuMznBu8du/8wfJe5Wxv0X5Ru8gxjAQOQ3 cC+LEBq3IlYHhNb0at74O/Ke3gTm1PhlaukPH+1hUMarCkTCsFtTA3BZwi/iszb1tFtXJt PTasnkUbdCz8572vFhCroQ40+WgLqbozLZ1o0ezO/x4CPKa7m6TsqTOuH8rhZuXy5xdUrb v36hEtFHyLWUWYqkF7LN3czZCuofAAIL94Ys8y0xcXCT7n1p+lGraX/e9QXUrA== 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 4PQtWM6f6Hz13ny; Tue, 28 Feb 2023 10:14:07 +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 31SAE7ho013693; Tue, 28 Feb 2023 10:14:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31SAE7mO013692; Tue, 28 Feb 2023 10:14:07 GMT (envelope-from git) Date: Tue, 28 Feb 2023 10:14:07 GMT Message-Id: <202302281014.31SAE7mO013692@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: b5d47fa9a511 - stable/13 - bhyve: add helper struct for acpi device handling 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: b5d47fa9a5112f13cac8282c18d36f40661967a0 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=b5d47fa9a5112f13cac8282c18d36f40661967a0 commit b5d47fa9a5112f13cac8282c18d36f40661967a0 Author: Corvin Köhne AuthorDate: 2021-10-07 13:54:46 +0000 Commit: Corvin Köhne CommitDate: 2023-02-28 10:04:26 +0000 bhyve: add helper struct for acpi device handling To simplify the handling of different acpi devices like qemu fwcfg or a tpm, add a helper struct. It will handle the reporting of acpi resources. Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D38327 (cherry picked from commit 1231f047c3ed46ca6041df62f2b71f6e879bbb40) --- usr.sbin/bhyve/Makefile | 1 + usr.sbin/bhyve/acpi_device.c | 92 ++++++++++++++++++++++++++++++++++++++++++++ usr.sbin/bhyve/acpi_device.h | 31 +++++++++++++++ 3 files changed, 124 insertions(+) diff --git a/usr.sbin/bhyve/Makefile b/usr.sbin/bhyve/Makefile index a456d507a071..bf0a17edc59e 100644 --- a/usr.sbin/bhyve/Makefile +++ b/usr.sbin/bhyve/Makefile @@ -15,6 +15,7 @@ MAN= bhyve.8 bhyve_config.5 BHYVE_SYSDIR?=${SRCTOP} SRCS= \ + acpi_device.c \ atkbdc.c \ acpi.c \ audio.c \ diff --git a/usr.sbin/bhyve/acpi_device.c b/usr.sbin/bhyve/acpi_device.c new file mode 100644 index 000000000000..66d50de814fd --- /dev/null +++ b/usr.sbin/bhyve/acpi_device.c @@ -0,0 +1,92 @@ +/*- + * 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.h" +#include "acpi_device.h" + +/** + * List entry to enumerate all resources used by an ACPI device. + * + * @param chain Used to chain multiple elements together. + * @param type Type of the ACPI resource. + * @param data Data of the ACPI resource. + */ +struct acpi_resource_list_entry { + SLIST_ENTRY(acpi_resource_list_entry) chain; + UINT32 type; + ACPI_RESOURCE_DATA data; +}; + +/** + * Holds information about an ACPI device. + * + * @param vm_ctx VM context the ACPI device was created in. + * @param name Name of the ACPI device. + * @param hid Hardware ID of the ACPI device. + * @param crs Current resources used by the ACPI device. + */ +struct acpi_device { + struct vmctx *vm_ctx; + const char *name; + const char *hid; + SLIST_HEAD(acpi_resource_list, acpi_resource_list_entry) crs; +}; + +int +acpi_device_create(struct acpi_device **const new_dev, + struct vmctx *const vm_ctx, const char *const name, const char *const hid) +{ + if (new_dev == NULL || vm_ctx == NULL || name == NULL || hid == NULL) { + return (EINVAL); + } + + struct acpi_device *const dev = calloc(1, sizeof(*dev)); + if (dev == NULL) { + return (ENOMEM); + } + + dev->vm_ctx = vm_ctx; + dev->name = strdup(name); + dev->hid = strdup(hid); + SLIST_INIT(&dev->crs); + if (dev->name == NULL || dev->hid == NULL) { + acpi_device_destroy(dev); + return (ENOMEM); + } + + *new_dev = dev; + + return (0); +} + +void +acpi_device_destroy(struct acpi_device *const dev) +{ + if (dev == NULL) { + return; + } + + struct acpi_resource_list_entry *res; + while (!SLIST_EMPTY(&dev->crs)) { + res = SLIST_FIRST(&dev->crs); + SLIST_REMOVE_HEAD(&dev->crs, chain); + free(res); + } + + free(__DECONST(void *, dev->hid)); + free(__DECONST(void *, dev->name)); + free(dev); +} diff --git a/usr.sbin/bhyve/acpi_device.h b/usr.sbin/bhyve/acpi_device.h new file mode 100644 index 000000000000..1728acd4cdcd --- /dev/null +++ b/usr.sbin/bhyve/acpi_device.h @@ -0,0 +1,31 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 Beckhoff Automation GmbH & Co. KG + * Author: Corvin Köhne + */ + +#pragma once + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#include +#pragma GCC diagnostic pop + +struct vmctx; + +struct acpi_device; + +/** + * Creates an ACPI device. + * + * @param[out] new_dev Returns the newly create ACPI device. + * @param[in] vm_ctx VM context the ACPI device is created in. + * @param[in] name Name of the ACPI device. Should always be a NULL + * terminated string. + * @param[in] hid Hardware ID of the ACPI device. Should always be a NULL + * terminated string. + */ +int acpi_device_create(struct acpi_device **const new_dev, + struct vmctx *const vm_ctx, const char *const name, const char *const hid); +void acpi_device_destroy(struct acpi_device *const dev);