2 * Copyright 2019 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.
24 #include "CUnit/Basic.h"
26 #include "amdgpu_test.h"
27 #include "amdgpu_drm.h"
28 #include "amdgpu_internal.h"
30 static amdgpu_device_handle device_handle;
31 static uint32_t major_version;
32 static uint32_t minor_version;
34 static void amdgpu_security_alloc_buf_test(void);
35 static void amdgpu_security_gfx_submission_test(void);
37 CU_BOOL suite_security_tests_enable(void)
39 CU_BOOL enable = CU_TRUE;
41 if (amdgpu_device_initialize(drm_amdgpu[0], &major_version,
42 &minor_version, &device_handle))
45 if (device_handle->info.family_id < AMDGPU_FAMILY_RV) {
46 printf("\n\nDon't support TMZ (trust memory zone), security suite disabled\n");
50 if (amdgpu_device_deinitialize(device_handle))
56 int suite_security_tests_init(void)
58 if (amdgpu_device_initialize(drm_amdgpu[0], &major_version,
59 &minor_version, &device_handle))
60 return CUE_SINIT_FAILED;
65 int suite_security_tests_clean(void)
69 r = amdgpu_device_deinitialize(device_handle);
71 return CUE_SCLEAN_FAILED;
77 CU_TestInfo security_tests[] = {
78 { "allocate secure buffer test", amdgpu_security_alloc_buf_test },
79 { "graphics secure command submission", amdgpu_security_gfx_submission_test },
83 static void amdgpu_security_alloc_buf_test(void)
86 amdgpu_va_handle va_handle;
90 /* Test secure buffer allocation in VRAM */
91 bo = gpu_mem_alloc(device_handle, 4096, 4096,
92 AMDGPU_GEM_DOMAIN_VRAM,
93 AMDGPU_GEM_CREATE_ENCRYPTED,
96 r = gpu_mem_free(bo, va_handle, bo_mc, 4096);
97 CU_ASSERT_EQUAL(r, 0);
99 /* Test secure buffer allocation in system memory */
100 bo = gpu_mem_alloc(device_handle, 4096, 4096,
101 AMDGPU_GEM_DOMAIN_GTT,
102 AMDGPU_GEM_CREATE_ENCRYPTED,
105 r = gpu_mem_free(bo, va_handle, bo_mc, 4096);
106 CU_ASSERT_EQUAL(r, 0);
108 /* Test secure buffer allocation in invisible VRAM */
109 bo = gpu_mem_alloc(device_handle, 4096, 4096,
110 AMDGPU_GEM_DOMAIN_GTT,
111 AMDGPU_GEM_CREATE_ENCRYPTED |
112 AMDGPU_GEM_CREATE_NO_CPU_ACCESS,
115 r = gpu_mem_free(bo, va_handle, bo_mc, 4096);
116 CU_ASSERT_EQUAL(r, 0);
119 static void amdgpu_security_gfx_submission_test(void)
121 amdgpu_command_submission_write_linear_helper_with_secure(device_handle,