1 /***************************************************************************//**
2 * \file cy_crypto_core_vu.h
3 * \version 2.120
4 *
5 * \brief
6 *  This file provides the headers to the API for the utils
7 *  in the Crypto driver.
8 *
9 ********************************************************************************
10 * \copyright
11 * Copyright (c) (2020-2022), Cypress Semiconductor Corporation (an Infineon company) or
12 * an affiliate of Cypress Semiconductor Corporation.
13 * SPDX-License-Identifier: Apache-2.0
14 *
15 * Licensed under the Apache License, Version 2.0 (the "License");
16 * you may not use this file except in compliance with the License.
17 * You may obtain a copy of the License at
18 *
19 *    http://www.apache.org/licenses/LICENSE-2.0
20 *
21 * Unless required by applicable law or agreed to in writing, software
22 * distributed under the License is distributed on an "AS IS" BASIS,
23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 * See the License for the specific language governing permissions and
25 * limitations under the License.
26 *******************************************************************************/
27 
28 
29 #if !defined (CY_CRYPTO_CORE_VU_H)
30 #define CY_CRYPTO_CORE_VU_H
31 
32 #include "cy_device.h"
33 
34 #if defined (CY_IP_MXCRYPTO)
35 
36 #include "cy_crypto_common.h"
37 
38 #if defined(__cplusplus)
39 extern "C" {
40 #endif
41 
42 #if (CPUSS_CRYPTO_VU == 1)
43 
44 #include "cy_crypto_core_hw.h"
45 #include "cy_crypto_core_hw_vu.h"
46 #include <string.h>
47 
48 /**
49 * \addtogroup group_crypto_lld_vu_functions
50 * \{
51 */
52 
53 /*******************************************************************************
54 * Function Name: Cy_Crypto_Core_Vu_SetMemValue
55 ****************************************************************************//**
56 *
57 * Sets the value in the Crypto memory allocated by the destination VU register.
58 *
59 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled, the user is expected to maintain the cache coherency of data..
60 *
61 * \param base
62 * The pointer to the CRYPTO instance.
63 *
64 * \param dstReg
65 * The destination vector unit register.
66 *
67 * \param src
68 * The pointer to the source value.
69 *
70 * \param size
71 * The size of the operated value.
72 *
73 *******************************************************************************/
74 void Cy_Crypto_Core_Vu_SetMemValue(CRYPTO_Type *base, uint32_t dstReg, uint8_t const *src, uint32_t size);
75 
76 /*******************************************************************************
77 * Function Name: Cy_Crypto_Core_Vu_GetMemValue
78 ****************************************************************************//**
79 *
80 * Gets the value located in the crypto memory and pointed by source VU register.
81 *
82 * For CAT1C & CAT1D(CM55) devices when D-Cache is enabled, the user is expected to maintain the cache coherency of data..
83 *
84 * \param base
85 * The pointer to the CRYPTO instance.
86 *
87 * \param dst
88 * The pointer to the destination value.
89 *
90 * \param srcReg
91 * The source vector unit register.
92 *
93 * \param size
94 * The size of the operated value.
95 *
96 *******************************************************************************/
97 void Cy_Crypto_Core_Vu_GetMemValue(CRYPTO_Type *base, uint8_t *dst, uint32_t srcReg, uint32_t size);
98 
99 /*******************************************************************************
100 * Function Name: Cy_Crypto_Core_Vu_IsRegZero
101 ****************************************************************************//**
102 *
103 * Returns TRUE if srcReg contains 0. FALSE - otherwise.
104 *
105 * \param base
106 * The pointer to the CRYPTO instance.
107 *
108 * \param srcReg
109 * The source vector unit register.
110 *
111 * \return
112 * The result of the comparison.
113 *
114 *******************************************************************************/
115 bool Cy_Crypto_Core_Vu_IsRegZero(CRYPTO_Type *base, uint32_t srcReg);
116 
117 /*******************************************************************************
118 * Function Name: Cy_Crypto_Core_Vu_IsRegEqual
119 ****************************************************************************//**
120 *
121 * Returns TRUE if srcReg0 contains the same value as srcReg1. FALSE - otherwise.
122 *
123 * \param base
124 * The pointer to the CRYPTO instance.
125 *
126 * \param srcReg0
127 * The source 0 vector unit register.
128 *
129 * \param srcReg1
130 * The source 1 vector unit register.
131 *
132 * \return
133 * The result of the comparison.
134 *
135 *******************************************************************************/
136 bool Cy_Crypto_Core_Vu_IsRegEqual(CRYPTO_Type *base, uint32_t srcReg0, uint32_t srcReg1);
137 
138 /*******************************************************************************
139 * Function Name: Cy_Crypto_Core_Vu_IsRegEqual
140 ****************************************************************************//**
141 *
142 * Returns TRUE if srcReg0 contains the value less than value of srcReg1.
143 * FALSE - otherwise.
144 *
145 * \param base
146 * The pointer to the CRYPTO instance.
147 *
148 * \param srcReg0
149 * The source 0 vector unit register.
150 *
151 * \param srcReg1
152 * The source 1 vector unit register.
153 *
154 * \return
155 * The result of the comparison.
156 *
157 *******************************************************************************/
158 bool Cy_Crypto_Core_Vu_IsRegLess(CRYPTO_Type *base, uint32_t srcReg0, uint32_t srcReg1);
159 
160 /*******************************************************************************
161 * Function Name: Cy_Crypto_Core_Vu_RegRead
162 ****************************************************************************//**
163 *
164 * Returns the data pointed in a given register.
165 *
166 * \param base
167 * The pointer to the CRYPTO instance.
168 *
169 * \param srcReg
170 * The source vector unit register.
171 *
172 *******************************************************************************/
Cy_Crypto_Core_Vu_RegRead(CRYPTO_Type * base,uint32_t srcReg)173 __STATIC_INLINE uint32_t Cy_Crypto_Core_Vu_RegRead(CRYPTO_Type *base, uint32_t srcReg)
174 {
175     return ((uint32_t)_FLD2VAL(CRYPTO_RF_DATA_DATA32, REG_CRYPTO_VU_RF_DATA(base, srcReg)));
176 }
177 
178 /*******************************************************************************
179 * Function Name: Cy_Crypto_Core_Vu_RegSizeRead
180 ****************************************************************************//**
181 *
182 * Returns size of the data pointed in given register,
183 * it is lower 12Bit of the 32Bit word
184 *
185 * \param base
186 * The pointer to the CRYPTO instance.
187 *
188 * \param srcReg
189 * The source vector unit register.
190 *
191 *******************************************************************************/
Cy_Crypto_Core_Vu_RegSizeRead(CRYPTO_Type * base,uint32_t srcReg)192 __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegSizeRead(CRYPTO_Type *base, uint32_t srcReg)
193 {
194     return ((uint16_t)(_FLD2VAL(CRYPTO_RF_DATA_DATA32, REG_CRYPTO_VU_RF_DATA(base, srcReg)) & CY_CRYPTO_VU_SIZE_FLD_MASK));
195 }
196 
197 /*******************************************************************************
198 * Function Name: Cy_Crypto_Core_Vu_RegBitSizeRead
199 ****************************************************************************//**
200 *
201 * Returns size of the data pointed in given register, in Bits.
202 * It is lower 12Bit of the 32Bit word
203 *
204 * \param base
205 * The pointer to the CRYPTO instance.
206 *
207 * \param srcReg
208 * The source vector unit register.
209 *
210 *******************************************************************************/
Cy_Crypto_Core_Vu_RegBitSizeRead(CRYPTO_Type * base,uint32_t srcReg)211 __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegBitSizeRead(CRYPTO_Type *base, uint32_t srcReg)
212 {
213     return ((uint16_t)(_FLD2VAL(CRYPTO_RF_DATA_DATA32, REG_CRYPTO_VU_RF_DATA(base, srcReg)) & CY_CRYPTO_VU_SIZE_FLD_MASK) + 1u);
214 }
215 
216 /*******************************************************************************
217 * Function Name: Cy_Crypto_Core_Vu_RegByteSizeRead
218 ****************************************************************************//**
219 *
220 * Returns size of the data pointed in given register, in Bytes.
221 * It is lower 12Bit of the 32Bit word
222 *
223 * \param base
224 * The pointer to the CRYPTO instance.
225 *
226 * \param srcReg
227 * The source vector unit register.
228 *
229 *******************************************************************************/
Cy_Crypto_Core_Vu_RegByteSizeRead(CRYPTO_Type * base,uint32_t srcReg)230 __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegByteSizeRead(CRYPTO_Type *base, uint32_t srcReg)
231 {
232     return ((uint16_t)((_FLD2VAL(CRYPTO_RF_DATA_DATA32, REG_CRYPTO_VU_RF_DATA(base, srcReg)) & CY_CRYPTO_VU_SIZE_FLD_MASK) + 1u) >> 3u);
233 }
234 
235 /*******************************************************************************
236 * Function Name: Cy_Crypto_Core_Vu_RegWordSizeRead
237 ****************************************************************************//**
238 *
239 * Returns size of the data pointed in given register, in words (uint32_t).
240 * It is lower 12Bit of the 32Bit word
241 *
242 * \param base
243 * The pointer to the CRYPTO instance.
244 *
245 * \param srcReg
246 * The source vector unit register.
247 *
248 *******************************************************************************/
Cy_Crypto_Core_Vu_RegWordSizeRead(CRYPTO_Type * base,uint32_t srcReg)249 __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegWordSizeRead(CRYPTO_Type *base, uint32_t srcReg)
250 {
251     return ((uint16_t)((_FLD2VAL(CRYPTO_RF_DATA_DATA32, REG_CRYPTO_VU_RF_DATA(base, srcReg)) & CY_CRYPTO_VU_SIZE_FLD_MASK) + 1u) >> 5u);
252 }
253 
254 /*******************************************************************************
255 * Function Name: Cy_Crypto_Core_Vu_RegDataPtrRead
256 ****************************************************************************//**
257 *
258 * Returns the data pointer, in 14-bit format of the data pointed in given register,
259 * it is upper 16Bit of the 32Bir word. Pointer is in words (uint32_t).
260 *
261 * \param base
262 * The pointer to the CRYPTO instance.
263 *
264 * \param srcReg
265 * The source vector unit register.
266 *
267 *******************************************************************************/
Cy_Crypto_Core_Vu_RegDataPtrRead(CRYPTO_Type * base,uint32_t srcReg)268 __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegDataPtrRead(CRYPTO_Type *base, uint32_t srcReg)
269 {
270     return (uint16_t)((_FLD2VAL(CRYPTO_RF_DATA_DATA32, REG_CRYPTO_VU_RF_DATA(base, srcReg)) >> CY_CRYPTO_VU_DATA_FLD_POS)
271                                 & CY_CRYPTO_VU_DATA_FLD_MASK);
272 }
273 
274 /*******************************************************************************
275 * Function Name: Cy_Crypto_Core_Vu_RegMemPointer
276 ****************************************************************************//**
277 *
278 * Returns the memory address of the data pointed in given register.
279 *
280 * \param base
281 * The pointer to the CRYPTO instance.
282 *
283 * \param srcReg
284 * The source vector unit register.
285 *
286 *******************************************************************************/
Cy_Crypto_Core_Vu_RegMemPointer(CRYPTO_Type * base,uint32_t srcReg)287 __STATIC_INLINE uint32_t * Cy_Crypto_Core_Vu_RegMemPointer(CRYPTO_Type *base, uint32_t srcReg)
288 {
289     return (uint32_t *)((uint32_t)REG_CRYPTO_VU_CTL1(base) + (4u * (uint32_t)Cy_Crypto_Core_Vu_RegDataPtrRead(base, srcReg)));
290 }
291 
292 /*******************************************************************************
293 * Function Name: Cy_Crypto_Core_Vu_StatusRead
294 ****************************************************************************//**
295 *
296 * Returns the value of the VU status register.
297 *
298 * \param base
299 * The pointer to the CRYPTO instance.
300 *
301 *******************************************************************************/
Cy_Crypto_Core_Vu_StatusRead(CRYPTO_Type * base)302 __STATIC_INLINE uint32_t Cy_Crypto_Core_Vu_StatusRead(CRYPTO_Type *base)
303 {
304     /* Wait until the VU instruction is complete */
305     Cy_Crypto_Core_Vu_WaitForComplete(base);
306 
307     return((uint32_t)REG_CRYPTO_VU_STATUS(base));
308 }
309 
310 /*******************************************************************************
311 * Function Name: Cy_Crypto_Core_VU_RegInvertEndianness
312 ****************************************************************************//**
313 *
314 * Reverts the memory data block pointed in given register.
315 *
316 * \param base
317 * The pointer to the CRYPTO instance.
318 *
319 * \param srcReg
320 * The source vector unit register.
321 *
322 *******************************************************************************/
323 void Cy_Crypto_Core_VU_RegInvertEndianness(CRYPTO_Type *base, uint32_t srcReg);
324 
325 /** \} group_crypto_lld_vu_functions */
326 
327 #endif /* #if (CPUSS_CRYPTO_VU == 1) */
328 
329 #if defined(__cplusplus)
330 }
331 #endif
332 
333 #endif /* CY_IP_MXCRYPTO */
334 
335 #endif /* #if !defined (CY_CRYPTO_CORE_VU_H) */
336 
337 /* [] END OF FILE */
338