radeon_ioc32.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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->f_path.dentry->d_inode, file,
  88. DRM_IOCTL_RADEON_CP_INIT, (unsigned long)init);
  89. }
  90. typedef struct drm_radeon_clear32 {
  91. unsigned int flags;
  92. unsigned int clear_color;
  93. unsigned int clear_depth;
  94. unsigned int color_mask;
  95. unsigned int depth_mask; /* misnamed field: should be stencil */
  96. u32 depth_boxes;
  97. } drm_radeon_clear32_t;
  98. static int compat_radeon_cp_clear(struct file *file, unsigned int cmd,
  99. unsigned long arg)
  100. {
  101. drm_radeon_clear32_t clr32;
  102. drm_radeon_clear_t __user *clr;
  103. if (copy_from_user(&clr32, (void __user *)arg, sizeof(clr32)))
  104. return -EFAULT;
  105. clr = compat_alloc_user_space(sizeof(*clr));
  106. if (!access_ok(VERIFY_WRITE, clr, sizeof(*clr))
  107. || __put_user(clr32.flags, &clr->flags)
  108. || __put_user(clr32.clear_color, &clr->clear_color)
  109. || __put_user(clr32.clear_depth, &clr->clear_depth)
  110. || __put_user(clr32.color_mask, &clr->color_mask)
  111. || __put_user(clr32.depth_mask, &clr->depth_mask)
  112. || __put_user((void __user *)(unsigned long)clr32.depth_boxes,
  113. &clr->depth_boxes))
  114. return -EFAULT;
  115. return drm_ioctl(file->f_path.dentry->d_inode, file,
  116. DRM_IOCTL_RADEON_CLEAR, (unsigned long)clr);
  117. }
  118. typedef struct drm_radeon_stipple32 {
  119. u32 mask;
  120. } drm_radeon_stipple32_t;
  121. static int compat_radeon_cp_stipple(struct file *file, unsigned int cmd,
  122. unsigned long arg)
  123. {
  124. drm_radeon_stipple32_t __user *argp = (void __user *)arg;
  125. drm_radeon_stipple_t __user *request;
  126. u32 mask;
  127. if (get_user(mask, &argp->mask))
  128. return -EFAULT;
  129. request = compat_alloc_user_space(sizeof(*request));
  130. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  131. || __put_user((unsigned int __user *)(unsigned long)mask,
  132. &request->mask))
  133. return -EFAULT;
  134. return drm_ioctl(file->f_path.dentry->d_inode, file,
  135. DRM_IOCTL_RADEON_STIPPLE, (unsigned long)request);
  136. }
  137. typedef struct drm_radeon_tex_image32 {
  138. unsigned int x, y; /* Blit coordinates */
  139. unsigned int width, height;
  140. u32 data;
  141. } drm_radeon_tex_image32_t;
  142. typedef struct drm_radeon_texture32 {
  143. unsigned int offset;
  144. int pitch;
  145. int format;
  146. int width; /* Texture image coordinates */
  147. int height;
  148. u32 image;
  149. } drm_radeon_texture32_t;
  150. static int compat_radeon_cp_texture(struct file *file, unsigned int cmd,
  151. unsigned long arg)
  152. {
  153. drm_radeon_texture32_t req32;
  154. drm_radeon_texture_t __user *request;
  155. drm_radeon_tex_image32_t img32;
  156. drm_radeon_tex_image_t __user *image;
  157. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  158. return -EFAULT;
  159. if (req32.image == 0)
  160. return -EINVAL;
  161. if (copy_from_user(&img32, (void __user *)(unsigned long)req32.image,
  162. sizeof(img32)))
  163. return -EFAULT;
  164. request = compat_alloc_user_space(sizeof(*request) + sizeof(*image));
  165. if (!access_ok(VERIFY_WRITE, request,
  166. sizeof(*request) + sizeof(*image)))
  167. return -EFAULT;
  168. image = (drm_radeon_tex_image_t __user *) (request + 1);
  169. if (__put_user(req32.offset, &request->offset)
  170. || __put_user(req32.pitch, &request->pitch)
  171. || __put_user(req32.format, &request->format)
  172. || __put_user(req32.width, &request->width)
  173. || __put_user(req32.height, &request->height)
  174. || __put_user(image, &request->image)
  175. || __put_user(img32.x, &image->x)
  176. || __put_user(img32.y, &image->y)
  177. || __put_user(img32.width, &image->width)
  178. || __put_user(img32.height, &image->height)
  179. || __put_user((const void __user *)(unsigned long)img32.data,
  180. &image->data))
  181. return -EFAULT;
  182. return drm_ioctl(file->f_path.dentry->d_inode, file,
  183. DRM_IOCTL_RADEON_TEXTURE, (unsigned long)request);
  184. }
  185. typedef struct drm_radeon_vertex2_32 {
  186. int idx; /* Index of vertex buffer */
  187. int discard; /* Client finished with buffer? */
  188. int nr_states;
  189. u32 state;
  190. int nr_prims;
  191. u32 prim;
  192. } drm_radeon_vertex2_32_t;
  193. static int compat_radeon_cp_vertex2(struct file *file, unsigned int cmd,
  194. unsigned long arg)
  195. {
  196. drm_radeon_vertex2_32_t req32;
  197. drm_radeon_vertex2_t __user *request;
  198. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  199. return -EFAULT;
  200. request = compat_alloc_user_space(sizeof(*request));
  201. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  202. || __put_user(req32.idx, &request->idx)
  203. || __put_user(req32.discard, &request->discard)
  204. || __put_user(req32.nr_states, &request->nr_states)
  205. || __put_user((void __user *)(unsigned long)req32.state,
  206. &request->state)
  207. || __put_user(req32.nr_prims, &request->nr_prims)
  208. || __put_user((void __user *)(unsigned long)req32.prim,
  209. &request->prim))
  210. return -EFAULT;
  211. return drm_ioctl(file->f_path.dentry->d_inode, file,
  212. DRM_IOCTL_RADEON_VERTEX2, (unsigned long)request);
  213. }
  214. typedef struct drm_radeon_cmd_buffer32 {
  215. int bufsz;
  216. u32 buf;
  217. int nbox;
  218. u32 boxes;
  219. } drm_radeon_cmd_buffer32_t;
  220. static int compat_radeon_cp_cmdbuf(struct file *file, unsigned int cmd,
  221. unsigned long arg)
  222. {
  223. drm_radeon_cmd_buffer32_t req32;
  224. drm_radeon_cmd_buffer_t __user *request;
  225. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  226. return -EFAULT;
  227. request = compat_alloc_user_space(sizeof(*request));
  228. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  229. || __put_user(req32.bufsz, &request->bufsz)
  230. || __put_user((void __user *)(unsigned long)req32.buf,
  231. &request->buf)
  232. || __put_user(req32.nbox, &request->nbox)
  233. || __put_user((void __user *)(unsigned long)req32.boxes,
  234. &request->boxes))
  235. return -EFAULT;
  236. return drm_ioctl(file->f_path.dentry->d_inode, file,
  237. DRM_IOCTL_RADEON_CMDBUF, (unsigned long)request);
  238. }
  239. typedef struct drm_radeon_getparam32 {
  240. int param;
  241. u32 value;
  242. } drm_radeon_getparam32_t;
  243. static int compat_radeon_cp_getparam(struct file *file, unsigned int cmd,
  244. unsigned long arg)
  245. {
  246. drm_radeon_getparam32_t req32;
  247. drm_radeon_getparam_t __user *request;
  248. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  249. return -EFAULT;
  250. request = compat_alloc_user_space(sizeof(*request));
  251. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  252. || __put_user(req32.param, &request->param)
  253. || __put_user((void __user *)(unsigned long)req32.value,
  254. &request->value))
  255. return -EFAULT;
  256. return drm_ioctl(file->f_path.dentry->d_inode, file,
  257. DRM_IOCTL_RADEON_GETPARAM, (unsigned long)request);
  258. }
  259. typedef struct drm_radeon_mem_alloc32 {
  260. int region;
  261. int alignment;
  262. int size;
  263. u32 region_offset; /* offset from start of fb or GART */
  264. } drm_radeon_mem_alloc32_t;
  265. static int compat_radeon_mem_alloc(struct file *file, unsigned int cmd,
  266. unsigned long arg)
  267. {
  268. drm_radeon_mem_alloc32_t req32;
  269. drm_radeon_mem_alloc_t __user *request;
  270. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  271. return -EFAULT;
  272. request = compat_alloc_user_space(sizeof(*request));
  273. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  274. || __put_user(req32.region, &request->region)
  275. || __put_user(req32.alignment, &request->alignment)
  276. || __put_user(req32.size, &request->size)
  277. || __put_user((int __user *)(unsigned long)req32.region_offset,
  278. &request->region_offset))
  279. return -EFAULT;
  280. return drm_ioctl(file->f_path.dentry->d_inode, file,
  281. DRM_IOCTL_RADEON_ALLOC, (unsigned long)request);
  282. }
  283. typedef struct drm_radeon_irq_emit32 {
  284. u32 irq_seq;
  285. } drm_radeon_irq_emit32_t;
  286. static int compat_radeon_irq_emit(struct file *file, unsigned int cmd,
  287. unsigned long arg)
  288. {
  289. drm_radeon_irq_emit32_t req32;
  290. drm_radeon_irq_emit_t __user *request;
  291. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  292. return -EFAULT;
  293. request = compat_alloc_user_space(sizeof(*request));
  294. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  295. || __put_user((int __user *)(unsigned long)req32.irq_seq,
  296. &request->irq_seq))
  297. return -EFAULT;
  298. return drm_ioctl(file->f_path.dentry->d_inode, file,
  299. DRM_IOCTL_RADEON_IRQ_EMIT, (unsigned long)request);
  300. }
  301. /* The two 64-bit arches where alignof(u64)==4 in 32-bit code */
  302. #if defined (CONFIG_X86_64) || defined(CONFIG_IA64)
  303. typedef struct drm_radeon_setparam32 {
  304. int param;
  305. u64 value;
  306. } __attribute__((packed)) drm_radeon_setparam32_t;
  307. static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
  308. unsigned long arg)
  309. {
  310. drm_radeon_setparam32_t req32;
  311. drm_radeon_setparam_t __user *request;
  312. if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
  313. return -EFAULT;
  314. request = compat_alloc_user_space(sizeof(*request));
  315. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  316. || __put_user(req32.param, &request->param)
  317. || __put_user((void __user *)(unsigned long)req32.value,
  318. &request->value))
  319. return -EFAULT;
  320. return drm_ioctl(file->f_dentry->d_inode, file,
  321. DRM_IOCTL_RADEON_SETPARAM, (unsigned long) request);
  322. }
  323. #else
  324. #define compat_radeon_cp_setparam NULL
  325. #endif /* X86_64 || IA64 */
  326. drm_ioctl_compat_t *radeon_compat_ioctls[] = {
  327. [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
  328. [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
  329. [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
  330. [DRM_RADEON_TEXTURE] = compat_radeon_cp_texture,
  331. [DRM_RADEON_VERTEX2] = compat_radeon_cp_vertex2,
  332. [DRM_RADEON_CMDBUF] = compat_radeon_cp_cmdbuf,
  333. [DRM_RADEON_GETPARAM] = compat_radeon_cp_getparam,
  334. [DRM_RADEON_SETPARAM] = compat_radeon_cp_setparam,
  335. [DRM_RADEON_ALLOC] = compat_radeon_mem_alloc,
  336. [DRM_RADEON_IRQ_EMIT] = compat_radeon_irq_emit,
  337. };
  338. /**
  339. * Called whenever a 32-bit process running under a 64-bit kernel
  340. * performs an ioctl on /dev/dri/card<n>.
  341. *
  342. * \param filp file pointer.
  343. * \param cmd command.
  344. * \param arg user argument.
  345. * \return zero on success or negative number on failure.
  346. */
  347. long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  348. {
  349. unsigned int nr = DRM_IOCTL_NR(cmd);
  350. drm_ioctl_compat_t *fn = NULL;
  351. int ret;
  352. if (nr < DRM_COMMAND_BASE)
  353. return drm_compat_ioctl(filp, cmd, arg);
  354. if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
  355. fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
  356. lock_kernel(); /* XXX for now */
  357. if (fn != NULL)
  358. ret = (*fn) (filp, cmd, arg);
  359. else
  360. ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
  361. unlock_kernel();
  362. return ret;
  363. }