diff options
author | Christian König <christian.koenig@amd.com> | 2018-10-19 09:06:06 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2018-11-05 14:21:20 -0500 |
commit | 62b53b37e4b1500d4eb4624a44ad861cf8d3cd18 (patch) | |
tree | 0193d438cbb744c1c423415145ca8d695cdf34c6 | |
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>
-rw-r--r-- | drivers/gpu/drm/ttm/ttm_bo.c | 31 | ||||
-rw-r--r-- | include/drm/ttm/ttm_bo_driver.h | 15 |
2 files changed, 31 insertions, 15 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); | |||
49 | * ttm_global_mutex - protecting the global BO state | 49 | * ttm_global_mutex - protecting the global BO state |
50 | */ | 50 | */ |
51 | DEFINE_MUTEX(ttm_global_mutex); | 51 | DEFINE_MUTEX(ttm_global_mutex); |
52 | struct ttm_bo_global ttm_bo_glob = { | ||
53 | .use_count = 0 | ||
54 | }; | ||
52 | 55 | ||
53 | static struct attribute ttm_bo_count = { | 56 | static struct attribute ttm_bo_count = { |
54 | .name = "bo_count", | 57 | .name = "bo_count", |
@@ -1527,22 +1530,35 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj) | |||
1527 | kfree(glob); | 1530 | kfree(glob); |
1528 | } | 1531 | } |
1529 | 1532 | ||
1530 | void ttm_bo_global_release(struct ttm_bo_global *glob) | 1533 | void ttm_bo_global_release(void) |
1531 | { | 1534 | { |
1535 | struct ttm_bo_global *glob = &ttm_bo_glob; | ||
1536 | |||
1537 | mutex_lock(&ttm_global_mutex); | ||
1538 | if (--glob->use_count > 0) | ||
1539 | goto out; | ||
1540 | |||
1532 | kobject_del(&glob->kobj); | 1541 | kobject_del(&glob->kobj); |
1533 | kobject_put(&glob->kobj); | 1542 | kobject_put(&glob->kobj); |
1534 | ttm_mem_global_release(&ttm_mem_glob); | 1543 | ttm_mem_global_release(&ttm_mem_glob); |
1544 | out: | ||
1545 | mutex_unlock(&ttm_global_mutex); | ||
1535 | } | 1546 | } |
1536 | EXPORT_SYMBOL(ttm_bo_global_release); | 1547 | EXPORT_SYMBOL(ttm_bo_global_release); |
1537 | 1548 | ||
1538 | int ttm_bo_global_init(struct ttm_bo_global *glob) | 1549 | int ttm_bo_global_init(void) |
1539 | { | 1550 | { |
1540 | int ret; | 1551 | struct ttm_bo_global *glob = &ttm_bo_glob; |
1552 | int ret = 0; | ||
1541 | unsigned i; | 1553 | unsigned i; |
1542 | 1554 | ||
1555 | mutex_lock(&ttm_global_mutex); | ||
1556 | if (++glob->use_count > 1) | ||
1557 | goto out; | ||
1558 | |||
1543 | ret = ttm_mem_global_init(&ttm_mem_glob); | 1559 | ret = ttm_mem_global_init(&ttm_mem_glob); |
1544 | if (ret) | 1560 | if (ret) |
1545 | return ret; | 1561 | goto out; |
1546 | 1562 | ||
1547 | spin_lock_init(&glob->lru_lock); | 1563 | spin_lock_init(&glob->lru_lock); |
1548 | glob->mem_glob = &ttm_mem_glob; | 1564 | glob->mem_glob = &ttm_mem_glob; |
@@ -1551,7 +1567,7 @@ int ttm_bo_global_init(struct ttm_bo_global *glob) | |||
1551 | 1567 | ||
1552 | if (unlikely(glob->dummy_read_page == NULL)) { | 1568 | if (unlikely(glob->dummy_read_page == NULL)) { |
1553 | ret = -ENOMEM; | 1569 | ret = -ENOMEM; |
1554 | goto out_no_drp; | 1570 | goto out; |
1555 | } | 1571 | } |
1556 | 1572 | ||
1557 | for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) | 1573 | for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) |
@@ -1563,9 +1579,8 @@ int ttm_bo_global_init(struct ttm_bo_global *glob) | |||
1563 | &glob->kobj, &ttm_bo_glob_kobj_type, ttm_get_kobj(), "buffer_objects"); | 1579 | &glob->kobj, &ttm_bo_glob_kobj_type, ttm_get_kobj(), "buffer_objects"); |
1564 | if (unlikely(ret != 0)) | 1580 | if (unlikely(ret != 0)) |
1565 | kobject_put(&glob->kobj); | 1581 | kobject_put(&glob->kobj); |
1566 | return ret; | 1582 | out: |
1567 | out_no_drp: | 1583 | mutex_unlock(&ttm_global_mutex); |
1568 | kfree(glob); | ||
1569 | return ret; | 1584 | return ret; |
1570 | } | 1585 | } |
1571 | EXPORT_SYMBOL(ttm_bo_global_init); | 1586 | EXPORT_SYMBOL(ttm_bo_global_init); |
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index 9cec8835b88f..26be74939f10 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h | |||
@@ -398,7 +398,7 @@ struct ttm_bo_driver { | |||
398 | * @swap_lru: Lru list of buffer objects used for swapping. | 398 | * @swap_lru: Lru list of buffer objects used for swapping. |
399 | */ | 399 | */ |
400 | 400 | ||
401 | struct ttm_bo_global { | 401 | extern struct ttm_bo_global { |
402 | 402 | ||
403 | /** | 403 | /** |
404 | * Constant after init. | 404 | * Constant after init. |
@@ -410,8 +410,9 @@ struct ttm_bo_global { | |||
410 | spinlock_t lru_lock; | 410 | spinlock_t lru_lock; |
411 | 411 | ||
412 | /** | 412 | /** |
413 | * Protected by device_list_mutex. | 413 | * Protected by ttm_global_mutex. |
414 | */ | 414 | */ |
415 | unsigned int use_count; | ||
415 | struct list_head device_list; | 416 | struct list_head device_list; |
416 | 417 | ||
417 | /** | 418 | /** |
@@ -423,7 +424,7 @@ struct ttm_bo_global { | |||
423 | * Internal protection. | 424 | * Internal protection. |
424 | */ | 425 | */ |
425 | atomic_t bo_count; | 426 | atomic_t bo_count; |
426 | }; | 427 | } ttm_bo_glob; |
427 | 428 | ||
428 | 429 | ||
429 | #define TTM_NUM_MEM_TYPES 8 | 430 | #define TTM_NUM_MEM_TYPES 8 |
@@ -568,8 +569,8 @@ void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem); | |||
568 | void ttm_bo_mem_put_locked(struct ttm_buffer_object *bo, | 569 | void ttm_bo_mem_put_locked(struct ttm_buffer_object *bo, |
569 | struct ttm_mem_reg *mem); | 570 | struct ttm_mem_reg *mem); |
570 | 571 | ||
571 | void ttm_bo_global_release(struct ttm_bo_global *glob); | 572 | void ttm_bo_global_release(void); |
572 | int ttm_bo_global_init(struct ttm_bo_global *glob); | 573 | int ttm_bo_global_init(void); |
573 | 574 | ||
574 | int ttm_bo_device_release(struct ttm_bo_device *bdev); | 575 | int ttm_bo_device_release(struct ttm_bo_device *bdev); |
575 | 576 | ||
@@ -906,7 +907,7 @@ struct ttm_bo_global_ref { | |||
906 | */ | 907 | */ |
907 | static inline int ttm_bo_global_ref_init(struct drm_global_reference *ref) | 908 | static inline int ttm_bo_global_ref_init(struct drm_global_reference *ref) |
908 | { | 909 | { |
909 | return ttm_bo_global_init(ref->object); | 910 | return ttm_bo_global_init(); |
910 | } | 911 | } |
911 | 912 | ||
912 | /** | 913 | /** |
@@ -920,7 +921,7 @@ static inline int ttm_bo_global_ref_init(struct drm_global_reference *ref) | |||
920 | */ | 921 | */ |
921 | static inline void ttm_bo_global_ref_release(struct drm_global_reference *ref) | 922 | static inline void ttm_bo_global_ref_release(struct drm_global_reference *ref) |
922 | { | 923 | { |
923 | ttm_bo_global_release(ref->object); | 924 | ttm_bo_global_release(); |
924 | } | 925 | } |
925 | 926 | ||
926 | #endif | 927 | #endif |