drm: Convert proc files to seq_file and introduce debugfs
[linux-2.6-block.git] / drivers / gpu / drm / drm_proc.c
CommitLineData
1da177e4 1/**
b5e89ed5 2 * \file drm_proc.c
1da177e4
LT
3 * /proc support for DRM
4 *
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
7 *
8 * \par Acknowledgements:
9 * Matthew J Sottek <matthew.j.sottek@intel.com> sent in a patch to fix
10 * the problem with the proc files not outputting all their information.
11 */
12
13/*
14 * Created: Mon Jan 11 09:48:47 1999 by faith@valinux.com
15 *
16 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
17 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
18 * All Rights Reserved.
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining a
21 * copy of this software and associated documentation files (the "Software"),
22 * to deal in the Software without restriction, including without limitation
23 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
24 * and/or sell copies of the Software, and to permit persons to whom the
25 * Software is furnished to do so, subject to the following conditions:
26 *
27 * The above copyright notice and this permission notice (including the next
28 * paragraph) shall be included in all copies or substantial portions of the
29 * Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
34 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
35 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
36 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
37 * OTHER DEALINGS IN THE SOFTWARE.
38 */
39
28a62277 40#include <linux/seq_file.h>
1da177e4
LT
41#include "drmP.h"
42
28a62277
BG
43
44/***************************************************
45 * Initialization, etc.
46 **************************************************/
1da177e4
LT
47
48/**
49 * Proc file list.
50 */
28a62277 51static struct drm_info_list drm_proc_list[] = {
673a394b 52 {"name", drm_name_info, 0},
673a394b
EA
53 {"vm", drm_vm_info, 0},
54 {"clients", drm_clients_info, 0},
55 {"queues", drm_queues_info, 0},
56 {"bufs", drm_bufs_info, 0},
57 {"gem_names", drm_gem_name_info, DRIVER_GEM},
58 {"gem_objects", drm_gem_object_info, DRIVER_GEM},
1da177e4 59#if DRM_DEBUG_CODE
28a62277 60 {"vma", drm_vma_info, 0},
1da177e4
LT
61#endif
62};
8311d570 63#define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list)
1da177e4 64
28a62277
BG
65static int drm_proc_open(struct inode *inode, struct file *file)
66{
67 struct drm_info_node* node = PDE(inode)->data;
68
69 return single_open(file, node->info_ent->show, node);
70}
71
72static const struct file_operations drm_proc_fops = {
73 .owner = THIS_MODULE,
74 .open = drm_proc_open,
75 .read = seq_read,
76 .llseek = seq_lseek,
77 .release = single_release,
78};
79
80
1da177e4 81/**
28a62277 82 * Initialize a given set of proc files for a device
1da177e4 83 *
28a62277
BG
84 * \param files The array of files to create
85 * \param count The number of files given
1da177e4 86 * \param root DRI proc dir entry.
28a62277
BG
87 * \param minor device minor number
88 * \return Zero on success, non-zero on failure
b5e89ed5 89 *
28a62277
BG
90 * Create a given set of proc files represented by an array of
91 * gdm_proc_lists in the given root directory.
1da177e4 92 */
28a62277
BG
93int drm_proc_create_files(struct drm_info_list *files, int count,
94 struct proc_dir_entry *root, struct drm_minor *minor)
1da177e4 95{
673a394b 96 struct drm_device *dev = minor->dev;
1da177e4 97 struct proc_dir_entry *ent;
28a62277 98 struct drm_info_node *tmp;
b5e89ed5 99 char name[64];
28a62277 100 int i, ret;
1da177e4 101
28a62277
BG
102 for (i = 0; i < count; i++) {
103 u32 features = files[i].driver_features;
673a394b
EA
104
105 if (features != 0 &&
106 (dev->driver->driver_features & features) != features)
107 continue;
108
28a62277
BG
109 tmp = drm_alloc(sizeof(struct drm_info_node), _DRM_DRIVER);
110 ent = create_proc_entry(files[i].name, S_IFREG | S_IRUGO, root);
1da177e4
LT
111 if (!ent) {
112 DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
28a62277
BG
113 name, files[i].name);
114 drm_free(tmp, sizeof(struct drm_info_node),
115 _DRM_DRIVER);
673a394b
EA
116 ret = -1;
117 goto fail;
1da177e4 118 }
1da177e4 119
28a62277
BG
120 ent->proc_fops = &drm_proc_fops;
121 ent->data = tmp;
122 tmp->minor = minor;
123 tmp->info_ent = &files[i];
124 list_add(&(tmp->list), &(minor->proc_nodes.list));
673a394b 125 }
1da177e4 126 return 0;
673a394b 127
28a62277
BG
128fail:
129 for (i = 0; i < count; i++)
130 remove_proc_entry(drm_proc_list[i].name, minor->proc_root);
673a394b 131 return ret;
1da177e4
LT
132}
133
1da177e4 134/**
28a62277 135 * Initialize the DRI proc filesystem for a device
1da177e4 136 *
28a62277
BG
137 * \param dev DRM device
138 * \param minor device minor number
1da177e4 139 * \param root DRI proc dir entry.
28a62277
BG
140 * \param dev_root resulting DRI device proc dir entry.
141 * \return root entry pointer on success, or NULL on failure.
1da177e4 142 *
28a62277
BG
143 * Create the DRI proc root entry "/proc/dri", the device proc root entry
144 * "/proc/dri/%minor%/", and each entry in proc_list as
145 * "/proc/dri/%minor%/%name%".
1da177e4 146 */
28a62277
BG
147int drm_proc_init(struct drm_minor *minor, int minor_id,
148 struct proc_dir_entry *root)
1da177e4 149{
673a394b 150 struct drm_device *dev = minor->dev;
1da177e4 151 char name[64];
28a62277 152 int ret;
1da177e4 153
28a62277
BG
154 INIT_LIST_HEAD(&minor->proc_nodes.list);
155 sprintf(name, "%d", minor_id);
156 minor->proc_root = proc_mkdir(name, root);
157 if (!minor->proc_root) {
158 DRM_ERROR("Cannot create /proc/dri/%s\n", name);
159 return -1;
1da177e4
LT
160 }
161
28a62277
BG
162 ret = drm_proc_create_files(drm_proc_list, DRM_PROC_ENTRIES,
163 minor->proc_root, minor);
164 if (ret) {
165 remove_proc_entry(name, root);
166 minor->proc_root = NULL;
167 DRM_ERROR("Failed to create core drm proc files\n");
168 return ret;
1da177e4
LT
169 }
170
28a62277
BG
171 if (dev->driver->proc_init) {
172 ret = dev->driver->proc_init(minor);
173 if (ret) {
174 DRM_ERROR("DRM: Driver failed to initialize "
175 "/proc/dri.\n");
176 return ret;
1da177e4 177 }
1da177e4 178 }
28a62277 179 return 0;
1da177e4
LT
180}
181
28a62277
BG
182int drm_proc_remove_files(struct drm_info_list *files, int count,
183 struct drm_minor *minor)
1da177e4 184{
28a62277
BG
185 struct list_head *pos, *q;
186 struct drm_info_node *tmp;
b5e89ed5 187 int i;
1da177e4 188
28a62277
BG
189 for (i = 0; i < count; i++) {
190 list_for_each_safe(pos, q, &minor->proc_nodes.list) {
191 tmp = list_entry(pos, struct drm_info_node, list);
192 if (tmp->info_ent == &files[i]) {
193 remove_proc_entry(files[i].name,
194 minor->proc_root);
195 list_del(pos);
196 drm_free(tmp, sizeof(struct drm_info_node),
197 _DRM_DRIVER);
198 }
199 }
1da177e4 200 }
28a62277 201 return 0;
1da177e4
LT
202}
203
fede5c91 204/**
28a62277 205 * Cleanup the proc filesystem resources.
fede5c91 206 *
28a62277
BG
207 * \param minor device minor number.
208 * \param root DRI proc dir entry.
209 * \param dev_root DRI device proc dir entry.
210 * \return always zero.
b5e89ed5 211 *
28a62277 212 * Remove all proc entries created by proc_init().
1da177e4 213 */
28a62277 214int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root)
1da177e4 215{
2c14f28b 216 struct drm_device *dev = minor->dev;
28a62277 217 char name[64];
1da177e4 218
28a62277 219 if (!root || !minor->proc_root)
1da177e4 220 return 0;
1da177e4 221
28a62277
BG
222 if (dev->driver->proc_cleanup)
223 dev->driver->proc_cleanup(minor);
673a394b 224
28a62277 225 drm_proc_remove_files(drm_proc_list, DRM_PROC_ENTRIES, minor);
673a394b 226
28a62277
BG
227 sprintf(name, "%d", minor->index);
228 remove_proc_entry(name, root);
673a394b 229
673a394b
EA
230 return 0;
231}
232