4 * 32-bit ioctl compatibility routines for the i915 DRM.
6 * \author Alan Hourihane <alanh@fairlite.demon.co.uk>
9 * Copyright (C) Paul Mackerras 2005
10 * Copyright (C) Alan Hourihane 2005
11 * All Rights Reserved.
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
20 * The above copyright notice and this permission notice (including the next
21 * paragraph) shall be included in all copies or substantial portions of the
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include <linux/compat.h>
39 typedef struct _drm_i915_batchbuffer32 {
40 int start; /* agp offset */
41 int used; /* nr bytes in use */
42 int DR1; /* hw flags for GFX_OP_DRAWRECT_INFO */
43 int DR4; /* window origin for GFX_OP_DRAWRECT_INFO */
44 int num_cliprects; /* mulitpass with multiple cliprects? */
45 u32 cliprects; /* pointer to userspace cliprects */
46 } drm_i915_batchbuffer32_t;
48 static int compat_i915_batchbuffer(struct file *file, unsigned int cmd,
51 drm_i915_batchbuffer32_t batchbuffer32;
52 drm_i915_batchbuffer_t __user *batchbuffer;
55 (&batchbuffer32, (void __user *)arg, sizeof(batchbuffer32)))
58 batchbuffer = compat_alloc_user_space(sizeof(*batchbuffer));
59 if (!access_ok(VERIFY_WRITE, batchbuffer, sizeof(*batchbuffer))
60 || __put_user(batchbuffer32.start, &batchbuffer->start)
61 || __put_user(batchbuffer32.used, &batchbuffer->used)
62 || __put_user(batchbuffer32.DR1, &batchbuffer->DR1)
63 || __put_user(batchbuffer32.DR4, &batchbuffer->DR4)
64 || __put_user(batchbuffer32.num_cliprects,
65 &batchbuffer->num_cliprects)
66 || __put_user((int __user *)(unsigned long)batchbuffer32.cliprects,
67 &batchbuffer->cliprects))
70 return drm_ioctl(file->f_dentry->d_inode, file,
71 DRM_IOCTL_I915_BATCHBUFFER,
72 (unsigned long) batchbuffer);
75 typedef struct _drm_i915_cmdbuffer32 {
76 u32 buf; /* pointer to userspace command buffer */
77 int sz; /* nr bytes in buf */
78 int DR1; /* hw flags for GFX_OP_DRAWRECT_INFO */
79 int DR4; /* window origin for GFX_OP_DRAWRECT_INFO */
80 int num_cliprects; /* mulitpass with multiple cliprects? */
81 u32 cliprects; /* pointer to userspace cliprects */
82 } drm_i915_cmdbuffer32_t;
84 static int compat_i915_cmdbuffer(struct file *file, unsigned int cmd,
87 drm_i915_cmdbuffer32_t cmdbuffer32;
88 drm_i915_cmdbuffer_t __user *cmdbuffer;
91 (&cmdbuffer32, (void __user *)arg, sizeof(cmdbuffer32)))
94 cmdbuffer = compat_alloc_user_space(sizeof(*cmdbuffer));
95 if (!access_ok(VERIFY_WRITE, cmdbuffer, sizeof(*cmdbuffer))
96 || __put_user((int __user *)(unsigned long)cmdbuffer32.buf,
98 || __put_user(cmdbuffer32.sz, &cmdbuffer->sz)
99 || __put_user(cmdbuffer32.DR1, &cmdbuffer->DR1)
100 || __put_user(cmdbuffer32.DR4, &cmdbuffer->DR4)
101 || __put_user(cmdbuffer32.num_cliprects, &cmdbuffer->num_cliprects)
102 || __put_user((int __user *)(unsigned long)cmdbuffer32.cliprects,
103 &cmdbuffer->cliprects))
106 return drm_ioctl(file->f_dentry->d_inode, file,
107 DRM_IOCTL_I915_CMDBUFFER, (unsigned long) cmdbuffer);
110 typedef struct drm_i915_irq_emit32 {
112 } drm_i915_irq_emit32_t;
114 static int compat_i915_irq_emit(struct file *file, unsigned int cmd,
117 drm_i915_irq_emit32_t req32;
118 drm_i915_irq_emit_t __user *request;
120 if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
123 request = compat_alloc_user_space(sizeof(*request));
124 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
125 || __put_user((int __user *)(unsigned long)req32.irq_seq,
129 return drm_ioctl(file->f_dentry->d_inode, file,
130 DRM_IOCTL_I915_IRQ_EMIT, (unsigned long) request);
132 typedef struct drm_i915_getparam32 {
135 } drm_i915_getparam32_t;
137 static int compat_i915_getparam(struct file *file, unsigned int cmd,
140 drm_i915_getparam32_t req32;
141 drm_i915_getparam_t __user *request;
143 if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
146 request = compat_alloc_user_space(sizeof(*request));
147 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
148 || __put_user(req32.param, &request->param)
149 || __put_user((void __user *)(unsigned long)req32.value,
153 return drm_ioctl(file->f_dentry->d_inode, file,
154 DRM_IOCTL_I915_GETPARAM, (unsigned long) request);
157 typedef struct drm_i915_mem_alloc32 {
161 u32 region_offset; /* offset from start of fb or agp */
162 } drm_i915_mem_alloc32_t;
164 static int compat_i915_alloc(struct file *file, unsigned int cmd,
167 drm_i915_mem_alloc32_t req32;
168 drm_i915_mem_alloc_t __user *request;
170 if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
173 request = compat_alloc_user_space(sizeof(*request));
174 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
175 || __put_user(req32.region, &request->region)
176 || __put_user(req32.alignment, &request->alignment)
177 || __put_user(req32.size, &request->size)
178 || __put_user((void __user *)(unsigned long)req32.region_offset,
179 &request->region_offset))
182 return drm_ioctl(file->f_dentry->d_inode, file,
183 DRM_IOCTL_I915_ALLOC, (unsigned long) request);
186 typedef struct drm_i915_execbuffer32 {
188 uint32_t num_buffers;
189 struct _drm_i915_batchbuffer32 batch;
190 drm_context_t context;
191 struct drm_fence_arg fence_arg;
192 } drm_i915_execbuffer32_t;
194 static int compat_i915_execbuffer(struct file *file, unsigned int cmd,
197 drm_i915_execbuffer32_t req32;
198 struct drm_i915_execbuffer __user *request;
201 if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
204 request = compat_alloc_user_space(sizeof(*request));
206 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
207 || __put_user(req32.ops_list, &request->ops_list)
208 || __put_user(req32.num_buffers, &request->num_buffers)
209 || __put_user(req32.context, &request->context)
210 || __copy_to_user(&request->fence_arg, &req32.fence_arg,
211 sizeof(req32.fence_arg))
212 || __put_user(req32.batch.start, &request->batch.start)
213 || __put_user(req32.batch.used, &request->batch.used)
214 || __put_user(req32.batch.DR1, &request->batch.DR1)
215 || __put_user(req32.batch.DR4, &request->batch.DR4)
216 || __put_user(req32.batch.num_cliprects,
217 &request->batch.num_cliprects)
218 || __put_user((int __user *)(unsigned long)req32.batch.cliprects,
219 &request->batch.cliprects))
222 err = drm_ioctl(file->f_dentry->d_inode, file,
223 DRM_IOCTL_I915_EXECBUFFER, (unsigned long)request);
228 if (__get_user(req32.fence_arg.handle, &request->fence_arg.handle)
229 || __get_user(req32.fence_arg.fence_class, &request->fence_arg.fence_class)
230 || __get_user(req32.fence_arg.type, &request->fence_arg.type)
231 || __get_user(req32.fence_arg.flags, &request->fence_arg.flags)
232 || __get_user(req32.fence_arg.signaled, &request->fence_arg.signaled)
233 || __get_user(req32.fence_arg.error, &request->fence_arg.error)
234 || __get_user(req32.fence_arg.sequence, &request->fence_arg.sequence))
237 if (copy_to_user((void __user *)arg, &req32, sizeof(req32)))
244 drm_ioctl_compat_t *i915_compat_ioctls[] = {
245 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
246 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
247 [DRM_I915_GETPARAM] = compat_i915_getparam,
248 [DRM_I915_IRQ_EMIT] = compat_i915_irq_emit,
249 [DRM_I915_ALLOC] = compat_i915_alloc,
250 #ifdef I915_HAVE_BUFFER
251 [DRM_I915_EXECBUFFER] = compat_i915_execbuffer,
256 * Called whenever a 32-bit process running under a 64-bit kernel
257 * performs an ioctl on /dev/dri/card<n>.
259 * \param filp file pointer.
260 * \param cmd command.
261 * \param arg user argument.
262 * \return zero on success or negative number on failure.
264 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
266 unsigned int nr = DRM_IOCTL_NR(cmd);
267 drm_ioctl_compat_t *fn = NULL;
270 if (nr < DRM_COMMAND_BASE)
271 return drm_compat_ioctl(filp, cmd, arg);
273 if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
274 fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
276 lock_kernel(); /* XXX for now */
278 ret = (*fn)(filp, cmd, arg);
280 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);