]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/i915: Consolidate get_fence with pin_fence
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 9 Oct 2017 08:43:56 +0000 (09:43 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Mon, 9 Oct 2017 16:07:29 +0000 (17:07 +0100)
Following the pattern now used for obj->mm.pages, use just pin_fence and
unpin_fence to control access to the fence registers. I.e. instead of
calling get_fence(); pin_fence(), we now just need to call pin_fence().
This will make it easier to reduce the locking requirements around
fence registers.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20171009084401.29090-2-chris@chris-wilson.co.uk
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/i915_gem.c
drivers/gpu/drm/i915/i915_gem_execbuffer.c
drivers/gpu/drm/i915/i915_gem_fence_reg.c
drivers/gpu/drm/i915/i915_vma.c
drivers/gpu/drm/i915/i915_vma.h
drivers/gpu/drm/i915/intel_display.c

index 799a90abd81f267a9588ad0c022326b108f4b8d7..5d322cf490c4c0fec745beefe5e54230af6d69d1 100644 (file)
@@ -3759,8 +3759,6 @@ i915_vm_to_ppgtt(struct i915_address_space *vm)
 }
 
 /* i915_gem_fence_reg.c */
-int __must_check i915_vma_get_fence(struct i915_vma *vma);
-int __must_check i915_vma_put_fence(struct i915_vma *vma);
 struct drm_i915_fence_reg *
 i915_reserve_fence(struct drm_i915_private *dev_priv);
 void i915_unreserve_fence(struct drm_i915_fence_reg *fence);
index eba23c239aae2d1cd97f91eea0a25303b62cdc71..37eba9da3fcabb011746ddbd9b6981a236402de7 100644 (file)
@@ -1910,7 +1910,7 @@ int i915_gem_fault(struct vm_fault *vmf)
        if (ret)
                goto err_unpin;
 
-       ret = i915_vma_get_fence(vma);
+       ret = i915_vma_pin_fence(vma);
        if (ret)
                goto err_unpin;
 
@@ -1926,6 +1926,7 @@ int i915_gem_fault(struct vm_fault *vmf)
                               min_t(u64, vma->size, area->vm_end - area->vm_start),
                               &ggtt->mappable);
 
+       i915_vma_unpin_fence(vma);
 err_unpin:
        __i915_vma_unpin(vma);
 err_unlock:
