Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: MIT */
0002 /*
0003  * AMD Trusted Execution Environment (TEE) interface
0004  *
0005  * Author: Rijo Thomas <Rijo-john.Thomas@amd.com>
0006  *
0007  * Copyright 2019 Advanced Micro Devices, Inc.
0008  *
0009  */
0010 
0011 #ifndef __PSP_TEE_H_
0012 #define __PSP_TEE_H_
0013 
0014 #include <linux/types.h>
0015 #include <linux/errno.h>
0016 
0017 /* This file defines the Trusted Execution Environment (TEE) interface commands
0018  * and the API exported by AMD Secure Processor driver to communicate with
0019  * AMD-TEE Trusted OS.
0020  */
0021 
0022 /**
0023  * enum tee_cmd_id - TEE Interface Command IDs
0024  * @TEE_CMD_ID_LOAD_TA:          Load Trusted Application (TA) binary into
0025  *                               TEE environment
0026  * @TEE_CMD_ID_UNLOAD_TA:        Unload TA binary from TEE environment
0027  * @TEE_CMD_ID_OPEN_SESSION:     Open session with loaded TA
0028  * @TEE_CMD_ID_CLOSE_SESSION:    Close session with loaded TA
0029  * @TEE_CMD_ID_INVOKE_CMD:       Invoke a command with loaded TA
0030  * @TEE_CMD_ID_MAP_SHARED_MEM:   Map shared memory
0031  * @TEE_CMD_ID_UNMAP_SHARED_MEM: Unmap shared memory
0032  */
0033 enum tee_cmd_id {
0034     TEE_CMD_ID_LOAD_TA = 1,
0035     TEE_CMD_ID_UNLOAD_TA,
0036     TEE_CMD_ID_OPEN_SESSION,
0037     TEE_CMD_ID_CLOSE_SESSION,
0038     TEE_CMD_ID_INVOKE_CMD,
0039     TEE_CMD_ID_MAP_SHARED_MEM,
0040     TEE_CMD_ID_UNMAP_SHARED_MEM,
0041 };
0042 
0043 #ifdef CONFIG_CRYPTO_DEV_SP_PSP
0044 /**
0045  * psp_tee_process_cmd() - Process command in Trusted Execution Environment
0046  * @cmd_id:     TEE command ID (&enum tee_cmd_id)
0047  * @buf:        Command buffer for TEE processing. On success, is updated
0048  *              with the response
0049  * @len:        Length of command buffer in bytes
0050  * @status:     On success, holds the TEE command execution status
0051  *
0052  * This function submits a command to the Trusted OS for processing in the
0053  * TEE environment and waits for a response or until the command times out.
0054  *
0055  * Returns:
0056  * 0 if TEE successfully processed the command
0057  * -%ENODEV    if PSP device not available
0058  * -%EINVAL    if invalid input
0059  * -%ETIMEDOUT if TEE command timed out
0060  * -%EBUSY     if PSP device is not responsive
0061  */
0062 int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf, size_t len,
0063             u32 *status);
0064 
0065 /**
0066  * psp_check_tee_status() - Checks whether there is a TEE which a driver can
0067  * talk to.
0068  *
0069  * This function can be used by AMD-TEE driver to query if there is TEE with
0070  * which it can communicate.
0071  *
0072  * Returns:
0073  * 0          if the device has TEE
0074  * -%ENODEV   if there is no TEE available
0075  */
0076 int psp_check_tee_status(void);
0077 
0078 #else /* !CONFIG_CRYPTO_DEV_SP_PSP */
0079 
0080 static inline int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf,
0081                       size_t len, u32 *status)
0082 {
0083     return -ENODEV;
0084 }
0085 
0086 static inline int psp_check_tee_status(void)
0087 {
0088     return -ENODEV;
0089 }
0090 #endif /* CONFIG_CRYPTO_DEV_SP_PSP */
0091 #endif /* __PSP_TEE_H_ */