nv-p2p.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* _NVRM_COPYRIGHT_BEGIN_
  2. *
  3. * Copyright 2011 by NVIDIA Corporation. All rights reserved. All
  4. * information contained herein is proprietary and confidential to NVIDIA
  5. * Corporation. Any use, reproduction, or disclosure without the written
  6. * permission of NVIDIA Corporation is prohibited.
  7. *
  8. * _NVRM_COPYRIGHT_END_
  9. */
  10. #ifndef _NV_P2P_H_
  11. #define _NV_P2P_H_
  12. enum {
  13. NVIDIA_P2P_ARCHITECTURE_TESLA = 0,
  14. NVIDIA_P2P_ARCHITECTURE_FERMI,
  15. NVIDIA_P2P_ARCHITECTURE_CURRENT = NVIDIA_P2P_ARCHITECTURE_FERMI
  16. };
  17. #define NVIDIA_P2P_PARAMS_VERSION 0x00010001
  18. enum {
  19. NVIDIA_P2P_PARAMS_ADDRESS_INDEX_GPU = 0,
  20. NVIDIA_P2P_PARAMS_ADDRESS_INDEX_THIRD_PARTY_DEVICE,
  21. NVIDIA_P2P_PARAMS_ADDRESS_INDEX_MAX = \
  22. NVIDIA_P2P_PARAMS_ADDRESS_INDEX_THIRD_PARTY_DEVICE
  23. };
  24. typedef
  25. struct nvidia_p2p_params {
  26. uint32_t version;
  27. uint32_t architecture;
  28. union nvidia_p2p_mailbox_addresses {
  29. struct {
  30. uint64_t wmb_addr;
  31. uint64_t wmb_data;
  32. uint64_t rreq_addr;
  33. uint64_t rcomp_addr;
  34. uint64_t reserved[2];
  35. } fermi;
  36. } addresses[NVIDIA_P2P_PARAMS_ADDRESS_INDEX_MAX+1];
  37. } nvidia_p2p_params_t;
  38. /*
  39. * @brief
  40. * Initializes a third-party P2P mapping between an NVIDIA
  41. * GPU and a third-party device.
  42. *
  43. * @param[in] p2p_token
  44. * A token that uniquely identifies the P2P mapping.
  45. * @param[in,out] params
  46. * A pointer to a structure with P2P mapping parameters.
  47. * @param[in] destroy_callback
  48. * A pointer to the function to be invoked when the P2P mapping
  49. * is destroyed implictly.
  50. * @param[in] data
  51. * An opaque pointer to private data to be passed to the
  52. * callback function.
  53. *
  54. * @return
  55. * 0 upon successful completion.
  56. * -EINVAL if an invalid argument was supplied.
  57. * -ENOTSUPP if the requested configuration is not supported.
  58. * -ENOMEM if the driver failed to allocate memory.
  59. * -EBUSY if the mapping has already been initialized.
  60. * -EIO if an unknown error occurred.
  61. */
  62. int nvidia_p2p_init_mapping(uint64_t p2p_token,
  63. struct nvidia_p2p_params *params,
  64. void (*destroy_callback)(void *data),
  65. void *data);
  66. /*
  67. * @brief
  68. * Tear down a previously initialized third-party P2P mapping.
  69. *
  70. * @param[in] p2p_token
  71. * A token that uniquely identifies the mapping.
  72. *
  73. * @return
  74. * 0 upon successful completion.
  75. * -EINVAL if an invalid argument was supplied.
  76. * -ENOTSUPP if the requested configuration is not supported.
  77. * -ENOMEM if the driver failed to allocate memory.
  78. */
  79. int nvidia_p2p_destroy_mapping(uint64_t p2p_token);
  80. enum {
  81. NVIDIA_P2P_PAGE_SIZE_4KB = 0,
  82. NVIDIA_P2P_PAGE_SIZE_64KB,
  83. NVIDIA_P2P_PAGE_SIZE_128KB
  84. };
  85. typedef
  86. struct nvidia_p2p_page {
  87. uint64_t physical_address;
  88. union nvidia_p2p_request_registers {
  89. struct {
  90. uint32_t wreqmb_h;
  91. uint32_t rreqmb_h;
  92. uint32_t rreqmb_0;
  93. uint32_t reserved[3];
  94. } fermi;
  95. } registers;
  96. } nvidia_p2p_page_t;
  97. #define NVIDIA_P2P_PAGE_TABLE_VERSION 0x00010001
  98. typedef
  99. struct nvidia_p2p_page_table {
  100. uint32_t version;
  101. uint32_t page_size;
  102. struct nvidia_p2p_page **pages;
  103. uint32_t entries;
  104. } nvidia_p2p_page_table_t;
  105. /*
  106. * @brief
  107. * Make the pages underlying a range of GPU virtual memory
  108. * accessible to a third-party device.
  109. *
  110. * @param[in] p2p_token
  111. * A token that uniquely identifies the P2P mapping.
  112. * @param[in] va_space
  113. * A GPU virtual address space qualifier.
  114. * @param[in] virtual_address
  115. * The start address in the specified virtual address space.
  116. * @param[in] length
  117. * The length of the requested P2P mapping.
  118. * @param[out] page_table
  119. * A pointer to an array of structures with P2P PTEs.
  120. * @param[in] free_callback
  121. * A pointer to the function to be invoked when the pages
  122. * underlying the virtual address range are freed
  123. * implicitly.
  124. * @param[in] data
  125. * An opaque pointer to private data to be passed to the
  126. * callback function.
  127. *
  128. * @return
  129. * 0 upon successful completion.
  130. * -EINVAL if an invalid argument was supplied.
  131. * -ENOTSUPP if the requested operation is not supported.
  132. * -ENOMEM if the driver failed to allocate memory or if
  133. * insufficient resources were available to complete the operation.
  134. * -EIO if an unknown error occurred.
  135. */
  136. int nvidia_p2p_get_pages(uint64_t p2p_token, uint32_t va_space,
  137. uint64_t virtual_address,
  138. uint64_t length,
  139. struct nvidia_p2p_page_table **page_table,
  140. void (*free_callback)(void *data),
  141. void *data);
  142. /*
  143. * @brief
  144. * Release a set of pages previously made accessible to
  145. * a third-party device.
  146. *
  147. * @param[in] p2p_token
  148. * A token that uniquely identifies the P2P mapping.
  149. * @param[in] va_space
  150. * A GPU virtual address space qualifier.
  151. * @param[in] virtual_address
  152. * The start address in the specified virtual address space.
  153. * @param[in] page_table
  154. * A pointer to the array of structures with P2P PTEs.
  155. *
  156. * @return
  157. * 0 upon successful completion.
  158. * -EINVAL if an invalid argument was supplied.
  159. * -EIO if an unknown error occurred.
  160. */
  161. int nvidia_p2p_put_pages(uint64_t p2p_token, uint32_t va_space,
  162. uint64_t virtual_address,
  163. struct nvidia_p2p_page_table *page_table);
  164. /*
  165. * @brief
  166. * Free a third-party P2P page table.
  167. *
  168. * @param[in] page_table
  169. * A pointer to the array of structures with P2P PTEs.
  170. *
  171. * @return
  172. * 0 upon successful completion.
  173. * -EINVAL if an invalid argument was supplied.
  174. */
  175. int nvidia_p2p_free_page_table(struct nvidia_p2p_page_table *page_table);
  176. #endif /* _NV_P2P_H_ */