radeon_irq_kms.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 "radeon_drm.h"
  30. #include "radeon_reg.h"
  31. #include "radeon.h"
  32. #include "atom.h"
  33. irqreturn_t radeon_driver_irq_handler_kms(DRM_IRQ_ARGS)
  34. {
  35. struct drm_device *dev = (struct drm_device *) arg;
  36. struct radeon_device *rdev = dev->dev_private;
  37. return radeon_irq_process(rdev);
  38. }
  39. /*
  40. * Handle hotplug events outside the interrupt handler proper.
  41. */
  42. static void radeon_hotplug_work_func(struct work_struct *work)
  43. {
  44. struct radeon_device *rdev = container_of(work, struct radeon_device,
  45. hotplug_work);
  46. struct drm_device *dev = rdev->ddev;
  47. struct drm_mode_config *mode_config = &dev->mode_config;
  48. struct drm_connector *connector;
  49. if (mode_config->num_connector) {
  50. list_for_each_entry(connector, &mode_config->connector_list, head)
  51. radeon_connector_hotplug(connector);
  52. }
  53. /* Just fire off a uevent and let userspace tell us what to do */
  54. drm_sysfs_hotplug_event(dev);
  55. }
  56. void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
  57. {
  58. struct radeon_device *rdev = dev->dev_private;
  59. unsigned i;
  60. INIT_WORK(&rdev->hotplug_work, radeon_hotplug_work_func);
  61. /* Disable *all* interrupts */
  62. rdev->irq.sw_int = false;
  63. for (i = 0; i < rdev->num_crtc; i++)
  64. rdev->irq.crtc_vblank_int[i] = false;
  65. for (i = 0; i < 6; i++)
  66. rdev->irq.hpd[i] = false;
  67. radeon_irq_set(rdev);
  68. /* Clear bits */
  69. radeon_irq_process(rdev);
  70. }
  71. int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
  72. {
  73. struct radeon_device *rdev = dev->dev_private;
  74. dev->max_vblank_count = 0x001fffff;
  75. rdev->irq.sw_int = true;
  76. radeon_irq_set(rdev);
  77. return 0;
  78. }
  79. void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
  80. {
  81. struct radeon_device *rdev = dev->dev_private;
  82. unsigned i;
  83. if (rdev == NULL) {
  84. return;
  85. }
  86. /* Disable *all* interrupts */
  87. rdev->irq.sw_int = false;
  88. for (i = 0; i < rdev->num_crtc; i++)
  89. rdev->irq.crtc_vblank_int[i] = false;
  90. for (i = 0; i < 6; i++)
  91. rdev->irq.hpd[i] = false;
  92. radeon_irq_set(rdev);
  93. }
  94. int radeon_irq_kms_init(struct radeon_device *rdev)
  95. {
  96. int r = 0;
  97. spin_lock_init(&rdev->irq.sw_lock);
  98. r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
  99. if (r) {
  100. return r;
  101. }
  102. /* enable msi */
  103. rdev->msi_enabled = 0;
  104. /* MSIs don't seem to work reliably on all IGP
  105. * chips. Disable MSI on them for now.
  106. */
  107. if ((rdev->family >= CHIP_RV380) &&
  108. (!(rdev->flags & RADEON_IS_IGP))) {
  109. int ret = pci_enable_msi(rdev->pdev);
  110. if (!ret) {
  111. rdev->msi_enabled = 1;
  112. DRM_INFO("radeon: using MSI.\n");
  113. }
  114. }
  115. rdev->irq.installed = true;
  116. r = drm_irq_install(rdev->ddev);
  117. if (r) {
  118. rdev->irq.installed = false;
  119. return r;
  120. }
  121. DRM_INFO("radeon: irq initialized.\n");
  122. return 0;
  123. }
  124. void radeon_irq_kms_fini(struct radeon_device *rdev)
  125. {
  126. drm_vblank_cleanup(rdev->ddev);
  127. if (rdev->irq.installed) {
  128. drm_irq_uninstall(rdev->ddev);
  129. rdev->irq.installed = false;
  130. if (rdev->msi_enabled)
  131. pci_disable_msi(rdev->pdev);
  132. }
  133. }
  134. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev)
  135. {
  136. unsigned long irqflags;
  137. spin_lock_irqsave(&rdev->irq.sw_lock, irqflags);
  138. if (rdev->ddev->irq_enabled && (++rdev->irq.sw_refcount == 1)) {
  139. rdev->irq.sw_int = true;
  140. radeon_irq_set(rdev);
  141. }
  142. spin_unlock_irqrestore(&rdev->irq.sw_lock, irqflags);
  143. }
  144. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev)
  145. {
  146. unsigned long irqflags;
  147. spin_lock_irqsave(&rdev->irq.sw_lock, irqflags);
  148. BUG_ON(rdev->ddev->irq_enabled && rdev->irq.sw_refcount <= 0);
  149. if (rdev->ddev->irq_enabled && (--rdev->irq.sw_refcount == 0)) {
  150. rdev->irq.sw_int = false;
  151. radeon_irq_set(rdev);
  152. }
  153. spin_unlock_irqrestore(&rdev->irq.sw_lock, irqflags);
  154. }