diff mbox

[1/6] drm/i915: Faults for scratch PTEs

Message ID 1372458217-2053-2-git-send-email-ben@bwidawsk.net (mailing list archive)
State New, archived
Headers show

Commit Message

Ben Widawsky June 28, 2013, 10:23 p.m. UTC
Using a new "debug_flags" we'll be able to configure some options which
make it easier for user space to quickly identify when there is a bug in
their code.

There is no way to yet turn it on.

Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
---
 drivers/gpu/drm/i915/i915_debugfs.c | 1 +
 drivers/gpu/drm/i915/i915_drv.c     | 3 +++
 drivers/gpu/drm/i915/i915_drv.h     | 4 ++++
 drivers/gpu/drm/i915/i915_gem_gtt.c | 9 +++++++++
 4 files changed, 17 insertions(+)
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index b3a2dbe..4d9d8a1 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -812,6 +812,7 @@  static int i915_error_state(struct i915_error_state_file_priv *error_priv,
 	err_printf(m, "FORCEWAKE: 0x%08x\n", error->forcewake);
 	err_printf(m, "DERRMR: 0x%08x\n", error->derrmr);
 	err_printf(m, "CCID: 0x%08x\n", error->ccid);
+	err_printf(m, "debug_flags: 0x%llx\n", dev_priv->debug_flags);
 
 	for (i = 0; i < dev_priv->num_fence_regs; i++)
 		err_printf(m, "  fence[%d] = %08llx\n", i, error->fence[i]);
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 062cbda..5718f45 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -940,6 +940,9 @@  int i915_reset(struct drm_device *dev)
 		return ret;
 	}
 
+	/* Assume debug flags may have been the cause of the problem */
+	dev_priv->debug_flags = 0;
+
 	/* Ok, now get things going again... */
 
 	/*
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 56bd82b..7a98f7e 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1176,6 +1176,10 @@  typedef struct drm_i915_private {
 	/* Old dri1 support infrastructure, beware the dragons ya fools entering
 	 * here! */
 	struct i915_dri1_state dri1;
+
+#define I915_DEBUG_NONE 0
+#define I915_SCRATCH_FAULTS (1<<0)
+	u64 debug_flags;
 } drm_i915_private_t;
 
 /* Iterate over initialised rings */
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 5101ab6..982c791 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -41,6 +41,8 @@ 
 #define GEN6_PTE_CACHE_LLC		(2 << 1)
 #define GEN6_PTE_CACHE_LLC_MLC		(3 << 1)
 #define GEN6_PTE_ADDR_ENCODE(addr)	GEN6_GTT_ADDR_ENCODE(addr)
+/* Use a pattern to make debug a bit easier */
+#define GEN6_PTE_FAULT			0xbaddc0de
 
 static gen6_gtt_pte_t gen6_pte_encode(struct drm_device *dev,
 				      dma_addr_t addr,
@@ -185,6 +187,7 @@  static void gen6_ppgtt_clear_range(struct i915_hw_ppgtt *ppgtt,
 				   unsigned first_entry,
 				   unsigned num_entries)
 {
+	struct drm_i915_private *dev_priv = ppgtt->dev->dev_private;
 	gen6_gtt_pte_t *pt_vaddr, scratch_pte;
 	unsigned act_pt = first_entry / I915_PPGTT_PT_ENTRIES;
 	unsigned first_pte = first_entry % I915_PPGTT_PT_ENTRIES;
@@ -194,6 +197,9 @@  static void gen6_ppgtt_clear_range(struct i915_hw_ppgtt *ppgtt,
 					ppgtt->scratch_page_dma_addr,
 					I915_CACHE_LLC);
 
+	if (unlikely(dev_priv->debug_flags & I915_SCRATCH_FAULTS))
+		scratch_pte = GEN6_PTE_FAULT;
+
 	while (num_entries) {
 		last_pte = first_pte + num_entries;
 		if (last_pte > I915_PPGTT_PT_ENTRIES)
@@ -521,6 +527,8 @@  static void gen6_ggtt_clear_range(struct drm_device *dev,
 	scratch_pte = dev_priv->gtt.pte_encode(dev,
 					       dev_priv->gtt.scratch_page_dma,
 					       I915_CACHE_LLC);
+	if (unlikely(dev_priv->debug_flags & I915_SCRATCH_FAULTS))
+		scratch_pte = GEN6_PTE_FAULT;
 	for (i = 0; i < num_entries; i++)
 		iowrite32(scratch_pte, &gtt_base[i]);
 	readl(gtt_base);
@@ -623,6 +631,7 @@  void i915_gem_setup_global_gtt(struct drm_device *dev,
 	struct drm_i915_gem_object *obj;
 	unsigned long hole_start, hole_end;
 
+	BUILD_BUG_ON(GEN6_PTE_FAULT & GEN6_PTE_VALID);
 	BUG_ON(mappable_end > end);
 
 	/* Subtract the guard page ... */