blob: 439e2113c6e41393e828a8ba3b79a2c623462a86 [file] [log] [blame]
jaypit02ea3cd062018-10-05 12:22:38 +05301/** @file
jk-arm7cc5d1d2022-01-31 08:16:42 +05302 * Copyright (c) 2018-2022, Arm Limited or its affiliates. All rights reserved.
jaypit02ea3cd062018-10-05 12:22:38 +05303 * SPDX-License-Identifier : Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16**/
17
18#ifndef _VAL_COMMON_H_
19#define _VAL_COMMON_H_
20
Gowtham Siddarth47223082019-01-17 09:59:50 +053021#include "pal_common.h"
jaypit02ea3cd062018-10-05 12:22:38 +053022
23#ifndef VAL_NSPE_BUILD
24#define STATIC_DECLARE static
25#else
26#define STATIC_DECLARE
27#endif
28
29#ifndef __WEAK
30#define __WEAK __attribute__((weak))
31#endif
32
33#ifndef __UNUSED
34#define __UNUSED __attribute__((unused))
35#endif
36
37#ifndef TRUE
38#define TRUE 0
39#endif
40#ifndef FALSE
41#define FALSE 1
42#endif
43
Murat Cakmak26652972019-01-02 22:18:32 +000044#define _CONCAT(A,B) A##B
45#define CONCAT(A,B) _CONCAT(A,B)
46
jaypit02ea3cd062018-10-05 12:22:38 +053047/* test status defines */
48#define TEST_START 0x01
49#define TEST_END 0x02
50#define TEST_PASS 0x04
51#define TEST_FAIL 0x08
52#define TEST_SKIP 0x10
53#define TEST_PENDING 0x20
54
55#define TEST_NUM_BIT 32
56#define TEST_STATE_BIT 8
57#define TEST_STATUS_BIT 0
58
59#define TEST_NUM_MASK 0xFFFFFFFF
60#define TEST_STATE_MASK 0xFF
61#define TEST_STATUS_MASK 0xFF
62
63#define RESULT_START(status) (((TEST_START) << TEST_STATE_BIT) | ((status) << TEST_STATUS_BIT))
64#define RESULT_END(status) (((TEST_END) << TEST_STATE_BIT) | ((status) << TEST_STATUS_BIT))
65#define RESULT_PASS(status) (((TEST_PASS) << TEST_STATE_BIT) | ((status) << TEST_STATUS_BIT))
66#define RESULT_FAIL(status) (((TEST_FAIL) << TEST_STATE_BIT) | ((status) << TEST_STATUS_BIT))
67#define RESULT_SKIP(status) (((TEST_SKIP) << TEST_STATE_BIT) | ((status) << TEST_STATUS_BIT))
68#define RESULT_PENDING(status) (((TEST_PENDING) << TEST_STATE_BIT) | ((status) << TEST_STATUS_BIT))
69
70#define IS_TEST_FAIL(status) (((status >> TEST_STATE_BIT) & TEST_STATE_MASK) == TEST_FAIL)
71#define IS_TEST_PASS(status) (((status >> TEST_STATE_BIT) & TEST_STATE_MASK) == TEST_PASS)
72#define IS_TEST_SKIP(status) (((status >> TEST_STATE_BIT) & TEST_STATE_MASK) == TEST_SKIP)
73#define IS_TEST_PENDING(status) (((status >> TEST_STATE_BIT) & TEST_STATE_MASK) == TEST_PENDING)
74#define IS_TEST_START(status) (((status >> TEST_STATE_BIT) & TEST_STATE_MASK) == TEST_START)
75#define IS_TEST_END(status) (((status >> TEST_STATE_BIT) & TEST_STATE_MASK) == TEST_END)
Gowtham Siddarth47223082019-01-17 09:59:50 +053076#define VAL_ERROR(status) ((status & TEST_STATUS_MASK) ? 1 : 0)
jaypit02ea3cd062018-10-05 12:22:38 +053077
78
79
80/* Test Defines */
81#define TEST_PUBLISH(test_id, entry) \
Gowtham Siddarth47223082019-01-17 09:59:50 +053082 const val_test_info_t __attribute__((section(".acs_test_info"))) \
83 CONCAT(acs_test_info, entry) = {test_id, entry}
jaypit02ea3cd062018-10-05 12:22:38 +053084
Gowtham Siddarth47223082019-01-17 09:59:50 +053085#define VAL_MAX_TEST_PER_COMP 200
86#define VAL_FF_BASE 0
87#define VAL_CRYPTO_BASE 1
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +053088#define VAL_STORAGE_BASE 2
89#define VAL_INITIAL_ATTESTATION_BASE 3
Gowtham Siddarth47223082019-01-17 09:59:50 +053090
jaypit02ea3cd062018-10-05 12:22:38 +053091#define VAL_GET_COMP_NUM(test_id) \
92 ((test_id - (test_id % VAL_MAX_TEST_PER_COMP)) / VAL_MAX_TEST_PER_COMP)
93#define VAL_GET_TEST_NUM(test_id) (test_id % VAL_MAX_TEST_PER_COMP)
94#define VAL_CREATE_TEST_ID(comp,num) ((comp*VAL_MAX_TEST_PER_COMP) + num)
95
96#define TEST_FIELD(num1,num2) (num2 << 8 | num1)
97#define GET_TEST_ISOLATION_LEVEL(num) (num & 0x3)
Gowtham Siddarth47223082019-01-17 09:59:50 +053098#define GET_WD_TIMOUT_TYPE(num) ((num >> 8) & 0x7)
jaypit02ea3cd062018-10-05 12:22:38 +053099
100#define TEST_CHECKPOINT_NUM(n) n
101#define TEST(n) n
102#define BLOCK(n) n
103
104#define BLOCK_NUM_POS 8
105#define ACTION_POS 16
106#define GET_TEST_NUM(n) (0xff & n)
107#define GET_BLOCK_NUM(n) ((n >> BLOCK_NUM_POS) & 0xff)
108
109#define GET_ACTION_NUM(n) ((n >> ACTION_POS) & 0xff)
110#define TEST_EXECUTE_FUNC 1
111#define TEST_RETURN_RESULT 2
112#define INVALID_HANDLE 0x1234DEAD
113
114#define VAL_NVMEM_BLOCK_SIZE 4
115#define VAL_NVMEM_OFFSET(nvmem_idx) (nvmem_idx * VAL_NVMEM_BLOCK_SIZE)
116
Gowtham Siddarth47223082019-01-17 09:59:50 +0530117#define UART_INIT_SIGN 0xff
jaypit02ac23b5b2018-11-02 13:10:19 +0530118#define UART_PRINT_SIGN 0xfe
jaypit02ea3cd062018-10-05 12:22:38 +0530119
Gowtham Siddarth47223082019-01-17 09:59:50 +0530120#define TEST_PANIC() \
121 do { \
122 } while(1)
123
124#define TEST_ASSERT_EQUAL(arg1, arg2, checkpoint) \
125 do { \
jotman018ee505a2022-04-12 17:56:45 +0800126 if ((arg1) == PAL_STATUS_UNSUPPORTED_FUNC) \
Antonio de Angelisadfa40e2022-03-29 16:07:10 +0100127 { \
128 return RESULT_SKIP(VAL_STATUS_UNSUPPORTED); \
129 } \
Gowtham Siddarth47223082019-01-17 09:59:50 +0530130 if ((arg1) != arg2) \
131 { \
132 val->print(PRINT_ERROR, "\tFailed at Checkpoint: %d\n", checkpoint); \
133 val->print(PRINT_ERROR, "\tActual: %d\n", arg1); \
134 val->print(PRINT_ERROR, "\tExpected: %d\n", arg2); \
135 return 1; \
136 } \
137 } while (0)
138
139#define TEST_ASSERT_DUAL(arg1, status1, status2, checkpoint) \
140 do { \
jotman018ee505a2022-04-12 17:56:45 +0800141 if ((arg1) == PAL_STATUS_UNSUPPORTED_FUNC) \
Antonio de Angelisadfa40e2022-03-29 16:07:10 +0100142 { \
143 return RESULT_SKIP(VAL_STATUS_UNSUPPORTED); \
144 } \
Gowtham Siddarth47223082019-01-17 09:59:50 +0530145 if ((arg1) != status1 && (arg1) != status2) \
146 { \
147 val->print(PRINT_ERROR, "\tFailed at Checkpoint: %d\n", checkpoint); \
148 val->print(PRINT_ERROR, "\tActual: %d\n", arg1); \
Bence Szépkúti90a550c2021-12-15 21:18:37 +0100149 if ((status1) != (status2)) \
150 { \
151 val->print(PRINT_ERROR, "\tExpected: %d", status1); \
152 val->print(PRINT_ERROR, "or %d\n", status2); \
153 } \
154 else \
155 { \
156 val->print(PRINT_ERROR, "\tExpected: %d\n", status1); \
157 } \
Gowtham Siddarth47223082019-01-17 09:59:50 +0530158 return 1; \
159 } \
160 } while (0)
161
162#define TEST_ASSERT_NOT_EQUAL(arg1, arg2, checkpoint) \
163 do { \
jotman018ee505a2022-04-12 17:56:45 +0800164 if ((arg1) == PAL_STATUS_UNSUPPORTED_FUNC) \
Antonio de Angelisadfa40e2022-03-29 16:07:10 +0100165 { \
166 return RESULT_SKIP(VAL_STATUS_UNSUPPORTED); \
167 } \
Gowtham Siddarth47223082019-01-17 09:59:50 +0530168 if ((arg1) == arg2) \
169 { \
170 val->print(PRINT_ERROR, "\tFailed at Checkpoint: %d\n", checkpoint); \
171 val->print(PRINT_ERROR, "\tValue: %d\n", arg1); \
172 return 1; \
173 } \
174 } while (0)
175
176#define TEST_ASSERT_MEMCMP(buf1, buf2, size, checkpoint) \
177 do { \
178 if (memcmp(buf1, buf2, size)) \
179 { \
180 val->print(PRINT_ERROR, "\tFailed at Checkpoint: %d : ", checkpoint); \
181 val->print(PRINT_ERROR, "Unequal data in compared buffers\n", 0); \
182 return 1; \
183 } \
184 } while (0)
185
Jaykumar Pitambarbhai Patel0a4740b2020-03-03 16:57:20 +0530186#define TEST_ASSERT_RANGE(arg1, range1, range2, checkpoint) \
187 do { \
jotman018ee505a2022-04-12 17:56:45 +0800188 if ((arg1) == PAL_STATUS_UNSUPPORTED_FUNC) \
Antonio de Angelisadfa40e2022-03-29 16:07:10 +0100189 { \
190 return RESULT_SKIP(VAL_STATUS_UNSUPPORTED); \
191 } \
Jaykumar Pitambarbhai Patel0a4740b2020-03-03 16:57:20 +0530192 if ((arg1) < range1 || (arg1) > range2) \
193 { \
194 val->print(PRINT_ERROR, "\tFailed at Checkpoint: %d\n", checkpoint); \
195 val->print(PRINT_ERROR, "\tActual: %d\n", arg1); \
196 val->print(PRINT_ERROR, "\tExpected range: %d to ", range1); \
197 val->print(PRINT_ERROR, "%d", range2); \
198 return 1; \
199 } \
200 } while (0)
201
jaypit02ea3cd062018-10-05 12:22:38 +0530202/* enums */
203typedef enum {
Gowtham Siddarthb1cd50f2019-08-21 11:50:26 +0530204 CALLER_NONSECURE = 0x0,
205 CALLER_SECURE = 0x1,
206} caller_security_t;
jaypit02ea3cd062018-10-05 12:22:38 +0530207
208typedef enum {
209 TEST_ISOLATION_L1 = 0x1,
210 TEST_ISOLATION_L2 = 0x2,
211 TEST_ISOLATION_L3 = 0x3,
212} test_isolation_level_t;
213
214typedef enum {
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530215 LEVEL1 = 0x1,
216 LEVEL2,
217 LEVEL3,
218} isolation_level_t;
219
220typedef enum {
Jaykumar Pitambarbhai Patelf97bc882019-06-03 11:57:48 +0530221 /* VAL uses this boot flag to mark first time boot of the system */
222 BOOT_UNKNOWN = 0x1,
223 /* VAL/Test uses this boot flag to catch any unwanted system reboot - SIM ERROR Cases*/
224 BOOT_NOT_EXPECTED = 0x2,
225 /* Test performs panic check for non-secure test run and expect reboot */
226 BOOT_EXPECTED_NS = 0x3,
227 /* Test performs panic check for secure test run and expect reboot */
228 BOOT_EXPECTED_S = 0x4,
Gowtham Siddarthb8926262019-08-05 12:59:35 +0530229 /* Test expects reboot but it didn't happen */
Jaykumar Pitambarbhai Patelf97bc882019-06-03 11:57:48 +0530230 BOOT_EXPECTED_BUT_FAILED = 0x5,
Gowtham Siddarthb8926262019-08-05 12:59:35 +0530231 /* Test expects reboot for secure/non-secure test run. If reboot happens,
232 * re-enter the same test and execute the next check function
233 */
Jaykumar Pitambarbhai Patelf97bc882019-06-03 11:57:48 +0530234 BOOT_EXPECTED_REENTER_TEST = 0x6,
Gowtham Siddarthb8926262019-08-05 12:59:35 +0530235 /* Test expect reboot for the test run. If reboot happens,
236 * re-enter the same test and continue executing the same check function
237 */
238 BOOT_EXPECTED_CONT_TEST_EXEC = 0x7,
jk-arm7cc5d1d2022-01-31 08:16:42 +0530239 /* Test expects reboot for secure/non-secure on second check of test . If reboot happens,
240 * re-enter the same test and execute the next check function
241 */
242 BOOT_EXPECTED_ON_SECOND_CHECK = 0x8,
jaypit02ea3cd062018-10-05 12:22:38 +0530243} boot_state_t;
244
245typedef enum {
246 NV_BOOT = 0x0,
247 NV_TEST_ID_PREVIOUS = 0x1,
248 NV_TEST_ID_CURRENT = 0x2,
249 NV_TEST_CNT = 0x3,
Gowtham Siddarthb8926262019-08-05 12:59:35 +0530250 NV_TEST_DATA1 = 0x4,
251 NV_TEST_DATA2 = 0x5,
252 NV_TEST_DATA3 = 0x6,
jaypit02ea3cd062018-10-05 12:22:38 +0530253} nvmem_index_t;
254
jaypit02ea3cd062018-10-05 12:22:38 +0530255/* enums to report test sub-state */
256typedef enum {
257 VAL_STATUS_SUCCESS = 0x0,
258 VAL_STATUS_INVALID = 0x10,
259 VAL_STATUS_ERROR = 0x11,
260 VAL_STATUS_NOT_FOUND = 0x12,
261 VAL_STATUS_LOAD_ERROR = 0x13,
262 VAL_STATUS_INSUFFICIENT_SIZE = 0x14,
263 VAL_STATUS_CONNECTION_FAILED = 0x15,
264 VAL_STATUS_CALL_FAILED = 0x16,
265 VAL_STATUS_READ_FAILED = 0x17,
266 VAL_STATUS_WRITE_FAILED = 0x18,
267 VAL_STATUS_ISOLATION_LEVEL_NOT_SUPP = 0x19,
268 VAL_STATUS_INIT_FAILED = 0x1A,
269 VAL_STATUS_SPM_FAILED = 0x1B,
270 VAL_STATUS_SPM_UNEXPECTED_BEH = 0x1C,
271 VAL_STATUS_FRAMEWORK_VERSION_FAILED = 0x1D,
272 VAL_STATUS_VERSION_API_FAILED = 0x1E,
273 VAL_STATUS_INVALID_HANDLE = 0x1F,
274 VAL_STATUS_INVALID_MSG_TYPE = 0x20,
275 VAL_STATUS_WRONG_IDENTITY = 0x21,
276 VAL_STATUS_MSG_INSIZE_FAILED = 0x22,
277 VAL_STATUS_MSG_OUTSIZE_FAILED = 0x23,
278 VAL_STATUS_SKIP_FAILED = 0x24,
279 VAL_STATUS_CRYPTO_FAILURE = 0x25,
280 VAL_STATUS_INVALID_SIZE = 0x26,
281 VAL_STATUS_DATA_MISMATCH = 0x27,
282 VAL_STATUS_BOOT_EXPECTED_BUT_FAILED = 0x28,
Gowtham Siddarth47223082019-01-17 09:59:50 +0530283 VAL_STATUS_INIT_ALREADY_DONE = 0x29,
284 VAL_STATUS_HEAP_NOT_AVAILABLE = 0x2A,
cherat01914f46a2019-01-24 13:32:09 +0530285 VAL_STATUS_UNSUPPORTED = 0x2B,
Jaykumar Pitambarbhai Patelf97bc882019-06-03 11:57:48 +0530286 VAL_STATUS_DRIVER_FN_FAILED = 0x2C,
Gowtham Siddarthb8926262019-08-05 12:59:35 +0530287 VAL_STATUS_NO_TESTS = 0X2D,
Vikas Katariyaf0175d62019-08-30 11:16:10 +0100288 VAL_STATUS_TEST_FAILED = 0x2E,
Gowtham Siddarth47223082019-01-17 09:59:50 +0530289 VAL_STATUS_ERROR_MAX = INT_MAX,
jaypit02ea3cd062018-10-05 12:22:38 +0530290} val_status_t;
291
292/* verbosity enums */
293typedef enum {
294 PRINT_INFO = 1,
295 PRINT_DEBUG = 2,
296 PRINT_TEST = 3,
297 PRINT_WARN = 4,
298 PRINT_ERROR = 5,
299 PRINT_ALWAYS = 9
300} print_verbosity_t;
301
Jaykumar Pitambarbhai Patelf97bc882019-06-03 11:57:48 +0530302/* Driver test function id enums */
Gowtham Siddarth47223082019-01-17 09:59:50 +0530303typedef enum {
304 TEST_PSA_EOI_WITH_NON_INTR_SIGNAL = 1,
305 TEST_PSA_EOI_WITH_MULTIPLE_SIGNALS = 2,
306 TEST_PSA_EOI_WITH_UNASSERTED_SIGNAL = 3,
307 TEST_INTR_SERVICE = 4,
Jaykumar Pitambarbhai Patelf97bc882019-06-03 11:57:48 +0530308 TEST_ISOLATION_PSA_ROT_DATA_RD = 5,
309 TEST_ISOLATION_PSA_ROT_DATA_WR = 6,
310 TEST_ISOLATION_PSA_ROT_STACK_RD = 7,
311 TEST_ISOLATION_PSA_ROT_STACK_WR = 8,
312 TEST_ISOLATION_PSA_ROT_HEAP_RD = 9,
313 TEST_ISOLATION_PSA_ROT_HEAP_WR = 10,
314 TEST_ISOLATION_PSA_ROT_MMIO_RD = 11,
315 TEST_ISOLATION_PSA_ROT_MMIO_WR = 12,
316} driver_test_fn_id_t;
Gowtham Siddarth47223082019-01-17 09:59:50 +0530317
jaypit02ea3cd062018-10-05 12:22:38 +0530318/* typedef's */
319typedef struct {
320 boot_state_t state;
321} boot_t;
322
323typedef struct {
324 uint32_t pass_cnt:8;
325 uint32_t skip_cnt:8;
326 uint32_t fail_cnt:8;
327 uint32_t sim_error_cnt:8;
328} test_count_t;
329
330typedef struct {
jaypit02ea3cd062018-10-05 12:22:38 +0530331 uint16_t test_num;
332 uint8_t block_num;
333} test_info_t;
334
335
336/* struture to capture test state */
337typedef struct {
338 uint16_t reserved;
339 uint8_t state;
340 uint8_t status;
341} test_status_buffer_t;
342
Gowtham Siddarthb1cd50f2019-08-21 11:50:26 +0530343typedef int32_t (*client_test_t)(caller_security_t caller);
jaypit02ea3cd062018-10-05 12:22:38 +0530344typedef int32_t (*server_test_t)(void);
345#endif /* VAL_COMMON_H */