kfd_ioctl.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * Copyright 2014 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #ifndef KFD_IOCTL_H_INCLUDED
  23. #define KFD_IOCTL_H_INCLUDED
  24. #include <linux/types.h>
  25. #include <linux/ioctl.h>
  26. #define KFD_IOCTL_MAJOR_VERSION 1
  27. #define KFD_IOCTL_MINOR_VERSION 1
  28. struct kfd_ioctl_get_version_args {
  29. uint32_t major_version; /* from KFD */
  30. uint32_t minor_version; /* from KFD */
  31. };
  32. /* For kfd_ioctl_create_queue_args.queue_type. */
  33. #define KFD_IOC_QUEUE_TYPE_COMPUTE 0
  34. #define KFD_IOC_QUEUE_TYPE_SDMA 1
  35. #define KFD_IOC_QUEUE_TYPE_COMPUTE_AQL 2
  36. #define KFD_MAX_QUEUE_PERCENTAGE 100
  37. #define KFD_MAX_QUEUE_PRIORITY 15
  38. struct kfd_ioctl_create_queue_args {
  39. uint64_t ring_base_address; /* to KFD */
  40. uint64_t write_pointer_address; /* from KFD */
  41. uint64_t read_pointer_address; /* from KFD */
  42. uint64_t doorbell_offset; /* from KFD */
  43. uint32_t ring_size; /* to KFD */
  44. uint32_t gpu_id; /* to KFD */
  45. uint32_t queue_type; /* to KFD */
  46. uint32_t queue_percentage; /* to KFD */
  47. uint32_t queue_priority; /* to KFD */
  48. uint32_t queue_id; /* from KFD */
  49. uint64_t eop_buffer_address; /* to KFD */
  50. uint64_t eop_buffer_size; /* to KFD */
  51. uint64_t ctx_save_restore_address; /* to KFD */
  52. uint64_t ctx_save_restore_size; /* to KFD */
  53. };
  54. struct kfd_ioctl_destroy_queue_args {
  55. uint32_t queue_id; /* to KFD */
  56. uint32_t pad;
  57. };
  58. struct kfd_ioctl_update_queue_args {
  59. uint64_t ring_base_address; /* to KFD */
  60. uint32_t queue_id; /* to KFD */
  61. uint32_t ring_size; /* to KFD */
  62. uint32_t queue_percentage; /* to KFD */
  63. uint32_t queue_priority; /* to KFD */
  64. };
  65. /* For kfd_ioctl_set_memory_policy_args.default_policy and alternate_policy */
  66. #define KFD_IOC_CACHE_POLICY_COHERENT 0
  67. #define KFD_IOC_CACHE_POLICY_NONCOHERENT 1
  68. struct kfd_ioctl_set_memory_policy_args {
  69. uint64_t alternate_aperture_base; /* to KFD */
  70. uint64_t alternate_aperture_size; /* to KFD */
  71. uint32_t gpu_id; /* to KFD */
  72. uint32_t default_policy; /* to KFD */
  73. uint32_t alternate_policy; /* to KFD */
  74. uint32_t pad;
  75. };
  76. /*
  77. * All counters are monotonic. They are used for profiling of compute jobs.
  78. * The profiling is done by userspace.
  79. *
  80. * In case of GPU reset, the counter should not be affected.
  81. */
  82. struct kfd_ioctl_get_clock_counters_args {
  83. uint64_t gpu_clock_counter; /* from KFD */
  84. uint64_t cpu_clock_counter; /* from KFD */
  85. uint64_t system_clock_counter; /* from KFD */
  86. uint64_t system_clock_freq; /* from KFD */
  87. uint32_t gpu_id; /* to KFD */
  88. uint32_t pad;
  89. };
  90. #define NUM_OF_SUPPORTED_GPUS 7
  91. struct kfd_process_device_apertures {
  92. uint64_t lds_base; /* from KFD */
  93. uint64_t lds_limit; /* from KFD */
  94. uint64_t scratch_base; /* from KFD */
  95. uint64_t scratch_limit; /* from KFD */
  96. uint64_t gpuvm_base; /* from KFD */
  97. uint64_t gpuvm_limit; /* from KFD */
  98. uint32_t gpu_id; /* from KFD */
  99. uint32_t pad;
  100. };
  101. struct kfd_ioctl_get_process_apertures_args {
  102. struct kfd_process_device_apertures
  103. process_apertures[NUM_OF_SUPPORTED_GPUS];/* from KFD */
  104. /* from KFD, should be in the range [1 - NUM_OF_SUPPORTED_GPUS] */
  105. uint32_t num_of_nodes;
  106. uint32_t pad;
  107. };
  108. #define MAX_ALLOWED_NUM_POINTS 100
  109. #define MAX_ALLOWED_AW_BUFF_SIZE 4096
  110. #define MAX_ALLOWED_WAC_BUFF_SIZE 128
  111. struct kfd_ioctl_dbg_register_args {
  112. uint32_t gpu_id; /* to KFD */
  113. uint32_t pad;
  114. };
  115. struct kfd_ioctl_dbg_unregister_args {
  116. uint32_t gpu_id; /* to KFD */
  117. uint32_t pad;
  118. };
  119. struct kfd_ioctl_dbg_address_watch_args {
  120. uint64_t content_ptr; /* a pointer to the actual content */
  121. uint32_t gpu_id; /* to KFD */
  122. uint32_t buf_size_in_bytes; /*including gpu_id and buf_size */
  123. };
  124. struct kfd_ioctl_dbg_wave_control_args {
  125. uint64_t content_ptr; /* a pointer to the actual content */
  126. uint32_t gpu_id; /* to KFD */
  127. uint32_t buf_size_in_bytes; /*including gpu_id and buf_size */
  128. };
  129. /* Matching HSA_EVENTTYPE */
  130. #define KFD_IOC_EVENT_SIGNAL 0
  131. #define KFD_IOC_EVENT_NODECHANGE 1
  132. #define KFD_IOC_EVENT_DEVICESTATECHANGE 2
  133. #define KFD_IOC_EVENT_HW_EXCEPTION 3
  134. #define KFD_IOC_EVENT_SYSTEM_EVENT 4
  135. #define KFD_IOC_EVENT_DEBUG_EVENT 5
  136. #define KFD_IOC_EVENT_PROFILE_EVENT 6
  137. #define KFD_IOC_EVENT_QUEUE_EVENT 7
  138. #define KFD_IOC_EVENT_MEMORY 8
  139. #define KFD_IOC_WAIT_RESULT_COMPLETE 0
  140. #define KFD_IOC_WAIT_RESULT_TIMEOUT 1
  141. #define KFD_IOC_WAIT_RESULT_FAIL 2
  142. #define KFD_SIGNAL_EVENT_LIMIT 256
  143. struct kfd_ioctl_create_event_args {
  144. uint64_t event_page_offset; /* from KFD */
  145. uint32_t event_trigger_data; /* from KFD - signal events only */
  146. uint32_t event_type; /* to KFD */
  147. uint32_t auto_reset; /* to KFD */
  148. uint32_t node_id; /* to KFD - only valid for certain
  149. event types */
  150. uint32_t event_id; /* from KFD */
  151. uint32_t event_slot_index; /* from KFD */
  152. };
  153. struct kfd_ioctl_destroy_event_args {
  154. uint32_t event_id; /* to KFD */
  155. uint32_t pad;
  156. };
  157. struct kfd_ioctl_set_event_args {
  158. uint32_t event_id; /* to KFD */
  159. uint32_t pad;
  160. };
  161. struct kfd_ioctl_reset_event_args {
  162. uint32_t event_id; /* to KFD */
  163. uint32_t pad;
  164. };
  165. struct kfd_memory_exception_failure {
  166. uint32_t NotPresent; /* Page not present or supervisor privilege */
  167. uint32_t ReadOnly; /* Write access to a read-only page */
  168. uint32_t NoExecute; /* Execute access to a page marked NX */
  169. uint32_t pad;
  170. };
  171. /* memory exception data*/
  172. struct kfd_hsa_memory_exception_data {
  173. struct kfd_memory_exception_failure failure;
  174. uint64_t va;
  175. uint32_t gpu_id;
  176. uint32_t pad;
  177. };
  178. /* Event data*/
  179. struct kfd_event_data {
  180. union {
  181. struct kfd_hsa_memory_exception_data memory_exception_data;
  182. }; /* From KFD */
  183. uint64_t kfd_event_data_ext; /* pointer to an extension structure
  184. for future exception types */
  185. uint32_t event_id; /* to KFD */
  186. uint32_t pad;
  187. };
  188. struct kfd_ioctl_wait_events_args {
  189. uint64_t events_ptr; /* pointed to struct
  190. kfd_event_data array, to KFD */
  191. uint32_t num_events; /* to KFD */
  192. uint32_t wait_for_all; /* to KFD */
  193. uint32_t timeout; /* to KFD */
  194. uint32_t wait_result; /* from KFD */
  195. };
  196. #define AMDKFD_IOCTL_BASE 'K'
  197. #define AMDKFD_IO(nr) _IO(AMDKFD_IOCTL_BASE, nr)
  198. #define AMDKFD_IOR(nr, type) _IOR(AMDKFD_IOCTL_BASE, nr, type)
  199. #define AMDKFD_IOW(nr, type) _IOW(AMDKFD_IOCTL_BASE, nr, type)
  200. #define AMDKFD_IOWR(nr, type) _IOWR(AMDKFD_IOCTL_BASE, nr, type)
  201. #define AMDKFD_IOC_GET_VERSION \
  202. AMDKFD_IOR(0x01, struct kfd_ioctl_get_version_args)
  203. #define AMDKFD_IOC_CREATE_QUEUE \
  204. AMDKFD_IOWR(0x02, struct kfd_ioctl_create_queue_args)
  205. #define AMDKFD_IOC_DESTROY_QUEUE \
  206. AMDKFD_IOWR(0x03, struct kfd_ioctl_destroy_queue_args)
  207. #define AMDKFD_IOC_SET_MEMORY_POLICY \
  208. AMDKFD_IOW(0x04, struct kfd_ioctl_set_memory_policy_args)
  209. #define AMDKFD_IOC_GET_CLOCK_COUNTERS \
  210. AMDKFD_IOWR(0x05, struct kfd_ioctl_get_clock_counters_args)
  211. #define AMDKFD_IOC_GET_PROCESS_APERTURES \
  212. AMDKFD_IOR(0x06, struct kfd_ioctl_get_process_apertures_args)
  213. #define AMDKFD_IOC_UPDATE_QUEUE \
  214. AMDKFD_IOW(0x07, struct kfd_ioctl_update_queue_args)
  215. #define AMDKFD_IOC_CREATE_EVENT \
  216. AMDKFD_IOWR(0x08, struct kfd_ioctl_create_event_args)
  217. #define AMDKFD_IOC_DESTROY_EVENT \
  218. AMDKFD_IOW(0x09, struct kfd_ioctl_destroy_event_args)
  219. #define AMDKFD_IOC_SET_EVENT \
  220. AMDKFD_IOW(0x0A, struct kfd_ioctl_set_event_args)
  221. #define AMDKFD_IOC_RESET_EVENT \
  222. AMDKFD_IOW(0x0B, struct kfd_ioctl_reset_event_args)
  223. #define AMDKFD_IOC_WAIT_EVENTS \
  224. AMDKFD_IOWR(0x0C, struct kfd_ioctl_wait_events_args)
  225. #define AMDKFD_IOC_DBG_REGISTER \
  226. AMDKFD_IOW(0x0D, struct kfd_ioctl_dbg_register_args)
  227. #define AMDKFD_IOC_DBG_UNREGISTER \
  228. AMDKFD_IOW(0x0E, struct kfd_ioctl_dbg_unregister_args)
  229. #define AMDKFD_IOC_DBG_ADDRESS_WATCH \
  230. AMDKFD_IOW(0x0F, struct kfd_ioctl_dbg_address_watch_args)
  231. #define AMDKFD_IOC_DBG_WAVE_CONTROL \
  232. AMDKFD_IOW(0x10, struct kfd_ioctl_dbg_wave_control_args)
  233. #define AMDKFD_COMMAND_START 0x01
  234. #define AMDKFD_COMMAND_END 0x11
  235. #endif