i915_ioc32.c 7.2 KB

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