9ae3a8
From 5a0718f03d4da66682d5580e156c6cf4b8005891 Mon Sep 17 00:00:00 2001
9ae3a8
From: Tarun Gupta <tgupta@redhat.com>
9ae3a8
Date: Wed, 20 Jun 2018 18:54:23 +0200
9ae3a8
Subject: [PATCH 15/17] vfio/display: core & wireup
9ae3a8
9ae3a8
RH-Author: Tarun Gupta <tgupta@redhat.com>
9ae3a8
Message-id: <1529520865-18127-10-git-send-email-tgupta@redhat.com>
9ae3a8
Patchwork-id: 80918
9ae3a8
O-Subject: [RHEL7.6 qemu-kvm PATCH v3 09/11] vfio/display: core & wireup
9ae3a8
Bugzilla: 1555246
9ae3a8
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
9ae3a8
nfrastructure for display support.  Must be enabled
9ae3a8
using 'display' property.
9ae3a8
9ae3a8
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
9ae3a8
Reviewed By: Kirti Wankhede <kwankhede@nvidia.com>
9ae3a8
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
9ae3a8
(cherry picked from a9994687cb9b5f72399398a0985419f4d2b95dc5)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 hw/misc/vfio.c | 40 ++++++++++++++++++++++++++++++++++++++++
9ae3a8
 1 file changed, 40 insertions(+)
9ae3a8
9ae3a8
diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
9ae3a8
index 414b689..22d5cac 100644
9ae3a8
--- a/hw/misc/vfio.c
9ae3a8
+++ b/hw/misc/vfio.c
9ae3a8
@@ -40,6 +40,7 @@
9ae3a8
 #include "sysemu/kvm.h"
9ae3a8
 #include "sysemu/sysemu.h"
9ae3a8
 #include "trace.h"
9ae3a8
+#include "ui/console.h"
9ae3a8
 
9ae3a8
 /* #define DEBUG_VFIO */
9ae3a8
 #ifdef DEBUG_VFIO
9ae3a8
@@ -235,6 +236,7 @@ typedef struct VFIOPCIDevice {
9ae3a8
 #define VFIO_FEATURE_ENABLE_VGA (1 << VFIO_FEATURE_ENABLE_VGA_BIT)
9ae3a8
 #define VFIO_FEATURE_ENABLE_REQ_BIT 1
9ae3a8
 #define VFIO_FEATURE_ENABLE_REQ (1 << VFIO_FEATURE_ENABLE_REQ_BIT)
9ae3a8
+    OnOffAuto display;
9ae3a8
     int32_t bootindex;
9ae3a8
     uint8_t pm_cap;
9ae3a8
     bool has_vga;
9ae3a8
@@ -2760,6 +2762,33 @@ static int vfio_region_mmap(VFIORegion *region)
9ae3a8
     return 0;
9ae3a8
 }
9ae3a8
 
9ae3a8
+static int vfio_display_probe(VFIOPCIDevice *vdev)
9ae3a8
+{
9ae3a8
+    struct vfio_device_gfx_plane_info probe;
9ae3a8
+    int ret;
9ae3a8
+
9ae3a8
+    memset(&probe, 0, sizeof(probe));
9ae3a8
+    probe.argsz = sizeof(probe);
9ae3a8
+    probe.flags = VFIO_GFX_PLANE_TYPE_PROBE | VFIO_GFX_PLANE_TYPE_REGION;
9ae3a8
+    ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_QUERY_GFX_PLANE, &probe);
9ae3a8
+    if (ret == 0) {
9ae3a8
+        error_report("vfio-display: region support not implemented yet");
9ae3a8
+        return -1;
9ae3a8
+    }
9ae3a8
+
9ae3a8
+    if (vdev->display == ON_OFF_AUTO_AUTO) {
9ae3a8
+        /* not an error in automatic mode */
9ae3a8
+        return 0;
9ae3a8
+    }
9ae3a8
+
9ae3a8
+    error_report("vfio: device doesn't support any (known) display method");
9ae3a8
+    return -1;
9ae3a8
+}
9ae3a8
+
9ae3a8
+static void vfio_display_finalize(VFIOPCIDevice *vdev)
9ae3a8
+{
9ae3a8
+}
9ae3a8
+
9ae3a8
 static void vfio_region_exit(VFIORegion *region)
9ae3a8
 {
9ae3a8
     int i;
9ae3a8
@@ -4232,6 +4261,14 @@ static int vfio_initfn(PCIDevice *pdev)
9ae3a8
     }
9ae3a8
 
9ae3a8
     add_boot_device_path(vdev->bootindex, &pdev->qdev, NULL);
9ae3a8
+
9ae3a8
+    if (vdev->display != ON_OFF_AUTO_OFF) {
9ae3a8
+        ret = vfio_display_probe(vdev);
9ae3a8
+        if (ret) {
9ae3a8
+            goto out_teardown;
9ae3a8
+        }
9ae3a8
+    }
9ae3a8
+
9ae3a8
     vfio_register_err_notifier(vdev);
9ae3a8
     vfio_register_req_notifier(vdev);
9ae3a8
 
9ae3a8
@@ -4261,6 +4298,7 @@ static void vfio_exitfn(PCIDevice *pdev)
9ae3a8
         qemu_free_timer(vdev->intx.mmap_timer);
9ae3a8
     }
9ae3a8
     vfio_teardown_msi(vdev);
9ae3a8
+    vfio_display_finalize(vdev);
9ae3a8
     vfio_unmap_bars(vdev);
9ae3a8
     g_free(vdev->emulated_config_bits);
9ae3a8
     g_free(vdev->rom);
9ae3a8
@@ -4313,6 +4351,8 @@ static void vfio_instance_init(Object *obj)
9ae3a8
 static Property vfio_pci_dev_properties[] = {
9ae3a8
     DEFINE_PROP_PCI_HOST_DEVADDR("host", VFIOPCIDevice, host),
9ae3a8
     DEFINE_PROP_STRING("sysfsdev", VFIOPCIDevice, vbasedev.sysfsdev),
9ae3a8
+    DEFINE_PROP_ON_OFF_AUTO("display", VFIOPCIDevice,
9ae3a8
+                            display, ON_OFF_AUTO_AUTO),
9ae3a8
     DEFINE_PROP_UINT32("x-intx-mmap-timeout-ms", VFIOPCIDevice,
9ae3a8
                        intx.mmap_timeout, 1100),
9ae3a8
     DEFINE_PROP_BIT("x-vga", VFIOPCIDevice, features,
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8