kfd_packet_manager.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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 <linux/slab.h>
  24. #include <linux/mutex.h>
  25. #include "kfd_device_queue_manager.h"
  26. #include "kfd_kernel_queue.h"
  27. #include "kfd_priv.h"
  28. #include "kfd_pm4_headers.h"
  29. #include "kfd_pm4_headers_vi.h"
  30. #include "kfd_pm4_opcodes.h"
  31. static inline void inc_wptr(unsigned int *wptr, unsigned int increment_bytes,
  32. unsigned int buffer_size_bytes)
  33. {
  34. unsigned int temp = *wptr + increment_bytes / sizeof(uint32_t);
  35. BUG_ON((temp * sizeof(uint32_t)) > buffer_size_bytes);
  36. *wptr = temp;
  37. }
  38. static unsigned int build_pm4_header(unsigned int opcode, size_t packet_size)
  39. {
  40. union PM4_MES_TYPE_3_HEADER header;
  41. header.u32all = 0;
  42. header.opcode = opcode;
  43. header.count = packet_size/sizeof(uint32_t) - 2;
  44. header.type = PM4_TYPE_3;
  45. return header.u32all;
  46. }
  47. static void pm_calc_rlib_size(struct packet_manager *pm,
  48. unsigned int *rlib_size,
  49. bool *over_subscription)
  50. {
  51. unsigned int process_count, queue_count;
  52. unsigned int map_queue_size;
  53. BUG_ON(!pm || !rlib_size || !over_subscription);
  54. process_count = pm->dqm->processes_count;
  55. queue_count = pm->dqm->queue_count;
  56. /* check if there is over subscription*/
  57. *over_subscription = false;
  58. if ((process_count > 1) || queue_count > get_queues_num(pm->dqm)) {
  59. *over_subscription = true;
  60. pr_debug("kfd: over subscribed runlist\n");
  61. }
  62. map_queue_size =
  63. (pm->dqm->dev->device_info->asic_family == CHIP_CARRIZO) ?
  64. sizeof(struct pm4_mes_map_queues) :
  65. sizeof(struct pm4_map_queues);
  66. /* calculate run list ib allocation size */
  67. *rlib_size = process_count * sizeof(struct pm4_map_process) +
  68. queue_count * map_queue_size;
  69. /*
  70. * Increase the allocation size in case we need a chained run list
  71. * when over subscription
  72. */
  73. if (*over_subscription)
  74. *rlib_size += sizeof(struct pm4_runlist);
  75. pr_debug("kfd: runlist ib size %d\n", *rlib_size);
  76. }
  77. static int pm_allocate_runlist_ib(struct packet_manager *pm,
  78. unsigned int **rl_buffer,
  79. uint64_t *rl_gpu_buffer,
  80. unsigned int *rl_buffer_size,
  81. bool *is_over_subscription)
  82. {
  83. int retval;
  84. BUG_ON(!pm);
  85. BUG_ON(pm->allocated);
  86. BUG_ON(is_over_subscription == NULL);
  87. pm_calc_rlib_size(pm, rl_buffer_size, is_over_subscription);
  88. retval = kfd_gtt_sa_allocate(pm->dqm->dev, *rl_buffer_size,
  89. &pm->ib_buffer_obj);
  90. if (retval != 0) {
  91. pr_err("kfd: failed to allocate runlist IB\n");
  92. return retval;
  93. }
  94. *(void **)rl_buffer = pm->ib_buffer_obj->cpu_ptr;
  95. *rl_gpu_buffer = pm->ib_buffer_obj->gpu_addr;
  96. memset(*rl_buffer, 0, *rl_buffer_size);
  97. pm->allocated = true;
  98. return retval;
  99. }
  100. static int pm_create_runlist(struct packet_manager *pm, uint32_t *buffer,
  101. uint64_t ib, size_t ib_size_in_dwords, bool chain)
  102. {
  103. struct pm4_runlist *packet;
  104. BUG_ON(!pm || !buffer || !ib);
  105. packet = (struct pm4_runlist *)buffer;
  106. memset(buffer, 0, sizeof(struct pm4_runlist));
  107. packet->header.u32all = build_pm4_header(IT_RUN_LIST,
  108. sizeof(struct pm4_runlist));
  109. packet->bitfields4.ib_size = ib_size_in_dwords;
  110. packet->bitfields4.chain = chain ? 1 : 0;
  111. packet->bitfields4.offload_polling = 0;
  112. packet->bitfields4.valid = 1;
  113. packet->ordinal2 = lower_32_bits(ib);
  114. packet->bitfields3.ib_base_hi = upper_32_bits(ib);
  115. return 0;
  116. }
  117. static int pm_create_map_process(struct packet_manager *pm, uint32_t *buffer,
  118. struct qcm_process_device *qpd)
  119. {
  120. struct pm4_map_process *packet;
  121. struct queue *cur;
  122. uint32_t num_queues;
  123. BUG_ON(!pm || !buffer || !qpd);
  124. packet = (struct pm4_map_process *)buffer;
  125. pr_debug("kfd: In func %s\n", __func__);
  126. memset(buffer, 0, sizeof(struct pm4_map_process));
  127. packet->header.u32all = build_pm4_header(IT_MAP_PROCESS,
  128. sizeof(struct pm4_map_process));
  129. packet->bitfields2.diq_enable = (qpd->is_debug) ? 1 : 0;
  130. packet->bitfields2.process_quantum = 1;
  131. packet->bitfields2.pasid = qpd->pqm->process->pasid;
  132. packet->bitfields3.page_table_base = qpd->page_table_base;
  133. packet->bitfields10.gds_size = qpd->gds_size;
  134. packet->bitfields10.num_gws = qpd->num_gws;
  135. packet->bitfields10.num_oac = qpd->num_oac;
  136. num_queues = 0;
  137. list_for_each_entry(cur, &qpd->queues_list, list)
  138. num_queues++;
  139. packet->bitfields10.num_queues = (qpd->is_debug) ? 0 : num_queues;
  140. packet->sh_mem_config = qpd->sh_mem_config;
  141. packet->sh_mem_bases = qpd->sh_mem_bases;
  142. packet->sh_mem_ape1_base = qpd->sh_mem_ape1_base;
  143. packet->sh_mem_ape1_limit = qpd->sh_mem_ape1_limit;
  144. packet->gds_addr_lo = lower_32_bits(qpd->gds_context_area);
  145. packet->gds_addr_hi = upper_32_bits(qpd->gds_context_area);
  146. return 0;
  147. }
  148. static int pm_create_map_queue_vi(struct packet_manager *pm, uint32_t *buffer,
  149. struct queue *q, bool is_static)
  150. {
  151. struct pm4_mes_map_queues *packet;
  152. bool use_static = is_static;
  153. BUG_ON(!pm || !buffer || !q);
  154. pr_debug("kfd: In func %s\n", __func__);
  155. packet = (struct pm4_mes_map_queues *)buffer;
  156. memset(buffer, 0, sizeof(struct pm4_map_queues));
  157. packet->header.u32all = build_pm4_header(IT_MAP_QUEUES,
  158. sizeof(struct pm4_map_queues));
  159. packet->bitfields2.alloc_format =
  160. alloc_format__mes_map_queues__one_per_pipe_vi;
  161. packet->bitfields2.num_queues = 1;
  162. packet->bitfields2.queue_sel =
  163. queue_sel__mes_map_queues__map_to_hws_determined_queue_slots_vi;
  164. packet->bitfields2.engine_sel =
  165. engine_sel__mes_map_queues__compute_vi;
  166. packet->bitfields2.queue_type =
  167. queue_type__mes_map_queues__normal_compute_vi;
  168. switch (q->properties.type) {
  169. case KFD_QUEUE_TYPE_COMPUTE:
  170. if (use_static)
  171. packet->bitfields2.queue_type =
  172. queue_type__mes_map_queues__normal_latency_static_queue_vi;
  173. break;
  174. case KFD_QUEUE_TYPE_DIQ:
  175. packet->bitfields2.queue_type =
  176. queue_type__mes_map_queues__debug_interface_queue_vi;
  177. break;
  178. case KFD_QUEUE_TYPE_SDMA:
  179. packet->bitfields2.engine_sel =
  180. engine_sel__mes_map_queues__sdma0_vi;
  181. use_static = false; /* no static queues under SDMA */
  182. break;
  183. default:
  184. pr_err("kfd: in %s queue type %d\n", __func__,
  185. q->properties.type);
  186. BUG();
  187. break;
  188. }
  189. packet->bitfields3.doorbell_offset =
  190. q->properties.doorbell_off;
  191. packet->mqd_addr_lo =
  192. lower_32_bits(q->gart_mqd_addr);
  193. packet->mqd_addr_hi =
  194. upper_32_bits(q->gart_mqd_addr);
  195. packet->wptr_addr_lo =
  196. lower_32_bits((uint64_t)q->properties.write_ptr);
  197. packet->wptr_addr_hi =
  198. upper_32_bits((uint64_t)q->properties.write_ptr);
  199. return 0;
  200. }
  201. static int pm_create_map_queue(struct packet_manager *pm, uint32_t *buffer,
  202. struct queue *q, bool is_static)
  203. {
  204. struct pm4_map_queues *packet;
  205. bool use_static = is_static;
  206. BUG_ON(!pm || !buffer || !q);
  207. pr_debug("kfd: In func %s\n", __func__);
  208. packet = (struct pm4_map_queues *)buffer;
  209. memset(buffer, 0, sizeof(struct pm4_map_queues));
  210. packet->header.u32all = build_pm4_header(IT_MAP_QUEUES,
  211. sizeof(struct pm4_map_queues));
  212. packet->bitfields2.alloc_format =
  213. alloc_format__mes_map_queues__one_per_pipe;
  214. packet->bitfields2.num_queues = 1;
  215. packet->bitfields2.queue_sel =
  216. queue_sel__mes_map_queues__map_to_hws_determined_queue_slots;
  217. packet->bitfields2.vidmem = (q->properties.is_interop) ?
  218. vidmem__mes_map_queues__uses_video_memory :
  219. vidmem__mes_map_queues__uses_no_video_memory;
  220. switch (q->properties.type) {
  221. case KFD_QUEUE_TYPE_COMPUTE:
  222. case KFD_QUEUE_TYPE_DIQ:
  223. packet->bitfields2.engine_sel =
  224. engine_sel__mes_map_queues__compute;
  225. break;
  226. case KFD_QUEUE_TYPE_SDMA:
  227. packet->bitfields2.engine_sel =
  228. engine_sel__mes_map_queues__sdma0;
  229. use_static = false; /* no static queues under SDMA */
  230. break;
  231. default:
  232. BUG();
  233. break;
  234. }
  235. packet->mes_map_queues_ordinals[0].bitfields3.doorbell_offset =
  236. q->properties.doorbell_off;
  237. packet->mes_map_queues_ordinals[0].bitfields3.is_static =
  238. (use_static) ? 1 : 0;
  239. packet->mes_map_queues_ordinals[0].mqd_addr_lo =
  240. lower_32_bits(q->gart_mqd_addr);
  241. packet->mes_map_queues_ordinals[0].mqd_addr_hi =
  242. upper_32_bits(q->gart_mqd_addr);
  243. packet->mes_map_queues_ordinals[0].wptr_addr_lo =
  244. lower_32_bits((uint64_t)q->properties.write_ptr);
  245. packet->mes_map_queues_ordinals[0].wptr_addr_hi =
  246. upper_32_bits((uint64_t)q->properties.write_ptr);
  247. return 0;
  248. }
  249. static int pm_create_runlist_ib(struct packet_manager *pm,
  250. struct list_head *queues,
  251. uint64_t *rl_gpu_addr,
  252. size_t *rl_size_bytes)
  253. {
  254. unsigned int alloc_size_bytes;
  255. unsigned int *rl_buffer, rl_wptr, i;
  256. int retval, proccesses_mapped;
  257. struct device_process_node *cur;
  258. struct qcm_process_device *qpd;
  259. struct queue *q;
  260. struct kernel_queue *kq;
  261. bool is_over_subscription;
  262. BUG_ON(!pm || !queues || !rl_size_bytes || !rl_gpu_addr);
  263. rl_wptr = retval = proccesses_mapped = 0;
  264. retval = pm_allocate_runlist_ib(pm, &rl_buffer, rl_gpu_addr,
  265. &alloc_size_bytes, &is_over_subscription);
  266. if (retval != 0)
  267. return retval;
  268. *rl_size_bytes = alloc_size_bytes;
  269. pr_debug("kfd: In func %s\n", __func__);
  270. pr_debug("kfd: building runlist ib process count: %d queues count %d\n",
  271. pm->dqm->processes_count, pm->dqm->queue_count);
  272. /* build the run list ib packet */
  273. list_for_each_entry(cur, queues, list) {
  274. qpd = cur->qpd;
  275. /* build map process packet */
  276. if (proccesses_mapped >= pm->dqm->processes_count) {
  277. pr_debug("kfd: not enough space left in runlist IB\n");
  278. pm_release_ib(pm);
  279. return -ENOMEM;
  280. }
  281. retval = pm_create_map_process(pm, &rl_buffer[rl_wptr], qpd);
  282. if (retval != 0)
  283. return retval;
  284. proccesses_mapped++;
  285. inc_wptr(&rl_wptr, sizeof(struct pm4_map_process),
  286. alloc_size_bytes);
  287. list_for_each_entry(kq, &qpd->priv_queue_list, list) {
  288. if (!kq->queue->properties.is_active)
  289. continue;
  290. pr_debug("kfd: static_queue, mapping kernel q %d, is debug status %d\n",
  291. kq->queue->queue, qpd->is_debug);
  292. if (pm->dqm->dev->device_info->asic_family ==
  293. CHIP_CARRIZO)
  294. retval = pm_create_map_queue_vi(pm,
  295. &rl_buffer[rl_wptr],
  296. kq->queue,
  297. qpd->is_debug);
  298. else
  299. retval = pm_create_map_queue(pm,
  300. &rl_buffer[rl_wptr],
  301. kq->queue,
  302. qpd->is_debug);
  303. if (retval != 0)
  304. return retval;
  305. inc_wptr(&rl_wptr,
  306. sizeof(struct pm4_map_queues),
  307. alloc_size_bytes);
  308. }
  309. list_for_each_entry(q, &qpd->queues_list, list) {
  310. if (!q->properties.is_active)
  311. continue;
  312. pr_debug("kfd: static_queue, mapping user queue %d, is debug status %d\n",
  313. q->queue, qpd->is_debug);
  314. if (pm->dqm->dev->device_info->asic_family ==
  315. CHIP_CARRIZO)
  316. retval = pm_create_map_queue_vi(pm,
  317. &rl_buffer[rl_wptr],
  318. q,
  319. qpd->is_debug);
  320. else
  321. retval = pm_create_map_queue(pm,
  322. &rl_buffer[rl_wptr],
  323. q,
  324. qpd->is_debug);
  325. if (retval != 0)
  326. return retval;
  327. inc_wptr(&rl_wptr,
  328. sizeof(struct pm4_map_queues),
  329. alloc_size_bytes);
  330. }
  331. }
  332. pr_debug("kfd: finished map process and queues to runlist\n");
  333. if (is_over_subscription)
  334. pm_create_runlist(pm, &rl_buffer[rl_wptr], *rl_gpu_addr,
  335. alloc_size_bytes / sizeof(uint32_t), true);
  336. for (i = 0; i < alloc_size_bytes / sizeof(uint32_t); i++)
  337. pr_debug("0x%2X ", rl_buffer[i]);
  338. pr_debug("\n");
  339. return 0;
  340. }
  341. int pm_init(struct packet_manager *pm, struct device_queue_manager *dqm)
  342. {
  343. BUG_ON(!dqm);
  344. pm->dqm = dqm;
  345. mutex_init(&pm->lock);
  346. pm->priv_queue = kernel_queue_init(dqm->dev, KFD_QUEUE_TYPE_HIQ);
  347. if (pm->priv_queue == NULL) {
  348. mutex_destroy(&pm->lock);
  349. return -ENOMEM;
  350. }
  351. pm->allocated = false;
  352. return 0;
  353. }
  354. void pm_uninit(struct packet_manager *pm)
  355. {
  356. BUG_ON(!pm);
  357. mutex_destroy(&pm->lock);
  358. kernel_queue_uninit(pm->priv_queue);
  359. }
  360. int pm_send_set_resources(struct packet_manager *pm,
  361. struct scheduling_resources *res)
  362. {
  363. struct pm4_set_resources *packet;
  364. BUG_ON(!pm || !res);
  365. pr_debug("kfd: In func %s\n", __func__);
  366. mutex_lock(&pm->lock);
  367. pm->priv_queue->ops.acquire_packet_buffer(pm->priv_queue,
  368. sizeof(*packet) / sizeof(uint32_t),
  369. (unsigned int **)&packet);
  370. if (packet == NULL) {
  371. mutex_unlock(&pm->lock);
  372. pr_err("kfd: failed to allocate buffer on kernel queue\n");
  373. return -ENOMEM;
  374. }
  375. memset(packet, 0, sizeof(struct pm4_set_resources));
  376. packet->header.u32all = build_pm4_header(IT_SET_RESOURCES,
  377. sizeof(struct pm4_set_resources));
  378. packet->bitfields2.queue_type =
  379. queue_type__mes_set_resources__hsa_interface_queue_hiq;
  380. packet->bitfields2.vmid_mask = res->vmid_mask;
  381. packet->bitfields2.unmap_latency = KFD_UNMAP_LATENCY;
  382. packet->bitfields7.oac_mask = res->oac_mask;
  383. packet->bitfields8.gds_heap_base = res->gds_heap_base;
  384. packet->bitfields8.gds_heap_size = res->gds_heap_size;
  385. packet->gws_mask_lo = lower_32_bits(res->gws_mask);
  386. packet->gws_mask_hi = upper_32_bits(res->gws_mask);
  387. packet->queue_mask_lo = lower_32_bits(res->queue_mask);
  388. packet->queue_mask_hi = upper_32_bits(res->queue_mask);
  389. pm->priv_queue->ops.submit_packet(pm->priv_queue);
  390. mutex_unlock(&pm->lock);
  391. return 0;
  392. }
  393. int pm_send_runlist(struct packet_manager *pm, struct list_head *dqm_queues)
  394. {
  395. uint64_t rl_gpu_ib_addr;
  396. uint32_t *rl_buffer;
  397. size_t rl_ib_size, packet_size_dwords;
  398. int retval;
  399. BUG_ON(!pm || !dqm_queues);
  400. retval = pm_create_runlist_ib(pm, dqm_queues, &rl_gpu_ib_addr,
  401. &rl_ib_size);
  402. if (retval != 0)
  403. goto fail_create_runlist_ib;
  404. pr_debug("kfd: runlist IB address: 0x%llX\n", rl_gpu_ib_addr);
  405. packet_size_dwords = sizeof(struct pm4_runlist) / sizeof(uint32_t);
  406. mutex_lock(&pm->lock);
  407. retval = pm->priv_queue->ops.acquire_packet_buffer(pm->priv_queue,
  408. packet_size_dwords, &rl_buffer);
  409. if (retval != 0)
  410. goto fail_acquire_packet_buffer;
  411. retval = pm_create_runlist(pm, rl_buffer, rl_gpu_ib_addr,
  412. rl_ib_size / sizeof(uint32_t), false);
  413. if (retval != 0)
  414. goto fail_create_runlist;
  415. pm->priv_queue->ops.submit_packet(pm->priv_queue);
  416. mutex_unlock(&pm->lock);
  417. return retval;
  418. fail_create_runlist:
  419. pm->priv_queue->ops.rollback_packet(pm->priv_queue);
  420. fail_acquire_packet_buffer:
  421. mutex_unlock(&pm->lock);
  422. fail_create_runlist_ib:
  423. if (pm->allocated)
  424. pm_release_ib(pm);
  425. return retval;
  426. }
  427. int pm_send_query_status(struct packet_manager *pm, uint64_t fence_address,
  428. uint32_t fence_value)
  429. {
  430. int retval;
  431. struct pm4_query_status *packet;
  432. BUG_ON(!pm || !fence_address);
  433. mutex_lock(&pm->lock);
  434. retval = pm->priv_queue->ops.acquire_packet_buffer(
  435. pm->priv_queue,
  436. sizeof(struct pm4_query_status) / sizeof(uint32_t),
  437. (unsigned int **)&packet);
  438. if (retval != 0)
  439. goto fail_acquire_packet_buffer;
  440. packet->header.u32all = build_pm4_header(IT_QUERY_STATUS,
  441. sizeof(struct pm4_query_status));
  442. packet->bitfields2.context_id = 0;
  443. packet->bitfields2.interrupt_sel =
  444. interrupt_sel__mes_query_status__completion_status;
  445. packet->bitfields2.command =
  446. command__mes_query_status__fence_only_after_write_ack;
  447. packet->addr_hi = upper_32_bits((uint64_t)fence_address);
  448. packet->addr_lo = lower_32_bits((uint64_t)fence_address);
  449. packet->data_hi = upper_32_bits((uint64_t)fence_value);
  450. packet->data_lo = lower_32_bits((uint64_t)fence_value);
  451. pm->priv_queue->ops.submit_packet(pm->priv_queue);
  452. mutex_unlock(&pm->lock);
  453. return 0;
  454. fail_acquire_packet_buffer:
  455. mutex_unlock(&pm->lock);
  456. return retval;
  457. }
  458. int pm_send_unmap_queue(struct packet_manager *pm, enum kfd_queue_type type,
  459. enum kfd_preempt_type_filter mode,
  460. uint32_t filter_param, bool reset,
  461. unsigned int sdma_engine)
  462. {
  463. int retval;
  464. uint32_t *buffer;
  465. struct pm4_unmap_queues *packet;
  466. BUG_ON(!pm);
  467. mutex_lock(&pm->lock);
  468. retval = pm->priv_queue->ops.acquire_packet_buffer(
  469. pm->priv_queue,
  470. sizeof(struct pm4_unmap_queues) / sizeof(uint32_t),
  471. &buffer);
  472. if (retval != 0)
  473. goto err_acquire_packet_buffer;
  474. packet = (struct pm4_unmap_queues *)buffer;
  475. memset(buffer, 0, sizeof(struct pm4_unmap_queues));
  476. pr_debug("kfd: static_queue: unmapping queues: mode is %d , reset is %d , type is %d\n",
  477. mode, reset, type);
  478. packet->header.u32all = build_pm4_header(IT_UNMAP_QUEUES,
  479. sizeof(struct pm4_unmap_queues));
  480. switch (type) {
  481. case KFD_QUEUE_TYPE_COMPUTE:
  482. case KFD_QUEUE_TYPE_DIQ:
  483. packet->bitfields2.engine_sel =
  484. engine_sel__mes_unmap_queues__compute;
  485. break;
  486. case KFD_QUEUE_TYPE_SDMA:
  487. packet->bitfields2.engine_sel =
  488. engine_sel__mes_unmap_queues__sdma0 + sdma_engine;
  489. break;
  490. default:
  491. BUG();
  492. break;
  493. }
  494. if (reset)
  495. packet->bitfields2.action =
  496. action__mes_unmap_queues__reset_queues;
  497. else
  498. packet->bitfields2.action =
  499. action__mes_unmap_queues__preempt_queues;
  500. switch (mode) {
  501. case KFD_PREEMPT_TYPE_FILTER_SINGLE_QUEUE:
  502. packet->bitfields2.queue_sel =
  503. queue_sel__mes_unmap_queues__perform_request_on_specified_queues;
  504. packet->bitfields2.num_queues = 1;
  505. packet->bitfields3b.doorbell_offset0 = filter_param;
  506. break;
  507. case KFD_PREEMPT_TYPE_FILTER_BY_PASID:
  508. packet->bitfields2.queue_sel =
  509. queue_sel__mes_unmap_queues__perform_request_on_pasid_queues;
  510. packet->bitfields3a.pasid = filter_param;
  511. break;
  512. case KFD_PREEMPT_TYPE_FILTER_ALL_QUEUES:
  513. packet->bitfields2.queue_sel =
  514. queue_sel__mes_unmap_queues__perform_request_on_all_active_queues;
  515. break;
  516. case KFD_PREEMPT_TYPE_FILTER_DYNAMIC_QUEUES:
  517. /* in this case, we do not preempt static queues */
  518. packet->bitfields2.queue_sel =
  519. queue_sel__mes_unmap_queues__perform_request_on_dynamic_queues_only;
  520. break;
  521. default:
  522. BUG();
  523. break;
  524. }
  525. pm->priv_queue->ops.submit_packet(pm->priv_queue);
  526. mutex_unlock(&pm->lock);
  527. return 0;
  528. err_acquire_packet_buffer:
  529. mutex_unlock(&pm->lock);
  530. return retval;
  531. }
  532. void pm_release_ib(struct packet_manager *pm)
  533. {
  534. BUG_ON(!pm);
  535. mutex_lock(&pm->lock);
  536. if (pm->allocated) {
  537. kfd_gtt_sa_free(pm->dqm->dev, pm->ib_buffer_obj);
  538. pm->allocated = false;
  539. }
  540. mutex_unlock(&pm->lock);
  541. }