Skip to content

Commit 38d9dff

Browse files
committed
Merge tag 'optee-bus-for-v5.9' of git://git.linaro.org/people/jens.wiklander/linux-tee into arm/drivers
Enable multi-stage OP-TEE bus enumeration Probes drivers on the OP-TEE bus in two steps. First for drivers which do not depend on tee-supplicant. After tee-supplicant has been started probe the devices which do depend on tee-supplicant. Also introduces driver which uses an OP-TEE based fTPM Trusted Application depends on tee-supplicant NV RAM implementation based on RPMB secure storage. * tag 'optee-bus-for-v5.9' of git://git.linaro.org/people/jens.wiklander/linux-tee: tpm_ftpm_tee: register driver on TEE bus optee: enable support for multi-stage bus enumeration optee: use uuid for sysfs driver entry Link: https://lore.kernel.org/r/20200710085230.GA1312913@jade Signed-off-by: Arnd Bergmann <[email protected]>
2 parents 86aa160 + 9f1944c commit 38d9dff

File tree

6 files changed

+119
-35
lines changed

6 files changed

+119
-35
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
What: /sys/bus/tee/devices/optee-ta-<uuid>/
2+
Date: May 2020
3+
KernelVersion 5.8
4+
5+
Description:
6+
OP-TEE bus provides reference to registered drivers under this directory. The <uuid>
7+
matches Trusted Application (TA) driver and corresponding TA in secure OS. Drivers
8+
are free to create needed API under optee-ta-<uuid> directory.

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12697,6 +12697,7 @@ OP-TEE DRIVER
1269712697
M: Jens Wiklander <[email protected]>
1269812698
1269912699
S: Maintained
12700+
F: Documentation/ABI/testing/sysfs-bus-optee-devices
1270012701
F: drivers/tee/optee/
1270112702

1270212703
OP-TEE RANDOM NUMBER GENERATOR (RNG) DRIVER

drivers/char/tpm/tpm_ftpm_tee.c

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,10 @@ static int ftpm_tee_match(struct tee_ioctl_version_data *ver, const void *data)
214214
* Return:
215215
* On success, 0. On failure, -errno.
216216
*/
217-
static int ftpm_tee_probe(struct platform_device *pdev)
217+
static int ftpm_tee_probe(struct device *dev)
218218
{
219219
int rc;
220220
struct tpm_chip *chip;
221-
struct device *dev = &pdev->dev;
222221
struct ftpm_tee_private *pvt_data = NULL;
223222
struct tee_ioctl_open_session_arg sess_arg;
224223

@@ -297,16 +296,23 @@ static int ftpm_tee_probe(struct platform_device *pdev)
297296
return rc;
298297
}
299298

299+
static int ftpm_plat_tee_probe(struct platform_device *pdev)
300+
{
301+
struct device *dev = &pdev->dev;
302+
303+
return ftpm_tee_probe(dev);
304+
}
305+
300306
/**
301307
* ftpm_tee_remove() - remove the TPM device
302308
* @pdev: the platform_device description.
303309
*
304310
* Return:
305311
* 0 always.
306312
*/
307-
static int ftpm_tee_remove(struct platform_device *pdev)
313+
static int ftpm_tee_remove(struct device *dev)
308314
{
309-
struct ftpm_tee_private *pvt_data = dev_get_drvdata(&pdev->dev);
315+
struct ftpm_tee_private *pvt_data = dev_get_drvdata(dev);
310316

311317
/* Release the chip */
312318
tpm_chip_unregister(pvt_data->chip);
@@ -328,11 +334,18 @@ static int ftpm_tee_remove(struct platform_device *pdev)
328334
return 0;
329335
}
330336

