From nobody Tue Feb 10 23:53:03 2026 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507644350684815.3851000414267; Tue, 10 Oct 2017 07:05:50 -0700 (PDT) Received: from localhost ([::1]:35252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1vAG-0002uZ-QU for importer@patchew.org; Tue, 10 Oct 2017 10:05:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1v8O-0001ja-5c for qemu-devel@nongnu.org; Tue, 10 Oct 2017 10:03:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1v8J-00048P-0P for qemu-devel@nongnu.org; Tue, 10 Oct 2017 10:03:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46202) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1v8I-000482-OG for qemu-devel@nongnu.org; Tue, 10 Oct 2017 10:03:42 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1ABBC059B63; Tue, 10 Oct 2017 14:03:41 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-239.ams2.redhat.com [10.36.116.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id E08CF69549; Tue, 10 Oct 2017 14:03:40 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 5ABB74FD41; Tue, 10 Oct 2017 16:03:34 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C1ABBC059B63 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=kraxel@redhat.com From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 16:03:33 +0200 Message-Id: <20171010140334.8231-6-kraxel@redhat.com> In-Reply-To: <20171010140334.8231-1-kraxel@redhat.com> References: <20171010140334.8231-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 10 Oct 2017 14:03:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RfC PATCH 5/6] 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 , intel-gvt-dev@lists.freedesktop.org, Gerd Hoffmann , 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. UNTESTED. Signed-off-by: Gerd Hoffmann --- hw/vfio/pci.h | 6 ++++ hw/vfio/display.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++= ++-- 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 3c1b0a33ab..c03c4b3eb0 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -146,6 +146,12 @@ typedef struct VFIOPCIDevice { bool no_kvm_intx; bool no_kvm_msi; bool no_kvm_msix; + /* vgpu local display */ + QemuConsole *display_con; + uint32_t region_index; + uint32_t region_size; + void *region_mmap; + DisplaySurface *region_surface; } VFIOPCIDevice; =20 uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len); diff --git a/hw/vfio/display.c b/hw/vfio/display.c index 064ec95f3e..8211bcc6d4 100644 --- a/hw/vfio/display.c +++ b/hw/vfio/display.c @@ -18,6 +18,99 @@ #include "ui/console.h" #include "pci.h" =20 +/* ---------------------------------------------------------------------- = */ + +static void vfio_display_region_update(void *opaque) +{ + VFIOPCIDevice *vdev =3D opaque; + struct vfio_device_gfx_plane_info plane; + struct vfio_region_info *region =3D NULL; + pixman_format_code_t format =3D PIXMAN_x8r8g8b8; + int ret; + + memset(&plane, 0, sizeof(plane)); + plane.argsz =3D sizeof(plane); + plane.flags =3D VFIO_GFX_PLANE_TYPE_REGION; + ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_QUERY_GFX_PLANE, &plane); + if (ret < 0) { + fprintf(stderr, "ioctl VFIO_DEVICE_QUERY_GFX_PLANE: %s\n", + strerror(errno)); + return; + } + if (!plane.drm_format || !plane.size) { + return; + } + format =3D qemu_drm_format_to_pixman(plane.drm_format); + + if (vdev->region_mmap && vdev->region_index !=3D plane.region_index) { + /* region changed */ + munmap(vdev->region_mmap, vdev->region_size); + vdev->region_mmap =3D NULL; + vdev->region_surface =3D NULL; + } + + if (vdev->region_surface && + (surface_width(vdev->region_surface) !=3D plane.width || + surface_height(vdev->region_surface) !=3D plane.height || + surface_format(vdev->region_surface) !=3D format)) { + /* size changed */ + vdev->region_surface =3D NULL; + } + + if (vdev->region_mmap =3D=3D NULL) { + /* mmap region */ + ret =3D vfio_get_region_info(&vdev->vbasedev, plane.region_index, + ®ion); + if (ret !=3D 0) { + fprintf(stderr, "%s: vfio_get_region_info(%d): %s\n", + __func__, plane.region_index, strerror(-ret)); + return; + } + vdev->region_size =3D region->size; + vdev->region_mmap =3D mmap(NULL, region->size, + PROT_READ, MAP_SHARED, + vdev->vbasedev.fd, + region->offset); + if (vdev->region_mmap =3D=3D MAP_FAILED) { + fprintf(stderr, "%s: mmap region %d: %s\n", __func__, + plane.region_index, strerror(errno)); + vdev->region_mmap =3D NULL; + g_free(region); + return; + } + g_free(region); + } + + if (vdev->region_surface =3D=3D NULL) { + /* create surface */ + vdev->region_surface =3D qemu_create_displaysurface_from + (plane.width, plane.height, format, + plane.stride, vdev->region_mmap); + dpy_gfx_replace_surface(vdev->display_con, vdev->region_surface); + } + + /* full screen update */ + dpy_gfx_update(vdev->display_con, 0, 0, + surface_width(vdev->region_surface), + surface_height(vdev->region_surface)); + +} + +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->display_con =3D graphic_console_init(DEVICE(vdev), 0, + &vfio_display_region_ops, + vdev); + /* TODO: disable hotplug (there is no graphic_console_close) */ + return 0; +} + +/* ---------------------------------------------------------------------- = */ + int vfio_display_probe(VFIOPCIDevice *vdev, Error **errp) { struct vfio_device_gfx_plane_info probe; @@ -37,8 +130,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