radeon_ioc32.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /**
  2. * \file radeon_ioc32.c
  3. *
  4. * 32-bit ioctl compatibility routines for the Radeon DRM.
  5. *
  6. * \author Paul Mackerras <paulus@samba.org>
  7. *
  8. * Copyright (C) Paul Mackerras 2005
  9. * All Rights Reserved.
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a
  12. * copy of this software and associated documentation files (the "Software"),
  13. * to deal in the Software without restriction, including without limitation
  14. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15. * and/or sell copies of the Software, and to permit persons to whom the
  16. * Software is furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice (including the next
  19. * paragraph) shall be included in all copies or substantial portions of the
  20. * Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  25. * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  26. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  28. * IN THE SOFTWARE.
  29. */
  30. #include <linux/compat.h>
  31. #include "drmP.h"
  32. #include "drm.h"
  33. #include "radeon_drm.h"
  34. #include "radeon_drv.h"
  35. typedef struct drm_radeon_init32 {
  36. int func;
  37. u32 sarea_priv_offset;
  38. int is_pci;
  39. int cp_mode;
  40. int gart_size;
  41. int ring_size;
  42. int usec_timeout;
  43. unsigned int fb_bpp;
  44. unsigned int front_offset, front_pitch;
  45. unsigned int back_offset, back_pitch;
  46. unsigned int depth_bpp;
  47. unsigned int depth_offset, depth_pitch;
  48. u32 fb_offset;
  49. u32 mmio_offset;
  50. u32 ring_offset;
  51. u32 ring_rptr_offset;
  52. u32 buffers_offset;
  53. u32 gart_textures_offset;
  54. } drm_radeon_init32_t;
  55. static int compat_radeon_cp_init(struct file *file, unsigned int cmd,
  56. unsigned long arg)
  57. {
  58. drm_radeon_init32_t init32;
  59. drm_radeon_init_t __user *init;
  60. if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
  61. return -EFAULT;
  62. init = compat_alloc_user_space(sizeof(*init));
  63. if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
  64. || __put_user(init32.func, &init->func)
  65. || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
  66. || __put_user(init32.is_pci, &init->is_pci)
  67. || __put_user(init32.cp_mode, &init->cp_mode)
  68. || __put_user(init32.gart_size, &init->gart_size)
  69. || __put_user(init32.ring_size, &init->ring_size)
  70. || __put_user(init32.usec_timeout, &init->usec_timeout)
  71. || __put_user(init32.fb_bpp, &init->fb_bpp)
  72. || __put_user(init32.front_offset, &init->front_offset)
  73. || __put_user(init32.front_pitch, &init->front_pitch)
  74. || __put_user(init32.back_offset, &init->back_offset)
  75. || __put_user(init32.back_pitch, &init->back_pitch)
  76. || __put_user(init32.depth_bpp, &init->depth_bpp)
  77. || __put_user(init32.depth_offset, &init->depth_offset)
  78. || __put_user(init32.depth_pitch, &init->depth_pitch)
  79. || __put_user(init32.fb_offset, &init->fb_offset)
  80. || __put_user(init32.mmio_offset, &init->mmio_offset)
  81. || __put_user(init32.ring_offset, &init->ring_offset)
  82. || __put_user(init32.ring_rptr_offset, &init->ring_rptr_offset)
  83. || __put_user(init32.buffers_offset, &init->buffers_offset)
  84. || __put_user(init32.gart_textures_offset,
  85. &init->gart_textures_offset))
  86. return -EFAULT;
  87. return drm_ioctl(file, DRM_IOCTL_RADEON_CP_INIT, (unsigned long)init);
  88. }
  89. typedef struct drm_radeon_clear32 {
  90. unsigned int flags;
  91. unsigned int clear_color;
  92. unsigned int clear_depth;
  93. unsigned int color_mask;
  94. unsigned int depth_mask; /* misnamed field: should be stencil */
  95. u32 depth_boxes;
  96. } drm_radeon_clear32_t;
  97. static int compat_radeon_cp_clear(struct file *file, unsigned int cmd,
  98. unsigned long arg)
  99. {
  100. drm_radeon_clear32_t clr32;
  101. drm_radeon_clear_t __user *clr;
  102. if (copy_from_user(&clr32, (void __user *)arg, sizeof(clr32)))
  103. return -EFAULT;
  104. clr = compat_alloc_user_space(sizeof(*clr));
  105. if (!access_ok(VERIFY_WRITE, clr, sizeof(*clr))
  106. || __put_user(clr32.flags, &clr->flags)
  107. || __put_user(clr32.clear_color, &clr->clear_color)
  108. || __put_user(clr32.clear_depth, &clr->clear_depth)
  109. || __put_user(clr32.color_mask, &clr->color_mask)
  110. || __put_user(clr32.depth_mask, &clr->depth_mask)
  111. || __put_user((void __user *)(unsigned long)clr32.depth_boxes,
  112. &clr->depth_boxes))
  113. return -EFAULT;
  114. return drm_ioctl(file, DRM_IOCTL_RADEON_CLEAR, (unsigned long)clr);
  115. }
  116. typedef struct drm_radeon_stipple32 {
  117. u32 mask;
  118. } drm_radeon_stipple32_t;
  119. static int compat_radeon_cp_stipple(struct file *file, unsigned int cmd,
  120. unsigned long arg)
  121. {
  122. drm_radeon_stipple32_t __user *argp = (void __user *)arg;
  123. drm_radeon_stipple_t __user *request;
  124. u32 mask;
  125. if (get_user(mask, &argp->mask))
  126. return -EFAULT;
  127. request = compat_alloc_user_space(sizeof(*request));
  128. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  129. || __put_user((unsigned int __user *)(unsigned long)mask,
  130. &request->mask))
  131. return -EFAULT;
  132. return drm_ioctl(file, DRM_IOCTL_RADEON_STIPPLE, (unsigned long)request);
  133. }
  134. typedef struct drm_radeon_tex_image32 {
  135. unsigned int x, y; /* Blit coordinates */
  136. unsigned int width, height;
  137. u32 data;
  138. } drm_radeon_tex_image32_t;
  139. typedef struct drm_radeon_texture32 {
  140. unsigned int offset;
  141. int pitch;
  142. int format;
  143. int width; /* Texture image coordinates */
  144. int height;
  145. u32 image;
  146. } drm_radeon_texture32_t;
  147. static int compat_radeon_cp_texture(struct file *file, unsigned int cmd,
  148. unsigned long arg)
  149. {
  150. drm_radeon_texture32_t req32;
  151. drm_radeon_texture_t __user *request;
  152. drm_radeon_tex_image32_t img32;
  153. drm_radeon_tex_image_t __user *image;
  154. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  155. return -EFAULT;
  156. if (req32.image == 0)
  157. return -EINVAL;
  158. if (copy_from_user(&img32, (void __user *)(unsigned long)req32.image,
  159. sizeof(img32)))
  160. return -EFAULT;
  161. request = compat_alloc_user_space(sizeof(*request) + sizeof(*image));
  162. if (!access_ok(VERIFY_WRITE, request,
  163. sizeof(*request) + sizeof(*image)))
  164. return -EFAULT;
  165. image = (drm_radeon_tex_image_t __user *) (request + 1);
  166. if (__put_user(req32.offset, &request->offset)
  167. || __put_user(req32.pitch, &request->pitch)
  168. || __put_user(req32.format, &request->format)
  169. || __put_user(req32.width, &request->width)
  170. || __put_user(req32.height, &request->height)
  171. || __put_user(image, &request->image)
  172. || __put_user(img32.x, &image->x)
  173. || __put_user(img32.y, &image->y)
  174. || __put_user(img32.width, &image->width)
  175. || __put_user(img32.height, &image->height)
  176. || __put_user((const void __user *)(unsigned long)img32.data,
  177. &image->data))
  178. return -EFAULT;
  179. return drm_ioctl(file, DRM_IOCTL_RADEON_TEXTURE, (unsigned long)request);
  180. }
  181. typedef struct drm_radeon_vertex2_32 {
  182. int idx; /* Index of vertex buffer */
  183. int discard; /* Client finished with buffer? */
  184. int nr_states;
  185. u32 state;
  186. int nr_prims;
  187. u32 prim;
  188. } drm_radeon_vertex2_32_t;
  189. static int compat_radeon_cp_vertex2(struct file *file, unsigned int cmd,
  190. unsigned long arg)
  191. {
  192. drm_radeon_vertex2_32_t req32;
  193. drm_radeon_vertex2_t __user *request;
  194. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  195. return -EFAULT;
  196. request = compat_alloc_user_space(sizeof(*request));
  197. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  198. || __put_user(req32.idx, &request->idx)
  199. || __put_user(req32.discard, &request->discard)
  200. || __put_user(req32.nr_states, &request->nr_states)
  201. || __put_user((void __user *)(unsigned long)req32.state,
  202. &request->state)
  203. || __put_user(req32.nr_prims, &request->nr_prims)
  204. || __put_user((void __user *)(unsigned long)req32.prim,
  205. &request->prim))
  206. return -EFAULT;
  207. return drm_ioctl(file, DRM_IOCTL_RADEON_VERTEX2, (unsigned long)request);
  208. }
  209. typedef struct drm_radeon_cmd_buffer32 {
  210. int bufsz;
  211. u32 buf;
  212. int nbox;
  213. u32 boxes;
  214. } drm_radeon_cmd_buffer32_t;
  215. static int compat_radeon_cp_cmdbuf(struct file *file, unsigned int cmd,
  216. unsigned long arg)
  217. {
  218. drm_radeon_cmd_buffer32_t req32;
  219. drm_radeon_cmd_buffer_t __user *request;
  220. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  221. return -EFAULT;
  222. request = compat_alloc_user_space(sizeof(*request));
  223. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  224. || __put_user(req32.bufsz, &request->bufsz)
  225. || __put_user((void __user *)(unsigned long)req32.buf,
  226. &request->buf)
  227. || __put_user(req32.nbox, &request->nbox)
  228. || __put_user((void __user *)(unsigned long)req32.boxes,
  229. &request->boxes))
  230. return -EFAULT;
  231. return drm_ioctl(file, DRM_IOCTL_RADEON_CMDBUF, (unsigned long)request);
  232. }
  233. typedef struct drm_radeon_getparam32 {
  234. int param;
  235. u32 value;
  236. } drm_radeon_getparam32_t;
  237. static int compat_radeon_cp_getparam(struct file *file, unsigned int cmd,
  238. unsigned long arg)
  239. {
  240. drm_radeon_getparam32_t req32;
  241. drm_radeon_getparam_t __user *request;
  242. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  243. return -EFAULT;
  244. request = compat_alloc_user_space(sizeof(*request));
  245. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  246. || __put_user(req32.param, &request->param)
  247. || __put_user((void __user *)(unsigned long)req32.value,
  248. &request->value))
  249. return -EFAULT;
  250. return drm_ioctl(file, DRM_IOCTL_RADEON_GETPARAM, (unsigned long)request);
  251. }
  252. typedef struct drm_radeon_mem_alloc32 {
  253. int region;
  254. int alignment;
  255. int size;
  256. u32 region_offset; /* offset from start of fb or GART */
  257. } drm_radeon_mem_alloc32_t;
  258. static int compat_radeon_mem_alloc(struct file *file, unsigned int cmd,
  259. unsigned long arg)
  260. {
  261. drm_radeon_mem_alloc32_t req32;
  262. drm_radeon_mem_alloc_t __user *request;
  263. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  264. return -EFAULT;
  265. request = compat_alloc_user_space(sizeof(*request));
  266. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  267. || __put_user(req32.region, &request->region)
  268. || __put_user(req32.alignment, &request->alignment)
  269. || __put_user(req32.size, &request->size)
  270. || __put_user((int __user *)(unsigned long)req32.region_offset,
  271. &request->region_offset))
  272. return -EFAULT;
  273. return drm_ioctl(file, DRM_IOCTL_RADEON_ALLOC, (unsigned long)request);
  274. }
  275. typedef struct drm_radeon_irq_emit32 {
  276. u32 irq_seq;
  277. } drm_radeon_irq_emit32_t;
  278. static int compat_radeon_irq_emit(struct file *file, unsigned int cmd,
  279. unsigned long arg)
  280. {
  281. drm_radeon_irq_emit32_t req32;
  282. drm_radeon_irq_emit_t __user *request;
  283. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  284. return -EFAULT;
  285. request = compat_alloc_user_space(sizeof(*request));
  286. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  287. || __put_user((int __user *)(unsigned long)req32.irq_seq,
  288. &request->irq_seq))
  289. return -EFAULT;
  290. return drm_ioctl(file, DRM_IOCTL_RADEON_IRQ_EMIT, (unsigned long)request);
  291. }
  292. /* The two 64-bit arches where alignof(u64)==4 in 32-bit code */
  293. #if defined (CONFIG_X86_64) || defined(CONFIG_IA64)
  294. typedef struct drm_radeon_setparam32 {
  295. int param;
  296. u64 value;
  297. } __attribute__((packed)) drm_radeon_setparam32_t;
  298. static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
  299. unsigned long arg)
  300. {
  301. drm_radeon_setparam32_t req32;
  302. drm_radeon_setparam_t __user *request;
  303. if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
  304. return -EFAULT;
  305. request = compat_alloc_user_space(sizeof(*request));
  306. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  307. || __put_user(req32.param, &request->param)
  308. || __put_user((void __user *)(unsigned long)req32.value,
  309. &request->value))
  310. return -EFAULT;
  311. return drm_ioctl(file, DRM_IOCTL_RADEON_SETPARAM, (unsigned long) request);
  312. }
  313. #else
  314. #define compat_radeon_cp_setparam NULL
  315. #endif /* X86_64 || IA64 */
  316. drm_ioctl_compat_t *radeon_compat_ioctls[] = {
  317. [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
  318. [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
  319. [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
  320. [DRM_RADEON_TEXTURE] = compat_radeon_cp_texture,
  321. [DRM_RADEON_VERTEX2] = compat_radeon_cp_vertex2,
  322. [DRM_RADEON_CMDBUF] = compat_radeon_cp_cmdbuf,
  323. [DRM_RADEON_GETPARAM] = compat_radeon_cp_getparam,
  324. [DRM_RADEON_SETPARAM] = compat_radeon_cp_setparam,
  325. [DRM_RADEON_ALLOC] = compat_radeon_mem_alloc,
  326. [DRM_RADEON_IRQ_EMIT] = compat_radeon_irq_emit,
  327. };
  328. /**
  329. * Called whenever a 32-bit process running under a 64-bit kernel
  330. * performs an ioctl on /dev/dri/card<n>.
  331. *
  332. * \param filp file pointer.
  333. * \param cmd command.
  334. * \param arg user argument.
  335. * \return zero on success or negative number on failure.
  336. */
  337. long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  338. {
  339. unsigned int nr = DRM_IOCTL_NR(cmd);
  340. drm_ioctl_compat_t *fn = NULL;
  341. int ret;
  342. if (nr < DRM_COMMAND_BASE)
  343. return drm_compat_ioctl(filp, cmd, arg);
  344. if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
  345. fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
  346. if (fn != NULL)
  347. ret = (*fn) (filp, cmd, arg);
  348. else
  349. ret = drm_ioctl(filp, cmd, arg);
  350. return ret;
  351. }
  352. long radeon_kms_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  353. {
  354. unsigned int nr = DRM_IOCTL_NR(cmd);
  355. int ret;
  356. if (nr < DRM_COMMAND_BASE)
  357. return drm_compat_ioctl(filp, cmd, arg);
  358. ret = drm_ioctl(filp, cmd, arg);
  359. return ret;
  360. }