Commit bb812f1e authored by Junwei Zhang's avatar Junwei Zhang Committed by Alex Deucher

drm/amdgpu: allocate gart memory when it's required (v3)

Instead of calling gart address space on every bo pin,
allocates it on demand

v2: fix error handling
v3: drop the change on amdgpu_amdkfd_gpuvm.c, not needed.
Signed-off-by: default avatarJunwei Zhang <Jerry.Zhang@amd.com>
Acked-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 7b7c6c81
...@@ -280,6 +280,12 @@ int alloc_gtt_mem(struct kgd_dev *kgd, size_t size, ...@@ -280,6 +280,12 @@ int alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
goto allocate_mem_pin_bo_failed; goto allocate_mem_pin_bo_failed;
} }
r = amdgpu_ttm_alloc_gart(&bo->tbo);
if (r) {
dev_err(adev->dev, "%p bind failed\n", bo);
goto allocate_mem_kmap_bo_failed;
}
r = amdgpu_bo_kmap(bo, &cpu_ptr_tmp); r = amdgpu_bo_kmap(bo, &cpu_ptr_tmp);
if (r) { if (r) {
dev_err(adev->dev, dev_err(adev->dev,
......
...@@ -96,11 +96,16 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size, ...@@ -96,11 +96,16 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
if (unlikely(r != 0)) if (unlikely(r != 0))
goto out_cleanup; goto out_cleanup;
r = amdgpu_bo_pin(sobj, sdomain); r = amdgpu_bo_pin(sobj, sdomain);
saddr = amdgpu_bo_gpu_offset(sobj); if (r) {
amdgpu_bo_unreserve(sobj);
goto out_cleanup;
}
r = amdgpu_ttm_alloc_gart(&sobj->tbo);
amdgpu_bo_unreserve(sobj); amdgpu_bo_unreserve(sobj);
if (r) { if (r) {
goto out_cleanup; goto out_cleanup;
} }
saddr = amdgpu_bo_gpu_offset(sobj);
bp.domain = ddomain; bp.domain = ddomain;
r = amdgpu_bo_create(adev, &bp, &dobj); r = amdgpu_bo_create(adev, &bp, &dobj);
if (r) { if (r) {
...@@ -110,11 +115,16 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size, ...@@ -110,11 +115,16 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
if (unlikely(r != 0)) if (unlikely(r != 0))
goto out_cleanup; goto out_cleanup;
r = amdgpu_bo_pin(dobj, ddomain); r = amdgpu_bo_pin(dobj, ddomain);
daddr = amdgpu_bo_gpu_offset(dobj); if (r) {
amdgpu_bo_unreserve(sobj);
goto out_cleanup;
}
r = amdgpu_ttm_alloc_gart(&dobj->tbo);
amdgpu_bo_unreserve(dobj); amdgpu_bo_unreserve(dobj);
if (r) { if (r) {
goto out_cleanup; goto out_cleanup;
} }
daddr = amdgpu_bo_gpu_offset(dobj);
if (adev->mman.buffer_funcs) { if (adev->mman.buffer_funcs) {
time = amdgpu_benchmark_do_move(adev, size, saddr, daddr, n); time = amdgpu_benchmark_do_move(adev, size, saddr, daddr, n);
......
...@@ -194,6 +194,12 @@ int amdgpu_display_crtc_page_flip_target(struct drm_crtc *crtc, ...@@ -194,6 +194,12 @@ int amdgpu_display_crtc_page_flip_target(struct drm_crtc *crtc,
goto unreserve; goto unreserve;
} }
r = amdgpu_ttm_alloc_gart(&new_abo->tbo);
if (unlikely(r != 0)) {
DRM_ERROR("%p bind failed\n", new_abo);
goto unpin;
}
r = reservation_object_get_fences_rcu(new_abo->tbo.resv, &work->excl, r = reservation_object_get_fences_rcu(new_abo->tbo.resv, &work->excl,
&work->shared_count, &work->shared_count,
&work->shared); &work->shared);
......
...@@ -173,6 +173,14 @@ static int amdgpufb_create_pinned_object(struct amdgpu_fbdev *rfbdev, ...@@ -173,6 +173,14 @@ static int amdgpufb_create_pinned_object(struct amdgpu_fbdev *rfbdev,
amdgpu_bo_unreserve(abo); amdgpu_bo_unreserve(abo);
goto out_unref; goto out_unref;
} }
ret = amdgpu_ttm_alloc_gart(&abo->tbo);
if (ret) {
amdgpu_bo_unreserve(abo);
dev_err(adev->dev, "%p bind failed\n", abo);
goto out_unref;
}
ret = amdgpu_bo_kmap(abo, NULL); ret = amdgpu_bo_kmap(abo, NULL);
amdgpu_bo_unreserve(abo); amdgpu_bo_unreserve(abo);
if (ret) { if (ret) {
......
...@@ -257,6 +257,13 @@ int amdgpu_bo_create_reserved(struct amdgpu_device *adev, ...@@ -257,6 +257,13 @@ int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
dev_err(adev->dev, "(%d) kernel bo pin failed\n", r); dev_err(adev->dev, "(%d) kernel bo pin failed\n", r);
goto error_unreserve; goto error_unreserve;
} }
r = amdgpu_ttm_alloc_gart(&(*bo_ptr)->tbo);
if (r) {
dev_err(adev->dev, "%p bind failed\n", *bo_ptr);
goto error_unpin;
}
if (gpu_addr) if (gpu_addr)
*gpu_addr = amdgpu_bo_gpu_offset(*bo_ptr); *gpu_addr = amdgpu_bo_gpu_offset(*bo_ptr);
...@@ -270,6 +277,8 @@ int amdgpu_bo_create_reserved(struct amdgpu_device *adev, ...@@ -270,6 +277,8 @@ int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
return 0; return 0;
error_unpin:
amdgpu_bo_unpin(*bo_ptr);
error_unreserve: error_unreserve:
amdgpu_bo_unreserve(*bo_ptr); amdgpu_bo_unreserve(*bo_ptr);
...@@ -903,12 +912,6 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, ...@@ -903,12 +912,6 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
goto error; goto error;
} }
r = amdgpu_ttm_alloc_gart(&bo->tbo);
if (unlikely(r)) {
dev_err(adev->dev, "%p bind failed\n", bo);
goto error;
}
bo->pin_count = 1; bo->pin_count = 1;
domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type); domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
......
...@@ -103,6 +103,11 @@ static void amdgpu_do_test_moves(struct amdgpu_device *adev) ...@@ -103,6 +103,11 @@ static void amdgpu_do_test_moves(struct amdgpu_device *adev)
DRM_ERROR("Failed to pin GTT object %d\n", i); DRM_ERROR("Failed to pin GTT object %d\n", i);
goto out_lclean_unres; goto out_lclean_unres;
} }
r = amdgpu_ttm_alloc_gart(&gtt_obj[i]->tbo);
if (r) {
DRM_ERROR("%p bind failed\n", gtt_obj[i]);
goto out_lclean_unpin;
}
gart_addr = amdgpu_bo_gpu_offset(gtt_obj[i]); gart_addr = amdgpu_bo_gpu_offset(gtt_obj[i]);
r = amdgpu_bo_kmap(gtt_obj[i], &gtt_map); r = amdgpu_bo_kmap(gtt_obj[i], &gtt_map);
......
...@@ -3095,13 +3095,22 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane, ...@@ -3095,13 +3095,22 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane,
domain = AMDGPU_GEM_DOMAIN_VRAM; domain = AMDGPU_GEM_DOMAIN_VRAM;
r = amdgpu_bo_pin(rbo, domain); r = amdgpu_bo_pin(rbo, domain);
amdgpu_bo_unreserve(rbo);
if (unlikely(r != 0)) { if (unlikely(r != 0)) {
if (r != -ERESTARTSYS) if (r != -ERESTARTSYS)
DRM_ERROR("Failed to pin framebuffer with error %d\n", r); DRM_ERROR("Failed to pin framebuffer with error %d\n", r);
amdgpu_bo_unreserve(rbo);
return r;
}
r = amdgpu_ttm_alloc_gart(&rbo->tbo);
if (unlikely(r != 0)) {
amdgpu_bo_unpin(rbo);
amdgpu_bo_unreserve(rbo);
DRM_ERROR("%p bind failed\n", rbo);
return r; return r;
} }
amdgpu_bo_unreserve(rbo);
afb->address = amdgpu_bo_gpu_offset(rbo); afb->address = amdgpu_bo_gpu_offset(rbo);
amdgpu_bo_ref(rbo); amdgpu_bo_ref(rbo);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment