drm/amdgpu: add optional fence out-parameter to amdgpu_vm_clear_freed
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Thu, 23 Mar 2017 18:36:31 +0000 (19:36 +0100)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 30 Mar 2017 03:54:15 +0000 (23:54 -0400)
We will add the fence to freed buffer objects in a later commit, to ensure
that the underlying memory can only be re-used after all references in
page tables have been cleared.

Signed-off-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Reviewed-by: Chunming Zhou <david1.zhou@amd.com>
Reviewed-by: Junwei Zhang <Jerry.Zhang@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

index 419fab50dc548f24ac5ddc603a3fb0bc1b286b44..e83a6dcf2f687192ce709244623c4f804cfa87c5 100644 (file)
@@ -785,7 +785,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p)
        if (r)
                return r;
 
-       r = amdgpu_vm_clear_freed(adev, vm);
+       r = amdgpu_vm_clear_freed(adev, vm, NULL);
        if (r)
                return r;
 
index c71c087727b89b99023b35ffebadda3d75044ced..5e068eefcaecc5d0834a748a03ddf66354b18957 100644 (file)
@@ -540,7 +540,7 @@ static void amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
        if (r)
                goto error;
 
-       r = amdgpu_vm_clear_freed(adev, vm);
+       r = amdgpu_vm_clear_freed(adev, vm, NULL);
        if (r)
                goto error;
 
index 4fe892e3600d66f1c6c3d1e52ca701c73426f956..696860132f043f602ac96f2e49a03b596a047620 100644 (file)
@@ -1382,6 +1382,8 @@ static void amdgpu_vm_prt_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
  *
  * @adev: amdgpu_device pointer
  * @vm: requested vm
+ * @fence: optional resulting fence (unchanged if no work needed to be done
+ * or if an error occurred)
  *
  * Make sure all freed BOs are cleared in the PT.
  * Returns 0 for success.
@@ -1389,10 +1391,11 @@ static void amdgpu_vm_prt_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
  * PTs have to be reserved and mutex must be locked!
  */
 int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
-                         struct amdgpu_vm *vm)
+                         struct amdgpu_vm *vm,
+                         struct dma_fence **fence)
 {
        struct amdgpu_bo_va_mapping *mapping;
-       struct dma_fence *fence = NULL;
+       struct dma_fence *f = NULL;
        int r;
 
        while (!list_empty(&vm->freed)) {
@@ -1401,15 +1404,21 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
                list_del(&mapping->list);
 
                r = amdgpu_vm_bo_split_mapping(adev, NULL, 0, NULL, vm, mapping,
-                                              0, 0, &fence);
-               amdgpu_vm_free_mapping(adev, vm, mapping, fence);
+                                              0, 0, &f);
+               amdgpu_vm_free_mapping(adev, vm, mapping, f);
                if (r) {
-                       dma_fence_put(fence);
+                       dma_fence_put(f);
                        return r;
                }
+       }
 
+       if (fence && f) {
+               dma_fence_put(*fence);
+               *fence = f;
+       } else {
+               dma_fence_put(f);
        }
-       dma_fence_put(fence);
+
        return 0;
 
 }
index ab0429d12992fc3d549502d3471f958b5bad17ff..cbef85bef29610dc625e6fa9ca08c8efede18661 100644 (file)
@@ -190,7 +190,8 @@ void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
 int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
                                    struct amdgpu_vm *vm);
 int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
-                         struct amdgpu_vm *vm);
+                         struct amdgpu_vm *vm,
+                         struct dma_fence **fence);
 int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
                             struct amdgpu_sync *sync);
 int amdgpu_vm_bo_update(struct amdgpu_device *adev,