2 * drm_ioctl.h -- IOCTL processing for DRM -*- linux-c -*-
3 * Created: Fri Jan 8 09:01:26 1999 by faith@valinux.com
6 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
7 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice (including the next
18 * paragraph) shall be included in all copies or substantial portions of the
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
30 * Rickard E. (Rik) Faith <faith@valinux.com>
31 * Gareth Hughes <gareth@valinux.com>
36 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
37 * Use is subject to license terms.
40 #pragma ident "%Z%%M% %I% %E% SMI"
46 * Beginning in revision 1.1 of the DRM interface, getunique will return
47 * a unique in the form pci:oooo:bb:dd.f (o=domain, b=bus, d=device, f=function)
48 * before setunique has been called. The format for the bus-specific part of
49 * the unique is not defined for any other bus.
53 drm_getunique(DRM_IOCTL_ARGS
)
58 #ifdef _MULTI_DATAMODEL
59 if (ddi_model_convert_from(mode
& FMODELS
) == DDI_MODEL_ILP32
) {
62 DRM_COPYFROM_WITH_RETURN(&u32
, (void *)data
, sizeof (u32
));
63 u1
.unique_len
= u32
.unique_len
;
64 u1
.unique
= (char __user
*)(uintptr_t)u32
.unique
;
67 DRM_COPYFROM_WITH_RETURN(&u1
, (void *)data
, sizeof (u1
));
69 if (u1
.unique_len
>= dev
->unique_len
) {
70 if (dev
->unique_len
== 0) {
71 DRM_ERROR("drm_getunique: dev->unique_len = 0");
74 if (DRM_COPY_TO_USER(u1
.unique
, dev
->unique
, dev
->unique_len
))
77 u1
.unique_len
= dev
->unique_len
;
79 #ifdef _MULTI_DATAMODEL
80 if (ddi_model_convert_from(mode
& FMODELS
) == DDI_MODEL_ILP32
) {
83 u32
.unique_len
= (uint32_t)u1
.unique_len
;
84 u32
.unique
= (caddr32_t
)(uintptr_t)u1
.unique
;
85 DRM_COPYTO_WITH_RETURN((void *)data
, &u32
, sizeof (u32
));
88 DRM_COPYTO_WITH_RETURN((void *)data
, &u1
, sizeof (u1
));
94 * Deprecated in DRM version 1.1, and will return EBUSY when setversion has
95 * requested version 1.1 or greater.
99 drm_setunique(DRM_IOCTL_ARGS
)
106 drm_set_busid(drm_device_t
*dev
)
110 if (dev
->unique
!= NULL
) {
115 dev
->unique_len
= 20;
116 dev
->unique
= drm_alloc(dev
->unique_len
+ 1, DRM_MEM_DRIVER
);
117 if (dev
->unique
== NULL
) {
122 (void) snprintf(dev
->unique
, dev
->unique_len
, "pci:%04x:%02x:%02x.%1x",
123 dev
->pci_domain
, dev
->pci_bus
, dev
->pci_slot
, dev
->pci_func
);
132 drm_getmap(DRM_IOCTL_ARGS
)
136 drm_local_map_t
*mapinlist
;
140 #ifdef _MULTI_DATAMODEL
141 if (ddi_model_convert_from(mode
& FMODELS
) == DDI_MODEL_ILP32
) {
144 DRM_COPYFROM_WITH_RETURN(&map32
, (void *)data
, sizeof (map32
));
145 map
.offset
= map32
.offset
;
146 map
.size
= map32
.size
;
147 map
.type
= map32
.type
;
148 map
.flags
= map32
.flags
;
149 map
.handle
= map32
.handle
;
150 map
.mtrr
= map32
.mtrr
;
153 DRM_COPYFROM_WITH_RETURN(&map
, (void *)data
, sizeof (map
));
155 idx
= (int)map
.offset
;
163 TAILQ_FOREACH(mapinlist
, &dev
->maplist
, link
) {
165 map
.offset
= mapinlist
->offset
;
166 map
.size
= mapinlist
->size
;
167 map
.type
= mapinlist
->type
;
168 map
.flags
= mapinlist
->flags
;
169 map
.handle
= (unsigned long long)(uintptr_t)
171 map
.mtrr
= mapinlist
->mtrr
;
179 if (mapinlist
== NULL
)
182 #ifdef _MULTI_DATAMODEL
183 if (ddi_model_convert_from(mode
& FMODELS
) == DDI_MODEL_ILP32
) {
186 map32
.offset
= map
.offset
;
187 map32
.size
= (uint32_t)map
.size
;
188 map32
.type
= map
.type
;
189 map32
.flags
= map
.flags
;
190 map32
.handle
= (uintptr_t)map
.handle
;
191 map32
.mtrr
= map
.mtrr
;
192 DRM_COPYTO_WITH_RETURN((void *)data
, &map32
, sizeof (map32
));
195 DRM_COPYTO_WITH_RETURN((void *)data
, &map
, sizeof (map
));
202 drm_getclient(DRM_IOCTL_ARGS
)
210 #ifdef _MULTI_DATAMODEL
211 if (ddi_model_convert_from(mode
& FMODELS
) == DDI_MODEL_ILP32
) {
212 drm_client_32_t client32
;
214 DRM_COPYFROM_WITH_RETURN(&client32
, (void *)data
,
216 client
.idx
= client32
.idx
;
217 client
.auth
= client32
.auth
;
218 client
.pid
= client32
.pid
;
219 client
.uid
= client32
.uid
;
220 client
.magic
= client32
.magic
;
221 client
.iocs
= client32
.iocs
;
224 DRM_COPYFROM_WITH_RETURN(&client
, (void *)data
,
229 TAILQ_FOREACH(pt
, &dev
->files
, link
) {
231 client
.auth
= pt
->authenticated
;
232 client
.pid
= pt
->pid
;
233 client
.uid
= pt
->uid
;
234 client
.magic
= pt
->magic
;
235 client
.iocs
= pt
->ioctl_count
;
238 #ifdef _MULTI_DATAMODEL
239 if (ddi_model_convert_from(mode
& FMODELS
) ==
241 drm_client_32_t client32
;
243 client32
.idx
= client
.idx
;
244 client32
.auth
= client
.auth
;
245 client32
.pid
= (uint32_t)client
.pid
;
246 client32
.uid
= (uint32_t)client
.uid
;
247 client32
.magic
= (uint32_t)client
.magic
;
248 client32
.iocs
= (uint32_t)client
.iocs
;
250 DRM_COPYTO_WITH_RETURN((void *)data
, &client32
,
254 DRM_COPYTO_WITH_RETURN((void *)data
,
255 &client
, sizeof (client
));
267 drm_getstats(DRM_IOCTL_ARGS
)
273 bzero(&stats
, sizeof (stats
));
277 for (i
= 0; i
< dev
->counters
; i
++) {
278 if (dev
->types
[i
] == _DRM_STAT_LOCK
) {
281 ? dev
->lock
.hw_lock
->lock
: 0);
283 stats
.data
[i
].value
= atomic_read(&dev
->counts
[i
]);
284 stats
.data
[i
].type
= dev
->types
[i
];
287 stats
.count
= dev
->counters
;
291 #ifdef _MULTI_DATAMODEL
292 if (ddi_model_convert_from(mode
& FMODELS
) == DDI_MODEL_ILP32
) {
293 drm_stats_32_t stats32
;
294 stats32
.count
= (uint32_t)stats
.count
;
295 for (i
= 0; i
< 15; i
++) {
296 stats32
.data
[i
].value
= stats
.data
[i
].value
;
297 stats32
.data
[i
].type
= stats
.data
[i
].type
;
299 DRM_COPYTO_WITH_RETURN((void *)data
, &stats32
,
303 DRM_COPYTO_WITH_RETURN((void *)data
, &stats
, sizeof (stats
));
308 #define DRM_IF_MAJOR 1
309 #define DRM_IF_MINOR 2
313 drm_setversion(DRM_IOCTL_ARGS
)
316 drm_set_version_t sv
;
317 drm_set_version_t retv
;
320 DRM_COPYFROM_WITH_RETURN(&sv
, (void *)data
, sizeof (sv
));
322 retv
.drm_di_major
= DRM_IF_MAJOR
;
323 retv
.drm_di_minor
= DRM_IF_MINOR
;
324 retv
.drm_dd_major
= dev
->driver
->driver_major
;
325 retv
.drm_dd_minor
= dev
->driver
->driver_minor
;
327 DRM_COPYTO_WITH_RETURN((void *)data
, &retv
, sizeof (sv
));
329 if (sv
.drm_di_major
!= -1) {
330 if (sv
.drm_di_major
!= DRM_IF_MAJOR
||
331 sv
.drm_di_minor
< 0 || sv
.drm_di_minor
> DRM_IF_MINOR
)
333 if_version
= DRM_IF_VERSION(sv
.drm_di_major
, sv
.drm_dd_minor
);
334 dev
->if_version
= DRM_MAX(if_version
, dev
->if_version
);
335 if (sv
.drm_di_minor
>= 1) {
337 * Version 1.1 includes tying of DRM to specific device
339 (void) drm_set_busid(dev
);
343 if (sv
.drm_dd_major
!= -1) {
344 if (sv
.drm_dd_major
!= dev
->driver
->driver_major
||
345 sv
.drm_dd_minor
< 0 ||
346 sv
.drm_dd_minor
> dev
->driver
->driver_minor
)
355 drm_noop(DRM_IOCTL_ARGS
)
357 DRM_DEBUG("drm_noop\n");
363 drm_version(DRM_IOCTL_ARGS
)
366 drm_version_t version
;
369 #ifdef _MULTI_DATAMODEL
370 if (ddi_model_convert_from(mode
& FMODELS
) == DDI_MODEL_ILP32
) {
371 drm_version_32_t version32
;
373 DRM_COPYFROM_WITH_RETURN(&version32
,
374 (void *)data
, sizeof (drm_version_32_t
));
375 version
.name_len
= version32
.name_len
;
376 version
.name
= (char *)(uintptr_t)version32
.name
;
377 version
.date_len
= version32
.date_len
;
378 version
.date
= (char *)(uintptr_t)version32
.date
;
379 version
.desc_len
= version32
.desc_len
;
380 version
.desc
= (char *)(uintptr_t)version32
.desc
;
383 DRM_COPYFROM_WITH_RETURN(&version
, (void *)data
,
386 #define DRM_COPY(name, value) \
387 len = strlen(value); \
388 if (len > name##_len) len = name##_len; \
389 name##_len = strlen(value); \
391 if (DRM_COPY_TO_USER(name, value, len)) \
395 version
.version_major
= dev
->driver
->driver_major
;
396 version
.version_minor
= dev
->driver
->driver_minor
;
397 version
.version_patchlevel
= dev
->driver
->driver_patchlevel
;
399 DRM_COPY(version
.name
, dev
->driver
->driver_name
);
400 DRM_COPY(version
.date
, dev
->driver
->driver_date
);
401 DRM_COPY(version
.desc
, dev
->driver
->driver_desc
);
403 #ifdef _MULTI_DATAMODEL
404 if (ddi_model_convert_from(mode
& FMODELS
) == DDI_MODEL_ILP32
) {
405 drm_version_32_t version32
;
407 version32
.version_major
= version
.version_major
;
408 version32
.version_minor
= version
.version_minor
;
409 version32
.version_patchlevel
= version
.version_patchlevel
;
410 version32
.name_len
= (uint32_t)version
.name_len
;
411 version32
.name
= (caddr32_t
)(uintptr_t)version
.name
;
412 version32
.date_len
= (uint32_t)version
.date_len
;
413 version32
.date
= (caddr32_t
)(uintptr_t)version
.date
;
414 version32
.desc_len
= (uint32_t)version
.desc_len
;
415 version32
.desc
= (caddr32_t
)(uintptr_t)version
.desc
;
416 DRM_COPYTO_WITH_RETURN((void *)data
, &version32
,
417 sizeof (drm_version_32_t
));
420 DRM_COPYTO_WITH_RETURN((void *)data
, &version
,