xref: /linux/drivers/gpu/drm/qxl/qxl_debugfs.c (revision 0cc848a7)
1f64122c1SDave Airlie /*
2f64122c1SDave Airlie  * Copyright (C) 2009 Red Hat <bskeggs@redhat.com>
3f64122c1SDave Airlie  *
4f64122c1SDave Airlie  * Permission is hereby granted, free of charge, to any person obtaining
5f64122c1SDave Airlie  * a copy of this software and associated documentation files (the
6f64122c1SDave Airlie  * "Software"), to deal in the Software without restriction, including
7f64122c1SDave Airlie  * without limitation the rights to use, copy, modify, merge, publish,
8f64122c1SDave Airlie  * distribute, sublicense, and/or sell copies of the Software, and to
9f64122c1SDave Airlie  * permit persons to whom the Software is furnished to do so, subject to
10f64122c1SDave Airlie  * the following conditions:
11f64122c1SDave Airlie  *
12f64122c1SDave Airlie  * The above copyright notice and this permission notice (including the
13f64122c1SDave Airlie  * next paragraph) shall be included in all copies or substantial
14f64122c1SDave Airlie  * portions of the Software.
15f64122c1SDave Airlie  *
16f64122c1SDave Airlie  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17f64122c1SDave Airlie  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18f64122c1SDave Airlie  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19f64122c1SDave Airlie  * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
20f64122c1SDave Airlie  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21f64122c1SDave Airlie  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22f64122c1SDave Airlie  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23f64122c1SDave Airlie  *
24f64122c1SDave Airlie  */
25f64122c1SDave Airlie 
26f64122c1SDave Airlie /*
27f64122c1SDave Airlie  * Authors:
28f64122c1SDave Airlie  *  Alon Levy <alevy@redhat.com>
29f64122c1SDave Airlie  */
30f64122c1SDave Airlie 
31c0f4b75cSSam Ravnborg #include <drm/drm_debugfs.h>
32c0f4b75cSSam Ravnborg #include <drm/drm_file.h>
33f64122c1SDave Airlie 
34f64122c1SDave Airlie #include "qxl_drv.h"
35f64122c1SDave Airlie #include "qxl_object.h"
36f64122c1SDave Airlie 
37caaa0352SDavid Rientjes #if defined(CONFIG_DEBUG_FS)
38f64122c1SDave Airlie static int
qxl_debugfs_irq_received(struct seq_file * m,void * data)39f64122c1SDave Airlie qxl_debugfs_irq_received(struct seq_file *m, void *data)
40f64122c1SDave Airlie {
41f64122c1SDave Airlie 	struct drm_info_node *node = (struct drm_info_node *) m->private;
42e304f8a0SDaniel Vetter 	struct qxl_device *qdev = to_qxl(node->minor->dev);
43f64122c1SDave Airlie 
44f64122c1SDave Airlie 	seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
45f64122c1SDave Airlie 	seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
46f64122c1SDave Airlie 	seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
47f64122c1SDave Airlie 	seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
48f64122c1SDave Airlie 	seq_printf(m, "%d\n", qdev->irq_received_error);
49f64122c1SDave Airlie 	return 0;
50f64122c1SDave Airlie }
51f64122c1SDave Airlie 
52f64122c1SDave Airlie static int
qxl_debugfs_buffers_info(struct seq_file * m,void * data)53f64122c1SDave Airlie qxl_debugfs_buffers_info(struct seq_file *m, void *data)
54f64122c1SDave Airlie {
55f64122c1SDave Airlie 	struct drm_info_node *node = (struct drm_info_node *) m->private;
56e304f8a0SDaniel Vetter 	struct qxl_device *qdev = to_qxl(node->minor->dev);
57f64122c1SDave Airlie 	struct qxl_bo *bo;
58f64122c1SDave Airlie 
59f64122c1SDave Airlie 	list_for_each_entry(bo, &qdev->gem.objects, list) {
6086baad19SChristian König 		struct dma_resv_iter cursor;
6186baad19SChristian König 		struct dma_fence *fence;
6286baad19SChristian König 		int rel = 0;
632f453ed4SMaarten Lankhorst 
647bc80a54SChristian König 		dma_resv_iter_begin(&cursor, bo->tbo.base.resv,
650cc848a7SChristian König 				    DMA_RESV_USAGE_BOOKKEEP);
6686baad19SChristian König 		dma_resv_for_each_fence_unlocked(&cursor, fence) {
6786baad19SChristian König 			if (dma_resv_iter_is_restarted(&cursor))
6886baad19SChristian König 				rel = 0;
6986baad19SChristian König 			++rel;
7086baad19SChristian König 		}
712f453ed4SMaarten Lankhorst 
72f2c24b83SMaarten Lankhorst 		seq_printf(m, "size %ld, pc %d, num releases %d\n",
73e0828d54SGerd Hoffmann 			   (unsigned long)bo->tbo.base.size,
749d36d432SChristian König 			   bo->tbo.pin_count, rel);
75f64122c1SDave Airlie 	}
76f64122c1SDave Airlie 	return 0;
77f64122c1SDave Airlie }
78f64122c1SDave Airlie 
79f64122c1SDave Airlie static struct drm_info_list qxl_debugfs_list[] = {
80f64122c1SDave Airlie 	{ "irq_received", qxl_debugfs_irq_received, 0, NULL },
81f64122c1SDave Airlie 	{ "qxl_buffers", qxl_debugfs_buffers_info, 0, NULL },
82f64122c1SDave Airlie };
83f64122c1SDave Airlie #define QXL_DEBUGFS_ENTRIES ARRAY_SIZE(qxl_debugfs_list)
84caaa0352SDavid Rientjes #endif
85f64122c1SDave Airlie 
867ce84471SWambui Karuga void
qxl_debugfs_init(struct drm_minor * minor)87f64122c1SDave Airlie qxl_debugfs_init(struct drm_minor *minor)
88f64122c1SDave Airlie {
89caaa0352SDavid Rientjes #if defined(CONFIG_DEBUG_FS)
90e304f8a0SDaniel Vetter 	struct qxl_device *dev = to_qxl(minor->dev);
912b65d567SGabriel Krisman Bertazi 
92f64122c1SDave Airlie 	drm_debugfs_create_files(qxl_debugfs_list, QXL_DEBUGFS_ENTRIES,
93f64122c1SDave Airlie 				 minor->debugfs_root, minor);
942b65d567SGabriel Krisman Bertazi 
957ce84471SWambui Karuga 	qxl_ttm_debugfs_init(dev);
96caaa0352SDavid Rientjes #endif
97f64122c1SDave Airlie }
98f64122c1SDave Airlie 
qxl_debugfs_add_files(struct qxl_device * qdev,struct drm_info_list * files,unsigned int nfiles)997ce84471SWambui Karuga void qxl_debugfs_add_files(struct qxl_device *qdev,
100f64122c1SDave Airlie 			   struct drm_info_list *files,
1011b000494SShayenne da Luz Moura 			   unsigned int nfiles)
102f64122c1SDave Airlie {
1031b000494SShayenne da Luz Moura 	unsigned int i;
104f64122c1SDave Airlie 
105f64122c1SDave Airlie 	for (i = 0; i < qdev->debugfs_count; i++) {
106f64122c1SDave Airlie 		if (qdev->debugfs[i].files == files) {
107f64122c1SDave Airlie 			/* Already registered */
1087ce84471SWambui Karuga 			return;
109f64122c1SDave Airlie 		}
110f64122c1SDave Airlie 	}
111f64122c1SDave Airlie 
112f64122c1SDave Airlie 	i = qdev->debugfs_count + 1;
113f64122c1SDave Airlie 	if (i > QXL_DEBUGFS_MAX_COMPONENTS) {
114f64122c1SDave Airlie 		DRM_ERROR("Reached maximum number of debugfs components.\n");
115f64122c1SDave Airlie 		DRM_ERROR("Report so we increase QXL_DEBUGFS_MAX_COMPONENTS.\n");
1167ce84471SWambui Karuga 		return;
117f64122c1SDave Airlie 	}
118f64122c1SDave Airlie 	qdev->debugfs[qdev->debugfs_count].files = files;
119f64122c1SDave Airlie 	qdev->debugfs[qdev->debugfs_count].num_files = nfiles;
120f64122c1SDave Airlie 	qdev->debugfs_count = i;
121f64122c1SDave Airlie #if defined(CONFIG_DEBUG_FS)
122f64122c1SDave Airlie 	drm_debugfs_create_files(files, nfiles,
123cbdded7fSGabriel Krisman Bertazi 				 qdev->ddev.primary->debugfs_root,
124cbdded7fSGabriel Krisman Bertazi 				 qdev->ddev.primary);
125f64122c1SDave Airlie #endif
126f64122c1SDave Airlie }
127