From 2a1c66fae27ea188393ead7618910ca7c6fcf6ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Tue, 12 Jun 2018 12:07:33 +0200 Subject: [PATCH 1/3] drm/amdgpu: Refactor amdgpu_vram_mgr_bo_sizes helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No functional change intended. Signed-off-by: Michel Dänzer --- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 16 +++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 23 ++++++++++++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index f5b0b180a6cc..c2ab9c3b019f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -917,9 +917,11 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type); if (domain == AMDGPU_GEM_DOMAIN_VRAM) { - adev->vram_pin_size += amdgpu_bo_size(bo); - if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS) - adev->invisible_pin_size += amdgpu_bo_size(bo); + u64 visible, invisible; + + amdgpu_vram_mgr_bo_sizes(bo, &visible, &invisible); + adev->vram_pin_size += visible + invisible; + adev->invisible_pin_size += invisible; } else if (domain == AMDGPU_GEM_DOMAIN_GTT) { adev->gart_pin_size += amdgpu_bo_size(bo); } @@ -980,9 +982,11 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo) } if (bo->tbo.mem.mem_type == TTM_PL_VRAM) { - adev->vram_pin_size -= amdgpu_bo_size(bo); - if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS) - adev->invisible_pin_size -= amdgpu_bo_size(bo); + u64 visible, invisible; + + amdgpu_vram_mgr_bo_sizes(bo, &visible, &invisible); + adev->vram_pin_size -= visible + invisible; + adev->invisible_pin_size -= invisible; } else if (bo->tbo.mem.mem_type == TTM_PL_TT) { adev->gart_pin_size -= amdgpu_bo_size(bo); } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h index e969c879d87e..5722835b12c2 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h @@ -73,6 +73,8 @@ bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_mem_reg *mem); uint64_t amdgpu_gtt_mgr_usage(struct ttm_mem_type_manager *man); int amdgpu_gtt_mgr_recover(struct ttm_mem_type_manager *man); +void amdgpu_vram_mgr_bo_sizes(struct amdgpu_bo *bo, u64 *visible, + u64 *invisible); uint64_t amdgpu_vram_mgr_usage(struct ttm_mem_type_manager *man); uint64_t amdgpu_vram_mgr_vis_usage(struct ttm_mem_type_manager *man); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c index ba009571e252..09095233c62c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c @@ -96,6 +96,29 @@ static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev, adev->gmc.visible_vram_size : end) - start; } +/** + * amdgpu_vram_mgr_bo_sizes - calculate (in)visible VRAM sizes of an &amdgpu_bo + * buffer object + * + * @bo: &amdgpu_bo buffer object + * @visible: pointer to visible VRAM size value (out) + * @invisible: pointer to invisible VRAM size value (out) + * + * Calculates how much of the given &amdgpu_bo buffer object lies in CPU + * (in)visible VRAM, and stores the values to the given pointers. + */ +void amdgpu_vram_mgr_bo_sizes(struct amdgpu_bo *bo, u64 *visible, + u64 *invisible) +{ + if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS) { + *visible = 0; + *invisible = amdgpu_bo_size(bo); + } else { + *visible = amdgpu_bo_size(bo); + *invisible = 0; + } +} + /** * amdgpu_vram_mgr_new - allocate new ranges * -- 2.17.1