5544c1b
From e9062966428416da41ec5f9ace3d2ef58b3265b1 Mon Sep 17 00:00:00 2001
c8dfc65
From: Alon Levy <alevy@redhat.com>
c8dfc65
Date: Wed, 22 Aug 2012 11:16:25 +0300
5544c1b
Subject: [PATCH] qxl: add QXL_IO_MONITORS_CONFIG_ASYNC
c8dfc65
c8dfc65
Revision bumped to 4 for new IO support, enabled for spice-server >=
c8dfc65
0.11.1. New io enabled if revision is 4. Revision can be set to 4.
c8dfc65
c8dfc65
[ kraxel: 3 continues to be the default revision.  Once we have a new
c8dfc65
          stable spice-server release and the qemu patches to enable
c8dfc65
          the new bits merged we'll go flip the switch and make rev4
c8dfc65
          the default ]
c8dfc65
c8dfc65
This io calls the corresponding new spice api
c8dfc65
spice_qxl_monitors_config_async to let spice-server read a new guest set
c8dfc65
monitors config and notify the client.
c8dfc65
c8dfc65
On migration reissue spice_qxl_monitors_config_async.
c8dfc65
c8dfc65
RHBZ: 770842
c8dfc65
c8dfc65
Signed-off-by: Alon Levy <alevy@redhat.com>
c8dfc65
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
c8dfc65
c8dfc65
fixup
c8dfc65
c8dfc65
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
5544c1b
(cherry picked from commit 020af1c45fec664d5d4cf3b8e5117f8bc1d691f2)
5544c1b
5544c1b
Conflicts:
5544c1b
5544c1b
	hw/qxl.c
5544c1b
5544c1b
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
c8dfc65
---
c8dfc65
 configure          |  7 ++++
5544c1b
 hw/qxl.c           | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
c8dfc65
 hw/qxl.h           |  7 ++++
c8dfc65
 trace-events       |  1 +
c8dfc65
 ui/spice-display.h |  1 +
5544c1b
 5 files changed, 111 insertions(+), 3 deletions(-)
c8dfc65
c8dfc65
diff --git a/configure b/configure
5544c1b
index 8ffddf4..b5cea26 100755
c8dfc65
--- a/configure
c8dfc65
+++ b/configure
5544c1b
@@ -2670,6 +2670,9 @@ EOF
c8dfc65
     spice="yes"
c8dfc65
     libs_softmmu="$libs_softmmu $spice_libs"
c8dfc65
     QEMU_CFLAGS="$QEMU_CFLAGS $spice_cflags"
c8dfc65
+    if $pkg_config --atleast-version=0.12.0 spice-protocol >/dev/null 2>&1; then
c8dfc65
+        spice_qxl_io_monitors_config_async="yes"
c8dfc65
+    fi
c8dfc65
   else
c8dfc65
     if test "$spice" = "yes" ; then
c8dfc65
       feature_not_found "spice"
5544c1b
@@ -3407,6 +3410,10 @@ if test "$spice" = "yes" ; then
c8dfc65
   echo "CONFIG_SPICE=y" >> $config_host_mak
c8dfc65
 fi
c8dfc65
 
c8dfc65
+if test "$spice_qxl_io_monitors_config_async" = "yes" ; then
c8dfc65
+  echo "CONFIG_QXL_IO_MONITORS_CONFIG_ASYNC=y" >> $config_host_mak
c8dfc65
+fi
c8dfc65
+
c8dfc65
 if test "$smartcard" = "yes" ; then
c8dfc65
   echo "CONFIG_SMARTCARD=y" >> $config_host_mak
c8dfc65
 fi
c8dfc65
diff --git a/hw/qxl.c b/hw/qxl.c
5544c1b
index baf9bb4..27f3779 100644
c8dfc65
--- a/hw/qxl.c
c8dfc65
+++ b/hw/qxl.c
c8dfc65
@@ -27,6 +27,11 @@
c8dfc65
 
c8dfc65
 #include "qxl.h"
c8dfc65
 
