4 * 32-bit ioctl compatibility routines for the DRM.
6 * \author Paul Mackerras <paulus@samba.org>
8 * Copyright (C) Paul Mackerras 2005.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice (including the next
19 * paragraph) shall be included in all copies or substantial portions of the
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 #include <linux/compat.h>
31 #include <linux/ratelimit.h>
32 #include <linux/export.h>
35 #include <drm/drm_core.h>
37 #define DRM_IOCTL_VERSION32 DRM_IOWR(0x00, drm_version32_t)
38 #define DRM_IOCTL_GET_UNIQUE32 DRM_IOWR(0x01, drm_unique32_t)
39 #define DRM_IOCTL_GET_MAP32 DRM_IOWR(0x04, drm_map32_t)
40 #define DRM_IOCTL_GET_CLIENT32 DRM_IOWR(0x05, drm_client32_t)
41 #define DRM_IOCTL_GET_STATS32 DRM_IOR( 0x06, drm_stats32_t)
43 #define DRM_IOCTL_SET_UNIQUE32 DRM_IOW( 0x10, drm_unique32_t)
44 #define DRM_IOCTL_ADD_MAP32 DRM_IOWR(0x15, drm_map32_t)
45 #define DRM_IOCTL_ADD_BUFS32 DRM_IOWR(0x16, drm_buf_desc32_t)
46 #define DRM_IOCTL_MARK_BUFS32 DRM_IOW( 0x17, drm_buf_desc32_t)
47 #define DRM_IOCTL_INFO_BUFS32 DRM_IOWR(0x18, drm_buf_info32_t)
48 #define DRM_IOCTL_MAP_BUFS32 DRM_IOWR(0x19, drm_buf_map32_t)
49 #define DRM_IOCTL_FREE_BUFS32 DRM_IOW( 0x1a, drm_buf_free32_t)
51 #define DRM_IOCTL_RM_MAP32 DRM_IOW( 0x1b, drm_map32_t)
53 #define DRM_IOCTL_SET_SAREA_CTX32 DRM_IOW( 0x1c, drm_ctx_priv_map32_t)
54 #define DRM_IOCTL_GET_SAREA_CTX32 DRM_IOWR(0x1d, drm_ctx_priv_map32_t)
56 #define DRM_IOCTL_RES_CTX32 DRM_IOWR(0x26, drm_ctx_res32_t)
57 #define DRM_IOCTL_DMA32 DRM_IOWR(0x29, drm_dma32_t)
59 #define DRM_IOCTL_AGP_ENABLE32 DRM_IOW( 0x32, drm_agp_mode32_t)
60 #define DRM_IOCTL_AGP_INFO32 DRM_IOR( 0x33, drm_agp_info32_t)
61 #define DRM_IOCTL_AGP_ALLOC32 DRM_IOWR(0x34, drm_agp_buffer32_t)
62 #define DRM_IOCTL_AGP_FREE32 DRM_IOW( 0x35, drm_agp_buffer32_t)
63 #define DRM_IOCTL_AGP_BIND32 DRM_IOW( 0x36, drm_agp_binding32_t)
64 #define DRM_IOCTL_AGP_UNBIND32 DRM_IOW( 0x37, drm_agp_binding32_t)
66 #define DRM_IOCTL_SG_ALLOC32 DRM_IOW( 0x38, drm_scatter_gather32_t)
67 #define DRM_IOCTL_SG_FREE32 DRM_IOW( 0x39, drm_scatter_gather32_t)
69 #define DRM_IOCTL_UPDATE_DRAW32 DRM_IOW( 0x3f, drm_update_draw32_t)
71 #define DRM_IOCTL_WAIT_VBLANK32 DRM_IOWR(0x3a, drm_wait_vblank32_t)
73 #define DRM_IOCTL_MODE_ADDFB232 DRM_IOWR(0xb8, drm_mode_fb_cmd232_t)
75 typedef struct drm_version_32
{
76 int version_major
; /**< Major version */
77 int version_minor
; /**< Minor version */
78 int version_patchlevel
; /**< Patch level */
79 u32 name_len
; /**< Length of name buffer */
80 u32 name
; /**< Name of driver */
81 u32 date_len
; /**< Length of date buffer */
82 u32 date
; /**< User-space buffer to hold date */
83 u32 desc_len
; /**< Length of desc buffer */
84 u32 desc
; /**< User-space buffer to hold desc */
87 static int compat_drm_version(struct file
*file
, unsigned int cmd
,
91 struct drm_version __user
*version
;
94 if (copy_from_user(&v32
, (void __user
*)arg
, sizeof(v32
)))
97 version
= compat_alloc_user_space(sizeof(*version
));
98 if (!access_ok(VERIFY_WRITE
, version
, sizeof(*version
)))
100 if (__put_user(v32
.name_len
, &version
->name_len
)
101 || __put_user((void __user
*)(unsigned long)v32
.name
,
103 || __put_user(v32
.date_len
, &version
->date_len
)
104 || __put_user((void __user
*)(unsigned long)v32
.date
,
106 || __put_user(v32
.desc_len
, &version
->desc_len
)
107 || __put_user((void __user
*)(unsigned long)v32
.desc
,
111 err
= drm_ioctl(file
,
112 DRM_IOCTL_VERSION
, (unsigned long)version
);
116 if (__get_user(v32
.version_major
, &version
->version_major
)
117 || __get_user(v32
.version_minor
, &version
->version_minor
)
118 || __get_user(v32
.version_patchlevel
, &version
->version_patchlevel
)
119 || __get_user(v32
.name_len
, &version
->name_len
)
120 || __get_user(v32
.date_len
, &version
->date_len
)
121 || __get_user(v32
.desc_len
, &version
->desc_len
))
124 if (copy_to_user((void __user
*)arg
, &v32
, sizeof(v32
)))
129 typedef struct drm_unique32
{
130 u32 unique_len
; /**< Length of unique */
131 u32 unique
; /**< Unique name for driver instantiation */
134 static int compat_drm_getunique(struct file
*file
, unsigned int cmd
,
138 struct drm_unique __user
*u
;
141 if (copy_from_user(&uq32
, (void __user
*)arg
, sizeof(uq32
)))
144 u
= compat_alloc_user_space(sizeof(*u
));
145 if (!access_ok(VERIFY_WRITE
, u
, sizeof(*u
)))
147 if (__put_user(uq32
.unique_len
, &u
->unique_len
)
148 || __put_user((void __user
*)(unsigned long)uq32
.unique
,
152 err
= drm_ioctl(file
, DRM_IOCTL_GET_UNIQUE
, (unsigned long)u
);
156 if (__get_user(uq32
.unique_len
, &u
->unique_len
))
158 if (copy_to_user((void __user
*)arg
, &uq32
, sizeof(uq32
)))
163 static int compat_drm_setunique(struct file
*file
, unsigned int cmd
,
167 struct drm_unique __user
*u
;
169 if (copy_from_user(&uq32
, (void __user
*)arg
, sizeof(uq32
)))
172 u
= compat_alloc_user_space(sizeof(*u
));
173 if (!access_ok(VERIFY_WRITE
, u
, sizeof(*u
)))
175 if (__put_user(uq32
.unique_len
, &u
->unique_len
)
176 || __put_user((void __user
*)(unsigned long)uq32
.unique
,
180 return drm_ioctl(file
, DRM_IOCTL_SET_UNIQUE
, (unsigned long)u
);
183 typedef struct drm_map32
{
184 u32 offset
; /**< Requested physical address (0 for SAREA)*/
185 u32 size
; /**< Requested physical size (bytes) */
186 enum drm_map_type type
; /**< Type of memory to map */
187 enum drm_map_flags flags
; /**< Flags */
188 u32 handle
; /**< User-space: "Handle" to pass to mmap() */
189 int mtrr
; /**< MTRR slot used */
192 static int compat_drm_getmap(struct file
*file
, unsigned int cmd
,
195 drm_map32_t __user
*argp
= (void __user
*)arg
;
197 struct drm_map __user
*map
;
201 if (get_user(idx
, &argp
->offset
))
204 map
= compat_alloc_user_space(sizeof(*map
));
205 if (!access_ok(VERIFY_WRITE
, map
, sizeof(*map
)))
207 if (__put_user(idx
, &map
->offset
))
210 err
= drm_ioctl(file
, DRM_IOCTL_GET_MAP
, (unsigned long)map
);
214 if (__get_user(m32
.offset
, &map
->offset
)
215 || __get_user(m32
.size
, &map
->size
)
216 || __get_user(m32
.type
, &map
->type
)
217 || __get_user(m32
.flags
, &map
->flags
)
218 || __get_user(handle
, &map
->handle
)
219 || __get_user(m32
.mtrr
, &map
->mtrr
))
222 m32
.handle
= (unsigned long)handle
;
223 if (copy_to_user(argp
, &m32
, sizeof(m32
)))
229 static int compat_drm_addmap(struct file
*file
, unsigned int cmd
,
232 drm_map32_t __user
*argp
= (void __user
*)arg
;
234 struct drm_map __user
*map
;
238 if (copy_from_user(&m32
, argp
, sizeof(m32
)))
241 map
= compat_alloc_user_space(sizeof(*map
));
242 if (!access_ok(VERIFY_WRITE
, map
, sizeof(*map
)))
244 if (__put_user(m32
.offset
, &map
->offset
)
245 || __put_user(m32
.size
, &map
->size
)
246 || __put_user(m32
.type
, &map
->type
)
247 || __put_user(m32
.flags
, &map
->flags
))
250 err
= drm_ioctl(file
, DRM_IOCTL_ADD_MAP
, (unsigned long)map
);
254 if (__get_user(m32
.offset
, &map
->offset
)
255 || __get_user(m32
.mtrr
, &map
->mtrr
)
256 || __get_user(handle
, &map
->handle
))
259 m32
.handle
= (unsigned long)handle
;
260 if (m32
.handle
!= (unsigned long)handle
)
261 printk_ratelimited(KERN_ERR
"compat_drm_addmap truncated handle"
262 " %p for type %d offset %x\n",
263 handle
, m32
.type
, m32
.offset
);
265 if (copy_to_user(argp
, &m32
, sizeof(m32
)))
271 static int compat_drm_rmmap(struct file
*file
, unsigned int cmd
,
274 drm_map32_t __user
*argp
= (void __user
*)arg
;
275 struct drm_map __user
*map
;
278 if (get_user(handle
, &argp
->handle
))
281 map
= compat_alloc_user_space(sizeof(*map
));
282 if (!access_ok(VERIFY_WRITE
, map
, sizeof(*map
)))
284 if (__put_user((void *)(unsigned long)handle
, &map
->handle
))
287 return drm_ioctl(file
, DRM_IOCTL_RM_MAP
, (unsigned long)map
);
290 typedef struct drm_client32
{
291 int idx
; /**< Which client desired? */
292 int auth
; /**< Is client authenticated? */
293 u32 pid
; /**< Process ID */
294 u32 uid
; /**< User ID */
295 u32 magic
; /**< Magic */
296 u32 iocs
; /**< Ioctl count */
299 static int compat_drm_getclient(struct file
*file
, unsigned int cmd
,
303 drm_client32_t __user
*argp
= (void __user
*)arg
;
304 struct drm_client __user
*client
;
307 if (get_user(idx
, &argp
->idx
))
310 client
= compat_alloc_user_space(sizeof(*client
));
311 if (!access_ok(VERIFY_WRITE
, client
, sizeof(*client
)))
313 if (__put_user(idx
, &client
->idx
))
316 err
= drm_ioctl(file
, DRM_IOCTL_GET_CLIENT
, (unsigned long)client
);
320 if (__get_user(c32
.idx
, &client
->idx
)
321 || __get_user(c32
.auth
, &client
->auth
)
322 || __get_user(c32
.pid
, &client
->pid
)
323 || __get_user(c32
.uid
, &client
->uid
)
324 || __get_user(c32
.magic
, &client
->magic
)
325 || __get_user(c32
.iocs
, &client
->iocs
))
328 if (copy_to_user(argp
, &c32
, sizeof(c32
)))
333 typedef struct drm_stats32
{
337 enum drm_stat_type type
;
341 static int compat_drm_getstats(struct file
*file
, unsigned int cmd
,
345 drm_stats32_t __user
*argp
= (void __user
*)arg
;
346 struct drm_stats __user
*stats
;
349 stats
= compat_alloc_user_space(sizeof(*stats
));
350 if (!access_ok(VERIFY_WRITE
, stats
, sizeof(*stats
)))
353 err
= drm_ioctl(file
, DRM_IOCTL_GET_STATS
, (unsigned long)stats
);
357 if (__get_user(s32
.count
, &stats
->count
))
359 for (i
= 0; i
< 15; ++i
)
360 if (__get_user(s32
.data
[i
].value
, &stats
->data
[i
].value
)
361 || __get_user(s32
.data
[i
].type
, &stats
->data
[i
].type
))
364 if (copy_to_user(argp
, &s32
, sizeof(s32
)))
369 typedef struct drm_buf_desc32
{
370 int count
; /**< Number of buffers of this size */
371 int size
; /**< Size in bytes */
372 int low_mark
; /**< Low water mark */
373 int high_mark
; /**< High water mark */
375 u32 agp_start
; /**< Start address in the AGP aperture */
378 static int compat_drm_addbufs(struct file
*file
, unsigned int cmd
,
381 drm_buf_desc32_t __user
*argp
= (void __user
*)arg
;
382 struct drm_buf_desc __user
*buf
;
384 unsigned long agp_start
;
386 buf
= compat_alloc_user_space(sizeof(*buf
));
387 if (!access_ok(VERIFY_WRITE
, buf
, sizeof(*buf
))
388 || !access_ok(VERIFY_WRITE
, argp
, sizeof(*argp
)))
391 if (__copy_in_user(buf
, argp
, offsetof(drm_buf_desc32_t
, agp_start
))
392 || __get_user(agp_start
, &argp
->agp_start
)
393 || __put_user(agp_start
, &buf
->agp_start
))
396 err
= drm_ioctl(file
, DRM_IOCTL_ADD_BUFS
, (unsigned long)buf
);
400 if (__copy_in_user(argp
, buf
, offsetof(drm_buf_desc32_t
, agp_start
))
401 || __get_user(agp_start
, &buf
->agp_start
)
402 || __put_user(agp_start
, &argp
->agp_start
))
408 static int compat_drm_markbufs(struct file
*file
, unsigned int cmd
,
411 drm_buf_desc32_t b32
;
412 drm_buf_desc32_t __user
*argp
= (void __user
*)arg
;
413 struct drm_buf_desc __user
*buf
;
415 if (copy_from_user(&b32
, argp
, sizeof(b32
)))
418 buf
= compat_alloc_user_space(sizeof(*buf
));
419 if (!access_ok(VERIFY_WRITE
, buf
, sizeof(*buf
)))
422 if (__put_user(b32
.size
, &buf
->size
)
423 || __put_user(b32
.low_mark
, &buf
->low_mark
)
424 || __put_user(b32
.high_mark
, &buf
->high_mark
))
427 return drm_ioctl(file
, DRM_IOCTL_MARK_BUFS
, (unsigned long)buf
);
430 typedef struct drm_buf_info32
{
431 int count
; /**< Entries in list */
435 static int compat_drm_infobufs(struct file
*file
, unsigned int cmd
,
438 drm_buf_info32_t req32
;
439 drm_buf_info32_t __user
*argp
= (void __user
*)arg
;
440 drm_buf_desc32_t __user
*to
;
441 struct drm_buf_info __user
*request
;
442 struct drm_buf_desc __user
*list
;
447 if (copy_from_user(&req32
, argp
, sizeof(req32
)))
451 to
= (drm_buf_desc32_t __user
*) (unsigned long)req32
.list
;
455 && !access_ok(VERIFY_WRITE
, to
, count
* sizeof(drm_buf_desc32_t
)))
458 nbytes
= sizeof(*request
) + count
* sizeof(struct drm_buf_desc
);
459 request
= compat_alloc_user_space(nbytes
);
460 if (!access_ok(VERIFY_WRITE
, request
, nbytes
))
462 list
= (struct drm_buf_desc
*) (request
+ 1);
464 if (__put_user(count
, &request
->count
)
465 || __put_user(list
, &request
->list
))
468 err
= drm_ioctl(file
, DRM_IOCTL_INFO_BUFS
, (unsigned long)request
);
472 if (__get_user(actual
, &request
->count
))
475 for (i
= 0; i
< actual
; ++i
)
476 if (__copy_in_user(&to
[i
], &list
[i
],
477 offsetof(struct drm_buf_desc
, flags
)))
480 if (__put_user(actual
, &argp
->count
))
486 typedef struct drm_buf_pub32
{
487 int idx
; /**< Index into the master buffer list */
488 int total
; /**< Buffer size */
489 int used
; /**< Amount of buffer in use (for DMA) */
490 u32 address
; /**< Address of buffer */
493 typedef struct drm_buf_map32
{
494 int count
; /**< Length of the buffer list */
495 u32
virtual; /**< Mmap'd area in user-virtual */
496 u32 list
; /**< Buffer information */
499 static int compat_drm_mapbufs(struct file
*file
, unsigned int cmd
,
502 drm_buf_map32_t __user
*argp
= (void __user
*)arg
;
503 drm_buf_map32_t req32
;
504 drm_buf_pub32_t __user
*list32
;
505 struct drm_buf_map __user
*request
;
506 struct drm_buf_pub __user
*list
;
512 if (copy_from_user(&req32
, argp
, sizeof(req32
)))
515 list32
= (void __user
*)(unsigned long)req32
.list
;
519 nbytes
= sizeof(*request
) + count
* sizeof(struct drm_buf_pub
);
520 request
= compat_alloc_user_space(nbytes
);
521 if (!access_ok(VERIFY_WRITE
, request
, nbytes
))
523 list
= (struct drm_buf_pub
*) (request
+ 1);
525 if (__put_user(count
, &request
->count
)
526 || __put_user(list
, &request
->list
))
529 err
= drm_ioctl(file
, DRM_IOCTL_MAP_BUFS
, (unsigned long)request
);
533 if (__get_user(actual
, &request
->count
))
536 for (i
= 0; i
< actual
; ++i
)
537 if (__copy_in_user(&list32
[i
], &list
[i
],
538 offsetof(struct drm_buf_pub
, address
))
539 || __get_user(addr
, &list
[i
].address
)
540 || __put_user((unsigned long)addr
,
544 if (__put_user(actual
, &argp
->count
)
545 || __get_user(addr
, &request
->virtual)
546 || __put_user((unsigned long)addr
, &argp
->virtual))
552 typedef struct drm_buf_free32
{
557 static int compat_drm_freebufs(struct file
*file
, unsigned int cmd
,
560 drm_buf_free32_t req32
;
561 struct drm_buf_free __user
*request
;
562 drm_buf_free32_t __user
*argp
= (void __user
*)arg
;
564 if (copy_from_user(&req32
, argp
, sizeof(req32
)))
567 request
= compat_alloc_user_space(sizeof(*request
));
568 if (!access_ok(VERIFY_WRITE
, request
, sizeof(*request
)))
570 if (__put_user(req32
.count
, &request
->count
)
571 || __put_user((int __user
*)(unsigned long)req32
.list
,
575 return drm_ioctl(file
, DRM_IOCTL_FREE_BUFS
, (unsigned long)request
);
578 typedef struct drm_ctx_priv_map32
{
579 unsigned int ctx_id
; /**< Context requesting private mapping */
580 u32 handle
; /**< Handle of map */
581 } drm_ctx_priv_map32_t
;
583 static int compat_drm_setsareactx(struct file
*file
, unsigned int cmd
,
586 drm_ctx_priv_map32_t req32
;
587 struct drm_ctx_priv_map __user
*request
;
588 drm_ctx_priv_map32_t __user
*argp
= (void __user
*)arg
;
590 if (copy_from_user(&req32
, argp
, sizeof(req32
)))
593 request
= compat_alloc_user_space(sizeof(*request
));
594 if (!access_ok(VERIFY_WRITE
, request
, sizeof(*request
)))
596 if (__put_user(req32
.ctx_id
, &request
->ctx_id
)
597 || __put_user((void *)(unsigned long)req32
.handle
,
601 return drm_ioctl(file
, DRM_IOCTL_SET_SAREA_CTX
, (unsigned long)request
);
604 static int compat_drm_getsareactx(struct file
*file
, unsigned int cmd
,
607 struct drm_ctx_priv_map __user
*request
;
608 drm_ctx_priv_map32_t __user
*argp
= (void __user
*)arg
;
613 if (!access_ok(VERIFY_WRITE
, argp
, sizeof(*argp
))
614 || __get_user(ctx_id
, &argp
->ctx_id
))
617 request
= compat_alloc_user_space(sizeof(*request
));
618 if (!access_ok(VERIFY_WRITE
, request
, sizeof(*request
)))
620 if (__put_user(ctx_id
, &request
->ctx_id
))
623 err
= drm_ioctl(file
, DRM_IOCTL_GET_SAREA_CTX
, (unsigned long)request
);
627 if (__get_user(handle
, &request
->handle
)
628 || __put_user((unsigned long)handle
, &argp
->handle
))
634 typedef struct drm_ctx_res32
{
639 static int compat_drm_resctx(struct file
*file
, unsigned int cmd
,
642 drm_ctx_res32_t __user
*argp
= (void __user
*)arg
;
643 drm_ctx_res32_t res32
;
644 struct drm_ctx_res __user
*res
;
647 if (copy_from_user(&res32
, argp
, sizeof(res32
)))
650 res
= compat_alloc_user_space(sizeof(*res
));
651 if (!access_ok(VERIFY_WRITE
, res
, sizeof(*res
)))
653 if (__put_user(res32
.count
, &res
->count
)
654 || __put_user((struct drm_ctx __user
*) (unsigned long)res32
.contexts
,
658 err
= drm_ioctl(file
, DRM_IOCTL_RES_CTX
, (unsigned long)res
);
662 if (__get_user(res32
.count
, &res
->count
)
663 || __put_user(res32
.count
, &argp
->count
))
669 typedef struct drm_dma32
{
670 int context
; /**< Context handle */
671 int send_count
; /**< Number of buffers to send */
672 u32 send_indices
; /**< List of handles to buffers */
673 u32 send_sizes
; /**< Lengths of data to send */
674 enum drm_dma_flags flags
; /**< Flags */
675 int request_count
; /**< Number of buffers requested */
676 int request_size
; /**< Desired size for buffers */
677 u32 request_indices
; /**< Buffer information */
679 int granted_count
; /**< Number of buffers granted */
682 static int compat_drm_dma(struct file
*file
, unsigned int cmd
,
686 drm_dma32_t __user
*argp
= (void __user
*)arg
;
687 struct drm_dma __user
*d
;
690 if (copy_from_user(&d32
, argp
, sizeof(d32
)))
693 d
= compat_alloc_user_space(sizeof(*d
));
694 if (!access_ok(VERIFY_WRITE
, d
, sizeof(*d
)))
697 if (__put_user(d32
.context
, &d
->context
)
698 || __put_user(d32
.send_count
, &d
->send_count
)
699 || __put_user((int __user
*)(unsigned long)d32
.send_indices
,
701 || __put_user((int __user
*)(unsigned long)d32
.send_sizes
,
703 || __put_user(d32
.flags
, &d
->flags
)
704 || __put_user(d32
.request_count
, &d
->request_count
)
705 || __put_user((int __user
*)(unsigned long)d32
.request_indices
,
707 || __put_user((int __user
*)(unsigned long)d32
.request_sizes
,
711 err
= drm_ioctl(file
, DRM_IOCTL_DMA
, (unsigned long)d
);
715 if (__get_user(d32
.request_size
, &d
->request_size
)
716 || __get_user(d32
.granted_count
, &d
->granted_count
)
717 || __put_user(d32
.request_size
, &argp
->request_size
)
718 || __put_user(d32
.granted_count
, &argp
->granted_count
))
725 typedef struct drm_agp_mode32
{
726 u32 mode
; /**< AGP mode */
729 static int compat_drm_agp_enable(struct file
*file
, unsigned int cmd
,
732 drm_agp_mode32_t __user
*argp
= (void __user
*)arg
;
733 drm_agp_mode32_t m32
;
734 struct drm_agp_mode __user
*mode
;
736 if (get_user(m32
.mode
, &argp
->mode
))
739 mode
= compat_alloc_user_space(sizeof(*mode
));
740 if (put_user(m32
.mode
, &mode
->mode
))
743 return drm_ioctl(file
, DRM_IOCTL_AGP_ENABLE
, (unsigned long)mode
);
746 typedef struct drm_agp_info32
{
747 int agp_version_major
;
748 int agp_version_minor
;
750 u32 aperture_base
; /* physical address */
751 u32 aperture_size
; /* bytes */
752 u32 memory_allowed
; /* bytes */
755 /* PCI information */
756 unsigned short id_vendor
;
757 unsigned short id_device
;
760 static int compat_drm_agp_info(struct file
*file
, unsigned int cmd
,
763 drm_agp_info32_t __user
*argp
= (void __user
*)arg
;
764 drm_agp_info32_t i32
;
765 struct drm_agp_info __user
*info
;
768 info
= compat_alloc_user_space(sizeof(*info
));
769 if (!access_ok(VERIFY_WRITE
, info
, sizeof(*info
)))
772 err
= drm_ioctl(file
, DRM_IOCTL_AGP_INFO
, (unsigned long)info
);
776 if (__get_user(i32
.agp_version_major
, &info
->agp_version_major
)
777 || __get_user(i32
.agp_version_minor
, &info
->agp_version_minor
)
778 || __get_user(i32
.mode
, &info
->mode
)
779 || __get_user(i32
.aperture_base
, &info
->aperture_base
)
780 || __get_user(i32
.aperture_size
, &info
->aperture_size
)
781 || __get_user(i32
.memory_allowed
, &info
->memory_allowed
)
782 || __get_user(i32
.memory_used
, &info
->memory_used
)
783 || __get_user(i32
.id_vendor
, &info
->id_vendor
)
784 || __get_user(i32
.id_device
, &info
->id_device
))
787 if (copy_to_user(argp
, &i32
, sizeof(i32
)))
793 typedef struct drm_agp_buffer32
{
794 u32 size
; /**< In bytes -- will round to page boundary */
795 u32 handle
; /**< Used for binding / unbinding */
796 u32 type
; /**< Type of memory to allocate */
797 u32 physical
; /**< Physical used by i810 */
798 } drm_agp_buffer32_t
;
800 static int compat_drm_agp_alloc(struct file
*file
, unsigned int cmd
,
803 drm_agp_buffer32_t __user
*argp
= (void __user
*)arg
;
804 drm_agp_buffer32_t req32
;
805 struct drm_agp_buffer __user
*request
;
808 if (copy_from_user(&req32
, argp
, sizeof(req32
)))
811 request
= compat_alloc_user_space(sizeof(*request
));
812 if (!access_ok(VERIFY_WRITE
, request
, sizeof(*request
))
813 || __put_user(req32
.size
, &request
->size
)
814 || __put_user(req32
.type
, &request
->type
))
817 err
= drm_ioctl(file
, DRM_IOCTL_AGP_ALLOC
, (unsigned long)request
);
821 if (__get_user(req32
.handle
, &request
->handle
)
822 || __get_user(req32
.physical
, &request
->physical
)
823 || copy_to_user(argp
, &req32
, sizeof(req32
))) {
824 drm_ioctl(file
, DRM_IOCTL_AGP_FREE
, (unsigned long)request
);
831 static int compat_drm_agp_free(struct file
*file
, unsigned int cmd
,
834 drm_agp_buffer32_t __user
*argp
= (void __user
*)arg
;
835 struct drm_agp_buffer __user
*request
;
838 request
= compat_alloc_user_space(sizeof(*request
));
839 if (!access_ok(VERIFY_WRITE
, request
, sizeof(*request
))
840 || get_user(handle
, &argp
->handle
)
841 || __put_user(handle
, &request
->handle
))
844 return drm_ioctl(file
, DRM_IOCTL_AGP_FREE
, (unsigned long)request
);
847 typedef struct drm_agp_binding32
{
848 u32 handle
; /**< From drm_agp_buffer */
849 u32 offset
; /**< In bytes -- will round to page boundary */
850 } drm_agp_binding32_t
;
852 static int compat_drm_agp_bind(struct file
*file
, unsigned int cmd
,
855 drm_agp_binding32_t __user
*argp
= (void __user
*)arg
;
856 drm_agp_binding32_t req32
;
857 struct drm_agp_binding __user
*request
;
859 if (copy_from_user(&req32
, argp
, sizeof(req32
)))
862 request
= compat_alloc_user_space(sizeof(*request
));
863 if (!access_ok(VERIFY_WRITE
, request
, sizeof(*request
))
864 || __put_user(req32
.handle
, &request
->handle
)
865 || __put_user(req32
.offset
, &request
->offset
))
868 return drm_ioctl(file
, DRM_IOCTL_AGP_BIND
, (unsigned long)request
);
871 static int compat_drm_agp_unbind(struct file
*file
, unsigned int cmd
,
874 drm_agp_binding32_t __user
*argp
= (void __user
*)arg
;
875 struct drm_agp_binding __user
*request
;
878 request
= compat_alloc_user_space(sizeof(*request
));
879 if (!access_ok(VERIFY_WRITE
, request
, sizeof(*request
))
880 || get_user(handle
, &argp
->handle
)
881 || __put_user(handle
, &request
->handle
))
884 return drm_ioctl(file
, DRM_IOCTL_AGP_UNBIND
, (unsigned long)request
);
886 #endif /* __OS_HAS_AGP */
888 typedef struct drm_scatter_gather32
{
889 u32 size
; /**< In bytes -- will round to page boundary */
890 u32 handle
; /**< Used for mapping / unmapping */
891 } drm_scatter_gather32_t
;
893 static int compat_drm_sg_alloc(struct file
*file
, unsigned int cmd
,
896 drm_scatter_gather32_t __user
*argp
= (void __user
*)arg
;
897 struct drm_scatter_gather __user
*request
;
901 request
= compat_alloc_user_space(sizeof(*request
));
902 if (!access_ok(VERIFY_WRITE
, request
, sizeof(*request
))
903 || !access_ok(VERIFY_WRITE
, argp
, sizeof(*argp
))
904 || __get_user(x
, &argp
->size
)
905 || __put_user(x
, &request
->size
))
908 err
= drm_ioctl(file
, DRM_IOCTL_SG_ALLOC
, (unsigned long)request
);
912 /* XXX not sure about the handle conversion here... */
913 if (__get_user(x
, &request
->handle
)
914 || __put_user(x
>> PAGE_SHIFT
, &argp
->handle
))
920 static int compat_drm_sg_free(struct file
*file
, unsigned int cmd
,
923 drm_scatter_gather32_t __user
*argp
= (void __user
*)arg
;
924 struct drm_scatter_gather __user
*request
;
927 request
= compat_alloc_user_space(sizeof(*request
));
928 if (!access_ok(VERIFY_WRITE
, request
, sizeof(*request
))
929 || !access_ok(VERIFY_WRITE
, argp
, sizeof(*argp
))
930 || __get_user(x
, &argp
->handle
)
931 || __put_user(x
<< PAGE_SHIFT
, &request
->handle
))
934 return drm_ioctl(file
, DRM_IOCTL_SG_FREE
, (unsigned long)request
);
937 #if defined(CONFIG_X86) || defined(CONFIG_IA64)
938 typedef struct drm_update_draw32
{
939 drm_drawable_t handle
;
942 /* 64-bit version has a 32-bit pad here */
943 u64 data
; /**< Pointer */
944 } __attribute__((packed
)) drm_update_draw32_t
;
946 static int compat_drm_update_draw(struct file
*file
, unsigned int cmd
,
949 drm_update_draw32_t update32
;
950 struct drm_update_draw __user
*request
;
953 if (copy_from_user(&update32
, (void __user
*)arg
, sizeof(update32
)))
956 request
= compat_alloc_user_space(sizeof(*request
));
957 if (!access_ok(VERIFY_WRITE
, request
, sizeof(*request
)) ||
958 __put_user(update32
.handle
, &request
->handle
) ||
959 __put_user(update32
.type
, &request
->type
) ||
960 __put_user(update32
.num
, &request
->num
) ||
961 __put_user(update32
.data
, &request
->data
))
964 err
= drm_ioctl(file
, DRM_IOCTL_UPDATE_DRAW
, (unsigned long)request
);
969 struct drm_wait_vblank_request32
{
970 enum drm_vblank_seq_type type
;
971 unsigned int sequence
;
975 struct drm_wait_vblank_reply32
{
976 enum drm_vblank_seq_type type
;
977 unsigned int sequence
;
982 typedef union drm_wait_vblank32
{
983 struct drm_wait_vblank_request32 request
;
984 struct drm_wait_vblank_reply32 reply
;
985 } drm_wait_vblank32_t
;
987 static int compat_drm_wait_vblank(struct file
*file
, unsigned int cmd
,
990 drm_wait_vblank32_t __user
*argp
= (void __user
*)arg
;
991 drm_wait_vblank32_t req32
;
992 union drm_wait_vblank __user
*request
;
995 if (copy_from_user(&req32
, argp
, sizeof(req32
)))
998 request
= compat_alloc_user_space(sizeof(*request
));
999 if (!access_ok(VERIFY_WRITE
, request
, sizeof(*request
))
1000 || __put_user(req32
.request
.type
, &request
->request
.type
)
1001 || __put_user(req32
.request
.sequence
, &request
->request
.sequence
)
1002 || __put_user(req32
.request
.signal
, &request
->request
.signal
))
1005 err
= drm_ioctl(file
, DRM_IOCTL_WAIT_VBLANK
, (unsigned long)request
);
1009 if (__get_user(req32
.reply
.type
, &request
->reply
.type
)
1010 || __get_user(req32
.reply
.sequence
, &request
->reply
.sequence
)
1011 || __get_user(req32
.reply
.tval_sec
, &request
->reply
.tval_sec
)
1012 || __get_user(req32
.reply
.tval_usec
, &request
->reply
.tval_usec
))
1015 if (copy_to_user(argp
, &req32
, sizeof(req32
)))
1021 typedef struct drm_mode_fb_cmd232
{
1031 } __attribute__((packed
)) drm_mode_fb_cmd232_t
;
1033 static int compat_drm_mode_addfb2(struct file
*file
, unsigned int cmd
,
1036 struct drm_mode_fb_cmd232 __user
*argp
= (void __user
*)arg
;
1037 struct drm_mode_fb_cmd232 req32
;
1038 struct drm_mode_fb_cmd2 __user
*req64
;
1042 if (copy_from_user(&req32
, argp
, sizeof(req32
)))
1045 req64
= compat_alloc_user_space(sizeof(*req64
));
1047 if (!access_ok(VERIFY_WRITE
, req64
, sizeof(*req64
))
1048 || __put_user(req32
.width
, &req64
->width
)
1049 || __put_user(req32
.height
, &req64
->height
)
1050 || __put_user(req32
.pixel_format
, &req64
->pixel_format
)
1051 || __put_user(req32
.flags
, &req64
->flags
))
1054 for (i
= 0; i
< 4; i
++) {
1055 if (__put_user(req32
.handles
[i
], &req64
->handles
[i
]))
1057 if (__put_user(req32
.pitches
[i
], &req64
->pitches
[i
]))
1059 if (__put_user(req32
.offsets
[i
], &req64
->offsets
[i
]))
1061 if (__put_user(req32
.modifier
[i
], &req64
->modifier
[i
]))
1065 err
= drm_ioctl(file
, DRM_IOCTL_MODE_ADDFB2
, (unsigned long)req64
);
1069 if (__get_user(req32
.fb_id
, &req64
->fb_id
))
1072 if (copy_to_user(argp
, &req32
, sizeof(req32
)))
1078 static drm_ioctl_compat_t
*drm_compat_ioctls
[] = {
1079 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32
)] = compat_drm_version
,
1080 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32
)] = compat_drm_getunique
,
1081 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32
)] = compat_drm_getmap
,
1082 [DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT32
)] = compat_drm_getclient
,
1083 [DRM_IOCTL_NR(DRM_IOCTL_GET_STATS32
)] = compat_drm_getstats
,
1084 [DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE32
)] = compat_drm_setunique
,
1085 [DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP32
)] = compat_drm_addmap
,
1086 [DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS32
)] = compat_drm_addbufs
,
1087 [DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS32
)] = compat_drm_markbufs
,
1088 [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS32
)] = compat_drm_infobufs
,
1089 [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS32
)] = compat_drm_mapbufs
,
1090 [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS32
)] = compat_drm_freebufs
,
1091 [DRM_IOCTL_NR(DRM_IOCTL_RM_MAP32
)] = compat_drm_rmmap
,
1092 [DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX32
)] = compat_drm_setsareactx
,
1093 [DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX32
)] = compat_drm_getsareactx
,
1094 [DRM_IOCTL_NR(DRM_IOCTL_RES_CTX32
)] = compat_drm_resctx
,
1095 [DRM_IOCTL_NR(DRM_IOCTL_DMA32
)] = compat_drm_dma
,
1097 [DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE32
)] = compat_drm_agp_enable
,
1098 [DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO32
)] = compat_drm_agp_info
,
1099 [DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC32
)] = compat_drm_agp_alloc
,
1100 [DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE32
)] = compat_drm_agp_free
,
1101 [DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND32
)] = compat_drm_agp_bind
,
1102 [DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND32
)] = compat_drm_agp_unbind
,
1104 [DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC32
)] = compat_drm_sg_alloc
,
1105 [DRM_IOCTL_NR(DRM_IOCTL_SG_FREE32
)] = compat_drm_sg_free
,
1106 #if defined(CONFIG_X86) || defined(CONFIG_IA64)
1107 [DRM_IOCTL_NR(DRM_IOCTL_UPDATE_DRAW32
)] = compat_drm_update_draw
,
1109 [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK32
)] = compat_drm_wait_vblank
,
1110 [DRM_IOCTL_NR(DRM_IOCTL_MODE_ADDFB232
)] = compat_drm_mode_addfb2
,
1114 * Called whenever a 32-bit process running under a 64-bit kernel
1115 * performs an ioctl on /dev/drm.
1117 * \param file_priv DRM file private.
1118 * \param cmd command.
1119 * \param arg user argument.
1120 * \return zero on success or negative number on failure.
1122 long drm_compat_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
1124 unsigned int nr
= DRM_IOCTL_NR(cmd
);
1125 drm_ioctl_compat_t
*fn
;
1128 /* Assume that ioctls without an explicit compat routine will just
1129 * work. This may not always be a good assumption, but it's better
1130 * than always failing.
1132 if (nr
>= ARRAY_SIZE(drm_compat_ioctls
))
1133 return drm_ioctl(filp
, cmd
, arg
);
1135 fn
= drm_compat_ioctls
[nr
];
1138 ret
= (*fn
) (filp
, cmd
, arg
);
1140 ret
= drm_ioctl(filp
, cmd
, arg
);
1145 EXPORT_SYMBOL(drm_compat_ioctl
);