radeon_irq.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /* radeon_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. * Michel D�zer <michel@daenzer.net>
  31. *
  32. * ------------------------ This file is DEPRECATED! -------------------------
  33. */
  34. #include <drm/drmP.h>
  35. #include <drm/radeon_drm.h>
  36. #include "radeon_drv.h"
  37. void radeon_irq_set_state(struct drm_device *dev, u32 mask, int state)
  38. {
  39. drm_radeon_private_t *dev_priv = dev->dev_private;
  40. if (state)
  41. dev_priv->irq_enable_reg |= mask;
  42. else
  43. dev_priv->irq_enable_reg &= ~mask;
  44. if (dev->irq_enabled)
  45. RADEON_WRITE(RADEON_GEN_INT_CNTL, dev_priv->irq_enable_reg);
  46. }
  47. static void r500_vbl_irq_set_state(struct drm_device *dev, u32 mask, int state)
  48. {
  49. drm_radeon_private_t *dev_priv = dev->dev_private;
  50. if (state)
  51. dev_priv->r500_disp_irq_reg |= mask;
  52. else
  53. dev_priv->r500_disp_irq_reg &= ~mask;
  54. if (dev->irq_enabled)
  55. RADEON_WRITE(R500_DxMODE_INT_MASK, dev_priv->r500_disp_irq_reg);
  56. }
  57. int radeon_enable_vblank(struct drm_device *dev, unsigned int pipe)
  58. {
  59. drm_radeon_private_t *dev_priv = dev->dev_private;
  60. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600) {
  61. switch (pipe) {
  62. case 0:
  63. r500_vbl_irq_set_state(dev, R500_D1MODE_INT_MASK, 1);
  64. break;
  65. case 1:
  66. r500_vbl_irq_set_state(dev, R500_D2MODE_INT_MASK, 1);
  67. break;
  68. default:
  69. DRM_ERROR("tried to enable vblank on non-existent crtc %u\n",
  70. pipe);
  71. return -EINVAL;
  72. }
  73. } else {
  74. switch (pipe) {
  75. case 0:
  76. radeon_irq_set_state(dev, RADEON_CRTC_VBLANK_MASK, 1);
  77. break;
  78. case 1:
  79. radeon_irq_set_state(dev, RADEON_CRTC2_VBLANK_MASK, 1);
  80. break;
  81. default:
  82. DRM_ERROR("tried to enable vblank on non-existent crtc %u\n",
  83. pipe);
  84. return -EINVAL;
  85. }
  86. }
  87. return 0;
  88. }
  89. void radeon_disable_vblank(struct drm_device *dev, unsigned int pipe)
  90. {
  91. drm_radeon_private_t *dev_priv = dev->dev_private;
  92. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600) {
  93. switch (pipe) {
  94. case 0:
  95. r500_vbl_irq_set_state(dev, R500_D1MODE_INT_MASK, 0);
  96. break;
  97. case 1:
  98. r500_vbl_irq_set_state(dev, R500_D2MODE_INT_MASK, 0);
  99. break;
  100. default:
  101. DRM_ERROR("tried to enable vblank on non-existent crtc %u\n",
  102. pipe);
  103. break;
  104. }
  105. } else {
  106. switch (pipe) {
  107. case 0:
  108. radeon_irq_set_state(dev, RADEON_CRTC_VBLANK_MASK, 0);
  109. break;
  110. case 1:
  111. radeon_irq_set_state(dev, RADEON_CRTC2_VBLANK_MASK, 0);
  112. break;
  113. default:
  114. DRM_ERROR("tried to enable vblank on non-existent crtc %u\n",
  115. pipe);
  116. break;
  117. }
  118. }
  119. }
  120. static u32 radeon_acknowledge_irqs(drm_radeon_private_t *dev_priv, u32 *r500_disp_int)
  121. {
  122. u32 irqs = RADEON_READ(RADEON_GEN_INT_STATUS);
  123. u32 irq_mask = RADEON_SW_INT_TEST;
  124. *r500_disp_int = 0;
  125. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600) {
  126. /* vbl interrupts in a different place */
  127. if (irqs & R500_DISPLAY_INT_STATUS) {
  128. /* if a display interrupt */
  129. u32 disp_irq;
  130. disp_irq = RADEON_READ(R500_DISP_INTERRUPT_STATUS);
  131. *r500_disp_int = disp_irq;
  132. if (disp_irq & R500_D1_VBLANK_INTERRUPT)
  133. RADEON_WRITE(R500_D1MODE_VBLANK_STATUS, R500_VBLANK_ACK);
  134. if (disp_irq & R500_D2_VBLANK_INTERRUPT)
  135. RADEON_WRITE(R500_D2MODE_VBLANK_STATUS, R500_VBLANK_ACK);
  136. }
  137. irq_mask |= R500_DISPLAY_INT_STATUS;
  138. } else
  139. irq_mask |= RADEON_CRTC_VBLANK_STAT | RADEON_CRTC2_VBLANK_STAT;
  140. irqs &= irq_mask;
  141. if (irqs)
  142. RADEON_WRITE(RADEON_GEN_INT_STATUS, irqs);
  143. return irqs;
  144. }
  145. /* Interrupts - Used for device synchronization and flushing in the
  146. * following circumstances:
  147. *
  148. * - Exclusive FB access with hw idle:
  149. * - Wait for GUI Idle (?) interrupt, then do normal flush.
  150. *
  151. * - Frame throttling, NV_fence:
  152. * - Drop marker irq's into command stream ahead of time.
  153. * - Wait on irq's with lock *not held*
  154. * - Check each for termination condition
  155. *
  156. * - Internally in cp_getbuffer, etc:
  157. * - as above, but wait with lock held???
  158. *
  159. * NOTE: These functions are misleadingly named -- the irq's aren't
  160. * tied to dma at all, this is just a hangover from dri prehistory.
  161. */
  162. irqreturn_t radeon_driver_irq_handler(int irq, void *arg)
  163. {
  164. struct drm_device *dev = (struct drm_device *) arg;
  165. drm_radeon_private_t *dev_priv =
  166. (drm_radeon_private_t *) dev->dev_private;
  167. u32 stat;
  168. u32 r500_disp_int;
  169. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600)
  170. return IRQ_NONE;
  171. /* Only consider the bits we're interested in - others could be used
  172. * outside the DRM
  173. */
  174. stat = radeon_acknowledge_irqs(dev_priv, &r500_disp_int);
  175. if (!stat)
  176. return IRQ_NONE;
  177. stat &= dev_priv->irq_enable_reg;
  178. /* SW interrupt */
  179. if (stat & RADEON_SW_INT_TEST)
  180. wake_up(&dev_priv->swi_queue);
  181. /* VBLANK interrupt */
  182. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600) {
  183. if (r500_disp_int & R500_D1_VBLANK_INTERRUPT)
  184. drm_handle_vblank(dev, 0);
  185. if (r500_disp_int & R500_D2_VBLANK_INTERRUPT)
  186. drm_handle_vblank(dev, 1);
  187. } else {
  188. if (stat & RADEON_CRTC_VBLANK_STAT)
  189. drm_handle_vblank(dev, 0);
  190. if (stat & RADEON_CRTC2_VBLANK_STAT)
  191. drm_handle_vblank(dev, 1);
  192. }
  193. return IRQ_HANDLED;
  194. }
  195. static int radeon_emit_irq(struct drm_device * dev)
  196. {
  197. drm_radeon_private_t *dev_priv = dev->dev_private;
  198. unsigned int ret;
  199. RING_LOCALS;
  200. atomic_inc(&dev_priv->swi_emitted);
  201. ret = atomic_read(&dev_priv->swi_emitted);
  202. BEGIN_RING(4);
  203. OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
  204. OUT_RING_REG(RADEON_GEN_INT_STATUS, RADEON_SW_INT_FIRE);
  205. ADVANCE_RING();
  206. COMMIT_RING();
  207. return ret;
  208. }
  209. static int radeon_wait_irq(struct drm_device * dev, int swi_nr)
  210. {
  211. drm_radeon_private_t *dev_priv =
  212. (drm_radeon_private_t *) dev->dev_private;
  213. int ret = 0;
  214. if (RADEON_READ(RADEON_LAST_SWI_REG) >= swi_nr)
  215. return 0;
  216. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  217. DRM_WAIT_ON(ret, dev_priv->swi_queue, 3 * HZ,
  218. RADEON_READ(RADEON_LAST_SWI_REG) >= swi_nr);
  219. return ret;
  220. }
  221. u32 radeon_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
  222. {
  223. drm_radeon_private_t *dev_priv = dev->dev_private;
  224. if (!dev_priv) {
  225. DRM_ERROR("called with no initialization\n");
  226. return -EINVAL;
  227. }
  228. if (pipe > 1) {
  229. DRM_ERROR("Invalid crtc %u\n", pipe);
  230. return -EINVAL;
  231. }
  232. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600) {
  233. if (pipe == 0)
  234. return RADEON_READ(R500_D1CRTC_FRAME_COUNT);
  235. else
  236. return RADEON_READ(R500_D2CRTC_FRAME_COUNT);
  237. } else {
  238. if (pipe == 0)
  239. return RADEON_READ(RADEON_CRTC_CRNT_FRAME);
  240. else
  241. return RADEON_READ(RADEON_CRTC2_CRNT_FRAME);
  242. }
  243. }
  244. /* Needs the lock as it touches the ring.
  245. */
  246. int radeon_irq_emit(struct drm_device *dev, void *data, struct drm_file *file_priv)
  247. {
  248. drm_radeon_private_t *dev_priv = dev->dev_private;
  249. drm_radeon_irq_emit_t *emit = data;
  250. int result;
  251. if (!dev_priv) {
  252. DRM_ERROR("called with no initialization\n");
  253. return -EINVAL;
  254. }
  255. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600)
  256. return -EINVAL;
  257. LOCK_TEST_WITH_RETURN(dev, file_priv);
  258. result = radeon_emit_irq(dev);
  259. if (copy_to_user(emit->irq_seq, &result, sizeof(int))) {
  260. DRM_ERROR("copy_to_user\n");
  261. return -EFAULT;
  262. }
  263. return 0;
  264. }
  265. /* Doesn't need the hardware lock.
  266. */
  267. int radeon_irq_wait(struct drm_device *dev, void *data, struct drm_file *file_priv)
  268. {
  269. drm_radeon_private_t *dev_priv = dev->dev_private;
  270. drm_radeon_irq_wait_t *irqwait = data;
  271. if (!dev_priv) {
  272. DRM_ERROR("called with no initialization\n");
  273. return -EINVAL;
  274. }
  275. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600)
  276. return -EINVAL;
  277. return radeon_wait_irq(dev, irqwait->irq_seq);
  278. }
  279. /* drm_dma.h hooks
  280. */
  281. void radeon_driver_irq_preinstall(struct drm_device * dev)
  282. {
  283. drm_radeon_private_t *dev_priv =
  284. (drm_radeon_private_t *) dev->dev_private;
  285. u32 dummy;
  286. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600)
  287. return;
  288. /* Disable *all* interrupts */
  289. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600)
  290. RADEON_WRITE(R500_DxMODE_INT_MASK, 0);
  291. RADEON_WRITE(RADEON_GEN_INT_CNTL, 0);
  292. /* Clear bits if they're already high */
  293. radeon_acknowledge_irqs(dev_priv, &dummy);
  294. }
  295. int radeon_driver_irq_postinstall(struct drm_device *dev)
  296. {
  297. drm_radeon_private_t *dev_priv =
  298. (drm_radeon_private_t *) dev->dev_private;
  299. atomic_set(&dev_priv->swi_emitted, 0);
  300. init_waitqueue_head(&dev_priv->swi_queue);
  301. dev->max_vblank_count = 0x001fffff;
  302. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600)
  303. return 0;
  304. radeon_irq_set_state(dev, RADEON_SW_INT_ENABLE, 1);
  305. return 0;
  306. }
  307. void radeon_driver_irq_uninstall(struct drm_device * dev)
  308. {
  309. drm_radeon_private_t *dev_priv =
  310. (drm_radeon_private_t *) dev->dev_private;
  311. if (!dev_priv)
  312. return;
  313. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600)
  314. return;
  315. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600)
  316. RADEON_WRITE(R500_DxMODE_INT_MASK, 0);
  317. /* Disable *all* interrupts */
  318. RADEON_WRITE(RADEON_GEN_INT_CNTL, 0);
  319. }
  320. int radeon_vblank_crtc_get(struct drm_device *dev)
  321. {
  322. drm_radeon_private_t *dev_priv = (drm_radeon_private_t *) dev->dev_private;
  323. return dev_priv->vblank_crtc;
  324. }
  325. int radeon_vblank_crtc_set(struct drm_device *dev, int64_t value)
  326. {
  327. drm_radeon_private_t *dev_priv = (drm_radeon_private_t *) dev->dev_private;
  328. if (value & ~(DRM_RADEON_VBLANK_CRTC1 | DRM_RADEON_VBLANK_CRTC2)) {
  329. DRM_ERROR("called with invalid crtc 0x%x\n", (unsigned int)value);
  330. return -EINVAL;
  331. }
  332. dev_priv->vblank_crtc = (unsigned int)value;
  333. return 0;
  334. }