c8dfc65
+#ifndef CONFIG_QXL_IO_MONITORS_CONFIG_ASYNC
c8dfc65
+/* spice-protocol is too old, add missing definitions */
c8dfc65
+#define QXL_IO_MONITORS_CONFIG_ASYNC (QXL_IO_FLUSH_RELEASE + 1)
c8dfc65
+#endif
c8dfc65
+
c8dfc65
 /*
c8dfc65
  * NOTE: SPICE_RING_PROD_ITEM accesses memory on the pci bar and as
c8dfc65
  * such can be changed by the guest, so to avoid a guest trigerrable
c8dfc65
@@ -249,6 +254,39 @@ static void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl, qxl_async_io async)
c8dfc65
     }
c8dfc65
 }
c8dfc65
 
c8dfc65
+static void qxl_spice_monitors_config_async(PCIQXLDevice *qxl, int replay)
c8dfc65
+{
c8dfc65
+    trace_qxl_spice_monitors_config(qxl->id);
c8dfc65
+/* 0x000b01 == 0.11.1 */
c8dfc65
+#if SPICE_SERVER_VERSION >= 0x000b01 && \
c8dfc65
+    defined(CONFIG_QXL_IO_MONITORS_CONFIG_ASYNC)
c8dfc65
+    if (replay) {
c8dfc65
+        /*
c8dfc65
+         * don't use QXL_COOKIE_TYPE_IO:
c8dfc65
+         *  - we are not running yet (post_load), we will assert
c8dfc65
+         *    in send_events
c8dfc65
+         *  - this is not a guest io, but a reply, so async_io isn't set.
c8dfc65
+         */
c8dfc65
+        spice_qxl_monitors_config_async(&qxl->ssd.qxl,
c8dfc65
+                qxl->guest_monitors_config,
c8dfc65
+                MEMSLOT_GROUP_GUEST,
c8dfc65
+                (uintptr_t)qxl_cookie_new(
c8dfc65
+                    QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG,
c8dfc65
+                    0));
c8dfc65
+    } else {
c8dfc65
+        qxl->guest_monitors_config = qxl->ram->monitors_config;
c8dfc65
+        spice_qxl_monitors_config_async(&qxl->ssd.qxl,
c8dfc65
+                qxl->ram->monitors_config,
c8dfc65
+                MEMSLOT_GROUP_GUEST,
c8dfc65
+                (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
c8dfc65
+                                          QXL_IO_MONITORS_CONFIG_ASYNC));
c8dfc65
+    }
c8dfc65
+#else
c8dfc65
+    fprintf(stderr, "qxl: too old spice-protocol/spice-server for "
c8dfc65
+            "QXL_IO_MONITORS_CONFIG_ASYNC\n");
c8dfc65
+#endif
c8dfc65
+}
c8dfc65
+
c8dfc65
 void qxl_spice_reset_image_cache(PCIQXLDevice *qxl)
c8dfc65
 {
c8dfc65
     trace_qxl_spice_reset_image_cache(qxl->id);
c8dfc65
@@ -538,6 +576,7 @@ static const char *io_port_to_string(uint32_t io_port)
c8dfc65
                                         = "QXL_IO_DESTROY_ALL_SURFACES_ASYNC",
c8dfc65
         [QXL_IO_FLUSH_SURFACES_ASYNC]   = "QXL_IO_FLUSH_SURFACES_ASYNC",
c8dfc65
         [QXL_IO_FLUSH_RELEASE]          = "QXL_IO_FLUSH_RELEASE",
c8dfc65
+        [QXL_IO_MONITORS_CONFIG_ASYNC]  = "QXL_IO_MONITORS_CONFIG_ASYNC",
c8dfc65
     };
c8dfc65
     return io_port_to_string[io_port];
c8dfc65
 }
c8dfc65
@@ -819,6 +858,7 @@ static void interface_async_complete_io(PCIQXLDevice *qxl, QXLCookie *cookie)
c8dfc65
     case QXL_IO_DESTROY_PRIMARY_ASYNC:
