Merge branch 'topic/pcm-subclass-fix' into for-linus
[deliverable/linux.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
955b12de 40#include <linux/seq_file.h>
1da177e4
LT
41#include "drmP.h"
42
955b12de
BG
43/***************************************************
44 * Initialization, etc.
45 **************************************************/
1da177e4
LT
46
47/**
48 * Proc file list.
49 */
955b12de 50static struct drm_info_list drm_proc_list[] = {
673a394b 51 {"name", drm_name_info, 0},
673a394b
EA
52 {"vm", drm_vm_info, 0},
53 {"clients", drm_clients_info, 0},
54 {"queues", drm_queues_info, 0},
55 {"bufs", drm_bufs_info, 0},
56 {"gem_names", drm_gem_name_info, DRIVER_GEM},
57 {"gem_objects", drm_gem_object_info, DRIVER_GEM},
1da177e4 58#if DRM_DEBUG_CODE
955b12de 59 {"vma", drm_vma_info, 0},
1da177e4
LT
60#endif
61};
8311d570 62#define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list)
1da177e4 63
955b12de
BG
64static int drm_proc_open(struct inode *inode, struct file *file)
65{
66 struct drm_info_node* node = PDE(inode)->data;
67
68 return single_open(file, node->info_ent->show, node);
69}
70
71static const struct file_operations drm_proc_fops = {
72 .owner = THIS_MODULE,
73 .open = drm_proc_open,
74 .read = seq_read,
75 .llseek = seq_lseek,
76 .release = single_release,
77};
78
79
1da177e4 80/**
955b12de 81 * Initialize a given set of proc files for a device
1da177e4 82 *
955b12de
BG
83 * \param files The array of files to create
84 * \param count The number of files given
1da177e4 85 * \param root DRI proc dir entry.
955b12de
BG
86 * \param minor device minor number
87 * \return Zero on success, non-zero on failure
b5e89ed5 88 *
955b12de
BG
89 * Create a given set of proc files represented by an array of
90 * gdm_proc_lists in the given root directory.
1da177e4 91 */
955b12de
BG
92int drm_proc_create_files(struct drm_info_list *files, int count,
93 struct proc_dir_entry *root, struct drm_minor *minor)
1da177e4 94{
673a394b 95 struct drm_device *dev = minor->dev;
1da177e4 96 struct proc_dir_entry *ent;
955b12de 97 struct drm_info_node *tmp;
b5e89ed5 98 char name[64];
955b12de 99 int i, ret;
1da177e4 100
955b12de
BG
101 for (i = 0; i < count; i++) {
102 u32 features = files[i].driver_features;
673a394b
EA
103
104 if (features != 0 &&
105 (dev->driver->driver_features & features) != features)
106 continue;
107
955b12de
BG
108 tmp = drm_alloc(sizeof(struct drm_info_node), _DRM_DRIVER);
109 ent = create_proc_entry(files[i].name, S_IFREG | S_IRUGO, root);
1da177e4
LT
110 if (!ent) {
111 DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
955b12de
BG
112 name, files[i].name);
113 drm_free(tmp, sizeof(struct drm_info_node),
114 _DRM_DRIVER);
673a394b
EA
115 ret = -1;
116 goto fail;
1da177e4 117 }
1da177e4 118
955b12de
BG
119 ent->proc_fops = &drm_proc_fops;
120 ent->data = tmp;
121 tmp->minor = minor;
122 tmp->info_ent = &files[i];
123 list_add(&(tmp->list), &(minor->proc_nodes.list));
673a394b 124 }
1da177e4 125 return 0;
673a394b 126
955b12de
BG
127fail:
128 for (i = 0; i < count; i++)
129 remove_proc_entry(drm_proc_list[i].name, minor->proc_root);
673a394b 130 return ret;
1da177e4
LT
131}
132
1da177e4 133/**
955b12de 134 * Initialize the DRI proc filesystem for a device
1da177e4 135 *
955b12de
BG
136 * \param dev DRM device
137 * \param minor device minor number
1da177e4 138 * \param root DRI proc dir entry.
955b12de
BG
139 * \param dev_root resulting DRI device proc dir entry.
140 * \return root entry pointer on success, or NULL on failure.
1da177e4 141 *
955b12de
BG
142 * Create the DRI proc root entry "/proc/dri", the device proc root entry
143 * "/proc/dri/%minor%/", and each entry in proc_list as
144 * "/proc/dri/%minor%/%name%".
1da177e4 145 */
955b12de
BG
146int drm_proc_init(struct drm_minor *minor, int minor_id,
147 struct proc_dir_entry *root)
1da177e4 148{
673a394b 149 struct drm_device *dev = minor->dev;
1da177e4 150 char name[64];
955b12de 151 int ret;
1da177e4 152
955b12de
BG
153 INIT_LIST_HEAD(&minor->proc_nodes.list);
154 sprintf(name, "%d", minor_id);
155 minor->proc_root = proc_mkdir(name, root);
156 if (!minor->proc_root) {
157 DRM_ERROR("Cannot create /proc/dri/%s\n", name);
158 return -1;
1da177e4
LT
159 }
160
955b12de
BG
161 ret = drm_proc_create_files(drm_proc_list, DRM_PROC_ENTRIES,
162 minor->proc_root, minor);
163 if (ret) {
164 remove_proc_entry(name, root);
165 minor->proc_root = NULL;
166 DRM_ERROR("Failed to create core drm proc files\n");
167 return ret;
1da177e4
LT
168 }
169
955b12de
BG
170 if (dev->driver->proc_init) {
171 ret = dev->driver->proc_init(minor);
172 if (ret) {
173 DRM_ERROR("DRM: Driver failed to initialize "
174 "/proc/dri.\n");
175 return ret;
1da177e4 176 }
1da177e4 177 }
955b12de 178 return 0;
1da177e4
LT
179}
180
955b12de
BG
181int drm_proc_remove_files(struct drm_info_list *files, int count,
182 struct drm_minor *minor)
1da177e4 183{
955b12de
BG
184 struct list_head *pos, *q;
185 struct drm_info_node *tmp;
b5e89ed5 186 int i;
1da177e4 187
955b12de
BG
188 for (i = 0; i < count; i++) {
189 list_for_each_safe(pos, q, &minor->proc_nodes.list) {
190 tmp = list_entry(pos, struct drm_info_node, list);
191 if (tmp->info_ent == &files[i]) {
192 remove_proc_entry(files[i].name,
193 minor->proc_root);
194 list_del(pos);
195 drm_free(tmp, sizeof(struct drm_info_node),
196 _DRM_DRIVER);
197 }
198 }
1da177e4 199 }
955b12de 200 return 0;
1da177e4
LT
201}
202
fede5c91 203/**
955b12de 204 * Cleanup the proc filesystem resources.
fede5c91 205 *
955b12de
BG
206 * \param minor device minor number.
207 * \param root DRI proc dir entry.
208 * \param dev_root DRI device proc dir entry.
209 * \return always zero.
b5e89ed5 210 *
955b12de 211 * Remove all proc entries created by proc_init().
1da177e4 212 */
955b12de 213int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root)
1da177e4 214{
2c14f28b 215 struct drm_device *dev = minor->dev;
955b12de 216 char name[64];
1da177e4 217
955b12de 218 if (!root || !minor->proc_root)
1da177e4 219 return 0;
1da177e4 220
955b12de
BG
221 if (dev->driver->proc_cleanup)
222 dev->driver->proc_cleanup(minor);
673a394b 223
955b12de 224 drm_proc_remove_files(drm_proc_list, DRM_PROC_ENTRIES, minor);
673a394b 225
955b12de
BG
226 sprintf(name, "%d", minor->index);
227 remove_proc_entry(name, root);
673a394b 228
673a394b
EA
229 return 0;
230}
231
This page took 0.428502 seconds and 5 git commands to generate.