1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2020 NXP
4  */
5 #ifndef __DCP_UTILS_H__
6 #define __DCP_UTILS_H__
7 
8 #include <drivers/imx/dcp.h>
9 #include <types_ext.h>
10 
11 /* Adjust index value for writing in register */
12 #define DCP_SRAM_KEY_INDEX(idx) SHIFT_U32(idx, 4)
13 
14 /* Calculate context switching buffer offset */
15 #define DCP_CONTEXT_SW_OFFSET(chann) ((DCP_NB_CHANNELS - 1 - (chann)) * 52)
16 
17 /*
18  * Allocate internal driver buffer aligned with a cache line and initialize it
19  * with 0s
20  *
21  * @buf   [out] Buffer to allocate
22  * @size  Size in bytes of the memory to allocate
23  */
24 TEE_Result dcp_calloc_align_buf(struct dcp_align_buf *buf, size_t size);
25 
26 /*
27  * Free allocated memory
28  *
29  * @buf  buffer to free.
30  */
31 void dcp_free(struct dcp_align_buf *buf);
32 
33 /*
34  * Left shifting a multi bytes buffer by one bit
35  *
36  * @result       [out] Buffer containing the result of the operation
37  * @input        Input buffer for the operation
38  * @buffer_size  Size of the buffer in bytes
39  */
40 void dcp_left_shift_buffer(uint8_t *result, uint8_t *input, size_t buffer_size);
41 
42 /*
43  * Wait given microsecond
44  *
45  * @time   Time in microsecond
46  */
47 void dcp_udelay(uint32_t time);
48 
49 /*
50  * Copies elements from a buffer to another one. These elements are copied in
51  * reverse order.
52  *
53  * @in     input buffer
54  * @out    output buffer
55  * @size   bytes to copy
56  */
57 void dcp_reverse(uint8_t *in, uint8_t *out, size_t size);
58 
59 /*
60  * Operate a XOR between two same size buffers
61  *
62  * @a    Input buffer to XOR
63  * @b    Input buffer to XOR
64  * @out  Result of the XOR operation
65  * @size Size of input and output buffers
66  */
67 void dcp_xor(uint8_t *a, uint8_t *b, uint8_t *out, size_t size);
68 
69 /*
70  * CMAC padding.
71  * The padding result is the concatenation of the input buffer block and a
72  * single '1' followed by the minimum number of '0's to get a 128 bits
73  * block.
74  *
75  * @block Block to pad
76  * @len   Length of the padding
77  */
78 void dcp_cmac_padding(uint8_t *block, size_t len);
79 
80 #endif /* __DCP_UTILS_H__ */
81