c8dfc65
     case QXL_IO_UPDATE_AREA_ASYNC:
c8dfc65
     case QXL_IO_FLUSH_SURFACES_ASYNC:
c8dfc65
+    case QXL_IO_MONITORS_CONFIG_ASYNC:
c8dfc65
         break;
c8dfc65
     case QXL_IO_CREATE_PRIMARY_ASYNC:
c8dfc65
         qxl_create_guest_primary_complete(qxl);
c8dfc65
@@ -894,6 +934,8 @@ static void interface_async_complete(QXLInstance *sin, uint64_t cookie_token)
c8dfc65
     case QXL_COOKIE_TYPE_RENDER_UPDATE_AREA:
c8dfc65
         qxl_render_update_area_done(qxl, cookie);
c8dfc65
         break;
c8dfc65
+    case QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG:
c8dfc65
+        break;
c8dfc65
     default:
c8dfc65
         fprintf(stderr, "qxl: %s: unexpected cookie type %d\n",
c8dfc65
                 __func__, cookie->type);
c8dfc65
@@ -1315,6 +1357,13 @@ static void ioport_write(void *opaque, target_phys_addr_t addr,
c8dfc65
         return;
c8dfc65
     }
c8dfc65
 
c8dfc65
+    if (d->revision <= QXL_REVISION_STABLE_V10 &&
c8dfc65
+        io_port >= QXL_IO_FLUSH_SURFACES_ASYNC) {
c8dfc65
+        qxl_set_guest_bug(d, "unsupported io %d for revision %d\n",
c8dfc65
+            io_port, d->revision);
c8dfc65
+        return;
c8dfc65
+    }
c8dfc65
+
c8dfc65
     switch (io_port) {
c8dfc65
     case QXL_IO_RESET:
c8dfc65
     case QXL_IO_SET_MODE:
c8dfc65
@@ -1334,7 +1383,7 @@ static void ioport_write(void *opaque, target_phys_addr_t addr,
c8dfc65
             io_port, io_port_to_string(io_port));
c8dfc65
         /* be nice to buggy guest drivers */
c8dfc65
         if (io_port >= QXL_IO_UPDATE_AREA_ASYNC &&
c8dfc65
-            io_port <= QXL_IO_DESTROY_ALL_SURFACES_ASYNC) {
c8dfc65
+            io_port < QXL_IO_RANGE_SIZE) {
c8dfc65
             qxl_send_events(d, QXL_INTERRUPT_IO_CMD);
c8dfc65
         }
c8dfc65
         return;
c8dfc65
@@ -1362,6 +1411,7 @@ static void ioport_write(void *opaque, target_phys_addr_t addr,
c8dfc65
         io_port = QXL_IO_DESTROY_ALL_SURFACES;
c8dfc65
         goto async_common;
c8dfc65
     case QXL_IO_FLUSH_SURFACES_ASYNC:
c8dfc65
+    case QXL_IO_MONITORS_CONFIG_ASYNC:
c8dfc65
 async_common:
c8dfc65
         async = QXL_ASYNC;
c8dfc65
         qemu_mutex_lock(&d->async_lock);
c8dfc65
@@ -1503,6 +1553,9 @@ async_common:
c8dfc65
         d->mode = QXL_MODE_UNDEFINED;
c8dfc65
         qxl_spice_destroy_surfaces(d, async);
c8dfc65
         break;
c8dfc65
+    case QXL_IO_MONITORS_CONFIG_ASYNC:
c8dfc65
+        qxl_spice_monitors_config_async(d, 0);
c8dfc65
+        break;
c8dfc65
     default:
c8dfc65
         qxl_set_guest_bug(d, "%s: unexpected ioport=0x%x\n", __func__, io_port);
c8dfc65
     }
5544c1b
@@ -1798,6 +1851,17 @@ static int qxl_init_common(PCIQXLDevice *qxl)
c8dfc65
         io_size = 16;
c8dfc65
         break;
c8dfc65
     case 3: /* qxl-3 */
c8dfc65
+        pci_device_rev = QXL_REVISION_STABLE_V10;
c8dfc65
+        io_size = 32; /* PCI region size must be pow2 */
c8dfc65
+        break;
c8dfc65
+/* 0x000b01 == 0.11.1 */
c8dfc65
+#if SPICE_SERVER_VERSION >= 0x000b01 && \
c8dfc65
+        defined(CONFIG_QXL_IO_MONITORS_CONFIG_ASYNC)
c8dfc65
+    case 4: /* qxl-4 */
c8dfc65
+        pci_device_rev = QXL_REVISION_STABLE_V12;
5544c1b
+        io_size = msb_mask(QXL_IO_RANGE_SIZE * 2 - 1);
5544c1b
+        break;
c8dfc65
+#endif
c8dfc65
     default:
5544c1b
         pci_device_rev = QXL_DEFAULT_REVISION;
5544c1b
         io_size = msb_mask(QXL_IO_RANGE_SIZE * 2 - 1);
5544c1b
@@ -1996,7 +2060,9 @@ static int qxl_post_load(void *opaque, int version)
c8dfc65
         }
