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