blob: 2c69ef813b066f1ddc13ebd4ef17f1616d524dba [file] [log] [blame]
jaypit02ea3cd062018-10-05 12:22:38 +05301/** @file
Avi Nawaldcef7342025-07-12 01:23:45 +05302 * Copyright (c) 2018-2025, 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
Avi Nawaldcef7342025-07-12 01:23:45 +053018#ifndef _VAL_H_
19#define _VAL_H_
jaypit02ea3cd062018-10-05 12:22:38 +053020
Gowtham Siddarth47223082019-01-17 09:59:50 +053021#include "pal_common.h"
Avi Nawaldcef7342025-07-12 01:23:45 +053022#include "val_common_log.h"
23#include "val_common_status.h"
jaypit02ea3cd062018-10-05 12:22:38 +053024
25#ifndef VAL_NSPE_BUILD
26#define STATIC_DECLARE static
27#else
28#define STATIC_DECLARE
29#endif
30
31#ifndef __WEAK
32#define __WEAK __attribute__((weak))
33#endif
34
35#ifndef __UNUSED
36#define __UNUSED __attribute__((unused))
37#endif
38
39#ifndef TRUE
40#define TRUE 0
41#endif
42#ifndef FALSE
43#define FALSE 1
44#endif
45
Avi Nawal5e72bf92024-03-14 18:39:09 +080046#define _CONCAT(A, B) A##B
47#define CONCAT(A, B) _CONCAT(A, B)
Murat Cakmak26652972019-01-02 22:18:32 +000048
Avi Nawaldcef7342025-07-12 01:23:45 +053049#define TEST_NUM_BIT 32
jaypit02ea3cd062018-10-05 12:22:38 +053050#define TEST_NUM_MASK 0xFFFFFFFF
jaypit02ea3cd062018-10-05 12:22:38 +053051
Avi Nawaldcef7342025-07-12 01:23:45 +053052#define VAL_ERROR(status) ((status & TEST_STATUS_CODE_MASK) ? 1 : 0)
jaypit02ea3cd062018-10-05 12:22:38 +053053
54
55/* Test Defines */
56#define TEST_PUBLISH(test_id, entry) \
Gowtham Siddarth47223082019-01-17 09:59:50 +053057 const val_test_info_t __attribute__((section(".acs_test_info"))) \
58 CONCAT(acs_test_info, entry) = {test_id, entry}
jaypit02ea3cd062018-10-05 12:22:38 +053059
Gowtham Siddarth47223082019-01-17 09:59:50 +053060#define VAL_MAX_TEST_PER_COMP 200
61#define VAL_FF_BASE 0
62#define VAL_CRYPTO_BASE 1
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +053063#define VAL_STORAGE_BASE 2
64#define VAL_INITIAL_ATTESTATION_BASE 3
Gowtham Siddarth47223082019-01-17 09:59:50 +053065
jaypit02ea3cd062018-10-05 12:22:38 +053066#define VAL_GET_COMP_NUM(test_id) \
67 ((test_id - (test_id % VAL_MAX_TEST_PER_COMP)) / VAL_MAX_TEST_PER_COMP)
68#define VAL_GET_TEST_NUM(test_id) (test_id % VAL_MAX_TEST_PER_COMP)
Avi Nawal5e72bf92024-03-14 18:39:09 +080069#define VAL_CREATE_TEST_ID(comp, num) ((comp*VAL_MAX_TEST_PER_COMP) + num)
jaypit02ea3cd062018-10-05 12:22:38 +053070
Avi Nawal5e72bf92024-03-14 18:39:09 +080071#define TEST_FIELD(num1, num2) (num2 << 8 | num1)
jaypit02ea3cd062018-10-05 12:22:38 +053072#define GET_TEST_ISOLATION_LEVEL(num) (num & 0x3)
Gowtham Siddarth47223082019-01-17 09:59:50 +053073#define GET_WD_TIMOUT_TYPE(num) ((num >> 8) & 0x7)
jaypit02ea3cd062018-10-05 12:22:38 +053074
75#define TEST_CHECKPOINT_NUM(n) n
76#define TEST(n) n
77#define BLOCK(n) n
78
79#define BLOCK_NUM_POS 8
80#define ACTION_POS 16
81#define GET_TEST_NUM(n) (0xff & n)
82#define GET_BLOCK_NUM(n) ((n >> BLOCK_NUM_POS) & 0xff)
83
84#define GET_ACTION_NUM(n) ((n >> ACTION_POS) & 0xff)
85#define TEST_EXECUTE_FUNC 1
86#define TEST_RETURN_RESULT 2
87#define INVALID_HANDLE 0x1234DEAD
88
Gowtham Siddarth47223082019-01-17 09:59:50 +053089#define UART_INIT_SIGN 0xff
jaypit02ac23b5b2018-11-02 13:10:19 +053090#define UART_PRINT_SIGN 0xfe
jaypit02ea3cd062018-10-05 12:22:38 +053091
Gowtham Siddarth47223082019-01-17 09:59:50 +053092#define TEST_PANIC() \
93 do { \
Avi Nawal5e72bf92024-03-14 18:39:09 +080094 } while (1)
Gowtham Siddarth47223082019-01-17 09:59:50 +053095
96#define TEST_ASSERT_EQUAL(arg1, arg2, checkpoint) \
97 do { \
jotman018ee505a2022-04-12 17:56:45 +080098 if ((arg1) == PAL_STATUS_UNSUPPORTED_FUNC) \
Antonio de Angelisadfa40e2022-03-29 16:07:10 +010099 { \
100 return RESULT_SKIP(VAL_STATUS_UNSUPPORTED); \
101 } \
Gowtham Siddarth47223082019-01-17 09:59:50 +0530102 if ((arg1) != arg2) \
103 { \
Avi Nawaldcef7342025-07-12 01:23:45 +0530104 val->print(ERROR, "\tFailed at Checkpoint: %d\n", checkpoint); \
105 val->print(ERROR, "\tActual: %d\n", arg1); \
106 val->print(ERROR, "\tExpected: %d\n", arg2); \
Gowtham Siddarth47223082019-01-17 09:59:50 +0530107 return 1; \
108 } \
109 } while (0)
110
111#define TEST_ASSERT_DUAL(arg1, status1, status2, checkpoint) \
112 do { \
jotman018ee505a2022-04-12 17:56:45 +0800113 if ((arg1) == PAL_STATUS_UNSUPPORTED_FUNC) \
Antonio de Angelisadfa40e2022-03-29 16:07:10 +0100114 { \
115 return RESULT_SKIP(VAL_STATUS_UNSUPPORTED); \
116 } \
Gowtham Siddarth47223082019-01-17 09:59:50 +0530117 if ((arg1) != status1 && (arg1) != status2) \
118 { \
Avi Nawaldcef7342025-07-12 01:23:45 +0530119 val->print(ERROR, "\tFailed at Checkpoint: %d\n", checkpoint); \
120 val->print(ERROR, "\tActual: %d\n", arg1); \
Bence Szépkúti90a550c2021-12-15 21:18:37 +0100121 if ((status1) != (status2)) \
122 { \
Avi Nawaldcef7342025-07-12 01:23:45 +0530123 val->print(ERROR, "\tExpected: %d", status1); \
124 val->print(ERROR, "or %d\n", status2); \
Bence Szépkúti90a550c2021-12-15 21:18:37 +0100125 } \
126 else \
127 { \
Avi Nawaldcef7342025-07-12 01:23:45 +0530128 val->print(ERROR, "\tExpected: %d\n", status1); \
Bence Szépkúti90a550c2021-12-15 21:18:37 +0100129 } \
Gowtham Siddarth47223082019-01-17 09:59:50 +0530130 return 1; \
131 } \
132 } while (0)
133
134#define TEST_ASSERT_NOT_EQUAL(arg1, arg2, checkpoint) \
135 do { \
jotman018ee505a2022-04-12 17:56:45 +0800136 if ((arg1) == PAL_STATUS_UNSUPPORTED_FUNC) \
Antonio de Angelisadfa40e2022-03-29 16:07:10 +0100137 { \
138 return RESULT_SKIP(VAL_STATUS_UNSUPPORTED); \
139 } \
Gowtham Siddarth47223082019-01-17 09:59:50 +0530140 if ((arg1) == arg2) \
141 { \
Avi Nawaldcef7342025-07-12 01:23:45 +0530142 val->print(ERROR, "\tFailed at Checkpoint: %d\n", checkpoint); \
143 val->print(ERROR, "\tValue: %d\n", arg1); \
Gowtham Siddarth47223082019-01-17 09:59:50 +0530144 return 1; \
145 } \
146 } while (0)
147
148#define TEST_ASSERT_MEMCMP(buf1, buf2, size, checkpoint) \
149 do { \
150 if (memcmp(buf1, buf2, size)) \
151 { \
Avi Nawaldcef7342025-07-12 01:23:45 +0530152 val->print(ERROR, "\tFailed at Checkpoint: %d : ", checkpoint); \
153 val->print(ERROR, "Unequal data in compared buffers\n", 0); \
Gowtham Siddarth47223082019-01-17 09:59:50 +0530154 return 1; \
155 } \
156 } while (0)
157
Jaykumar Pitambarbhai Patel0a4740b2020-03-03 16:57:20 +0530158#define TEST_ASSERT_RANGE(arg1, range1, range2, checkpoint) \
159 do { \
jotman018ee505a2022-04-12 17:56:45 +0800160 if ((arg1) == PAL_STATUS_UNSUPPORTED_FUNC) \
Antonio de Angelisadfa40e2022-03-29 16:07:10 +0100161 { \
162 return RESULT_SKIP(VAL_STATUS_UNSUPPORTED); \
163 } \
Jaykumar Pitambarbhai Patel0a4740b2020-03-03 16:57:20 +0530164 if ((arg1) < range1 || (arg1) > range2) \
165 { \
Avi Nawaldcef7342025-07-12 01:23:45 +0530166 val->print(ERROR, "\tFailed at Checkpoint: %d\n", checkpoint); \
167 val->print(ERROR, "\tActual: %d\n", arg1); \
168 val->print(ERROR, "\tExpected range: %d to ", range1); \
169 val->print(ERROR, "%d", range2); \
Jaykumar Pitambarbhai Patel0a4740b2020-03-03 16:57:20 +0530170 return 1; \
171 } \
172 } while (0)
173
jaypit02ea3cd062018-10-05 12:22:38 +0530174/* enums */
175typedef enum {
Gowtham Siddarthb1cd50f2019-08-21 11:50:26 +0530176 CALLER_NONSECURE = 0x0,
177 CALLER_SECURE = 0x1,
178} caller_security_t;
jaypit02ea3cd062018-10-05 12:22:38 +0530179
180typedef enum {
181 TEST_ISOLATION_L1 = 0x1,
182 TEST_ISOLATION_L2 = 0x2,
183 TEST_ISOLATION_L3 = 0x3,
184} test_isolation_level_t;
185
186typedef enum {
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530187 LEVEL1 = 0x1,
188 LEVEL2,
189 LEVEL3,
190} isolation_level_t;
191
192typedef enum {
Jaykumar Pitambarbhai Patelf97bc882019-06-03 11:57:48 +0530193 /* VAL uses this boot flag to mark first time boot of the system */
194 BOOT_UNKNOWN = 0x1,
195 /* VAL/Test uses this boot flag to catch any unwanted system reboot - SIM ERROR Cases*/
196 BOOT_NOT_EXPECTED = 0x2,
197 /* Test performs panic check for non-secure test run and expect reboot */
198 BOOT_EXPECTED_NS = 0x3,
199 /* Test performs panic check for secure test run and expect reboot */
200 BOOT_EXPECTED_S = 0x4,
Gowtham Siddarthb8926262019-08-05 12:59:35 +0530201 /* Test expects reboot but it didn't happen */
Jaykumar Pitambarbhai Patelf97bc882019-06-03 11:57:48 +0530202 BOOT_EXPECTED_BUT_FAILED = 0x5,
Gowtham Siddarthb8926262019-08-05 12:59:35 +0530203 /* Test expects reboot for secure/non-secure test run. If reboot happens,
204 * re-enter the same test and execute the next check function
205 */
Jaykumar Pitambarbhai Patelf97bc882019-06-03 11:57:48 +0530206 BOOT_EXPECTED_REENTER_TEST = 0x6,
Gowtham Siddarthb8926262019-08-05 12:59:35 +0530207 /* Test expect reboot for the test run. If reboot happens,
208 * re-enter the same test and continue executing the same check function
209 */
210 BOOT_EXPECTED_CONT_TEST_EXEC = 0x7,
jk-arm7cc5d1d2022-01-31 08:16:42 +0530211 /* Test expects reboot for secure/non-secure on second check of test . If reboot happens,
212 * re-enter the same test and execute the next check function
213 */
214 BOOT_EXPECTED_ON_SECOND_CHECK = 0x8,
jaypit02ea3cd062018-10-05 12:22:38 +0530215} boot_state_t;
216
jaypit02ea3cd062018-10-05 12:22:38 +0530217/* enums to report test sub-state */
218typedef enum {
219 VAL_STATUS_SUCCESS = 0x0,
jaypit02ea3cd062018-10-05 12:22:38 +0530220 VAL_STATUS_ERROR = 0x11,
221 VAL_STATUS_NOT_FOUND = 0x12,
222 VAL_STATUS_LOAD_ERROR = 0x13,
223 VAL_STATUS_INSUFFICIENT_SIZE = 0x14,
224 VAL_STATUS_CONNECTION_FAILED = 0x15,
225 VAL_STATUS_CALL_FAILED = 0x16,
226 VAL_STATUS_READ_FAILED = 0x17,
227 VAL_STATUS_WRITE_FAILED = 0x18,
228 VAL_STATUS_ISOLATION_LEVEL_NOT_SUPP = 0x19,
229 VAL_STATUS_INIT_FAILED = 0x1A,
230 VAL_STATUS_SPM_FAILED = 0x1B,
231 VAL_STATUS_SPM_UNEXPECTED_BEH = 0x1C,
232 VAL_STATUS_FRAMEWORK_VERSION_FAILED = 0x1D,
233 VAL_STATUS_VERSION_API_FAILED = 0x1E,
234 VAL_STATUS_INVALID_HANDLE = 0x1F,
235 VAL_STATUS_INVALID_MSG_TYPE = 0x20,
236 VAL_STATUS_WRONG_IDENTITY = 0x21,
237 VAL_STATUS_MSG_INSIZE_FAILED = 0x22,
238 VAL_STATUS_MSG_OUTSIZE_FAILED = 0x23,
239 VAL_STATUS_SKIP_FAILED = 0x24,
240 VAL_STATUS_CRYPTO_FAILURE = 0x25,
241 VAL_STATUS_INVALID_SIZE = 0x26,
242 VAL_STATUS_DATA_MISMATCH = 0x27,
243 VAL_STATUS_BOOT_EXPECTED_BUT_FAILED = 0x28,
Gowtham Siddarth47223082019-01-17 09:59:50 +0530244 VAL_STATUS_INIT_ALREADY_DONE = 0x29,
245 VAL_STATUS_HEAP_NOT_AVAILABLE = 0x2A,
cherat01914f46a2019-01-24 13:32:09 +0530246 VAL_STATUS_UNSUPPORTED = 0x2B,
Jaykumar Pitambarbhai Patelf97bc882019-06-03 11:57:48 +0530247 VAL_STATUS_DRIVER_FN_FAILED = 0x2C,
Gowtham Siddarthb8926262019-08-05 12:59:35 +0530248 VAL_STATUS_NO_TESTS = 0X2D,
Vikas Katariyaf0175d62019-08-30 11:16:10 +0100249 VAL_STATUS_TEST_FAILED = 0x2E,
Avi Nawaldcef7342025-07-12 01:23:45 +0530250 VAL_STATUS_MAX_ERROR = INT_MAX,
jaypit02ea3cd062018-10-05 12:22:38 +0530251} val_status_t;
252
Jaykumar Pitambarbhai Patelf97bc882019-06-03 11:57:48 +0530253/* Driver test function id enums */
Gowtham Siddarth47223082019-01-17 09:59:50 +0530254typedef enum {
255 TEST_PSA_EOI_WITH_NON_INTR_SIGNAL = 1,
256 TEST_PSA_EOI_WITH_MULTIPLE_SIGNALS = 2,
257 TEST_PSA_EOI_WITH_UNASSERTED_SIGNAL = 3,
258 TEST_INTR_SERVICE = 4,
Jaykumar Pitambarbhai Patelf97bc882019-06-03 11:57:48 +0530259 TEST_ISOLATION_PSA_ROT_DATA_RD = 5,
260 TEST_ISOLATION_PSA_ROT_DATA_WR = 6,
261 TEST_ISOLATION_PSA_ROT_STACK_RD = 7,
262 TEST_ISOLATION_PSA_ROT_STACK_WR = 8,
263 TEST_ISOLATION_PSA_ROT_HEAP_RD = 9,
264 TEST_ISOLATION_PSA_ROT_HEAP_WR = 10,
265 TEST_ISOLATION_PSA_ROT_MMIO_RD = 11,
266 TEST_ISOLATION_PSA_ROT_MMIO_WR = 12,
267} driver_test_fn_id_t;
Gowtham Siddarth47223082019-01-17 09:59:50 +0530268
Avi Nawaldcef7342025-07-12 01:23:45 +0530269typedef enum {
270 NOT_AVAILABLE = 0x0,
271 AVAILABLE = 0x1,
272} is_available_t;
273
274typedef enum {
275 TYPE_READ_ONLY = 0x10,
276 TYPE_WRITE_ONLY,
277 TYPE_READ_WRITE,
278 TYPE_EXECUTE,
279 TYPE_RESERVED,
280} perm_type_t;
281
jaypit02ea3cd062018-10-05 12:22:38 +0530282/* typedef's */
283typedef struct {
284 boot_state_t state;
285} boot_t;
286
287typedef struct {
jaypit02ea3cd062018-10-05 12:22:38 +0530288 uint16_t test_num;
289 uint8_t block_num;
Avi Nawaldcef7342025-07-12 01:23:45 +0530290} test_info_ipc_t;
jaypit02ea3cd062018-10-05 12:22:38 +0530291
Gowtham Siddarthb1cd50f2019-08-21 11:50:26 +0530292typedef int32_t (*client_test_t)(caller_security_t caller);
jaypit02ea3cd062018-10-05 12:22:38 +0530293typedef int32_t (*server_test_t)(void);
Avi Nawaldcef7342025-07-12 01:23:45 +0530294#endif /* VAL_H */