1
2
3
4
5
6
7#ifndef AMDTEE_PRIVATE_H
8#define AMDTEE_PRIVATE_H
9
10#include <linux/mutex.h>
11#include <linux/spinlock.h>
12#include <linux/tee_drv.h>
13#include <linux/kref.h>
14#include <linux/types.h>
15#include "amdtee_if.h"
16
17#define DRIVER_NAME "amdtee"
18#define DRIVER_AUTHOR "AMD-TEE Linux driver team"
19
20
21#define TEEC_SUCCESS 0x00000000
22#define TEEC_ERROR_GENERIC 0xFFFF0000
23#define TEEC_ERROR_BAD_PARAMETERS 0xFFFF0006
24#define TEEC_ERROR_OUT_OF_MEMORY 0xFFFF000C
25#define TEEC_ERROR_COMMUNICATION 0xFFFF000E
26
27#define TEEC_ORIGIN_COMMS 0x00000002
28
29
30#define TEE_NUM_SESSIONS 32
31
32#define TA_LOAD_PATH "/amdtee"
33#define TA_PATH_MAX 60
34
35
36
37
38
39
40struct amdtee {
41 struct tee_device *teedev;
42 struct tee_shm_pool *pool;
43};
44
45
46
47
48
49
50
51
52
53
54
55
56struct amdtee_session {
57 struct list_head list_node;
58 u32 ta_handle;
59 struct kref refcount;
60 u32 session_info[TEE_NUM_SESSIONS];
61 DECLARE_BITMAP(sess_mask, TEE_NUM_SESSIONS);
62 spinlock_t lock;
63};
64
65
66
67
68
69
70
71struct amdtee_context_data {
72 struct list_head sess_list;
73 struct list_head shm_list;
74 struct mutex shm_mutex;
75};
76
77struct amdtee_driver_data {
78 struct amdtee *amdtee;
79};
80
81struct shmem_desc {
82 void *kaddr;
83 u64 size;
84};
85
86
87
88
89
90
91struct amdtee_shm_data {
92 struct list_head shm_node;
93 void *kaddr;
94 u32 buf_id;
95};
96
97
98
99
100
101
102
103struct amdtee_ta_data {
104 struct list_head list_node;
105 u32 ta_handle;
106 u32 refcount;
107};
108
109#define LOWER_TWO_BYTE_MASK 0x0000FFFF
110
111
112
113
114
115
116
117
118
119
120static inline void set_session_id(u32 ta_handle, u32 session_index,
121 u32 *session)
122{
123 *session = (session_index << 16) | (LOWER_TWO_BYTE_MASK & ta_handle);
124}
125
126static inline u32 get_ta_handle(u32 session)
127{
128 return session & LOWER_TWO_BYTE_MASK;
129}
130
131static inline u32 get_session_index(u32 session)
132{
133 return (session >> 16) & LOWER_TWO_BYTE_MASK;
134}
135
136int amdtee_open_session(struct tee_context *ctx,
137 struct tee_ioctl_open_session_arg *arg,
138 struct tee_param *param);
139
140int amdtee_close_session(struct tee_context *ctx, u32 session);
141
142int amdtee_invoke_func(struct tee_context *ctx,
143 struct tee_ioctl_invoke_arg *arg,
144 struct tee_param *param);
145
146int amdtee_cancel_req(struct tee_context *ctx, u32 cancel_id, u32 session);
147
148int amdtee_map_shmem(struct tee_shm *shm);
149
150void amdtee_unmap_shmem(struct tee_shm *shm);
151
152int handle_load_ta(void *data, u32 size,
153 struct tee_ioctl_open_session_arg *arg);
154
155int handle_unload_ta(u32 ta_handle);
156
157int handle_open_session(struct tee_ioctl_open_session_arg *arg, u32 *info,
158 struct tee_param *p);
159
160int handle_close_session(u32 ta_handle, u32 info);
161
162int handle_map_shmem(u32 count, struct shmem_desc *start, u32 *buf_id);
163
164void handle_unmap_shmem(u32 buf_id);
165
166int handle_invoke_cmd(struct tee_ioctl_invoke_arg *arg, u32 sinfo,
167 struct tee_param *p);
168
169struct tee_shm_pool *amdtee_config_shm(void);
170
171u32 get_buffer_id(struct tee_shm *shm);
172#endif
173