[Intel-gfx] [PATCH 14/15] drm/i915: Factor out and expose i915_steal_fence()
Zhi Wang
zhi.a.wang at intel.com
Sun May 15 17:32:52 UTC 2016
Factor out and expose fence stealing functionality for GVT-g. GVT-g
will use i915_find_fence_reg() to find a free/unpin fence register
and use i915_steal_fence() to steal it.
Signed-off-by: Zhi Wang <zhi.a.wang at intel.com>
---
drivers/gpu/drm/i915/i915_drv.h | 1 +
drivers/gpu/drm/i915/i915_gem_fence.c | 39 +++++++++++++++++++++++++++--------
2 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index ae1149c..96d9abd 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -3376,6 +3376,7 @@ i915_gem_object_ggtt_unpin(struct drm_i915_gem_object *obj)
/* i915_gem_fence.c */
int __must_check i915_gem_object_get_fence(struct drm_i915_gem_object *obj);
int __must_check i915_gem_object_put_fence(struct drm_i915_gem_object *obj);
+int i915_steal_fence(struct drm_i915_fence_reg *reg);
bool i915_gem_object_pin_fence(struct drm_i915_gem_object *obj);
void i915_gem_object_unpin_fence(struct drm_i915_gem_object *obj);
diff --git a/drivers/gpu/drm/i915/i915_gem_fence.c b/drivers/gpu/drm/i915/i915_gem_fence.c
index a2b938e..e790d7b 100644
--- a/drivers/gpu/drm/i915/i915_gem_fence.c
+++ b/drivers/gpu/drm/i915/i915_gem_fence.c
@@ -346,6 +346,33 @@ deadlock:
}
/**
+ * i915_steal_fence - steal a fence from a GEM object
+ * @reg: the fence register to be stolen
+ *
+ * Returns:
+ *
+ * 0 on success, negative error code on failure.
+ */
+int i915_steal_fence(struct drm_i915_fence_reg *reg)
+{
+ int ret;
+
+ if (WARN_ON(reg->pin_count))
+ return -EBUSY;
+
+ if (reg->obj) {
+ struct drm_i915_gem_object *old = reg->obj;
+
+ ret = i915_gem_object_wait_fence(old);
+ if (ret)
+ return ret;
+
+ i915_gem_object_fence_lost(old);
+ }
+ return 0;
+}
+
+/**
* i915_gem_object_get_fence - set up fencing for an object
* @obj: object to map through a fence reg
*
@@ -397,15 +424,9 @@ i915_gem_object_get_fence(struct drm_i915_gem_object *obj)
if (IS_ERR(reg))
return PTR_ERR(reg);
- if (reg->obj) {
- struct drm_i915_gem_object *old = reg->obj;
-
- ret = i915_gem_object_wait_fence(old);
- if (ret)
- return ret;
-
- i915_gem_object_fence_lost(old);
- }
+ ret = i915_steal_fence(reg);
+ if (ret)
+ return ret;
} else
return 0;
--
1.9.1
More information about the Intel-gfx
mailing list