nvc0_fence.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/client.h>
  26. #include <core/class.h>
  27. #include <engine/fifo.h>
  28. #include "nouveau_drm.h"
  29. #include "nouveau_dma.h"
  30. #include "nouveau_fence.h"
  31. #include "nv50_display.h"
  32. static int
  33. nvc0_fence_emit(struct nouveau_fence *fence)
  34. {
  35. struct nouveau_channel *chan = fence->channel;
  36. struct nv84_fence_chan *fctx = chan->fence;
  37. struct nouveau_fifo_chan *fifo = (void *)chan->object;
  38. u64 addr = fctx->vma.offset + fifo->chid * 16;
  39. int ret;
  40. ret = RING_SPACE(chan, 6);
  41. if (ret == 0) {
  42. BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 5);
  43. OUT_RING (chan, upper_32_bits(addr));
  44. OUT_RING (chan, lower_32_bits(addr));
  45. OUT_RING (chan, fence->sequence);
  46. OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
  47. OUT_RING (chan, 0x00000000);
  48. FIRE_RING (chan);
  49. }
  50. return ret;
  51. }
  52. static int
  53. nvc0_fence_sync(struct nouveau_fence *fence,
  54. struct nouveau_channel *prev, struct nouveau_channel *chan)
  55. {
  56. struct nv84_fence_chan *fctx = chan->fence;
  57. struct nouveau_fifo_chan *fifo = (void *)prev->object;
  58. u64 addr = fctx->vma.offset + fifo->chid * 16;
  59. int ret;
  60. ret = RING_SPACE(chan, 5);
  61. if (ret == 0) {
  62. BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
  63. OUT_RING (chan, upper_32_bits(addr));
  64. OUT_RING (chan, lower_32_bits(addr));
  65. OUT_RING (chan, fence->sequence);
  66. OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL |
  67. NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
  68. FIRE_RING (chan);
  69. }
  70. return ret;
  71. }
  72. int
  73. nvc0_fence_create(struct nouveau_drm *drm)
  74. {
  75. struct nouveau_fifo *pfifo = nouveau_fifo(drm->device);
  76. struct nv84_fence_priv *priv;
  77. int ret;
  78. priv = drm->fence = kzalloc(sizeof(*priv), GFP_KERNEL);
  79. if (!priv)
  80. return -ENOMEM;
  81. priv->base.dtor = nv84_fence_destroy;
  82. priv->base.suspend = nv84_fence_suspend;
  83. priv->base.resume = nv84_fence_resume;
  84. priv->base.context_new = nv84_fence_context_new;
  85. priv->base.context_del = nv84_fence_context_del;
  86. priv->base.emit = nvc0_fence_emit;
  87. priv->base.sync = nvc0_fence_sync;
  88. priv->base.read = nv84_fence_read;
  89. init_waitqueue_head(&priv->base.waiting);
  90. priv->base.uevent = true;
  91. ret = nouveau_bo_new(drm->dev, 16 * (pfifo->max + 1), 0,
  92. TTM_PL_FLAG_VRAM, 0, 0, NULL, &priv->bo);
  93. if (ret == 0) {
  94. ret = nouveau_bo_pin(priv->bo, TTM_PL_FLAG_VRAM);
  95. if (ret == 0) {
  96. ret = nouveau_bo_map(priv->bo);
  97. if (ret)
  98. nouveau_bo_unpin(priv->bo);
  99. }
  100. if (ret)
  101. nouveau_bo_ref(NULL, &priv->bo);
  102. }
  103. if (ret)
  104. nv84_fence_destroy(drm);
  105. return ret;
  106. }