kfd_device_queue_manager.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. * @evict_process_queues: Evict all active queues of a process
  77. *
  78. * @restore_process_queues: Restore all evicted queues queues of a process
  79. *
  80. */
  81. struct device_queue_manager_ops {
  82. int (*create_queue)(struct device_queue_manager *dqm,
  83. struct queue *q,
  84. struct qcm_process_device *qpd);
  85. int (*destroy_queue)(struct device_queue_manager *dqm,
  86. struct qcm_process_device *qpd,
  87. struct queue *q);
  88. int (*update_queue)(struct device_queue_manager *dqm,
  89. struct queue *q);
  90. struct mqd_manager * (*get_mqd_manager)
  91. (struct device_queue_manager *dqm,
  92. enum KFD_MQD_TYPE type);
  93. int (*register_process)(struct device_queue_manager *dqm,
  94. struct qcm_process_device *qpd);
  95. int (*unregister_process)(struct device_queue_manager *dqm,
  96. struct qcm_process_device *qpd);
  97. int (*initialize)(struct device_queue_manager *dqm);
  98. int (*start)(struct device_queue_manager *dqm);
  99. int (*stop)(struct device_queue_manager *dqm);
  100. void (*uninitialize)(struct device_queue_manager *dqm);
  101. int (*create_kernel_queue)(struct device_queue_manager *dqm,
  102. struct kernel_queue *kq,
  103. struct qcm_process_device *qpd);
  104. void (*destroy_kernel_queue)(struct device_queue_manager *dqm,
  105. struct kernel_queue *kq,
  106. struct qcm_process_device *qpd);
  107. bool (*set_cache_memory_policy)(struct device_queue_manager *dqm,
  108. struct qcm_process_device *qpd,
  109. enum cache_policy default_policy,
  110. enum cache_policy alternate_policy,
  111. void __user *alternate_aperture_base,
  112. uint64_t alternate_aperture_size);
  113. int (*set_trap_handler)(struct device_queue_manager *dqm,
  114. struct qcm_process_device *qpd,
  115. uint64_t tba_addr,
  116. uint64_t tma_addr);
  117. int (*process_termination)(struct device_queue_manager *dqm,
  118. struct qcm_process_device *qpd);
  119. int (*evict_process_queues)(struct device_queue_manager *dqm,
  120. struct qcm_process_device *qpd);
  121. int (*restore_process_queues)(struct device_queue_manager *dqm,
  122. struct qcm_process_device *qpd);
  123. };
  124. struct device_queue_manager_asic_ops {
  125. int (*update_qpd)(struct device_queue_manager *dqm,
  126. struct qcm_process_device *qpd);
  127. bool (*set_cache_memory_policy)(struct device_queue_manager *dqm,
  128. struct qcm_process_device *qpd,
  129. enum cache_policy default_policy,
  130. enum cache_policy alternate_policy,
  131. void __user *alternate_aperture_base,
  132. uint64_t alternate_aperture_size);
  133. void (*init_sdma_vm)(struct device_queue_manager *dqm,
  134. struct queue *q,
  135. struct qcm_process_device *qpd);
  136. };
  137. /**
  138. * struct device_queue_manager
  139. *
  140. * This struct is a base class for the kfd queues scheduler in the
  141. * device level. The device base class should expose the basic operations
  142. * for queue creation and queue destruction. This base class hides the
  143. * scheduling mode of the driver and the specific implementation of the
  144. * concrete device. This class is the only class in the queues scheduler
  145. * that configures the H/W.
  146. *
  147. */
  148. struct device_queue_manager {
  149. struct device_queue_manager_ops ops;
  150. struct device_queue_manager_asic_ops asic_ops;
  151. struct mqd_manager *mqds[KFD_MQD_TYPE_MAX];
  152. struct packet_manager packets;
  153. struct kfd_dev *dev;
  154. struct mutex lock;
  155. struct list_head queues;
  156. unsigned int processes_count;
  157. unsigned int queue_count;
  158. unsigned int sdma_queue_count;
  159. unsigned int total_queue_count;
  160. unsigned int next_pipe_to_allocate;
  161. unsigned int *allocated_queues;
  162. unsigned int sdma_bitmap;
  163. unsigned int vmid_bitmap;
  164. uint64_t pipelines_addr;
  165. struct kfd_mem_obj *pipeline_mem;
  166. uint64_t fence_gpu_addr;
  167. unsigned int *fence_addr;
  168. struct kfd_mem_obj *fence_mem;
  169. bool active_runlist;
  170. int sched_policy;
  171. };
  172. void device_queue_manager_init_cik(
  173. struct device_queue_manager_asic_ops *asic_ops);
  174. void device_queue_manager_init_cik_hawaii(
  175. struct device_queue_manager_asic_ops *asic_ops);
  176. void device_queue_manager_init_vi(
  177. struct device_queue_manager_asic_ops *asic_ops);
  178. void device_queue_manager_init_vi_tonga(
  179. struct device_queue_manager_asic_ops *asic_ops);
  180. void device_queue_manager_init_v9(
  181. struct device_queue_manager_asic_ops *asic_ops);
  182. void program_sh_mem_settings(struct device_queue_manager *dqm,
  183. struct qcm_process_device *qpd);
  184. unsigned int get_queues_num(struct device_queue_manager *dqm);
  185. unsigned int get_queues_per_pipe(struct device_queue_manager *dqm);
  186. unsigned int get_pipes_per_mec(struct device_queue_manager *dqm);
  187. static inline unsigned int get_sh_mem_bases_32(struct kfd_process_device *pdd)
  188. {
  189. return (pdd->lds_base >> 16) & 0xFF;
  190. }
  191. static inline unsigned int
  192. get_sh_mem_bases_nybble_64(struct kfd_process_device *pdd)
  193. {
  194. return (pdd->lds_base >> 60) & 0x0E;
  195. }
  196. #endif /* KFD_DEVICE_QUEUE_MANAGER_H_ */