drm_irq.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /**
  2. * \file drm_irq.c
  3. * IRQ support
  4. *
  5. * \author Rickard E. (Rik) Faith <faith@valinux.com>
  6. * \author Gareth Hughes <gareth@valinux.com>
  7. */
  8. /*
  9. * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
  10. *
  11. * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
  12. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  13. * All Rights Reserved.
  14. *
  15. * Permission is hereby granted, free of charge, to any person obtaining a
  16. * copy of this software and associated documentation files (the "Software"),
  17. * to deal in the Software without restriction, including without limitation
  18. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  19. * and/or sell copies of the Software, and to permit persons to whom the
  20. * Software is furnished to do so, subject to the following conditions:
  21. *
  22. * The above copyright notice and this permission notice (including the next
  23. * paragraph) shall be included in all copies or substantial portions of the
  24. * Software.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  27. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  28. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  29. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  30. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  31. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  32. * OTHER DEALINGS IN THE SOFTWARE.
  33. */
  34. #include "drmP.h"
  35. #include <linux/interrupt.h> /* For task queue support */
  36. /**
  37. * Get interrupt from bus id.
  38. *
  39. * \param inode device inode.
  40. * \param file_priv DRM file private.
  41. * \param cmd command.
  42. * \param arg user argument, pointing to a drm_irq_busid structure.
  43. * \return zero on success or a negative number on failure.
  44. *
  45. * Finds the PCI device with the specified bus id and gets its IRQ number.
  46. * This IOCTL is deprecated, and will now return EINVAL for any busid not equal
  47. * to that of the device that this DRM instance attached to.
  48. */
  49. int drm_irq_by_busid(struct drm_device *dev, void *data,
  50. struct drm_file *file_priv)
  51. {
  52. struct drm_irq_busid *p = data;
  53. if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
  54. return -EINVAL;
  55. if ((p->busnum >> 8) != drm_get_pci_domain(dev) ||
  56. (p->busnum & 0xff) != dev->pdev->bus->number ||
  57. p->devnum != PCI_SLOT(dev->pdev->devfn) || p->funcnum != PCI_FUNC(dev->pdev->devfn))
  58. return -EINVAL;
  59. p->irq = dev->pdev->irq;
  60. DRM_DEBUG("%d:%d:%d => IRQ %d\n", p->busnum, p->devnum, p->funcnum,
  61. p->irq);
  62. return 0;
  63. }
  64. static void vblank_disable_fn(unsigned long arg)
  65. {
  66. struct drm_device *dev = (struct drm_device *)arg;
  67. unsigned long irqflags;
  68. int i;
  69. if (!dev->vblank_disable_allowed)
  70. return;
  71. for (i = 0; i < dev->num_crtcs; i++) {
  72. spin_lock_irqsave(&dev->vbl_lock, irqflags);
  73. if (atomic_read(&dev->vblank_refcount[i]) == 0 &&
  74. dev->vblank_enabled[i]) {
  75. DRM_DEBUG("disabling vblank on crtc %d\n", i);
  76. dev->last_vblank[i] =
  77. dev->driver->get_vblank_counter(dev, i);
  78. dev->driver->disable_vblank(dev, i);
  79. dev->vblank_enabled[i] = 0;
  80. }
  81. spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
  82. }
  83. }
  84. void drm_vblank_cleanup(struct drm_device *dev)
  85. {
  86. /* Bail if the driver didn't call drm_vblank_init() */
  87. if (dev->num_crtcs == 0)
  88. return;
  89. del_timer(&dev->vblank_disable_timer);
  90. vblank_disable_fn((unsigned long)dev);
  91. drm_free(dev->vbl_queue, sizeof(*dev->vbl_queue) * dev->num_crtcs,
  92. DRM_MEM_DRIVER);
  93. drm_free(dev->_vblank_count, sizeof(*dev->_vblank_count) *
  94. dev->num_crtcs, DRM_MEM_DRIVER);
  95. drm_free(dev->vblank_refcount, sizeof(*dev->vblank_refcount) *
  96. dev->num_crtcs, DRM_MEM_DRIVER);
  97. drm_free(dev->vblank_enabled, sizeof(*dev->vblank_enabled) *
  98. dev->num_crtcs, DRM_MEM_DRIVER);
  99. drm_free(dev->last_vblank, sizeof(*dev->last_vblank) * dev->num_crtcs,
  100. DRM_MEM_DRIVER);
  101. drm_free(dev->last_vblank_wait,
  102. sizeof(*dev->last_vblank_wait) * dev->num_crtcs,
  103. DRM_MEM_DRIVER);
  104. drm_free(dev->vblank_inmodeset, sizeof(*dev->vblank_inmodeset) *
  105. dev->num_crtcs, DRM_MEM_DRIVER);
  106. dev->num_crtcs = 0;
  107. }
  108. int drm_vblank_init(struct drm_device *dev, int num_crtcs)
  109. {
  110. int i, ret = -ENOMEM;
  111. setup_timer(&dev->vblank_disable_timer, vblank_disable_fn,
  112. (unsigned long)dev);
  113. spin_lock_init(&dev->vbl_lock);
  114. dev->num_crtcs = num_crtcs;
  115. dev->vbl_queue = drm_alloc(sizeof(wait_queue_head_t) * num_crtcs,
  116. DRM_MEM_DRIVER);
  117. if (!dev->vbl_queue)
  118. goto err;
  119. dev->_vblank_count = drm_alloc(sizeof(atomic_t) * num_crtcs,
  120. DRM_MEM_DRIVER);
  121. if (!dev->_vblank_count)
  122. goto err;
  123. dev->vblank_refcount = drm_alloc(sizeof(atomic_t) * num_crtcs,
  124. DRM_MEM_DRIVER);
  125. if (!dev->vblank_refcount)
  126. goto err;
  127. dev->vblank_enabled = drm_calloc(num_crtcs, sizeof(int),
  128. DRM_MEM_DRIVER);
  129. if (!dev->vblank_enabled)
  130. goto err;
  131. dev->last_vblank = drm_calloc(num_crtcs, sizeof(u32), DRM_MEM_DRIVER);
  132. if (!dev->last_vblank)
  133. goto err;
  134. dev->last_vblank_wait = drm_calloc(num_crtcs, sizeof(u32),
  135. DRM_MEM_DRIVER);
  136. if (!dev->last_vblank_wait)
  137. goto err;
  138. dev->vblank_inmodeset = drm_calloc(num_crtcs, sizeof(int),
  139. DRM_MEM_DRIVER);
  140. if (!dev->vblank_inmodeset)
  141. goto err;
  142. /* Zero per-crtc vblank stuff */
  143. for (i = 0; i < num_crtcs; i++) {
  144. init_waitqueue_head(&dev->vbl_queue[i]);
  145. atomic_set(&dev->_vblank_count[i], 0);
  146. atomic_set(&dev->vblank_refcount[i], 0);
  147. }
  148. dev->vblank_disable_allowed = 0;
  149. return 0;
  150. err:
  151. drm_vblank_cleanup(dev);
  152. return ret;
  153. }
  154. EXPORT_SYMBOL(drm_vblank_init);
  155. /**
  156. * Install IRQ handler.
  157. *
  158. * \param dev DRM device.
  159. *
  160. * Initializes the IRQ related data. Installs the handler, calling the driver
  161. * \c drm_driver_irq_preinstall() and \c drm_driver_irq_postinstall() functions
  162. * before and after the installation.
  163. */
  164. int drm_irq_install(struct drm_device *dev)
  165. {
  166. int ret = 0;
  167. unsigned long sh_flags = 0;
  168. char *irqname;
  169. if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
  170. return -EINVAL;
  171. if (dev->pdev->irq == 0)
  172. return -EINVAL;
  173. mutex_lock(&dev->struct_mutex);
  174. /* Driver must have been initialized */
  175. if (!dev->dev_private) {
  176. mutex_unlock(&dev->struct_mutex);
  177. return -EINVAL;
  178. }
  179. if (dev->irq_enabled) {
  180. mutex_unlock(&dev->struct_mutex);
  181. return -EBUSY;
  182. }
  183. dev->irq_enabled = 1;
  184. mutex_unlock(&dev->struct_mutex);
  185. DRM_DEBUG("irq=%d\n", dev->pdev->irq);
  186. /* Before installing handler */
  187. dev->driver->irq_preinstall(dev);
  188. /* Install handler */
  189. if (drm_core_check_feature(dev, DRIVER_IRQ_SHARED))
  190. sh_flags = IRQF_SHARED;
  191. if (dev->devname)
  192. irqname = dev->devname;
  193. else
  194. irqname = dev->driver->name;
  195. ret = request_irq(drm_dev_to_irq(dev), dev->driver->irq_handler,
  196. sh_flags, irqname, dev);
  197. if (ret < 0) {
  198. mutex_lock(&dev->struct_mutex);
  199. dev->irq_enabled = 0;
  200. mutex_unlock(&dev->struct_mutex);
  201. return ret;
  202. }
  203. /* After installing handler */
  204. ret = dev->driver->irq_postinstall(dev);
  205. if (ret < 0) {
  206. mutex_lock(&dev->struct_mutex);
  207. dev->irq_enabled = 0;
  208. mutex_unlock(&dev->struct_mutex);
  209. }
  210. return ret;
  211. }
  212. EXPORT_SYMBOL(drm_irq_install);
  213. /**
  214. * Uninstall the IRQ handler.
  215. *
  216. * \param dev DRM device.
  217. *
  218. * Calls the driver's \c drm_driver_irq_uninstall() function, and stops the irq.
  219. */
  220. int drm_irq_uninstall(struct drm_device * dev)
  221. {
  222. unsigned long irqflags;
  223. int irq_enabled, i;
  224. if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
  225. return -EINVAL;
  226. mutex_lock(&dev->struct_mutex);
  227. irq_enabled = dev->irq_enabled;
  228. dev->irq_enabled = 0;
  229. mutex_unlock(&dev->struct_mutex);
  230. /*
  231. * Wake up any waiters so they don't hang.
  232. */
  233. spin_lock_irqsave(&dev->vbl_lock, irqflags);
  234. for (i = 0; i < dev->num_crtcs; i++) {
  235. DRM_WAKEUP(&dev->vbl_queue[i]);
  236. dev->vblank_enabled[i] = 0;
  237. dev->last_vblank[i] = dev->driver->get_vblank_counter(dev, i);
  238. }
  239. spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
  240. if (!irq_enabled)
  241. return -EINVAL;
  242. DRM_DEBUG("irq=%d\n", dev->pdev->irq);
  243. dev->driver->irq_uninstall(dev);
  244. free_irq(dev->pdev->irq, dev);
  245. return 0;
  246. }
  247. EXPORT_SYMBOL(drm_irq_uninstall);
  248. /**
  249. * IRQ control ioctl.
  250. *
  251. * \param inode device inode.
  252. * \param file_priv DRM file private.
  253. * \param cmd command.
  254. * \param arg user argument, pointing to a drm_control structure.
  255. * \return zero on success or a negative number on failure.
  256. *
  257. * Calls irq_install() or irq_uninstall() according to \p arg.
  258. */
  259. int drm_control(struct drm_device *dev, void *data,
  260. struct drm_file *file_priv)
  261. {
  262. struct drm_control *ctl = data;
  263. /* if we haven't irq we fallback for compatibility reasons - this used to be a separate function in drm_dma.h */
  264. switch (ctl->func) {
  265. case DRM_INST_HANDLER:
  266. if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
  267. return 0;
  268. if (drm_core_check_feature(dev, DRIVER_MODESET))
  269. return 0;
  270. if (dev->if_version < DRM_IF_VERSION(1, 2) &&
  271. ctl->irq != dev->pdev->irq)
  272. return -EINVAL;
  273. return drm_irq_install(dev);
  274. case DRM_UNINST_HANDLER:
  275. if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
  276. return 0;
  277. if (drm_core_check_feature(dev, DRIVER_MODESET))
  278. return 0;
  279. return drm_irq_uninstall(dev);
  280. default:
  281. return -EINVAL;
  282. }
  283. }
  284. /**
  285. * drm_vblank_count - retrieve "cooked" vblank counter value
  286. * @dev: DRM device
  287. * @crtc: which counter to retrieve
  288. *
  289. * Fetches the "cooked" vblank count value that represents the number of
  290. * vblank events since the system was booted, including lost events due to
  291. * modesetting activity.
  292. */
  293. u32 drm_vblank_count(struct drm_device *dev, int crtc)
  294. {
  295. return atomic_read(&dev->_vblank_count[crtc]);
  296. }
  297. EXPORT_SYMBOL(drm_vblank_count);
  298. /**
  299. * drm_update_vblank_count - update the master vblank counter
  300. * @dev: DRM device
  301. * @crtc: counter to update
  302. *
  303. * Call back into the driver to update the appropriate vblank counter
  304. * (specified by @crtc). Deal with wraparound, if it occurred, and
  305. * update the last read value so we can deal with wraparound on the next
  306. * call if necessary.
  307. *
  308. * Only necessary when going from off->on, to account for frames we
  309. * didn't get an interrupt for.
  310. *
  311. * Note: caller must hold dev->vbl_lock since this reads & writes
  312. * device vblank fields.
  313. */
  314. static void drm_update_vblank_count(struct drm_device *dev, int crtc)
  315. {
  316. u32 cur_vblank, diff;
  317. /*
  318. * Interrupts were disabled prior to this call, so deal with counter
  319. * wrap if needed.
  320. * NOTE! It's possible we lost a full dev->max_vblank_count events
  321. * here if the register is small or we had vblank interrupts off for
  322. * a long time.
  323. */
  324. cur_vblank = dev->driver->get_vblank_counter(dev, crtc);
  325. diff = cur_vblank - dev->last_vblank[crtc];
  326. if (cur_vblank < dev->last_vblank[crtc]) {
  327. diff += dev->max_vblank_count;
  328. DRM_DEBUG("last_vblank[%d]=0x%x, cur_vblank=0x%x => diff=0x%x\n",
  329. crtc, dev->last_vblank[crtc], cur_vblank, diff);
  330. }
  331. DRM_DEBUG("enabling vblank interrupts on crtc %d, missed %d\n",
  332. crtc, diff);
  333. atomic_add(diff, &dev->_vblank_count[crtc]);
  334. }
  335. /**
  336. * drm_vblank_get - get a reference count on vblank events
  337. * @dev: DRM device
  338. * @crtc: which CRTC to own
  339. *
  340. * Acquire a reference count on vblank events to avoid having them disabled
  341. * while in use.
  342. *
  343. * RETURNS
  344. * Zero on success, nonzero on failure.
  345. */
  346. int drm_vblank_get(struct drm_device *dev, int crtc)
  347. {
  348. unsigned long irqflags;
  349. int ret = 0;
  350. spin_lock_irqsave(&dev->vbl_lock, irqflags);
  351. /* Going from 0->1 means we have to enable interrupts again */
  352. if (atomic_add_return(1, &dev->vblank_refcount[crtc]) == 1 &&
  353. !dev->vblank_enabled[crtc]) {
  354. ret = dev->driver->enable_vblank(dev, crtc);
  355. DRM_DEBUG("enabling vblank on crtc %d, ret: %d\n", crtc, ret);
  356. if (ret)
  357. atomic_dec(&dev->vblank_refcount[crtc]);
  358. else {
  359. dev->vblank_enabled[crtc] = 1;
  360. drm_update_vblank_count(dev, crtc);
  361. }
  362. }
  363. spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
  364. return ret;
  365. }
  366. EXPORT_SYMBOL(drm_vblank_get);
  367. /**
  368. * drm_vblank_put - give up ownership of vblank events
  369. * @dev: DRM device
  370. * @crtc: which counter to give up
  371. *
  372. * Release ownership of a given vblank counter, turning off interrupts
  373. * if possible.
  374. */
  375. void drm_vblank_put(struct drm_device *dev, int crtc)
  376. {
  377. BUG_ON (atomic_read (&dev->vblank_refcount[crtc]) == 0);
  378. /* Last user schedules interrupt disable */
  379. if (atomic_dec_and_test(&dev->vblank_refcount[crtc]))
  380. mod_timer(&dev->vblank_disable_timer, jiffies + 5*DRM_HZ);
  381. }
  382. EXPORT_SYMBOL(drm_vblank_put);
  383. /**
  384. * drm_vblank_pre_modeset - account for vblanks across mode sets
  385. * @dev: DRM device
  386. * @crtc: CRTC in question
  387. * @post: post or pre mode set?
  388. *
  389. * Account for vblank events across mode setting events, which will likely
  390. * reset the hardware frame counter.
  391. */
  392. void drm_vblank_pre_modeset(struct drm_device *dev, int crtc)
  393. {
  394. /*
  395. * To avoid all the problems that might happen if interrupts
  396. * were enabled/disabled around or between these calls, we just
  397. * have the kernel take a reference on the CRTC (just once though
  398. * to avoid corrupting the count if multiple, mismatch calls occur),
  399. * so that interrupts remain enabled in the interim.
  400. */
  401. if (!dev->vblank_inmodeset[crtc]) {
  402. dev->vblank_inmodeset[crtc] = 0x1;
  403. if (drm_vblank_get(dev, crtc) == 0)
  404. dev->vblank_inmodeset[crtc] |= 0x2;
  405. }
  406. }
  407. EXPORT_SYMBOL(drm_vblank_pre_modeset);
  408. void drm_vblank_post_modeset(struct drm_device *dev, int crtc)
  409. {
  410. unsigned long irqflags;
  411. if (dev->vblank_inmodeset[crtc]) {
  412. spin_lock_irqsave(&dev->vbl_lock, irqflags);
  413. dev->vblank_disable_allowed = 1;
  414. spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
  415. if (dev->vblank_inmodeset[crtc] & 0x2)
  416. drm_vblank_put(dev, crtc);
  417. dev->vblank_inmodeset[crtc] = 0;
  418. }
  419. }
  420. EXPORT_SYMBOL(drm_vblank_post_modeset);
  421. /**
  422. * drm_modeset_ctl - handle vblank event counter changes across mode switch
  423. * @DRM_IOCTL_ARGS: standard ioctl arguments
  424. *
  425. * Applications should call the %_DRM_PRE_MODESET and %_DRM_POST_MODESET
  426. * ioctls around modesetting so that any lost vblank events are accounted for.
  427. *
  428. * Generally the counter will reset across mode sets. If interrupts are
  429. * enabled around this call, we don't have to do anything since the counter
  430. * will have already been incremented.
  431. */
  432. int drm_modeset_ctl(struct drm_device *dev, void *data,
  433. struct drm_file *file_priv)
  434. {
  435. struct drm_modeset_ctl *modeset = data;
  436. int crtc, ret = 0;
  437. /* If drm_vblank_init() hasn't been called yet, just no-op */
  438. if (!dev->num_crtcs)
  439. goto out;
  440. crtc = modeset->crtc;
  441. if (crtc >= dev->num_crtcs) {
  442. ret = -EINVAL;
  443. goto out;
  444. }
  445. switch (modeset->cmd) {
  446. case _DRM_PRE_MODESET:
  447. drm_vblank_pre_modeset(dev, crtc);
  448. break;
  449. case _DRM_POST_MODESET:
  450. drm_vblank_post_modeset(dev, crtc);
  451. break;
  452. default:
  453. ret = -EINVAL;
  454. break;
  455. }
  456. out:
  457. return ret;
  458. }
  459. /**
  460. * Wait for VBLANK.
  461. *
  462. * \param inode device inode.
  463. * \param file_priv DRM file private.
  464. * \param cmd command.
  465. * \param data user argument, pointing to a drm_wait_vblank structure.
  466. * \return zero on success or a negative number on failure.
  467. *
  468. * This function enables the vblank interrupt on the pipe requested, then
  469. * sleeps waiting for the requested sequence number to occur, and drops
  470. * the vblank interrupt refcount afterwards. (vblank irq disable follows that
  471. * after a timeout with no further vblank waits scheduled).
  472. */
  473. int drm_wait_vblank(struct drm_device *dev, void *data,
  474. struct drm_file *file_priv)
  475. {
  476. union drm_wait_vblank *vblwait = data;
  477. int ret = 0;
  478. unsigned int flags, seq, crtc;
  479. if ((!dev->pdev->irq) || (!dev->irq_enabled))
  480. return -EINVAL;
  481. if (vblwait->request.type & _DRM_VBLANK_SIGNAL)
  482. return -EINVAL;
  483. if (vblwait->request.type &
  484. ~(_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK)) {
  485. DRM_ERROR("Unsupported type value 0x%x, supported mask 0x%x\n",
  486. vblwait->request.type,
  487. (_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK));
  488. return -EINVAL;
  489. }
  490. flags = vblwait->request.type & _DRM_VBLANK_FLAGS_MASK;
  491. crtc = flags & _DRM_VBLANK_SECONDARY ? 1 : 0;
  492. if (crtc >= dev->num_crtcs)
  493. return -EINVAL;
  494. ret = drm_vblank_get(dev, crtc);
  495. if (ret) {
  496. DRM_ERROR("failed to acquire vblank counter, %d\n", ret);
  497. return ret;
  498. }
  499. seq = drm_vblank_count(dev, crtc);
  500. switch (vblwait->request.type & _DRM_VBLANK_TYPES_MASK) {
  501. case _DRM_VBLANK_RELATIVE:
  502. vblwait->request.sequence += seq;
  503. vblwait->request.type &= ~_DRM_VBLANK_RELATIVE;
  504. case _DRM_VBLANK_ABSOLUTE:
  505. break;
  506. default:
  507. ret = -EINVAL;
  508. goto done;
  509. }
  510. if ((flags & _DRM_VBLANK_NEXTONMISS) &&
  511. (seq - vblwait->request.sequence) <= (1<<23)) {
  512. vblwait->request.sequence = seq + 1;
  513. }
  514. DRM_DEBUG("waiting on vblank count %d, crtc %d\n",
  515. vblwait->request.sequence, crtc);
  516. dev->last_vblank_wait[crtc] = vblwait->request.sequence;
  517. DRM_WAIT_ON(ret, dev->vbl_queue[crtc], 3 * DRM_HZ,
  518. (((drm_vblank_count(dev, crtc) -
  519. vblwait->request.sequence) <= (1 << 23)) ||
  520. !dev->irq_enabled));
  521. if (ret != -EINTR) {
  522. struct timeval now;
  523. do_gettimeofday(&now);
  524. vblwait->reply.tval_sec = now.tv_sec;
  525. vblwait->reply.tval_usec = now.tv_usec;
  526. vblwait->reply.sequence = drm_vblank_count(dev, crtc);
  527. DRM_DEBUG("returning %d to client\n",
  528. vblwait->reply.sequence);
  529. } else {
  530. DRM_DEBUG("vblank wait interrupted by signal\n");
  531. }
  532. done:
  533. drm_vblank_put(dev, crtc);
  534. return ret;
  535. }
  536. /**
  537. * drm_handle_vblank - handle a vblank event
  538. * @dev: DRM device
  539. * @crtc: where this event occurred
  540. *
  541. * Drivers should call this routine in their vblank interrupt handlers to
  542. * update the vblank counter and send any signals that may be pending.
  543. */
  544. void drm_handle_vblank(struct drm_device *dev, int crtc)
  545. {
  546. atomic_inc(&dev->_vblank_count[crtc]);
  547. DRM_WAKEUP(&dev->vbl_queue[crtc]);
  548. }
  549. EXPORT_SYMBOL(drm_handle_vblank);