Add a function to bufmgr_fake to evict all buffers in the GTT.
authorEric Anholt <eric@anholt.net>
Thu, 5 Jun 2008 15:44:46 +0000 (08:44 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 5 Jun 2008 15:45:39 +0000 (08:45 -0700)
This will be used by the X Server for VT switch.

libdrm/intel/intel_bufmgr.h
libdrm/intel/intel_bufmgr_fake.c

index b9542ea..1cf0d51 100644 (file)
@@ -85,6 +85,7 @@ void intel_bo_fake_disable_backing_store(dri_bo *bo,
                                         void (*invalidate_cb)(dri_bo *bo,
                                                               void *ptr),
                                         void *ptr);
+void intel_bufmgr_fake_evict_all(dri_bufmgr *bufmgr);
 
 int intel_bo_emit_reloc(dri_bo *reloc_buf,
                        uint32_t read_domains, uint32_t write_domain,
index 1bddbea..3f5a22d 100644 (file)
@@ -125,7 +125,6 @@ typedef struct _bufmgr_fake {
     * List of blocks which have an expired fence and are ready to be evicted.
     */
    struct block lru;
-                                /* then to bufmgr->lru or free() */
 
    unsigned int last_fence;
 
@@ -1141,6 +1140,40 @@ dri_fake_check_aperture_space(dri_bo *bo)
    return 0;
 }
 
+/**
+ * Evicts all buffers, waiting for fences to pass and copying contents out
+ * as necessary.
+ *
+ * Used by the X Server on LeaveVT, when the card memory is no longer our
+ * own.
+ */
+void
+intel_bufmgr_fake_evict_all(dri_bufmgr *bufmgr)
+{
+   dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bufmgr;
+   struct block *block, *tmp;
+
+   bufmgr_fake->need_fence = 1;
+   bufmgr_fake->fail = 0;
+
+   /* Wait for hardware idle.  We don't know where acceleration has been
+    * happening, so we'll need to wait anyway before letting anything get
+    * put on the card again.
+    */
+   dri_bufmgr_fake_wait_idle(bufmgr_fake);
+
+   /* Check that we hadn't released the lock without having fenced the last
+    * set of buffers.
+    */
+   assert(DRMLISTEMPTY(&bufmgr_fake->fenced));
+   assert(DRMLISTEMPTY(&bufmgr_fake->on_hardware));
+
+   DRMLISTFOREACHSAFE(block, tmp, &bufmgr_fake->lru) {
+      /* Releases the memory, and memcpys dirty contents out if necessary. */
+      free_block(bufmgr_fake, block);
+   }
+}
+
 dri_bufmgr *
 intel_bufmgr_fake_init(unsigned long low_offset, void *low_virtual,
                       unsigned long size,