r128_ioc32.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**
  2. * \file r128_ioc32.c
  3. *
  4. * 32-bit ioctl compatibility routines for the R128 DRM.
  5. *
  6. * \author Dave Airlie <airlied@linux.ie> with code from patches by Egbert Eich
  7. *
  8. * Copyright (C) Paul Mackerras 2005
  9. * Copyright (C) Egbert Eich 2003,2004
  10. * Copyright (C) Dave Airlie 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 <drm/drmP.h>
  34. #include <drm/r128_drm.h>
  35. #include "r128_drv.h"
  36. typedef struct drm_r128_init32 {
  37. int func;
  38. unsigned int sarea_priv_offset;
  39. int is_pci;
  40. int cce_mode;
  41. int cce_secure;
  42. int ring_size;
  43. int usec_timeout;
  44. unsigned int fb_bpp;
  45. unsigned int front_offset, front_pitch;
  46. unsigned int back_offset, back_pitch;
  47. unsigned int depth_bpp;
  48. unsigned int depth_offset, depth_pitch;
  49. unsigned int span_offset;
  50. unsigned int fb_offset;
  51. unsigned int mmio_offset;
  52. unsigned int ring_offset;
  53. unsigned int ring_rptr_offset;
  54. unsigned int buffers_offset;
  55. unsigned int agp_textures_offset;
  56. } drm_r128_init32_t;
  57. static int compat_r128_init(struct file *file, unsigned int cmd,
  58. unsigned long arg)
  59. {
  60. drm_r128_init32_t init32;
  61. drm_r128_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. init.is_pci = init32.is_pci;
  67. init.cce_mode = init32.cce_mode;
  68. init.cce_secure = init32.cce_secure;
  69. init.ring_size = init32.ring_size;
  70. init.usec_timeout = init32.usec_timeout;
  71. init.fb_bpp = init32.fb_bpp;
  72. init.front_offset = init32.front_offset;
  73. init.front_pitch = init32.front_pitch;
  74. init.back_offset = init32.back_offset;
  75. init.back_pitch = init32.back_pitch;
  76. init.depth_bpp = init32.depth_bpp;
  77. init.depth_offset = init32.depth_offset;
  78. init.depth_pitch = init32.depth_pitch;
  79. init.span_offset = init32.span_offset;
  80. init.fb_offset = init32.fb_offset;
  81. init.mmio_offset = init32.mmio_offset;
  82. init.ring_offset = init32.ring_offset;
  83. init.ring_rptr_offset = init32.ring_rptr_offset;
  84. init.buffers_offset = init32.buffers_offset;
  85. init.agp_textures_offset = init32.agp_textures_offset;
  86. return drm_ioctl_kernel(file, r128_cce_init, &init,
  87. DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
  88. }
  89. typedef struct drm_r128_depth32 {
  90. int func;
  91. int n;
  92. u32 x;
  93. u32 y;
  94. u32 buffer;
  95. u32 mask;
  96. } drm_r128_depth32_t;
  97. static int compat_r128_depth(struct file *file, unsigned int cmd,
  98. unsigned long arg)
  99. {
  100. drm_r128_depth32_t depth32;
  101. drm_r128_depth_t depth;
  102. if (copy_from_user(&depth32, (void __user *)arg, sizeof(depth32)))
  103. return -EFAULT;
  104. depth.func = depth32.func;
  105. depth.n = depth32.n;
  106. depth.x = compat_ptr(depth32.x);
  107. depth.y = compat_ptr(depth32.y);
  108. depth.buffer = compat_ptr(depth32.buffer);
  109. depth.mask = compat_ptr(depth32.mask);
  110. return drm_ioctl_kernel(file, r128_cce_depth, &depth, DRM_AUTH);
  111. }
  112. typedef struct drm_r128_stipple32 {
  113. u32 mask;
  114. } drm_r128_stipple32_t;
  115. static int compat_r128_stipple(struct file *file, unsigned int cmd,
  116. unsigned long arg)
  117. {
  118. drm_r128_stipple32_t stipple32;
  119. drm_r128_stipple_t stipple;
  120. if (copy_from_user(&stipple32, (void __user *)arg, sizeof(stipple32)))
  121. return -EFAULT;
  122. stipple.mask = compat_ptr(stipple32.mask);
  123. return drm_ioctl_kernel(file, r128_cce_stipple, &stipple, DRM_AUTH);
  124. }
  125. typedef struct drm_r128_getparam32 {
  126. int param;
  127. u32 value;
  128. } drm_r128_getparam32_t;
  129. static int compat_r128_getparam(struct file *file, unsigned int cmd,
  130. unsigned long arg)
  131. {
  132. drm_r128_getparam32_t getparam32;
  133. drm_r128_getparam_t getparam;
  134. if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
  135. return -EFAULT;
  136. getparam.param = getparam32.param;
  137. getparam.value = compat_ptr(getparam32.value);
  138. return drm_ioctl_kernel(file, r128_getparam, &getparam, DRM_AUTH);
  139. }
  140. drm_ioctl_compat_t *r128_compat_ioctls[] = {
  141. [DRM_R128_INIT] = compat_r128_init,
  142. [DRM_R128_DEPTH] = compat_r128_depth,
  143. [DRM_R128_STIPPLE] = compat_r128_stipple,
  144. [DRM_R128_GETPARAM] = compat_r128_getparam,
  145. };
  146. /**
  147. * Called whenever a 32-bit process running under a 64-bit kernel
  148. * performs an ioctl on /dev/dri/card<n>.
  149. *
  150. * \param filp file pointer.
  151. * \param cmd command.
  152. * \param arg user argument.
  153. * \return zero on success or negative number on failure.
  154. */
  155. long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  156. {
  157. unsigned int nr = DRM_IOCTL_NR(cmd);
  158. drm_ioctl_compat_t *fn = NULL;
  159. int ret;
  160. if (nr < DRM_COMMAND_BASE)
  161. return drm_compat_ioctl(filp, cmd, arg);
  162. if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
  163. fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
  164. if (fn != NULL)
  165. ret = (*fn) (filp, cmd, arg);
  166. else
  167. ret = drm_ioctl(filp, cmd, arg);
  168. return ret;
  169. }