diff options
author | Christian König <christian.koenig@amd.com> | 2018-08-27 16:17:59 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2018-08-27 16:19:12 -0400 |
commit | e21eb2613d071abfaa40e353b106f01f4ce83d77 (patch) | |
tree | 8efdb108239045dc6c83f24fe994046d5394ae0d /drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | |
parent | 248f2b8ef25c9505fc763d42bf5e2c9fcf94fd16 (diff) |
drm/amdgpu: add helper for VM PD/PT allocation parameters v3
Add a helper function to figure them out only once.
v2: fix typo with memset
v3: rebase on kfd changes (Alex)
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Junwei Zhang <Jerry.Zhang@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 63 |
1 files changed, 29 insertions, 34 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index 5ef755458d3e..f78be285d296 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | |||
@@ -468,6 +468,32 @@ error: | |||
468 | } | 468 | } |
469 | 469 | ||
470 | /** | 470 | /** |
471 | * amdgpu_vm_bo_param - fill in parameters for PD/PT allocation | ||
472 | * | ||
473 | * @adev: amdgpu_device pointer | ||
474 | * @vm: requesting vm | ||
475 | * @bp: resulting BO allocation parameters | ||
476 | */ | ||
477 | static void amdgpu_vm_bo_param(struct amdgpu_device *adev, struct amdgpu_vm *vm, | ||
478 | int level, struct amdgpu_bo_param *bp) | ||
479 | { | ||
480 | memset(bp, 0, sizeof(*bp)); | ||
481 | |||
482 | bp->size = amdgpu_vm_bo_size(adev, level); | ||
483 | bp->byte_align = AMDGPU_GPU_PAGE_SIZE; | ||
484 | bp->domain = AMDGPU_GEM_DOMAIN_VRAM; | ||
485 | bp->flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS; | ||
486 | if (vm->use_cpu_for_update) | ||
487 | bp->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; | ||
488 | else | ||
489 | bp->flags |= AMDGPU_GEM_CREATE_SHADOW | | ||
490 | AMDGPU_GEM_CREATE_NO_CPU_ACCESS; | ||
491 | bp->type = ttm_bo_type_kernel; | ||
492 | if (vm->root.base.bo) | ||
493 | bp->resv = vm->root.base.bo->tbo.resv; | ||
494 | } | ||
495 | |||
496 | /** | ||
471 | * amdgpu_vm_alloc_levels - allocate the PD/PT levels | 497 | * amdgpu_vm_alloc_levels - allocate the PD/PT levels |
472 | * | 498 | * |
473 | * @adev: amdgpu_device pointer | 499 | * @adev: amdgpu_device pointer |
@@ -490,8 +516,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, | |||
490 | unsigned level, bool ats) | 516 | unsigned level, bool ats) |
491 | { | 517 | { |
492 | unsigned shift = amdgpu_vm_level_shift(adev, level); | 518 | unsigned shift = amdgpu_vm_level_shift(adev, level); |
519 | struct amdgpu_bo_param bp; | ||
493 | unsigned pt_idx, from, to; | 520 | unsigned pt_idx, from, to; |
494 | u64 flags; | ||
495 | int r; | 521 | int r; |
496 | 522 | ||
497 | if (!parent->entries) { | 523 | if (!parent->entries) { |
@@ -515,30 +541,14 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, | |||
515 | saddr = saddr & ((1 << shift) - 1); | 541 | saddr = saddr & ((1 << shift) - 1); |
516 | eaddr = eaddr & ((1 << shift) - 1); | 542 | eaddr = eaddr & ((1 << shift) - 1); |
517 | 543 | ||
518 | flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS; | 544 | amdgpu_vm_bo_param(adev, vm, level, &bp); |
519 | if (vm->root.base.bo->shadow) | ||
520 | flags |= AMDGPU_GEM_CREATE_SHADOW; | ||
521 | if (vm->use_cpu_for_update) | ||
522 | flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; | ||
523 | else | ||
524 | flags |= AMDGPU_GEM_CREATE_NO_CPU_ACCESS; | ||
525 | 545 | ||
526 | /* walk over the address space and allocate the page tables */ | 546 | /* walk over the address space and allocate the page tables */ |
527 | for (pt_idx = from; pt_idx <= to; ++pt_idx) { | 547 | for (pt_idx = from; pt_idx <= to; ++pt_idx) { |
528 | struct reservation_object *resv = vm->root.base.bo->tbo.resv; | ||
529 | struct amdgpu_vm_pt *entry = &parent->entries[pt_idx]; | 548 | struct amdgpu_vm_pt *entry = &parent->entries[pt_idx]; |
530 | struct amdgpu_bo *pt; | 549 | struct amdgpu_bo *pt; |
531 | 550 | ||
532 | if (!entry->base.bo) { | 551 | if (!entry->base.bo) { |
533 | struct amdgpu_bo_param bp; | ||
534 | |||
535 | memset(&bp, 0, sizeof(bp)); | ||
536 | bp.size = amdgpu_vm_bo_size(adev, level); | ||
537 | bp.byte_align = AMDGPU_GPU_PAGE_SIZE; | ||
538 | bp.domain = AMDGPU_GEM_DOMAIN_VRAM; | ||
539 | bp.flags = flags; | ||
540 | bp.type = ttm_bo_type_kernel; | ||
541 | bp.resv = resv; | ||
542 | r = amdgpu_bo_create(adev, &bp, &pt); | 552 | r = amdgpu_bo_create(adev, &bp, &pt); |
543 | if (r) | 553 | if (r) |
544 | return r; | 554 | return r; |
@@ -2612,8 +2622,6 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, | |||
2612 | { | 2622 | { |
2613 | struct amdgpu_bo_param bp; | 2623 | struct amdgpu_bo_param bp; |
2614 | struct amdgpu_bo *root; | 2624 | struct amdgpu_bo *root; |
2615 | unsigned long size; | ||
2616 | uint64_t flags; | ||
2617 | int r, i; | 2625 | int r, i; |
2618 | 2626 | ||
2619 | vm->va = RB_ROOT_CACHED; | 2627 | vm->va = RB_ROOT_CACHED; |
@@ -2651,20 +2659,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, | |||
2651 | "CPU update of VM recommended only for large BAR system\n"); | 2659 | "CPU update of VM recommended only for large BAR system\n"); |
2652 | vm->last_update = NULL; | 2660 | vm->last_update = NULL; |
2653 | 2661 | ||
2654 | flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS; | 2662 | amdgpu_vm_bo_param(adev, vm, adev->vm_manager.root_level, &bp); |
2655 | if (vm->use_cpu_for_update) | ||
2656 | flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; | ||
2657 | else if (vm_context != AMDGPU_VM_CONTEXT_COMPUTE) | ||
2658 | flags |= AMDGPU_GEM_CREATE_SHADOW; | ||
2659 | |||
2660 | size = amdgpu_vm_bo_size(adev, adev->vm_manager.root_level); | ||
2661 | memset(&bp, 0, sizeof(bp)); | ||
2662 | bp.size = size; | ||
2663 | bp.byte_align = AMDGPU_GPU_PAGE_SIZE; | ||
2664 | bp.domain = AMDGPU_GEM_DOMAIN_VRAM; | ||
2665 | bp.flags = flags; | ||
2666 | bp.type = ttm_bo_type_kernel; | ||
2667 | bp.resv = NULL; | ||
2668 | r = amdgpu_bo_create(adev, &bp, &root); | 2663 | r = amdgpu_bo_create(adev, &bp, &root); |
2669 | if (r) | 2664 | if (r) |
2670 | goto error_free_sched_entity; | 2665 | goto error_free_sched_entity; |