xref: /openbmc/linux/drivers/tee/amdtee/amdtee_if.h (revision fbb6b31a)
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  */
126 struct tee_cmd_load_ta {
127 	u32 low_addr;
128 	u32 hi_addr;
129 	u32 size;
130 	u32 ta_handle;
131 };
132 
133 /**
134  * struct tee_cmd_unload_ta - command to unload TA binary from TEE environment
135  * @ta_handle:    [in] handle of the loaded TA to be unloaded
136  */
137 struct tee_cmd_unload_ta {
138 	u32 ta_handle;
139 };
140 
141 /**
142  * struct tee_cmd_open_session - command to call TA_OpenSessionEntryPoint in TA
143  * @ta_handle:      [in] handle of the loaded TA
144  * @session_info:   [out] pointer to TA allocated session data
145  * @op:             [in/out] operation parameters
146  * @return_origin:  [out] origin of return code after TEE processing
147  */
148 struct tee_cmd_open_session {
149 	u32 ta_handle;
150 	u32 session_info;
151 	struct tee_operation op;
152 	u32 return_origin;
153 };
154 
155 /**
156  * struct tee_cmd_close_session - command to call TA_CloseSessionEntryPoint()
157  *                                in TA
158  * @ta_handle:      [in] handle of the loaded TA
159  * @session_info:   [in] pointer to TA allocated session data
160  */
161 struct tee_cmd_close_session {
162 	u32 ta_handle;
163 	u32 session_info;
164 };
165 
166 /**
167  * struct tee_cmd_invoke_cmd - command to call TA_InvokeCommandEntryPoint() in
168  *                             TA
169  * @ta_handle:     [in] handle of the loaded TA
170  * @cmd_id:        [in] TA command ID
171  * @session_info:  [in] pointer to TA allocated session data
172  * @op:            [in/out] operation parameters
173  * @return_origin: [out] origin of return code after TEE processing
174  */
175 struct tee_cmd_invoke_cmd {
176 	u32 ta_handle;
177 	u32 cmd_id;
178 	u32 session_info;
179 	struct tee_operation op;
180 	u32 return_origin;
181 };
182 
183 #endif /*AMDTEE_IF_H*/
184