2 * Copyright 2009 VMware, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
22 * Authors: Michel Dänzer
25 #include <drm/radeon_drm.h>
26 #include "radeon_reg.h"
30 /* Test BO GTT->VRAM and VRAM->GTT GPU copies across the whole GTT aperture */
31 void radeon_test_moves(struct radeon_device *rdev)
33 struct radeon_object *vram_obj = NULL;
34 struct radeon_object **gtt_obj = NULL;
35 struct radeon_fence *fence = NULL;
36 uint64_t gtt_addr, vram_addr;
43 * (Total GTT - IB pool - writeback page - ring buffer) / test size
45 n = (rdev->mc.gtt_size - RADEON_IB_POOL_SIZE*64*1024 - 4096 -
46 rdev->cp.ring_size) / size;
48 gtt_obj = kzalloc(n * sizeof(*gtt_obj), GFP_KERNEL);
50 DRM_ERROR("Failed to allocate %d pointers\n", n);
55 r = radeon_object_create(rdev, NULL, size, true, RADEON_GEM_DOMAIN_VRAM,
58 DRM_ERROR("Failed to create VRAM object\n");
62 r = radeon_object_pin(vram_obj, RADEON_GEM_DOMAIN_VRAM, &vram_addr);
64 DRM_ERROR("Failed to pin VRAM object\n");
68 for (i = 0; i < n; i++) {
69 void *gtt_map, *vram_map;
70 void **gtt_start, **gtt_end;
71 void **vram_start, **vram_end;
73 r = radeon_object_create(rdev, NULL, size, true,
74 RADEON_GEM_DOMAIN_GTT, false, gtt_obj + i);
76 DRM_ERROR("Failed to create GTT object %d\n", i);
80 r = radeon_object_pin(gtt_obj[i], RADEON_GEM_DOMAIN_GTT, >t_addr);
82 DRM_ERROR("Failed to pin GTT object %d\n", i);
86 r = radeon_object_kmap(gtt_obj[i], >t_map);
88 DRM_ERROR("Failed to map GTT object %d\n", i);
92 for (gtt_start = gtt_map, gtt_end = gtt_map + size;
95 *gtt_start = gtt_start;
97 radeon_object_kunmap(gtt_obj[i]);
99 r = radeon_fence_create(rdev, &fence);
101 DRM_ERROR("Failed to create GTT->VRAM fence %d\n", i);
105 r = radeon_copy(rdev, gtt_addr, vram_addr, size / 4096, fence);
107 DRM_ERROR("Failed GTT->VRAM copy %d\n", i);
111 r = radeon_fence_wait(fence, false);
113 DRM_ERROR("Failed to wait for GTT->VRAM fence %d\n", i);
117 radeon_fence_unref(&fence);
119 r = radeon_object_kmap(vram_obj, &vram_map);
121 DRM_ERROR("Failed to map VRAM object after copy %d\n", i);
125 for (gtt_start = gtt_map, gtt_end = gtt_map + size,
126 vram_start = vram_map, vram_end = vram_map + size;
127 vram_start < vram_end;
128 gtt_start++, vram_start++) {
129 if (*vram_start != gtt_start) {
130 DRM_ERROR("Incorrect GTT->VRAM copy %d: Got 0x%p, "
131 "expected 0x%p (GTT map 0x%p-0x%p)\n",
132 i, *vram_start, gtt_start, gtt_map,
134 radeon_object_kunmap(vram_obj);
137 *vram_start = vram_start;
140 radeon_object_kunmap(vram_obj);
142 r = radeon_fence_create(rdev, &fence);
144 DRM_ERROR("Failed to create VRAM->GTT fence %d\n", i);
148 r = radeon_copy(rdev, vram_addr, gtt_addr, size / 4096, fence);
150 DRM_ERROR("Failed VRAM->GTT copy %d\n", i);
154 r = radeon_fence_wait(fence, false);
156 DRM_ERROR("Failed to wait for VRAM->GTT fence %d\n", i);
160 radeon_fence_unref(&fence);
162 r = radeon_object_kmap(gtt_obj[i], >t_map);
164 DRM_ERROR("Failed to map GTT object after copy %d\n", i);
168 for (gtt_start = gtt_map, gtt_end = gtt_map + size,
169 vram_start = vram_map, vram_end = vram_map + size;
171 gtt_start++, vram_start++) {
172 if (*gtt_start != vram_start) {
173 DRM_ERROR("Incorrect VRAM->GTT copy %d: Got 0x%p, "
174 "expected 0x%p (VRAM map 0x%p-0x%p)\n",
175 i, *gtt_start, vram_start, vram_map,
177 radeon_object_kunmap(gtt_obj[i]);
182 radeon_object_kunmap(gtt_obj[i]);
184 DRM_INFO("Tested GTT->VRAM and VRAM->GTT copy for GTT offset 0x%llx\n",
185 gtt_addr - rdev->mc.gtt_location);
190 radeon_object_unpin(vram_obj);
191 radeon_object_unref(&vram_obj);
194 for (i = 0; i < n; i++) {
196 radeon_object_unpin(gtt_obj[i]);
197 radeon_object_unref(>t_obj[i]);
203 radeon_fence_unref(&fence);
206 printk(KERN_WARNING "Error while testing BO move.\n");