162306a36Sopenharmony_ci/* SPDX-License-Identifier: MIT */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * AMD Trusted Execution Environment (TEE) interface 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Author: Rijo Thomas <Rijo-john.Thomas@amd.com> 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Copyright 2019 Advanced Micro Devices, Inc. 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#ifndef __PSP_TEE_H_ 1262306a36Sopenharmony_ci#define __PSP_TEE_H_ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include <linux/types.h> 1562306a36Sopenharmony_ci#include <linux/errno.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci/* This file defines the Trusted Execution Environment (TEE) interface commands 1862306a36Sopenharmony_ci * and the API exported by AMD Secure Processor driver to communicate with 1962306a36Sopenharmony_ci * AMD-TEE Trusted OS. 2062306a36Sopenharmony_ci */ 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci/** 2362306a36Sopenharmony_ci * enum tee_cmd_id - TEE Interface Command IDs 2462306a36Sopenharmony_ci * @TEE_CMD_ID_LOAD_TA: Load Trusted Application (TA) binary into 2562306a36Sopenharmony_ci * TEE environment 2662306a36Sopenharmony_ci * @TEE_CMD_ID_UNLOAD_TA: Unload TA binary from TEE environment 2762306a36Sopenharmony_ci * @TEE_CMD_ID_OPEN_SESSION: Open session with loaded TA 2862306a36Sopenharmony_ci * @TEE_CMD_ID_CLOSE_SESSION: Close session with loaded TA 2962306a36Sopenharmony_ci * @TEE_CMD_ID_INVOKE_CMD: Invoke a command with loaded TA 3062306a36Sopenharmony_ci * @TEE_CMD_ID_MAP_SHARED_MEM: Map shared memory 3162306a36Sopenharmony_ci * @TEE_CMD_ID_UNMAP_SHARED_MEM: Unmap shared memory 3262306a36Sopenharmony_ci */ 3362306a36Sopenharmony_cienum tee_cmd_id { 3462306a36Sopenharmony_ci TEE_CMD_ID_LOAD_TA = 1, 3562306a36Sopenharmony_ci TEE_CMD_ID_UNLOAD_TA, 3662306a36Sopenharmony_ci TEE_CMD_ID_OPEN_SESSION, 3762306a36Sopenharmony_ci TEE_CMD_ID_CLOSE_SESSION, 3862306a36Sopenharmony_ci TEE_CMD_ID_INVOKE_CMD, 3962306a36Sopenharmony_ci TEE_CMD_ID_MAP_SHARED_MEM, 4062306a36Sopenharmony_ci TEE_CMD_ID_UNMAP_SHARED_MEM, 4162306a36Sopenharmony_ci}; 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#ifdef CONFIG_CRYPTO_DEV_SP_PSP 4462306a36Sopenharmony_ci/** 4562306a36Sopenharmony_ci * psp_tee_process_cmd() - Process command in Trusted Execution Environment 4662306a36Sopenharmony_ci * @cmd_id: TEE command ID (&enum tee_cmd_id) 4762306a36Sopenharmony_ci * @buf: Command buffer for TEE processing. On success, is updated 4862306a36Sopenharmony_ci * with the response 4962306a36Sopenharmony_ci * @len: Length of command buffer in bytes 5062306a36Sopenharmony_ci * @status: On success, holds the TEE command execution status 5162306a36Sopenharmony_ci * 5262306a36Sopenharmony_ci * This function submits a command to the Trusted OS for processing in the 5362306a36Sopenharmony_ci * TEE environment and waits for a response or until the command times out. 5462306a36Sopenharmony_ci * 5562306a36Sopenharmony_ci * Returns: 5662306a36Sopenharmony_ci * 0 if TEE successfully processed the command 5762306a36Sopenharmony_ci * -%ENODEV if PSP device not available 5862306a36Sopenharmony_ci * -%EINVAL if invalid input 5962306a36Sopenharmony_ci * -%ETIMEDOUT if TEE command timed out 6062306a36Sopenharmony_ci * -%EBUSY if PSP device is not responsive 6162306a36Sopenharmony_ci */ 6262306a36Sopenharmony_ciint psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf, size_t len, 6362306a36Sopenharmony_ci u32 *status); 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci/** 6662306a36Sopenharmony_ci * psp_check_tee_status() - Checks whether there is a TEE which a driver can 6762306a36Sopenharmony_ci * talk to. 6862306a36Sopenharmony_ci * 6962306a36Sopenharmony_ci * This function can be used by AMD-TEE driver to query if there is TEE with 7062306a36Sopenharmony_ci * which it can communicate. 7162306a36Sopenharmony_ci * 7262306a36Sopenharmony_ci * Returns: 7362306a36Sopenharmony_ci * 0 if the device has TEE 7462306a36Sopenharmony_ci * -%ENODEV if there is no TEE available 7562306a36Sopenharmony_ci */ 7662306a36Sopenharmony_ciint psp_check_tee_status(void); 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci#else /* !CONFIG_CRYPTO_DEV_SP_PSP */ 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_cistatic inline int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf, 8162306a36Sopenharmony_ci size_t len, u32 *status) 8262306a36Sopenharmony_ci{ 8362306a36Sopenharmony_ci return -ENODEV; 8462306a36Sopenharmony_ci} 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_cistatic inline int psp_check_tee_status(void) 8762306a36Sopenharmony_ci{ 8862306a36Sopenharmony_ci return -ENODEV; 8962306a36Sopenharmony_ci} 9062306a36Sopenharmony_ci#endif /* CONFIG_CRYPTO_DEV_SP_PSP */ 9162306a36Sopenharmony_ci#endif /* __PSP_TEE_H_ */ 92