1 /* 2 * Copyright (c) 2014-2015, 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 <arch/defines.h> 27 #include <lib/trusty/uuid.h> 28 #include <remoteproc/remoteproc.h> 29 #include <sys/types.h> 30 31 struct tipc_dev; 32 33 struct trusty_virtio_bus; 34 35 /* 36 * This ID has to match to the value defined in virtio_ids.h on Linux side 37 */ 38 #define VIRTIO_ID_TIPC (13) 39 40 /* 41 * TIPC device supports 2 vqueues: TX and RX 42 */ 43 #define TIPC_VQ_TX (0) 44 #define TIPC_VQ_RX (1) 45 #define TIPC_VQ_NUM (2) 46 47 /* 48 * Maximum device name size 49 */ 50 #define TIPC_MAX_DEV_NAME_LEN (32) 51 52 /* 53 * Trusty IPC device configuration shared with linux side 54 */ 55 struct tipc_dev_config { 56 uint32_t msg_buf_max_size; /* max msg size that this device can handle */ 57 uint32_t msg_buf_alignment; /* required msg alignment (PAGE_SIZE) */ 58 char dev_name[TIPC_MAX_DEV_NAME_LEN]; /* NS device node name */ 59 } __PACKED; 60 61 struct tipc_vdev_descr { 62 struct fw_rsc_hdr hdr; 63 struct fw_rsc_vdev vdev; 64 struct fw_rsc_vdev_vring vrings[TIPC_VQ_NUM]; 65 struct tipc_dev_config config; 66 } __PACKED; 67 68 #define DECLARE_TIPC_DEVICE_DESCR(_nm, _nid, _txvq_sz, _rxvq_sz, _nd_name) \ 69 static const struct tipc_vdev_descr _nm = { \ 70 .hdr.type = RSC_VDEV, \ 71 .vdev = {.id = VIRTIO_ID_TIPC, \ 72 .notifyid = _nid, \ 73 .dfeatures = 0, \ 74 .config_len = sizeof(struct tipc_dev_config), \ 75 .num_of_vrings = TIPC_VQ_NUM}, \ 76 .vrings = {[TIPC_VQ_TX] = {.align = PAGE_SIZE, \ 77 .num = (_txvq_sz), \ 78 .notifyid = 1}, \ 79 [TIPC_VQ_RX] = {.align = PAGE_SIZE, \ 80 .num = (_rxvq_sz), \ 81 .notifyid = 2}}, \ 82 .config = {.msg_buf_max_size = PAGE_SIZE, \ 83 .msg_buf_alignment = PAGE_SIZE, \ 84 .dev_name = _nd_name}}; 85 86 /* 87 * Create TIPC device and register it witth virtio subsystem 88 */ 89 status_t create_tipc_device(struct trusty_virtio_bus* vb, 90 const struct tipc_vdev_descr* descr, 91 size_t descr_sz, 92 const uuid_t* uuid, 93 struct tipc_dev** dev_ptr); 94 95 /** 96 * tipc_ext_mem_vmm_obj_to_ext_mem_vmm_obj - Get inner ext_mem vmm_obj 97 * @obj: Pointer to a vmm_obj believed to point to external memory. 98 * 99 * Reflects through the tipc_ext_mem vmm_obj to find an ext_mem vmm_obj and 100 * returns it if possible. 101 * 102 * Return: If the provided vmm_obj is a tipc wrapped external memory object, 103 * returns the external memory vmm_obj pointer. Otherwise, returns NULL. 104 */ 105 struct vmm_obj* tipc_ext_mem_vmm_obj_to_ext_mem_vmm_obj(struct vmm_obj* obj); 106