1 /* drm_ioctl.h -- IOCTL processing for DRM -*- linux-c -*-
2 * Created: Fri Jan 8 09:01:26 1999 by faith@valinux.com
5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
29 * Rickard E. (Rik) Faith <faith@valinux.com>
30 * Gareth Hughes <gareth@valinux.com>
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;
70 DRM_COPY_FROM_USER_IOCTL( u, (drm_unique_t *)data, sizeof(u) );
72 /* Check and copy in the submitted Bus ID */
73 if (!u.unique_len || u.unique_len > 1024)
74 return DRM_ERR(EINVAL);
76 busid = malloc(u.unique_len + 1, M_DRM, M_WAITOK);
78 return DRM_ERR(ENOMEM);
80 if (DRM_COPY_FROM_USER(busid, u.unique, u.unique_len)) {
82 return DRM_ERR(EFAULT);
84 busid[u.unique_len] = '\0';
86 /* Return error if the busid submitted doesn't match the device's actual
89 ret = sscanf(busid, "PCI:%d:%d:%d", &bus, &slot, &func);
92 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)) {
102 return DRM_ERR(EINVAL);
105 /* Actually set the device's busid now. */
107 if (dev->unique_len || dev->unique) {
109 return DRM_ERR(EBUSY);
112 dev->unique_len = u.unique_len;
121 drm_set_busid(drm_device_t *dev)
126 if (dev->unique != NULL) {
131 dev->unique_len = 20;
132 dev->unique = malloc(dev->unique_len + 1, M_DRM, M_NOWAIT);
133 if (dev->unique == NULL) {
138 snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%1x",
139 dev->pci_domain, dev->pci_bus, dev->pci_slot, dev->pci_func);
146 int drm_getmap(DRM_IOCTL_ARGS)
150 drm_local_map_t *mapinlist;
154 DRM_COPY_FROM_USER_IOCTL( map, (drm_map_t *)data, sizeof(map) );
161 return DRM_ERR(EINVAL);
164 TAILQ_FOREACH(mapinlist, &dev->maplist, link) {
166 map.offset = mapinlist->offset;
167 map.size = mapinlist->size;
168 map.type = mapinlist->type;
169 map.flags = mapinlist->flags;
170 map.handle = mapinlist->handle;
171 map.mtrr = mapinlist->mtrr;
179 if (mapinlist == NULL)
182 DRM_COPY_TO_USER_IOCTL( (drm_map_t *)data, map, sizeof(map) );
187 int drm_getclient(DRM_IOCTL_ARGS)
195 DRM_COPY_FROM_USER_IOCTL( client, (drm_client_t *)data, sizeof(client) );
199 TAILQ_FOREACH(pt, &dev->files, link) {
202 client.auth = pt->authenticated;
203 client.pid = pt->pid;
204 client.uid = pt->uid;
205 client.magic = pt->magic;
206 client.iocs = pt->ioctl_count;
209 *(drm_client_t *)data = client;
216 DRM_COPY_TO_USER_IOCTL( (drm_client_t *)data, client, sizeof(client) );
221 int drm_getstats(DRM_IOCTL_ARGS)
227 memset(&stats, 0, sizeof(stats));
231 for (i = 0; i < dev->counters; i++) {
232 if (dev->types[i] == _DRM_STAT_LOCK)
235 ? dev->lock.hw_lock->lock : 0);
237 stats.data[i].value = atomic_read(&dev->counts[i]);
238 stats.data[i].type = dev->types[i];
241 stats.count = dev->counters;
245 DRM_COPY_TO_USER_IOCTL( (drm_stats_t *)data, stats, sizeof(stats) );
250 #define DRM_IF_MAJOR 1
251 #define DRM_IF_MINOR 2
253 int drm_setversion(DRM_IOCTL_ARGS)
256 drm_set_version_t sv;
257 drm_set_version_t retv;
260 DRM_COPY_FROM_USER_IOCTL(sv, (drm_set_version_t *)data, sizeof(sv));
262 retv.drm_di_major = DRM_IF_MAJOR;
263 retv.drm_di_minor = DRM_IF_MINOR;
264 retv.drm_dd_major = dev->driver.major;
265 retv.drm_dd_minor = dev->driver.minor;
267 DRM_COPY_TO_USER_IOCTL((drm_set_version_t *)data, retv, sizeof(sv));
269 if (sv.drm_di_major != -1) {
270 if (sv.drm_di_major != DRM_IF_MAJOR ||
271 sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR)
273 if_version = DRM_IF_VERSION(sv.drm_di_major, sv.drm_dd_minor);
274 dev->if_version = DRM_MAX(if_version, dev->if_version);
275 if (sv.drm_di_minor >= 1) {
277 * Version 1.1 includes tying of DRM to specific device
283 if (sv.drm_dd_major != -1) {
284 if (sv.drm_dd_major != dev->driver.major ||
285 sv.drm_dd_minor < 0 || sv.drm_dd_minor > dev->driver.minor)
292 int drm_noop(DRM_IOCTL_ARGS)