tz_sys_ipc.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. #include <linux/types.h>
  2. #include <linux/mutex.h>
  3. #include <linux/sched.h>
  4. #include <linux/semaphore.h>
  5. #include <linux/wait.h>
  6. #include <linux/slab.h>
  7. #include "tz_cross/trustzone.h"
  8. #include "tz_cross/ree_service.h"
  9. #include "trustzone/kree/system.h"
  10. /* Mutex
  11. */
  12. TZ_RESULT KREE_ServMutexCreate(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
  13. {
  14. struct mutex *mutex;
  15. unsigned long *out;
  16. mutex = kmalloc(sizeof(struct mutex), GFP_KERNEL);
  17. if (mutex == NULL)
  18. return TZ_RESULT_ERROR_OUT_OF_MEMORY;
  19. mutex_init(mutex);
  20. out = (unsigned long *) &param[0];
  21. *out = (unsigned long) mutex;
  22. return TZ_RESULT_SUCCESS;
  23. }
  24. TZ_RESULT KREE_ServMutexDestroy(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
  25. {
  26. struct mutex *mutex;
  27. unsigned long *in;
  28. in = (unsigned long *) &param[0];
  29. mutex = (struct mutex *)*in;
  30. kfree(mutex);
  31. return TZ_RESULT_SUCCESS;
  32. }
  33. TZ_RESULT KREE_ServMutexLock(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
  34. {
  35. struct mutex *mutex;
  36. unsigned long *in;
  37. in = (unsigned long *) &param[0];
  38. mutex = (struct mutex *)*in;
  39. mutex_lock(mutex);
  40. return TZ_RESULT_SUCCESS;
  41. }
  42. TZ_RESULT KREE_ServMutexUnlock(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
  43. {
  44. struct mutex *mutex;
  45. unsigned long *in;
  46. in = (unsigned long *) &param[0];
  47. mutex = (struct mutex *)*in;
  48. mutex_unlock(mutex);
  49. return TZ_RESULT_SUCCESS;
  50. }
  51. TZ_RESULT KREE_ServMutexTrylock(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
  52. {
  53. struct mutex *mutex;
  54. unsigned long *in;
  55. int *out;
  56. int ret;
  57. in = (unsigned long *) &param[0];
  58. mutex = (struct mutex *)*in;
  59. ret = mutex_trylock(mutex);
  60. out = (int *)&param[0];
  61. *out = ret;
  62. return TZ_RESULT_SUCCESS;
  63. }
  64. TZ_RESULT KREE_ServMutexIslock(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
  65. {
  66. struct mutex *mutex;
  67. unsigned long *in;
  68. int *out;
  69. int ret;
  70. in = (unsigned long *) &param[0];
  71. mutex = (struct mutex *)*in;
  72. ret = mutex_is_locked(mutex);
  73. out = (int *)&param[0];
  74. *out = ret;
  75. return TZ_RESULT_SUCCESS;
  76. }
  77. /* Semaphore
  78. */
  79. TZ_RESULT KREE_ServSemaphoreCreate(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
  80. {
  81. struct semaphore *sema;
  82. unsigned long *out;
  83. int *val;
  84. val = (int *)&param[0];
  85. sema = kmalloc(sizeof(struct semaphore), GFP_KERNEL);
  86. if (sema == NULL)
  87. return TZ_RESULT_ERROR_OUT_OF_MEMORY;
  88. sema_init(sema, *val);
  89. out = (unsigned long *) &param[0];
  90. *out = (unsigned long) sema;
  91. return TZ_RESULT_SUCCESS;
  92. }
  93. TZ_RESULT KREE_ServSemaphoreDestroy(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
  94. {
  95. struct semaphore *sema;
  96. unsigned long *in;
  97. in = (unsigned long *) &param[0];
  98. sema = (struct semaphore *)*in;
  99. kfree(sema);
  100. return TZ_RESULT_SUCCESS;
  101. }
  102. TZ_RESULT KREE_ServSemaphoreDown(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
  103. {
  104. struct semaphore *sema;
  105. unsigned long *in;
  106. in = (unsigned long *) &param[0];
  107. sema = (struct semaphore *)*in;
  108. down(sema);
  109. return TZ_RESULT_SUCCESS;
  110. }
  111. TZ_RESULT KREE_ServSemaphoreDownInterruptible(u32 op,
  112. u8 param[REE_SERVICE_BUFFER_SIZE])
  113. {
  114. struct semaphore *sema;
  115. unsigned long *in;
  116. int *out;
  117. in = (unsigned long *)&param[0];
  118. sema = (struct semaphore *)*in;
  119. out = (int *)&param[0];
  120. *out = down_interruptible(sema);
  121. return TZ_RESULT_SUCCESS;
  122. }
  123. TZ_RESULT KREE_ServSemaphoreDownTimeout(u32 op,
  124. u8 param[REE_SERVICE_BUFFER_SIZE])
  125. {
  126. struct semaphore *sema;
  127. unsigned long *in;
  128. long jiffies;
  129. int *out;
  130. int ret;
  131. in = (unsigned long *) &param[0];
  132. sema = (struct semaphore *)in[0];
  133. jiffies = (long)in[1];
  134. ret = down_timeout(sema, jiffies);
  135. out = (int *)&param[0];
  136. *out = ret;
  137. return TZ_RESULT_SUCCESS;
  138. }
  139. TZ_RESULT KREE_ServSemaphoreDowntrylock(u32 op,
  140. u8 param[REE_SERVICE_BUFFER_SIZE])
  141. {
  142. struct semaphore *sema;
  143. unsigned long *in;
  144. int *out;
  145. int ret;
  146. in = (unsigned long *) &param[0];
  147. sema = (struct semaphore *)*in;
  148. ret = down_trylock(sema);
  149. out = (int *)&param[0];
  150. *out = ret;
  151. return TZ_RESULT_SUCCESS;
  152. }
  153. TZ_RESULT KREE_ServSemaphoreUp(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
  154. {
  155. struct semaphore *sema;
  156. unsigned long *in;
  157. in = (unsigned long *) &param[0];
  158. sema = (struct semaphore *)*in;
  159. up(sema);
  160. return TZ_RESULT_SUCCESS;
  161. }
  162. #if 0
  163. /* wait queue
  164. */
  165. TZ_RESULT KREE_ServWaitqCreate(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
  166. {
  167. wait_queue_head_t *q;
  168. u32 *out;
  169. q = kmalloc(sizeof(wait_queue_head_t), GFP_KERNEL);
  170. if (q == NULL)
  171. return TZ_RESULT_ERROR_OUT_OF_MEMORY;
  172. init_waitqueue_head(q);
  173. out = (u32 *) &param[0];
  174. *out = (u32) q;
  175. return TZ_RESULT_SUCCESS;
  176. }
  177. TZ_RESULT KREE_ServWaitqDestroy(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
  178. {
  179. wait_queue_head_t *q;
  180. u32 *in;
  181. in = (u32 *) &param[0];
  182. q = (wait_queue_head_t *) *in;
  183. kfree(q);
  184. return TZ_RESULT_SUCCESS;
  185. }
  186. TZ_RESULT KREE_ServWaitqWaitevent(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
  187. {
  188. wait_queue_head_t *q;
  189. u32 *in;
  190. u32 condition;
  191. in = (u32 *) &param[0];
  192. q = (wait_queue_head_t *) in[0];
  193. condition = in[1];
  194. wait_event(*q, condition);
  195. return TZ_RESULT_SUCCESS;
  196. }
  197. TZ_RESULT KREE_ServWaitqWaiteventTimeout(u32 op,
  198. u8 param[REE_SERVICE_BUFFER_SIZE])
  199. {
  200. wait_queue_head_t *q;
  201. u32 *in;
  202. u32 condition;
  203. long timeout;
  204. int *out;
  205. int ret;
  206. in = (u32 *) &param[0];
  207. q = (wait_queue_head_t *) in[0];
  208. condition = in[1];
  209. timeout = (long)in[2];
  210. ret = wait_event_timeout(*q, condition, timeout);
  211. out = (int *)&param[0];
  212. *out = ret;
  213. return TZ_RESULT_SUCCESS;
  214. }
  215. TZ_RESULT KREE_ServWaitqWakeup(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
  216. {
  217. wait_queue_head_t *q;
  218. u32 *in;
  219. in = (u32 *) &param[0];
  220. q = (wait_queue_head_t *) in[0];
  221. wake_up(q);
  222. return TZ_RESULT_SUCCESS;
  223. }
  224. #endif