All of lore.kernel.org
 help / color / mirror / Atom feed
* Radeon debugging patches for 3.14
@ 2013-12-12  8:42 Christian König
  2013-12-12  8:42 ` [PATCH 1/6] drm/radeon: improve ring debugfs a bit Christian König
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Christian König @ 2013-12-12  8:42 UTC (permalink / raw)
  To: dri-devel

The following patchset improves debugging functionality for the radeon driver.

Apart from a few other minor improvements it gives debugging access to even
the invisible parts of VRAM. And in general now allows to make dumps of all the
memory the GPU can access.

Please review,
Christian.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/6] drm/radeon: improve ring debugfs a bit
  2013-12-12  8:42 Radeon debugging patches for 3.14 Christian König
@ 2013-12-12  8:42 ` Christian König
  2013-12-12  8:42 ` [PATCH 2/6] drm/radeon: report the real offset in radeon_sa_bo_dump_debug_info Christian König
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Christian König @ 2013-12-12  8:42 UTC (permalink / raw)
  To: dri-devel

From: Christian König <christian.koenig@amd.com>

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/radeon/radeon_ring.c | 56 ++++++++++++++++++++++++------------
 1 file changed, 38 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_ring.c b/drivers/gpu/drm/radeon/radeon_ring.c
index 9214403..f1cec22 100644
--- a/drivers/gpu/drm/radeon/radeon_ring.c
+++ b/drivers/gpu/drm/radeon/radeon_ring.c
@@ -790,34 +790,54 @@ static int radeon_debugfs_ring_info(struct seq_file *m, void *data)
 	struct radeon_device *rdev = dev->dev_private;
 	int ridx = *(int*)node->info_ent->data;
 	struct radeon_ring *ring = &rdev->ring[ridx];
+
+	uint32_t rptr, wptr, rptr_next;
 	unsigned count, i, j;
-	u32 tmp;
 
 	radeon_ring_free_size(rdev, ring);
 	count = (ring->ring_size / 4) - ring->ring_free_dw;
-	tmp = radeon_ring_get_wptr(rdev, ring);
-	seq_printf(m, "wptr(0x%04x): 0x%08x [%5d]\n", ring->wptr_reg, tmp, tmp);
-	tmp = radeon_ring_get_rptr(rdev, ring);
-	seq_printf(m, "rptr(0x%04x): 0x%08x [%5d]\n", ring->rptr_reg, tmp, tmp);
+
+	wptr = radeon_ring_get_wptr(rdev, ring);
+	seq_printf(m, "wptr(0x%04x): 0x%08x [%5d]\n",
+		   ring->wptr_reg, wptr, wptr);
+
+	rptr = radeon_ring_get_rptr(rdev, ring);
+	seq_printf(m, "rptr(0x%04x): 0x%08x [%5d]\n",
+		   ring->rptr_reg, rptr, rptr);
+
 	if (ring->rptr_save_reg) {
-		seq_printf(m, "rptr next(0x%04x): 0x%08x\n", ring->rptr_save_reg,
-			   RREG32(ring->rptr_save_reg));
-	}
-	seq_printf(m, "driver's copy of the wptr: 0x%08x [%5d]\n", ring->wptr, ring->wptr);
-	seq_printf(m, "driver's copy of the rptr: 0x%08x [%5d]\n", ring->rptr, ring->rptr);
-	seq_printf(m, "last semaphore signal addr : 0x%016llx\n", ring->last_semaphore_signal_addr);
-	seq_printf(m, "last semaphore wait addr   : 0x%016llx\n", ring->last_semaphore_wait_addr);
+		rptr_next = RREG32(ring->rptr_save_reg);
+		seq_printf(m, "rptr next(0x%04x): 0x%08x [%5d]\n",
+			   ring->rptr_save_reg, rptr_next, rptr_next);
+	} else
+		rptr_next = ~0;
+
+	seq_printf(m, "driver's copy of the wptr: 0x%08x [%5d]\n",
+		   ring->wptr, ring->wptr);
+	seq_printf(m, "driver's copy of the rptr: 0x%08x [%5d]\n",
+		   ring->rptr, ring->rptr);
+	seq_printf(m, "last semaphore signal addr : 0x%016llx\n",
+		   ring->last_semaphore_signal_addr);
+	seq_printf(m, "last semaphore wait addr   : 0x%016llx\n",
+		   ring->last_semaphore_wait_addr);
 	seq_printf(m, "%u free dwords in ring\n", ring->ring_free_dw);
 	seq_printf(m, "%u dwords in ring\n", count);
+
+	if (!ring->ready)
+		return 0;
+
 	/* print 8 dw before current rptr as often it's the last executed
 	 * packet that is the root issue
 	 */
-	i = (ring->rptr + ring->ptr_mask + 1 - 32) & ring->ptr_mask;
-	if (ring->ready) {
-		for (j = 0; j <= (count + 32); j++) {
-			seq_printf(m, "r[%5d]=0x%08x\n", i, ring->ring[i]);
-			i = (i + 1) & ring->ptr_mask;
-		}
+	i = (rptr + ring->ptr_mask + 1 - 32) & ring->ptr_mask;
+	for (j = 0; j <= (count + 32); j++) {
+		seq_printf(m, "r[%5d]=0x%08x", i, ring->ring[i]);
+		if (rptr == i)
+			seq_puts(m, " *");
+		if (rptr_next == i)
+			seq_puts(m, " #");
+		seq_puts(m, "\n");
+		i = (i + 1) & ring->ptr_mask;
 	}
 	return 0;
 }
-- 
1.8.1.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/6] drm/radeon: report the real offset in radeon_sa_bo_dump_debug_info
  2013-12-12  8:42 Radeon debugging patches for 3.14 Christian König
  2013-12-12  8:42 ` [PATCH 1/6] drm/radeon: improve ring debugfs a bit Christian König
