diff options
author | Felix Kuehling <Felix.Kuehling@amd.com> | 2018-03-15 17:27:42 -0400 |
---|---|---|
committer | Oded Gabbay <oded.gabbay@gmail.com> | 2018-03-15 17:27:42 -0400 |
commit | b236fa1d339670cc997b68c31be57855bbabc126 (patch) | |
tree | 3754fd1869dc4acdc4645be0d7bf3f93c926dbcb | |
parent | 3486625bbfb629621f8a2402e2b24e7ab0a86ef4 (diff) |
drm/amdgpu: Add helper to turn an existing VM into a compute VM
v2: Removed updating and checking of vm->vm_context
v3: Enable amdgpu_vm_clear_bo in amdgpu_vm_make_compute
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 67 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 1 |
2 files changed, 68 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index 24474294c92a..ea39ccf288ed 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | |||
@@ -2462,6 +2462,73 @@ error_free_sched_entity: | |||
2462 | } | 2462 | } |
2463 | 2463 | ||
2464 | /** | 2464 | /** |
2465 | * amdgpu_vm_make_compute - Turn a GFX VM into a compute VM | ||
2466 | * | ||
2467 | * This only works on GFX VMs that don't have any BOs added and no | ||
2468 | * page tables allocated yet. | ||
2469 | * | ||
2470 | * Changes the following VM parameters: | ||
2471 | * - use_cpu_for_update | ||
2472 | * - pte_supports_ats | ||
2473 | * - pasid (old PASID is released, because compute manages its own PASIDs) | ||
2474 | * | ||
2475 | * Reinitializes the page directory to reflect the changed ATS | ||
2476 | * setting. May leave behind an unused shadow BO for the page | ||
2477 | * directory when switching from SDMA updates to CPU updates. | ||
2478 | * | ||
2479 | * Returns 0 for success, -errno for errors. | ||
2480 | */ | ||
2481 | int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm) | ||
2482 | { | ||
2483 | bool pte_support_ats = (adev->asic_type == CHIP_RAVEN); | ||
2484 | int r; | ||
2485 | |||
2486 | r = amdgpu_bo_reserve(vm->root.base.bo, true); | ||
2487 | if (r) | ||
2488 | return r; | ||
2489 | |||
2490 | /* Sanity checks */ | ||
2491 | if (!RB_EMPTY_ROOT(&vm->va.rb_root) || vm->root.entries) { | ||
2492 | r = -EINVAL; | ||
2493 | goto error; | ||
2494 | } | ||
2495 | |||
2496 | /* Check if PD needs to be reinitialized and do it before | ||
2497 | * changing any other state, in case it fails. | ||
2498 | */ | ||
2499 | if (pte_support_ats != vm->pte_support_ats) { | ||
2500 | r = amdgpu_vm_clear_bo(adev, vm, vm->root.base.bo, | ||
2501 | adev->vm_manager.root_level, | ||
2502 | pte_support_ats); | ||
2503 | if (r) | ||
2504 | goto error; | ||
2505 | } | ||
2506 | |||
2507 | /* Update VM state */ | ||
2508 | vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode & | ||
2509 | AMDGPU_VM_USE_CPU_FOR_COMPUTE); | ||
2510 | vm->pte_support_ats = pte_support_ats; | ||
2511 | DRM_DEBUG_DRIVER("VM update mode is %s\n", | ||
2512 | vm->use_cpu_for_update ? "CPU" : "SDMA"); | ||
2513 | WARN_ONCE((vm->use_cpu_for_update & !amdgpu_vm_is_large_bar(adev)), | ||
2514 | "CPU update of VM recommended only for large BAR system\n"); | ||
2515 | |||
2516 | if (vm->pasid) { | ||
2517 | unsigned long flags; | ||
2518 | |||
2519 | spin_lock_irqsave(&adev->vm_manager.pasid_lock, flags); | ||
2520 | idr_remove(&adev->vm_manager.pasid_idr, vm->pasid); | ||
2521 | spin_unlock_irqrestore(&adev->vm_manager.pasid_lock, flags); | ||
2522 | |||
2523 | vm->pasid = 0; | ||
2524 | } | ||
2525 | |||
2526 | error: | ||
2527 | amdgpu_bo_unreserve(vm->root.base.bo); | ||
2528 | return r; | ||
2529 | } | ||
2530 | |||
2531 | /** | ||
2465 | * amdgpu_vm_free_levels - free PD/PT levels | 2532 | * amdgpu_vm_free_levels - free PD/PT levels |
2466 | * | 2533 | * |
2467 | * @adev: amdgpu device structure | 2534 | * @adev: amdgpu device structure |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h index 4dfdefb7de1f..30f080364c97 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | |||
@@ -260,6 +260,7 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev); | |||
260 | void amdgpu_vm_manager_fini(struct amdgpu_device *adev); | 260 | void amdgpu_vm_manager_fini(struct amdgpu_device *adev); |
261 | int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, | 261 | int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, |
262 | int vm_context, unsigned int pasid); | 262 | int vm_context, unsigned int pasid); |
263 | int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm); | ||
263 | void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm); | 264 | void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm); |
264 | bool amdgpu_vm_pasid_fault_credit(struct amdgpu_device *adev, | 265 | bool amdgpu_vm_pasid_fault_credit(struct amdgpu_device *adev, |
265 | unsigned int pasid); | 266 | unsigned int pasid); |