aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
diff options
context:
space:
mode:
authorAndrey Grodzovsky <andrey.grodzovsky@amd.com>2017-11-10 18:35:56 -0500
committerAlex Deucher <alexander.deucher@amd.com>2017-12-06 12:47:22 -0500
commit79c631239a83aeb3e13216f2eda1741650645d64 (patch)
treed0dd9475405c0e7249e7d975b82757f9dcc6fc90 /drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
parentfdd5faaa08f891153ac4fd8cedace6d95bed0968 (diff)
drm/amdgpu: Implement BO size validation V2
Validates BO size against each requested domain's total memory. v2: Make GTT size check a MUST to allow fall back to GTT. Rmove redundant NULL check. Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_object.c')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_object.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index a937c49590a9..5acf20cfb1d0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -281,6 +281,44 @@ void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
281 *cpu_addr = NULL; 281 *cpu_addr = NULL;
282} 282}
283 283
284/* Validate bo size is bit bigger then the request domain */
285static bool amdgpu_bo_validate_size(struct amdgpu_device *adev,
286 unsigned long size, u32 domain)
287{
288 struct ttm_mem_type_manager *man = NULL;
289
290 /*
291 * If GTT is part of requested domains the check must succeed to
292 * allow fall back to GTT
293 */
294 if (domain & AMDGPU_GEM_DOMAIN_GTT) {
295 man = &adev->mman.bdev.man[TTM_PL_TT];
296
297 if (size < (man->size << PAGE_SHIFT))
298 return true;
299 else
300 goto fail;
301 }
302
303 if (domain & AMDGPU_GEM_DOMAIN_VRAM) {
304 man = &adev->mman.bdev.man[TTM_PL_VRAM];
305
306 if (size < (man->size << PAGE_SHIFT))
307 return true;
308 else
309 goto fail;
310 }
311
312
313 /* TODO add more domains checks, such as AMDGPU_GEM_DOMAIN_CPU */
314 return true;
315
316fail:
317 DRM_ERROR("BO size %lu > total memory in domain: %llu\n", size,
318 man->size << PAGE_SHIFT);
319 return false;
320}
321
284static int amdgpu_bo_do_create(struct amdgpu_device *adev, 322static int amdgpu_bo_do_create(struct amdgpu_device *adev,
285 unsigned long size, int byte_align, 323 unsigned long size, int byte_align,
286 bool kernel, u32 domain, u64 flags, 324 bool kernel, u32 domain, u64 flags,
@@ -299,6 +337,9 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
299 page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT; 337 page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
300 size = ALIGN(size, PAGE_SIZE); 338 size = ALIGN(size, PAGE_SIZE);
301 339
340 if (!amdgpu_bo_validate_size(adev, size, domain))
341 return -ENOMEM;
342
302 if (kernel) { 343 if (kernel) {
303 type = ttm_bo_type_kernel; 344 type = ttm_bo_type_kernel;
304 } else if (sg) { 345 } else if (sg) {