nvc0_fb.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright 2011 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs
  23. */
  24. #include "drmP.h"
  25. #include "nouveau_drv.h"
  26. #include "nouveau_drm.h"
  27. struct nvc0_fb_priv {
  28. struct page *r100c10_page;
  29. dma_addr_t r100c10;
  30. };
  31. static inline void
  32. nvc0_mfb_subp_isr(struct drm_device *dev, int unit, int subp)
  33. {
  34. u32 subp_base = 0x141000 + (unit * 0x2000) + (subp * 0x400);
  35. u32 stat = nv_rd32(dev, subp_base + 0x020);
  36. if (stat) {
  37. NV_INFO(dev, "PMFB%d_SUBP%d: 0x%08x\n", unit, subp, stat);
  38. nv_wr32(dev, subp_base + 0x020, stat);
  39. }
  40. }
  41. static void
  42. nvc0_mfb_isr(struct drm_device *dev)
  43. {
  44. u32 units = nv_rd32(dev, 0x00017c);
  45. while (units) {
  46. u32 subp, unit = ffs(units) - 1;
  47. for (subp = 0; subp < 2; subp++)
  48. nvc0_mfb_subp_isr(dev, unit, subp);
  49. units &= ~(1 << unit);
  50. }
  51. /* we do something horribly wrong and upset PMFB a lot, so mask off
  52. * interrupts from it after the first one until it's fixed
  53. */
  54. nv_mask(dev, 0x000640, 0x02000000, 0x00000000);
  55. }
  56. static void
  57. nvc0_fb_destroy(struct drm_device *dev)
  58. {
  59. struct drm_nouveau_private *dev_priv = dev->dev_private;
  60. struct nouveau_fb_engine *pfb = &dev_priv->engine.fb;
  61. struct nvc0_fb_priv *priv = pfb->priv;
  62. nouveau_irq_unregister(dev, 25);
  63. if (priv->r100c10_page) {
  64. pci_unmap_page(dev->pdev, priv->r100c10, PAGE_SIZE,
  65. PCI_DMA_BIDIRECTIONAL);
  66. __free_page(priv->r100c10_page);
  67. }
  68. kfree(priv);
  69. pfb->priv = NULL;
  70. }
  71. static int
  72. nvc0_fb_create(struct drm_device *dev)
  73. {
  74. struct drm_nouveau_private *dev_priv = dev->dev_private;
  75. struct nouveau_fb_engine *pfb = &dev_priv->engine.fb;
  76. struct nvc0_fb_priv *priv;
  77. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  78. if (!priv)
  79. return -ENOMEM;
  80. pfb->priv = priv;
  81. priv->r100c10_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
  82. if (!priv->r100c10_page) {
  83. nvc0_fb_destroy(dev);
  84. return -ENOMEM;
  85. }
  86. priv->r100c10 = pci_map_page(dev->pdev, priv->r100c10_page, 0,
  87. PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
  88. if (pci_dma_mapping_error(dev->pdev, priv->r100c10)) {
  89. nvc0_fb_destroy(dev);
  90. return -EFAULT;
  91. }
  92. nouveau_irq_register(dev, 25, nvc0_mfb_isr);
  93. return 0;
  94. }
  95. int
  96. nvc0_fb_init(struct drm_device *dev)
  97. {
  98. struct drm_nouveau_private *dev_priv = dev->dev_private;
  99. struct nvc0_fb_priv *priv;
  100. int ret;
  101. if (!dev_priv->engine.fb.priv) {
  102. ret = nvc0_fb_create(dev);
  103. if (ret)
  104. return ret;
  105. }
  106. priv = dev_priv->engine.fb.priv;
  107. nv_wr32(dev, 0x100c10, priv->r100c10 >> 8);
  108. nv_mask(dev, 0x17e820, 0x00100000, 0x00000000); /* NV_PLTCG_INTR_EN */
  109. return 0;
  110. }
  111. void
  112. nvc0_fb_takedown(struct drm_device *dev)
  113. {
  114. nvc0_fb_destroy(dev);
  115. }