aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/ttm/ttm_bo.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/ttm/ttm_bo.c')
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo.c97
1 files changed, 26 insertions, 71 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 50fc8e4c9a3..617b64678fc 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -499,7 +499,7 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)
499 int ret; 499 int ret;
500 500
501 spin_lock(&bdev->fence_lock); 501 spin_lock(&bdev->fence_lock);
502 (void) ttm_bo_wait(bo, false, false, true, TTM_USAGE_READWRITE); 502 (void) ttm_bo_wait(bo, false, false, true);
503 if (!bo->sync_obj) { 503 if (!bo->sync_obj) {
504 504
505 spin_lock(&glob->lru_lock); 505 spin_lock(&glob->lru_lock);
@@ -567,8 +567,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
567 567
568retry: 568retry:
569 spin_lock(&bdev->fence_lock); 569 spin_lock(&bdev->fence_lock);
570 ret = ttm_bo_wait(bo, false, interruptible, no_wait_gpu, 570 ret = ttm_bo_wait(bo, false, interruptible, no_wait_gpu);
571 TTM_USAGE_READWRITE);
572 spin_unlock(&bdev->fence_lock); 571 spin_unlock(&bdev->fence_lock);
573 572
574 if (unlikely(ret != 0)) 573 if (unlikely(ret != 0))
@@ -727,8 +726,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool interruptible,
727 int ret = 0; 726 int ret = 0;
728 727
729 spin_lock(&bdev->fence_lock); 728 spin_lock(&bdev->fence_lock);
730 ret = ttm_bo_wait(bo, false, interruptible, no_wait_gpu, 729 ret = ttm_bo_wait(bo, false, interruptible, no_wait_gpu);
731 TTM_USAGE_READWRITE);
732 spin_unlock(&bdev->fence_lock); 730 spin_unlock(&bdev->fence_lock);
733 731
734 if (unlikely(ret != 0)) { 732 if (unlikely(ret != 0)) {
@@ -1075,8 +1073,7 @@ int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
1075 * instead of doing it here. 1073 * instead of doing it here.
1076 */ 1074 */
1077 spin_lock(&bdev->fence_lock); 1075 spin_lock(&bdev->fence_lock);
1078 ret = ttm_bo_wait(bo, false, interruptible, no_wait_gpu, 1076 ret = ttm_bo_wait(bo, false, interruptible, no_wait_gpu);
1079 TTM_USAGE_READWRITE);
1080 spin_unlock(&bdev->fence_lock); 1077 spin_unlock(&bdev->fence_lock);
1081 if (ret) 1078 if (ret)
1082 return ret; 1079 return ret;
@@ -1697,83 +1694,34 @@ out_unlock:
1697 return ret; 1694 return ret;
1698} 1695}
1699 1696
1700static void ttm_bo_unref_sync_obj_locked(struct ttm_buffer_object *bo,
1701 void *sync_obj,
1702 void **extra_sync_obj)
1703{
1704 struct ttm_bo_device *bdev = bo->bdev;
1705 struct ttm_bo_driver *driver = bdev->driver;
1706 void *tmp_obj = NULL, *tmp_obj_read = NULL, *tmp_obj_write = NULL;
1707
1708 /* We must unref the sync obj wherever it's ref'd.
1709 * Note that if we unref bo->sync_obj, we can unref both the read
1710 * and write sync objs too, because they can't be newer than
1711 * bo->sync_obj, so they are no longer relevant. */
1712 if (sync_obj == bo->sync_obj ||
1713 sync_obj == bo->sync_obj_read) {
1714 tmp_obj_read = bo->sync_obj_read;
1715 bo->sync_obj_read = NULL;
1716 }
1717 if (sync_obj == bo->sync_obj ||
1718 sync_obj == bo->sync_obj_write) {
1719 tmp_obj_write = bo->sync_obj_write;
1720 bo->sync_obj_write = NULL;
1721 }
1722 if (sync_obj == bo->sync_obj) {
1723 tmp_obj = bo->sync_obj;
1724 bo->sync_obj = NULL;
1725 }
1726
1727 clear_bit(TTM_BO_PRIV_FLAG_MOVING, &bo->priv_flags);
1728 spin_unlock(&bdev->fence_lock);
1729 if (tmp_obj)
1730 driver->sync_obj_unref(&tmp_obj);
1731 if (tmp_obj_read)
1732 driver->sync_obj_unref(&tmp_obj_read);
1733 if (tmp_obj_write)
1734 driver->sync_obj_unref(&tmp_obj_write);
1735 if (extra_sync_obj)
1736 driver->sync_obj_unref(extra_sync_obj);
1737 spin_lock(&bdev->fence_lock);
1738}
1739
1740int ttm_bo_wait(struct ttm_buffer_object *bo, 1697int ttm_bo_wait(struct ttm_buffer_object *bo,
1741 bool lazy, bool interruptible, bool no_wait, 1698 bool lazy, bool interruptible, bool no_wait)
1742 enum ttm_buffer_usage usage)
1743{ 1699{
1744 struct ttm_bo_driver *driver = bo->bdev->driver; 1700 struct ttm_bo_driver *driver = bo->bdev->driver;
1745 struct ttm_bo_device *bdev = bo->bdev; 1701 struct ttm_bo_device *bdev = bo->bdev;
1746 void *sync_obj; 1702 void *sync_obj;
1747 void *sync_obj_arg; 1703 void *sync_obj_arg;
1748 int ret = 0; 1704 int ret = 0;
1749 void **bo_sync_obj;
1750 1705
1751 switch (usage) { 1706 if (likely(bo->sync_obj == NULL))
1752 case TTM_USAGE_READ:
1753 bo_sync_obj = &bo->sync_obj_read;
1754 break;
1755 case TTM_USAGE_WRITE:
1756 bo_sync_obj = &bo->sync_obj_write;
1757 break;
1758 case TTM_USAGE_READWRITE:
1759 default:
1760 bo_sync_obj = &bo->sync_obj;
1761 }
1762
1763 if (likely(*bo_sync_obj == NULL))
1764 return 0; 1707 return 0;
1765 1708
1766 while (*bo_sync_obj) { 1709 while (bo->sync_obj) {
1767 1710
1768 if (driver->sync_obj_signaled(*bo_sync_obj, bo->sync_obj_arg)) { 1711 if (driver->sync_obj_signaled(bo->sync_obj, bo->sync_obj_arg)) {
1769 ttm_bo_unref_sync_obj_locked(bo, *bo_sync_obj, NULL); 1712 void *tmp_obj = bo->sync_obj;
1713 bo->sync_obj = NULL;
1714 clear_bit(TTM_BO_PRIV_FLAG_MOVING, &bo->priv_flags);
1715 spin_unlock(&bdev->fence_lock);
1716 driver->sync_obj_unref(&tmp_obj);
1717 spin_lock(&bdev->fence_lock);
1770 continue; 1718 continue;
1771 } 1719 }
1772 1720
1773 if (no_wait) 1721 if (no_wait)
1774 return -EBUSY; 1722 return -EBUSY;
1775 1723
1776 sync_obj = driver->sync_obj_ref(*bo_sync_obj); 1724 sync_obj = driver->sync_obj_ref(bo->sync_obj);
1777 sync_obj_arg = bo->sync_obj_arg; 1725 sync_obj_arg = bo->sync_obj_arg;
1778 spin_unlock(&bdev->fence_lock); 1726 spin_unlock(&bdev->fence_lock);
1779 ret = driver->sync_obj_wait(sync_obj, sync_obj_arg, 1727 ret = driver->sync_obj_wait(sync_obj, sync_obj_arg,
@@ -1784,9 +1732,16 @@ int ttm_bo_wait(struct ttm_buffer_object *bo,
1784 return ret; 1732 return ret;
1785 } 1733 }
1786 spin_lock(&bdev->fence_lock); 1734 spin_lock(&bdev->fence_lock);
1787 if (likely(*bo_sync_obj == sync_obj && 1735 if (likely(bo->sync_obj == sync_obj &&
1788 bo->sync_obj_arg == sync_obj_arg)) { 1736 bo->sync_obj_arg == sync_obj_arg)) {
1789 ttm_bo_unref_sync_obj_locked(bo, *bo_sync_obj, &sync_obj); 1737 void *tmp_obj = bo->sync_obj;
1738 bo->sync_obj = NULL;
1739 clear_bit(TTM_BO_PRIV_FLAG_MOVING,
1740 &bo->priv_flags);
1741 spin_unlock(&bdev->fence_lock);
1742 driver->sync_obj_unref(&sync_obj);
1743 driver->sync_obj_unref(&tmp_obj);
1744 spin_lock(&bdev->fence_lock);
1790 } else { 1745 } else {
1791 spin_unlock(&bdev->fence_lock); 1746 spin_unlock(&bdev->fence_lock);
1792 driver->sync_obj_unref(&sync_obj); 1747 driver->sync_obj_unref(&sync_obj);
@@ -1810,7 +1765,7 @@ int ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait)
1810 if (unlikely(ret != 0)) 1765 if (unlikely(ret != 0))
1811 return ret; 1766 return ret;
1812 spin_lock(&bdev->fence_lock); 1767 spin_lock(&bdev->fence_lock);
1813 ret = ttm_bo_wait(bo, false, true, no_wait, TTM_USAGE_READWRITE); 1768 ret = ttm_bo_wait(bo, false, true, no_wait);
1814 spin_unlock(&bdev->fence_lock); 1769 spin_unlock(&bdev->fence_lock);
1815 if (likely(ret == 0)) 1770 if (likely(ret == 0))
1816 atomic_inc(&bo->cpu_writers); 1771 atomic_inc(&bo->cpu_writers);
@@ -1884,7 +1839,7 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)
1884 */ 1839 */
1885 1840
1886 spin_lock(&bo->bdev->fence_lock); 1841 spin_lock(&bo->bdev->fence_lock);
1887 ret = ttm_bo_wait(bo, false, false, false, TTM_USAGE_READWRITE); 1842 ret = ttm_bo_wait(bo, false, false, false);
1888 spin_unlock(&bo->bdev->fence_lock); 1843 spin_unlock(&bo->bdev->fence_lock);
1889 1844
1890 if (unlikely(ret != 0)) 1845 if (unlikely(ret != 0))