drm_ioctl.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. /*
  2. * Created: Fri Jan 8 09:01:26 1999 by faith@valinux.com
  3. *
  4. * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  5. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  6. * All Rights Reserved.
  7. *
  8. * Author Rickard E. (Rik) Faith <faith@valinux.com>
  9. * Author Gareth Hughes <gareth@valinux.com>
  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. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  26. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  27. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  28. * OTHER DEALINGS IN THE SOFTWARE.
  29. */
  30. #include <linux/export.h>
  31. #include <linux/nospec.h>
  32. #include <linux/pci.h>
  33. #include <linux/uaccess.h>
  34. #include <drm/drm_agpsupport.h>
  35. #include <drm/drm_auth.h>
  36. #include <drm/drm_crtc.h>
  37. #include <drm/drm_drv.h>
  38. #include <drm/drm_file.h>
  39. #include <drm/drm_ioctl.h>
  40. #include <drm/drm_print.h>
  41. #include "drm_crtc_internal.h"
  42. #include "drm_internal.h"
  43. #include "drm_legacy.h"
  44. /**
  45. * DOC: getunique and setversion story
  46. *
  47. * BEWARE THE DRAGONS! MIND THE TRAPDOORS!
  48. *
  49. * In an attempt to warn anyone else who's trying to figure out what's going
  50. * on here, I'll try to summarize the story. First things first, let's clear up
  51. * the names, because the kernel internals, libdrm and the ioctls are all named
  52. * differently:
  53. *
  54. * - GET_UNIQUE ioctl, implemented by drm_getunique is wrapped up in libdrm
  55. * through the drmGetBusid function.
  56. * - The libdrm drmSetBusid function is backed by the SET_UNIQUE ioctl. All
  57. * that code is nerved in the kernel with drm_invalid_op().
  58. * - The internal set_busid kernel functions and driver callbacks are
  59. * exclusively use by the SET_VERSION ioctl, because only drm 1.0 (which is
  60. * nerved) allowed userspace to set the busid through the above ioctl.
  61. * - Other ioctls and functions involved are named consistently.
  62. *
  63. * For anyone wondering what's the difference between drm 1.1 and 1.4: Correctly
  64. * handling pci domains in the busid on ppc. Doing this correctly was only
  65. * implemented in libdrm in 2010, hence can't be nerved yet. No one knows what's
  66. * special with drm 1.2 and 1.3.
  67. *
  68. * Now the actual horror story of how device lookup in drm works. At large,
  69. * there's 2 different ways, either by busid, or by device driver name.
  70. *
  71. * Opening by busid is fairly simple:
  72. *
  73. * 1. First call SET_VERSION to make sure pci domains are handled properly. As a
  74. * side-effect this fills out the unique name in the master structure.
  75. * 2. Call GET_UNIQUE to read out the unique name from the master structure,
  76. * which matches the busid thanks to step 1. If it doesn't, proceed to try
  77. * the next device node.
  78. *
  79. * Opening by name is slightly different:
  80. *
  81. * 1. Directly call VERSION to get the version and to match against the driver
  82. * name returned by that ioctl. Note that SET_VERSION is not called, which
  83. * means the the unique name for the master node just opening is _not_ filled
  84. * out. This despite that with current drm device nodes are always bound to
  85. * one device, and can't be runtime assigned like with drm 1.0.
  86. * 2. Match driver name. If it mismatches, proceed to the next device node.
  87. * 3. Call GET_UNIQUE, and check whether the unique name has length zero (by
  88. * checking that the first byte in the string is 0). If that's not the case
  89. * libdrm skips and proceeds to the next device node. Probably this is just
  90. * copypasta from drm 1.0 times where a set unique name meant that the driver
  91. * was in use already, but that's just conjecture.
  92. *
  93. * Long story short: To keep the open by name logic working, GET_UNIQUE must
  94. * _not_ return a unique string when SET_VERSION hasn't been called yet,
  95. * otherwise libdrm breaks. Even when that unique string can't ever change, and
  96. * is totally irrelevant for actually opening the device because runtime
  97. * assignable device instances were only support in drm 1.0, which is long dead.
  98. * But the libdrm code in drmOpenByName somehow survived, hence this can't be
  99. * broken.
  100. */
  101. /*
  102. * Get the bus id.
  103. *
  104. * \param inode device inode.
  105. * \param file_priv DRM file private.
  106. * \param cmd command.
  107. * \param arg user argument, pointing to a drm_unique structure.
  108. * \return zero on success or a negative number on failure.
  109. *
  110. * Copies the bus id from drm_device::unique into user space.
  111. */
  112. int drm_getunique(struct drm_device *dev, void *data,
  113. struct drm_file *file_priv)
  114. {
  115. struct drm_unique *u = data;
  116. struct drm_master *master;
  117. mutex_lock(&dev->master_mutex);
  118. master = file_priv->master;
  119. if (u->unique_len >= master->unique_len) {
  120. if (copy_to_user(u->unique, master->unique, master->unique_len)) {
  121. mutex_unlock(&dev->master_mutex);
  122. return -EFAULT;
  123. }
  124. }
  125. u->unique_len = master->unique_len;
  126. mutex_unlock(&dev->master_mutex);
  127. return 0;
  128. }
  129. static void
  130. drm_unset_busid(struct drm_device *dev,
  131. struct drm_master *master)
  132. {
  133. kfree(master->unique);
  134. master->unique = NULL;
  135. master->unique_len = 0;
  136. }
  137. static int drm_set_busid(struct drm_device *dev, struct drm_file *file_priv)
  138. {
  139. struct drm_master *master = file_priv->master;
  140. int ret;
  141. if (master->unique != NULL)
  142. drm_unset_busid(dev, master);
  143. if (dev->dev && dev_is_pci(dev->dev)) {
  144. ret = drm_pci_set_busid(dev, master);
  145. if (ret) {
  146. drm_unset_busid(dev, master);
  147. return ret;
  148. }
  149. } else {
  150. WARN_ON(!dev->unique);
  151. master->unique = kstrdup(dev->unique, GFP_KERNEL);
  152. if (master->unique)
  153. master->unique_len = strlen(dev->unique);
  154. }
  155. return 0;
  156. }
  157. /*
  158. * Get client information.
  159. *
  160. * \param inode device inode.
  161. * \param file_priv DRM file private.
  162. * \param cmd command.
  163. * \param arg user argument, pointing to a drm_client structure.
  164. *
  165. * \return zero on success or a negative number on failure.
  166. *
  167. * Searches for the client with the specified index and copies its information
  168. * into userspace
  169. */
  170. int drm_getclient(struct drm_device *dev, void *data,
  171. struct drm_file *file_priv)
  172. {
  173. struct drm_client *client = data;
  174. /*
  175. * Hollowed-out getclient ioctl to keep some dead old drm tests/tools
  176. * not breaking completely. Userspace tools stop enumerating one they
  177. * get -EINVAL, hence this is the return value we need to hand back for
  178. * no clients tracked.
  179. *
  180. * Unfortunately some clients (*cough* libva *cough*) use this in a fun
  181. * attempt to figure out whether they're authenticated or not. Since
  182. * that's the only thing they care about, give it to the directly
  183. * instead of walking one giant list.
  184. */
  185. if (client->idx == 0) {
  186. client->auth = file_priv->authenticated;
  187. client->pid = task_pid_vnr(current);
  188. client->uid = overflowuid;
  189. client->magic = 0;
  190. client->iocs = 0;
  191. return 0;
  192. } else {
  193. return -EINVAL;
  194. }
  195. }
  196. /*
  197. * Get statistics information.
  198. *
  199. * \param inode device inode.
  200. * \param file_priv DRM file private.
  201. * \param cmd command.
  202. * \param arg user argument, pointing to a drm_stats structure.
  203. *
  204. * \return zero on success or a negative number on failure.
  205. */
  206. static int drm_getstats(struct drm_device *dev, void *data,
  207. struct drm_file *file_priv)
  208. {
  209. struct drm_stats *stats = data;
  210. /* Clear stats to prevent userspace from eating its stack garbage. */
  211. memset(stats, 0, sizeof(*stats));
  212. return 0;
  213. }
  214. /*
  215. * Get device/driver capabilities
  216. */
  217. static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
  218. {
  219. struct drm_get_cap *req = data;
  220. struct drm_crtc *crtc;
  221. req->value = 0;
  222. /* Only some caps make sense with UMS/render-only drivers. */
  223. switch (req->capability) {
  224. case DRM_CAP_TIMESTAMP_MONOTONIC:
  225. req->value = 1;
  226. return 0;
  227. case DRM_CAP_PRIME:
  228. req->value |= dev->driver->prime_fd_to_handle ? DRM_PRIME_CAP_IMPORT : 0;
  229. req->value |= dev->driver->prime_handle_to_fd ? DRM_PRIME_CAP_EXPORT : 0;
  230. return 0;
  231. case DRM_CAP_SYNCOBJ:
  232. req->value = drm_core_check_feature(dev, DRIVER_SYNCOBJ);
  233. return 0;
  234. case DRM_CAP_SYNCOBJ_TIMELINE:
  235. req->value = drm_core_check_feature(dev, DRIVER_SYNCOBJ_TIMELINE);
  236. return 0;
  237. }
  238. /* Other caps only work with KMS drivers */
  239. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  240. return -EOPNOTSUPP;
  241. switch (req->capability) {
  242. case DRM_CAP_DUMB_BUFFER:
  243. if (dev->driver->dumb_create)
  244. req->value = 1;
  245. break;
  246. case DRM_CAP_VBLANK_HIGH_CRTC:
  247. req->value = 1;
  248. break;
  249. case DRM_CAP_DUMB_PREFERRED_DEPTH:
  250. req->value = dev->mode_config.preferred_depth;
  251. break;
  252. case DRM_CAP_DUMB_PREFER_SHADOW:
  253. req->value = dev->mode_config.prefer_shadow;
  254. break;
  255. case DRM_CAP_ASYNC_PAGE_FLIP:
  256. req->value = dev->mode_config.async_page_flip;
  257. break;
  258. case DRM_CAP_PAGE_FLIP_TARGET:
  259. req->value = 1;
  260. drm_for_each_crtc(crtc, dev) {
  261. if (!crtc->funcs->page_flip_target)
  262. req->value = 0;
  263. }
  264. break;
  265. case DRM_CAP_CURSOR_WIDTH:
  266. if (dev->mode_config.cursor_width)
  267. req->value = dev->mode_config.cursor_width;
  268. else
  269. req->value = 64;
  270. break;
  271. case DRM_CAP_CURSOR_HEIGHT:
  272. if (dev->mode_config.cursor_height)
  273. req->value = dev->mode_config.cursor_height;
  274. else
  275. req->value = 64;
  276. break;
  277. case DRM_CAP_ADDFB2_MODIFIERS:
  278. req->value = dev->mode_config.allow_fb_modifiers;
  279. break;
  280. case DRM_CAP_CRTC_IN_VBLANK_EVENT:
  281. req->value = 1;
  282. break;
  283. default:
  284. return -EINVAL;
  285. }
  286. return 0;
  287. }
  288. /*
  289. * Set device/driver capabilities
  290. */
  291. static int
  292. drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
  293. {
  294. struct drm_set_client_cap *req = data;
  295. /* No render-only settable capabilities for now */
  296. /* Below caps that only works with KMS drivers */
  297. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  298. return -EOPNOTSUPP;
  299. switch (req->capability) {
  300. case DRM_CLIENT_CAP_STEREO_3D:
  301. if (req->value > 1)
  302. return -EINVAL;
  303. file_priv->stereo_allowed = req->value;
  304. break;
  305. case DRM_CLIENT_CAP_UNIVERSAL_PLANES:
  306. if (req->value > 1)
  307. return -EINVAL;
  308. file_priv->universal_planes = req->value;
  309. break;
  310. case DRM_CLIENT_CAP_ATOMIC:
  311. if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
  312. return -EOPNOTSUPP;
  313. /* The modesetting DDX has a totally broken idea of atomic. */
  314. if (current->comm[0] == 'X' && req->value == 1) {
  315. pr_info("broken atomic modeset userspace detected, disabling atomic\n");
  316. return -EOPNOTSUPP;
  317. }
  318. if (req->value > 2)
  319. return -EINVAL;
  320. file_priv->atomic = req->value;
  321. file_priv->universal_planes = req->value;
  322. /*
  323. * No atomic user-space blows up on aspect ratio mode bits.
  324. */
  325. file_priv->aspect_ratio_allowed = req->value;
  326. break;
  327. case DRM_CLIENT_CAP_ASPECT_RATIO:
  328. if (req->value > 1)
  329. return -EINVAL;
  330. file_priv->aspect_ratio_allowed = req->value;
  331. break;
  332. case DRM_CLIENT_CAP_WRITEBACK_CONNECTORS:
  333. if (!file_priv->atomic)
  334. return -EINVAL;
  335. if (req->value > 1)
  336. return -EINVAL;
  337. file_priv->writeback_connectors = req->value;
  338. break;
  339. default:
  340. return -EINVAL;
  341. }
  342. return 0;
  343. }
  344. /*
  345. * Setversion ioctl.
  346. *
  347. * \param inode device inode.
  348. * \param file_priv DRM file private.
  349. * \param cmd command.
  350. * \param arg user argument, pointing to a drm_lock structure.
  351. * \return zero on success or negative number on failure.
  352. *
  353. * Sets the requested interface version
  354. */
  355. static int drm_setversion(struct drm_device *dev, void *data, struct drm_file *file_priv)
  356. {
  357. struct drm_set_version *sv = data;
  358. int if_version, retcode = 0;
  359. mutex_lock(&dev->master_mutex);
  360. if (sv->drm_di_major != -1) {
  361. if (sv->drm_di_major != DRM_IF_MAJOR ||
  362. sv->drm_di_minor < 0 || sv->drm_di_minor > DRM_IF_MINOR) {
  363. retcode = -EINVAL;
  364. goto done;
  365. }
  366. if_version = DRM_IF_VERSION(sv->drm_di_major,
  367. sv->drm_di_minor);
  368. dev->if_version = max(if_version, dev->if_version);
  369. if (sv->drm_di_minor >= 1) {
  370. /*
  371. * Version 1.1 includes tying of DRM to specific device
  372. * Version 1.4 has proper PCI domain support
  373. */
  374. retcode = drm_set_busid(dev, file_priv);
  375. if (retcode)
  376. goto done;
  377. }
  378. }
  379. if (sv->drm_dd_major != -1) {
  380. if (sv->drm_dd_major != dev->driver->major ||
  381. sv->drm_dd_minor < 0 || sv->drm_dd_minor >
  382. dev->driver->minor) {
  383. retcode = -EINVAL;
  384. goto done;
  385. }
  386. }
  387. done:
  388. sv->drm_di_major = DRM_IF_MAJOR;
  389. sv->drm_di_minor = DRM_IF_MINOR;
  390. sv->drm_dd_major = dev->driver->major;
  391. sv->drm_dd_minor = dev->driver->minor;
  392. mutex_unlock(&dev->master_mutex);
  393. return retcode;
  394. }
  395. /**
  396. * drm_noop - DRM no-op ioctl implemntation
  397. * @dev: DRM device for the ioctl
  398. * @data: data pointer for the ioctl
  399. * @file_priv: DRM file for the ioctl call
  400. *
  401. * This no-op implementation for drm ioctls is useful for deprecated
  402. * functionality where we can't return a failure code because existing userspace
  403. * checks the result of the ioctl, but doesn't care about the action.
  404. *
  405. * Always returns successfully with 0.
  406. */
  407. int drm_noop(struct drm_device *dev, void *data,
  408. struct drm_file *file_priv)
  409. {
  410. DRM_DEBUG("\n");
  411. return 0;
  412. }
  413. EXPORT_SYMBOL(drm_noop);
  414. /**
  415. * drm_invalid_op - DRM invalid ioctl implemntation
  416. * @dev: DRM device for the ioctl
  417. * @data: data pointer for the ioctl
  418. * @file_priv: DRM file for the ioctl call
  419. *
  420. * This no-op implementation for drm ioctls is useful for deprecated
  421. * functionality where we really don't want to allow userspace to call the ioctl
  422. * any more. This is the case for old ums interfaces for drivers that
  423. * transitioned to kms gradually and so kept the old legacy tables around. This
  424. * only applies to radeon and i915 kms drivers, other drivers shouldn't need to
  425. * use this function.
  426. *
  427. * Always fails with a return value of -EINVAL.
  428. */
  429. int drm_invalid_op(struct drm_device *dev, void *data,
  430. struct drm_file *file_priv)
  431. {
  432. return -EINVAL;
  433. }
  434. EXPORT_SYMBOL(drm_invalid_op);
  435. /*
  436. * Copy and IOCTL return string to user space
  437. */
  438. static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
  439. {
  440. int len;
  441. /* don't overflow userbuf */
  442. len = strlen(value);
  443. if (len > *buf_len)
  444. len = *buf_len;
  445. /* let userspace know exact length of driver value (which could be
  446. * larger than the userspace-supplied buffer) */
  447. *buf_len = strlen(value);
  448. /* finally, try filling in the userbuf */
  449. if (len && buf)
  450. if (copy_to_user(buf, value, len))
  451. return -EFAULT;
  452. return 0;
  453. }
  454. /*
  455. * Get version information
  456. *
  457. * \param inode device inode.
  458. * \param filp file pointer.
  459. * \param cmd command.
  460. * \param arg user argument, pointing to a drm_version structure.
  461. * \return zero on success or negative number on failure.
  462. *
  463. * Fills in the version information in \p arg.
  464. */
  465. int drm_version(struct drm_device *dev, void *data,
  466. struct drm_file *file_priv)
  467. {
  468. struct drm_version *version = data;
  469. int err;
  470. version->version_major = dev->driver->major;
  471. version->version_minor = dev->driver->minor;
  472. version->version_patchlevel = dev->driver->patchlevel;
  473. err = drm_copy_field(version->name, &version->name_len,
  474. dev->driver->name);
  475. if (!err)
  476. err = drm_copy_field(version->date, &version->date_len,
  477. dev->driver->date);
  478. if (!err)
  479. err = drm_copy_field(version->desc, &version->desc_len,
  480. dev->driver->desc);
  481. return err;
  482. }
  483. /**
  484. * drm_ioctl_permit - Check ioctl permissions against caller
  485. *
  486. * @flags: ioctl permission flags.
  487. * @file_priv: Pointer to struct drm_file identifying the caller.
  488. *
  489. * Checks whether the caller is allowed to run an ioctl with the
  490. * indicated permissions.
  491. *
  492. * Returns:
  493. * Zero if allowed, -EACCES otherwise.
  494. */
  495. int drm_ioctl_permit(u32 flags, struct drm_file *file_priv)
  496. {
  497. /* ROOT_ONLY is only for CAP_SYS_ADMIN */
  498. if (unlikely((flags & DRM_ROOT_ONLY) && !capable(CAP_SYS_ADMIN)))
  499. return -EACCES;
  500. /* AUTH is only for authenticated or render client */
  501. if (unlikely((flags & DRM_AUTH) && !drm_is_render_client(file_priv) &&
  502. !file_priv->authenticated))
  503. return -EACCES;
  504. /* MASTER is only for master or control clients */
  505. if (unlikely((flags & DRM_MASTER) &&
  506. !drm_is_current_master(file_priv)))
  507. return -EACCES;
  508. /* Render clients must be explicitly allowed */
  509. if (unlikely(!(flags & DRM_RENDER_ALLOW) &&
  510. drm_is_render_client(file_priv)))
  511. return -EACCES;
  512. return 0;
  513. }
  514. EXPORT_SYMBOL(drm_ioctl_permit);
  515. #define DRM_IOCTL_DEF(ioctl, _func, _flags) \
  516. [DRM_IOCTL_NR(ioctl)] = { \
  517. .cmd = ioctl, \
  518. .func = _func, \
  519. .flags = _flags, \
  520. .name = #ioctl \
  521. }
  522. #if IS_ENABLED(CONFIG_DRM_LEGACY)
  523. #define DRM_LEGACY_IOCTL_DEF(ioctl, _func, _flags) DRM_IOCTL_DEF(ioctl, _func, _flags)
  524. #else
  525. #define DRM_LEGACY_IOCTL_DEF(ioctl, _func, _flags) DRM_IOCTL_DEF(ioctl, drm_invalid_op, _flags)
  526. #endif
  527. /* Ioctl table */
  528. static const struct drm_ioctl_desc drm_ioctls[] = {
  529. DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version, DRM_RENDER_ALLOW),
  530. DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, 0),
  531. DRM_IOCTL_DEF(DRM_IOCTL_GET_MAGIC, drm_getmagic, 0),
  532. DRM_IOCTL_DEF(DRM_IOCTL_IRQ_BUSID, drm_irq_by_busid, DRM_MASTER|DRM_ROOT_ONLY),
  533. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_GET_MAP, drm_legacy_getmap_ioctl, 0),
  534. DRM_IOCTL_DEF(DRM_IOCTL_GET_CLIENT, drm_getclient, 0),
  535. DRM_IOCTL_DEF(DRM_IOCTL_GET_STATS, drm_getstats, 0),
  536. DRM_IOCTL_DEF(DRM_IOCTL_GET_CAP, drm_getcap, DRM_RENDER_ALLOW),
  537. DRM_IOCTL_DEF(DRM_IOCTL_SET_CLIENT_CAP, drm_setclientcap, 0),
  538. DRM_IOCTL_DEF(DRM_IOCTL_SET_VERSION, drm_setversion, DRM_MASTER),
  539. DRM_IOCTL_DEF(DRM_IOCTL_SET_UNIQUE, drm_invalid_op, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  540. DRM_IOCTL_DEF(DRM_IOCTL_BLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  541. DRM_IOCTL_DEF(DRM_IOCTL_UNBLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  542. DRM_IOCTL_DEF(DRM_IOCTL_AUTH_MAGIC, drm_authmagic, DRM_MASTER),
  543. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_ADD_MAP, drm_legacy_addmap_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  544. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_RM_MAP, drm_legacy_rmmap_ioctl, DRM_AUTH),
  545. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX, drm_legacy_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  546. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_legacy_getsareactx, DRM_AUTH),
  547. DRM_IOCTL_DEF(DRM_IOCTL_SET_MASTER, drm_setmaster_ioctl, 0),
  548. DRM_IOCTL_DEF(DRM_IOCTL_DROP_MASTER, drm_dropmaster_ioctl, 0),
  549. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_ADD_CTX, drm_legacy_addctx, DRM_AUTH|DRM_ROOT_ONLY),
  550. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_RM_CTX, drm_legacy_rmctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  551. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_MOD_CTX, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  552. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_GET_CTX, drm_legacy_getctx, DRM_AUTH),
  553. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_SWITCH_CTX, drm_legacy_switchctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  554. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_NEW_CTX, drm_legacy_newctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  555. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_RES_CTX, drm_legacy_resctx, DRM_AUTH),
  556. DRM_IOCTL_DEF(DRM_IOCTL_ADD_DRAW, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  557. DRM_IOCTL_DEF(DRM_IOCTL_RM_DRAW, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  558. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_LOCK, drm_legacy_lock, DRM_AUTH),
  559. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_UNLOCK, drm_legacy_unlock, DRM_AUTH),
  560. DRM_IOCTL_DEF(DRM_IOCTL_FINISH, drm_noop, DRM_AUTH),
  561. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_ADD_BUFS, drm_legacy_addbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  562. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_MARK_BUFS, drm_legacy_markbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  563. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_INFO_BUFS, drm_legacy_infobufs, DRM_AUTH),
  564. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_MAP_BUFS, drm_legacy_mapbufs, DRM_AUTH),
  565. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_FREE_BUFS, drm_legacy_freebufs, DRM_AUTH),
  566. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_DMA, drm_legacy_dma_ioctl, DRM_AUTH),
  567. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_CONTROL, drm_legacy_irq_control, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  568. #if IS_ENABLED(CONFIG_AGP)
  569. DRM_IOCTL_DEF(DRM_IOCTL_AGP_ACQUIRE, drm_agp_acquire_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  570. DRM_IOCTL_DEF(DRM_IOCTL_AGP_RELEASE, drm_agp_release_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  571. DRM_IOCTL_DEF(DRM_IOCTL_AGP_ENABLE, drm_agp_enable_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  572. DRM_IOCTL_DEF(DRM_IOCTL_AGP_INFO, drm_agp_info_ioctl, DRM_AUTH),
  573. DRM_IOCTL_DEF(DRM_IOCTL_AGP_ALLOC, drm_agp_alloc_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  574. DRM_IOCTL_DEF(DRM_IOCTL_AGP_FREE, drm_agp_free_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  575. DRM_IOCTL_DEF(DRM_IOCTL_AGP_BIND, drm_agp_bind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  576. DRM_IOCTL_DEF(DRM_IOCTL_AGP_UNBIND, drm_agp_unbind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  577. #endif
  578. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_SG_ALLOC, drm_legacy_sg_alloc, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  579. DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_SG_FREE, drm_legacy_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  580. DRM_IOCTL_DEF(DRM_IOCTL_WAIT_VBLANK, drm_wait_vblank_ioctl, DRM_UNLOCKED),
  581. DRM_IOCTL_DEF(DRM_IOCTL_MODESET_CTL, drm_legacy_modeset_ctl_ioctl, 0),
  582. DRM_IOCTL_DEF(DRM_IOCTL_UPDATE_DRAW, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  583. DRM_IOCTL_DEF(DRM_IOCTL_GEM_CLOSE, drm_gem_close_ioctl, DRM_RENDER_ALLOW),
  584. DRM_IOCTL_DEF(DRM_IOCTL_GEM_FLINK, drm_gem_flink_ioctl, DRM_AUTH),
  585. DRM_IOCTL_DEF(DRM_IOCTL_GEM_OPEN, drm_gem_open_ioctl, DRM_AUTH),
  586. DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETRESOURCES, drm_mode_getresources, 0),
  587. DRM_IOCTL_DEF(DRM_IOCTL_PRIME_HANDLE_TO_FD, drm_prime_handle_to_fd_ioctl, DRM_RENDER_ALLOW),
  588. DRM_IOCTL_DEF(DRM_IOCTL_PRIME_FD_TO_HANDLE, drm_prime_fd_to_handle_ioctl, DRM_RENDER_ALLOW),
  589. DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPLANERESOURCES, drm_mode_getplane_res, 0),
  590. DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCRTC, drm_mode_getcrtc, 0),
  591. DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETCRTC, drm_mode_setcrtc, DRM_MASTER),
  592. DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPLANE, drm_mode_getplane, 0),
  593. DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPLANE, drm_mode_setplane, DRM_MASTER),
  594. DRM_IOCTL_DEF(DRM_IOCTL_MODE_CURSOR, drm_mode_cursor_ioctl, DRM_MASTER),
  595. DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETGAMMA, drm_mode_gamma_get_ioctl, 0),
  596. DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETGAMMA, drm_mode_gamma_set_ioctl, DRM_MASTER),
  597. DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETENCODER, drm_mode_getencoder, 0),
  598. DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCONNECTOR, drm_mode_getconnector, 0),
  599. DRM_IOCTL_DEF(DRM_IOCTL_MODE_ATTACHMODE, drm_noop, DRM_MASTER),
  600. DRM_IOCTL_DEF(DRM_IOCTL_MODE_DETACHMODE, drm_noop, DRM_MASTER),
  601. DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPERTY, drm_mode_getproperty_ioctl, 0),
  602. DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPROPERTY, drm_connector_property_set_ioctl, DRM_MASTER),
  603. DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPBLOB, drm_mode_getblob_ioctl, 0),
  604. DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, 0),
  605. DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB2, drm_mode_getfb2_ioctl, 0),
  606. DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb_ioctl, 0),
  607. DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB2, drm_mode_addfb2_ioctl, 0),
  608. DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb_ioctl, 0),
  609. DRM_IOCTL_DEF(DRM_IOCTL_MODE_PAGE_FLIP, drm_mode_page_flip_ioctl, DRM_MASTER),
  610. DRM_IOCTL_DEF(DRM_IOCTL_MODE_DIRTYFB, drm_mode_dirtyfb_ioctl, DRM_MASTER),
  611. DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_DUMB, drm_mode_create_dumb_ioctl, DRM_RENDER_ALLOW),
  612. DRM_IOCTL_DEF(DRM_IOCTL_MODE_MAP_DUMB, drm_mode_mmap_dumb_ioctl, DRM_RENDER_ALLOW),
  613. DRM_IOCTL_DEF(DRM_IOCTL_MODE_DESTROY_DUMB, drm_mode_destroy_dumb_ioctl, DRM_RENDER_ALLOW),
  614. DRM_IOCTL_DEF(DRM_IOCTL_MODE_OBJ_GETPROPERTIES, drm_mode_obj_get_properties_ioctl, 0),
  615. DRM_IOCTL_DEF(DRM_IOCTL_MODE_OBJ_SETPROPERTY, drm_mode_obj_set_property_ioctl, DRM_MASTER),
  616. DRM_IOCTL_DEF(DRM_IOCTL_MODE_CURSOR2, drm_mode_cursor2_ioctl, DRM_MASTER),
  617. DRM_IOCTL_DEF(DRM_IOCTL_MODE_ATOMIC, drm_mode_atomic_ioctl, DRM_MASTER),
  618. DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATEPROPBLOB, drm_mode_createblob_ioctl, 0),
  619. DRM_IOCTL_DEF(DRM_IOCTL_MODE_DESTROYPROPBLOB, drm_mode_destroyblob_ioctl, 0),
  620. DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_CREATE, drm_syncobj_create_ioctl,
  621. DRM_RENDER_ALLOW),
  622. DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_DESTROY, drm_syncobj_destroy_ioctl,
  623. DRM_RENDER_ALLOW),
  624. DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, drm_syncobj_handle_to_fd_ioctl,
  625. DRM_RENDER_ALLOW),
  626. DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, drm_syncobj_fd_to_handle_ioctl,
  627. DRM_RENDER_ALLOW),
  628. DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_TRANSFER, drm_syncobj_transfer_ioctl,
  629. DRM_RENDER_ALLOW),
  630. DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_WAIT, drm_syncobj_wait_ioctl,
  631. DRM_RENDER_ALLOW),
  632. DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT, drm_syncobj_timeline_wait_ioctl,
  633. DRM_RENDER_ALLOW),
  634. DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_RESET, drm_syncobj_reset_ioctl,
  635. DRM_RENDER_ALLOW),
  636. DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SIGNAL, drm_syncobj_signal_ioctl,
  637. DRM_RENDER_ALLOW),
  638. DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL, drm_syncobj_timeline_signal_ioctl,
  639. DRM_RENDER_ALLOW),
  640. DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_QUERY, drm_syncobj_query_ioctl,
  641. DRM_RENDER_ALLOW),
  642. DRM_IOCTL_DEF(DRM_IOCTL_CRTC_GET_SEQUENCE, drm_crtc_get_sequence_ioctl, 0),
  643. DRM_IOCTL_DEF(DRM_IOCTL_CRTC_QUEUE_SEQUENCE, drm_crtc_queue_sequence_ioctl, 0),
  644. DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_LEASE, drm_mode_create_lease_ioctl, DRM_MASTER),
  645. DRM_IOCTL_DEF(DRM_IOCTL_MODE_LIST_LESSEES, drm_mode_list_lessees_ioctl, DRM_MASTER),
  646. DRM_IOCTL_DEF(DRM_IOCTL_MODE_GET_LEASE, drm_mode_get_lease_ioctl, DRM_MASTER),
  647. DRM_IOCTL_DEF(DRM_IOCTL_MODE_REVOKE_LEASE, drm_mode_revoke_lease_ioctl, DRM_MASTER),
  648. };
  649. #define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
  650. /**
  651. * DOC: driver specific ioctls
  652. *
  653. * First things first, driver private IOCTLs should only be needed for drivers
  654. * supporting rendering. Kernel modesetting is all standardized, and extended
  655. * through properties. There are a few exceptions in some existing drivers,
  656. * which define IOCTL for use by the display DRM master, but they all predate
  657. * properties.
  658. *
  659. * Now if you do have a render driver you always have to support it through
  660. * driver private properties. There's a few steps needed to wire all the things
  661. * up.
  662. *
  663. * First you need to define the structure for your IOCTL in your driver private
  664. * UAPI header in ``include/uapi/drm/my_driver_drm.h``::
  665. *
  666. * struct my_driver_operation {
  667. * u32 some_thing;
  668. * u32 another_thing;
  669. * };
  670. *
  671. * Please make sure that you follow all the best practices from
  672. * ``Documentation/process/botching-up-ioctls.rst``. Note that drm_ioctl()
  673. * automatically zero-extends structures, hence make sure you can add more stuff
  674. * at the end, i.e. don't put a variable sized array there.
  675. *
  676. * Then you need to define your IOCTL number, using one of DRM_IO(), DRM_IOR(),
  677. * DRM_IOW() or DRM_IOWR(). It must start with the DRM_IOCTL\_ prefix::
  678. *
  679. * ##define DRM_IOCTL_MY_DRIVER_OPERATION \
  680. * DRM_IOW(DRM_COMMAND_BASE, struct my_driver_operation)
  681. *
  682. * DRM driver private IOCTL must be in the range from DRM_COMMAND_BASE to
  683. * DRM_COMMAND_END. Finally you need an array of &struct drm_ioctl_desc to wire
  684. * up the handlers and set the access rights::
  685. *
  686. * static const struct drm_ioctl_desc my_driver_ioctls[] = {
  687. * DRM_IOCTL_DEF_DRV(MY_DRIVER_OPERATION, my_driver_operation,
  688. * DRM_AUTH|DRM_RENDER_ALLOW),
  689. * };
  690. *
  691. * And then assign this to the &drm_driver.ioctls field in your driver
  692. * structure.
  693. *
  694. * See the separate chapter on :ref:`file operations<drm_driver_fops>` for how
  695. * the driver-specific IOCTLs are wired up.
  696. */
  697. long drm_ioctl_kernel(struct file *file, drm_ioctl_t *func, void *kdata,
  698. u32 flags)
  699. {
  700. struct drm_file *file_priv = file->private_data;
  701. struct drm_device *dev = file_priv->minor->dev;
  702. int retcode;
  703. if (drm_dev_is_unplugged(dev))
  704. return -ENODEV;
  705. retcode = drm_ioctl_permit(flags, file_priv);
  706. if (unlikely(retcode))
  707. return retcode;
  708. /* Enforce sane locking for modern driver ioctls. */
  709. if (likely(!drm_core_check_feature(dev, DRIVER_LEGACY)) ||
  710. (flags & DRM_UNLOCKED))
  711. retcode = func(dev, kdata, file_priv);
  712. else {
  713. mutex_lock(&drm_global_mutex);
  714. retcode = func(dev, kdata, file_priv);
  715. mutex_unlock(&drm_global_mutex);
  716. }
  717. return retcode;
  718. }
  719. EXPORT_SYMBOL(drm_ioctl_kernel);
  720. /**
  721. * drm_ioctl - ioctl callback implementation for DRM drivers
  722. * @filp: file this ioctl is called on
  723. * @cmd: ioctl cmd number
  724. * @arg: user argument
  725. *
  726. * Looks up the ioctl function in the DRM core and the driver dispatch table,
  727. * stored in &drm_driver.ioctls. It checks for necessary permission by calling
  728. * drm_ioctl_permit(), and dispatches to the respective function.
  729. *
  730. * Returns:
  731. * Zero on success, negative error code on failure.
  732. */
  733. long drm_ioctl(struct file *filp,
  734. unsigned int cmd, unsigned long arg)
  735. {
  736. struct drm_file *file_priv = filp->private_data;
  737. struct drm_device *dev;
  738. const struct drm_ioctl_desc *ioctl = NULL;
  739. drm_ioctl_t *func;
  740. unsigned int nr = DRM_IOCTL_NR(cmd);
  741. int retcode = -EINVAL;
  742. char stack_kdata[128];
  743. char *kdata = NULL;
  744. unsigned int in_size, out_size, drv_size, ksize;
  745. bool is_driver_ioctl;
  746. dev = file_priv->minor->dev;
  747. if (drm_dev_is_unplugged(dev))
  748. return -ENODEV;
  749. if (DRM_IOCTL_TYPE(cmd) != DRM_IOCTL_BASE)
  750. return -ENOTTY;
  751. is_driver_ioctl = nr >= DRM_COMMAND_BASE && nr < DRM_COMMAND_END;
  752. if (is_driver_ioctl) {
  753. /* driver ioctl */
  754. unsigned int index = nr - DRM_COMMAND_BASE;
  755. if (index >= dev->driver->num_ioctls)
  756. goto err_i1;
  757. index = array_index_nospec(index, dev->driver->num_ioctls);
  758. ioctl = &dev->driver->ioctls[index];
  759. } else {
  760. /* core ioctl */
  761. if (nr >= DRM_CORE_IOCTL_COUNT)
  762. goto err_i1;
  763. nr = array_index_nospec(nr, DRM_CORE_IOCTL_COUNT);
  764. ioctl = &drm_ioctls[nr];
  765. }
  766. drv_size = _IOC_SIZE(ioctl->cmd);
  767. out_size = in_size = _IOC_SIZE(cmd);
  768. if ((cmd & ioctl->cmd & IOC_IN) == 0)
  769. in_size = 0;
  770. if ((cmd & ioctl->cmd & IOC_OUT) == 0)
  771. out_size = 0;
  772. ksize = max(max(in_size, out_size), drv_size);
  773. DRM_DEBUG("comm=\"%s\" pid=%d, dev=0x%lx, auth=%d, %s\n",
  774. current->comm, task_pid_nr(current),
  775. (long)old_encode_dev(file_priv->minor->kdev->devt),
  776. file_priv->authenticated, ioctl->name);
  777. /* Do not trust userspace, use our own definition */
  778. func = ioctl->func;
  779. if (unlikely(!func)) {
  780. DRM_DEBUG("no function\n");
  781. retcode = -EINVAL;
  782. goto err_i1;
  783. }
  784. if (ksize <= sizeof(stack_kdata)) {
  785. kdata = stack_kdata;
  786. } else {
  787. kdata = kmalloc(ksize, GFP_KERNEL);
  788. if (!kdata) {
  789. retcode = -ENOMEM;
  790. goto err_i1;
  791. }
  792. }
  793. if (copy_from_user(kdata, (void __user *)arg, in_size) != 0) {
  794. retcode = -EFAULT;
  795. goto err_i1;
  796. }
  797. if (ksize > in_size)
  798. memset(kdata + in_size, 0, ksize - in_size);
  799. retcode = drm_ioctl_kernel(filp, func, kdata, ioctl->flags);
  800. if (copy_to_user((void __user *)arg, kdata, out_size) != 0)
  801. retcode = -EFAULT;
  802. err_i1:
  803. if (!ioctl)
  804. DRM_DEBUG("invalid ioctl: comm=\"%s\", pid=%d, dev=0x%lx, auth=%d, cmd=0x%02x, nr=0x%02x\n",
  805. current->comm, task_pid_nr(current),
  806. (long)old_encode_dev(file_priv->minor->kdev->devt),
  807. file_priv->authenticated, cmd, nr);
  808. if (kdata != stack_kdata)
  809. kfree(kdata);
  810. if (retcode)
  811. DRM_DEBUG("comm=\"%s\", pid=%d, ret=%d\n", current->comm,
  812. task_pid_nr(current), retcode);
  813. return retcode;
  814. }
  815. EXPORT_SYMBOL(drm_ioctl);
  816. /**
  817. * drm_ioctl_flags - Check for core ioctl and return ioctl permission flags
  818. * @nr: ioctl number
  819. * @flags: where to return the ioctl permission flags
  820. *
  821. * This ioctl is only used by the vmwgfx driver to augment the access checks
  822. * done by the drm core and insofar a pretty decent layering violation. This
  823. * shouldn't be used by any drivers.
  824. *
  825. * Returns:
  826. * True if the @nr corresponds to a DRM core ioctl number, false otherwise.
  827. */
  828. bool drm_ioctl_flags(unsigned int nr, unsigned int *flags)
  829. {
  830. if (nr >= DRM_COMMAND_BASE && nr < DRM_COMMAND_END)
  831. return false;
  832. if (nr >= DRM_CORE_IOCTL_COUNT)
  833. return false;
  834. nr = array_index_nospec(nr, DRM_CORE_IOCTL_COUNT);
  835. *flags = drm_ioctls[nr].flags;
  836. return true;
  837. }
  838. EXPORT_SYMBOL(drm_ioctl_flags);