@ 2013-12-12  8:42 ` Christian König
  2013-12-12  8:42 ` [PATCH 3/6] drm/radeon: update fence values in before reporting them Christian König
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Christian König @ 2013-12-12  8:42 UTC (permalink / raw)
  To: dri-devel

From: Christian König <christian.koenig@amd.com>

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/radeon/radeon_sa.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_sa.c b/drivers/gpu/drm/radeon/radeon_sa.c
index f0bac68..c062580 100644
--- a/drivers/gpu/drm/radeon/radeon_sa.c
+++ b/drivers/gpu/drm/radeon/radeon_sa.c
@@ -402,13 +402,15 @@ void radeon_sa_bo_dump_debug_info(struct radeon_sa_manager *sa_manager,
 
 	spin_lock(&sa_manager->wq.lock);
 	list_for_each_entry(i, &sa_manager->olist, olist) {
+		uint64_t soffset = i->soffset + sa_manager->gpu_addr;
+		uint64_t eoffset = i->eoffset + sa_manager->gpu_addr;
 		if (&i->olist == sa_manager->hole) {
 			seq_printf(m, ">");
 		} else {
 			seq_printf(m, " ");
 		}
-		seq_printf(m, "[0x%08x 0x%08x] size %8d",
-			   i->soffset, i->eoffset, i->eoffset - i->soffset);
+		seq_printf(m, "[0x%010llx 0x%010llx] size %8lld",
+			   soffset, eoffset, eoffset - soffset);
 		if (i->fence) {
 			seq_printf(m, " protected by 0x%016llx on ring %d",
 				   i->fence->seq, i->fence->ring);
-- 
1.8.1.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/6] drm/radeon: update fence values in before reporting them
  2013-12-12  8:42 Radeon debugging patches for 3.14 Christian König
  2013-12-12  8:42 ` [PATCH 1/6] drm/radeon: improve ring debugfs a bit Christian König
  2013-12-12  8:42 ` [PATCH 2/6] drm/radeon: report the real offset in radeon_sa_bo_dump_debug_info Christian König
@ 2013-12-12  8:42 ` Christian König
  2013-12-12  8:42 ` [PATCH 4/6] drm/radeon: cleanup radeon_ttm debugfs handling Christian König
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Christian König @ 2013-12-12  8:42 UTC (permalink / raw)
  To: dri-devel

From: Christian König <christian.koenig@amd.com>

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/radeon/radeon_fence.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
index d3a86e4..866744e 100644
--- a/drivers/gpu/drm/radeon/radeon_fence.c
+++ b/drivers/gpu/drm/radeon/radeon_fence.c
@@ -841,6 +841,8 @@ static int radeon_debugfs_fence_info(struct seq_file *m, void *data)
 		if (!rdev->fence_drv[i].initialized)
 			continue;
 
+		radeon_fence_process(rdev, i);
+
 		seq_printf(m, "--- ring %d ---\n", i);
 		seq_printf(m, "Last signaled fence 0x%016llx\n",
 			   (unsigned long long)atomic64_read(&rdev->fence_drv[i].last_seq));
-- 
1.8.1.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/6] drm/radeon: cleanup radeon_ttm debugfs handling
  2013-12-12  8:42 Radeon debugging patches for 3.14 Christian König
                   ` (2 preceding siblings ...)
  2013-12-12  8:42 ` [PATCH 3/6] drm/radeon: update fence values in before reporting them Christian König
@ 2013-12-12  8:42 ` Christian König
  2013-12-12  8:42 ` [PATCH 5/6] drm/radeon: add VRAM debugfs access Christian König
  2013-12-12  8:42 ` [PATCH 6/6] drm/radeon: add GART " Christian König
  5 siblings, 0 replies; 10+ messages in thread
From: Christian König @ 2013-12-12  8:42 UTC (permalink / raw)
  To: dri-devel

From: Christian König <christian.koenig@amd.com>

Otherwise we not necessary export the right information.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/radeon/radeon_ttm.c | 59 +++++++++++++++----------------------
 1 file changed, 23 insertions(+), 36 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 71245d6..a2d6c4f 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -832,16 +832,15 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
 	return 0;
 }
 
-
-#define RADEON_DEBUGFS_MEM_TYPES 2
-
 #if defined(CONFIG_DEBUG_FS)
+
 static int radeon_mm_dump_table(struct seq_file *m, void *data)
 {
 	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_mm *mm = (struct drm_mm *)node->info_ent->data;
+	unsigned ttm_pl = *(int *)node->info_ent->data;
 	struct drm_device *dev = node->minor->dev;
 	struct radeon_device *rdev = dev->dev_private;
+	struct drm_mm *mm = (struct drm_mm *)rdev->mman.bdev.man[ttm_pl].priv;
 	int ret;
 	struct ttm_bo_global *glob = rdev->mman.bdev.glob;
 
@@ -850,46 +849,34 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
 	spin_unlock(&glob->lru_lock);
 	return ret;
 }
+
+static int ttm_pl_vram = TTM_PL_VRAM;
+static int ttm_pl_tt = TTM_PL_TT;
+
+static struct drm_info_list radeon_ttm_debugfs_list[] = {
+	{"radeon_vram_mm", radeon_mm_dump_table, 0, &ttm_pl_vram},
+	{"radeon_gtt_mm", radeon_mm_dump_table, 0, &ttm_pl_tt},
+	{"ttm_page_pool", ttm_page_alloc_debugfs, 0, NULL},
+#ifdef CONFIG_SWIOTLB
+	{"ttm_dma_page_pool", ttm_dma_page_alloc_debugfs, 0, NULL}
+#endif
+};
+
 #endif
 
 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
 {
 #if defined(CONFIG_DEBUG_FS)
-	static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
-	static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
-	unsigned i;
+	unsigned count = ARRAY_SIZE(radeon_ttm_debugfs_list);
 
-	for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
-		if (i == 0)
-			sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
-		else
-			sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
-		radeon_mem_types_list[i].name = radeon_mem_types_names[i];
-		radeon_mem_types_list[i].show = &radeon_mm_dump_table;
-		radeon_mem_types_list[i].driver_features = 0;
-		if (i == 0)
-			radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
-		else
-			radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
-
-	}
-	/* Add ttm page pool to debugfs */
-	sprintf(radeon_mem_types_names[i], "ttm_page_pool");
-	radeon_mem_types_list[i].name = radeon_mem_types_names[i];
-	radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
-	radeon_mem_types_list[i].driver_features = 0;
-	radeon_mem_types_list[i++].data = NULL;
 #ifdef CONFIG_SWIOTLB
-	if (swiotlb_nr_tbl()) {
-		sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
-		radeon_mem_types_list[i].name = radeon_mem_types_names[i];
-		radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
-		radeon_mem_types_list[i].driver_features = 0;
-		radeon_mem_types_list[i++].data = NULL;
-	}
+	if (!swiotlb_nr_tbl())
+		--count;
 #endif
-	return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
 
-#endif
+	return radeon_debugfs_add_files(rdev, radeon_ttm_debugfs_list, count);
+#else
+
 	return 0;
+#endif
 }
-- 
1.8.1.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/6] drm/radeon: add VRAM debugfs access
  2013-12-12  8:42 Radeon debugging patches for 3.14 Christian König
                   ` (3 preceding siblings ...)
  2013-12-12  8:42 ` [PATCH 4/6] drm/radeon: cleanup radeon_ttm debugfs handling Christian König
@ 2013-12-12  8:42 ` Christian König
  2013-12-12 13:31   ` Alex Deucher
  2013-12-12  8:42 ` [PATCH 6/6] drm/radeon: add GART " Christian König
  5 siblings, 1 reply; 10+ messages in thread
From: Christian König @ 2013-12-12  8:42 UTC (permalink / raw)
  To: dri-devel

From: Christian König <christian.koenig@amd.com>

Not very fast, but makes it possible to access even the
normally inaccessible parts of VRAM from userspace.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/radeon/radeon.h     |  4 +++
 drivers/gpu/drm/radeon/radeon_ttm.c | 72 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index b1f990d..49f210c1 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -413,6 +413,10 @@ struct radeon_mman {
 	struct ttm_bo_device		bdev;
 	bool				mem_global_referenced;
 	bool				initialized;
+
+#if defined(CONFIG_DEBUG_FS)
+	struct dentry			*vram;
+#endif
 };
 
 /* bo virtual address in a specific vm */
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index a2d6c4f..f5e8eed 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -39,12 +39,14 @@
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/swiotlb.h>
+#include <linux/debugfs.h>
 #include "radeon_reg.h"
 #include "radeon.h"
 
 #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
 
 static int radeon_ttm_debugfs_init(struct radeon_device *rdev);
+static void radeon_ttm_debugfs_fini(struct radeon_device *rdev);
 
 static struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev)
 {
@@ -753,6 +755,7 @@ void radeon_ttm_fini(struct radeon_device *rdev)
 
 	if (!rdev->mman.initialized)
 		return;
+	radeon_ttm_debugfs_fini(rdev);
 	if (rdev->stollen_vga_memory) {
 		r = radeon_bo_reserve(rdev->stollen_vga_memory, false);
 		if (r == 0) {
@@ -862,12 +865,70 @@ static struct drm_info_list radeon_ttm_debugfs_list[] = {
 #endif
 };
 
+static int radeon_ttm_mem_open(struct inode *inode, struct file *filep)
+{
+	filep->private_data = inode->i_private;
+	return 0;
+}
+
+static ssize_t radeon_ttm_vram_read(struct file *f, char __user *buf,
+				    size_t size, loff_t *pos)
+{
+	struct radeon_device *rdev = f->private_data;
+	ssize_t result = 0;
+	int r;
+
+	if (size & 0x3 || *pos & 0x3)
+		return -EINVAL;
+
+	while (size) {
+		unsigned long flags;
+		uint32_t value;
+
+		if (*pos >= rdev->mc.mc_vram_size || *pos >= 0x7FFFFFFF)
+			return result;
+
+		spin_lock_irqsave(&rdev->mmio_idx_lock, flags);
+		WREG32(RADEON_MM_INDEX, ((uint32_t)*pos) | 0x80000000);
+		value = RREG32(RADEON_MM_DATA);
+		spin_unlock_irqrestore(&rdev->mmio_idx_lock, flags);
+
+		r = put_user(value, (uint32_t *)buf);
+		if (r)
+			return r;
+
+		result += 4;
+		buf += 4;
+		*pos += 4;
+		size -= 4;
+	}
+
+	return result;
+}
+
+static const struct file_operations radeon_ttm_vram_fops = {
+	.owner = THIS_MODULE,
+	.open = radeon_ttm_mem_open,
+	.read = radeon_ttm_vram_read,
+};
+
 #endif
 
 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
 {
 #if defined(CONFIG_DEBUG_FS)
-	unsigned count = ARRAY_SIZE(radeon_ttm_debugfs_list);
+	unsigned count;
+
+	struct drm_minor *minor = rdev->ddev->primary;
+	struct dentry *ent, *root = minor->debugfs_root;
+
+	ent = debugfs_create_file("radeon_vram", S_IFREG | S_IRUGO, root,
+				  rdev, &radeon_ttm_vram_fops);
+	if (IS_ERR(ent))
+		return PTR_ERR(ent);
+	rdev->mman.vram = ent;
+
+	count = ARRAY_SIZE(radeon_ttm_debugfs_list);
 
 #ifdef CONFIG_SWIOTLB
 	if (!swiotlb_nr_tbl())
@@ -880,3 +941,12 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
 	return 0;
 #endif
 }
+
+static void radeon_ttm_debugfs_fini(struct radeon_device *rdev)
+{
+#if defined(CONFIG_DEBUG_FS)
+
+	debugfs_remove(rdev->mman.vram);
+	rdev->mman.vram = NULL;
+#endif
+}
-- 
1.8.1.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/6] drm/radeon: add GART debugfs access
  2013-12-12  8:42 Radeon debugging patches for 3.14 Christian König
                   ` (4 preceding siblings ...)
  2013-12-12  8:42 ` [PATCH 5/6] drm/radeon: add VRAM debugfs access Christian König
@ 2013-12-12  8:42 ` Christian König
  5 siblings, 0 replies; 10+ messages in thread
From: Christian König @ 2013-12-12  8:42 UTC (permalink / raw)
  To: dri-devel

From: Christian König <christian.koenig@amd.com>

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/radeon/radeon.h     |  1 +
 drivers/gpu/drm/radeon/radeon_ttm.c | 54 +++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 49f210c1..572476b 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -416,6 +416,7 @@ struct radeon_mman {
 
 #if defined(CONFIG_DEBUG_FS)
 	struct dentry			*vram;
+	struct dentry			*gtt;
 #endif
 };
 
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index f5e8eed..277faeb 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -912,6 +912,51 @@ static const struct file_operations radeon_ttm_vram_fops = {
 	.read = radeon_ttm_vram_read,
 };
 
+static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf,
+				   size_t size, loff_t *pos)
+{
+	struct radeon_device *rdev = f->private_data;
+	ssize_t result = 0;
+	int r;
+
+	while (size) {
+		loff_t p = *pos / PAGE_SIZE;
+		unsigned off = *pos & ~PAGE_MASK;
+		ssize_t cur_size = min(size, PAGE_SIZE - off);
+		struct page *page;
+		void *ptr;
+
+		if (p >= rdev->gart.num_cpu_pages)
+			return result;
+
+		page = rdev->gart.pages[p];
+		if (page) {
+			ptr = kmap(page);
+			ptr += off;
+
+			r = copy_to_user(buf, ptr, cur_size);
+			kunmap(rdev->gart.pages[p]);
+		} else
+			r = clear_user(buf, cur_size);
+
+		if (r)
+			return -EFAULT;
+
+		result += cur_size;
+		buf += cur_size;
+		*pos += cur_size;
+		size -= cur_size;
+	}
+
+	return result;
+}
+
+static const struct file_operations radeon_ttm_gtt_fops = {
+	.owner = THIS_MODULE,
+	.open = radeon_ttm_mem_open,
+	.read = radeon_ttm_gtt_read,
+};
+
 #endif
 
 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
@@ -928,6 +973,12 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
 		return PTR_ERR(ent);
 	rdev->mman.vram = ent;
 
+	ent = debugfs_create_file("radeon_gtt", S_IFREG | S_IRUGO, root,
+				  rdev, &radeon_ttm_gtt_fops);
+	if (IS_ERR(ent))
+		return PTR_ERR(ent);
+	rdev->mman.gtt = ent;
+
 	count = ARRAY_SIZE(radeon_ttm_debugfs_list);
 
 #ifdef CONFIG_SWIOTLB
@@ -948,5 +999,8 @@ static void radeon_ttm_debugfs_fini(struct radeon_device *rdev)
 
 	debugfs_remove(rdev->mman.vram);
 	rdev->mman.vram = NULL;
+
+	debugfs_remove(rdev->mman.gtt);
+	rdev->mman.gtt = NULL;
 #endif
 }
-- 
1.8.1.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 5/6] drm/radeon: add VRAM debugfs access
  2013-12-12  8:42 ` [PATCH 5/6] drm/radeon: add VRAM debugfs access Christian König
@ 2013-12-12 13:31   ` Alex Deucher
  2013-12-12 13:35     ` Christian König
  0 siblings, 1 reply; 10+ messages in thread
From: Alex Deucher @ 2013-12-12 13:31 UTC (permalink / raw)
  To: Christian König; +Cc: Maling list - DRI developers

On Thu, Dec 12, 2013 at 3:42 AM, Christian König
<deathsimple@vodafone.de> wrote:
> From: Christian König <christian.koenig@amd.com>
>
> Not very fast, but makes it possible to access even the
> normally inaccessible parts of VRAM from userspace.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  drivers/gpu/drm/radeon/radeon.h     |  4 +++
>  drivers/gpu/drm/radeon/radeon_ttm.c | 72 ++++++++++++++++++++++++++++++++++++-
>  2 files changed, 75 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
> index b1f990d..49f210c1 100644
> --- a/drivers/gpu/drm/radeon/radeon.h
> +++ b/drivers/gpu/drm/radeon/radeon.h
> @@ -413,6 +413,10 @@ struct radeon_mman {
>         struct ttm_bo_device            bdev;
>         bool                            mem_global_referenced;
>         bool                            initialized;
> +
> +#if defined(CONFIG_DEBUG_FS)
> +       struct dentry                   *vram;
> +#endif
>  };
>
>  /* bo virtual address in a specific vm */
> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
> index a2d6c4f..f5e8eed 100644
> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
> @@ -39,12 +39,14 @@
>  #include <linux/seq_file.h>
>  #include <linux/slab.h>
>  #include <linux/swiotlb.h>
> +#include <linux/debugfs.h>
>  #include "radeon_reg.h"
>  #include "radeon.h"
>
>  #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
>
>  static int radeon_ttm_debugfs_init(struct radeon_device *rdev);
> +static void radeon_ttm_debugfs_fini(struct radeon_device *rdev);
>
>  static struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev)
>  {
> @@ -753,6 +755,7 @@ void radeon_ttm_fini(struct radeon_device *rdev)
>
>         if (!rdev->mman.initialized)
>                 return;
> +       radeon_ttm_debugfs_fini(rdev);
>         if (rdev->stollen_vga_memory) {
>                 r = radeon_bo_reserve(rdev->stollen_vga_memory, false);
>                 if (r == 0) {
> @@ -862,12 +865,70 @@ static struct drm_info_list radeon_ttm_debugfs_list[] = {
>  #endif
>  };
>
> +static int radeon_ttm_mem_open(struct inode *inode, struct file *filep)
> +{
> +       filep->private_data = inode->i_private;
> +       return 0;
> +}
> +
> +static ssize_t radeon_ttm_vram_read(struct file *f, char __user *buf,
> +                                   size_t size, loff_t *pos)
> +{
> +       struct radeon_device *rdev = f->private_data;
> +       ssize_t result = 0;
> +       int r;
> +
> +       if (size & 0x3 || *pos & 0x3)
> +               return -EINVAL;
> +
> +       while (size) {
> +               unsigned long flags;
> +               uint32_t value;
> +
> +               if (*pos >= rdev->mc.mc_vram_size || *pos >= 0x7FFFFFFF)
> +                       return result;
> +
> +               spin_lock_irqsave(&rdev->mmio_idx_lock, flags);
> +               WREG32(RADEON_MM_INDEX, ((uint32_t)*pos) | 0x80000000);

Starting with evergreen dGPUs, there is also an MM_INDEX_HI register
at 0x18 for accessing addresses over 30 bits.

Alex


> +               value = RREG32(RADEON_MM_DATA);
> +               spin_unlock_irqrestore(&rdev->mmio_idx_lock, flags);
> +
> +               r = put_user(value, (uint32_t *)buf);
> +               if (r)
> +                       return r;
> +
> +               result += 4;
> +               buf += 4;
> +               *pos += 4;
> +               size -= 4;
> +       }
> +
> +       return result;
> +}
> +
> +static const struct file_operations radeon_ttm_vram_fops = {
> +       .owner = THIS_MODULE,
> +       .open = radeon_ttm_mem_open,
> +       .read = radeon_ttm_vram_read,
> +};
> +
>  #endif
>
>  static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
>  {
>  #if defined(CONFIG_DEBUG_FS)
> -       unsigned count = ARRAY_SIZE(radeon_ttm_debugfs_list);
> +       unsigned count;
> +
> +       struct drm_minor *minor = rdev->ddev->primary;
> +       struct dentry *ent, *root = minor->debugfs_root;
> +
> +       ent = debugfs_create_file("radeon_vram", S_IFREG | S_IRUGO, root,
> +                                 rdev, &radeon_ttm_vram_fops);
> +       if (IS_ERR(ent))
> +               return PTR_ERR(ent);
> +       rdev->mman.vram = ent;
> +
> +       count = ARRAY_SIZE(radeon_ttm_debugfs_list);
>
>  #ifdef CONFIG_SWIOTLB
>         if (!swiotlb_nr_tbl())
> @@ -880,3 +941,12 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
>         return 0;
>  #endif
>  }
> +
> +static void radeon_ttm_debugfs_fini(struct radeon_device *rdev)
> +{
> +#if defined(CONFIG_DEBUG_FS)
> +
> +       debugfs_remove(rdev->mman.vram);
> +       rdev->mman.vram = NULL;
> +#endif
> +}
> --
> 1.8.1.2
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 5/6] drm/radeon: add VRAM debugfs access
  2013-12-12 13:31   ` Alex Deucher
@ 2013-12-12 13:35     ` Christian König
  2013-12-12 13:44       ` Alex Deucher
  0 siblings, 1 reply; 10+ messages in thread
From: Christian König @ 2013-12-12 13:35 UTC (permalink / raw)
  To: Alex Deucher; +Cc: Maling list - DRI developers

Am 12.12.2013 14:31, schrieb Alex Deucher:
> On Thu, Dec 12, 2013 at 3:42 AM, Christian König
> <deathsimple@vodafone.de> wrote:
>> From: Christian König <christian.koenig@amd.com>
>>
>> Not very fast, but makes it possible to access even the
>> normally inaccessible parts of VRAM from userspace.
>>
>> Signed-off-by: Christian König <christian.koenig@amd.com>
>> ---
>>   drivers/gpu/drm/radeon/radeon.h     |  4 +++
>>   drivers/gpu/drm/radeon/radeon_ttm.c | 72 ++++++++++++++++++++++++++++++++++++-
>>   2 files changed, 75 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
>> index b1f990d..49f210c1 100644
>> --- a/drivers/gpu/drm/radeon/radeon.h
>> +++ b/drivers/gpu/drm/radeon/radeon.h
>> @@ -413,6 +413,10 @@ struct radeon_mman {
>>          struct ttm_bo_device            bdev;
>>          bool                            mem_global_referenced;
>>          bool                            initialized;
>> +
>> +#if defined(CONFIG_DEBUG_FS)
>> +       struct dentry                   *vram;
>> +#endif
>>   };
>>
>>   /* bo virtual address in a specific vm */
>> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
>> index a2d6c4f..f5e8eed 100644
>> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
>> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
>> @@ -39,12 +39,14 @@
>>   #include <linux/seq_file.h>
>>   #include <linux/slab.h>
>>   #include <linux/swiotlb.h>
>> +#include <linux/debugfs.h>
>>   #include "radeon_reg.h"
>>   #include "radeon.h"
>>
>>   #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
>>
>>   static int radeon_ttm_debugfs_init(struct radeon_device *rdev);
>> +static void radeon_ttm_debugfs_fini(struct radeon_device *rdev);
>>
>>   static struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev)
>>   {
>> @@ -753,6 +755,7 @@ void radeon_ttm_fini(struct radeon_device *rdev)
>>
>>          if (!rdev->mman.initialized)
>>                  return;
>> +       radeon_ttm_debugfs_fini(rdev);
>>          if (rdev->stollen_vga_memory) {
>>                  r = radeon_bo_reserve(rdev->stollen_vga_memory, false);
>>                  if (r == 0) {
>> @@ -862,12 +865,70 @@ static struct drm_info_list radeon_ttm_debugfs_list[] = {
>>   #endif
>>   };
>>
>> +static int radeon_ttm_mem_open(struct inode *inode, struct file *filep)
>> +{
>> +       filep->private_data = inode->i_private;
>> +       return 0;
>> +}
>> +
>> +static ssize_t radeon_ttm_vram_read(struct file *f, char __user *buf,
>> +                                   size_t size, loff_t *pos)
>> +{
>> +       struct radeon_device *rdev = f->private_data;
>> +       ssize_t result = 0;
>> +       int r;
>> +
>> +       if (size & 0x3 || *pos & 0x3)
>> +               return -EINVAL;
>> +
>> +       while (size) {
>> +               unsigned long flags;
>> +               uint32_t value;
>> +
>> +               if (*pos >= rdev->mc.mc_vram_size || *pos >= 0x7FFFFFFF)
>> +                       return result;
>> +
>> +               spin_lock_irqsave(&rdev->mmio_idx_lock, flags);
>> +               WREG32(RADEON_MM_INDEX, ((uint32_t)*pos) | 0x80000000);
> Starting with evergreen dGPUs, there is also an MM_INDEX_HI register
> at 0x18 for accessing addresses over 30 bits.

I know, but I wanted to keep that as simple and stupid as possible. I 
mean this code should work from r100 till CIK and except for HAINAN do 
we really have cards with more than 2GB or ram?

And I'm not even sure if radeon_ttm is the right place for this.

Christian.

>
> Alex
>
>
>> +               value = RREG32(RADEON_MM_DATA);
>> +               spin_unlock_irqrestore(&rdev->mmio_idx_lock, flags);
>> +
>> +               r = put_user(value, (uint32_t *)buf);
>> +               if (r)
>> +                       return r;
>> +
>> +               result += 4;
>> +               buf += 4;
>> +               *pos += 4;
>> +               size -= 4;
>> +       }
>> +
>> +       return result;
>> +}
>> +
>> +static const struct file_operations radeon_ttm_vram_fops = {
>> +       .owner = THIS_MODULE,
>> +       .open = radeon_ttm_mem_open,
>> +       .read = radeon_ttm_vram_read,
>> +};
>> +
>>   #endif
>>
>>   static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
>>   {
>>   #if defined(CONFIG_DEBUG_FS)
>> -       unsigned count = ARRAY_SIZE(radeon_ttm_debugfs_list);
>> +       unsigned count;
>> +
>> +       struct drm_minor *minor = rdev->ddev->primary;
>> +       struct dentry *ent, *root = minor->debugfs_root;
>> +
>> +       ent = debugfs_create_file("radeon_vram", S_IFREG | S_IRUGO, root,
>> +                                 rdev, &radeon_ttm_vram_fops);
>> +       if (IS_ERR(ent))
>> +               return PTR_ERR(ent);
>> +       rdev->mman.vram = ent;
>> +
>> +       count = ARRAY_SIZE(radeon_ttm_debugfs_list);
>>
>>   #ifdef CONFIG_SWIOTLB
>>          if (!swiotlb_nr_tbl())
>> @@ -880,3 +941,12 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
>>          return 0;
>>   #endif
>>   }
>> +
>> +static void radeon_ttm_debugfs_fini(struct radeon_device *rdev)
>> +{
>> +#if defined(CONFIG_DEBUG_FS)
>> +
>> +       debugfs_remove(rdev->mman.vram);
>> +       rdev->mman.vram = NULL;
>> +#endif
>> +}
>> --
>> 1.8.1.2
>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 5/6] drm/radeon: add VRAM debugfs access
  2013-12-12 13:35     ` Christian König
@ 2013-12-12 13:44       ` Alex Deucher
  0 siblings, 0 replies; 10+ messages in thread
From: Alex Deucher @ 2013-12-12 13:44 UTC (permalink / raw)
  To: Christian König; +Cc: Maling list - DRI developers

On Thu, Dec 12, 2013 at 8:35 AM, Christian König
<deathsimple@vodafone.de> wrote:
> Am 12.12.2013 14:31, schrieb Alex Deucher:
>
>> On Thu, Dec 12, 2013 at 3:42 AM, Christian König
>> <deathsimple@vodafone.de> wrote:
>>>
>>> From: Christian König <christian.koenig@amd.com>
>>>
>>> Not very fast, but makes it possible to access even the
>>> normally inaccessible parts of VRAM from userspace.
>>>
>>> Signed-off-by: Christian König <christian.koenig@amd.com>
>>> ---
>>>   drivers/gpu/drm/radeon/radeon.h     |  4 +++
>>>   drivers/gpu/drm/radeon/radeon_ttm.c | 72
>>> ++++++++++++++++++++++++++++++++++++-
>>>   2 files changed, 75 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/radeon/radeon.h
>>> b/drivers/gpu/drm/radeon/radeon.h
>>> index b1f990d..49f210c1 100644
>>> --- a/drivers/gpu/drm/radeon/radeon.h
>>> +++ b/drivers/gpu/drm/radeon/radeon.h
>>> @@ -413,6 +413,10 @@ struct radeon_mman {
>>>          struct ttm_bo_device            bdev;
>>>          bool                            mem_global_referenced;
>>>          bool                            initialized;
>>> +
>>> +#if defined(CONFIG_DEBUG_FS)
>>> +       struct dentry                   *vram;
>>> +#endif
>>>   };
>>>
>>>   /* bo virtual address in a specific vm */
>>> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c
>>> b/drivers/gpu/drm/radeon/radeon_ttm.c
>>> index a2d6c4f..f5e8eed 100644
>>> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
>>> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
>>> @@ -39,12 +39,14 @@
>>>   #include <linux/seq_file.h>
>>>   #include <linux/slab.h>
>>>   #include <linux/swiotlb.h>
>>> +#include <linux/debugfs.h>
>>>   #include "radeon_reg.h"
>>>   #include "radeon.h"
>>>
>>>   #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
>>>
>>>   static int radeon_ttm_debugfs_init(struct radeon_device *rdev);
>>> +static void radeon_ttm_debugfs_fini(struct radeon_device *rdev);
>>>
>>>   static struct radeon_device *radeon_get_rdev(struct ttm_bo_device
>>> *bdev)
>>>   {
>>> @@ -753,6 +755,7 @@ void radeon_ttm_fini(struct radeon_device *rdev)
>>>
>>>          if (!rdev->mman.initialized)
>>>                  return;
>>> +       radeon_ttm_debugfs_fini(rdev);
>>>          if (rdev->stollen_vga_memory) {
>>>                  r = radeon_bo_reserve(rdev->stollen_vga_memory, false);
>>>                  if (r == 0) {
>>> @@ -862,12 +865,70 @@ static struct drm_info_list
>>> radeon_ttm_debugfs_list[] = {
>>>   #endif
>>>   };
>>>
>>> +static int radeon_ttm_mem_open(struct inode *inode, struct file *filep)
>>> +{
>>> +       filep->private_data = inode->i_private;
>>> +       return 0;
>>> +}
>>> +
>>> +static ssize_t radeon_ttm_vram_read(struct file *f, char __user *buf,
>>> +                                   size_t size, loff_t *pos)
>>> +{
>>> +       struct radeon_device *rdev = f->private_data;
>>> +       ssize_t result = 0;
>>> +       int r;
>>> +
>>> +       if (size & 0x3 || *pos & 0x3)
>>> +               return -EINVAL;
>>> +
>>> +       while (size) {
>>> +               unsigned long flags;
>>> +               uint32_t value;
>>> +
>>> +               if (*pos >= rdev->mc.mc_vram_size || *pos >= 0x7FFFFFFF)
>>> +                       return result;
>>> +
>>> +               spin_lock_irqsave(&rdev->mmio_idx_lock, flags);
>>> +               WREG32(RADEON_MM_INDEX, ((uint32_t)*pos) | 0x80000000);
>>
>> Starting with evergreen dGPUs, there is also an MM_INDEX_HI register
>> at 0x18 for accessing addresses over 30 bits.
>
>
> I know, but I wanted to keep that as simple and stupid as possible. I mean
> this code should work from r100 till CIK and except for HAINAN do we really
> have cards with more than 2GB or ram?

Most Hawaii boards are shipping with 4GB and a number of workstation
cards have large amounts of memory.

Alex

>
> And I'm not even sure if radeon_ttm is the right place for this.
>
> Christian.
>
>
>>
>> Alex
>>
>>
>>> +               value = RREG32(RADEON_MM_DATA);
>>> +               spin_unlock_irqrestore(&rdev->mmio_idx_lock, flags);
>>> +
>>> +               r = put_user(value, (uint32_t *)buf);
>>> +               if (r)
>>> +                       return r;
>>> +
>>> +               result += 4;
>>> +               buf += 4;
>>> +               *pos += 4;
>>> +               size -= 4;
>>> +       }
>>> +
>>> +       return result;
>>> +}
>>> +
>>> +static const struct file_operations radeon_ttm_vram_fops = {
>>> +       .owner = THIS_MODULE,
>>> +       .open = radeon_ttm_mem_open,
>>> +       .read = radeon_ttm_vram_read,
>>> +};
>>> +
>>>   #endif
>>>
>>>   static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
>>>   {
>>>   #if defined(CONFIG_DEBUG_FS)
>>> -       unsigned count = ARRAY_SIZE(radeon_ttm_debugfs_list);
>>> +       unsigned count;
>>> +
>>> +       struct drm_minor *minor = rdev->ddev->primary;
>>> +       struct dentry *ent, *root = minor->debugfs_root;
>>> +
>>> +       ent = debugfs_create_file("radeon_vram", S_IFREG | S_IRUGO, root,
>>> +                                 rdev, &radeon_ttm_vram_fops);
>>> +       if (IS_ERR(ent))
>>> +               return PTR_ERR(ent);
>>> +       rdev->mman.vram = ent;
>>> +
>>> +       count = ARRAY_SIZE(radeon_ttm_debugfs_list);
>>>
>>>   #ifdef CONFIG_SWIOTLB
>>>          if (!swiotlb_nr_tbl())
>>> @@ -880,3 +941,12 @@ static int radeon_ttm_debugfs_init(struct
>>> radeon_device *rdev)
>>>          return 0;
>>>   #endif
>>>   }
>>> +
>>> +static void radeon_ttm_debugfs_fini(struct radeon_device *rdev)
>>> +{
>>> +#if defined(CONFIG_DEBUG_FS)
>>> +
>>> +       debugfs_remove(rdev->mman.vram);
>>> +       rdev->mman.vram = NULL;
>>> +#endif
>>> +}
>>> --
>>> 1.8.1.2
>>>
>>> _______________________________________________
>>> dri-devel mailing list
>>> dri-devel@lists.freedesktop.org
>>> http://lists.freedesktop.org/mailman/listinfo/dri-devel
>
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-12-12 13:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-12  8:42 Radeon debugging patches for 3.14 Christian König
2013-12-12  8:42 ` [PATCH 1/6] drm/radeon: improve ring debugfs a bit Christian König
2013-12-12  8:42 ` [PATCH 2/6] drm/radeon: report the real offset in radeon_sa_bo_dump_debug_info Christian König
2013-12-12  8:42 ` [PATCH 3/6] drm/radeon: update fence values in before reporting them Christian König
2013-12-12  8:42 ` [PATCH 4/6] drm/radeon: cleanup radeon_ttm debugfs handling Christian König
2013-12-12  8:42 ` [PATCH 5/6] drm/radeon: add VRAM debugfs access Christian König
2013-12-12 13:31   ` Alex Deucher
2013-12-12 13:35     ` Christian König
2013-12-12 13:44       ` Alex Deucher
2013-12-12  8:42 ` [PATCH 6/6] drm/radeon: add GART " Christian König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.