index d733c4d5a5002c047fed386a9531081a80373197..1df54e5fbb6eddf12e85f84c2918c0106294a38a 100644 (file)
@@ -367,12 +367,12 @@ eb_pin_vma(struct i915_execbuffer *eb,
                return false;
 
        if (unlikely(exec_flags & EXEC_OBJECT_NEEDS_FENCE)) {
-               if (unlikely(i915_vma_get_fence(vma))) {
+               if (unlikely(i915_vma_pin_fence(vma))) {
                        i915_vma_unpin(vma);
                        return false;
                }
 
-               if (i915_vma_pin_fence(vma))
+               if (vma->fence)
                        exec_flags |= __EXEC_OBJECT_HAS_FENCE;
        }
 
@@ -385,7 +385,7 @@ static inline void __eb_unreserve_vma(struct i915_vma *vma, unsigned int flags)
        GEM_BUG_ON(!(flags & __EXEC_OBJECT_HAS_PIN));
 
        if (unlikely(flags & __EXEC_OBJECT_HAS_FENCE))
-               i915_vma_unpin_fence(vma);
+               __i915_vma_unpin_fence(vma);
 
        __i915_vma_unpin(vma);
 }
@@ -563,13 +563,13 @@ static int eb_reserve_vma(const struct i915_execbuffer *eb,
        }
 
        if (unlikely(exec_flags & EXEC_OBJECT_NEEDS_FENCE)) {
-               err = i915_vma_get_fence(vma);
+               err = i915_vma_pin_fence(vma);
                if (unlikely(err)) {
                        i915_vma_unpin(vma);
                        return err;
                }
 
-               if (i915_vma_pin_fence(vma))
+               if (vma->fence)
                        exec_flags |= __EXEC_OBJECT_HAS_FENCE;
        }
 
index 2783d63bd1adac44fc06da4922893051c6966bbb..af824b8d73eac470f6b3d57e881c0352dcdf4e1e 100644 (file)
@@ -280,8 +280,7 @@ static int fence_update(struct drm_i915_fence_reg *fence,
  *
  * 0 on success, negative error code on failure.
  */
-int
-i915_vma_put_fence(struct i915_vma *vma)
+int i915_vma_put_fence(struct i915_vma *vma)
 {
        struct drm_i915_fence_reg *fence = vma->fence;
 
@@ -299,6 +298,8 @@ static struct drm_i915_fence_reg *fence_find(struct drm_i915_private *dev_priv)
        struct drm_i915_fence_reg *fence;
 
        list_for_each_entry(fence, &dev_priv->mm.fence_list, link) {
+               GEM_BUG_ON(fence->vma && fence->vma->fence != fence);
+
                if (fence->pin_count)
                        continue;
 
@@ -313,7 +314,7 @@ static struct drm_i915_fence_reg *fence_find(struct drm_i915_private *dev_priv)
 }
 
 /**
- * i915_vma_get_fence - set up fencing for a vma
+ * i915_vma_pin_fence - set up fencing for a vma
  * @vma: vma to map through a fence reg
  *
  * When mapping objects through the GTT, userspace wants to be able to write
@@ -331,10 +332,11 @@ static struct drm_i915_fence_reg *fence_find(struct drm_i915_private *dev_priv)
  * 0 on success, negative error code on failure.
  */
 int
-i915_vma_get_fence(struct i915_vma *vma)
+i915_vma_pin_fence(struct i915_vma *vma)
 {
        struct drm_i915_fence_reg *fence;
        struct i915_vma *set = i915_gem_object_is_tiled(vma->obj) ? vma : NULL;
+       int err;
 
        /* Note that we revoke fences on runtime suspend. Therefore the user
         * must keep the device awake whilst using the fence.
@@ -344,6 +346,8 @@ i915_vma_get_fence(struct i915_vma *vma)
        /* Just update our place in the LRU if our fence is getting reused. */
        if (vma->fence) {
                fence = vma->fence;
+               GEM_BUG_ON(fence->vma != vma);
+               fence->pin_count++;
                if (!fence->dirty) {
                        list_move_tail(&fence->link,
                                       &fence->i915->mm.fence_list);
@@ -353,10 +357,25 @@ i915_vma_get_fence(struct i915_vma *vma)
                fence = fence_find(vma->vm->i915);
                if (IS_ERR(fence))
                        return PTR_ERR(fence);
+
+               GEM_BUG_ON(fence->pin_count);
+               fence->pin_count++;
        } else
                return 0;
 
-       return fence_update(fence, set);
+       err = fence_update(fence, set);
+       if (err)
+               goto out_unpin;
+
+       GEM_BUG_ON(fence->vma != set);
+       GEM_BUG_ON(vma->fence != (set ? fence : NULL));
+
+       if (set)
+               return 0;
+
+out_unpin:
+       fence->pin_count--;
+       return err;
 }
 
 /**
@@ -429,6 +448,8 @@ void i915_gem_revoke_fences(struct drm_i915_private *dev_priv)
        for (i = 0; i < dev_priv->num_fence_regs; i++) {
                struct drm_i915_fence_reg *fence = &dev_priv->fence_regs[i];
 
+               GEM_BUG_ON(fence->vma && fence->vma->fence != fence);
+
                if (fence->vma)
                        i915_gem_release_mmap(fence->vma->obj);
        }
@@ -450,6 +471,8 @@ void i915_gem_restore_fences(struct drm_i915_private *dev_priv)
                struct drm_i915_fence_reg *reg = &dev_priv->fence_regs[i];
                struct i915_vma *vma = reg->vma;
 
+               GEM_BUG_ON(vma && vma->fence != reg);
+
                /*
                 * Commit delayed tiling changes if we have an object still
                 * attached to the fence, otherwise just clear the fence.
index 595209a2f1599fe5e5b8f034163348d2116c5e13..2b0083c34914c72121b6fea7089749090d469d6b 100644 (file)
@@ -309,12 +309,10 @@ void __iomem *i915_vma_pin_iomap(struct i915_vma *vma)
 
        __i915_vma_pin(vma);
 
-       err = i915_vma_get_fence(vma);
+       err = i915_vma_pin_fence(vma);
        if (err)
                goto err_unpin;
 
-       i915_vma_pin_fence(vma);
-
        return ptr;
 
 err_unpin:
index 864d84ab916dc0069274cd9de247025f24dc1fe1..13d7ba7ee21ecfc40d165a67dc6539cc15f28dde 100644 (file)
@@ -345,15 +345,13 @@ static inline struct page *i915_vma_first_page(struct i915_vma *vma)
  *
  * True if the vma has a fence, false otherwise.
  */
-static inline bool
-i915_vma_pin_fence(struct i915_vma *vma)
+int i915_vma_pin_fence(struct i915_vma *vma);
+int __must_check i915_vma_put_fence(struct i915_vma *vma);
+
+static inline void __i915_vma_unpin_fence(struct i915_vma *vma)
 {
-       lockdep_assert_held(&vma->obj->base.dev->struct_mutex);
-       if (vma->fence) {
-               vma->fence->pin_count++;
-               return true;
-       } else
-               return false;
+       GEM_BUG_ON(vma->fence->pin_count <= 0);
+       vma->fence->pin_count--;
 }
 
 /**
@@ -368,10 +366,8 @@ static inline void
 i915_vma_unpin_fence(struct i915_vma *vma)
 {
        lockdep_assert_held(&vma->obj->base.dev->struct_mutex);
-       if (vma->fence) {
-               GEM_BUG_ON(vma->fence->pin_count <= 0);
-               vma->fence->pin_count--;
-       }
+       if (vma->fence)
+               __i915_vma_unpin_fence(vma);
 }
 
 #endif
index 15844bf924343fa9a5168e1bd80915d61831f7a1..a1182eeee5afb2117bbcd80840ff79319c3e588f 100644 (file)
@@ -2219,8 +2219,7 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, unsigned int rotation)
                 * something and try to run the system in a "less than optimal"
                 * mode that matches the user configuration.
                 */
-               if (i915_vma_get_fence(vma) == 0)
-                       i915_vma_pin_fence(vma);
+               i915_vma_pin_fence(vma);
        }
 
        i915_vma_get(vma);