i915_ioc32.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 <linux/ioctl32.h>
  34. #include "drmP.h"
  35. #include "drm.h"
  36. #include "i915_drm.h"
  37. typedef struct _drm_i915_batchbuffer32 {
  38. int start; /* agp offset */
  39. int used; /* nr bytes in use */
  40. int DR1; /* hw flags for GFX_OP_DRAWRECT_INFO */
  41. int DR4; /* window origin for GFX_OP_DRAWRECT_INFO */
  42. int num_cliprects; /* mulitpass with multiple cliprects? */
  43. u32 cliprects; /* pointer to userspace cliprects */
  44. } drm_i915_batchbuffer32_t;
  45. static int compat_i915_batchbuffer(struct file *file, unsigned int cmd,
  46. unsigned long arg)
  47. {
  48. drm_i915_batchbuffer32_t batchbuffer32;
  49. drm_i915_batchbuffer_t __user *batchbuffer;
  50. if (copy_from_user
  51. (&batchbuffer32, (void __user *)arg, sizeof(batchbuffer32)))
  52. return -EFAULT;
  53. batchbuffer = compat_alloc_user_space(sizeof(*batchbuffer));
  54. if (!access_ok(VERIFY_WRITE, batchbuffer, sizeof(*batchbuffer))
  55. || __put_user(batchbuffer32.start, &batchbuffer->start)
  56. || __put_user(batchbuffer32.used, &batchbuffer->used)
  57. || __put_user(batchbuffer32.DR1, &batchbuffer->DR1)
  58. || __put_user(batchbuffer32.DR4, &batchbuffer->DR4)
  59. || __put_user(batchbuffer32.num_cliprects,
  60. &batchbuffer->num_cliprects)
  61. || __put_user((int __user *)(unsigned long)batchbuffer32.cliprects,
  62. &batchbuffer->cliprects))
  63. return -EFAULT;
  64. return drm_ioctl(file->f_dentry->d_inode, file,
  65. DRM_IOCTL_I915_BATCHBUFFER,
  66. (unsigned long)batchbuffer);
  67. }
  68. typedef struct _drm_i915_cmdbuffer32 {
  69. u32 buf; /* pointer to userspace command buffer */
  70. int sz; /* nr bytes in buf */
  71. int DR1; /* hw flags for GFX_OP_DRAWRECT_INFO */
  72. int DR4; /* window origin for GFX_OP_DRAWRECT_INFO */
  73. int num_cliprects; /* mulitpass with multiple cliprects? */
  74. u32 cliprects; /* pointer to userspace cliprects */
  75. } drm_i915_cmdbuffer32_t;
  76. static int compat_i915_cmdbuffer(struct file *file, unsigned int cmd,
  77. unsigned long arg)
  78. {
  79. drm_i915_cmdbuffer32_t cmdbuffer32;
  80. drm_i915_cmdbuffer_t __user *cmdbuffer;
  81. if (copy_from_user
  82. (&cmdbuffer32, (void __user *)arg, sizeof(cmdbuffer32)))
  83. return -EFAULT;
  84. cmdbuffer = compat_alloc_user_space(sizeof(*cmdbuffer));
  85. if (!access_ok(VERIFY_WRITE, cmdbuffer, sizeof(*cmdbuffer))
  86. || __put_user((int __user *)(unsigned long)cmdbuffer32.buf,
  87. &cmdbuffer->buf)
  88. || __put_user(cmdbuffer32.sz, &cmdbuffer->sz)
  89. || __put_user(cmdbuffer32.DR1, &cmdbuffer->DR1)
  90. || __put_user(cmdbuffer32.DR4, &cmdbuffer->DR4)
  91. || __put_user(cmdbuffer32.num_cliprects, &cmdbuffer->num_cliprects)
  92. || __put_user((int __user *)(unsigned long)cmdbuffer32.cliprects,
  93. &cmdbuffer->cliprects))
  94. return -EFAULT;
  95. return drm_ioctl(file->f_dentry->d_inode, file,
  96. DRM_IOCTL_I915_CMDBUFFER, (unsigned long)cmdbuffer);
  97. }
  98. typedef struct drm_i915_irq_emit32 {
  99. u32 irq_seq;
  100. } drm_i915_irq_emit32_t;
  101. static int compat_i915_irq_emit(struct file *file, unsigned int cmd,
  102. unsigned long arg)
  103. {
  104. drm_i915_irq_emit32_t req32;
  105. drm_i915_irq_emit_t __user *request;
  106. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  107. return -EFAULT;
  108. request = compat_alloc_user_space(sizeof(*request));
  109. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  110. || __put_user((int __user *)(unsigned long)req32.irq_seq,
  111. &request->irq_seq))
  112. return -EFAULT;
  113. return drm_ioctl(file->f_dentry->d_inode, file,
  114. DRM_IOCTL_I915_IRQ_EMIT, (unsigned long)request);
  115. }
  116. typedef struct drm_i915_getparam32 {
  117. int param;
  118. u32 value;
  119. } drm_i915_getparam32_t;
  120. static int compat_i915_getparam(struct file *file, unsigned int cmd,
  121. unsigned long arg)
  122. {
  123. drm_i915_getparam32_t req32;
  124. drm_i915_getparam_t __user *request;
  125. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  126. return -EFAULT;
  127. request = compat_alloc_user_space(sizeof(*request));
  128. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  129. || __put_user(req32.param, &request->param)
  130. || __put_user((void __user *)(unsigned long)req32.value,
  131. &request->value))
  132. return -EFAULT;
  133. return drm_ioctl(file->f_dentry->d_inode, file,
  134. DRM_IOCTL_I915_GETPARAM, (unsigned long)request);
  135. }
  136. typedef struct drm_i915_mem_alloc32 {
  137. int region;
  138. int alignment;
  139. int size;
  140. u32 region_offset; /* offset from start of fb or agp */
  141. } drm_i915_mem_alloc32_t;
  142. static int compat_i915_alloc(struct file *file, unsigned int cmd,
  143. unsigned long arg)
  144. {
  145. drm_i915_mem_alloc32_t req32;
  146. drm_i915_mem_alloc_t __user *request;
  147. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  148. return -EFAULT;
  149. request = compat_alloc_user_space(sizeof(*request));
  150. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  151. || __put_user(req32.region, &request->region)
  152. || __put_user(req32.alignment, &request->alignment)
  153. || __put_user(req32.size, &request->size)
  154. || __put_user((void __user *)(unsigned long)req32.region_offset,
  155. &request->region_offset))
  156. return -EFAULT;
  157. return drm_ioctl(file->f_dentry->d_inode, file,
  158. DRM_IOCTL_I915_ALLOC, (unsigned long)request);
  159. }
  160. drm_ioctl_compat_t *i915_compat_ioctls[] = {
  161. [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
  162. [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
  163. [DRM_I915_GETPARAM] = compat_i915_getparam,
  164. [DRM_I915_IRQ_EMIT] = compat_i915_irq_emit,
  165. [DRM_I915_ALLOC] = compat_i915_alloc
  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 i915_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(i915_compat_ioctls))
  184. fn = i915_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. }