drm/radeon: switch over to the new pin interface
authorChristian König <christian.koenig@amd.com>
Mon, 21 Sep 2020 11:18:02 +0000 (13:18 +0200)
committerChristian König <christian.koenig@amd.com>
Thu, 24 Sep 2020 14:16:50 +0000 (16:16 +0200)
Stop using TTM_PL_FLAG_NO_EVICT.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Huang Rui <ray.huang@amd.com>
Link: https://patchwork.freedesktop.org/patch/391610/?series=81973&rev=1
drivers/gpu/drm/radeon/radeon.h
drivers/gpu/drm/radeon/radeon_display.c
drivers/gpu/drm/radeon/radeon_object.c
drivers/gpu/drm/radeon/radeon_object.h
drivers/gpu/drm/radeon/radeon_ttm.c

index a6d8de01194ae74722f0bee3b8bad0723d3fcae8..5d54bccebd4d643d38e3eadb1afcb4c1cd3fe042 100644 (file)
@@ -497,7 +497,6 @@ struct radeon_bo {
        struct ttm_buffer_object        tbo;
        struct ttm_bo_kmap_obj          kmap;
        u32                             flags;
-       unsigned                        pin_count;
        void                            *kptr;
        u32                             tiling_flags;
        u32                             pitch;
index 7b69d6dfe44a37455ee73147f5f88d78fe409f17..3eacf33bbe4860f7dfd15be2037720c42e95471b 100644 (file)
@@ -273,10 +273,7 @@ static void radeon_unpin_work_func(struct work_struct *__work)
        /* unpin of the old buffer */
        r = radeon_bo_reserve(work->old_rbo, false);
        if (likely(r == 0)) {
-               r = radeon_bo_unpin(work->old_rbo);
-               if (unlikely(r != 0)) {
-                       DRM_ERROR("failed to unpin buffer after flip\n");
-               }
+               radeon_bo_unpin(work->old_rbo);
                radeon_bo_unreserve(work->old_rbo);
        } else
                DRM_ERROR("failed to reserve buffer after flip\n");
@@ -607,9 +604,7 @@ pflip_cleanup:
                DRM_ERROR("failed to reserve new rbo in error path\n");
                goto cleanup;
        }
-       if (unlikely(radeon_bo_unpin(new_rbo) != 0)) {
-               DRM_ERROR("failed to unpin new rbo in error path\n");
-       }
+       radeon_bo_unpin(new_rbo);
        radeon_bo_unreserve(new_rbo);
 
 cleanup:
index 76dfed30d61c14f33cb4a5e6f7608d455b56291f..689426dd8480aab8e2200ee6d1108cdfc5f4d8c0 100644 (file)
@@ -334,8 +334,8 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
        if (radeon_ttm_tt_has_userptr(bo->rdev, bo->tbo.ttm))
                return -EPERM;
 
-       if (bo->pin_count) {
-               bo->pin_count++;
+       if (bo->tbo.pin_count) {
+               ttm_bo_pin(&bo->tbo);
                if (gpu_addr)
                        *gpu_addr = radeon_bo_gpu_offset(bo);
 
@@ -367,13 +367,11 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
                                bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
                else
                        bo->placements[i].lpfn = max_offset >> PAGE_SHIFT;
-
-               bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
        }
 
        r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
        if (likely(r == 0)) {
-               bo->pin_count = 1;
+               ttm_bo_pin(&bo->tbo);
                if (gpu_addr != NULL)
                        *gpu_addr = radeon_bo_gpu_offset(bo);
                if (domain == RADEON_GEM_DOMAIN_VRAM)
@@ -391,32 +389,15 @@ int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr)
        return radeon_bo_pin_restricted(bo, domain, 0, gpu_addr);
 }
 
-int radeon_bo_unpin(struct radeon_bo *bo)
+void radeon_bo_unpin(struct radeon_bo *bo)
 {
-       struct ttm_operation_ctx ctx = { false, false };
-       int r, i;
-
-       if (!bo->pin_count) {
-               dev_warn(bo->rdev->dev, "%p unpin not necessary\n", bo);
-               return 0;
-       }
-       bo->pin_count--;
-       if (bo->pin_count)
-               return 0;
-       for (i = 0; i < bo->placement.num_placement; i++) {
-               bo->placements[i].lpfn = 0;
-               bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
-       }
-       r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
-       if (likely(r == 0)) {
+       ttm_bo_unpin(&bo->tbo);
+       if (!bo->tbo.pin_count) {
                if (bo->tbo.mem.mem_type == TTM_PL_VRAM)
                        bo->rdev->vram_pin_size -= radeon_bo_size(bo);
                else
                        bo->rdev->gart_pin_size -= radeon_bo_size(bo);
-       } else {
-               dev_err(bo->rdev->dev, "%p validate failed for unpin\n", bo);
        }
-       return r;
 }
 
 int radeon_bo_evict_vram(struct radeon_device *rdev)
@@ -549,7 +530,7 @@ int radeon_bo_list_validate(struct radeon_device *rdev,
 
        list_for_each_entry(lobj, head, tv.head) {
                struct radeon_bo *bo = lobj->robj;
-               if (!bo->pin_count) {
+               if (!bo->tbo.pin_count) {
                        u32 domain = lobj->preferred_domains;
                        u32 allowed = lobj->allowed_domains;
                        u32 current_domain =
@@ -629,7 +610,7 @@ int radeon_bo_get_surface_reg(struct radeon_bo *bo)
                        break;
 
                old_object = reg->bo;
-               if (old_object->pin_count == 0)
+               if (old_object->tbo.pin_count == 0)
                        steal = i;
        }
 
@@ -816,7 +797,7 @@ int radeon_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
                return 0;
 
        /* Can't move a pinned BO to visible VRAM */
-       if (rbo->pin_count > 0)
+       if (rbo->tbo.pin_count > 0)
                return -EINVAL;
 
        /* hurrah the memory is not visible ! */
index 430574caaf0913b0e9d8779144752be8c2405c34..27cfb64057fef084386cfa19342232cc88a844e3 100644 (file)
@@ -146,7 +146,7 @@ extern void radeon_bo_unref(struct radeon_bo **bo);
 extern int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr);
 extern int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain,
                                    u64 max_offset, u64 *gpu_addr);
-extern int radeon_bo_unpin(struct radeon_bo *bo);
+extern void radeon_bo_unpin(struct radeon_bo *bo);
 extern int radeon_bo_evict_vram(struct radeon_device *rdev);
 extern void radeon_bo_force_delete(struct radeon_device *rdev);
 extern int radeon_bo_init(struct radeon_device *rdev);
index 6869770e2eef857df1e4aa042fe2179d5e64f9bf..ea9ffa6198da06555a7954fba6964fb8850f8dbc 100644 (file)
@@ -308,7 +308,7 @@ static int radeon_bo_move(struct ttm_buffer_object *bo, bool evict,
 
        /* Can't move a pinned BO */
        rbo = container_of(bo, struct radeon_bo, tbo);
-       if (WARN_ON_ONCE(rbo->pin_count > 0))
+       if (WARN_ON_ONCE(rbo->tbo.pin_count > 0))
                return -EINVAL;
 
        rdev = radeon_get_rdev(bo->bdev);