evergreen_dma.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright 2010 Advanced Micro Devices, 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: Alex Deucher
  23. */
  24. #include "radeon.h"
  25. #include "radeon_asic.h"
  26. #include "evergreen.h"
  27. #include "evergreend.h"
  28. /**
  29. * evergreen_dma_fence_ring_emit - emit a fence on the DMA ring
  30. *
  31. * @rdev: radeon_device pointer
  32. * @fence: radeon fence object
  33. *
  34. * Add a DMA fence packet to the ring to write
  35. * the fence seq number and DMA trap packet to generate
  36. * an interrupt if needed (evergreen-SI).
  37. */
  38. void evergreen_dma_fence_ring_emit(struct radeon_device *rdev,
  39. struct radeon_fence *fence)
  40. {
  41. struct radeon_ring *ring = &rdev->ring[fence->ring];
  42. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  43. /* write the fence */
  44. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_FENCE, 0, 0));
  45. radeon_ring_write(ring, addr & 0xfffffffc);
  46. radeon_ring_write(ring, (upper_32_bits(addr) & 0xff));
  47. radeon_ring_write(ring, fence->seq);
  48. /* generate an interrupt */
  49. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_TRAP, 0, 0));
  50. /* flush HDP */
  51. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0));
  52. radeon_ring_write(ring, (0xf << 16) | (HDP_MEM_COHERENCY_FLUSH_CNTL >> 2));
  53. radeon_ring_write(ring, 1);
  54. }
  55. /**
  56. * evergreen_dma_ring_ib_execute - schedule an IB on the DMA engine
  57. *
  58. * @rdev: radeon_device pointer
  59. * @ib: IB object to schedule
  60. *
  61. * Schedule an IB in the DMA ring (evergreen).
  62. */
  63. void evergreen_dma_ring_ib_execute(struct radeon_device *rdev,
  64. struct radeon_ib *ib)
  65. {
  66. struct radeon_ring *ring = &rdev->ring[ib->ring];
  67. if (rdev->wb.enabled) {
  68. u32 next_rptr = ring->wptr + 4;
  69. while ((next_rptr & 7) != 5)
  70. next_rptr++;
  71. next_rptr += 3;
  72. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_WRITE, 0, 1));
  73. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  74. radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xff);
  75. radeon_ring_write(ring, next_rptr);
  76. }
  77. /* The indirect buffer packet must end on an 8 DW boundary in the DMA ring.
  78. * Pad as necessary with NOPs.
  79. */
  80. while ((ring->wptr & 7) != 5)
  81. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_NOP, 0, 0));
  82. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_INDIRECT_BUFFER, 0, 0));
  83. radeon_ring_write(ring, (ib->gpu_addr & 0xFFFFFFE0));
  84. radeon_ring_write(ring, (ib->length_dw << 12) | (upper_32_bits(ib->gpu_addr) & 0xFF));
  85. }
  86. /**
  87. * evergreen_copy_dma - copy pages using the DMA engine
  88. *
  89. * @rdev: radeon_device pointer
  90. * @src_offset: src GPU address
  91. * @dst_offset: dst GPU address
  92. * @num_gpu_pages: number of GPU pages to xfer
  93. * @resv: reservation object with embedded fence
  94. *
  95. * Copy GPU paging using the DMA engine (evergreen-cayman).
  96. * Used by the radeon ttm implementation to move pages if
  97. * registered as the asic copy callback.
  98. */
  99. struct radeon_fence *evergreen_copy_dma(struct radeon_device *rdev,
  100. uint64_t src_offset,
  101. uint64_t dst_offset,
  102. unsigned num_gpu_pages,
  103. struct dma_resv *resv)
  104. {
  105. struct radeon_fence *fence;
  106. struct radeon_sync sync;
  107. int ring_index = rdev->asic->copy.dma_ring_index;
  108. struct radeon_ring *ring = &rdev->ring[ring_index];
  109. u32 size_in_dw, cur_size_in_dw;
  110. int i, num_loops;
  111. int r = 0;
  112. radeon_sync_create(&sync);
  113. size_in_dw = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT) / 4;
  114. num_loops = DIV_ROUND_UP(size_in_dw, 0xfffff);
  115. r = radeon_ring_lock(rdev, ring, num_loops * 5 + 11);
  116. if (r) {
  117. DRM_ERROR("radeon: moving bo (%d).\n", r);
  118. radeon_sync_free(rdev, &sync, NULL);
  119. return ERR_PTR(r);
  120. }
  121. radeon_sync_resv(rdev, &sync, resv, false);
  122. radeon_sync_rings(rdev, &sync, ring->idx);
  123. for (i = 0; i < num_loops; i++) {
  124. cur_size_in_dw = size_in_dw;
  125. if (cur_size_in_dw > 0xFFFFF)
  126. cur_size_in_dw = 0xFFFFF;
  127. size_in_dw -= cur_size_in_dw;
  128. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 0, cur_size_in_dw));
  129. radeon_ring_write(ring, dst_offset & 0xfffffffc);
  130. radeon_ring_write(ring, src_offset & 0xfffffffc);
  131. radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff);
  132. radeon_ring_write(ring, upper_32_bits(src_offset) & 0xff);
  133. src_offset += cur_size_in_dw * 4;
  134. dst_offset += cur_size_in_dw * 4;
  135. }
  136. r = radeon_fence_emit(rdev, &fence, ring->idx);
  137. if (r) {
  138. radeon_ring_unlock_undo(rdev, ring);
  139. radeon_sync_free(rdev, &sync, NULL);
  140. return ERR_PTR(r);
  141. }
  142. radeon_ring_unlock_commit(rdev, ring, false);
  143. radeon_sync_free(rdev, &sync, fence);
  144. return fence;
  145. }
  146. /**
  147. * evergreen_dma_is_lockup - Check if the DMA engine is locked up
  148. *
  149. * @rdev: radeon_device pointer
  150. * @ring: radeon_ring structure holding ring information
  151. *
  152. * Check if the async DMA engine is locked up.
  153. * Returns true if the engine appears to be locked up, false if not.
  154. */
  155. bool evergreen_dma_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  156. {
  157. u32 reset_mask = evergreen_gpu_check_soft_reset(rdev);
  158. if (!(reset_mask & RADEON_RESET_DMA)) {
  159. radeon_ring_lockup_update(rdev, ring);
  160. return false;
  161. }
  162. return radeon_ring_test_lockup(rdev, ring);
  163. }