David Hu | 69e590e | 2020-05-12 17:19:21 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2020-2021, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * This file is a reference implementation of Non-secure mailbox RTOS API. |
| 10 | * This reference implementation is based on TF-M ROTS wrapper API. |
| 11 | * It can be replaced by RTOS specific implementation. |
| 12 | */ |
| 13 | |
| 14 | #include "os_wrapper/semaphore.h" |
| 15 | #include "os_wrapper/thread.h" |
| 16 | |
| 17 | #include "tfm_ns_mailbox.h" |
| 18 | |
| 19 | #define MAX_SEMAPHORE_COUNT NUM_MAILBOX_QUEUE_SLOT |
| 20 | |
| 21 | static void *ns_lock_handle = NULL; |
| 22 | |
| 23 | #ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL |
| 24 | const void *tfm_ns_mailbox_os_get_task_handle(void) |
| 25 | { |
| 26 | return os_wrapper_thread_get_handle(); |
| 27 | } |
| 28 | |
| 29 | void tfm_ns_mailbox_os_wait_reply(mailbox_msg_handle_t handle) |
| 30 | { |
| 31 | os_wrapper_thread_wait_flag((uint32_t)handle, OS_WRAPPER_WAIT_FOREVER); |
| 32 | } |
| 33 | |
| 34 | void tfm_ns_mailbox_os_wake_task_isr(const void *task_handle, |
| 35 | mailbox_msg_handle_t handle) |
| 36 | { |
| 37 | os_wrapper_thread_set_flag_isr((void *)task_handle, (uint32_t)handle); |
| 38 | } |
| 39 | #endif /* TFM_MULTI_CORE_MULTI_CLIENT_CALL */ |
| 40 | |
| 41 | int32_t tfm_ns_mailbox_os_lock_init(void) |
| 42 | { |
| 43 | ns_lock_handle = os_wrapper_semaphore_create(MAX_SEMAPHORE_COUNT, |
| 44 | MAX_SEMAPHORE_COUNT, |
| 45 | NULL); |
| 46 | if (!ns_lock_handle) { |
| 47 | return MAILBOX_GENERIC_ERROR; |
| 48 | } |
| 49 | |
| 50 | return MAILBOX_SUCCESS; |
| 51 | } |
| 52 | |
| 53 | int32_t tfm_ns_mailbox_os_lock_acquire(void) |
| 54 | { |
| 55 | return os_wrapper_semaphore_acquire(ns_lock_handle, |
| 56 | OS_WRAPPER_WAIT_FOREVER); |
| 57 | } |
| 58 | |
| 59 | int32_t tfm_ns_mailbox_os_lock_release(void) |
| 60 | { |
| 61 | return os_wrapper_semaphore_release(ns_lock_handle); |
| 62 | } |