drm/ttm: add reservation_object as argument to ttm_bo_init
authorMaarten Lankhorst <maarten.lankhorst@canonical.com>
Thu, 9 Jan 2014 10:03:15 +0000 (11:03 +0100)
committerMaarten Lankhorst <maarten.lankhorst@canonical.com>
Tue, 30 Sep 2014 12:04:00 +0000 (14:04 +0200)
This allows importing reservation objects from dma-bufs.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
drivers/gpu/drm/ast/ast_ttm.c
drivers/gpu/drm/bochs/bochs_mm.c
drivers/gpu/drm/cirrus/cirrus_ttm.c
drivers/gpu/drm/mgag200/mgag200_ttm.c
drivers/gpu/drm/nouveau/nouveau_bo.c
drivers/gpu/drm/qxl/qxl_object.c
drivers/gpu/drm/radeon/radeon_object.c
drivers/gpu/drm/ttm/ttm_bo.c
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
include/drm/ttm/ttm_bo_api.h

index c65d432f42c42f7f57d70d9f7b919661bf2151db..08f82eae69398509a7daf55d55a4a94a4e57b6f4 100644 (file)
@@ -339,7 +339,7 @@ int ast_bo_create(struct drm_device *dev, int size, int align,
        ret = ttm_bo_init(&ast->ttm.bdev, &astbo->bo, size,
                          ttm_bo_type_device, &astbo->placement,
                          align >> PAGE_SHIFT, false, NULL, acc_size,
-                         NULL, ast_bo_ttm_destroy);
+                         NULL, NULL, ast_bo_ttm_destroy);
        if (ret)
                return ret;
 
index 324f5a09a0a119bf1f1b6d8dd59d2838f47efe82..66286ff518d4be28e8b71b2b8ebf0d0b2ada6496 100644 (file)
@@ -377,7 +377,7 @@ static int bochs_bo_create(struct drm_device *dev, int size, int align,
        ret = ttm_bo_init(&bochs->ttm.bdev, &bochsbo->bo, size,
                          ttm_bo_type_device, &bochsbo->placement,
                          align >> PAGE_SHIFT, false, NULL, acc_size,
-                         NULL, bochs_bo_ttm_destroy);
+                         NULL, NULL, bochs_bo_ttm_destroy);
        if (ret)
                return ret;
 
index d3c615f9b1830170a46a69608e0ad90119dac033..dfffd528517a53b1783e8f5c22d1f622d1e7d537 100644 (file)
@@ -343,7 +343,7 @@ int cirrus_bo_create(struct drm_device *dev, int size, int align,
        ret = ttm_bo_init(&cirrus->ttm.bdev, &cirrusbo->bo, size,
                          ttm_bo_type_device, &cirrusbo->placement,
                          align >> PAGE_SHIFT, false, NULL, acc_size,
-                         NULL, cirrus_bo_ttm_destroy);
+                         NULL, NULL, cirrus_bo_ttm_destroy);
        if (ret)
                return ret;
 
index 8ac70626df6c3fa457056be1d32c827d0f00f223..d16964ea0ed4820039ca1b90030032e8ed735212 100644 (file)
@@ -339,7 +339,7 @@ int mgag200_bo_create(struct drm_device *dev, int size, int align,
        ret = ttm_bo_init(&mdev->ttm.bdev, &mgabo->bo, size,
                          ttm_bo_type_device, &mgabo->placement,
                          align >> PAGE_SHIFT, false, NULL, acc_size,
-                         NULL, mgag200_bo_ttm_destroy);
+                         NULL, NULL, mgag200_bo_ttm_destroy);
        if (ret)
                return ret;
 
