1 /*
2 * Copyright 2014 Advanced Micro Devices, 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 */
23
24 #ifndef _AMDGPU_TEST_H_
25 #define _AMDGPU_TEST_H_
26
27 #include "amdgpu.h"
28 #include "amdgpu_drm.h"
29
30 /**
31 * Define max. number of card in system which we are able to handle
32 */
33 #define MAX_CARDS_SUPPORTED 128
34
35 /* Forward reference for array to keep "drm" handles */
36 extern int drm_amdgpu[MAX_CARDS_SUPPORTED];
37
38 /* Global variables */
39 extern int open_render_node;
40
41 /************************* Basic test suite ********************************/
42
43 /*
44 * Define basic test suite to serve as the starting point for future testing
45 */
46
47 /**
48 * Initialize basic test suite
49 */
50 int suite_basic_tests_init();
51
52 /**
53 * Deinitialize basic test suite
54 */
55 int suite_basic_tests_clean();
56
57 /**
58 * Decide if the suite is enabled by default or not.
59 */
60 CU_BOOL suite_basic_tests_enable(void);
61
62 /**
63 * Tests in basic test suite
64 */
65 extern CU_TestInfo basic_tests[];
66
67 /**
68 * Initialize bo test suite
69 */
70 int suite_bo_tests_init();
71
72 /**
73 * Deinitialize bo test suite
74 */
75 int suite_bo_tests_clean();
76
77 /**
78 * Tests in bo test suite
79 */
80 extern CU_TestInfo bo_tests[];
81
82 /**
83 * Initialize cs test suite
84 */
85 int suite_cs_tests_init();
86
87 /**
88 * Deinitialize cs test suite
89 */
90 int suite_cs_tests_clean();
91
92 /**
93 * Decide if the suite is enabled by default or not.
94 */
95 CU_BOOL suite_cs_tests_enable(void);
96
97 /**
98 * Tests in cs test suite
99 */
100 extern CU_TestInfo cs_tests[];
101
102 /**
103 * Initialize vce test suite
104 */
105 int suite_vce_tests_init();
106
107 /**
108 * Deinitialize vce test suite
109 */
110 int suite_vce_tests_clean();
111
112 /**
113 * Decide if the suite is enabled by default or not.
114 */
115 CU_BOOL suite_vce_tests_enable(void);
116
117 /**
118 * Tests in vce test suite
119 */
120 extern CU_TestInfo vce_tests[];
121
122 /**
123 + * Initialize vcn test suite
124 + */
125 int suite_vcn_tests_init();
126
127 /**
128 + * Deinitialize vcn test suite
129 + */
130 int suite_vcn_tests_clean();
131
132 /**
133 * Decide if the suite is enabled by default or not.
134 */
135 CU_BOOL suite_vcn_tests_enable(void);
136
137 /**
138 + * Tests in vcn test suite
139 + */
140 extern CU_TestInfo vcn_tests[];
141
142 /**
143 * Initialize uvd enc test suite
144 */
145 int suite_uvd_enc_tests_init();
146
147 /**
148 * Deinitialize uvd enc test suite
149 */
150 int suite_uvd_enc_tests_clean();
151
152 /**
153 * Decide if the suite is enabled by default or not.
154 */
155 CU_BOOL suite_uvd_enc_tests_enable(void);
156
157 /**
158 * Tests in uvd enc test suite
159 */
160 extern CU_TestInfo uvd_enc_tests[];
161
162 /**
163 * Initialize deadlock test suite
164 */
165 int suite_deadlock_tests_init();
166
167 /**
168 * Deinitialize deadlock test suite
169 */
170 int suite_deadlock_tests_clean();
171
172 /**
173 * Decide if the suite is enabled by default or not.
174 */
175 CU_BOOL suite_deadlock_tests_enable(void);
176
177 /**
178 * Tests in uvd enc test suite
179 */
180 extern CU_TestInfo deadlock_tests[];
181
182 /**
183 * Initialize vm test suite
184 */
185 int suite_vm_tests_init();
186
187 /**
188 * Deinitialize deadlock test suite
189 */
190 int suite_vm_tests_clean();
191
192 /**
193 * Decide if the suite is enabled by default or not.
194 */
195 CU_BOOL suite_vm_tests_enable(void);
196
197 /**
198 * Tests in vm test suite
199 */
200 extern CU_TestInfo vm_tests[];
201
202
203 /**
204 * Initialize ras test suite
205 */
206 int suite_ras_tests_init();
207
208 /**
209 * Deinitialize deadlock test suite
210 */
211 int suite_ras_tests_clean();
212
213 /**
214 * Decide if the suite is enabled by default or not.
215 */
216 CU_BOOL suite_ras_tests_enable(void);
217
218 /**
219 * Tests in ras test suite
220 */
221 extern CU_TestInfo ras_tests[];
222
223
224 /**
225 * Initialize syncobj timeline test suite
226 */
227 int suite_syncobj_timeline_tests_init();
228
229 /**
230 * Deinitialize syncobj timeline test suite
231 */
232 int suite_syncobj_timeline_tests_clean();
233
234 /**
235 * Decide if the suite is enabled by default or not.
236 */
237 CU_BOOL suite_syncobj_timeline_tests_enable(void);
238
239 /**
240 * Tests in syncobj timeline test suite
241 */
242 extern CU_TestInfo syncobj_timeline_tests[];
243
244 void amdgpu_dispatch_hang_helper(amdgpu_device_handle device_handle, uint32_t ip_type);
245 void amdgpu_dispatch_hang_slow_helper(amdgpu_device_handle device_handle, uint32_t ip_type);
246 void amdgpu_memcpy_draw_test(amdgpu_device_handle device_handle, uint32_t ring,
247 int hang);
248 void amdgpu_memcpy_draw_hang_slow_test(amdgpu_device_handle device_handle, uint32_t ring);
249
250 /**
251 * Initialize security test suite
252 */
253 int suite_security_tests_init();
254
255 /**
256 * Deinitialize security test suite
257 */
258 int suite_security_tests_clean();
259
260 /**
261 * Decide if the suite is enabled by default or not.
262 */
263 CU_BOOL suite_security_tests_enable(void);
264
265 /**
266 * Tests in security test suite
267 */
268 extern CU_TestInfo security_tests[];
269
270 extern void
271 amdgpu_command_submission_write_linear_helper_with_secure(amdgpu_device_handle
272 device,
273 unsigned ip_type,
274 bool secure);
275
276
277
278 /**
279 * Initialize hotunplug test suite
280 */
281 int suite_hotunplug_tests_init();
282
283 /**
284 * Deinitialize hotunplug test suite
285 */
286 int suite_hotunplug_tests_clean();
287
288 /**
289 * Decide if the suite is enabled by default or not.
290 */
291 CU_BOOL suite_hotunplug_tests_enable(void);
292
293 /**
294 * Tests in uvd enc test suite
295 */
296 extern CU_TestInfo hotunplug_tests[];
297
298
299 /**
300 * Helper functions
301 */
gpu_mem_alloc(amdgpu_device_handle device_handle,uint64_t size,uint64_t alignment,uint32_t type,uint64_t flags,uint64_t * vmc_addr,amdgpu_va_handle * va_handle)302 static inline amdgpu_bo_handle gpu_mem_alloc(
303 amdgpu_device_handle device_handle,
304 uint64_t size,
305 uint64_t alignment,
306 uint32_t type,
307 uint64_t flags,
308 uint64_t *vmc_addr,
309 amdgpu_va_handle *va_handle)
310 {
311 struct amdgpu_bo_alloc_request req = {0};
312 amdgpu_bo_handle buf_handle = NULL;
313 int r;
314
315 req.alloc_size = size;
316 req.phys_alignment = alignment;
317 req.preferred_heap = type;
318 req.flags = flags;
319
320 r = amdgpu_bo_alloc(device_handle, &req, &buf_handle);
321 CU_ASSERT_EQUAL(r, 0);
322 if (r)
323 return NULL;
324
325 if (vmc_addr && va_handle) {
326 r = amdgpu_va_range_alloc(device_handle,
327 amdgpu_gpu_va_range_general,
328 size, alignment, 0, vmc_addr,
329 va_handle, 0);
330 CU_ASSERT_EQUAL(r, 0);
331 if (r)
332 goto error_free_bo;
333
334 r = amdgpu_bo_va_op(buf_handle, 0, size, *vmc_addr, 0,
335 AMDGPU_VA_OP_MAP);
336 CU_ASSERT_EQUAL(r, 0);
337 if (r)
338 goto error_free_va;
339 }
340
341 return buf_handle;
342
343 error_free_va:
344 r = amdgpu_va_range_free(*va_handle);
345 CU_ASSERT_EQUAL(r, 0);
346
347 error_free_bo:
348 r = amdgpu_bo_free(buf_handle);
349 CU_ASSERT_EQUAL(r, 0);
350
351 return NULL;
352 }
353
gpu_mem_free(amdgpu_bo_handle bo,amdgpu_va_handle va_handle,uint64_t vmc_addr,uint64_t size)354 static inline int gpu_mem_free(amdgpu_bo_handle bo,
355 amdgpu_va_handle va_handle,
356 uint64_t vmc_addr,
357 uint64_t size)
358 {
359 int r;
360
361 if (!bo)
362 return 0;
363
364 if (va_handle) {
365 r = amdgpu_bo_va_op(bo, 0, size, vmc_addr, 0,
366 AMDGPU_VA_OP_UNMAP);
367 CU_ASSERT_EQUAL(r, 0);
368 if (r)
369 return r;
370
371 r = amdgpu_va_range_free(va_handle);
372 CU_ASSERT_EQUAL(r, 0);
373 if (r)
374 return r;
375 }
376
377 r = amdgpu_bo_free(bo);
378 CU_ASSERT_EQUAL(r, 0);
379
380 return r;
381 }
382
383 static inline int
amdgpu_bo_alloc_wrap(amdgpu_device_handle dev,unsigned size,unsigned alignment,unsigned heap,uint64_t flags,amdgpu_bo_handle * bo)384 amdgpu_bo_alloc_wrap(amdgpu_device_handle dev, unsigned size,
385 unsigned alignment, unsigned heap, uint64_t flags,
386 amdgpu_bo_handle *bo)
387 {
388 struct amdgpu_bo_alloc_request request = {};
389 amdgpu_bo_handle buf_handle;
390 int r;
391
392 request.alloc_size = size;
393 request.phys_alignment = alignment;
394 request.preferred_heap = heap;
395 request.flags = flags;
396
397 r = amdgpu_bo_alloc(dev, &request, &buf_handle);
398 if (r)
399 return r;
400
401 *bo = buf_handle;
402
403 return 0;
404 }
405
406 int amdgpu_bo_alloc_and_map_raw(amdgpu_device_handle dev, unsigned size,
407 unsigned alignment, unsigned heap, uint64_t alloc_flags,
408 uint64_t mapping_flags, amdgpu_bo_handle *bo, void **cpu,
409 uint64_t *mc_address,
410 amdgpu_va_handle *va_handle);
411
412 static inline int
amdgpu_bo_alloc_and_map(amdgpu_device_handle dev,unsigned size,unsigned alignment,unsigned heap,uint64_t alloc_flags,amdgpu_bo_handle * bo,void ** cpu,uint64_t * mc_address,amdgpu_va_handle * va_handle)413 amdgpu_bo_alloc_and_map(amdgpu_device_handle dev, unsigned size,
414 unsigned alignment, unsigned heap, uint64_t alloc_flags,
415 amdgpu_bo_handle *bo, void **cpu, uint64_t *mc_address,
416 amdgpu_va_handle *va_handle)
417 {
418 return amdgpu_bo_alloc_and_map_raw(dev, size, alignment, heap,
419 alloc_flags, 0, bo, cpu, mc_address, va_handle);
420 }
421
422 static inline int
amdgpu_bo_unmap_and_free(amdgpu_bo_handle bo,amdgpu_va_handle va_handle,uint64_t mc_addr,uint64_t size)423 amdgpu_bo_unmap_and_free(amdgpu_bo_handle bo, amdgpu_va_handle va_handle,
424 uint64_t mc_addr, uint64_t size)
425 {
426 amdgpu_bo_cpu_unmap(bo);
427 amdgpu_bo_va_op(bo, 0, size, mc_addr, 0, AMDGPU_VA_OP_UNMAP);
428 amdgpu_va_range_free(va_handle);
429 amdgpu_bo_free(bo);
430
431 return 0;
432
433 }
434
435 static inline int
amdgpu_get_bo_list(amdgpu_device_handle dev,amdgpu_bo_handle bo1,amdgpu_bo_handle bo2,amdgpu_bo_list_handle * list)436 amdgpu_get_bo_list(amdgpu_device_handle dev, amdgpu_bo_handle bo1,
437 amdgpu_bo_handle bo2, amdgpu_bo_list_handle *list)
438 {
439 amdgpu_bo_handle resources[] = {bo1, bo2};
440
441 return amdgpu_bo_list_create(dev, bo2 ? 2 : 1, resources, NULL, list);
442 }
443
444
amdgpu_set_suite_active(const char * suite_name,CU_BOOL active)445 static inline CU_ErrorCode amdgpu_set_suite_active(const char *suite_name,
446 CU_BOOL active)
447 {
448 CU_ErrorCode r = CU_set_suite_active(CU_get_suite(suite_name), active);
449
450 if (r != CUE_SUCCESS)
451 fprintf(stderr, "Failed to obtain suite %s\n", suite_name);
452
453 return r;
454 }
455
amdgpu_set_test_active(const char * suite_name,const char * test_name,CU_BOOL active)456 static inline CU_ErrorCode amdgpu_set_test_active(const char *suite_name,
457 const char *test_name, CU_BOOL active)
458 {
459 CU_ErrorCode r;
460 CU_pSuite pSuite = CU_get_suite(suite_name);
461
462 if (!pSuite) {
463 fprintf(stderr, "Failed to obtain suite %s\n",
464 suite_name);
465 return CUE_NOSUITE;
466 }
467
468 r = CU_set_test_active(CU_get_test(pSuite, test_name), active);
469 if (r != CUE_SUCCESS)
470 fprintf(stderr, "Failed to obtain test %s\n", test_name);
471
472 return r;
473 }
474
475
asic_is_gfx_pipe_removed(uint32_t family_id,uint32_t chip_id,uint32_t chip_rev)476 static inline bool asic_is_gfx_pipe_removed(uint32_t family_id, uint32_t chip_id, uint32_t chip_rev)
477 {
478
479 if (family_id != AMDGPU_FAMILY_AI)
480 return false;
481
482 switch (chip_id - chip_rev) {
483 /* Arcturus */
484 case 0x32:
485 /* Aldebaran */
486 case 0x3c:
487 return true;
488 default:
489 return false;
490 }
491 }
492
493 void amdgpu_test_exec_cs_helper_raw(amdgpu_device_handle device_handle,
494 amdgpu_context_handle context_handle,
495 unsigned ip_type, int instance, int pm4_dw,
496 uint32_t *pm4_src, int res_cnt,
497 amdgpu_bo_handle *resources,
498 struct amdgpu_cs_ib_info *ib_info,
499 struct amdgpu_cs_request *ibs_request,
500 bool secure);
501
502 void amdgpu_close_devices();
503 int amdgpu_open_device_on_test_index(int render_node);
504 char *amdgpu_get_device_from_fd(int fd);
505
506 #endif /* #ifdef _AMDGPU_TEST_H_ */
507