]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
drm/amdgpu: unify BO evicting method in amdgpu_ttm
[mirror_ubuntu-jammy-kernel.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_ttm.c
index 94126dc3968882fc4bda5d1a045db6f6655c2b5b..51c76d6322c94e89760fba60c626e4e84e15a1b1 100644 (file)
@@ -1892,7 +1892,7 @@ int amdgpu_copy_buffer(struct amdgpu_ring *ring, uint64_t src_offset,
        unsigned i;
        int r;
 
-       if (direct_submit && !ring->sched.ready) {
+       if (!direct_submit && !ring->sched.ready) {
                DRM_ERROR("Trying to move memory with ring turned off.\n");
                return -EINVAL;
        }
@@ -2036,6 +2036,36 @@ error_free:
        return r;
 }
 
+/**
+ * amdgpu_ttm_evict_resources - evict memory buffers
+ * @adev: amdgpu device object
+ * @mem_type: evicted BO's memory type
+ *
+ * Evicts all @mem_type buffers on the lru list of the memory type.
+ *
+ * Returns:
+ * 0 for success or a negative error code on failure.
+ */
+int amdgpu_ttm_evict_resources(struct amdgpu_device *adev, int mem_type)
+{
+       struct ttm_resource_manager *man;
+
+       switch (mem_type) {
+       case TTM_PL_VRAM:
+       case TTM_PL_TT:
+       case AMDGPU_PL_GWS:
+       case AMDGPU_PL_GDS:
+       case AMDGPU_PL_OA:
+               man = ttm_manager_type(&adev->mman.bdev, mem_type);
+               break;
+       default:
+               DRM_ERROR("Trying to evict invalid memory type\n");
+               return -EINVAL;
+       }
+
+       return ttm_resource_manager_evict_all(&adev->mman.bdev, man);
+}
+
 #if defined(CONFIG_DEBUG_FS)
 
 static int amdgpu_mm_vram_table_show(struct seq_file *m, void *unused)