Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /** |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2 | * \file drm_proc.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 40 | #include <linux/seq_file.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 41 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include "drmP.h" |
| 43 | |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 44 | /*************************************************** |
| 45 | * Initialization, etc. |
| 46 | **************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Proc file list. |
| 50 | */ |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 51 | static struct drm_info_list drm_proc_list[] = { |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 52 | {"name", drm_name_info, 0}, |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 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}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #if DRM_DEBUG_CODE |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 60 | {"vma", drm_vma_info, 0}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #endif |
| 62 | }; |
Ahmed S. Darwish | 8311d57 | 2007-02-09 10:30:10 +1100 | [diff] [blame] | 63 | #define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 65 | static 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 | |
| 72 | static 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | /** |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 82 | * Initialize a given set of proc files for a device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | * |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 84 | * \param files The array of files to create |
| 85 | * \param count The number of files given |
| 86 | * \param root DRI proc dir entry. |
| 87 | * \param minor device minor number |
| 88 | * \return Zero on success, non-zero on failure |
| 89 | * |
| 90 | * Create a given set of proc files represented by an array of |
| 91 | * gdm_proc_lists in the given root directory. |
| 92 | */ |
| 93 | int drm_proc_create_files(struct drm_info_list *files, int count, |
| 94 | struct proc_dir_entry *root, struct drm_minor *minor) |
| 95 | { |
| 96 | struct drm_device *dev = minor->dev; |
| 97 | struct proc_dir_entry *ent; |
| 98 | struct drm_info_node *tmp; |
| 99 | char name[64]; |
| 100 | int i, ret; |
| 101 | |
| 102 | for (i = 0; i < count; i++) { |
| 103 | u32 features = files[i].driver_features; |
| 104 | |
| 105 | if (features != 0 && |
| 106 | (dev->driver->driver_features & features) != features) |
| 107 | continue; |
| 108 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 109 | tmp = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL); |
Roel Kluin | 1ae7007 | 2009-08-29 22:20:34 +0200 | [diff] [blame] | 110 | if (tmp == NULL) { |
| 111 | ret = -1; |
| 112 | goto fail; |
| 113 | } |
Alexey Dobriyan | 3b51096 | 2009-08-28 22:58:07 +0400 | [diff] [blame] | 114 | tmp->minor = minor; |
| 115 | tmp->info_ent = &files[i]; |
| 116 | list_add(&tmp->list, &minor->proc_nodes.list); |
| 117 | |
| 118 | ent = proc_create_data(files[i].name, S_IRUGO, root, |
| 119 | &drm_proc_fops, tmp); |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 120 | if (!ent) { |
| 121 | DRM_ERROR("Cannot create /proc/dri/%s/%s\n", |
| 122 | name, files[i].name); |
Alexey Dobriyan | 3b51096 | 2009-08-28 22:58:07 +0400 | [diff] [blame] | 123 | list_del(&tmp->list); |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 124 | kfree(tmp); |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 125 | ret = -1; |
| 126 | goto fail; |
| 127 | } |
| 128 | |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 129 | } |
| 130 | return 0; |
| 131 | |
| 132 | fail: |
| 133 | for (i = 0; i < count; i++) |
| 134 | remove_proc_entry(drm_proc_list[i].name, minor->proc_root); |
| 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Initialize the DRI proc filesystem for a device |
| 140 | * |
| 141 | * \param dev DRM device |
| 142 | * \param minor device minor number |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | * \param root DRI proc dir entry. |
| 144 | * \param dev_root resulting DRI device proc dir entry. |
| 145 | * \return root entry pointer on success, or NULL on failure. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 146 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | * Create the DRI proc root entry "/proc/dri", the device proc root entry |
| 148 | * "/proc/dri/%minor%/", and each entry in proc_list as |
| 149 | * "/proc/dri/%minor%/%name%". |
| 150 | */ |
Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 151 | int drm_proc_init(struct drm_minor *minor, int minor_id, |
| 152 | struct proc_dir_entry *root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 154 | char name[64]; |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 155 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 157 | INIT_LIST_HEAD(&minor->proc_nodes.list); |
Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 158 | sprintf(name, "%d", minor_id); |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 159 | minor->proc_root = proc_mkdir(name, root); |
| 160 | if (!minor->proc_root) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | DRM_ERROR("Cannot create /proc/dri/%s\n", name); |
| 162 | return -1; |
| 163 | } |
| 164 | |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 165 | ret = drm_proc_create_files(drm_proc_list, DRM_PROC_ENTRIES, |
| 166 | minor->proc_root, minor); |
| 167 | if (ret) { |
| 168 | remove_proc_entry(name, root); |
| 169 | minor->proc_root = NULL; |
| 170 | DRM_ERROR("Failed to create core drm proc files\n"); |
| 171 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | return 0; |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 175 | } |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 176 | |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 177 | int drm_proc_remove_files(struct drm_info_list *files, int count, |
| 178 | struct drm_minor *minor) |
| 179 | { |
| 180 | struct list_head *pos, *q; |
| 181 | struct drm_info_node *tmp; |
| 182 | int i; |
| 183 | |
| 184 | for (i = 0; i < count; i++) { |
| 185 | list_for_each_safe(pos, q, &minor->proc_nodes.list) { |
| 186 | tmp = list_entry(pos, struct drm_info_node, list); |
| 187 | if (tmp->info_ent == &files[i]) { |
| 188 | remove_proc_entry(files[i].name, |
| 189 | minor->proc_root); |
| 190 | list_del(pos); |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 191 | kfree(tmp); |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | } |
| 195 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | /** |
| 199 | * Cleanup the proc filesystem resources. |
| 200 | * |
| 201 | * \param minor device minor number. |
| 202 | * \param root DRI proc dir entry. |
| 203 | * \param dev_root DRI device proc dir entry. |
| 204 | * \return always zero. |
| 205 | * |
| 206 | * Remove all proc entries created by proc_init(). |
| 207 | */ |
Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 208 | int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | char name[64]; |
| 211 | |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 212 | if (!root || !minor->proc_root) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 213 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 215 | drm_proc_remove_files(drm_proc_list, DRM_PROC_ENTRIES, minor); |
| 216 | |
Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 217 | sprintf(name, "%d", minor->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | remove_proc_entry(name, root); |
| 219 | |
| 220 | return 0; |
| 221 | } |
| 222 | |