mga_irq.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* mga_irq.c -- IRQ handling for radeon -*- linux-c -*-
  2. *
  3. * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
  4. *
  5. * The Weather Channel (TM) funded Tungsten Graphics to develop the
  6. * initial release of the Radeon 8500 driver under the XFree86 license.
  7. * This notice must be preserved.
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a
  10. * copy of this software and associated documentation files (the "Software"),
  11. * to deal in the Software without restriction, including without limitation
  12. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13. * and/or sell copies of the Software, and to permit persons to whom the
  14. * Software is furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice (including the next
  17. * paragraph) shall be included in all copies or substantial portions of the
  18. * Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  23. * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  24. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  25. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  26. * DEALINGS IN THE SOFTWARE.
  27. *
  28. * Authors:
  29. * Keith Whitwell <keith@tungstengraphics.com>
  30. * Eric Anholt <anholt@FreeBSD.org>
  31. */
  32. #include "drmP.h"
  33. #include "drm.h"
  34. #include "mga_drm.h"
  35. #include "mga_drv.h"
  36. irqreturn_t mga_driver_irq_handler( DRM_IRQ_ARGS )
  37. {
  38. drm_device_t *dev = (drm_device_t *) arg;
  39. drm_mga_private_t *dev_priv =
  40. (drm_mga_private_t *)dev->dev_private;
  41. int status;
  42. int handled = 0;
  43. status = MGA_READ(MGA_STATUS);
  44. /* VBLANK interrupt */
  45. if ( status & MGA_VLINEPEN ) {
  46. MGA_WRITE( MGA_ICLEAR, MGA_VLINEICLR );
  47. atomic_inc(&dev->vbl_received);
  48. DRM_WAKEUP(&dev->vbl_queue);
  49. drm_vbl_send_signals(dev);
  50. handled = 1;
  51. }
  52. /* SOFTRAP interrupt */
  53. if (status & MGA_SOFTRAPEN) {
  54. const u32 prim_start = MGA_READ(MGA_PRIMADDRESS);
  55. const u32 prim_end = MGA_READ(MGA_PRIMEND);
  56. MGA_WRITE(MGA_ICLEAR, MGA_SOFTRAPICLR);
  57. /* In addition to clearing the interrupt-pending bit, we
  58. * have to write to MGA_PRIMEND to re-start the DMA operation.
  59. */
  60. if ( (prim_start & ~0x03) != (prim_end & ~0x03) ) {
  61. MGA_WRITE(MGA_PRIMEND, prim_end);
  62. }
  63. atomic_inc(&dev_priv->last_fence_retired);
  64. DRM_WAKEUP(&dev_priv->fence_queue);
  65. handled = 1;
  66. }
  67. if ( handled ) {
  68. return IRQ_HANDLED;
  69. }
  70. return IRQ_NONE;
  71. }
  72. int mga_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence)
  73. {
  74. unsigned int cur_vblank;
  75. int ret = 0;
  76. /* Assume that the user has missed the current sequence number
  77. * by about a day rather than she wants to wait for years
  78. * using vertical blanks...
  79. */
  80. DRM_WAIT_ON( ret, dev->vbl_queue, 3*DRM_HZ,
  81. ( ( ( cur_vblank = atomic_read(&dev->vbl_received ) )
  82. - *sequence ) <= (1<<23) ) );
  83. *sequence = cur_vblank;
  84. return ret;
  85. }
  86. int mga_driver_fence_wait(drm_device_t * dev, unsigned int *sequence)
  87. {
  88. drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
  89. unsigned int cur_fence;
  90. int ret = 0;
  91. /* Assume that the user has missed the current sequence number
  92. * by about a day rather than she wants to wait for years
  93. * using fences.
  94. */
  95. DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
  96. (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
  97. - *sequence) <= (1 << 23)));
  98. *sequence = cur_fence;
  99. return ret;
  100. }
  101. void mga_driver_irq_preinstall(drm_device_t * dev)
  102. {
  103. drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
  104. /* Disable *all* interrupts */
  105. MGA_WRITE( MGA_IEN, 0 );
  106. /* Clear bits if they're already high */
  107. MGA_WRITE( MGA_ICLEAR, ~0 );
  108. }
  109. void mga_driver_irq_postinstall(drm_device_t * dev)
  110. {
  111. drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
  112. DRM_INIT_WAITQUEUE( &dev_priv->fence_queue );
  113. /* Turn on vertical blank interrupt and soft trap interrupt. */
  114. MGA_WRITE(MGA_IEN, MGA_VLINEIEN | MGA_SOFTRAPEN);
  115. }
  116. void mga_driver_irq_uninstall( drm_device_t *dev ) {
  117. drm_mga_private_t *dev_priv =
  118. (drm_mga_private_t *)dev->dev_private;
  119. if (!dev_priv)
  120. return;
  121. /* Disable *all* interrupts */
  122. MGA_WRITE(MGA_IEN, 0);
  123. dev->irq_enabled = 0;
  124. }