116 lines · c
1/* SPDX-License-Identifier: MIT */2/*3 * Copyright (C) 2019,2021 Advanced Micro Devices, Inc.4 *5 * Author: Rijo Thomas <Rijo-john.Thomas@amd.com>6 * Author: Devaraj Rangasamy <Devaraj.Rangasamy@amd.com>7 *8 */9 10/* This file describes the TEE communication interface between host and AMD11 * Secure Processor12 */13 14#ifndef __TEE_DEV_H__15#define __TEE_DEV_H__16 17#include <linux/device.h>18#include <linux/mutex.h>19 20#define TEE_DEFAULT_CMD_TIMEOUT (10 * MSEC_PER_SEC)21#define TEE_DEFAULT_RING_TIMEOUT 1022#define MAX_BUFFER_SIZE 98823 24/**25 * struct tee_init_ring_cmd - Command to init TEE ring buffer26 * @low_addr: bits [31:0] of the physical address of ring buffer27 * @hi_addr: bits [63:32] of the physical address of ring buffer28 * @size: size of ring buffer in bytes29 */30struct tee_init_ring_cmd {31 u32 low_addr;32 u32 hi_addr;33 u32 size;34};35 36#define MAX_RING_BUFFER_ENTRIES 3237 38/**39 * struct ring_buf_manager - Helper structure to manage ring buffer.40 * @ring_start: starting address of ring buffer41 * @ring_size: size of ring buffer in bytes42 * @ring_pa: physical address of ring buffer43 * @wptr: index to the last written entry in ring buffer44 */45struct ring_buf_manager {46 struct mutex mutex; /* synchronizes access to ring buffer */47 void *ring_start;48 u32 ring_size;49 phys_addr_t ring_pa;50 u32 wptr;51};52 53struct psp_tee_device {54 struct device *dev;55 struct psp_device *psp;56 void __iomem *io_regs;57 struct tee_vdata *vdata;58 struct ring_buf_manager rb_mgr;59};60 61/**62 * enum tee_cmd_state - TEE command states for the ring buffer interface63 * @TEE_CMD_STATE_INIT: initial state of command when sent from host64 * @TEE_CMD_STATE_PROCESS: command being processed by TEE environment65 * @TEE_CMD_STATE_COMPLETED: command processing completed66 */67enum tee_cmd_state {68 TEE_CMD_STATE_INIT,69 TEE_CMD_STATE_PROCESS,70 TEE_CMD_STATE_COMPLETED,71};72 73/**74 * enum cmd_resp_state - TEE command's response status maintained by driver75 * @CMD_RESPONSE_INVALID: initial state when no command is written to ring76 * @CMD_WAITING_FOR_RESPONSE: driver waiting for response from TEE77 * @CMD_RESPONSE_TIMEDOUT: failed to get response from TEE78 * @CMD_RESPONSE_COPIED: driver has copied response from TEE79 */80enum cmd_resp_state {81 CMD_RESPONSE_INVALID,82 CMD_WAITING_FOR_RESPONSE,83 CMD_RESPONSE_TIMEDOUT,84 CMD_RESPONSE_COPIED,85};86 87/**88 * struct tee_ring_cmd - Structure of the command buffer in TEE ring89 * @cmd_id: refers to &enum tee_cmd_id. Command id for the ring buffer90 * interface91 * @cmd_state: refers to &enum tee_cmd_state92 * @status: status of TEE command execution93 * @res0: reserved region94 * @pdata: private data (currently unused)95 * @res1: reserved region96 * @buf: TEE command specific buffer97 * @flag: refers to &enum cmd_resp_state98 */99struct tee_ring_cmd {100 u32 cmd_id;101 u32 cmd_state;102 u32 status;103 u32 res0[1];104 u64 pdata;105 u32 res1[2];106 u8 buf[MAX_BUFFER_SIZE];107 u32 flag;108 109 /* Total size: 1024 bytes */110} __packed;111 112int tee_dev_init(struct psp_device *psp);113void tee_dev_destroy(struct psp_device *psp);114 115#endif /* __TEE_DEV_H__ */116