drm: add tests/amdgpu (v3)
[platform/upstream/libdrm.git] / tests / amdgpu / amdgpu_test.h
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
29 /**
30  * Define max. number of card in system which we are able to handle
31  */
32 #define MAX_CARDS_SUPPORTED     4
33
34 /* Forward reference for array to keep "drm" handles */
35 extern int drm_amdgpu[MAX_CARDS_SUPPORTED];
36
37 /*************************  Basic test suite ********************************/
38
39 /*
40  * Define basic test suite to serve as the starting point for future testing
41 */
42
43 /**
44  * Initialize basic test suite
45  */
46 int suite_basic_tests_init();
47
48 /**
49  * Deinitialize basic test suite
50  */
51 int suite_basic_tests_clean();
52
53 /**
54  * Tests in basic test suite
55  */
56 extern CU_TestInfo basic_tests[];
57
58 /**
59  * Initialize bo test suite
60  */
61 int suite_bo_tests_init();
62
63 /**
64  * Deinitialize bo test suite
65  */
66 int suite_bo_tests_clean();
67
68 /**
69  * Tests in bo test suite
70  */
71 extern CU_TestInfo bo_tests[];
72
73 /**
74  * Initialize cs test suite
75  */
76 int suite_cs_tests_init();
77
78 /**
79  * Deinitialize cs test suite
80  */
81 int suite_cs_tests_clean();
82
83 /**
84  * Tests in cs test suite
85  */
86 extern CU_TestInfo cs_tests[];
87
88 /**
89  * Helper functions
90  */
91 static inline amdgpu_bo_handle gpu_mem_alloc(
92                                         amdgpu_device_handle device_handle,
93                                         uint64_t size,
94                                         uint64_t alignment,
95                                         uint32_t type,
96                                         uint64_t flags,
97                                         uint64_t *vmc_addr)
98 {
99         struct amdgpu_bo_alloc_request req = {0};
100         struct amdgpu_bo_alloc_result res = {0};
101         int r;
102
103         CU_ASSERT_NOT_EQUAL(vmc_addr, NULL);
104
105         req.alloc_size = size;
106         req.phys_alignment = alignment;
107         req.preferred_heap = type;
108         req.flags = flags;
109
110         r = amdgpu_bo_alloc(device_handle, &req, &res);
111         CU_ASSERT_EQUAL(r, 0);
112
113         CU_ASSERT_NOT_EQUAL(res.virtual_mc_base_address, 0);
114         CU_ASSERT_NOT_EQUAL(res.buf_handle, NULL);
115         *vmc_addr = res.virtual_mc_base_address;
116         return res.buf_handle;
117 }
118
119 #endif  /* #ifdef _AMDGPU_TEST_H_ */