drm/ttm: add ttm_bo_pipeline_gutting
authorChristian König <christian.koenig@amd.com>
Tue, 20 Feb 2018 14:35:21 +0000 (15:35 +0100)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 14 Mar 2018 19:38:27 +0000 (14:38 -0500)
Allows us to gut a BO of it's backing store when the driver says that it
isn't needed any more.

Signed-off-by: Christian König <christian.koenig@amd.com>
Acked-by: Roger He <Hongbo.He@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/ttm/ttm_bo.c
drivers/gpu/drm/ttm/ttm_bo_util.c
include/drm/ttm/ttm_bo_driver.h

index ad142a92eb808937dbf50141af988935066b6dff..98e06f8bf23bf20f7ffdb8ade4d09ee34652674f 100644 (file)
@@ -622,14 +622,23 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
 
        reservation_object_assert_held(bo->resv);
 
+       placement.num_placement = 0;
+       placement.num_busy_placement = 0;
+       bdev->driver->evict_flags(bo, &placement);
+
+       if (!placement.num_placement && !placement.num_busy_placement) {
+               ret = ttm_bo_pipeline_gutting(bo);
+               if (ret)
+                       return ret;
+
+               return ttm_tt_create(bo, false);
+       }
+
        evict_mem = bo->mem;
        evict_mem.mm_node = NULL;
        evict_mem.bus.io_reserved_vm = false;
        evict_mem.bus.io_reserved_count = 0;
 
-       placement.num_placement = 0;
-       placement.num_busy_placement = 0;
-       bdev->driver->evict_flags(bo, &placement);
        ret = ttm_bo_mem_space(bo, &placement, &evict_mem, ctx);
        if (ret) {
                if (ret != -ERESTARTSYS) {
index 6d6a3f46143be30f404ebbcd383ffe6bce03ffb3..1f730b3f18e5ae206a15770e0050d4196e8d33f8 100644 (file)
@@ -801,3 +801,27 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
        return 0;
 }
 EXPORT_SYMBOL(ttm_bo_pipeline_move);
+
+int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo)
+{
+       struct ttm_buffer_object *ghost;
+       int ret;
+
+       ret = ttm_buffer_object_transfer(bo, &ghost);
+       if (ret)
+               return ret;
+
+       ret = reservation_object_copy_fences(ghost->resv, bo->resv);
+       /* Last resort, wait for the BO to be idle when we are OOM */
+       if (ret)
+               ttm_bo_wait(bo, false, false);
+
+       memset(&bo->mem, 0, sizeof(bo->mem));
+       bo->mem.mem_type = TTM_PL_SYSTEM;
+       bo->ttm = NULL;
+
+       ttm_bo_unreserve(ghost);
+       ttm_bo_unref(&ghost);
+
+       return 0;
+}
index f8e2515b401f153bc3615a071b1ca43dc7c90566..39cd6b086d3af8b8cba2e6ed9ab7cb2506ea59ac 100644 (file)
@@ -849,6 +849,15 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
                         struct dma_fence *fence, bool evict,
                         struct ttm_mem_reg *new_mem);
 
+/**
+ * ttm_bo_pipeline_gutting.
+ *
+ * @bo: A pointer to a struct ttm_buffer_object.
+ *
+ * Pipelined gutting a BO of it's backing store.
+ */
+int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo);
+
 /**
  * ttm_io_prot
  *