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.
38 #include <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);
145 * Get a mapping information.
147 * \param inode device inode.
148 * \param file_priv DRM file private.
149 * \param cmd command.
150 * \param arg user argument, pointing to a drm_map structure.
152 * \return zero on success or a negative number on failure.
154 * Searches for the mapping with the specified offset and copies its information
157 int drm_getmap(struct drm_device *dev, void *data,
158 struct drm_file *file_priv)
160 struct drm_map *map = data;
161 struct drm_map_list *r_list = NULL;
162 struct list_head *list;
173 list_for_each(list, &dev->maplist) {
175 r_list = list_entry(list, struct drm_map_list, head);
180 if (!r_list || !r_list->map) {
185 map->offset = r_list->map->offset;
186 map->size = r_list->map->size;
187 map->type = r_list->map->type;
188 map->flags = r_list->map->flags;
189 map->handle = r_list->map->handle;
190 map->mtrr = r_list->map->mtrr;
196 int drm_getclient(struct drm_device *dev, void *data,
197 struct drm_file *file_priv)
199 struct drm_client *client = data;
206 TAILQ_FOREACH(pt, &dev->files, link) {
208 client->auth = pt->authenticated;
209 client->pid = pt->pid;
210 client->uid = pt->uid;
211 client->magic = pt->magic;
212 client->iocs = pt->ioctl_count;
223 int drm_getstats(struct drm_device *dev, void *data, struct drm_file *file_priv)
225 struct drm_stats *stats = data;
228 memset(stats, 0, sizeof(struct drm_stats));
232 for (i = 0; i < dev->counters; i++) {
233 if (dev->types[i] == _DRM_STAT_LOCK)
234 stats->data[i].value =
235 (dev->lock.hw_lock ? 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;
248 int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
250 struct drm_get_cap *req = data;
253 switch (req->capability) {
254 case DRM_CAP_DUMB_BUFFER:
255 if (dev->driver->dumb_create)
258 case DRM_CAP_VBLANK_HIGH_CRTC:
261 case DRM_CAP_DUMB_PREFERRED_DEPTH:
262 req->value = dev->mode_config.preferred_depth;
264 case DRM_CAP_DUMB_PREFER_SHADOW:
265 req->value = dev->mode_config.prefer_shadow;
273 int drm_setversion(struct drm_device *dev, void *data,
274 struct drm_file *file_priv)
276 struct drm_set_version *sv = data;
277 struct drm_set_version ver;
280 /* Save the incoming data, and set the response before continuing
284 sv->drm_di_major = DRM_IF_MAJOR;
285 sv->drm_di_minor = DRM_IF_MINOR;
286 sv->drm_dd_major = dev->driver->major;
287 sv->drm_dd_minor = dev->driver->minor;
289 DRM_DEBUG("ver.drm_di_major %d ver.drm_di_minor %d "
290 "ver.drm_dd_major %d ver.drm_dd_minor %d\n",
291 ver.drm_di_major, ver.drm_di_minor, ver.drm_dd_major,
293 DRM_DEBUG("sv->drm_di_major %d sv->drm_di_minor %d "
294 "sv->drm_dd_major %d sv->drm_dd_minor %d\n",
295 sv->drm_di_major, sv->drm_di_minor, sv->drm_dd_major,
298 if (ver.drm_di_major != -1) {
299 if (ver.drm_di_major != DRM_IF_MAJOR ||
300 ver.drm_di_minor < 0 || ver.drm_di_minor > DRM_IF_MINOR) {
303 if_version = DRM_IF_VERSION(ver.drm_di_major,
305 dev->if_version = DRM_MAX(if_version, dev->if_version);
306 if (ver.drm_di_minor >= 1) {
308 * Version 1.1 includes tying of DRM to specific device
314 if (ver.drm_dd_major != -1) {
315 if (ver.drm_dd_major != dev->driver->major ||
316 ver.drm_dd_minor < 0 ||
317 ver.drm_dd_minor > dev->driver->minor)
327 int drm_noop(struct drm_device *dev, void *data, struct drm_file *file_priv)