index 049f5de909282bbc0e9f6d0cb75e213187ef283c..7034cacaa4a1b9729c422d0dd2b3d16c6b379d18 100644 (file)
@@ -230,7 +230,7 @@ nouveau_bo_new(struct drm_device *dev, int size, int align,
        ret = ttm_bo_init(&drm->ttm.bdev, &nvbo->bo, size,
                          type, &nvbo->placement,
                          align >> PAGE_SHIFT, false, NULL, acc_size, sg,
-                         nouveau_bo_del_ttm);
+                         NULL, nouveau_bo_del_ttm);
        if (ret) {
                /* ttm will call nouveau_bo_del_ttm if it fails.. */
                return ret;
index 69c104c3240f5adab48e775e25933f7bed6eb40a..cdeaf08fdc745a9b27600e78edc200e97e53c620 100644 (file)
@@ -110,7 +110,7 @@ int qxl_bo_create(struct qxl_device *qdev,
 
        r = ttm_bo_init(&qdev->mman.bdev, &bo->tbo, size, type,
                        &bo->placement, 0, !kernel, NULL, size,
-                       NULL, &qxl_ttm_bo_destroy);
+                       NULL, NULL, &qxl_ttm_bo_destroy);
        if (unlikely(r != 0)) {
                if (r != -ERESTARTSYS)
                        dev_err(qdev->dev,
index 8abee5fa93bd59c2bac81f181b2297f2f8c8f430..0e82f0223fd48df3134bfd23287128e01e141779 100644 (file)
@@ -216,7 +216,7 @@ int radeon_bo_create(struct radeon_device *rdev,
        down_read(&rdev->pm.mclk_lock);
        r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type,
                        &bo->placement, page_align, !kernel, NULL,
-                       acc_size, sg, &radeon_ttm_bo_destroy);
+                       acc_size, sg, NULL, &radeon_ttm_bo_destroy);
        up_read(&rdev->pm.mclk_lock);
        if (unlikely(r != 0)) {
                return r;
index a11969acfea5363fc1ce747338edd03b40b24cba..8f5cec67c47dd6b8976af0709bae49105b67ed49 100644 (file)
@@ -1068,6 +1068,7 @@ int ttm_bo_init(struct ttm_bo_device *bdev,
                struct file *persistent_swap_storage,
                size_t acc_size,
                struct sg_table *sg,
+               struct reservation_object *resv,
                void (*destroy) (struct ttm_buffer_object *))
 {
        int ret = 0;
@@ -1121,8 +1122,13 @@ int ttm_bo_init(struct ttm_bo_device *bdev,
        bo->persistent_swap_storage = persistent_swap_storage;
        bo->acc_size = acc_size;
        bo->sg = sg;
-       bo->resv = &bo->ttm_resv;
-       reservation_object_init(bo->resv);
+       if (resv) {
+               bo->resv = resv;
+               lockdep_assert_held(&bo->resv->lock.base);
+       } else {
+               bo->resv = &bo->ttm_resv;
+               reservation_object_init(&bo->ttm_resv);
+       }
        atomic_inc(&bo->glob->bo_count);
        drm_vma_node_reset(&bo->vma_node);
 
@@ -1135,13 +1141,19 @@ int ttm_bo_init(struct ttm_bo_device *bdev,
                ret = drm_vma_offset_add(&bdev->vma_manager, &bo->vma_node,
                                         bo->mem.num_pages);
 
-       locked = ww_mutex_trylock(&bo->resv->lock);
-       WARN_ON(!locked);
+       /* passed reservation objects should already be locked,
+        * since otherwise lockdep will be angered in radeon.
+        */
+       if (!resv) {
+               locked = ww_mutex_trylock(&bo->resv->lock);
+               WARN_ON(!locked);
+       }
 
        if (likely(!ret))
                ret = ttm_bo_validate(bo, placement, interruptible, false);
 
-       ttm_bo_unreserve(bo);
+       if (!resv)
+               ttm_bo_unreserve(bo);
 
        if (unlikely(ret))
                ttm_bo_unref(&bo);
@@ -1199,7 +1211,7 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
        acc_size = ttm_bo_acc_size(bdev, size, sizeof(struct ttm_buffer_object));
        ret = ttm_bo_init(bdev, bo, size, type, placement, page_alignment,
                          interruptible, persistent_swap_storage, acc_size,
-                         NULL, NULL);
+                         NULL, NULL, NULL);
        if (likely(ret == 0))
                *p_bo = bo;
 
index 26584316cb789002ff73982f73620056d13f9ada..026de7cea0f662bd75e92cf4ad1dfde057c7775e 100644 (file)
@@ -430,7 +430,7 @@ int vmw_dmabuf_init(struct vmw_private *dev_priv,
        ret = ttm_bo_init(bdev, &vmw_bo->base, size,
                          ttm_bo_type_device, placement,
                          0, interruptible,
-                         NULL, acc_size, NULL, bo_free);
+                         NULL, acc_size, NULL, NULL, bo_free);
        return ret;
 }
 
index 70b44917c36892670382c1b7b8b4b514846f6a13..0ccf7f267ff94408387d71da446cc89ab1caf6fa 100644 (file)
@@ -460,6 +460,7 @@ size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev,
  * point to the shmem object backing a GEM object if TTM is used to back a
  * GEM user interface.
  * @acc_size: Accounted size for this object.
+ * @resv: Pointer to a reservation_object, or NULL to let ttm allocate one.
  * @destroy: Destroy function. Use NULL for kfree().
  *
  * This function initializes a pre-allocated struct ttm_buffer_object.
@@ -487,6 +488,7 @@ extern int ttm_bo_init(struct ttm_bo_device *bdev,
                        struct file *persistent_swap_storage,
                        size_t acc_size,
                        struct sg_table *sg,
+                       struct reservation_object *resv,
                        void (*destroy) (struct ttm_buffer_object *));
 
 /**