nvc0_software.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright 2012 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_ramht.h"
  27. #include "nouveau_software.h"
  28. #include "nv50_display.h"
  29. struct nvc0_software_priv {
  30. struct nouveau_software_priv base;
  31. };
  32. struct nvc0_software_chan {
  33. struct nouveau_software_chan base;
  34. struct nouveau_vma dispc_vma[4];
  35. };
  36. u64
  37. nvc0_software_crtc(struct nouveau_channel *chan, int crtc)
  38. {
  39. struct nvc0_software_chan *pch = chan->engctx[NVOBJ_ENGINE_SW];
  40. return pch->dispc_vma[crtc].offset;
  41. }
  42. static int
  43. nvc0_software_context_new(struct nouveau_channel *chan, int engine)
  44. {
  45. struct drm_device *dev = chan->dev;
  46. struct drm_nouveau_private *dev_priv = dev->dev_private;
  47. struct nvc0_software_priv *psw = nv_engine(dev, NVOBJ_ENGINE_SW);
  48. struct nvc0_software_chan *pch;
  49. int ret = 0, i;
  50. pch = kzalloc(sizeof(*pch), GFP_KERNEL);
  51. if (!pch)
  52. return -ENOMEM;
  53. nouveau_software_context_new(&pch->base);
  54. chan->engctx[engine] = pch;
  55. /* map display semaphore buffers into channel's vm */
  56. for (i = 0; !ret && i < dev->mode_config.num_crtc; i++) {
  57. struct nouveau_bo *bo;
  58. if (dev_priv->card_type >= NV_D0)
  59. bo = nvd0_display_crtc_sema(dev, i);
  60. else
  61. bo = nv50_display(dev)->crtc[i].sem.bo;
  62. ret = nouveau_bo_vma_add(bo, chan->vm, &pch->dispc_vma[i]);
  63. }
  64. if (ret)
  65. psw->base.base.context_del(chan, engine);
  66. return ret;
  67. }
  68. static void
  69. nvc0_software_context_del(struct nouveau_channel *chan, int engine)
  70. {
  71. struct drm_device *dev = chan->dev;
  72. struct drm_nouveau_private *dev_priv = dev->dev_private;
  73. struct nvc0_software_chan *pch = chan->engctx[engine];
  74. int i;
  75. if (dev_priv->card_type >= NV_D0) {
  76. for (i = 0; i < dev->mode_config.num_crtc; i++) {
  77. struct nouveau_bo *bo = nvd0_display_crtc_sema(dev, i);
  78. nouveau_bo_vma_del(bo, &pch->dispc_vma[i]);
  79. }
  80. } else
  81. if (dev_priv->card_type >= NV_50) {
  82. struct nv50_display *disp = nv50_display(dev);
  83. for (i = 0; i < dev->mode_config.num_crtc; i++) {
  84. struct nv50_display_crtc *dispc = &disp->crtc[i];
  85. nouveau_bo_vma_del(dispc->sem.bo, &pch->dispc_vma[i]);
  86. }
  87. }
  88. chan->engctx[engine] = NULL;
  89. kfree(pch);
  90. }
  91. static int
  92. nvc0_software_object_new(struct nouveau_channel *chan, int engine,
  93. u32 handle, u16 class)
  94. {
  95. return 0;
  96. }
  97. static int
  98. nvc0_software_init(struct drm_device *dev, int engine)
  99. {
  100. return 0;
  101. }
  102. static int
  103. nvc0_software_fini(struct drm_device *dev, int engine, bool suspend)
  104. {
  105. return 0;
  106. }
  107. static void
  108. nvc0_software_destroy(struct drm_device *dev, int engine)
  109. {
  110. struct nvc0_software_priv *psw = nv_engine(dev, engine);
  111. NVOBJ_ENGINE_DEL(dev, SW);
  112. kfree(psw);
  113. }
  114. int
  115. nvc0_software_create(struct drm_device *dev)
  116. {
  117. struct nvc0_software_priv *psw = kzalloc(sizeof(*psw), GFP_KERNEL);
  118. if (!psw)
  119. return -ENOMEM;
  120. psw->base.base.destroy = nvc0_software_destroy;
  121. psw->base.base.init = nvc0_software_init;
  122. psw->base.base.fini = nvc0_software_fini;
  123. psw->base.base.context_new = nvc0_software_context_new;
  124. psw->base.base.context_del = nvc0_software_context_del;
  125. psw->base.base.object_new = nvc0_software_object_new;
  126. nouveau_software_create(&psw->base);
  127. NVOBJ_ENGINE_ADD(dev, SW, &psw->base.base);
  128. NVOBJ_CLASS(dev, 0x906e, SW);
  129. return 0;
  130. }