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_bo *vram_obj = NULL;
34 struct radeon_bo **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 = ((u32)(rdev->mc.gtt_size - RADEON_IB_POOL_SIZE*64*1024 - RADEON_GPU_PAGE_SIZE -
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_bo_create(rdev, NULL, size, true, RADEON_GEM_DOMAIN_VRAM,
58 DRM_ERROR("Failed to create VRAM object\n");
61 r = radeon_bo_reserve(vram_obj, false);
64 r = radeon_bo_pin(vram_obj, RADEON_GEM_DOMAIN_VRAM, &vram_addr);
66 DRM_ERROR("Failed to pin VRAM object\n");
69 for (i = 0; i < n; i++) {
70 void *gtt_map, *vram_map;
71 void **gtt_start, **gtt_end;
72 void **vram_start, **vram_end;
74 r = radeon_bo_create(rdev, NULL, size, true,
75 RADEON_GEM_DOMAIN_GTT, gtt_obj + i);
77 DRM_ERROR("Failed to create GTT object %d\n", i);
81 r = radeon_bo_reserve(gtt_obj[i], false);
84 r = radeon_bo_pin(gtt_obj[i], RADEON_GEM_DOMAIN_GTT, >t_addr);
86 DRM_ERROR("Failed to pin GTT object %d\n", i);
90 r = radeon_bo_kmap(gtt_obj[i], >t_map);
92 DRM_ERROR("Failed to map GTT object %d\n", i);
96 for (gtt_start = gtt_map, gtt_end = gtt_map + size;
99 *gtt_start = gtt_start;
101 radeon_bo_kunmap(gtt_obj[i]);
103 r = radeon_fence_create(rdev, &fence);
105 DRM_ERROR("Failed to create GTT->VRAM fence %d\n", i);
109 r = radeon_copy(rdev, gtt_addr, vram_addr, size / RADEON_GPU_PAGE_SIZE, fence);
111 DRM_ERROR("Failed GTT->VRAM copy %d\n", i);
115 r = radeon_fence_wait(fence, false);
117 DRM_ERROR("Failed to wait for GTT->VRAM fence %d\n", i);
121 radeon_fence_unref(&fence);
123 r = radeon_bo_kmap(vram_obj, &vram_map);
125 DRM_ERROR("Failed to map VRAM object after copy %d\n", i);
129 for (gtt_start = gtt_map, gtt_end = gtt_map + size,
130 vram_start = vram_map, vram_end = vram_map + size;
131 vram_start < vram_end;
132 gtt_start++, vram_start++) {
133 if (*vram_start != gtt_start) {
134 DRM_ERROR("Incorrect GTT->VRAM copy %d: Got 0x%p, "
135 "expected 0x%p (GTT map 0x%p-0x%p)\n",
136 i, *vram_start, gtt_start, gtt_map,
138 radeon_bo_kunmap(vram_obj);
141 *vram_start = vram_start;
144 radeon_bo_kunmap(vram_obj);
146 r = radeon_fence_create(rdev, &fence);
148 DRM_ERROR("Failed to create VRAM->GTT fence %d\n", i);
152 r = radeon_copy(rdev, vram_addr, gtt_addr, size / RADEON_GPU_PAGE_SIZE, fence);
154 DRM_ERROR("Failed VRAM->GTT copy %d\n", i);
158 r = radeon_fence_wait(fence, false);
160 DRM_ERROR("Failed to wait for VRAM->GTT fence %d\n", i);
164 radeon_fence_unref(&fence);
166 r = radeon_bo_kmap(gtt_obj[i], >t_map);
168 DRM_ERROR("Failed to map GTT object after copy %d\n", i);
172 for (gtt_start = gtt_map, gtt_end = gtt_map + size,
173 vram_start = vram_map, vram_end = vram_map + size;
175 gtt_start++, vram_start++) {
176 if (*gtt_start != vram_start) {
177 DRM_ERROR("Incorrect VRAM->GTT copy %d: Got 0x%p, "
178 "expected 0x%p (VRAM map 0x%p-0x%p)\n",
179 i, *gtt_start, vram_start, vram_map,
181 radeon_bo_kunmap(gtt_obj[i]);
186 radeon_bo_kunmap(gtt_obj[i]);
188 DRM_INFO("Tested GTT->VRAM and VRAM->GTT copy for GTT offset 0x%llx\n",
189 gtt_addr - rdev->mc.gtt_start);
194 if (radeon_bo_is_reserved(vram_obj)) {
195 radeon_bo_unpin(vram_obj);
196 radeon_bo_unreserve(vram_obj);
198 radeon_bo_unref(&vram_obj);
201 for (i = 0; i < n; i++) {
203 if (radeon_bo_is_reserved(gtt_obj[i])) {
204 radeon_bo_unpin(gtt_obj[i]);
205 radeon_bo_unreserve(gtt_obj[i]);
207 radeon_bo_unref(>t_obj[i]);
213 radeon_fence_unref(&fence);
216 printk(KERN_WARNING "Error while testing BO move.\n");