aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
diff options
context:
space:
mode:
authorOak Zeng <Oak.Zeng@amd.com>2018-08-29 13:33:52 -0400
committerAlex Deucher <alexander.deucher@amd.com>2018-08-29 13:34:49 -0400
commit1685b01a858872075bc258a350153de0c7e95404 (patch)
tree18b1596da9dc1a082b7c78f12fdd7dd092bf5c11 /drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
parentbdb1922abd620d24715906bac4d119274d98f4c9 (diff)
drm/amdgpu: Set pasid for compute vm (v2)
To make a amdgpu vm to a compute vm, the old pasid will be freed and replaced with a pasid managed by kfd. Kfd can't reuse original pasid allocated by amdgpu because kfd uses different pasid policy with amdgpu. For example, all graphic devices share one same pasid in a process. v2: rebase (Alex) Signed-off-by: Oak Zeng <Oak.Zeng@amd.com> Reviewed-by: Felix Kuehling <Felix.Kuehling@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.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 60c0609b78a4..272b7902a25c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2740,7 +2740,7 @@ error_free_sched_entity:
2740 * Returns: 2740 * Returns:
2741 * 0 for success, -errno for errors. 2741 * 0 for success, -errno for errors.
2742 */ 2742 */
2743int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm) 2743int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, unsigned int pasid)
2744{ 2744{
2745 bool pte_support_ats = (adev->asic_type == CHIP_RAVEN); 2745 bool pte_support_ats = (adev->asic_type == CHIP_RAVEN);
2746 int r; 2746 int r;
@@ -2752,7 +2752,20 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
2752 /* Sanity checks */ 2752 /* Sanity checks */
2753 if (!RB_EMPTY_ROOT(&vm->va.rb_root) || vm->root.entries) { 2753 if (!RB_EMPTY_ROOT(&vm->va.rb_root) || vm->root.entries) {
2754 r = -EINVAL; 2754 r = -EINVAL;
2755 goto error; 2755 goto unreserve_bo;
2756 }
2757
2758 if (pasid) {
2759 unsigned long flags;
2760
2761 spin_lock_irqsave(&adev->vm_manager.pasid_lock, flags);
2762 r = idr_alloc(&adev->vm_manager.pasid_idr, vm, pasid, pasid + 1,
2763 GFP_ATOMIC);
2764 spin_unlock_irqrestore(&adev->vm_manager.pasid_lock, flags);
2765
2766 if (r == -ENOSPC)
2767 goto unreserve_bo;
2768 r = 0;
2756 } 2769 }
2757 2770
2758 /* Check if PD needs to be reinitialized and do it before 2771 /* Check if PD needs to be reinitialized and do it before
@@ -2763,7 +2776,7 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
2763 adev->vm_manager.root_level, 2776 adev->vm_manager.root_level,
2764 pte_support_ats); 2777 pte_support_ats);
2765 if (r) 2778 if (r)
2766 goto error; 2779 goto free_idr;
2767 } 2780 }
2768 2781
2769 /* Update VM state */ 2782 /* Update VM state */
@@ -2782,13 +2795,30 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
2782 idr_remove(&adev->vm_manager.pasid_idr, vm->pasid); 2795 idr_remove(&adev->vm_manager.pasid_idr, vm->pasid);
2783 spin_unlock_irqrestore(&adev->vm_manager.pasid_lock, flags); 2796 spin_unlock_irqrestore(&adev->vm_manager.pasid_lock, flags);
2784 2797
2798 /* Free the original amdgpu allocated pasid
2799 * Will be replaced with kfd allocated pasid
2800 */
2801 amdgpu_pasid_free(vm->pasid);
2785 vm->pasid = 0; 2802 vm->pasid = 0;
2786 } 2803 }
2787 2804
2788 /* Free the shadow bo for compute VM */ 2805 /* Free the shadow bo for compute VM */
2789 amdgpu_bo_unref(&vm->root.base.bo->shadow); 2806 amdgpu_bo_unref(&vm->root.base.bo->shadow);
2790 2807
2791error: 2808 if (pasid)
2809 vm->pasid = pasid;
2810
2811 goto unreserve_bo;
2812
2813free_idr:
2814 if (pasid) {
2815 unsigned long flags;
2816
2817 spin_lock_irqsave(&adev->vm_manager.pasid_lock, flags);
2818 idr_remove(&adev->vm_manager.pasid_idr, pasid);
2819 spin_unlock_irqrestore(&adev->vm_manager.pasid_lock, flags);
2820 }
2821unreserve_bo:
2792 amdgpu_bo_unreserve(vm->root.base.bo); 2822 amdgpu_bo_unreserve(vm->root.base.bo);
2793 return r; 2823 return r;
2794} 2824}