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)
37 amdgpu_va_handle va_handle;
41 /* Test secure buffer allocation in VRAM */
42 bo = gpu_mem_alloc(device_handle, 4096, 4096,
43 AMDGPU_GEM_DOMAIN_VRAM,
44 AMDGPU_GEM_CREATE_ENCRYPTED,
47 r = gpu_mem_free(bo, va_handle, bo_mc, 4096);
48 CU_ASSERT_EQUAL(r, 0);
50 /* Test secure buffer allocation in system memory */
51 bo = gpu_mem_alloc(device_handle, 4096, 4096,
52 AMDGPU_GEM_DOMAIN_GTT,
53 AMDGPU_GEM_CREATE_ENCRYPTED,
56 r = gpu_mem_free(bo, va_handle, bo_mc, 4096);
57 CU_ASSERT_EQUAL(r, 0);
59 /* Test secure buffer allocation in invisible VRAM */
60 bo = gpu_mem_alloc(device_handle, 4096, 4096,
61 AMDGPU_GEM_DOMAIN_GTT,
62 AMDGPU_GEM_CREATE_ENCRYPTED |
63 AMDGPU_GEM_CREATE_NO_CPU_ACCESS,
66 r = gpu_mem_free(bo, va_handle, bo_mc, 4096);
67 CU_ASSERT_EQUAL(r, 0);
70 static void amdgpu_security_gfx_submission_test(void)
72 amdgpu_command_submission_write_linear_helper_with_secure(device_handle,
77 static void amdgpu_security_sdma_submission_test(void)
79 amdgpu_command_submission_write_linear_helper_with_secure(device_handle,
84 /* ----------------------------------------------------------------- */
86 CU_TestInfo security_tests[] = {
87 { "allocate secure buffer test", amdgpu_security_alloc_buf_test },
88 { "graphics secure command submission", amdgpu_security_gfx_submission_test },
89 { "sdma secure command submission", amdgpu_security_sdma_submission_test },
93 CU_BOOL suite_security_tests_enable(void)
95 CU_BOOL enable = CU_TRUE;
97 if (amdgpu_device_initialize(drm_amdgpu[0], &major_version,
98 &minor_version, &device_handle))
101 if (device_handle->info.family_id < AMDGPU_FAMILY_RV) {
102 printf("\n\nDon't support TMZ (trust memory zone), security suite disabled\n");
106 if ((major_version < 3) ||
107 ((major_version == 3) && (minor_version < 37))) {
108 printf("\n\nDon't support TMZ (trust memory zone), kernel DRM version (%d.%d)\n",
109 major_version, minor_version);
110 printf("is older, security suite disabled\n");
114 if (amdgpu_device_deinitialize(device_handle))
120 int suite_security_tests_init(void)
122 if (amdgpu_device_initialize(drm_amdgpu[0], &major_version,
123 &minor_version, &device_handle))
124 return CUE_SINIT_FAILED;
129 int suite_security_tests_clean(void)
133 r = amdgpu_device_deinitialize(device_handle);
135 return CUE_SCLEAN_FAILED;