kfd_device_queue_manager.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 QUEUES_PER_PIPE (8)
  31. #define PIPE_PER_ME_CP_SCHEDULING (3)
  32. #define CIK_VMID_NUM (8)
  33. #define KFD_VMID_START_OFFSET (8)
  34. #define VMID_PER_DEVICE CIK_VMID_NUM
  35. #define KFD_DQM_FIRST_PIPE (0)
  36. #define CIK_SDMA_QUEUES (4)
  37. #define CIK_SDMA_QUEUES_PER_ENGINE (2)
  38. #define CIK_SDMA_ENGINE_NUM (2)
  39. struct device_process_node {
  40. struct qcm_process_device *qpd;
  41. struct list_head list;
  42. };
  43. /**
  44. * struct device_queue_manager_ops
  45. *
  46. * @create_queue: Queue creation routine.
  47. *
  48. * @destroy_queue: Queue destruction routine.
  49. *
  50. * @update_queue: Queue update routine.
  51. *
  52. * @get_mqd_manager: Returns the mqd manager according to the mqd type.
  53. *
  54. * @exeute_queues: Dispatches the queues list to the H/W.
  55. *
  56. * @register_process: This routine associates a specific process with device.
  57. *
  58. * @unregister_process: destroys the associations between process to device.
  59. *
  60. * @initialize: Initializes the pipelines and memory module for that device.
  61. *
  62. * @start: Initializes the resources/modules the the device needs for queues
  63. * execution. This function is called on device initialization and after the
  64. * system woke up after suspension.
  65. *
  66. * @stop: This routine stops execution of all the active queue running on the
  67. * H/W and basically this function called on system suspend.
  68. *
  69. * @uninitialize: Destroys all the device queue manager resources allocated in
  70. * initialize routine.
  71. *
  72. * @create_kernel_queue: Creates kernel queue. Used for debug queue.
  73. *
  74. * @destroy_kernel_queue: Destroys kernel queue. Used for debug queue.
  75. *
  76. * @set_cache_memory_policy: Sets memory policy (cached/ non cached) for the
  77. * memory apertures.
  78. *
  79. */
  80. struct device_queue_manager_ops {
  81. int (*create_queue)(struct device_queue_manager *dqm,
  82. struct queue *q,
  83. struct qcm_process_device *qpd,
  84. int *allocate_vmid);
  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. };
  114. struct device_queue_manager_asic_ops {
  115. int (*register_process)(struct device_queue_manager *dqm,
  116. struct qcm_process_device *qpd);
  117. int (*initialize)(struct device_queue_manager *dqm);
  118. bool (*set_cache_memory_policy)(struct device_queue_manager *dqm,
  119. struct qcm_process_device *qpd,
  120. enum cache_policy default_policy,
  121. enum cache_policy alternate_policy,
  122. void __user *alternate_aperture_base,
  123. uint64_t alternate_aperture_size);
  124. void (*init_sdma_vm)(struct device_queue_manager *dqm,
  125. struct queue *q,
  126. struct qcm_process_device *qpd);
  127. };
  128. /**
  129. * struct device_queue_manager
  130. *
  131. * This struct is a base class for the kfd queues scheduler in the
  132. * device level. The device base class should expose the basic operations
  133. * for queue creation and queue destruction. This base class hides the
  134. * scheduling mode of the driver and the specific implementation of the
  135. * concrete device. This class is the only class in the queues scheduler
  136. * that configures the H/W.
  137. *
  138. */
  139. struct device_queue_manager {
  140. struct device_queue_manager_ops ops;
  141. struct device_queue_manager_asic_ops ops_asic_specific;
  142. struct mqd_manager *mqds[KFD_MQD_TYPE_MAX];
  143. struct packet_manager packets;
  144. struct kfd_dev *dev;
  145. struct mutex lock;
  146. struct list_head queues;
  147. unsigned int processes_count;
  148. unsigned int queue_count;
  149. unsigned int sdma_queue_count;
  150. unsigned int total_queue_count;
  151. unsigned int next_pipe_to_allocate;
  152. unsigned int *allocated_queues;
  153. unsigned int sdma_bitmap;
  154. unsigned int vmid_bitmap;
  155. uint64_t pipelines_addr;
  156. struct kfd_mem_obj *pipeline_mem;
  157. uint64_t fence_gpu_addr;
  158. unsigned int *fence_addr;
  159. struct kfd_mem_obj *fence_mem;
  160. bool active_runlist;
  161. };
  162. void device_queue_manager_init_cik(struct device_queue_manager_asic_ops *ops);
  163. void device_queue_manager_init_vi(struct device_queue_manager_asic_ops *ops);
  164. void program_sh_mem_settings(struct device_queue_manager *dqm,
  165. struct qcm_process_device *qpd);
  166. int init_pipelines(struct device_queue_manager *dqm,
  167. unsigned int pipes_num, unsigned int first_pipe);
  168. unsigned int get_first_pipe(struct device_queue_manager *dqm);
  169. unsigned int get_pipes_num(struct device_queue_manager *dqm);
  170. extern inline unsigned int get_sh_mem_bases_32(struct kfd_process_device *pdd)
  171. {
  172. return (pdd->lds_base >> 16) & 0xFF;
  173. }
  174. extern inline unsigned int
  175. get_sh_mem_bases_nybble_64(struct kfd_process_device *pdd)
  176. {
  177. return (pdd->lds_base >> 60) & 0x0E;
  178. }
  179. #endif /* KFD_DEVICE_QUEUE_MANAGER_H_ */