1632b0b53SRijo Thomas /* SPDX-License-Identifier: MIT */
2632b0b53SRijo Thomas /*
3632b0b53SRijo Thomas * AMD Trusted Execution Environment (TEE) interface
4632b0b53SRijo Thomas *
5632b0b53SRijo Thomas * Author: Rijo Thomas <Rijo-john.Thomas@amd.com>
6632b0b53SRijo Thomas *
7632b0b53SRijo Thomas * Copyright 2019 Advanced Micro Devices, Inc.
8632b0b53SRijo Thomas *
9632b0b53SRijo Thomas */
10632b0b53SRijo Thomas
11632b0b53SRijo Thomas #ifndef __PSP_TEE_H_
12632b0b53SRijo Thomas #define __PSP_TEE_H_
13632b0b53SRijo Thomas
14632b0b53SRijo Thomas #include <linux/types.h>
15632b0b53SRijo Thomas #include <linux/errno.h>
16632b0b53SRijo Thomas
17632b0b53SRijo Thomas /* This file defines the Trusted Execution Environment (TEE) interface commands
18632b0b53SRijo Thomas * and the API exported by AMD Secure Processor driver to communicate with
19632b0b53SRijo Thomas * AMD-TEE Trusted OS.
20632b0b53SRijo Thomas */
21632b0b53SRijo Thomas
22632b0b53SRijo Thomas /**
23632b0b53SRijo Thomas * enum tee_cmd_id - TEE Interface Command IDs
24632b0b53SRijo Thomas * @TEE_CMD_ID_LOAD_TA: Load Trusted Application (TA) binary into
25632b0b53SRijo Thomas * TEE environment
26632b0b53SRijo Thomas * @TEE_CMD_ID_UNLOAD_TA: Unload TA binary from TEE environment
27632b0b53SRijo Thomas * @TEE_CMD_ID_OPEN_SESSION: Open session with loaded TA
28632b0b53SRijo Thomas * @TEE_CMD_ID_CLOSE_SESSION: Close session with loaded TA
29632b0b53SRijo Thomas * @TEE_CMD_ID_INVOKE_CMD: Invoke a command with loaded TA
30632b0b53SRijo Thomas * @TEE_CMD_ID_MAP_SHARED_MEM: Map shared memory
31632b0b53SRijo Thomas * @TEE_CMD_ID_UNMAP_SHARED_MEM: Unmap shared memory
32632b0b53SRijo Thomas */
33632b0b53SRijo Thomas enum tee_cmd_id {
34632b0b53SRijo Thomas TEE_CMD_ID_LOAD_TA = 1,
35632b0b53SRijo Thomas TEE_CMD_ID_UNLOAD_TA,
36632b0b53SRijo Thomas TEE_CMD_ID_OPEN_SESSION,
37632b0b53SRijo Thomas TEE_CMD_ID_CLOSE_SESSION,
38632b0b53SRijo Thomas TEE_CMD_ID_INVOKE_CMD,
39632b0b53SRijo Thomas TEE_CMD_ID_MAP_SHARED_MEM,
40632b0b53SRijo Thomas TEE_CMD_ID_UNMAP_SHARED_MEM,
41632b0b53SRijo Thomas };
42632b0b53SRijo Thomas
43632b0b53SRijo Thomas #ifdef CONFIG_CRYPTO_DEV_SP_PSP
44632b0b53SRijo Thomas /**
45632b0b53SRijo Thomas * psp_tee_process_cmd() - Process command in Trusted Execution Environment
46632b0b53SRijo Thomas * @cmd_id: TEE command ID (&enum tee_cmd_id)
47632b0b53SRijo Thomas * @buf: Command buffer for TEE processing. On success, is updated
48632b0b53SRijo Thomas * with the response
49632b0b53SRijo Thomas * @len: Length of command buffer in bytes
50632b0b53SRijo Thomas * @status: On success, holds the TEE command execution status
51632b0b53SRijo Thomas *
52632b0b53SRijo Thomas * This function submits a command to the Trusted OS for processing in the
53632b0b53SRijo Thomas * TEE environment and waits for a response or until the command times out.
54632b0b53SRijo Thomas *
55632b0b53SRijo Thomas * Returns:
56632b0b53SRijo Thomas * 0 if TEE successfully processed the command
57632b0b53SRijo Thomas * -%ENODEV if PSP device not available
58632b0b53SRijo Thomas * -%EINVAL if invalid input
59632b0b53SRijo Thomas * -%ETIMEDOUT if TEE command timed out
60632b0b53SRijo Thomas * -%EBUSY if PSP device is not responsive
61632b0b53SRijo Thomas */
62632b0b53SRijo Thomas int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf, size_t len,
63632b0b53SRijo Thomas u32 *status);
64632b0b53SRijo Thomas
65bade7e1fSRijo Thomas /**
66bade7e1fSRijo Thomas * psp_check_tee_status() - Checks whether there is a TEE which a driver can
67bade7e1fSRijo Thomas * talk to.
68bade7e1fSRijo Thomas *
69bade7e1fSRijo Thomas * This function can be used by AMD-TEE driver to query if there is TEE with
70bade7e1fSRijo Thomas * which it can communicate.
71bade7e1fSRijo Thomas *
72bade7e1fSRijo Thomas * Returns:
73bade7e1fSRijo Thomas * 0 if the device has TEE
74bade7e1fSRijo Thomas * -%ENODEV if there is no TEE available
75bade7e1fSRijo Thomas */
76bade7e1fSRijo Thomas int psp_check_tee_status(void);
77bade7e1fSRijo Thomas
78632b0b53SRijo Thomas #else /* !CONFIG_CRYPTO_DEV_SP_PSP */
79632b0b53SRijo Thomas
psp_tee_process_cmd(enum tee_cmd_id cmd_id,void * buf,size_t len,u32 * status)80632b0b53SRijo Thomas static inline int psp_tee_process_cmd(enum tee_cmd_id cmd_id, void *buf,
81632b0b53SRijo Thomas size_t len, u32 *status)
82632b0b53SRijo Thomas {
83632b0b53SRijo Thomas return -ENODEV;
84632b0b53SRijo Thomas }
85bade7e1fSRijo Thomas
psp_check_tee_status(void)86bade7e1fSRijo Thomas static inline int psp_check_tee_status(void)
87bade7e1fSRijo Thomas {
88bade7e1fSRijo Thomas return -ENODEV;
89bade7e1fSRijo Thomas }
90632b0b53SRijo Thomas #endif /* CONFIG_CRYPTO_DEV_SP_PSP */
91632b0b53SRijo Thomas #endif /* __PSP_TEE_H_ */
92