| 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* |
| 3 | * VMware VMCI Driver |
| 4 | * |
| 5 | * Copyright (C) 2012 VMware, Inc. All rights reserved. |
| 6 | */ |
| 7 | |
| 8 | #ifndef _VMCI_QUEUE_PAIR_H_ |
| 9 | #define _VMCI_QUEUE_PAIR_H_ |
| 10 | |
| 11 | #include <linux/vmw_vmci_defs.h> |
| 12 | #include <linux/types.h> |
| 13 | |
| 14 | #include "vmci_context.h" |
| 15 | |
| 16 | /* Callback needed for correctly waiting on events. */ |
| 17 | typedef int (*vmci_event_release_cb) (void *client_data); |
| 18 | |
| 19 | /* Guest device port I/O. */ |
| 20 | struct ppn_set { |
| 21 | u64 num_produce_pages; |
| 22 | u64 num_consume_pages; |
| 23 | u64 *produce_ppns; |
| 24 | u64 *consume_ppns; |
| 25 | bool initialized; |
| 26 | }; |
| 27 | |
| 28 | /* VMCIqueue_pairAllocInfo */ |
| 29 | struct vmci_qp_alloc_info { |
| 30 | struct vmci_handle handle; |
| 31 | u32 peer; |
| 32 | u32 flags; |
| 33 | u64 produce_size; |
| 34 | u64 consume_size; |
| 35 | u64 ppn_va; /* Start VA of queue pair PPNs. */ |
| 36 | u64 num_ppns; |
| 37 | s32 result; |
| 38 | u32 version; |
| 39 | }; |
| 40 | |
| 41 | /* VMCIqueue_pairSetVAInfo */ |
| 42 | struct vmci_qp_set_va_info { |
| 43 | struct vmci_handle handle; |
| 44 | u64 va; /* Start VA of queue pair PPNs. */ |
| 45 | u64 num_ppns; |
| 46 | u32 version; |
| 47 | s32 result; |
| 48 | }; |
| 49 | |
| 50 | /* |
| 51 | * For backwards compatibility, here is a version of the |
| 52 | * VMCIqueue_pairPageFileInfo before host support end-points was added. |
| 53 | * Note that the current version of that structure requires VMX to |
| 54 | * pass down the VA of the mapped file. Before host support was added |
| 55 | * there was nothing of the sort. So, when the driver sees the ioctl |
| 56 | * with a parameter that is the sizeof |
| 57 | * VMCIqueue_pairPageFileInfo_NoHostQP then it can infer that the version |
| 58 | * of VMX running can't attach to host end points because it doesn't |
| 59 | * provide the VA of the mapped files. |
| 60 | * |
| 61 | * The Linux driver doesn't get an indication of the size of the |
| 62 | * structure passed down from user space. So, to fix a long standing |
| 63 | * but unfiled bug, the _pad field has been renamed to version. |
| 64 | * Existing versions of VMX always initialize the PageFileInfo |
| 65 | * structure so that _pad, er, version is set to 0. |
| 66 | * |
| 67 | * A version value of 1 indicates that the size of the structure has |
| 68 | * been increased to include two UVA's: produce_uva and consume_uva. |
| 69 | * These UVA's are of the mmap()'d queue contents backing files. |
| 70 | * |
| 71 | * In addition, if when VMX is sending down the |
| 72 | * VMCIqueue_pairPageFileInfo structure it gets an error then it will |
| 73 | * try again with the _NoHostQP version of the file to see if an older |
| 74 | * VMCI kernel module is running. |
| 75 | */ |
| 76 | |
| 77 | /* VMCIqueue_pairPageFileInfo */ |
| 78 | struct vmci_qp_page_file_info { |
| 79 | struct vmci_handle handle; |
| 80 | u64 produce_page_file; /* User VA. */ |
| 81 | u64 consume_page_file; /* User VA. */ |
| 82 | u64 produce_page_file_size; /* Size of the file name array. */ |
| 83 | u64 consume_page_file_size; /* Size of the file name array. */ |
| 84 | s32 result; |
| 85 | u32 version; /* Was _pad. */ |
| 86 | u64 produce_va; /* User VA of the mapped file. */ |
| 87 | u64 consume_va; /* User VA of the mapped file. */ |
| 88 | }; |
| 89 | |
| 90 | /* vmci queuepair detach info */ |
| 91 | struct vmci_qp_dtch_info { |
| 92 | struct vmci_handle handle; |
| 93 | s32 result; |
| 94 | u32 _pad; |
| 95 | }; |
| 96 | |
| 97 | /* |
| 98 | * struct vmci_qp_page_store describes how the memory of a given queue pair |
| 99 | * is backed. When the queue pair is between the host and a guest, the |
| 100 | * page store consists of references to the guest pages. On vmkernel, |
| 101 | * this is a list of PPNs, and on hosted, it is a user VA where the |
| 102 | * queue pair is mapped into the VMX address space. |
| 103 | */ |
| 104 | struct vmci_qp_page_store { |
| 105 | /* Reference to pages backing the queue pair. */ |
| 106 | u64 pages; |
| 107 | /* Length of pageList/virtual addres range (in pages). */ |
| 108 | u32 len; |
| 109 | }; |
| 110 | |
| 111 | /* |
| 112 | * This data type contains the information about a queue. |
| 113 | * There are two queues (hence, queue pairs) per transaction model between a |
| 114 | * pair of end points, A & B. One queue is used by end point A to transmit |
| 115 | * commands and responses to B. The other queue is used by B to transmit |
| 116 | * commands and responses. |
| 117 | * |
| 118 | * struct vmci_queue_kern_if is a per-OS defined Queue structure. It contains |
| 119 | * either a direct pointer to the linear address of the buffer contents or a |
| 120 | * pointer to structures which help the OS locate those data pages. See |
| 121 | * vmciKernelIf.c for each platform for its definition. |
| 122 | */ |
| 123 | struct vmci_queue { |
| 124 | struct vmci_queue_header *q_header; |
| 125 | struct vmci_queue_header *saved_header; |
| 126 | struct vmci_queue_kern_if *kernel_if; |
| 127 | }; |
| 128 | |
| 129 | /* |
| 130 | * Utility function that checks whether the fields of the page |
| 131 | * store contain valid values. |
| 132 | * Result: |
| 133 | * true if the page store is wellformed. false otherwise. |
| 134 | */ |
| 135 | static inline bool |
| 136 | VMCI_QP_PAGESTORE_IS_WELLFORMED(struct vmci_qp_page_store *page_store) |
| 137 | { |
| 138 | return page_store->len >= 2; |
| 139 | } |
| 140 | |
| 141 | void vmci_qp_broker_exit(void); |
| 142 | int vmci_qp_broker_alloc(struct vmci_handle handle, u32 peer, |
| 143 | u32 flags, u32 priv_flags, |
| 144 | u64 produce_size, u64 consume_size, |
| 145 | struct vmci_qp_page_store *page_store, |
| 146 | struct vmci_ctx *context); |
| 147 | int vmci_qp_broker_set_page_store(struct vmci_handle handle, |
| 148 | u64 produce_uva, u64 consume_uva, |
| 149 | struct vmci_ctx *context); |
| 150 | int vmci_qp_broker_detach(struct vmci_handle handle, struct vmci_ctx *context); |
| 151 | |
| 152 | void vmci_qp_guest_endpoints_exit(void); |
| 153 | |
| 154 | int vmci_qp_alloc(struct vmci_handle *handle, |
| 155 | struct vmci_queue **produce_q, u64 produce_size, |
| 156 | struct vmci_queue **consume_q, u64 consume_size, |
| 157 | u32 peer, u32 flags, u32 priv_flags, |
| 158 | bool guest_endpoint, vmci_event_release_cb wakeup_cb, |
| 159 | void *client_data); |
| 160 | int vmci_qp_broker_map(struct vmci_handle handle, |
| 161 | struct vmci_ctx *context, u64 guest_mem); |
| 162 | int vmci_qp_broker_unmap(struct vmci_handle handle, |
| 163 | struct vmci_ctx *context, u32 gid); |
| 164 | |
| 165 | #endif /* _VMCI_QUEUE_PAIR_H_ */ |