18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * VMware VMCI Driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2012 VMware, Inc. All rights reserved. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef _VMCI_QUEUE_PAIR_H_ 98c2ecf20Sopenharmony_ci#define _VMCI_QUEUE_PAIR_H_ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/vmw_vmci_defs.h> 128c2ecf20Sopenharmony_ci#include <linux/types.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include "vmci_context.h" 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* Callback needed for correctly waiting on events. */ 178c2ecf20Sopenharmony_citypedef int (*vmci_event_release_cb) (void *client_data); 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* Guest device port I/O. */ 208c2ecf20Sopenharmony_cistruct ppn_set { 218c2ecf20Sopenharmony_ci u64 num_produce_pages; 228c2ecf20Sopenharmony_ci u64 num_consume_pages; 238c2ecf20Sopenharmony_ci u64 *produce_ppns; 248c2ecf20Sopenharmony_ci u64 *consume_ppns; 258c2ecf20Sopenharmony_ci bool initialized; 268c2ecf20Sopenharmony_ci}; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* VMCIqueue_pairAllocInfo */ 298c2ecf20Sopenharmony_cistruct vmci_qp_alloc_info { 308c2ecf20Sopenharmony_ci struct vmci_handle handle; 318c2ecf20Sopenharmony_ci u32 peer; 328c2ecf20Sopenharmony_ci u32 flags; 338c2ecf20Sopenharmony_ci u64 produce_size; 348c2ecf20Sopenharmony_ci u64 consume_size; 358c2ecf20Sopenharmony_ci u64 ppn_va; /* Start VA of queue pair PPNs. */ 368c2ecf20Sopenharmony_ci u64 num_ppns; 378c2ecf20Sopenharmony_ci s32 result; 388c2ecf20Sopenharmony_ci u32 version; 398c2ecf20Sopenharmony_ci}; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* VMCIqueue_pairSetVAInfo */ 428c2ecf20Sopenharmony_cistruct vmci_qp_set_va_info { 438c2ecf20Sopenharmony_ci struct vmci_handle handle; 448c2ecf20Sopenharmony_ci u64 va; /* Start VA of queue pair PPNs. */ 458c2ecf20Sopenharmony_ci u64 num_ppns; 468c2ecf20Sopenharmony_ci u32 version; 478c2ecf20Sopenharmony_ci s32 result; 488c2ecf20Sopenharmony_ci}; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* 518c2ecf20Sopenharmony_ci * For backwards compatibility, here is a version of the 528c2ecf20Sopenharmony_ci * VMCIqueue_pairPageFileInfo before host support end-points was added. 538c2ecf20Sopenharmony_ci * Note that the current version of that structure requires VMX to 548c2ecf20Sopenharmony_ci * pass down the VA of the mapped file. Before host support was added 558c2ecf20Sopenharmony_ci * there was nothing of the sort. So, when the driver sees the ioctl 568c2ecf20Sopenharmony_ci * with a parameter that is the sizeof 578c2ecf20Sopenharmony_ci * VMCIqueue_pairPageFileInfo_NoHostQP then it can infer that the version 588c2ecf20Sopenharmony_ci * of VMX running can't attach to host end points because it doesn't 598c2ecf20Sopenharmony_ci * provide the VA of the mapped files. 608c2ecf20Sopenharmony_ci * 618c2ecf20Sopenharmony_ci * The Linux driver doesn't get an indication of the size of the 628c2ecf20Sopenharmony_ci * structure passed down from user space. So, to fix a long standing 638c2ecf20Sopenharmony_ci * but unfiled bug, the _pad field has been renamed to version. 648c2ecf20Sopenharmony_ci * Existing versions of VMX always initialize the PageFileInfo 658c2ecf20Sopenharmony_ci * structure so that _pad, er, version is set to 0. 668c2ecf20Sopenharmony_ci * 678c2ecf20Sopenharmony_ci * A version value of 1 indicates that the size of the structure has 688c2ecf20Sopenharmony_ci * been increased to include two UVA's: produce_uva and consume_uva. 698c2ecf20Sopenharmony_ci * These UVA's are of the mmap()'d queue contents backing files. 708c2ecf20Sopenharmony_ci * 718c2ecf20Sopenharmony_ci * In addition, if when VMX is sending down the 728c2ecf20Sopenharmony_ci * VMCIqueue_pairPageFileInfo structure it gets an error then it will 738c2ecf20Sopenharmony_ci * try again with the _NoHostQP version of the file to see if an older 748c2ecf20Sopenharmony_ci * VMCI kernel module is running. 758c2ecf20Sopenharmony_ci */ 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/* VMCIqueue_pairPageFileInfo */ 788c2ecf20Sopenharmony_cistruct vmci_qp_page_file_info { 798c2ecf20Sopenharmony_ci struct vmci_handle handle; 808c2ecf20Sopenharmony_ci u64 produce_page_file; /* User VA. */ 818c2ecf20Sopenharmony_ci u64 consume_page_file; /* User VA. */ 828c2ecf20Sopenharmony_ci u64 produce_page_file_size; /* Size of the file name array. */ 838c2ecf20Sopenharmony_ci u64 consume_page_file_size; /* Size of the file name array. */ 848c2ecf20Sopenharmony_ci s32 result; 858c2ecf20Sopenharmony_ci u32 version; /* Was _pad. */ 868c2ecf20Sopenharmony_ci u64 produce_va; /* User VA of the mapped file. */ 878c2ecf20Sopenharmony_ci u64 consume_va; /* User VA of the mapped file. */ 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci/* vmci queuepair detach info */ 918c2ecf20Sopenharmony_cistruct vmci_qp_dtch_info { 928c2ecf20Sopenharmony_ci struct vmci_handle handle; 938c2ecf20Sopenharmony_ci s32 result; 948c2ecf20Sopenharmony_ci u32 _pad; 958c2ecf20Sopenharmony_ci}; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci/* 988c2ecf20Sopenharmony_ci * struct vmci_qp_page_store describes how the memory of a given queue pair 998c2ecf20Sopenharmony_ci * is backed. When the queue pair is between the host and a guest, the 1008c2ecf20Sopenharmony_ci * page store consists of references to the guest pages. On vmkernel, 1018c2ecf20Sopenharmony_ci * this is a list of PPNs, and on hosted, it is a user VA where the 1028c2ecf20Sopenharmony_ci * queue pair is mapped into the VMX address space. 1038c2ecf20Sopenharmony_ci */ 1048c2ecf20Sopenharmony_cistruct vmci_qp_page_store { 1058c2ecf20Sopenharmony_ci /* Reference to pages backing the queue pair. */ 1068c2ecf20Sopenharmony_ci u64 pages; 1078c2ecf20Sopenharmony_ci /* Length of pageList/virtual addres range (in pages). */ 1088c2ecf20Sopenharmony_ci u32 len; 1098c2ecf20Sopenharmony_ci}; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci/* 1128c2ecf20Sopenharmony_ci * This data type contains the information about a queue. 1138c2ecf20Sopenharmony_ci * There are two queues (hence, queue pairs) per transaction model between a 1148c2ecf20Sopenharmony_ci * pair of end points, A & B. One queue is used by end point A to transmit 1158c2ecf20Sopenharmony_ci * commands and responses to B. The other queue is used by B to transmit 1168c2ecf20Sopenharmony_ci * commands and responses. 1178c2ecf20Sopenharmony_ci * 1188c2ecf20Sopenharmony_ci * struct vmci_queue_kern_if is a per-OS defined Queue structure. It contains 1198c2ecf20Sopenharmony_ci * either a direct pointer to the linear address of the buffer contents or a 1208c2ecf20Sopenharmony_ci * pointer to structures which help the OS locate those data pages. See 1218c2ecf20Sopenharmony_ci * vmciKernelIf.c for each platform for its definition. 1228c2ecf20Sopenharmony_ci */ 1238c2ecf20Sopenharmony_cistruct vmci_queue { 1248c2ecf20Sopenharmony_ci struct vmci_queue_header *q_header; 1258c2ecf20Sopenharmony_ci struct vmci_queue_header *saved_header; 1268c2ecf20Sopenharmony_ci struct vmci_queue_kern_if *kernel_if; 1278c2ecf20Sopenharmony_ci}; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci/* 1308c2ecf20Sopenharmony_ci * Utility function that checks whether the fields of the page 1318c2ecf20Sopenharmony_ci * store contain valid values. 1328c2ecf20Sopenharmony_ci * Result: 1338c2ecf20Sopenharmony_ci * true if the page store is wellformed. false otherwise. 1348c2ecf20Sopenharmony_ci */ 1358c2ecf20Sopenharmony_cistatic inline bool 1368c2ecf20Sopenharmony_ciVMCI_QP_PAGESTORE_IS_WELLFORMED(struct vmci_qp_page_store *page_store) 1378c2ecf20Sopenharmony_ci{ 1388c2ecf20Sopenharmony_ci return page_store->len >= 2; 1398c2ecf20Sopenharmony_ci} 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_civoid vmci_qp_broker_exit(void); 1428c2ecf20Sopenharmony_ciint vmci_qp_broker_alloc(struct vmci_handle handle, u32 peer, 1438c2ecf20Sopenharmony_ci u32 flags, u32 priv_flags, 1448c2ecf20Sopenharmony_ci u64 produce_size, u64 consume_size, 1458c2ecf20Sopenharmony_ci struct vmci_qp_page_store *page_store, 1468c2ecf20Sopenharmony_ci struct vmci_ctx *context); 1478c2ecf20Sopenharmony_ciint vmci_qp_broker_set_page_store(struct vmci_handle handle, 1488c2ecf20Sopenharmony_ci u64 produce_uva, u64 consume_uva, 1498c2ecf20Sopenharmony_ci struct vmci_ctx *context); 1508c2ecf20Sopenharmony_ciint vmci_qp_broker_detach(struct vmci_handle handle, struct vmci_ctx *context); 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_civoid vmci_qp_guest_endpoints_exit(void); 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ciint vmci_qp_alloc(struct vmci_handle *handle, 1558c2ecf20Sopenharmony_ci struct vmci_queue **produce_q, u64 produce_size, 1568c2ecf20Sopenharmony_ci struct vmci_queue **consume_q, u64 consume_size, 1578c2ecf20Sopenharmony_ci u32 peer, u32 flags, u32 priv_flags, 1588c2ecf20Sopenharmony_ci bool guest_endpoint, vmci_event_release_cb wakeup_cb, 1598c2ecf20Sopenharmony_ci void *client_data); 1608c2ecf20Sopenharmony_ciint vmci_qp_broker_map(struct vmci_handle handle, 1618c2ecf20Sopenharmony_ci struct vmci_ctx *context, u64 guest_mem); 1628c2ecf20Sopenharmony_ciint vmci_qp_broker_unmap(struct vmci_handle handle, 1638c2ecf20Sopenharmony_ci struct vmci_ctx *context, u32 gid); 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci#endif /* _VMCI_QUEUE_PAIR_H_ */ 166