rv770_dma.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 2013 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 "rv770d.h"
  27. /**
  28. * rv770_copy_dma - copy pages using the DMA engine
  29. *
  30. * @rdev: radeon_device pointer
  31. * @src_offset: src GPU address
  32. * @dst_offset: dst GPU address
  33. * @num_gpu_pages: number of GPU pages to xfer
  34. * @resv: reservation object to sync to
  35. *
  36. * Copy GPU paging using the DMA engine (r7xx).
  37. * Used by the radeon ttm implementation to move pages if
  38. * registered as the asic copy callback.
  39. */
  40. struct radeon_fence *rv770_copy_dma(struct radeon_device *rdev,
  41. uint64_t src_offset, uint64_t dst_offset,
  42. unsigned num_gpu_pages,
  43. struct dma_resv *resv)
  44. {
  45. struct radeon_fence *fence;
  46. struct radeon_sync sync;
  47. int ring_index = rdev->asic->copy.dma_ring_index;
  48. struct radeon_ring *ring = &rdev->ring[ring_index];
  49. u32 size_in_dw, cur_size_in_dw;
  50. int i, num_loops;
  51. int r = 0;
  52. radeon_sync_create(&sync);
  53. size_in_dw = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT) / 4;
  54. num_loops = DIV_ROUND_UP(size_in_dw, 0xFFFF);
  55. r = radeon_ring_lock(rdev, ring, num_loops * 5 + 8);
  56. if (r) {
  57. DRM_ERROR("radeon: moving bo (%d).\n", r);
  58. radeon_sync_free(rdev, &sync, NULL);
  59. return ERR_PTR(r);
  60. }
  61. radeon_sync_resv(rdev, &sync, resv, false);
  62. radeon_sync_rings(rdev, &sync, ring->idx);
  63. for (i = 0; i < num_loops; i++) {
  64. cur_size_in_dw = size_in_dw;
  65. if (cur_size_in_dw > 0xFFFF)
  66. cur_size_in_dw = 0xFFFF;
  67. size_in_dw -= cur_size_in_dw;
  68. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 0, 0, cur_size_in_dw));
  69. radeon_ring_write(ring, dst_offset & 0xfffffffc);
  70. radeon_ring_write(ring, src_offset & 0xfffffffc);
  71. radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff);
  72. radeon_ring_write(ring, upper_32_bits(src_offset) & 0xff);
  73. src_offset += cur_size_in_dw * 4;
  74. dst_offset += cur_size_in_dw * 4;
  75. }
  76. r = radeon_fence_emit(rdev, &fence, ring->idx);
  77. if (r) {
  78. radeon_ring_unlock_undo(rdev, ring);
  79. radeon_sync_free(rdev, &sync, NULL);
  80. return ERR_PTR(r);
  81. }
  82. radeon_ring_unlock_commit(rdev, ring, false);
  83. radeon_sync_free(rdev, &sync, fence);
  84. return fence;
  85. }