1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2015, Linaro Limited
6 #ifndef OPTEE_PRIVATE_H
7 #define OPTEE_PRIVATE_H
9 #include <linux/arm-smccc.h>
10 #include <linux/semaphore.h>
11 #include <linux/tee_drv.h>
12 #include <linux/types.h>
13 #include "optee_msg.h"
15 #define OPTEE_MAX_ARG_SIZE 1024
17 /* Some Global Platform error codes used in this driver */
18 #define TEEC_SUCCESS 0x00000000
19 #define TEEC_ERROR_BAD_PARAMETERS 0xFFFF0006
20 #define TEEC_ERROR_COMMUNICATION 0xFFFF000E
21 #define TEEC_ERROR_OUT_OF_MEMORY 0xFFFF000C
22 #define TEEC_ERROR_SHORT_BUFFER 0xFFFF0010
24 #define TEEC_ORIGIN_COMMS 0x00000002
26 typedef void (optee_invoke_fn
)(unsigned long, unsigned long, unsigned long,
27 unsigned long, unsigned long, unsigned long,
28 unsigned long, unsigned long,
29 struct arm_smccc_res
*);
31 struct optee_call_queue
{
32 /* Serializes access to this struct */
34 struct list_head waiters
;
37 struct optee_wait_queue
{
38 /* Serializes access to this struct */
44 * struct optee_supp - supplicant synchronization struct
45 * @ctx the context of current connected supplicant.
46 * if !NULL the supplicant device is available for use,
48 * @mutex: held while accessing content of this struct
49 * @req_id: current request id if supplicant is doing synchronous
50 * communication, else -1
51 * @reqs: queued request not yet retrieved by supplicant
52 * @idr: IDR holding all requests currently being processed
54 * @reqs_c: completion used by supplicant when waiting for a
55 * request to be queued.
58 /* Serializes access to this struct */
60 struct tee_context
*ctx
;
63 struct list_head reqs
;
65 struct completion reqs_c
;
69 * struct optee - main service struct
70 * @supp_teedev: supplicant device
71 * @teedev: client device
72 * @invoke_fn: function to issue smc or hvc
73 * @call_queue: queue of threads waiting to call @invoke_fn
74 * @wait_queue: queue of threads from secure world waiting for a
75 * secure world sync object
76 * @supp: supplicant synchronization struct for RPC to supplicant
77 * @pool: shared memory pool
78 * @memremaped_shm virtual address of memory in shared memory pool
79 * @sec_caps: secure world capabilities defined by
80 * OPTEE_SMC_SEC_CAP_* in optee_smc.h
83 struct tee_device
*supp_teedev
;
84 struct tee_device
*teedev
;
85 optee_invoke_fn
*invoke_fn
;
86 struct optee_call_queue call_queue
;
87 struct optee_wait_queue wait_queue
;
88 struct optee_supp supp
;
89 struct tee_shm_pool
*pool
;
94 struct optee_session
{
95 struct list_head list_node
;
99 struct optee_context_data
{
100 /* Serializes access to this struct */
102 struct list_head sess_list
;
105 struct optee_rpc_param
{
116 /* Holds context that is preserved during one STD call */
117 struct optee_call_ctx
{
118 /* information about pages list used in last allocation */
123 void optee_handle_rpc(struct tee_context
*ctx
, struct optee_rpc_param
*param
,
124 struct optee_call_ctx
*call_ctx
);
125 void optee_rpc_finalize_call(struct optee_call_ctx
*call_ctx
);
127 void optee_wait_queue_init(struct optee_wait_queue
*wq
);
128 void optee_wait_queue_exit(struct optee_wait_queue
*wq
);
130 u32
optee_supp_thrd_req(struct tee_context
*ctx
, u32 func
, size_t num_params
,
131 struct tee_param
*param
);
133 int optee_supp_read(struct tee_context
*ctx
, void __user
*buf
, size_t len
);
134 int optee_supp_write(struct tee_context
*ctx
, void __user
*buf
, size_t len
);
135 void optee_supp_init(struct optee_supp
*supp
);
136 void optee_supp_uninit(struct optee_supp
*supp
);
137 void optee_supp_release(struct optee_supp
*supp
);
139 int optee_supp_recv(struct tee_context
*ctx
, u32
*func
, u32
*num_params
,
140 struct tee_param
*param
);
141 int optee_supp_send(struct tee_context
*ctx
, u32 ret
, u32 num_params
,
142 struct tee_param
*param
);
144 u32
optee_do_call_with_arg(struct tee_context
*ctx
, phys_addr_t parg
);
145 int optee_open_session(struct tee_context
*ctx
,
146 struct tee_ioctl_open_session_arg
*arg
,
147 struct tee_param
*param
);
148 int optee_close_session(struct tee_context
*ctx
, u32 session
);
149 int optee_invoke_func(struct tee_context
*ctx
, struct tee_ioctl_invoke_arg
*arg
,
150 struct tee_param
*param
);
151 int optee_cancel_req(struct tee_context
*ctx
, u32 cancel_id
, u32 session
);
153 void optee_enable_shm_cache(struct optee
*optee
);
154 void optee_disable_shm_cache(struct optee
*optee
);
156 int optee_shm_register(struct tee_context
*ctx
, struct tee_shm
*shm
,
157 struct page
**pages
, size_t num_pages
,
158 unsigned long start
);
159 int optee_shm_unregister(struct tee_context
*ctx
, struct tee_shm
*shm
);
161 int optee_shm_register_supp(struct tee_context
*ctx
, struct tee_shm
*shm
,
162 struct page
**pages
, size_t num_pages
,
163 unsigned long start
);
164 int optee_shm_unregister_supp(struct tee_context
*ctx
, struct tee_shm
*shm
);
166 int optee_from_msg_param(struct tee_param
*params
, size_t num_params
,
167 const struct optee_msg_param
*msg_params
);
168 int optee_to_msg_param(struct optee_msg_param
*msg_params
, size_t num_params
,
169 const struct tee_param
*params
);
171 u64
*optee_allocate_pages_list(size_t num_entries
);
172 void optee_free_pages_list(void *array
, size_t num_entries
);
173 void optee_fill_pages_list(u64
*dst
, struct page
**pages
, int num_pages
,
176 int optee_enumerate_devices(void);
182 static inline void *reg_pair_to_ptr(u32 reg0
, u32 reg1
)
184 return (void *)(unsigned long)(((u64
)reg0
<< 32) | reg1
);
187 static inline void reg_pair_from_64(u32
*reg0
, u32
*reg1
, u64 val
)
193 #endif /*OPTEE_PRIVATE_H*/