drm_ioc32.c 32 KB

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