radeon_irq_kms.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_microcode.h"
  32. #include "radeon.h"
  33. #include "atom.h"
  34. static inline uint32_t r100_irq_ack(struct radeon_device *rdev)
  35. {
  36. uint32_t irqs = RREG32(RADEON_GEN_INT_STATUS);
  37. uint32_t irq_mask = RADEON_SW_INT_TEST;
  38. if (irqs) {
  39. WREG32(RADEON_GEN_INT_STATUS, irqs);
  40. }
  41. return irqs & irq_mask;
  42. }
  43. int r100_irq_set(struct radeon_device *rdev)
  44. {
  45. uint32_t tmp = 0;
  46. if (rdev->irq.sw_int) {
  47. tmp |= RADEON_SW_INT_ENABLE;
  48. }
  49. /* Todo go through CRTC and enable vblank int or not */
  50. WREG32(RADEON_GEN_INT_CNTL, tmp);
  51. return 0;
  52. }
  53. int r100_irq_process(struct radeon_device *rdev)
  54. {
  55. uint32_t status;
  56. status = r100_irq_ack(rdev);
  57. if (!status) {
  58. return IRQ_NONE;
  59. }
  60. while (status) {
  61. /* SW interrupt */
  62. if (status & RADEON_SW_INT_TEST) {
  63. radeon_fence_process(rdev);
  64. }
  65. status = r100_irq_ack(rdev);
  66. }
  67. return IRQ_HANDLED;
  68. }
  69. int rs600_irq_set(struct radeon_device *rdev)
  70. {
  71. uint32_t tmp = 0;
  72. if (rdev->irq.sw_int) {
  73. tmp |= RADEON_SW_INT_ENABLE;
  74. }
  75. WREG32(RADEON_GEN_INT_CNTL, tmp);
  76. /* Todo go through CRTC and enable vblank int or not */
  77. WREG32(R500_DxMODE_INT_MASK, 0);
  78. return 0;
  79. }
  80. irqreturn_t radeon_driver_irq_handler_kms(DRM_IRQ_ARGS)
  81. {
  82. struct drm_device *dev = (struct drm_device *) arg;
  83. struct radeon_device *rdev = dev->dev_private;
  84. return radeon_irq_process(rdev);
  85. }
  86. void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
  87. {
  88. struct radeon_device *rdev = dev->dev_private;
  89. unsigned i;
  90. /* Disable *all* interrupts */
  91. rdev->irq.sw_int = false;
  92. for (i = 0; i < 2; i++) {
  93. rdev->irq.crtc_vblank_int[i] = false;
  94. }
  95. radeon_irq_set(rdev);
  96. /* Clear bits */
  97. radeon_irq_process(rdev);
  98. }
  99. int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
  100. {
  101. struct radeon_device *rdev = dev->dev_private;
  102. dev->max_vblank_count = 0x001fffff;
  103. rdev->irq.sw_int = true;
  104. radeon_irq_set(rdev);
  105. return 0;
  106. }
  107. void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
  108. {
  109. struct radeon_device *rdev = dev->dev_private;
  110. unsigned i;
  111. if (rdev == NULL) {
  112. return;
  113. }
  114. /* Disable *all* interrupts */
  115. rdev->irq.sw_int = false;
  116. for (i = 0; i < 2; i++) {
  117. rdev->irq.crtc_vblank_int[i] = false;
  118. }
  119. radeon_irq_set(rdev);
  120. }
  121. int radeon_irq_kms_init(struct radeon_device *rdev)
  122. {
  123. int r = 0;
  124. r = drm_vblank_init(rdev->ddev, 2);
  125. if (r) {
  126. return r;
  127. }
  128. drm_irq_install(rdev->ddev);
  129. rdev->irq.installed = true;
  130. DRM_INFO("radeon: irq initialized.\n");
  131. return 0;
  132. }
  133. void radeon_irq_kms_fini(struct radeon_device *rdev)
  134. {
  135. if (rdev->irq.installed) {
  136. rdev->irq.installed = false;
  137. drm_irq_uninstall(rdev->ddev);
  138. }
  139. }