Christian Taedcke | c4c41a1 | 2023-07-25 09:26:58 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * (C) Copyright 2018 Xilinx, Inc. |
| 4 | * Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com> |
| 5 | * |
| 6 | * Copyright (C) 2023 Weidmueller Interface GmbH & Co. KG <oss@weidmueller.com> |
| 7 | * Christian Taedcke <christian.taedcke@weidmueller.com> |
| 8 | */ |
| 9 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 10 | #include <common.h> |
Christian Taedcke | c4c41a1 | 2023-07-25 09:26:58 +0200 | [diff] [blame] | 11 | #include <mach/zynqmp_aes.h> |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 12 | |
Christian Taedcke | c4c41a1 | 2023-07-25 09:26:58 +0200 | [diff] [blame] | 13 | #include <asm/arch/sys_proto.h> |
| 14 | #include <cpu_func.h> |
| 15 | #include <memalign.h> |
| 16 | #include <zynqmp_firmware.h> |
| 17 | |
| 18 | int zynqmp_aes_operation(struct zynqmp_aes *aes) |
| 19 | { |
| 20 | u32 ret_payload[PAYLOAD_ARG_CNT]; |
| 21 | int ret; |
| 22 | |
| 23 | if (zynqmp_firmware_version() <= PMUFW_V1_0) |
| 24 | return -ENOENT; |
| 25 | |
| 26 | if (aes->srcaddr && aes->ivaddr && aes->dstaddr) { |
| 27 | flush_dcache_range(aes->srcaddr, |
| 28 | aes->srcaddr + |
| 29 | roundup(aes->len, ARCH_DMA_MINALIGN)); |
| 30 | flush_dcache_range(aes->ivaddr, |
| 31 | aes->ivaddr + |
| 32 | roundup(IV_SIZE, ARCH_DMA_MINALIGN)); |
| 33 | flush_dcache_range(aes->dstaddr, |
| 34 | aes->dstaddr + |
| 35 | roundup(aes->len, ARCH_DMA_MINALIGN)); |
| 36 | } |
| 37 | |
| 38 | if (aes->keysrc == 0) { |
| 39 | if (aes->keyaddr == 0) |
| 40 | return -EINVAL; |
| 41 | |
| 42 | flush_dcache_range(aes->keyaddr, |
| 43 | aes->keyaddr + |
| 44 | roundup(KEY_PTR_LEN, ARCH_DMA_MINALIGN)); |
| 45 | } |
| 46 | |
| 47 | flush_dcache_range((ulong)aes, (ulong)(aes) + |
| 48 | roundup(sizeof(struct zynqmp_aes), ARCH_DMA_MINALIGN)); |
| 49 | |
| 50 | ret = xilinx_pm_request(PM_SECURE_AES, upper_32_bits((ulong)aes), |
| 51 | lower_32_bits((ulong)aes), 0, 0, ret_payload); |
| 52 | if (ret || ret_payload[1]) { |
| 53 | printf("Failed: AES op status:0x%x, errcode:0x%x\n", |
| 54 | ret, ret_payload[1]); |
| 55 | return -EIO; |
| 56 | } |
| 57 | |
| 58 | return 0; |
| 59 | } |