1 /* 2 * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU) 3 * Licensed under the Mulan PSL v2. 4 * You can use this software according to the terms and conditions of the Mulan PSL v2. 5 * You may obtain a copy of Mulan PSL v2 at: 6 * http://license.coscl.org.cn/MulanPSL2 7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR 8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR 9 * PURPOSE. 10 * See the Mulan PSL v2 for more details. 11 */ 12 #ifndef IPC_CHANNEL_H 13 #define IPC_CHANNEL_H 14 15 #ifdef CHCORE_OH_TEE 16 17 #include <common/lock.h> 18 #include <object/thread.h> 19 #include <common/types.h> 20 21 /* declare that wait forever when receive msg */ 22 #define OS_WAIT_FOREVER 0xFFFFFFFF 23 24 /* declare that no wait when receiver msg */ 25 #define OS_NO_WAIT 0 26 27 #define NOTIFY_MAX_LEN 152 28 29 #define CH_CNT_MAX 2 30 #define E_EX_TIMER_TIMEOUT 0xff 31 32 enum message_msgtype { 33 MSG_TYPE_INVALID = 0, 34 MSG_TYPE_NOTIF = 1, 35 MSG_TYPE_CALL = 2, 36 }; 37 38 struct src_msginfo { 39 /* client's pid */ 40 u32 src_pid; 41 /* client's tid */ 42 u32 src_tid; 43 /* msg type(notification or call) */ 44 u16 msg_type; 45 }; 46 47 /* client's ipc context */ 48 struct client_msg_record { 49 struct src_msginfo info; 50 void *ksend_buf, *recv_buf; 51 size_t send_len, recv_len; 52 struct thread *client; 53 }; 54 55 /* server's ipc context */ 56 struct server_msg_record { 57 void *recv_buf; 58 size_t recv_len; 59 struct thread *server; 60 void *info; 61 }; 62 63 struct msg_entry { 64 struct list_head msg_queue_node; 65 struct client_msg_record client_msg_record; 66 }; 67 68 enum channel_state { CHANNEL_VALID, CHANNEL_INVALID }; 69 70 struct channel { 71 /* queue of waiting server threads */ 72 struct list_head thread_queue; 73 /* queue of message */ 74 struct list_head msg_queue; 75 struct lock lock; 76 /* Only creater can receive at this channel */ 77 struct cap_group *creater; 78 /* used to determine whether the channel is valid */ 79 int state; 80 }; 81 82 /* full context of current ipc */ 83 struct msg_hdl { 84 struct list_head thread_queue_node; 85 struct client_msg_record client_msg_record; 86 struct server_msg_record server_msg_record; 87 struct lock lock; 88 }; 89 90 int close_channel(struct channel *channel, struct cap_group *cap_group); 91 void channel_deinit(void *ptr); 92 void msg_hdl_deinit(void *ptr); 93 94 int sys_tee_msg_create_msg_hdl(void); 95 96 int sys_tee_msg_create_channel(void); 97 98 int sys_tee_msg_stop_channel(int channel_cap); 99 100 int sys_tee_msg_receive(int channel_cap, void *recv_buf, size_t recv_len, 101 int msg_hdl_cap, void *info, int timeout); 102 103 int sys_tee_msg_call(int channel_cap, void *send_buf, size_t send_len, 104 void *recv_buf, size_t recv_len, struct timespec *timeout); 105 int sys_tee_msg_reply(int msg_hdl_cap, void *reply_buf, size_t reply_len); 106 107 int sys_tee_msg_notify(int channel_cap, void *send_buf, size_t send_len); 108 109 #endif /* CHCORE_OH_TEE */ 110 111 #endif /* IPC_CHANNEL_H */