Staging: netwave: delete the driver
[linux/fpc-iii.git] / drivers / gpu / drm / drm_ioctl.c
blob9b9ff46c2378b8601661e8dacbd176f7e40d979d
1 /**
2 * \file drm_ioctl.c
3 * IOCTL processing for DRM
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
7 */
9 /*
10 * Created: Fri Jan 8 09:01:26 1999 by faith@valinux.com
12 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
13 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
14 * All Rights Reserved.
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:
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.
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.
36 #include "drmP.h"
37 #include "drm_core.h"
39 #include "linux/pci.h"
41 /**
42 * Get the bus id.
44 * \param inode device inode.
45 * \param file_priv DRM file private.
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.
50 * Copies the bus id from drm_device::unique into user space.
52 int drm_getunique(struct drm_device *dev, void *data,
53 struct drm_file *file_priv)
55 struct drm_unique *u = data;
56 struct drm_master *master = file_priv->master;
58 if (u->unique_len >= master->unique_len) {
59 if (copy_to_user(u->unique, master->unique, master->unique_len))
60 return -EFAULT;
62 u->unique_len = master->unique_len;
64 return 0;
67 /**
68 * Set the bus id.
70 * \param inode device inode.
71 * \param file_priv DRM file private.
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.
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.
81 int drm_setunique(struct drm_device *dev, void *data,
82 struct drm_file *file_priv)
84 struct drm_unique *u = data;
85 struct drm_master *master = file_priv->master;
86 int domain, bus, slot, func, ret;
88 if (master->unique_len || master->unique)
89 return -EBUSY;
91 if (!u->unique_len || u->unique_len > 1024)
92 return -EINVAL;
94 master->unique_len = u->unique_len;
95 master->unique_size = u->unique_len + 1;
96 master->unique = kmalloc(master->unique_size, GFP_KERNEL);
97 if (!master->unique)
98 return -ENOMEM;
99 if (copy_from_user(master->unique, u->unique, master->unique_len))
100 return -EFAULT;
102 master->unique[master->unique_len] = '\0';
104 dev->devname = kmalloc(strlen(dev->driver->pci_driver.name) +
105 strlen(master->unique) + 2, GFP_KERNEL);
106 if (!dev->devname)
107 return -ENOMEM;
109 sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
110 master->unique);
112 /* Return error if the busid submitted doesn't match the device's actual
113 * busid.
115 ret = sscanf(master->unique, "PCI:%d:%d:%d", &bus, &slot, &func);
116 if (ret != 3)
117 return -EINVAL;
118 domain = bus >> 8;
119 bus &= 0xff;
121 if ((domain != drm_get_pci_domain(dev)) ||
122 (bus != dev->pdev->bus->number) ||
123 (slot != PCI_SLOT(dev->pdev->devfn)) ||
124 (func != PCI_FUNC(dev->pdev->devfn)))
125 return -EINVAL;
127 return 0;
130 static int drm_set_busid(struct drm_device *dev, struct drm_file *file_priv)
132 struct drm_master *master = file_priv->master;
133 int len;
135 if (master->unique != NULL)
136 return -EBUSY;
138 master->unique_len = 40;
139 master->unique_size = master->unique_len;
140 master->unique = kmalloc(master->unique_size, GFP_KERNEL);
141 if (master->unique == NULL)
142 return -ENOMEM;
144 len = snprintf(master->unique, master->unique_len, "pci:%04x:%02x:%02x.%d",
145 drm_get_pci_domain(dev),
146 dev->pdev->bus->number,
147 PCI_SLOT(dev->pdev->devfn),
148 PCI_FUNC(dev->pdev->devfn));
149 if (len >= master->unique_len)
150 DRM_ERROR("buffer overflow");
151 else
152 master->unique_len = len;
154 dev->devname = kmalloc(strlen(dev->driver->pci_driver.name) +
155 master->unique_len + 2, GFP_KERNEL);
156 if (dev->devname == NULL)
157 return -ENOMEM;
159 sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
160 master->unique);
162 return 0;
166 * Get a mapping information.
168 * \param inode device inode.
169 * \param file_priv DRM file private.
170 * \param cmd command.
171 * \param arg user argument, pointing to a drm_map structure.
173 * \return zero on success or a negative number on failure.
175 * Searches for the mapping with the specified offset and copies its information
176 * into userspace
178 int drm_getmap(struct drm_device *dev, void *data,
179 struct drm_file *file_priv)
181 struct drm_map *map = data;
182 struct drm_map_list *r_list = NULL;
183 struct list_head *list;
184 int idx;
185 int i;
187 idx = map->offset;
189 mutex_lock(&dev->struct_mutex);
190 if (idx < 0) {
191 mutex_unlock(&dev->struct_mutex);
192 return -EINVAL;
195 i = 0;
196 list_for_each(list, &dev->maplist) {
197 if (i == idx) {
198 r_list = list_entry(list, struct drm_map_list, head);
199 break;
201 i++;
203 if (!r_list || !r_list->map) {
204 mutex_unlock(&dev->struct_mutex);
205 return -EINVAL;
208 map->offset = r_list->map->offset;
209 map->size = r_list->map->size;
210 map->type = r_list->map->type;
211 map->flags = r_list->map->flags;
212 map->handle = (void *)(unsigned long) r_list->user_token;
213 map->mtrr = r_list->map->mtrr;
214 mutex_unlock(&dev->struct_mutex);
216 return 0;
220 * Get client information.
222 * \param inode device inode.
223 * \param file_priv DRM file private.
224 * \param cmd command.
225 * \param arg user argument, pointing to a drm_client structure.
227 * \return zero on success or a negative number on failure.
229 * Searches for the client with the specified index and copies its information
230 * into userspace
232 int drm_getclient(struct drm_device *dev, void *data,
233 struct drm_file *file_priv)
235 struct drm_client *client = data;
236 struct drm_file *pt;
237 int idx;
238 int i;
240 idx = client->idx;
241 mutex_lock(&dev->struct_mutex);
243 i = 0;
244 list_for_each_entry(pt, &dev->filelist, lhead) {
245 if (i++ >= idx) {
246 client->auth = pt->authenticated;
247 client->pid = pt->pid;
248 client->uid = pt->uid;
249 client->magic = pt->magic;
250 client->iocs = pt->ioctl_count;
251 mutex_unlock(&dev->struct_mutex);
253 return 0;
256 mutex_unlock(&dev->struct_mutex);
258 return -EINVAL;
262 * Get statistics information.
264 * \param inode device inode.
265 * \param file_priv DRM file private.
266 * \param cmd command.
267 * \param arg user argument, pointing to a drm_stats structure.
269 * \return zero on success or a negative number on failure.
271 int drm_getstats(struct drm_device *dev, void *data,
272 struct drm_file *file_priv)
274 struct drm_stats *stats = data;
275 int i;
277 memset(stats, 0, sizeof(*stats));
279 mutex_lock(&dev->struct_mutex);
281 for (i = 0; i < dev->counters; i++) {
282 if (dev->types[i] == _DRM_STAT_LOCK)
283 stats->data[i].value =
284 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
285 else
286 stats->data[i].value = atomic_read(&dev->counts[i]);
287 stats->data[i].type = dev->types[i];
290 stats->count = dev->counters;
292 mutex_unlock(&dev->struct_mutex);
294 return 0;
298 * Setversion ioctl.
300 * \param inode device inode.
301 * \param file_priv DRM file private.
302 * \param cmd command.
303 * \param arg user argument, pointing to a drm_lock structure.
304 * \return zero on success or negative number on failure.
306 * Sets the requested interface version
308 int drm_setversion(struct drm_device *dev, void *data, struct drm_file *file_priv)
310 struct drm_set_version *sv = data;
311 int if_version, retcode = 0;
313 if (sv->drm_di_major != -1) {
314 if (sv->drm_di_major != DRM_IF_MAJOR ||
315 sv->drm_di_minor < 0 || sv->drm_di_minor > DRM_IF_MINOR) {
316 retcode = -EINVAL;
317 goto done;
319 if_version = DRM_IF_VERSION(sv->drm_di_major,
320 sv->drm_di_minor);
321 dev->if_version = max(if_version, dev->if_version);
322 if (sv->drm_di_minor >= 1) {
324 * Version 1.1 includes tying of DRM to specific device
326 drm_set_busid(dev, file_priv);
330 if (sv->drm_dd_major != -1) {
331 if (sv->drm_dd_major != dev->driver->major ||
332 sv->drm_dd_minor < 0 || sv->drm_dd_minor >
333 dev->driver->minor) {
334 retcode = -EINVAL;
335 goto done;
338 if (dev->driver->set_version)
339 dev->driver->set_version(dev, sv);
342 done:
343 sv->drm_di_major = DRM_IF_MAJOR;
344 sv->drm_di_minor = DRM_IF_MINOR;
345 sv->drm_dd_major = dev->driver->major;
346 sv->drm_dd_minor = dev->driver->minor;
348 return retcode;
351 /** No-op ioctl. */
352 int drm_noop(struct drm_device *dev, void *data,
353 struct drm_file *file_priv)
355 DRM_DEBUG("\n");
356 return 0;