From nobody Sun Jul 26 11:51:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1782818621; cv=none; d=zohomail.com; s=zohoarc; b=b5gnLf3o/llJwYJ3cm9X2HIWt/EHtcvc1kze1cLx3ETCkMa1dU/VI7oJB5m5qge4NPym5Y1/d29eNGbqGOV+BnRc/cBi8XfvUBMrXXV8wfu2QZNn7zp/YbCcqoLsnv0Am6efrnezruQOQfndbLjm4vxEigopjn23Xq1QJq5a4yE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782818621; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iYts4rJsICRglCBK64//7QzvYf2luURO8e9CajLyTJY=; b=NYyTeqaPYEavgy0kj5LEKiXnt6U7gZEJvPx+qXe5QpTw5KA17zFtPBGqVaITVa3rlnarCiXGIGKVUbA9vpW+B1OZtL09OlZETkrMytN7qw1QYl2vGW/PVi1LSzi3Pr+OHZXmXLK80Ti+uce42O8jOt9h4DxT3G1TkoNlg8R/Gw4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1782818621357957.1173983892758; Tue, 30 Jun 2026 04:23:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1weWYt-0003V6-Tz; Tue, 30 Jun 2026 07:23:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1weWYl-0003SR-3h for qemu-devel@nongnu.org; Tue, 30 Jun 2026 07:23:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1weWYi-0005cR-PQ for qemu-devel@nongnu.org; Tue, 30 Jun 2026 07:23:22 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-567-I93T73G6Pi-VtdsUOPNXgA-1; Tue, 30 Jun 2026 07:23:17 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8A3C8180057C; Tue, 30 Jun 2026 11:23:16 +0000 (UTC) Received: from fedora (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A130B1800678; Tue, 30 Jun 2026 11:23:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782818599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iYts4rJsICRglCBK64//7QzvYf2luURO8e9CajLyTJY=; b=eawnUn+wNVk1R5N9sT3zu52N0aLwkUljEjvN9ug7wvG4INQJ08TVCShgWsaWMLHf3AFUs4 7t+WDG9GbauYRIE4DJlSIldC0SSRPOxHR+LRl+IcBAgubLFxMQY3CTNis+vqbFNDhcZh++ uvZ/exGv095b3Yg0ZJOi4+qNjyjcIro= X-MC-Unique: I93T73G6Pi-VtdsUOPNXgA-1 X-Mimecast-MFC-AGG-ID: I93T73G6Pi-VtdsUOPNXgA_1782818596 From: Albert Esteve To: qemu-devel@nongnu.org Cc: manos.pitsidianakis@linaro.org, Stefano Garzarella , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , Cornelia Huck , Paolo Bonzini , Albert Esteve Subject: [PATCH 1/3] virtio_ids: Add ID for virtio media Date: Tue, 30 Jun 2026 13:23:08 +0200 Message-ID: <20260630112310.552606-2-aesteve@redhat.com> In-Reply-To: <20260630112310.552606-1-aesteve@redhat.com> References: <20260630112310.552606-1-aesteve@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=aesteve@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1782818622697158500 Content-Type: text/plain; charset="utf-8" Temporary commit. DO NOT MERGE. While we wait for the patch [1] to get merged upstream, manually update and add the virtio-media ID to the kernel header for testing purposes. [1] https://lore.kernel.org/all/20260310-virtio-media-id-v1-1-be211bcf682b@= redhat.com/ Signed-off-by: Albert Esteve Tested-by: Dorinda Bassey --- include/standard-headers/linux/virtio_ids.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/standard-headers/linux/virtio_ids.h b/include/standard= -headers/linux/virtio_ids.h index 6c12db16fa..fd73ae9d13 100644 --- a/include/standard-headers/linux/virtio_ids.h +++ b/include/standard-headers/linux/virtio_ids.h @@ -69,6 +69,7 @@ #define VIRTIO_ID_BT 40 /* virtio bluetooth */ #define VIRTIO_ID_GPIO 41 /* virtio gpio */ #define VIRTIO_ID_SPI 45 /* virtio spi */ +#define VIRTIO_ID_MEDIA 48 /* virtio media */ =20 /* * Virtio Transitional IDs --=20 2.54.0 From nobody Sun Jul 26 11:51:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1782818639; cv=none; d=zohomail.com; s=zohoarc; b=AhPka28a19B4ekzGB9a7KC7gUlw1KLLmFSJeCuiLQ3g43l5yU1UOVXkV8Zxwu2SEZIn3csenER2m4TN9aBI/98qDfomhHh3pXiSEvuKlFjivBOVNX0j1Vn2LAHxKua9kUCEY63FfYp5VfaRu52e8BUBNdOR1omXKMsGNZ4tTti8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782818639; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mnk2mBT1aDzVMVKjRPnRen745v+cn0fcjhguALlq9KU=; b=mkB5mta0IN9wbcPtjYHUTO0Yn7h6009CGq2FjWcOtE1eexb9lgQtHpp9wi/m7N4y6oBK5EmOt9KLYmvzSvxsAB+DIAfJNS1rhCT3hLelQwDNSI6CGaapnQZcURdfQYBOd1O0fcG5eeWhKPR92jARKl//qOScETW9a1ZG2jnmrs0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1782818639132464.0370299216619; Tue, 30 Jun 2026 04:23:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1weWYy-0003Y5-D0; Tue, 30 Jun 2026 07:23:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1weWYp-0003Ut-UX for qemu-devel@nongnu.org; Tue, 30 Jun 2026 07:23:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1weWYm-0005d1-Ve for qemu-devel@nongnu.org; Tue, 30 Jun 2026 07:23:27 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-282-ScHvcqWcMYWQnBIVXfqobg-1; Tue, 30 Jun 2026 07:23:20 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 057BC1954AD9; Tue, 30 Jun 2026 11:23:19 +0000 (UTC) Received: from fedora (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2AB691800678; Tue, 30 Jun 2026 11:23:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782818603; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mnk2mBT1aDzVMVKjRPnRen745v+cn0fcjhguALlq9KU=; b=c3MEn6ZkY9ZBSZ41WEB/Km3JnNyYGldo4WB89OBmyCeOCtZ0AX1KPWucyxYl7OpratRtfD JEPUUOJGIdb3sM/7cfwb+fozVLXEqTCr0saJNWQDCg5ZMTuy/1a6ommyAZie1dFnQnSm/W M+kN3ch+zF2aH9IuICByD01MgpBnuEI= X-MC-Unique: ScHvcqWcMYWQnBIVXfqobg-1 X-Mimecast-MFC-AGG-ID: ScHvcqWcMYWQnBIVXfqobg_1782818599 From: Albert Esteve To: qemu-devel@nongnu.org Cc: manos.pitsidianakis@linaro.org, Stefano Garzarella , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , Cornelia Huck , Paolo Bonzini , Albert Esteve Subject: [PATCH 2/3] hw/display: add vhost-user-media device Date: Tue, 30 Jun 2026 13:23:09 +0200 Message-ID: <20260630112310.552606-3-aesteve@redhat.com> In-Reply-To: <20260630112310.552606-1-aesteve@redhat.com> References: <20260630112310.552606-1-aesteve@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=aesteve@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1782818641030158500 Content-Type: text/plain; charset="utf-8" Add the QEMU side of the vhost-user-media device, which connects to a virtio-media vhost-user backend daemon implementing the V4L2 API over the virtio-media protocol. The virtio-media device is specified in the VirtIO specification v1.4, section 5.22: https://docs.oasis-open.org/virtio/virtio/v1.4/cs01/virtio-v1.4-cs01.ht= ml Tested with the rust-vmm vhost-device-media backend [1]: cargo run -- -s /path/to/media.sock -d /dev/video0 --backend v4l2-proxy Example invocation: qemu-system-x86_64 \ -chardev socket,path=3D/tmp/media.sock,id=3Dmedia \ -device vhost-user-media-pci,chardev=3Dmedia,id=3Dmedia [1] https://github.com/rust-vmm/vhost-device/pull/944 Signed-off-by: Albert Esteve Tested-by: Dorinda Bassey --- hw/display/Kconfig | 5 + hw/display/meson.build | 3 + hw/display/vhost-user-media-pci.c | 77 ++++++ hw/display/vhost-user-media.c | 393 +++++++++++++++++++++++++++ hw/virtio/virtio.c | 3 +- include/hw/virtio/vhost-user-media.h | 47 ++++ 6 files changed, 527 insertions(+), 1 deletion(-) create mode 100644 hw/display/vhost-user-media-pci.c create mode 100644 hw/display/vhost-user-media.c create mode 100644 include/hw/virtio/vhost-user-media.h diff --git a/hw/display/Kconfig b/hw/display/Kconfig index b3593fe981..060274b1e6 100644 --- a/hw/display/Kconfig +++ b/hw/display/Kconfig @@ -120,6 +120,11 @@ config VHOST_USER_VGA default y depends on VIRTIO_VGA && VHOST_USER_GPU =20 +config VHOST_USER_MEDIA + bool + default y + depends on VIRTIO && VHOST_USER + config DPCD bool select AUX diff --git a/hw/display/meson.build b/hw/display/meson.build index ffecedbf70..214c047df6 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -37,6 +37,9 @@ system_ss.add(when: 'CONFIG_NEXTCUBE', if_true: files('ne= xt-fb.c')) system_ss.add(when: 'CONFIG_VGA', if_true: files('vga.c')) system_ss.add(when: 'CONFIG_VIRTIO', if_true: files('virtio-dmabuf.c')) system_ss.add(when: 'CONFIG_DM163', if_true: files('dm163.c')) +system_ss.add(when: 'CONFIG_VHOST_USER_MEDIA', if_true: files('vhost-user-= media.c')) +system_ss.add(when: ['CONFIG_VHOST_USER_MEDIA', 'CONFIG_VIRTIO_PCI' ], + if_true: files('vhost-user-media-pci.c')) =20 stub_ss.add([files('acpi-vga-stub.c'), pixman]) if (config_all_devices.has_key('CONFIG_VGA_CIRRUS') or diff --git a/hw/display/vhost-user-media-pci.c b/hw/display/vhost-user-medi= a-pci.c new file mode 100644 index 0000000000..ad9e3900a4 --- /dev/null +++ b/hw/display/vhost-user-media-pci.c @@ -0,0 +1,77 @@ +/* + * Vhost-user MEDIA virtio device PCI glue + * + * Copyright Red Hat, Inc. 2024 + * Authors: Albert Esteve + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/core/qdev-properties.h" +#include "hw/virtio/vhost-user-media.h" +#include "hw/virtio/virtio-pci.h" + +#define TYPE_VHOST_USER_MEDIA_PCI "vhost-user-media-pci-base" +OBJECT_DECLARE_SIMPLE_TYPE(VHostUserMEDIAPCI, VHOST_USER_MEDIA_PCI) + +struct VHostUserMEDIAPCI { + VirtIOPCIProxy parent_obj; + VHostUserMEDIA vdev; +}; + +static const Property vumedia_pci_properties[] =3D { + DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, + VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, + DEV_NVECTORS_UNSPECIFIED), +}; + +static void vumedia_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VHostUserMEDIAPCI *dev =3D VHOST_USER_MEDIA_PCI(vpci_dev); + DeviceState *dev_state =3D DEVICE(&dev->vdev); + + if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { + vpci_dev->nvectors =3D 1; + } + + qdev_realize(dev_state, BUS(&vpci_dev->bus), errp); +} + +static void vumedia_pci_class_init(ObjectClass *klass, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + k->realize =3D vumedia_pci_realize; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + device_class_set_props(dc, vumedia_pci_properties); + pcidev_k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id =3D 0; /* Set by virtio-pci based on virtio id */ + pcidev_k->revision =3D 0x00; + pcidev_k->class_id =3D PCI_CLASS_STORAGE_OTHER; +} + +static void vumedia_pci_instance_init(Object *obj) +{ + VHostUserMEDIAPCI *dev =3D VHOST_USER_MEDIA_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_USER_MEDIA); +} + +static const VirtioPCIDeviceTypeInfo vumedia_pci_info =3D { + .base_name =3D TYPE_VHOST_USER_MEDIA_PCI, + .non_transitional_name =3D "vhost-user-media-pci", + .instance_size =3D sizeof(VHostUserMEDIAPCI), + .instance_init =3D vumedia_pci_instance_init, + .class_init =3D vumedia_pci_class_init, +}; + +static void vumedia_pci_register(void) +{ + virtio_pci_types_register(&vumedia_pci_info); +} + +type_init(vumedia_pci_register); diff --git a/hw/display/vhost-user-media.c b/hw/display/vhost-user-media.c new file mode 100644 index 0000000000..5c627437e7 --- /dev/null +++ b/hw/display/vhost-user-media.c @@ -0,0 +1,393 @@ +/* + * Vhost-user Media device + * + * Copyright Red Hat, Inc. 2024 + * + * This is the boilerplate for instantiating a vhost-user device + * implementing a virtio-media device. + * + * Authors: + * Albert Esteve + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "hw/core/qdev-properties.h" +#include "standard-headers/linux/virtio_ids.h" +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/vhost-user-media.h" + +static const int feature_bits[] =3D { + VIRTIO_F_RING_RESET, + VHOST_INVALID_FEATURE_BIT +}; + +static void +vhost_user_media_get_config(VirtIODevice *vdev, uint8_t *config_data) +{ + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + Error *local_err =3D NULL; + int ret; + + memset(config_data, 0, sizeof(struct virtio_media_config)); + + ret =3D vhost_dev_get_config(&media->vhost_dev, + config_data, sizeof(struct virtio_media_con= fig), + &local_err); + if (ret) { + error_report_err(local_err); + return; + } +} + +static void vhost_user_media_start(VirtIODevice *vdev) +{ + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + int i; + + if (!k->set_guest_notifiers) { + error_report("binding does not support guest notifiers"); + return; + } + + ret =3D vhost_dev_enable_notifiers(&media->vhost_dev, vdev); + if (ret < 0) { + error_report("Error enabling host notifiers: %d", -ret); + return; + } + + ret =3D k->set_guest_notifiers(qbus->parent, media->vhost_dev.nvqs, tr= ue); + if (ret < 0) { + error_report("Error binding guest notifier: %d", -ret); + goto err_host_notifiers; + } + + media->vhost_dev.acked_features =3D vdev->guest_features; + + media->vhost_dev.vq_index_end =3D media->vhost_dev.nvqs; + ret =3D vhost_dev_start(&media->vhost_dev, vdev, true); + if (ret < 0) { + error_report("Error starting vhost-user-media: %d", -ret); + goto err_guest_notifiers; + } + + /* + * guest_notifier_mask/pending not used yet, so just unmask + * everything here. virtio-pci will do the right thing by + * enabling/disabling irqfd. + */ + for (i =3D 0; i < media->vhost_dev.nvqs; i++) { + vhost_virtqueue_mask(&media->vhost_dev, vdev, i, false); + } + + return; + +err_guest_notifiers: + k->set_guest_notifiers(qbus->parent, media->vhost_dev.nvqs, false); +err_host_notifiers: + vhost_dev_disable_notifiers(&media->vhost_dev, vdev); +} + +static void vhost_user_media_stop(VirtIODevice *vdev) +{ + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + + if (!k->set_guest_notifiers) { + return; + } + + vhost_dev_stop(&media->vhost_dev, vdev, true); + + ret =3D k->set_guest_notifiers(qbus->parent, media->vhost_dev.nvqs, fa= lse); + if (ret < 0) { + error_report("vhost guest notifier cleanup failed: %d", ret); + return; + } + + vhost_dev_disable_notifiers(&media->vhost_dev, vdev); +} + +static int vhost_user_media_set_status(VirtIODevice *vdev, uint8_t status) +{ + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + bool should_start =3D virtio_device_started(vdev, status); + + if (!vdev->vm_running) { + should_start =3D false; + } + + if (media->vhost_dev.started =3D=3D should_start) { + return 0; + } + + if (should_start) { + vhost_user_media_start(vdev); + } else { + vhost_user_media_stop(vdev); + } + return 0; +} + +static uint64_t vhost_user_media_get_features(VirtIODevice *vdev, + uint64_t requested_features, + Error **errp) +{ + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + + return vhost_get_features(&media->vhost_dev, feature_bits, + requested_features); +} + +static void vhost_user_media_handle_output(VirtIODevice *vdev, VirtQueue *= vq) +{ + /* + * Not normally called; it's the daemon that handles the queue; + * however virtio's cleanup path can call this. + */ +} + +static void vhost_user_media_guest_notifier_mask(VirtIODevice *vdev, int i= dx, + bool mask) +{ + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + return; + } + + vhost_virtqueue_mask(&media->vhost_dev, vdev, idx, mask); +} + +static bool vhost_user_media_guest_notifier_pending(VirtIODevice *vdev, in= t idx) +{ + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + return false; + } + + return vhost_virtqueue_pending(&media->vhost_dev, idx); +} + +/* + * Chardev connect/disconnect events + */ + +static int vhost_user_media_handle_config_change(struct vhost_dev *dev) +{ + int ret; + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(dev->vdev); + Error *local_err =3D NULL; + + ret =3D vhost_dev_get_config(dev, (uint8_t *)&media->conf.config, + sizeof(struct virtio_media_config), &local_= err); + if (ret < 0) { + error_report("get config space failed"); + return -1; + } + + return 0; +} + +static const VhostDevConfigOps media_ops =3D { + .vhost_dev_config_notifier =3D vhost_user_media_handle_config_change, +}; + +static int vhost_user_media_connect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + + if (media->connected) { + return 0; + } + media->connected =3D true; + + /* restore vhost state */ + if (virtio_device_started(vdev, vdev->status)) { + vhost_user_media_start(vdev); + } + + return 0; +} + +static void vhost_user_media_disconnect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + + if (!media->connected) { + return; + } + media->connected =3D false; + + if (media->vhost_dev.started) { + vhost_user_media_stop(vdev); + } + + vhost_dev_cleanup(&media->vhost_dev); +} + +static void vhost_user_media_event(void *opaque, QEMUChrEvent event) +{ + DeviceState *dev =3D opaque; + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + + switch (event) { + case CHR_EVENT_OPENED: + if (vhost_user_media_connect(dev) < 0) { + qemu_chr_fe_disconnect(&media->conf.chardev); + return; + } + break; + case CHR_EVENT_CLOSED: + vhost_user_media_disconnect(dev); + break; + case CHR_EVENT_BREAK: + case CHR_EVENT_MUX_IN: + case CHR_EVENT_MUX_OUT: + /* Ignore */ + break; + } +} + +static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserMEDIA *medi= a) +{ + vhost_user_cleanup(&media->vhost_user); + virtio_delete_queue(media->command_vq); + virtio_delete_queue(media->event_vq); + virtio_cleanup(vdev); + g_free(media->vhost_dev.vqs); + media->vhost_dev.vqs =3D NULL; +} + +static void vhost_user_media_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(dev); + int ret; + + if (!media->conf.chardev.chr) { + error_setg(errp, "vhost-user-media: chardev is mandatory"); + return; + } + + if (!vhost_user_init(&media->vhost_user, &media->conf.chardev, errp)) { + return; + } + + virtio_init(vdev, VIRTIO_ID_MEDIA, sizeof(struct virtio_media_config)); + + /* one command queue and one event queue */ + media->vhost_dev.nvqs =3D 2; + media->vhost_dev.vqs =3D g_new0(struct vhost_virtqueue, + media->vhost_dev.nvqs); + media->vhost_dev.vq_index =3D 0; + + vhost_dev_set_config_notifier(&media->vhost_dev, &media_ops); + media->vhost_user.supports_config =3D true; + + ret =3D vhost_dev_init(&media->vhost_dev, &media->vhost_user, + VHOST_BACKEND_TYPE_USER, 0, errp); + if (ret < 0) { + error_report("vhost_dev_init failed: %s", strerror(-ret)); + goto vhost_dev_init_failed; + } + + /* One command queue, for sending commands */ + media->command_vq =3D virtio_add_queue(vdev, 128, + vhost_user_media_handle_output); + + if (!media->command_vq) { + error_setg_errno(errp, -1, "virtio_add_queue() failed"); + goto cmd_q_fail; + } + + /* One event queue, for sending events */ + media->event_vq =3D virtio_add_queue(vdev, 128, + vhost_user_media_handle_output); + + if (!media->event_vq) { + error_setg_errno(errp, -1, "virtio_add_queue() failed"); + goto event_q_fail; + } + + /* + * At this point the next event we will get is a connection from + * the daemon on the control socket. + */ + + qemu_chr_fe_set_handlers(&media->conf.chardev, NULL, + NULL, vhost_user_media_event, + NULL, (void *)dev, NULL, true); + + return; + +event_q_fail: + virtio_delete_queue(media->event_vq); +cmd_q_fail: + vhost_user_cleanup(&media->vhost_user); +vhost_dev_init_failed: + virtio_cleanup(vdev); +} + +static void vhost_user_media_device_unrealize(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(dev); + + /* This will stop vhost backend if appropriate. */ + vhost_user_media_set_status(vdev, 0); + + do_vhost_user_cleanup(vdev, media); +} + +static const VMStateDescription vhost_user_media_vmstate =3D { + .name =3D "vhost-user-media", + .unmigratable =3D 1, +}; + +static const Property vhost_user_media_properties[] =3D { + DEFINE_PROP_CHR("chardev", VHostUserMEDIA, conf.chardev), +}; + +static void vhost_user_media_class_init(ObjectClass *klass, const void *da= ta) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + device_class_set_props(dc, vhost_user_media_properties); + dc->vmsd =3D &vhost_user_media_vmstate; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + vdc->realize =3D vhost_user_media_device_realize; + vdc->unrealize =3D vhost_user_media_device_unrealize; + vdc->get_features =3D vhost_user_media_get_features; + vdc->get_config =3D vhost_user_media_get_config; + vdc->set_status =3D vhost_user_media_set_status; + vdc->guest_notifier_mask =3D vhost_user_media_guest_notifier_mask; + vdc->guest_notifier_pending =3D vhost_user_media_guest_notifier_pendin= g; +} + +static const TypeInfo vhost_user_media_info =3D { + .name =3D TYPE_VHOST_USER_MEDIA, + .parent =3D TYPE_VIRTIO_DEVICE, + .instance_size =3D sizeof(VHostUserMEDIA), + .class_init =3D vhost_user_media_class_init, +}; + +static void vhost_user_media_register_types(void) +{ + type_register_static(&vhost_user_media_info); +} + +type_init(vhost_user_media_register_types) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index f4d86a3655..a07ef66c58 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -198,7 +198,8 @@ const char *virtio_device_names[] =3D { [VIRTIO_ID_AUDIO_POLICY] =3D "virtio-audio-pol", [VIRTIO_ID_BT] =3D "virtio-bluetooth", [VIRTIO_ID_GPIO] =3D "virtio-gpio", - [VIRTIO_ID_SPI] =3D "virtio-spi" + [VIRTIO_ID_SPI] =3D "virtio-spi", + [VIRTIO_ID_MEDIA] =3D "virtio-media", }; =20 static const char *virtio_id_to_name(uint16_t device_id) diff --git a/include/hw/virtio/vhost-user-media.h b/include/hw/virtio/vhost= -user-media.h new file mode 100644 index 0000000000..30bdef8ce1 --- /dev/null +++ b/include/hw/virtio/vhost-user-media.h @@ -0,0 +1,47 @@ +/* + * vhost-user-media virtio device + * + * Copyright Red Hat, Inc. 2024 + * + * Authors: + * Albert Esteve + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef QEMU_VHOST_USER_MEDIA_H +#define QEMU_VHOST_USER_MEDIA_H + +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" +#include "chardev/char-fe.h" +#include "qom/object.h" + +#define TYPE_VHOST_USER_MEDIA "vhost-user-media-device" +OBJECT_DECLARE_SIMPLE_TYPE(VHostUserMEDIA, VHOST_USER_MEDIA) + +struct virtio_media_config { + uint32_t device_caps; + uint32_t device_type; + uint8_t card[32]; +}; + +typedef struct { + CharFrontend chardev; + struct virtio_media_config config; +} VHostUserMEDIAConf; + +struct VHostUserMEDIA { + /*< private >*/ + VirtIODevice parent; + VHostUserMEDIAConf conf; + struct vhost_dev vhost_dev; + VhostUserState vhost_user; + VirtQueue *command_vq; + VirtQueue *event_vq; + bool connected; + /*< public >*/ +}; + +#endif /* QEMU_VHOST_USER_MEDIA_H */ --=20 2.54.0 From nobody Sun Jul 26 11:51:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1782818640; cv=none; d=zohomail.com; s=zohoarc; b=E4OS0UWHHPHpqwRdVOUUzYjiuGkowt1gHZoHXyUEds0V6MotuJLYy78biE4YZaHSV4csRlf/TVKMiFHuJG4g0DlFu6/08E5FEcFUNpfO/BGCHTsE9yfdaYJFPe4l/eQDXGTUME6NrNHHC3Smd10BgmEEPKSqx8wfW7mjQCMzeFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782818640; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fAgskVNcOFIUtP/RrQaHagFgGhUfOdFnNQlOrd7k3bg=; b=NA85XvWKMZr4iceZ6nYk/Zbu9dCbhJgUpOeXXJyGidtcCY7z2ZVpNcGmomPwP+ITgIap4xSk6Kx8l8g4OZD2iXQAr2PaccJFI5SN0KqXVrDRHuazwpyD7lfBcQvprB00nwiqRiSz/rzQlMupHrJh9KqIwL6MTKVrzzff2oPZFbA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1782818640854269.16119217086464; Tue, 30 Jun 2026 04:24:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1weWYx-0003XT-UZ; Tue, 30 Jun 2026 07:23:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1weWYr-0003VD-6I for qemu-devel@nongnu.org; Tue, 30 Jun 2026 07:23:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1weWYp-0005eY-IS for qemu-devel@nongnu.org; Tue, 30 Jun 2026 07:23:28 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-367-qX_9pg8SPjaN62cHn8CAAw-1; Tue, 30 Jun 2026 07:23:22 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D6B3C1955F7C; Tue, 30 Jun 2026 11:23:21 +0000 (UTC) Received: from fedora (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 90F85180065F; Tue, 30 Jun 2026 11:23:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782818606; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fAgskVNcOFIUtP/RrQaHagFgGhUfOdFnNQlOrd7k3bg=; b=dw17452VJEUwY4trC6L+yNq3CKTuoFy0v0ZONTk15YDZf2q+0GJJayyvrchQq9+k1z5e3e 5guYsKtGSPB+qsUZOrlji8BdxzvYsL5/MQ5DBOcJO9rH2iesziumHTeuSPZ20ra7FmACj5 5fQW1yAGj9zX9EQUzV97Tg0cAExKbZY= X-MC-Unique: qX_9pg8SPjaN62cHn8CAAw-1 X-Mimecast-MFC-AGG-ID: qX_9pg8SPjaN62cHn8CAAw_1782818601 From: Albert Esteve To: qemu-devel@nongnu.org Cc: manos.pitsidianakis@linaro.org, Stefano Garzarella , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , Cornelia Huck , Paolo Bonzini , Albert Esteve Subject: [PATCH 3/3] hw/display/vhost-user-media: add shared memory cache BAR Date: Tue, 30 Jun 2026 13:23:10 +0200 Message-ID: <20260630112310.552606-4-aesteve@redhat.com> In-Reply-To: <20260630112310.552606-1-aesteve@redhat.com> References: <20260630112310.552606-1-aesteve@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=aesteve@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1782818642832158501 Content-Type: text/plain; charset="utf-8" Register a 4 GiB shared memory PCI BAR (BAR 2) so the guest driver can use it as a DMA cache for video buffers. The memory region is allocated on device realize and exposed to the guest through a VirtIO shared memory capability (shmem ID 0). The host must be started with a memfd-backed memory object covering at least the shared region size, e.g.: -object memory-backend-memfd,id=3Dmem,size=3D4G,share=3Don \ -numa node,memdev=3Dmem Signed-off-by: Albert Esteve Tested-by: Dorinda Bassey --- hw/display/vhost-user-media-pci.c | 28 ++++++++++++++++++++++++++++ hw/display/vhost-user-media.c | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/hw/display/vhost-user-media-pci.c b/hw/display/vhost-user-medi= a-pci.c index ad9e3900a4..838a9da71d 100644 --- a/hw/display/vhost-user-media-pci.c +++ b/hw/display/vhost-user-media-pci.c @@ -12,12 +12,18 @@ #include "hw/virtio/vhost-user-media.h" #include "hw/virtio/virtio-pci.h" =20 +/* BAR 2 is used for the shared memory cache region exposed to the guest */ +#define VIRTIO_MEDIA_PCI_CACHE_BAR 2 + +#define VIRTIO_MEDIA_PCI_SHMCAP_ID_CACHE 0 + #define TYPE_VHOST_USER_MEDIA_PCI "vhost-user-media-pci-base" OBJECT_DECLARE_SIMPLE_TYPE(VHostUserMEDIAPCI, VHOST_USER_MEDIA_PCI) =20 struct VHostUserMEDIAPCI { VirtIOPCIProxy parent_obj; VHostUserMEDIA vdev; + MemoryRegion cachebar; }; =20 static const Property vumedia_pci_properties[] =3D { @@ -31,12 +37,34 @@ static void vumedia_pci_realize(VirtIOPCIProxy *vpci_de= v, Error **errp) { VHostUserMEDIAPCI *dev =3D VHOST_USER_MEDIA_PCI(vpci_dev); DeviceState *dev_state =3D DEVICE(&dev->vdev); + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev_state); + VirtioSharedMemory *shmem; + uint64_t cache_size; =20 if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { vpci_dev->nvectors =3D 1; } =20 qdev_realize(dev_state, BUS(&vpci_dev->bus), errp); + if (*errp) { + return; + } + + shmem =3D QSIMPLEQ_LAST(&vdev->shmem_list, VirtioSharedMemory, entry); + cache_size =3D memory_region_size(&shmem->mr); + + memory_region_init(&dev->cachebar, OBJECT(vpci_dev), + "vhost-media-pci-cachebar", cache_size); + memory_region_add_subregion(&dev->cachebar, 0, &shmem->mr); + virtio_pci_add_shm_cap(vpci_dev, VIRTIO_MEDIA_PCI_CACHE_BAR, 0, + cache_size, VIRTIO_MEDIA_PCI_SHMCAP_ID_CACHE); + + /* After 'realized' so the memory region exists */ + pci_register_bar(&vpci_dev->pci_dev, VIRTIO_MEDIA_PCI_CACHE_BAR, + PCI_BASE_ADDRESS_SPACE_MEMORY | + PCI_BASE_ADDRESS_MEM_PREFETCH | + PCI_BASE_ADDRESS_MEM_TYPE_64, + &dev->cachebar); } =20 static void vumedia_pci_class_init(ObjectClass *klass, const void *data) diff --git a/hw/display/vhost-user-media.c b/hw/display/vhost-user-media.c index 5c627437e7..bbb64ea4d3 100644 --- a/hw/display/vhost-user-media.c +++ b/hw/display/vhost-user-media.c @@ -20,6 +20,8 @@ #include "hw/virtio/virtio-bus.h" #include "hw/virtio/vhost-user-media.h" =20 +#define CACHE_SIZE (1ull << 32) + static const int feature_bits[] =3D { VIRTIO_F_RING_RESET, VHOST_INVALID_FEATURE_BIT @@ -288,6 +290,8 @@ static void vhost_user_media_device_realize(DeviceState= *dev, Error **errp) =20 virtio_init(vdev, VIRTIO_ID_MEDIA, sizeof(struct virtio_media_config)); =20 + virtio_new_shmem_region(vdev, 0, CACHE_SIZE); + /* one command queue and one event queue */ media->vhost_dev.nvqs =3D 2; media->vhost_dev.vqs =3D g_new0(struct vhost_virtqueue, --=20 2.54.0