0001
0002
0003
0004
0005
0006
0007 #ifndef AMDTEE_PRIVATE_H
0008 #define AMDTEE_PRIVATE_H
0009
0010 #include <linux/mutex.h>
0011 #include <linux/spinlock.h>
0012 #include <linux/tee_drv.h>
0013 #include <linux/kref.h>
0014 #include <linux/types.h>
0015 #include "amdtee_if.h"
0016
0017 #define DRIVER_NAME "amdtee"
0018 #define DRIVER_AUTHOR "AMD-TEE Linux driver team"
0019
0020
0021 #define TEEC_SUCCESS 0x00000000
0022 #define TEEC_ERROR_GENERIC 0xFFFF0000
0023 #define TEEC_ERROR_BAD_PARAMETERS 0xFFFF0006
0024 #define TEEC_ERROR_OUT_OF_MEMORY 0xFFFF000C
0025 #define TEEC_ERROR_COMMUNICATION 0xFFFF000E
0026
0027 #define TEEC_ORIGIN_COMMS 0x00000002
0028
0029
0030 #define TEE_NUM_SESSIONS 32
0031
0032 #define TA_LOAD_PATH "/amdtee"
0033 #define TA_PATH_MAX 60
0034
0035
0036
0037
0038
0039
0040 struct amdtee {
0041 struct tee_device *teedev;
0042 struct tee_shm_pool *pool;
0043 };
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056 struct amdtee_session {
0057 struct list_head list_node;
0058 u32 ta_handle;
0059 struct kref refcount;
0060 u32 session_info[TEE_NUM_SESSIONS];
0061 DECLARE_BITMAP(sess_mask, TEE_NUM_SESSIONS);
0062 spinlock_t lock;
0063 };
0064
0065
0066
0067
0068
0069
0070
0071 struct amdtee_context_data {
0072 struct list_head sess_list;
0073 struct list_head shm_list;
0074 struct mutex shm_mutex;
0075 };
0076
0077 struct amdtee_driver_data {
0078 struct amdtee *amdtee;
0079 };
0080
0081 struct shmem_desc {
0082 void *kaddr;
0083 u64 size;
0084 };
0085
0086
0087
0088
0089
0090
0091 struct amdtee_shm_data {
0092 struct list_head shm_node;
0093 void *kaddr;
0094 u32 buf_id;
0095 };
0096
0097
0098
0099
0100
0101
0102
0103 struct amdtee_ta_data {
0104 struct list_head list_node;
0105 u32 ta_handle;
0106 u32 refcount;
0107 };
0108
0109 #define LOWER_TWO_BYTE_MASK 0x0000FFFF
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120 static inline void set_session_id(u32 ta_handle, u32 session_index,
0121 u32 *session)
0122 {
0123 *session = (session_index << 16) | (LOWER_TWO_BYTE_MASK & ta_handle);
0124 }
0125
0126 static inline u32 get_ta_handle(u32 session)
0127 {
0128 return session & LOWER_TWO_BYTE_MASK;
0129 }
0130
0131 static inline u32 get_session_index(u32 session)
0132 {
0133 return (session >> 16) & LOWER_TWO_BYTE_MASK;
0134 }
0135
0136 int amdtee_open_session(struct tee_context *ctx,
0137 struct tee_ioctl_open_session_arg *arg,
0138 struct tee_param *param);
0139
0140 int amdtee_close_session(struct tee_context *ctx, u32 session);
0141
0142 int amdtee_invoke_func(struct tee_context *ctx,
0143 struct tee_ioctl_invoke_arg *arg,
0144 struct tee_param *param);
0145
0146 int amdtee_cancel_req(struct tee_context *ctx, u32 cancel_id, u32 session);
0147
0148 int amdtee_map_shmem(struct tee_shm *shm);
0149
0150 void amdtee_unmap_shmem(struct tee_shm *shm);
0151
0152 int handle_load_ta(void *data, u32 size,
0153 struct tee_ioctl_open_session_arg *arg);
0154
0155 int handle_unload_ta(u32 ta_handle);
0156
0157 int handle_open_session(struct tee_ioctl_open_session_arg *arg, u32 *info,
0158 struct tee_param *p);
0159
0160 int handle_close_session(u32 ta_handle, u32 info);
0161
0162 int handle_map_shmem(u32 count, struct shmem_desc *start, u32 *buf_id);
0163
0164 void handle_unmap_shmem(u32 buf_id);
0165
0166 int handle_invoke_cmd(struct tee_ioctl_invoke_arg *arg, u32 sinfo,
0167 struct tee_param *p);
0168
0169 struct tee_shm_pool *amdtee_config_shm(void);
0170
0171 u32 get_buffer_id(struct tee_shm *shm);
0172 #endif