@@ -2526,7 +2526,7 @@ i915_seqno_passed(uint32_t seq1, uint32_t seq2)
return (int32_t)(seq1 - seq2) >= 0;
}
-int __must_check i915_gem_get_seqno(struct drm_device *dev, u32 *seqno);
+int __must_check i915_gem_prepare_next_seqno(struct drm_device *dev);
int __must_check i915_gem_set_seqno(struct drm_device *dev, u32 seqno);
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);
@@ -2314,12 +2314,15 @@ int i915_gem_set_seqno(struct drm_device *dev, u32 seqno)
}
int
-i915_gem_get_seqno(struct drm_device *dev, u32 *seqno)
+i915_gem_prepare_next_seqno(struct drm_device *dev)
{
struct drm_i915_private *dev_priv = dev->dev_private;
/* reserve 0 for non-seqno */
if (dev_priv->next_seqno == 0) {
+ /* Why is the full re-initialisation required? Is it only for
+ * hardware semaphores? If so, could skip it in the case where
+ * semaphores are disabled? */
int ret = i915_gem_init_seqno(dev, 0);
if (ret)
return ret;
@@ -2327,6 +2330,24 @@ i915_gem_get_seqno(struct drm_device *dev, u32 *seqno)
dev_priv->next_seqno = 1;
}
+ return 0;
+}
+
+static int
+i915_gem_get_seqno(struct drm_device *dev, u32 *seqno)
+{
+ struct drm_i915_private *dev_priv = dev->dev_private;
+
+ /* reserve 0 for non-seqno */
+ if (dev_priv->next_seqno == 0) {
+ /* Should never get here! Must always call 'prepare_next' in
+ * advance. This code is called during request submission.
+ * Trying to wrap the seqno and the implicit idle() calls that
+ * the wrap code makes are a bad idea at this point! */
+ DRM_ERROR("Need to wrap seqno at inopportune moment!\n");
+ return -EBUSY;
+ }
+
*seqno = dev_priv->last_seqno = dev_priv->next_seqno++;
return 0;
}
@@ -2369,6 +2390,11 @@ int __i915_add_request(struct intel_engine_cs *ring,
return ret;
}
+ /* Assign an identifier to track this request through the hardware: */
+ ret = i915_gem_get_seqno(ring->dev, &request->seqno);
+ if (ret)
+ return ret;
+
/* Record the position of the start of the request so that
* should we detect the updated seqno part-way through the
* GPU processing the request, we never over-estimate the
@@ -2673,6 +2699,9 @@ void i915_gem_complete_requests_ring(struct intel_engine_cs *ring,
if (req->complete)
continue;
+ if (req->seqno == 0)
+ continue;
+
if (i915_seqno_passed(seqno, req->seqno))
req->complete = true;
}
@@ -803,6 +803,10 @@ static int logical_ring_alloc_request(struct intel_engine_cs *ring,
if (ring->outstanding_lazy_request)
return 0;
+ ret = i915_gem_prepare_next_seqno(ring->dev);
+ if (ret)
+ return ret;
+
request = kzalloc(sizeof(*request), GFP_KERNEL);
if (request == NULL)
return -ENOMEM;
@@ -811,12 +815,6 @@ static int logical_ring_alloc_request(struct intel_engine_cs *ring,
request->ring = ring;
request->uniq = dev_private->request_uniq++;
- ret = i915_gem_get_seqno(ring->dev, &request->seqno);
- if (ret) {
- kfree(request);
- return ret;
- }
-
/* Hold a reference to the context this request belongs to
* (we will need it when the time comes to emit/retire the
* request).
@@ -2034,6 +2034,10 @@ intel_ring_alloc_request(struct intel_engine_cs *ring)
if (ring->outstanding_lazy_request)
return 0;
+ ret = i915_gem_prepare_next_seqno(ring->dev);
+ if (ret)
+ return ret;
+
request = kzalloc(sizeof(*request), GFP_KERNEL);
if (request == NULL)
return -ENOMEM;
@@ -2042,12 +2046,6 @@ intel_ring_alloc_request(struct intel_engine_cs *ring)
request->ring = ring;
request->uniq = dev_private->request_uniq++;
- ret = i915_gem_get_seqno(ring->dev, &request->seqno);
- if (ret) {
- kfree(request);
- return ret;
- }
-
ring->outstanding_lazy_request = request;
return 0;
}