diff options
author | Christian König <christian.koenig@amd.com> | 2016-02-15 10:59:57 -0500 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2016-02-16 17:46:24 -0500 |
commit | 418aa0c296ddb5df90c4e94f995cfd3f3c9e96dc (patch) | |
tree | ad4be1eb7a8537b33c479418f6f749f7f827f1d2 | |
parent | 7ea235653328644b5ba8707e65484446a118e193 (diff) |
drm/amdgpu: cleanup gem init/finit
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>
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu.h | 9 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 31 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 23 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 4 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 6 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 6 |
8 files changed, 23 insertions, 58 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 4be61f0ed19d..f5bac97a438b 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h | |||
@@ -607,13 +607,7 @@ struct amdgpu_sa_bo { | |||
607 | /* | 607 | /* |
608 | * GEM objects. | 608 | * GEM objects. |
609 | */ | 609 | */ |
610 | struct amdgpu_gem { | 610 | void amdgpu_gem_force_release(struct amdgpu_device *adev); |
611 | struct mutex mutex; | ||
612 | struct list_head objects; | ||
613 | }; | ||
614 | |||
615 | int amdgpu_gem_init(struct amdgpu_device *adev); | ||
616 | void amdgpu_gem_fini(struct amdgpu_device *adev); | ||
617 | int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, | 611 | int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, |
618 | int alignment, u32 initial_domain, | 612 | int alignment, u32 initial_domain, |
619 | u64 flags, bool kernel, | 613 | u64 flags, bool kernel, |
@@ -2012,7 +2006,6 @@ struct amdgpu_device { | |||
2012 | 2006 | ||
2013 | /* memory management */ | 2007 | /* memory management */ |
2014 | struct amdgpu_mman mman; | 2008 | struct amdgpu_mman mman; |
2015 | struct amdgpu_gem gem; | ||
2016 | struct amdgpu_vram_scratch vram_scratch; | 2009 | struct amdgpu_vram_scratch vram_scratch; |
2017 | struct amdgpu_wb wb; | 2010 | struct amdgpu_wb wb; |
2018 | atomic64_t vram_usage; | 2011 | atomic64_t vram_usage; |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index 93cd1a46ccc4..db20d2783def 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | |||
@@ -1426,7 +1426,6 @@ int amdgpu_device_init(struct amdgpu_device *adev, | |||
1426 | * can recall function without having locking issues */ | 1426 | * can recall function without having locking issues */ |
1427 | mutex_init(&adev->vm_manager.lock); | 1427 | mutex_init(&adev->vm_manager.lock); |
1428 | atomic_set(&adev->irq.ih.lock, 0); | 1428 | atomic_set(&adev->irq.ih.lock, 0); |
1429 | mutex_init(&adev->gem.mutex); | ||
1430 | mutex_init(&adev->pm.mutex); | 1429 | mutex_init(&adev->pm.mutex); |
1431 | mutex_init(&adev->gfx.gpu_clock_mutex); | 1430 | mutex_init(&adev->gfx.gpu_clock_mutex); |
1432 | mutex_init(&adev->srbm_mutex); | 1431 | mutex_init(&adev->srbm_mutex); |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index 0a80febbc1b2..2e26a517f2d6 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | |||
@@ -84,22 +84,31 @@ retry: | |||
84 | } | 84 | } |
85 | *obj = &robj->gem_base; | 85 | *obj = &robj->gem_base; |
86 | 86 | ||
87 | mutex_lock(&adev->gem.mutex); | ||
88 | list_add_tail(&robj->list, &adev->gem.objects); | ||
89 | mutex_unlock(&adev->gem.mutex); | ||
90 | |||
91 | return 0; | 87 | return 0; |
92 | } | 88 | } |
93 | 89 | ||
94 | int amdgpu_gem_init(struct amdgpu_device *adev) | 90 | void amdgpu_gem_force_release(struct amdgpu_device *adev) |
95 | { | 91 | { |
96 | INIT_LIST_HEAD(&adev->gem.objects); | 92 | struct drm_device *ddev = adev->ddev; |
97 | return 0; | 93 | struct drm_file *file; |
98 | } | ||
99 | 94 | ||
100 | void amdgpu_gem_fini(struct amdgpu_device *adev) | 95 | mutex_lock(&ddev->struct_mutex); |
101 | { | 96 | |
102 | amdgpu_bo_force_delete(adev); | 97 | list_for_each_entry(file, &ddev->filelist, lhead) { |
98 | struct drm_gem_object *gobj; | ||
99 | int handle; | ||
100 | |||
101 | WARN_ONCE(1, "Still active user space clients!\n"); | ||
102 | spin_lock(&file->table_lock); | ||
103 | idr_for_each_entry(&file->object_idr, gobj, handle) { | ||
104 | WARN_ONCE(1, "And also active allocations!\n"); | ||
105 | drm_gem_object_unreference(gobj); | ||
106 | } | ||
107 | idr_destroy(&file->object_idr); | ||
108 | spin_unlock(&file->table_lock); | ||
109 | } | ||
110 | |||
111 | mutex_unlock(&ddev->struct_mutex); | ||
103 | } | 112 | } |
104 | 113 | ||
105 | /* | 114 | /* |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index b74084ce734f..9a025a77958d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | |||
@@ -97,9 +97,6 @@ static void amdgpu_ttm_bo_destroy(struct ttm_buffer_object *tbo) | |||
97 | 97 | ||
98 | amdgpu_update_memory_usage(bo->adev, &bo->tbo.mem, NULL); | 98 | amdgpu_update_memory_usage(bo->adev, &bo->tbo.mem, NULL); |
99 | 99 | ||
100 | mutex_lock(&bo->adev->gem.mutex); | ||
101 | list_del_init(&bo->list); | ||
102 | mutex_unlock(&bo->adev->gem.mutex); | ||
103 | drm_gem_object_release(&bo->gem_base); | 100 | drm_gem_object_release(&bo->gem_base); |
104 | amdgpu_bo_unref(&bo->parent); | 101 | amdgpu_bo_unref(&bo->parent); |
105 | kfree(bo->metadata); | 102 | kfree(bo->metadata); |
@@ -473,26 +470,6 @@ int amdgpu_bo_evict_vram(struct amdgpu_device *adev) | |||
473 | return ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_VRAM); | 470 | return ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_VRAM); |
474 | } | 471 | } |
475 | 472 | ||
476 | void amdgpu_bo_force_delete(struct amdgpu_device *adev) | ||
477 | { | ||
478 | struct amdgpu_bo *bo, *n; | ||
479 | |||
480 | if (list_empty(&adev->gem.objects)) { | ||
481 | return; | ||
482 | } | ||
483 | dev_err(adev->dev, "Userspace still has active objects !\n"); | ||
484 | list_for_each_entry_safe(bo, n, &adev->gem.objects, list) { | ||
485 | dev_err(adev->dev, "%p %p %lu %lu force free\n", | ||
486 | &bo->gem_base, bo, (unsigned long)bo->gem_base.size, | ||
487 | *((unsigned long *)&bo->gem_base.refcount)); | ||
488 | mutex_lock(&bo->adev->gem.mutex); | ||
489 | list_del_init(&bo->list); | ||
490 | mutex_unlock(&bo->adev->gem.mutex); | ||
491 | /* this should unref the ttm bo */ | ||
492 | drm_gem_object_unreference_unlocked(&bo->gem_base); | ||
493 | } | ||
494 | } | ||
495 | |||
496 | int amdgpu_bo_init(struct amdgpu_device *adev) | 473 | int amdgpu_bo_init(struct amdgpu_device *adev) |
497 | { | 474 | { |
498 | /* Add an MTRR for the VRAM */ | 475 | /* Add an MTRR for the VRAM */ |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h index 5107fb291bdb..acc08018c6cc 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | |||
@@ -149,7 +149,6 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, | |||
149 | u64 *gpu_addr); | 149 | u64 *gpu_addr); |
150 | int amdgpu_bo_unpin(struct amdgpu_bo *bo); | 150 | int amdgpu_bo_unpin(struct amdgpu_bo *bo); |
151 | int amdgpu_bo_evict_vram(struct amdgpu_device *adev); | 151 | int amdgpu_bo_evict_vram(struct amdgpu_device *adev); |
152 | void amdgpu_bo_force_delete(struct amdgpu_device *adev); | ||
153 | int amdgpu_bo_init(struct amdgpu_device *adev); | 152 | int amdgpu_bo_init(struct amdgpu_device *adev); |
154 | void amdgpu_bo_fini(struct amdgpu_device *adev); | 153 | void amdgpu_bo_fini(struct amdgpu_device *adev); |
155 | int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo, | 154 | int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo, |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c index a0bdb0e45c0f..be6388f73ba2 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | |||
@@ -73,10 +73,6 @@ struct drm_gem_object *amdgpu_gem_prime_import_sg_table(struct drm_device *dev, | |||
73 | if (ret) | 73 | if (ret) |
74 | return ERR_PTR(ret); | 74 | return ERR_PTR(ret); |
75 | 75 | ||
76 | mutex_lock(&adev->gem.mutex); | ||
77 | list_add_tail(&bo->list, &adev->gem.objects); | ||
78 | mutex_unlock(&adev->gem.mutex); | ||
79 | |||
80 | return &bo->gem_base; | 76 | return &bo->gem_base; |
81 | } | 77 | } |
82 | 78 | ||
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c index cceffe2288d0..68ee66b38e5c 100644 --- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | |||
@@ -927,10 +927,6 @@ static int gmc_v7_0_sw_init(void *handle) | |||
927 | int dma_bits; | 927 | int dma_bits; |
928 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; | 928 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
929 | 929 | ||
930 | r = amdgpu_gem_init(adev); | ||
931 | if (r) | ||
932 | return r; | ||
933 | |||
934 | r = amdgpu_irq_add_id(adev, 146, &adev->mc.vm_fault); | 930 | r = amdgpu_irq_add_id(adev, 146, &adev->mc.vm_fault); |
935 | if (r) | 931 | if (r) |
936 | return r; | 932 | return r; |
@@ -1011,7 +1007,7 @@ static int gmc_v7_0_sw_fini(void *handle) | |||
1011 | adev->vm_manager.enabled = false; | 1007 | adev->vm_manager.enabled = false; |
1012 | } | 1008 | } |
1013 | gmc_v7_0_gart_fini(adev); | 1009 | gmc_v7_0_gart_fini(adev); |
1014 | amdgpu_gem_fini(adev); | 1010 | amdgpu_gem_force_release(adev); |
1015 | amdgpu_bo_fini(adev); | 1011 | amdgpu_bo_fini(adev); |
1016 | 1012 | ||
1017 | return 0; | 1013 | return 0; |
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c index ca0a0c666b71..757803ae7c4a 100644 --- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | |||
@@ -887,10 +887,6 @@ static int gmc_v8_0_sw_init(void *handle) | |||
887 | int dma_bits; | 887 | int dma_bits; |
888 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; | 888 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
889 | 889 | ||
890 | r = amdgpu_gem_init(adev); | ||
891 | if (r) | ||
892 | return r; | ||
893 | |||
894 | r = amdgpu_irq_add_id(adev, 146, &adev->mc.vm_fault); | 890 | r = amdgpu_irq_add_id(adev, 146, &adev->mc.vm_fault); |
895 | if (r) | 891 | if (r) |
896 | return r; | 892 | return r; |
@@ -971,7 +967,7 @@ static int gmc_v8_0_sw_fini(void *handle) | |||
971 | adev->vm_manager.enabled = false; | 967 | adev->vm_manager.enabled = false; |
972 | } | 968 | } |
973 | gmc_v8_0_gart_fini(adev); | 969 | gmc_v8_0_gart_fini(adev); |
974 | amdgpu_gem_fini(adev); | 970 | amdgpu_gem_force_release(adev); |
975 | amdgpu_bo_fini(adev); | 971 | amdgpu_bo_fini(adev); |
976 | 972 | ||
977 | return 0; | 973 | return 0; |