mga_ioc32.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 <drm/drmP.h>
  35. #include <drm/mga_drm.h>
  36. #include "mga_drv.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 init;
  62. if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
  63. return -EFAULT;
  64. init.func = init32.func;
  65. init.sarea_priv_offset = init32.sarea_priv_offset;
  66. memcpy(&init.chipset, &init32.chipset,
  67. offsetof(drm_mga_init_t, fb_offset) -
  68. offsetof(drm_mga_init_t, chipset));
  69. init.fb_offset = init32.fb_offset;
  70. init.mmio_offset = init32.mmio_offset;
  71. init.status_offset = init32.status_offset;
  72. init.warp_offset = init32.warp_offset;
  73. init.primary_offset = init32.primary_offset;
  74. init.buffers_offset = init32.buffers_offset;
  75. return drm_ioctl_kernel(file, mga_dma_init, &init,
  76. DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
  77. }
  78. typedef struct drm_mga_getparam32 {
  79. int param;
  80. u32 value;
  81. } drm_mga_getparam32_t;
  82. static int compat_mga_getparam(struct file *file, unsigned int cmd,
  83. unsigned long arg)
  84. {
  85. drm_mga_getparam32_t getparam32;
  86. drm_mga_getparam_t getparam;
  87. if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
  88. return -EFAULT;
  89. getparam.param = getparam32.param;
  90. getparam.value = compat_ptr(getparam32.value);
  91. return drm_ioctl_kernel(file, mga_getparam, &getparam, DRM_AUTH);
  92. }
  93. typedef struct drm_mga_drm_bootstrap32 {
  94. u32 texture_handle;
  95. u32 texture_size;
  96. u32 primary_size;
  97. u32 secondary_bin_count;
  98. u32 secondary_bin_size;
  99. u32 agp_mode;
  100. u8 agp_size;
  101. } drm_mga_dma_bootstrap32_t;
  102. static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
  103. unsigned long arg)
  104. {
  105. drm_mga_dma_bootstrap32_t dma_bootstrap32;
  106. drm_mga_dma_bootstrap_t dma_bootstrap;
  107. int err;
  108. if (copy_from_user(&dma_bootstrap32, (void __user *)arg,
  109. sizeof(dma_bootstrap32)))
  110. return -EFAULT;
  111. dma_bootstrap.texture_handle = dma_bootstrap32.texture_handle;
  112. dma_bootstrap.texture_size = dma_bootstrap32.texture_size;
  113. dma_bootstrap.primary_size = dma_bootstrap32.primary_size;
  114. dma_bootstrap.secondary_bin_count = dma_bootstrap32.secondary_bin_count;
  115. dma_bootstrap.secondary_bin_size = dma_bootstrap32.secondary_bin_size;
  116. dma_bootstrap.agp_mode = dma_bootstrap32.agp_mode;
  117. dma_bootstrap.agp_size = dma_bootstrap32.agp_size;
  118. err = drm_ioctl_kernel(file, mga_dma_bootstrap, &dma_bootstrap,
  119. DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
  120. if (err)
  121. return err;
  122. dma_bootstrap32.texture_handle = dma_bootstrap.texture_handle;
  123. dma_bootstrap32.texture_size = dma_bootstrap.texture_size;
  124. dma_bootstrap32.primary_size = dma_bootstrap.primary_size;
  125. dma_bootstrap32.secondary_bin_count = dma_bootstrap.secondary_bin_count;
  126. dma_bootstrap32.secondary_bin_size = dma_bootstrap.secondary_bin_size;
  127. dma_bootstrap32.agp_mode = dma_bootstrap.agp_mode;
  128. dma_bootstrap32.agp_size = dma_bootstrap.agp_size;
  129. if (copy_to_user((void __user *)arg, &dma_bootstrap32,
  130. sizeof(dma_bootstrap32)))
  131. return -EFAULT;
  132. return 0;
  133. }
  134. static struct {
  135. drm_ioctl_compat_t *fn;
  136. char *name;
  137. } mga_compat_ioctls[] = {
  138. #define DRM_IOCTL32_DEF(n, f)[DRM_##n] = {.fn = f, .name = #n}
  139. DRM_IOCTL32_DEF(MGA_INIT, compat_mga_init),
  140. DRM_IOCTL32_DEF(MGA_GETPARAM, compat_mga_getparam),
  141. DRM_IOCTL32_DEF(MGA_DMA_BOOTSTRAP, compat_mga_dma_bootstrap),
  142. };
  143. /**
  144. * Called whenever a 32-bit process running under a 64-bit kernel
  145. * performs an ioctl on /dev/dri/card<n>.
  146. *
  147. * \param filp file pointer.
  148. * \param cmd command.
  149. * \param arg user argument.
  150. * \return zero on success or negative number on failure.
  151. */
  152. long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  153. {
  154. unsigned int nr = DRM_IOCTL_NR(cmd);
  155. struct drm_file *file_priv = filp->private_data;
  156. drm_ioctl_compat_t *fn = NULL;
  157. int ret;
  158. if (nr < DRM_COMMAND_BASE)
  159. return drm_compat_ioctl(filp, cmd, arg);
  160. if (nr >= DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
  161. return drm_ioctl(filp, cmd, arg);
  162. fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE].fn;
  163. if (!fn)
  164. return drm_ioctl(filp, cmd, arg);
  165. DRM_DEBUG("pid=%d, dev=0x%lx, auth=%d, %s\n",
  166. task_pid_nr(current),
  167. (long)old_encode_dev(file_priv->minor->kdev->devt),
  168. file_priv->authenticated,
  169. mga_compat_ioctls[nr - DRM_COMMAND_BASE].name);
  170. ret = (*fn) (filp, cmd, arg);
  171. if (ret)
  172. DRM_DEBUG("ret = %d\n", ret);
  173. return ret;
  174. }