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