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>
35 #include "dev/drm/drmP.h"
38 * Beginning in revision 1.1 of the DRM interface, getunique will return
39 * a unique in the form pci:oooo:bb:dd.f (o=domain, b=bus, d=device, f=function)
40 * before setunique has been called. The format for the bus-specific part of
41 * the unique is not defined for any other bus.
43 int drm_getunique(DRM_IOCTL_ARGS)
48 DRM_COPY_FROM_USER_IOCTL( u, (drm_unique_t *)data, sizeof(u) );
50 if (u.unique_len >= dev->unique_len) {
51 if (DRM_COPY_TO_USER(u.unique, dev->unique, dev->unique_len))
52 return DRM_ERR(EFAULT);
54 u.unique_len = dev->unique_len;
56 DRM_COPY_TO_USER_IOCTL( (drm_unique_t *)data, u, sizeof(u) );
61 /* Deprecated in DRM version 1.1, and will return EBUSY when setversion has
62 * requested version 1.1 or greater.
64 int drm_setunique(DRM_IOCTL_ARGS)
68 int domain, bus, slot, func, ret;
71 DRM_COPY_FROM_USER_IOCTL( u, (drm_unique_t *)data, sizeof(u) );
73 /* Check and copy in the submitted Bus ID */
74 if (!u.unique_len || u.unique_len > 1024)
75 return DRM_ERR(EINVAL);
77 busid = malloc(u.unique_len + 1, M_DRM, M_WAITOK);
79 return DRM_ERR(ENOMEM);
81 if (DRM_COPY_FROM_USER(busid, u.unique, u.unique_len)) {
83 return DRM_ERR(EFAULT);
85 busid[u.unique_len] = '\0';
87 /* Return error if the busid submitted doesn't match the device's actual
90 ret = sscanf(busid, "PCI:%d:%d:%d", &bus, &slot, &func);
93 return DRM_ERR(EINVAL);
98 if ((domain != dev->pci_domain) ||
99 (bus != dev->pci_bus) ||
100 (slot != dev->pci_slot) ||
101 (func != dev->pci_func)) {
103 return DRM_ERR(EINVAL);
106 /* Actually set the device's busid now. */
108 if (dev->unique_len || dev->unique) {
110 return DRM_ERR(EBUSY);
113 dev->unique_len = u.unique_len;
122 drm_set_busid(drm_device_t *dev)
127 if (dev->unique != NULL) {
132 dev->unique_len = 20;
133 dev->unique = malloc(dev->unique_len + 1, M_DRM, M_NOWAIT);
134 if (dev->unique == NULL) {
139 snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%1x",
140 dev->pci_domain, dev->pci_bus, dev->pci_slot, dev->pci_func);
147 int drm_getmap(DRM_IOCTL_ARGS)
151 drm_local_map_t *mapinlist;
155 DRM_COPY_FROM_USER_IOCTL( map, (drm_map_t *)data, sizeof(map) );
162 return DRM_ERR(EINVAL);
165 TAILQ_FOREACH(mapinlist, &dev->maplist, link) {
167 map.offset = mapinlist->offset;
168 map.size = mapinlist->size;
169 map.type = mapinlist->type;
170 map.flags = mapinlist->flags;
171 map.handle = mapinlist->handle;
172 map.mtrr = mapinlist->mtrr;
180 if (mapinlist == NULL)
183 DRM_COPY_TO_USER_IOCTL( (drm_map_t *)data, map, sizeof(map) );
188 int drm_getclient(DRM_IOCTL_ARGS)
196 DRM_COPY_FROM_USER_IOCTL( client, (drm_client_t *)data, sizeof(client) );
200 TAILQ_FOREACH(pt, &dev->files, link) {
203 client.auth = pt->authenticated;
204 client.pid = pt->pid;
205 client.uid = pt->uid;
206 client.magic = pt->magic;
207 client.iocs = pt->ioctl_count;
210 *(drm_client_t *)data = client;
217 DRM_COPY_TO_USER_IOCTL( (drm_client_t *)data, client, sizeof(client) );
222 int drm_getstats(DRM_IOCTL_ARGS)
228 memset(&stats, 0, sizeof(stats));
232 for (i = 0; i < dev->counters; i++) {
233 if (dev->types[i] == _DRM_STAT_LOCK)
236 ? dev->lock.hw_lock->lock : 0);
238 stats.data[i].value = atomic_read(&dev->counts[i]);
239 stats.data[i].type = dev->types[i];
242 stats.count = dev->counters;
246 DRM_COPY_TO_USER_IOCTL( (drm_stats_t *)data, stats, sizeof(stats) );
251 #define DRM_IF_MAJOR 1
252 #define DRM_IF_MINOR 2
254 int drm_setversion(DRM_IOCTL_ARGS)
257 drm_set_version_t sv;
258 drm_set_version_t retv;
261 DRM_COPY_FROM_USER_IOCTL(sv, (drm_set_version_t *)data, sizeof(sv));
263 retv.drm_di_major = DRM_IF_MAJOR;
264 retv.drm_di_minor = DRM_IF_MINOR;
265 retv.drm_dd_major = dev->driver_major;
266 retv.drm_dd_minor = dev->driver_minor;
268 DRM_COPY_TO_USER_IOCTL((drm_set_version_t *)data, retv, sizeof(sv));
270 if (sv.drm_di_major != -1) {
271 if (sv.drm_di_major != DRM_IF_MAJOR ||
272 sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR)
274 if_version = DRM_IF_VERSION(sv.drm_di_major, sv.drm_dd_minor);
275 dev->if_version = DRM_MAX(if_version, dev->if_version);
276 if (sv.drm_di_minor >= 1) {
278 * Version 1.1 includes tying of DRM to specific device
284 if (sv.drm_dd_major != -1) {
285 if (sv.drm_dd_major != dev->driver_major ||
286 sv.drm_dd_minor < 0 || sv.drm_dd_minor > dev->driver_minor)
293 int drm_noop(DRM_IOCTL_ARGS)