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 if (!access_ok(VERIFY_WRITE, (void __user *)(unsigned long)data.addr,
182 shm = tee_shm_register(ctx, data.addr, data.length,
183 TEE_SHM_DMA_BUF | TEE_SHM_USER_MAPPED);
188 data.flags = shm->flags;
189 data.length = shm->size;
191 if (copy_to_user(udata, &data, sizeof(data)))
194 ret = tee_shm_get_fd(shm);
196 * When user space closes the file descriptor the shared memory
197 * should be freed or if tee_shm_get_fd() failed then it will
198 * be freed immediately.
204 static int params_from_user(struct tee_context *ctx, struct tee_param *params,
206 struct tee_ioctl_param __user *uparams)
210 for (n = 0; n < num_params; n++) {
212 struct tee_ioctl_param ip;
214 if (copy_from_user(&ip, uparams + n, sizeof(ip)))
217 /* All unused attribute bits has to be zero */
218 if (ip.attr & ~TEE_IOCTL_PARAM_ATTR_MASK)
221 params[n].attr = ip.attr;
222 switch (ip.attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK) {
223 case TEE_IOCTL_PARAM_ATTR_TYPE_NONE:
224 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT:
226 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT:
227 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT:
228 params[n].u.value.a = ip.a;
229 params[n].u.value.b = ip.b;
230 params[n].u.value.c = ip.c;
232 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT:
233 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT:
234 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT:
236 * If we fail to get a pointer to a shared memory
237 * object (and increase the ref count) from an
238 * identifier we return an error. All pointers that
239 * has been added in params have an increased ref
240 * count. It's the callers responibility to do
241 * tee_shm_put() on all resolved pointers.
243 shm = tee_shm_get_from_id(ctx, ip.c);
248 * Ensure offset + size does not overflow offset
249 * and does not overflow the size of the referred
250 * shared memory object.
252 if ((ip.a + ip.b) < ip.a ||
253 (ip.a + ip.b) > shm->size) {
258 params[n].u.memref.shm_offs = ip.a;
259 params[n].u.memref.size = ip.b;
260 params[n].u.memref.shm = shm;
263 /* Unknown attribute */
270 static int params_to_user(struct tee_ioctl_param __user *uparams,
271 size_t num_params, struct tee_param *params)
275 for (n = 0; n < num_params; n++) {
276 struct tee_ioctl_param __user *up = uparams + n;
277 struct tee_param *p = params + n;
280 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT:
281 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT:
282 if (put_user(p->u.value.a, &up->a) ||
283 put_user(p->u.value.b, &up->b) ||
284 put_user(p->u.value.c, &up->c))
287 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT:
288 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT:
289 if (put_user((u64)p->u.memref.size, &up->b))
298 static int tee_ioctl_open_session(struct tee_context *ctx,
299 struct tee_ioctl_buf_data __user *ubuf)
303 struct tee_ioctl_buf_data buf;
304 struct tee_ioctl_open_session_arg __user *uarg;
305 struct tee_ioctl_open_session_arg arg;
306 struct tee_ioctl_param __user *uparams = NULL;
307 struct tee_param *params = NULL;
308 bool have_session = false;
310 if (!ctx->teedev->desc->ops->open_session)
313 if (copy_from_user(&buf, ubuf, sizeof(buf)))
316 if (buf.buf_len > TEE_MAX_ARG_SIZE ||
317 buf.buf_len < sizeof(struct tee_ioctl_open_session_arg))
320 uarg = u64_to_user_ptr(buf.buf_ptr);
321 if (copy_from_user(&arg, uarg, sizeof(arg)))
324 if (sizeof(arg) + TEE_IOCTL_PARAM_SIZE(arg.num_params) != buf.buf_len)
327 if (arg.num_params) {
328 params = kcalloc(arg.num_params, sizeof(struct tee_param),
332 uparams = uarg->params;
333 rc = params_from_user(ctx, params, arg.num_params, uparams);
338 rc = ctx->teedev->desc->ops->open_session(ctx, &arg, params);
343 if (put_user(arg.session, &uarg->session) ||
344 put_user(arg.ret, &uarg->ret) ||
345 put_user(arg.ret_origin, &uarg->ret_origin)) {
349 rc = params_to_user(uparams, arg.num_params, params);
352 * If we've succeeded to open the session but failed to communicate
353 * it back to user space, close the session again to avoid leakage.
355 if (rc && have_session && ctx->teedev->desc->ops->close_session)
356 ctx->teedev->desc->ops->close_session(ctx, arg.session);
359 /* Decrease ref count for all valid shared memory pointers */
360 for (n = 0; n < arg.num_params; n++)
361 if (tee_param_is_memref(params + n) &&
362 params[n].u.memref.shm)
363 tee_shm_put(params[n].u.memref.shm);
370 static int tee_ioctl_invoke(struct tee_context *ctx,
371 struct tee_ioctl_buf_data __user *ubuf)
375 struct tee_ioctl_buf_data buf;
376 struct tee_ioctl_invoke_arg __user *uarg;
377 struct tee_ioctl_invoke_arg arg;
378 struct tee_ioctl_param __user *uparams = NULL;
379 struct tee_param *params = NULL;
381 if (!ctx->teedev->desc->ops->invoke_func)
384 if (copy_from_user(&buf, ubuf, sizeof(buf)))
387 if (buf.buf_len > TEE_MAX_ARG_SIZE ||
388 buf.buf_len < sizeof(struct tee_ioctl_invoke_arg))
391 uarg = u64_to_user_ptr(buf.buf_ptr);
392 if (copy_from_user(&arg, uarg, sizeof(arg)))
395 if (sizeof(arg) + TEE_IOCTL_PARAM_SIZE(arg.num_params) != buf.buf_len)
398 if (arg.num_params) {
399 params = kcalloc(arg.num_params, sizeof(struct tee_param),
403 uparams = uarg->params;
404 rc = params_from_user(ctx, params, arg.num_params, uparams);
409 rc = ctx->teedev->desc->ops->invoke_func(ctx, &arg, params);
413 if (put_user(arg.ret, &uarg->ret) ||
414 put_user(arg.ret_origin, &uarg->ret_origin)) {
418 rc = params_to_user(uparams, arg.num_params, params);
421 /* Decrease ref count for all valid shared memory pointers */
422 for (n = 0; n < arg.num_params; n++)
423 if (tee_param_is_memref(params + n) &&
424 params[n].u.memref.shm)
425 tee_shm_put(params[n].u.memref.shm);
431 static int tee_ioctl_cancel(struct tee_context *ctx,
432 struct tee_ioctl_cancel_arg __user *uarg)
434 struct tee_ioctl_cancel_arg arg;
436 if (!ctx->teedev->desc->ops->cancel_req)
439 if (copy_from_user(&arg, uarg, sizeof(arg)))
442 return ctx->teedev->desc->ops->cancel_req(ctx, arg.cancel_id,
447 tee_ioctl_close_session(struct tee_context *ctx,
448 struct tee_ioctl_close_session_arg __user *uarg)
450 struct tee_ioctl_close_session_arg arg;
452 if (!ctx->teedev->desc->ops->close_session)
455 if (copy_from_user(&arg, uarg, sizeof(arg)))
458 return ctx->teedev->desc->ops->close_session(ctx, arg.session);
461 static int params_to_supp(struct tee_context *ctx,
462 struct tee_ioctl_param __user *uparams,
463 size_t num_params, struct tee_param *params)
467 for (n = 0; n < num_params; n++) {
468 struct tee_ioctl_param ip;
469 struct tee_param *p = params + n;
472 switch (p->attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK) {
473 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT:
474 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT:
479 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT:
480 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT:
481 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT:
482 ip.b = p->u.memref.size;
483 if (!p->u.memref.shm) {
485 ip.c = (u64)-1; /* invalid shm id */
488 ip.a = p->u.memref.shm_offs;
489 ip.c = p->u.memref.shm->id;
498 if (copy_to_user(uparams + n, &ip, sizeof(ip)))
505 static int tee_ioctl_supp_recv(struct tee_context *ctx,
506 struct tee_ioctl_buf_data __user *ubuf)
509 struct tee_ioctl_buf_data buf;
510 struct tee_iocl_supp_recv_arg __user *uarg;
511 struct tee_param *params;
515 if (!ctx->teedev->desc->ops->supp_recv)
518 if (copy_from_user(&buf, ubuf, sizeof(buf)))
521 if (buf.buf_len > TEE_MAX_ARG_SIZE ||
522 buf.buf_len < sizeof(struct tee_iocl_supp_recv_arg))
525 uarg = u64_to_user_ptr(buf.buf_ptr);
526 if (get_user(num_params, &uarg->num_params))
529 if (sizeof(*uarg) + TEE_IOCTL_PARAM_SIZE(num_params) != buf.buf_len)
532 params = kcalloc(num_params, sizeof(struct tee_param), GFP_KERNEL);
536 rc = params_from_user(ctx, params, num_params, uarg->params);
540 rc = ctx->teedev->desc->ops->supp_recv(ctx, &func, &num_params, params);
544 if (put_user(func, &uarg->func) ||
545 put_user(num_params, &uarg->num_params)) {
550 rc = params_to_supp(ctx, uarg->params, num_params, params);
556 static int params_from_supp(struct tee_param *params, size_t num_params,
557 struct tee_ioctl_param __user *uparams)
561 for (n = 0; n < num_params; n++) {
562 struct tee_param *p = params + n;
563 struct tee_ioctl_param ip;
565 if (copy_from_user(&ip, uparams + n, sizeof(ip)))
568 /* All unused attribute bits has to be zero */
569 if (ip.attr & ~TEE_IOCTL_PARAM_ATTR_MASK)
573 switch (ip.attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK) {
574 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT:
575 case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT:
576 /* Only out and in/out values can be updated */
581 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT:
582 case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT:
584 * Only the size of the memref can be updated.
585 * Since we don't have access to the original
586 * parameters here, only store the supplied size.
587 * The driver will copy the updated size into the
588 * original parameters.
590 p->u.memref.shm = NULL;
591 p->u.memref.shm_offs = 0;
592 p->u.memref.size = ip.b;
595 memset(&p->u, 0, sizeof(p->u));
602 static int tee_ioctl_supp_send(struct tee_context *ctx,
603 struct tee_ioctl_buf_data __user *ubuf)
606 struct tee_ioctl_buf_data buf;
607 struct tee_iocl_supp_send_arg __user *uarg;
608 struct tee_param *params;
612 /* Not valid for this driver */
613 if (!ctx->teedev->desc->ops->supp_send)
616 if (copy_from_user(&buf, ubuf, sizeof(buf)))
619 if (buf.buf_len > TEE_MAX_ARG_SIZE ||
620 buf.buf_len < sizeof(struct tee_iocl_supp_send_arg))
623 uarg = u64_to_user_ptr(buf.buf_ptr);
624 if (get_user(ret, &uarg->ret) ||
625 get_user(num_params, &uarg->num_params))
628 if (sizeof(*uarg) + TEE_IOCTL_PARAM_SIZE(num_params) > buf.buf_len)
631 params = kcalloc(num_params, sizeof(struct tee_param), GFP_KERNEL);
635 rc = params_from_supp(params, num_params, uarg->params);
639 rc = ctx->teedev->desc->ops->supp_send(ctx, ret, num_params, params);
645 static long tee_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
647 struct tee_context *ctx = filp->private_data;
648 void __user *uarg = (void __user *)arg;
651 case TEE_IOC_VERSION:
652 return tee_ioctl_version(ctx, uarg);
653 case TEE_IOC_SHM_ALLOC:
654 return tee_ioctl_shm_alloc(ctx, uarg);
655 case TEE_IOC_SHM_REGISTER:
656 return tee_ioctl_shm_register(ctx, uarg);
657 case TEE_IOC_OPEN_SESSION:
658 return tee_ioctl_open_session(ctx, uarg);
660 return tee_ioctl_invoke(ctx, uarg);
662 return tee_ioctl_cancel(ctx, uarg);
663 case TEE_IOC_CLOSE_SESSION:
664 return tee_ioctl_close_session(ctx, uarg);
665 case TEE_IOC_SUPPL_RECV:
666 return tee_ioctl_supp_recv(ctx, uarg);
667 case TEE_IOC_SUPPL_SEND:
668 return tee_ioctl_supp_send(ctx, uarg);
674 static const struct file_operations tee_fops = {
675 .owner = THIS_MODULE,
677 .release = tee_release,
678 .unlocked_ioctl = tee_ioctl,
679 .compat_ioctl = tee_ioctl,
682 static void tee_release_device(struct device *dev)
684 struct tee_device *teedev = container_of(dev, struct tee_device, dev);
686 spin_lock(&driver_lock);
687 clear_bit(teedev->id, dev_mask);
688 spin_unlock(&driver_lock);
689 mutex_destroy(&teedev->mutex);
690 idr_destroy(&teedev->idr);
695 * tee_device_alloc() - Allocate a new struct tee_device instance
696 * @teedesc: Descriptor for this driver
697 * @dev: Parent device for this device
698 * @pool: Shared memory pool, NULL if not used
699 * @driver_data: Private driver data for this device
701 * Allocates a new struct tee_device instance. The device is
702 * removed by tee_device_unregister().
704 * @returns a pointer to a 'struct tee_device' or an ERR_PTR on failure
706 struct tee_device *tee_device_alloc(const struct tee_desc *teedesc,
708 struct tee_shm_pool *pool,
711 struct tee_device *teedev;
716 if (!teedesc || !teedesc->name || !teedesc->ops ||
717 !teedesc->ops->get_version || !teedesc->ops->open ||
718 !teedesc->ops->release || !pool)
719 return ERR_PTR(-EINVAL);
721 teedev = kzalloc(sizeof(*teedev), GFP_KERNEL);
723 ret = ERR_PTR(-ENOMEM);
727 max_id = TEE_NUM_DEVICES / 2;
729 if (teedesc->flags & TEE_DESC_PRIVILEGED) {
730 offs = TEE_NUM_DEVICES / 2;
731 max_id = TEE_NUM_DEVICES;
734 spin_lock(&driver_lock);
735 teedev->id = find_next_zero_bit(dev_mask, max_id, offs);
736 if (teedev->id < max_id)
737 set_bit(teedev->id, dev_mask);
738 spin_unlock(&driver_lock);
740 if (teedev->id >= max_id) {
741 ret = ERR_PTR(-ENOMEM);
745 snprintf(teedev->name, sizeof(teedev->name), "tee%s%d",
746 teedesc->flags & TEE_DESC_PRIVILEGED ? "priv" : "",
749 teedev->dev.class = tee_class;
750 teedev->dev.release = tee_release_device;
751 teedev->dev.parent = dev;
753 teedev->dev.devt = MKDEV(MAJOR(tee_devt), teedev->id);
755 rc = dev_set_name(&teedev->dev, "%s", teedev->name);
761 cdev_init(&teedev->cdev, &tee_fops);
762 teedev->cdev.owner = teedesc->owner;
763 teedev->cdev.kobj.parent = &teedev->dev.kobj;
765 dev_set_drvdata(&teedev->dev, driver_data);
766 device_initialize(&teedev->dev);
768 /* 1 as tee_device_unregister() does one final tee_device_put() */
769 teedev->num_users = 1;
770 init_completion(&teedev->c_no_users);
771 mutex_init(&teedev->mutex);
772 idr_init(&teedev->idr);
774 teedev->desc = teedesc;
779 unregister_chrdev_region(teedev->dev.devt, 1);
781 pr_err("could not register %s driver\n",
782 teedesc->flags & TEE_DESC_PRIVILEGED ? "privileged" : "client");
783 if (teedev && teedev->id < TEE_NUM_DEVICES) {
784 spin_lock(&driver_lock);
785 clear_bit(teedev->id, dev_mask);
786 spin_unlock(&driver_lock);
791 EXPORT_SYMBOL_GPL(tee_device_alloc);
793 static ssize_t implementation_id_show(struct device *dev,
794 struct device_attribute *attr, char *buf)
796 struct tee_device *teedev = container_of(dev, struct tee_device, dev);
797 struct tee_ioctl_version_data vers;
799 teedev->desc->ops->get_version(teedev, &vers);
800 return scnprintf(buf, PAGE_SIZE, "%d\n", vers.impl_id);
802 static DEVICE_ATTR_RO(implementation_id);
804 static struct attribute *tee_dev_attrs[] = {
805 &dev_attr_implementation_id.attr,
809 static const struct attribute_group tee_dev_group = {
810 .attrs = tee_dev_attrs,
814 * tee_device_register() - Registers a TEE device
815 * @teedev: Device to register
817 * tee_device_unregister() need to be called to remove the @teedev if
818 * this function fails.
820 * @returns < 0 on failure
822 int tee_device_register(struct tee_device *teedev)
826 if (teedev->flags & TEE_DEVICE_FLAG_REGISTERED) {
827 dev_err(&teedev->dev, "attempt to register twice\n");
831 rc = cdev_add(&teedev->cdev, teedev->dev.devt, 1);
833 dev_err(&teedev->dev,
834 "unable to cdev_add() %s, major %d, minor %d, err=%d\n",
835 teedev->name, MAJOR(teedev->dev.devt),
836 MINOR(teedev->dev.devt), rc);
840 rc = device_add(&teedev->dev);
842 dev_err(&teedev->dev,
843 "unable to device_add() %s, major %d, minor %d, err=%d\n",
844 teedev->name, MAJOR(teedev->dev.devt),
845 MINOR(teedev->dev.devt), rc);
849 rc = sysfs_create_group(&teedev->dev.kobj, &tee_dev_group);
851 dev_err(&teedev->dev,
852 "failed to create sysfs attributes, err=%d\n", rc);
853 goto err_sysfs_create_group;
856 teedev->flags |= TEE_DEVICE_FLAG_REGISTERED;
859 err_sysfs_create_group:
860 device_del(&teedev->dev);
862 cdev_del(&teedev->cdev);
865 EXPORT_SYMBOL_GPL(tee_device_register);
867 void tee_device_put(struct tee_device *teedev)
869 mutex_lock(&teedev->mutex);
870 /* Shouldn't put in this state */
871 if (!WARN_ON(!teedev->desc)) {
873 if (!teedev->num_users) {
875 complete(&teedev->c_no_users);
878 mutex_unlock(&teedev->mutex);
881 bool tee_device_get(struct tee_device *teedev)
883 mutex_lock(&teedev->mutex);
885 mutex_unlock(&teedev->mutex);
889 mutex_unlock(&teedev->mutex);
894 * tee_device_unregister() - Removes a TEE device
895 * @teedev: Device to unregister
897 * This function should be called to remove the @teedev even if
898 * tee_device_register() hasn't been called yet. Does nothing if
901 void tee_device_unregister(struct tee_device *teedev)
906 if (teedev->flags & TEE_DEVICE_FLAG_REGISTERED) {
907 sysfs_remove_group(&teedev->dev.kobj, &tee_dev_group);
908 cdev_del(&teedev->cdev);
909 device_del(&teedev->dev);
912 tee_device_put(teedev);
913 wait_for_completion(&teedev->c_no_users);
916 * No need to take a mutex any longer now since teedev->desc was
917 * set to NULL before teedev->c_no_users was completed.
922 put_device(&teedev->dev);
924 EXPORT_SYMBOL_GPL(tee_device_unregister);
927 * tee_get_drvdata() - Return driver_data pointer
928 * @teedev: Device containing the driver_data pointer
929 * @returns the driver_data pointer supplied to tee_register().
931 void *tee_get_drvdata(struct tee_device *teedev)
933 return dev_get_drvdata(&teedev->dev);
935 EXPORT_SYMBOL_GPL(tee_get_drvdata);
937 static int __init tee_init(void)
941 tee_class = class_create(THIS_MODULE, "tee");
942 if (IS_ERR(tee_class)) {
943 pr_err("couldn't create class\n");
944 return PTR_ERR(tee_class);
947 rc = alloc_chrdev_region(&tee_devt, 0, TEE_NUM_DEVICES, "tee");
949 pr_err("failed to allocate char dev region\n");
950 class_destroy(tee_class);
957 static void __exit tee_exit(void)
959 class_destroy(tee_class);
961 unregister_chrdev_region(tee_devt, TEE_NUM_DEVICES);
964 subsys_initcall(tee_init);
965 module_exit(tee_exit);
967 MODULE_AUTHOR("Linaro");
968 MODULE_DESCRIPTION("TEE Driver");
969 MODULE_VERSION("1.0");
970 MODULE_LICENSE("GPL v2");