vmci_queue_pair.h 5.3 KB

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