drm/radeon: fix AGP userptr handling
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / radeon / radeon_ttm.c
index 822eb36300456aee5da04f438a405534df78ace9..d73ea9c0422783fdb18e2f284e768b40d96b2082 100644 (file)
@@ -233,6 +233,7 @@ static int radeon_move_blit(struct ttm_buffer_object *bo,
        struct radeon_device *rdev;
        uint64_t old_start, new_start;
        struct radeon_fence *fence;
+       unsigned num_pages;
        int r, ridx;
 
        rdev = radeon_get_rdev(bo->bdev);
@@ -269,13 +270,12 @@ static int radeon_move_blit(struct ttm_buffer_object *bo,
 
        BUILD_BUG_ON((PAGE_SIZE % RADEON_GPU_PAGE_SIZE) != 0);
 
-       /* sync other rings */
-       fence = bo->sync_obj;
-       r = radeon_copy(rdev, old_start, new_start,
-                       new_mem->num_pages * (PAGE_SIZE / RADEON_GPU_PAGE_SIZE), /* GPU pages */
-                       &fence);
-       /* FIXME: handle copy error */
-       r = ttm_bo_move_accel_cleanup(bo, (void *)fence,
+       num_pages = new_mem->num_pages * (PAGE_SIZE / RADEON_GPU_PAGE_SIZE);
+       fence = radeon_copy(rdev, old_start, new_start, num_pages, bo->resv);
+       if (IS_ERR(fence))
+               return PTR_ERR(fence);
+
+       r = ttm_bo_move_accel_cleanup(bo, &fence->base,
                                      evict, no_wait_gpu, new_mem);
        radeon_fence_unref(&fence);
        return r;
@@ -488,31 +488,6 @@ static void radeon_ttm_io_mem_free(struct ttm_bo_device *bdev, struct ttm_mem_re
 {
 }
 
-static int radeon_sync_obj_wait(void *sync_obj, bool lazy, bool interruptible)
-{
-       return radeon_fence_wait((struct radeon_fence *)sync_obj, interruptible);
-}
-
-static int radeon_sync_obj_flush(void *sync_obj)
-{
-       return 0;
-}
-
-static void radeon_sync_obj_unref(void **sync_obj)
-{
-       radeon_fence_unref((struct radeon_fence **)sync_obj);
-}
-
-static void *radeon_sync_obj_ref(void *sync_obj)
-{
-       return radeon_fence_ref((struct radeon_fence *)sync_obj);
-}
-
-static bool radeon_sync_obj_signaled(void *sync_obj)
-{
-       return radeon_fence_signaled((struct radeon_fence *)sync_obj);
-}
-
 /*
  * TTM backend functions.
  */
@@ -700,10 +675,17 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_bo_device *bdev,
        return &gtt->ttm.ttm;
 }
 
+static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct ttm_tt *ttm)
+{
+       if (!ttm || ttm->func != &radeon_backend_func)
+               return NULL;
+       return (struct radeon_ttm_tt *)ttm;
+}
+
 static int radeon_ttm_tt_populate(struct ttm_tt *ttm)
 {
+       struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
        struct radeon_device *rdev;
-       struct radeon_ttm_tt *gtt = (void *)ttm;
        unsigned i;
        int r;
        bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
@@ -711,7 +693,7 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm)
        if (ttm->state != tt_unpopulated)
                return 0;
 
-       if (gtt->userptr) {
+       if (gtt && gtt->userptr) {
                ttm->sg = kcalloc(1, sizeof(struct sg_table), GFP_KERNEL);
                if (!ttm->sg)
                        return -ENOMEM;
@@ -766,11 +748,11 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm)
 static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm)
 {
        struct radeon_device *rdev;
-       struct radeon_ttm_tt *gtt = (void *)ttm;
+       struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
        unsigned i;
        bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
-       if (gtt->userptr) {
+       if (gtt && gtt->userptr) {
                kfree(ttm->sg);
                ttm->page_flags &= ~TTM_PAGE_FLAG_SG;
                return;
@@ -807,7 +789,7 @@ static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm)
 int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
                              uint32_t flags)
 {
-       struct radeon_ttm_tt *gtt = (void *)ttm;
+       struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
 
        if (gtt == NULL)
                return -EINVAL;
@@ -820,7 +802,7 @@ int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
 
 bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm)
 {
-       struct radeon_ttm_tt *gtt = (void *)ttm;
+       struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
 
        if (gtt == NULL)
                return false;
@@ -830,7 +812,7 @@ bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm)
 
 bool radeon_ttm_tt_is_readonly(struct ttm_tt *ttm)
 {
-       struct radeon_ttm_tt *gtt = (void *)ttm;
+       struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
 
        if (gtt == NULL)
                return false;
@@ -847,11 +829,6 @@ static struct ttm_bo_driver radeon_bo_driver = {
        .evict_flags = &radeon_evict_flags,
        .move = &radeon_bo_move,
        .verify_access = &radeon_verify_access,
-       .sync_obj_signaled = &radeon_sync_obj_signaled,
-       .sync_obj_wait = &radeon_sync_obj_wait,
-       .sync_obj_flush = &radeon_sync_obj_flush,
-       .sync_obj_unref = &radeon_sync_obj_unref,
-       .sync_obj_ref = &radeon_sync_obj_ref,
        .move_notify = &radeon_bo_move_notify,
        .fault_reserve_notify = &radeon_bo_fault_reserve_notify,
        .io_mem_reserve = &radeon_ttm_io_mem_reserve,