tee_private.h 2.2 KB

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