| 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | 	if ((domain != dev->pci_domain) || | 
 | 131 | 	    (bus != dev->pci_bus) || | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 132 | 	    (slot != dev->pci_slot) || (func != dev->pci_func)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | 		return -EINVAL; | 
 | 134 |  | 
 | 135 | 	return 0; | 
 | 136 | } | 
 | 137 |  | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 138 | static int drm_set_busid(drm_device_t * dev) | 
| 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 | 	int len; | 
 | 141 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | 	if (dev->unique != NULL) | 
 | 143 | 		return EBUSY; | 
 | 144 |  | 
| Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 145 | 	dev->unique_len = 40; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | 	dev->unique = drm_alloc(dev->unique_len + 1, DRM_MEM_DRIVER); | 
 | 147 | 	if (dev->unique == NULL) | 
 | 148 | 		return ENOMEM; | 
 | 149 |  | 
| Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 150 | 	len = snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d", | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 151 | 		 dev->pci_domain, dev->pci_bus, dev->pci_slot, dev->pci_func); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 |  | 
| Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 153 | 	if (len > dev->unique_len) | 
 | 154 | 		DRM_ERROR("Unique buffer overflowed\n"); | 
 | 155 |  | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 156 | 	dev->devname = | 
 | 157 | 	    drm_alloc(strlen(dev->driver->pci_driver.name) + dev->unique_len + | 
 | 158 | 		      2, DRM_MEM_DRIVER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | 	if (dev->devname == NULL) | 
 | 160 | 		return ENOMEM; | 
 | 161 |  | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 162 | 	sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name, | 
 | 163 | 		dev->unique); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 |  | 
 | 165 | 	return 0; | 
 | 166 | } | 
 | 167 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | /** | 
 | 169 |  * Get a mapping information. | 
 | 170 |  * | 
 | 171 |  * \param inode device inode. | 
 | 172 |  * \param filp file pointer. | 
 | 173 |  * \param cmd command. | 
 | 174 |  * \param arg user argument, pointing to a drm_map structure. | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 175 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 |  * \return zero on success or a negative number on failure. | 
 | 177 |  * | 
 | 178 |  * Searches for the mapping with the specified offset and copies its information | 
 | 179 |  * into userspace | 
 | 180 |  */ | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 181 | int drm_getmap(struct inode *inode, struct file *filp, | 
 | 182 | 	       unsigned int cmd, unsigned long arg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 184 | 	drm_file_t *priv = filp->private_data; | 
 | 185 | 	drm_device_t *dev = priv->head->dev; | 
 | 186 | 	drm_map_t __user *argp = (void __user *)arg; | 
 | 187 | 	drm_map_t map; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | 	drm_map_list_t *r_list = NULL; | 
 | 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 |  | 
 | 197 | 	down(&dev->struct_sem); | 
 | 198 | 	if (idx < 0) { | 
 | 199 | 		up(&dev->struct_sem); | 
 | 200 | 		return -EINVAL; | 
 | 201 | 	} | 
 | 202 |  | 
 | 203 | 	i = 0; | 
 | 204 | 	list_for_each(list, &dev->maplist->head) { | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 205 | 		if (i == idx) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | 			r_list = list_entry(list, drm_map_list_t, head); | 
 | 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) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | 		up(&dev->struct_sem); | 
 | 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; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | 	up(&dev->struct_sem); | 
 | 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. | 
 | 233 |  * \param filp file pointer. | 
 | 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 |  */ | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 242 | int drm_getclient(struct inode *inode, struct file *filp, | 
 | 243 | 		  unsigned int cmd, unsigned long arg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 245 | 	drm_file_t *priv = filp->private_data; | 
 | 246 | 	drm_device_t *dev = priv->head->dev; | 
| Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 247 | 	drm_client_t __user *argp = (drm_client_t __user *)arg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | 	drm_client_t client; | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 249 | 	drm_file_t *pt; | 
 | 250 | 	int idx; | 
 | 251 | 	int i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 |  | 
 | 253 | 	if (copy_from_user(&client, argp, sizeof(client))) | 
 | 254 | 		return -EFAULT; | 
 | 255 | 	idx = client.idx; | 
 | 256 | 	down(&dev->struct_sem); | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 257 | 	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] | 258 |  | 
 | 259 | 	if (!pt) { | 
 | 260 | 		up(&dev->struct_sem); | 
 | 261 | 		return -EINVAL; | 
 | 262 | 	} | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 263 | 	client.auth = pt->authenticated; | 
 | 264 | 	client.pid = pt->pid; | 
 | 265 | 	client.uid = pt->uid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | 	client.magic = pt->magic; | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 267 | 	client.iocs = pt->ioctl_count; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | 	up(&dev->struct_sem); | 
 | 269 |  | 
| Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 270 | 	if (copy_to_user(argp, &client, sizeof(client))) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | 		return -EFAULT; | 
 | 272 | 	return 0; | 
 | 273 | } | 
 | 274 |  | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 275 | /** | 
 | 276 |  * Get statistics information. | 
 | 277 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 |  * \param inode device inode. | 
 | 279 |  * \param filp file pointer. | 
 | 280 |  * \param cmd command. | 
 | 281 |  * \param arg user argument, pointing to a drm_stats structure. | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 282 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 |  * \return zero on success or a negative number on failure. | 
 | 284 |  */ | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 285 | int drm_getstats(struct inode *inode, struct file *filp, | 
 | 286 | 		 unsigned int cmd, unsigned long arg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 288 | 	drm_file_t *priv = filp->private_data; | 
 | 289 | 	drm_device_t *dev = priv->head->dev; | 
 | 290 | 	drm_stats_t stats; | 
 | 291 | 	int i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 |  | 
 | 293 | 	memset(&stats, 0, sizeof(stats)); | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 294 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | 	down(&dev->struct_sem); | 
 | 296 |  | 
 | 297 | 	for (i = 0; i < dev->counters; i++) { | 
 | 298 | 		if (dev->types[i] == _DRM_STAT_LOCK) | 
 | 299 | 			stats.data[i].value | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 300 | 			    = (dev->lock.hw_lock ? dev->lock.hw_lock->lock : 0); | 
 | 301 | 		else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | 			stats.data[i].value = atomic_read(&dev->counts[i]); | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 303 | 		stats.data[i].type = dev->types[i]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | 	} | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 305 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | 	stats.count = dev->counters; | 
 | 307 |  | 
 | 308 | 	up(&dev->struct_sem); | 
 | 309 |  | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 310 | 	if (copy_to_user((drm_stats_t __user *) arg, &stats, sizeof(stats))) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | 		return -EFAULT; | 
 | 312 | 	return 0; | 
 | 313 | } | 
 | 314 |  | 
 | 315 | /** | 
 | 316 |  * Setversion ioctl. | 
 | 317 |  * | 
 | 318 |  * \param inode device inode. | 
 | 319 |  * \param filp file pointer. | 
 | 320 |  * \param cmd command. | 
 | 321 |  * \param arg user argument, pointing to a drm_lock structure. | 
 | 322 |  * \return zero on success or negative number on failure. | 
 | 323 |  * | 
 | 324 |  * Sets the requested interface version | 
 | 325 |  */ | 
 | 326 | int drm_setversion(DRM_IOCTL_ARGS) | 
 | 327 | { | 
 | 328 | 	DRM_DEVICE; | 
 | 329 | 	drm_set_version_t sv; | 
 | 330 | 	drm_set_version_t retv; | 
 | 331 | 	int if_version; | 
 | 332 | 	drm_set_version_t __user *argp = (void __user *)data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 |  | 
 | 334 | 	DRM_COPY_FROM_USER_IOCTL(sv, argp, sizeof(sv)); | 
 | 335 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | 	retv.drm_di_major = DRM_IF_MAJOR; | 
 | 337 | 	retv.drm_di_minor = DRM_IF_MINOR; | 
| Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 338 | 	retv.drm_dd_major = dev->driver->major; | 
 | 339 | 	retv.drm_dd_minor = dev->driver->minor; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 |  | 
 | 341 | 	DRM_COPY_TO_USER_IOCTL(argp, retv, sizeof(sv)); | 
 | 342 |  | 
 | 343 | 	if (sv.drm_di_major != -1) { | 
 | 344 | 		if (sv.drm_di_major != DRM_IF_MAJOR || | 
 | 345 | 		    sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR) | 
 | 346 | 			return EINVAL; | 
| Dave Airlie | fe34765 | 2006-01-02 21:19:39 +1100 | [diff] [blame] | 347 | 		if_version = DRM_IF_VERSION(sv.drm_di_major, sv.drm_di_minor); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | 		dev->if_version = DRM_MAX(if_version, dev->if_version); | 
 | 349 | 		if (sv.drm_di_minor >= 1) { | 
 | 350 | 			/* | 
 | 351 | 			 * Version 1.1 includes tying of DRM to specific device | 
 | 352 | 			 */ | 
 | 353 | 			drm_set_busid(dev); | 
 | 354 | 		} | 
 | 355 | 	} | 
 | 356 |  | 
 | 357 | 	if (sv.drm_dd_major != -1) { | 
| Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 358 | 		if (sv.drm_dd_major != dev->driver->major || | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 359 | 		    sv.drm_dd_minor < 0 | 
| Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 360 | 		    || sv.drm_dd_minor > dev->driver->minor) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | 			return EINVAL; | 
 | 362 |  | 
 | 363 | 		if (dev->driver->set_version) | 
 | 364 | 			dev->driver->set_version(dev, &sv); | 
 | 365 | 	} | 
 | 366 | 	return 0; | 
 | 367 | } | 
 | 368 |  | 
 | 369 | /** No-op ioctl. */ | 
 | 370 | int drm_noop(struct inode *inode, struct file *filp, unsigned int cmd, | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 371 | 	     unsigned long arg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | { | 
 | 373 | 	DRM_DEBUG("\n"); | 
 | 374 | 	return 0; | 
 | 375 | } |