aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
diff options
context:
space:
mode:
authorChristian König <christian.koenig@amd.com>2017-09-12 04:56:17 -0400
committerAlex Deucher <alexander.deucher@amd.com>2017-09-13 12:10:14 -0400
commitc09312a6532a9a976ec4e72eb3b7fa10e87a8b07 (patch)
tree76ac1c2e7915283c4870e6f9329f1009f2183737 /drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
parent88531913a841a6354adfb40c78c86599639e5f32 (diff)
drm/amdgpu: fix and cleanup amdgpu_bo_create v2
We adjusted the BO flags for USWC handling, but those never took effect because the placement was passed in instead of generated inside this function. v2: better commit message Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@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.c83
1 files changed, 23 insertions, 60 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 52d0109c0d9c..726a662f43f4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -64,11 +64,12 @@ bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo)
64 return false; 64 return false;
65} 65}
66 66
67static void amdgpu_ttm_placement_init(struct amdgpu_device *adev, 67void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain)
68 struct ttm_placement *placement,
69 struct ttm_place *places,
70 u32 domain, u64 flags)
71{ 68{
69 struct amdgpu_device *adev = amdgpu_ttm_adev(abo->tbo.bdev);
70 struct ttm_placement *placement = &abo->placement;
71 struct ttm_place *places = abo->placements;
72 u64 flags = abo->flags;
72 u32 c = 0; 73 u32 c = 0;
73 74
74 if (domain & AMDGPU_GEM_DOMAIN_VRAM) { 75 if (domain & AMDGPU_GEM_DOMAIN_VRAM) {
@@ -151,27 +152,6 @@ static void amdgpu_ttm_placement_init(struct amdgpu_device *adev,
151 placement->busy_placement = places; 152 placement->busy_placement = places;
152} 153}
153 154
154void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32 domain)
155{
156 struct amdgpu_device *adev = amdgpu_ttm_adev(abo->tbo.bdev);
157
158 amdgpu_ttm_placement_init(adev, &abo->placement, abo->placements,
159 domain, abo->flags);
160}
161
162static void amdgpu_fill_placement_to_bo(struct amdgpu_bo *bo,
163 struct ttm_placement *placement)
164{
165 BUG_ON(placement->num_placement > (AMDGPU_GEM_DOMAIN_MAX + 1));
166
167 memcpy(bo->placements, placement->placement,
168 placement->num_placement * sizeof(struct ttm_place));
169 bo->placement.num_placement = placement->num_placement;
170 bo->placement.num_busy_placement = placement->num_busy_placement;
171 bo->placement.placement = bo->placements;
172 bo->placement.busy_placement = bo->placements;
173}
174
175/** 155/**
176 * amdgpu_bo_create_reserved - create reserved BO for kernel use 156 * amdgpu_bo_create_reserved - create reserved BO for kernel use
177 * 157 *
@@ -303,14 +283,13 @@ void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
303 *cpu_addr = NULL; 283 *cpu_addr = NULL;
304} 284}
305 285
306int amdgpu_bo_create_restricted(struct amdgpu_device *adev, 286static int amdgpu_bo_do_create(struct amdgpu_device *adev,
307 unsigned long size, int byte_align, 287 unsigned long size, int byte_align,
308 bool kernel, u32 domain, u64 flags, 288 bool kernel, u32 domain, u64 flags,
309 struct sg_table *sg, 289 struct sg_table *sg,
310 struct ttm_placement *placement, 290 struct reservation_object *resv,
311 struct reservation_object *resv, 291 uint64_t init_value,
312 uint64_t init_value, 292 struct amdgpu_bo **bo_ptr)
313 struct amdgpu_bo **bo_ptr)
314{ 293{
315 struct amdgpu_bo *bo; 294 struct amdgpu_bo *bo;
316 enum ttm_bo_type type; 295 enum ttm_bo_type type;
@@ -384,10 +363,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
384 bo->flags &= ~AMDGPU_GEM_CREATE_CPU_GTT_USWC; 363 bo->flags &= ~AMDGPU_GEM_CREATE_CPU_GTT_USWC;
385#endif 364#endif
386 365
387 amdgpu_fill_placement_to_bo(bo, placement); 366 bo->tbo.bdev = &adev->mman.bdev;
388 /* Kernel allocation are uninterruptible */ 367 amdgpu_ttm_placement_from_domain(bo, domain);
389 368
390 initial_bytes_moved = atomic64_read(&adev->num_bytes_moved); 369 initial_bytes_moved = atomic64_read(&adev->num_bytes_moved);
370 /* Kernel allocation are uninterruptible */
391 r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, type, 371 r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, type,
392 &bo->placement, page_align, !kernel, NULL, 372 &bo->placement, page_align, !kernel, NULL,
393 acc_size, sg, resv, &amdgpu_ttm_bo_destroy); 373 acc_size, sg, resv, &amdgpu_ttm_bo_destroy);
@@ -442,27 +422,17 @@ static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
442 unsigned long size, int byte_align, 422 unsigned long size, int byte_align,
443 struct amdgpu_bo *bo) 423 struct amdgpu_bo *bo)
444{ 424{
445 struct ttm_placement placement = {0};
446 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
447 int r; 425 int r;
448 426
449 if (bo->shadow) 427 if (bo->shadow)
450 return 0; 428 return 0;
451 429
452 memset(&placements, 0, sizeof(placements)); 430 r = amdgpu_bo_do_create(adev, size, byte_align, true,
453 amdgpu_ttm_placement_init(adev, &placement, placements, 431 AMDGPU_GEM_DOMAIN_GTT,
454 AMDGPU_GEM_DOMAIN_GTT, 432 AMDGPU_GEM_CREATE_CPU_GTT_USWC |
455 AMDGPU_GEM_CREATE_CPU_GTT_USWC | 433 AMDGPU_GEM_CREATE_SHADOW,
456 AMDGPU_GEM_CREATE_SHADOW); 434 NULL, bo->tbo.resv, 0,
457 435 &bo->shadow);
458 r = amdgpu_bo_create_restricted(adev, size, byte_align, true,
459 AMDGPU_GEM_DOMAIN_GTT,
460 AMDGPU_GEM_CREATE_CPU_GTT_USWC |
461 AMDGPU_GEM_CREATE_SHADOW,
462 NULL, &placement,
463 bo->tbo.resv,
464 0,
465 &bo->shadow);
466 if (!r) { 436 if (!r) {
467 bo->shadow->parent = amdgpu_bo_ref(bo); 437 bo->shadow->parent = amdgpu_bo_ref(bo);
468 mutex_lock(&adev->shadow_list_lock); 438 mutex_lock(&adev->shadow_list_lock);
@@ -484,18 +454,11 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
484 uint64_t init_value, 454 uint64_t init_value,
485 struct amdgpu_bo **bo_ptr) 455 struct amdgpu_bo **bo_ptr)
486{ 456{
487 struct ttm_placement placement = {0};
488 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
489 uint64_t parent_flags = flags & ~AMDGPU_GEM_CREATE_SHADOW; 457 uint64_t parent_flags = flags & ~AMDGPU_GEM_CREATE_SHADOW;
490 int r; 458 int r;
491 459
492 memset(&placements, 0, sizeof(placements)); 460 r = amdgpu_bo_do_create(adev, size, byte_align, kernel, domain,
493 amdgpu_ttm_placement_init(adev, &placement, placements, 461 parent_flags, sg, resv, init_value, bo_ptr);
494 domain, parent_flags);
495
496 r = amdgpu_bo_create_restricted(adev, size, byte_align, kernel, domain,
497 parent_flags, sg, &placement, resv,
498 init_value, bo_ptr);
499 if (r) 462 if (r)
500 return r; 463 return r;
501 464