nouveau_irq.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. /* Master disable */
  42. nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
  43. }
  44. int
  45. nouveau_irq_postinstall(struct drm_device *dev)
  46. {
  47. struct drm_nouveau_private *dev_priv = dev->dev_private;
  48. /* Master enable */
  49. nv_wr32(dev, NV03_PMC_INTR_EN_0, NV_PMC_INTR_EN_0_MASTER_ENABLE);
  50. if (dev_priv->msi_enabled)
  51. nv_wr08(dev, 0x00088068, 0xff);
  52. return 0;
  53. }
  54. void
  55. nouveau_irq_uninstall(struct drm_device *dev)
  56. {
  57. /* Master disable */
  58. nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
  59. }
  60. irqreturn_t
  61. nouveau_irq_handler(DRM_IRQ_ARGS)
  62. {
  63. struct drm_device *dev = (struct drm_device *)arg;
  64. struct drm_nouveau_private *dev_priv = dev->dev_private;
  65. unsigned long flags;
  66. u32 stat;
  67. int i;
  68. stat = nv_rd32(dev, NV03_PMC_INTR_0);
  69. if (stat == 0 || stat == ~0)
  70. return IRQ_NONE;
  71. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  72. for (i = 0; i < 32 && stat; i++) {
  73. if (!(stat & (1 << i)) || !dev_priv->irq_handler[i])
  74. continue;
  75. dev_priv->irq_handler[i](dev);
  76. stat &= ~(1 << i);
  77. }
  78. if (dev_priv->msi_enabled)
  79. nv_wr08(dev, 0x00088068, 0xff);
  80. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  81. if (stat && nouveau_ratelimit())
  82. NV_ERROR(dev, "PMC - unhandled INTR 0x%08x\n", stat);
  83. return IRQ_HANDLED;
  84. }
  85. int
  86. nouveau_irq_init(struct drm_device *dev)
  87. {
  88. struct drm_nouveau_private *dev_priv = dev->dev_private;
  89. int ret;
  90. if (nouveau_msi != 0 && dev_priv->card_type >= NV_50) {
  91. ret = pci_enable_msi(dev->pdev);
  92. if (ret == 0) {
  93. NV_INFO(dev, "enabled MSI\n");
  94. dev_priv->msi_enabled = true;
  95. }
  96. }
  97. return drm_irq_install(dev);
  98. }
  99. void
  100. nouveau_irq_fini(struct drm_device *dev)
  101. {
  102. struct drm_nouveau_private *dev_priv = dev->dev_private;
  103. drm_irq_uninstall(dev);
  104. if (dev_priv->msi_enabled)
  105. pci_disable_msi(dev->pdev);
  106. }
  107. void
  108. nouveau_irq_register(struct drm_device *dev, int status_bit,
  109. void (*handler)(struct drm_device *))
  110. {
  111. struct drm_nouveau_private *dev_priv = dev->dev_private;
  112. unsigned long flags;
  113. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  114. dev_priv->irq_handler[status_bit] = handler;
  115. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  116. }
  117. void
  118. nouveau_irq_unregister(struct drm_device *dev, int status_bit)
  119. {
  120. struct drm_nouveau_private *dev_priv = dev->dev_private;
  121. unsigned long flags;
  122. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  123. dev_priv->irq_handler[status_bit] = NULL;
  124. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  125. }