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. |
| 45 | * \param filp file pointer. |
| 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 | */ |
| 52 | int drm_getunique(struct inode *inode, struct file *filp, |
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 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 55 | drm_file_t *priv = filp->private_data; |
| 56 | drm_device_t *dev = priv->head->dev; |
| 57 | drm_unique_t __user *argp = (void __user *)arg; |
| 58 | drm_unique_t u; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | if (copy_from_user(&u, argp, sizeof(u))) |
| 61 | return -EFAULT; |
| 62 | if (u.unique_len >= dev->unique_len) { |
| 63 | if (copy_to_user(u.unique, dev->unique, dev->unique_len)) |
| 64 | return -EFAULT; |
| 65 | } |
| 66 | u.unique_len = dev->unique_len; |
| 67 | if (copy_to_user(argp, &u, sizeof(u))) |
| 68 | return -EFAULT; |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Set the bus id. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 74 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | * \param inode device inode. |
| 76 | * \param filp file pointer. |
| 77 | * \param cmd command. |
| 78 | * \param arg user argument, pointing to a drm_unique structure. |
| 79 | * \return zero on success or a negative number on failure. |
| 80 | * |
| 81 | * Copies the bus id from userspace into drm_device::unique, and verifies that |
| 82 | * it matches the device this DRM is attached to (EINVAL otherwise). Deprecated |
| 83 | * in interface version 1.1 and will return EBUSY when setversion has requested |
| 84 | * version 1.1 or greater. |
| 85 | */ |
| 86 | int drm_setunique(struct inode *inode, struct file *filp, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 87 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 89 | drm_file_t *priv = filp->private_data; |
| 90 | drm_device_t *dev = priv->head->dev; |
| 91 | drm_unique_t u; |
| 92 | int domain, bus, slot, func, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 94 | if (dev->unique_len || dev->unique) |
| 95 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 97 | if (copy_from_user(&u, (drm_unique_t __user *) arg, sizeof(u))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | return -EFAULT; |
| 99 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 100 | if (!u.unique_len || u.unique_len > 1024) |
| 101 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | dev->unique_len = u.unique_len; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 104 | dev->unique = drm_alloc(u.unique_len + 1, DRM_MEM_DRIVER); |
| 105 | if (!dev->unique) |
| 106 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | if (copy_from_user(dev->unique, u.unique, dev->unique_len)) |
| 108 | return -EFAULT; |
| 109 | |
| 110 | dev->unique[dev->unique_len] = '\0'; |
| 111 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 112 | dev->devname = |
| 113 | drm_alloc(strlen(dev->driver->pci_driver.name) + |
| 114 | strlen(dev->unique) + 2, DRM_MEM_DRIVER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | if (!dev->devname) |
| 116 | return -ENOMEM; |
| 117 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 118 | sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name, |
| 119 | dev->unique); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | /* Return error if the busid submitted doesn't match the device's actual |
| 122 | * busid. |
| 123 | */ |
| 124 | ret = sscanf(dev->unique, "PCI:%d:%d:%d", &bus, &slot, &func); |
| 125 | if (ret != 3) |
| 126 | return DRM_ERR(EINVAL); |
| 127 | domain = bus >> 8; |
| 128 | bus &= 0xff; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 129 | |
Dave Airlie | 3322960 | 2006-08-07 20:23:42 +1000 | [diff] [blame^] | 130 | if ((domain != drm_get_pci_domain(dev)) || |
Dave | 242ef0e | 2006-07-18 04:01:01 +1000 | [diff] [blame] | 131 | (bus != dev->pdev->bus->number) || |
| 132 | (slot != PCI_SLOT(dev->pdev->devfn)) || |
| 133 | (func != PCI_FUNC(dev->pdev->devfn))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | return -EINVAL; |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 139 | static int drm_set_busid(drm_device_t * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | { |
Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 141 | int len; |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | if (dev->unique != NULL) |
| 144 | return EBUSY; |
| 145 | |
Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 146 | dev->unique_len = 40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | dev->unique = drm_alloc(dev->unique_len + 1, DRM_MEM_DRIVER); |
| 148 | if (dev->unique == NULL) |
| 149 | return ENOMEM; |
| 150 | |
Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 151 | len = snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d", |
Dave Airlie | 3322960 | 2006-08-07 20:23:42 +1000 | [diff] [blame^] | 152 | drm_get_pci_domain(dev), dev->pdev->bus->number, |
Dave | 242ef0e | 2006-07-18 04:01:01 +1000 | [diff] [blame] | 153 | PCI_SLOT(dev->pdev->devfn), |
| 154 | PCI_FUNC(dev->pdev->devfn)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 156 | if (len > dev->unique_len) |
| 157 | DRM_ERROR("Unique buffer overflowed\n"); |
| 158 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 159 | dev->devname = |
| 160 | drm_alloc(strlen(dev->driver->pci_driver.name) + dev->unique_len + |
| 161 | 2, DRM_MEM_DRIVER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | if (dev->devname == NULL) |
| 163 | return ENOMEM; |
| 164 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 165 | sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name, |
| 166 | dev->unique); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | /** |
| 172 | * Get a mapping information. |
| 173 | * |
| 174 | * \param inode device inode. |
| 175 | * \param filp file pointer. |
| 176 | * \param cmd command. |
| 177 | * \param arg user argument, pointing to a drm_map structure. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 178 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | * \return zero on success or a negative number on failure. |
| 180 | * |
| 181 | * Searches for the mapping with the specified offset and copies its information |
| 182 | * into userspace |
| 183 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 184 | int drm_getmap(struct inode *inode, struct file *filp, |
| 185 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 187 | drm_file_t *priv = filp->private_data; |
| 188 | drm_device_t *dev = priv->head->dev; |
| 189 | drm_map_t __user *argp = (void __user *)arg; |
| 190 | drm_map_t map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | drm_map_list_t *r_list = NULL; |
| 192 | struct list_head *list; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 193 | int idx; |
| 194 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
| 196 | if (copy_from_user(&map, argp, sizeof(map))) |
| 197 | return -EFAULT; |
| 198 | idx = map.offset; |
| 199 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 200 | mutex_lock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | if (idx < 0) { |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 202 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | return -EINVAL; |
| 204 | } |
| 205 | |
| 206 | i = 0; |
| 207 | list_for_each(list, &dev->maplist->head) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 208 | if (i == idx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | r_list = list_entry(list, drm_map_list_t, head); |
| 210 | break; |
| 211 | } |
| 212 | i++; |
| 213 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 214 | if (!r_list || !r_list->map) { |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 215 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | return -EINVAL; |
| 217 | } |
| 218 | |
| 219 | map.offset = r_list->map->offset; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 220 | map.size = r_list->map->size; |
| 221 | map.type = r_list->map->type; |
| 222 | map.flags = r_list->map->flags; |
| 223 | map.handle = (void *)(unsigned long)r_list->user_token; |
| 224 | map.mtrr = r_list->map->mtrr; |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 225 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 227 | if (copy_to_user(argp, &map, sizeof(map))) |
| 228 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Get client information. |
| 234 | * |
| 235 | * \param inode device inode. |
| 236 | * \param filp file pointer. |
| 237 | * \param cmd command. |
| 238 | * \param arg user argument, pointing to a drm_client structure. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 239 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | * \return zero on success or a negative number on failure. |
| 241 | * |
| 242 | * Searches for the client with the specified index and copies its information |
| 243 | * into userspace |
| 244 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 245 | int drm_getclient(struct inode *inode, struct file *filp, |
| 246 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 248 | drm_file_t *priv = filp->private_data; |
| 249 | drm_device_t *dev = priv->head->dev; |
Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 250 | drm_client_t __user *argp = (drm_client_t __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | drm_client_t client; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 252 | drm_file_t *pt; |
| 253 | int idx; |
| 254 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
| 256 | if (copy_from_user(&client, argp, sizeof(client))) |
| 257 | return -EFAULT; |
| 258 | idx = client.idx; |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 259 | mutex_lock(&dev->struct_mutex); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 260 | for (i = 0, pt = dev->file_first; i < idx && pt; i++, pt = pt->next) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
| 262 | if (!pt) { |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 263 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | return -EINVAL; |
| 265 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 266 | client.auth = pt->authenticated; |
| 267 | client.pid = pt->pid; |
| 268 | client.uid = pt->uid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | client.magic = pt->magic; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 270 | client.iocs = pt->ioctl_count; |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 271 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 273 | if (copy_to_user(argp, &client, sizeof(client))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | return -EFAULT; |
| 275 | return 0; |
| 276 | } |
| 277 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 278 | /** |
| 279 | * Get statistics information. |
| 280 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | * \param inode device inode. |
| 282 | * \param filp file pointer. |
| 283 | * \param cmd command. |
| 284 | * \param arg user argument, pointing to a drm_stats structure. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 285 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | * \return zero on success or a negative number on failure. |
| 287 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 288 | int drm_getstats(struct inode *inode, struct file *filp, |
| 289 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 291 | drm_file_t *priv = filp->private_data; |
| 292 | drm_device_t *dev = priv->head->dev; |
| 293 | drm_stats_t stats; |
| 294 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
| 296 | memset(&stats, 0, sizeof(stats)); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 297 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 298 | mutex_lock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
| 300 | for (i = 0; i < dev->counters; i++) { |
| 301 | if (dev->types[i] == _DRM_STAT_LOCK) |
| 302 | stats.data[i].value |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 303 | = (dev->lock.hw_lock ? dev->lock.hw_lock->lock : 0); |
| 304 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | stats.data[i].value = atomic_read(&dev->counts[i]); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 306 | stats.data[i].type = dev->types[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | stats.count = dev->counters; |
| 310 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 311 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 313 | if (copy_to_user((drm_stats_t __user *) arg, &stats, sizeof(stats))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | return -EFAULT; |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * Setversion ioctl. |
| 320 | * |
| 321 | * \param inode device inode. |
| 322 | * \param filp file pointer. |
| 323 | * \param cmd command. |
| 324 | * \param arg user argument, pointing to a drm_lock structure. |
| 325 | * \return zero on success or negative number on failure. |
| 326 | * |
| 327 | * Sets the requested interface version |
| 328 | */ |
| 329 | int drm_setversion(DRM_IOCTL_ARGS) |
| 330 | { |
| 331 | DRM_DEVICE; |
| 332 | drm_set_version_t sv; |
| 333 | drm_set_version_t retv; |
| 334 | int if_version; |
| 335 | drm_set_version_t __user *argp = (void __user *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
Dave Airlie | 3d77461 | 2006-08-07 20:07:43 +1000 | [diff] [blame] | 337 | if (copy_from_user(&sv, argp, sizeof(sv))) |
| 338 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | retv.drm_di_major = DRM_IF_MAJOR; |
| 341 | retv.drm_di_minor = DRM_IF_MINOR; |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 342 | retv.drm_dd_major = dev->driver->major; |
| 343 | retv.drm_dd_minor = dev->driver->minor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
Dave Airlie | 3d77461 | 2006-08-07 20:07:43 +1000 | [diff] [blame] | 345 | if (copy_to_user(argp, &retv, sizeof(sv))) |
| 346 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
| 348 | if (sv.drm_di_major != -1) { |
| 349 | if (sv.drm_di_major != DRM_IF_MAJOR || |
| 350 | sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR) |
| 351 | return EINVAL; |
Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 352 | 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] | 353 | dev->if_version = max(if_version, dev->if_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | if (sv.drm_di_minor >= 1) { |
| 355 | /* |
| 356 | * Version 1.1 includes tying of DRM to specific device |
| 357 | */ |
| 358 | drm_set_busid(dev); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | if (sv.drm_dd_major != -1) { |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 363 | if (sv.drm_dd_major != dev->driver->major || |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 364 | sv.drm_dd_minor < 0 |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 365 | || sv.drm_dd_minor > dev->driver->minor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | return EINVAL; |
| 367 | |
| 368 | if (dev->driver->set_version) |
| 369 | dev->driver->set_version(dev, &sv); |
| 370 | } |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | /** No-op ioctl. */ |
| 375 | int drm_noop(struct inode *inode, struct file *filp, unsigned int cmd, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 376 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | { |
| 378 | DRM_DEBUG("\n"); |
| 379 | return 0; |
| 380 | } |