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