xref: /openbmc/linux/drivers/gpu/drm/msm/msm_debugfs.c (revision de2bdb3d)
1 /*
2  * Copyright (C) 2013-2016 Red Hat
3  * Author: Rob Clark <robdclark@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published by
7  * the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifdef CONFIG_DEBUG_FS
19 #include "msm_drv.h"
20 #include "msm_gpu.h"
21 #include "msm_debugfs.h"
22 
23 static int msm_gpu_show(struct drm_device *dev, struct seq_file *m)
24 {
25 	struct msm_drm_private *priv = dev->dev_private;
26 	struct msm_gpu *gpu = priv->gpu;
27 
28 	if (gpu) {
29 		seq_printf(m, "%s Status:\n", gpu->name);
30 		gpu->funcs->show(gpu, m);
31 	}
32 
33 	return 0;
34 }
35 
36 static int msm_gem_show(struct drm_device *dev, struct seq_file *m)
37 {
38 	struct msm_drm_private *priv = dev->dev_private;
39 	struct msm_gpu *gpu = priv->gpu;
40 
41 	if (gpu) {
42 		seq_printf(m, "Active Objects (%s):\n", gpu->name);
43 		msm_gem_describe_objects(&gpu->active_list, m);
44 	}
45 
46 	seq_printf(m, "Inactive Objects:\n");
47 	msm_gem_describe_objects(&priv->inactive_list, m);
48 
49 	return 0;
50 }
51 
52 static int msm_mm_show(struct drm_device *dev, struct seq_file *m)
53 {
54 	return drm_mm_dump_table(m, &dev->vma_offset_manager->vm_addr_space_mm);
55 }
56 
57 static int msm_fb_show(struct drm_device *dev, struct seq_file *m)
58 {
59 	struct msm_drm_private *priv = dev->dev_private;
60 	struct drm_framebuffer *fb, *fbdev_fb = NULL;
61 
62 	if (priv->fbdev) {
63 		seq_printf(m, "fbcon ");
64 		fbdev_fb = priv->fbdev->fb;
65 		msm_framebuffer_describe(fbdev_fb, m);
66 	}
67 
68 	mutex_lock(&dev->mode_config.fb_lock);
69 	list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
70 		if (fb == fbdev_fb)
71 			continue;
72 
73 		seq_printf(m, "user ");
74 		msm_framebuffer_describe(fb, m);
75 	}
76 	mutex_unlock(&dev->mode_config.fb_lock);
77 
78 	return 0;
79 }
80 
81 static int show_locked(struct seq_file *m, void *arg)
82 {
83 	struct drm_info_node *node = (struct drm_info_node *) m->private;
84 	struct drm_device *dev = node->minor->dev;
85 	int (*show)(struct drm_device *dev, struct seq_file *m) =
86 			node->info_ent->data;
87 	int ret;
88 
89 	ret = mutex_lock_interruptible(&dev->struct_mutex);
90 	if (ret)
91 		return ret;
92 
93 	ret = show(dev, m);
94 
95 	mutex_unlock(&dev->struct_mutex);
96 
97 	return ret;
98 }
99 
100 static struct drm_info_list msm_debugfs_list[] = {
101 		{"gpu", show_locked, 0, msm_gpu_show},
102 		{"gem", show_locked, 0, msm_gem_show},
103 		{ "mm", show_locked, 0, msm_mm_show },
104 		{ "fb", show_locked, 0, msm_fb_show },
105 };
106 
107 static int late_init_minor(struct drm_minor *minor)
108 {
109 	int ret;
110 
111 	if (!minor)
112 		return 0;
113 
114 	ret = msm_rd_debugfs_init(minor);
115 	if (ret) {
116 		dev_err(minor->dev->dev, "could not install rd debugfs\n");
117 		return ret;
118 	}
119 
120 	ret = msm_perf_debugfs_init(minor);
121 	if (ret) {
122 		dev_err(minor->dev->dev, "could not install perf debugfs\n");
123 		return ret;
124 	}
125 
126 	return 0;
127 }
128 
129 int msm_debugfs_late_init(struct drm_device *dev)
130 {
131 	int ret;
132 	ret = late_init_minor(dev->primary);
133 	if (ret)
134 		return ret;
135 	ret = late_init_minor(dev->render);
136 	if (ret)
137 		return ret;
138 	ret = late_init_minor(dev->control);
139 	return ret;
140 }
141 
142 int msm_debugfs_init(struct drm_minor *minor)
143 {
144 	struct drm_device *dev = minor->dev;
145 	int ret;
146 
147 	ret = drm_debugfs_create_files(msm_debugfs_list,
148 			ARRAY_SIZE(msm_debugfs_list),
149 			minor->debugfs_root, minor);
150 
151 	if (ret) {
152 		dev_err(dev->dev, "could not install msm_debugfs_list\n");
153 		return ret;
154 	}
155 
156 	return 0;
157 }
158 
159 void msm_debugfs_cleanup(struct drm_minor *minor)
160 {
161 	drm_debugfs_remove_files(msm_debugfs_list,
162 			ARRAY_SIZE(msm_debugfs_list), minor);
163 	if (!minor->dev->dev_private)
164 		return;
165 	msm_rd_debugfs_cleanup(minor);
166 	msm_perf_debugfs_cleanup(minor);
167 }
168 #endif
169 
170