radeon_irq_kms.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. INIT_WORK(&rdev->hotplug_work, radeon_hotplug_work_func);
  62. /* Disable *all* interrupts */
  63. rdev->irq.sw_int = false;
  64. rdev->irq.gui_idle = false;
  65. for (i = 0; i < rdev->num_crtc; i++)
  66. rdev->irq.crtc_vblank_int[i] = false;
  67. for (i = 0; i < 6; i++)
  68. rdev->irq.hpd[i] = false;
  69. radeon_irq_set(rdev);
  70. /* Clear bits */
  71. radeon_irq_process(rdev);
  72. }
  73. int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
  74. {
  75. struct radeon_device *rdev = dev->dev_private;
  76. dev->max_vblank_count = 0x001fffff;
  77. rdev->irq.sw_int = true;
  78. radeon_irq_set(rdev);
  79. return 0;
  80. }
  81. void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
  82. {
  83. struct radeon_device *rdev = dev->dev_private;
  84. unsigned i;
  85. if (rdev == NULL) {
  86. return;
  87. }
  88. /* Disable *all* interrupts */
  89. rdev->irq.sw_int = false;
  90. rdev->irq.gui_idle = false;
  91. for (i = 0; i < rdev->num_crtc; i++)
  92. rdev->irq.crtc_vblank_int[i] = false;
  93. for (i = 0; i < 6; i++)
  94. rdev->irq.hpd[i] = false;
  95. radeon_irq_set(rdev);
  96. }
  97. int radeon_irq_kms_init(struct radeon_device *rdev)
  98. {
  99. int r = 0;
  100. spin_lock_init(&rdev->irq.sw_lock);
  101. r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
  102. if (r) {
  103. return r;
  104. }
  105. /* enable msi */
  106. rdev->msi_enabled = 0;
  107. /* MSIs don't seem to work reliably on all IGP
  108. * chips. Disable MSI on them for now.
  109. */
  110. if ((rdev->family >= CHIP_RV380) &&
  111. (!(rdev->flags & RADEON_IS_IGP))) {
  112. int ret = pci_enable_msi(rdev->pdev);
  113. if (!ret) {
  114. rdev->msi_enabled = 1;
  115. DRM_INFO("radeon: using MSI.\n");
  116. }
  117. }
  118. rdev->irq.installed = true;
  119. r = drm_irq_install(rdev->ddev);
  120. if (r) {
  121. rdev->irq.installed = false;
  122. return r;
  123. }
  124. DRM_INFO("radeon: irq initialized.\n");
  125. return 0;
  126. }
  127. void radeon_irq_kms_fini(struct radeon_device *rdev)
  128. {
  129. drm_vblank_cleanup(rdev->ddev);
  130. if (rdev->irq.installed) {
  131. drm_irq_uninstall(rdev->ddev);
  132. rdev->irq.installed = false;
  133. if (rdev->msi_enabled)
  134. pci_disable_msi(rdev->pdev);
  135. }
  136. }
  137. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev)
  138. {
  139. unsigned long irqflags;
  140. spin_lock_irqsave(&rdev->irq.sw_lock, irqflags);
  141. if (rdev->ddev->irq_enabled && (++rdev->irq.sw_refcount == 1)) {
  142. rdev->irq.sw_int = true;
  143. radeon_irq_set(rdev);
  144. }
  145. spin_unlock_irqrestore(&rdev->irq.sw_lock, irqflags);
  146. }
  147. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev)
  148. {
  149. unsigned long irqflags;
  150. spin_lock_irqsave(&rdev->irq.sw_lock, irqflags);
  151. BUG_ON(rdev->ddev->irq_enabled && rdev->irq.sw_refcount <= 0);
  152. if (rdev->ddev->irq_enabled && (--rdev->irq.sw_refcount == 0)) {
  153. rdev->irq.sw_int = false;
  154. radeon_irq_set(rdev);
  155. }
  156. spin_unlock_irqrestore(&rdev->irq.sw_lock, irqflags);
  157. }