@@ -23,11 +23,23 @@ typedef uint32_t qcomtee_op_t;
2323 * @{
2424 */
2525
26+ /**
27+ * @def QCOMTEE_OBJREF_TEE
28+ * @brief It indicates that the object is hosted in QTEE.
29+ */
30+ #define QCOMTEE_OBJREF_TEE (1 << 0)
31+
2632/**
2733 * @def QCOMTEE_OBJREF_USER
2834 * @brief It indicates that the object is hosted in userspace.
2935 */
30- #define QCOMTEE_OBJREF_USER (1 << 0)
36+ #define QCOMTEE_OBJREF_USER (1 << 1)
37+
38+ /**
39+ * @def QCOMTEE_OBJREF_MEM
40+ * @brief It indicates that the object is a memory object.
41+ */
42+ #define QCOMTEE_OBJREF_MEM (1 << 2)
3143
3244/** @} */ // end of ObjRefFlags
3345
@@ -44,7 +56,7 @@ typedef uint32_t qcomtee_op_t;
4456 * @brief Release object.
4557 *
4658 */
47- #define QCOMTEE_OBJREF_OP_RELEASE ((qcomtee_op_t)(65536 ))
59+ #define QCOMTEE_OBJREF_OP_RELEASE ((qcomtee_op_t)(65535 ))
4860
4961/** @} */ // end of ObjRefOperations
5062
@@ -130,6 +142,7 @@ typedef enum {
130142 QCOMTEE_OBJECT_TYPE_TEE , /**< It is an object hosted in QTEE. */
131143 QCOMTEE_OBJECT_TYPE_ROOT , /**< It is a root object. */
132144 QCOMTEE_OBJECT_TYPE_CB , /**< It is a callback object. */
145+ QCOMTEE_OBJECT_TYPE_MEMORY , /**< It is a memory object. */
133146} qcomtee_object_type_t ;
134147
135148/**
@@ -195,6 +208,7 @@ struct qcomtee_object_ops {
195208struct qcomtee_object {
196209 atomic_int refs ; /**< Number of references to this object. */
197210 uint64_t object_id ; /**< ID assigned to this object. */
211+ uint64_t tee_object_id ; /**< ID assigned to this object for QTEE. */
198212 qcomtee_object_type_t object_type ; /**< Object Type. */
199213
200214 /**
@@ -244,10 +258,23 @@ qcomtee_object_typeof(struct qcomtee_object *object)
244258/**
245259 * @brief Increase object reference count.
246260 * @param object The object being incremented.
261+ * @return On success, returns 0;
262+ * Otherwise, returns -1.
247263 */
248- static inline void qcomtee_object_refs_inc (struct qcomtee_object * object )
264+ static inline int qcomtee_object_refs_inc (struct qcomtee_object * object )
249265{
250- atomic_fetch_add (& object -> refs , 1 );
266+ int old ;
267+
268+ if (object == QCOMTEE_OBJECT_NULL )
269+ return -1 ;
270+
271+ old = atomic_load (& object -> refs );
272+ do {
273+ if (old == 0 )
274+ return -1 ;
275+ } while (!atomic_compare_exchange_weak (& object -> refs , & old , old + 1 ));
276+
277+ return 0 ;
251278}
252279
253280/**
@@ -256,9 +283,16 @@ static inline void qcomtee_object_refs_inc(struct qcomtee_object *object)
256283 */
257284void qcomtee_object_refs_dec (struct qcomtee_object * object );
258285
286+ #ifdef __GLIBC__
287+ typedef int (* tee_call_t )(int , unsigned long , ...);
288+ #else
289+ typedef int (* tee_call_t )(int , int , ...);
290+ #endif
291+
259292/**
260293 * @brief Create a root object.
261294 * @param dev TEE device file pathname.
295+ * @param tee_call API to call to TEE driver (e.g. ioctl()).
262296 * @param release Called on destruction of this root object.
263297 * @param arg Argument passed to release.
264298 *
@@ -268,8 +302,10 @@ void qcomtee_object_refs_dec(struct qcomtee_object *object);
268302 * @return On success, returns the object;
269303 * Otherwise, returns @ref QCOMTEE_OBJECT_NULL.
270304 */
271- struct qcomtee_object *
272- qcomtee_object_root_init (const char * dev , void (* release )(void * ), void * arg );
305+ struct qcomtee_object * qcomtee_object_root_init (const char * dev ,
306+ tee_call_t tee_call ,
307+ void (* release )(void * ),
308+ void * arg );
273309
274310/**
275311 * @brief Initialize a callback objet.
@@ -282,12 +318,6 @@ int qcomtee_object_cb_init(struct qcomtee_object *object,
282318 struct qcomtee_object_ops * ops ,
283319 struct qcomtee_object * root );
284320
285- #ifdef __GLIBC__
286- typedef int (* tee_call_t )(int , unsigned long , ...);
287- #else
288- typedef int (* tee_call_t )(int , int , ...);
289- #endif
290-
291321/**
292322 * @brief Invoke an Object.
293323 *
@@ -299,12 +329,11 @@ typedef int (*tee_call_t)(int, int, ...);
299329 * @param params Input parameter array to the requested operation.
300330 * @param num_params Number of parameter in the input array.
301331 * @param result Result of operation.
302- * @param tee_call Submit request to kernel driver.
303332 * @return On success, 0; Otherwise, returns -1.
304333 */
305334int qcomtee_object_invoke (struct qcomtee_object * object , qcomtee_op_t op ,
306335 struct qcomtee_param * params , int num_params ,
307- qcomtee_result_t * result , tee_call_t tee_call );
336+ qcomtee_result_t * result );
308337
309338/**
310339 * @brief Process single request.
@@ -317,15 +346,13 @@ int qcomtee_object_invoke(struct qcomtee_object *object, qcomtee_op_t op,
317346 * operation. Therefore, if it is being executed by a pthread, it is not
318347 * safe to use PTHREAD_CANCEL_ASYNCHRONOUS.
319348 *
320- * The tee_call function should implement support for reading a new request
321- * (i.e., TEE_IOC_SUPPL_RECV) and submitting the response
349+ * The @ref qcomtee_object:: tee_call function should implement support for
350+ * reading a new request (i.e., TEE_IOC_SUPPL_RECV) and submitting the response
322351 * (i.e., TEE_IOC_SUPPL_SEND).
323352 *
324353 * @param root The root object for which the request queue is checked.
325- * @param tee_call Read a request and submit response to kernel driver.
326354 * @return On success, 0; Otherwise, returns -1.
327355 */
328- int qcomtee_object_process_one (struct qcomtee_object * root ,
329- tee_call_t tee_call );
356+ int qcomtee_object_process_one (struct qcomtee_object * root );
330357
331358#endif // _QCOMTEE_OBJECT_H
0 commit comments