No empty .Rs/.Re
[netbsd-mini2440.git] / sys / external / bsd / drm / dist / bsd-core / drm_ioctl.c
blob28dd99720b46c2ddc30098feff0989688bc9da71
1 /*-
2 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
4 * All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
25 * Authors:
26 * Rickard E. (Rik) Faith <faith@valinux.com>
27 * Gareth Hughes <gareth@valinux.com>
31 /** @file drm_ioctl.c
32 * Varios minor DRM ioctls not applicable to other files, such as versioning
33 * information and reporting DRM information to userland.
36 #include "drmP.h"
39 * Beginning in revision 1.1 of the DRM interface, getunique will return
40 * a unique in the form pci:oooo:bb:dd.f (o=domain, b=bus, d=device, f=function)
41 * before setunique has been called. The format for the bus-specific part of
42 * the unique is not defined for any other bus.
44 int drm_getunique(struct drm_device *dev, void *data,
45 struct drm_file *file_priv)
47 struct drm_unique *u = data;
49 if (u->unique_len >= dev->unique_len) {
50 if (DRM_COPY_TO_USER(u->unique, dev->unique, dev->unique_len))
51 return EFAULT;
53 u->unique_len = dev->unique_len;
55 return 0;
58 /* Deprecated in DRM version 1.1, and will return EBUSY when setversion has
59 * requested version 1.1 or greater.
61 int drm_setunique(struct drm_device *dev, void *data,
62 struct drm_file *file_priv)
64 #if defined(__NetBSD__)
65 return EOPNOTSUPP;
66 #else
67 struct drm_unique *u = data;
68 int domain, bus, slot, func, ret;
69 char *busid;
71 /* Check and copy in the submitted Bus ID */
72 if (!u->unique_len || u->unique_len > 1024)
73 return EINVAL;
75 busid = malloc(u->unique_len + 1, DRM_MEM_DRIVER, M_WAITOK);
76 if (busid == NULL)
77 return ENOMEM;
79 if (DRM_COPY_FROM_USER(busid, u->unique, u->unique_len)) {
80 free(busid, DRM_MEM_DRIVER);
81 return EFAULT;
83 busid[u->unique_len] = '\0';
85 /* Return error if the busid submitted doesn't match the device's actual
86 * busid.
88 ret = sscanf(busid, "PCI:%d:%d:%d", &bus, &slot, &func);
89 if (ret != 3) {
90 free(busid, DRM_MEM_DRIVER);
91 return EINVAL;
93 domain = bus >> 8;
94 bus &= 0xff;
96 if ((domain != dev->pci_domain) ||
97 (bus != dev->pci_bus) ||
98 (slot != dev->pci_slot) ||
99 (func != dev->pci_func)) {
100 free(busid, DRM_MEM_DRIVER);
101 return EINVAL;
104 /* Actually set the device's busid now. */
105 DRM_LOCK();
106 if (dev->unique_len || dev->unique) {
107 DRM_UNLOCK();
108 return EBUSY;
111 dev->unique_len = u->unique_len;
112 dev->unique = busid;
113 DRM_UNLOCK();
115 return 0;
116 #endif
120 static int
121 drm_set_busid(struct drm_device *dev)
124 DRM_LOCK();
126 if (dev->unique != NULL) {
127 DRM_UNLOCK();
128 return EBUSY;
131 dev->unique_len = 20;
132 dev->unique = malloc(dev->unique_len + 1, DRM_MEM_DRIVER, M_NOWAIT);
133 if (dev->unique == NULL) {
134 DRM_UNLOCK();
135 return ENOMEM;
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);
141 DRM_UNLOCK();
143 return 0;
146 int drm_getmap(struct drm_device *dev, void *data, struct drm_file *file_priv)
148 struct drm_map *map = data;
149 drm_local_map_t *mapinlist;
150 int idx;
151 int i = 0;
153 idx = map->offset;
155 DRM_LOCK();
156 if (idx < 0) {
157 DRM_UNLOCK();
158 return EINVAL;
161 TAILQ_FOREACH(mapinlist, &dev->maplist, link) {
162 if (i == idx) {
163 map->offset = mapinlist->offset;
164 map->size = mapinlist->size;
165 map->type = mapinlist->type;
166 map->flags = mapinlist->flags;
167 map->handle = mapinlist->handle;
168 map->mtrr = mapinlist->mtrr;
169 break;
171 i++;
174 DRM_UNLOCK();
176 if (mapinlist == NULL)
177 return EINVAL;
179 return 0;
182 int drm_getclient(struct drm_device *dev, void *data,
183 struct drm_file *file_priv)
185 struct drm_client *client = data;
186 struct drm_file *pt;
187 int idx;
188 int i = 0;
190 idx = client->idx;
191 DRM_LOCK();
192 TAILQ_FOREACH(pt, &dev->files, link) {
193 if (i == idx) {
194 client->auth = pt->authenticated;
195 client->pid = pt->pid;
196 client->uid = pt->uid;
197 client->magic = pt->magic;
198 client->iocs = pt->ioctl_count;
199 DRM_UNLOCK();
200 return 0;
202 i++;
204 DRM_UNLOCK();
206 return EINVAL;
209 int drm_getstats(struct drm_device *dev, void *data, struct drm_file *file_priv)
211 struct drm_stats *stats = data;
212 int i;
214 memset(stats, 0, sizeof(struct drm_stats));
216 DRM_LOCK();
218 for (i = 0; i < dev->counters; i++) {
219 if (dev->types[i] == _DRM_STAT_LOCK)
220 stats->data[i].value =
221 (dev->lock.hw_lock ? dev->lock.hw_lock->lock : 0);
222 else
223 stats->data[i].value = atomic_read(&dev->counts[i]);
224 stats->data[i].type = dev->types[i];
227 stats->count = dev->counters;
229 DRM_UNLOCK();
231 return 0;
234 #define DRM_IF_MAJOR 1
235 #define DRM_IF_MINOR 2
237 int drm_setversion(struct drm_device *dev, void *data,
238 struct drm_file *file_priv)
240 struct drm_set_version *sv = data;
241 struct drm_set_version ver;
242 int if_version;
244 /* Save the incoming data, and set the response before continuing
245 * any further.
247 ver = *sv;
248 sv->drm_di_major = DRM_IF_MAJOR;
249 sv->drm_di_minor = DRM_IF_MINOR;
250 sv->drm_dd_major = dev->driver->major;
251 sv->drm_dd_minor = dev->driver->minor;
253 if (ver.drm_di_major != -1) {
254 if (ver.drm_di_major != DRM_IF_MAJOR ||
255 ver.drm_di_minor < 0 || ver.drm_di_minor > DRM_IF_MINOR) {
256 return EINVAL;
258 if_version = DRM_IF_VERSION(ver.drm_di_major,
259 ver.drm_dd_minor);
260 dev->if_version = DRM_MAX(if_version, dev->if_version);
261 if (ver.drm_di_minor >= 1) {
263 * Version 1.1 includes tying of DRM to specific device
265 drm_set_busid(dev);
269 if (ver.drm_dd_major != -1) {
270 if (ver.drm_dd_major != dev->driver->major ||
271 ver.drm_dd_minor < 0 ||
272 ver.drm_dd_minor > dev->driver->minor)
274 return EINVAL;
278 return 0;
282 int drm_noop(struct drm_device *dev, void *data, struct drm_file *file_priv)
284 DRM_DEBUG("\n");
285 return 0;