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.
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>
27 * struct tee_shm - shared memory object
28 * @teedev: device used to allocate the object
29 * @ctx: context using the object, if NULL the context is gone
31 * @paddr: physical address of the shared memory
32 * @kaddr: virtual address of the shared memory
33 * @size: size of shared memory
34 * @dmabuf: dmabuf used to for exporting to user space
35 * @flags: defined by TEE_SHM_* in tee_drv.h
36 * @id: unique id of a shared memory object on this device
39 struct tee_device
*teedev
;
40 struct tee_context
*ctx
;
41 struct list_head link
;
45 struct dma_buf
*dmabuf
;
50 struct tee_shm_pool_mgr
;
53 * struct tee_shm_pool_mgr_ops - shared memory pool manager operations
54 * @alloc: called when allocating shared memory
55 * @free: called when freeing shared memory
57 struct tee_shm_pool_mgr_ops
{
58 int (*alloc
)(struct tee_shm_pool_mgr
*poolmgr
, struct tee_shm
*shm
,
60 void (*free
)(struct tee_shm_pool_mgr
*poolmgr
, struct tee_shm
*shm
);
64 * struct tee_shm_pool_mgr - shared memory manager
66 * @private_data: private data for the shared memory manager
68 struct tee_shm_pool_mgr
{
69 const struct tee_shm_pool_mgr_ops
*ops
;
74 * struct tee_shm_pool - shared memory pool
75 * @private_mgr: pool manager for shared memory only between kernel
77 * @dma_buf_mgr: pool manager for shared memory exported to user space
78 * @destroy: called when destroying the pool
79 * @private_data: private data for the pool
82 struct tee_shm_pool_mgr private_mgr
;
83 struct tee_shm_pool_mgr dma_buf_mgr
;
84 void (*destroy
)(struct tee_shm_pool
*pool
);
88 #define TEE_DEVICE_FLAG_REGISTERED 0x1
89 #define TEE_MAX_DEV_NAME_LEN 32
92 * struct tee_device - TEE Device representation
93 * @name: name of device
94 * @desc: description of device
95 * @id: unique id of device
96 * @flags: represented by TEE_DEVICE_FLAG_REGISTERED above
97 * @dev: embedded basic device structure
98 * @cdev: embedded cdev
99 * @num_users: number of active users of this device
100 * @c_no_user: completion used when unregistering the device
101 * @mutex: mutex protecting @num_users and @idr
102 * @idr: register of shared memory object allocated on this device
103 * @pool: shared memory pool
106 char name
[TEE_MAX_DEV_NAME_LEN
];
107 const struct tee_desc
*desc
;
115 struct completion c_no_users
;
116 struct mutex mutex
; /* protects num_users and idr */
119 struct tee_shm_pool
*pool
;
122 int tee_shm_init(void);
124 int tee_shm_get_fd(struct tee_shm
*shm
);
126 bool tee_device_get(struct tee_device
*teedev
);
127 void tee_device_put(struct tee_device
*teedev
);
129 #endif /*TEE_PRIVATE_H*/