drm_ioc32.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. /**
  2. * \file drm_ioc32.c
  3. *
  4. * 32-bit ioctl compatibility routines for the 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 <linux/ratelimit.h>
  32. #include "drmP.h"
  33. #include "drm_core.h"
  34. #define DRM_IOCTL_VERSION32 DRM_IOWR(0x00, drm_version32_t)
  35. #define DRM_IOCTL_GET_UNIQUE32 DRM_IOWR(0x01, drm_unique32_t)
  36. #define DRM_IOCTL_GET_MAP32 DRM_IOWR(0x04, drm_map32_t)
  37. #define DRM_IOCTL_GET_CLIENT32 DRM_IOWR(0x05, drm_client32_t)
  38. #define DRM_IOCTL_GET_STATS32 DRM_IOR( 0x06, drm_stats32_t)
  39. #define DRM_IOCTL_SET_UNIQUE32 DRM_IOW( 0x10, drm_unique32_t)
  40. #define DRM_IOCTL_ADD_MAP32 DRM_IOWR(0x15, drm_map32_t)
  41. #define DRM_IOCTL_ADD_BUFS32 DRM_IOWR(0x16, drm_buf_desc32_t)
  42. #define DRM_IOCTL_MARK_BUFS32 DRM_IOW( 0x17, drm_buf_desc32_t)
  43. #define DRM_IOCTL_INFO_BUFS32 DRM_IOWR(0x18, drm_buf_info32_t)
  44. #define DRM_IOCTL_MAP_BUFS32 DRM_IOWR(0x19, drm_buf_map32_t)
  45. #define DRM_IOCTL_FREE_BUFS32 DRM_IOW( 0x1a, drm_buf_free32_t)
  46. #define DRM_IOCTL_RM_MAP32 DRM_IOW( 0x1b, drm_map32_t)
  47. #define DRM_IOCTL_SET_SAREA_CTX32 DRM_IOW( 0x1c, drm_ctx_priv_map32_t)
  48. #define DRM_IOCTL_GET_SAREA_CTX32 DRM_IOWR(0x1d, drm_ctx_priv_map32_t)
  49. #define DRM_IOCTL_RES_CTX32 DRM_IOWR(0x26, drm_ctx_res32_t)
  50. #define DRM_IOCTL_DMA32 DRM_IOWR(0x29, drm_dma32_t)
  51. #define DRM_IOCTL_AGP_ENABLE32 DRM_IOW( 0x32, drm_agp_mode32_t)
  52. #define DRM_IOCTL_AGP_INFO32 DRM_IOR( 0x33, drm_agp_info32_t)
  53. #define DRM_IOCTL_AGP_ALLOC32 DRM_IOWR(0x34, drm_agp_buffer32_t)
  54. #define DRM_IOCTL_AGP_FREE32 DRM_IOW( 0x35, drm_agp_buffer32_t)
  55. #define DRM_IOCTL_AGP_BIND32 DRM_IOW( 0x36, drm_agp_binding32_t)
  56. #define DRM_IOCTL_AGP_UNBIND32 DRM_IOW( 0x37, drm_agp_binding32_t)
  57. #define DRM_IOCTL_SG_ALLOC32 DRM_IOW( 0x38, drm_scatter_gather32_t)
  58. #define DRM_IOCTL_SG_FREE32 DRM_IOW( 0x39, drm_scatter_gather32_t)
  59. #define DRM_IOCTL_UPDATE_DRAW32 DRM_IOW( 0x3f, drm_update_draw32_t)
  60. #define DRM_IOCTL_WAIT_VBLANK32 DRM_IOWR(0x3a, drm_wait_vblank32_t)
  61. typedef struct drm_version_32 {
  62. int version_major; /**< Major version */
  63. int version_minor; /**< Minor version */
  64. int version_patchlevel; /**< Patch level */
  65. u32 name_len; /**< Length of name buffer */
  66. u32 name; /**< Name of driver */
  67. u32 date_len; /**< Length of date buffer */
  68. u32 date; /**< User-space buffer to hold date */
  69. u32 desc_len; /**< Length of desc buffer */
  70. u32 desc; /**< User-space buffer to hold desc */
  71. } drm_version32_t;
  72. static int compat_drm_version(struct file *file, unsigned int cmd,
  73. unsigned long arg)
  74. {
  75. drm_version32_t v32;
  76. struct drm_version __user *version;
  77. int err;
  78. if (copy_from_user(&v32, (void __user *)arg, sizeof(v32)))
  79. return -EFAULT;
  80. version = compat_alloc_user_space(sizeof(*version));
  81. if (!access_ok(VERIFY_WRITE, version, sizeof(*version)))
  82. return -EFAULT;
  83. if (__put_user(v32.name_len, &version->name_len)
  84. || __put_user((void __user *)(unsigned long)v32.name,
  85. &version->name)
  86. || __put_user(v32.date_len, &version->date_len)
  87. || __put_user((void __user *)(unsigned long)v32.date,
  88. &version->date)
  89. || __put_user(v32.desc_len, &version->desc_len)
  90. || __put_user((void __user *)(unsigned long)v32.desc,
  91. &version->desc))
  92. return -EFAULT;
  93. err = drm_ioctl(file,
  94. DRM_IOCTL_VERSION, (unsigned long)version);
  95. if (err)
  96. return err;
  97. if (__get_user(v32.version_major, &version->version_major)
  98. || __get_user(v32.version_minor, &version->version_minor)
  99. || __get_user(v32.version_patchlevel, &version->version_patchlevel)
  100. || __get_user(v32.name_len, &version->name_len)
  101. || __get_user(v32.date_len, &version->date_len)
  102. || __get_user(v32.desc_len, &version->desc_len))
  103. return -EFAULT;
  104. if (copy_to_user((void __user *)arg, &v32, sizeof(v32)))
  105. return -EFAULT;
  106. return 0;
  107. }
  108. typedef struct drm_unique32 {
  109. u32 unique_len; /**< Length of unique */
  110. u32 unique; /**< Unique name for driver instantiation */
  111. } drm_unique32_t;
  112. static int compat_drm_getunique(struct file *file, unsigned int cmd,
  113. unsigned long arg)
  114. {
  115. drm_unique32_t uq32;
  116. struct drm_unique __user *u;
  117. int err;
  118. if (copy_from_user(&uq32, (void __user *)arg, sizeof(uq32)))
  119. return -EFAULT;
  120. u = compat_alloc_user_space(sizeof(*u));
  121. if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
  122. return -EFAULT;
  123. if (__put_user(uq32.unique_len, &u->unique_len)
  124. || __put_user((void __user *)(unsigned long)uq32.unique,
  125. &u->unique))
  126. return -EFAULT;
  127. err = drm_ioctl(file, DRM_IOCTL_GET_UNIQUE, (unsigned long)u);
  128. if (err)
  129. return err;
  130. if (__get_user(uq32.unique_len, &u->unique_len))
  131. return -EFAULT;
  132. if (copy_to_user((void __user *)arg, &uq32, sizeof(uq32)))
  133. return -EFAULT;
  134. return 0;
  135. }
  136. static int compat_drm_setunique(struct file *file, unsigned int cmd,
  137. unsigned long arg)
  138. {
  139. drm_unique32_t uq32;
  140. struct drm_unique __user *u;
  141. if (copy_from_user(&uq32, (void __user *)arg, sizeof(uq32)))
  142. return -EFAULT;
  143. u = compat_alloc_user_space(sizeof(*u));
  144. if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
  145. return -EFAULT;
  146. if (__put_user(uq32.unique_len, &u->unique_len)
  147. || __put_user((void __user *)(unsigned long)uq32.unique,
  148. &u->unique))
  149. return -EFAULT;
  150. return drm_ioctl(file, DRM_IOCTL_SET_UNIQUE, (unsigned long)u);
  151. }
  152. typedef struct drm_map32 {
  153. u32 offset; /**< Requested physical address (0 for SAREA)*/
  154. u32 size; /**< Requested physical size (bytes) */
  155. enum drm_map_type type; /**< Type of memory to map */
  156. enum drm_map_flags flags; /**< Flags */
  157. u32 handle; /**< User-space: "Handle" to pass to mmap() */
  158. int mtrr; /**< MTRR slot used */
  159. } drm_map32_t;
  160. static int compat_drm_getmap(struct file *file, unsigned int cmd,
  161. unsigned long arg)
  162. {
  163. drm_map32_t __user *argp = (void __user *)arg;
  164. drm_map32_t m32;
  165. struct drm_map __user *map;
  166. int idx, err;
  167. void *handle;
  168. if (get_user(idx, &argp->offset))
  169. return -EFAULT;
  170. map = compat_alloc_user_space(sizeof(*map));
  171. if (!access_ok(VERIFY_WRITE, map, sizeof(*map)))
  172. return -EFAULT;
  173. if (__put_user(idx, &map->offset))
  174. return -EFAULT;
  175. err = drm_ioctl(file, DRM_IOCTL_GET_MAP, (unsigned long)map);
  176. if (err)
  177. return err;
  178. if (__get_user(m32.offset, &map->offset)
  179. || __get_user(m32.size, &map->size)
  180. || __get_user(m32.type, &map->type)
  181. || __get_user(m32.flags, &map->flags)
  182. || __get_user(handle, &map->handle)
  183. || __get_user(m32.mtrr, &map->mtrr))
  184. return -EFAULT;
  185. m32.handle = (unsigned long)handle;
  186. if (copy_to_user(argp, &m32, sizeof(m32)))
  187. return -EFAULT;
  188. return 0;
  189. }
  190. static int compat_drm_addmap(struct file *file, unsigned int cmd,
  191. unsigned long arg)
  192. {
  193. drm_map32_t __user *argp = (void __user *)arg;
  194. drm_map32_t m32;
  195. struct drm_map __user *map;
  196. int err;
  197. void *handle;
  198. if (copy_from_user(&m32, argp, sizeof(m32)))
  199. return -EFAULT;
  200. map = compat_alloc_user_space(sizeof(*map));
  201. if (!access_ok(VERIFY_WRITE, map, sizeof(*map)))
  202. return -EFAULT;
  203. if (__put_user(m32.offset, &map->offset)
  204. || __put_user(m32.size, &map->size)
  205. || __put_user(m32.type, &map->type)
  206. || __put_user(m32.flags, &map->flags))
  207. return -EFAULT;
  208. err = drm_ioctl(file, DRM_IOCTL_ADD_MAP, (unsigned long)map);
  209. if (err)
  210. return err;
  211. if (__get_user(m32.offset, &map->offset)
  212. || __get_user(m32.mtrr, &map->mtrr)
  213. || __get_user(handle, &map->handle))
  214. return -EFAULT;
  215. m32.handle = (unsigned long)handle;
  216. if (m32.handle != (unsigned long)handle)
  217. printk_ratelimited(KERN_ERR "compat_drm_addmap truncated handle"
  218. " %p for type %d offset %x\n",
  219. handle, m32.type, m32.offset);
  220. if (copy_to_user(argp, &m32, sizeof(m32)))
  221. return -EFAULT;
  222. return 0;
  223. }
  224. static int compat_drm_rmmap(struct file *file, unsigned int cmd,
  225. unsigned long arg)
  226. {
  227. drm_map32_t __user *argp = (void __user *)arg;
  228. struct drm_map __user *map;
  229. u32 handle;
  230. if (get_user(handle, &argp->handle))
  231. return -EFAULT;
  232. map = compat_alloc_user_space(sizeof(*map));
  233. if (!access_ok(VERIFY_WRITE, map, sizeof(*map)))
  234. return -EFAULT;
  235. if (__put_user((void *)(unsigned long)handle, &map->handle))
  236. return -EFAULT;
  237. return drm_ioctl(file, DRM_IOCTL_RM_MAP, (unsigned long)map);
  238. }
  239. typedef struct drm_client32 {
  240. int idx; /**< Which client desired? */
  241. int auth; /**< Is client authenticated? */
  242. u32 pid; /**< Process ID */
  243. u32 uid; /**< User ID */
  244. u32 magic; /**< Magic */
  245. u32 iocs; /**< Ioctl count */
  246. } drm_client32_t;
  247. static int compat_drm_getclient(struct file *file, unsigned int cmd,
  248. unsigned long arg)
  249. {
  250. drm_client32_t c32;
  251. drm_client32_t __user *argp = (void __user *)arg;
  252. struct drm_client __user *client;
  253. int idx, err;
  254. if (get_user(idx, &argp->idx))
  255. return -EFAULT;
  256. client = compat_alloc_user_space(sizeof(*client));
  257. if (!access_ok(VERIFY_WRITE, client, sizeof(*client)))
  258. return -EFAULT;
  259. if (__put_user(idx, &client->idx))
  260. return -EFAULT;
  261. err = drm_ioctl(file, DRM_IOCTL_GET_CLIENT, (unsigned long)client);
  262. if (err)
  263. return err;
  264. if (__get_user(c32.auth, &client->auth)
  265. || __get_user(c32.pid, &client->pid)
  266. || __get_user(c32.uid, &client->uid)
  267. || __get_user(c32.magic, &client->magic)
  268. || __get_user(c32.iocs, &client->iocs))
  269. return -EFAULT;
  270. if (copy_to_user(argp, &c32, sizeof(c32)))
  271. return -EFAULT;
  272. return 0;
  273. }
  274. typedef struct drm_stats32 {
  275. u32 count;
  276. struct {
  277. u32 value;
  278. enum drm_stat_type type;
  279. } data[15];
  280. } drm_stats32_t;
  281. static int compat_drm_getstats(struct file *file, unsigned int cmd,
  282. unsigned long arg)
  283. {
  284. drm_stats32_t s32;
  285. drm_stats32_t __user *argp = (void __user *)arg;
  286. struct drm_stats __user *stats;
  287. int i, err;
  288. stats = compat_alloc_user_space(sizeof(*stats));
  289. if (!access_ok(VERIFY_WRITE, stats, sizeof(*stats)))
  290. return -EFAULT;
  291. err = drm_ioctl(file, DRM_IOCTL_GET_STATS, (unsigned long)stats);
  292. if (err)
  293. return err;
  294. if (__get_user(s32.count, &stats->count))
  295. return -EFAULT;
  296. for (i = 0; i < 15; ++i)
  297. if (__get_user(s32.data[i].value, &stats->data[i].value)
  298. || __get_user(s32.data[i].type, &stats->data[i].type))
  299. return -EFAULT;
  300. if (copy_to_user(argp, &s32, sizeof(s32)))
  301. return -EFAULT;
  302. return 0;
  303. }
  304. typedef struct drm_buf_desc32 {
  305. int count; /**< Number of buffers of this size */
  306. int size; /**< Size in bytes */
  307. int low_mark; /**< Low water mark */
  308. int high_mark; /**< High water mark */
  309. int flags;
  310. u32 agp_start; /**< Start address in the AGP aperture */
  311. } drm_buf_desc32_t;
  312. static int compat_drm_addbufs(struct file *file, unsigned int cmd,
  313. unsigned long arg)
  314. {
  315. drm_buf_desc32_t __user *argp = (void __user *)arg;
  316. struct drm_buf_desc __user *buf;
  317. int err;
  318. unsigned long agp_start;
  319. buf = compat_alloc_user_space(sizeof(*buf));
  320. if (!access_ok(VERIFY_WRITE, buf, sizeof(*buf))
  321. || !access_ok(VERIFY_WRITE, argp, sizeof(*argp)))
  322. return -EFAULT;
  323. if (__copy_in_user(buf, argp, offsetof(drm_buf_desc32_t, agp_start))
  324. || __get_user(agp_start, &argp->agp_start)
  325. || __put_user(agp_start, &buf->agp_start))
  326. return -EFAULT;
  327. err = drm_ioctl(file, DRM_IOCTL_ADD_BUFS, (unsigned long)buf);
  328. if (err)
  329. return err;
  330. if (__copy_in_user(argp, buf, offsetof(drm_buf_desc32_t, agp_start))
  331. || __get_user(agp_start, &buf->agp_start)
  332. || __put_user(agp_start, &argp->agp_start))
  333. return -EFAULT;
  334. return 0;
  335. }
  336. static int compat_drm_markbufs(struct file *file, unsigned int cmd,
  337. unsigned long arg)
  338. {
  339. drm_buf_desc32_t b32;
  340. drm_buf_desc32_t __user *argp = (void __user *)arg;
  341. struct drm_buf_desc __user *buf;
  342. if (copy_from_user(&b32, argp, sizeof(b32)))
  343. return -EFAULT;
  344. buf = compat_alloc_user_space(sizeof(*buf));
  345. if (!access_ok(VERIFY_WRITE, buf, sizeof(*buf)))
  346. return -EFAULT;
  347. if (__put_user(b32.size, &buf->size)
  348. || __put_user(b32.low_mark, &buf->low_mark)
  349. || __put_user(b32.high_mark, &buf->high_mark))
  350. return -EFAULT;
  351. return drm_ioctl(file, DRM_IOCTL_MARK_BUFS, (unsigned long)buf);
  352. }
  353. typedef struct drm_buf_info32 {
  354. int count; /**< Entries in list */
  355. u32 list;
  356. } drm_buf_info32_t;
  357. static int compat_drm_infobufs(struct file *file, unsigned int cmd,
  358. unsigned long arg)
  359. {
  360. drm_buf_info32_t req32;
  361. drm_buf_info32_t __user *argp = (void __user *)arg;
  362. drm_buf_desc32_t __user *to;
  363. struct drm_buf_info __user *request;
  364. struct drm_buf_desc __user *list;
  365. size_t nbytes;
  366. int i, err;
  367. int count, actual;
  368. if (copy_from_user(&req32, argp, sizeof(req32)))
  369. return -EFAULT;
  370. count = req32.count;
  371. to = (drm_buf_desc32_t __user *) (unsigned long)req32.list;
  372. if (count < 0)
  373. count = 0;
  374. if (count > 0
  375. && !access_ok(VERIFY_WRITE, to, count * sizeof(drm_buf_desc32_t)))
  376. return -EFAULT;
  377. nbytes = sizeof(*request) + count * sizeof(struct drm_buf_desc);
  378. request = compat_alloc_user_space(nbytes);
  379. if (!access_ok(VERIFY_WRITE, request, nbytes))
  380. return -EFAULT;
  381. list = (struct drm_buf_desc *) (request + 1);
  382. if (__put_user(count, &request->count)
  383. || __put_user(list, &request->list))
  384. return -EFAULT;
  385. err = drm_ioctl(file, DRM_IOCTL_INFO_BUFS, (unsigned long)request);
  386. if (err)
  387. return err;
  388. if (__get_user(actual, &request->count))
  389. return -EFAULT;
  390. if (count >= actual)
  391. for (i = 0; i < actual; ++i)
  392. if (__copy_in_user(&to[i], &list[i],
  393. offsetof(struct drm_buf_desc, flags)))
  394. return -EFAULT;
  395. if (__put_user(actual, &argp->count))
  396. return -EFAULT;
  397. return 0;
  398. }
  399. typedef struct drm_buf_pub32 {
  400. int idx; /**< Index into the master buffer list */
  401. int total; /**< Buffer size */
  402. int used; /**< Amount of buffer in use (for DMA) */
  403. u32 address; /**< Address of buffer */
  404. } drm_buf_pub32_t;
  405. typedef struct drm_buf_map32 {
  406. int count; /**< Length of the buffer list */
  407. u32 virtual; /**< Mmap'd area in user-virtual */
  408. u32 list; /**< Buffer information */
  409. } drm_buf_map32_t;
  410. static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
  411. unsigned long arg)
  412. {
  413. drm_buf_map32_t __user *argp = (void __user *)arg;
  414. drm_buf_map32_t req32;
  415. drm_buf_pub32_t __user *list32;
  416. struct drm_buf_map __user *request;
  417. struct drm_buf_pub __user *list;
  418. int i, err;
  419. int count, actual;
  420. size_t nbytes;
  421. void __user *addr;
  422. if (copy_from_user(&req32, argp, sizeof(req32)))
  423. return -EFAULT;
  424. count = req32.count;
  425. list32 = (void __user *)(unsigned long)req32.list;
  426. if (count < 0)
  427. return -EINVAL;
  428. nbytes = sizeof(*request) + count * sizeof(struct drm_buf_pub);
  429. request = compat_alloc_user_space(nbytes);
  430. if (!access_ok(VERIFY_WRITE, request, nbytes))
  431. return -EFAULT;
  432. list = (struct drm_buf_pub *) (request + 1);
  433. if (__put_user(count, &request->count)
  434. || __put_user(list, &request->list))
  435. return -EFAULT;
  436. err = drm_ioctl(file, DRM_IOCTL_MAP_BUFS, (unsigned long)request);
  437. if (err)
  438. return err;
  439. if (__get_user(actual, &request->count))
  440. return -EFAULT;
  441. if (count >= actual)
  442. for (i = 0; i < actual; ++i)
  443. if (__copy_in_user(&list32[i], &list[i],
  444. offsetof(struct drm_buf_pub, address))
  445. || __get_user(addr, &list[i].address)
  446. || __put_user((unsigned long)addr,
  447. &list32[i].address))
  448. return -EFAULT;
  449. if (__put_user(actual, &argp->count)
  450. || __get_user(addr, &request->virtual)
  451. || __put_user((unsigned long)addr, &argp->virtual))
  452. return -EFAULT;
  453. return 0;
  454. }
  455. typedef struct drm_buf_free32 {
  456. int count;
  457. u32 list;
  458. } drm_buf_free32_t;
  459. static int compat_drm_freebufs(struct file *file, unsigned int cmd,
  460. unsigned long arg)
  461. {
  462. drm_buf_free32_t req32;
  463. struct drm_buf_free __user *request;
  464. drm_buf_free32_t __user *argp = (void __user *)arg;
  465. if (copy_from_user(&req32, argp, sizeof(req32)))
  466. return -EFAULT;
  467. request = compat_alloc_user_space(sizeof(*request));
  468. if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
  469. return -EFAULT;
  470. if (__put_user(req32.count, &request->count)
  471. || __put_user((int __user *)(unsigned long)req32.list,
  472. &request->list))
  473. return -EFAULT;
  474. return drm_ioctl(file, DRM_IOCTL_FREE_BUFS, (unsigned long)request);
  475. }
  476. typedef struct drm_ctx_priv_map32 {
  477. unsigned int ctx_id; /**< Context requesting private mapping */
  478. u32 handle; /**< Handle of map */
  479. } drm_ctx_priv_map32_t;
  480. static int compat_drm_setsareactx(struct file *file, unsigned int cmd,
  481. unsigned long arg)
  482. {
  483. drm_ctx_priv_map32_t req32;
  484. struct drm_ctx_priv_map __user *request;
  485. drm_ctx_priv_map32_t __user *argp = (void __user *)arg;
  486. if (copy_from_user(&req32, argp, sizeof(req32)))
  487. return -EFAULT;
  488. request = compat_alloc_user_space(sizeof(*request));
  489. if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
  490. return -EFAULT;
  491. if (__put_user(req32.ctx_id, &request->ctx_id)
  492. || __put_user((void *)(unsigned long)req32.handle,
  493. &request->handle))
  494. return -EFAULT;
  495. return drm_ioctl(file, DRM_IOCTL_SET_SAREA_CTX, (unsigned long)request);
  496. }
  497. static int compat_drm_getsareactx(struct file *file, unsigned int cmd,
  498. unsigned long arg)
  499. {
  500. struct drm_ctx_priv_map __user *request;
  501. drm_ctx_priv_map32_t __user *argp = (void __user *)arg;
  502. int err;
  503. unsigned int ctx_id;
  504. void *handle;
  505. if (!access_ok(VERIFY_WRITE, argp, sizeof(*argp))
  506. || __get_user(ctx_id, &argp->ctx_id))
  507. return -EFAULT;
  508. request = compat_alloc_user_space(sizeof(*request));
  509. if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
  510. return -EFAULT;
  511. if (__put_user(ctx_id, &request->ctx_id))
  512. return -EFAULT;
  513. err = drm_ioctl(file, DRM_IOCTL_GET_SAREA_CTX, (unsigned long)request);
  514. if (err)
  515. return err;
  516. if (__get_user(handle, &request->handle)
  517. || __put_user((unsigned long)handle, &argp->handle))
  518. return -EFAULT;
  519. return 0;
  520. }
  521. typedef struct drm_ctx_res32 {
  522. int count;
  523. u32 contexts;
  524. } drm_ctx_res32_t;
  525. static int compat_drm_resctx(struct file *file, unsigned int cmd,
  526. unsigned long arg)
  527. {
  528. drm_ctx_res32_t __user *argp = (void __user *)arg;
  529. drm_ctx_res32_t res32;
  530. struct drm_ctx_res __user *res;
  531. int err;
  532. if (copy_from_user(&res32, argp, sizeof(res32)))
  533. return -EFAULT;
  534. res = compat_alloc_user_space(sizeof(*res));
  535. if (!access_ok(VERIFY_WRITE, res, sizeof(*res)))
  536. return -EFAULT;
  537. if (__put_user(res32.count, &res->count)
  538. || __put_user((struct drm_ctx __user *) (unsigned long)res32.contexts,
  539. &res->contexts))
  540. return -EFAULT;
  541. err = drm_ioctl(file, DRM_IOCTL_RES_CTX, (unsigned long)res);
  542. if (err)
  543. return err;
  544. if (__get_user(res32.count, &res->count)
  545. || __put_user(res32.count, &argp->count))
  546. return -EFAULT;
  547. return 0;
  548. }
  549. typedef struct drm_dma32 {
  550. int context; /**< Context handle */
  551. int send_count; /**< Number of buffers to send */
  552. u32 send_indices; /**< List of handles to buffers */
  553. u32 send_sizes; /**< Lengths of data to send */
  554. enum drm_dma_flags flags; /**< Flags */
  555. int request_count; /**< Number of buffers requested */
  556. int request_size; /**< Desired size for buffers */
  557. u32 request_indices; /**< Buffer information */
  558. u32 request_sizes;
  559. int granted_count; /**< Number of buffers granted */
  560. } drm_dma32_t;
  561. static int compat_drm_dma(struct file *file, unsigned int cmd,
  562. unsigned long arg)
  563. {
  564. drm_dma32_t d32;
  565. drm_dma32_t __user *argp = (void __user *)arg;
  566. struct drm_dma __user *d;
  567. int err;
  568. if (copy_from_user(&d32, argp, sizeof(d32)))
  569. return -EFAULT;
  570. d = compat_alloc_user_space(sizeof(*d));
  571. if (!access_ok(VERIFY_WRITE, d, sizeof(*d)))
  572. return -EFAULT;
  573. if (__put_user(d32.context, &d->context)
  574. || __put_user(d32.send_count, &d->send_count)
  575. || __put_user((int __user *)(unsigned long)d32.send_indices,
  576. &d->send_indices)
  577. || __put_user((int __user *)(unsigned long)d32.send_sizes,
  578. &d->send_sizes)
  579. || __put_user(d32.flags, &d->flags)
  580. || __put_user(d32.request_count, &d->request_count)
  581. || __put_user((int __user *)(unsigned long)d32.request_indices,
  582. &d->request_indices)
  583. || __put_user((int __user *)(unsigned long)d32.request_sizes,
  584. &d->request_sizes))
  585. return -EFAULT;
  586. err = drm_ioctl(file, DRM_IOCTL_DMA, (unsigned long)d);
  587. if (err)
  588. return err;
  589. if (__get_user(d32.request_size, &d->request_size)
  590. || __get_user(d32.granted_count, &d->granted_count)
  591. || __put_user(d32.request_size, &argp->request_size)
  592. || __put_user(d32.granted_count, &argp->granted_count))
  593. return -EFAULT;
  594. return 0;
  595. }
  596. #if __OS_HAS_AGP
  597. typedef struct drm_agp_mode32 {
  598. u32 mode; /**< AGP mode */
  599. } drm_agp_mode32_t;
  600. static int compat_drm_agp_enable(struct file *file, unsigned int cmd,
  601. unsigned long arg)
  602. {
  603. drm_agp_mode32_t __user *argp = (void __user *)arg;
  604. drm_agp_mode32_t m32;
  605. struct drm_agp_mode __user *mode;
  606. if (get_user(m32.mode, &argp->mode))
  607. return -EFAULT;
  608. mode = compat_alloc_user_space(sizeof(*mode));
  609. if (put_user(m32.mode, &mode->mode))
  610. return -EFAULT;
  611. return drm_ioctl(file, DRM_IOCTL_AGP_ENABLE, (unsigned long)mode);
  612. }
  613. typedef struct drm_agp_info32 {
  614. int agp_version_major;
  615. int agp_version_minor;
  616. u32 mode;
  617. u32 aperture_base; /* physical address */
  618. u32 aperture_size; /* bytes */
  619. u32 memory_allowed; /* bytes */
  620. u32 memory_used;
  621. /* PCI information */
  622. unsigned short id_vendor;
  623. unsigned short id_device;
  624. } drm_agp_info32_t;
  625. static int compat_drm_agp_info(struct file *file, unsigned int cmd,
  626. unsigned long arg)
  627. {
  628. drm_agp_info32_t __user *argp = (void __user *)arg;
  629. drm_agp_info32_t i32;
  630. struct drm_agp_info __user *info;
  631. int err;
  632. info = compat_alloc_user_space(sizeof(*info));
  633. if (!access_ok(VERIFY_WRITE, info, sizeof(*info)))
  634. return -EFAULT;
  635. err = drm_ioctl(file, DRM_IOCTL_AGP_INFO, (unsigned long)info);
  636. if (err)
  637. return err;
  638. if (__get_user(i32.agp_version_major, &info->agp_version_major)
  639. || __get_user(i32.agp_version_minor, &info->agp_version_minor)
  640. || __get_user(i32.mode, &info->mode)
  641. || __get_user(i32.aperture_base, &info->aperture_base)
  642. || __get_user(i32.aperture_size, &info->aperture_size)
  643. || __get_user(i32.memory_allowed, &info->memory_allowed)
  644. || __get_user(i32.memory_used, &info->memory_used)
  645. || __get_user(i32.id_vendor, &info->id_vendor)
  646. || __get_user(i32.id_device, &info->id_device))
  647. return -EFAULT;
  648. if (copy_to_user(argp, &i32, sizeof(i32)))
  649. return -EFAULT;
  650. return 0;
  651. }
  652. typedef struct drm_agp_buffer32 {
  653. u32 size; /**< In bytes -- will round to page boundary */
  654. u32 handle; /**< Used for binding / unbinding */
  655. u32 type; /**< Type of memory to allocate */
  656. u32 physical; /**< Physical used by i810 */
  657. } drm_agp_buffer32_t;
  658. static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
  659. unsigned long arg)
  660. {
  661. drm_agp_buffer32_t __user *argp = (void __user *)arg;
  662. drm_agp_buffer32_t req32;
  663. struct drm_agp_buffer __user *request;
  664. int err;
  665. if (copy_from_user(&req32, argp, sizeof(req32)))
  666. return -EFAULT;
  667. request = compat_alloc_user_space(sizeof(*request));
  668. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  669. || __put_user(req32.size, &request->size)
  670. || __put_user(req32.type, &request->type))
  671. return -EFAULT;
  672. err = drm_ioctl(file, DRM_IOCTL_AGP_ALLOC, (unsigned long)request);
  673. if (err)
  674. return err;
  675. if (__get_user(req32.handle, &request->handle)
  676. || __get_user(req32.physical, &request->physical)
  677. || copy_to_user(argp, &req32, sizeof(req32))) {
  678. drm_ioctl(file, DRM_IOCTL_AGP_FREE, (unsigned long)request);
  679. return -EFAULT;
  680. }
  681. return 0;
  682. }
  683. static int compat_drm_agp_free(struct file *file, unsigned int cmd,
  684. unsigned long arg)
  685. {
  686. drm_agp_buffer32_t __user *argp = (void __user *)arg;
  687. struct drm_agp_buffer __user *request;
  688. u32 handle;
  689. request = compat_alloc_user_space(sizeof(*request));
  690. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  691. || get_user(handle, &argp->handle)
  692. || __put_user(handle, &request->handle))
  693. return -EFAULT;
  694. return drm_ioctl(file, DRM_IOCTL_AGP_FREE, (unsigned long)request);
  695. }
  696. typedef struct drm_agp_binding32 {
  697. u32 handle; /**< From drm_agp_buffer */
  698. u32 offset; /**< In bytes -- will round to page boundary */
  699. } drm_agp_binding32_t;
  700. static int compat_drm_agp_bind(struct file *file, unsigned int cmd,
  701. unsigned long arg)
  702. {
  703. drm_agp_binding32_t __user *argp = (void __user *)arg;
  704. drm_agp_binding32_t req32;
  705. struct drm_agp_binding __user *request;
  706. if (copy_from_user(&req32, argp, sizeof(req32)))
  707. return -EFAULT;
  708. request = compat_alloc_user_space(sizeof(*request));
  709. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  710. || __put_user(req32.handle, &request->handle)
  711. || __put_user(req32.offset, &request->offset))
  712. return -EFAULT;
  713. return drm_ioctl(file, DRM_IOCTL_AGP_BIND, (unsigned long)request);
  714. }
  715. static int compat_drm_agp_unbind(struct file *file, unsigned int cmd,
  716. unsigned long arg)
  717. {
  718. drm_agp_binding32_t __user *argp = (void __user *)arg;
  719. struct drm_agp_binding __user *request;
  720. u32 handle;
  721. request = compat_alloc_user_space(sizeof(*request));
  722. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  723. || get_user(handle, &argp->handle)
  724. || __put_user(handle, &request->handle))
  725. return -EFAULT;
  726. return drm_ioctl(file, DRM_IOCTL_AGP_UNBIND, (unsigned long)request);
  727. }
  728. #endif /* __OS_HAS_AGP */
  729. typedef struct drm_scatter_gather32 {
  730. u32 size; /**< In bytes -- will round to page boundary */
  731. u32 handle; /**< Used for mapping / unmapping */
  732. } drm_scatter_gather32_t;
  733. static int compat_drm_sg_alloc(struct file *file, unsigned int cmd,
  734. unsigned long arg)
  735. {
  736. drm_scatter_gather32_t __user *argp = (void __user *)arg;
  737. struct drm_scatter_gather __user *request;
  738. int err;
  739. unsigned long x;
  740. request = compat_alloc_user_space(sizeof(*request));
  741. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  742. || !access_ok(VERIFY_WRITE, argp, sizeof(*argp))
  743. || __get_user(x, &argp->size)
  744. || __put_user(x, &request->size))
  745. return -EFAULT;
  746. err = drm_ioctl(file, DRM_IOCTL_SG_ALLOC, (unsigned long)request);
  747. if (err)
  748. return err;
  749. /* XXX not sure about the handle conversion here... */
  750. if (__get_user(x, &request->handle)
  751. || __put_user(x >> PAGE_SHIFT, &argp->handle))
  752. return -EFAULT;
  753. return 0;
  754. }
  755. static int compat_drm_sg_free(struct file *file, unsigned int cmd,
  756. unsigned long arg)
  757. {
  758. drm_scatter_gather32_t __user *argp = (void __user *)arg;
  759. struct drm_scatter_gather __user *request;
  760. unsigned long x;
  761. request = compat_alloc_user_space(sizeof(*request));
  762. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  763. || !access_ok(VERIFY_WRITE, argp, sizeof(*argp))
  764. || __get_user(x, &argp->handle)
  765. || __put_user(x << PAGE_SHIFT, &request->handle))
  766. return -EFAULT;
  767. return drm_ioctl(file, DRM_IOCTL_SG_FREE, (unsigned long)request);
  768. }
  769. #if defined(CONFIG_X86) || defined(CONFIG_IA64)
  770. typedef struct drm_update_draw32 {
  771. drm_drawable_t handle;
  772. unsigned int type;
  773. unsigned int num;
  774. /* 64-bit version has a 32-bit pad here */
  775. u64 data; /**< Pointer */
  776. } __attribute__((packed)) drm_update_draw32_t;
  777. static int compat_drm_update_draw(struct file *file, unsigned int cmd,
  778. unsigned long arg)
  779. {
  780. drm_update_draw32_t update32;
  781. struct drm_update_draw __user *request;
  782. int err;
  783. if (copy_from_user(&update32, (void __user *)arg, sizeof(update32)))
  784. return -EFAULT;
  785. request = compat_alloc_user_space(sizeof(*request));
  786. if (!access_ok(VERIFY_WRITE, request, sizeof(*request)) ||
  787. __put_user(update32.handle, &request->handle) ||
  788. __put_user(update32.type, &request->type) ||
  789. __put_user(update32.num, &request->num) ||
  790. __put_user(update32.data, &request->data))
  791. return -EFAULT;
  792. err = drm_ioctl(file, DRM_IOCTL_UPDATE_DRAW, (unsigned long)request);
  793. return err;
  794. }
  795. #endif
  796. struct drm_wait_vblank_request32 {
  797. enum drm_vblank_seq_type type;
  798. unsigned int sequence;
  799. u32 signal;
  800. };
  801. struct drm_wait_vblank_reply32 {
  802. enum drm_vblank_seq_type type;
  803. unsigned int sequence;
  804. s32 tval_sec;
  805. s32 tval_usec;
  806. };
  807. typedef union drm_wait_vblank32 {
  808. struct drm_wait_vblank_request32 request;
  809. struct drm_wait_vblank_reply32 reply;
  810. } drm_wait_vblank32_t;
  811. static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
  812. unsigned long arg)
  813. {
  814. drm_wait_vblank32_t __user *argp = (void __user *)arg;
  815. drm_wait_vblank32_t req32;
  816. union drm_wait_vblank __user *request;
  817. int err;
  818. if (copy_from_user(&req32, argp, sizeof(req32)))
  819. return -EFAULT;
  820. request = compat_alloc_user_space(sizeof(*request));
  821. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  822. || __put_user(req32.request.type, &request->request.type)
  823. || __put_user(req32.request.sequence, &request->request.sequence)
  824. || __put_user(req32.request.signal, &request->request.signal))
  825. return -EFAULT;
  826. err = drm_ioctl(file, DRM_IOCTL_WAIT_VBLANK, (unsigned long)request);
  827. if (err)
  828. return err;
  829. if (__get_user(req32.reply.type, &request->reply.type)
  830. || __get_user(req32.reply.sequence, &request->reply.sequence)
  831. || __get_user(req32.reply.tval_sec, &request->reply.tval_sec)
  832. || __get_user(req32.reply.tval_usec, &request->reply.tval_usec))
  833. return -EFAULT;
  834. if (copy_to_user(argp, &req32, sizeof(req32)))
  835. return -EFAULT;
  836. return 0;
  837. }
  838. drm_ioctl_compat_t *drm_compat_ioctls[] = {
  839. [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
  840. [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
  841. [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
  842. [DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT32)] = compat_drm_getclient,
  843. [DRM_IOCTL_NR(DRM_IOCTL_GET_STATS32)] = compat_drm_getstats,
  844. [DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE32)] = compat_drm_setunique,
  845. [DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP32)] = compat_drm_addmap,
  846. [DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS32)] = compat_drm_addbufs,
  847. [DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS32)] = compat_drm_markbufs,
  848. [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS32)] = compat_drm_infobufs,
  849. [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS32)] = compat_drm_mapbufs,
  850. [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS32)] = compat_drm_freebufs,
  851. [DRM_IOCTL_NR(DRM_IOCTL_RM_MAP32)] = compat_drm_rmmap,
  852. [DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX32)] = compat_drm_setsareactx,
  853. [DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX32)] = compat_drm_getsareactx,
  854. [DRM_IOCTL_NR(DRM_IOCTL_RES_CTX32)] = compat_drm_resctx,
  855. [DRM_IOCTL_NR(DRM_IOCTL_DMA32)] = compat_drm_dma,
  856. #if __OS_HAS_AGP
  857. [DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE32)] = compat_drm_agp_enable,
  858. [DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO32)] = compat_drm_agp_info,
  859. [DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC32)] = compat_drm_agp_alloc,
  860. [DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE32)] = compat_drm_agp_free,
  861. [DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND32)] = compat_drm_agp_bind,
  862. [DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND32)] = compat_drm_agp_unbind,
  863. #endif
  864. [DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC32)] = compat_drm_sg_alloc,
  865. [DRM_IOCTL_NR(DRM_IOCTL_SG_FREE32)] = compat_drm_sg_free,
  866. #if defined(CONFIG_X86) || defined(CONFIG_IA64)
  867. [DRM_IOCTL_NR(DRM_IOCTL_UPDATE_DRAW32)] = compat_drm_update_draw,
  868. #endif
  869. [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK32)] = compat_drm_wait_vblank,
  870. };
  871. /**
  872. * Called whenever a 32-bit process running under a 64-bit kernel
  873. * performs an ioctl on /dev/drm.
  874. *
  875. * \param file_priv DRM file private.
  876. * \param cmd command.
  877. * \param arg user argument.
  878. * \return zero on success or negative number on failure.
  879. */
  880. long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  881. {
  882. unsigned int nr = DRM_IOCTL_NR(cmd);
  883. drm_ioctl_compat_t *fn;
  884. int ret;
  885. /* Assume that ioctls without an explicit compat routine will just
  886. * work. This may not always be a good assumption, but it's better
  887. * than always failing.
  888. */
  889. if (nr >= ARRAY_SIZE(drm_compat_ioctls))
  890. return drm_ioctl(filp, cmd, arg);
  891. fn = drm_compat_ioctls[nr];
  892. if (fn != NULL)
  893. ret = (*fn) (filp, cmd, arg);
  894. else
  895. ret = drm_ioctl(filp, cmd, arg);
  896. return ret;
  897. }
  898. EXPORT_SYMBOL(drm_compat_ioctl);