drm_ioctl.c 31 KB

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