3 * IOCTL processing for DRM
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
10 * Created: Fri Jan 8 09:01:26 1999 by faith@valinux.com
12 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
13 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
14 * All Rights Reserved.
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of this software and associated documentation files (the "Software"),
18 * to deal in the Software without restriction, including without limitation
19 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20 * and/or sell copies of the Software, and to permit persons to whom the
21 * Software is furnished to do so, subject to the following conditions:
23 * The above copyright notice and this permission notice (including the next
24 * paragraph) shall be included in all copies or substantial portions of the
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
31 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
32 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33 * OTHER DEALINGS IN THE SOFTWARE.
35 * $FreeBSD: src/sys/dev/drm2/drm_ioctl.c,v 1.1 2012/05/22 11:07:44 kib Exp $
39 #include <drm/drm_core.h>
41 #include <linux/export.h>
46 * \param inode device inode.
47 * \param file_priv DRM file private.
49 * \param arg user argument, pointing to a drm_unique structure.
50 * \return zero on success or a negative number on failure.
52 * Copies the bus id from drm_device::unique into user space.
54 int drm_getunique(struct drm_device
*dev
, void *data
,
55 struct drm_file
*file_priv
)
57 struct drm_unique
*u
= data
;
59 if (u
->unique_len
>= dev
->unique_len
) {
60 if (DRM_COPY_TO_USER(u
->unique
, dev
->unique
, dev
->unique_len
))
63 u
->unique_len
= dev
->unique_len
;
71 * \param inode device inode.
72 * \param file_priv DRM file private.
74 * \param arg user argument, pointing to a drm_unique structure.
75 * \return zero on success or a negative number on failure.
77 * Copies the bus id from userspace into drm_device::unique, and verifies that
78 * it matches the device this DRM is attached to (EINVAL otherwise). Deprecated
79 * in interface version 1.1 and will return EBUSY when setversion has requested
80 * version 1.1 or greater.
82 int drm_setunique(struct drm_device
*dev
, void *data
,
83 struct drm_file
*file_priv
)
85 struct drm_unique
*u
= data
;
86 int domain
, bus
, slot
, func
, ret
;
89 /* Check and copy in the submitted Bus ID */
90 if (!u
->unique_len
|| u
->unique_len
> 1024)
93 busid
= kmalloc(u
->unique_len
+ 1, M_DRM
, M_WAITOK
);
97 if (DRM_COPY_FROM_USER(busid
, u
->unique
, u
->unique_len
)) {
98 drm_free(busid
, M_DRM
);
101 busid
[u
->unique_len
] = '\0';
103 /* Return error if the busid submitted doesn't match the device's actual
106 ret
= ksscanf(busid
, "PCI:%d:%d:%d", &bus
, &slot
, &func
);
108 drm_free(busid
, M_DRM
);
114 if ((domain
!= dev
->pci_domain
) ||
115 (bus
!= dev
->pci_bus
) ||
116 (slot
!= dev
->pci_slot
) ||
117 (func
!= dev
->pci_func
)) {
118 drm_free(busid
, M_DRM
);
122 /* Actually set the device's busid now. */
124 if (dev
->unique_len
|| dev
->unique
) {
129 dev
->unique_len
= u
->unique_len
;
136 static int drm_set_busid(struct drm_device
*dev
, struct drm_file
*file_priv
)
141 dev
->unique_len
= 20;
142 dev
->unique
= kmalloc(dev
->unique_len
+ 1, M_DRM
, M_WAITOK
| M_NULLOK
);
143 if (dev
->unique
== NULL
) {
148 ksnprintf(dev
->unique
, dev
->unique_len
, "pci:%04x:%02x:%02x.%1x",
149 dev
->pci_domain
, dev
->pci_bus
, dev
->pci_slot
, dev
->pci_func
);
157 * Get a mapping information.
159 * \param inode device inode.
160 * \param file_priv DRM file private.
161 * \param cmd command.
162 * \param arg user argument, pointing to a drm_map structure.
164 * \return zero on success or a negative number on failure.
166 * Searches for the mapping with the specified offset and copies its information
169 int drm_getmap(struct drm_device
*dev
, void *data
,
170 struct drm_file
*file_priv
)
172 struct drm_map
*map
= data
;
173 struct drm_map_list
*r_list
= NULL
;
174 struct list_head
*list
;
185 list_for_each(list
, &dev
->maplist
) {
187 r_list
= list_entry(list
, struct drm_map_list
, head
);
192 if (!r_list
|| !r_list
->map
) {
197 map
->offset
= r_list
->map
->offset
;
198 map
->size
= r_list
->map
->size
;
199 map
->type
= r_list
->map
->type
;
200 map
->flags
= r_list
->map
->flags
;
201 map
->handle
= r_list
->map
->handle
;
202 map
->mtrr
= r_list
->map
->mtrr
;
209 * Get client information.
211 * \param inode device inode.
212 * \param file_priv DRM file private.
213 * \param cmd command.
214 * \param arg user argument, pointing to a drm_client structure.
216 * \return zero on success or a negative number on failure.
218 * Searches for the client with the specified index and copies its information
221 int drm_getclient(struct drm_device
*dev
, void *data
,
222 struct drm_file
*file_priv
)
224 struct drm_client
*client
= data
;
231 list_for_each_entry(pt
, &dev
->filelist
, lhead
) {
233 client
->auth
= pt
->authenticated
;
234 client
->pid
= pt
->pid
;
235 client
->uid
= pt
->uid
;
236 client
->magic
= pt
->magic
;
237 client
->iocs
= pt
->ioctl_count
;
249 * Get statistics information.
251 * \param inode device inode.
252 * \param file_priv DRM file private.
253 * \param cmd command.
254 * \param arg user argument, pointing to a drm_stats structure.
256 * \return zero on success or a negative number on failure.
258 int drm_getstats(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
260 struct drm_stats
*stats
= data
;
263 memset(stats
, 0, sizeof(struct drm_stats
));
267 for (i
= 0; i
< dev
->counters
; i
++) {
268 if (dev
->types
[i
] == _DRM_STAT_LOCK
)
269 stats
->data
[i
].value
=
270 (dev
->lock
.hw_lock
? dev
->lock
.hw_lock
->lock
: 0);
272 stats
->data
[i
].value
= atomic_read(&dev
->counts
[i
]);
273 stats
->data
[i
].type
= dev
->types
[i
];
276 stats
->count
= dev
->counters
;
284 * Get device/driver capabilities
286 int drm_getcap(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
288 struct drm_get_cap
*req
= data
;
291 switch (req
->capability
) {
292 case DRM_CAP_DUMB_BUFFER
:
293 if (dev
->driver
->dumb_create
)
296 case DRM_CAP_VBLANK_HIGH_CRTC
:
299 case DRM_CAP_DUMB_PREFERRED_DEPTH
:
300 req
->value
= dev
->mode_config
.preferred_depth
;
302 case DRM_CAP_DUMB_PREFER_SHADOW
:
303 req
->value
= dev
->mode_config
.prefer_shadow
;
305 case DRM_CAP_TIMESTAMP_MONOTONIC
:
306 req
->value
= drm_timestamp_monotonic
;
315 * Set device/driver capabilities
318 drm_setclientcap(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
320 struct drm_set_client_cap
*req
= data
;
322 switch (req
->capability
) {
323 case DRM_CLIENT_CAP_STEREO_3D
:
326 file_priv
->stereo_allowed
= req
->value
;
328 case DRM_CLIENT_CAP_UNIVERSAL_PLANES
:
329 if (!drm_universal_planes
)
333 file_priv
->universal_planes
= req
->value
;
345 * \param inode device inode.
346 * \param file_priv DRM file private.
347 * \param cmd command.
348 * \param arg user argument, pointing to a drm_lock structure.
349 * \return zero on success or negative number on failure.
351 * Sets the requested interface version
353 int drm_setversion(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
355 struct drm_set_version
*sv
= data
;
356 struct drm_set_version ver
;
357 int if_version
, retcode
= 0;
359 /* Save the incoming data, and set the response before continuing
363 sv
->drm_di_major
= DRM_IF_MAJOR
;
364 sv
->drm_di_minor
= DRM_IF_MINOR
;
365 sv
->drm_dd_major
= dev
->driver
->major
;
366 sv
->drm_dd_minor
= dev
->driver
->minor
;
368 if (ver
.drm_di_major
!= -1) {
369 if (ver
.drm_di_major
!= DRM_IF_MAJOR
||
370 ver
.drm_di_minor
< 0 || ver
.drm_di_minor
> DRM_IF_MINOR
) {
373 if_version
= DRM_IF_VERSION(ver
.drm_di_major
,
375 dev
->if_version
= DRM_MAX(if_version
, dev
->if_version
);
376 if (ver
.drm_di_minor
>= 1) {
378 * Version 1.1 includes tying of DRM to specific device
379 * Version 1.4 has proper PCI domain support
381 retcode
= drm_set_busid(dev
, file_priv
);
387 if (ver
.drm_dd_major
!= -1) {
388 if (ver
.drm_dd_major
!= dev
->driver
->major
||
389 ver
.drm_dd_minor
< 0 ||
390 ver
.drm_dd_minor
> dev
->driver
->minor
)
400 int drm_noop(struct drm_device
*dev
, void *data
,
401 struct drm_file
*file_priv
)
406 EXPORT_SYMBOL(drm_noop
);