kfd_ioctl.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 0
  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 AMDKFD_IOCTL_BASE 'K'
  109. #define AMDKFD_IO(nr) _IO(AMDKFD_IOCTL_BASE, nr)
  110. #define AMDKFD_IOR(nr, type) _IOR(AMDKFD_IOCTL_BASE, nr, type)
  111. #define AMDKFD_IOW(nr, type) _IOW(AMDKFD_IOCTL_BASE, nr, type)
  112. #define AMDKFD_IOWR(nr, type) _IOWR(AMDKFD_IOCTL_BASE, nr, type)
  113. #define AMDKFD_IOC_GET_VERSION \
  114. AMDKFD_IOR(0x01, struct kfd_ioctl_get_version_args)
  115. #define AMDKFD_IOC_CREATE_QUEUE \
  116. AMDKFD_IOWR(0x02, struct kfd_ioctl_create_queue_args)
  117. #define AMDKFD_IOC_DESTROY_QUEUE \
  118. AMDKFD_IOWR(0x03, struct kfd_ioctl_destroy_queue_args)
  119. #define AMDKFD_IOC_SET_MEMORY_POLICY \
  120. AMDKFD_IOW(0x04, struct kfd_ioctl_set_memory_policy_args)
  121. #define AMDKFD_IOC_GET_CLOCK_COUNTERS \
  122. AMDKFD_IOWR(0x05, struct kfd_ioctl_get_clock_counters_args)
  123. #define AMDKFD_IOC_GET_PROCESS_APERTURES \
  124. AMDKFD_IOR(0x06, struct kfd_ioctl_get_process_apertures_args)
  125. #define AMDKFD_IOC_UPDATE_QUEUE \
  126. AMDKFD_IOW(0x07, struct kfd_ioctl_update_queue_args)
  127. #define AMDKFD_COMMAND_START 0x01
  128. #define AMDKFD_COMMAND_END 0x08
  129. #endif