2 * Copyright (C) 2013-2016 Red Hat
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.
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
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/>.
18 #ifdef CONFIG_DEBUG_FS
19 #include <linux/debugfs.h>
23 #include "msm_debugfs.h"
25 struct msm_gpu_show_priv {
26 struct msm_gpu_state *state;
27 struct drm_device *dev;
30 static int msm_gpu_show(struct seq_file *m, void *arg)
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;
38 ret = mutex_lock_interruptible(&show_priv->dev->struct_mutex);
42 drm_printf(&p, "%s Status:\n", gpu->name);
43 gpu->funcs->show(gpu, show_priv->state, &p);
45 mutex_unlock(&show_priv->dev->struct_mutex);
50 static int msm_gpu_release(struct inode *inode, struct file *file)
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;
58 ret = mutex_lock_interruptible(&show_priv->dev->struct_mutex);
62 gpu->funcs->gpu_state_put(show_priv->state);
63 mutex_unlock(&show_priv->dev->struct_mutex);
67 return single_release(inode, file);
70 static int msm_gpu_open(struct inode *inode, struct file *file)
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;
81 show_priv = kmalloc(sizeof(*show_priv), GFP_KERNEL);
85 ret = mutex_lock_interruptible(&dev->struct_mutex);
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);
93 mutex_unlock(&dev->struct_mutex);
95 if (IS_ERR(show_priv->state)) {
96 ret = PTR_ERR(show_priv->state);
101 show_priv->dev = dev;
103 return single_open(file, msm_gpu_show, show_priv);
106 static const struct file_operations msm_gpu_fops = {
107 .owner = THIS_MODULE,
108 .open = msm_gpu_open,
111 .release = msm_gpu_release,
114 static int msm_gem_show(struct drm_device *dev, struct seq_file *m)
116 struct msm_drm_private *priv = dev->dev_private;
117 struct msm_gpu *gpu = priv->gpu;
120 seq_printf(m, "Active Objects (%s):\n", gpu->name);
121 msm_gem_describe_objects(&gpu->active_list, m);
124 seq_printf(m, "Inactive Objects:\n");
125 msm_gem_describe_objects(&priv->inactive_list, m);
130 static int msm_mm_show(struct drm_device *dev, struct seq_file *m)
132 struct drm_printer p = drm_seq_file_printer(m);
134 drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p);
139 static int msm_fb_show(struct drm_device *dev, struct seq_file *m)
141 struct msm_drm_private *priv = dev->dev_private;
142 struct drm_framebuffer *fb, *fbdev_fb = NULL;
145 seq_printf(m, "fbcon ");
146 fbdev_fb = priv->fbdev->fb;
147 msm_framebuffer_describe(fbdev_fb, m);
150 mutex_lock(&dev->mode_config.fb_lock);
151 list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
155 seq_printf(m, "user ");
156 msm_framebuffer_describe(fb, m);
158 mutex_unlock(&dev->mode_config.fb_lock);
163 static int show_locked(struct seq_file *m, void *arg)
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;
171 ret = mutex_lock_interruptible(&dev->struct_mutex);
177 mutex_unlock(&dev->struct_mutex);
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 },
188 static int late_init_minor(struct drm_minor *minor)
195 ret = msm_rd_debugfs_init(minor);
197 dev_err(minor->dev->dev, "could not install rd debugfs\n");
201 ret = msm_perf_debugfs_init(minor);
203 dev_err(minor->dev->dev, "could not install perf debugfs\n");
210 int msm_debugfs_late_init(struct drm_device *dev)
213 ret = late_init_minor(dev->primary);
216 ret = late_init_minor(dev->render);
220 int msm_debugfs_init(struct drm_minor *minor)
222 struct drm_device *dev = minor->dev;
223 struct msm_drm_private *priv = dev->dev_private;
226 ret = drm_debugfs_create_files(msm_debugfs_list,
227 ARRAY_SIZE(msm_debugfs_list),
228 minor->debugfs_root, minor);
231 dev_err(dev->dev, "could not install msm_debugfs_list\n");
235 debugfs_create_file("gpu", S_IRUSR, minor->debugfs_root,
238 if (priv->kms->funcs->debugfs_init) {
239 ret = priv->kms->funcs->debugfs_init(priv->kms, minor);