1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (C) Foundries Ltd. 2022
4  * Author: Jorge Ramirez <jorge@foundries.io>
5  */
6 
7 #ifndef IPI_H
8 #define IPI_H
9 
10 #include <drivers/versal_mbox.h>
11 
12 struct versal_rsa_input_param {
13 	uint64_t key_addr;
14 	uint64_t data_addr;
15 	uint32_t key_len;
16 };
17 
18 struct versal_rsa_sign_param {
19 	uint64_t sign_addr;
20 	uint64_t hash_addr;
21 	uint32_t hash_len;
22 };
23 
24 struct versal_ecc_sign_param {
25 	uint64_t hash_addr;
26 	uint64_t priv_key_addr;
27 	uint64_t epriv_key_addr;
28 	uint32_t curve;
29 	uint32_t hash_len;
30 };
31 
32 struct versal_ecc_verify_param {
33 	uint64_t hash_addr;
34 	uint64_t pub_key_addr;
35 	uint64_t signature_addr;
36 	uint32_t curve;
37 	uint32_t hash_len;
38 };
39 
40 enum versal_aes_operation { VERSAL_AES_ENCRYPT, VERSAL_AES_DECRYPT };
41 
42 struct versal_aes_init {
43 	uint64_t iv_addr;
44 	uint32_t operation;
45 	uint32_t key_src;
46 	uint32_t key_len;
47 };
48 
49 struct versal_aes_input_param {
50 	uint64_t input_addr;
51 	uint32_t input_len;
52 	uint32_t is_last;
53 };
54 
55 enum versal_crypto_api {
56 	VERSAL_FEATURES = 0U,
57 	VERSAL_RSA_SIGN_VERIFY,
58 	VERSAL_RSA_PUBLIC_ENCRYPT,
59 	VERSAL_RSA_PRIVATE_DECRYPT,
60 	VERSAL_RSA_KAT,
61 	VERSAL_SHA3_UPDATE = 32U,
62 	VERSAL_SHA3_KAT,
63 	VERSAL_ELLIPTIC_GENERATE_PUBLIC_KEY = 64U,
64 	VERSAL_ELLIPTIC_GENERATE_SIGN,
65 	VERSAL_ELLIPTIC_VALIDATE_PUBLIC_KEY,
66 	VERSAL_ELLIPTIC_VERIFY_SIGN,
67 	VERSAL_ELLIPTIC_KAT,
68 	VERSAL_AES_INIT = 96U,
69 	VERSAL_AES_OP_INIT,
70 	VERSAL_AES_UPDATE_AAD,
71 	VERSAL_AES_ENCRYPT_UPDATE,
72 	VERSAL_AES_ENCRYPT_FINAL,
73 	VERSAL_AES_DECRYPT_UPDATE,
74 	VERSAL_AES_DECRYPT_FINAL,
75 	VERSAL_AES_KEY_ZERO,
76 	VERSAL_AES_WRITE_KEY,
77 	VERSAL_AES_LOCK_USER_KEY,
78 	VERSAL_AES_KEK_DECRYPT,
79 	VERSAL_AES_SET_DPA_CM,
80 	VERSAL_AES_DECRYPT_KAT,
81 	VERSAL_AES_DECRYPT_CM_KAT,
82 	VERSAL_CRYPTO_API_MAX
83 };
84 
85 #define VERSAL_MAX_IPI_REGS 6
86 
87 struct versal_cmd_args {
88 	uint32_t data[VERSAL_MAX_IPI_REGS];
89 	size_t dlen;
90 	struct versal_ipi_buf ibuf[VERSAL_MAX_IPI_BUF];
91 };
92 
93 TEE_Result versal_crypto_request(enum versal_crypto_api id,
94 				 struct versal_cmd_args *arg, uint32_t *err);
95 #endif
96 
97