i915_ioc32.c 7.0 KB

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