Thomas Gleixner | 9c92ab6 | 2019-05-29 07:17:56 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Jens Wiklander | 967c9cc | 2015-03-11 14:39:39 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015-2016, Linaro Limited |
Jens Wiklander | 967c9cc | 2015-03-11 14:39:39 +0100 | [diff] [blame] | 4 | */ |
| 5 | #ifndef TEE_PRIVATE_H |
| 6 | #define TEE_PRIVATE_H |
| 7 | |
| 8 | #include <linux/cdev.h> |
| 9 | #include <linux/completion.h> |
| 10 | #include <linux/device.h> |
| 11 | #include <linux/kref.h> |
| 12 | #include <linux/mutex.h> |
| 13 | #include <linux/types.h> |
| 14 | |
Jens Wiklander | 967c9cc | 2015-03-11 14:39:39 +0100 | [diff] [blame] | 15 | /** |
| 16 | * struct tee_shm_pool - shared memory pool |
| 17 | * @private_mgr: pool manager for shared memory only between kernel |
| 18 | * and secure world |
| 19 | * @dma_buf_mgr: pool manager for shared memory exported to user space |
Jens Wiklander | 967c9cc | 2015-03-11 14:39:39 +0100 | [diff] [blame] | 20 | */ |
| 21 | struct tee_shm_pool { |
Jens Wiklander | e2aca5d | 2017-11-29 14:48:25 +0200 | [diff] [blame] | 22 | struct tee_shm_pool_mgr *private_mgr; |
| 23 | struct tee_shm_pool_mgr *dma_buf_mgr; |
Jens Wiklander | 967c9cc | 2015-03-11 14:39:39 +0100 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | #define TEE_DEVICE_FLAG_REGISTERED 0x1 |
| 27 | #define TEE_MAX_DEV_NAME_LEN 32 |
| 28 | |
| 29 | /** |
| 30 | * struct tee_device - TEE Device representation |
| 31 | * @name: name of device |
| 32 | * @desc: description of device |
| 33 | * @id: unique id of device |
| 34 | * @flags: represented by TEE_DEVICE_FLAG_REGISTERED above |
| 35 | * @dev: embedded basic device structure |
| 36 | * @cdev: embedded cdev |
| 37 | * @num_users: number of active users of this device |
| 38 | * @c_no_user: completion used when unregistering the device |
| 39 | * @mutex: mutex protecting @num_users and @idr |
Jens Wiklander | f1bbace | 2019-11-07 11:42:56 +0100 | [diff] [blame] | 40 | * @idr: register of user space shared memory objects allocated or |
| 41 | * registered on this device |
Jens Wiklander | 967c9cc | 2015-03-11 14:39:39 +0100 | [diff] [blame] | 42 | * @pool: shared memory pool |
| 43 | */ |
| 44 | struct tee_device { |
| 45 | char name[TEE_MAX_DEV_NAME_LEN]; |
| 46 | const struct tee_desc *desc; |
| 47 | int id; |
| 48 | unsigned int flags; |
| 49 | |
| 50 | struct device dev; |
| 51 | struct cdev cdev; |
| 52 | |
| 53 | size_t num_users; |
| 54 | struct completion c_no_users; |
| 55 | struct mutex mutex; /* protects num_users and idr */ |
| 56 | |
| 57 | struct idr idr; |
| 58 | struct tee_shm_pool *pool; |
| 59 | }; |
| 60 | |
| 61 | int tee_shm_init(void); |
| 62 | |
| 63 | int tee_shm_get_fd(struct tee_shm *shm); |
| 64 | |
| 65 | bool tee_device_get(struct tee_device *teedev); |
| 66 | void tee_device_put(struct tee_device *teedev); |
| 67 | |
Volodymyr Babchuk | 217e025 | 2017-11-29 14:48:37 +0200 | [diff] [blame] | 68 | void teedev_ctx_get(struct tee_context *ctx); |
| 69 | void teedev_ctx_put(struct tee_context *ctx); |
| 70 | |
Jens Wiklander | 967c9cc | 2015-03-11 14:39:39 +0100 | [diff] [blame] | 71 | #endif /*TEE_PRIVATE_H*/ |