blob: de9cd8c2477898c70c4c5bebb65400c2e56b85b7 [file] [log] [blame]
jaypit02ea3cd062018-10-05 12:22:38 +05301/** @file
2 * Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
3 * 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
21#include <string.h>
22#include <stdint.h>
23#include <stdlib.h>
24
25/* typedef's */
26typedef uint8_t bool_t;
27typedef uint32_t addr_t;
28typedef uint32_t test_id_t;
29typedef uint32_t block_id_t;
30typedef char char8_t;
31typedef uint32_t cfg_id_t;
32
33
34#ifndef VAL_NSPE_BUILD
35#define STATIC_DECLARE static
36#else
37#define STATIC_DECLARE
38#endif
39
40#ifndef __WEAK
41#define __WEAK __attribute__((weak))
42#endif
43
44#ifndef __UNUSED
45#define __UNUSED __attribute__((unused))
46#endif
47
48#ifndef TRUE
49#define TRUE 0
50#endif
51#ifndef FALSE
52#define FALSE 1
53#endif
54
Murat Cakmak26652972019-01-02 22:18:32 +000055#define _CONCAT(A,B) A##B
56#define CONCAT(A,B) _CONCAT(A,B)
57
jaypit02ea3cd062018-10-05 12:22:38 +053058/* test status defines */
59#define TEST_START 0x01
60#define TEST_END 0x02
61#define TEST_PASS 0x04
62#define TEST_FAIL 0x08
63#define TEST_SKIP 0x10
64#define TEST_PENDING 0x20
65
66#define TEST_NUM_BIT 32
67#define TEST_STATE_BIT 8
68#define TEST_STATUS_BIT 0
69
70#define TEST_NUM_MASK 0xFFFFFFFF
71#define TEST_STATE_MASK 0xFF
72#define TEST_STATUS_MASK 0xFF
73
74#define RESULT_START(status) (((TEST_START) << TEST_STATE_BIT) | ((status) << TEST_STATUS_BIT))
75#define RESULT_END(status) (((TEST_END) << TEST_STATE_BIT) | ((status) << TEST_STATUS_BIT))
76#define RESULT_PASS(status) (((TEST_PASS) << TEST_STATE_BIT) | ((status) << TEST_STATUS_BIT))
77#define RESULT_FAIL(status) (((TEST_FAIL) << TEST_STATE_BIT) | ((status) << TEST_STATUS_BIT))
78#define RESULT_SKIP(status) (((TEST_SKIP) << TEST_STATE_BIT) | ((status) << TEST_STATUS_BIT))
79#define RESULT_PENDING(status) (((TEST_PENDING) << TEST_STATE_BIT) | ((status) << TEST_STATUS_BIT))
80
81#define IS_TEST_FAIL(status) (((status >> TEST_STATE_BIT) & TEST_STATE_MASK) == TEST_FAIL)
82#define IS_TEST_PASS(status) (((status >> TEST_STATE_BIT) & TEST_STATE_MASK) == TEST_PASS)
83#define IS_TEST_SKIP(status) (((status >> TEST_STATE_BIT) & TEST_STATE_MASK) == TEST_SKIP)
84#define IS_TEST_PENDING(status) (((status >> TEST_STATE_BIT) & TEST_STATE_MASK) == TEST_PENDING)
85#define IS_TEST_START(status) (((status >> TEST_STATE_BIT) & TEST_STATE_MASK) == TEST_START)
86#define IS_TEST_END(status) (((status >> TEST_STATE_BIT) & TEST_STATE_MASK) == TEST_END)
87#define VAL_ERROR(status) (status?1:0)
88
89
90
91/* Test Defines */
92#define TEST_PUBLISH(test_id, entry) \
Murat Cakmak26652972019-01-02 22:18:32 +000093 const val_test_info_t __attribute__((section(".acs_test_info"))) CONCAT(acs_test_info, entry) = {test_id, entry}
jaypit02ea3cd062018-10-05 12:22:38 +053094
95#define VAL_MAX_TEST_PER_COMP 200
96#define VAL_FF_BASE 0
97#define VAL_CRYPTO_BASE 1
98#define VAL_GET_COMP_NUM(test_id) \
99 ((test_id - (test_id % VAL_MAX_TEST_PER_COMP)) / VAL_MAX_TEST_PER_COMP)
100#define VAL_GET_TEST_NUM(test_id) (test_id % VAL_MAX_TEST_PER_COMP)
101#define VAL_CREATE_TEST_ID(comp,num) ((comp*VAL_MAX_TEST_PER_COMP) + num)
102
103#define TEST_FIELD(num1,num2) (num2 << 8 | num1)
104#define GET_TEST_ISOLATION_LEVEL(num) (num & 0x3)
105#define GET_WD_TIMOUT_TYPE(num) ((num >> 8) & 0x3)
106
107#define TEST_CHECKPOINT_NUM(n) n
108#define TEST(n) n
109#define BLOCK(n) n
110
111#define BLOCK_NUM_POS 8
112#define ACTION_POS 16
113#define GET_TEST_NUM(n) (0xff & n)
114#define GET_BLOCK_NUM(n) ((n >> BLOCK_NUM_POS) & 0xff)
115
116#define GET_ACTION_NUM(n) ((n >> ACTION_POS) & 0xff)
117#define TEST_EXECUTE_FUNC 1
118#define TEST_RETURN_RESULT 2
119#define INVALID_HANDLE 0x1234DEAD
120
121#define VAL_NVMEM_BLOCK_SIZE 4
122#define VAL_NVMEM_OFFSET(nvmem_idx) (nvmem_idx * VAL_NVMEM_BLOCK_SIZE)
123
124#define UART_INIT_SIGN 0xff
jaypit02ac23b5b2018-11-02 13:10:19 +0530125#define UART_PRINT_SIGN 0xfe
jaypit02ea3cd062018-10-05 12:22:38 +0530126
127/* enums */
128typedef enum {
129 NONSECURE = 0x0,
130 SECURE = 0x1,
131} security_t;
132
133typedef enum {
134 TEST_ISOLATION_L1 = 0x1,
135 TEST_ISOLATION_L2 = 0x2,
136 TEST_ISOLATION_L3 = 0x3,
137} test_isolation_level_t;
138
139typedef enum {
140 BOOT_UNKNOWN = 0x1,
141 BOOT_NOT_EXPECTED = 0x2,
142 BOOT_EXPECTED_NS = 0x3,
143 BOOT_EXPECTED_S = 0x4,
144 BOOT_EXPECTED_BUT_FAILED = 0x5,
145 BOOT_EXPECTED_CRYPTO = 0x6,
146} boot_state_t;
147
148typedef enum {
149 NV_BOOT = 0x0,
150 NV_TEST_ID_PREVIOUS = 0x1,
151 NV_TEST_ID_CURRENT = 0x2,
152 NV_TEST_CNT = 0x3,
153} nvmem_index_t;
154
155typedef enum {
156 WD_INIT_SEQ = 0x1,
157 WD_ENABLE_SEQ = 0x2,
158 WD_DISABLE_SEQ = 0x3,
159 WD_STATUS_SEQ = 0x4,
160} wd_fn_type_t;
161
162typedef enum {
163 WD_LOW_TIMEOUT = 0x1,
164 WD_MEDIUM_TIMEOUT = 0x2,
165 WD_HIGH_TIMEOUT = 0x3,
166} wd_timeout_type_t;
167
168typedef enum {
169 NVMEM_READ = 0x1,
170 NVMEM_WRITE = 0x2,
171} nvmem_fn_type_t;
172
jaypit02ac23b5b2018-11-02 13:10:19 +0530173typedef enum {
174 UART_INIT = 0x1,
175 UART_PRINT = 0x2,
176} uart_fn_type_t;
177
jaypit02ea3cd062018-10-05 12:22:38 +0530178/* enums to report test sub-state */
179typedef enum {
180 VAL_STATUS_SUCCESS = 0x0,
181 VAL_STATUS_INVALID = 0x10,
182 VAL_STATUS_ERROR = 0x11,
183 VAL_STATUS_NOT_FOUND = 0x12,
184 VAL_STATUS_LOAD_ERROR = 0x13,
185 VAL_STATUS_INSUFFICIENT_SIZE = 0x14,
186 VAL_STATUS_CONNECTION_FAILED = 0x15,
187 VAL_STATUS_CALL_FAILED = 0x16,
188 VAL_STATUS_READ_FAILED = 0x17,
189 VAL_STATUS_WRITE_FAILED = 0x18,
190 VAL_STATUS_ISOLATION_LEVEL_NOT_SUPP = 0x19,
191 VAL_STATUS_INIT_FAILED = 0x1A,
192 VAL_STATUS_SPM_FAILED = 0x1B,
193 VAL_STATUS_SPM_UNEXPECTED_BEH = 0x1C,
194 VAL_STATUS_FRAMEWORK_VERSION_FAILED = 0x1D,
195 VAL_STATUS_VERSION_API_FAILED = 0x1E,
196 VAL_STATUS_INVALID_HANDLE = 0x1F,
197 VAL_STATUS_INVALID_MSG_TYPE = 0x20,
198 VAL_STATUS_WRONG_IDENTITY = 0x21,
199 VAL_STATUS_MSG_INSIZE_FAILED = 0x22,
200 VAL_STATUS_MSG_OUTSIZE_FAILED = 0x23,
201 VAL_STATUS_SKIP_FAILED = 0x24,
202 VAL_STATUS_CRYPTO_FAILURE = 0x25,
203 VAL_STATUS_INVALID_SIZE = 0x26,
204 VAL_STATUS_DATA_MISMATCH = 0x27,
205 VAL_STATUS_BOOT_EXPECTED_BUT_FAILED = 0x28,
206} val_status_t;
207
208/* verbosity enums */
209typedef enum {
210 PRINT_INFO = 1,
211 PRINT_DEBUG = 2,
212 PRINT_TEST = 3,
213 PRINT_WARN = 4,
214 PRINT_ERROR = 5,
215 PRINT_ALWAYS = 9
216} print_verbosity_t;
217
218/* typedef's */
219typedef struct {
220 boot_state_t state;
221} boot_t;
222
223typedef struct {
224 uint32_t pass_cnt:8;
225 uint32_t skip_cnt:8;
226 uint32_t fail_cnt:8;
227 uint32_t sim_error_cnt:8;
228} test_count_t;
229
230typedef struct {
231 wd_fn_type_t wd_fn_type;
jaypit02ac23b5b2018-11-02 13:10:19 +0530232 addr_t wd_base_addr;
233 uint32_t wd_time_us;
234 uint32_t wd_timer_tick_us;
jaypit02ea3cd062018-10-05 12:22:38 +0530235} wd_param_t;
236
237typedef struct {
238 nvmem_fn_type_t nvmem_fn_type;
jaypit02ac23b5b2018-11-02 13:10:19 +0530239 addr_t base;
240 uint32_t offset;
241 int size;
jaypit02ea3cd062018-10-05 12:22:38 +0530242} nvmem_param_t;
243
244typedef struct {
jaypit02ea3cd062018-10-05 12:22:38 +0530245 uint16_t test_num;
246 uint8_t block_num;
247} test_info_t;
248
249
250/* struture to capture test state */
251typedef struct {
252 uint16_t reserved;
253 uint8_t state;
254 uint8_t status;
255} test_status_buffer_t;
256
257typedef int32_t (*client_test_t)(security_t caller);
258typedef int32_t (*server_test_t)(void);
259#endif /* VAL_COMMON_H */