2 * Copyright (c) 2015-2016, Linaro Limited
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
15 #define pr_fmt(fmt) "%s: " fmt, __func__
17 #include <linux/cdev.h>
18 #include <linux/device.h>
20 #include <linux/idr.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/tee_drv.h>
24 #include <linux/uaccess.h>
25 #include "tee_private.h"
27 #define TEE_NUM_DEVICES 32
29 #define TEE_IOCTL_PARAM_SIZE(x) (sizeof(struct tee_param) * (x))
32 * Unprivileged devices in the lower half range and privileged devices in
33 * the upper half range.
35 static DECLARE_BITMAP(dev_mask, TEE_NUM_DEVICES);
36 static DEFINE_SPINLOCK(driver_lock);
38 static struct class *tee_class;
39 static dev_t tee_devt;
41 static int tee_open(struct inode *inode, struct file *filp)
44 struct tee_device *teedev;
45 struct tee_context *ctx;
47 teedev = container_of(inode->i_cdev, struct tee_device, cdev);
48 if (!tee_device_get(teedev))
51 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
57 kref_init(&ctx->refcount);
59 INIT_LIST_HEAD(&ctx->list_shm);
60 filp->private_data = ctx;
61 rc = teedev->desc->ops->open(ctx);
68 tee_device_put(teedev);
72 void teedev_ctx_get(struct tee_context *ctx)
77 kref_get(&ctx->refcount);
80 static void teedev_ctx_release(struct kref *ref)
82 struct tee_context *ctx = container_of(ref, struct tee_context,
84 ctx->releasing = true;
85 ctx->teedev->desc->ops->release(ctx);
89 void teedev_ctx_put(struct tee_context *ctx)
94 kref_put(&ctx->refcount, teedev_ctx_release);
97 static void teedev_close_context(struct tee_context *ctx)
99 struct tee_device *teedev = ctx->teedev;
102 tee_device_put(teedev);
105 static int tee_release(struct inode *inode, struct file *filp)
107 teedev_close_context(filp->private_data);
111 static int tee_ioctl_version(struct tee_context *ctx,
112 struct tee_ioctl_version_data __user *uvers)
114 struct tee_ioctl_version_data vers;
116 ctx->teedev->desc->ops->get_version(ctx->teedev, &vers);
118 if (ctx->teedev->desc->flags & TEE_DESC_PRIVILEGED)
119 vers.gen_caps |= TEE_GEN_CAP_PRIVILEGED;
121 if (copy_to_user(uvers, &vers, sizeof(vers)))
127 static int tee_ioctl_shm_alloc(struct tee_context *ctx,
128 struct tee_ioctl_shm_alloc_data __user *udata)
131 struct tee_ioctl_shm_alloc_data data;
134 if (copy_from_user(&data, udata, sizeof(data)))
137 /* Currently no input flags are supported */
141 shm = tee_shm_alloc(ctx, data.size, TEE_SHM_MAPPED | TEE_SHM_DMA_BUF);
146 data.flags = shm->flags;
147 data.size = shm->size;
149 if (copy_to_user(udata, &data, sizeof(data)))
152 ret = tee_shm_get_fd(shm);
155 * When user space closes the file descriptor the shared memory
156 * should be freed or if tee_shm_get_fd() failed then it will
157 * be freed immediately.
164 tee_ioctl_shm_register(struct tee_context *ctx,
165 struct tee_ioctl_shm_register_data __user *udata)
168 struct tee_ioctl_shm_register_data data;
171 if (copy_from_user(&data, udata, sizeof(data)))
174 /* Currently no input flags are supported */
178 shm = tee_shm_register(ctx, data.addr, data.length,
179 TEE_SHM_DMA_BUF | TEE_SHM_USER_MAPPED);
184 data.flags = shm->flags;
185 data.length = shm->size;
187 if (copy_to_user(udata, &data, sizeof(data)))
190 ret = tee_shm_get_fd(shm);
192 * When user space closes the file descriptor the shared memory
193 * should be freed or if tee_shm_get_fd() failed then it will
194 * be freed immediately.
200 static int params_from_user(struct tee_context *ctx, struct tee_param *params,
202 struct tee_ioctl_param __user *uparams)
206 for (n = 0; n < num_params; n++) {
208 struct tee_ioctl_param ip;
210 if (copy_from_user(&ip, uparams + n, sizeof(ip)))
213 /* All unused attribute bits has to be zero */
214 if (ip.attr & ~TEE_IOCTL_PARAM_ATTR_MASK)
217 params[n].attr = ip.attr;
218 switch (ip.attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK) {
219 case TEE_IOCTL_PARAM_ATTR_TYPE_NONE:
220 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT:
222 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT:
223 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT:
224 params[n].u.value.a = ip.a;
225 params[n].u.value.b = ip.b;
226 params[n].u.value.c = ip.c;
228 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT:
229 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT:
230 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT:
232 * If we fail to get a pointer to a shared memory
233 * object (and increase the ref count) from an
234 * identifier we return an error. All pointers that
235 * has been added in params have an increased ref
236 * count. It's the callers responibility to do
237 * tee_shm_put() on all resolved pointers.
239 shm = tee_shm_get_from_id(ctx, ip.c);
244 * Ensure offset + size does not overflow offset
245 * and does not overflow the size of the referred
246 * shared memory object.
248 if ((ip.a + ip.b) < ip.a ||
249 (ip.a + ip.b) > shm->size) {
254 params[n].u.memref.shm_offs = ip.a;
255 params[n].u.memref.size = ip.b;
256 params[n].u.memref.shm = shm;
259 /* Unknown attribute */
266 static int params_to_user(struct tee_ioctl_param __user *uparams,
267 size_t num_params, struct tee_param *params)
271 for (n = 0; n < num_params; n++) {
272 struct tee_ioctl_param __user *up = uparams + n;
273 struct tee_param *p = params + n;
276 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT:
277 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT:
278 if (put_user(p->u.value.a, &up->a) ||
279 put_user(p->u.value.b, &up->b) ||
280 put_user(p->u.value.c, &up->c))
283 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT:
284 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT:
285 if (put_user((u64)p->u.memref.size, &up->b))
294 static int tee_ioctl_open_session(struct tee_context *ctx,
295 struct tee_ioctl_buf_data __user *ubuf)
299 struct tee_ioctl_buf_data buf;
300 struct tee_ioctl_open_session_arg __user *uarg;
301 struct tee_ioctl_open_session_arg arg;
302 struct tee_ioctl_param __user *uparams = NULL;
303 struct tee_param *params = NULL;
304 bool have_session = false;
306 if (!ctx->teedev->desc->ops->open_session)
309 if (copy_from_user(&buf, ubuf, sizeof(buf)))
312 if (buf.buf_len > TEE_MAX_ARG_SIZE ||
313 buf.buf_len < sizeof(struct tee_ioctl_open_session_arg))
316 uarg = u64_to_user_ptr(buf.buf_ptr);
317 if (copy_from_user(&arg, uarg, sizeof(arg)))
320 if (sizeof(arg) + TEE_IOCTL_PARAM_SIZE(arg.num_params) != buf.buf_len)
323 if (arg.num_params) {
324 params = kcalloc(arg.num_params, sizeof(struct tee_param),
328 uparams = uarg->params;
329 rc = params_from_user(ctx, params, arg.num_params, uparams);
334 rc = ctx->teedev->desc->ops->open_session(ctx, &arg, params);
339 if (put_user(arg.session, &uarg->session) ||
340 put_user(arg.ret, &uarg->ret) ||
341 put_user(arg.ret_origin, &uarg->ret_origin)) {
345 rc = params_to_user(uparams, arg.num_params, params);
348 * If we've succeeded to open the session but failed to communicate
349 * it back to user space, close the session again to avoid leakage.
351 if (rc && have_session && ctx->teedev->desc->ops->close_session)
352 ctx->teedev->desc->ops->close_session(ctx, arg.session);
355 /* Decrease ref count for all valid shared memory pointers */
356 for (n = 0; n < arg.num_params; n++)
357 if (tee_param_is_memref(params + n) &&
358 params[n].u.memref.shm)
359 tee_shm_put(params[n].u.memref.shm);
366 static int tee_ioctl_invoke(struct tee_context *ctx,
367 struct tee_ioctl_buf_data __user *ubuf)
371 struct tee_ioctl_buf_data buf;
372 struct tee_ioctl_invoke_arg __user *uarg;
373 struct tee_ioctl_invoke_arg arg;
374 struct tee_ioctl_param __user *uparams = NULL;
375 struct tee_param *params = NULL;
377 if (!ctx->teedev->desc->ops->invoke_func)
380 if (copy_from_user(&buf, ubuf, sizeof(buf)))
383 if (buf.buf_len > TEE_MAX_ARG_SIZE ||
384 buf.buf_len < sizeof(struct tee_ioctl_invoke_arg))
387 uarg = u64_to_user_ptr(buf.buf_ptr);
388 if (copy_from_user(&arg, uarg, sizeof(arg)))
391 if (sizeof(arg) + TEE_IOCTL_PARAM_SIZE(arg.num_params) != buf.buf_len)
394 if (arg.num_params) {
395 params = kcalloc(arg.num_params, sizeof(struct tee_param),
399 uparams = uarg->params;
400 rc = params_from_user(ctx, params, arg.num_params, uparams);
405 rc = ctx->teedev->desc->ops->invoke_func(ctx, &arg, params);
409 if (put_user(arg.ret, &uarg->ret) ||
410 put_user(arg.ret_origin, &uarg->ret_origin)) {
414 rc = params_to_user(uparams, arg.num_params, params);
417 /* Decrease ref count for all valid shared memory pointers */
418 for (n = 0; n < arg.num_params; n++)
419 if (tee_param_is_memref(params + n) &&
420 params[n].u.memref.shm)
421 tee_shm_put(params[n].u.memref.shm);
427 static int tee_ioctl_cancel(struct tee_context *ctx,
428 struct tee_ioctl_cancel_arg __user *uarg)
430 struct tee_ioctl_cancel_arg arg;
432 if (!ctx->teedev->desc->ops->cancel_req)
435 if (copy_from_user(&arg, uarg, sizeof(arg)))
438 return ctx->teedev->desc->ops->cancel_req(ctx, arg.cancel_id,
443 tee_ioctl_close_session(struct tee_context *ctx,
444 struct tee_ioctl_close_session_arg __user *uarg)
446 struct tee_ioctl_close_session_arg arg;
448 if (!ctx->teedev->desc->ops->close_session)
451 if (copy_from_user(&arg, uarg, sizeof(arg)))
454 return ctx->teedev->desc->ops->close_session(ctx, arg.session);
457 static int params_to_supp(struct tee_context *ctx,
458 struct tee_ioctl_param __user *uparams,
459 size_t num_params, struct tee_param *params)
463 for (n = 0; n < num_params; n++) {
464 struct tee_ioctl_param ip;
465 struct tee_param *p = params + n;
468 switch (p->attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK) {
469 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT:
470 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT:
475 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT:
476 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT:
477 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT:
478 ip.b = p->u.memref.size;
479 if (!p->u.memref.shm) {
481 ip.c = (u64)-1; /* invalid shm id */
484 ip.a = p->u.memref.shm_offs;
485 ip.c = p->u.memref.shm->id;
494 if (copy_to_user(uparams + n, &ip, sizeof(ip)))
501 static int tee_ioctl_supp_recv(struct tee_context *ctx,
502 struct tee_ioctl_buf_data __user *ubuf)
505 struct tee_ioctl_buf_data buf;
506 struct tee_iocl_supp_recv_arg __user *uarg;
507 struct tee_param *params;
511 if (!ctx->teedev->desc->ops->supp_recv)
514 if (copy_from_user(&buf, ubuf, sizeof(buf)))
517 if (buf.buf_len > TEE_MAX_ARG_SIZE ||
518 buf.buf_len < sizeof(struct tee_iocl_supp_recv_arg))
521 uarg = u64_to_user_ptr(buf.buf_ptr);
522 if (get_user(num_params, &uarg->num_params))
525 if (sizeof(*uarg) + TEE_IOCTL_PARAM_SIZE(num_params) != buf.buf_len)
528 params = kcalloc(num_params, sizeof(struct tee_param), GFP_KERNEL);
532 rc = params_from_user(ctx, params, num_params, uarg->params);
536 rc = ctx->teedev->desc->ops->supp_recv(ctx, &func, &num_params, params);
540 if (put_user(func, &uarg->func) ||
541 put_user(num_params, &uarg->num_params)) {
546 rc = params_to_supp(ctx, uarg->params, num_params, params);
552 static int params_from_supp(struct tee_param *params, size_t num_params,
553 struct tee_ioctl_param __user *uparams)
557 for (n = 0; n < num_params; n++) {
558 struct tee_param *p = params + n;
559 struct tee_ioctl_param ip;
561 if (copy_from_user(&ip, uparams + n, sizeof(ip)))
564 /* All unused attribute bits has to be zero */
565 if (ip.attr & ~TEE_IOCTL_PARAM_ATTR_MASK)
569 switch (ip.attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK) {
570 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT:
571 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT:
572 /* Only out and in/out values can be updated */
577 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT:
578 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT:
580 * Only the size of the memref can be updated.
581 * Since we don't have access to the original
582 * parameters here, only store the supplied size.
583 * The driver will copy the updated size into the
584 * original parameters.
586 p->u.memref.shm = NULL;
587 p->u.memref.shm_offs = 0;
588 p->u.memref.size = ip.b;
591 memset(&p->u, 0, sizeof(p->u));
598 static int tee_ioctl_supp_send(struct tee_context *ctx,
599 struct tee_ioctl_buf_data __user *ubuf)
602 struct tee_ioctl_buf_data buf;
603 struct tee_iocl_supp_send_arg __user *uarg;
604 struct tee_param *params;
608 /* Not valid for this driver */
609 if (!ctx->teedev->desc->ops->supp_send)
612 if (copy_from_user(&buf, ubuf, sizeof(buf)))
615 if (buf.buf_len > TEE_MAX_ARG_SIZE ||
616 buf.buf_len < sizeof(struct tee_iocl_supp_send_arg))
619 uarg = u64_to_user_ptr(buf.buf_ptr);
620 if (get_user(ret, &uarg->ret) ||
621 get_user(num_params, &uarg->num_params))
624 if (sizeof(*uarg) + TEE_IOCTL_PARAM_SIZE(num_params) > buf.buf_len)
627 params = kcalloc(num_params, sizeof(struct tee_param), GFP_KERNEL);
631 rc = params_from_supp(params, num_params, uarg->params);
635 rc = ctx->teedev->desc->ops->supp_send(ctx, ret, num_params, params);
641 static long tee_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
643 struct tee_context *ctx = filp->private_data;
644 void __user *uarg = (void __user *)arg;
647 case TEE_IOC_VERSION:
648 return tee_ioctl_version(ctx, uarg);
649 case TEE_IOC_SHM_ALLOC:
650 return tee_ioctl_shm_alloc(ctx, uarg);
651 case TEE_IOC_SHM_REGISTER:
652 return tee_ioctl_shm_register(ctx, uarg);
653 case TEE_IOC_OPEN_SESSION:
654 return tee_ioctl_open_session(ctx, uarg);
656 return tee_ioctl_invoke(ctx, uarg);
658 return tee_ioctl_cancel(ctx, uarg);
659 case TEE_IOC_CLOSE_SESSION:
660 return tee_ioctl_close_session(ctx, uarg);
661 case TEE_IOC_SUPPL_RECV:
662 return tee_ioctl_supp_recv(ctx, uarg);
663 case TEE_IOC_SUPPL_SEND:
664 return tee_ioctl_supp_send(ctx, uarg);
670 static const struct file_operations tee_fops = {
671 .owner = THIS_MODULE,
673 .release = tee_release,
674 .unlocked_ioctl = tee_ioctl,
675 .compat_ioctl = tee_ioctl,
678 static void tee_release_device(struct device *dev)
680 struct tee_device *teedev = container_of(dev, struct tee_device, dev);
682 spin_lock(&driver_lock);
683 clear_bit(teedev->id, dev_mask);
684 spin_unlock(&driver_lock);
685 mutex_destroy(&teedev->mutex);
686 idr_destroy(&teedev->idr);
691 * tee_device_alloc() - Allocate a new struct tee_device instance
692 * @teedesc: Descriptor for this driver
693 * @dev: Parent device for this device
694 * @pool: Shared memory pool, NULL if not used
695 * @driver_data: Private driver data for this device
697 * Allocates a new struct tee_device instance. The device is
698 * removed by tee_device_unregister().
700 * @returns a pointer to a 'struct tee_device' or an ERR_PTR on failure
702 struct tee_device *tee_device_alloc(const struct tee_desc *teedesc,
704 struct tee_shm_pool *pool,
707 struct tee_device *teedev;
712 if (!teedesc || !teedesc->name || !teedesc->ops ||
713 !teedesc->ops->get_version || !teedesc->ops->open ||
714 !teedesc->ops->release || !pool)
715 return ERR_PTR(-EINVAL);
717 teedev = kzalloc(sizeof(*teedev), GFP_KERNEL);
719 ret = ERR_PTR(-ENOMEM);
723 max_id = TEE_NUM_DEVICES / 2;
725 if (teedesc->flags & TEE_DESC_PRIVILEGED) {
726 offs = TEE_NUM_DEVICES / 2;
727 max_id = TEE_NUM_DEVICES;
730 spin_lock(&driver_lock);
731 teedev->id = find_next_zero_bit(dev_mask, max_id, offs);
732 if (teedev->id < max_id)
733 set_bit(teedev->id, dev_mask);
734 spin_unlock(&driver_lock);
736 if (teedev->id >= max_id) {
737 ret = ERR_PTR(-ENOMEM);
741 snprintf(teedev->name, sizeof(teedev->name), "tee%s%d",
742 teedesc->flags & TEE_DESC_PRIVILEGED ? "priv" : "",
745 teedev->dev.class = tee_class;
746 teedev->dev.release = tee_release_device;
747 teedev->dev.parent = dev;
749 teedev->dev.devt = MKDEV(MAJOR(tee_devt), teedev->id);
751 rc = dev_set_name(&teedev->dev, "%s", teedev->name);
757 cdev_init(&teedev->cdev, &tee_fops);
758 teedev->cdev.owner = teedesc->owner;
759 teedev->cdev.kobj.parent = &teedev->dev.kobj;
761 dev_set_drvdata(&teedev->dev, driver_data);
762 device_initialize(&teedev->dev);
764 /* 1 as tee_device_unregister() does one final tee_device_put() */
765 teedev->num_users = 1;
766 init_completion(&teedev->c_no_users);
767 mutex_init(&teedev->mutex);
768 idr_init(&teedev->idr);
770 teedev->desc = teedesc;
775 unregister_chrdev_region(teedev->dev.devt, 1);
777 pr_err("could not register %s driver\n",
778 teedesc->flags & TEE_DESC_PRIVILEGED ? "privileged" : "client");
779 if (teedev && teedev->id < TEE_NUM_DEVICES) {
780 spin_lock(&driver_lock);
781 clear_bit(teedev->id, dev_mask);
782 spin_unlock(&driver_lock);
787 EXPORT_SYMBOL_GPL(tee_device_alloc);
789 static ssize_t implementation_id_show(struct device *dev,
790 struct device_attribute *attr, char *buf)
792 struct tee_device *teedev = container_of(dev, struct tee_device, dev);
793 struct tee_ioctl_version_data vers;
795 teedev->desc->ops->get_version(teedev, &vers);
796 return scnprintf(buf, PAGE_SIZE, "%d\n", vers.impl_id);
798 static DEVICE_ATTR_RO(implementation_id);
800 static struct attribute *tee_dev_attrs[] = {
801 &dev_attr_implementation_id.attr,
805 static const struct attribute_group tee_dev_group = {
806 .attrs = tee_dev_attrs,
810 * tee_device_register() - Registers a TEE device
811 * @teedev: Device to register
813 * tee_device_unregister() need to be called to remove the @teedev if
814 * this function fails.
816 * @returns < 0 on failure
818 int tee_device_register(struct tee_device *teedev)
822 if (teedev->flags & TEE_DEVICE_FLAG_REGISTERED) {
823 dev_err(&teedev->dev, "attempt to register twice\n");
827 rc = cdev_add(&teedev->cdev, teedev->dev.devt, 1);
829 dev_err(&teedev->dev,
830 "unable to cdev_add() %s, major %d, minor %d, err=%d\n",
831 teedev->name, MAJOR(teedev->dev.devt),
832 MINOR(teedev->dev.devt), rc);
836 rc = device_add(&teedev->dev);
838 dev_err(&teedev->dev,
839 "unable to device_add() %s, major %d, minor %d, err=%d\n",
840 teedev->name, MAJOR(teedev->dev.devt),
841 MINOR(teedev->dev.devt), rc);
845 rc = sysfs_create_group(&teedev->dev.kobj, &tee_dev_group);
847 dev_err(&teedev->dev,
848 "failed to create sysfs attributes, err=%d\n", rc);
849 goto err_sysfs_create_group;
852 teedev->flags |= TEE_DEVICE_FLAG_REGISTERED;
855 err_sysfs_create_group:
856 device_del(&teedev->dev);
858 cdev_del(&teedev->cdev);
861 EXPORT_SYMBOL_GPL(tee_device_register);
863 void tee_device_put(struct tee_device *teedev)
865 mutex_lock(&teedev->mutex);
866 /* Shouldn't put in this state */
867 if (!WARN_ON(!teedev->desc)) {
869 if (!teedev->num_users) {
871 complete(&teedev->c_no_users);
874 mutex_unlock(&teedev->mutex);
877 bool tee_device_get(struct tee_device *teedev)
879 mutex_lock(&teedev->mutex);
881 mutex_unlock(&teedev->mutex);
885 mutex_unlock(&teedev->mutex);
890 * tee_device_unregister() - Removes a TEE device
891 * @teedev: Device to unregister
893 * This function should be called to remove the @teedev even if
894 * tee_device_register() hasn't been called yet. Does nothing if
897 void tee_device_unregister(struct tee_device *teedev)
902 if (teedev->flags & TEE_DEVICE_FLAG_REGISTERED) {
903 sysfs_remove_group(&teedev->dev.kobj, &tee_dev_group);
904 cdev_del(&teedev->cdev);
905 device_del(&teedev->dev);
908 tee_device_put(teedev);
909 wait_for_completion(&teedev->c_no_users);
912 * No need to take a mutex any longer now since teedev->desc was
913 * set to NULL before teedev->c_no_users was completed.
918 put_device(&teedev->dev);
920 EXPORT_SYMBOL_GPL(tee_device_unregister);
923 * tee_get_drvdata() - Return driver_data pointer
924 * @teedev: Device containing the driver_data pointer
925 * @returns the driver_data pointer supplied to tee_register().
927 void *tee_get_drvdata(struct tee_device *teedev)
929 return dev_get_drvdata(&teedev->dev);
931 EXPORT_SYMBOL_GPL(tee_get_drvdata);
933 static int __init tee_init(void)
937 tee_class = class_create(THIS_MODULE, "tee");
938 if (IS_ERR(tee_class)) {
939 pr_err("couldn't create class\n");
940 return PTR_ERR(tee_class);
943 rc = alloc_chrdev_region(&tee_devt, 0, TEE_NUM_DEVICES, "tee");
945 pr_err("failed to allocate char dev region\n");
946 class_destroy(tee_class);
953 static void __exit tee_exit(void)
955 class_destroy(tee_class);
957 unregister_chrdev_region(tee_devt, TEE_NUM_DEVICES);
960 subsys_initcall(tee_init);
961 module_exit(tee_exit);
963 MODULE_AUTHOR("Linaro");
964 MODULE_DESCRIPTION("TEE Driver");
965 MODULE_VERSION("1.0");
966 MODULE_LICENSE("GPL v2");