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 <linux/debugfs.h>
20 #include "msm_drv.h"
21 #include "msm_gpu.h"
22 #include "msm_kms.h"
23 #include "msm_debugfs.h"
24
25 struct msm_gpu_show_priv {
26 struct msm_gpu_state *state;
27 struct drm_device *dev;
28 };
29
msm_gpu_show(struct seq_file * m,void * arg)30 static int msm_gpu_show(struct seq_file *m, void *arg)
31 {
32 struct drm_printer p = drm_seq_file_printer(m);
33 struct msm_gpu_show_priv *show_priv = m->private;
34 struct msm_drm_private *priv = show_priv->dev->dev_private;
35 struct msm_gpu *gpu = priv->gpu;
36 int ret;
37
38 ret = mutex_lock_interruptible(&show_priv->dev->struct_mutex);
39 if (ret)
40 return ret;
41
42 drm_printf(&p, "%s Status:\n", gpu->name);
43 gpu->funcs->show(gpu, show_priv->state, &p);
44
45 mutex_unlock(&show_priv->dev->struct_mutex);
46
47 return 0;
48 }
49
msm_gpu_release(struct inode * inode,struct file * file)50 static int msm_gpu_release(struct inode *inode, struct file *file)
51 {
52 struct seq_file *m = file->private_data;
53 struct msm_gpu_show_priv *show_priv = m->private;
54 struct msm_drm_private *priv = show_priv->dev->dev_private;
55 struct msm_gpu *gpu = priv->gpu;
56 int ret;
57
58 ret = mutex_lock_interruptible(&show_priv->dev->struct_mutex);
59 if (ret)
60 return ret;
61
62 gpu->funcs->gpu_state_put(show_priv->state);
63 mutex_unlock(&show_priv->dev->struct_mutex);
64
65 kfree(show_priv);
66
67 return single_release(inode, file);
68 }
69
msm_gpu_open(struct inode * inode,struct file * file)70 static int msm_gpu_open(struct inode *inode, struct file *file)
71 {
72 struct drm_device *dev = inode->i_private;
73 struct msm_drm_private *priv = dev->dev_private;
74 struct msm_gpu *gpu = priv->gpu;
75 struct msm_gpu_show_priv *show_priv;
76 int ret;
77
78 if (!gpu)
79 return -ENODEV;
80
81 show_priv = kmalloc(sizeof(*show_priv), GFP_KERNEL);
82 if (!show_priv)
83 return -ENOMEM;
84
85 ret = mutex_lock_interruptible(&dev->struct_mutex);
86 if (ret)
87 return ret;
88
89 pm_runtime_get_sync(&gpu->pdev->dev);
90 show_priv->state = gpu->funcs->gpu_state_get(gpu);
91 pm_runtime_put_sync(&gpu->pdev->dev);
92
93 mutex_unlock(&dev->struct_mutex);
94
95 if (IS_ERR(show_priv->state)) {
96 ret = PTR_ERR(show_priv->state);
97 kfree(show_priv);
98 return ret;
99 }
100
101 show_priv->dev = dev;
102
103 return single_open(file, msm_gpu_show, show_priv);
104 }
105
106 static const struct file_operations msm_gpu_fops = {
107 .owner = THIS_MODULE,
108 .open = msm_gpu_open,
109 .read = seq_read,
110 .llseek = seq_lseek,
111 .release = msm_gpu_release,
112 };
113
msm_gem_show(struct drm_device * dev,struct seq_file * m)114 static int msm_gem_show(struct drm_device *dev, struct seq_file *m)
115 {
116 struct msm_drm_private *priv = dev->dev_private;
117 struct msm_gpu *gpu = priv->gpu;
118
119 if (gpu) {
120 seq_printf(m, "Active Objects (%s):\n", gpu->name);
121 msm_gem_describe_objects(&gpu->active_list, m);
122 }
123
124 seq_printf(m, "Inactive Objects:\n");
125 msm_gem_describe_objects(&priv->inactive_list, m);
126
127 return 0;
128 }
129
msm_mm_show(struct drm_device * dev,struct seq_file * m)130 static int msm_mm_show(struct drm_device *dev, struct seq_file *m)
131 {
132 struct drm_printer p = drm_seq_file_printer(m);
133
134 drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p);
135
136 return 0;
137 }
138
msm_fb_show(struct drm_device * dev,struct seq_file * m)139 static int msm_fb_show(struct drm_device *dev, struct seq_file *m)
140 {
141 struct msm_drm_private *priv = dev->dev_private;
142 struct drm_framebuffer *fb, *fbdev_fb = NULL;
143
144 if (priv->fbdev) {
145 seq_printf(m, "fbcon ");
146 fbdev_fb = priv->fbdev->fb;
147 msm_framebuffer_describe(fbdev_fb, m);
148 }
149
150 mutex_lock(&dev->mode_config.fb_lock);
151 list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
152 if (fb == fbdev_fb)
153 continue;
154
155 seq_printf(m, "user ");
156 msm_framebuffer_describe(fb, m);
157 }
158 mutex_unlock(&dev->mode_config.fb_lock);
159
160 return 0;
161 }
162
show_locked(struct seq_file * m,void * arg)163 static int show_locked(struct seq_file *m, void *arg)
164 {
165 struct drm_info_node *node = (struct drm_info_node *) m->private;
166 struct drm_device *dev = node->minor->dev;
167 int (*show)(struct drm_device *dev, struct seq_file *m) =
168 node->info_ent->data;
169 int ret;
170
171 ret = mutex_lock_interruptible(&dev->struct_mutex);
172 if (ret)
173 return ret;
174
175 ret = show(dev, m);
176
177 mutex_unlock(&dev->struct_mutex);
178
179 return ret;
180 }
181
182 static struct drm_info_list msm_debugfs_list[] = {
183 {"gem", show_locked, 0, msm_gem_show},
184 { "mm", show_locked, 0, msm_mm_show },
185 { "fb", show_locked, 0, msm_fb_show },
186 };
187
late_init_minor(struct drm_minor * minor)188 static int late_init_minor(struct drm_minor *minor)
189 {
190 int ret;
191
192 if (!minor)
193 return 0;
194
195 ret = msm_rd_debugfs_init(minor);
196 if (ret) {
197 dev_err(minor->dev->dev, "could not install rd debugfs\n");
198 return ret;
199 }
200
201 ret = msm_perf_debugfs_init(minor);
202 if (ret) {
203 dev_err(minor->dev->dev, "could not install perf debugfs\n");
204 return ret;
205 }
206
207 return 0;
208 }
209
msm_debugfs_late_init(struct drm_device * dev)210 int msm_debugfs_late_init(struct drm_device *dev)
211 {
212 int ret;
213 ret = late_init_minor(dev->primary);
214 if (ret)
215 return ret;
216 ret = late_init_minor(dev->render);
217 return ret;
218 }
219
msm_debugfs_init(struct drm_minor * minor)220 int msm_debugfs_init(struct drm_minor *minor)
221 {
222 struct drm_device *dev = minor->dev;
223 struct msm_drm_private *priv = dev->dev_private;
224 int ret;
225
226 ret = drm_debugfs_create_files(msm_debugfs_list,
227 ARRAY_SIZE(msm_debugfs_list),
228 minor->debugfs_root, minor);
229
230 if (ret) {
231 dev_err(dev->dev, "could not install msm_debugfs_list\n");
232 return ret;
233 }
234
235 debugfs_create_file("gpu", S_IRUSR, minor->debugfs_root,
236 dev, &msm_gpu_fops);
237
238 if (priv->kms->funcs->debugfs_init) {
239 ret = priv->kms->funcs->debugfs_init(priv->kms, minor);
240 if (ret)
241 return ret;
242 }
243
244 return ret;
245 }
246 #endif
247
248