drm/radeon: track pinned memory (v2)
authorAlex Deucher <alexander.deucher@amd.com>
Thu, 17 Jul 2014 16:09:25 +0000 (12:09 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 5 Aug 2014 12:53:33 +0000 (08:53 -0400)
So we know how large an allocation we can allow.

v2: incorporate Michel's comments

Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
drivers/gpu/drm/radeon/radeon.h
drivers/gpu/drm/radeon/radeon_object.c

index 67e9931fd76ad2f42559bc367e8415b533122a2e..ee101b24ede148e89a91861aedcdaba7d74064c5 100644 (file)
@@ -2353,6 +2353,10 @@ struct radeon_device {
 
        struct dev_pm_domain vga_pm_domain;
        bool have_disp_power_ref;
+
+       /* tracking pinned memory */
+       u64 vram_pin_size;
+       u64 gart_pin_size;
 };
 
 bool radeon_is_px(struct drm_device *dev);
index 1b05a4de5c0ad58798c156bd50bbff38bee72fad..a00cf17a051044314fbeb175bd8c6a0f637950a2 100644 (file)
@@ -306,9 +306,13 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
                bo->pin_count = 1;
                if (gpu_addr != NULL)
                        *gpu_addr = radeon_bo_gpu_offset(bo);
-       }
-       if (unlikely(r != 0))
+               if (domain == RADEON_GEM_DOMAIN_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 pin failed\n", bo);
+       }
        return r;
 }
 
@@ -331,8 +335,14 @@ int radeon_bo_unpin(struct radeon_bo *bo)
        for (i = 0; i < bo->placement.num_placement; i++)
                bo->placements[i] &= ~TTM_PL_FLAG_NO_EVICT;
        r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
-       if (unlikely(r != 0))
+       if (likely(r == 0)) {
+               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;
 }