[Intel-gfx] [PATCH] Correctly implement batchbuffer dumping

Ben Gamari bgamari at gmail.com
Thu Jan 15 04:11:49 CET 2009


We need to map the batch buffer before we attempt to dump it. Also,
break dumping out into a separate function to make error handling a
bit cleaner.
---
 drivers/gpu/drm/i915/i915_gem_debugfs.c |   63 ++++++++++++++++++++++++------
 1 files changed, 50 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_debugfs.c b/drivers/gpu/drm/i915/i915_gem_debugfs.c
index e8ca71b..1386605 100644
--- a/drivers/gpu/drm/i915/i915_gem_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_gem_debugfs.c
@@ -9,6 +9,10 @@
 
 #if defined(CONFIG_DEBUG_FS)
 
+static void dump_batch_buffer(struct drm_device *dev, struct seq_file *m, 
+	uint32_t batch_offset, uint32_t mask, uint32_t acthd);
+
+
 static int i915_gem_active_info(struct seq_file *m, void *data)
 {
 	struct drm_minor *minor = (struct drm_minor *) m->private;
@@ -683,20 +687,14 @@ static void dump_cmds (struct seq_file	*m,
 
 			/* check for MI_BATCH_BUFFER_START */
 			if ( (data & batch_start_mask) == batch_start_cmd) {
-				uint32_t batch = ptr[1] & ~3;
+				uint32_t batch_offset = ptr[1] & ~3;
 				uint32_t addr_type = (ptr[0] & (1 << 7));
-				struct drm_i915_gem_object *obj_priv = find_batch_buffer(dev, batch);
-
-				seq_printf(m, "\t%08x: %08x\n", (ring + 4) & mask, batch);
-				seq_printf(m, "Batch buffer at 0x%08x (%s)\n", batch, addr_type ? "GfxMem" : "PhysMem");
-				if (obj_priv) {
-					unsigned char *virt = obj_priv->obj;
-					/* TODO: Implement batch buffer dumping */
-					seq_printf(m, "{\n");
-					dump_cmds(m, dev, (unsigned char*)batch, 0, 4096, mask, acthd);
-					ring = (ring + (count -1)*4) & mask;
-					seq_printf(m, "}\n");
-				}
+
+				seq_printf(m, "\t%08x: %08x\n", (ring + 4) & mask, batch_offset);
+				seq_printf(m, "Batch buffer at 0x%08x (%s)\n", batch_offset, addr_type ? "GfxMem" : "PhysMem");
+				if (addr_type)
+					dump_batch_buffer(dev, m, batch_offset, mask, acthd);
+				ring = (ring + (count - 1) * 4) & mask;
 			}
 			cmd = (cmd + count * 4) & mask;
 		} else
@@ -706,6 +704,45 @@ static void dump_cmds (struct seq_file	*m,
 	}
 }
 
+static void dump_batch_buffer(struct drm_device *dev, struct seq_file *m, uint32_t batch_offset,
+	uint32_t mask, uint32_t acthd)
+{
+	drm_i915_private_t	*dev_priv = dev->dev_private;
+	struct drm_i915_gem_object *obj_priv;
+	uint32_t page_offset = (batch_offset & ~(PAGE_SIZE-1));
+	unsigned char *page;
+	unsigned char *virt;
+	int ret;
+	
+	obj_priv = find_batch_buffer(dev, batch_offset);
+	if (obj_priv == NULL) {
+		DRM_INFO("%s: Couldn't find batch buffer %08x\n", __func__, batch_offset);
+		return;
+	}
+
+	ret = i915_gem_object_pin(obj_priv->obj, 0);
+	if (!ret) {
+		DRM_INFO("%s: Failed to pin batch buffer %08x\n", __func__, batch_offset);
+		goto err_pin;
+	}
+
+	page = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping, page_offset);
+	if (!page) {
+		DRM_INFO("%s: Failed to map batch buffer %08x\n", __func__, batch_offset);
+		goto err_map;
+	}
+
+	virt = (unsigned char*)(page + batch_offset - page_offset);
+	seq_printf(m, "{\n");
+	dump_cmds(m, dev, virt, 0, PAGE_SIZE, mask, acthd);
+	seq_printf(m, "}\n");
+
+err_map:
+	io_mapping_unmap_atomic(page);
+err_pin:
+	i915_gem_object_unpin(obj_priv->obj);
+}
+
 static int valid_chain(struct drm_device *dev, unsigned int ring, unsigned int end)
 {
 	drm_i915_private_t	*dev_priv = dev->dev_private;
-- 
1.6.0.6




More information about the Intel-gfx mailing list