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.
28 #include "CUnit/Basic.h"
30 #include "amdgpu_test.h"
31 #include "amdgpu_drm.h"
32 #include "amdgpu_internal.h"
34 static amdgpu_device_handle device_handle;
35 static uint32_t major_version;
36 static uint32_t minor_version;
39 static void amdgpu_vmid_reserve_test(void);
41 CU_BOOL suite_vm_tests_enable(void)
43 CU_BOOL enable = CU_TRUE;
45 if (amdgpu_device_initialize(drm_amdgpu[0], &major_version,
46 &minor_version, &device_handle))
49 if (device_handle->info.family_id == AMDGPU_FAMILY_SI) {
50 printf("\n\nCurrently hangs the CP on this ASIC, VM suite disabled\n");
54 if (amdgpu_device_deinitialize(device_handle))
60 int suite_vm_tests_init(void)
64 r = amdgpu_device_initialize(drm_amdgpu[0], &major_version,
65 &minor_version, &device_handle);
68 if ((r == -EACCES) && (errno == EACCES))
69 printf("\n\nError:%s. "
70 "Hint:Try to run this test program as root.",
72 return CUE_SINIT_FAILED;
78 int suite_vm_tests_clean(void)
80 int r = amdgpu_device_deinitialize(device_handle);
85 return CUE_SCLEAN_FAILED;
89 CU_TestInfo vm_tests[] = {
90 { "resere vmid test", amdgpu_vmid_reserve_test },
94 static void amdgpu_vmid_reserve_test(void)
96 amdgpu_context_handle context_handle;
97 amdgpu_bo_handle ib_result_handle;
99 uint64_t ib_result_mc_address;
100 struct amdgpu_cs_request ibs_request;
101 struct amdgpu_cs_ib_info ib_info;
102 struct amdgpu_cs_fence fence_status;
103 uint32_t expired, flags;
105 amdgpu_bo_list_handle bo_list;
106 amdgpu_va_handle va_handle;
107 static uint32_t *ptr;
109 r = amdgpu_cs_ctx_create(device_handle, &context_handle);
110 CU_ASSERT_EQUAL(r, 0);
113 r = amdgpu_vm_reserve_vmid(device_handle, flags);
114 CU_ASSERT_EQUAL(r, 0);
117 r = amdgpu_bo_alloc_and_map(device_handle, 4096, 4096,
118 AMDGPU_GEM_DOMAIN_GTT, 0,
119 &ib_result_handle, &ib_result_cpu,
120 &ib_result_mc_address, &va_handle);
121 CU_ASSERT_EQUAL(r, 0);
123 r = amdgpu_get_bo_list(device_handle, ib_result_handle, NULL,
125 CU_ASSERT_EQUAL(r, 0);
129 for (i = 0; i < 16; ++i)
132 memset(&ib_info, 0, sizeof(struct amdgpu_cs_ib_info));
133 ib_info.ib_mc_address = ib_result_mc_address;
136 memset(&ibs_request, 0, sizeof(struct amdgpu_cs_request));
137 ibs_request.ip_type = AMDGPU_HW_IP_GFX;
138 ibs_request.ring = 0;
139 ibs_request.number_of_ibs = 1;
140 ibs_request.ibs = &ib_info;
141 ibs_request.resources = bo_list;
142 ibs_request.fence_info.handle = NULL;
144 r = amdgpu_cs_submit(context_handle, 0,&ibs_request, 1);
145 CU_ASSERT_EQUAL(r, 0);
148 memset(&fence_status, 0, sizeof(struct amdgpu_cs_fence));
149 fence_status.context = context_handle;
150 fence_status.ip_type = AMDGPU_HW_IP_GFX;
151 fence_status.ip_instance = 0;
152 fence_status.ring = 0;
153 fence_status.fence = ibs_request.seq_no;
155 r = amdgpu_cs_query_fence_status(&fence_status,
156 AMDGPU_TIMEOUT_INFINITE,0, &expired);
157 CU_ASSERT_EQUAL(r, 0);
159 r = amdgpu_bo_list_destroy(bo_list);
160 CU_ASSERT_EQUAL(r, 0);
162 r = amdgpu_bo_unmap_and_free(ib_result_handle, va_handle,
163 ib_result_mc_address, 4096);
164 CU_ASSERT_EQUAL(r, 0);
167 r = amdgpu_vm_unreserve_vmid(device_handle, flags);
168 CU_ASSERT_EQUAL(r, 0);
171 r = amdgpu_cs_ctx_free(context_handle);
172 CU_ASSERT_EQUAL(r, 0);