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