c8dfc65
         qxl_spice_loadvm_commands(d, cmds, out);
c8dfc65
         g_free(cmds);
c8dfc65
-
c8dfc65
+        if (d->guest_monitors_config) {
c8dfc65
+            qxl_spice_monitors_config_async(d, 1);
c8dfc65
+        }
c8dfc65
         break;
c8dfc65
     case QXL_MODE_COMPAT:
c8dfc65
         /* note: no need to call qxl_create_memslots, qxl_set_mode
5544c1b
@@ -2009,6 +2075,14 @@ static int qxl_post_load(void *opaque, int version)
c8dfc65
 
c8dfc65
 #define QXL_SAVE_VERSION 21
c8dfc65
 
c8dfc65
+static bool qxl_monitors_config_needed(void *opaque)
c8dfc65
+{
c8dfc65
+    PCIQXLDevice *qxl = opaque;
c8dfc65
+
c8dfc65
+    return qxl->guest_monitors_config != 0;
c8dfc65
+}
c8dfc65
+
c8dfc65
+
c8dfc65
 static VMStateDescription qxl_memslot = {
c8dfc65
     .name               = "qxl-memslot",
c8dfc65
     .version_id         = QXL_SAVE_VERSION,
5544c1b
@@ -2039,6 +2113,16 @@ static VMStateDescription qxl_surface = {
c8dfc65
     }
c8dfc65
 };
c8dfc65
 
c8dfc65
+static VMStateDescription qxl_vmstate_monitors_config = {
c8dfc65
+    .name               = "qxl/monitors-config",
c8dfc65
+    .version_id         = 1,
c8dfc65
+    .minimum_version_id = 1,
c8dfc65
+    .fields = (VMStateField[]) {
c8dfc65
+        VMSTATE_UINT64(guest_monitors_config, PCIQXLDevice),
c8dfc65
+        VMSTATE_END_OF_LIST()
c8dfc65
+    },
c8dfc65
+};
c8dfc65
+
c8dfc65
 static VMStateDescription qxl_vmstate = {
c8dfc65
     .name               = "qxl",
c8dfc65
     .version_id         = QXL_SAVE_VERSION,
5544c1b
@@ -2046,7 +2130,7 @@ static VMStateDescription qxl_vmstate = {
c8dfc65
     .pre_save           = qxl_pre_save,
c8dfc65
     .pre_load           = qxl_pre_load,
c8dfc65
     .post_load          = qxl_post_load,
c8dfc65
-    .fields = (VMStateField []) {
c8dfc65
+    .fields = (VMStateField[]) {
c8dfc65
         VMSTATE_PCI_DEVICE(pci, PCIQXLDevice),
c8dfc65
         VMSTATE_STRUCT(vga, PCIQXLDevice, 0, vmstate_vga_common, VGACommonState),
c8dfc65
         VMSTATE_UINT32(shadow_rom.mode, PCIQXLDevice),
5544c1b
@@ -2065,6 +2149,14 @@ static VMStateDescription qxl_vmstate = {
c8dfc65
         VMSTATE_UINT64(guest_cursor, PCIQXLDevice),
c8dfc65
         VMSTATE_END_OF_LIST()
c8dfc65
     },
c8dfc65
+    .subsections = (VMStateSubsection[]) {
c8dfc65
+        {
c8dfc65
+            .vmsd = &qxl_vmstate_monitors_config,
c8dfc65
+            .needed = qxl_monitors_config_needed,
c8dfc65
+        }, {
c8dfc65
+            /* empty */
c8dfc65
+        }
c8dfc65
+    }
c8dfc65
 };
