blob: 8a2b7fdcbe9fe56daad72563fec843ec0a40d857 [file] [log] [blame]
Christian Taedckec4c41a12023-07-25 09:26:58 +02001// 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 Riniabb9a042024-05-18 20:20:43 -060010#include <common.h>
Christian Taedckec4c41a12023-07-25 09:26:58 +020011#include <mach/zynqmp_aes.h>
Tom Riniabb9a042024-05-18 20:20:43 -060012
Christian Taedckec4c41a12023-07-25 09:26:58 +020013#include <asm/arch/sys_proto.h>
14#include <cpu_func.h>
15#include <memalign.h>
16#include <zynqmp_firmware.h>
17
18int 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}