radeon_irq_kms.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include "drmP.h"
  29. #include "drm_crtc_helper.h"
  30. #include "radeon_drm.h"
  31. #include "radeon_reg.h"
  32. #include "radeon.h"
  33. #include "atom.h"
  34. irqreturn_t radeon_driver_irq_handler_kms(DRM_IRQ_ARGS)
  35. {
  36. struct drm_device *dev = (struct drm_device *) arg;
  37. struct radeon_device *rdev = dev->dev_private;
  38. return radeon_irq_process(rdev);
  39. }
  40. /*
  41. * Handle hotplug events outside the interrupt handler proper.
  42. */
  43. static void radeon_hotplug_work_func(struct work_struct *work)
  44. {
  45. struct radeon_device *rdev = container_of(work, struct radeon_device,
  46. hotplug_work);
  47. struct drm_device *dev = rdev->ddev;
  48. struct drm_mode_config *mode_config = &dev->mode_config;
  49. struct drm_connector *connector;
  50. if (mode_config->num_connector) {
  51. list_for_each_entry(connector, &mode_config->connector_list, head)
  52. radeon_connector_hotplug(connector);
  53. }
  54. /* Just fire off a uevent and let userspace tell us what to do */
  55. drm_helper_hpd_irq_event(dev);
  56. }
  57. void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
  58. {
  59. struct radeon_device *rdev = dev->dev_private;
  60. unsigned i;
  61. /* Disable *all* interrupts */
  62. for (i = 0; i < RADEON_NUM_RINGS; i++)
  63. rdev->irq.sw_int[i] = false;
  64. rdev->irq.gui_idle = false;
  65. for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
  66. rdev->irq.hpd[i] = false;
  67. for (i = 0; i < RADEON_MAX_CRTCS; i++) {
  68. rdev->irq.crtc_vblank_int[i] = false;
  69. rdev->irq.pflip[i] = false;
  70. }
  71. radeon_irq_set(rdev);
  72. /* Clear bits */
  73. radeon_irq_process(rdev);
  74. }
  75. int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
  76. {
  77. struct radeon_device *rdev = dev->dev_private;
  78. unsigned i;
  79. dev->max_vblank_count = 0x001fffff;
  80. for (i = 0; i < RADEON_NUM_RINGS; i++)
  81. rdev->irq.sw_int[i] = true;
  82. radeon_irq_set(rdev);
  83. return 0;
  84. }
  85. void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
  86. {
  87. struct radeon_device *rdev = dev->dev_private;
  88. unsigned i;
  89. if (rdev == NULL) {
  90. return;
  91. }
  92. /* Disable *all* interrupts */
  93. for (i = 0; i < RADEON_NUM_RINGS; i++)
  94. rdev->irq.sw_int[i] = false;
  95. rdev->irq.gui_idle = false;
  96. for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
  97. rdev->irq.hpd[i] = false;
  98. for (i = 0; i < RADEON_MAX_CRTCS; i++) {
  99. rdev->irq.crtc_vblank_int[i] = false;
  100. rdev->irq.pflip[i] = false;
  101. }
  102. radeon_irq_set(rdev);
  103. }
  104. static bool radeon_msi_ok(struct radeon_device *rdev)
  105. {
  106. /* RV370/RV380 was first asic with MSI support */
  107. if (rdev->family < CHIP_RV380)
  108. return false;
  109. /* MSIs don't work on AGP */
  110. if (rdev->flags & RADEON_IS_AGP)
  111. return false;
  112. /* force MSI on */
  113. if (radeon_msi == 1)
  114. return true;
  115. else if (radeon_msi == 0)
  116. return false;
  117. /* Quirks */
  118. /* HP RS690 only seems to work with MSIs. */
  119. if ((rdev->pdev->device == 0x791f) &&
  120. (rdev->pdev->subsystem_vendor == 0x103c) &&
  121. (rdev->pdev->subsystem_device == 0x30c2))
  122. return true;
  123. /* Dell RS690 only seems to work with MSIs. */
  124. if ((rdev->pdev->device == 0x791f) &&
  125. (rdev->pdev->subsystem_vendor == 0x1028) &&
  126. (rdev->pdev->subsystem_device == 0x01fd))
  127. return true;
  128. if (rdev->flags & RADEON_IS_IGP) {
  129. /* APUs work fine with MSIs */
  130. if (rdev->family >= CHIP_PALM)
  131. return true;
  132. /* lots of IGPs have problems with MSIs */
  133. return false;
  134. }
  135. return true;
  136. }
  137. int radeon_irq_kms_init(struct radeon_device *rdev)
  138. {
  139. int i;
  140. int r = 0;
  141. INIT_WORK(&rdev->hotplug_work, radeon_hotplug_work_func);
  142. spin_lock_init(&rdev->irq.sw_lock);
  143. for (i = 0; i < rdev->num_crtc; i++)
  144. spin_lock_init(&rdev->irq.pflip_lock[i]);
  145. r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
  146. if (r) {
  147. return r;
  148. }
  149. /* enable msi */
  150. rdev->msi_enabled = 0;
  151. if (radeon_msi_ok(rdev)) {
  152. int ret = pci_enable_msi(rdev->pdev);
  153. if (!ret) {
  154. rdev->msi_enabled = 1;
  155. dev_info(rdev->dev, "radeon: using MSI.\n");
  156. }
  157. }
  158. rdev->irq.installed = true;
  159. r = drm_irq_install(rdev->ddev);
  160. if (r) {
  161. rdev->irq.installed = false;
  162. return r;
  163. }
  164. DRM_INFO("radeon: irq initialized.\n");
  165. return 0;
  166. }
  167. void radeon_irq_kms_fini(struct radeon_device *rdev)
  168. {
  169. drm_vblank_cleanup(rdev->ddev);
  170. if (rdev->irq.installed) {
  171. drm_irq_uninstall(rdev->ddev);
  172. rdev->irq.installed = false;
  173. if (rdev->msi_enabled)
  174. pci_disable_msi(rdev->pdev);
  175. }
  176. flush_work_sync(&rdev->hotplug_work);
  177. }
  178. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring)
  179. {
  180. unsigned long irqflags;
  181. spin_lock_irqsave(&rdev->irq.sw_lock, irqflags);
  182. if (rdev->ddev->irq_enabled && (++rdev->irq.sw_refcount[ring] == 1)) {
  183. rdev->irq.sw_int[ring] = true;
  184. radeon_irq_set(rdev);
  185. }
  186. spin_unlock_irqrestore(&rdev->irq.sw_lock, irqflags);
  187. }
  188. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring)
  189. {
  190. unsigned long irqflags;
  191. spin_lock_irqsave(&rdev->irq.sw_lock, irqflags);
  192. BUG_ON(rdev->ddev->irq_enabled && rdev->irq.sw_refcount[ring] <= 0);
  193. if (rdev->ddev->irq_enabled && (--rdev->irq.sw_refcount[ring] == 0)) {
  194. rdev->irq.sw_int[ring] = false;
  195. radeon_irq_set(rdev);
  196. }
  197. spin_unlock_irqrestore(&rdev->irq.sw_lock, irqflags);
  198. }
  199. void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc)
  200. {
  201. unsigned long irqflags;
  202. if (crtc < 0 || crtc >= rdev->num_crtc)
  203. return;
  204. spin_lock_irqsave(&rdev->irq.pflip_lock[crtc], irqflags);
  205. if (rdev->ddev->irq_enabled && (++rdev->irq.pflip_refcount[crtc] == 1)) {
  206. rdev->irq.pflip[crtc] = true;
  207. radeon_irq_set(rdev);
  208. }
  209. spin_unlock_irqrestore(&rdev->irq.pflip_lock[crtc], irqflags);
  210. }
  211. void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc)
  212. {
  213. unsigned long irqflags;
  214. if (crtc < 0 || crtc >= rdev->num_crtc)
  215. return;
  216. spin_lock_irqsave(&rdev->irq.pflip_lock[crtc], irqflags);
  217. BUG_ON(rdev->ddev->irq_enabled && rdev->irq.pflip_refcount[crtc] <= 0);
  218. if (rdev->ddev->irq_enabled && (--rdev->irq.pflip_refcount[crtc] == 0)) {
  219. rdev->irq.pflip[crtc] = false;
  220. radeon_irq_set(rdev);
  221. }
  222. spin_unlock_irqrestore(&rdev->irq.pflip_lock[crtc], irqflags);
  223. }