Loading...
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (c) 2015-2016, Linaro Limited
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
15#define TEE_DEVICE_FLAG_REGISTERED 0x1
16#define TEE_MAX_DEV_NAME_LEN 32
17
18/**
19 * struct tee_device - TEE Device representation
20 * @name: name of device
21 * @desc: description of device
22 * @id: unique id of device
23 * @flags: represented by TEE_DEVICE_FLAG_REGISTERED above
24 * @dev: embedded basic device structure
25 * @cdev: embedded cdev
26 * @num_users: number of active users of this device
27 * @c_no_user: completion used when unregistering the device
28 * @mutex: mutex protecting @num_users and @idr
29 * @idr: register of user space shared memory objects allocated or
30 * registered on this device
31 * @pool: shared memory pool
32 */
33struct tee_device {
34 char name[TEE_MAX_DEV_NAME_LEN];
35 const struct tee_desc *desc;
36 int id;
37 unsigned int flags;
38
39 struct device dev;
40 struct cdev cdev;
41
42 size_t num_users;
43 struct completion c_no_users;
44 struct mutex mutex; /* protects num_users and idr */
45
46 struct idr idr;
47 struct tee_shm_pool *pool;
48};
49
50int tee_shm_get_fd(struct tee_shm *shm);
51
52bool tee_device_get(struct tee_device *teedev);
53void tee_device_put(struct tee_device *teedev);
54
55void teedev_ctx_get(struct tee_context *ctx);
56void teedev_ctx_put(struct tee_context *ctx);
57
58struct tee_shm *tee_shm_alloc_user_buf(struct tee_context *ctx, size_t size);
59struct tee_shm *tee_shm_register_user_buf(struct tee_context *ctx,
60 unsigned long addr, size_t length);
61
62#endif /*TEE_PRIVATE_H*/
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (c) 2015-2016, Linaro Limited
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
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
20 */
21struct tee_shm_pool {
22 struct tee_shm_pool_mgr *private_mgr;
23 struct tee_shm_pool_mgr *dma_buf_mgr;
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
40 * @idr: register of shared memory object allocated on this device
41 * @pool: shared memory pool
42 */
43struct tee_device {
44 char name[TEE_MAX_DEV_NAME_LEN];
45 const struct tee_desc *desc;
46 int id;
47 unsigned int flags;
48
49 struct device dev;
50 struct cdev cdev;
51
52 size_t num_users;
53 struct completion c_no_users;
54 struct mutex mutex; /* protects num_users and idr */
55
56 struct idr idr;
57 struct tee_shm_pool *pool;
58};
59
60int tee_shm_init(void);
61
62int tee_shm_get_fd(struct tee_shm *shm);
63
64bool tee_device_get(struct tee_device *teedev);
65void tee_device_put(struct tee_device *teedev);
66
67void teedev_ctx_get(struct tee_context *ctx);
68void teedev_ctx_put(struct tee_context *ctx);
69
70#endif /*TEE_PRIVATE_H*/