drm/amdgpu: cleanup gem init/finit
authorChristian König <christian.koenig@amd.com>
Mon, 15 Feb 2016 15:59:57 +0000 (16:59 +0100)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 16 Feb 2016 22:46:24 +0000 (17:46 -0500)
Remove the double housekeeping and use something sane to
forcefuly delete BOs on unload.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu.h
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c

index 4be61f0ed19d14ef10161c854611507188bf4635..f5bac97a438b09123cd1446ce118ed45f979d6ff 100644 (file)
@@ -607,13 +607,7 @@ struct amdgpu_sa_bo {
 /*
  * GEM objects.
  */
-struct amdgpu_gem {
-       struct mutex            mutex;
-       struct list_head        objects;
-};
-
-int amdgpu_gem_init(struct amdgpu_device *adev);
-void amdgpu_gem_fini(struct amdgpu_device *adev);
+void amdgpu_gem_force_release(struct amdgpu_device *adev);
 int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
                                int alignment, u32 initial_domain,
                                u64 flags, bool kernel,
@@ -2012,7 +2006,6 @@ struct amdgpu_device {
 
        /* memory management */
        struct amdgpu_mman              mman;
-       struct amdgpu_gem               gem;
        struct amdgpu_vram_scratch      vram_scratch;
        struct amdgpu_wb                wb;
        atomic64_t                      vram_usage;
index 93cd1a46ccc4e0ab186a83b72380d137d4e23e6f..db20d2783def92f30e811785d6f50d33532e2c37 100644 (file)
@@ -1426,7 +1426,6 @@ int amdgpu_device_init(struct amdgpu_device *adev,
         * can recall function without having locking issues */
        mutex_init(&adev->vm_manager.lock);
        atomic_set(&adev->irq.ih.lock, 0);
-       mutex_init(&adev->gem.mutex);
        mutex_init(&adev->pm.mutex);
        mutex_init(&adev->gfx.gpu_clock_mutex);
        mutex_init(&adev->srbm_mutex);
index 0a80febbc1b2d2618e17293b458005dd983c47f8..2e26a517f2d6301e295f1a8f736f25072011b8c2 100644 (file)
@@ -84,22 +84,31 @@ retry:
        }
        *obj = &robj->gem_base;
 
-       mutex_lock(&adev->gem.mutex);
-       list_add_tail(&robj->list, &adev->gem.objects);
-       mutex_unlock(&adev->gem.mutex);
-
        return 0;
 }
 
-int amdgpu_gem_init(struct amdgpu_device *adev)
+void amdgpu_gem_force_release(struct amdgpu_device *adev)
 {
-       INIT_LIST_HEAD(&adev->gem.objects);
-       return 0;
-}
+       struct drm_device *ddev = adev->ddev;
+       struct drm_file *file;
 
-void amdgpu_gem_fini(struct amdgpu_device *adev)
-{
-       amdgpu_bo_force_delete(adev);
+       mutex_lock(&ddev->struct_mutex);
+
+       list_for_each_entry(file, &ddev->filelist, lhead) {
+               struct drm_gem_object *gobj;
+               int handle;
+
+               WARN_ONCE(1, "Still active user space clients!\n");
+               spin_lock(&file->table_lock);
+               idr_for_each_entry(&file->object_idr, gobj, handle) {
+                       WARN_ONCE(1, "And also active allocations!\n");
+                       drm_gem_object_unreference(gobj);
+               }
+               idr_destroy(&file->object_idr);
+               spin_unlock(&file->table_lock);
+       }
+
+       mutex_unlock(&ddev->struct_mutex);
 }
 
 /*
index b74084ce734f980ac8de88a0a09b3397702ce4e1..9a025a77958d0579ce25dce653af067838b29ac6 100644 (file)
@@ -97,9 +97,6 @@ static void amdgpu_ttm_bo_destroy(struct ttm_buffer_object *tbo)
 
        amdgpu_update_memory_usage(bo->adev, &bo->tbo.mem, NULL);
 
-       mutex_lock(&bo->adev->gem.mutex);
-       list_del_init(&bo->list);
-       mutex_unlock(&bo->adev->gem.mutex);
        drm_gem_object_release(&bo->gem_base);
        amdgpu_bo_unref(&bo->parent);
        kfree(bo->metadata);
@@ -473,26 +470,6 @@ int amdgpu_bo_evict_vram(struct amdgpu_device *adev)
        return ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_VRAM);
 }
 
-void amdgpu_bo_force_delete(struct amdgpu_device *adev)
-{
-       struct amdgpu_bo *bo, *n;
-
-       if (list_empty(&adev->gem.objects)) {
-               return;
-       }
-       dev_err(adev->dev, "Userspace still has active objects !\n");
-       list_for_each_entry_safe(bo, n, &adev->gem.objects, list) {
-               dev_err(adev->dev, "%p %p %lu %lu force free\n",
-                       &bo->gem_base, bo, (unsigned long)bo->gem_base.size,
-                       *((unsigned long *)&bo->gem_base.refcount));
-               mutex_lock(&bo->adev->gem.mutex);
-               list_del_init(&bo->list);
-               mutex_unlock(&bo->adev->gem.mutex);
-               /* this should unref the ttm bo */
-               drm_gem_object_unreference_unlocked(&bo->gem_base);
-       }
-}
-
 int amdgpu_bo_init(struct amdgpu_device *adev)
 {
        /* Add an MTRR for the VRAM */
index 5107fb291bdbe9980a64e025bf1d88da4f1f046c..acc08018c6cc1ebfb50493b4e6a6080ab04de49a 100644 (file)
@@ -149,7 +149,6 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
                             u64 *gpu_addr);
 int amdgpu_bo_unpin(struct amdgpu_bo *bo);
 int amdgpu_bo_evict_vram(struct amdgpu_device *adev);
