r128_ioc32.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. #include "drmP.h"
  35. #include "drm.h"
  36. #include "r128_drm.h"
  37. typedef struct drm_r128_init32 {
  38. int func;
  39. unsigned int sarea_priv_offset;
  40. int is_pci;
  41. int cce_mode;
  42. int cce_secure;
  43. int ring_size;
  44. int usec_timeout;
  45. unsigned int fb_bpp;
  46. unsigned int front_offset, front_pitch;
  47. unsigned int back_offset, back_pitch;
  48. unsigned int depth_bpp;
  49. unsigned int depth_offset, depth_pitch;
  50. unsigned int span_offset;
  51. unsigned int fb_offset;
  52. unsigned int mmio_offset;
  53. unsigned int ring_offset;
  54. unsigned int ring_rptr_offset;
  55. unsigned int buffers_offset;
  56. unsigned int agp_textures_offset;
  57. } drm_r128_init32_t;
  58. static int compat_r128_init(struct file *file, unsigned int cmd,
  59. unsigned long arg)
  60. {
  61. drm_r128_init32_t init32;
  62. drm_r128_init_t __user *init;
  63. if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
  64. return -EFAULT;
  65. init = compat_alloc_user_space(sizeof(*init));
  66. if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
  67. || __put_user(init32.func, &init->func)
  68. || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
  69. || __put_user(init32.is_pci, &init->is_pci)
  70. || __put_user(init32.cce_mode, &init->cce_mode)
  71. || __put_user(init32.cce_secure, &init->cce_secure)
  72. || __put_user(init32.ring_size, &init->ring_size)
  73. || __put_user(init32.usec_timeout, &init->usec_timeout)
  74. || __put_user(init32.fb_bpp, &init->fb_bpp)
  75. || __put_user(init32.front_offset, &init->front_offset)
  76. || __put_user(init32.front_pitch, &init->front_pitch)
  77. || __put_user(init32.back_offset, &init->back_offset)
  78. || __put_user(init32.back_pitch, &init->back_pitch)
  79. || __put_user(init32.depth_bpp, &init->depth_bpp)
  80. || __put_user(init32.depth_offset, &init->depth_offset)
  81. || __put_user(init32.depth_pitch, &init->depth_pitch)
  82. || __put_user(init32.span_offset, &init->span_offset)
  83. || __put_user(init32.fb_offset, &init->fb_offset)
  84. || __put_user(init32.mmio_offset, &init->mmio_offset)
  85. || __put_user(init32.ring_offset, &init->ring_offset)
  86. || __put_user(init32.ring_rptr_offset, &init->ring_rptr_offset)
  87. || __put_user(init32.buffers_offset, &init->buffers_offset)
  88. || __put_user(init32.agp_textures_offset,
  89. &init->agp_textures_offset))
  90. return -EFAULT;
  91. return drm_ioctl(file->f_dentry->d_inode, file,
  92. DRM_IOCTL_R128_INIT, (unsigned long)init);
  93. }
  94. typedef struct drm_r128_depth32 {
  95. int func;
  96. int n;
  97. u32 x;
  98. u32 y;
  99. u32 buffer;
  100. u32 mask;
  101. } drm_r128_depth32_t;
  102. static int compat_r128_depth(struct file *file, unsigned int cmd,
  103. unsigned long arg)
  104. {
  105. drm_r128_depth32_t depth32;
  106. drm_r128_depth_t __user *depth;
  107. if (copy_from_user(&depth32, (void __user *)arg, sizeof(depth32)))
  108. return -EFAULT;
  109. depth = compat_alloc_user_space(sizeof(*depth));
  110. if (!access_ok(VERIFY_WRITE, depth, sizeof(*depth))
  111. || __put_user(depth32.func, &depth->func)
  112. || __put_user(depth32.n, &depth->n)
  113. || __put_user((int __user *)(unsigned long)depth32.x, &depth->x)
  114. || __put_user((int __user *)(unsigned long)depth32.y, &depth->y)
  115. || __put_user((unsigned int __user *)(unsigned long)depth32.buffer,
  116. &depth->buffer)
  117. || __put_user((unsigned char __user *)(unsigned long)depth32.mask,
  118. &depth->mask))
  119. return -EFAULT;
  120. return drm_ioctl(file->f_dentry->d_inode, file,
  121. DRM_IOCTL_R128_DEPTH, (unsigned long)depth);
  122. }
  123. typedef struct drm_r128_stipple32 {
  124. u32 mask;
  125. } drm_r128_stipple32_t;
  126. static int compat_r128_stipple(struct file *file, unsigned int cmd,
  127. unsigned long arg)
  128. {
  129. drm_r128_stipple32_t stipple32;
  130. drm_r128_stipple_t __user *stipple;
  131. if (copy_from_user(&stipple32, (void __user *)arg, sizeof(stipple32)))
  132. return -EFAULT;
  133. stipple = compat_alloc_user_space(sizeof(*stipple));
  134. if (!access_ok(VERIFY_WRITE, stipple, sizeof(*stipple))
  135. || __put_user((unsigned int __user *)(unsigned long)stipple32.mask,
  136. &stipple->mask))
  137. return -EFAULT;
  138. return drm_ioctl(file->f_dentry->d_inode, file,
  139. DRM_IOCTL_R128_STIPPLE, (unsigned long)stipple);
  140. }
  141. typedef struct drm_r128_getparam32 {
  142. int param;
  143. u32 value;
  144. } drm_r128_getparam32_t;
  145. static int compat_r128_getparam(struct file *file, unsigned int cmd,
  146. unsigned long arg)
  147. {
  148. drm_r128_getparam32_t getparam32;
  149. drm_r128_getparam_t __user *getparam;
  150. if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
  151. return -EFAULT;
  152. getparam = compat_alloc_user_space(sizeof(*getparam));
  153. if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam))
  154. || __put_user(getparam32.param, &getparam->param)
  155. || __put_user((void __user *)(unsigned long)getparam32.value,
  156. &getparam->value))
  157. return -EFAULT;
  158. return drm_ioctl(file->f_dentry->d_inode, file,
  159. DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
  160. }
  161. drm_ioctl_compat_t *r128_compat_ioctls[] = {
  162. [DRM_R128_INIT] = compat_r128_init,
  163. [DRM_R128_DEPTH] = compat_r128_depth,
  164. [DRM_R128_STIPPLE] = compat_r128_stipple,
  165. [DRM_R128_GETPARAM] = compat_r128_getparam,
  166. };
  167. /**
  168. * Called whenever a 32-bit process running under a 64-bit kernel
  169. * performs an ioctl on /dev/dri/card<n>.
  170. *
  171. * \param filp file pointer.
  172. * \param cmd command.
  173. * \param arg user argument.
  174. * \return zero on success or negative number on failure.
  175. */
  176. long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  177. {
  178. unsigned int nr = DRM_IOCTL_NR(cmd);
  179. drm_ioctl_compat_t *fn = NULL;
  180. int ret;
  181. if (nr < DRM_COMMAND_BASE)
  182. return drm_compat_ioctl(filp, cmd, arg);
  183. if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
  184. fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
  185. lock_kernel(); /* XXX for now */
  186. if (fn != NULL)
  187. ret = (*fn) (filp, cmd, arg);
  188. else
  189. ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
  190. unlock_kernel();
  191. return ret;
  192. }