amdgpu_test.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * Copyright 2009 VMware, 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: Michel Dänzer
  23. */
  24. #include <drm/drmP.h>
  25. #include <drm/amdgpu_drm.h>
  26. #include "amdgpu.h"
  27. #include "amdgpu_uvd.h"
  28. #include "amdgpu_vce.h"
  29. /* Test BO GTT->VRAM and VRAM->GTT GPU copies across the whole GTT aperture */
  30. static void amdgpu_do_test_moves(struct amdgpu_device *adev)
  31. {
  32. struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
  33. struct amdgpu_bo *vram_obj = NULL;
  34. struct amdgpu_bo **gtt_obj = NULL;
  35. uint64_t gart_addr, vram_addr;
  36. unsigned n, size;
  37. int i, r;
  38. size = 1024 * 1024;
  39. /* Number of tests =
  40. * (Total GTT - IB pool - writeback page - ring buffers) / test size
  41. */
  42. n = adev->mc.gart_size - AMDGPU_IB_POOL_SIZE*64*1024;
  43. for (i = 0; i < AMDGPU_MAX_RINGS; ++i)
  44. if (adev->rings[i])
  45. n -= adev->rings[i]->ring_size;
  46. if (adev->wb.wb_obj)
  47. n -= AMDGPU_GPU_PAGE_SIZE;
  48. if (adev->irq.ih.ring_obj)
  49. n -= adev->irq.ih.ring_size;
  50. n /= size;
  51. gtt_obj = kzalloc(n * sizeof(*gtt_obj), GFP_KERNEL);
  52. if (!gtt_obj) {
  53. DRM_ERROR("Failed to allocate %d pointers\n", n);
  54. r = 1;
  55. goto out_cleanup;
  56. }
  57. r = amdgpu_bo_create(adev, size, PAGE_SIZE, true,
  58. AMDGPU_GEM_DOMAIN_VRAM, 0,
  59. NULL, NULL, 0, &vram_obj);
  60. if (r) {
  61. DRM_ERROR("Failed to create VRAM object\n");
  62. goto out_cleanup;
  63. }
  64. r = amdgpu_bo_reserve(vram_obj, false);
  65. if (unlikely(r != 0))
  66. goto out_unref;
  67. r = amdgpu_bo_pin(vram_obj, AMDGPU_GEM_DOMAIN_VRAM, &vram_addr);
  68. if (r) {
  69. DRM_ERROR("Failed to pin VRAM object\n");
  70. goto out_unres;
  71. }
  72. for (i = 0; i < n; i++) {
  73. void *gtt_map, *vram_map;
  74. void **gart_start, **gart_end;
  75. void **vram_start, **vram_end;
  76. struct dma_fence *fence = NULL;
  77. r = amdgpu_bo_create(adev, size, PAGE_SIZE, true,
  78. AMDGPU_GEM_DOMAIN_GTT, 0, NULL,
  79. NULL, 0, gtt_obj + i);
  80. if (r) {
  81. DRM_ERROR("Failed to create GTT object %d\n", i);
  82. goto out_lclean;
  83. }
  84. r = amdgpu_bo_reserve(gtt_obj[i], false);
  85. if (unlikely(r != 0))
  86. goto out_lclean_unref;
  87. r = amdgpu_bo_pin(gtt_obj[i], AMDGPU_GEM_DOMAIN_GTT, &gart_addr);
  88. if (r) {
  89. DRM_ERROR("Failed to pin GTT object %d\n", i);
  90. goto out_lclean_unres;
  91. }
  92. r = amdgpu_bo_kmap(gtt_obj[i], &gtt_map);
  93. if (r) {
  94. DRM_ERROR("Failed to map GTT object %d\n", i);
  95. goto out_lclean_unpin;
  96. }
  97. for (gart_start = gtt_map, gart_end = gtt_map + size;
  98. gart_start < gart_end;
  99. gart_start++)
  100. *gart_start = gart_start;
  101. amdgpu_bo_kunmap(gtt_obj[i]);
  102. r = amdgpu_copy_buffer(ring, gart_addr, vram_addr,
  103. size, NULL, &fence, false, false);
  104. if (r) {
  105. DRM_ERROR("Failed GTT->VRAM copy %d\n", i);
  106. goto out_lclean_unpin;
  107. }
  108. r = dma_fence_wait(fence, false);
  109. if (r) {
  110. DRM_ERROR("Failed to wait for GTT->VRAM fence %d\n", i);
  111. goto out_lclean_unpin;
  112. }
  113. dma_fence_put(fence);
  114. fence = NULL;
  115. r = amdgpu_bo_kmap(vram_obj, &vram_map);
  116. if (r) {
  117. DRM_ERROR("Failed to map VRAM object after copy %d\n", i);
  118. goto out_lclean_unpin;
  119. }
  120. for (gart_start = gtt_map, gart_end = gtt_map + size,
  121. vram_start = vram_map, vram_end = vram_map + size;
  122. vram_start < vram_end;
  123. gart_start++, vram_start++) {
  124. if (*vram_start != gart_start) {
  125. DRM_ERROR("Incorrect GTT->VRAM copy %d: Got 0x%p, "
  126. "expected 0x%p (GTT/VRAM offset "
  127. "0x%16llx/0x%16llx)\n",
  128. i, *vram_start, gart_start,
  129. (unsigned long long)
  130. (gart_addr - adev->mc.gart_start +
  131. (void*)gart_start - gtt_map),
  132. (unsigned long long)
  133. (vram_addr - adev->mc.vram_start +
  134. (void*)gart_start - gtt_map));
  135. amdgpu_bo_kunmap(vram_obj);
  136. goto out_lclean_unpin;
  137. }
  138. *vram_start = vram_start;
  139. }
  140. amdgpu_bo_kunmap(vram_obj);
  141. r = amdgpu_copy_buffer(ring, vram_addr, gart_addr,
  142. size, NULL, &fence, false, false);
  143. if (r) {
  144. DRM_ERROR("Failed VRAM->GTT copy %d\n", i);
  145. goto out_lclean_unpin;
  146. }
  147. r = dma_fence_wait(fence, false);
  148. if (r) {
  149. DRM_ERROR("Failed to wait for VRAM->GTT fence %d\n", i);
  150. goto out_lclean_unpin;
  151. }
  152. dma_fence_put(fence);
  153. fence = NULL;
  154. r = amdgpu_bo_kmap(gtt_obj[i], &gtt_map);
  155. if (r) {
  156. DRM_ERROR("Failed to map GTT object after copy %d\n", i);
  157. goto out_lclean_unpin;
  158. }
  159. for (gart_start = gtt_map, gart_end = gtt_map + size,
  160. vram_start = vram_map, vram_end = vram_map + size;
  161. gart_start < gart_end;
  162. gart_start++, vram_start++) {
  163. if (*gart_start != vram_start) {
  164. DRM_ERROR("Incorrect VRAM->GTT copy %d: Got 0x%p, "
  165. "expected 0x%p (VRAM/GTT offset "
  166. "0x%16llx/0x%16llx)\n",
  167. i, *gart_start, vram_start,
  168. (unsigned long long)
  169. (vram_addr - adev->mc.vram_start +
  170. (void*)vram_start - vram_map),
  171. (unsigned long long)
  172. (gart_addr - adev->mc.gart_start +
  173. (void*)vram_start - vram_map));
  174. amdgpu_bo_kunmap(gtt_obj[i]);
  175. goto out_lclean_unpin;
  176. }
  177. }
  178. amdgpu_bo_kunmap(gtt_obj[i]);
  179. DRM_INFO("Tested GTT->VRAM and VRAM->GTT copy for GTT offset 0x%llx\n",
  180. gart_addr - adev->mc.gart_start);
  181. continue;
  182. out_lclean_unpin:
  183. amdgpu_bo_unpin(gtt_obj[i]);
  184. out_lclean_unres:
  185. amdgpu_bo_unreserve(gtt_obj[i]);
  186. out_lclean_unref:
  187. amdgpu_bo_unref(&gtt_obj[i]);
  188. out_lclean:
  189. for (--i; i >= 0; --i) {
  190. amdgpu_bo_unpin(gtt_obj[i]);
  191. amdgpu_bo_unreserve(gtt_obj[i]);
  192. amdgpu_bo_unref(&gtt_obj[i]);
  193. }
  194. if (fence)
  195. dma_fence_put(fence);
  196. break;
  197. }
  198. amdgpu_bo_unpin(vram_obj);
  199. out_unres:
  200. amdgpu_bo_unreserve(vram_obj);
  201. out_unref:
  202. amdgpu_bo_unref(&vram_obj);
  203. out_cleanup:
  204. kfree(gtt_obj);
  205. if (r) {
  206. pr_warn("Error while testing BO move\n");
  207. }
  208. }
  209. void amdgpu_test_moves(struct amdgpu_device *adev)
  210. {
  211. if (adev->mman.buffer_funcs)
  212. amdgpu_do_test_moves(adev);
  213. }