vmci_queue_pair.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * VMware VMCI Driver
  3. *
  4. * Copyright (C) 2012 VMware, Inc. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation version 2 and no later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. */
  15. #ifndef _VMCI_QUEUE_PAIR_H_
  16. #define _VMCI_QUEUE_PAIR_H_
  17. #include <linux/vmw_vmci_defs.h>
  18. #include <linux/types.h>
  19. #include "vmci_context.h"
  20. /* Callback needed for correctly waiting on events. */
  21. typedef int (*vmci_event_release_cb) (void *client_data);
  22. /* Guest device port I/O. */
  23. struct ppn_set {
  24. u64 num_produce_pages;
  25. u64 num_consume_pages;
  26. u32 *produce_ppns;
  27. u32 *consume_ppns;
  28. bool initialized;
  29. };
  30. /* VMCIqueue_pairAllocInfo */
  31. struct vmci_qp_alloc_info {
  32. struct vmci_handle handle;
  33. u32 peer;
  34. u32 flags;
  35. u64 produce_size;
  36. u64 consume_size;
  37. u64 ppn_va; /* Start VA of queue pair PPNs. */
  38. u64 num_ppns;
  39. s32 result;
  40. u32 version;
  41. };
  42. /* VMCIqueue_pairSetVAInfo */
  43. struct vmci_qp_set_va_info {
  44. struct vmci_handle handle;
  45. u64 va; /* Start VA of queue pair PPNs. */
  46. u64 num_ppns;
  47. u32 version;
  48. s32 result;
  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. /* VMCIqueue_pairPageFileInfo */
  77. struct vmci_qp_page_file_info {
  78. struct vmci_handle handle;
  79. u64 produce_page_file; /* User VA. */
  80. u64 consume_page_file; /* User VA. */
  81. u64 produce_page_file_size; /* Size of the file name array. */
  82. u64 consume_page_file_size; /* Size of the file name array. */
  83. s32 result;
  84. u32 version; /* Was _pad. */
  85. u64 produce_va; /* User VA of the mapped file. */
  86. u64 consume_va; /* User VA of the mapped file. */
  87. };
  88. /* vmci queuepair detach info */
  89. struct vmci_qp_dtch_info {
  90. struct vmci_handle handle;
  91. s32 result;
  92. u32 _pad;
  93. };
  94. /*
  95. * struct vmci_qp_page_store describes how the memory of a given queue pair
  96. * is backed. When the queue pair is between the host and a guest, the
  97. * page store consists of references to the guest pages. On vmkernel,
  98. * this is a list of PPNs, and on hosted, it is a user VA where the
  99. * queue pair is mapped into the VMX address space.
  100. */
  101. struct vmci_qp_page_store {
  102. /* Reference to pages backing the queue pair. */
  103. u64 pages;
  104. /* Length of pageList/virtual addres range (in pages). */
  105. u32 len;
  106. };
  107. /*
  108. * This data type contains the information about a queue.
  109. * There are two queues (hence, queue pairs) per transaction model between a
  110. * pair of end points, A & B. One queue is used by end point A to transmit
  111. * commands and responses to B. The other queue is used by B to transmit
  112. * commands and responses.
  113. *
  114. * struct vmci_queue_kern_if is a per-OS defined Queue structure. It contains
  115. * either a direct pointer to the linear address of the buffer contents or a
  116. * pointer to structures which help the OS locate those data pages. See
  117. * vmciKernelIf.c for each platform for its definition.
  118. */
  119. struct vmci_queue {
  120. struct vmci_queue_header *q_header;
  121. struct vmci_queue_header *saved_header;
  122. struct vmci_queue_kern_if *kernel_if;
  123. };
  124. /*
  125. * Utility function that checks whether the fields of the page
  126. * store contain valid values.
  127. * Result:
  128. * true if the page store is wellformed. false otherwise.
  129. */
  130. static inline bool
  131. VMCI_QP_PAGESTORE_IS_WELLFORMED(struct vmci_qp_page_store *page_store)
  132. {
  133. return page_store->len >= 2;
  134. }
  135. void vmci_qp_broker_exit(void);
  136. int vmci_qp_broker_alloc(struct vmci_handle handle, u32 peer,
  137. u32 flags, u32 priv_flags,
  138. u64 produce_size, u64 consume_size,
  139. struct vmci_qp_page_store *page_store,
  140. struct vmci_ctx *context);
  141. int vmci_qp_broker_set_page_store(struct vmci_handle handle,
  142. u64 produce_uva, u64 consume_uva,
  143. struct vmci_ctx *context);
  144. int vmci_qp_broker_detach(struct vmci_handle handle, struct vmci_ctx *context);
  145. void vmci_qp_guest_endpoints_exit(void);
  146. int vmci_qp_alloc(struct vmci_handle *handle,
  147. struct vmci_queue **produce_q, u64 produce_size,
  148. struct vmci_queue **consume_q, u64 consume_size,
  149. u32 peer, u32 flags, u32 priv_flags,
  150. bool guest_endpoint, vmci_event_release_cb wakeup_cb,
  151. void *client_data);
  152. int vmci_qp_broker_map(struct vmci_handle handle,
  153. struct vmci_ctx *context, u64 guest_mem);
  154. int vmci_qp_broker_unmap(struct vmci_handle handle,
  155. struct vmci_ctx *context, u32 gid);
  156. #endif /* _VMCI_QUEUE_PAIR_H_ */