i915_irq.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
  2. */
  3. /*
  4. * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  5. * All Rights Reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sub license, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice (including the
  16. * next paragraph) shall be included in all copies or substantial portions
  17. * of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  22. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  23. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  24. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  25. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. *
  27. */
  28. #include "drmP.h"
  29. #include "drm.h"
  30. #include "i915_drm.h"
  31. #include "i915_drv.h"
  32. #define USER_INT_FLAG (1<<1)
  33. #define VSYNC_PIPEB_FLAG (1<<5)
  34. #define VSYNC_PIPEA_FLAG (1<<7)
  35. #define MAX_NOPID ((u32)~0)
  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 | VSYNC_PIPEA_FLAG | VSYNC_PIPEB_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. dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
  48. if (temp & USER_INT_FLAG)
  49. DRM_WAKEUP(&dev_priv->irq_queue);
  50. if (temp & (VSYNC_PIPEA_FLAG | VSYNC_PIPEB_FLAG)) {
  51. atomic_inc(&dev->vbl_received);
  52. DRM_WAKEUP(&dev->vbl_queue);
  53. drm_vbl_send_signals(dev);
  54. }
  55. return IRQ_HANDLED;
  56. }
  57. static int i915_emit_irq(drm_device_t * dev)
  58. {
  59. drm_i915_private_t *dev_priv = dev->dev_private;
  60. u32 ret;
  61. RING_LOCALS;
  62. i915_kernel_lost_context(dev);
  63. DRM_DEBUG("%s\n", __FUNCTION__);
  64. ret = dev_priv->counter;
  65. BEGIN_LP_RING(2);
  66. OUT_RING(0);
  67. OUT_RING(GFX_OP_USER_INTERRUPT);
  68. ADVANCE_LP_RING();
  69. return ret;
  70. }
  71. static int i915_wait_irq(drm_device_t * dev, int irq_nr)
  72. {
  73. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  74. int ret = 0;
  75. DRM_DEBUG("%s irq_nr=%d breadcrumb=%d\n", __FUNCTION__, irq_nr,
  76. READ_BREADCRUMB(dev_priv));
  77. if (READ_BREADCRUMB(dev_priv) >= irq_nr)
  78. return 0;
  79. dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
  80. DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
  81. READ_BREADCRUMB(dev_priv) >= irq_nr);
  82. if (ret == DRM_ERR(EBUSY)) {
  83. DRM_ERROR("%s: EBUSY -- rec: %d emitted: %d\n",
  84. __FUNCTION__,
  85. READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
  86. }
  87. dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
  88. return ret;
  89. }
  90. int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence)
  91. {
  92. drm_i915_private_t *dev_priv = dev->dev_private;
  93. unsigned int cur_vblank;
  94. int ret = 0;
  95. if (!dev_priv) {
  96. DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
  97. return DRM_ERR(EINVAL);
  98. }
  99. DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
  100. (((cur_vblank = atomic_read(&dev->vbl_received))
  101. - *sequence) <= (1<<23)));
  102. *sequence = cur_vblank;
  103. return ret;
  104. }
  105. /* Needs the lock as it touches the ring.
  106. */
  107. int i915_irq_emit(DRM_IOCTL_ARGS)
  108. {
  109. DRM_DEVICE;
  110. drm_i915_private_t *dev_priv = dev->dev_private;
  111. drm_i915_irq_emit_t emit;
  112. int result;
  113. LOCK_TEST_WITH_RETURN(dev, filp);
  114. if (!dev_priv) {
  115. DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
  116. return DRM_ERR(EINVAL);
  117. }
  118. DRM_COPY_FROM_USER_IOCTL(emit, (drm_i915_irq_emit_t __user *) data,
  119. sizeof(emit));
  120. result = i915_emit_irq(dev);
  121. if (DRM_COPY_TO_USER(emit.irq_seq, &result, sizeof(int))) {
  122. DRM_ERROR("copy_to_user\n");
  123. return DRM_ERR(EFAULT);
  124. }
  125. return 0;
  126. }
  127. /* Doesn't need the hardware lock.
  128. */
  129. int i915_irq_wait(DRM_IOCTL_ARGS)
  130. {
  131. DRM_DEVICE;
  132. drm_i915_private_t *dev_priv = dev->dev_private;
  133. drm_i915_irq_wait_t irqwait;
  134. if (!dev_priv) {
  135. DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
  136. return DRM_ERR(EINVAL);
  137. }
  138. DRM_COPY_FROM_USER_IOCTL(irqwait, (drm_i915_irq_wait_t __user *) data,
  139. sizeof(irqwait));
  140. return i915_wait_irq(dev, irqwait.irq_seq);
  141. }
  142. static int i915_enable_interrupt (drm_device_t *dev)
  143. {
  144. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  145. u16 flag;
  146. flag = 0;
  147. if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_A)
  148. flag |= VSYNC_PIPEA_FLAG;
  149. if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_B)
  150. flag |= VSYNC_PIPEB_FLAG;
  151. if (dev_priv->vblank_pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) {
  152. DRM_ERROR("%s called with invalid pipe 0x%x\n",
  153. __FUNCTION__, dev_priv->vblank_pipe);
  154. return DRM_ERR(EINVAL);
  155. }
  156. I915_WRITE16(I915REG_INT_ENABLE_R, USER_INT_FLAG | flag);
  157. return 0;
  158. }
  159. /* Set the vblank monitor pipe
  160. */
  161. int i915_vblank_pipe_set(DRM_IOCTL_ARGS)
  162. {
  163. DRM_DEVICE;
  164. drm_i915_private_t *dev_priv = dev->dev_private;
  165. drm_i915_vblank_pipe_t pipe;
  166. if (!dev_priv) {
  167. DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
  168. return DRM_ERR(EINVAL);
  169. }
  170. DRM_COPY_FROM_USER_IOCTL(pipe, (drm_i915_vblank_pipe_t __user *) data,
  171. sizeof(pipe));
  172. dev_priv->vblank_pipe = pipe.pipe;
  173. return i915_enable_interrupt (dev);
  174. }
  175. int i915_vblank_pipe_get(DRM_IOCTL_ARGS)
  176. {
  177. DRM_DEVICE;
  178. drm_i915_private_t *dev_priv = dev->dev_private;
  179. drm_i915_vblank_pipe_t pipe;
  180. u16 flag;
  181. if (!dev_priv) {
  182. DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
  183. return DRM_ERR(EINVAL);
  184. }
  185. flag = I915_READ(I915REG_INT_ENABLE_R);
  186. pipe.pipe = 0;
  187. if (flag & VSYNC_PIPEA_FLAG)
  188. pipe.pipe |= DRM_I915_VBLANK_PIPE_A;
  189. if (flag & VSYNC_PIPEB_FLAG)
  190. pipe.pipe |= DRM_I915_VBLANK_PIPE_B;
  191. DRM_COPY_TO_USER_IOCTL((drm_i915_vblank_pipe_t __user *) data, pipe,
  192. sizeof(pipe));
  193. return 0;
  194. }
  195. /* drm_dma.h hooks
  196. */
  197. void i915_driver_irq_preinstall(drm_device_t * dev)
  198. {
  199. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  200. I915_WRITE16(I915REG_HWSTAM, 0xfffe);
  201. I915_WRITE16(I915REG_INT_MASK_R, 0x0);
  202. I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
  203. }
  204. void i915_driver_irq_postinstall(drm_device_t * dev)
  205. {
  206. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  207. i915_enable_interrupt(dev);
  208. DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
  209. }
  210. void i915_driver_irq_uninstall(drm_device_t * dev)
  211. {
  212. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  213. u16 temp;
  214. if (!dev_priv)
  215. return;
  216. I915_WRITE16(I915REG_HWSTAM, 0xffff);
  217. I915_WRITE16(I915REG_INT_MASK_R, 0xffff);
  218. I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
  219. temp = I915_READ16(I915REG_INT_IDENTITY_R);
  220. I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
  221. }