blob: 2218a946ec872e4041232b01d23a77624349e5b7 [file] [log] [blame]
Dave Airlie8ca7c1d2005-07-07 21:51:26 +10001/**
2 * \file i915_ioc32.c
3 *
4 * 32-bit ioctl compatibility routines for the i915 DRM.
5 *
Dave Airlieb5e89ed2005-09-25 14:28:13 +10006 * \author Alan Hourihane <alanh@fairlite.demon.co.uk>
Dave Airlie8ca7c1d2005-07-07 21:51:26 +10007 *
8 *
9 * Copyright (C) Paul Mackerras 2005
10 * Copyright (C) Alan Hourihane 2005
11 * All Rights Reserved.
12 *
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:
19 *
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
22 * Software.
23 *
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
30 * IN THE SOFTWARE.
31 */
32#include <linux/compat.h>
33#include <linux/ioctl32.h>
34
35#include "drmP.h"
36#include "drm.h"
37#include "i915_drm.h"
38
39typedef 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? */
Dave Airlieb5e89ed2005-09-25 14:28:13 +100045 u32 cliprects; /* pointer to userspace cliprects */
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100046} drm_i915_batchbuffer32_t;
47
48static int compat_i915_batchbuffer(struct file *file, unsigned int cmd,
Dave Airlieb5e89ed2005-09-25 14:28:13 +100049 unsigned long arg)
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100050{
51 drm_i915_batchbuffer32_t batchbuffer32;
52 drm_i915_batchbuffer_t __user *batchbuffer;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100053
54 if (copy_from_user
55 (&batchbuffer32, (void __user *)arg, sizeof(batchbuffer32)))
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100056 return -EFAULT;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100057
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100058 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)
Dave Airlieb5e89ed2005-09-25 14:28:13 +100064 || __put_user(batchbuffer32.num_cliprects,
65 &batchbuffer->num_cliprects)
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100066 || __put_user((int __user *)(unsigned long)batchbuffer32.cliprects,
67 &batchbuffer->cliprects))
68 return -EFAULT;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100069
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100070 return drm_ioctl(file->f_dentry->d_inode, file,
Dave Airlieb5e89ed2005-09-25 14:28:13 +100071 DRM_IOCTL_I915_BATCHBUFFER,
72 (unsigned long)batchbuffer);
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100073}
74
75typedef struct _drm_i915_cmdbuffer32 {
Dave Airlieb5e89ed2005-09-25 14:28:13 +100076 u32 buf; /* pointer to userspace command buffer */
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100077 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? */
Dave Airlieb5e89ed2005-09-25 14:28:13 +100081 u32 cliprects; /* pointer to userspace cliprects */
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100082} drm_i915_cmdbuffer32_t;
83
84static int compat_i915_cmdbuffer(struct file *file, unsigned int cmd,
Dave Airlieb5e89ed2005-09-25 14:28:13 +100085 unsigned long arg)
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100086{
87 drm_i915_cmdbuffer32_t cmdbuffer32;
88 drm_i915_cmdbuffer_t __user *cmdbuffer;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100089
90 if (copy_from_user
91 (&cmdbuffer32, (void __user *)arg, sizeof(cmdbuffer32)))
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100092 return -EFAULT;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100093
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100094 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,
97 &cmdbuffer->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))
104 return -EFAULT;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000105
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000106 return drm_ioctl(file->f_dentry->d_inode, file,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000107 DRM_IOCTL_I915_CMDBUFFER, (unsigned long)cmdbuffer);
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000108}
109
110typedef struct drm_i915_irq_emit32 {
111 u32 irq_seq;
112} drm_i915_irq_emit32_t;
113
114static int compat_i915_irq_emit(struct file *file, unsigned int cmd,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000115 unsigned long arg)
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000116{
117 drm_i915_irq_emit32_t req32;
118 drm_i915_irq_emit_t __user *request;
119
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000120 if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000121 return -EFAULT;
122
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,
126 &request->irq_seq))
127 return -EFAULT;
128
129 return drm_ioctl(file->f_dentry->d_inode, file,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000130 DRM_IOCTL_I915_IRQ_EMIT, (unsigned long)request);
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000131}
132typedef struct drm_i915_getparam32 {
133 int param;
134 u32 value;
135} drm_i915_getparam32_t;
136
137static int compat_i915_getparam(struct file *file, unsigned int cmd,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000138 unsigned long arg)
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000139{
140 drm_i915_getparam32_t req32;
141 drm_i915_getparam_t __user *request;
142
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000143 if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000144 return -EFAULT;
145
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,
150 &request->value))
151 return -EFAULT;
152
153 return drm_ioctl(file->f_dentry->d_inode, file,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000154 DRM_IOCTL_I915_GETPARAM, (unsigned long)request);
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000155}
156
157typedef struct drm_i915_mem_alloc32 {
158 int region;
159 int alignment;
160 int size;
161 u32 region_offset; /* offset from start of fb or agp */
162} drm_i915_mem_alloc32_t;
163
164static int compat_i915_alloc(struct file *file, unsigned int cmd,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000165 unsigned long arg)
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000166{
167 drm_i915_mem_alloc32_t req32;
168 drm_i915_mem_alloc_t __user *request;
169
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000170 if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000171 return -EFAULT;
172
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))
180 return -EFAULT;
181
182 return drm_ioctl(file->f_dentry->d_inode, file,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000183 DRM_IOCTL_I915_ALLOC, (unsigned long)request);
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000184}
185
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000186drm_ioctl_compat_t *i915_compat_ioctls[] = {
187 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
188 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
189 [DRM_I915_GETPARAM] = compat_i915_getparam,
190 [DRM_I915_IRQ_EMIT] = compat_i915_irq_emit,
191 [DRM_I915_ALLOC] = compat_i915_alloc
192};
193
194/**
195 * Called whenever a 32-bit process running under a 64-bit kernel
196 * performs an ioctl on /dev/dri/card<n>.
197 *
198 * \param filp file pointer.
199 * \param cmd command.
200 * \param arg user argument.
201 * \return zero on success or negative number on failure.
202 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000203long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000204{
205 unsigned int nr = DRM_IOCTL_NR(cmd);
206 drm_ioctl_compat_t *fn = NULL;
207 int ret;
208
209 if (nr < DRM_COMMAND_BASE)
210 return drm_compat_ioctl(filp, cmd, arg);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000211
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000212 if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
213 fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
214
215 lock_kernel(); /* XXX for now */
216 if (fn != NULL)
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000217 ret = (*fn) (filp, cmd, arg);
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000218 else
219 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
220 unlock_kernel();
221
222 return ret;
223}