[Spice-devel] [spice-protocol PATCH 11/46] qxlhw: add and use qxlhw_create_primary_surface

Alon Levy alevy at redhat.com
Tue Apr 10 04:50:07 PDT 2012


---
 src/qxl.h         |    1 -
 src/qxl_driver.c  |   26 --------------------------
 src/qxl_surface.c |   24 ++++++++++++------------
 src/qxlhw.c       |    5 +++++
 src/qxlhw.h       |    2 ++
 src/qxlhw_pci.c   |   26 ++++++++++++++++++++++++++
 6 files changed, 45 insertions(+), 39 deletions(-)

diff --git a/src/qxl.h b/src/qxl.h
index 96144d6..0b00474 100644
--- a/src/qxl.h
+++ b/src/qxl.h
@@ -374,7 +374,6 @@ int		   qxl_garbage_collect (qxl_screen_t *qxl);
  * I/O port commands
  */
 void qxl_memslot_add(qxl_screen_t *qxl, uint8_t id);
-void qxl_create_primary(qxl_screen_t *qxl);
 void qxl_notify_oom(qxl_screen_t *qxl);
 
 #ifdef XSPICE
diff --git a/src/qxl_driver.c b/src/qxl_driver.c
index 0db9221..0394016 100644
--- a/src/qxl_driver.c
+++ b/src/qxl_driver.c
@@ -133,32 +133,6 @@ qxl_available_options (int chipid, int busid)
     return DefaultOptions;
 }
 
