11573Srgrimes// SPDX-License-Identifier: GPL-2.0 21573Srgrimes/* 31573Srgrimes * (C) Copyright 2018 Xilinx, Inc. 41573Srgrimes * Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com> 51573Srgrimes * 61573Srgrimes * Copyright (C) 2023 Weidmueller Interface GmbH & Co. KG <oss@weidmueller.com> 71573Srgrimes * Christian Taedcke <christian.taedcke@weidmueller.com> 81573Srgrimes */ 91573Srgrimes 101573Srgrimes#include <common.h> 111573Srgrimes#include <mach/zynqmp_aes.h> 121573Srgrimes 131573Srgrimes#include <asm/arch/sys_proto.h> 141573Srgrimes#include <cpu_func.h> 151573Srgrimes#include <memalign.h> 161573Srgrimes#include <zynqmp_firmware.h> 171573Srgrimes 181573Srgrimesint zynqmp_aes_operation(struct zynqmp_aes *aes) 191573Srgrimes{ 201573Srgrimes u32 ret_payload[PAYLOAD_ARG_CNT]; 211573Srgrimes int ret; 221573Srgrimes 231573Srgrimes if (zynqmp_firmware_version() <= PMUFW_V1_0) 241573Srgrimes return -ENOENT; 251573Srgrimes 261573Srgrimes if (aes->srcaddr && aes->ivaddr && aes->dstaddr) { 271573Srgrimes flush_dcache_range(aes->srcaddr, 2854770Sgreen aes->srcaddr + 2954770Sgreen roundup(aes->len, ARCH_DMA_MINALIGN)); 301573Srgrimes flush_dcache_range(aes->ivaddr, 311573Srgrimes aes->ivaddr + 32129184Sbde roundup(IV_SIZE, ARCH_DMA_MINALIGN)); 331573Srgrimes flush_dcache_range(aes->dstaddr, 3423668Speter aes->dstaddr + 351573Srgrimes roundup(aes->len, ARCH_DMA_MINALIGN)); 36129184Sbde } 37129184Sbde 3890045Sobrien if (aes->keysrc == 0) { 3990045Sobrien if (aes->keyaddr == 0) 401573Srgrimes return -EINVAL; 4171579Sdeischen 421573Srgrimes flush_dcache_range(aes->keyaddr, 43129161Speadar aes->keyaddr + 441573Srgrimes roundup(KEY_PTR_LEN, ARCH_DMA_MINALIGN)); 451573Srgrimes } 461573Srgrimes 471573Srgrimes flush_dcache_range((ulong)aes, (ulong)(aes) + 481573Srgrimes roundup(sizeof(struct zynqmp_aes), ARCH_DMA_MINALIGN)); 491573Srgrimes 501573Srgrimes ret = xilinx_pm_request(PM_SECURE_AES, upper_32_bits((ulong)aes), 511573Srgrimes lower_32_bits((ulong)aes), 0, 0, ret_payload); 521573Srgrimes if (ret || ret_payload[1]) { 5371579Sdeischen printf("Failed: AES op status:0x%x, errcode:0x%x\n", 541573Srgrimes ret, ret_payload[1]); 55235647Sgleb return -EIO; 56235647Sgleb } 57175688Syar 5890045Sobrien return 0; 5990045Sobrien} 6090045Sobrien