blob: 9a05fbf9c11b48c5cc6394305ee7ef92630f8fd0 [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
Christian Taedckec4c41a12023-07-25 09:26:58 +020010#include <mach/zynqmp_aes.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060011#include <linux/errno.h>
Christian Taedckec4c41a12023-07-25 09:26:58 +020012#include <asm/arch/sys_proto.h>
13#include <cpu_func.h>
14#include <memalign.h>
15#include <zynqmp_firmware.h>
16
17int zynqmp_aes_operation(struct zynqmp_aes *aes)
18{
19 u32 ret_payload[PAYLOAD_ARG_CNT];
20 int ret;
21
22 if (zynqmp_firmware_version() <= PMUFW_V1_0)
23 return -ENOENT;
24
25 if (aes->srcaddr && aes->ivaddr && aes->dstaddr) {
26 flush_dcache_range(aes->srcaddr,
27 aes->srcaddr +
28 roundup(aes->len, ARCH_DMA_MINALIGN));
29 flush_dcache_range(aes->ivaddr,
30 aes->ivaddr +
31 roundup(IV_SIZE, ARCH_DMA_MINALIGN));
32 flush_dcache_range(aes->dstaddr,
33 aes->dstaddr +
34 roundup(aes->len, ARCH_DMA_MINALIGN));
35 }
36
37 if (aes->keysrc == 0) {
38 if (aes->keyaddr == 0)
39 return -EINVAL;
40
41 flush_dcache_range(aes->keyaddr,
42 aes->keyaddr +
43 roundup(KEY_PTR_LEN, ARCH_DMA_MINALIGN));
44 }
45
46 flush_dcache_range((ulong)aes, (ulong)(aes) +
47 roundup(sizeof(struct zynqmp_aes), ARCH_DMA_MINALIGN));
48
49 ret = xilinx_pm_request(PM_SECURE_AES, upper_32_bits((ulong)aes),
50 lower_32_bits((ulong)aes), 0, 0, ret_payload);
51 if (ret || ret_payload[1]) {
52 printf("Failed: AES op status:0x%x, errcode:0x%x\n",
53 ret, ret_payload[1]);
54 return -EIO;
55 }
56
57 return 0;
58}