From nobody Wed Apr 5 07:07:02 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 4Prwfv0Y0bz440GZ; Wed, 5 Apr 2023 07:07:03 +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 4Prwft6q8Yz45lF; Wed, 5 Apr 2023 07:07:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1680678423; 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=e9YIMBgc+mqPUg3iEvFEy+pCO5RGIRvCNDy8nSlh2ng=; b=AjmdQJAIz6QHFquLULKfMwOvIiIoVTkGU4BZ4eWoGFDE/mVi2Xrkdeb0IlcZDaoI27CY+/ HtzN1JZwAWYTNBh+B/VnrTRUWdNO+m0FouHpmAottf9ZcBayJic4khIzIv5fMiopQLxLcc 0zU0QRjDTLbB4lne0OF8kmljHXDRuIX3V7bIVqGHWZXOLio3assBr5Yd1ZhEQJLy42/uCb L1kWpYsvcU+S6XYP0nLFcLBjSBshs9Hbd+zUX4nCR6V0nKWAZ25lW5dDNTZWaM7s7nsiZP 5tDos+BmwAV+SSKvKQa5TPnQwfcTYkYGC0OJPRp1laHB4C8ZNRTSwIi6RRYGcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1680678423; 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=e9YIMBgc+mqPUg3iEvFEy+pCO5RGIRvCNDy8nSlh2ng=; b=AHD/P60bLCHqNgA3QZ2pqnYTZDEJnT69gze3sscown2c/MMs6KY3FoKwYxkhnfcV7wcygg sas+XYyXP4aDxVqdCrWRtxavaDNSh52/JEM0DCSQBYWB6+TyUpMQw0CjG2tB0I8sWZYqNx fif84yL+x0NK5/oia455t1DKVqiQdR87sfHMDLwbrw8i+wavbTjVNYMQ0QjbbqNz5/53D1 eibtTO3+4W+4WcxwVUZ5WXbldls1mhc8mTKe17WjyguBAAk0t7+934IPqbc0RrCxhSYU8c L2pxYMFfQdLaq0/sqdDyBLt3DGaDAVqqCR4RzBKbfkpxu1FIAGKM40xj51n+kQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1680678423; a=rsa-sha256; cv=none; b=IWHhDvORBRQOKuh78CpD2ONntMetWY2RR55ZSlvW7UNhetbQwri/RiLsf/H8eDLj3CJP+4 LJq06oxkMWpKN8YTSjowEp1bA9683ShjBUFOFlD7TpBfdzPRhdPNLMWgz+Pu/LPVEh756w e5SIw5dwIppITny1jVcLhIHZK/XveJAWPxAIm16j3F+i2BbiJ4bl8Zhi42PMVoagjb6Ngy uYU1IKzm+Eb+JDaOGnn8RRcMGdPHpa849dpZiuLLNylnBjdowihnJ/IJzs/m+UlSMQIT9X Vrrq8o0JPE0s4Pph5jWNJb5U2JA8vtPpUghBhNg3jnsu5EU3fs+JwXuwarpcVg== 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 4Prwft5mmzz1Ch3; Wed, 5 Apr 2023 07:07:02 +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 335772Tw045580; Wed, 5 Apr 2023 07:07:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 335772Ag045579; Wed, 5 Apr 2023 07:07:02 GMT (envelope-from git) Date: Wed, 5 Apr 2023 07:07:02 GMT Message-Id: <202304050707.335772Ag045579@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: acd0088c44f9 - main - bhyve: introduce acpi_device_emul struct 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: acd0088c44f9ccaff571e041dc56d01fcc47d64b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=acd0088c44f9ccaff571e041dc56d01fcc47d64b commit acd0088c44f9ccaff571e041dc56d01fcc47d64b Author: Corvin Köhne AuthorDate: 2022-07-22 08:00:10 +0000 Commit: Corvin Köhne CommitDate: 2023-04-05 07:06:41 +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 --- 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 65899cd3ad37..3c7cd0f33224 100644 --- a/usr.sbin/bhyve/qemu_fwcfg.c +++ b/usr.sbin/bhyve/qemu_fwcfg.c @@ -365,6 +365,11 @@ qemu_fwcfg_add_file(const char *name, const uint32_t size, void *const data) 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) { @@ -378,7 +383,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__);