blob: 0fb86faa8ca9fd88d42712253766c40e5e765a16 [file] [log] [blame]
Varun Wadekarbe5fade2020-06-02 22:54:42 -07001/*
2 * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
8#include <debug.h>
9#include <tftf_lib.h>
10#include <xlat_tables_v2.h>
11
12#include <platform_def.h>
13
14/*******************************************************************************
15 * Common Tegra SiP SMCs
16 ******************************************************************************/
17#define TEGRA_SIP_NEW_VIDEOMEM_REGION 0x82000003ULL
18
19/*
20 * @Test_Aim@ Test to issue VideoMem SiP SMC function IDs.
21 *
22 * This test runs on the lead CPU and issues TEGRA_SIP_NEW_VIDEOMEM_REGION
23 * SMC to resize the memory region.
24 */
25test_result_t test_sip_videomem_resize(void)
26{
27 uint32_t size_in_bytes = (4U << 20);
28 uint32_t offset = (8U << 20);
29 uint64_t vidmem_base = DRAM_END, mem;
30 uint64_t buf[] = { 0xCAFEBABE, 0xCAFEBABE, 0xCAFEBABE, 0xCAFEBABE };
31 smc_args args = { TEGRA_SIP_NEW_VIDEOMEM_REGION, vidmem_base, size_in_bytes };
32 smc_ret_values ret;
33 test_result_t result = TEST_RESULT_SUCCESS;
34 int err;
35
36 /* Map dummy memory region for the test */
37 err = mmap_add_dynamic_region(vidmem_base, vidmem_base, size_in_bytes << 2,
38 MT_DEVICE | MT_RW | MT_NS | MT_EXECUTE_NEVER);
39 if (err != 0) {
40 tftf_testcase_printf("%s: could not map memory (%d)\n", __func__, err);
41 return TEST_RESULT_FAIL;
42 }
43
44 /* copy sample data before setting up the memory protections */
45 memcpy((char *)vidmem_base, (void *)buf, sizeof(buf));
46 flush_dcache_range(vidmem_base, sizeof(buf));
47
48 /* Issue the SMC to program videomem and expect success */
49 ret = tftf_smc(&args);
50 if (ret.ret0 != 0UL) {
51 tftf_testcase_printf("%s failed. Expected 0, received %ld\n",
52 __func__, (long int)ret.ret0);
53 result = TEST_RESULT_FAIL;
54 goto exit;
55 }
56
57 /* copy sample data before setting up the memory protections */
58 memcpy((char *)vidmem_base + offset, (void *)buf, sizeof(buf));
59 flush_dcache_range(vidmem_base + offset, sizeof(buf));
60
61 /* Issue request to "move" the protected memory region */
62 args.arg1 = vidmem_base + offset;
63 args.arg2 = (u_register_t)size_in_bytes;
64 ret = tftf_smc(&args);
65 if (ret.ret0 != 0UL) {
66 tftf_testcase_printf("%s failed. Expected 0, received %ld\n",
67 __func__, (long int)ret.ret0);
68 result = TEST_RESULT_FAIL;
69 goto exit;
70 }
71
72 /* Verify that memory in the open has been cleared */
73 mem = vidmem_base;
74 for (unsigned int i = 0U; i < (size_in_bytes / 8); i++, mem += 8) {
75 if (*(uint64_t *)(void *)mem != 0ULL) {
76 tftf_testcase_printf("%s failed. Memory is non-zero (%llx:%llx)\n",
77 __func__, mem, *(uint64_t *)(void *)mem);
78 result = TEST_RESULT_FAIL;
79 goto exit;
80 }
81 }
82
83 /* copy sample data before setting up the memory protections */
84 memcpy((char *)vidmem_base, (void *)buf, sizeof(buf));
85 flush_dcache_range(vidmem_base, sizeof(buf));
86
87 /* Issue request to "move" the protected memory region */
88 args.arg1 = vidmem_base;
89 args.arg2 = (u_register_t)size_in_bytes;
90 ret = tftf_smc(&args);
91 if (ret.ret0 != 0UL) {
92 tftf_testcase_printf("%s failed. Expected 0, received %ld\n",
93 __func__, (long int)ret.ret0);
94 result = TEST_RESULT_FAIL;
95 goto exit;
96 }
97
98 /* Verify that memory in the open has been cleared */
99 mem = vidmem_base + offset;
100 for (unsigned int i = 0U; i < (size_in_bytes / 8); i++, mem += 8) {
101 if (*(uint64_t *)(void *)mem != 0U) {
102 tftf_testcase_printf("%s failed. Memory is non-zero (%llx:%llx)\n",
103 __func__, mem, *(uint64_t *)(void *)mem);
104 result = TEST_RESULT_FAIL;
105 goto exit;
106 }
107 }
108
109exit:
110 /* unmap dummy memory region */
111 err = mmap_remove_dynamic_region(vidmem_base, size_in_bytes << 2);
112 if (err != 0) {
113 tftf_testcase_printf("%s: could not unmap memory (%d)\n",
114 __func__, err);
115 result = TEST_RESULT_FAIL;
116 }
117
118 return result;
119}
120
121/*
122 * @Test_Aim@ Test to issue common SiP SMC function IDs.
123 *
124 * This test runs on the lead CPU and issues TEGRA_SIP_NEW_VIDEOMEM_REGION
125 * and tests positive and negative scenarios.
126 */
127test_result_t test_sip_videomem_incorrect_inputs(void)
128{
129 smc_args args = { TEGRA_SIP_NEW_VIDEOMEM_REGION };
130 smc_ret_values ret;
131
132 /* Issue the SMC with no input parameters and expect error */
133 ret = tftf_smc(&args);
134 if (ret.ret0 == 0UL) {
135 tftf_testcase_printf("%s failed. Expected -1, received %ld\n",
136 __func__, (long int)ret.ret0);
137 return TEST_RESULT_FAIL;
138 }
139
140 /* Issue the SMC with incorrect parameters and expect error */
141 args.arg1 = 0x10000000ULL;
142 args.arg2 = 4ULL << 20;
143
144 ret = tftf_smc(&args);
145 if (ret.ret0 == 0UL) {
146 tftf_testcase_printf("%s failed. Expected -1, received %ld\n",
147 __func__, (long int)ret.ret0);
148 return TEST_RESULT_FAIL;
149 }
150
151 /* Issue the SMC with incorrect parameters and expect error */
152 args.arg1 = 0x40000000ULL;
153 args.arg2 = 4ULL << 20;
154
155 ret = tftf_smc(&args);
156 if (ret.ret0 == 0UL) {
157 tftf_testcase_printf("%s failed. Expected -1, received %ld\n",
158 __func__, (long int)ret.ret0);
159 return TEST_RESULT_FAIL;
160 }
161
162 /* Issue the SMC with incorrect parameters and expect error */
163 args.arg1 = DRAM_END - (4U << 20);
164 args.arg2 = 0x100ULL;
165
166 ret = tftf_smc(&args);
167 if (ret.ret0 == 0UL) {
168 tftf_testcase_printf("%s failed. Expected -1, received %ld\n",
169 __func__, (long int)ret.ret0);
170 return TEST_RESULT_FAIL;
171 }
172
173 /* Issue the SMC with incorrect parameters and expect error */
174 args.arg1 = DRAM_END - (4U << 20);
175 args.arg2 = 0ULL;
176
177 ret = tftf_smc(&args);
178 if (ret.ret0 == 0UL) {
179 tftf_testcase_printf("%s failed. Expected -1, received %ld\n",
180 __func__, (long int)ret.ret0);
181 return TEST_RESULT_FAIL;
182 }
183
184 /* Issue the SMC with incorrect parameters and expect error */
185 args.arg1 = 0ULL;
186 args.arg2 = 4ULL << 20;
187
188 ret = tftf_smc(&args);
189 if (ret.ret0 == 0UL) {
190 tftf_testcase_printf("%s failed. Expected -1, received %ld\n",
191 __func__, (long int)ret.ret0);
192 return TEST_RESULT_FAIL;
193 }
194
195 return TEST_RESULT_SUCCESS;
196}