Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * VMware VMCI Driver
0004  *
0005  * Copyright (C) 2012 VMware, Inc. All rights reserved.
0006  */
0007 
0008 #ifndef _VMCI_QUEUE_PAIR_H_
0009 #define _VMCI_QUEUE_PAIR_H_
0010 
0011 #include <linux/vmw_vmci_defs.h>
0012 #include <linux/types.h>
0013 
0014 #include "vmci_context.h"
0015 
0016 /* Callback needed for correctly waiting on events. */
0017 typedef int (*vmci_event_release_cb) (void *client_data);
0018 
0019 /* Guest device port I/O. */
0020 struct ppn_set {
0021     u64 num_produce_pages;
0022     u64 num_consume_pages;
0023     u64 *produce_ppns;
0024     u64 *consume_ppns;
0025     bool initialized;
0026 };
0027 
0028 /* VMCIqueue_pairAllocInfo */
0029 struct vmci_qp_alloc_info {
0030     struct vmci_handle handle;
0031     u32 peer;
0032     u32 flags;
0033     u64 produce_size;
0034     u64 consume_size;
0035     u64 ppn_va; /* Start VA of queue pair PPNs. */
0036     u64 num_ppns;
0037     s32 result;
0038     u32 version;
0039 };
0040 
0041 /* VMCIqueue_pairSetVAInfo */
0042 struct vmci_qp_set_va_info {
0043     struct vmci_handle handle;
0044     u64 va;     /* Start VA of queue pair PPNs. */
0045     u64 num_ppns;
0046     u32 version;
0047     s32 result;
0048 };
0049 
0050 /*
0051  * For backwards compatibility, here is a version of the
0052  * VMCIqueue_pairPageFileInfo before host support end-points was added.
0053  * Note that the current version of that structure requires VMX to
0054  * pass down the VA of the mapped file.  Before host support was added
0055  * there was nothing of the sort.  So, when the driver sees the ioctl
0056  * with a parameter that is the sizeof
0057  * VMCIqueue_pairPageFileInfo_NoHostQP then it can infer that the version
0058  * of VMX running can't attach to host end points because it doesn't
0059  * provide the VA of the mapped files.
0060  *
0061  * The Linux driver doesn't get an indication of the size of the
0062  * structure passed down from user space.  So, to fix a long standing
0063  * but unfiled bug, the _pad field has been renamed to version.
0064  * Existing versions of VMX always initialize the PageFileInfo
0065  * structure so that _pad, er, version is set to 0.
0066  *
0067  * A version value of 1 indicates that the size of the structure has
0068  * been increased to include two UVA's: produce_uva and consume_uva.
0069  * These UVA's are of the mmap()'d queue contents backing files.
0070  *
0071  * In addition, if when VMX is sending down the
0072  * VMCIqueue_pairPageFileInfo structure it gets an error then it will
0073  * try again with the _NoHostQP version of the file to see if an older
0074  * VMCI kernel module is running.
0075  */
0076 
0077 /* VMCIqueue_pairPageFileInfo */
0078 struct vmci_qp_page_file_info {
0079     struct vmci_handle handle;
0080     u64 produce_page_file;    /* User VA. */
0081     u64 consume_page_file;    /* User VA. */
0082     u64 produce_page_file_size;  /* Size of the file name array. */
0083     u64 consume_page_file_size;  /* Size of the file name array. */
0084     s32 result;
0085     u32 version;    /* Was _pad. */
0086     u64 produce_va; /* User VA of the mapped file. */
0087     u64 consume_va; /* User VA of the mapped file. */
0088 };
0089 
0090 /* vmci queuepair detach info */
0091 struct vmci_qp_dtch_info {
0092     struct vmci_handle handle;
0093     s32 result;
0094     u32 _pad;
0095 };
0096 
0097 /*
0098  * struct vmci_qp_page_store describes how the memory of a given queue pair
0099  * is backed. When the queue pair is between the host and a guest, the
0100  * page store consists of references to the guest pages. On vmkernel,
0101  * this is a list of PPNs, and on hosted, it is a user VA where the
0102  * queue pair is mapped into the VMX address space.
0103  */
0104 struct vmci_qp_page_store {
0105     /* Reference to pages backing the queue pair. */
0106     u64 pages;
0107     /* Length of pageList/virtual address range (in pages). */
0108     u32 len;
0109 };
0110 
0111 /*
0112  * This data type contains the information about a queue.
0113  * There are two queues (hence, queue pairs) per transaction model between a
0114  * pair of end points, A & B.  One queue is used by end point A to transmit
0115  * commands and responses to B.  The other queue is used by B to transmit
0116  * commands and responses.
0117  *
0118  * struct vmci_queue_kern_if is a per-OS defined Queue structure.  It contains
0119  * either a direct pointer to the linear address of the buffer contents or a
0120  * pointer to structures which help the OS locate those data pages.  See
0121  * vmciKernelIf.c for each platform for its definition.
0122  */
0123 struct vmci_queue {
0124     struct vmci_queue_header *q_header;
0125     struct vmci_queue_header *saved_header;
0126     struct vmci_queue_kern_if *kernel_if;
0127 };
0128 
0129 /*
0130  * Utility function that checks whether the fields of the page
0131  * store contain valid values.
0132  * Result:
0133  * true if the page store is wellformed. false otherwise.
0134  */
0135 static inline bool
0136 VMCI_QP_PAGESTORE_IS_WELLFORMED(struct vmci_qp_page_store *page_store)
0137 {
0138     return page_store->len >= 2;
0139 }
0140 
0141 void vmci_qp_broker_exit(void);
0142 int vmci_qp_broker_alloc(struct vmci_handle handle, u32 peer,
0143              u32 flags, u32 priv_flags,
0144              u64 produce_size, u64 consume_size,
0145              struct vmci_qp_page_store *page_store,
0146              struct vmci_ctx *context);
0147 int vmci_qp_broker_set_page_store(struct vmci_handle handle,
0148                   u64 produce_uva, u64 consume_uva,
0149                   struct vmci_ctx *context);
0150 int vmci_qp_broker_detach(struct vmci_handle handle, struct vmci_ctx *context);
0151 
0152 void vmci_qp_guest_endpoints_exit(void);
0153 
0154 int vmci_qp_alloc(struct vmci_handle *handle,
0155           struct vmci_queue **produce_q, u64 produce_size,
0156           struct vmci_queue **consume_q, u64 consume_size,
0157           u32 peer, u32 flags, u32 priv_flags,
0158           bool guest_endpoint, vmci_event_release_cb wakeup_cb,
0159           void *client_data);
0160 int vmci_qp_broker_map(struct vmci_handle handle,
0161                struct vmci_ctx *context, u64 guest_mem);
0162 int vmci_qp_broker_unmap(struct vmci_handle handle,
0163              struct vmci_ctx *context, u32 gid);
0164 
0165 #endif /* _VMCI_QUEUE_PAIR_H_ */