@@ -1789,9 +1789,7 @@ int i915_driver_open(struct drm_device *dev, struct drm_file *file)
spin_lock_init(&file_priv->mm.lock);
INIT_LIST_HEAD(&file_priv->mm.request_list);
- idr_init(&file_priv->context_idr);
-
- return 0;
+ return i915_gem_context_open(dev, file);
}
/**
@@ -1891,6 +1891,7 @@ i915_gem_ggtt_pin(struct drm_i915_gem_object *obj,
void i915_gem_context_init(struct drm_device *dev);
void i915_gem_context_fini(struct drm_device *dev);
int i915_gem_context_enable(struct drm_i915_private *dev_priv);
+int i915_gem_context_open(struct drm_device *dev, struct drm_file *file);
void i915_gem_context_close(struct drm_device *dev, struct drm_file *file);
int i915_switch_context(struct intel_ring_buffer *ring,
struct drm_file *file, int to_id);
@@ -351,9 +351,31 @@ i915_gem_context_get_hang_stats(struct intel_ring_buffer *ring,
return &to->hang_stats;
}
+int i915_gem_context_open(struct drm_device *dev, struct drm_file *file)
+{
+ struct drm_i915_file_private *file_priv = file->driver_priv;
+ struct drm_i915_private *dev_priv = dev->dev_private;
+
+ mutex_lock(&dev->struct_mutex);
+ if (dev_priv->hw_contexts_disabled) {
+ mutex_unlock(&dev->struct_mutex);
+ return 0;
+ }
+
+ mutex_unlock(&dev->struct_mutex);
+
+ idr_init(&file_priv->context_idr);
+
+ return 0;
+}
+
void i915_gem_context_close(struct drm_device *dev, struct drm_file *file)
{
struct drm_i915_file_private *file_priv = file->driver_priv;
+ struct drm_i915_private *dev_priv = dev->dev_private;
+
+ if (dev_priv->hw_contexts_disabled)
+ return;
mutex_lock(&dev->struct_mutex);
idr_for_each(&file_priv->context_idr, context_idr_cleanup, NULL);
We'll be doing a bit more stuff with each file, so having our own open function should make things clean. This also allows us to easily add conditionals for stuff we don't want to do when we don't have HW contexts. Signed-off-by: Ben Widawsky <ben@bwidawsk.net> --- drivers/gpu/drm/i915/i915_dma.c | 4 +--- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_gem_context.c | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-)