xref: /openbmc/linux/drivers/tee/amdtee/amdtee_if.h (revision 6db6b729)
1 /* SPDX-License-Identifier: MIT */
2 
3 /*
4  * Copyright 2019 Advanced Micro Devices, Inc.
5  */
6 
7 /*
8  * This file has definitions related to Host and AMD-TEE Trusted OS interface.
9  * These definitions must match the definitions on the TEE side.
10  */
11 
12 #ifndef AMDTEE_IF_H
13 #define AMDTEE_IF_H
14 
15 #include <linux/types.h>
16 
17 /*****************************************************************************
18  ** TEE Param
19  ******************************************************************************/
20 #define TEE_MAX_PARAMS		4
21 
22 /**
23  * struct memref - memory reference structure
24  * @buf_id:    buffer ID of the buffer mapped by TEE_CMD_ID_MAP_SHARED_MEM
25  * @offset:    offset in bytes from beginning of the buffer
26  * @size:      data size in bytes
27  */
28 struct memref {
29 	u32 buf_id;
30 	u32 offset;
31 	u32 size;
32 };
33 
34 struct value {
35 	u32 a;
36 	u32 b;
37 };
38 
39 /*
40  * Parameters passed to open_session or invoke_command
41  */
42 union tee_op_param {
43 	struct memref mref;
44 	struct value val;
45 };
46 
47 struct tee_operation {
48 	u32 param_types;
49 	union tee_op_param params[TEE_MAX_PARAMS];
50 };
51 
52 /* Must be same as in GP TEE specification */
53 #define TEE_OP_PARAM_TYPE_NONE                  0
54 #define TEE_OP_PARAM_TYPE_VALUE_INPUT           1
55 #define TEE_OP_PARAM_TYPE_VALUE_OUTPUT          2
56 #define TEE_OP_PARAM_TYPE_VALUE_INOUT           3
57 #define TEE_OP_PARAM_TYPE_INVALID               4
58 #define TEE_OP_PARAM_TYPE_MEMREF_INPUT          5
59 #define TEE_OP_PARAM_TYPE_MEMREF_OUTPUT         6
60 #define TEE_OP_PARAM_TYPE_MEMREF_INOUT          7
61 
62 #define TEE_PARAM_TYPE_GET(t, i)        (((t) >> ((i) * 4)) & 0xF)
63 #define TEE_PARAM_TYPES(t0, t1, t2, t3) \
64 	((t0) | ((t1) << 4) | ((t2) << 8) | ((t3) << 12))
65 
66 /*****************************************************************************
67  ** TEE Commands
68  *****************************************************************************/
69 
70 /*
71  * The shared memory between rich world and secure world may be physically
72  * non-contiguous. Below structures are meant to describe a shared memory region
73  * via scatter/gather (sg) list
74  */
75 
76 /**
77  * struct tee_sg_desc - sg descriptor for a physically contiguous buffer
78  * @low_addr: [in] bits[31:0] of buffer's physical address. Must be 4KB aligned
79  * @hi_addr:  [in] bits[63:32] of the buffer's physical address
80  * @size:     [in] size in bytes (must be multiple of 4KB)
81  */
82 struct tee_sg_desc {
83 	u32 low_addr;
84 	u32 hi_addr;
85 	u32 size;
86 };
87 
88 /**
89  * struct tee_sg_list - structure describing a scatter/gather list
90  * @count:   [in] number of sg descriptors
91  * @size:    [in] total size of all buffers in the list. Must be multiple of 4KB
92  * @buf:     [in] list of sg buffer descriptors
93  */
94 #define TEE_MAX_SG_DESC 64
95 struct tee_sg_list {
96 	u32 count;
97 	u32 size;
98 	struct tee_sg_desc buf[TEE_MAX_SG_DESC];
99 };
100 
101 /**
102  * struct tee_cmd_map_shared_mem - command to map shared memory
103  * @buf_id:    [out] return buffer ID value
104  * @sg_list:   [in] list describing memory to be mapped
105  */
106 struct tee_cmd_map_shared_mem {
107 	u32 buf_id;
108 	struct tee_sg_list sg_list;
109 };
110 
111 /**
112  * struct tee_cmd_unmap_shared_mem - command to unmap shared memory
113  * @buf_id:    [in] buffer ID of memory to be unmapped
114  */
115 struct tee_cmd_unmap_shared_mem {
116 	u32 buf_id;
117 };
118 
119 /**
120  * struct tee_cmd_load_ta - load Trusted Application (TA) binary into TEE
121  * @low_addr:       [in] bits [31:0] of the physical address of the TA binary
122  * @hi_addr:        [in] bits [63:32] of the physical address of the TA binary
123  * @size:           [in] size of TA binary in bytes
124  * @ta_handle:      [out] return handle of the loaded TA
125  * @return_origin:  [out] origin of return code after TEE processing
126  */
127 struct tee_cmd_load_ta {
128 	u32 low_addr;
129 	u32 hi_addr;
130 	u32 size;
131 	u32 ta_handle;
132 	u32 return_origin;
133 };
134 
135 /**
136  * struct tee_cmd_unload_ta - command to unload TA binary from TEE environment
137  * @ta_handle:    [in] handle of the loaded TA to be unloaded
138  */
139 struct tee_cmd_unload_ta {
140 	u32 ta_handle;
141 };
142 
143 /**
144  * struct tee_cmd_open_session - command to call TA_OpenSessionEntryPoint in TA
145  * @ta_handle:      [in] handle of the loaded TA
146  * @session_info:   [out] pointer to TA allocated session data
147  * @op:             [in/out] operation parameters
148  * @return_origin:  [out] origin of return code after TEE processing
149  */
150 struct tee_cmd_open_session {
151 	u32 ta_handle;
152 	u32 session_info;
153 	struct tee_operation op;
154 	u32 return_origin;
155 };
156 
157 /**
158  * struct tee_cmd_close_session - command to call TA_CloseSessionEntryPoint()
159  *                                in TA
160  * @ta_handle:      [in] handle of the loaded TA
161  * @session_info:   [in] pointer to TA allocated session data
162  */
163 struct tee_cmd_close_session {
164 	u32 ta_handle;
165 	u32 session_info;
166 };
167 
168 /**
169  * struct tee_cmd_invoke_cmd - command to call TA_InvokeCommandEntryPoint() in
170  *                             TA
171  * @ta_handle:     [in] handle of the loaded TA
172  * @cmd_id:        [in] TA command ID
173  * @session_info:  [in] pointer to TA allocated session data
174  * @op:            [in/out] operation parameters
175  * @return_origin: [out] origin of return code after TEE processing
176  */
177 struct tee_cmd_invoke_cmd {
178 	u32 ta_handle;
179 	u32 cmd_id;
180 	u32 session_info;
181 	struct tee_operation op;
182 	u32 return_origin;
183 };
184 
185 #endif /*AMDTEE_IF_H*/
186