1 /* $NetBSD: virtgpu_debugfs.c,v 1.3 2021/12/18 23:45:45 riastradh Exp $ */
2
3 /*
4 * Copyright (C) 2015 Red Hat, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial
17 * portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
23 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: virtgpu_debugfs.c,v 1.3 2021/12/18 23:45:45 riastradh Exp $");
30
31 #include <drm/drm_debugfs.h>
32 #include <drm/drm_file.h>
33
34 #include "virtgpu_drv.h"
35
virtio_add_bool(struct seq_file * m,const char * name,bool value)36 static void virtio_add_bool(struct seq_file *m, const char *name,
37 bool value)
38 {
39 seq_printf(m, "%-16s : %s\n", name, value ? "yes" : "no");
40 }
41
virtio_add_int(struct seq_file * m,const char * name,int value)42 static void virtio_add_int(struct seq_file *m, const char *name,
43 int value)
44 {
45 seq_printf(m, "%-16s : %d\n", name, value);
46 }
47
virtio_gpu_features(struct seq_file * m,void * data)48 static int virtio_gpu_features(struct seq_file *m, void *data)
49 {
50 struct drm_info_node *node = (struct drm_info_node *) m->private;
51 struct virtio_gpu_device *vgdev = node->minor->dev->dev_private;
52
53 virtio_add_bool(m, "virgl", vgdev->has_virgl_3d);
54 virtio_add_bool(m, "edid", vgdev->has_edid);
55 virtio_add_int(m, "cap sets", vgdev->num_capsets);
56 virtio_add_int(m, "scanouts", vgdev->num_scanouts);
57 return 0;
58 }
59
60 static int
virtio_gpu_debugfs_irq_info(struct seq_file * m,void * data)61 virtio_gpu_debugfs_irq_info(struct seq_file *m, void *data)
62 {
63 struct drm_info_node *node = (struct drm_info_node *) m->private;
64 struct virtio_gpu_device *vgdev = node->minor->dev->dev_private;
65
66 seq_printf(m, "fence %llu %lld\n",
67 (u64)atomic64_read(&vgdev->fence_drv.last_seq),
68 vgdev->fence_drv.sync_seq);
69 return 0;
70 }
71
72 static struct drm_info_list virtio_gpu_debugfs_list[] = {
73 { "virtio-gpu-features", virtio_gpu_features },
74 { "virtio-gpu-irq-fence", virtio_gpu_debugfs_irq_info, 0, NULL },
75 };
76
77 #define VIRTIO_GPU_DEBUGFS_ENTRIES ARRAY_SIZE(virtio_gpu_debugfs_list)
78
79 int
virtio_gpu_debugfs_init(struct drm_minor * minor)80 virtio_gpu_debugfs_init(struct drm_minor *minor)
81 {
82 drm_debugfs_create_files(virtio_gpu_debugfs_list,
83 VIRTIO_GPU_DEBUGFS_ENTRIES,
84 minor->debugfs_root, minor);
85 return 0;
86 }
87