blob: 5085c98181401a21b765a58d7295a149aa3a7900 [file] [log] [blame]
Marcin Slusarz33b903e2013-02-08 21:42:13 +01001/*
2 * Copyright (C) 2009 Red Hat <bskeggs@redhat.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 */
25
26/*
27 * Authors:
28 * Ben Skeggs <bskeggs@redhat.com>
29 */
30
Karol Herbst1b7ab1a2015-07-29 13:44:21 +020031#include <linux/debugfs.h>
Marcin Slusarz33b903e2013-02-08 21:42:13 +010032#include "nouveau_debugfs.h"
33#include "nouveau_drm.h"
34
35static int
36nouveau_debugfs_vbios_image(struct seq_file *m, void *data)
37{
38 struct drm_info_node *node = (struct drm_info_node *) m->private;
39 struct nouveau_drm *drm = nouveau_drm(node->minor->dev);
40 int i;
41
42 for (i = 0; i < drm->vbios.length; i++)
43 seq_printf(m, "%c", drm->vbios.data[i]);
44 return 0;
45}
46
47static struct drm_info_list nouveau_debugfs_list[] = {
48 { "vbios.rom", nouveau_debugfs_vbios_image, 0, NULL },
49};
50#define NOUVEAU_DEBUGFS_ENTRIES ARRAY_SIZE(nouveau_debugfs_list)
51
Karol Herbst1b7ab1a2015-07-29 13:44:21 +020052static const struct nouveau_debugfs_files {
53 const char *name;
54 const struct file_operations *fops;
55} nouveau_debugfs_files[] = {};
56
57
58static int
59nouveau_debugfs_create_file(struct drm_minor *minor,
60 const struct nouveau_debugfs_files *ndf)
61{
62 struct drm_info_node *node;
63
64 node = kmalloc(sizeof(*node), GFP_KERNEL);
65 if (node == NULL)
66 return -ENOMEM;
67
68 node->minor = minor;
69 node->info_ent = (const void *)ndf->fops;
70 node->dent = debugfs_create_file(ndf->name, S_IRUGO | S_IWUSR,
71 minor->debugfs_root, node, ndf->fops);
72 if (!node->dent) {
73 kfree(node);
74 return -ENOMEM;
75 }
76
77 mutex_lock(&minor->debugfs_lock);
78 list_add(&node->list, &minor->debugfs_list);
79 mutex_unlock(&minor->debugfs_lock);
80 return 0;
81}
82
Marcin Slusarz33b903e2013-02-08 21:42:13 +010083int
Karol Herbst56c101a2015-07-31 00:35:42 +020084nouveau_drm_debugfs_init(struct drm_minor *minor)
Marcin Slusarz33b903e2013-02-08 21:42:13 +010085{
Karol Herbst1b7ab1a2015-07-29 13:44:21 +020086 int i, ret;
87
88 for (i = 0; i < ARRAY_SIZE(nouveau_debugfs_files); i++) {
89 ret = nouveau_debugfs_create_file(minor,
90 &nouveau_debugfs_files[i]);
91
92 if (ret)
93 return ret;
94 }
95
96 return drm_debugfs_create_files(nouveau_debugfs_list,
97 NOUVEAU_DEBUGFS_ENTRIES,
98 minor->debugfs_root, minor);
Marcin Slusarz33b903e2013-02-08 21:42:13 +010099}
100
101void
Karol Herbst56c101a2015-07-31 00:35:42 +0200102nouveau_drm_debugfs_cleanup(struct drm_minor *minor)
Marcin Slusarz33b903e2013-02-08 21:42:13 +0100103{
Karol Herbst1b7ab1a2015-07-29 13:44:21 +0200104 int i;
105
Marcin Slusarz33b903e2013-02-08 21:42:13 +0100106 drm_debugfs_remove_files(nouveau_debugfs_list, NOUVEAU_DEBUGFS_ENTRIES,
107 minor);
Karol Herbst1b7ab1a2015-07-29 13:44:21 +0200108
109 for (i = 0; i < ARRAY_SIZE(nouveau_debugfs_files); i++) {
110 drm_debugfs_remove_files((struct drm_info_list *)
111 nouveau_debugfs_files[i].fops,
112 1, minor);
113 }
Marcin Slusarz33b903e2013-02-08 21:42:13 +0100114}