Introduce TEE bus driver framework
Subsystems (5)
v3 cover Introduce TEE bus driver framework
This series introduces a generic TEE bus driver concept for TEE based kernel drivers which would like to communicate with TEE based devices/ services.
Patch #1 adds TEE bus concept where devices/services are identified via Universally Unique Identifier (UUID) and drivers register a table of device UUIDs which they can support. This concept also allows for device enumeration to be specific to corresponding TEE implementation like OP-TEE etc.
Patch #2 adds supp_nowait flag for non-blocking requests arising via TEE internal client interface.
Patch #3 adds TEE bus device enumeration support for OP-TEE. OP-TEE provides a pseudo TA to enumerate TAs which can act as devices/services for TEE bus.
Patch #4 adds OP-TEE based hwrng driver which act as TEE bus driver. On ARM SoC's with TrustZone enabled, peripherals like entropy sources might not be accessible to normal world (linux in this case) and rather accessible to secure world (OP-TEE in this case) only. So this driver aims to provides a generic interface to OP-TEE based random number generator service.
Example case is Developerbox based on Socionext's Synquacer SoC [1] which provides 7 thermal sensors accessible from secure world only which could be used as entropy sources (thermal/measurement noise).
[1] https://www.96boards.org/product/developerbox/
Changes in v3:
1. Fixed bus error path in Patch #1.
2. Reversed order of Patch #2 and #3.
3. Fixed miscellaneous syntax comments and memory leak.
4. Added comments in Patch #2 for supp_nowait flag.
Changes in v2:
Based on review comments, the scope of this series has increased as follows:
1. Added TEE bus driver framework.
2. Added OP-TEE based device enumeration.
3. Register optee-rng driver as TEE bus driver.
4. Removed DT dependency for optee-rng device UUID.
5. Added supp_nowait flag.
Sumit Garg (4):
tee: add bus driver framework for TEE based devices
tee: add supp_nowait flag in tee_context struct
tee: optee: add TEE bus device enumeration support
hwrng: add OP-TEE based rng driver
MAINTAINERS | 5 + drivers/char/hw_random/Kconfig | 15 ++ drivers/char/hw_random/Makefile | 1 + drivers/char/hw_random/optee-rng.c | 272 +++++++++++++++++++++++++++++++++++++ drivers/tee/optee/Makefile | 1 + drivers/tee/optee/core.c | 4 + drivers/tee/optee/device.c | 153 +++++++++++++++++++++ drivers/tee/optee/optee_private.h | 3 + drivers/tee/optee/supp.c | 10 +- drivers/tee/tee_core.c | 56 +++++++- include/linux/tee_drv.h | 42 ++++++ 11 files changed, 558 insertions(+), 4 deletions(-) create mode 100644 drivers/char/hw_random/optee-rng.c create mode 100644 drivers/tee/optee/device.c
Signature · 1 line
2.7.4
PATCH v3 1/4 tee: add bus driver framework for TEE based devices
Introduce a generic TEE bus driver concept for TEE based kernel drivers which would like to communicate with TEE based devices/services.
In this TEE bus concept, devices/services are identified via Universally Unique Identifier (UUID) and drivers register a table of device UUIDs which they can support.
So this TEE bus framework registers a match() callback function which iterates over the driver UUID table to find a corresponding match for device UUID. If a match is found, then this particular device is probed via corresponding probe api registered by the driver. This process happens whenever a device or a driver is registered with TEE bus.
Also this framework allows for device enumeration to be specific to corresponding TEE implementation like OP-TEE etc.
--- drivers/tee/tee_core.c | 43 ++++++++++++++++++++++++++++++++++++++++--- include/linux/tee_drv.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 3 deletions(-)
drivers/tee/tee_core.c +40 -3
@@ -15,7 +15,6 @@#define pr_fmt (fmt) "%s: " fmt, __func__#include <linux/cdev.h> -#include <linux/device.h> #include <linux/fs.h> #include <linux/idr.h> #include <linux/module.h>
@@ -1027,6 +1026,30 @@ int tee_client_invoke_func(struct tee_context *ctx, }EXPORT_SYMBOL_GPL (tee_client_invoke_func); +static int tee_client_device_match (struct device *dev, +struct device_driver *drv) +{ +struct tee_client_device *tee_device; +const struct tee_client_device_id *id_table; + + tee_device =to_tee_client_device (dev); + id_table =to_tee_client_driver (drv)->id_table; + +while (!uuid_is_null (&id_table->uuid)) { +if (uuid_equal (&tee_device->id.uuid, &id_table->uuid)) +return 1 ; + id_table++; + } + +return 0 ; +} + +struct bus_type tee_bus_type = { + .name ="tee" , + .match = tee_client_device_match, +}; +EXPORT_SYMBOL_GPL (tee_bus_type); +static int __init tee_init (void ) {int rc;
@@ -1040,10 +1063,23 @@ static int __init tee_init(void) rc =alloc_chrdev_region (&tee_devt,0 ,TEE_NUM_DEVICES ,"tee" );if (rc) {pr_err ("failed to allocate char dev region\n" ); -class_destroy (tee_class); - tee_class =NULL ; + goto chrdev_err; } + rc =bus_register (&tee_bus_type); +if (rc) { +pr_err ("failed to register tee bus\n" ); + goto bus_err; + } + +return 0 ; + +bus_err: +unregister_chrdev_region (tee_devt,TEE_NUM_DEVICES ); +chrdev_err: +class_destroy (tee_class); + tee_class =NULL ; +return rc; }
@@ -1052,6 +1088,7 @@ static void __exit tee_exit(void)class_destroy (tee_class); tee_class =NULL ;unregister_chrdev_region (tee_devt,TEE_NUM_DEVICES ); +bus_unregister (&tee_bus_type); }subsys_initcall (tee_init);
include/linux/tee_drv.h +36 -0
@@ -20,6 +20,8 @@#include <linux/kref.h> #include <linux/list.h> #include <linux/tee.h> +#include <linux/device.h> +#include <linux/uuid.h> /* * The file describes the API provided by the generic TEE driver to the
@@ -538,4 +540,38 @@ static inline bool tee_param_is_memref(struct tee_param *param) } } +extern struct bus_type tee_bus_type; + +/** +* struct tee_client_device_id - tee based device identifier +* @uuid: For TEE based client devices we use the device uuid +* as the identifier. +*/ +struct tee_client_device_id { +uuid_t uuid; +}; + +/** +* struct tee_client_device - tee based device +* @id: device identifier +* @dev: device structure +*/ +struct tee_client_device { +struct tee_client_device_id id; +struct device dev; +}; +#define to_tee_client_device (d) container_of(d, struct tee_client_device, dev) + +/** +* struct tee_client_driver - tee client driver +* @id_table: device id table supported by this driver +* @driver: driver structure +*/ +struct tee_client_driver { +const struct tee_client_device_id *id_table; +struct device_driver driver; +}; +#define to_tee_client_driver (d) \ + container_of(d, struct tee_client_driver, driver) +#endif /*__TEE_DRV_H*/
Signature · 1 line
2.7.4
Re: [PATCH v3 1/4] tee: add bus driver framework for TEE based devices
Hi Sumit,
Thanks for the patch. Some nitpicks in-line:
Quoted 78 lines · Sumit Garg
Introduce a generic TEE bus driver concept for TEE based kernel drivers which would like to communicate with TEE based devices/services.
In this TEE bus concept, devices/services are identified via Universally Unique Identifier (UUID) and drivers register a table of device UUIDs which they can support.
So this TEE bus framework registers a
match()callback function which iterates over the driver UUID table to find a corresponding match for device UUID. If a match is found, then this particular device is probed via corresponding probe api registered by the driver. This process happens whenever a device or a driver is registered with TEE bus.Also this framework allows for device enumeration to be specific to corresponding TEE implementation like OP-TEE etc.
Signed-off-by Sumit Garg <[email protected]>--- drivers/tee/tee_core.c | 43 ++++++++++++++++++++++++++++++++++++++++--- include/linux/tee_drv.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 3 deletions(-)drivers/tee/tee_core.c +29
-3@@ -15,7 +15,6 @@#define pr_fmt (fmt) "%s: " fmt, __func__#include <linux/cdev.h> -#include <linux/device.h> #include <linux/fs.h> #include <linux/idr.h> #include <linux/module.h> @@ -1027,6 +1026,30 @@ int tee_client_invoke_func(struct tee_context *ctx, }EXPORT_SYMBOL_GPL (tee_client_invoke_func); +static int tee_client_device_match (struct device *dev, +struct device_driver *drv) +{ +struct tee_client_device *tee_device; +const struct tee_client_device_id *id_table; + + tee_device =to_tee_client_device (dev); + id_table =to_tee_client_driver (drv)->id_table; + +while (!uuid_is_null (&id_table->uuid)) { +if (uuid_equal (&tee_device->id.uuid, &id_table->uuid)) +return 1 ; + id_table++; + } + +return 0 ; +} + +struct bus_type tee_bus_type = { + .name ="tee" , + .match = tee_client_device_match, +}; +EXPORT_SYMBOL_GPL (tee_bus_type); +static int __init tee_init (void ) {int rc;@@ -1040,10 +1063,23 @@ static int __init tee_init(void) rc =alloc_chrdev_region (&tee_devt,0 ,TEE_NUM_DEVICES ,"tee" );if (rc) {pr_err ("failed to allocate char dev region\n" ); -class_destroy (tee_class); - tee_class =NULL ; + goto chrdev_err; } + rc =bus_register (&tee_bus_type); +if (rc) { +pr_err ("failed to register tee bus\n" ); + goto bus_err;
drivers/tee/tee_core.c static int __init tee_init(void) · line 1082
Quoted 10 lines
drivers/tee/tee_core.c +10
-0+ } + +return 0 ; + +bus_err: +unregister_chrdev_region (tee_devt,TEE_NUM_DEVICES ); +chrdev_err: +class_destroy (tee_class); + tee_class =NULL ; +
Hmm.. these error paths/labels look out-of-order.
See 'drivers/i2c/i2c-dev.c' for example.
Normally our error paths in an __init function is of the same order as the __exit function implementation. So this should be changed to something like:
+out_unreg_class: + class_destroy(tee_class); + tee_class = NULL; +out_unreg_chrdev: + unregister_chrdev_region(tee_devt, TEE_NUM_DEVICES);
drivers/tee/tee_core.c static void __exit tee_exit(void) · line 1091
Quoted 8 lines
drivers/tee/tee_core.c +1
-0return rc; }@@ -1052,6 +1088,7 @@ static void __exit tee_exit(void)class_destroy (tee_class); tee_class =NULL ;unregister_chrdev_region (tee_devt,TEE_NUM_DEVICES ); +bus_unregister (&tee_bus_type);
Since the __exit function order is the reverse of the __init one, lets reorder this as:
+ bus_unregister(&tee_bus_type);
class_destroy(tee_class);
tee_class = NULL; unregister_chrdev_region(tee_devt, TEE_NUM_DEVICES);
See 'drivers/i2c/i2c-dev.c' for example.
include/linux/tee_drv.h line 24
Quoted 13 lines
drivers/tee/tee_core.c +0
-0}subsys_initcall (tee_init);include/linux/tee_drv.h +2
-0@@ -20,6 +20,8 @@#include <linux/kref.h> #include <linux/list.h> #include <linux/tee.h> +#include <linux/device.h> +#include <linux/uuid.h>
If possible, let's keep alphabetical order of header files when making changes in the patch.
Quoted 7 lines
include/linux/tee_drv.h +0
-0/* * The file describes the API provided by the generic TEE driver to the @@ -538,4 +540,38 @@ static inline bool tee_param_is_memref(struct tee_param *param) } }
include/linux/tee_drv.h static inline bool tee_param_is_memref(struct tee_param *param) · line 552
Quoted 10 lines
include/linux/tee_drv.h +10
-0+extern struct bus_type tee_bus_type; + +/** +* struct tee_client_device_id - tee based device identifier +* @uuid: For TEE based client devices we use the device uuid +* as the identifier. +*/ +struct tee_client_device_id { +uuid_t uuid; +};
Hmm.. Do we really need a struct for a single element, rather lets use a simple typedef here.
include/linux/tee_drv.h static inline bool tee_param_is_memref(struct tee_param *param) · line 562
Quoted 10 lines
include/linux/tee_drv.h +10
-0+ +/** +* struct tee_client_device - tee based device +* @id: device identifier +* @dev: device structure +*/ +struct tee_client_device { +struct tee_client_device_id id; +struct device dev; +};
Add a blank line here.
include/linux/tee_drv.h static inline bool tee_param_is_memref(struct tee_param *param) · line 573
Quoted 11 lines
include/linux/tee_drv.h +11
-0+#define to_tee_client_device (d) container_of(d, struct tee_client_device, dev) + +/** +* struct tee_client_driver - tee client driver +* @id_table: device id table supported by this driver +* @driver: driver structure +*/ +struct tee_client_driver { +const struct tee_client_device_id *id_table; +struct device_driver driver; +};
Add a blank line here.
include/linux/tee_drv.h static inline bool tee_param_is_memref(struct tee_param *param) · line 577
Quoted 5 lines
include/linux/tee_drv.h +3
-0+#define to_tee_client_driver (d) \ + container_of(d, struct tee_client_driver, driver) +#endif /*__TEE_DRV_H*/
Thanks,
Bhupesh
Re: [PATCH v3 1/4] tee: add bus driver framework for TEE based devices
Quoted 5 lines · Bhupesh Sharma
Hi Sumit,
Thanks for the patch. Some nitpicks in-line:
Apologies for delay in my response as I was on leave. Please find my comments inline.
Will include these nitpicks in v4 but let me wait for any further major comments.
Quoted 97 lines · Sumit Garg
Quoted 78 lines
Introduce a generic TEE bus driver concept for TEE based kernel drivers which would like to communicate with TEE based devices/services.
In this TEE bus concept, devices/services are identified via Universally Unique Identifier (UUID) and drivers register a table of device UUIDs which they can support.
So this TEE bus framework registers a
match()callback function which iterates over the driver UUID table to find a corresponding match for device UUID. If a match is found, then this particular device is probed via corresponding probe api registered by the driver. This process happens whenever a device or a driver is registered with TEE bus.Also this framework allows for device enumeration to be specific to corresponding TEE implementation like OP-TEE etc.
Signed-off-by Sumit Garg <[email protected]>--- drivers/tee/tee_core.c | 43 ++++++++++++++++++++++++++++++++++++++++--- include/linux/tee_drv.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 3 deletions(-)drivers/tee/tee_core.c +29
-3@@ -15,7 +15,6 @@#define pr_fmt (fmt) "%s: " fmt, __func__#include <linux/cdev.h> -#include <linux/device.h> #include <linux/fs.h> #include <linux/idr.h> #include <linux/module.h> @@ -1027,6 +1026,30 @@ int tee_client_invoke_func(struct tee_context *ctx, }EXPORT_SYMBOL_GPL (tee_client_invoke_func); +static int tee_client_device_match (struct device *dev, +struct device_driver *drv) +{ +struct tee_client_device *tee_device; +const struct tee_client_device_id *id_table; + + tee_device =to_tee_client_device (dev); + id_table =to_tee_client_driver (drv)->id_table; + +while (!uuid_is_null (&id_table->uuid)) { +if (uuid_equal (&tee_device->id.uuid, &id_table->uuid)) +return 1 ; + id_table++; + } + +return 0 ; +} + +struct bus_type tee_bus_type = { + .name ="tee" , + .match = tee_client_device_match, +}; +EXPORT_SYMBOL_GPL (tee_bus_type); +static int __init tee_init (void ) {int rc;@@ -1040,10 +1063,23 @@ static int __init tee_init(void) rc =alloc_chrdev_region (&tee_devt,0 ,TEE_NUM_DEVICES ,"tee" );if (rc) {pr_err ("failed to allocate char dev region\n" ); -class_destroy (tee_class); - tee_class =NULL ; + goto chrdev_err; } + rc =bus_register (&tee_bus_type); +if (rc) { +pr_err ("failed to register tee bus\n" ); + goto bus_err;drivers/tee/tee_core.c static int __init tee_init(void) · line 1082
Quoted 10 lines
drivers/tee/tee_core.c +10
-0+ } + +return 0 ; + +bus_err: +unregister_chrdev_region (tee_devt,TEE_NUM_DEVICES ); +chrdev_err: +class_destroy (tee_class); + tee_class =NULL ; +Hmm.. these error paths/labels look out-of-order.
See 'drivers/i2c/i2c-dev.c' for example.Normally our error paths in an
__initfunction is of the same order as the__exitfunction implementation. So this should be changed to something like:
Quoted 6 lines
+out_unreg_class:
+class_destroy(tee_class);
+tee_class= NULL;
+out_unreg_chrdev:
+unregister_chrdev_region(tee_devt, TEE_NUM_DEVICES);
It seems that prior to this patch also allocation order in __init function differed from release order in __exit function. Will correct that too along with this.
Quoted 12 lines
drivers/tee/tee_core.c static void __exit tee_exit(void) · line 1091
Quoted 8 lines
drivers/tee/tee_core.c +1
-0return rc; }@@ -1052,6 +1088,7 @@ static void __exit tee_exit(void)class_destroy (tee_class); tee_class =NULL ;unregister_chrdev_region (tee_devt,TEE_NUM_DEVICES ); +bus_unregister (&tee_bus_type);Since the
__exitfunction order is the reverse of the__initone, lets reorder this as:
Quoted 5 lines
+ bus_unregister(&tee_bus_type);
class_destroy(tee_class);
tee_class = NULL;
unregister_chrdev_region(tee_devt, TEE_NUM_DEVICES);Ok.
Quoted 4 lines
See '
drivers/i2c/i2c-dev.c' for example.Quoted 2 lines
drivers/tee/tee_core.c +0
-0}
Quoted 15 lines
include/linux/tee_drv.h line 24
Quoted 11 lines
drivers/tee/tee_core.c +0
-0subsys_initcall (tee_init);include/linux/tee_drv.h +2
-0@@ -20,6 +20,8 @@#include <linux/kref.h> #include <linux/list.h> #include <linux/tee.h> +#include <linux/device.h> +#include <linux/uuid.h> If possible, let's keep alphabetical order of header files when making changes in the patch.
Ok.
Quoted 7 lines
Quoted 7 lines
include/linux/tee_drv.h +0
-0/* * The file describes the API provided by the generic TEE driver to the @@ -538,4 +540,38 @@ static inline bool tee_param_is_memref(struct tee_param *param) } }
Quoted 14 lines
include/linux/tee_drv.h static inline bool tee_param_is_memref(struct tee_param *param) · line 552
Quoted 10 lines
include/linux/tee_drv.h +10
-0+extern struct bus_type tee_bus_type; + +/** +* struct tee_client_device_id - tee based device identifier +* @uuid: For TEE based client devices we use the device uuid +* as the identifier. +*/ +struct tee_client_device_id { +uuid_t uuid; +};Hmm.. Do we really need a struct for a single element, rather lets use a simple typedef here.
Agree, will rather use typedef here.
Quoted 4 lines
Quoted 4 lines
include/linux/tee_drv.h +4
-0+ +/** +* struct tee_client_device - tee based device +* @id: device identifier
Quoted 9 lines
include/linux/tee_drv.h static inline bool tee_param_is_memref(struct tee_param *param) · line 562
Quoted 6 lines
include/linux/tee_drv.h +6
-0+* @dev: device structure +*/ +struct tee_client_device { +struct tee_client_device_id id; +struct device dev; +};Add a blank line here.
Ok.
Quoted 5 lines
Quoted 5 lines
include/linux/tee_drv.h +5
-0+#define to_tee_client_device (d) container_of(d, struct tee_client_device, dev) + +/** +* struct tee_client_driver - tee client driver +* @id_table: device id table supported by this driver
Quoted 8 lines
include/linux/tee_drv.h static inline bool tee_param_is_memref(struct tee_param *param) · line 573
Quoted 6 lines
include/linux/tee_drv.h +6
-0+* @driver: driver structure +*/ +struct tee_client_driver { +const struct tee_client_device_id *id_table; +struct device_driver driver; +};Add a blank line here.
Ok.
-Sumit
Quoted 8 lines
include/linux/tee_drv.h static inline bool tee_param_is_memref(struct tee_param *param) · line 577
Quoted 5 lines
include/linux/tee_drv.h +3
-0+#define to_tee_client_driver (d) \ + container_of(d, struct tee_client_driver, driver) +#endif /*__TEE_DRV_H*/ Thanks,
Bhupesh
PATCH v3 2/4 tee: add supp_nowait flag in tee_context struct
In reply to Sumit GargThis flag indicates that requests in this context should not wait for tee-supplicant daemon to be started if not present and just return with an error code. It is needed for requests which should be non-blocking in nature like ones arising from TEE based kernel drivers or any in kernel api that uses TEE internal client interface.
--- drivers/tee/optee/supp.c | 10 +++++++++- drivers/tee/tee_core.c | 13 +++++++++++++ include/linux/tee_drv.h | 6 ++++++ 3 files changed, 28 insertions(+), 1 deletion(-)
drivers/tee/optee/supp.c +9 -1
@@ -88,10 +88,18 @@ u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params, {struct optee *optee =tee_get_drvdata (ctx->teedev);struct optee_supp *supp = &optee->supp; -struct optee_supp_req *req =kzalloc (sizeof (*req),GFP_KERNEL ); +struct optee_supp_req *req;bool interruptable;u32 ret; +/* +* Return in case there is no supplicant available and +* non-blocking request. +*/ +if (!supp->ctx && ctx->supp_nowait) +return TEEC_ERROR_COMMUNICATION ; + + req =kzalloc (sizeof (*req),GFP_KERNEL );if (!req)return TEEC_ERROR_OUT_OF_MEMORY ;
drivers/tee/tee_core.c +13 -0
@@ -105,6 +105,11 @@ static int tee_open(struct inode *inode, struct file *filp)if (IS_ERR (ctx))return PTR_ERR (ctx); +/* +* Default user-space behaviour is to wait for tee-supplicant +* if not present for any requests in this context. +*/ + ctx->supp_nowait = false; filp->private_data = ctx;return 0 ; }
@@ -981,6 +986,14 @@ tee_client_open_context(struct tee_context *start, }while (IS_ERR (ctx) &&PTR_ERR (ctx) != -ENOMEM );put_device (put_dev); +/* +* Default behaviour for in kernel client is to not wait for +* tee-supplicant if not present for any requests in this context. +* Also this flag could be configured again before call to +* tee_client_open_session() if any in kernel client requires +* different behaviour. +*/ + ctx->supp_nowait = true;return ctx; }EXPORT_SYMBOL_GPL (tee_client_open_context);
include/linux/tee_drv.h +6 -0
@@ -49,6 +49,11 @@ struct tee_shm_pool;* @releasing: flag that indicates if context is being released right now. * It is needed to break circular dependency on context during * shared memory release. +* @supp_nowait: flag that indicates that requests in this context should not +* wait for tee-supplicant daemon to be started if not present +* and just return with an error code. It is needed for requests +* that arises from TEE based kernel drivers that should be +* non-blocking in nature. */ struct tee_context {struct tee_device *teedev;
@@ -56,6 +61,7 @@ struct tee_context {void *data;struct kref refcount;bool releasing; +bool supp_nowait; };struct tee_param_memref {
Signature · 1 line
2.7.4
PATCH v3 3/4 tee: optee: add TEE bus device enumeration support
In reply to Sumit GargOP-TEE provides a pseudo TA to enumerate TAs which can act as devices/ services for TEE bus. So implement device enumeration using invoke
function: PTA_CMD_GET_DEVICES provided by pseudo TA to fetch array of device UUIDs. Also register these enumerated devices with TEE bus as "optee-clntX" device.
--- drivers/tee/optee/Makefile | 1 + drivers/tee/optee/core.c | 4 + drivers/tee/optee/device.c | 153 ++++++++++++++++++++++++++++++++++++++ drivers/tee/optee/optee_private.h | 3 + 4 files changed, 161 insertions(+) create mode 100644 drivers/tee/optee/device.c
drivers/tee/optee/Makefile +1 -0
@@ -5,3 +5,4 @@ optee-objs += call.o optee-objs += rpc.o optee-objs += supp.o optee-objs += shm_pool.o +optee-objs += device.o
drivers/tee/optee/core.c +4 -0
@@ -634,6 +634,10 @@ static struct optee *optee_probe(struct device_node *np)if (optee->sec_caps &OPTEE_SMC_SEC_CAP_DYNAMIC_SHM )pr_info ("dynamic shared memory is enabled\n" ); + rc =optee_enumerate_devices (); +if (rc) + goto err; +pr_info ("initialized driver\n" );return optee; err:
drivers/tee/optee/device.c new file +153 -0
153 lines not on this page · raw message
drivers/tee/optee/optee_private.h +3 -0
@@ -28,6 +28,7 @@#define TEEC_ERROR_BAD_PARAMETERS 0xFFFF0006#define TEEC_ERROR_COMMUNICATION 0xFFFF000E#define TEEC_ERROR_OUT_OF_MEMORY 0xFFFF000C +#define TEEC_ERROR_SHORT_BUFFER 0xFFFF0010#define TEEC_ORIGIN_COMMS 0x00000002
@@ -181,6 +182,8 @@ void optee_free_pages_list(void *array, size_t num_entries);void optee_fill_pages_list (u64 *dst,struct page **pages,int num_pages,size_t page_offset); +int optee_enumerate_devices (void ); +/* * Small helpers */
Signature · 1 line
2.7.4
PATCH v3 4/4 hwrng: add OP-TEE based rng driver
In reply to Sumit GargOn ARM SoC's with TrustZone enabled, peripherals like entropy sources might not be accessible to normal world (linux in this case) and rather accessible to secure world (OP-TEE in this case) only. So this driver aims to provides a generic interface to OP-TEE based random number generator service.
This driver registers on TEE bus to interact with OP-TEE based rng device/service.
--- MAINTAINERS | 5 + drivers/char/hw_random/Kconfig | 15 ++ drivers/char/hw_random/Makefile | 1 + drivers/char/hw_random/optee-rng.c | 272 +++++++++++++++++++++++++++++++++++++ 4 files changed, 293 insertions(+) create mode 100644 drivers/char/hw_random/optee-rng.c
MAINTAINERS +5 -0
@@ -11260,6 +11260,11 @@ M: Jens Wiklander <[email protected]> S: Maintained F: drivers/tee/optee/ +OP-TEE RANDOM NUMBER GENERATOR (RNG) DRIVER +M: Sumit Garg <[email protected]> +S: Maintained +F: drivers/char/hw_random/optee-rng.c + OPA-VNIC DRIVER M: Dennis Dalessandro <[email protected]> M: Niranjana Vishwanathapura <[email protected]>
drivers/char/hw_random/Kconfig +15 -0
@@ -424,6 +424,21 @@ config HW_RANDOM_EXYNOS will be called exynos-trng. If unsure, say Y. + +config HW_RANDOM_OPTEE + tristate "OP-TEE based Random Number Generator support" + depends on OPTEE + default HW_RANDOM + help + This driver provides support for OP-TEE based Random Number + Generator on ARM SoCs where hardware entropy sources are not + accessible to normal world (Linux). + + To compile this driver as a module, choose M here: the module + will be called optee-rng. + + If unsure, say Y. + endif # HW_RANDOM config UML_RANDOM
drivers/char/hw_random/Makefile +1 -0
@@ -38,3 +38,4 @@ obj-$(CONFIG_HW_RANDOM_CAVIUM) += cavium-rng.o cavium-rng-vf.o obj-$(CONFIG_HW_RANDOM_MTK) += mtk-rng.o obj-$(CONFIG_HW_RANDOM_S390) += s390-trng.o obj-$(CONFIG_HW_RANDOM_KEYSTONE) += ks-sa-rng.o +obj-$(CONFIG_HW_RANDOM_OPTEE) += optee-rng.o
drivers/char/hw_random/optee-rng.c new file +272 -0
272 lines not on this page · raw message
Signature · 1 line
2.7.4