nv84_fence.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 <core/object.h>
  25. #include <core/class.h>
  26. #include <engine/fifo.h>
  27. #include "nouveau_drm.h"
  28. #include "nouveau_dma.h"
  29. #include "nouveau_fence.h"
  30. #include "nv50_display.h"
  31. struct nv84_fence_chan {
  32. struct nouveau_fence_chan base;
  33. };
  34. struct nv84_fence_priv {
  35. struct nouveau_fence_priv base;
  36. struct nouveau_gpuobj *mem;
  37. };
  38. static int
  39. nv84_fence_emit(struct nouveau_fence *fence)
  40. {
  41. struct nouveau_channel *chan = fence->channel;
  42. struct nouveau_fifo_chan *fifo = (void *)chan->object;
  43. int ret = RING_SPACE(chan, 7);
  44. if (ret == 0) {
  45. BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
  46. OUT_RING (chan, NvSema);
  47. BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
  48. OUT_RING (chan, upper_32_bits(fifo->chid * 16));
  49. OUT_RING (chan, lower_32_bits(fifo->chid * 16));
  50. OUT_RING (chan, fence->sequence);
  51. OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
  52. FIRE_RING (chan);
  53. }
  54. return ret;
  55. }
  56. static int
  57. nv84_fence_sync(struct nouveau_fence *fence,
  58. struct nouveau_channel *prev, struct nouveau_channel *chan)
  59. {
  60. struct nouveau_fifo_chan *fifo = (void *)prev->object;
  61. int ret = RING_SPACE(chan, 7);
  62. if (ret == 0) {
  63. BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
  64. OUT_RING (chan, NvSema);
  65. BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
  66. OUT_RING (chan, upper_32_bits(fifo->chid * 16));
  67. OUT_RING (chan, lower_32_bits(fifo->chid * 16));
  68. OUT_RING (chan, fence->sequence);
  69. OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL);
  70. FIRE_RING (chan);
  71. }
  72. return ret;
  73. }
  74. static u32
  75. nv84_fence_read(struct nouveau_channel *chan)
  76. {
  77. struct nouveau_fifo_chan *fifo = (void *)chan->object;
  78. struct nv84_fence_priv *priv = chan->drm->fence;
  79. return nv_ro32(priv->mem, fifo->chid * 16);
  80. }
  81. static void
  82. nv84_fence_context_del(struct nouveau_channel *chan)
  83. {
  84. struct nv84_fence_chan *fctx = chan->fence;
  85. nouveau_fence_context_del(&fctx->base);
  86. chan->fence = NULL;
  87. kfree(fctx);
  88. }
  89. static int
  90. nv84_fence_context_new(struct nouveau_channel *chan)
  91. {
  92. struct drm_device *dev = chan->drm->dev;
  93. struct nouveau_fifo_chan *fifo = (void *)chan->object;
  94. struct nv84_fence_priv *priv = chan->drm->fence;
  95. struct nv84_fence_chan *fctx;
  96. struct nouveau_object *object;
  97. int ret, i;
  98. fctx = chan->fence = kzalloc(sizeof(*fctx), GFP_KERNEL);
  99. if (!fctx)
  100. return -ENOMEM;
  101. nouveau_fence_context_new(&fctx->base);
  102. ret = nouveau_object_new(nv_object(chan->cli), chan->handle,
  103. NvSema, 0x0002,
  104. &(struct nv_dma_class) {
  105. .flags = NV_DMA_TARGET_VRAM |
  106. NV_DMA_ACCESS_RDWR,
  107. .start = priv->mem->addr,
  108. .limit = priv->mem->addr +
  109. priv->mem->size - 1,
  110. }, sizeof(struct nv_dma_class),
  111. &object);
  112. /* dma objects for display sync channel semaphore blocks */
  113. for (i = 0; !ret && i < dev->mode_config.num_crtc; i++) {
  114. struct nouveau_bo *bo = nv50_display_crtc_sema(dev, i);
  115. ret = nouveau_object_new(nv_object(chan->cli), chan->handle,
  116. NvEvoSema0 + i, 0x003d,
  117. &(struct nv_dma_class) {
  118. .flags = NV_DMA_TARGET_VRAM |
  119. NV_DMA_ACCESS_RDWR,
  120. .start = bo->bo.offset,
  121. .limit = bo->bo.offset + 0xfff,
  122. }, sizeof(struct nv_dma_class),
  123. &object);
  124. }
  125. if (ret)
  126. nv84_fence_context_del(chan);
  127. nv_wo32(priv->mem, fifo->chid * 16, 0x00000000);
  128. return ret;
  129. }
  130. static void
  131. nv84_fence_destroy(struct nouveau_drm *drm)
  132. {
  133. struct nv84_fence_priv *priv = drm->fence;
  134. nouveau_gpuobj_ref(NULL, &priv->mem);
  135. drm->fence = NULL;
  136. kfree(priv);
  137. }
  138. int
  139. nv84_fence_create(struct nouveau_drm *drm)
  140. {
  141. struct nouveau_fifo *pfifo = nouveau_fifo(drm->device);
  142. struct nv84_fence_priv *priv;
  143. u32 chan = pfifo->max + 1;
  144. int ret;
  145. priv = drm->fence = kzalloc(sizeof(*priv), GFP_KERNEL);
  146. if (!priv)
  147. return -ENOMEM;
  148. priv->base.dtor = nv84_fence_destroy;
  149. priv->base.context_new = nv84_fence_context_new;
  150. priv->base.context_del = nv84_fence_context_del;
  151. priv->base.emit = nv84_fence_emit;
  152. priv->base.sync = nv84_fence_sync;
  153. priv->base.read = nv84_fence_read;
  154. ret = nouveau_gpuobj_new(drm->device, NULL, chan * 16, 0x1000, 0,
  155. &priv->mem);
  156. if (ret)
  157. nv84_fence_destroy(drm);
  158. return ret;
  159. }