radeon_test.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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/radeon_drm.h>
  26. #include "radeon_reg.h"
  27. #include "radeon.h"
  28. /* Test BO GTT->VRAM and VRAM->GTT GPU copies across the whole GTT aperture */
  29. void radeon_test_moves(struct radeon_device *rdev)
  30. {
  31. struct radeon_object *vram_obj = NULL;
  32. struct radeon_object **gtt_obj = NULL;
  33. struct radeon_fence *fence = NULL;
  34. uint64_t gtt_addr, vram_addr;
  35. unsigned i, n, size;
  36. int r;
  37. size = 1024 * 1024;
  38. /* Number of tests =
  39. * (Total GTT - IB pool - writeback page - ring buffer) / test size
  40. */
  41. n = (rdev->mc.gtt_size - RADEON_IB_POOL_SIZE*64*1024 - 4096 -
  42. rdev->cp.ring_size) / size;
  43. gtt_obj = kzalloc(n * sizeof(*gtt_obj), GFP_KERNEL);
  44. if (!gtt_obj) {
  45. DRM_ERROR("Failed to allocate %d pointers\n", n);
  46. r = 1;
  47. goto out_cleanup;
  48. }
  49. r = radeon_object_create(rdev, NULL, size, true, RADEON_GEM_DOMAIN_VRAM,
  50. false, &vram_obj);
  51. if (r) {
  52. DRM_ERROR("Failed to create VRAM object\n");
  53. goto out_cleanup;
  54. }
  55. r = radeon_object_pin(vram_obj, RADEON_GEM_DOMAIN_VRAM, &vram_addr);
  56. if (r) {
  57. DRM_ERROR("Failed to pin VRAM object\n");
  58. goto out_cleanup;
  59. }
  60. for (i = 0; i < n; i++) {
  61. void *gtt_map, *vram_map;
  62. void **gtt_start, **gtt_end;
  63. void **vram_start, **vram_end;
  64. r = radeon_object_create(rdev, NULL, size, true,
  65. RADEON_GEM_DOMAIN_GTT, false, gtt_obj + i);
  66. if (r) {
  67. DRM_ERROR("Failed to create GTT object %d\n", i);
  68. goto out_cleanup;
  69. }
  70. r = radeon_object_pin(gtt_obj[i], RADEON_GEM_DOMAIN_GTT, &gtt_addr);
  71. if (r) {
  72. DRM_ERROR("Failed to pin GTT object %d\n", i);
  73. goto out_cleanup;
  74. }
  75. r = radeon_object_kmap(gtt_obj[i], &gtt_map);
  76. if (r) {
  77. DRM_ERROR("Failed to map GTT object %d\n", i);
  78. goto out_cleanup;
  79. }
  80. for (gtt_start = gtt_map, gtt_end = gtt_map + size;
  81. gtt_start < gtt_end;
  82. gtt_start++)
  83. *gtt_start = gtt_start;
  84. radeon_object_kunmap(gtt_obj[i]);
  85. r = radeon_fence_create(rdev, &fence);
  86. if (r) {
  87. DRM_ERROR("Failed to create GTT->VRAM fence %d\n", i);
  88. goto out_cleanup;
  89. }
  90. r = radeon_copy(rdev, gtt_addr, vram_addr, size / 4096, fence);
  91. if (r) {
  92. DRM_ERROR("Failed GTT->VRAM copy %d\n", i);
  93. goto out_cleanup;
  94. }
  95. r = radeon_fence_wait(fence, false);
  96. if (r) {
  97. DRM_ERROR("Failed to wait for GTT->VRAM fence %d\n", i);
  98. goto out_cleanup;
  99. }
  100. radeon_fence_unref(&fence);
  101. r = radeon_object_kmap(vram_obj, &vram_map);
  102. if (r) {
  103. DRM_ERROR("Failed to map VRAM object after copy %d\n", i);
  104. goto out_cleanup;
  105. }
  106. for (gtt_start = gtt_map, gtt_end = gtt_map + size,
  107. vram_start = vram_map, vram_end = vram_map + size;
  108. vram_start < vram_end;
  109. gtt_start++, vram_start++) {
  110. if (*vram_start != gtt_start) {
  111. DRM_ERROR("Incorrect GTT->VRAM copy %d: Got 0x%p, "
  112. "expected 0x%p (GTT map 0x%p-0x%p)\n",
  113. i, *vram_start, gtt_start, gtt_map,
  114. gtt_end);
  115. radeon_object_kunmap(vram_obj);
  116. goto out_cleanup;
  117. }
  118. *vram_start = vram_start;
  119. }
  120. radeon_object_kunmap(vram_obj);
  121. r = radeon_fence_create(rdev, &fence);
  122. if (r) {
  123. DRM_ERROR("Failed to create VRAM->GTT fence %d\n", i);
  124. goto out_cleanup;
  125. }
  126. r = radeon_copy(rdev, vram_addr, gtt_addr, size / 4096, fence);
  127. if (r) {
  128. DRM_ERROR("Failed VRAM->GTT copy %d\n", i);
  129. goto out_cleanup;
  130. }
  131. r = radeon_fence_wait(fence, false);
  132. if (r) {
  133. DRM_ERROR("Failed to wait for VRAM->GTT fence %d\n", i);
  134. goto out_cleanup;
  135. }
  136. radeon_fence_unref(&fence);
  137. r = radeon_object_kmap(gtt_obj[i], &gtt_map);
  138. if (r) {
  139. DRM_ERROR("Failed to map GTT object after copy %d\n", i);
  140. goto out_cleanup;
  141. }
  142. for (gtt_start = gtt_map, gtt_end = gtt_map + size,
  143. vram_start = vram_map, vram_end = vram_map + size;
  144. gtt_start < gtt_end;
  145. gtt_start++, vram_start++) {
  146. if (*gtt_start != vram_start) {
  147. DRM_ERROR("Incorrect VRAM->GTT copy %d: Got 0x%p, "
  148. "expected 0x%p (VRAM map 0x%p-0x%p)\n",
  149. i, *gtt_start, vram_start, vram_map,
  150. vram_end);
  151. radeon_object_kunmap(gtt_obj[i]);
  152. goto out_cleanup;
  153. }
  154. }
  155. radeon_object_kunmap(gtt_obj[i]);
  156. DRM_INFO("Tested GTT->VRAM and VRAM->GTT copy for GTT offset 0x%llx\n",
  157. gtt_addr - rdev->mc.gtt_location);
  158. }
  159. out_cleanup:
  160. if (vram_obj) {
  161. radeon_object_unpin(vram_obj);
  162. radeon_object_unref(&vram_obj);
  163. }
  164. if (gtt_obj) {
  165. for (i = 0; i < n; i++) {
  166. if (gtt_obj[i]) {
  167. radeon_object_unpin(gtt_obj[i]);
  168. radeon_object_unref(&gtt_obj[i]);
  169. }
  170. }
  171. kfree(gtt_obj);
  172. }
  173. if (fence) {
  174. radeon_fence_unref(&fence);
  175. }
  176. if (r) {
  177. printk(KERN_WARNING "Error while testing BO move.\n");
  178. }
  179. }