carlwgeorge / rpms / qemu

Forked from rpms/qemu a year ago
Clone
5544c1b
From 1c74b60fa972c9489f9cf8fa59165dedd0c23de2 Mon Sep 17 00:00:00 2001
c8dfc65
From: Gerd Hoffmann <kraxel@redhat.com>
c8dfc65
Date: Tue, 4 Sep 2012 11:39:41 +0200
5544c1b
Subject: [PATCH] spice: make number of surfaces runtime-configurable.
c8dfc65
c8dfc65
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
c8dfc65
---
c8dfc65
 hw/qxl.c           | 31 +++++++++++++++++--------------
c8dfc65
 hw/qxl.h           |  3 +--
c8dfc65
 ui/spice-display.c |  5 ++++-
c8dfc65
 ui/spice-display.h |  3 +--
c8dfc65
 4 files changed, 23 insertions(+), 19 deletions(-)
c8dfc65
c8dfc65
diff --git a/hw/qxl.c b/hw/qxl.c
5544c1b
index 71879fe..83df499 100644
c8dfc65
--- a/hw/qxl.c
c8dfc65
+++ b/hw/qxl.c
5544c1b
@@ -238,7 +238,8 @@ static void qxl_spice_destroy_surfaces_complete(PCIQXLDevice *qxl)
c8dfc65
 {
c8dfc65
     trace_qxl_spice_destroy_surfaces_complete(qxl->id);
c8dfc65
     qemu_mutex_lock(&qxl->track_lock);
c8dfc65
-    memset(&qxl->guest_surfaces.cmds, 0, sizeof(qxl->guest_surfaces.cmds));
c8dfc65
+    memset(qxl->guest_surfaces.cmds, 0,
c8dfc65
+           sizeof(qxl->guest_surfaces.cmds) * qxl->ssd.num_surfaces);
c8dfc65
     qxl->guest_surfaces.count = 0;
c8dfc65
     qemu_mutex_unlock(&qxl->track_lock);
c8dfc65
 }
5544c1b
@@ -347,7 +348,7 @@ static void init_qxl_rom(PCIQXLDevice *d)
c8dfc65
     rom->slot_id_bits  = MEMSLOT_SLOT_BITS;
c8dfc65
     rom->slots_start   = 1;
c8dfc65
     rom->slots_end     = NUM_MEMSLOTS - 1;
c8dfc65
-    rom->n_surfaces    = cpu_to_le32(NUM_SURFACES);
c8dfc65
+    rom->n_surfaces    = cpu_to_le32(d->ssd.num_surfaces);
c8dfc65
 
c8dfc65
     for (i = 0, n = 0; i < ARRAY_SIZE(qxl_modes); i++) {
c8dfc65
         fb = qxl_modes[i].y_res * qxl_modes[i].stride;
5544c1b
@@ -451,9 +452,9 @@ static int qxl_track_command(PCIQXLDevice *qxl, struct QXLCommandExt *ext)
c8dfc65
         }
c8dfc65
         uint32_t id = le32_to_cpu(cmd->surface_id);
c8dfc65
 
c8dfc65
-        if (id >= NUM_SURFACES) {
c8dfc65
+        if (id >= qxl->ssd.num_surfaces) {
c8dfc65
             qxl_set_guest_bug(qxl, "QXL_CMD_SURFACE id %d >= %d", id,
c8dfc65
-                              NUM_SURFACES);
c8dfc65
+                              qxl->ssd.num_surfaces);
c8dfc65
             return 1;
c8dfc65
         }
c8dfc65
         qemu_mutex_lock(&qxl->track_lock);
5544c1b
@@ -529,7 +530,7 @@ static void interface_get_init_info(QXLInstance *sin, QXLDevInitInfo *info)
c8dfc65
     info->num_memslots_groups = NUM_MEMSLOTS_GROUPS;
c8dfc65
     info->internal_groupslot_id = 0;
c8dfc65
     info->qxl_ram_size = le32_to_cpu(qxl->shadow_rom.num_pages) << TARGET_PAGE_BITS;
c8dfc65
-    info->n_surfaces = NUM_SURFACES;
c8dfc65
+    info->n_surfaces = qxl->ssd.num_surfaces;
c8dfc65
 }
c8dfc65
 
c8dfc65
 static const char *qxl_mode_to_string(int mode)
5544c1b
@@ -1438,7 +1439,7 @@ async_common:
c8dfc65
         QXLCookie *cookie = NULL;
c8dfc65
         QXLRect update = d->ram->update_area;
c8dfc65
 
