From nobody Fri Apr 28 10:40:17 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 4Q78JK5Gtkz48JxY; Fri, 28 Apr 2023 10:40:17 +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 4Q78JK4N5gz3GRY; Fri, 28 Apr 2023 10:40:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682678417; 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=W/Uu4jJ4n3o+QNUbu2mWTzUOTsUV5xls2Jz7VJ1+9S0=; b=H4vA3WwJawKBPfbL2jdGVW8pzZXhBrV/AdJKh6FC+9Vsc9tlK8UmEPvu7rdE7LGZxKwANi lAEQ8CQWDL/G3y0G2n42JfdGwwtfS9kdcfq/73bD5HBvYrS75F2gkAXptmy9q1HDB9B2gg Tn7j/WP176a94thJ7ujyw1PYysziRejpUv1bMJHy5nKuj98qwNSdHngEoHlD98pucVEkdr izHkBq43ASKdUXnk7zy0le1TMXPlB01dOgKLdp7KtL3eT1v4VLFI1m+jtOxfXAHKXor9yg 80oxx1DB9z28SbfkCAnNtbZGMLng//2iX/fc4fCabRsEQT6qS/20i43f5T+WcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682678417; 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=W/Uu4jJ4n3o+QNUbu2mWTzUOTsUV5xls2Jz7VJ1+9S0=; b=PZjDMDiXgpOtylE1KV1ZW5itMhVSvrGRUe+kIdYxYGXIB0eTP2K/0u9L2p2lFNwO0e6pRc NAZC+7mIiLhANtpd27L+Tf7UJ8EbEzMqmUKyNirP3GViyNmWvRN2y254mu9AQ6+CnX0MlF CKVgCQtyOIn0mdJV8HjE+bkueCweAsTY1kEj4oTjpjrOraVzrloM6zac8oqlOUtlkTXlg+ 7jfZKPL3S49g902MKfOnRDz2yDLNTFCjZ0DLhW8n4IkSk5Jr1EibciCUqGzos+M95K1dr4 3FfD5U2fq4GD44ezjVcHRj90lThOJPeYXjMMz0dmbcbqMrc/Bp4M8yApEM4rxw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682678417; a=rsa-sha256; cv=none; b=t9ZjPh4d5Gu3QgQ51xEmoY8DJdWYx9t81B3GcMQjFW5CZHS9hHMi2eshbW/i8rjmkB7IPL RB9EzsPSUmTOrccI+WKnnOkMgFXuDjjSEFJp7ZcrLuBAd/AG7OqXkLhWonDwQ0av0kukVU U259EwksLX6pQ7noTbt5Ys+7bwFfTEv8OtbU4Y3AXN7s2uDdMRvMy9RH18pArI9TbFwDjr nbAmc1NZVknHxOwERqBPCqRZyBo6WB0SQtxHGSZiMGpbC0G6etR7FiH+gFZLRpworq5fsw INgBouOk6QhQS1VRcC3EJxhE0/2gQ7bch2dxP32Zam7fi0nlhEs2ZxJOh6PJwQ== 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 4Q78JK2mF4zx1f; Fri, 28 Apr 2023 10:40:17 +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 33SAeHwX092363; Fri, 28 Apr 2023 10:40:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33SAeHEE092357; Fri, 28 Apr 2023 10:40:17 GMT (envelope-from git) Date: Fri, 28 Apr 2023 10:40:17 GMT Message-Id: <202304281040.33SAeHEE092357@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: 3f7acfe0730c - stable/13 - bhyve: introduce acpi_device_emul struct 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: 3f7acfe0730cbe6ffa3550adc30ae4eaa1eaa2ac Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=3f7acfe0730cbe6ffa3550adc30ae4eaa1eaa2ac commit 3f7acfe0730cbe6ffa3550adc30ae4eaa1eaa2ac Author: Corvin Köhne AuthorDate: 2022-07-22 08:00:10 +0000 Commit: Corvin Köhne CommitDate: 2023-04-28 07:28:32 +0000 bhyve: introduce acpi_device_emul struct It'll be easier to add new properties to the ACPI device emulation if we have a struct which holds all device specific properties. In some future commits the acpi_device_emul struct will be expanded to include some device specific functions to build ACPI tables. Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D39319 (cherry picked from commit acd0088c44f9ccaff571e041dc56d01fcc47d64b) --- usr.sbin/bhyve/acpi_device.c | 30 +++++++++++------------------- usr.sbin/bhyve/acpi_device.h | 14 +++++++++----- usr.sbin/bhyve/qemu_fwcfg.c | 7 ++++++- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/usr.sbin/bhyve/acpi_device.c b/usr.sbin/bhyve/acpi_device.c index 047d411deec2..a1155ecb44b6 100644 --- a/usr.sbin/bhyve/acpi_device.c +++ b/usr.sbin/bhyve/acpi_device.c @@ -35,24 +35,23 @@ struct acpi_resource_list_entry { * 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 emul Device emulation struct. It contains some information like the + name of the ACPI device and some device specific functions. * @param crs Current resources used by the ACPI device. */ struct acpi_device { struct vmctx *vm_ctx; - const char *name; - const char *hid; + const struct acpi_device_emul *emul; 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) + struct vmctx *const vm_ctx, const struct acpi_device_emul *const emul) { - if (new_dev == NULL || vm_ctx == NULL || name == NULL || hid == NULL) { - return (EINVAL); - } + assert(new_dev != NULL); + assert(vm_ctx != NULL); + assert(emul != NULL); struct acpi_device *const dev = calloc(1, sizeof(*dev)); if (dev == NULL) { @@ -60,13 +59,8 @@ acpi_device_create(struct acpi_device **const new_dev, } dev->vm_ctx = vm_ctx; - dev->name = strdup(name); - dev->hid = strdup(hid); + dev->emul = emul; SLIST_INIT(&dev->crs); - if (dev->name == NULL || dev->hid == NULL) { - acpi_device_destroy(dev); - return (ENOMEM); - } const int error = acpi_tables_add_device(dev); if (error) { @@ -92,9 +86,7 @@ acpi_device_destroy(struct acpi_device *const dev) SLIST_REMOVE_HEAD(&dev->crs, chain); free(res); } - - free(__DECONST(void *, dev->hid)); - free(__DECONST(void *, dev->name)); + free(dev); } @@ -174,9 +166,9 @@ acpi_device_write_dsdt(const struct acpi_device *const dev) dsdt_line(""); dsdt_line(" Scope (\\_SB)"); dsdt_line(" {"); - dsdt_line(" Device (%s)", dev->name); + dsdt_line(" Device (%s)", dev->emul->name); dsdt_line(" {"); - dsdt_line(" Name (_HID, \"%s\")", dev->hid); + dsdt_line(" Name (_HID, \"%s\")", dev->emul->hid); dsdt_line(" Name (_STA, 0x0F)"); dsdt_line(" Name (_CRS, ResourceTemplate ()"); dsdt_line(" {"); diff --git a/usr.sbin/bhyve/acpi_device.h b/usr.sbin/bhyve/acpi_device.h index 49e55c7d4f14..45e36a8ae771 100644 --- a/usr.sbin/bhyve/acpi_device.h +++ b/usr.sbin/bhyve/acpi_device.h @@ -16,18 +16,22 @@ struct vmctx; struct acpi_device; +struct acpi_device_emul { + const char *name; + const char *hid; +}; + /** * 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. + * @param[in] emul Device emulation struct. It contains some information + * like the name of the ACPI device and some device specific + * functions. */ int acpi_device_create(struct acpi_device **new_dev, struct vmctx *vm_ctx, - const char *name, const char *hid); + const struct acpi_device_emul *emul); void acpi_device_destroy(struct acpi_device *dev); int acpi_device_add_res_fixed_ioport(struct acpi_device *dev, UINT16 port, diff --git a/usr.sbin/bhyve/qemu_fwcfg.c b/usr.sbin/bhyve/qemu_fwcfg.c index a93b37027142..e35d63d09795 100644 --- a/usr.sbin/bhyve/qemu_fwcfg.c +++ b/usr.sbin/bhyve/qemu_fwcfg.c @@ -363,6 +363,11 @@ qemu_fwcfg_add_file(const uint8_t name[QEMU_FWCFG_MAX_NAME], return (0); } +static const struct acpi_device_emul qemu_fwcfg_acpi_device_emul = { + .name = QEMU_FWCFG_ACPI_DEVICE_NAME, + .hid = QEMU_FWCFG_ACPI_HARDWARE_ID, +}; + int qemu_fwcfg_init(struct vmctx *const ctx) { @@ -376,7 +381,7 @@ qemu_fwcfg_init(struct vmctx *const ctx) */ if (strcmp(lpc_fwcfg(), "qemu") == 0) { error = acpi_device_create(&fwcfg_sc.acpi_dev, ctx, - QEMU_FWCFG_ACPI_DEVICE_NAME, QEMU_FWCFG_ACPI_HARDWARE_ID); + &qemu_fwcfg_acpi_device_emul); if (error) { warnx("%s: failed to create ACPI device for QEMU FwCfg", __func__);