kfd_device_queue_manager.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 QUEUE_PREEMPT_DEFAULT_TIMEOUT_MS (500)
  30. #define CIK_VMID_NUM (8)
  31. #define KFD_VMID_START_OFFSET (8)
  32. #define VMID_PER_DEVICE CIK_VMID_NUM
  33. #define KFD_DQM_FIRST_PIPE (0)
  34. #define CIK_SDMA_QUEUES (4)
  35. #define CIK_SDMA_QUEUES_PER_ENGINE (2)
  36. #define CIK_SDMA_ENGINE_NUM (2)
  37. struct device_process_node {
  38. struct qcm_process_device *qpd;
  39. struct list_head list;
  40. };
  41. /**
  42. * struct device_queue_manager_ops
  43. *
  44. * @create_queue: Queue creation routine.
  45. *
  46. * @destroy_queue: Queue destruction routine.
  47. *
  48. * @update_queue: Queue update routine.
  49. *
  50. * @get_mqd_manager: Returns the mqd manager according to the mqd type.
  51. *
  52. * @exeute_queues: Dispatches the queues list to the H/W.
  53. *
  54. * @register_process: This routine associates a specific process with device.
  55. *
  56. * @unregister_process: destroys the associations between process to device.
  57. *
  58. * @initialize: Initializes the pipelines and memory module for that device.
  59. *
  60. * @start: Initializes the resources/modules the the device needs for queues
  61. * execution. This function is called on device initialization and after the
  62. * system woke up after suspension.
  63. *
  64. * @stop: This routine stops execution of all the active queue running on the
  65. * H/W and basically this function called on system suspend.
  66. *
  67. * @uninitialize: Destroys all the device queue manager resources allocated in
  68. * initialize routine.
  69. *
  70. * @create_kernel_queue: Creates kernel queue. Used for debug queue.
  71. *
  72. * @destroy_kernel_queue: Destroys kernel queue. Used for debug queue.
  73. *
  74. * @set_cache_memory_policy: Sets memory policy (cached/ non cached) for the
  75. * memory apertures.
  76. *
  77. */
  78. struct device_queue_manager_ops {
  79. int (*create_queue)(struct device_queue_manager *dqm,
  80. struct queue *q,
  81. struct qcm_process_device *qpd,
  82. int *allocate_vmid);
  83. int (*destroy_queue)(struct device_queue_manager *dqm,
  84. struct qcm_process_device *qpd,
  85. struct queue *q);
  86. int (*update_queue)(struct device_queue_manager *dqm,
  87. struct queue *q);
  88. struct mqd_manager * (*get_mqd_manager)
  89. (struct device_queue_manager *dqm,
  90. enum KFD_MQD_TYPE type);
  91. int (*register_process)(struct device_queue_manager *dqm,
  92. struct qcm_process_device *qpd);
  93. int (*unregister_process)(struct device_queue_manager *dqm,
  94. struct qcm_process_device *qpd);
  95. int (*initialize)(struct device_queue_manager *dqm);
  96. int (*start)(struct device_queue_manager *dqm);
  97. int (*stop)(struct device_queue_manager *dqm);
  98. void (*uninitialize)(struct device_queue_manager *dqm);
  99. int (*create_kernel_queue)(struct device_queue_manager *dqm,
  100. struct kernel_queue *kq,
  101. struct qcm_process_device *qpd);
  102. void (*destroy_kernel_queue)(struct device_queue_manager *dqm,
  103. struct kernel_queue *kq,
  104. struct qcm_process_device *qpd);
  105. bool (*set_cache_memory_policy)(struct device_queue_manager *dqm,
  106. struct qcm_process_device *qpd,
  107. enum cache_policy default_policy,
  108. enum cache_policy alternate_policy,
  109. void __user *alternate_aperture_base,
  110. uint64_t alternate_aperture_size);
  111. };
  112. struct device_queue_manager_asic_ops {
  113. int (*register_process)(struct device_queue_manager *dqm,
  114. struct qcm_process_device *qpd);
  115. int (*initialize)(struct device_queue_manager *dqm);
  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 ops_asic_specific;
  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(struct device_queue_manager_asic_ops *ops);
  161. void device_queue_manager_init_vi(struct device_queue_manager_asic_ops *ops);
  162. void program_sh_mem_settings(struct device_queue_manager *dqm,
  163. struct qcm_process_device *qpd);
  164. unsigned int get_queues_num(struct device_queue_manager *dqm);
  165. unsigned int get_queues_per_pipe(struct device_queue_manager *dqm);
  166. unsigned int get_pipes_per_mec(struct device_queue_manager *dqm);
  167. static inline unsigned int get_sh_mem_bases_32(struct kfd_process_device *pdd)
  168. {
  169. return (pdd->lds_base >> 16) & 0xFF;
  170. }
  171. static inline unsigned int
  172. get_sh_mem_bases_nybble_64(struct kfd_process_device *pdd)
  173. {
  174. return (pdd->lds_base >> 60) & 0x0E;
  175. }
  176. #endif /* KFD_DEVICE_QUEUE_MANAGER_H_ */