3 * IOCTL processing for DRM
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
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
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.
39 #include "linux/pci.h"
44 * \param inode device inode.
45 * \param file_priv DRM file private.
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;
57 if (u->unique_len >= dev->unique_len) {
58 if (copy_to_user(u->unique, dev->unique, dev->unique_len))
61 u->unique_len = dev->unique_len;
69 * \param inode device inode.
70 * \param file_priv DRM file private.
72 * \param arg user argument, pointing to a drm_unique structure.
73 * \return zero on success or a negative number on failure.
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.
80 int drm_setunique(struct drm_device *dev, void *data,
81 struct drm_file *file_priv)
83 struct drm_unique *u = data;
84 int domain, bus, slot, func, ret;
86 if (dev->unique_len || dev->unique)
89 if (!u->unique_len || u->unique_len > 1024)
92 dev->unique_len = u->unique_len;
93 dev->unique = drm_alloc(u->unique_len + 1, DRM_MEM_DRIVER);
96 if (copy_from_user(dev->unique, u->unique, dev->unique_len))
99 dev->unique[dev->unique_len] = '\0';
102 drm_alloc(strlen(dev->driver->pci_driver.name) +
103 strlen(dev->unique) + 2, DRM_MEM_DRIVER);
107 sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
110 /* Return error if the busid submitted doesn't match the device's actual
113 ret = sscanf(dev->unique, "PCI:%d:%d:%d", &bus, &slot, &func);
119 if ((domain != drm_get_pci_domain(dev)) ||
120 (bus != dev->pdev->bus->number) ||
121 (slot != PCI_SLOT(dev->pdev->devfn)) ||
122 (func != PCI_FUNC(dev->pdev->devfn)))
128 static int drm_set_busid(struct drm_device * dev)
132 if (dev->unique != NULL)
135 dev->unique_len = 40;
136 dev->unique = drm_alloc(dev->unique_len + 1, DRM_MEM_DRIVER);
137 if (dev->unique == NULL)
140 len = snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d",
141 drm_get_pci_domain(dev), dev->pdev->bus->number,
142 PCI_SLOT(dev->pdev->devfn),
143 PCI_FUNC(dev->pdev->devfn));
145 if (len > dev->unique_len)
146 DRM_ERROR("Unique buffer overflowed\n");
149 drm_alloc(strlen(dev->driver->pci_driver.name) + dev->unique_len +
151 if (dev->devname == NULL)
154 sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
161 * Get a mapping information.
163 * \param inode device inode.
164 * \param file_priv DRM file private.
165 * \param cmd command.
166 * \param arg user argument, pointing to a drm_map structure.
168 * \return zero on success or a negative number on failure.
170 * Searches for the mapping with the specified offset and copies its information
173 int drm_getmap(struct drm_device *dev, void *data,
174 struct drm_file *file_priv)
176 struct drm_map *map = data;
177 struct drm_map_list *r_list = NULL;
178 struct list_head *list;
184 mutex_lock(&dev->struct_mutex);
186 mutex_unlock(&dev->struct_mutex);
191 list_for_each(list, &dev->maplist) {
193 r_list = list_entry(list, struct drm_map_list, head);
198 if (!r_list || !r_list->map) {
199 mutex_unlock(&dev->struct_mutex);
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;
209 mutex_unlock(&dev->struct_mutex);
215 * Get client information.
217 * \param inode device inode.
218 * \param file_priv DRM file private.
219 * \param cmd command.
220 * \param arg user argument, pointing to a drm_client structure.
222 * \return zero on success or a negative number on failure.
224 * Searches for the client with the specified index and copies its information
227 int drm_getclient(struct drm_device *dev, void *data,
228 struct drm_file *file_priv)
230 struct drm_client *client = data;
236 mutex_lock(&dev->struct_mutex);
238 if (list_empty(&dev->filelist)) {
239 mutex_unlock(&dev->struct_mutex);
244 list_for_each_entry(pt, &dev->filelist, lhead) {
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;
254 mutex_unlock(&dev->struct_mutex);
260 * Get statistics information.
262 * \param inode device inode.
263 * \param file_priv DRM file private.
264 * \param cmd command.
265 * \param arg user argument, pointing to a drm_stats structure.
267 * \return zero on success or a negative number on failure.
269 int drm_getstats(struct drm_device *dev, void *data,
270 struct drm_file *file_priv)
272 struct drm_stats *stats = data;
275 memset(stats, 0, sizeof(stats));
277 mutex_lock(&dev->struct_mutex);
279 for (i = 0; i < dev->counters; i++) {
280 if (dev->types[i] == _DRM_STAT_LOCK)
281 stats->data[i].value =
282 (dev->lock.hw_lock ? dev->lock.hw_lock->lock : 0);
284 stats->data[i].value = atomic_read(&dev->counts[i]);
285 stats->data[i].type = dev->types[i];
288 stats->count = dev->counters;
290 mutex_unlock(&dev->struct_mutex);
298 * \param inode device inode.
299 * \param file_priv DRM file private.
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.
304 * Sets the requested interface version
306 int drm_setversion(struct drm_device *dev, void *data, struct drm_file *file_priv)
308 struct drm_set_version *sv = data;
309 int if_version, retcode = 0;
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) {
317 if_version = DRM_IF_VERSION(sv->drm_di_major,
319 dev->if_version = max(if_version, dev->if_version);
320 if (sv->drm_di_minor >= 1) {
322 * Version 1.1 includes tying of DRM to specific device
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) {
336 if (dev->driver->set_version)
337 dev->driver->set_version(dev, sv);
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;
350 int drm_noop(struct drm_device *dev, void *data,
351 struct drm_file *file_priv)