Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
25struct msm_gpu_show_priv {
26 struct msm_gpu_state *state;
27 struct drm_device *dev;
28};
29
30static 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
50static 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
70static 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 goto free_priv;
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 goto free_priv;
98 }
99
100 show_priv->dev = dev;
101
102 ret = single_open(file, msm_gpu_show, show_priv);
103 if (ret)
104 goto free_priv;
105
106 return 0;
107
108free_priv:
109 kfree(show_priv);
110 return ret;
111}
112
113static const struct file_operations msm_gpu_fops = {
114 .owner = THIS_MODULE,
115 .open = msm_gpu_open,
116 .read = seq_read,
117 .llseek = seq_lseek,
118 .release = msm_gpu_release,
119};
120
121static int msm_gem_show(struct drm_device *dev, struct seq_file *m)
122{
123 struct msm_drm_private *priv = dev->dev_private;
124 struct msm_gpu *gpu = priv->gpu;
125
126 if (gpu) {
127 seq_printf(m, "Active Objects (%s):\n", gpu->name);
128 msm_gem_describe_objects(&gpu->active_list, m);
129 }
130
131 seq_printf(m, "Inactive Objects:\n");
132 msm_gem_describe_objects(&priv->inactive_list, m);
133
134 return 0;
135}
136
137static int msm_mm_show(struct drm_device *dev, struct seq_file *m)
138{
139 struct drm_printer p = drm_seq_file_printer(m);
140
141 drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p);
142
143 return 0;
144}
145
146static int msm_fb_show(struct drm_device *dev, struct seq_file *m)
147{
148 struct msm_drm_private *priv = dev->dev_private;
149 struct drm_framebuffer *fb, *fbdev_fb = NULL;
150
151 if (priv->fbdev) {
152 seq_printf(m, "fbcon ");
153 fbdev_fb = priv->fbdev->fb;
154 msm_framebuffer_describe(fbdev_fb, m);
155 }
156
157 mutex_lock(&dev->mode_config.fb_lock);
158 list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
159 if (fb == fbdev_fb)
160 continue;
161
162 seq_printf(m, "user ");
163 msm_framebuffer_describe(fb, m);
164 }
165 mutex_unlock(&dev->mode_config.fb_lock);
166
167 return 0;
168}
169
170static int show_locked(struct seq_file *m, void *arg)
171{
172 struct drm_info_node *node = (struct drm_info_node *) m->private;
173 struct drm_device *dev = node->minor->dev;
174 int (*show)(struct drm_device *dev, struct seq_file *m) =
175 node->info_ent->data;
176 int ret;
177
178 ret = mutex_lock_interruptible(&dev->struct_mutex);
179 if (ret)
180 return ret;
181
182 ret = show(dev, m);
183
184 mutex_unlock(&dev->struct_mutex);
185
186 return ret;
187}
188
189static struct drm_info_list msm_debugfs_list[] = {
190 {"gem", show_locked, 0, msm_gem_show},
191 { "mm", show_locked, 0, msm_mm_show },
192 { "fb", show_locked, 0, msm_fb_show },
193};
194
195static int late_init_minor(struct drm_minor *minor)
196{
197 int ret;
198
199 if (!minor)
200 return 0;
201
202 ret = msm_rd_debugfs_init(minor);
203 if (ret) {
204 DRM_DEV_ERROR(minor->dev->dev, "could not install rd debugfs\n");
205 return ret;
206 }
207
208 ret = msm_perf_debugfs_init(minor);
209 if (ret) {
210 DRM_DEV_ERROR(minor->dev->dev, "could not install perf debugfs\n");
211 return ret;
212 }
213
214 return 0;
215}
216
217int msm_debugfs_late_init(struct drm_device *dev)
218{
219 int ret;
220 ret = late_init_minor(dev->primary);
221 if (ret)
222 return ret;
223 ret = late_init_minor(dev->render);
224 return ret;
225}
226
227int msm_debugfs_init(struct drm_minor *minor)
228{
229 struct drm_device *dev = minor->dev;
230 struct msm_drm_private *priv = dev->dev_private;
231 int ret;
232
233 ret = drm_debugfs_create_files(msm_debugfs_list,
234 ARRAY_SIZE(msm_debugfs_list),
235 minor->debugfs_root, minor);
236
237 if (ret) {
238 DRM_DEV_ERROR(dev->dev, "could not install msm_debugfs_list\n");
239 return ret;
240 }
241
242 debugfs_create_file("gpu", S_IRUSR, minor->debugfs_root,
243 dev, &msm_gpu_fops);
244
245 if (priv->kms && priv->kms->funcs->debugfs_init) {
246 ret = priv->kms->funcs->debugfs_init(priv->kms, minor);
247 if (ret)
248 return ret;
249 }
250
251 return ret;
252}
253#endif
254