Skip to content

Commit 5f178bb

Browse files
muvarovjenswi-linaro
authored andcommitted
optee: enable support for multi-stage bus enumeration
Some drivers (like ftpm) can operate only after tee-supplicant runs because of tee-supplicant provides things like storage services (rpmb, shm).  This patch splits probe of non tee-supplicant dependable drivers to the early stage, and after tee-supplicant run probe other drivers. Signed-off-by: Maxim Uvarov <[email protected]> Suggested-by: Sumit Garg <[email protected]> Suggested-by: Arnd Bergmann <[email protected]> Reviewed-by: Sumit Garg <[email protected]> Acked-by: Jarkko Sakkinen <[email protected]> Tested-by: Sumit Garg <[email protected]> Signed-off-by: Jens Wiklander <[email protected]>
1 parent 58df195 commit 5f178bb

File tree

3 files changed

+44
-22
lines changed

3 files changed

+44
-22
lines changed

drivers/tee/optee/core.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/tee_drv.h>
1818
#include <linux/types.h>
1919
#include <linux/uaccess.h>
20+
#include <linux/workqueue.h>
2021
#include "optee_private.h"
2122
#include "optee_smc.h"
2223
#include "shm_pool.h"
@@ -218,6 +219,11 @@ static void optee_get_version(struct tee_device *teedev,
218219
*vers = v;
219220
}
220221

222+
static void optee_bus_scan(struct work_struct *work)
223+
{
224+
WARN_ON(optee_enumerate_devices(PTA_CMD_GET_DEVICES_SUPP));
225+
}
226+
221227
static int optee_open(struct tee_context *ctx)
222228
{
223229
struct optee_context_data *ctxdata;
@@ -241,8 +247,18 @@ static int optee_open(struct tee_context *ctx)
241247
kfree(ctxdata);
242248
return -EBUSY;
243249
}
244-
}
245250

251+
if (!optee->scan_bus_done) {
252+
INIT_WORK(&optee->scan_bus_work, optee_bus_scan);
253+
optee->scan_bus_wq = create_workqueue("optee_bus_scan");
254+
if (!optee->scan_bus_wq) {
255+
kfree(ctxdata);
256+
return -ECHILD;
257+
}
258+
queue_work(optee->scan_bus_wq, &optee->scan_bus_work);
259+
optee->scan_bus_done = true;
260+
}
261+
}
246262
mutex_init(&ctxdata->mutex);
247263
INIT_LIST_HEAD(&ctxdata->sess_list);
248264

@@ -296,8 +312,13 @@ static void optee_release(struct tee_context *ctx)
296312

297313
ctx->data = NULL;
298314

299-
if (teedev == optee->supp_teedev)
315+
if (teedev == optee->supp_teedev) {
316+
if (optee->scan_bus_wq) {
317+
destroy_workqueue(optee->scan_bus_wq);
318+
optee->scan_bus_wq = NULL;
319+
}
300320
optee_supp_release(&optee->supp);
321+
}
301322
}
302323

