nouveau_irq.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (C) 2006 Ben Skeggs.
  3. *
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial
  16. * portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  21. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  22. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. */
  27. /*
  28. * Authors:
  29. * Ben Skeggs <darktama@iinet.net.au>
  30. */
  31. #include "drmP.h"
  32. #include "drm.h"
  33. #include "nouveau_drm.h"
  34. #include "nouveau_drv.h"
  35. #include "nouveau_reg.h"
  36. #include "nouveau_ramht.h"
  37. #include "nouveau_util.h"
  38. void
  39. nouveau_irq_preinstall(struct drm_device *dev)
  40. {
  41. struct drm_nouveau_private *dev_priv = dev->dev_private;
  42. /* Master disable */
  43. nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
  44. INIT_LIST_HEAD(&dev_priv->vbl_waiting);
  45. }
  46. int
  47. nouveau_irq_postinstall(struct drm_device *dev)
  48. {
  49. struct drm_nouveau_private *dev_priv = dev->dev_private;
  50. /* Master enable */
  51. nv_wr32(dev, NV03_PMC_INTR_EN_0, NV_PMC_INTR_EN_0_MASTER_ENABLE);
  52. if (dev_priv->msi_enabled)
  53. nv_wr08(dev, 0x00088068, 0xff);
  54. return 0;
  55. }
  56. void
  57. nouveau_irq_uninstall(struct drm_device *dev)
  58. {
  59. /* Master disable */
  60. nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
  61. }
  62. irqreturn_t
  63. nouveau_irq_handler(DRM_IRQ_ARGS)
  64. {
  65. struct drm_device *dev = (struct drm_device *)arg;
  66. struct drm_nouveau_private *dev_priv = dev->dev_private;
  67. unsigned long flags;
  68. u32 stat;
  69. int i;
  70. stat = nv_rd32(dev, NV03_PMC_INTR_0);
  71. if (stat == 0 || stat == ~0)
  72. return IRQ_NONE;
  73. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  74. for (i = 0; i < 32 && stat; i++) {
  75. if (!(stat & (1 << i)) || !dev_priv->irq_handler[i])
  76. continue;
  77. dev_priv->irq_handler[i](dev);
  78. stat &= ~(1 << i);
  79. }
  80. if (dev_priv->msi_enabled)
  81. nv_wr08(dev, 0x00088068, 0xff);
  82. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  83. if (stat && nouveau_ratelimit())
  84. NV_ERROR(dev, "PMC - unhandled INTR 0x%08x\n", stat);
  85. return IRQ_HANDLED;
  86. }
  87. int
  88. nouveau_irq_init(struct drm_device *dev)
  89. {
  90. struct drm_nouveau_private *dev_priv = dev->dev_private;
  91. int ret;
  92. if (nouveau_msi != 0 && dev_priv->card_type >= NV_50) {
  93. ret = pci_enable_msi(dev->pdev);
  94. if (ret == 0) {
  95. NV_INFO(dev, "enabled MSI\n");
  96. dev_priv->msi_enabled = true;
  97. }
  98. }
  99. return drm_irq_install(dev);
  100. }
  101. void
  102. nouveau_irq_fini(struct drm_device *dev)
  103. {
  104. struct drm_nouveau_private *dev_priv = dev->dev_private;
  105. drm_irq_uninstall(dev);
  106. if (dev_priv->msi_enabled)
  107. pci_disable_msi(dev->pdev);
  108. }
  109. void
  110. nouveau_irq_register(struct drm_device *dev, int status_bit,
  111. void (*handler)(struct drm_device *))
  112. {
  113. struct drm_nouveau_private *dev_priv = dev->dev_private;
  114. unsigned long flags;
  115. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  116. dev_priv->irq_handler[status_bit] = handler;
  117. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  118. }
  119. void
  120. nouveau_irq_unregister(struct drm_device *dev, int status_bit)
  121. {
  122. struct drm_nouveau_private *dev_priv = dev->dev_private;
  123. unsigned long flags;
  124. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  125. dev_priv->irq_handler[status_bit] = NULL;
  126. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  127. }