kfd_packet_manager.c 18 KB

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