Commit | Line | Data |
---|---|---|
967c9cca JW |
1 | /* |
2 | * Copyright (c) 2015-2016, Linaro Limited | |
3 | * | |
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. | |
7 | * | |
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. | |
12 | * | |
13 | */ | |
14 | #ifndef TEE_PRIVATE_H | |
15 | #define TEE_PRIVATE_H | |
16 | ||
17 | #include <linux/cdev.h> | |
18 | #include <linux/completion.h> | |
19 | #include <linux/device.h> | |
20 | #include <linux/kref.h> | |
21 | #include <linux/mutex.h> | |
22 | #include <linux/types.h> | |
23 | ||
967c9cca JW |
24 | /** |
25 | * struct tee_shm_pool - shared memory pool | |
26 | * @private_mgr: pool manager for shared memory only between kernel | |
27 | * and secure world | |
28 | * @dma_buf_mgr: pool manager for shared memory exported to user space | |
967c9cca JW |
29 | */ |
30 | struct tee_shm_pool { | |
e2aca5d8 JW |
31 | struct tee_shm_pool_mgr *private_mgr; |
32 | struct tee_shm_pool_mgr *dma_buf_mgr; | |
967c9cca JW |
33 | }; |
34 | ||
35 | #define TEE_DEVICE_FLAG_REGISTERED 0x1 | |
36 | #define TEE_MAX_DEV_NAME_LEN 32 | |
37 | ||
38 | /** | |
39 | * struct tee_device - TEE Device representation | |
40 | * @name: name of device | |
41 | * @desc: description of device | |
42 | * @id: unique id of device | |
43 | * @flags: represented by TEE_DEVICE_FLAG_REGISTERED above | |
44 | * @dev: embedded basic device structure | |
45 | * @cdev: embedded cdev | |
46 | * @num_users: number of active users of this device | |
47 | * @c_no_user: completion used when unregistering the device | |
48 | * @mutex: mutex protecting @num_users and @idr | |
49 | * @idr: register of shared memory object allocated on this device | |
50 | * @pool: shared memory pool | |
51 | */ | |
52 | struct tee_device { | |
53 | char name[TEE_MAX_DEV_NAME_LEN]; | |
54 | const struct tee_desc *desc; | |
55 | int id; | |
56 | unsigned int flags; | |
57 | ||
58 | struct device dev; | |
59 | struct cdev cdev; | |
60 | ||
61 | size_t num_users; | |
62 | struct completion c_no_users; | |
63 | struct mutex mutex; /* protects num_users and idr */ | |
64 | ||
65 | struct idr idr; | |
66 | struct tee_shm_pool *pool; | |
67 | }; | |
68 | ||
69 | int tee_shm_init(void); | |
70 | ||
71 | int tee_shm_get_fd(struct tee_shm *shm); | |
72 | ||
73 | bool tee_device_get(struct tee_device *teedev); | |
74 | void tee_device_put(struct tee_device *teedev); | |
75 | ||
217e0250 VB |
76 | void teedev_ctx_get(struct tee_context *ctx); |
77 | void teedev_ctx_put(struct tee_context *ctx); | |
78 | ||
967c9cca | 79 | #endif /*TEE_PRIVATE_H*/ |