i915_ioc32.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /**
  2. * \file i915_ioc32.c
  3. *
  4. * 32-bit ioctl compatibility routines for the i915 DRM.
  5. *
  6. * \author Alan Hourihane <alanh@fairlite.demon.co.uk>
  7. *
  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 "drmP.h"
  34. #include "drm.h"
  35. #include "i915_drm.h"
  36. typedef struct _drm_i915_batchbuffer32 {
  37. int start; /* agp offset */
  38. int used; /* nr bytes in use */
  39. int DR1; /* hw flags for GFX_OP_DRAWRECT_INFO */
  40. int DR4; /* window origin for GFX_OP_DRAWRECT_INFO */
  41. int num_cliprects; /* mulitpass with multiple cliprects? */
  42. u32 cliprects; /* pointer to userspace cliprects */
  43. } drm_i915_batchbuffer32_t;
  44. static int compat_i915_batchbuffer(struct file *file, unsigned int cmd,
  45. unsigned long arg)
  46. {
  47. drm_i915_batchbuffer32_t batchbuffer32;
  48. drm_i915_batchbuffer_t __user *batchbuffer;
  49. if (copy_from_user
  50. (&batchbuffer32, (void __user *)arg, sizeof(batchbuffer32)))
  51. return -EFAULT;
  52. batchbuffer = compat_alloc_user_space(sizeof(*batchbuffer));
  53. if (!access_ok(VERIFY_WRITE, batchbuffer, sizeof(*batchbuffer))
  54. || __put_user(batchbuffer32.start, &batchbuffer->start)
  55. || __put_user(batchbuffer32.used, &batchbuffer->used)
  56. || __put_user(batchbuffer32.DR1, &batchbuffer->DR1)
  57. || __put_user(batchbuffer32.DR4, &batchbuffer->DR4)
  58. || __put_user(batchbuffer32.num_cliprects,
  59. &batchbuffer->num_cliprects)
  60. || __put_user((int __user *)(unsigned long)batchbuffer32.cliprects,
  61. &batchbuffer->cliprects))
  62. return -EFAULT;
  63. return drm_ioctl(file->f_path.dentry->d_inode, file,
  64. DRM_IOCTL_I915_BATCHBUFFER,
  65. (unsigned long)batchbuffer);
  66. }
  67. typedef struct _drm_i915_cmdbuffer32 {
  68. u32 buf; /* pointer to userspace command buffer */
  69. int sz; /* nr bytes in buf */
  70. int DR1; /* hw flags for GFX_OP_DRAWRECT_INFO */
  71. int DR4; /* window origin for GFX_OP_DRAWRECT_INFO */
  72. int num_cliprects; /* mulitpass with multiple cliprects? */
  73. u32 cliprects; /* pointer to userspace cliprects */
  74. } drm_i915_cmdbuffer32_t;
  75. static int compat_i915_cmdbuffer(struct file *file, unsigned int cmd,
  76. unsigned long arg)
  77. {
  78. drm_i915_cmdbuffer32_t cmdbuffer32;
  79. drm_i915_cmdbuffer_t __user *cmdbuffer;
  80. if (copy_from_user
  81. (&cmdbuffer32, (void __user *)arg, sizeof(cmdbuffer32)))
  82. return -EFAULT;
  83. cmdbuffer = compat_alloc_user_space(sizeof(*cmdbuffer));
  84. if (!access_ok(VERIFY_WRITE, cmdbuffer, sizeof(*cmdbuffer))
  85. || __put_user((int __user *)(unsigned long)cmdbuffer32.buf,
  86. &cmdbuffer->buf)
  87. || __put_user(cmdbuffer32.sz, &cmdbuffer->sz)
  88. || __put_user(cmdbuffer32.DR1, &cmdbuffer->DR1)
  89. || __put_user(cmdbuffer32.DR4, &cmdbuffer->DR4)
  90. || __put_user(cmdbuffer32.num_cliprects, &cmdbuffer->num_cliprects)
  91. || __put_user((int __user *)(unsigned long)cmdbuffer32.cliprects,
  92. &cmdbuffer->cliprects))
  93. return -EFAULT;
  94. return drm_ioctl(file->f_path.dentry->d_inode, file,
  95. DRM_IOCTL_I915_CMDBUFFER, (unsigned long)cmdbuffer);
  96. }
  97. typedef struct drm_i915_irq_emit32 {
  98. u32 irq_seq;
  99. } drm_i915_irq_emit32_t;
  100. static int compat_i915_irq_emit(struct file *file, unsigned int cmd,
  101. unsigned long arg)
  102. {
  103. drm_i915_irq_emit32_t req32;
  104. drm_i915_irq_emit_t __user *request;
  105. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  106. return -EFAULT;
  107. request = compat_alloc_user_space(sizeof(*request));
  108. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  109. || __put_user((int __user *)(unsigned long)req32.irq_seq,
  110. &request->irq_seq))
  111. return -EFAULT;
  112. return drm_ioctl(file->f_path.dentry->d_inode, file,
  113. DRM_IOCTL_I915_IRQ_EMIT, (unsigned long)request);
  114. }
  115. typedef struct drm_i915_getparam32 {
  116. int param;
  117. u32 value;
  118. } drm_i915_getparam32_t;
  119. static int compat_i915_getparam(struct file *file, unsigned int cmd,
  120. unsigned long arg)
  121. {
  122. drm_i915_getparam32_t req32;
  123. drm_i915_getparam_t __user *request;
  124. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  125. return -EFAULT;
  126. request = compat_alloc_user_space(sizeof(*request));
  127. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  128. || __put_user(req32.param, &request->param)
  129. || __put_user((void __user *)(unsigned long)req32.value,
  130. &request->value))
  131. return -EFAULT;
  132. return drm_ioctl(file->f_path.dentry->d_inode, file,
  133. DRM_IOCTL_I915_GETPARAM, (unsigned long)request);
  134. }
  135. typedef struct drm_i915_mem_alloc32 {
  136. int region;
  137. int alignment;
  138. int size;
  139. u32 region_offset; /* offset from start of fb or agp */
  140. } drm_i915_mem_alloc32_t;
  141. static int compat_i915_alloc(struct file *file, unsigned int cmd,
  142. unsigned long arg)
  143. {
  144. drm_i915_mem_alloc32_t req32;
  145. drm_i915_mem_alloc_t __user *request;
  146. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  147. return -EFAULT;
  148. request = compat_alloc_user_space(sizeof(*request));
  149. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  150. || __put_user(req32.region, &request->region)
  151. || __put_user(req32.alignment, &request->alignment)
  152. || __put_user(req32.size, &request->size)
  153. || __put_user((void __user *)(unsigned long)req32.region_offset,
  154. &request->region_offset))
  155. return -EFAULT;
  156. return drm_ioctl(file->f_path.dentry->d_inode, file,
  157. DRM_IOCTL_I915_ALLOC, (unsigned long)request);
  158. }
  159. drm_ioctl_compat_t *i915_compat_ioctls[] = {
  160. [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
  161. [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
  162. [DRM_I915_GETPARAM] = compat_i915_getparam,
  163. [DRM_I915_IRQ_EMIT] = compat_i915_irq_emit,
  164. [DRM_I915_ALLOC] = compat_i915_alloc
  165. };
  166. /**
  167. * Called whenever a 32-bit process running under a 64-bit kernel
  168. * performs an ioctl on /dev/dri/card<n>.
  169. *
  170. * \param filp file pointer.
  171. * \param cmd command.
  172. * \param arg user argument.
  173. * \return zero on success or negative number on failure.
  174. */
  175. long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  176. {
  177. unsigned int nr = DRM_IOCTL_NR(cmd);
  178. drm_ioctl_compat_t *fn = NULL;
  179. int ret;
  180. if (nr < DRM_COMMAND_BASE)
  181. return drm_compat_ioctl(filp, cmd, arg);
  182. if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
  183. fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
  184. lock_kernel(); /* XXX for now */
  185. if (fn != NULL)
  186. ret = (*fn) (filp, cmd, arg);
  187. else
  188. ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
  189. unlock_kernel();
  190. return ret;
  191. }