Skip to content

Commit 7c64a8b

Browse files
oleksiimoisieievnashif
authored andcommitted
drivers: tee: optee: handlde GET_THREAD_COUNT call
Optee driver should handle GET_THREAD_COUNT call. This limitation is set in Optee-OS during build and limits number of symultanious calls to optee. Add sym to handle this limitation. Signed-off-by: Oleksii Moisieiev <[email protected]>
1 parent 97ec554 commit 7c64a8b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

drivers/tee/optee/optee.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct optee_driver_data {
8686
struct k_spinlock notif_lock;
8787
struct optee_supp supp;
8888
unsigned long sec_caps;
89+
struct k_sem call_sem;
8990
};
9091

9192
/* 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)
683684
void *pages = NULL;
684685

685686
u64_to_regs((uint64_t)k_mem_phys_addr(arg), &param.a1, &param.a2);
687+
688+
k_sem_take(&data->call_sem, K_FOREVER);
686689
while (true) {
687690
struct arm_smccc_res res;
688691

@@ -697,6 +700,7 @@ static int optee_call(const struct device *dev, struct optee_msg_arg *arg)
697700
handle_rpc_call(dev, &param, &pages);
698701
} else {
699702
free_shm_pages(&pages);
703+
k_sem_give(&data->call_sem);
700704
return res.a0 == OPTEE_SMC_RETURN_OK ? TEEC_SUCCESS :
701705
TEEC_ERROR_BAD_PARAMETERS;
702706
}
@@ -1197,9 +1201,26 @@ static bool optee_exchange_caps(const struct device *dev, unsigned long *sec_cap
11971201
return true;
11981202
}
11991203

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+
12001220
static int optee_init(const struct device *dev)
12011221
{
12021222
struct optee_driver_data *data = dev->data;
1223+
unsigned long thread_count;
12031224

12041225
if (set_optee_method(dev)) {
12051226
return -ENOTSUP;
@@ -1227,6 +1248,13 @@ static int optee_init(const struct device *dev)
12271248
return -ENOTSUP;
12281249
}
12291250

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+
12301258
return 0;
12311259
}
12321260

tests/drivers/tee/optee/src/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ void arm_smccc_smc(unsigned long a0, unsigned long a1, unsigned long a2, unsigne
6767
res->a1 = OPTEE_SMC_SEC_CAP_DYNAMIC_SHM;
6868
return;
6969
}
70+
if (a0 == OPTEE_SMC_GET_THREAD_COUNT) {
71+
res->a1 = 5;
72+
return;
73+
}
7074
if (t_call.pending && t_call.smc_cb) {
7175
t_call.smc_cb(a0, a1, a2, a3, a4, a5, a6, a7, res);
7276
}

0 commit comments

Comments
 (0)