2 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
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
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.
26 * Rickard E. (Rik) Faith <faith@valinux.com>
27 * Gareth Hughes <gareth@valinux.com>
29 * $FreeBSD: src/sys/dev/drm2/drm_ioctl.c,v 1.1 2012/05/22 11:07:44 kib Exp $
33 * Varios minor DRM ioctls not applicable to other files, such as versioning
34 * information and reporting DRM information to userland.
37 #include "dev/drm/drmP.h"
38 #include <dev/drm/drm_core.h>
41 * Beginning in revision 1.1 of the DRM interface, getunique will return
42 * a unique in the form pci:oooo:bb:dd.f (o=domain, b=bus, d=device, f=function)
43 * before setunique has been called. The format for the bus-specific part of
44 * the unique is not defined for any other bus.
46 int drm_getunique(struct drm_device *dev, void *data,
47 struct drm_file *file_priv)
49 struct drm_unique *u = data;
51 if (u->unique_len >= dev->unique_len) {
52 if (DRM_COPY_TO_USER(u->unique, dev->unique, dev->unique_len))
55 u->unique_len = dev->unique_len;
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(struct drm_device *dev, void *data,
64 struct drm_file *file_priv)
66 struct drm_unique *u = data;
67 int domain, bus, slot, func, ret;
70 /* Check and copy in the submitted Bus ID */
71 if (!u->unique_len || u->unique_len > 1024)
74 busid = kmalloc(u->unique_len + 1, DRM_MEM_DRIVER, M_WAITOK);
78 if (DRM_COPY_FROM_USER(busid, u->unique, u->unique_len)) {
79 drm_free(busid, DRM_MEM_DRIVER);
82 busid[u->unique_len] = '\0';
84 /* Return error if the busid submitted doesn't match the device's actual
87 ret = ksscanf(busid, "PCI:%d:%d:%d", &bus, &slot, &func);
89 drm_free(busid, DRM_MEM_DRIVER);
95 if ((domain != dev->pci_domain) ||
96 (bus != dev->pci_bus) ||
97 (slot != dev->pci_slot) ||
98 (func != dev->pci_func)) {
99 drm_free(busid, DRM_MEM_DRIVER);
103 /* Actually set the device's busid now. */
105 if (dev->unique_len || dev->unique) {
110 dev->unique_len = u->unique_len;
119 drm_set_busid(struct drm_device *dev)
124 if (dev->unique != NULL) {
129 dev->unique_len = 20;
130 dev->unique = kmalloc(dev->unique_len + 1, DRM_MEM_DRIVER, M_NOWAIT);
131 if (dev->unique == NULL) {
136 ksnprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%1x",
137 dev->pci_domain, dev->pci_bus, dev->pci_slot, dev->pci_func);
144 int drm_getmap(struct drm_device *dev, void *data, struct drm_file *file_priv)
146 struct drm_map *map = data;
147 drm_local_map_t *mapinlist;
159 TAILQ_FOREACH(mapinlist, &dev->maplist, link) {
161 map->offset = mapinlist->offset;
162 map->size = mapinlist->size;
163 map->type = mapinlist->type;
164 map->flags = mapinlist->flags;
165 map->handle = mapinlist->handle;
166 map->mtrr = mapinlist->mtrr;
174 if (mapinlist == NULL)
180 int drm_getclient(struct drm_device *dev, void *data,
181 struct drm_file *file_priv)
183 struct drm_client *client = data;
190 TAILQ_FOREACH(pt, &dev->files, link) {
192 client->auth = pt->authenticated;
193 client->pid = pt->pid;
194 client->uid = pt->uid;
195 client->magic = pt->magic;
196 client->iocs = pt->ioctl_count;
207 int drm_getstats(struct drm_device *dev, void *data, struct drm_file *file_priv)
209 struct drm_stats *stats = data;
212 memset(stats, 0, sizeof(struct drm_stats));
216 for (i = 0; i < dev->counters; i++) {
217 if (dev->types[i] == _DRM_STAT_LOCK)
218 stats->data[i].value =
219 (dev->lock.hw_lock ? dev->lock.hw_lock->lock : 0);
221 stats->data[i].value = atomic_read(&dev->counts[i]);
222 stats->data[i].type = dev->types[i];
225 stats->count = dev->counters;
232 int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
234 struct drm_get_cap *req = data;
237 switch (req->capability) {
238 case DRM_CAP_DUMB_BUFFER:
239 if (dev->driver->dumb_create)
242 case DRM_CAP_VBLANK_HIGH_CRTC:
245 case DRM_CAP_DUMB_PREFERRED_DEPTH:
246 req->value = dev->mode_config.preferred_depth;
248 case DRM_CAP_DUMB_PREFER_SHADOW:
249 req->value = dev->mode_config.prefer_shadow;
257 int drm_setversion(struct drm_device *dev, void *data,
258 struct drm_file *file_priv)
260 struct drm_set_version *sv = data;
261 struct drm_set_version ver;
264 /* Save the incoming data, and set the response before continuing
268 sv->drm_di_major = DRM_IF_MAJOR;
269 sv->drm_di_minor = DRM_IF_MINOR;
270 sv->drm_dd_major = dev->driver->major;
271 sv->drm_dd_minor = dev->driver->minor;
273 DRM_DEBUG("ver.drm_di_major %d ver.drm_di_minor %d "
274 "ver.drm_dd_major %d ver.drm_dd_minor %d\n",
275 ver.drm_di_major, ver.drm_di_minor, ver.drm_dd_major,
277 DRM_DEBUG("sv->drm_di_major %d sv->drm_di_minor %d "
278 "sv->drm_dd_major %d sv->drm_dd_minor %d\n",
279 sv->drm_di_major, sv->drm_di_minor, sv->drm_dd_major,
282 if (ver.drm_di_major != -1) {
283 if (ver.drm_di_major != DRM_IF_MAJOR ||
284 ver.drm_di_minor < 0 || ver.drm_di_minor > DRM_IF_MINOR) {
287 if_version = DRM_IF_VERSION(ver.drm_di_major,
289 dev->if_version = DRM_MAX(if_version, dev->if_version);
290 if (ver.drm_di_minor >= 1) {
292 * Version 1.1 includes tying of DRM to specific device
298 if (ver.drm_dd_major != -1) {
299 if (ver.drm_dd_major != dev->driver->major ||
300 ver.drm_dd_minor < 0 ||
301 ver.drm_dd_minor > dev->driver->minor)
311 int drm_noop(struct drm_device *dev, void *data, struct drm_file *file_priv)