i915_irq.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
  2. */
  3. /**************************************************************************
  4. *
  5. * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  6. * All Rights Reserved.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the
  10. * "Software"), to deal in the Software without restriction, including
  11. * without limitation the rights to use, copy, modify, merge, publish,
  12. * distribute, sub license, and/or sell copies of the Software, and to
  13. * permit persons to whom the Software is furnished to do so, subject to
  14. * the following conditions:
  15. *
  16. * The above copyright notice and this permission notice (including the
  17. * next paragraph) shall be included in all copies or substantial portions
  18. * of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  23. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  24. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. *
  28. **************************************************************************/
  29. #include "drmP.h"
  30. #include "drm.h"
  31. #include "i915_drm.h"
  32. #include "i915_drv.h"
  33. #define USER_INT_FLAG 0x2
  34. #define MAX_NOPID ((u32)~0)
  35. #define READ_BREADCRUMB(dev_priv) (((u32*)(dev_priv->hw_status_page))[5])
  36. irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
  37. {
  38. drm_device_t *dev = (drm_device_t *) arg;
  39. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  40. u16 temp;
  41. temp = I915_READ16(I915REG_INT_IDENTITY_R);
  42. temp &= USER_INT_FLAG;
  43. DRM_DEBUG("%s flag=%08x\n", __FUNCTION__, temp);
  44. if (temp == 0)
  45. return IRQ_NONE;
  46. I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
  47. DRM_WAKEUP(&dev_priv->irq_queue);
  48. return IRQ_HANDLED;
  49. }
  50. static int i915_emit_irq(drm_device_t * dev)
  51. {
  52. drm_i915_private_t *dev_priv = dev->dev_private;
  53. u32 ret;
  54. RING_LOCALS;
  55. i915_kernel_lost_context(dev);
  56. DRM_DEBUG("%s\n", __FUNCTION__);
  57. ret = dev_priv->counter;
  58. BEGIN_LP_RING(2);
  59. OUT_RING(0);
  60. OUT_RING(GFX_OP_USER_INTERRUPT);
  61. ADVANCE_LP_RING();
  62. return ret;
  63. }
  64. static int i915_wait_irq(drm_device_t * dev, int irq_nr)
  65. {
  66. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  67. int ret = 0;
  68. DRM_DEBUG("%s irq_nr=%d breadcrumb=%d\n", __FUNCTION__, irq_nr,
  69. READ_BREADCRUMB(dev_priv));
  70. if (READ_BREADCRUMB(dev_priv) >= irq_nr)
  71. return 0;
  72. dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
  73. DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
  74. READ_BREADCRUMB(dev_priv) >= irq_nr);
  75. if (ret == DRM_ERR(EBUSY)) {
  76. DRM_ERROR("%s: EBUSY -- rec: %d emitted: %d\n",
  77. __FUNCTION__,
  78. READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
  79. }
  80. dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
  81. return ret;
  82. }
  83. /* Needs the lock as it touches the ring.
  84. */
  85. int i915_irq_emit(DRM_IOCTL_ARGS)
  86. {
  87. DRM_DEVICE;
  88. drm_i915_private_t *dev_priv = dev->dev_private;
  89. drm_i915_irq_emit_t emit;
  90. int result;
  91. LOCK_TEST_WITH_RETURN(dev, filp);
  92. if (!dev_priv) {
  93. DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
  94. return DRM_ERR(EINVAL);
  95. }
  96. DRM_COPY_FROM_USER_IOCTL(emit, (drm_i915_irq_emit_t __user *) data,
  97. sizeof(emit));
  98. result = i915_emit_irq(dev);
  99. if (DRM_COPY_TO_USER(emit.irq_seq, &result, sizeof(int))) {
  100. DRM_ERROR("copy_to_user\n");
  101. return DRM_ERR(EFAULT);
  102. }
  103. return 0;
  104. }
  105. /* Doesn't need the hardware lock.
  106. */
  107. int i915_irq_wait(DRM_IOCTL_ARGS)
  108. {
  109. DRM_DEVICE;
  110. drm_i915_private_t *dev_priv = dev->dev_private;
  111. drm_i915_irq_wait_t irqwait;
  112. if (!dev_priv) {
  113. DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
  114. return DRM_ERR(EINVAL);
  115. }
  116. DRM_COPY_FROM_USER_IOCTL(irqwait, (drm_i915_irq_wait_t __user *) data,
  117. sizeof(irqwait));
  118. return i915_wait_irq(dev, irqwait.irq_seq);
  119. }
  120. /* drm_dma.h hooks
  121. */
  122. void i915_driver_irq_preinstall(drm_device_t * dev)
  123. {
  124. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  125. I915_WRITE16(I915REG_HWSTAM, 0xfffe);
  126. I915_WRITE16(I915REG_INT_MASK_R, 0x0);
  127. I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
  128. }
  129. void i915_driver_irq_postinstall(drm_device_t * dev)
  130. {
  131. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  132. I915_WRITE16(I915REG_INT_ENABLE_R, USER_INT_FLAG);
  133. DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
  134. }
  135. void i915_driver_irq_uninstall(drm_device_t * dev)
  136. {
  137. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  138. if (!dev_priv)
  139. return;
  140. I915_WRITE16(I915REG_HWSTAM, 0xffff);
  141. I915_WRITE16(I915REG_INT_MASK_R, 0xffff);
  142. I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
  143. }