mga_ioc32.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /**
  2. * \file mga_ioc32.c
  3. *
  4. * 32-bit ioctl compatibility routines for the MGA DRM.
  5. *
  6. * \author Dave Airlie <airlied@linux.ie> with code from patches by Egbert Eich
  7. *
  8. *
  9. * Copyright (C) Paul Mackerras 2005
  10. * Copyright (C) Egbert Eich 2003,2004
  11. * Copyright (C) Dave Airlie 2005
  12. * All Rights Reserved.
  13. *
  14. * Permission is hereby granted, free of charge, to any person obtaining a
  15. * copy of this software and associated documentation files (the "Software"),
  16. * to deal in the Software without restriction, including without limitation
  17. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  18. * and/or sell copies of the Software, and to permit persons to whom the
  19. * Software is furnished to do so, subject to the following conditions:
  20. *
  21. * The above copyright notice and this permission notice (including the next
  22. * paragraph) shall be included in all copies or substantial portions of the
  23. * Software.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  26. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  27. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  28. * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  29. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  30. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  31. * IN THE SOFTWARE.
  32. */
  33. #include <linux/compat.h>
  34. #include "drmP.h"
  35. #include "drm.h"
  36. #include "mga_drm.h"
  37. typedef struct drm32_mga_init {
  38. int func;
  39. u32 sarea_priv_offset;
  40. int chipset;
  41. int sgram;
  42. unsigned int maccess;
  43. unsigned int fb_cpp;
  44. unsigned int front_offset, front_pitch;
  45. unsigned int back_offset, back_pitch;
  46. unsigned int depth_cpp;
  47. unsigned int depth_offset, depth_pitch;
  48. unsigned int texture_offset[MGA_NR_TEX_HEAPS];
  49. unsigned int texture_size[MGA_NR_TEX_HEAPS];
  50. u32 fb_offset;
  51. u32 mmio_offset;
  52. u32 status_offset;
  53. u32 warp_offset;
  54. u32 primary_offset;
  55. u32 buffers_offset;
  56. } drm_mga_init32_t;
  57. static int compat_mga_init(struct file *file, unsigned int cmd,
  58. unsigned long arg)
  59. {
  60. drm_mga_init32_t init32;
  61. drm_mga_init_t __user *init;
  62. int err = 0, i;
  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.chipset, &init->chipset)
  70. || __put_user(init32.sgram, &init->sgram)
  71. || __put_user(init32.maccess, &init->maccess)
  72. || __put_user(init32.fb_cpp, &init->fb_cpp)
  73. || __put_user(init32.front_offset, &init->front_offset)
  74. || __put_user(init32.front_pitch, &init->front_pitch)
  75. || __put_user(init32.back_offset, &init->back_offset)
  76. || __put_user(init32.back_pitch, &init->back_pitch)
  77. || __put_user(init32.depth_cpp, &init->depth_cpp)
  78. || __put_user(init32.depth_offset, &init->depth_offset)
  79. || __put_user(init32.depth_pitch, &init->depth_pitch)
  80. || __put_user(init32.fb_offset, &init->fb_offset)
  81. || __put_user(init32.mmio_offset, &init->mmio_offset)
  82. || __put_user(init32.status_offset, &init->status_offset)
  83. || __put_user(init32.warp_offset, &init->warp_offset)
  84. || __put_user(init32.primary_offset, &init->primary_offset)
  85. || __put_user(init32.buffers_offset, &init->buffers_offset))
  86. return -EFAULT;
  87. for (i = 0; i < MGA_NR_TEX_HEAPS; i++) {
  88. err |=
  89. __put_user(init32.texture_offset[i],
  90. &init->texture_offset[i]);
  91. err |=
  92. __put_user(init32.texture_size[i], &init->texture_size[i]);
  93. }
  94. if (err)
  95. return -EFAULT;
  96. return drm_ioctl(file, DRM_IOCTL_MGA_INIT, (unsigned long)init);
  97. }
  98. typedef struct drm_mga_getparam32 {
  99. int param;
  100. u32 value;
  101. } drm_mga_getparam32_t;
  102. static int compat_mga_getparam(struct file *file, unsigned int cmd,
  103. unsigned long arg)
  104. {
  105. drm_mga_getparam32_t getparam32;
  106. drm_mga_getparam_t __user *getparam;
  107. if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
  108. return -EFAULT;
  109. getparam = compat_alloc_user_space(sizeof(*getparam));
  110. if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam))
  111. || __put_user(getparam32.param, &getparam->param)
  112. || __put_user((void __user *)(unsigned long)getparam32.value,
  113. &getparam->value))
  114. return -EFAULT;
  115. return drm_ioctl(file, DRM_IOCTL_MGA_GETPARAM, (unsigned long)getparam);
  116. }
  117. typedef struct drm_mga_drm_bootstrap32 {
  118. u32 texture_handle;
  119. u32 texture_size;
  120. u32 primary_size;
  121. u32 secondary_bin_count;
  122. u32 secondary_bin_size;
  123. u32 agp_mode;
  124. u8 agp_size;
  125. } drm_mga_dma_bootstrap32_t;
  126. static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
  127. unsigned long arg)
  128. {
  129. drm_mga_dma_bootstrap32_t dma_bootstrap32;
  130. drm_mga_dma_bootstrap_t __user *dma_bootstrap;
  131. int err;
  132. if (copy_from_user(&dma_bootstrap32, (void __user *)arg,
  133. sizeof(dma_bootstrap32)))
  134. return -EFAULT;
  135. dma_bootstrap = compat_alloc_user_space(sizeof(*dma_bootstrap));
  136. if (!access_ok(VERIFY_WRITE, dma_bootstrap, sizeof(*dma_bootstrap))
  137. || __put_user(dma_bootstrap32.texture_handle,
  138. &dma_bootstrap->texture_handle)
  139. || __put_user(dma_bootstrap32.texture_size,
  140. &dma_bootstrap->texture_size)
  141. || __put_user(dma_bootstrap32.primary_size,
  142. &dma_bootstrap->primary_size)
  143. || __put_user(dma_bootstrap32.secondary_bin_count,
  144. &dma_bootstrap->secondary_bin_count)
  145. || __put_user(dma_bootstrap32.secondary_bin_size,
  146. &dma_bootstrap->secondary_bin_size)
  147. || __put_user(dma_bootstrap32.agp_mode, &dma_bootstrap->agp_mode)
  148. || __put_user(dma_bootstrap32.agp_size, &dma_bootstrap->agp_size))
  149. return -EFAULT;
  150. err = drm_ioctl(file, DRM_IOCTL_MGA_DMA_BOOTSTRAP,
  151. (unsigned long)dma_bootstrap);
  152. if (err)
  153. return err;
  154. if (__get_user(dma_bootstrap32.texture_handle,
  155. &dma_bootstrap->texture_handle)
  156. || __get_user(dma_bootstrap32.texture_size,
  157. &dma_bootstrap->texture_size)
  158. || __get_user(dma_bootstrap32.primary_size,
  159. &dma_bootstrap->primary_size)
  160. || __get_user(dma_bootstrap32.secondary_bin_count,
  161. &dma_bootstrap->secondary_bin_count)
  162. || __get_user(dma_bootstrap32.secondary_bin_size,
  163. &dma_bootstrap->secondary_bin_size)
  164. || __get_user(dma_bootstrap32.agp_mode, &dma_bootstrap->agp_mode)
  165. || __get_user(dma_bootstrap32.agp_size, &dma_bootstrap->agp_size))
  166. return -EFAULT;
  167. if (copy_to_user((void __user *)arg, &dma_bootstrap32,
  168. sizeof(dma_bootstrap32)))
  169. return -EFAULT;
  170. return 0;
  171. }
  172. drm_ioctl_compat_t *mga_compat_ioctls[] = {
  173. [DRM_MGA_INIT] = compat_mga_init,
  174. [DRM_MGA_GETPARAM] = compat_mga_getparam,
  175. [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
  176. };
  177. /**
  178. * Called whenever a 32-bit process running under a 64-bit kernel
  179. * performs an ioctl on /dev/dri/card<n>.
  180. *
  181. * \param filp file pointer.
  182. * \param cmd command.
  183. * \param arg user argument.
  184. * \return zero on success or negative number on failure.
  185. */
  186. long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  187. {
  188. unsigned int nr = DRM_IOCTL_NR(cmd);
  189. drm_ioctl_compat_t *fn = NULL;
  190. int ret;
  191. if (nr < DRM_COMMAND_BASE)
  192. return drm_compat_ioctl(filp, cmd, arg);
  193. if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
  194. fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
  195. if (fn != NULL)
  196. ret = (*fn) (filp, cmd, arg);
  197. else
  198. ret = drm_ioctl(filp, cmd, arg);
  199. return ret;
  200. }