3 * /proc support for DRM
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
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.
14 * Created: Mon Jan 11 09:48:47 1999 by faith@valinux.com
16 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
17 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
18 * All Rights Reserved.
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:
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
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.
40 #include <linux/seq_file.h>
43 /***************************************************
44 * Initialization, etc.
45 **************************************************/
50 static struct drm_info_list drm_proc_list[] = {
51 {"name", drm_name_info, 0},
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},
59 {"vma", drm_vma_info, 0},
62 #define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list)
64 static int drm_proc_open(struct inode *inode, struct file *file)
66 struct drm_info_node* node = PDE(inode)->data;
68 return single_open(file, node->info_ent->show, node);
71 static const struct file_operations drm_proc_fops = {
73 .open = drm_proc_open,
76 .release = single_release,
81 * Initialize a given set of proc files for a device
83 * \param files The array of files to create
84 * \param count The number of files given
85 * \param root DRI proc dir entry.
86 * \param minor device minor number
87 * \return Zero on success, non-zero on failure
89 * Create a given set of proc files represented by an array of
90 * gdm_proc_lists in the given root directory.
92 int drm_proc_create_files(struct drm_info_list *files, int count,
93 struct proc_dir_entry *root, struct drm_minor *minor)
95 struct drm_device *dev = minor->dev;
96 struct proc_dir_entry *ent;
97 struct drm_info_node *tmp;
101 for (i = 0; i < count; i++) {
102 u32 features = files[i].driver_features;
105 (dev->driver->driver_features & features) != features)
108 tmp = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
109 ent = create_proc_entry(files[i].name, S_IFREG | S_IRUGO, root);
111 DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
112 name, files[i].name);
118 ent->proc_fops = &drm_proc_fops;
121 tmp->info_ent = &files[i];
122 list_add(&(tmp->list), &(minor->proc_nodes.list));
127 for (i = 0; i < count; i++)
128 remove_proc_entry(drm_proc_list[i].name, minor->proc_root);
133 * Initialize the DRI proc filesystem for a device
135 * \param dev DRM device
136 * \param minor device minor number
137 * \param root DRI proc dir entry.
138 * \param dev_root resulting DRI device proc dir entry.
139 * \return root entry pointer on success, or NULL on failure.
141 * Create the DRI proc root entry "/proc/dri", the device proc root entry
142 * "/proc/dri/%minor%/", and each entry in proc_list as
143 * "/proc/dri/%minor%/%name%".
145 int drm_proc_init(struct drm_minor *minor, int minor_id,
146 struct proc_dir_entry *root)
148 struct drm_device *dev = minor->dev;
152 INIT_LIST_HEAD(&minor->proc_nodes.list);
153 sprintf(name, "%d", minor_id);
154 minor->proc_root = proc_mkdir(name, root);
155 if (!minor->proc_root) {
156 DRM_ERROR("Cannot create /proc/dri/%s\n", name);
160 ret = drm_proc_create_files(drm_proc_list, DRM_PROC_ENTRIES,
161 minor->proc_root, minor);
163 remove_proc_entry(name, root);
164 minor->proc_root = NULL;
165 DRM_ERROR("Failed to create core drm proc files\n");
169 if (dev->driver->proc_init) {
170 ret = dev->driver->proc_init(minor);
172 DRM_ERROR("DRM: Driver failed to initialize "
180 int drm_proc_remove_files(struct drm_info_list *files, int count,
181 struct drm_minor *minor)
183 struct list_head *pos, *q;
184 struct drm_info_node *tmp;
187 for (i = 0; i < count; i++) {
188 list_for_each_safe(pos, q, &minor->proc_nodes.list) {
189 tmp = list_entry(pos, struct drm_info_node, list);
190 if (tmp->info_ent == &files[i]) {
191 remove_proc_entry(files[i].name,
202 * Cleanup the proc filesystem resources.
204 * \param minor device minor number.
205 * \param root DRI proc dir entry.
206 * \param dev_root DRI device proc dir entry.
207 * \return always zero.
209 * Remove all proc entries created by proc_init().
211 int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root)
213 struct drm_device *dev = minor->dev;
216 if (!root || !minor->proc_root)
219 if (dev->driver->proc_cleanup)
220 dev->driver->proc_cleanup(minor);
222 drm_proc_remove_files(drm_proc_list, DRM_PROC_ENTRIES, minor);
224 sprintf(name, "%d", minor->index);
225 remove_proc_entry(name, root);