drm: add 32/64 support for MGA/R128/i915
[linux-2.6.git] / drivers / char / drm / r128_ioc32.c
1 /**
2  * \file r128_ioc32.c
3  *
4  * 32-bit ioctl compatibility routines for the R128 DRM.
5  *
6  * \author Dave Airlie <airlied@linux.ie> with code from patches by Egbert Eich
7  *
8  * Copyright (C) Paul Mackerras 2005
9  * Copyright (C) Egbert Eich 2003,2004
10  * Copyright (C) Dave Airlie 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 "r128_drm.h"
38
39 typedef struct drm_r128_init32 {
40         int func;
41         unsigned int sarea_priv_offset;
42         int is_pci;
43         int cce_mode;
44         int cce_secure;
45         int ring_size;
46         int usec_timeout;
47
48         unsigned int fb_bpp;
49         unsigned int front_offset, front_pitch;
50         unsigned int back_offset, back_pitch;
51         unsigned int depth_bpp;
52         unsigned int depth_offset, depth_pitch;
53         unsigned int span_offset;
54
55         unsigned int fb_offset;
56         unsigned int mmio_offset;
57         unsigned int ring_offset;
58         unsigned int ring_rptr_offset;
59         unsigned int buffers_offset;
60         unsigned int agp_textures_offset;
61 } drm_r128_init32_t;
62
63 static int compat_r128_init(struct file *file, unsigned int cmd,
64                             unsigned long arg)
65 {
66         drm_r128_init32_t init32;
67         drm_r128_init_t __user *init;
68         
69         if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
70                 return -EFAULT;
71         
72         init = compat_alloc_user_space(sizeof(*init));
73         if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
74             || __put_user(init32.func, &init->func)
75             || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
76             || __put_user(init32.is_pci, &init->is_pci)
77             || __put_user(init32.cce_mode, &init->cce_mode)
78             || __put_user(init32.cce_secure, &init->cce_secure)
79             || __put_user(init32.ring_size, &init->ring_size)
80             || __put_user(init32.usec_timeout, &init->usec_timeout)
81             || __put_user(init32.fb_bpp, &init->fb_bpp)
82             || __put_user(init32.front_offset, &init->front_offset)
83             || __put_user(init32.front_pitch, &init->front_pitch)
84             || __put_user(init32.back_offset, &init->back_offset)
85             || __put_user(init32.back_pitch, &init->back_pitch)
86             || __put_user(init32.depth_bpp, &init->depth_bpp)
87             || __put_user(init32.depth_offset, &init->depth_offset)
88             || __put_user(init32.depth_pitch, &init->depth_pitch)
89             || __put_user(init32.span_offset, &init->span_offset)
90             || __put_user(init32.fb_offset, &init->fb_offset)
91             || __put_user(init32.mmio_offset, &init->mmio_offset)
92             || __put_user(init32.ring_offset, &init->ring_offset)
93             || __put_user(init32.ring_rptr_offset, &init->ring_rptr_offset)
94             || __put_user(init32.buffers_offset, &init->buffers_offset)
95             || __put_user(init32.agp_textures_offset, &init->agp_textures_offset))
96                 return -EFAULT;
97         
98         return drm_ioctl(file->f_dentry->d_inode, file,
99                          DRM_IOCTL_R128_INIT, (unsigned long)init);
100 }
101
102
103 typedef struct drm_r128_depth32 {
104         int func;
105         int n;
106         u32 x;
107         u32 y;
108         u32 buffer;
109         u32 mask;
110 } drm_r128_depth32_t;
111
112 static int compat_r128_depth(struct file *file, unsigned int cmd,
113                              unsigned long arg)
114 {
115         drm_r128_depth32_t depth32;
116         drm_r128_depth_t __user *depth;
117
118         if (copy_from_user(&depth32, (void __user *)arg, sizeof(depth32)))
119                 return -EFAULT;
120
121         depth = compat_alloc_user_space(sizeof(*depth));
122         if (!access_ok(VERIFY_WRITE, depth, sizeof(*depth))
123             || __put_user(depth32.func, &depth->func)
124             || __put_user(depth32.n, &depth->n)
125             || __put_user((int __user *)(unsigned long)depth32.x, &depth->x)
126             || __put_user((int __user *)(unsigned long)depth32.y, &depth->y)
127             || __put_user((unsigned int __user *)(unsigned long)depth32.buffer, &depth->buffer)
128             || __put_user((unsigned char __user *)(unsigned long)depth32.mask, &depth->mask))
129                 return -EFAULT;
130         
131         return drm_ioctl(file->f_dentry->d_inode, file,
132                          DRM_IOCTL_R128_DEPTH, (unsigned long)depth);   
133         
134 }
135
136 typedef struct drm_r128_stipple32 {
137         u32 mask;
138 } drm_r128_stipple32_t;
139
140 static int compat_r128_stipple(struct file *file, unsigned int cmd,
141                                unsigned long arg)
142 {
143         drm_r128_stipple32_t stipple32;
144         drm_r128_stipple_t __user *stipple;
145
146         if (copy_from_user(&stipple32, (void __user *)arg, sizeof(stipple32)))
147                 return -EFAULT;
148
149         stipple = compat_alloc_user_space(sizeof(*stipple));
150         if (!access_ok(VERIFY_WRITE, stipple, sizeof(*stipple))
151             || __put_user((unsigned int __user *)(unsigned long)stipple32.mask, &stipple->mask))
152                 return -EFAULT;
153
154         return drm_ioctl(file->f_dentry->d_inode, file,
155                          DRM_IOCTL_R128_STIPPLE, (unsigned long)stipple);
156 }
157
158 typedef struct drm_r128_getparam32 {
159         int param;
160         u32 value;
161 } drm_r128_getparam32_t;
162
163 static int compat_r128_getparam(struct file *file, unsigned int cmd,
164                                 unsigned long arg)
165 {
166         drm_r128_getparam32_t getparam32;
167         drm_r128_getparam_t __user *getparam;
168
169         if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
170                 return -EFAULT;
171
172         getparam = compat_alloc_user_space(sizeof(*getparam));
173         if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam))
174             || __put_user(getparam32.param, &getparam->param)
175             || __put_user((void __user *)(unsigned long)getparam32.value, &getparam->value))
176                 return -EFAULT;
177         
178         return drm_ioctl(file->f_dentry->d_inode, file,
179                          DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
180 }
181
182 drm_ioctl_compat_t *r128_compat_ioctls[] = {
183         [DRM_R128_INIT] = compat_r128_init,
184         [DRM_R128_DEPTH] = compat_r128_depth,
185         [DRM_R128_STIPPLE] = compat_r128_stipple,
186         [DRM_R128_GETPARAM] = compat_r128_getparam,
187 };
188
189 /**
190  * Called whenever a 32-bit process running under a 64-bit kernel
191  * performs an ioctl on /dev/dri/card<n>.
192  *
193  * \param filp file pointer.
194  * \param cmd command.
195  * \param arg user argument.
196  * \return zero on success or negative number on failure.
197  */
198 long r128_compat_ioctl(struct file *filp, unsigned int cmd,
199                          unsigned long arg)
200 {
201         unsigned int nr = DRM_IOCTL_NR(cmd);
202         drm_ioctl_compat_t *fn = NULL;
203         int ret;
204
205         if (nr < DRM_COMMAND_BASE)
206                 return drm_compat_ioctl(filp, cmd, arg);
207
208         if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
209                 fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
210
211         lock_kernel();          /* XXX for now */
212         if (fn != NULL)
213                 ret = (*fn)(filp, cmd, arg);
214         else
215                 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
216         unlock_kernel();
217
218         return ret;
219 }