rv770_dma.c 3.3 KB

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