1 /* 2 * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef _TEST_PROJ_DEFS_H_ 8 #define _TEST_PROJ_DEFS_H_ 9 10 #include <stdint.h> 11 12 #include "dx_reg_base_host.h" 13 #include "dx_host.h" 14 #include "dx_crys_kernel.h" 15 #include "dx_env.h" 16 #include "dx_nvm.h" 17 #include "cc_regs.h" 18 19 #define BITS_IN_32BIT_WORD 32 20 21 /* Peripheral ID registers values */ 22 #define TEST_PID_0_VAL 0x000000C0UL 23 #define TEST_PID_1_VAL 0x000000B0UL 24 #define TEST_PID_2_VAL 0x0000001BUL 25 #define TEST_PID_3_VAL 0x00000000UL 26 #define TEST_PID_4_VAL 0x00000004UL 27 #define TEST_PID_SIZE_WORDS 5 28 29 /* Component ID registers values */ 30 #define TEST_CID_0_VAL 0x0DUL 31 #define TEST_CID_1_VAL 0xF0UL 32 #define TEST_CID_2_VAL 0x05UL 33 #define TEST_CID_3_VAL 0xB1UL 34 #define TEST_CID_SIZE_WORDS 4 35 36 /* HW KEYS */ 37 #define TEST_SB_HUK_KEY 0 38 #define TEST_SB_KCP_KEY 1 39 #define TEST_SB_KCE_KEY 2 40 #define TEST_SB_KPICV_KEY 3 41 #define TEST_SB_KCEICV_KEY 4 42 43 44 #define TEST_PROJ_LCS_CM 0 45 #define TEST_PROJ_LCS_DM 1 46 #define TEST_PROJ_LCS_SECURE 5 47 #define TEST_PROJ_LCS_RMA 7 48 #define INVALID_LCS (-1) 49 50 #define TST_SET_ENV_TO_SECURE() \ 51 do { \ 52 TEST_WRITE_TEE_ENV_REG( DX_ENV_APB_PPROT_OVERRIDE_REG_OFFSET, 0x9); \ 53 }while(0) 54 55 /* poll NVM register to be assure that the NVM boot is finished (and LCS and the keys are valid) */ 56 #define WAIT_NVM_IDLE() \ 57 do { \ 58 uint32_t regVal; \ 59 do { \ 60 regVal = TEST_READ_TEE_CC_REG(CC_REG_OFFSET(HOST_RGF, NVM_IS_IDLE)); \ 61 regVal = CC_REG_FLD_GET(0, NVM_IS_IDLE, VALUE, regVal); \ 62 }while( !regVal ); \ 63 }while(0) 64 65 /* turn off DFA */ 66 #define TURN_DFA_OFF() {\ 67 uint32_t regVal; \ 68 regVal = TEST_READ_TEE_CC_REG(CC_REG_OFFSET(HOST_RGF, HOST_AO_LOCK_BITS)); \ 69 CC_REG_FLD_SET(0, HOST_AO_LOCK_BITS, HOST_FORCE_DFA_ENABLE, regVal, 0); \ 70 CC_REG_FLD_SET(0, HOST_AO_LOCK_BITS, HOST_DFA_ENABLE_LOCK, regVal, 1); \ 71 TEST_WRITE_TEE_CC_REG(CC_REG_OFFSET(HOST_RGF, HOST_AO_LOCK_BITS) ,regVal ); \ 72 TEST_WRITE_TEE_CC_REG(CC_REG_OFFSET(HOST_RGF, AES_DFA_IS_ON) ,0 ); \ 73 } 74 75 /****************************************************************************/ 76 /* External API */ 77 /* 78 * @brief This function Maps the proj HW. 79 * 80 * @param[in] 81 * 82 * @param[out] 83 * 84 * @return rc - 0 for success, 1 for failure. 85 */ 86 uint32_t Test_ProjMap(void); 87 88 /****************************************************************************/ 89 /* 90 * @brief This function Maps the proj HW. 91 * 92 * @param[in] 93 * 94 * @param[out] 95 * 96 * @return none. 97 */ 98 void Test_ProjUnmap(void); 99 100 /****************************************************************************/ 101 /* 102 * @brief This function reads LCS register and verifies that LCS value is as expected. 103 * 104 * @param[in] LCS correct value. 105 * 106 * @param[out] 107 * 108 * @return rc - 0 for success, 1 for failure. 109 */ 110 uint32_t Test_ProjCheckLcs(uint32_t nextLcs); 111 112 113 /****************************************************************************/ 114 /* 115 * @brief This function reads LCS register, verifies that LCS value is as 116 * expected and no HW errors exist in HUK, Kcp* and Kce*. 117 * 118 * @param[in] LCS correct value. 119 * 120 * @param[out] 121 * 122 * @return rc - 0 for success, 1 for failure. 123 */ 124 uint32_t Test_ProjCheckLcsAndError(uint32_t nextLcs); 125 126 127 /****************************************************************************/ 128 /* 129 * @brief This function returns the current LCS value. 130 * 131 * @param[in] 132 * 133 * @param[out] LCS value. 134 * 135 * @return 0. 136 */ 137 uint32_t Test_ProjGetLcs(uint32_t *lcs); 138 139 140 /****************************************************************************/ 141 /* 142 * @brief This function performs global reset of CC, AO and environment registers. 143 * 144 * @param[in] 145 * 146 * @param[out] 147 * 148 * @return 149 */ 150 void Test_ProjPerformPowerOnReset(void); 151 152 /****************************************************************************/ 153 /* 154 * @brief This function resets CC and AO registers. 155 * 156 * @param[in] 157 * 158 * @param[out] 159 * 160 * @return 161 */ 162 void Test_ProjPerformColdReset(void); 163 164 /****************************************************************************/ 165 /* 166 * @brief This function resets CC registers. 167 * 168 * @param[in] 169 * 170 * @param[out] 171 * 172 * @return 173 */ 174 void Test_ProjPerformWarmReset(void); 175 176 /****************************************************************************/ 177 /* 178 * @brief This function resets CC registers. 179 * 180 * @param[in] 181 * 182 * @param[out] 183 * 184 * @return 185 */ 186 uint32_t Test_ProjVerifyPIDReg(void); 187 188 /****************************************************************************/ 189 /* 190 * @brief This function resets CC registers. 191 * 192 * @param[in] 193 * 194 * @param[out] 195 * 196 * @return 197 */ 198 uint32_t Test_ProjVerifyCIDReg(void); 199 200 201 #endif /* _TEST_PROJ_DEFS_H_ */ 202