diff options
author | Christian König <christian.koenig@amd.com> | 2018-10-19 15:06:06 +0200 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2018-11-05 14:21:20 -0500 |
commit | 62b53b37e4b1500d4eb4624a44ad861cf8d3cd18 (patch) | |
tree | 0193d438cbb744c1c423415145ca8d695cdf34c6 /drivers/gpu | |
parent | 56b3d20413587fab6a790cfc8bc075ca94bc8ed9 (diff) |
drm/ttm: use a static ttm_bo_global instance
As the name says we only need one global instance of ttm_bo_global.
Just use a single exported instance which is save to initialize multiple times.
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Junwei Zhang <Jerry.Zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r-- | drivers/gpu/drm/ttm/ttm_bo.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 4ec368b2555a..d89183f95570 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -49,6 +49,9 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj); * ttm_global_mutex - protecting the global BO state */ DEFINE_MUTEX(ttm_global_mutex); +struct ttm_bo_global ttm_bo_glob = { + .use_count = 0 +}; static struct attribute ttm_bo_count = { .name = "bo_count", @@ -1527,22 +1530,35 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj) kfree(glob); } -void ttm_bo_global_release(struct ttm_bo_global *glob) +void ttm_bo_global_release(void) { + struct ttm_bo_global *glob = &ttm_bo_glob; + + mutex_lock(&ttm_global_mutex); + if (--glob->use_count > 0) + goto out; + kobject_del(&glob->kobj); kobject_put(&glob->kobj); ttm_mem_global_release(&ttm_mem_glob); +out: + mutex_unlock(&ttm_global_mutex); } EXPORT_SYMBOL(ttm_bo_global_release); -int ttm_bo_global_init(struct ttm_bo_global *glob) +int ttm_bo_global_init(void) { - int ret; + struct ttm_bo_global *glob = &ttm_bo_glob; + int ret = 0; unsigned i; + mutex_lock(&ttm_global_mutex); + if (++glob->use_count > 1) + goto out; + ret = ttm_mem_global_init(&ttm_mem_glob); if (ret) - return ret; + goto out; spin_lock_init(&glob->lru_lock); glob->mem_glob = &ttm_mem_glob; @@ -1551,7 +1567,7 @@ int ttm_bo_global_init(struct ttm_bo_global *glob) if (unlikely(glob->dummy_read_page == NULL)) { ret = -ENOMEM; - goto out_no_drp; + goto out; } for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) @@ -1563,9 +1579,8 @@ int ttm_bo_global_init(struct ttm_bo_global *glob) &glob->kobj, &ttm_bo_glob_kobj_type, ttm_get_kobj(), "buffer_objects"); if (unlikely(ret != 0)) kobject_put(&glob->kobj); - return ret; -out_no_drp: - kfree(glob); +out: + mutex_unlock(&ttm_global_mutex); return ret; } EXPORT_SYMBOL(ttm_bo_global_init); |