303324
static const struct tee_driver_ops optee_ops = {
@@ -675,7 +696,7 @@ static int optee_probe(struct platform_device *pdev)
675696

676697
platform_set_drvdata(pdev, optee);
677698

678-
rc = optee_enumerate_devices();
699+
rc = optee_enumerate_devices(PTA_CMD_GET_DEVICES);
679700
if (rc) {
680701
optee_remove(pdev);
681702
return rc;

drivers/tee/optee/device.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@
1111
#include <linux/uuid.h>
1212
#include "optee_private.h"
1313

14-
/*
15-
* Get device UUIDs
16-
*
17-
* [out] memref[0] Array of device UUIDs
18-
*
19-
* Return codes:
20-
* TEE_SUCCESS - Invoke command success
21-
* TEE_ERROR_BAD_PARAMETERS - Incorrect input param
22-
* TEE_ERROR_SHORT_BUFFER - Output buffer size less than required
23-
*/
24-
#define PTA_CMD_GET_DEVICES 0x0
25-
2614
static int optee_ctx_match(struct tee_ioctl_version_data *ver, const void *data)
2715
{
2816
if (ver->impl_id == TEE_IMPL_ID_OPTEE)
@@ -32,7 +20,8 @@ static int optee_ctx_match(struct tee_ioctl_version_data *ver, const void *data)
3220
}
3321

3422
static int get_devices(struct tee_context *ctx, u32 session,
35-
struct tee_shm *device_shm, u32 *shm_size)
23+
struct tee_shm *device_shm, u32 *shm_size,
24+
u32 func)
3625
{
3726
int ret = 0;
3827
struct tee_ioctl_invoke_arg inv_arg;
@@ -41,8 +30,7 @@ static int get_devices(struct tee_context *ctx, u32 session,
4130
memset(&inv_arg, 0, sizeof(inv_arg));
4231
memset(&param, 0, sizeof(param));
4332

44-
/* Invoke PTA_CMD_GET_DEVICES function */
45-
inv_arg.func = PTA_CMD_GET_DEVICES;
33+
inv_arg.func = func;
4634
inv_arg.session = session;
4735
inv_arg.num_params = 4;
4836

@@ -90,7 +78,7 @@ static int optee_register_device(const uuid_t *device_uuid)
9078
return rc;
9179
}
9280

93-
int optee_enumerate_devices(void)
81+
static int __optee_enumerate_devices(u32 func)
9482
{
9583
const uuid_t pta_uuid =
9684
UUID_INIT(0x7011a688, 0xddde, 0x4053,
@@ -121,7 +109,7 @@ int optee_enumerate_devices(void)
121109
goto out_ctx;
122110
}
123111

124-
rc = get_devices(ctx, sess_arg.session, NULL, &shm_size);
112+
rc = get_devices(ctx, sess_arg.session, NULL, &shm_size, func);
125113
if (rc < 0 || !shm_size)
126114
goto out_sess;
127115

@@ -133,7 +121,7 @@ int optee_enumerate_devices(void)
133121
goto out_sess;
134122
}
135123

136-
rc = get_devices(ctx, sess_arg.session, device_shm, &shm_size);
124+
rc = get_devices(ctx, sess_arg.session, device_shm, &shm_size, func);
137125
if (rc < 0)
138126
goto out_shm;
139127

@@ -161,3 +149,8 @@ int optee_enumerate_devices(void)
161149

162150
return rc;
163151
}
152+
153+
int optee_enumerate_devices(u32 func)
154+
{
155+
return __optee_enumerate_devices(func);
156+
}

drivers/tee/optee/optee_private.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ struct optee_supp {
7878
* @memremaped_shm virtual address of memory in shared memory pool
7979
* @sec_caps: secure world capabilities defined by
8080
* OPTEE_SMC_SEC_CAP_* in optee_smc.h
81+
* @scan_bus_done flag if device registation was already done.
82+
* @scan_bus_wq workqueue to scan optee bus and register optee drivers
83+
* @scan_bus_work workq to scan optee bus and register optee drivers
8184
*/
8285
struct optee {
8386
struct tee_device *supp_teedev;
@@ -89,6 +92,9 @@ struct optee {
8992
struct tee_shm_pool *pool;
9093
void *memremaped_shm;
9194
u32 sec_caps;
95+
bool scan_bus_done;
96+
struct workqueue_struct *scan_bus_wq;
97+
struct work_struct scan_bus_work;
9298
};
9399

94100
struct optee_session {
@@ -173,7 +179,9 @@ void optee_free_pages_list(void *array, size_t num_entries);
173179
void optee_fill_pages_list(u64 *dst, struct page **pages, int num_pages,
174180
size_t page_offset);
175181

176-
int optee_enumerate_devices(void);
182+
#define PTA_CMD_GET_DEVICES 0x0
183+
#define PTA_CMD_GET_DEVICES_SUPP 0x1
184+
int optee_enumerate_devices(u32 func);
177185

178186
/*
179187
* Small helpers

0 commit comments

Comments
 (0)