From nobody Fri Oct 24 22:15:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151972182727446.50169947591564; Tue, 27 Feb 2018 00:57:07 -0800 (PST) Received: from localhost ([::1]:35590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqb4M-0006wO-1d for importer@patchew.org; Tue, 27 Feb 2018 03:57:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqazp-0003QU-Rv for qemu-devel@nongnu.org; Tue, 27 Feb 2018 03:52:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eqazn-00081o-0z for qemu-devel@nongnu.org; Tue, 27 Feb 2018 03:52:25 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55738 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eqazm-00080z-J4 for qemu-devel@nongnu.org; Tue, 27 Feb 2018 03:52:22 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F00540FB658; Tue, 27 Feb 2018 08:52:18 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-147.ams2.redhat.com [10.36.116.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id E32472156601; Tue, 27 Feb 2018 08:52:17 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 50F6717539; Tue, 27 Feb 2018 09:52:10 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 27 Feb 2018 09:52:08 +0100 Message-Id: <20180227085209.19151-7-kraxel@redhat.com> In-Reply-To: <20180227085209.19151-1-kraxel@redhat.com> References: <20180227085209.19151-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 27 Feb 2018 08:52:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 27 Feb 2018 08:52:18 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v5 6/7] vfio/display: adding region support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alex Williamson , Gerd Hoffmann , intel-gvt-dev@lists.freedesktop.org, Kirti Wankhede , Tina Zhang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Wire up region-based display. Signed-off-by: Gerd Hoffmann --- hw/vfio/pci.h | 1 + include/hw/vfio/vfio-common.h | 8 ++++ hw/vfio/display.c | 100 ++++++++++++++++++++++++++++++++++++++= +++- 3 files changed, 107 insertions(+), 2 deletions(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index fe2a7aeb4c..3227f9f660 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -148,6 +148,7 @@ typedef struct VFIOPCIDevice { bool no_kvm_msi; bool no_kvm_msix; bool no_geforce_quirks; + VFIODisplay *dpy; } VFIOPCIDevice; =20 uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len); diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index f3a2ac9fee..fc8ae14fb7 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -142,6 +142,14 @@ typedef struct VFIOGroup { QLIST_ENTRY(VFIOGroup) container_next; } VFIOGroup; =20 +typedef struct VFIODisplay { + QemuConsole *con; + struct { + VFIORegion buffer; + DisplaySurface *surface; + } region; +} VFIODisplay; + void vfio_put_base_device(VFIODevice *vbasedev); void vfio_disable_irqindex(VFIODevice *vbasedev, int index); void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index); diff --git a/hw/vfio/display.c b/hw/vfio/display.c index d9b4d07f20..8910f927e3 100644 --- a/hw/vfio/display.c +++ b/hw/vfio/display.c @@ -19,6 +19,103 @@ #include "qapi/error.h" #include "pci.h" =20 +/* ---------------------------------------------------------------------- = */ + +static void vfio_display_region_update(void *opaque) +{ + VFIOPCIDevice *vdev =3D opaque; + VFIODisplay *dpy =3D vdev->dpy; + struct vfio_device_gfx_plane_info plane =3D { + .argsz =3D sizeof(plane), + .flags =3D VFIO_GFX_PLANE_TYPE_REGION + }; + pixman_format_code_t format; + int ret; + + ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_QUERY_GFX_PLANE, &plane); + if (ret < 0) { + error_report("ioctl VFIO_DEVICE_QUERY_GFX_PLANE: %s", + strerror(errno)); + return; + } + if (!plane.drm_format || !plane.size) { + return; + } + format =3D qemu_drm_format_to_pixman(plane.drm_format); + if (!format) { + return; + } + + if (dpy->region.buffer.size && + dpy->region.buffer.nr !=3D plane.region_index) { + /* region changed */ + vfio_region_exit(&dpy->region.buffer); + vfio_region_finalize(&dpy->region.buffer); + dpy->region.surface =3D NULL; + } + + if (dpy->region.surface && + (surface_width(dpy->region.surface) !=3D plane.width || + surface_height(dpy->region.surface) !=3D plane.height || + surface_format(dpy->region.surface) !=3D format)) { + /* size changed */ + dpy->region.surface =3D NULL; + } + + if (!dpy->region.buffer.size) { + /* mmap region */ + ret =3D vfio_region_setup(OBJECT(vdev), &vdev->vbasedev, + &dpy->region.buffer, + plane.region_index, + "display"); + if (ret !=3D 0) { + error_report("%s: vfio_region_setup(%d): %s", + __func__, plane.region_index, strerror(-ret)); + goto err; + } + ret =3D vfio_region_mmap(&dpy->region.buffer); + if (ret !=3D 0) { + error_report("%s: vfio_region_mmap(%d): %s", __func__, + plane.region_index, strerror(-ret)); + goto err; + } + assert(dpy->region.buffer.mmaps[0].mmap !=3D NULL); + } + + if (dpy->region.surface =3D=3D NULL) { + /* create surface */ + dpy->region.surface =3D qemu_create_displaysurface_from + (plane.width, plane.height, format, + plane.stride, dpy->region.buffer.mmaps[0].mmap); + dpy_gfx_replace_surface(dpy->con, dpy->region.surface); + } + + /* full screen update */ + dpy_gfx_update(dpy->con, 0, 0, + surface_width(dpy->region.surface), + surface_height(dpy->region.surface)); + return; + +err: + vfio_region_exit(&dpy->region.buffer); + vfio_region_finalize(&dpy->region.buffer); +} + +static const GraphicHwOps vfio_display_region_ops =3D { + .gfx_update =3D vfio_display_region_update, +}; + +static int vfio_display_region_init(VFIOPCIDevice *vdev, Error **errp) +{ + vdev->dpy =3D g_new0(VFIODisplay, 1); + vdev->dpy->con =3D graphic_console_init(DEVICE(vdev), 0, + &vfio_display_region_ops, + vdev); + return 0; +} + +/* ---------------------------------------------------------------------- = */ + int vfio_display_probe(VFIOPCIDevice *vdev, Error **errp) { struct vfio_device_gfx_plane_info probe; @@ -38,8 +135,7 @@ int vfio_display_probe(VFIOPCIDevice *vdev, Error **errp) probe.flags =3D VFIO_GFX_PLANE_TYPE_PROBE | VFIO_GFX_PLANE_TYPE_REGION; ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_QUERY_GFX_PLANE, &probe); if (ret =3D=3D 0) { - error_setg(errp, "vfio-display: region support not implemented yet= "); - return -1; + return vfio_display_region_init(vdev, errp); } =20 error_setg(errp, "vfio: device doesn't support any (known) display met= hod"); --=20 2.9.3