@@ -1479,6 +1479,14 @@ static void i915_driver_release(struct drm_device *dev)
kfree(dev_priv);
}
+void i915_release(struct kref *kref)
+{
+ struct drm_i915_private *i915 =
+ container_of(kref, struct drm_i915_private, drm.ref);
+
+ i915_driver_release(&i915->drm);
+}
+
static int i915_driver_open(struct drm_device *dev, struct drm_file *file)
{
struct drm_i915_private *i915 = to_i915(dev);
@@ -3547,4 +3547,16 @@ static inline int intel_hws_csb_write_index(struct drm_i915_private *i915)
return I915_HWS_CSB_WRITE_INDEX;
}
+static inline struct drm_i915_private *i915_get(struct drm_i915_private *i915)
+{
+ kref_get(&i915->drm.ref);
+ return i915;
+}
+
+void i915_release(struct kref *kref);
+static inline void i915_put(struct drm_i915_private *i915)
+{
+ kref_put(&i915->drm.ref, i915_release);
+}
+
#endif
@@ -74,6 +74,7 @@ static signed long i915_fence_wait(struct dma_fence *fence,
static void i915_fence_release(struct dma_fence *fence)
{
struct i915_request *rq = to_request(fence);
+ struct drm_i915_private *i915 = rq->i915;
/*
* The request is put onto a RCU freelist (i.e. the address
@@ -84,7 +85,8 @@ static void i915_fence_release(struct dma_fence *fence)
*/
i915_sw_fence_fini(&rq->submit);
- kmem_cache_free(rq->i915->requests, rq);
+ kmem_cache_free(i915->requests, rq);
+ i915_put(i915);
}
const struct dma_fence_ops i915_fence_ops = {
@@ -717,7 +719,7 @@ i915_request_alloc(struct intel_engine_cs *engine, struct i915_gem_context *ctx)
}
INIT_LIST_HEAD(&rq->active_list);
- rq->i915 = i915;
+ rq->i915 = i915_get(i915);
rq->engine = engine;
rq->gem_context = ctx;
rq->hw_context = ce;
@@ -795,6 +797,7 @@ i915_request_alloc(struct intel_engine_cs *engine, struct i915_gem_context *ctx)
GEM_BUG_ON(!list_empty(&rq->sched.waiters_list));
kmem_cache_free(i915->requests, rq);
+ i915_put(i915);
err_unreserve:
unreserve_gt(i915);
err_unpin: