From nobody Tue Feb 14 07:29:07 2023 X-Original-To: dev-commits-src-main@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 4PGCWR6BVyz3rKw3; Tue, 14 Feb 2023 07:29:07 +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 4PGCWR5ZGsz4Nn5; Tue, 14 Feb 2023 07:29:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676359747; 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=5RAa1FQLLHSBkmZU9LwKFewX6VLz8/SH3oxDymoGJvA=; b=duCNgI78vKsBloZGc8Tv+WCmcdrkpcAnzzzOz5O/yBO+dA0GNIW52jI76tKW+JFfnCAWpf XiVWunzF5wkHcG04oh82BsYrjq+mD3ZHOS8cB5yr2dbMTUAOGnc87x7dCyjU2NOyNElubu +6hhshdtc91Rl73unissSMNxLsn8YGW/lE9dPWcG4DF2mzcnzoqCrGIbCyeFoAfwp7l7eF fpc95t0Uov9Y5nWRDBAeGrS7FWd7n+8bG7PHDK4NK98NChQ8XGqsGEJjfmIKsaOupgA2W3 1/QVslHoIi+XExqfbdG13LqRG124H6rkS0aczal4lYlnpo7Km9t/z5Qzq2ziHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676359747; 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=5RAa1FQLLHSBkmZU9LwKFewX6VLz8/SH3oxDymoGJvA=; b=s6t6ft6iM+xEJoYw8Fjqe9Y+/LON/3hJpnAzJ7++wy86Szd3zAKNQCwjUevYPJEEo8Tqff DW/SshknKx9CgjAbhLln3pKXJCHA/HvGTRxeRCKSA7QORFMn2pDCOCd7anDpgYoXJGOfnp f/Mip4eOqBrXg5TAMbblH+T3SfCQ3tqbBBPc7akzPTYDhJ8CgRpsYAQ75A2cI8593MV0DF knPyKerT99uMVtlW8Ji36mERSzLJVXn8OAGJpKCJ+qUYD8Bp6OcHTz5a7/qKrGuv7h+A36 WiviWpPhwFzMJ0k3UNC05ANuR7/xdj5x/MzKNN2psDi1zu44HKISR+qd3kaHLQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676359747; a=rsa-sha256; cv=none; b=VV9X3hhFRu8cM+HzH8yV8NNwFFilVNQOhi1yLC2WKS3At8j/z8LsGd4iAcDcW2gt7ehTg8 RuNZKbwa1izkAegzzxZUNdn6/hmVUJIlktkbVz2CvmpV2u7SobYeNUMJ58eNGANJqr17Bz K+B+E2bDhILpm9jpdwQZqA1s/mOIu9rF0eSdU0cl9ZHhHEykqQWTGBl3PLdbEdkUKEUIi/ e8UdWRhExq4NXCvxzo/4tXS8I2xdE2/owwwxP7Tjb3mJwr9TBeaU+vfojp/tNI/aaTIkom fFk2mA/OGN4+0RV7VVftZMXGyvCuZMzXi86jgN7iDSPaos5eopp0PCDXUmBiJg== 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 4PGCWR4dTpzqlM; Tue, 14 Feb 2023 07:29: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 31E7T7XZ043940; Tue, 14 Feb 2023 07:29:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31E7T7HB043939; Tue, 14 Feb 2023 07:29:07 GMT (envelope-from git) Date: Tue, 14 Feb 2023 07:29:07 GMT Message-Id: <202302140729.31E7T7HB043939@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: 1231f047c3ed - main - bhyve: add helper struct for acpi device handling List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: 1231f047c3ed46ca6041df62f2b71f6e879bbb40 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=1231f047c3ed46ca6041df62f2b71f6e879bbb40 commit 1231f047c3ed46ca6041df62f2b71f6e879bbb40 Author: Corvin Köhne AuthorDate: 2021-10-07 13:54:46 +0000 Commit: Corvin Köhne CommitDate: 2023-02-14 07:28:17 +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 --- 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);