1 /* 2 * Copyright (c) 2013, Google, Inc. All rights reserved 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files 6 * (the "Software"), to deal in the Software without restriction, 7 * including without limitation the rights to use, copy, modify, merge, 8 * publish, distribute, sublicense, and/or sell copies of the Software, 9 * and to permit persons to whom the Software is furnished to do so, 10 * subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24 #pragma once 25 26 #include <kernel/usercopy.h> 27 #include <stdbool.h> 28 #include <stdint.h> 29 #include <sys/types.h> 30 #include <uapi/trusty_ipc.h> 31 32 #include <lib/trusty/uctx.h> 33 #include <lib/trusty/uio.h> 34 35 __BEGIN_CDECLS 36 37 struct ipc_msg_queue; 38 int ipc_msg_queue_create(uint num_items, 39 size_t item_sz, 40 struct ipc_msg_queue** mq); 41 void ipc_msg_queue_destroy(struct ipc_msg_queue* mq); 42 43 bool ipc_msg_queue_is_empty(struct ipc_msg_queue* mq); 44 bool ipc_msg_queue_is_full(struct ipc_msg_queue* mq); 45 46 /********** these structure definitions shared with userspace **********/ 47 48 /* The layout for iovec_user and ipc_msg_user MUST match 49 * the layout of iovec_kern and ipc_msg_kern 50 */ 51 #define MAX_MSG_HANDLES IPC_MAX_MSG_HANDLES 52 53 struct ipc_msg_kern { 54 uint32_t num_iov; 55 struct iovec_kern* iov; 56 57 uint32_t num_handles; 58 struct handle** handles; 59 }; 60 61 struct ipc_msg_user { 62 uint32_t num_iov; 63 user_addr_t iov; 64 65 uint32_t num_handles; 66 user_addr_t handles; /* points to array of handle ids */ 67 }; 68 69 struct ipc_msg_info { 70 size_t len; 71 uint32_t id; 72 uint32_t num_handles; 73 }; 74 75 struct ipc_msg_info_user { 76 user_size_t len; 77 uint32_t id; 78 uint32_t num_handles; 79 }; 80 81 int ipc_get_msg(struct handle* chandle, struct ipc_msg_info* msg_info); 82 int ipc_read_msg(struct handle* chandle, 83 uint32_t msg_id, 84 uint32_t offset, 85 struct ipc_msg_kern* msg); 86 int ipc_put_msg(struct handle* chandle, uint32_t msg_id); 87 int ipc_send_msg(struct handle* chandle, struct ipc_msg_kern* msg); 88 89 __END_CDECLS 90