kfd_mqd_manager.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* SPDX-License-Identifier: GPL-2.0 OR MIT */
  2. /*
  3. * Copyright 2014-2022 Advanced Micro Devices, Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. */
  24. #ifndef KFD_MQD_MANAGER_H_
  25. #define KFD_MQD_MANAGER_H_
  26. #include "kfd_priv.h"
  27. #define KFD_MAX_NUM_SE 8
  28. #define KFD_MAX_NUM_SH_PER_SE 2
  29. /**
  30. * struct mqd_manager
  31. *
  32. * @init_mqd: Allocates the mqd buffer on local gpu memory and initialize it.
  33. *
  34. * @load_mqd: Loads the mqd to a concrete hqd slot. Used only for no cp
  35. * scheduling mode.
  36. *
  37. * @update_mqd: Handles a update call for the MQD
  38. *
  39. * @destroy_mqd: Destroys the HQD slot and by that preempt the relevant queue.
  40. * Used only for no cp scheduling.
  41. *
  42. * @free_mqd: Releases the mqd buffer from local gpu memory.
  43. *
  44. * @is_occupied: Checks if the relevant HQD slot is occupied.
  45. *
  46. * @get_wave_state: Retrieves context save state and optionally copies the
  47. * control stack, if kept in the MQD, to the given userspace address.
  48. *
  49. * @mqd_mutex: Mqd manager mutex.
  50. *
  51. * @dev: The kfd device structure coupled with this module.
  52. *
  53. * MQD stands for Memory Queue Descriptor which represents the current queue
  54. * state in the memory and initiate the HQD (Hardware Queue Descriptor) state.
  55. * This structure is actually a base class for the different types of MQDs
  56. * structures for the variant ASICs that should be supported in the future.
  57. * This base class is also contains all the MQD specific operations.
  58. * Another important thing to mention is that each queue has a MQD that keeps
  59. * his state (or context) after each preemption or reassignment.
  60. * Basically there are a instances of the mqd manager class per MQD type per
  61. * ASIC. Currently the kfd driver supports only Kaveri so there are instances
  62. * per KFD_MQD_TYPE for each device.
  63. *
  64. */
  65. extern int pipe_priority_map[];
  66. struct mqd_manager {
  67. struct kfd_mem_obj* (*allocate_mqd)(struct kfd_node *kfd,
  68. struct queue_properties *q);
  69. void (*init_mqd)(struct mqd_manager *mm, void **mqd,
  70. struct kfd_mem_obj *mqd_mem_obj, uint64_t *gart_addr,
  71. struct queue_properties *q);
  72. int (*load_mqd)(struct mqd_manager *mm, void *mqd,
  73. uint32_t pipe_id, uint32_t queue_id,
  74. struct queue_properties *p,
  75. struct mm_struct *mms);
  76. void (*update_mqd)(struct mqd_manager *mm, void *mqd,
  77. struct queue_properties *q,
  78. struct mqd_update_info *minfo);
  79. int (*destroy_mqd)(struct mqd_manager *mm, void *mqd,
  80. enum kfd_preempt_type type,
  81. unsigned int timeout, uint32_t pipe_id,
  82. uint32_t queue_id);
  83. void (*free_mqd)(struct mqd_manager *mm, void *mqd,
  84. struct kfd_mem_obj *mqd_mem_obj);
  85. bool (*is_occupied)(struct mqd_manager *mm, void *mqd,
  86. uint64_t queue_address, uint32_t pipe_id,
  87. uint32_t queue_id);
  88. int (*get_wave_state)(struct mqd_manager *mm, void *mqd,
  89. struct queue_properties *q,
  90. void __user *ctl_stack,
  91. u32 *ctl_stack_used_size,
  92. u32 *save_area_used_size);
  93. void (*get_checkpoint_info)(struct mqd_manager *mm, void *mqd, uint32_t *ctl_stack_size);
  94. void (*checkpoint_mqd)(struct mqd_manager *mm,
  95. void *mqd,
  96. void *mqd_dst,
  97. void *ctl_stack_dst);
  98. void (*restore_mqd)(struct mqd_manager *mm, void **mqd,
  99. struct kfd_mem_obj *mqd_mem_obj, uint64_t *gart_addr,
  100. struct queue_properties *p,
  101. const void *mqd_src,
  102. const void *ctl_stack_src,
  103. const u32 ctl_stack_size);
  104. #if defined(CONFIG_DEBUG_FS)
  105. int (*debugfs_show_mqd)(struct seq_file *m, void *data);
  106. #endif
  107. bool (*check_preemption_failed)(struct mqd_manager *mm, void *mqd);
  108. uint64_t (*mqd_stride)(struct mqd_manager *mm,
  109. struct queue_properties *p);
  110. struct mutex mqd_mutex;
  111. struct kfd_node *dev;
  112. uint32_t mqd_size;
  113. };
  114. struct mqd_user_context_save_area_header {
  115. /* Byte offset from start of user context
  116. * save area to the last saved top (lowest
  117. * address) of control stack data. Must be
  118. * 4 byte aligned.
  119. */
  120. uint32_t control_stack_offset;
  121. /* Byte size of the last saved control stack
  122. * data. Must be 4 byte aligned.
  123. */
  124. uint32_t control_stack_size;
  125. /* Byte offset from start of user context save
  126. * area to the last saved base (lowest address)
  127. * of wave state data. Must be 4 byte aligned.
  128. */
  129. uint32_t wave_state_offset;
  130. /* Byte size of the last saved wave state data.
  131. * Must be 4 byte aligned.
  132. */
  133. uint32_t wave_state_size;
  134. };
  135. struct kfd_mem_obj *allocate_hiq_mqd(struct kfd_node *dev,
  136. struct queue_properties *q);
  137. struct kfd_mem_obj *allocate_sdma_mqd(struct kfd_node *dev,
  138. struct queue_properties *q);
  139. void free_mqd_hiq_sdma(struct mqd_manager *mm, void *mqd,
  140. struct kfd_mem_obj *mqd_mem_obj);
  141. void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm,
  142. const uint32_t *cu_mask, uint32_t cu_mask_count,
  143. uint32_t *se_mask, uint32_t inst);
  144. int kfd_hiq_load_mqd_kiq(struct mqd_manager *mm, void *mqd,
  145. uint32_t pipe_id, uint32_t queue_id,
  146. struct queue_properties *p, struct mm_struct *mms);
  147. int kfd_destroy_mqd_cp(struct mqd_manager *mm, void *mqd,
  148. enum kfd_preempt_type type, unsigned int timeout,
  149. uint32_t pipe_id, uint32_t queue_id);
  150. void kfd_free_mqd_cp(struct mqd_manager *mm, void *mqd,
  151. struct kfd_mem_obj *mqd_mem_obj);
  152. bool kfd_is_occupied_cp(struct mqd_manager *mm, void *mqd,
  153. uint64_t queue_address, uint32_t pipe_id,
  154. uint32_t queue_id);
  155. int kfd_load_mqd_sdma(struct mqd_manager *mm, void *mqd,
  156. uint32_t pipe_id, uint32_t queue_id,
  157. struct queue_properties *p, struct mm_struct *mms);
  158. int kfd_destroy_mqd_sdma(struct mqd_manager *mm, void *mqd,
  159. enum kfd_preempt_type type, unsigned int timeout,
  160. uint32_t pipe_id, uint32_t queue_id);
  161. bool kfd_is_occupied_sdma(struct mqd_manager *mm, void *mqd,
  162. uint64_t queue_address, uint32_t pipe_id,
  163. uint32_t queue_id);
  164. void kfd_get_hiq_xcc_mqd(struct kfd_node *dev,
  165. struct kfd_mem_obj *mqd_mem_obj, uint32_t virtual_xcc_id);
  166. uint64_t kfd_hiq_mqd_stride(struct kfd_node *dev);
  167. uint64_t kfd_mqd_stride(struct mqd_manager *mm,
  168. struct queue_properties *q);
  169. bool kfd_check_hiq_mqd_doorbell_id(struct kfd_node *node, uint32_t doorbell_id,
  170. uint32_t inst);
  171. #endif /* KFD_MQD_MANAGER_H_ */