drm_fops.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /**
  2. * \file drm_fops.c
  3. * File operations for DRM
  4. *
  5. * \author Rickard E. (Rik) Faith <faith@valinux.com>
  6. * \author Daryll Strauss <daryll@valinux.com>
  7. * \author Gareth Hughes <gareth@valinux.com>
  8. */
  9. /*
  10. * Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
  11. *
  12. * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  13. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  14. * All Rights Reserved.
  15. *
  16. * Permission is hereby granted, free of charge, to any person obtaining a
  17. * copy of this software and associated documentation files (the "Software"),
  18. * to deal in the Software without restriction, including without limitation
  19. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  20. * and/or sell copies of the Software, and to permit persons to whom the
  21. * Software is furnished to do so, subject to the following conditions:
  22. *
  23. * The above copyright notice and this permission notice (including the next
  24. * paragraph) shall be included in all copies or substantial portions of the
  25. * Software.
  26. *
  27. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  28. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  29. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  30. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  31. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  32. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  33. * OTHER DEALINGS IN THE SOFTWARE.
  34. */
  35. #include "drmP.h"
  36. #include <linux/poll.h>
  37. #include <linux/slab.h>
  38. #include <linux/module.h>
  39. /* from BKL pushdown: note that nothing else serializes idr_find() */
  40. DEFINE_MUTEX(drm_global_mutex);
  41. EXPORT_SYMBOL(drm_global_mutex);
  42. static int drm_open_helper(struct inode *inode, struct file *filp,
  43. struct drm_device * dev);
  44. static int drm_setup(struct drm_device * dev)
  45. {
  46. int i;
  47. int ret;
  48. if (dev->driver->firstopen) {
  49. ret = dev->driver->firstopen(dev);
  50. if (ret != 0)
  51. return ret;
  52. }
  53. atomic_set(&dev->ioctl_count, 0);
  54. atomic_set(&dev->vma_count, 0);
  55. if (drm_core_check_feature(dev, DRIVER_HAVE_DMA) &&
  56. !drm_core_check_feature(dev, DRIVER_MODESET)) {
  57. dev->buf_use = 0;
  58. atomic_set(&dev->buf_alloc, 0);
  59. i = drm_dma_setup(dev);
  60. if (i < 0)
  61. return i;
  62. }
  63. for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
  64. atomic_set(&dev->counts[i], 0);
  65. dev->sigdata.lock = NULL;
  66. dev->queue_count = 0;
  67. dev->queue_reserved = 0;
  68. dev->queue_slots = 0;
  69. dev->queuelist = NULL;
  70. dev->context_flag = 0;
  71. dev->interrupt_flag = 0;
  72. dev->dma_flag = 0;
  73. dev->last_context = 0;
  74. dev->last_switch = 0;
  75. dev->last_checked = 0;
  76. init_waitqueue_head(&dev->context_wait);
  77. dev->if_version = 0;
  78. dev->ctx_start = 0;
  79. dev->lck_start = 0;
  80. dev->buf_async = NULL;
  81. init_waitqueue_head(&dev->buf_readers);
  82. init_waitqueue_head(&dev->buf_writers);
  83. DRM_DEBUG("\n");
  84. /*
  85. * The kernel's context could be created here, but is now created
  86. * in drm_dma_enqueue. This is more resource-efficient for
  87. * hardware that does not do DMA, but may mean that
  88. * drm_select_queue fails between the time the interrupt is
  89. * initialized and the time the queues are initialized.
  90. */
  91. return 0;
  92. }
  93. /**
  94. * Open file.
  95. *
  96. * \param inode device inode
  97. * \param filp file pointer.
  98. * \return zero on success or a negative number on failure.
  99. *
  100. * Searches the DRM device with the same minor number, calls open_helper(), and
  101. * increments the device open count. If the open count was previous at zero,
  102. * i.e., it's the first that the device is open, then calls setup().
  103. */
  104. int drm_open(struct inode *inode, struct file *filp)
  105. {
  106. struct drm_device *dev = NULL;
  107. int minor_id = iminor(inode);
  108. struct drm_minor *minor;
  109. int retcode = 0;
  110. minor = idr_find(&drm_minors_idr, minor_id);
  111. if (!minor)
  112. return -ENODEV;
  113. if (!(dev = minor->dev))
  114. return -ENODEV;
  115. if (drm_device_is_unplugged(dev))
  116. return -ENODEV;
  117. retcode = drm_open_helper(inode, filp, dev);
  118. if (!retcode) {
  119. atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
  120. if (!dev->open_count++) {
  121. retcode = drm_setup(dev);
  122. if (retcode)
  123. dev->open_count--;
  124. }
  125. }
  126. if (!retcode) {
  127. mutex_lock(&dev->struct_mutex);
  128. if (minor->type == DRM_MINOR_LEGACY) {
  129. if (dev->dev_mapping == NULL)
  130. dev->dev_mapping = inode->i_mapping;
  131. else if (dev->dev_mapping != inode->i_mapping)
  132. retcode = -ENODEV;
  133. }
  134. mutex_unlock(&dev->struct_mutex);
  135. }
  136. return retcode;
  137. }
  138. EXPORT_SYMBOL(drm_open);
  139. /**
  140. * File \c open operation.
  141. *
  142. * \param inode device inode.
  143. * \param filp file pointer.
  144. *
  145. * Puts the dev->fops corresponding to the device minor number into
  146. * \p filp, call the \c open method, and restore the file operations.
  147. */
  148. int drm_stub_open(struct inode *inode, struct file *filp)
  149. {
  150. struct drm_device *dev = NULL;
  151. struct drm_minor *minor;
  152. int minor_id = iminor(inode);
  153. int err = -ENODEV;
  154. const struct file_operations *old_fops;
  155. DRM_DEBUG("\n");
  156. mutex_lock(&drm_global_mutex);
  157. minor = idr_find(&drm_minors_idr, minor_id);
  158. if (!minor)
  159. goto out;
  160. if (!(dev = minor->dev))
  161. goto out;
  162. if (drm_device_is_unplugged(dev))
  163. goto out;
  164. old_fops = filp->f_op;
  165. filp->f_op = fops_get(dev->driver->fops);
  166. if (filp->f_op == NULL) {
  167. filp->f_op = old_fops;
  168. goto out;
  169. }
  170. if (filp->f_op->open && (err = filp->f_op->open(inode, filp))) {
  171. fops_put(filp->f_op);
  172. filp->f_op = fops_get(old_fops);
  173. }
  174. fops_put(old_fops);
  175. out:
  176. mutex_unlock(&drm_global_mutex);
  177. return err;
  178. }
  179. /**
  180. * Check whether DRI will run on this CPU.
  181. *
  182. * \return non-zero if the DRI will run on this CPU, or zero otherwise.
  183. */
  184. static int drm_cpu_valid(void)
  185. {
  186. #if defined(__i386__)
  187. if (boot_cpu_data.x86 == 3)
  188. return 0; /* No cmpxchg on a 386 */
  189. #endif
  190. #if defined(__sparc__) && !defined(__sparc_v9__)
  191. return 0; /* No cmpxchg before v9 sparc. */
  192. #endif
  193. return 1;
  194. }
  195. /**
  196. * Called whenever a process opens /dev/drm.
  197. *
  198. * \param inode device inode.
  199. * \param filp file pointer.
  200. * \param dev device.
  201. * \return zero on success or a negative number on failure.
  202. *
  203. * Creates and initializes a drm_file structure for the file private data in \p
  204. * filp and add it into the double linked list in \p dev.
  205. */
  206. static int drm_open_helper(struct inode *inode, struct file *filp,
  207. struct drm_device * dev)
  208. {
  209. int minor_id = iminor(inode);
  210. struct drm_file *priv;
  211. int ret;
  212. if (filp->f_flags & O_EXCL)
  213. return -EBUSY; /* No exclusive opens */
  214. if (!drm_cpu_valid())
  215. return -EINVAL;
  216. if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
  217. return -EINVAL;
  218. DRM_DEBUG("pid = %d, minor = %d\n", task_pid_nr(current), minor_id);
  219. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  220. if (!priv)
  221. return -ENOMEM;
  222. filp->private_data = priv;
  223. priv->filp = filp;
  224. priv->uid = current_euid();
  225. priv->pid = task_pid_nr(current);
  226. priv->minor = idr_find(&drm_minors_idr, minor_id);
  227. priv->ioctl_count = 0;
  228. /* for compatibility root is always authenticated */
  229. priv->authenticated = capable(CAP_SYS_ADMIN);
  230. priv->lock_count = 0;
  231. INIT_LIST_HEAD(&priv->lhead);
  232. INIT_LIST_HEAD(&priv->fbs);
  233. INIT_LIST_HEAD(&priv->event_list);
  234. init_waitqueue_head(&priv->event_wait);
  235. priv->event_space = 4096; /* set aside 4k for event buffer */
  236. if (dev->driver->driver_features & DRIVER_GEM)
  237. drm_gem_open(dev, priv);
  238. if (drm_core_check_feature(dev, DRIVER_PRIME))
  239. drm_prime_init_file_private(&priv->prime);
  240. if (dev->driver->open) {
  241. ret = dev->driver->open(dev, priv);
  242. if (ret < 0)
  243. goto out_free;
  244. }
  245. /* if there is no current master make this fd it */
  246. mutex_lock(&dev->struct_mutex);
  247. if (!priv->minor->master) {
  248. /* create a new master */
  249. priv->minor->master = drm_master_create(priv->minor);
  250. if (!priv->minor->master) {
  251. mutex_unlock(&dev->struct_mutex);
  252. ret = -ENOMEM;
  253. goto out_free;
  254. }
  255. priv->is_master = 1;
  256. /* take another reference for the copy in the local file priv */
  257. priv->master = drm_master_get(priv->minor->master);
  258. priv->authenticated = 1;
  259. mutex_unlock(&dev->struct_mutex);
  260. if (dev->driver->master_create) {
  261. ret = dev->driver->master_create(dev, priv->master);
  262. if (ret) {
  263. mutex_lock(&dev->struct_mutex);
  264. /* drop both references if this fails */
  265. drm_master_put(&priv->minor->master);
  266. drm_master_put(&priv->master);
  267. mutex_unlock(&dev->struct_mutex);
  268. goto out_free;
  269. }
  270. }
  271. mutex_lock(&dev->struct_mutex);
  272. if (dev->driver->master_set) {
  273. ret = dev->driver->master_set(dev, priv, true);
  274. if (ret) {
  275. /* drop both references if this fails */
  276. drm_master_put(&priv->minor->master);
  277. drm_master_put(&priv->master);
  278. mutex_unlock(&dev->struct_mutex);
  279. goto out_free;
  280. }
  281. }
  282. mutex_unlock(&dev->struct_mutex);
  283. } else {
  284. /* get a reference to the master */
  285. priv->master = drm_master_get(priv->minor->master);
  286. mutex_unlock(&dev->struct_mutex);
  287. }
  288. mutex_lock(&dev->struct_mutex);
  289. list_add(&priv->lhead, &dev->filelist);
  290. mutex_unlock(&dev->struct_mutex);
  291. #ifdef __alpha__
  292. /*
  293. * Default the hose
  294. */
  295. if (!dev->hose) {
  296. struct pci_dev *pci_dev;
  297. pci_dev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, NULL);
  298. if (pci_dev) {
  299. dev->hose = pci_dev->sysdata;
  300. pci_dev_put(pci_dev);
  301. }
  302. if (!dev->hose) {
  303. struct pci_bus *b = pci_bus_b(pci_root_buses.next);
  304. if (b)
  305. dev->hose = b->sysdata;
  306. }
  307. }
  308. #endif
  309. return 0;
  310. out_free:
  311. kfree(priv);
  312. filp->private_data = NULL;
  313. return ret;
  314. }
  315. /** No-op. */
  316. int drm_fasync(int fd, struct file *filp, int on)
  317. {
  318. struct drm_file *priv = filp->private_data;
  319. struct drm_device *dev = priv->minor->dev;
  320. DRM_DEBUG("fd = %d, device = 0x%lx\n", fd,
  321. (long)old_encode_dev(priv->minor->device));
  322. return fasync_helper(fd, filp, on, &dev->buf_async);
  323. }
  324. EXPORT_SYMBOL(drm_fasync);
  325. /*
  326. * Reclaim locked buffers; note that this may be a bad idea if the current
  327. * context doesn't have the hw lock...
  328. */
  329. static void drm_reclaim_locked_buffers(struct drm_device *dev, struct file *f)
  330. {
  331. struct drm_file *file_priv = f->private_data;
  332. if (drm_i_have_hw_lock(dev, file_priv)) {
  333. dev->driver->reclaim_buffers_locked(dev, file_priv);
  334. } else {
  335. unsigned long _end = jiffies + 3 * DRM_HZ;
  336. int locked = 0;
  337. drm_idlelock_take(&file_priv->master->lock);
  338. /*
  339. * Wait for a while.
  340. */
  341. do {
  342. spin_lock_bh(&file_priv->master->lock.spinlock);
  343. locked = file_priv->master->lock.idle_has_lock;
  344. spin_unlock_bh(&file_priv->master->lock.spinlock);
  345. if (locked)
  346. break;
  347. schedule();
  348. } while (!time_after_eq(jiffies, _end));
  349. if (!locked) {
  350. DRM_ERROR("reclaim_buffers_locked() deadlock. Please rework this\n"
  351. "\tdriver to use reclaim_buffers_idlelocked() instead.\n"
  352. "\tI will go on reclaiming the buffers anyway.\n");
  353. }
  354. dev->driver->reclaim_buffers_locked(dev, file_priv);
  355. drm_idlelock_release(&file_priv->master->lock);
  356. }
  357. }
  358. static void drm_master_release(struct drm_device *dev, struct file *filp)
  359. {
  360. struct drm_file *file_priv = filp->private_data;
  361. if (dev->driver->reclaim_buffers_locked &&
  362. file_priv->master->lock.hw_lock)
  363. drm_reclaim_locked_buffers(dev, filp);
  364. if (dev->driver->reclaim_buffers_idlelocked &&
  365. file_priv->master->lock.hw_lock) {
  366. drm_idlelock_take(&file_priv->master->lock);
  367. dev->driver->reclaim_buffers_idlelocked(dev, file_priv);
  368. drm_idlelock_release(&file_priv->master->lock);
  369. }
  370. if (drm_i_have_hw_lock(dev, file_priv)) {
  371. DRM_DEBUG("File %p released, freeing lock for context %d\n",
  372. filp, _DRM_LOCKING_CONTEXT(file_priv->master->lock.hw_lock->lock));
  373. drm_lock_free(&file_priv->master->lock,
  374. _DRM_LOCKING_CONTEXT(file_priv->master->lock.hw_lock->lock));
  375. }
  376. if (drm_core_check_feature(dev, DRIVER_HAVE_DMA) &&
  377. !dev->driver->reclaim_buffers_locked) {
  378. dev->driver->reclaim_buffers(dev, file_priv);
  379. }
  380. }
  381. static void drm_events_release(struct drm_file *file_priv)
  382. {
  383. struct drm_device *dev = file_priv->minor->dev;
  384. struct drm_pending_event *e, *et;
  385. struct drm_pending_vblank_event *v, *vt;
  386. unsigned long flags;
  387. spin_lock_irqsave(&dev->event_lock, flags);
  388. /* Remove pending flips */
  389. list_for_each_entry_safe(v, vt, &dev->vblank_event_list, base.link)
  390. if (v->base.file_priv == file_priv) {
  391. list_del(&v->base.link);
  392. drm_vblank_put(dev, v->pipe);
  393. v->base.destroy(&v->base);
  394. }
  395. /* Remove unconsumed events */
  396. list_for_each_entry_safe(e, et, &file_priv->event_list, link)
  397. e->destroy(e);
  398. spin_unlock_irqrestore(&dev->event_lock, flags);
  399. }
  400. /**
  401. * Release file.
  402. *
  403. * \param inode device inode
  404. * \param file_priv DRM file private.
  405. * \return zero on success or a negative number on failure.
  406. *
  407. * If the hardware lock is held then free it, and take it again for the kernel
  408. * context since it's necessary to reclaim buffers. Unlink the file private
  409. * data from its list and free it. Decreases the open count and if it reaches
  410. * zero calls drm_lastclose().
  411. */
  412. int drm_release(struct inode *inode, struct file *filp)
  413. {
  414. struct drm_file *file_priv = filp->private_data;
  415. struct drm_device *dev = file_priv->minor->dev;
  416. int retcode = 0;
  417. mutex_lock(&drm_global_mutex);
  418. DRM_DEBUG("open_count = %d\n", dev->open_count);
  419. if (dev->driver->preclose)
  420. dev->driver->preclose(dev, file_priv);
  421. /* ========================================================
  422. * Begin inline drm_release
  423. */
  424. DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
  425. task_pid_nr(current),
  426. (long)old_encode_dev(file_priv->minor->device),
  427. dev->open_count);
  428. /* Release any auth tokens that might point to this file_priv,
  429. (do that under the drm_global_mutex) */
  430. if (file_priv->magic)
  431. (void) drm_remove_magic(file_priv->master, file_priv->magic);
  432. /* if the master has gone away we can't do anything with the lock */
  433. if (file_priv->minor->master)
  434. drm_master_release(dev, filp);
  435. drm_events_release(file_priv);
  436. if (dev->driver->driver_features & DRIVER_MODESET)
  437. drm_fb_release(file_priv);
  438. if (dev->driver->driver_features & DRIVER_GEM)
  439. drm_gem_release(dev, file_priv);
  440. mutex_lock(&dev->ctxlist_mutex);
  441. if (!list_empty(&dev->ctxlist)) {
  442. struct drm_ctx_list *pos, *n;
  443. list_for_each_entry_safe(pos, n, &dev->ctxlist, head) {
  444. if (pos->tag == file_priv &&
  445. pos->handle != DRM_KERNEL_CONTEXT) {
  446. if (dev->driver->context_dtor)
  447. dev->driver->context_dtor(dev,
  448. pos->handle);
  449. drm_ctxbitmap_free(dev, pos->handle);
  450. list_del(&pos->head);
  451. kfree(pos);
  452. --dev->ctx_count;
  453. }
  454. }
  455. }
  456. mutex_unlock(&dev->ctxlist_mutex);
  457. mutex_lock(&dev->struct_mutex);
  458. if (file_priv->is_master) {
  459. struct drm_master *master = file_priv->master;
  460. struct drm_file *temp;
  461. list_for_each_entry(temp, &dev->filelist, lhead) {
  462. if ((temp->master == file_priv->master) &&
  463. (temp != file_priv))
  464. temp->authenticated = 0;
  465. }
  466. /**
  467. * Since the master is disappearing, so is the
  468. * possibility to lock.
  469. */
  470. if (master->lock.hw_lock) {
  471. if (dev->sigdata.lock == master->lock.hw_lock)
  472. dev->sigdata.lock = NULL;
  473. master->lock.hw_lock = NULL;
  474. master->lock.file_priv = NULL;
  475. wake_up_interruptible_all(&master->lock.lock_queue);
  476. }
  477. if (file_priv->minor->master == file_priv->master) {
  478. /* drop the reference held my the minor */
  479. if (dev->driver->master_drop)
  480. dev->driver->master_drop(dev, file_priv, true);
  481. drm_master_put(&file_priv->minor->master);
  482. }
  483. }
  484. /* drop the reference held my the file priv */
  485. drm_master_put(&file_priv->master);
  486. file_priv->is_master = 0;
  487. list_del(&file_priv->lhead);
  488. mutex_unlock(&dev->struct_mutex);
  489. if (dev->driver->postclose)
  490. dev->driver->postclose(dev, file_priv);
  491. if (drm_core_check_feature(dev, DRIVER_PRIME))
  492. drm_prime_destroy_file_private(&file_priv->prime);
  493. kfree(file_priv);
  494. /* ========================================================
  495. * End inline drm_release
  496. */
  497. atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
  498. if (!--dev->open_count) {
  499. if (atomic_read(&dev->ioctl_count)) {
  500. DRM_ERROR("Device busy: %d\n",
  501. atomic_read(&dev->ioctl_count));
  502. retcode = -EBUSY;
  503. } else
  504. retcode = drm_lastclose(dev);
  505. if (drm_device_is_unplugged(dev))
  506. drm_put_dev(dev);
  507. }
  508. mutex_unlock(&drm_global_mutex);
  509. return retcode;
  510. }
  511. EXPORT_SYMBOL(drm_release);
  512. static bool
  513. drm_dequeue_event(struct drm_file *file_priv,
  514. size_t total, size_t max, struct drm_pending_event **out)
  515. {
  516. struct drm_device *dev = file_priv->minor->dev;
  517. struct drm_pending_event *e;
  518. unsigned long flags;
  519. bool ret = false;
  520. spin_lock_irqsave(&dev->event_lock, flags);
  521. *out = NULL;
  522. if (list_empty(&file_priv->event_list))
  523. goto out;
  524. e = list_first_entry(&file_priv->event_list,
  525. struct drm_pending_event, link);
  526. if (e->event->length + total > max)
  527. goto out;
  528. file_priv->event_space += e->event->length;
  529. list_del(&e->link);
  530. *out = e;
  531. ret = true;
  532. out:
  533. spin_unlock_irqrestore(&dev->event_lock, flags);
  534. return ret;
  535. }
  536. ssize_t drm_read(struct file *filp, char __user *buffer,
  537. size_t count, loff_t *offset)
  538. {
  539. struct drm_file *file_priv = filp->private_data;
  540. struct drm_pending_event *e;
  541. size_t total;
  542. ssize_t ret;
  543. ret = wait_event_interruptible(file_priv->event_wait,
  544. !list_empty(&file_priv->event_list));
  545. if (ret < 0)
  546. return ret;
  547. total = 0;
  548. while (drm_dequeue_event(file_priv, total, count, &e)) {
  549. if (copy_to_user(buffer + total,
  550. e->event, e->event->length)) {
  551. total = -EFAULT;
  552. break;
  553. }
  554. total += e->event->length;
  555. e->destroy(e);
  556. }
  557. return total;
  558. }
  559. EXPORT_SYMBOL(drm_read);
  560. unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait)
  561. {
  562. struct drm_file *file_priv = filp->private_data;
  563. unsigned int mask = 0;
  564. poll_wait(filp, &file_priv->event_wait, wait);
  565. if (!list_empty(&file_priv->event_list))
  566. mask |= POLLIN | POLLRDNORM;
  567. return mask;
  568. }
  569. EXPORT_SYMBOL(drm_poll);