/* SPDX-License-Identifier: MIT */1/*2* Copyright (C) 2019,2021 Advanced Micro Devices, Inc.3*4* Author: Rijo Thomas <[email protected]>5* Author: Devaraj Rangasamy <[email protected]>6*7*/89/* This file describes the TEE communication interface between host and AMD10* Secure Processor11*/1213#ifndef __TEE_DEV_H__14#define __TEE_DEV_H__1516#include <linux/device.h>17#include <linux/mutex.h>1819#define TEE_DEFAULT_CMD_TIMEOUT (10 * MSEC_PER_SEC)20#define TEE_DEFAULT_RING_TIMEOUT 1021#define MAX_BUFFER_SIZE 9882223/**24* struct tee_init_ring_cmd - Command to init TEE ring buffer25* @low_addr: bits [31:0] of the physical address of ring buffer26* @hi_addr: bits [63:32] of the physical address of ring buffer27* @size: size of ring buffer in bytes28*/29struct tee_init_ring_cmd {30u32 low_addr;31u32 hi_addr;32u32 size;33};3435#define MAX_RING_BUFFER_ENTRIES 323637/**38* struct ring_buf_manager - Helper structure to manage ring buffer.39* @ring_start: starting address of ring buffer40* @ring_size: size of ring buffer in bytes41* @ring_pa: physical address of ring buffer42* @wptr: index to the last written entry in ring buffer43*/44struct ring_buf_manager {45struct mutex mutex; /* synchronizes access to ring buffer */46void *ring_start;47u32 ring_size;48phys_addr_t ring_pa;49u32 wptr;50};5152struct psp_tee_device {53struct device *dev;54struct psp_device *psp;55void __iomem *io_regs;56struct tee_vdata *vdata;57struct ring_buf_manager rb_mgr;58};5960/**61* enum tee_cmd_state - TEE command states for the ring buffer interface62* @TEE_CMD_STATE_INIT: initial state of command when sent from host63* @TEE_CMD_STATE_PROCESS: command being processed by TEE environment64* @TEE_CMD_STATE_COMPLETED: command processing completed65*/66enum tee_cmd_state {67TEE_CMD_STATE_INIT,68TEE_CMD_STATE_PROCESS,69TEE_CMD_STATE_COMPLETED,70};7172/**73* enum cmd_resp_state - TEE command's response status maintained by driver74* @CMD_RESPONSE_INVALID: initial state when no command is written to ring75* @CMD_WAITING_FOR_RESPONSE: driver waiting for response from TEE76* @CMD_RESPONSE_TIMEDOUT: failed to get response from TEE77* @CMD_RESPONSE_COPIED: driver has copied response from TEE78*/79enum cmd_resp_state {80CMD_RESPONSE_INVALID,81CMD_WAITING_FOR_RESPONSE,82CMD_RESPONSE_TIMEDOUT,83CMD_RESPONSE_COPIED,84};8586/**87* struct tee_ring_cmd - Structure of the command buffer in TEE ring88* @cmd_id: refers to &enum tee_cmd_id. Command id for the ring buffer89* interface90* @cmd_state: refers to &enum tee_cmd_state91* @status: status of TEE command execution92* @res0: reserved region93* @pdata: private data (currently unused)94* @res1: reserved region95* @buf: TEE command specific buffer96* @flag: refers to &enum cmd_resp_state97*/98struct tee_ring_cmd {99u32 cmd_id;100u32 cmd_state;101u32 status;102u32 res0[1];103u64 pdata;104u32 res1[2];105u8 buf[MAX_BUFFER_SIZE];106u32 flag;107108/* Total size: 1024 bytes */109} __packed;110111int tee_dev_init(struct psp_device *psp);112void tee_dev_destroy(struct psp_device *psp);113114#endif /* __TEE_DEV_H__ */115116117