1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2013-2016 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
9 #include <linux/debugfs.h>
11 #include <drm/drm_debugfs.h>
12 #include <drm/drm_file.h>
17 #include "msm_debugfs.h"
19 struct msm_gpu_show_priv
{
20 struct msm_gpu_state
*state
;
21 struct drm_device
*dev
;
24 static int msm_gpu_show(struct seq_file
*m
, void *arg
)
26 struct drm_printer p
= drm_seq_file_printer(m
);
27 struct msm_gpu_show_priv
*show_priv
= m
->private;
28 struct msm_drm_private
*priv
= show_priv
->dev
->dev_private
;
29 struct msm_gpu
*gpu
= priv
->gpu
;
32 ret
= mutex_lock_interruptible(&show_priv
->dev
->struct_mutex
);
36 drm_printf(&p
, "%s Status:\n", gpu
->name
);
37 gpu
->funcs
->show(gpu
, show_priv
->state
, &p
);
39 mutex_unlock(&show_priv
->dev
->struct_mutex
);
44 static int msm_gpu_release(struct inode
*inode
, struct file
*file
)
46 struct seq_file
*m
= file
->private_data
;
47 struct msm_gpu_show_priv
*show_priv
= m
->private;
48 struct msm_drm_private
*priv
= show_priv
->dev
->dev_private
;
49 struct msm_gpu
*gpu
= priv
->gpu
;
51 mutex_lock(&show_priv
->dev
->struct_mutex
);
52 gpu
->funcs
->gpu_state_put(show_priv
->state
);
53 mutex_unlock(&show_priv
->dev
->struct_mutex
);
57 return single_release(inode
, file
);
60 static int msm_gpu_open(struct inode
*inode
, struct file
*file
)
62 struct drm_device
*dev
= inode
->i_private
;
63 struct msm_drm_private
*priv
= dev
->dev_private
;
64 struct msm_gpu
*gpu
= priv
->gpu
;
65 struct msm_gpu_show_priv
*show_priv
;
68 if (!gpu
|| !gpu
->funcs
->gpu_state_get
)
71 show_priv
= kmalloc(sizeof(*show_priv
), GFP_KERNEL
);
75 ret
= mutex_lock_interruptible(&dev
->struct_mutex
);
79 pm_runtime_get_sync(&gpu
->pdev
->dev
);
80 show_priv
->state
= gpu
->funcs
->gpu_state_get(gpu
);
81 pm_runtime_put_sync(&gpu
->pdev
->dev
);
83 mutex_unlock(&dev
->struct_mutex
);
85 if (IS_ERR(show_priv
->state
)) {
86 ret
= PTR_ERR(show_priv
->state
);
92 ret
= single_open(file
, msm_gpu_show
, show_priv
);
103 static const struct file_operations msm_gpu_fops
= {
104 .owner
= THIS_MODULE
,
105 .open
= msm_gpu_open
,
108 .release
= msm_gpu_release
,
111 static int msm_gem_show(struct drm_device
*dev
, struct seq_file
*m
)
113 struct msm_drm_private
*priv
= dev
->dev_private
;
114 struct msm_gpu
*gpu
= priv
->gpu
;
117 seq_printf(m
, "Active Objects (%s):\n", gpu
->name
);
118 msm_gem_describe_objects(&gpu
->active_list
, m
);
121 seq_printf(m
, "Inactive Objects:\n");
122 msm_gem_describe_objects(&priv
->inactive_list
, m
);
127 static int msm_mm_show(struct drm_device
*dev
, struct seq_file
*m
)
129 struct drm_printer p
= drm_seq_file_printer(m
);
131 drm_mm_print(&dev
->vma_offset_manager
->vm_addr_space_mm
, &p
);
136 static int msm_fb_show(struct drm_device
*dev
, struct seq_file
*m
)
138 struct msm_drm_private
*priv
= dev
->dev_private
;
139 struct drm_framebuffer
*fb
, *fbdev_fb
= NULL
;
142 seq_printf(m
, "fbcon ");
143 fbdev_fb
= priv
->fbdev
->fb
;
144 msm_framebuffer_describe(fbdev_fb
, m
);
147 mutex_lock(&dev
->mode_config
.fb_lock
);
148 list_for_each_entry(fb
, &dev
->mode_config
.fb_list
, head
) {
152 seq_printf(m
, "user ");
153 msm_framebuffer_describe(fb
, m
);
155 mutex_unlock(&dev
->mode_config
.fb_lock
);
160 static int show_locked(struct seq_file
*m
, void *arg
)
162 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
163 struct drm_device
*dev
= node
->minor
->dev
;
164 int (*show
)(struct drm_device
*dev
, struct seq_file
*m
) =
165 node
->info_ent
->data
;
168 ret
= mutex_lock_interruptible(&dev
->struct_mutex
);
174 mutex_unlock(&dev
->struct_mutex
);
179 static struct drm_info_list msm_debugfs_list
[] = {
180 {"gem", show_locked
, 0, msm_gem_show
},
181 { "mm", show_locked
, 0, msm_mm_show
},
182 { "fb", show_locked
, 0, msm_fb_show
},
185 static int late_init_minor(struct drm_minor
*minor
)
192 ret
= msm_rd_debugfs_init(minor
);
194 DRM_DEV_ERROR(minor
->dev
->dev
, "could not install rd debugfs\n");
198 ret
= msm_perf_debugfs_init(minor
);
200 DRM_DEV_ERROR(minor
->dev
->dev
, "could not install perf debugfs\n");
207 int msm_debugfs_late_init(struct drm_device
*dev
)
210 ret
= late_init_minor(dev
->primary
);
213 ret
= late_init_minor(dev
->render
);
217 int msm_debugfs_init(struct drm_minor
*minor
)
219 struct drm_device
*dev
= minor
->dev
;
220 struct msm_drm_private
*priv
= dev
->dev_private
;
223 ret
= drm_debugfs_create_files(msm_debugfs_list
,
224 ARRAY_SIZE(msm_debugfs_list
),
225 minor
->debugfs_root
, minor
);
228 DRM_DEV_ERROR(dev
->dev
, "could not install msm_debugfs_list\n");
232 debugfs_create_file("gpu", S_IRUSR
, minor
->debugfs_root
,
235 if (priv
->kms
&& priv
->kms
->funcs
->debugfs_init
) {
236 ret
= priv
->kms
->funcs
->debugfs_init(priv
->kms
, minor
);