19c92ab61SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
24fb0a5ebSJens Wiklander /*
36dea6352SJens Wiklander * Copyright (c) 2015-2021, 2023 Linaro Limited
44fb0a5ebSJens Wiklander */
54fb0a5ebSJens Wiklander
64fb0a5ebSJens Wiklander #ifndef OPTEE_PRIVATE_H
74fb0a5ebSJens Wiklander #define OPTEE_PRIVATE_H
84fb0a5ebSJens Wiklander
94fb0a5ebSJens Wiklander #include <linux/arm-smccc.h>
10*f0c84315SJens Wiklander #include <linux/notifier.h>
114615e5a3SJens Wiklander #include <linux/rhashtable.h>
12*f0c84315SJens Wiklander #include <linux/rpmb.h>
134fb0a5ebSJens Wiklander #include <linux/semaphore.h>
140439fcffSSumit Garg #include <linux/tee_core.h>
154fb0a5ebSJens Wiklander #include <linux/types.h>
164fb0a5ebSJens Wiklander #include "optee_msg.h"
174fb0a5ebSJens Wiklander
18c51a564aSJens Wiklander #define DRIVER_NAME "optee"
19c51a564aSJens Wiklander
204fb0a5ebSJens Wiklander #define OPTEE_MAX_ARG_SIZE 1024
214fb0a5ebSJens Wiklander
224fb0a5ebSJens Wiklander /* Some Global Platform error codes used in this driver */
234fb0a5ebSJens Wiklander #define TEEC_SUCCESS 0x00000000
244fb0a5ebSJens Wiklander #define TEEC_ERROR_BAD_PARAMETERS 0xFFFF0006
25*f0c84315SJens Wiklander #define TEEC_ERROR_ITEM_NOT_FOUND 0xFFFF0008
26c05210abSJorge Ramirez-Ortiz #define TEEC_ERROR_NOT_SUPPORTED 0xFFFF000A
274fb0a5ebSJens Wiklander #define TEEC_ERROR_COMMUNICATION 0xFFFF000E
284fb0a5ebSJens Wiklander #define TEEC_ERROR_OUT_OF_MEMORY 0xFFFF000C
294615e5a3SJens Wiklander #define TEEC_ERROR_BUSY 0xFFFF000D
30c3fa24afSSumit Garg #define TEEC_ERROR_SHORT_BUFFER 0xFFFF0010
314fb0a5ebSJens Wiklander
3214ca6401SGavin Liu /* API Return Codes are from the GP TEE Internal Core API Specification */
3314ca6401SGavin Liu #define TEE_ERROR_TIMEOUT 0xFFFF3001
34*f0c84315SJens Wiklander #define TEE_ERROR_STORAGE_NOT_AVAILABLE 0xF0100003
3514ca6401SGavin Liu
364fb0a5ebSJens Wiklander #define TEEC_ORIGIN_COMMS 0x00000002
374fb0a5ebSJens Wiklander
38787c80ccSJens Wiklander /*
39787c80ccSJens Wiklander * This value should be larger than the number threads in secure world to
40787c80ccSJens Wiklander * meet the need from secure world. The number of threads in secure world
41787c80ccSJens Wiklander * are usually not even close to 255 so we should be safe for now.
42787c80ccSJens Wiklander */
43787c80ccSJens Wiklander #define OPTEE_DEFAULT_MAX_NOTIF_VALUE 255
44787c80ccSJens Wiklander
454fb0a5ebSJens Wiklander typedef void (optee_invoke_fn)(unsigned long, unsigned long, unsigned long,
464fb0a5ebSJens Wiklander unsigned long, unsigned long, unsigned long,
474fb0a5ebSJens Wiklander unsigned long, unsigned long,
484fb0a5ebSJens Wiklander struct arm_smccc_res *);
494fb0a5ebSJens Wiklander
5045bc2c9bSEtienne Carriere /*
5145bc2c9bSEtienne Carriere * struct optee_call_waiter - TEE entry may need to wait for a free TEE thread
5245bc2c9bSEtienne Carriere * @list_node Reference in waiters list
5345bc2c9bSEtienne Carriere * @c Waiting completion reference
5445bc2c9bSEtienne Carriere * @sys_thread True if waiter belongs to a system thread
5545bc2c9bSEtienne Carriere */
56c51a564aSJens Wiklander struct optee_call_waiter {
57c51a564aSJens Wiklander struct list_head list_node;
58c51a564aSJens Wiklander struct completion c;
5945bc2c9bSEtienne Carriere bool sys_thread;
60c51a564aSJens Wiklander };
61c51a564aSJens Wiklander
6245bc2c9bSEtienne Carriere /*
6345bc2c9bSEtienne Carriere * struct optee_call_queue - OP-TEE call queue management
6445bc2c9bSEtienne Carriere * @mutex Serializes access to this struct
6545bc2c9bSEtienne Carriere * @waiters List of threads waiting to enter OP-TEE
6645bc2c9bSEtienne Carriere * @total_thread_count Overall number of thread context in OP-TEE or 0
6745bc2c9bSEtienne Carriere * @free_thread_count Number of threads context free in OP-TEE
6845bc2c9bSEtienne Carriere * @sys_thread_req_count Number of registered system thread sessions
6945bc2c9bSEtienne Carriere */
704fb0a5ebSJens Wiklander struct optee_call_queue {
714fb0a5ebSJens Wiklander /* Serializes access to this struct */
724fb0a5ebSJens Wiklander struct mutex mutex;
734fb0a5ebSJens Wiklander struct list_head waiters;
7445bc2c9bSEtienne Carriere int total_thread_count;
7545bc2c9bSEtienne Carriere int free_thread_count;
7645bc2c9bSEtienne Carriere int sys_thread_req_count;
774fb0a5ebSJens Wiklander };
784fb0a5ebSJens Wiklander
79787c80ccSJens Wiklander struct optee_notif {
80787c80ccSJens Wiklander u_int max_key;
81787c80ccSJens Wiklander /* Serializes access to the elements below in this struct */
82787c80ccSJens Wiklander spinlock_t lock;
834fb0a5ebSJens Wiklander struct list_head db;
84787c80ccSJens Wiklander u_long *bitmap;
854fb0a5ebSJens Wiklander };
864fb0a5ebSJens Wiklander
875b4018b9SJens Wiklander #define OPTEE_SHM_ARG_ALLOC_PRIV BIT(0)
885b4018b9SJens Wiklander #define OPTEE_SHM_ARG_SHARED BIT(1)
895b4018b9SJens Wiklander struct optee_shm_arg_entry;
905b4018b9SJens Wiklander struct optee_shm_arg_cache {
915b4018b9SJens Wiklander u32 flags;
925b4018b9SJens Wiklander /* Serializes access to this struct */
935b4018b9SJens Wiklander struct mutex mutex;
945b4018b9SJens Wiklander struct list_head shm_args;
955b4018b9SJens Wiklander };
965b4018b9SJens Wiklander
974fb0a5ebSJens Wiklander /**
984fb0a5ebSJens Wiklander * struct optee_supp - supplicant synchronization struct
994fb0a5ebSJens Wiklander * @ctx the context of current connected supplicant.
1004fb0a5ebSJens Wiklander * if !NULL the supplicant device is available for use,
1014fb0a5ebSJens Wiklander * else busy
1021647a5acSJens Wiklander * @mutex: held while accessing content of this struct
1031647a5acSJens Wiklander * @req_id: current request id if supplicant is doing synchronous
1041647a5acSJens Wiklander * communication, else -1
1051647a5acSJens Wiklander * @reqs: queued request not yet retrieved by supplicant
1061647a5acSJens Wiklander * @idr: IDR holding all requests currently being processed
1071647a5acSJens Wiklander * by supplicant
1081647a5acSJens Wiklander * @reqs_c: completion used by supplicant when waiting for a
1091647a5acSJens Wiklander * request to be queued.
1104fb0a5ebSJens Wiklander */
1114fb0a5ebSJens Wiklander struct optee_supp {
1121647a5acSJens Wiklander /* Serializes access to this struct */
1131647a5acSJens Wiklander struct mutex mutex;
1144fb0a5ebSJens Wiklander struct tee_context *ctx;
1154fb0a5ebSJens Wiklander
1161647a5acSJens Wiklander int req_id;
1171647a5acSJens Wiklander struct list_head reqs;
1181647a5acSJens Wiklander struct idr idr;
1191647a5acSJens Wiklander struct completion reqs_c;
1204fb0a5ebSJens Wiklander };
1214fb0a5ebSJens Wiklander
122b3b4ced1SEtienne Carriere /*
123b3b4ced1SEtienne Carriere * struct optee_pcpu - per cpu notif private struct passed to work functions
124b3b4ced1SEtienne Carriere * @optee optee device reference
125b3b4ced1SEtienne Carriere */
126b3b4ced1SEtienne Carriere struct optee_pcpu {
127b3b4ced1SEtienne Carriere struct optee *optee;
128b3b4ced1SEtienne Carriere };
129b3b4ced1SEtienne Carriere
130b3b4ced1SEtienne Carriere /*
131b3b4ced1SEtienne Carriere * struct optee_smc - optee smc communication struct
132b3b4ced1SEtienne Carriere * @invoke_fn handler function to invoke secure monitor
133b3b4ced1SEtienne Carriere * @memremaped_shm virtual address of memory in shared memory pool
134b3b4ced1SEtienne Carriere * @sec_caps: secure world capabilities defined by
135b3b4ced1SEtienne Carriere * OPTEE_SMC_SEC_CAP_* in optee_smc.h
136b3b4ced1SEtienne Carriere * @notif_irq interrupt used as async notification by OP-TEE or 0
137b3b4ced1SEtienne Carriere * @optee_pcpu per_cpu optee instance for per cpu work or NULL
138b3b4ced1SEtienne Carriere * @notif_pcpu_wq workqueue for per cpu asynchronous notification or NULL
139b3b4ced1SEtienne Carriere * @notif_pcpu_work work for per cpu asynchronous notification
140b3b4ced1SEtienne Carriere * @notif_cpuhp_state CPU hotplug state assigned for pcpu interrupt management
141b3b4ced1SEtienne Carriere */
142c51a564aSJens Wiklander struct optee_smc {
143c51a564aSJens Wiklander optee_invoke_fn *invoke_fn;
144c51a564aSJens Wiklander void *memremaped_shm;
145c51a564aSJens Wiklander u32 sec_caps;
1466749e69cSJens Wiklander unsigned int notif_irq;
147b3b4ced1SEtienne Carriere struct optee_pcpu __percpu *optee_pcpu;
148b3b4ced1SEtienne Carriere struct workqueue_struct *notif_pcpu_wq;
149b3b4ced1SEtienne Carriere struct work_struct notif_pcpu_work;
150b3b4ced1SEtienne Carriere unsigned int notif_cpuhp_state;
151c51a564aSJens Wiklander };
152c51a564aSJens Wiklander
1534615e5a3SJens Wiklander /**
1544615e5a3SJens Wiklander * struct optee_ffa_data - FFA communication struct
1554615e5a3SJens Wiklander * @ffa_dev FFA device, contains the destination id, the id of
1564615e5a3SJens Wiklander * OP-TEE in secure world
157d0476a59SJens Wiklander * @bottom_half_value Notification ID used for bottom half signalling or
158d0476a59SJens Wiklander * U32_MAX if unused
1594615e5a3SJens Wiklander * @mutex Serializes access to @global_ids
1604615e5a3SJens Wiklander * @global_ids FF-A shared memory global handle translation
1614615e5a3SJens Wiklander */
1624615e5a3SJens Wiklander struct optee_ffa {
1634615e5a3SJens Wiklander struct ffa_device *ffa_dev;
164d0476a59SJens Wiklander u32 bottom_half_value;
1654615e5a3SJens Wiklander /* Serializes access to @global_ids */
1664615e5a3SJens Wiklander struct mutex mutex;
1674615e5a3SJens Wiklander struct rhashtable global_ids;
1684615e5a3SJens Wiklander };
1694615e5a3SJens Wiklander
1704602c584SJens Wiklander struct optee;
1714602c584SJens Wiklander
1724602c584SJens Wiklander /**
1734602c584SJens Wiklander * struct optee_ops - OP-TEE driver internal operations
1744602c584SJens Wiklander * @do_call_with_arg: enters OP-TEE in secure world
1754602c584SJens Wiklander * @to_msg_param: converts from struct tee_param to OPTEE_MSG parameters
1764602c584SJens Wiklander * @from_msg_param: converts from OPTEE_MSG parameters to struct tee_param
1774602c584SJens Wiklander *
1784602c584SJens Wiklander * These OPs are only supposed to be used internally in the OP-TEE driver
1794602c584SJens Wiklander * as a way of abstracting the different methogs of entering OP-TEE in
1804602c584SJens Wiklander * secure world.
1814602c584SJens Wiklander */
1824602c584SJens Wiklander struct optee_ops {
1834602c584SJens Wiklander int (*do_call_with_arg)(struct tee_context *ctx,
184077798daSEtienne Carriere struct tee_shm *shm_arg, u_int offs,
185077798daSEtienne Carriere bool system_thread);
1864602c584SJens Wiklander int (*to_msg_param)(struct optee *optee,
1874602c584SJens Wiklander struct optee_msg_param *msg_params,
1884602c584SJens Wiklander size_t num_params, const struct tee_param *params);
1894602c584SJens Wiklander int (*from_msg_param)(struct optee *optee, struct tee_param *params,
1904602c584SJens Wiklander size_t num_params,
1914602c584SJens Wiklander const struct optee_msg_param *msg_params);
1924602c584SJens Wiklander };
1934602c584SJens Wiklander
1944fb0a5ebSJens Wiklander /**
1954fb0a5ebSJens Wiklander * struct optee - main service struct
1964fb0a5ebSJens Wiklander * @supp_teedev: supplicant device
197aceeafefSJens Wiklander * @teedev: client device
1984602c584SJens Wiklander * @ops: internal callbacks for different ways to reach secure
1994602c584SJens Wiklander * world
200aceeafefSJens Wiklander * @ctx: driver internal TEE context
201c51a564aSJens Wiklander * @smc: specific to SMC ABI
2024615e5a3SJens Wiklander * @ffa: specific to FF-A ABI
2034fb0a5ebSJens Wiklander * @call_queue: queue of threads waiting to call @invoke_fn
204787c80ccSJens Wiklander * @notif: notification synchronization struct
2054fb0a5ebSJens Wiklander * @supp: supplicant synchronization struct for RPC to supplicant
2064fb0a5ebSJens Wiklander * @pool: shared memory pool
207*f0c84315SJens Wiklander * @mutex: mutex protecting @rpmb_dev
208*f0c84315SJens Wiklander * @rpmb_dev: current RPMB device or NULL
209*f0c84315SJens Wiklander * @rpmb_scan_bus_done flag if device registation of RPMB dependent devices
210*f0c84315SJens Wiklander * was already done
211*f0c84315SJens Wiklander * @rpmb_scan_bus_work workq to for an RPMB device and to scan optee bus
212*f0c84315SJens Wiklander * and register RPMB dependent optee drivers
21330c375a7SJens Wiklander * @rpc_param_count: If > 0 number of RPC parameters to make room for
2145f178bb7SMaxim Uvarov * @scan_bus_done flag if device registation was already done.
2155f178bb7SMaxim Uvarov * @scan_bus_work workq to scan optee bus and register optee drivers
2164fb0a5ebSJens Wiklander */
2174fb0a5ebSJens Wiklander struct optee {
2184fb0a5ebSJens Wiklander struct tee_device *supp_teedev;
2194fb0a5ebSJens Wiklander struct tee_device *teedev;
2204602c584SJens Wiklander const struct optee_ops *ops;
221aceeafefSJens Wiklander struct tee_context *ctx;
2224615e5a3SJens Wiklander union {
223c51a564aSJens Wiklander struct optee_smc smc;
2244615e5a3SJens Wiklander struct optee_ffa ffa;
2254615e5a3SJens Wiklander };
2265b4018b9SJens Wiklander struct optee_shm_arg_cache shm_arg_cache;
2274fb0a5ebSJens Wiklander struct optee_call_queue call_queue;
228787c80ccSJens Wiklander struct optee_notif notif;
2294fb0a5ebSJens Wiklander struct optee_supp supp;
2304fb0a5ebSJens Wiklander struct tee_shm_pool *pool;
231*f0c84315SJens Wiklander /* Protects rpmb_dev pointer */
232*f0c84315SJens Wiklander struct mutex rpmb_dev_mutex;
233*f0c84315SJens Wiklander struct rpmb_dev *rpmb_dev;
234*f0c84315SJens Wiklander struct notifier_block rpmb_intf;
23530c375a7SJens Wiklander unsigned int rpc_param_count;
2365f178bb7SMaxim Uvarov bool scan_bus_done;
237*f0c84315SJens Wiklander bool rpmb_scan_bus_done;
238*f0c84315SJens Wiklander bool in_kernel_rpmb_routing;
2395f178bb7SMaxim Uvarov struct work_struct scan_bus_work;
240*f0c84315SJens Wiklander struct work_struct rpmb_scan_bus_work;
2414fb0a5ebSJens Wiklander };
2424fb0a5ebSJens Wiklander
2434fb0a5ebSJens Wiklander struct optee_session {
2444fb0a5ebSJens Wiklander struct list_head list_node;
2454fb0a5ebSJens Wiklander u32 session_id;
246077798daSEtienne Carriere bool use_sys_thread;
2474fb0a5ebSJens Wiklander };
2484fb0a5ebSJens Wiklander
2494fb0a5ebSJens Wiklander struct optee_context_data {
2504fb0a5ebSJens Wiklander /* Serializes access to this struct */
2514fb0a5ebSJens Wiklander struct mutex mutex;
2524fb0a5ebSJens Wiklander struct list_head sess_list;
2534fb0a5ebSJens Wiklander };
2544fb0a5ebSJens Wiklander
2554fb0a5ebSJens Wiklander struct optee_rpc_param {
2564fb0a5ebSJens Wiklander u32 a0;
2574fb0a5ebSJens Wiklander u32 a1;
2584fb0a5ebSJens Wiklander u32 a2;
2594fb0a5ebSJens Wiklander u32 a3;
2604fb0a5ebSJens Wiklander u32 a4;
2614fb0a5ebSJens Wiklander u32 a5;
2624fb0a5ebSJens Wiklander u32 a6;
2634fb0a5ebSJens Wiklander u32 a7;
2644fb0a5ebSJens Wiklander };
2654fb0a5ebSJens Wiklander
26653a107c8SVolodymyr Babchuk /* Holds context that is preserved during one STD call */
26753a107c8SVolodymyr Babchuk struct optee_call_ctx {
26853a107c8SVolodymyr Babchuk /* information about pages list used in last allocation */
26953a107c8SVolodymyr Babchuk void *pages_list;
27053a107c8SVolodymyr Babchuk size_t num_entries;
27153a107c8SVolodymyr Babchuk };
27253a107c8SVolodymyr Babchuk
273*f0c84315SJens Wiklander extern struct blocking_notifier_head optee_rpmb_intf_added;
274*f0c84315SJens Wiklander
275787c80ccSJens Wiklander int optee_notif_init(struct optee *optee, u_int max_key);
276787c80ccSJens Wiklander void optee_notif_uninit(struct optee *optee);
27714ca6401SGavin Liu int optee_notif_wait(struct optee *optee, u_int key, u32 timeout);
278787c80ccSJens Wiklander int optee_notif_send(struct optee *optee, u_int key);
2794fb0a5ebSJens Wiklander
2804fb0a5ebSJens Wiklander u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params,
2814fb0a5ebSJens Wiklander struct tee_param *param);
2824fb0a5ebSJens Wiklander
2834fb0a5ebSJens Wiklander void optee_supp_init(struct optee_supp *supp);
2844fb0a5ebSJens Wiklander void optee_supp_uninit(struct optee_supp *supp);
2851647a5acSJens Wiklander void optee_supp_release(struct optee_supp *supp);
2864fb0a5ebSJens Wiklander
2874fb0a5ebSJens Wiklander int optee_supp_recv(struct tee_context *ctx, u32 *func, u32 *num_params,
2884fb0a5ebSJens Wiklander struct tee_param *param);
2894fb0a5ebSJens Wiklander int optee_supp_send(struct tee_context *ctx, u32 ret, u32 num_params,
2904fb0a5ebSJens Wiklander struct tee_param *param);
2914fb0a5ebSJens Wiklander
2924fb0a5ebSJens Wiklander int optee_open_session(struct tee_context *ctx,
2934fb0a5ebSJens Wiklander struct tee_ioctl_open_session_arg *arg,
2944fb0a5ebSJens Wiklander struct tee_param *param);
29545bc2c9bSEtienne Carriere int optee_system_session(struct tee_context *ctx, u32 session);
296077798daSEtienne Carriere int optee_close_session_helper(struct tee_context *ctx, u32 session,
297077798daSEtienne Carriere bool system_thread);
2984fb0a5ebSJens Wiklander int optee_close_session(struct tee_context *ctx, u32 session);
2994fb0a5ebSJens Wiklander int optee_invoke_func(struct tee_context *ctx, struct tee_ioctl_invoke_arg *arg,
3004fb0a5ebSJens Wiklander struct tee_param *param);
3014fb0a5ebSJens Wiklander int optee_cancel_req(struct tee_context *ctx, u32 cancel_id, u32 session);
3024fb0a5ebSJens Wiklander
3035f178bb7SMaxim Uvarov #define PTA_CMD_GET_DEVICES 0x0
3045f178bb7SMaxim Uvarov #define PTA_CMD_GET_DEVICES_SUPP 0x1
305*f0c84315SJens Wiklander #define PTA_CMD_GET_DEVICES_RPMB 0x2
3065f178bb7SMaxim Uvarov int optee_enumerate_devices(u32 func);
3077f565d0eSSumit Garg void optee_unregister_devices(void);
308*f0c84315SJens Wiklander void optee_bus_scan_rpmb(struct work_struct *work);
309*f0c84315SJens Wiklander int optee_rpmb_intf_rdev(struct notifier_block *intf, unsigned long action,
310*f0c84315SJens Wiklander void *data);
311c3fa24afSSumit Garg
312*f0c84315SJens Wiklander void optee_set_dev_group(struct optee *optee);
313c51a564aSJens Wiklander void optee_remove_common(struct optee *optee);
314c51a564aSJens Wiklander int optee_open(struct tee_context *ctx, bool cap_memref_null);
315c51a564aSJens Wiklander void optee_release(struct tee_context *ctx);
316c51a564aSJens Wiklander void optee_release_supp(struct tee_context *ctx);
317c51a564aSJens Wiklander
optee_from_msg_param_value(struct tee_param * p,u32 attr,const struct optee_msg_param * mp)318c51a564aSJens Wiklander static inline void optee_from_msg_param_value(struct tee_param *p, u32 attr,
319c51a564aSJens Wiklander const struct optee_msg_param *mp)
320c51a564aSJens Wiklander {
321c51a564aSJens Wiklander p->attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT +
322c51a564aSJens Wiklander attr - OPTEE_MSG_ATTR_TYPE_VALUE_INPUT;
323c51a564aSJens Wiklander p->u.value.a = mp->u.value.a;
324c51a564aSJens Wiklander p->u.value.b = mp->u.value.b;
325c51a564aSJens Wiklander p->u.value.c = mp->u.value.c;
326c51a564aSJens Wiklander }
327c51a564aSJens Wiklander
optee_to_msg_param_value(struct optee_msg_param * mp,const struct tee_param * p)328c51a564aSJens Wiklander static inline void optee_to_msg_param_value(struct optee_msg_param *mp,
329c51a564aSJens Wiklander const struct tee_param *p)
330c51a564aSJens Wiklander {
331c51a564aSJens Wiklander mp->attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT + p->attr -
332c51a564aSJens Wiklander TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT;
333c51a564aSJens Wiklander mp->u.value.a = p->u.value.a;
334c51a564aSJens Wiklander mp->u.value.b = p->u.value.b;
335c51a564aSJens Wiklander mp->u.value.c = p->u.value.c;
336c51a564aSJens Wiklander }
337c51a564aSJens Wiklander
33845bc2c9bSEtienne Carriere void optee_cq_init(struct optee_call_queue *cq, int thread_count);
339c51a564aSJens Wiklander void optee_cq_wait_init(struct optee_call_queue *cq,
340077798daSEtienne Carriere struct optee_call_waiter *w, bool sys_thread);
341c51a564aSJens Wiklander void optee_cq_wait_for_completion(struct optee_call_queue *cq,
342c51a564aSJens Wiklander struct optee_call_waiter *w);
343c51a564aSJens Wiklander void optee_cq_wait_final(struct optee_call_queue *cq,
344c51a564aSJens Wiklander struct optee_call_waiter *w);
345c51a564aSJens Wiklander int optee_check_mem_type(unsigned long start, size_t num_pages);
3465b4018b9SJens Wiklander
3475b4018b9SJens Wiklander void optee_shm_arg_cache_init(struct optee *optee, u32 flags);
3485b4018b9SJens Wiklander void optee_shm_arg_cache_uninit(struct optee *optee);
3495b4018b9SJens Wiklander struct optee_msg_arg *optee_get_msg_arg(struct tee_context *ctx,
3505b4018b9SJens Wiklander size_t num_params,
3515b4018b9SJens Wiklander struct optee_shm_arg_entry **entry,
3525b4018b9SJens Wiklander struct tee_shm **shm_ret,
3535b4018b9SJens Wiklander u_int *offs);
3545b4018b9SJens Wiklander void optee_free_msg_arg(struct tee_context *ctx,
3555b4018b9SJens Wiklander struct optee_shm_arg_entry *entry, u_int offs);
3565b4018b9SJens Wiklander size_t optee_msg_arg_size(size_t rpc_param_count);
3575b4018b9SJens Wiklander
358c51a564aSJens Wiklander
359c51a564aSJens Wiklander struct tee_shm *optee_rpc_cmd_alloc_suppl(struct tee_context *ctx, size_t sz);
360c51a564aSJens Wiklander void optee_rpc_cmd_free_suppl(struct tee_context *ctx, struct tee_shm *shm);
361c51a564aSJens Wiklander void optee_rpc_cmd(struct tee_context *ctx, struct optee *optee,
362c51a564aSJens Wiklander struct optee_msg_arg *arg);
363c51a564aSJens Wiklander
3646dea6352SJens Wiklander int optee_do_bottom_half(struct tee_context *ctx);
3656dea6352SJens Wiklander int optee_stop_async_notif(struct tee_context *ctx);
3666dea6352SJens Wiklander
3674fb0a5ebSJens Wiklander /*
3684fb0a5ebSJens Wiklander * Small helpers
3694fb0a5ebSJens Wiklander */
3704fb0a5ebSJens Wiklander
reg_pair_to_ptr(u32 reg0,u32 reg1)3714fb0a5ebSJens Wiklander static inline void *reg_pair_to_ptr(u32 reg0, u32 reg1)
3724fb0a5ebSJens Wiklander {
3734fb0a5ebSJens Wiklander return (void *)(unsigned long)(((u64)reg0 << 32) | reg1);
3744fb0a5ebSJens Wiklander }
3754fb0a5ebSJens Wiklander
reg_pair_from_64(u32 * reg0,u32 * reg1,u64 val)3764fb0a5ebSJens Wiklander static inline void reg_pair_from_64(u32 *reg0, u32 *reg1, u64 val)
3774fb0a5ebSJens Wiklander {
3784fb0a5ebSJens Wiklander *reg0 = val >> 32;
3794fb0a5ebSJens Wiklander *reg1 = val;
3804fb0a5ebSJens Wiklander }
3814fb0a5ebSJens Wiklander
382c51a564aSJens Wiklander /* Registration of the ABIs */
383c51a564aSJens Wiklander int optee_smc_abi_register(void);
384c51a564aSJens Wiklander void optee_smc_abi_unregister(void);
3854615e5a3SJens Wiklander int optee_ffa_abi_register(void);
3864615e5a3SJens Wiklander void optee_ffa_abi_unregister(void);
387c51a564aSJens Wiklander
3884fb0a5ebSJens Wiklander #endif /*OPTEE_PRIVATE_H*/
389