]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/char/drm/drm_ioctl.c
drm: remove remnants of DRM_COPY_FROM/TO_USER_IOCTL
[mirror_ubuntu-artful-kernel.git] / drivers / char / drm / drm_ioctl.c
CommitLineData
1da177e4 1/**
b5e89ed5 2 * \file drm_ioctl.c
1da177e4
LT
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.
b5e89ed5 43 *
1da177e4 44 * \param inode device inode.
6c340eac 45 * \param file_priv DRM file private.
1da177e4
LT
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 */
c153f45f
EA
52int drm_getunique(struct drm_device *dev, void *data,
53 struct drm_file *file_priv)
1da177e4 54{
c153f45f 55 struct drm_unique *u = data;
1da177e4 56
c153f45f
EA
57 if (u->unique_len >= dev->unique_len) {
58 if (copy_to_user(u->unique, dev->unique, dev->unique_len))
1da177e4
LT
59 return -EFAULT;
60 }
c153f45f
EA
61 u->unique_len = dev->unique_len;
62
1da177e4
LT
63 return 0;
64}
65
66/**
67 * Set the bus id.
b5e89ed5 68 *
1da177e4 69 * \param inode device inode.
6c340eac 70 * \param file_priv DRM file private.
1da177e4
LT
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 */
c153f45f
EA
80int drm_setunique(struct drm_device *dev, void *data,
81 struct drm_file *file_priv)
1da177e4 82{
c153f45f 83 struct drm_unique *u = data;
b5e89ed5 84 int domain, bus, slot, func, ret;
1da177e4 85
b5e89ed5
DA
86 if (dev->unique_len || dev->unique)
87 return -EBUSY;
1da177e4 88
c153f45f 89 if (!u->unique_len || u->unique_len > 1024)
b5e89ed5 90 return -EINVAL;
1da177e4 91
c153f45f
EA
92 dev->unique_len = u->unique_len;
93 dev->unique = drm_alloc(u->unique_len + 1, DRM_MEM_DRIVER);
b5e89ed5
DA
94 if (!dev->unique)
95 return -ENOMEM;
c153f45f 96 if (copy_from_user(dev->unique, u->unique, dev->unique_len))
1da177e4
LT
97 return -EFAULT;
98
99 dev->unique[dev->unique_len] = '\0';
100
b5e89ed5
DA
101 dev->devname =
102 drm_alloc(strlen(dev->driver->pci_driver.name) +
103 strlen(dev->unique) + 2, DRM_MEM_DRIVER);
1da177e4
LT
104 if (!dev->devname)
105 return -ENOMEM;
106
b5e89ed5
DA
107 sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
108 dev->unique);
1da177e4
LT
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)
20caafa6 115 return -EINVAL;
1da177e4
LT
116 domain = bus >> 8;
117 bus &= 0xff;
b5e89ed5 118
33229601 119 if ((domain != drm_get_pci_domain(dev)) ||
242ef0e1
D
120 (bus != dev->pdev->bus->number) ||
121 (slot != PCI_SLOT(dev->pdev->devfn)) ||
122 (func != PCI_FUNC(dev->pdev->devfn)))
1da177e4
LT
123 return -EINVAL;
124
125 return 0;
126}
127
84b1fd10 128static int drm_set_busid(struct drm_device * dev)
1da177e4 129{
fe34765b
DA
130 int len;
131
1da177e4 132 if (dev->unique != NULL)
1f27ce6a 133 return 0;
1da177e4 134
fe34765b 135 dev->unique_len = 40;
1da177e4
LT
136 dev->unique = drm_alloc(dev->unique_len + 1, DRM_MEM_DRIVER);
137 if (dev->unique == NULL)
1f27ce6a 138 return -ENOMEM;
1da177e4 139
fe34765b 140 len = snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d",
33229601 141 drm_get_pci_domain(dev), dev->pdev->bus->number,
242ef0e1
D
142 PCI_SLOT(dev->pdev->devfn),
143 PCI_FUNC(dev->pdev->devfn));
1da177e4 144
fe34765b
DA
145 if (len > dev->unique_len)
146 DRM_ERROR("Unique buffer overflowed\n");
147
b5e89ed5
DA
148 dev->devname =
149 drm_alloc(strlen(dev->driver->pci_driver.name) + dev->unique_len +
150 2, DRM_MEM_DRIVER);
1da177e4 151 if (dev->devname == NULL)
1f27ce6a 152 return -ENOMEM;
1da177e4 153
b5e89ed5
DA
154 sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
155 dev->unique);
1da177e4
LT
156
157 return 0;
158}
159
1da177e4
LT
160/**
161 * Get a mapping information.
162 *
163 * \param inode device inode.
6c340eac 164 * \param file_priv DRM file private.
1da177e4
LT
165 * \param cmd command.
166 * \param arg user argument, pointing to a drm_map structure.
b5e89ed5 167 *
1da177e4
LT
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 */
c153f45f
EA
173int drm_getmap(struct drm_device *dev, void *data,
174 struct drm_file *file_priv)
1da177e4 175{
c153f45f 176 struct drm_map *map = data;
55910517 177 struct drm_map_list *r_list = NULL;
1da177e4 178 struct list_head *list;
b5e89ed5
DA
179 int idx;
180 int i;
1da177e4 181
c153f45f 182 idx = map->offset;
1da177e4 183
30e2fb18 184 mutex_lock(&dev->struct_mutex);
1da177e4 185 if (idx < 0) {
30e2fb18 186 mutex_unlock(&dev->struct_mutex);
1da177e4
LT
187 return -EINVAL;
188 }
189
190 i = 0;
bd1b331f 191 list_for_each(list, &dev->maplist) {
b5e89ed5 192 if (i == idx) {
55910517 193 r_list = list_entry(list, struct drm_map_list, head);
1da177e4
LT
194 break;
195 }
196 i++;
197 }
b5e89ed5 198 if (!r_list || !r_list->map) {
30e2fb18 199 mutex_unlock(&dev->struct_mutex);
1da177e4
LT
200 return -EINVAL;
201 }
202
c153f45f
EA
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;
30e2fb18 209 mutex_unlock(&dev->struct_mutex);
1da177e4 210
1da177e4
LT
211 return 0;
212}
213
214/**
215 * Get client information.
216 *
217 * \param inode device inode.
6c340eac 218 * \param file_priv DRM file private.
1da177e4
LT
219 * \param cmd command.
220 * \param arg user argument, pointing to a drm_client structure.
b5e89ed5 221 *
1da177e4
LT
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 */
c153f45f
EA
227int drm_getclient(struct drm_device *dev, void *data,
228 struct drm_file *file_priv)
1da177e4 229{
c153f45f 230 struct drm_client *client = data;
84b1fd10 231 struct drm_file *pt;
b5e89ed5
DA
232 int idx;
233 int i;
1da177e4 234
c153f45f 235 idx = client->idx;
30e2fb18 236 mutex_lock(&dev->struct_mutex);
bd1b331f
DA
237
238 if (list_empty(&dev->filelist)) {
30e2fb18 239 mutex_unlock(&dev->struct_mutex);
1da177e4
LT
240 return -EINVAL;
241 }
bd1b331f
DA
242
243 i = 0;
244 list_for_each_entry(pt, &dev->filelist, lhead) {
245 if (i++ >= idx)
246 break;
247 }
248
c153f45f
EA
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;
30e2fb18 254 mutex_unlock(&dev->struct_mutex);
1da177e4 255
1da177e4
LT
256 return 0;
257}
258
b5e89ed5
DA
259/**
260 * Get statistics information.
261 *
1da177e4 262 * \param inode device inode.
6c340eac 263 * \param file_priv DRM file private.
1da177e4
LT
264 * \param cmd command.
265 * \param arg user argument, pointing to a drm_stats structure.
b5e89ed5 266 *
1da177e4
LT
267 * \return zero on success or a negative number on failure.
268 */
c153f45f
EA
269int drm_getstats(struct drm_device *dev, void *data,
270 struct drm_file *file_priv)
1da177e4 271{
c153f45f 272 struct drm_stats *stats = data;
b5e89ed5 273 int i;
1da177e4 274
c153f45f 275 memset(stats, 0, sizeof(stats));
b5e89ed5 276
30e2fb18 277 mutex_lock(&dev->struct_mutex);
1da177e4
LT
278
279 for (i = 0; i < dev->counters; i++) {
280 if (dev->types[i] == _DRM_STAT_LOCK)
c153f45f
EA
281 stats->data[i].value =
282 (dev->lock.hw_lock ? dev->lock.hw_lock->lock : 0);
b5e89ed5 283 else
c153f45f
EA
284 stats->data[i].value = atomic_read(&dev->counts[i]);
285 stats->data[i].type = dev->types[i];
1da177e4 286 }
b5e89ed5 287
c153f45f 288 stats->count = dev->counters;
1da177e4 289
30e2fb18 290 mutex_unlock(&dev->struct_mutex);
1da177e4 291
1da177e4
LT
292 return 0;
293}
294
295/**
296 * Setversion ioctl.
297 *
298 * \param inode device inode.
6c340eac 299 * \param file_priv DRM file private.
1da177e4
LT
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 */
c153f45f 306int drm_setversion(struct drm_device *dev, void *data, struct drm_file *file_priv)
1da177e4 307{
c153f45f
EA
308 struct drm_set_version *sv = data;
309 int if_version, retcode = 0;
310
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);
3d77461e 319 dev->if_version = max(if_version, dev->if_version);
c153f45f 320 if (sv->drm_di_minor >= 1) {
1da177e4
LT
321 /*
322 * Version 1.1 includes tying of DRM to specific device
323 */
c153f45f 324 drm_set_busid(dev);
1da177e4
LT
325 }
326 }
327
c153f45f
EA
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 }
1da177e4
LT
335
336 if (dev->driver->set_version)
c153f45f 337 dev->driver->set_version(dev, sv);
1da177e4 338 }
c153f45f
EA
339
340done:
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;
1da177e4
LT
347}
348
349/** No-op ioctl. */
c153f45f
EA
350int drm_noop(struct drm_device *dev, void *data,
351 struct drm_file *file_priv)
1da177e4
LT
352{
353 DRM_DEBUG("\n");
354 return 0;
355}