aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/vmwgfx
diff options
context:
space:
mode:
authorJerome Glisse <jglisse@redhat.com>2011-11-11 15:42:57 -0500
committerDave Airlie <airlied@redhat.com>2011-12-06 05:40:11 -0500
commit57de4ba959b290f0b8cf36ecd5e7f1b29d4b8a12 (patch)
tree8063f4dfaf1a22bf8cf7a5f0410d4e4929b250ec /drivers/gpu/drm/vmwgfx
parent8e7e70522d760c4ccd4cd370ebfa0ba69e006c6e (diff)
drm/ttm: simplify memory accounting for ttm user v2
Provide helper function to compute the kernel memory size needed for each buffer object. Move all the accounting inside ttm, simplifying driver and avoiding code duplication accross them. v2 fix accounting of ghost object, one would have thought that i would have run into the issue since a longtime but it seems ghost object are rare when you have plenty of vram ;) Signed-off-by: Jerome Glisse <jglisse@redhat.com> Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
Diffstat (limited to 'drivers/gpu/drm/vmwgfx')
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_resource.c35
1 files changed, 1 insertions, 34 deletions
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 86c5e4cceb31..2eb84a55aee7 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -1517,29 +1517,10 @@ out_bad_surface:
1517/** 1517/**
1518 * Buffer management. 1518 * Buffer management.
1519 */ 1519 */
1520
1521static size_t vmw_dmabuf_acc_size(struct ttm_bo_global *glob,
1522 unsigned long num_pages)
1523{
1524 static size_t bo_user_size = ~0;
1525
1526 size_t page_array_size =
1527 (num_pages * sizeof(void *) + PAGE_SIZE - 1) & PAGE_MASK;
1528
1529 if (unlikely(bo_user_size == ~0)) {
1530 bo_user_size = glob->ttm_bo_extra_size +
1531 ttm_round_pot(sizeof(struct vmw_dma_buffer));
1532 }
1533
1534 return bo_user_size + page_array_size;
1535}
1536
1537void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo) 1520void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo)
1538{ 1521{
1539 struct vmw_dma_buffer *vmw_bo = vmw_dma_buffer(bo); 1522 struct vmw_dma_buffer *vmw_bo = vmw_dma_buffer(bo);
1540 struct ttm_bo_global *glob = bo->glob;
1541 1523
1542 ttm_mem_global_free(glob->mem_glob, bo->acc_size);
1543 kfree(vmw_bo); 1524 kfree(vmw_bo);
1544} 1525}
1545 1526
@@ -1550,24 +1531,12 @@ int vmw_dmabuf_init(struct vmw_private *dev_priv,
1550 void (*bo_free) (struct ttm_buffer_object *bo)) 1531 void (*bo_free) (struct ttm_buffer_object *bo))
1551{ 1532{
1552 struct ttm_bo_device *bdev = &dev_priv->bdev; 1533 struct ttm_bo_device *bdev = &dev_priv->bdev;
1553 struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;
1554 size_t acc_size; 1534 size_t acc_size;
1555 int ret; 1535 int ret;
1556 1536
1557 BUG_ON(!bo_free); 1537 BUG_ON(!bo_free);
1558 1538
1559 acc_size = 1539 acc_size = ttm_bo_acc_size(bdev, size, sizeof(struct vmw_dma_buffer));
1560 vmw_dmabuf_acc_size(bdev->glob,
1561 (size + PAGE_SIZE - 1) >> PAGE_SHIFT);
1562
1563 ret = ttm_mem_global_alloc(mem_glob, acc_size, false, false);
1564 if (unlikely(ret != 0)) {
1565 /* we must free the bo here as
1566 * ttm_buffer_object_init does so as well */
1567 bo_free(&vmw_bo->base);
1568 return ret;
1569 }
1570
1571 memset(vmw_bo, 0, sizeof(*vmw_bo)); 1540 memset(vmw_bo, 0, sizeof(*vmw_bo));
1572 1541
1573 INIT_LIST_HEAD(&vmw_bo->validate_list); 1542 INIT_LIST_HEAD(&vmw_bo->validate_list);
@@ -1582,9 +1551,7 @@ int vmw_dmabuf_init(struct vmw_private *dev_priv,
1582static void vmw_user_dmabuf_destroy(struct ttm_buffer_object *bo) 1551static void vmw_user_dmabuf_destroy(struct ttm_buffer_object *bo)
1583{ 1552{
1584 struct vmw_user_dma_buffer *vmw_user_bo = vmw_user_dma_buffer(bo); 1553 struct vmw_user_dma_buffer *vmw_user_bo = vmw_user_dma_buffer(bo);
1585 struct ttm_bo_global *glob = bo->glob;
1586 1554
1587 ttm_mem_global_free(glob->mem_glob, bo->acc_size);
1588 kfree(vmw_user_bo); 1555 kfree(vmw_user_bo);
1589} 1556}
1590 1557