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_ioctl.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * IOCTL processing for DRM |
| 4 | * |
| 5 | * \author Rickard E. (Rik) Faith <faith@valinux.com> |
| 6 | * \author Gareth Hughes <gareth@valinux.com> |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * Created: Fri Jan 8 09:01:26 1999 by faith@valinux.com |
| 11 | * |
| 12 | * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. |
| 13 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. |
| 14 | * All Rights Reserved. |
| 15 | * |
| 16 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 17 | * copy of this software and associated documentation files (the "Software"), |
| 18 | * to deal in the Software without restriction, including without limitation |
| 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 20 | * and/or sell copies of the Software, and to permit persons to whom the |
| 21 | * Software is furnished to do so, subject to the following conditions: |
| 22 | * |
| 23 | * The above copyright notice and this permission notice (including the next |
| 24 | * paragraph) shall be included in all copies or substantial portions of the |
| 25 | * Software. |
| 26 | * |
| 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 29 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 30 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 31 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 32 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 33 | * OTHER DEALINGS IN THE SOFTWARE. |
| 34 | */ |
| 35 | |
| 36 | #include "drmP.h" |
| 37 | #include "drm_core.h" |
| 38 | |
| 39 | #include "linux/pci.h" |
| 40 | |
| 41 | /** |
| 42 | * Get the bus id. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 43 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | * \param inode device inode. |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 45 | * \param file_priv DRM file private. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | * \param cmd command. |
| 47 | * \param arg user argument, pointing to a drm_unique structure. |
| 48 | * \return zero on success or a negative number on failure. |
| 49 | * |
| 50 | * Copies the bus id from drm_device::unique into user space. |
| 51 | */ |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 52 | int drm_getunique(struct inode *inode, struct drm_file *file_priv, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 53 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 55 | struct drm_device *dev = file_priv->head->dev; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 56 | struct drm_unique __user *argp = (void __user *)arg; |
| 57 | struct drm_unique u; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | if (copy_from_user(&u, argp, sizeof(u))) |
| 60 | return -EFAULT; |
| 61 | if (u.unique_len >= dev->unique_len) { |
| 62 | if (copy_to_user(u.unique, dev->unique, dev->unique_len)) |
| 63 | return -EFAULT; |
| 64 | } |
| 65 | u.unique_len = dev->unique_len; |
| 66 | if (copy_to_user(argp, &u, sizeof(u))) |
| 67 | return -EFAULT; |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Set the bus id. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 73 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | * \param inode device inode. |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 75 | * \param file_priv DRM file private. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | * \param cmd command. |
| 77 | * \param arg user argument, pointing to a drm_unique structure. |
| 78 | * \return zero on success or a negative number on failure. |
| 79 | * |
| 80 | * Copies the bus id from userspace into drm_device::unique, and verifies that |
| 81 | * it matches the device this DRM is attached to (EINVAL otherwise). Deprecated |
| 82 | * in interface version 1.1 and will return EBUSY when setversion has requested |
| 83 | * version 1.1 or greater. |
| 84 | */ |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 85 | int drm_setunique(struct inode *inode, struct drm_file *file_priv, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 86 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 88 | struct drm_device *dev = file_priv->head->dev; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 89 | struct drm_unique u; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 90 | int domain, bus, slot, func, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 92 | if (dev->unique_len || dev->unique) |
| 93 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 95 | if (copy_from_user(&u, (struct drm_unique __user *) arg, sizeof(u))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | return -EFAULT; |
| 97 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 98 | if (!u.unique_len || u.unique_len > 1024) |
| 99 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | dev->unique_len = u.unique_len; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 102 | dev->unique = drm_alloc(u.unique_len + 1, DRM_MEM_DRIVER); |
| 103 | if (!dev->unique) |
| 104 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | if (copy_from_user(dev->unique, u.unique, dev->unique_len)) |
| 106 | return -EFAULT; |
| 107 | |
| 108 | dev->unique[dev->unique_len] = '\0'; |
| 109 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 110 | dev->devname = |
| 111 | drm_alloc(strlen(dev->driver->pci_driver.name) + |
| 112 | strlen(dev->unique) + 2, DRM_MEM_DRIVER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | if (!dev->devname) |
| 114 | return -ENOMEM; |
| 115 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 116 | sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name, |
| 117 | dev->unique); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | /* Return error if the busid submitted doesn't match the device's actual |
| 120 | * busid. |
| 121 | */ |
| 122 | ret = sscanf(dev->unique, "PCI:%d:%d:%d", &bus, &slot, &func); |
| 123 | if (ret != 3) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 124 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | domain = bus >> 8; |
| 126 | bus &= 0xff; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 127 | |
Dave Airlie | 3322960 | 2006-08-07 20:23:42 +1000 | [diff] [blame] | 128 | if ((domain != drm_get_pci_domain(dev)) || |
Dave | 242ef0e | 2006-07-18 04:01:01 +1000 | [diff] [blame] | 129 | (bus != dev->pdev->bus->number) || |
| 130 | (slot != PCI_SLOT(dev->pdev->devfn)) || |
| 131 | (func != PCI_FUNC(dev->pdev->devfn))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | return -EINVAL; |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 137 | static int drm_set_busid(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 139 | int len; |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | if (dev->unique != NULL) |
Dave Airlie | 1f27ce6 | 2006-08-27 11:11:14 +1000 | [diff] [blame] | 142 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 144 | dev->unique_len = 40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | dev->unique = drm_alloc(dev->unique_len + 1, DRM_MEM_DRIVER); |
| 146 | if (dev->unique == NULL) |
Dave Airlie | 1f27ce6 | 2006-08-27 11:11:14 +1000 | [diff] [blame] | 147 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 149 | len = snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d", |
Dave Airlie | 3322960 | 2006-08-07 20:23:42 +1000 | [diff] [blame] | 150 | drm_get_pci_domain(dev), dev->pdev->bus->number, |
Dave | 242ef0e | 2006-07-18 04:01:01 +1000 | [diff] [blame] | 151 | PCI_SLOT(dev->pdev->devfn), |
| 152 | PCI_FUNC(dev->pdev->devfn)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 154 | if (len > dev->unique_len) |
| 155 | DRM_ERROR("Unique buffer overflowed\n"); |
| 156 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 157 | dev->devname = |
| 158 | drm_alloc(strlen(dev->driver->pci_driver.name) + dev->unique_len + |
| 159 | 2, DRM_MEM_DRIVER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | if (dev->devname == NULL) |
Dave Airlie | 1f27ce6 | 2006-08-27 11:11:14 +1000 | [diff] [blame] | 161 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 163 | sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name, |
| 164 | dev->unique); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | /** |
| 170 | * Get a mapping information. |
| 171 | * |
| 172 | * \param inode device inode. |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 173 | * \param file_priv DRM file private. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | * \param cmd command. |
| 175 | * \param arg user argument, pointing to a drm_map structure. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 176 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | * \return zero on success or a negative number on failure. |
| 178 | * |
| 179 | * Searches for the mapping with the specified offset and copies its information |
| 180 | * into userspace |
| 181 | */ |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 182 | int drm_getmap(struct inode *inode, struct drm_file *file_priv, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 183 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 185 | struct drm_device *dev = file_priv->head->dev; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 186 | struct drm_map __user *argp = (void __user *)arg; |
| 187 | struct drm_map map; |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 188 | struct drm_map_list *r_list = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | struct list_head *list; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 190 | int idx; |
| 191 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | if (copy_from_user(&map, argp, sizeof(map))) |
| 194 | return -EFAULT; |
| 195 | idx = map.offset; |
| 196 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 197 | mutex_lock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | if (idx < 0) { |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 199 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | return -EINVAL; |
| 201 | } |
| 202 | |
| 203 | i = 0; |
Dave Airlie | bd1b331 | 2007-05-26 05:01:51 +1000 | [diff] [blame] | 204 | list_for_each(list, &dev->maplist) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 205 | if (i == idx) { |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 206 | r_list = list_entry(list, struct drm_map_list, head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | break; |
| 208 | } |
| 209 | i++; |
| 210 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 211 | if (!r_list || !r_list->map) { |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 212 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | return -EINVAL; |
| 214 | } |
| 215 | |
| 216 | map.offset = r_list->map->offset; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 217 | map.size = r_list->map->size; |
| 218 | map.type = r_list->map->type; |
| 219 | map.flags = r_list->map->flags; |
| 220 | map.handle = (void *)(unsigned long)r_list->user_token; |
| 221 | map.mtrr = r_list->map->mtrr; |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 222 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 224 | if (copy_to_user(argp, &map, sizeof(map))) |
| 225 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Get client information. |
| 231 | * |
| 232 | * \param inode device inode. |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 233 | * \param file_priv DRM file private. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | * \param cmd command. |
| 235 | * \param arg user argument, pointing to a drm_client structure. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 236 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | * \return zero on success or a negative number on failure. |
| 238 | * |
| 239 | * Searches for the client with the specified index and copies its information |
| 240 | * into userspace |
| 241 | */ |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 242 | int drm_getclient(struct inode *inode, struct drm_file *file_priv, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 243 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 245 | struct drm_device *dev = file_priv->head->dev; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 246 | struct drm_client __user *argp = (struct drm_client __user *)arg; |
| 247 | struct drm_client client; |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 248 | struct drm_file *pt; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 249 | int idx; |
| 250 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | if (copy_from_user(&client, argp, sizeof(client))) |
| 253 | return -EFAULT; |
| 254 | idx = client.idx; |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 255 | mutex_lock(&dev->struct_mutex); |
Dave Airlie | bd1b331 | 2007-05-26 05:01:51 +1000 | [diff] [blame] | 256 | |
| 257 | if (list_empty(&dev->filelist)) { |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 258 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | return -EINVAL; |
| 260 | } |
Dave Airlie | bd1b331 | 2007-05-26 05:01:51 +1000 | [diff] [blame] | 261 | |
| 262 | i = 0; |
| 263 | list_for_each_entry(pt, &dev->filelist, lhead) { |
| 264 | if (i++ >= idx) |
| 265 | break; |
| 266 | } |
| 267 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 268 | client.auth = pt->authenticated; |
| 269 | client.pid = pt->pid; |
| 270 | client.uid = pt->uid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | client.magic = pt->magic; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 272 | client.iocs = pt->ioctl_count; |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 273 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 275 | if (copy_to_user(argp, &client, sizeof(client))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | return -EFAULT; |
| 277 | return 0; |
| 278 | } |
| 279 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 280 | /** |
| 281 | * Get statistics information. |
| 282 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | * \param inode device inode. |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 284 | * \param file_priv DRM file private. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | * \param cmd command. |
| 286 | * \param arg user argument, pointing to a drm_stats structure. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 287 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | * \return zero on success or a negative number on failure. |
| 289 | */ |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 290 | int drm_getstats(struct inode *inode, struct drm_file *file_priv, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 291 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 293 | struct drm_device *dev = file_priv->head->dev; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 294 | struct drm_stats stats; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 295 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
| 297 | memset(&stats, 0, sizeof(stats)); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 298 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 299 | mutex_lock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | for (i = 0; i < dev->counters; i++) { |
| 302 | if (dev->types[i] == _DRM_STAT_LOCK) |
| 303 | stats.data[i].value |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 304 | = (dev->lock.hw_lock ? dev->lock.hw_lock->lock : 0); |
| 305 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | stats.data[i].value = atomic_read(&dev->counts[i]); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 307 | stats.data[i].type = dev->types[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | stats.count = dev->counters; |
| 311 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 312 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 314 | if (copy_to_user((struct drm_stats __user *) arg, &stats, sizeof(stats))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | return -EFAULT; |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Setversion ioctl. |
| 321 | * |
| 322 | * \param inode device inode. |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 323 | * \param file_priv DRM file private. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | * \param cmd command. |
| 325 | * \param arg user argument, pointing to a drm_lock structure. |
| 326 | * \return zero on success or negative number on failure. |
| 327 | * |
| 328 | * Sets the requested interface version |
| 329 | */ |
| 330 | int drm_setversion(DRM_IOCTL_ARGS) |
| 331 | { |
| 332 | DRM_DEVICE; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 333 | struct drm_set_version sv; |
| 334 | struct drm_set_version retv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | int if_version; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 336 | struct drm_set_version __user *argp = (void __user *)data; |
Dave Airlie | 1f27ce6 | 2006-08-27 11:11:14 +1000 | [diff] [blame] | 337 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Dave Airlie | 3d77461 | 2006-08-07 20:07:43 +1000 | [diff] [blame] | 339 | if (copy_from_user(&sv, argp, sizeof(sv))) |
| 340 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | retv.drm_di_major = DRM_IF_MAJOR; |
| 343 | retv.drm_di_minor = DRM_IF_MINOR; |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 344 | retv.drm_dd_major = dev->driver->major; |
| 345 | retv.drm_dd_minor = dev->driver->minor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Dave Airlie | 1f27ce6 | 2006-08-27 11:11:14 +1000 | [diff] [blame] | 347 | if (copy_to_user(argp, &retv, sizeof(retv))) |
Dave Airlie | 3d77461 | 2006-08-07 20:07:43 +1000 | [diff] [blame] | 348 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
| 350 | if (sv.drm_di_major != -1) { |
| 351 | if (sv.drm_di_major != DRM_IF_MAJOR || |
| 352 | sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR) |
Dave Airlie | 1f27ce6 | 2006-08-27 11:11:14 +1000 | [diff] [blame] | 353 | return -EINVAL; |
Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 354 | if_version = DRM_IF_VERSION(sv.drm_di_major, sv.drm_di_minor); |
Dave Airlie | 3d77461 | 2006-08-07 20:07:43 +1000 | [diff] [blame] | 355 | dev->if_version = max(if_version, dev->if_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | if (sv.drm_di_minor >= 1) { |
| 357 | /* |
| 358 | * Version 1.1 includes tying of DRM to specific device |
| 359 | */ |
Dave Airlie | 1f27ce6 | 2006-08-27 11:11:14 +1000 | [diff] [blame] | 360 | ret = drm_set_busid(dev); |
| 361 | if (ret) |
| 362 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
| 366 | if (sv.drm_dd_major != -1) { |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 367 | if (sv.drm_dd_major != dev->driver->major || |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 368 | sv.drm_dd_minor < 0 |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 369 | || sv.drm_dd_minor > dev->driver->minor) |
Dave Airlie | 1f27ce6 | 2006-08-27 11:11:14 +1000 | [diff] [blame] | 370 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
| 372 | if (dev->driver->set_version) |
| 373 | dev->driver->set_version(dev, &sv); |
| 374 | } |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | /** No-op ioctl. */ |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame^] | 379 | int drm_noop(struct inode *inode, struct drm_file *file_priv, unsigned int cmd, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 380 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
| 382 | DRM_DEBUG("\n"); |
| 383 | return 0; |
| 384 | } |