1 /* drm_ioctl.h -- IOCTL processing for DRM -*- linux-c -*-
2 * Created: Fri Jan 8 09:01:26 1999 by faith@valinux.com */
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
28 * Rickard E. (Rik) Faith <faith@valinux.com>
29 * Gareth Hughes <gareth@valinux.com>
34 #include "dev/drm/drmP.h"
37 * Beginning in revision 1.1 of the DRM interface, getunique will return
38 * a unique in the form pci:oooo:bb:dd.f (o=domain, b=bus, d=device, f=function)
39 * before setunique has been called. The format for the bus-specific part of
40 * the unique is not defined for any other bus.
42 int DRM(getunique)( DRM_IOCTL_ARGS )
47 DRM_COPY_FROM_USER_IOCTL( u, (drm_unique_t *)data, sizeof(u) );
49 if (u.unique_len >= dev->unique_len) {
50 if (DRM_COPY_TO_USER(u.unique, dev->unique, dev->unique_len))
51 return DRM_ERR(EFAULT);
53 u.unique_len = dev->unique_len;
55 DRM_COPY_TO_USER_IOCTL( (drm_unique_t *)data, u, sizeof(u) );
60 /* Deprecated in DRM version 1.1, and will return EBUSY when setversion has
61 * requested version 1.1 or greater.
63 int DRM(setunique)( DRM_IOCTL_ARGS )
67 int domain, bus, slot, func, ret;
69 if (dev->unique_len || dev->unique)
70 return DRM_ERR(EBUSY);
72 DRM_COPY_FROM_USER_IOCTL( u, (drm_unique_t *)data, sizeof(u) );
74 if (!u.unique_len || u.unique_len > 1024)
75 return DRM_ERR(EINVAL);
77 dev->unique_len = u.unique_len;
78 dev->unique = DRM(alloc)(u.unique_len + 1, DRM_MEM_DRIVER);
80 if (dev->unique == NULL)
81 return DRM_ERR(ENOMEM);
83 if (DRM_COPY_FROM_USER(dev->unique, u.unique, dev->unique_len))
84 return DRM_ERR(EFAULT);
86 dev->unique[dev->unique_len] = '\0';
88 /* Return error if the busid submitted doesn't match the device's actual
91 ret = sscanf(dev->unique, "PCI:%d:%d:%d", &bus, &slot, &func);
93 return DRM_ERR(EINVAL);
97 if ((domain != dev->pci_domain) ||
98 (bus != dev->pci_bus) ||
99 (slot != dev->pci_slot) ||
100 (func != dev->pci_func))
101 return DRM_ERR(EINVAL);
108 DRM(set_busid)(drm_device_t *dev)
111 if (dev->unique != NULL)
114 dev->unique_len = 20;
115 dev->unique = DRM(alloc)(dev->unique_len + 1, DRM_MEM_DRIVER);
116 if (dev->unique == NULL)
119 snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%1x",
120 dev->pci_domain, dev->pci_bus, dev->pci_slot, dev->pci_func);
125 int DRM(getmap)( DRM_IOCTL_ARGS )
129 drm_local_map_t *mapinlist;
130 drm_map_list_entry_t *list;
134 DRM_COPY_FROM_USER_IOCTL( map, (drm_map_t *)data, sizeof(map) );
141 return DRM_ERR(EINVAL);
144 TAILQ_FOREACH(list, dev->maplist, link) {
145 mapinlist = list->map;
147 map.offset = mapinlist->offset;
148 map.size = mapinlist->size;
149 map.type = mapinlist->type;
150 map.flags = mapinlist->flags;
151 map.handle = mapinlist->handle;
152 map.mtrr = mapinlist->mtrr;
163 DRM_COPY_TO_USER_IOCTL( (drm_map_t *)data, map, sizeof(map) );
168 int DRM(getclient)( DRM_IOCTL_ARGS )
176 DRM_COPY_FROM_USER_IOCTL( client, (drm_client_t *)data, sizeof(client) );
180 TAILQ_FOREACH(pt, &dev->files, link) {
183 client.auth = pt->authenticated;
184 client.pid = pt->pid;
185 client.uid = pt->uid;
186 client.magic = pt->magic;
187 client.iocs = pt->ioctl_count;
190 *(drm_client_t *)data = client;
197 DRM_COPY_TO_USER_IOCTL( (drm_client_t *)data, client, sizeof(client) );
202 int DRM(getstats)( DRM_IOCTL_ARGS )
208 memset(&stats, 0, sizeof(stats));
212 for (i = 0; i < dev->counters; i++) {
213 if (dev->types[i] == _DRM_STAT_LOCK)
216 ? dev->lock.hw_lock->lock : 0);
218 stats.data[i].value = atomic_read(&dev->counts[i]);
219 stats.data[i].type = dev->types[i];
222 stats.count = dev->counters;
226 DRM_COPY_TO_USER_IOCTL( (drm_stats_t *)data, stats, sizeof(stats) );
231 #define DRM_IF_MAJOR 1
232 #define DRM_IF_MINOR 2
234 int DRM(setversion)(DRM_IOCTL_ARGS)
237 drm_set_version_t sv;
238 drm_set_version_t retv;
241 DRM_COPY_FROM_USER_IOCTL(sv, (drm_set_version_t *)data, sizeof(sv));
243 retv.drm_di_major = DRM_IF_MAJOR;
244 retv.drm_di_minor = DRM_IF_MINOR;
245 retv.drm_dd_major = DRIVER_MAJOR;
246 retv.drm_dd_minor = DRIVER_MINOR;
248 DRM_COPY_TO_USER_IOCTL((drm_set_version_t *)data, retv, sizeof(sv));
250 if (sv.drm_di_major != -1) {
251 if (sv.drm_di_major != DRM_IF_MAJOR ||
252 sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR)
254 if_version = DRM_IF_VERSION(sv.drm_di_major, sv.drm_dd_minor);
255 dev->if_version = DRM_MAX(if_version, dev->if_version);
256 if (sv.drm_di_minor >= 1) {
258 * Version 1.1 includes tying of DRM to specific device
264 if (sv.drm_dd_major != -1) {
265 if (sv.drm_dd_major != DRIVER_MAJOR ||
266 sv.drm_dd_minor < 0 || sv.drm_dd_minor > DRIVER_MINOR)
268 #ifdef DRIVER_SETVERSION
269 DRIVER_SETVERSION(dev, &sv);
276 int DRM(noop)(DRM_IOCTL_ARGS)