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>
This commit is contained in:
Christian König
2018-10-19 15:06:06 +02:00
committed by Alex Deucher
parent 56b3d20413
commit 62b53b37e4
2 changed files with 31 additions and 15 deletions

View File

@@ -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);