-#ifndef XSPICE
-static void qxl_wait_for_io_command(qxl_screen_t *qxl)
-{
-    struct QXLRam *ram_header = qxlhw_pci_get_ram_header(qxl->hw);
-
-    while (!(ram_header->int_pending & QXL_INTERRUPT_IO_CMD)) {
-        usleep(1);
-    }
-    ram_header->int_pending &= ~QXL_INTERRUPT_IO_CMD;
-}
-#endif
-
-void qxl_create_primary(qxl_screen_t *qxl)
-{
-#ifndef XSPICE
-    if (qxl->pci->revision >= 3) {
-        ioport_write(qxl, QXL_IO_CREATE_PRIMARY_ASYNC, 0);
-        qxl_wait_for_io_command(qxl);
-    } else {
-        ioport_write(qxl, QXL_IO_CREATE_PRIMARY, 0);
-    }
-#else
-    ioport_write(qxl, QXL_IO_CREATE_PRIMARY, 0);
-#endif
-}
-
 void qxl_notify_oom(qxl_screen_t *qxl)
 {
     ioport_write(qxl, QXL_IO_NOTIFY_OOM, 0);
diff --git a/src/qxl_surface.c b/src/qxl_surface.c
index 8052998..1747dca 100644
--- a/src/qxl_surface.c
+++ b/src/qxl_surface.c
@@ -51,6 +51,7 @@
 #include "qxl.h"
 #include "qxl_ring.h"
 #include "qxl_mem.h"
+#include "qxlhw.h"
 #include "qxlhw_pci.h"
 
 typedef struct evacuated_surface_t evacuated_surface_t;
@@ -298,9 +299,8 @@ qxl_surface_cache_create_primary (surface_cache_t	*cache,
 				  struct QXLMode	*mode)
 {
     qxl_screen_t *qxl = cache->qxl;
-    struct QXLRam *ram_header = qxlhw_pci_get_ram_header(qxl->hw);
     void *ram = qxlhw_pci_get_ram(qxl->hw);
-    struct QXLSurfaceCreate *create = &(ram_header->create_surface);
+    struct QXLSurfaceCreate create;
     pixman_format_code_t format;
     uint8_t *dev_addr;
     pixman_image_t *dev_image, *host_image;
@@ -321,16 +321,16 @@ qxl_surface_cache_create_primary (surface_cache_t	*cache,
 	return NULL;
     }
 	
-    create->width = mode->x_res;
-    create->height = mode->y_res;
-    create->stride = - mode->stride;
-    create->format = mode->bits;
-    create->position = 0; /* What is this? The Windows driver doesn't use it */
-    create->flags = 0;
-    create->type = QXL_SURF_TYPE_PRIMARY;
-    create->mem = physical_address (qxl, ram, qxl->main_mem_slot);
-
-    qxl_create_primary(qxl);
+    create.width = mode->x_res;
+    create.height = mode->y_res;
+    create.stride = - mode->stride;
+    create.format = mode->bits;
+    create.position = 0; /* What is this? The Windows driver doesn't use it */
+    create.flags = 0;
+    create.type = QXL_SURF_TYPE_PRIMARY;
+    create.mem = 0; // filled in by qxlhw_create_primary_surface
+
+    qxlhw_create_primary_surface(qxl->hw, &create);
 
     dev_addr = (uint8_t *)ram + mode->stride * (mode->y_res - 1);
 
diff --git a/src/qxlhw.c b/src/qxlhw.c
index d412c83..9706141 100644
--- a/src/qxlhw.c
+++ b/src/qxlhw.c
@@ -53,6 +53,11 @@ void *qxlhw_data_alloc(struct qxlhw *base, unsigned long size)
         return base->data_alloc(base, size);
 }
 
+void qxlhw_create_primary_surface(struct qxlhw *base, QXLSurfaceCreate *create)
+{
+        base->create_primary_surface(base, create);
+}
+
 void qxlhw_update_area(struct qxlhw *base, int surface_id, struct QXLRect rect)
 {
         base->update_area(base, surface_id, rect);
diff --git a/src/qxlhw.h b/src/qxlhw.h
index 34023d0..741d951 100644
--- a/src/qxlhw.h
+++ b/src/qxlhw.h
@@ -19,6 +19,7 @@ struct qxlhw {
     /* memory handling callbacks */
     void *(*data_alloc)(struct qxlhw *base, unsigned long size);
     void (*data_free)(struct qxlhw *base, void *p);
+    void (*create_primary_surface)(struct qxlhw *base, QXLSurfaceCreate *create);
     void (*update_area)(struct qxlhw *base, int surface_id, struct QXLRect rect);
     /* tried to avoid this. but qxl_surface.c wants to check when failing to
      * find a surface in the free list, which it populates using
@@ -33,6 +34,7 @@ void qxlhw_init(struct qxlhw *base, qxl_screen_t *qxl);
 struct qxlhw *qxlhw_create(qxl_screen_t *qxl, ScrnInfoPtr pScrn);
 
 void qxlhw_update_area(struct qxlhw *base, int surface_id, struct QXLRect rect);
+void qxlhw_create_primary_surface(struct qxlhw *base, QXLSurfaceCreate *create);
 
 /* reset vs device_reset - device_reset is just the io / drm call,
  * reset does -- what? (definition, not contents) */
diff --git a/src/qxlhw_pci.c b/src/qxlhw_pci.c
index 1caf778..ac8b6f8 100644
--- a/src/qxlhw_pci.c
+++ b/src/qxlhw_pci.c
@@ -571,6 +571,31 @@ static void qxlhw_pci_data_free(struct qxlhw *base, void *p)
     qxl_free (hw->mem, p);
 }
 
+static void qxlhw_pci_create_primary_surface(struct qxlhw *base, QXLSurfaceCreate *create)
+{
+    struct qxlhw_pci *hw = (struct qxlhw_pci *)base;
+    struct QXLRam *ram_header = (void *)(
+        (unsigned long)hw->ram + hw->rom->ram_header_offset);
+#ifndef XSPICE
+    qxl_screen_t *qxl = base->qxl;
+#endif
+
+    memcpy(&ram_header->create_surface, create, sizeof(*create));
+    ram_header->create_surface.mem =
+        qxlhw_physical_address (hw, hw->ram, hw->main_mem_slot);
+
+#ifndef XSPICE
+    if (qxl->pci->revision >= 3) {
+        qxlhw_pci_ioport_write(hw, QXL_IO_CREATE_PRIMARY_ASYNC, 0);
+        qxlhw_pci_wait_for_io_command(hw);
+    } else {
+        qxlhw_pci_ioport_write(hw, QXL_IO_CREATE_PRIMARY, 0);
+    }
+#else
+    qxlhw_pci_ioport_write(hw, QXL_IO_CREATE_PRIMARY, 0);
+#endif
+}
+
 static void qxlhw_pci_update_area(struct qxlhw *base, int surface_id, struct QXLRect rect)
 {
     struct qxlhw_pci *hw = (struct qxlhw_pci *)base;
@@ -608,6 +633,7 @@ struct qxlhw *create_qxlhw_pci(qxl_screen_t *qxl, ScrnInfoPtr pScrn)
     base->unmap_memory = qxlhw_pci_unmap_memory;
     base->data_alloc = qxlhw_pci_data_alloc;
     base->data_free = qxlhw_pci_data_free;
+    base->create_primary_surface = qxlhw_pci_create_primary_surface;
     base->update_area = qxlhw_pci_update_area;
     return base;
 }
-- 
1.7.9.3



More information about the Spice-devel mailing list