337+
static int ftpm_plat_tee_remove(struct platform_device *pdev)
338+
{
339+
struct device *dev = &pdev->dev;
340+
341+
return ftpm_tee_remove(dev);
342+
}
343+
331344
/**
332345
* ftpm_tee_shutdown() - shutdown the TPM device
333346
* @pdev: the platform_device description.
334347
*/
335-
static void ftpm_tee_shutdown(struct platform_device *pdev)
348+
static void ftpm_plat_tee_shutdown(struct platform_device *pdev)
336349
{
337350
struct ftpm_tee_private *pvt_data = dev_get_drvdata(&pdev->dev);
338351

@@ -347,17 +360,54 @@ static const struct of_device_id of_ftpm_tee_ids[] = {
347360
};
348361
MODULE_DEVICE_TABLE(of, of_ftpm_tee_ids);
349362

350-
static struct platform_driver ftpm_tee_driver = {
363+
static struct platform_driver ftpm_tee_plat_driver = {
351364
.driver = {
352365
.name = "ftpm-tee",
353366
.of_match_table = of_match_ptr(of_ftpm_tee_ids),
354367
},
355-
.probe = ftpm_tee_probe,
356-
.remove = ftpm_tee_remove,
357-
.shutdown = ftpm_tee_shutdown,
368+
.shutdown = ftpm_plat_tee_shutdown,
369+
.probe = ftpm_plat_tee_probe,
370+
.remove = ftpm_plat_tee_remove,
371+
};
372+
373+
/* UUID of the fTPM TA */
374+
static const struct tee_client_device_id optee_ftpm_id_table[] = {
375+
{UUID_INIT(0xbc50d971, 0xd4c9, 0x42c4,
376+
0x82, 0xcb, 0x34, 0x3f, 0xb7, 0xf3, 0x78, 0x96)},
377+
{}
358378
};
359379

360-
module_platform_driver(ftpm_tee_driver);
380+
MODULE_DEVICE_TABLE(tee, optee_ftpm_id_table);
381+
382+
static struct tee_client_driver ftpm_tee_driver = {
383+
.id_table = optee_ftpm_id_table,
384+
.driver = {
385+
.name = "optee-ftpm",
386+
.bus = &tee_bus_type,
387+
.probe = ftpm_tee_probe,
388+
.remove = ftpm_tee_remove,
389+
},
390+
};
391+
392+
static int __init ftpm_mod_init(void)
393+
{
394+
int rc;
395+
396+
rc = platform_driver_register(&ftpm_tee_plat_driver);
397+
if (rc)
398+
return rc;
399+
400+
return driver_register(&ftpm_tee_driver.driver);
401+
}
402+
403+
static void __exit ftpm_mod_exit(void)
404+
{
405+
platform_driver_unregister(&ftpm_tee_plat_driver);
406+
driver_unregister(&ftpm_tee_driver.driver);
407+
}
408+
409+
module_init(ftpm_mod_init);
410+
module_exit(ftpm_mod_exit);
361411

362412
MODULE_AUTHOR("Thirupathaiah Annapureddy <[email protected]>");
363413
MODULE_DESCRIPTION("TPM Driver for fTPM TA in TEE");

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: 17 additions & 21 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

@@ -65,7 +53,7 @@ static int get_devices(struct tee_context *ctx, u32 session,
6553
return 0;
6654
}
6755

68-
static int optee_register_device(const uuid_t *device_uuid, u32 device_id)
56+
static int optee_register_device(const uuid_t *device_uuid)
6957
{
7058
struct tee_client_device *optee_device = NULL;
7159
int rc;
@@ -75,7 +63,10 @@ static int optee_register_device(const uuid_t *device_uuid, u32 device_id)
7563
return -ENOMEM;
7664

7765
optee_device->dev.bus = &tee_bus_type;
78-
dev_set_name(&optee_device->dev, "optee-clnt%u", device_id);
66+
if (dev_set_name(&optee_device->dev, "optee-ta-%pUb", device_uuid)) {
67+
kfree(optee_device);
68+
return -ENOMEM;
69+
}
7970
uuid_copy(&optee_device->id.uuid, device_uuid);
8071

8172
rc = device_register(&optee_device->dev);
@@ -87,7 +78,7 @@ static int optee_register_device(const uuid_t *device_uuid, u32 device_id)
8778
return rc;
8879
}
8980

90-
int optee_enumerate_devices(void)
81+
static int __optee_enumerate_devices(u32 func)
9182
{
9283
const uuid_t pta_uuid =
9384
UUID_INIT(0x7011a688, 0xddde, 0x4053,
@@ -118,7 +109,7 @@ int optee_enumerate_devices(void)
118109
goto out_ctx;
119110
}
120111

121-
rc = get_devices(ctx, sess_arg.session, NULL, &shm_size);
112+
rc = get_devices(ctx, sess_arg.session, NULL, &shm_size, func);
122113
if (rc < 0 || !shm_size)
123114
goto out_sess;
124115

@@ -130,7 +121,7 @@ int optee_enumerate_devices(void)
130121
goto out_sess;
131122
}
132123

133-
rc = get_devices(ctx, sess_arg.session, device_shm, &shm_size);
124+
rc = get_devices(ctx, sess_arg.session, device_shm, &shm_size, func);
134125
if (rc < 0)
135126
goto out_shm;
136127

@@ -144,7 +135,7 @@ int optee_enumerate_devices(void)
144135
num_devices = shm_size / sizeof(uuid_t);
145136

146137
for (idx = 0; idx < num_devices; idx++) {
147-
rc = optee_register_device(&device_uuid[idx], idx);
138+
rc = optee_register_device(&device_uuid[idx]);
148139
if (rc)
149140
goto out_shm;
150141
}
@@ -158,3 +149,8 @@ int optee_enumerate_devices(void)
158149

159150
return rc;
160151
}
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)