19c92ab61SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2967c9ccaSJens Wiklander /* 3967c9ccaSJens Wiklander * Copyright (c) 2015-2016, Linaro Limited 4967c9ccaSJens Wiklander */ 5967c9ccaSJens Wiklander #ifndef TEE_PRIVATE_H 6967c9ccaSJens Wiklander #define TEE_PRIVATE_H 7967c9ccaSJens Wiklander 8967c9ccaSJens Wiklander #include <linux/cdev.h> 9967c9ccaSJens Wiklander #include <linux/completion.h> 10967c9ccaSJens Wiklander #include <linux/device.h> 11967c9ccaSJens Wiklander #include <linux/kref.h> 12967c9ccaSJens Wiklander #include <linux/mutex.h> 13967c9ccaSJens Wiklander #include <linux/types.h> 14967c9ccaSJens Wiklander 15967c9ccaSJens Wiklander #define TEE_DEVICE_FLAG_REGISTERED 0x1 16967c9ccaSJens Wiklander #define TEE_MAX_DEV_NAME_LEN 32 17967c9ccaSJens Wiklander 18967c9ccaSJens Wiklander /** 19967c9ccaSJens Wiklander * struct tee_device - TEE Device representation 20967c9ccaSJens Wiklander * @name: name of device 21967c9ccaSJens Wiklander * @desc: description of device 22967c9ccaSJens Wiklander * @id: unique id of device 23967c9ccaSJens Wiklander * @flags: represented by TEE_DEVICE_FLAG_REGISTERED above 24967c9ccaSJens Wiklander * @dev: embedded basic device structure 25967c9ccaSJens Wiklander * @cdev: embedded cdev 26967c9ccaSJens Wiklander * @num_users: number of active users of this device 27967c9ccaSJens Wiklander * @c_no_user: completion used when unregistering the device 28967c9ccaSJens Wiklander * @mutex: mutex protecting @num_users and @idr 29f1bbacedSJens Wiklander * @idr: register of user space shared memory objects allocated or 30f1bbacedSJens Wiklander * registered on this device 31967c9ccaSJens Wiklander * @pool: shared memory pool 32967c9ccaSJens Wiklander */ 33967c9ccaSJens Wiklander struct tee_device { 34967c9ccaSJens Wiklander char name[TEE_MAX_DEV_NAME_LEN]; 35967c9ccaSJens Wiklander const struct tee_desc *desc; 36967c9ccaSJens Wiklander int id; 37967c9ccaSJens Wiklander unsigned int flags; 38967c9ccaSJens Wiklander 39967c9ccaSJens Wiklander struct device dev; 40967c9ccaSJens Wiklander struct cdev cdev; 41967c9ccaSJens Wiklander 42967c9ccaSJens Wiklander size_t num_users; 43967c9ccaSJens Wiklander struct completion c_no_users; 44967c9ccaSJens Wiklander struct mutex mutex; /* protects num_users and idr */ 45967c9ccaSJens Wiklander 46967c9ccaSJens Wiklander struct idr idr; 47967c9ccaSJens Wiklander struct tee_shm_pool *pool; 48967c9ccaSJens Wiklander }; 49967c9ccaSJens Wiklander 50967c9ccaSJens Wiklander int tee_shm_get_fd(struct tee_shm *shm); 51967c9ccaSJens Wiklander 52967c9ccaSJens Wiklander bool tee_device_get(struct tee_device *teedev); 53967c9ccaSJens Wiklander void tee_device_put(struct tee_device *teedev); 54967c9ccaSJens Wiklander 55217e0250SVolodymyr Babchuk void teedev_ctx_get(struct tee_context *ctx); 56217e0250SVolodymyr Babchuk void teedev_ctx_put(struct tee_context *ctx); 57217e0250SVolodymyr Babchuk 5871cc47d4SJens Wiklander struct tee_shm *tee_shm_alloc_user_buf(struct tee_context *ctx, size_t size); 59*056d3fedSJens Wiklander struct tee_shm *tee_shm_register_user_buf(struct tee_context *ctx, 60*056d3fedSJens Wiklander unsigned long addr, size_t length); 6171cc47d4SJens Wiklander 62967c9ccaSJens Wiklander #endif /*TEE_PRIVATE_H*/ 63