]> Git Repo - linux.git/blob - drivers/gpu/drm/amd/amdgpu/amdgpu_test.c
Merge tag 'drm-misc-next-2018-07-18' of git://anongit.freedesktop.org/drm/drm-misc...
[linux.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_test.c
1 // SPDX-License-Identifier: GPL-2.0 OR MIT
2 /*
3  * Copyright 2009 VMware, Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  *
23  * Authors: Michel Dänzer
24  */
25 #include <drm/drmP.h>
26 #include <drm/amdgpu_drm.h>
27 #include "amdgpu.h"
28 #include "amdgpu_uvd.h"
29 #include "amdgpu_vce.h"
30
31 /* Test BO GTT->VRAM and VRAM->GTT GPU copies across the whole GTT aperture */
32 static void amdgpu_do_test_moves(struct amdgpu_device *adev)
33 {
34         struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
35         struct amdgpu_bo *vram_obj = NULL;
36         struct amdgpu_bo **gtt_obj = NULL;
37         struct amdgpu_bo_param bp;
38         uint64_t gart_addr, vram_addr;
39         unsigned n, size;
40         int i, r;
41
42         size = 1024 * 1024;
43
44         /* Number of tests =
45          * (Total GTT - IB pool - writeback page - ring buffers) / test size
46          */
47         n = adev->gmc.gart_size - AMDGPU_IB_POOL_SIZE*64*1024;
48         for (i = 0; i < AMDGPU_MAX_RINGS; ++i)
49                 if (adev->rings[i])
50                         n -= adev->rings[i]->ring_size;
51         if (adev->wb.wb_obj)
52                 n -= AMDGPU_GPU_PAGE_SIZE;
53         if (adev->irq.ih.ring_obj)
54                 n -= adev->irq.ih.ring_size;
55         n /= size;
56
57         gtt_obj = kcalloc(n, sizeof(*gtt_obj), GFP_KERNEL);
58         if (!gtt_obj) {
59                 DRM_ERROR("Failed to allocate %d pointers\n", n);
60                 r = 1;
61                 goto out_cleanup;
62         }
63         memset(&bp, 0, sizeof(bp));
64         bp.size = size;
65         bp.byte_align = PAGE_SIZE;
66         bp.domain = AMDGPU_GEM_DOMAIN_VRAM;
67         bp.flags = 0;
68         bp.type = ttm_bo_type_kernel;
69         bp.resv = NULL;
70
71         r = amdgpu_bo_create(adev, &bp, &vram_obj);
72         if (r) {
73                 DRM_ERROR("Failed to create VRAM object\n");
74                 goto out_cleanup;
75         }
76         r = amdgpu_bo_reserve(vram_obj, false);
77         if (unlikely(r != 0))
78                 goto out_unref;
79         r = amdgpu_bo_pin(vram_obj, AMDGPU_GEM_DOMAIN_VRAM, &vram_addr);
80         if (r) {
81                 DRM_ERROR("Failed to pin VRAM object\n");
82                 goto out_unres;
83         }
84         for (i = 0; i < n; i++) {
85                 void *gtt_map, *vram_map;
86                 void **gart_start, **gart_end;
87                 void **vram_start, **vram_end;
88                 struct dma_fence *fence = NULL;
89
90                 bp.domain = AMDGPU_GEM_DOMAIN_GTT;
91                 r = amdgpu_bo_create(adev, &bp, gtt_obj + i);
92                 if (r) {
93                         DRM_ERROR("Failed to create GTT object %d\n", i);
94                         goto out_lclean;
95                 }
96
97                 r = amdgpu_bo_reserve(gtt_obj[i], false);
98                 if (unlikely(r != 0))
99                         goto out_lclean_unref;
100                 r = amdgpu_bo_pin(gtt_obj[i], AMDGPU_GEM_DOMAIN_GTT, &gart_addr);
101                 if (r) {
102                         DRM_ERROR("Failed to pin GTT object %d\n", i);
103                         goto out_lclean_unres;
104                 }
105
106                 r = amdgpu_bo_kmap(gtt_obj[i], &gtt_map);
107                 if (r) {
108                         DRM_ERROR("Failed to map GTT object %d\n", i);
109                         goto out_lclean_unpin;
110                 }
111
112                 for (gart_start = gtt_map, gart_end = gtt_map + size;
113                      gart_start < gart_end;
114                      gart_start++)
115                         *gart_start = gart_start;
116
117                 amdgpu_bo_kunmap(gtt_obj[i]);
118
119                 r = amdgpu_copy_buffer(ring, gart_addr, vram_addr,
120                                        size, NULL, &fence, false, false);
121
122                 if (r) {
123                         DRM_ERROR("Failed GTT->VRAM copy %d\n", i);
124                         goto out_lclean_unpin;
125                 }
126
127                 r = dma_fence_wait(fence, false);
128                 if (r) {
129                         DRM_ERROR("Failed to wait for GTT->VRAM fence %d\n", i);
130                         goto out_lclean_unpin;
131                 }
132
133                 dma_fence_put(fence);
134
135                 r = amdgpu_bo_kmap(vram_obj, &vram_map);
136                 if (r) {
137                         DRM_ERROR("Failed to map VRAM object after copy %d\n", i);
138                         goto out_lclean_unpin;
139                 }
140
141                 for (gart_start = gtt_map, gart_end = gtt_map + size,
142                      vram_start = vram_map, vram_end = vram_map + size;
143                      vram_start < vram_end;
144                      gart_start++, vram_start++) {
145                         if (*vram_start != gart_start) {
146                                 DRM_ERROR("Incorrect GTT->VRAM copy %d: Got 0x%p, "
147                                           "expected 0x%p (GTT/VRAM offset "
148                                           "0x%16llx/0x%16llx)\n",
149                                           i, *vram_start, gart_start,
150                                           (unsigned long long)
151                                           (gart_addr - adev->gmc.gart_start +
152                                            (void*)gart_start - gtt_map),
153                                           (unsigned long long)
154                                           (vram_addr - adev->gmc.vram_start +
155                                            (void*)gart_start - gtt_map));
156                                 amdgpu_bo_kunmap(vram_obj);
157                                 goto out_lclean_unpin;
158                         }
159                         *vram_start = vram_start;
160                 }
161
162                 amdgpu_bo_kunmap(vram_obj);
163
164                 r = amdgpu_copy_buffer(ring, vram_addr, gart_addr,
165                                        size, NULL, &fence, false, false);
166
167                 if (r) {
168                         DRM_ERROR("Failed VRAM->GTT copy %d\n", i);
169                         goto out_lclean_unpin;
170                 }
171
172                 r = dma_fence_wait(fence, false);
173                 if (r) {
174                         DRM_ERROR("Failed to wait for VRAM->GTT fence %d\n", i);
175                         goto out_lclean_unpin;
176                 }
177
178                 dma_fence_put(fence);
179
180                 r = amdgpu_bo_kmap(gtt_obj[i], &gtt_map);
181                 if (r) {
182                         DRM_ERROR("Failed to map GTT object after copy %d\n", i);
183                         goto out_lclean_unpin;
184                 }
185
186                 for (gart_start = gtt_map, gart_end = gtt_map + size,
187                      vram_start = vram_map, vram_end = vram_map + size;
188                      gart_start < gart_end;
189                      gart_start++, vram_start++) {
190                         if (*gart_start != vram_start) {
191                                 DRM_ERROR("Incorrect VRAM->GTT copy %d: Got 0x%p, "
192                                           "expected 0x%p (VRAM/GTT offset "
193                                           "0x%16llx/0x%16llx)\n",
194                                           i, *gart_start, vram_start,
195                                           (unsigned long long)
196                                           (vram_addr - adev->gmc.vram_start +
197                                            (void*)vram_start - vram_map),
198                                           (unsigned long long)
199                                           (gart_addr - adev->gmc.gart_start +
200                                            (void*)vram_start - vram_map));
201                                 amdgpu_bo_kunmap(gtt_obj[i]);
202                                 goto out_lclean_unpin;
203                         }
204                 }
205
206                 amdgpu_bo_kunmap(gtt_obj[i]);
207
208                 DRM_INFO("Tested GTT->VRAM and VRAM->GTT copy for GTT offset 0x%llx\n",
209                          gart_addr - adev->gmc.gart_start);
210                 continue;
211
212 out_lclean_unpin:
213                 amdgpu_bo_unpin(gtt_obj[i]);
214 out_lclean_unres:
215                 amdgpu_bo_unreserve(gtt_obj[i]);
216 out_lclean_unref:
217                 amdgpu_bo_unref(&gtt_obj[i]);
218 out_lclean:
219                 for (--i; i >= 0; --i) {
220                         amdgpu_bo_unpin(gtt_obj[i]);
221                         amdgpu_bo_unreserve(gtt_obj[i]);
222                         amdgpu_bo_unref(&gtt_obj[i]);
223                 }
224                 if (fence)
225                         dma_fence_put(fence);
226                 break;
227         }
228
229         amdgpu_bo_unpin(vram_obj);
230 out_unres:
231         amdgpu_bo_unreserve(vram_obj);
232 out_unref:
233         amdgpu_bo_unref(&vram_obj);
234 out_cleanup:
235         kfree(gtt_obj);
236         if (r) {
237                 pr_warn("Error while testing BO move\n");
238         }
239 }
240
241 void amdgpu_test_moves(struct amdgpu_device *adev)
242 {
243         if (adev->mman.buffer_funcs)
244                 amdgpu_do_test_moves(adev);
245 }
This page took 0.066604 seconds and 4 git commands to generate.