| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- #include <linux/types.h>
- #include <linux/mutex.h>
- #include <linux/sched.h>
- #include <linux/semaphore.h>
- #include <linux/wait.h>
- #include <linux/slab.h>
- #include "tz_cross/trustzone.h"
- #include "tz_cross/ree_service.h"
- #include "trustzone/kree/system.h"
- /* Mutex
- */
- TZ_RESULT KREE_ServMutexCreate(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- struct mutex *mutex;
- unsigned long *out;
- mutex = kmalloc(sizeof(struct mutex), GFP_KERNEL);
- if (mutex == NULL)
- return TZ_RESULT_ERROR_OUT_OF_MEMORY;
- mutex_init(mutex);
- out = (unsigned long *) ¶m[0];
- *out = (unsigned long) mutex;
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServMutexDestroy(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- struct mutex *mutex;
- unsigned long *in;
- in = (unsigned long *) ¶m[0];
- mutex = (struct mutex *)*in;
- kfree(mutex);
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServMutexLock(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- struct mutex *mutex;
- unsigned long *in;
- in = (unsigned long *) ¶m[0];
- mutex = (struct mutex *)*in;
- mutex_lock(mutex);
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServMutexUnlock(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- struct mutex *mutex;
- unsigned long *in;
- in = (unsigned long *) ¶m[0];
- mutex = (struct mutex *)*in;
- mutex_unlock(mutex);
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServMutexTrylock(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- struct mutex *mutex;
- unsigned long *in;
- int *out;
- int ret;
- in = (unsigned long *) ¶m[0];
- mutex = (struct mutex *)*in;
- ret = mutex_trylock(mutex);
- out = (int *)¶m[0];
- *out = ret;
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServMutexIslock(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- struct mutex *mutex;
- unsigned long *in;
- int *out;
- int ret;
- in = (unsigned long *) ¶m[0];
- mutex = (struct mutex *)*in;
- ret = mutex_is_locked(mutex);
- out = (int *)¶m[0];
- *out = ret;
- return TZ_RESULT_SUCCESS;
- }
- /* Semaphore
- */
- TZ_RESULT KREE_ServSemaphoreCreate(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- struct semaphore *sema;
- unsigned long *out;
- int *val;
- val = (int *)¶m[0];
- sema = kmalloc(sizeof(struct semaphore), GFP_KERNEL);
- if (sema == NULL)
- return TZ_RESULT_ERROR_OUT_OF_MEMORY;
- sema_init(sema, *val);
- out = (unsigned long *) ¶m[0];
- *out = (unsigned long) sema;
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServSemaphoreDestroy(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- struct semaphore *sema;
- unsigned long *in;
- in = (unsigned long *) ¶m[0];
- sema = (struct semaphore *)*in;
- kfree(sema);
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServSemaphoreDown(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- struct semaphore *sema;
- unsigned long *in;
- in = (unsigned long *) ¶m[0];
- sema = (struct semaphore *)*in;
- down(sema);
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServSemaphoreDownInterruptible(u32 op,
- u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- struct semaphore *sema;
- unsigned long *in;
- int *out;
- in = (unsigned long *)¶m[0];
- sema = (struct semaphore *)*in;
- out = (int *)¶m[0];
- *out = down_interruptible(sema);
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServSemaphoreDownTimeout(u32 op,
- u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- struct semaphore *sema;
- unsigned long *in;
- long jiffies;
- int *out;
- int ret;
- in = (unsigned long *) ¶m[0];
- sema = (struct semaphore *)in[0];
- jiffies = (long)in[1];
- ret = down_timeout(sema, jiffies);
- out = (int *)¶m[0];
- *out = ret;
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServSemaphoreDowntrylock(u32 op,
- u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- struct semaphore *sema;
- unsigned long *in;
- int *out;
- int ret;
- in = (unsigned long *) ¶m[0];
- sema = (struct semaphore *)*in;
- ret = down_trylock(sema);
- out = (int *)¶m[0];
- *out = ret;
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServSemaphoreUp(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- struct semaphore *sema;
- unsigned long *in;
- in = (unsigned long *) ¶m[0];
- sema = (struct semaphore *)*in;
- up(sema);
- return TZ_RESULT_SUCCESS;
- }
- #if 0
- /* wait queue
- */
- TZ_RESULT KREE_ServWaitqCreate(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- wait_queue_head_t *q;
- u32 *out;
- q = kmalloc(sizeof(wait_queue_head_t), GFP_KERNEL);
- if (q == NULL)
- return TZ_RESULT_ERROR_OUT_OF_MEMORY;
- init_waitqueue_head(q);
- out = (u32 *) ¶m[0];
- *out = (u32) q;
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServWaitqDestroy(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- wait_queue_head_t *q;
- u32 *in;
- in = (u32 *) ¶m[0];
- q = (wait_queue_head_t *) *in;
- kfree(q);
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServWaitqWaitevent(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- wait_queue_head_t *q;
- u32 *in;
- u32 condition;
- in = (u32 *) ¶m[0];
- q = (wait_queue_head_t *) in[0];
- condition = in[1];
- wait_event(*q, condition);
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServWaitqWaiteventTimeout(u32 op,
- u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- wait_queue_head_t *q;
- u32 *in;
- u32 condition;
- long timeout;
- int *out;
- int ret;
- in = (u32 *) ¶m[0];
- q = (wait_queue_head_t *) in[0];
- condition = in[1];
- timeout = (long)in[2];
- ret = wait_event_timeout(*q, condition, timeout);
- out = (int *)¶m[0];
- *out = ret;
- return TZ_RESULT_SUCCESS;
- }
- TZ_RESULT KREE_ServWaitqWakeup(u32 op, u8 param[REE_SERVICE_BUFFER_SIZE])
- {
- wait_queue_head_t *q;
- u32 *in;
- in = (u32 *) ¶m[0];
- q = (wait_queue_head_t *) in[0];
- wake_up(q);
- return TZ_RESULT_SUCCESS;
- }
- #endif
|