summaryrefslogtreecommitdiff
path: root/drivers/tee/amdtee/amdtee_if.h
blob: e2014e21530acb86d50eb5995e2124f52acb5e7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* SPDX-License-Identifier: MIT */

/*
 * Copyright 2019 Advanced Micro Devices, Inc.
 */

/*
 * This file has definitions related to Host and AMD-TEE Trusted OS interface.
 * These definitions must match the definitions on the TEE side.
 */

#ifndef AMDTEE_IF_H
#define AMDTEE_IF_H

#include <linux/types.h>

/*****************************************************************************
 ** TEE Param
 ******************************************************************************/
#define TEE_MAX_PARAMS		4

/**
 * struct memref - memory reference structure
 * @buf_id:    buffer ID of the buffer mapped by TEE_CMD_ID_MAP_SHARED_MEM
 * @offset:    offset in bytes from beginning of the buffer
 * @size:      data size in bytes
 */
struct memref {
	u32 buf_id;
	u32 offset;
	u32 size;
};

struct value {
	u32 a;
	u32 b;
};

/*
 * Parameters passed to open_session or invoke_command
 */
union tee_op_param {
	struct memref mref;
	struct value val;
};

struct tee_operation {
	u32 param_types;
	union tee_op_param params[TEE_MAX_PARAMS];
};

/* Must be same as in GP TEE specification */
#define TEE_OP_PARAM_TYPE_NONE                  0
#define TEE_OP_PARAM_TYPE_VALUE_INPUT           1
#define TEE_OP_PARAM_TYPE_VALUE_OUTPUT          2
#define TEE_OP_PARAM_TYPE_VALUE_INOUT           3
#define TEE_OP_PARAM_TYPE_INVALID               4
#define TEE_OP_PARAM_TYPE_MEMREF_INPUT          5
#define TEE_OP_PARAM_TYPE_MEMREF_OUTPUT         6
#define TEE_OP_PARAM_TYPE_MEMREF_INOUT          7

#define TEE_PARAM_TYPE_GET(t, i)        (((t) >> ((i) * 4)) & 0xF)
#define TEE_PARAM_TYPES(t0, t1, t2, t3) \
	((t0) | ((t1) << 4) | ((t2) << 8) | ((t3) << 12))

/*****************************************************************************
 ** TEE Commands
 *****************************************************************************/

/*
 * The shared memory between rich world and secure world may be physically
 * non-contiguous. Below structures are meant to describe a shared memory region
 * via scatter/gather (sg) list
 */

/**
 * struct tee_sg_desc - sg descriptor for a physically contiguous buffer
 * @low_addr: [in] bits[31:0] of buffer's physical address. Must be 4KB aligned
 * @hi_addr:  [in] bits[63:32] of the buffer's physical address
 * @size:     [in] size in bytes (must be multiple of 4KB)
 */
struct tee_sg_desc {
	u32 low_addr;
	u32 hi_addr;
	u32 size;
};

/**
 * struct tee_sg_list - structure describing a scatter/gather list
 * @count:   [in] number of sg descriptors
 * @size:    [in] total size of all buffers in the list. Must be multiple of 4KB
 * @buf:     [in] list of sg buffer descriptors
 */
#define TEE_MAX_SG_DESC 64
struct tee_sg_list {
	u32 count;
	u32 size;
	struct tee_sg_desc buf[TEE_MAX_SG_DESC];
};

/**
 * struct tee_cmd_map_shared_mem - command to map shared memory
 * @buf_id:    [out] return buffer ID value
 * @sg_list:   [in] list describing memory to be mapped
 */
struct tee_cmd_map_shared_mem {
	u32 buf_id;
	struct tee_sg_list sg_list;
};

/**
 * struct tee_cmd_unmap_shared_mem - command to unmap shared memory
 * @buf_id:    [in] buffer ID of memory to be unmapped
 */
struct tee_cmd_unmap_shared_mem {
	u32 buf_id;
};

/**
 * struct tee_cmd_load_ta - load Trusted Application (TA) binary into TEE
 * @low_addr:       [in] bits [31:0] of the physical address of the TA binary
 * @hi_addr:        [in] bits [63:32] of the physical address of the TA binary
 * @size:           [in] size of TA binary in bytes
 * @ta_handle:      [out] return handle of the loaded TA
 * @return_origin:  [out] origin of return code after TEE processing
 */
struct tee_cmd_load_ta {
	u32 low_addr;
	u32 hi_addr;
	u32 size;
	u32 ta_handle;
	u32 return_origin;
};

/**
 * struct tee_cmd_unload_ta - command to unload TA binary from TEE environment
 * @ta_handle:    [in] handle of the loaded TA to be unloaded
 */
struct tee_cmd_unload_ta {
	u32 ta_handle;
};

/**
 * struct tee_cmd_open_session - command to call TA_OpenSessionEntryPoint in TA
 * @ta_handle:      [in] handle of the loaded TA
 * @session_info:   [out] pointer to TA allocated session data
 * @op:             [in/out] operation parameters
 * @return_origin:  [out] origin of return code after TEE processing
 */
struct tee_cmd_open_session {
	u32 ta_handle;
	u32 session_info;
	struct tee_operation op;
	u32 return_origin;
};

/**
 * struct tee_cmd_close_session - command to call TA_CloseSessionEntryPoint()
 *                                in TA
 * @ta_handle:      [in] handle of the loaded TA
 * @session_info:   [in] pointer to TA allocated session data
 */
struct tee_cmd_close_session {
	u32 ta_handle;
	u32 session_info;
};

/**
 * struct tee_cmd_invoke_cmd - command to call TA_InvokeCommandEntryPoint() in
 *                             TA
 * @ta_handle:     [in] handle of the loaded TA
 * @cmd_id:        [in] TA command ID
 * @session_info:  [in] pointer to TA allocated session data
 * @op:            [in/out] operation parameters
 * @return_origin: [out] origin of return code after TEE processing
 */
struct tee_cmd_invoke_cmd {
	u32 ta_handle;
	u32 cmd_id;
	u32 session_info;
	struct tee_operation op;
	u32 return_origin;
};

#endif /*AMDTEE_IF_H*/