2 * Copyright 2017 Advanced Micro Devices, 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.
31 #include "CUnit/Basic.h"
33 #include "util_math.h"
35 #include "amdgpu_test.h"
36 #include "amdgpu_drm.h"
37 #include "amdgpu_internal.h"
40 #define MAX_RESOURCES 16
42 struct amdgpu_vcn_bo {
43 amdgpu_bo_handle handle;
44 amdgpu_va_handle va_handle;
50 static amdgpu_device_handle device_handle;
51 static uint32_t major_version;
52 static uint32_t minor_version;
53 static uint32_t family_id;
55 static amdgpu_context_handle context_handle;
56 static amdgpu_bo_handle ib_handle;
57 static amdgpu_va_handle ib_va_handle;
58 static uint64_t ib_mc_address;
59 static uint32_t *ib_cpu;
61 static amdgpu_bo_handle resources[MAX_RESOURCES];
62 static unsigned num_resources;
64 static void amdgpu_cs_vcn_dec_create(void);
65 static void amdgpu_cs_vcn_dec_decode(void);
66 static void amdgpu_cs_vcn_dec_destroy(void);
68 static void amdgpu_cs_vcn_enc_create(void);
69 static void amdgpu_cs_vcn_enc_encode(void);
70 static void amdgpu_cs_vcn_enc_destroy(void);
72 CU_TestInfo vcn_tests[] = {
74 { "VCN DEC create", amdgpu_cs_vcn_dec_create },
75 { "VCN DEC decode", amdgpu_cs_vcn_dec_decode },
76 { "VCN DEC destroy", amdgpu_cs_vcn_dec_destroy },
78 { "VCN ENC create", amdgpu_cs_vcn_enc_create },
79 { "VCN ENC decode", amdgpu_cs_vcn_enc_encode },
80 { "VCN ENC destroy", amdgpu_cs_vcn_enc_destroy },
84 int suite_vcn_tests_init(void)
88 r = amdgpu_device_initialize(drm_amdgpu[0], &major_version,
89 &minor_version, &device_handle);
91 return CUE_SINIT_FAILED;
93 family_id = device_handle->info.family_id;
95 if (family_id < AMDGPU_FAMILY_RV) {
96 printf("\n\nThe ASIC NOT support VCN, all sub-tests will pass\n");
100 r = amdgpu_cs_ctx_create(device_handle, &context_handle);
102 return CUE_SINIT_FAILED;
104 r = amdgpu_bo_alloc_and_map(device_handle, IB_SIZE, 4096,
105 AMDGPU_GEM_DOMAIN_GTT, 0,
106 &ib_handle, (void**)&ib_cpu,
107 &ib_mc_address, &ib_va_handle);
109 return CUE_SINIT_FAILED;
114 int suite_vcn_tests_clean(void)
118 if (family_id < AMDGPU_FAMILY_RV) {
119 r = amdgpu_device_deinitialize(device_handle);
121 return CUE_SCLEAN_FAILED;
123 r = amdgpu_bo_unmap_and_free(ib_handle, ib_va_handle,
124 ib_mc_address, IB_SIZE);
126 return CUE_SCLEAN_FAILED;
128 r = amdgpu_cs_ctx_free(context_handle);
130 return CUE_SCLEAN_FAILED;
132 r = amdgpu_device_deinitialize(device_handle);
134 return CUE_SCLEAN_FAILED;
140 static int submit(unsigned ndw, unsigned ip)
142 struct amdgpu_cs_request ibs_request = {0};
143 struct amdgpu_cs_ib_info ib_info = {0};
144 struct amdgpu_cs_fence fence_status = {0};
148 ib_info.ib_mc_address = ib_mc_address;
151 ibs_request.ip_type = ip;
153 r = amdgpu_bo_list_create(device_handle, num_resources, resources,
154 NULL, &ibs_request.resources);
158 ibs_request.number_of_ibs = 1;
159 ibs_request.ibs = &ib_info;
160 ibs_request.fence_info.handle = NULL;
162 r = amdgpu_cs_submit(context_handle, 0, &ibs_request, 1);
166 r = amdgpu_bo_list_destroy(ibs_request.resources);
170 fence_status.context = context_handle;
171 fence_status.ip_type = ip;
172 fence_status.fence = ibs_request.seq_no;
174 r = amdgpu_cs_query_fence_status(&fence_status,
175 AMDGPU_TIMEOUT_INFINITE,
183 static void alloc_resource(struct amdgpu_vcn_bo *vcn_bo,
184 unsigned size, unsigned domain)
186 struct amdgpu_bo_alloc_request req = {0};
187 amdgpu_bo_handle buf_handle;
188 amdgpu_va_handle va_handle;
192 req.alloc_size = ALIGN(size, 4096);
193 req.preferred_heap = domain;
194 r = amdgpu_bo_alloc(device_handle, &req, &buf_handle);
195 CU_ASSERT_EQUAL(r, 0);
196 r = amdgpu_va_range_alloc(device_handle,
197 amdgpu_gpu_va_range_general,
198 req.alloc_size, 1, 0, &va,
200 CU_ASSERT_EQUAL(r, 0);
201 r = amdgpu_bo_va_op(buf_handle, 0, req.alloc_size, va, 0,
203 CU_ASSERT_EQUAL(r, 0);
205 vcn_bo->handle = buf_handle;
206 vcn_bo->size = req.alloc_size;
207 vcn_bo->va_handle = va_handle;
208 r = amdgpu_bo_cpu_map(vcn_bo->handle, (void **)&vcn_bo->ptr);
209 CU_ASSERT_EQUAL(r, 0);
210 memset(vcn_bo->ptr, 0, size);
211 r = amdgpu_bo_cpu_unmap(vcn_bo->handle);
212 CU_ASSERT_EQUAL(r, 0);
215 static void free_resource(struct amdgpu_vcn_bo *vcn_bo)
219 r = amdgpu_bo_va_op(vcn_bo->handle, 0, vcn_bo->size,
220 vcn_bo->addr, 0, AMDGPU_VA_OP_UNMAP);
221 CU_ASSERT_EQUAL(r, 0);
223 r = amdgpu_va_range_free(vcn_bo->va_handle);
224 CU_ASSERT_EQUAL(r, 0);
226 r = amdgpu_bo_free(vcn_bo->handle);
227 CU_ASSERT_EQUAL(r, 0);
228 memset(vcn_bo, 0, sizeof(*vcn_bo));
231 static void amdgpu_cs_vcn_dec_create(void)
233 if (family_id < AMDGPU_FAMILY_RV)
239 static void amdgpu_cs_vcn_dec_decode(void)
241 if (family_id < AMDGPU_FAMILY_RV)
247 static void amdgpu_cs_vcn_dec_destroy(void)
249 if (family_id < AMDGPU_FAMILY_RV)
255 static void amdgpu_cs_vcn_enc_create(void)
257 if (family_id < AMDGPU_FAMILY_RV)
263 static void amdgpu_cs_vcn_enc_encode(void)
265 if (family_id < AMDGPU_FAMILY_RV)
271 static void amdgpu_cs_vcn_enc_destroy(void)
273 if (family_id < AMDGPU_FAMILY_RV)