@@ -86,6 +86,7 @@ struct optee_driver_data {
86
86
struct k_spinlock notif_lock ;
87
87
struct optee_supp supp ;
88
88
unsigned long sec_caps ;
89
+ struct k_sem call_sem ;
89
90
};
90
91
91
92
/* Wrapping functions so function pointer can be used */
@@ -683,6 +684,8 @@ static int optee_call(const struct device *dev, struct optee_msg_arg *arg)
683
684
void * pages = NULL ;
684
685
685
686
u64_to_regs ((uint64_t )k_mem_phys_addr (arg ), & param .a1 , & param .a2 );
687
+
688
+ k_sem_take (& data -> call_sem , K_FOREVER );
686
689
while (true) {
687
690
struct arm_smccc_res res ;
688
691
@@ -697,6 +700,7 @@ static int optee_call(const struct device *dev, struct optee_msg_arg *arg)
697
700
handle_rpc_call (dev , & param , & pages );
698
701
} else {
699
702
free_shm_pages (& pages );
703
+ k_sem_give (& data -> call_sem );
700
704
return res .a0 == OPTEE_SMC_RETURN_OK ? TEEC_SUCCESS :
701
705
TEEC_ERROR_BAD_PARAMETERS ;
702
706
}
@@ -1197,9 +1201,26 @@ static bool optee_exchange_caps(const struct device *dev, unsigned long *sec_cap
1197
1201
return true;
1198
1202
}
1199
1203
1204
+ static unsigned long optee_get_thread_count (const struct device * dev , unsigned long * thread_count )
1205
+ {
1206
+ struct optee_driver_data * data = (struct optee_driver_data * )dev -> data ;
1207
+ struct arm_smccc_res res = { 0 };
1208
+ unsigned long a1 = 0 ;
1209
+
1210
+ data -> smc_call (OPTEE_SMC_GET_THREAD_COUNT , a1 , 0 , 0 , 0 , 0 , 0 , 0 , & res );
1211
+
1212
+ if (res .a0 != OPTEE_SMC_RETURN_OK ) {
1213
+ return false;
1214
+ }
1215
+
1216
+ * thread_count = res .a1 ;
1217
+ return true;
1218
+ }
1219
+
1200
1220
static int optee_init (const struct device * dev )
1201
1221
{
1202
1222
struct optee_driver_data * data = dev -> data ;
1223
+ unsigned long thread_count ;
1203
1224
1204
1225
if (set_optee_method (dev )) {
1205
1226
return - ENOTSUP ;
@@ -1227,6 +1248,13 @@ static int optee_init(const struct device *dev)
1227
1248
return - ENOTSUP ;
1228
1249
}
1229
1250
1251
+ if (!optee_get_thread_count (dev , & thread_count )) {
1252
+ LOG_ERR ("OPTEE unable to get maximum thread count" );
1253
+ return - ENOTSUP ;
1254
+ }
1255
+
1256
+ k_sem_init (& data -> call_sem , thread_count , thread_count );
1257
+
1230
1258
return 0 ;
1231
1259
}
1232
1260
0 commit comments