c8dfc65
-        if (d->ram->update_surface > NUM_SURFACES) {
c8dfc65
+        if (d->ram->update_surface > d->ssd.num_surfaces) {
c8dfc65
             qxl_set_guest_bug(d, "QXL_IO_UPDATE_AREA: invalid surface id %d\n",
c8dfc65
                               d->ram->update_surface);
c8dfc65
             return;
5544c1b
@@ -1538,7 +1539,7 @@ async_common:
c8dfc65
         }
c8dfc65
         break;
c8dfc65
     case QXL_IO_DESTROY_SURFACE_WAIT:
c8dfc65
-        if (val >= NUM_SURFACES) {
c8dfc65
+        if (val >= d->ssd.num_surfaces) {
c8dfc65
             qxl_set_guest_bug(d, "QXL_IO_DESTROY_SURFACE (async=%d):"
c8dfc65
                              "%" PRIu64 " >= NUM_SURFACES", async, val);
c8dfc65
             goto cancel_async;
5544c1b
@@ -1717,7 +1718,7 @@ static void qxl_dirty_surfaces(PCIQXLDevice *qxl)
c8dfc65
     vram_start =  (intptr_t)memory_region_get_ram_ptr(&qxl->vram_bar);
c8dfc65
 
c8dfc65
     /* dirty the off-screen surfaces */
c8dfc65
-    for (i = 0; i < NUM_SURFACES; i++) {
c8dfc65
+    for (i = 0; i < qxl->ssd.num_surfaces; i++) {
c8dfc65
         QXLSurfaceCmd *cmd;
c8dfc65
         intptr_t surface_offset;
c8dfc65
         int surface_size;
5544c1b
@@ -1845,7 +1846,6 @@ static int qxl_init_common(PCIQXLDevice *qxl)
c8dfc65
     qxl->mode = QXL_MODE_UNDEFINED;
c8dfc65
     qxl->generation = 1;
c8dfc65
     qxl->num_memslots = NUM_MEMSLOTS;
c8dfc65
-    qxl->num_surfaces = NUM_SURFACES;
c8dfc65
     qemu_mutex_init(&qxl->track_lock);
c8dfc65
     qemu_mutex_init(&qxl->async_lock);
c8dfc65
     qxl->current_async = QXL_UNDEFINED_IO;
5544c1b
@@ -1887,6 +1887,7 @@ static int qxl_init_common(PCIQXLDevice *qxl)
c8dfc65
     init_qxl_rom(qxl);
c8dfc65
     init_qxl_ram(qxl);
c8dfc65
 
c8dfc65
+    qxl->guest_surfaces.cmds = g_new0(QXLPHYSICAL, qxl->ssd.num_surfaces);
c8dfc65
     memory_region_init_ram(&qxl->vram_bar, "qxl.vram", qxl->vram_size);
c8dfc65
     vmstate_register_ram(&qxl->vram_bar, &qxl->pci.qdev);
c8dfc65
     memory_region_init_alias(&qxl->vram32_bar, "qxl.vram32", &qxl->vram_bar,
5544c1b
@@ -2052,8 +2053,8 @@ static int qxl_post_load(void *opaque, int version)
c8dfc65
         qxl_create_guest_primary(d, 1, QXL_SYNC);
c8dfc65
 
c8dfc65
         /* replay surface-create and cursor-set commands */
c8dfc65
-        cmds = g_malloc0(sizeof(QXLCommandExt) * (NUM_SURFACES + 1));
c8dfc65
-        for (in = 0, out = 0; in < NUM_SURFACES; in++) {
c8dfc65
+        cmds = g_malloc0(sizeof(QXLCommandExt) * (d->ssd.num_surfaces + 1));
c8dfc65
+        for (in = 0, out = 0; in < d->ssd.num_surfaces; in++) {
c8dfc65
             if (d->guest_surfaces.cmds[in] == 0) {
c8dfc65
                 continue;
c8dfc65
             }
5544c1b
@@ -2153,9 +2154,10 @@ static VMStateDescription qxl_vmstate = {
c8dfc65
                              qxl_memslot, struct guest_slots),
c8dfc65
         VMSTATE_STRUCT(guest_primary.surface, PCIQXLDevice, 0,
c8dfc65
                        qxl_surface, QXLSurfaceCreate),
c8dfc65
-        VMSTATE_INT32_EQUAL(num_surfaces, PCIQXLDevice),
c8dfc65
-        VMSTATE_ARRAY(guest_surfaces.cmds, PCIQXLDevice, NUM_SURFACES, 0,
c8dfc65
-                      vmstate_info_uint64, uint64_t),
c8dfc65
+        VMSTATE_INT32_EQUAL(ssd.num_surfaces, PCIQXLDevice),
c8dfc65
+        VMSTATE_VARRAY_INT32(guest_surfaces.cmds, PCIQXLDevice,
c8dfc65
+                             ssd.num_surfaces, 0,
c8dfc65
+                             vmstate_info_uint64, uint64_t),
c8dfc65
         VMSTATE_UINT64(guest_cursor, PCIQXLDevice),
c8dfc65
         VMSTATE_END_OF_LIST()
c8dfc65
     },
5544c1b
@@ -2183,6 +2185,7 @@ static Property qxl_properties[] = {
c8dfc65
         DEFINE_PROP_UINT32("vram_size_mb", PCIQXLDevice, vram32_size_mb, -1),
c8dfc65
         DEFINE_PROP_UINT32("vram64_size_mb", PCIQXLDevice, vram_size_mb, -1),
c8dfc65
         DEFINE_PROP_UINT32("vgamem_mb", PCIQXLDevice, vgamem_size_mb, 16),
c8dfc65
+        DEFINE_PROP_INT32("surfaces", PCIQXLDevice, ssd.num_surfaces, 1024),
c8dfc65
         DEFINE_PROP_END_OF_LIST(),
c8dfc65
 };
c8dfc65
 
c8dfc65
diff --git a/hw/qxl.h b/hw/qxl.h
c8dfc65
index 9cfedb7..5553824 100644
c8dfc65
--- a/hw/qxl.h
c8dfc65
+++ b/hw/qxl.h
c8dfc65
@@ -40,7 +40,6 @@ typedef struct PCIQXLDevice {
c8dfc65
     uint32_t           revision;
c8dfc65
 
c8dfc65
     int32_t            num_memslots;
c8dfc65
-    int32_t            num_surfaces;
c8dfc65
 
c8dfc65
     uint32_t           current_async;
c8dfc65
     QemuMutex          async_lock;
c8dfc65
@@ -65,7 +64,7 @@ typedef struct PCIQXLDevice {
c8dfc65
     } guest_primary;
c8dfc65
 
c8dfc65
     struct surfaces {
c8dfc65
-        QXLPHYSICAL    cmds[NUM_SURFACES];
c8dfc65
+        QXLPHYSICAL    *cmds;
c8dfc65
         uint32_t       count;
c8dfc65
         uint32_t       max;
c8dfc65
     } guest_surfaces;
c8dfc65
diff --git a/ui/spice-display.c b/ui/spice-display.c
c8dfc65
index 1c31418..99bc665 100644
c8dfc65
--- a/ui/spice-display.c
c8dfc65
+++ b/ui/spice-display.c
c8dfc65
@@ -317,6 +317,9 @@ void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd, DisplayState *ds)
c8dfc65
     qemu_mutex_init(&ssd->lock);
c8dfc65
     ssd->mouse_x = -1;
c8dfc65
     ssd->mouse_y = -1;
c8dfc65
+    if (ssd->num_surfaces == 0) {
c8dfc65
+        ssd->num_surfaces = 1024;
c8dfc65
+    }
c8dfc65
     ssd->bufsize = (16 * 1024 * 1024);
c8dfc65
     ssd->buf = g_malloc(ssd->bufsize);
c8dfc65
 }
c8dfc65
@@ -427,7 +430,7 @@ static void interface_get_init_info(QXLInstance *sin, QXLDevInitInfo *info)
c8dfc65
     info->num_memslots_groups = NUM_MEMSLOTS_GROUPS;
c8dfc65
     info->internal_groupslot_id = 0;
c8dfc65
     info->qxl_ram_size = ssd->bufsize;
c8dfc65
-    info->n_surfaces = NUM_SURFACES;
c8dfc65
+    info->n_surfaces = ssd->num_surfaces;
c8dfc65
 }
c8dfc65
 
c8dfc65
 static int interface_get_command(QXLInstance *sin, struct QXLCommandExt *ext)
c8dfc65
diff --git a/ui/spice-display.h b/ui/spice-display.h
c8dfc65
index bcff114..512ab78 100644
c8dfc65
--- a/ui/spice-display.h
c8dfc65
+++ b/ui/spice-display.h
c8dfc65
@@ -32,8 +32,6 @@
c8dfc65
 #define MEMSLOT_GROUP_GUEST 1
c8dfc65
 #define NUM_MEMSLOTS_GROUPS 2
c8dfc65
 
c8dfc65
-#define NUM_SURFACES 1024
c8dfc65
-
c8dfc65
 /*
c8dfc65
  * Internal enum to differenciate between options for
c8dfc65
  * io calls that have a sync (old) version and an _async (new)
c8dfc65
@@ -80,6 +78,7 @@ struct SimpleSpiceDisplay {
c8dfc65
     QXLInstance qxl;
c8dfc65
     uint32_t unique;
c8dfc65
     QemuPfConv *conv;
c8dfc65
+    int32_t num_surfaces;
c8dfc65
 
c8dfc65
     QXLRect dirty;
c8dfc65
     int notify;
c8dfc65
-- 
5544c1b
1.7.12.1
c8dfc65