drm/amdgpu/ttm: use new takedown path
authorDave Airlie <airlied@redhat.com>
Tue, 4 Aug 2020 02:56:00 +0000 (12:56 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 6 Aug 2020 02:32:03 +0000 (12:32 +1000)
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200804025632.3868079-28-airlied@gmail.com
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c

index f94c6a3..699cb0d 100644 (file)
@@ -133,10 +133,18 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
  * Destroy and free the GTT manager, returns -EBUSY if ranges are still
  * allocated inside it.
  */
-static int amdgpu_gtt_mgr_fini(struct ttm_mem_type_manager *man)
+void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
 {
-       struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
+       struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_TT];
        struct amdgpu_gtt_mgr *mgr = man->priv;
+       int ret;
+
+       ttm_mem_type_manager_disable(man);
+
+       ret = ttm_mem_type_manager_force_list_clean(&adev->mman.bdev, man);
+       if (ret)
+               return;
+
        spin_lock(&mgr->lock);
        drm_mm_takedown(&mgr->mm);
        spin_unlock(&mgr->lock);
@@ -146,7 +154,7 @@ static int amdgpu_gtt_mgr_fini(struct ttm_mem_type_manager *man)
        device_remove_file(adev->dev, &dev_attr_mem_info_gtt_total);
        device_remove_file(adev->dev, &dev_attr_mem_info_gtt_used);
 
-       return 0;
+       ttm_mem_type_manager_cleanup(man);
 }
 
 /**
@@ -309,7 +317,6 @@ static void amdgpu_gtt_mgr_debug(struct ttm_mem_type_manager *man,
 }
 
 static const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func = {
-       .takedown = amdgpu_gtt_mgr_fini,
        .get_node = amdgpu_gtt_mgr_new,
        .put_node = amdgpu_gtt_mgr_del,
        .debug = amdgpu_gtt_mgr_debug
index 4058354..95aedfc 100644 (file)
@@ -1994,11 +1994,11 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
                iounmap(adev->mman.aper_base_kaddr);
        adev->mman.aper_base_kaddr = NULL;
 
-       ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_VRAM);
-       ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_TT);
-       ttm_bo_clean_mm(&adev->mman.bdev, AMDGPU_PL_GDS);
-       ttm_bo_clean_mm(&adev->mman.bdev, AMDGPU_PL_GWS);
-       ttm_bo_clean_mm(&adev->mman.bdev, AMDGPU_PL_OA);
+       amdgpu_vram_mgr_fini(adev);
+       amdgpu_gtt_mgr_fini(adev);
+       ttm_range_man_fini(&adev->mman.bdev, &adev->mman.bdev.man[AMDGPU_PL_GDS]);
+       ttm_range_man_fini(&adev->mman.bdev, &adev->mman.bdev.man[AMDGPU_PL_GWS]);
+       ttm_range_man_fini(&adev->mman.bdev, &adev->mman.bdev.man[AMDGPU_PL_OA]);
        ttm_bo_device_release(&adev->mman.bdev);
        adev->mman.initialized = false;
        DRM_INFO("amdgpu: ttm finalized\n");
index fb45c0a..c01fdb3 100644 (file)
@@ -68,7 +68,9 @@ struct amdgpu_copy_mem {
 };
 
 int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size);
+void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev);
 int amdgpu_vram_mgr_init(struct amdgpu_device *adev);
+void amdgpu_vram_mgr_fini(struct amdgpu_device *adev);
 
 bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_mem_reg *mem);
 uint64_t amdgpu_gtt_mgr_usage(struct ttm_mem_type_manager *man);
index 6fcbeb0..b33c516 100644 (file)
@@ -205,10 +205,17 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
  * Destroy and free the VRAM manager, returns -EBUSY if ranges are still
  * allocated inside it.
  */
-static int amdgpu_vram_mgr_fini(struct ttm_mem_type_manager *man)
+void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
 {
-       struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
+       struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_VRAM];
        struct amdgpu_vram_mgr *mgr = man->priv;
+       int ret;
+
+       ttm_mem_type_manager_disable(man);
+
+       ret = ttm_mem_type_manager_force_list_clean(&adev->mman.bdev, man);
+       if (ret)
+               return;
 
        spin_lock(&mgr->lock);
        drm_mm_takedown(&mgr->mm);
@@ -216,7 +223,8 @@ static int amdgpu_vram_mgr_fini(struct ttm_mem_type_manager *man)
        kfree(mgr);
        man->priv = NULL;
        sysfs_remove_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
-       return 0;
+
+       ttm_mem_type_manager_cleanup(man);
 }
 
 /**
@@ -598,7 +606,6 @@ static void amdgpu_vram_mgr_debug(struct ttm_mem_type_manager *man,
 }
 
 static const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func = {
-       .takedown       = amdgpu_vram_mgr_fini,
        .get_node       = amdgpu_vram_mgr_new,
        .put_node       = amdgpu_vram_mgr_del,
        .debug          = amdgpu_vram_mgr_debug