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