kfd_device_queue_manager.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. */
  23. #ifndef KFD_DEVICE_QUEUE_MANAGER_H_
  24. #define KFD_DEVICE_QUEUE_MANAGER_H_
  25. #include <linux/rwsem.h>
  26. #include <linux/list.h>
  27. #include "kfd_priv.h"
  28. #include "kfd_mqd_manager.h"
  29. #define KFD_UNMAP_LATENCY_MS (4000)
  30. #define QUEUE_PREEMPT_DEFAULT_TIMEOUT_MS (2 * KFD_UNMAP_LATENCY_MS + 1000)
  31. #define CIK_SDMA_QUEUES (4)
  32. #define CIK_SDMA_QUEUES_PER_ENGINE (2)
  33. #define CIK_SDMA_ENGINE_NUM (2)
  34. struct device_process_node {
  35. struct qcm_process_device *qpd;
  36. struct list_head list;
  37. };
  38. /**
  39. * struct device_queue_manager_ops
  40. *
  41. * @create_queue: Queue creation routine.
  42. *
  43. * @destroy_queue: Queue destruction routine.
  44. *
  45. * @update_queue: Queue update routine.
  46. *
  47. * @get_mqd_manager: Returns the mqd manager according to the mqd type.
  48. *
  49. * @exeute_queues: Dispatches the queues list to the H/W.
  50. *
  51. * @register_process: This routine associates a specific process with device.
  52. *
  53. * @unregister_process: destroys the associations between process to device.
  54. *
  55. * @initialize: Initializes the pipelines and memory module for that device.
  56. *
  57. * @start: Initializes the resources/modules the the device needs for queues
  58. * execution. This function is called on device initialization and after the
  59. * system woke up after suspension.
  60. *
  61. * @stop: This routine stops execution of all the active queue running on the
  62. * H/W and basically this function called on system suspend.
  63. *
  64. * @uninitialize: Destroys all the device queue manager resources allocated in
  65. * initialize routine.
  66. *
  67. * @create_kernel_queue: Creates kernel queue. Used for debug queue.
  68. *
  69. * @destroy_kernel_queue: Destroys kernel queue. Used for debug queue.
  70. *
  71. * @set_cache_memory_policy: Sets memory policy (cached/ non cached) for the
  72. * memory apertures.
  73. *
  74. * @process_termination: Clears all process queues belongs to that device.
  75. *
  76. */
  77. struct device_queue_manager_ops {
  78. int (*create_queue)(struct device_queue_manager *dqm,
  79. struct queue *q,
  80. struct qcm_process_device *qpd,
  81. int *allocate_vmid);
  82. int (*destroy_queue)(struct device_queue_manager *dqm,
  83. struct qcm_process_device *qpd,
  84. struct queue *q);
  85. int (*update_queue)(struct device_queue_manager *dqm,
  86. struct queue *q);
  87. struct mqd_manager * (*get_mqd_manager)
  88. (struct device_queue_manager *dqm,
  89. enum KFD_MQD_TYPE type);
  90. int (*register_process)(struct device_queue_manager *dqm,
  91. struct qcm_process_device *qpd);
  92. int (*unregister_process)(struct device_queue_manager *dqm,
  93. struct qcm_process_device *qpd);
  94. int (*initialize)(struct device_queue_manager *dqm);
  95. int (*start)(struct device_queue_manager *dqm);
  96. int (*stop)(struct device_queue_manager *dqm);
  97. void (*uninitialize)(struct device_queue_manager *dqm);
  98. int (*create_kernel_queue)(struct device_queue_manager *dqm,
  99. struct kernel_queue *kq,
  100. struct qcm_process_device *qpd);
  101. void (*destroy_kernel_queue)(struct device_queue_manager *dqm,
  102. struct kernel_queue *kq,
  103. struct qcm_process_device *qpd);
  104. bool (*set_cache_memory_policy)(struct device_queue_manager *dqm,
  105. struct qcm_process_device *qpd,
  106. enum cache_policy default_policy,
  107. enum cache_policy alternate_policy,
  108. void __user *alternate_aperture_base,
  109. uint64_t alternate_aperture_size);
  110. int (*process_termination)(struct device_queue_manager *dqm,
  111. struct qcm_process_device *qpd);
  112. };
  113. struct device_queue_manager_asic_ops {
  114. int (*update_qpd)(struct device_queue_manager *dqm,
  115. struct qcm_process_device *qpd);
  116. bool (*set_cache_memory_policy)(struct device_queue_manager *dqm,
  117. struct qcm_process_device *qpd,
  118. enum cache_policy default_policy,
  119. enum cache_policy alternate_policy,
  120. void __user *alternate_aperture_base,
  121. uint64_t alternate_aperture_size);
  122. void (*init_sdma_vm)(struct device_queue_manager *dqm,
  123. struct queue *q,
  124. struct qcm_process_device *qpd);
  125. };
  126. /**
  127. * struct device_queue_manager
  128. *
  129. * This struct is a base class for the kfd queues scheduler in the
  130. * device level. The device base class should expose the basic operations
  131. * for queue creation and queue destruction. This base class hides the
  132. * scheduling mode of the driver and the specific implementation of the
  133. * concrete device. This class is the only class in the queues scheduler
  134. * that configures the H/W.
  135. *
  136. */
  137. struct device_queue_manager {
  138. struct device_queue_manager_ops ops;
  139. struct device_queue_manager_asic_ops asic_ops;
  140. struct mqd_manager *mqds[KFD_MQD_TYPE_MAX];
  141. struct packet_manager packets;
  142. struct kfd_dev *dev;
  143. struct mutex lock;
  144. struct list_head queues;
  145. unsigned int processes_count;
  146. unsigned int queue_count;
  147. unsigned int sdma_queue_count;
  148. unsigned int total_queue_count;
  149. unsigned int next_pipe_to_allocate;
  150. unsigned int *allocated_queues;
  151. unsigned int sdma_bitmap;
  152. unsigned int vmid_bitmap;
  153. uint64_t pipelines_addr;
  154. struct kfd_mem_obj *pipeline_mem;
  155. uint64_t fence_gpu_addr;
  156. unsigned int *fence_addr;
  157. struct kfd_mem_obj *fence_mem;
  158. bool active_runlist;
  159. };
  160. void device_queue_manager_init_cik(
  161. struct device_queue_manager_asic_ops *asic_ops);
  162. void device_queue_manager_init_vi(
  163. struct device_queue_manager_asic_ops *asic_ops);
  164. void program_sh_mem_settings(struct device_queue_manager *dqm,
  165. struct qcm_process_device *qpd);
  166. unsigned int get_queues_num(struct device_queue_manager *dqm);
  167. unsigned int get_queues_per_pipe(struct device_queue_manager *dqm);
  168. unsigned int get_pipes_per_mec(struct device_queue_manager *dqm);
  169. static inline unsigned int get_sh_mem_bases_32(struct kfd_process_device *pdd)
  170. {
  171. return (pdd->lds_base >> 16) & 0xFF;
  172. }
  173. static inline unsigned int
  174. get_sh_mem_bases_nybble_64(struct kfd_process_device *pdd)
  175. {
  176. return (pdd->lds_base >> 60) & 0x0E;
  177. }
  178. #endif /* KFD_DEVICE_QUEUE_MANAGER_H_ */