Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
r128_ioc32.c
Go to the documentation of this file.
1 
32 #include <linux/compat.h>
33 
34 #include <drm/drmP.h>
35 #include <drm/r128_drm.h>
36 
37 typedef struct drm_r128_init32 {
38  int func;
39  unsigned int sarea_priv_offset;
40  int is_pci;
41  int cce_mode;
43  int ring_size;
45 
46  unsigned int fb_bpp;
47  unsigned int front_offset, front_pitch;
48  unsigned int back_offset, back_pitch;
49  unsigned int depth_bpp;
50  unsigned int depth_offset, depth_pitch;
51  unsigned int span_offset;
52 
53  unsigned int fb_offset;
54  unsigned int mmio_offset;
55  unsigned int ring_offset;
56  unsigned int ring_rptr_offset;
57  unsigned int buffers_offset;
58  unsigned int agp_textures_offset;
60 
61 static int compat_r128_init(struct file *file, unsigned int cmd,
62  unsigned long arg)
63 {
64  drm_r128_init32_t init32;
66 
67  if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
68  return -EFAULT;
69 
70  init = compat_alloc_user_space(sizeof(*init));
71  if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
72  || __put_user(init32.func, &init->func)
73  || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
74  || __put_user(init32.is_pci, &init->is_pci)
75  || __put_user(init32.cce_mode, &init->cce_mode)
76  || __put_user(init32.cce_secure, &init->cce_secure)
77  || __put_user(init32.ring_size, &init->ring_size)
78  || __put_user(init32.usec_timeout, &init->usec_timeout)
79  || __put_user(init32.fb_bpp, &init->fb_bpp)
80  || __put_user(init32.front_offset, &init->front_offset)
81  || __put_user(init32.front_pitch, &init->front_pitch)
82  || __put_user(init32.back_offset, &init->back_offset)
83  || __put_user(init32.back_pitch, &init->back_pitch)
84  || __put_user(init32.depth_bpp, &init->depth_bpp)
85  || __put_user(init32.depth_offset, &init->depth_offset)
86  || __put_user(init32.depth_pitch, &init->depth_pitch)
87  || __put_user(init32.span_offset, &init->span_offset)
88  || __put_user(init32.fb_offset, &init->fb_offset)
89  || __put_user(init32.mmio_offset, &init->mmio_offset)
90  || __put_user(init32.ring_offset, &init->ring_offset)
91  || __put_user(init32.ring_rptr_offset, &init->ring_rptr_offset)
92  || __put_user(init32.buffers_offset, &init->buffers_offset)
94  &init->agp_textures_offset))
95  return -EFAULT;
96 
97  return drm_ioctl(file, DRM_IOCTL_R128_INIT, (unsigned long)init);
98 }
99 
100 typedef struct drm_r128_depth32 {
101  int func;
102  int n;
108 
109 static int compat_r128_depth(struct file *file, unsigned int cmd,
110  unsigned long arg)
111 {
112  drm_r128_depth32_t depth32;
114 
115  if (copy_from_user(&depth32, (void __user *)arg, sizeof(depth32)))
116  return -EFAULT;
117 
118  depth = compat_alloc_user_space(sizeof(*depth));
119  if (!access_ok(VERIFY_WRITE, depth, sizeof(*depth))
120  || __put_user(depth32.func, &depth->func)
121  || __put_user(depth32.n, &depth->n)
122  || __put_user((int __user *)(unsigned long)depth32.x, &depth->x)
123  || __put_user((int __user *)(unsigned long)depth32.y, &depth->y)
124  || __put_user((unsigned int __user *)(unsigned long)depth32.buffer,
125  &depth->buffer)
126  || __put_user((unsigned char __user *)(unsigned long)depth32.mask,
127  &depth->mask))
128  return -EFAULT;
129 
130  return drm_ioctl(file, DRM_IOCTL_R128_DEPTH, (unsigned long)depth);
131 
132 }
133 
134 typedef struct drm_r128_stipple32 {
137 
138 static int compat_r128_stipple(struct file *file, unsigned int cmd,
139  unsigned long arg)
140 {
141  drm_r128_stipple32_t stipple32;
142  drm_r128_stipple_t __user *stipple;
143 
144  if (copy_from_user(&stipple32, (void __user *)arg, sizeof(stipple32)))
145  return -EFAULT;
146 
147  stipple = compat_alloc_user_space(sizeof(*stipple));
148  if (!access_ok(VERIFY_WRITE, stipple, sizeof(*stipple))
149  || __put_user((unsigned int __user *)(unsigned long)stipple32.mask,
150  &stipple->mask))
151  return -EFAULT;
152 
153  return drm_ioctl(file, DRM_IOCTL_R128_STIPPLE, (unsigned long)stipple);
154 }
155 
156 typedef struct drm_r128_getparam32 {
157  int param;
160 
161 static int compat_r128_getparam(struct file *file, unsigned int cmd,
162  unsigned long arg)
163 {
164  drm_r128_getparam32_t getparam32;
165  drm_r128_getparam_t __user *getparam;
166 
167  if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
168  return -EFAULT;
169 
170  getparam = compat_alloc_user_space(sizeof(*getparam));
171  if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam))
172  || __put_user(getparam32.param, &getparam->param)
173  || __put_user((void __user *)(unsigned long)getparam32.value,
174  &getparam->value))
175  return -EFAULT;
176 
177  return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
178 }
179 
180 drm_ioctl_compat_t *r128_compat_ioctls[] = {
181  [DRM_R128_INIT] = compat_r128_init,
182  [DRM_R128_DEPTH] = compat_r128_depth,
183  [DRM_R128_STIPPLE] = compat_r128_stipple,
184  [DRM_R128_GETPARAM] = compat_r128_getparam,
185 };
186 
196 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
197 {
198  unsigned int nr = DRM_IOCTL_NR(cmd);
199  drm_ioctl_compat_t *fn = NULL;
200  int ret;
201 
202  if (nr < DRM_COMMAND_BASE)
203  return drm_compat_ioctl(filp, cmd, arg);
204 
205  if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
207 
208  if (fn != NULL)
209  ret = (*fn) (filp, cmd, arg);
210  else
211  ret = drm_ioctl(filp, cmd, arg);
212 
213  return ret;
214 }