Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

firmware: xilinx: Add firmware API's to support aes-gcm in Versal device

Add aes-gcm crypto API's for AMD/Xilinx Versal device.

Signed-off-by: Harsh Jain <h.jain@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Harsh Jain and committed by
Herbert Xu
e9f6870b c315cb00

+223 -3
+149 -1
drivers/firmware/xilinx/zynqmp-crypto.c
··· 60 60 61 61 /** 62 62 * xlnx_get_crypto_dev_data() - Get crypto dev data of platform 63 - * @feature_map: List of available feature map of all platform 63 + * @feature_map: List of available feature map of all platform 64 64 * 65 65 * Return: Returns crypto dev data, either address crypto dev or ERR PTR 66 66 */ ··· 88 88 return ERR_PTR(-ENODEV); 89 89 } 90 90 EXPORT_SYMBOL_GPL(xlnx_get_crypto_dev_data); 91 + 92 + /** 93 + * versal_pm_aes_key_write - Write AES key registers 94 + * @keylen: Size of the input key to be written 95 + * @keysrc: Key Source to be selected to which provided 96 + * key should be updated 97 + * @keyaddr: Address of a buffer which should contain the key 98 + * to be written 99 + * 100 + * This function provides support to write AES volatile user keys. 101 + * 102 + * Return: Returns status, either success or error+reason 103 + */ 104 + int versal_pm_aes_key_write(const u32 keylen, 105 + const u32 keysrc, const u64 keyaddr) 106 + { 107 + return zynqmp_pm_invoke_fn(XSECURE_API_AES_WRITE_KEY, NULL, 4, 108 + keylen, keysrc, 109 + lower_32_bits(keyaddr), 110 + upper_32_bits(keyaddr)); 111 + } 112 + EXPORT_SYMBOL_GPL(versal_pm_aes_key_write); 113 + 114 + /** 115 + * versal_pm_aes_key_zero - Zeroise AES User key registers 116 + * @keysrc: Key Source to be selected to which provided 117 + * key should be updated 118 + * 119 + * This function provides support to zeroise AES volatile user keys. 120 + * 121 + * Return: Returns status, either success or error+reason 122 + */ 123 + int versal_pm_aes_key_zero(const u32 keysrc) 124 + { 125 + return zynqmp_pm_invoke_fn(XSECURE_API_AES_KEY_ZERO, NULL, 1, keysrc); 126 + } 127 + EXPORT_SYMBOL_GPL(versal_pm_aes_key_zero); 128 + 129 + /** 130 + * versal_pm_aes_op_init - Init AES operation 131 + * @hw_req: AES op init structure address 132 + * 133 + * This function provides support to init AES operation. 134 + * 135 + * Return: Returns status, either success or error+reason 136 + */ 137 + int versal_pm_aes_op_init(const u64 hw_req) 138 + { 139 + return zynqmp_pm_invoke_fn(XSECURE_API_AES_OP_INIT, NULL, 2, 140 + lower_32_bits(hw_req), 141 + upper_32_bits(hw_req)); 142 + } 143 + EXPORT_SYMBOL_GPL(versal_pm_aes_op_init); 144 + 145 + /** 146 + * versal_pm_aes_update_aad - AES update aad 147 + * @aad_addr: AES aad address 148 + * @aad_len: AES aad data length 149 + * 150 + * This function provides support to update AAD data. 151 + * 152 + * Return: Returns status, either success or error+reason 153 + */ 154 + int versal_pm_aes_update_aad(const u64 aad_addr, const u32 aad_len) 155 + { 156 + return zynqmp_pm_invoke_fn(XSECURE_API_AES_UPDATE_AAD, NULL, 3, 157 + lower_32_bits(aad_addr), 158 + upper_32_bits(aad_addr), 159 + aad_len); 160 + } 161 + EXPORT_SYMBOL_GPL(versal_pm_aes_update_aad); 162 + 163 + /** 164 + * versal_pm_aes_enc_update - Access AES hardware to encrypt the data using 165 + * AES-GCM core. 166 + * @in_params: Address of the AesParams structure 167 + * @in_addr: Address of input buffer 168 + * 169 + * Return: Returns status, either success or error code. 170 + */ 171 + int versal_pm_aes_enc_update(const u64 in_params, const u64 in_addr) 172 + { 173 + return zynqmp_pm_invoke_fn(XSECURE_API_AES_ENCRYPT_UPDATE, NULL, 4, 174 + lower_32_bits(in_params), 175 + upper_32_bits(in_params), 176 + lower_32_bits(in_addr), 177 + upper_32_bits(in_addr)); 178 + } 179 + EXPORT_SYMBOL_GPL(versal_pm_aes_enc_update); 180 + 181 + /** 182 + * versal_pm_aes_enc_final - Access AES hardware to store the GCM tag 183 + * @gcm_addr: Address of the gcm tag 184 + * 185 + * Return: Returns status, either success or error code. 186 + */ 187 + int versal_pm_aes_enc_final(const u64 gcm_addr) 188 + { 189 + return zynqmp_pm_invoke_fn(XSECURE_API_AES_ENCRYPT_FINAL, NULL, 2, 190 + lower_32_bits(gcm_addr), 191 + upper_32_bits(gcm_addr)); 192 + } 193 + EXPORT_SYMBOL_GPL(versal_pm_aes_enc_final); 194 + 195 + /** 196 + * versal_pm_aes_dec_update - Access AES hardware to decrypt the data using 197 + * AES-GCM core. 198 + * @in_params: Address of the AesParams structure 199 + * @in_addr: Address of input buffer 200 + * 201 + * Return: Returns status, either success or error code. 202 + */ 203 + int versal_pm_aes_dec_update(const u64 in_params, const u64 in_addr) 204 + { 205 + return zynqmp_pm_invoke_fn(XSECURE_API_AES_DECRYPT_UPDATE, NULL, 4, 206 + lower_32_bits(in_params), 207 + upper_32_bits(in_params), 208 + lower_32_bits(in_addr), 209 + upper_32_bits(in_addr)); 210 + } 211 + EXPORT_SYMBOL_GPL(versal_pm_aes_dec_update); 212 + 213 + /** 214 + * versal_pm_aes_dec_final - Access AES hardware to get the GCM tag 215 + * @gcm_addr: Address of the gcm tag 216 + * 217 + * Return: Returns status, either success or error code. 218 + */ 219 + int versal_pm_aes_dec_final(const u64 gcm_addr) 220 + { 221 + return zynqmp_pm_invoke_fn(XSECURE_API_AES_DECRYPT_FINAL, NULL, 2, 222 + lower_32_bits(gcm_addr), 223 + upper_32_bits(gcm_addr)); 224 + } 225 + EXPORT_SYMBOL_GPL(versal_pm_aes_dec_final); 226 + 227 + /** 228 + * versal_pm_aes_init - Init AES block 229 + * 230 + * This function initialise AES block. 231 + * 232 + * Return: Returns status, either success or error+reason 233 + */ 234 + int versal_pm_aes_init(void) 235 + { 236 + return zynqmp_pm_invoke_fn(XSECURE_API_AES_INIT, NULL, 0); 237 + } 238 + EXPORT_SYMBOL_GPL(versal_pm_aes_init);
+74 -2
include/linux/firmware/xlnx-zynqmp-crypto.h
··· 2 2 /* 3 3 * Firmware layer for XilSECURE APIs. 4 4 * 5 - * Copyright (C) 2014-2022 Xilinx, Inc. 6 - * Copyright (C) 2022-2025 Advanced Micro Devices, Inc. 5 + * Copyright (C) 2014-2022 Xilinx, Inc. 6 + * Copyright (C) 2022-2025 Advanced Micro Devices, Inc. 7 7 */ 8 8 9 9 #ifndef __FIRMWARE_XLNX_ZYNQMP_CRYPTO_H__ ··· 22 22 void *data; 23 23 }; 24 24 25 + /* xilSecure API commands module id + api id */ 26 + #define XSECURE_API_AES_INIT 0x509 27 + #define XSECURE_API_AES_OP_INIT 0x50a 28 + #define XSECURE_API_AES_UPDATE_AAD 0x50b 29 + #define XSECURE_API_AES_ENCRYPT_UPDATE 0x50c 30 + #define XSECURE_API_AES_ENCRYPT_FINAL 0x50d 31 + #define XSECURE_API_AES_DECRYPT_UPDATE 0x50e 32 + #define XSECURE_API_AES_DECRYPT_FINAL 0x50f 33 + #define XSECURE_API_AES_KEY_ZERO 0x510 34 + #define XSECURE_API_AES_WRITE_KEY 0x511 35 + 25 36 #if IS_REACHABLE(CONFIG_ZYNQMP_FIRMWARE) 26 37 int zynqmp_pm_aes_engine(const u64 address, u32 *out); 27 38 int zynqmp_pm_sha_hash(const u64 address, const u32 size, const u32 flags); 28 39 void *xlnx_get_crypto_dev_data(struct xlnx_feature *feature_map); 40 + int versal_pm_aes_key_write(const u32 keylen, 41 + const u32 keysrc, const u64 keyaddr); 42 + int versal_pm_aes_key_zero(const u32 keysrc); 43 + int versal_pm_aes_op_init(const u64 hw_req); 44 + int versal_pm_aes_update_aad(const u64 aad_addr, const u32 aad_len); 45 + int versal_pm_aes_enc_update(const u64 in_params, const u64 in_addr); 46 + int versal_pm_aes_dec_update(const u64 in_params, const u64 in_addr); 47 + int versal_pm_aes_dec_final(const u64 gcm_addr); 48 + int versal_pm_aes_enc_final(const u64 gcm_addr); 49 + int versal_pm_aes_init(void); 50 + 29 51 #else 30 52 static inline int zynqmp_pm_aes_engine(const u64 address, u32 *out) 31 53 { ··· 64 42 { 65 43 return ERR_PTR(-ENODEV); 66 44 } 45 + 46 + static inline int versal_pm_aes_key_write(const u32 keylen, 47 + const u32 keysrc, const u64 keyaddr) 48 + { 49 + return -ENODEV; 50 + } 51 + 52 + static inline int versal_pm_aes_key_zero(const u32 keysrc) 53 + { 54 + return -ENODEV; 55 + } 56 + 57 + static inline int versal_pm_aes_op_init(const u64 hw_req) 58 + { 59 + return -ENODEV; 60 + } 61 + 62 + static inline int versal_pm_aes_update_aad(const u64 aad_addr, 63 + const u32 aad_len) 64 + { 65 + return -ENODEV; 66 + } 67 + 68 + static inline int versal_pm_aes_enc_update(const u64 in_params, 69 + const u64 in_addr) 70 + { 71 + return -ENODEV; 72 + } 73 + 74 + static inline int versal_pm_aes_dec_update(const u64 in_params, 75 + const u64 in_addr) 76 + { 77 + return -ENODEV; 78 + } 79 + 80 + static inline int versal_pm_aes_enc_final(const u64 gcm_addr) 81 + { 82 + return -ENODEV; 83 + } 84 + 85 + static inline int versal_pm_aes_dec_final(const u64 gcm_addr) 86 + { 87 + return -ENODEV; 88 + } 89 + 90 + static inline int versal_pm_aes_init(void) 91 + { 92 + return -ENODEV; 93 + } 94 + 67 95 #endif 68 96 69 97 #endif /* __FIRMWARE_XLNX_ZYNQMP_CRYPTO_H__ */