tee_private.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. struct tee_device;
  23. /**
  24. * struct tee_shm - shared memory object
  25. * @teedev: device used to allocate the object
  26. * @ctx: context using the object, if NULL the context is gone
  27. * @link link element
  28. * @paddr: physical address of the shared memory
  29. * @kaddr: virtual address of the shared memory
  30. * @size: size of shared memory
  31. * @dmabuf: dmabuf used to for exporting to user space
  32. * @flags: defined by TEE_SHM_* in tee_drv.h
  33. * @id: unique id of a shared memory object on this device
  34. */
  35. struct tee_shm {
  36. struct tee_device *teedev;
  37. struct tee_context *ctx;
  38. struct list_head link;
  39. phys_addr_t paddr;
  40. void *kaddr;
  41. size_t size;
  42. struct dma_buf *dmabuf;
  43. u32 flags;
  44. int id;
  45. };
  46. struct tee_shm_pool_mgr;
  47. /**
  48. * struct tee_shm_pool_mgr_ops - shared memory pool manager operations
  49. * @alloc: called when allocating shared memory
  50. * @free: called when freeing shared memory
  51. */
  52. struct tee_shm_pool_mgr_ops {
  53. int (*alloc)(struct tee_shm_pool_mgr *poolmgr, struct tee_shm *shm,
  54. size_t size);
  55. void (*free)(struct tee_shm_pool_mgr *poolmgr, struct tee_shm *shm);
  56. };
  57. /**
  58. * struct tee_shm_pool_mgr - shared memory manager
  59. * @ops: operations
  60. * @private_data: private data for the shared memory manager
  61. */
  62. struct tee_shm_pool_mgr {
  63. const struct tee_shm_pool_mgr_ops *ops;
  64. void *private_data;
  65. };
  66. /**
  67. * struct tee_shm_pool - shared memory pool
  68. * @private_mgr: pool manager for shared memory only between kernel
  69. * and secure world
  70. * @dma_buf_mgr: pool manager for shared memory exported to user space
  71. * @destroy: called when destroying the pool
  72. * @private_data: private data for the pool
  73. */
  74. struct tee_shm_pool {
  75. struct tee_shm_pool_mgr private_mgr;
  76. struct tee_shm_pool_mgr dma_buf_mgr;
  77. void (*destroy)(struct tee_shm_pool *pool);
  78. void *private_data;
  79. };
  80. #define TEE_DEVICE_FLAG_REGISTERED 0x1
  81. #define TEE_MAX_DEV_NAME_LEN 32
  82. /**
  83. * struct tee_device - TEE Device representation
  84. * @name: name of device
  85. * @desc: description of device
  86. * @id: unique id of device
  87. * @flags: represented by TEE_DEVICE_FLAG_REGISTERED above
  88. * @dev: embedded basic device structure
  89. * @cdev: embedded cdev
  90. * @num_users: number of active users of this device
  91. * @c_no_user: completion used when unregistering the device
  92. * @mutex: mutex protecting @num_users and @idr
  93. * @idr: register of shared memory object allocated on this device
  94. * @pool: shared memory pool
  95. */
  96. struct tee_device {
  97. char name[TEE_MAX_DEV_NAME_LEN];
  98. const struct tee_desc *desc;
  99. int id;
  100. unsigned int flags;
  101. struct device dev;
  102. struct cdev cdev;
  103. size_t num_users;
  104. struct completion c_no_users;
  105. struct mutex mutex; /* protects num_users and idr */
  106. struct idr idr;
  107. struct tee_shm_pool *pool;
  108. };
  109. int tee_shm_init(void);
  110. int tee_shm_get_fd(struct tee_shm *shm);
  111. bool tee_device_get(struct tee_device *teedev);
  112. void tee_device_put(struct tee_device *teedev);
  113. #endif /*TEE_PRIVATE_H*/