i915_irq.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. RING_LOCALS;
  61. i915_kernel_lost_context(dev);
  62. DRM_DEBUG("%s\n", __FUNCTION__);
  63. dev_priv->sarea_priv->last_enqueue = ++dev_priv->counter;
  64. if (dev_priv->counter > 0x7FFFFFFFUL)
  65. dev_priv->sarea_priv->last_enqueue = dev_priv->counter = 1;
  66. BEGIN_LP_RING(6);
  67. OUT_RING(CMD_STORE_DWORD_IDX);
  68. OUT_RING(20);
  69. OUT_RING(dev_priv->counter);
  70. OUT_RING(0);
  71. OUT_RING(0);
  72. OUT_RING(GFX_OP_USER_INTERRUPT);
  73. ADVANCE_LP_RING();
  74. return dev_priv->counter;
  75. }
  76. static int i915_wait_irq(drm_device_t * dev, int irq_nr)
  77. {
  78. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  79. int ret = 0;
  80. DRM_DEBUG("%s irq_nr=%d breadcrumb=%d\n", __FUNCTION__, irq_nr,
  81. READ_BREADCRUMB(dev_priv));
  82. if (READ_BREADCRUMB(dev_priv) >= irq_nr)
  83. return 0;
  84. dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
  85. DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
  86. READ_BREADCRUMB(dev_priv) >= irq_nr);
  87. if (ret == DRM_ERR(EBUSY)) {
  88. DRM_ERROR("%s: EBUSY -- rec: %d emitted: %d\n",
  89. __FUNCTION__,
  90. READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
  91. }
  92. dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
  93. return ret;
  94. }
  95. int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence)
  96. {
  97. drm_i915_private_t *dev_priv = dev->dev_private;
  98. unsigned int cur_vblank;
  99. int ret = 0;
  100. if (!dev_priv) {
  101. DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
  102. return DRM_ERR(EINVAL);
  103. }
  104. DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
  105. (((cur_vblank = atomic_read(&dev->vbl_received))
  106. - *sequence) <= (1<<23)));
  107. *sequence = cur_vblank;
  108. return ret;
  109. }
  110. /* Needs the lock as it touches the ring.
  111. */
  112. int i915_irq_emit(DRM_IOCTL_ARGS)
  113. {
  114. DRM_DEVICE;
  115. drm_i915_private_t *dev_priv = dev->dev_private;
  116. drm_i915_irq_emit_t emit;
  117. int result;
  118. LOCK_TEST_WITH_RETURN(dev, filp);
  119. if (!dev_priv) {
  120. DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
  121. return DRM_ERR(EINVAL);
  122. }
  123. DRM_COPY_FROM_USER_IOCTL(emit, (drm_i915_irq_emit_t __user *) data,
  124. sizeof(emit));
  125. result = i915_emit_irq(dev);
  126. if (DRM_COPY_TO_USER(emit.irq_seq, &result, sizeof(int))) {
  127. DRM_ERROR("copy_to_user\n");
  128. return DRM_ERR(EFAULT);
  129. }
  130. return 0;
  131. }
  132. /* Doesn't need the hardware lock.
  133. */
  134. int i915_irq_wait(DRM_IOCTL_ARGS)
  135. {
  136. DRM_DEVICE;
  137. drm_i915_private_t *dev_priv = dev->dev_private;
  138. drm_i915_irq_wait_t irqwait;
  139. if (!dev_priv) {
  140. DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
  141. return DRM_ERR(EINVAL);
  142. }
  143. DRM_COPY_FROM_USER_IOCTL(irqwait, (drm_i915_irq_wait_t __user *) data,
  144. sizeof(irqwait));
  145. return i915_wait_irq(dev, irqwait.irq_seq);
  146. }
  147. static int i915_enable_interrupt (drm_device_t *dev)
  148. {
  149. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  150. u16 flag;
  151. flag = 0;
  152. if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_A)
  153. flag |= VSYNC_PIPEA_FLAG;
  154. if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_B)
  155. flag |= VSYNC_PIPEB_FLAG;
  156. if (dev_priv->vblank_pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) {
  157. DRM_ERROR("%s called with invalid pipe 0x%x\n",
  158. __FUNCTION__, dev_priv->vblank_pipe);
  159. return DRM_ERR(EINVAL);
  160. }
  161. I915_WRITE16(I915REG_INT_ENABLE_R, USER_INT_FLAG | flag);
  162. return 0;
  163. }
  164. /* Set the vblank monitor pipe
  165. */
  166. int i915_vblank_pipe_set(DRM_IOCTL_ARGS)
  167. {
  168. DRM_DEVICE;
  169. drm_i915_private_t *dev_priv = dev->dev_private;
  170. drm_i915_vblank_pipe_t pipe;
  171. if (!dev_priv) {
  172. DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
  173. return DRM_ERR(EINVAL);
  174. }
  175. DRM_COPY_FROM_USER_IOCTL(pipe, (drm_i915_vblank_pipe_t __user *) data,
  176. sizeof(pipe));
  177. dev_priv->vblank_pipe = pipe.pipe;
  178. return i915_enable_interrupt (dev);
  179. }
  180. int i915_vblank_pipe_get(DRM_IOCTL_ARGS)
  181. {
  182. DRM_DEVICE;
  183. drm_i915_private_t *dev_priv = dev->dev_private;
  184. drm_i915_vblank_pipe_t pipe;
  185. u16 flag;
  186. if (!dev_priv) {
  187. DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
  188. return DRM_ERR(EINVAL);
  189. }
  190. flag = I915_READ(I915REG_INT_ENABLE_R);
  191. pipe.pipe = 0;
  192. if (flag & VSYNC_PIPEA_FLAG)
  193. pipe.pipe |= DRM_I915_VBLANK_PIPE_A;
  194. if (flag & VSYNC_PIPEB_FLAG)
  195. pipe.pipe |= DRM_I915_VBLANK_PIPE_B;
  196. DRM_COPY_TO_USER_IOCTL((drm_i915_vblank_pipe_t __user *) data, pipe,
  197. sizeof(pipe));
  198. return 0;
  199. }
  200. /* drm_dma.h hooks
  201. */
  202. void i915_driver_irq_preinstall(drm_device_t * dev)
  203. {
  204. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  205. I915_WRITE16(I915REG_HWSTAM, 0xfffe);
  206. I915_WRITE16(I915REG_INT_MASK_R, 0x0);
  207. I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
  208. }
  209. void i915_driver_irq_postinstall(drm_device_t * dev)
  210. {
  211. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  212. i915_enable_interrupt(dev);
  213. DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
  214. }
  215. void i915_driver_irq_uninstall(drm_device_t * dev)
  216. {
  217. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  218. u16 temp;
  219. if (!dev_priv)
  220. return;
  221. I915_WRITE16(I915REG_HWSTAM, 0xffff);
  222. I915_WRITE16(I915REG_INT_MASK_R, 0xffff);
  223. I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
  224. temp = I915_READ16(I915REG_INT_IDENTITY_R);
  225. I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
  226. }