radeon_irq_kms.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 < 2; i++) {
  64. rdev->irq.crtc_vblank_int[i] = false;
  65. }
  66. radeon_irq_set(rdev);
  67. /* Clear bits */
  68. radeon_irq_process(rdev);
  69. }
  70. int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
  71. {
  72. struct radeon_device *rdev = dev->dev_private;
  73. dev->max_vblank_count = 0x001fffff;
  74. rdev->irq.sw_int = true;
  75. radeon_irq_set(rdev);
  76. return 0;
  77. }
  78. void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
  79. {
  80. struct radeon_device *rdev = dev->dev_private;
  81. unsigned i;
  82. if (rdev == NULL) {
  83. return;
  84. }
  85. /* Disable *all* interrupts */
  86. rdev->irq.sw_int = false;
  87. for (i = 0; i < 2; i++) {
  88. rdev->irq.crtc_vblank_int[i] = false;
  89. }
  90. radeon_irq_set(rdev);
  91. }
  92. int radeon_irq_kms_init(struct radeon_device *rdev)
  93. {
  94. int r = 0;
  95. int num_crtc = 2;
  96. if (rdev->flags & RADEON_SINGLE_CRTC)
  97. num_crtc = 1;
  98. spin_lock_init(&rdev->irq.sw_lock);
  99. r = drm_vblank_init(rdev->ddev, num_crtc);
  100. if (r) {
  101. return r;
  102. }
  103. /* enable msi */
  104. rdev->msi_enabled = 0;
  105. /* MSIs don't seem to work on my rs780;
  106. * not sure about rs880 or other rs780s.
  107. * Needs more investigation.
  108. */
  109. if ((rdev->family >= CHIP_RV380) &&
  110. (rdev->family != CHIP_RS780) &&
  111. (rdev->family != CHIP_RS880)) {
  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. drm_irq_install(rdev->ddev);
  119. rdev->irq.installed = true;
  120. DRM_INFO("radeon: irq initialized.\n");
  121. return 0;
  122. }
  123. void radeon_irq_kms_fini(struct radeon_device *rdev)
  124. {
  125. if (rdev->irq.installed) {
  126. rdev->irq.installed = false;
  127. drm_irq_uninstall(rdev->ddev);
  128. if (rdev->msi_enabled)
  129. pci_disable_msi(rdev->pdev);
  130. }
  131. }
  132. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev)
  133. {
  134. unsigned long irqflags;
  135. spin_lock_irqsave(&rdev->irq.sw_lock, irqflags);
  136. if (rdev->ddev->irq_enabled && (++rdev->irq.sw_refcount == 1)) {
  137. rdev->irq.sw_int = true;
  138. radeon_irq_set(rdev);
  139. }
  140. spin_unlock_irqrestore(&rdev->irq.sw_lock, irqflags);
  141. }
  142. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev)
  143. {
  144. unsigned long irqflags;
  145. spin_lock_irqsave(&rdev->irq.sw_lock, irqflags);
  146. BUG_ON(rdev->ddev->irq_enabled && rdev->irq.sw_refcount <= 0);
  147. if (rdev->ddev->irq_enabled && (--rdev->irq.sw_refcount == 0)) {
  148. rdev->irq.sw_int = false;
  149. radeon_irq_set(rdev);
  150. }
  151. spin_unlock_irqrestore(&rdev->irq.sw_lock, irqflags);
  152. }