c8dfc65
 
c8dfc65
 static Property qxl_properties[] = {
c8dfc65
diff --git a/hw/qxl.h b/hw/qxl.h
c8dfc65
index 172baf6..9cfedb7 100644
c8dfc65
--- a/hw/qxl.h
c8dfc65
+++ b/hw/qxl.h
c8dfc65
@@ -71,6 +71,8 @@ typedef struct PCIQXLDevice {
c8dfc65
     } guest_surfaces;
c8dfc65
     QXLPHYSICAL        guest_cursor;
c8dfc65
 
c8dfc65
+    QXLPHYSICAL        guest_monitors_config;
c8dfc65
+
c8dfc65
     QemuMutex          track_lock;
c8dfc65
 
c8dfc65
     /* thread signaling */
c8dfc65
@@ -128,7 +130,12 @@ typedef struct PCIQXLDevice {
c8dfc65
         }                                                               \
c8dfc65
     } while (0)
c8dfc65
 
c8dfc65
+#if 0
c8dfc65
+/* spice-server 0.12 is still in development */
c8dfc65
+#define QXL_DEFAULT_REVISION QXL_REVISION_STABLE_V12
c8dfc65
+#else
c8dfc65
 #define QXL_DEFAULT_REVISION QXL_REVISION_STABLE_V10
c8dfc65
+#endif
c8dfc65
 
c8dfc65
 /* qxl.c */
c8dfc65
 void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL phys, int group_id);
c8dfc65
diff --git a/trace-events b/trace-events
5544c1b
index 04b0723..8fcbc50 100644
c8dfc65
--- a/trace-events
c8dfc65
+++ b/trace-events
5544c1b
@@ -956,6 +956,7 @@ qxl_spice_destroy_surfaces(int qid, int async) "%d async=%d"
c8dfc65
 qxl_spice_destroy_surface_wait_complete(int qid, uint32_t id) "%d sid=%d"
c8dfc65
 qxl_spice_destroy_surface_wait(int qid, uint32_t id, int async) "%d sid=%d async=%d"
c8dfc65
 qxl_spice_flush_surfaces_async(int qid, uint32_t surface_count, uint32_t num_free_res) "%d s#=%d, res#=%d"
c8dfc65
+qxl_spice_monitors_config(int id) "%d"
c8dfc65
 qxl_spice_loadvm_commands(int qid, void *ext, uint32_t count) "%d ext=%p count=%d"
c8dfc65
 qxl_spice_oom(int qid) "%d"
c8dfc65
 qxl_spice_reset_cursor(int qid) "%d"
c8dfc65
diff --git a/ui/spice-display.h b/ui/spice-display.h
c8dfc65
index 672d65e..bcff114 100644
c8dfc65
--- a/ui/spice-display.h
c8dfc65
+++ b/ui/spice-display.h
c8dfc65
@@ -51,6 +51,7 @@ typedef enum qxl_async_io {
c8dfc65
 enum {
c8dfc65
     QXL_COOKIE_TYPE_IO,
c8dfc65
     QXL_COOKIE_TYPE_RENDER_UPDATE_AREA,
c8dfc65
+    QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG,
c8dfc65
 };
c8dfc65
 
c8dfc65
 typedef struct QXLCookie {