PageRenderTime 71ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager_vi.c

https://github.com/kvaneesh/linux
C | 334 lines | 244 code | 58 blank | 32 comment | 6 complexity | 9f1b5eb8f5f4ecb7693bb7fe5ce1d46a MD5 | raw file
  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. #include "kfd_kernel_queue.h"
  24. #include "kfd_device_queue_manager.h"
  25. #include "kfd_pm4_headers_vi.h"
  26. #include "kfd_pm4_opcodes.h"
  27. unsigned int pm_build_pm4_header(unsigned int opcode, size_t packet_size)
  28. {
  29. union PM4_MES_TYPE_3_HEADER header;
  30. header.u32All = 0;
  31. header.opcode = opcode;
  32. header.count = packet_size / 4 - 2;
  33. header.type = PM4_TYPE_3;
  34. return header.u32All;
  35. }
  36. static int pm_map_process_vi(struct packet_manager *pm, uint32_t *buffer,
  37. struct qcm_process_device *qpd)
  38. {
  39. struct pm4_mes_map_process *packet;
  40. packet = (struct pm4_mes_map_process *)buffer;
  41. memset(buffer, 0, sizeof(struct pm4_mes_map_process));
  42. packet->header.u32All = pm_build_pm4_header(IT_MAP_PROCESS,
  43. sizeof(struct pm4_mes_map_process));
  44. packet->bitfields2.diq_enable = (qpd->is_debug) ? 1 : 0;
  45. packet->bitfields2.process_quantum = 10;
  46. packet->bitfields2.pasid = qpd->pqm->process->pasid;
  47. packet->bitfields3.page_table_base = qpd->page_table_base;
  48. packet->bitfields10.gds_size = qpd->gds_size;
  49. packet->bitfields10.num_gws = qpd->num_gws;
  50. packet->bitfields10.num_oac = qpd->num_oac;
  51. packet->bitfields10.num_queues = (qpd->is_debug) ? 0 : qpd->queue_count;
  52. packet->sh_mem_config = qpd->sh_mem_config;
  53. packet->sh_mem_bases = qpd->sh_mem_bases;
  54. packet->sh_mem_ape1_base = qpd->sh_mem_ape1_base;
  55. packet->sh_mem_ape1_limit = qpd->sh_mem_ape1_limit;
  56. packet->sh_hidden_private_base_vmid = qpd->sh_hidden_private_base;
  57. packet->gds_addr_lo = lower_32_bits(qpd->gds_context_area);
  58. packet->gds_addr_hi = upper_32_bits(qpd->gds_context_area);
  59. return 0;
  60. }
  61. static int pm_runlist_vi(struct packet_manager *pm, uint32_t *buffer,
  62. uint64_t ib, size_t ib_size_in_dwords, bool chain)
  63. {
  64. struct pm4_mes_runlist *packet;
  65. int concurrent_proc_cnt = 0;
  66. struct kfd_dev *kfd = pm->dqm->dev;
  67. if (WARN_ON(!ib))
  68. return -EFAULT;
  69. /* Determine the number of processes to map together to HW:
  70. * it can not exceed the number of VMIDs available to the
  71. * scheduler, and it is determined by the smaller of the number
  72. * of processes in the runlist and kfd module parameter
  73. * hws_max_conc_proc.
  74. * Note: the arbitration between the number of VMIDs and
  75. * hws_max_conc_proc has been done in
  76. * kgd2kfd_device_init().
  77. */
  78. concurrent_proc_cnt = min(pm->dqm->processes_count,
  79. kfd->max_proc_per_quantum);
  80. packet = (struct pm4_mes_runlist *)buffer;
  81. memset(buffer, 0, sizeof(struct pm4_mes_runlist));
  82. packet->header.u32All = pm_build_pm4_header(IT_RUN_LIST,
  83. sizeof(struct pm4_mes_runlist));
  84. packet->bitfields4.ib_size = ib_size_in_dwords;
  85. packet->bitfields4.chain = chain ? 1 : 0;
  86. packet->bitfields4.offload_polling = 0;
  87. packet->bitfields4.valid = 1;
  88. packet->bitfields4.process_cnt = concurrent_proc_cnt;
  89. packet->ordinal2 = lower_32_bits(ib);
  90. packet->bitfields3.ib_base_hi = upper_32_bits(ib);
  91. return 0;
  92. }
  93. int pm_set_resources_vi(struct packet_manager *pm, uint32_t *buffer,
  94. struct scheduling_resources *res)
  95. {
  96. struct pm4_mes_set_resources *packet;
  97. packet = (struct pm4_mes_set_resources *)buffer;
  98. memset(buffer, 0, sizeof(struct pm4_mes_set_resources));
  99. packet->header.u32All = pm_build_pm4_header(IT_SET_RESOURCES,
  100. sizeof(struct pm4_mes_set_resources));
  101. packet->bitfields2.queue_type =
  102. queue_type__mes_set_resources__hsa_interface_queue_hiq;
  103. packet->bitfields2.vmid_mask = res->vmid_mask;
  104. packet->bitfields2.unmap_latency = KFD_UNMAP_LATENCY_MS / 100;
  105. packet->bitfields7.oac_mask = res->oac_mask;
  106. packet->bitfields8.gds_heap_base = res->gds_heap_base;
  107. packet->bitfields8.gds_heap_size = res->gds_heap_size;
  108. packet->gws_mask_lo = lower_32_bits(res->gws_mask);
  109. packet->gws_mask_hi = upper_32_bits(res->gws_mask);
  110. packet->queue_mask_lo = lower_32_bits(res->queue_mask);
  111. packet->queue_mask_hi = upper_32_bits(res->queue_mask);
  112. return 0;
  113. }
  114. static int pm_map_queues_vi(struct packet_manager *pm, uint32_t *buffer,
  115. struct queue *q, bool is_static)
  116. {
  117. struct pm4_mes_map_queues *packet;
  118. bool use_static = is_static;
  119. packet = (struct pm4_mes_map_queues *)buffer;
  120. memset(buffer, 0, sizeof(struct pm4_mes_map_queues));
  121. packet->header.u32All = pm_build_pm4_header(IT_MAP_QUEUES,
  122. sizeof(struct pm4_mes_map_queues));
  123. packet->bitfields2.num_queues = 1;
  124. packet->bitfields2.queue_sel =
  125. queue_sel__mes_map_queues__map_to_hws_determined_queue_slots_vi;
  126. packet->bitfields2.engine_sel =
  127. engine_sel__mes_map_queues__compute_vi;
  128. packet->bitfields2.queue_type =
  129. queue_type__mes_map_queues__normal_compute_vi;
  130. switch (q->properties.type) {
  131. case KFD_QUEUE_TYPE_COMPUTE:
  132. if (use_static)
  133. packet->bitfields2.queue_type =
  134. queue_type__mes_map_queues__normal_latency_static_queue_vi;
  135. break;
  136. case KFD_QUEUE_TYPE_DIQ:
  137. packet->bitfields2.queue_type =
  138. queue_type__mes_map_queues__debug_interface_queue_vi;
  139. break;
  140. case KFD_QUEUE_TYPE_SDMA:
  141. case KFD_QUEUE_TYPE_SDMA_XGMI:
  142. packet->bitfields2.engine_sel = q->properties.sdma_engine_id +
  143. engine_sel__mes_map_queues__sdma0_vi;
  144. use_static = false; /* no static queues under SDMA */
  145. break;
  146. default:
  147. WARN(1, "queue type %d", q->properties.type);
  148. return -EINVAL;
  149. }
  150. packet->bitfields3.doorbell_offset =
  151. q->properties.doorbell_off;
  152. packet->mqd_addr_lo =
  153. lower_32_bits(q->gart_mqd_addr);
  154. packet->mqd_addr_hi =
  155. upper_32_bits(q->gart_mqd_addr);
  156. packet->wptr_addr_lo =
  157. lower_32_bits((uint64_t)q->properties.write_ptr);
  158. packet->wptr_addr_hi =
  159. upper_32_bits((uint64_t)q->properties.write_ptr);
  160. return 0;
  161. }
  162. static int pm_unmap_queues_vi(struct packet_manager *pm, uint32_t *buffer,
  163. enum kfd_queue_type type,
  164. enum kfd_unmap_queues_filter filter,
  165. uint32_t filter_param, bool reset,
  166. unsigned int sdma_engine)
  167. {
  168. struct pm4_mes_unmap_queues *packet;
  169. packet = (struct pm4_mes_unmap_queues *)buffer;
  170. memset(buffer, 0, sizeof(struct pm4_mes_unmap_queues));
  171. packet->header.u32All = pm_build_pm4_header(IT_UNMAP_QUEUES,
  172. sizeof(struct pm4_mes_unmap_queues));
  173. switch (type) {
  174. case KFD_QUEUE_TYPE_COMPUTE:
  175. case KFD_QUEUE_TYPE_DIQ:
  176. packet->bitfields2.engine_sel =
  177. engine_sel__mes_unmap_queues__compute;
  178. break;
  179. case KFD_QUEUE_TYPE_SDMA:
  180. case KFD_QUEUE_TYPE_SDMA_XGMI:
  181. packet->bitfields2.engine_sel =
  182. engine_sel__mes_unmap_queues__sdma0 + sdma_engine;
  183. break;
  184. default:
  185. WARN(1, "queue type %d", type);
  186. return -EINVAL;
  187. }
  188. if (reset)
  189. packet->bitfields2.action =
  190. action__mes_unmap_queues__reset_queues;
  191. else
  192. packet->bitfields2.action =
  193. action__mes_unmap_queues__preempt_queues;
  194. switch (filter) {
  195. case KFD_UNMAP_QUEUES_FILTER_SINGLE_QUEUE:
  196. packet->bitfields2.queue_sel =
  197. queue_sel__mes_unmap_queues__perform_request_on_specified_queues;
  198. packet->bitfields2.num_queues = 1;
  199. packet->bitfields3b.doorbell_offset0 = filter_param;
  200. break;
  201. case KFD_UNMAP_QUEUES_FILTER_BY_PASID:
  202. packet->bitfields2.queue_sel =
  203. queue_sel__mes_unmap_queues__perform_request_on_pasid_queues;
  204. packet->bitfields3a.pasid = filter_param;
  205. break;
  206. case KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES:
  207. packet->bitfields2.queue_sel =
  208. queue_sel__mes_unmap_queues__unmap_all_queues;
  209. break;
  210. case KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES:
  211. /* in this case, we do not preempt static queues */
  212. packet->bitfields2.queue_sel =
  213. queue_sel__mes_unmap_queues__unmap_all_non_static_queues;
  214. break;
  215. default:
  216. WARN(1, "filter %d", filter);
  217. return -EINVAL;
  218. }
  219. return 0;
  220. }
  221. static int pm_query_status_vi(struct packet_manager *pm, uint32_t *buffer,
  222. uint64_t fence_address, uint64_t fence_value)
  223. {
  224. struct pm4_mes_query_status *packet;
  225. packet = (struct pm4_mes_query_status *)buffer;
  226. memset(buffer, 0, sizeof(struct pm4_mes_query_status));
  227. packet->header.u32All = pm_build_pm4_header(IT_QUERY_STATUS,
  228. sizeof(struct pm4_mes_query_status));
  229. packet->bitfields2.context_id = 0;
  230. packet->bitfields2.interrupt_sel =
  231. interrupt_sel__mes_query_status__completion_status;
  232. packet->bitfields2.command =
  233. command__mes_query_status__fence_only_after_write_ack;
  234. packet->addr_hi = upper_32_bits((uint64_t)fence_address);
  235. packet->addr_lo = lower_32_bits((uint64_t)fence_address);
  236. packet->data_hi = upper_32_bits((uint64_t)fence_value);
  237. packet->data_lo = lower_32_bits((uint64_t)fence_value);
  238. return 0;
  239. }
  240. static int pm_release_mem_vi(uint64_t gpu_addr, uint32_t *buffer)
  241. {
  242. struct pm4_mec_release_mem *packet;
  243. packet = (struct pm4_mec_release_mem *)buffer;
  244. memset(buffer, 0, sizeof(*packet));
  245. packet->header.u32All = pm_build_pm4_header(IT_RELEASE_MEM,
  246. sizeof(*packet));
  247. packet->bitfields2.event_type = CACHE_FLUSH_AND_INV_TS_EVENT;
  248. packet->bitfields2.event_index = event_index___release_mem__end_of_pipe;
  249. packet->bitfields2.tcl1_action_ena = 1;
  250. packet->bitfields2.tc_action_ena = 1;
  251. packet->bitfields2.cache_policy = cache_policy___release_mem__lru;
  252. packet->bitfields2.atc = 0;
  253. packet->bitfields3.data_sel = data_sel___release_mem__send_32_bit_low;
  254. packet->bitfields3.int_sel =
  255. int_sel___release_mem__send_interrupt_after_write_confirm;
  256. packet->bitfields4.address_lo_32b = (gpu_addr & 0xffffffff) >> 2;
  257. packet->address_hi = upper_32_bits(gpu_addr);
  258. packet->data_lo = 0;
  259. return 0;
  260. }
  261. const struct packet_manager_funcs kfd_vi_pm_funcs = {
  262. .map_process = pm_map_process_vi,
  263. .runlist = pm_runlist_vi,
  264. .set_resources = pm_set_resources_vi,
  265. .map_queues = pm_map_queues_vi,
  266. .unmap_queues = pm_unmap_queues_vi,
  267. .query_status = pm_query_status_vi,
  268. .release_mem = pm_release_mem_vi,
  269. .map_process_size = sizeof(struct pm4_mes_map_process),
  270. .runlist_size = sizeof(struct pm4_mes_runlist),
  271. .set_resources_size = sizeof(struct pm4_mes_set_resources),
  272. .map_queues_size = sizeof(struct pm4_mes_map_queues),
  273. .unmap_queues_size = sizeof(struct pm4_mes_unmap_queues),
  274. .query_status_size = sizeof(struct pm4_mes_query_status),
  275. .release_mem_size = sizeof(struct pm4_mec_release_mem)
  276. };