diff mbox

[22/50] drm/i915/bdw: Allocate ringbuffer backing objects for default global LRC

Message ID 1399637360-4277-23-git-send-email-oscar.mateo@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

oscar.mateo@intel.com May 9, 2014, 12:08 p.m. UTC
From: Oscar Mateo <oscar.mateo@intel.com>

The default context holds pointers to every engine's default ringbuffer,
and makes its own allocation of the corresponding backing objects. During
ringbuffer creation we might try to allocate them again, but this will
fail silently (same thing with deallocation).

This patch replaces a similar patch by Ben Widawsky in the early series
called: "drm/i915/bdw: Allocate ringbuffer for LR contexts"

Signed-off-by: Oscar Mateo <oscar.mateo@intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h         |  1 +
 drivers/gpu/drm/i915/i915_gem_context.c |  5 +++++
 drivers/gpu/drm/i915/intel_lrc.c        | 19 +++++++++++++++++++
 3 files changed, 25 insertions(+)
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 1cc1042..4d58167 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -597,6 +597,7 @@  struct i915_hw_context {
 	struct intel_engine *last_ring;
 	struct {
 		struct drm_i915_gem_object *obj;
+		struct intel_ringbuffer *ringbuf;
 	} engine[I915_NUM_RINGS];
 	struct i915_ctx_hang_stats hang_stats;
 	struct i915_address_space *vm;
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 16fc780..76314e3 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -185,6 +185,8 @@  void i915_gem_context_free(struct kref *ctx_ref)
 
 	for (i = 0; i < I915_NUM_RINGS; i++) {
 		struct drm_i915_gem_object *ctx_obj = ctx->engine[i].obj;
+		struct intel_ringbuffer *ringbuf = ctx->engine[i].ringbuf;
+
 		if (ctx_obj) {
 			if (i == RCS) {
 				/* We refcount even the aliasing PPGTT to keep the
@@ -197,6 +199,9 @@  void i915_gem_context_free(struct kref *ctx_ref)
 			 * space, in case we're bound in the PPGTT */
 			drm_gem_object_unreference(&ctx_obj->base);
 		}
+
+		if (ringbuf)
+			intel_destroy_ring_buffer(ringbuf);
 	}
 
 	if (ppgtt)
diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
index 875d7b9..64d40e4 100644
--- a/drivers/gpu/drm/i915/intel_lrc.c
+++ b/drivers/gpu/drm/i915/intel_lrc.c
@@ -95,6 +95,25 @@  int gen8_create_lr_context(struct i915_hw_context *ctx,
 		return ret;
 	}
 
+	if (!file_priv) {
+		ring->default_ringbuf.size = 32 * PAGE_SIZE;
+
+		/* TODO: For now we put this in the mappable region so that we can reuse
+		 * the existing ringbuffer code which ioremaps it. When we start
+		 * creating many contexts, this will no longer work and we must switch
+		 * to a kmapish interface.
+		 */
+		ret = intel_allocate_ring_buffer(dev, &ring->default_ringbuf);
+		if (ret) {
+			DRM_DEBUG_DRIVER("Failed to allocate ringbuffer %s: %d\n",
+					ring->name, ret);
+			i915_gem_object_ggtt_unpin(ctx_obj);
+			drm_gem_object_unreference(&ctx_obj->base);
+			return ret;
+		}
+		ctx->engine[ring->id].ringbuf = &ring->default_ringbuf;
+	}
+
 	ctx->engine[ring->id].obj = ctx_obj;
 
 	return 0;