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>
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include "dev/drm/drmP.h"
40 * Beginning in revision 1.1 of the DRM interface, getunique will return
41 * a unique in the form pci:oooo:bb:dd.f (o=domain, b=bus, d=device, f=function)
42 * before setunique has been called. The format for the bus-specific part of
43 * the unique is not defined for any other bus.
45 int drm_getunique(DRM_IOCTL_ARGS)
50 DRM_COPY_FROM_USER_IOCTL( u, (drm_unique_t *)data, sizeof(u) );
52 if (u.unique_len >= dev->unique_len) {
53 if (DRM_COPY_TO_USER(u.unique, dev->unique, dev->unique_len))
54 return DRM_ERR(EFAULT);
56 u.unique_len = dev->unique_len;
58 DRM_COPY_TO_USER_IOCTL( (drm_unique_t *)data, u, sizeof(u) );
63 /* Deprecated in DRM version 1.1, and will return EBUSY when setversion has
64 * requested version 1.1 or greater.
66 int drm_setunique(DRM_IOCTL_ARGS)
70 int domain, bus, slot, func, ret;
73 DRM_COPY_FROM_USER_IOCTL( u, (drm_unique_t *)data, sizeof(u) );
75 /* Check and copy in the submitted Bus ID */
76 if (!u.unique_len || u.unique_len > 1024)
77 return DRM_ERR(EINVAL);
79 busid = malloc(u.unique_len + 1, M_DRM, M_WAITOK);
81 return DRM_ERR(ENOMEM);
83 if (DRM_COPY_FROM_USER(busid, u.unique, u.unique_len)) {
85 return DRM_ERR(EFAULT);
87 busid[u.unique_len] = '\0';
89 /* Return error if the busid submitted doesn't match the device's actual
92 ret = sscanf(busid, "PCI:%d:%d:%d", &bus, &slot, &func);
95 return DRM_ERR(EINVAL);
100 if ((domain != dev->pci_domain) ||
101 (bus != dev->pci_bus) ||
102 (slot != dev->pci_slot) ||
103 (func != dev->pci_func)) {
105 return DRM_ERR(EINVAL);
108 /* Actually set the device's busid now. */
110 if (dev->unique_len || dev->unique) {
112 return DRM_ERR(EBUSY);
115 dev->unique_len = u.unique_len;
124 drm_set_busid(drm_device_t *dev)
129 if (dev->unique != NULL) {
134 dev->unique_len = 20;
135 dev->unique = malloc(dev->unique_len + 1, M_DRM, M_NOWAIT);
136 if (dev->unique == NULL) {
141 snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%1x",
142 dev->pci_domain, dev->pci_bus, dev->pci_slot, dev->pci_func);
149 int drm_getmap(DRM_IOCTL_ARGS)
153 drm_local_map_t *mapinlist;
157 DRM_COPY_FROM_USER_IOCTL( map, (drm_map_t *)data, sizeof(map) );
164 return DRM_ERR(EINVAL);
167 TAILQ_FOREACH(mapinlist, &dev->maplist, link) {
169 map.offset = mapinlist->offset;
170 map.size = mapinlist->size;
171 map.type = mapinlist->type;
172 map.flags = mapinlist->flags;
173 map.handle = mapinlist->handle;
174 map.mtrr = mapinlist->mtrr;
182 if (mapinlist == NULL)
185 DRM_COPY_TO_USER_IOCTL( (drm_map_t *)data, map, sizeof(map) );
190 int drm_getclient(DRM_IOCTL_ARGS)
198 DRM_COPY_FROM_USER_IOCTL( client, (drm_client_t *)data, sizeof(client) );
202 TAILQ_FOREACH(pt, &dev->files, link) {
205 client.auth = pt->authenticated;
206 client.pid = pt->pid;
207 client.uid = pt->uid;
208 client.magic = pt->magic;
209 client.iocs = pt->ioctl_count;
212 *(drm_client_t *)data = client;
219 DRM_COPY_TO_USER_IOCTL( (drm_client_t *)data, client, sizeof(client) );
224 int drm_getstats(DRM_IOCTL_ARGS)
230 memset(&stats, 0, sizeof(stats));
234 for (i = 0; i < dev->counters; i++) {
235 if (dev->types[i] == _DRM_STAT_LOCK)
238 ? dev->lock.hw_lock->lock : 0);
240 stats.data[i].value = atomic_read(&dev->counts[i]);
241 stats.data[i].type = dev->types[i];
244 stats.count = dev->counters;
248 DRM_COPY_TO_USER_IOCTL( (drm_stats_t *)data, stats, sizeof(stats) );
253 #define DRM_IF_MAJOR 1
254 #define DRM_IF_MINOR 2
256 int drm_setversion(DRM_IOCTL_ARGS)
259 drm_set_version_t sv;
260 drm_set_version_t retv;
263 DRM_COPY_FROM_USER_IOCTL(sv, (drm_set_version_t *)data, sizeof(sv));
265 retv.drm_di_major = DRM_IF_MAJOR;
266 retv.drm_di_minor = DRM_IF_MINOR;
267 retv.drm_dd_major = dev->driver.major;
268 retv.drm_dd_minor = dev->driver.minor;
270 DRM_COPY_TO_USER_IOCTL((drm_set_version_t *)data, retv, sizeof(sv));
272 if (sv.drm_di_major != -1) {
273 if (sv.drm_di_major != DRM_IF_MAJOR ||
274 sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR)
276 if_version = DRM_IF_VERSION(sv.drm_di_major, sv.drm_dd_minor);
277 dev->if_version = DRM_MAX(if_version, dev->if_version);
278 if (sv.drm_di_minor >= 1) {
280 * Version 1.1 includes tying of DRM to specific device
286 if (sv.drm_dd_major != -1) {
287 if (sv.drm_dd_major != dev->driver.major ||
288 sv.drm_dd_minor < 0 || sv.drm_dd_minor > dev->driver.minor)
295 int drm_noop(DRM_IOCTL_ARGS)