Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mga_ioc32.c
Go to the documentation of this file.
1 
33 #include <linux/compat.h>
34 
35 #include <drm/drmP.h>
36 #include <drm/mga_drm.h>
37 
38 typedef struct drm32_mga_init {
39  int func;
41  int chipset;
42  int sgram;
43  unsigned int maccess;
44  unsigned int fb_cpp;
45  unsigned int front_offset, front_pitch;
46  unsigned int back_offset, back_pitch;
47  unsigned int depth_cpp;
48  unsigned int depth_offset, depth_pitch;
58 
59 static int compat_mga_init(struct file *file, unsigned int cmd,
60  unsigned long arg)
61 {
62  drm_mga_init32_t init32;
64  int err = 0, i;
65 
66  if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
67  return -EFAULT;
68 
69  init = compat_alloc_user_space(sizeof(*init));
70  if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
71  || __put_user(init32.func, &init->func)
72  || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
73  || __put_user(init32.chipset, &init->chipset)
74  || __put_user(init32.sgram, &init->sgram)
75  || __put_user(init32.maccess, &init->maccess)
76  || __put_user(init32.fb_cpp, &init->fb_cpp)
77  || __put_user(init32.front_offset, &init->front_offset)
78  || __put_user(init32.front_pitch, &init->front_pitch)
79  || __put_user(init32.back_offset, &init->back_offset)
80  || __put_user(init32.back_pitch, &init->back_pitch)
81  || __put_user(init32.depth_cpp, &init->depth_cpp)
82  || __put_user(init32.depth_offset, &init->depth_offset)
83  || __put_user(init32.depth_pitch, &init->depth_pitch)
84  || __put_user(init32.fb_offset, &init->fb_offset)
85  || __put_user(init32.mmio_offset, &init->mmio_offset)
86  || __put_user(init32.status_offset, &init->status_offset)
87  || __put_user(init32.warp_offset, &init->warp_offset)
88  || __put_user(init32.primary_offset, &init->primary_offset)
89  || __put_user(init32.buffers_offset, &init->buffers_offset))
90  return -EFAULT;
91 
92  for (i = 0; i < MGA_NR_TEX_HEAPS; i++) {
93  err |=
94  __put_user(init32.texture_offset[i],
95  &init->texture_offset[i]);
96  err |=
97  __put_user(init32.texture_size[i], &init->texture_size[i]);
98  }
99  if (err)
100  return -EFAULT;
101 
102  return drm_ioctl(file, DRM_IOCTL_MGA_INIT, (unsigned long)init);
103 }
104 
105 typedef struct drm_mga_getparam32 {
106  int param;
109 
110 static int compat_mga_getparam(struct file *file, unsigned int cmd,
111  unsigned long arg)
112 {
113  drm_mga_getparam32_t getparam32;
114  drm_mga_getparam_t __user *getparam;
115 
116  if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
117  return -EFAULT;
118 
119  getparam = compat_alloc_user_space(sizeof(*getparam));
120  if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam))
121  || __put_user(getparam32.param, &getparam->param)
122  || __put_user((void __user *)(unsigned long)getparam32.value,
123  &getparam->value))
124  return -EFAULT;
125 
126  return drm_ioctl(file, DRM_IOCTL_MGA_GETPARAM, (unsigned long)getparam);
127 }
128 
129 typedef struct drm_mga_drm_bootstrap32 {
138 
139 static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
140  unsigned long arg)
141 {
142  drm_mga_dma_bootstrap32_t dma_bootstrap32;
143  drm_mga_dma_bootstrap_t __user *dma_bootstrap;
144  int err;
145 
146  if (copy_from_user(&dma_bootstrap32, (void __user *)arg,
147  sizeof(dma_bootstrap32)))
148  return -EFAULT;
149 
150  dma_bootstrap = compat_alloc_user_space(sizeof(*dma_bootstrap));
151  if (!access_ok(VERIFY_WRITE, dma_bootstrap, sizeof(*dma_bootstrap))
152  || __put_user(dma_bootstrap32.texture_handle,
153  &dma_bootstrap->texture_handle)
154  || __put_user(dma_bootstrap32.texture_size,
155  &dma_bootstrap->texture_size)
156  || __put_user(dma_bootstrap32.primary_size,
157  &dma_bootstrap->primary_size)
158  || __put_user(dma_bootstrap32.secondary_bin_count,
159  &dma_bootstrap->secondary_bin_count)
160  || __put_user(dma_bootstrap32.secondary_bin_size,
161  &dma_bootstrap->secondary_bin_size)
162  || __put_user(dma_bootstrap32.agp_mode, &dma_bootstrap->agp_mode)
163  || __put_user(dma_bootstrap32.agp_size, &dma_bootstrap->agp_size))
164  return -EFAULT;
165 
167  (unsigned long)dma_bootstrap);
168  if (err)
169  return err;
170 
171  if (__get_user(dma_bootstrap32.texture_handle,
172  &dma_bootstrap->texture_handle)
173  || __get_user(dma_bootstrap32.texture_size,
174  &dma_bootstrap->texture_size)
175  || __get_user(dma_bootstrap32.primary_size,
176  &dma_bootstrap->primary_size)
177  || __get_user(dma_bootstrap32.secondary_bin_count,
178  &dma_bootstrap->secondary_bin_count)
179  || __get_user(dma_bootstrap32.secondary_bin_size,
180  &dma_bootstrap->secondary_bin_size)
181  || __get_user(dma_bootstrap32.agp_mode, &dma_bootstrap->agp_mode)
182  || __get_user(dma_bootstrap32.agp_size, &dma_bootstrap->agp_size))
183  return -EFAULT;
184 
185  if (copy_to_user((void __user *)arg, &dma_bootstrap32,
186  sizeof(dma_bootstrap32)))
187  return -EFAULT;
188 
189  return 0;
190 }
191 
192 drm_ioctl_compat_t *mga_compat_ioctls[] = {
193  [DRM_MGA_INIT] = compat_mga_init,
194  [DRM_MGA_GETPARAM] = compat_mga_getparam,
195  [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
196 };
197 
207 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
208 {
209  unsigned int nr = DRM_IOCTL_NR(cmd);
210  drm_ioctl_compat_t *fn = NULL;
211  int ret;
212 
213  if (nr < DRM_COMMAND_BASE)
214  return drm_compat_ioctl(filp, cmd, arg);
215 
216  if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
217  fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
218 
219  if (fn != NULL)
220  ret = (*fn) (filp, cmd, arg);
221  else
222  ret = drm_ioctl(filp, cmd, arg);
223 
224  return ret;
225 }