-void amdgpu_bo_force_delete(struct amdgpu_device *adev);
 int amdgpu_bo_init(struct amdgpu_device *adev);
 void amdgpu_bo_fini(struct amdgpu_device *adev);
 int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo,
index a0bdb0e45c0f8ea181fc87bcdbf5efd5f1efcad9..be6388f73ba27a4caa0097954d245a38a4a73527 100644 (file)
@@ -73,10 +73,6 @@ struct drm_gem_object *amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
        if (ret)
                return ERR_PTR(ret);
 
-       mutex_lock(&adev->gem.mutex);
-       list_add_tail(&bo->list, &adev->gem.objects);
-       mutex_unlock(&adev->gem.mutex);
-
        return &bo->gem_base;
 }
 
index cceffe2288d0a70884b52746d4aac621285ac3cb..68ee66b38e5c6cfb1ea70d1bc217973421cee749 100644 (file)
@@ -927,10 +927,6 @@ static int gmc_v7_0_sw_init(void *handle)
        int dma_bits;
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-       r = amdgpu_gem_init(adev);
-       if (r)
-               return r;
-
        r = amdgpu_irq_add_id(adev, 146, &adev->mc.vm_fault);
        if (r)
                return r;
@@ -1011,7 +1007,7 @@ static int gmc_v7_0_sw_fini(void *handle)
                adev->vm_manager.enabled = false;
        }
        gmc_v7_0_gart_fini(adev);
-       amdgpu_gem_fini(adev);
+       amdgpu_gem_force_release(adev);
        amdgpu_bo_fini(adev);
 
        return 0;
index ca0a0c666b71840554f64f0bb4397c175eba13b3..757803ae7c4a290f28815840d2dc31101828ef95 100644 (file)
@@ -887,10 +887,6 @@ static int gmc_v8_0_sw_init(void *handle)
        int dma_bits;
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-       r = amdgpu_gem_init(adev);
-       if (r)
-               return r;
-
        r = amdgpu_irq_add_id(adev, 146, &adev->mc.vm_fault);
        if (r)
                return r;
@@ -971,7 +967,7 @@ static int gmc_v8_0_sw_fini(void *handle)
                adev->vm_manager.enabled = false;
        }
        gmc_v8_0_gart_fini(adev);
-       amdgpu_gem_fini(adev);
+       amdgpu_gem_force_release(adev);
        amdgpu_bo_fini(adev);
 
        return 0;