1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2020-2024 Intel Corporation
6 #include <drm/drm_file.h>
8 #include <linux/bitfield.h>
9 #include <linux/highmem.h>
10 #include <linux/pci.h>
11 #include <linux/module.h>
12 #include <uapi/drm/ivpu_accel.h>
19 #include "ivpu_jsm_msg.h"
21 #include "ivpu_trace.h"
22 #include "vpu_boot_api.h"
25 #define JOB_MAX_BUFFER_COUNT 65535
27 static void ivpu_cmdq_ring_db(struct ivpu_device
*vdev
, struct ivpu_cmdq
*cmdq
)
29 ivpu_hw_db_set(vdev
, cmdq
->db_id
);
32 static int ivpu_preemption_buffers_create(struct ivpu_device
*vdev
,
33 struct ivpu_file_priv
*file_priv
, struct ivpu_cmdq
*cmdq
)
35 u64 primary_size
= ALIGN(vdev
->fw
->primary_preempt_buf_size
, PAGE_SIZE
);
36 u64 secondary_size
= ALIGN(vdev
->fw
->secondary_preempt_buf_size
, PAGE_SIZE
);
38 if (vdev
->fw
->sched_mode
!= VPU_SCHEDULING_MODE_HW
||
39 ivpu_test_mode
& IVPU_TEST_MODE_MIP_DISABLE
)
42 cmdq
->primary_preempt_buf
= ivpu_bo_create(vdev
, &file_priv
->ctx
, &vdev
->hw
->ranges
.user
,
43 primary_size
, DRM_IVPU_BO_WC
);
44 if (!cmdq
->primary_preempt_buf
) {
45 ivpu_err(vdev
, "Failed to create primary preemption buffer\n");
49 cmdq
->secondary_preempt_buf
= ivpu_bo_create(vdev
, &file_priv
->ctx
, &vdev
->hw
->ranges
.dma
,
50 secondary_size
, DRM_IVPU_BO_WC
);
51 if (!cmdq
->secondary_preempt_buf
) {
52 ivpu_err(vdev
, "Failed to create secondary preemption buffer\n");
53 goto err_free_primary
;
59 ivpu_bo_free(cmdq
->primary_preempt_buf
);
60 cmdq
->primary_preempt_buf
= NULL
;
64 static void ivpu_preemption_buffers_free(struct ivpu_device
*vdev
,
65 struct ivpu_file_priv
*file_priv
, struct ivpu_cmdq
*cmdq
)
67 if (vdev
->fw
->sched_mode
!= VPU_SCHEDULING_MODE_HW
)
70 if (cmdq
->primary_preempt_buf
)
71 ivpu_bo_free(cmdq
->primary_preempt_buf
);
72 if (cmdq
->secondary_preempt_buf
)
73 ivpu_bo_free(cmdq
->secondary_preempt_buf
);
76 static struct ivpu_cmdq
*ivpu_cmdq_alloc(struct ivpu_file_priv
*file_priv
)
78 struct ivpu_device
*vdev
= file_priv
->vdev
;
79 struct ivpu_cmdq
*cmdq
;
82 cmdq
= kzalloc(sizeof(*cmdq
), GFP_KERNEL
);
86 ret
= xa_alloc_cyclic(&vdev
->db_xa
, &cmdq
->db_id
, NULL
, vdev
->db_limit
, &vdev
->db_next
,
89 ivpu_err(vdev
, "Failed to allocate doorbell id: %d\n", ret
);
93 ret
= xa_alloc_cyclic(&file_priv
->cmdq_xa
, &cmdq
->id
, cmdq
, file_priv
->cmdq_limit
,
94 &file_priv
->cmdq_id_next
, GFP_KERNEL
);
96 ivpu_err(vdev
, "Failed to allocate command queue id: %d\n", ret
);
100 cmdq
->mem
= ivpu_bo_create_global(vdev
, SZ_4K
, DRM_IVPU_BO_WC
| DRM_IVPU_BO_MAPPABLE
);
102 goto err_erase_cmdq_xa
;
104 ret
= ivpu_preemption_buffers_create(vdev
, file_priv
, cmdq
);
106 ivpu_warn(vdev
, "Failed to allocate preemption buffers, preemption limited\n");
111 xa_erase(&file_priv
->cmdq_xa
, cmdq
->id
);
113 xa_erase(&vdev
->db_xa
, cmdq
->db_id
);
119 static void ivpu_cmdq_free(struct ivpu_file_priv
*file_priv
, struct ivpu_cmdq
*cmdq
)
124 ivpu_preemption_buffers_free(file_priv
->vdev
, file_priv
, cmdq
);
125 ivpu_bo_free(cmdq
->mem
);
126 xa_erase(&file_priv
->vdev
->db_xa
, cmdq
->db_id
);
130 static int ivpu_hws_cmdq_init(struct ivpu_file_priv
*file_priv
, struct ivpu_cmdq
*cmdq
, u16 engine
,
133 struct ivpu_device
*vdev
= file_priv
->vdev
;
136 ret
= ivpu_jsm_hws_create_cmdq(vdev
, file_priv
->ctx
.id
, file_priv
->ctx
.id
, cmdq
->id
,
137 task_pid_nr(current
), engine
,
138 cmdq
->mem
->vpu_addr
, ivpu_bo_size(cmdq
->mem
));
142 ret
= ivpu_jsm_hws_set_context_sched_properties(vdev
, file_priv
->ctx
.id
, cmdq
->id
,
150 static int ivpu_register_db(struct ivpu_file_priv
*file_priv
, struct ivpu_cmdq
*cmdq
)
152 struct ivpu_device
*vdev
= file_priv
->vdev
;
155 if (vdev
->fw
->sched_mode
== VPU_SCHEDULING_MODE_HW
)
156 ret
= ivpu_jsm_hws_register_db(vdev
, file_priv
->ctx
.id
, cmdq
->id
, cmdq
->db_id
,
157 cmdq
->mem
->vpu_addr
, ivpu_bo_size(cmdq
->mem
));
159 ret
= ivpu_jsm_register_db(vdev
, file_priv
->ctx
.id
, cmdq
->db_id
,
160 cmdq
->mem
->vpu_addr
, ivpu_bo_size(cmdq
->mem
));
163 ivpu_dbg(vdev
, JOB
, "DB %d registered to cmdq %d ctx %d\n",
164 cmdq
->db_id
, cmdq
->id
, file_priv
->ctx
.id
);
170 ivpu_cmdq_init(struct ivpu_file_priv
*file_priv
, struct ivpu_cmdq
*cmdq
, u8 priority
)
172 struct ivpu_device
*vdev
= file_priv
->vdev
;
173 struct vpu_job_queue_header
*jobq_header
;
176 lockdep_assert_held(&file_priv
->lock
);
178 if (cmdq
->db_registered
)
181 cmdq
->entry_count
= (u32
)((ivpu_bo_size(cmdq
->mem
) - sizeof(struct vpu_job_queue_header
)) /
182 sizeof(struct vpu_job_queue_entry
));
184 cmdq
->jobq
= (struct vpu_job_queue
*)ivpu_bo_vaddr(cmdq
->mem
);
185 jobq_header
= &cmdq
->jobq
->header
;
186 jobq_header
->engine_idx
= VPU_ENGINE_COMPUTE
;
187 jobq_header
->head
= 0;
188 jobq_header
->tail
= 0;
189 if (ivpu_test_mode
& IVPU_TEST_MODE_TURBO
) {
190 ivpu_dbg(vdev
, JOB
, "Turbo mode enabled");
191 jobq_header
->flags
= VPU_JOB_QUEUE_FLAGS_TURBO_MODE
;
194 wmb(); /* Flush WC buffer for jobq->header */
196 if (vdev
->fw
->sched_mode
== VPU_SCHEDULING_MODE_HW
) {
197 ret
= ivpu_hws_cmdq_init(file_priv
, cmdq
, VPU_ENGINE_COMPUTE
, priority
);
202 ret
= ivpu_register_db(file_priv
, cmdq
);
206 cmdq
->db_registered
= true;
211 static int ivpu_cmdq_fini(struct ivpu_file_priv
*file_priv
, struct ivpu_cmdq
*cmdq
)
213 struct ivpu_device
*vdev
= file_priv
->vdev
;
216 lockdep_assert_held(&file_priv
->lock
);
218 if (!cmdq
->db_registered
)
221 cmdq
->db_registered
= false;
223 if (vdev
->fw
->sched_mode
== VPU_SCHEDULING_MODE_HW
) {
224 ret
= ivpu_jsm_hws_destroy_cmdq(vdev
, file_priv
->ctx
.id
, cmdq
->id
);
226 ivpu_dbg(vdev
, JOB
, "Command queue %d destroyed\n", cmdq
->id
);
229 ret
= ivpu_jsm_unregister_db(vdev
, cmdq
->db_id
);
231 ivpu_dbg(vdev
, JOB
, "DB %d unregistered\n", cmdq
->db_id
);
236 static struct ivpu_cmdq
*ivpu_cmdq_acquire(struct ivpu_file_priv
*file_priv
, u8 priority
)
238 struct ivpu_cmdq
*cmdq
;
239 unsigned long cmdq_id
;
242 lockdep_assert_held(&file_priv
->lock
);
244 xa_for_each(&file_priv
->cmdq_xa
, cmdq_id
, cmdq
)
245 if (cmdq
->priority
== priority
)
249 cmdq
= ivpu_cmdq_alloc(file_priv
);
252 cmdq
->priority
= priority
;
255 ret
= ivpu_cmdq_init(file_priv
, cmdq
, priority
);
262 void ivpu_cmdq_release_all_locked(struct ivpu_file_priv
*file_priv
)
264 struct ivpu_cmdq
*cmdq
;
265 unsigned long cmdq_id
;
267 lockdep_assert_held(&file_priv
->lock
);
269 xa_for_each(&file_priv
->cmdq_xa
, cmdq_id
, cmdq
) {
270 xa_erase(&file_priv
->cmdq_xa
, cmdq_id
);
271 ivpu_cmdq_fini(file_priv
, cmdq
);
272 ivpu_cmdq_free(file_priv
, cmdq
);
277 * Mark the doorbell as unregistered
278 * This function needs to be called when the VPU hardware is restarted
279 * and FW loses job queue state. The next time job queue is used it
280 * will be registered again.
282 static void ivpu_cmdq_reset(struct ivpu_file_priv
*file_priv
)
284 struct ivpu_cmdq
*cmdq
;
285 unsigned long cmdq_id
;
287 mutex_lock(&file_priv
->lock
);
289 xa_for_each(&file_priv
->cmdq_xa
, cmdq_id
, cmdq
)
290 cmdq
->db_registered
= false;
292 mutex_unlock(&file_priv
->lock
);
295 void ivpu_cmdq_reset_all_contexts(struct ivpu_device
*vdev
)
297 struct ivpu_file_priv
*file_priv
;
298 unsigned long ctx_id
;
300 mutex_lock(&vdev
->context_list_lock
);
302 xa_for_each(&vdev
->context_xa
, ctx_id
, file_priv
)
303 ivpu_cmdq_reset(file_priv
);
305 mutex_unlock(&vdev
->context_list_lock
);
308 static void ivpu_cmdq_fini_all(struct ivpu_file_priv
*file_priv
)
310 struct ivpu_cmdq
*cmdq
;
311 unsigned long cmdq_id
;
313 xa_for_each(&file_priv
->cmdq_xa
, cmdq_id
, cmdq
)
314 ivpu_cmdq_fini(file_priv
, cmdq
);
317 void ivpu_context_abort_locked(struct ivpu_file_priv
*file_priv
)
319 struct ivpu_device
*vdev
= file_priv
->vdev
;
321 lockdep_assert_held(&file_priv
->lock
);
323 ivpu_cmdq_fini_all(file_priv
);
325 if (vdev
->fw
->sched_mode
== VPU_SCHEDULING_MODE_OS
)
326 ivpu_jsm_context_release(vdev
, file_priv
->ctx
.id
);
329 static int ivpu_cmdq_push_job(struct ivpu_cmdq
*cmdq
, struct ivpu_job
*job
)
331 struct ivpu_device
*vdev
= job
->vdev
;
332 struct vpu_job_queue_header
*header
= &cmdq
->jobq
->header
;
333 struct vpu_job_queue_entry
*entry
;
334 u32 tail
= READ_ONCE(header
->tail
);
335 u32 next_entry
= (tail
+ 1) % cmdq
->entry_count
;
337 /* Check if there is space left in job queue */
338 if (next_entry
== header
->head
) {
339 ivpu_dbg(vdev
, JOB
, "Job queue full: ctx %d cmdq %d db %d head %d tail %d\n",
340 job
->file_priv
->ctx
.id
, cmdq
->id
, cmdq
->db_id
, header
->head
, tail
);
344 entry
= &cmdq
->jobq
->slot
[tail
].job
;
345 entry
->batch_buf_addr
= job
->cmd_buf_vpu_addr
;
346 entry
->job_id
= job
->job_id
;
348 if (unlikely(ivpu_test_mode
& IVPU_TEST_MODE_NULL_SUBMISSION
))
349 entry
->flags
= VPU_JOB_FLAGS_NULL_SUBMISSION_MASK
;
351 if (vdev
->fw
->sched_mode
== VPU_SCHEDULING_MODE_HW
) {
352 if (cmdq
->primary_preempt_buf
) {
353 entry
->primary_preempt_buf_addr
= cmdq
->primary_preempt_buf
->vpu_addr
;
354 entry
->primary_preempt_buf_size
= ivpu_bo_size(cmdq
->primary_preempt_buf
);
357 if (cmdq
->secondary_preempt_buf
) {
358 entry
->secondary_preempt_buf_addr
= cmdq
->secondary_preempt_buf
->vpu_addr
;
359 entry
->secondary_preempt_buf_size
=
360 ivpu_bo_size(cmdq
->secondary_preempt_buf
);
364 wmb(); /* Ensure that tail is updated after filling entry */
365 header
->tail
= next_entry
;
366 wmb(); /* Flush WC buffer for jobq header */
372 struct dma_fence base
;
373 spinlock_t lock
; /* protects base */
374 struct ivpu_device
*vdev
;
377 static inline struct ivpu_fence
*to_vpu_fence(struct dma_fence
*fence
)
379 return container_of(fence
, struct ivpu_fence
, base
);
382 static const char *ivpu_fence_get_driver_name(struct dma_fence
*fence
)
387 static const char *ivpu_fence_get_timeline_name(struct dma_fence
*fence
)
389 struct ivpu_fence
*ivpu_fence
= to_vpu_fence(fence
);
391 return dev_name(ivpu_fence
->vdev
->drm
.dev
);
394 static const struct dma_fence_ops ivpu_fence_ops
= {
395 .get_driver_name
= ivpu_fence_get_driver_name
,
396 .get_timeline_name
= ivpu_fence_get_timeline_name
,
399 static struct dma_fence
*ivpu_fence_create(struct ivpu_device
*vdev
)
401 struct ivpu_fence
*fence
;
403 fence
= kzalloc(sizeof(*fence
), GFP_KERNEL
);
408 spin_lock_init(&fence
->lock
);
409 dma_fence_init(&fence
->base
, &ivpu_fence_ops
, &fence
->lock
, dma_fence_context_alloc(1), 1);
414 static void ivpu_job_destroy(struct ivpu_job
*job
)
416 struct ivpu_device
*vdev
= job
->vdev
;
419 ivpu_dbg(vdev
, JOB
, "Job destroyed: id %3u ctx %2d engine %d",
420 job
->job_id
, job
->file_priv
->ctx
.id
, job
->engine_idx
);
422 for (i
= 0; i
< job
->bo_count
; i
++)
424 drm_gem_object_put(&job
->bos
[i
]->base
.base
);
426 dma_fence_put(job
->done_fence
);
427 ivpu_file_priv_put(&job
->file_priv
);
431 static struct ivpu_job
*
432 ivpu_job_create(struct ivpu_file_priv
*file_priv
, u32 engine_idx
, u32 bo_count
)
434 struct ivpu_device
*vdev
= file_priv
->vdev
;
435 struct ivpu_job
*job
;
437 job
= kzalloc(struct_size(job
, bos
, bo_count
), GFP_KERNEL
);
442 job
->engine_idx
= engine_idx
;
443 job
->bo_count
= bo_count
;
444 job
->done_fence
= ivpu_fence_create(vdev
);
445 if (!job
->done_fence
) {
446 ivpu_warn_ratelimited(vdev
, "Failed to create a fence\n");
450 job
->file_priv
= ivpu_file_priv_get(file_priv
);
452 trace_job("create", job
);
453 ivpu_dbg(vdev
, JOB
, "Job created: ctx %2d engine %d", file_priv
->ctx
.id
, job
->engine_idx
);
461 static struct ivpu_job
*ivpu_job_remove_from_submitted_jobs(struct ivpu_device
*vdev
, u32 job_id
)
463 struct ivpu_job
*job
;
465 xa_lock(&vdev
->submitted_jobs_xa
);
466 job
= __xa_erase(&vdev
->submitted_jobs_xa
, job_id
);
468 if (xa_empty(&vdev
->submitted_jobs_xa
) && job
) {
469 vdev
->busy_time
= ktime_add(ktime_sub(ktime_get(), vdev
->busy_start_ts
),
473 xa_unlock(&vdev
->submitted_jobs_xa
);
478 static int ivpu_job_signal_and_destroy(struct ivpu_device
*vdev
, u32 job_id
, u32 job_status
)
480 struct ivpu_job
*job
;
482 job
= ivpu_job_remove_from_submitted_jobs(vdev
, job_id
);
486 if (job
->file_priv
->has_mmu_faults
)
487 job_status
= DRM_IVPU_JOB_STATUS_ABORTED
;
489 job
->bos
[CMD_BUF_IDX
]->job_status
= job_status
;
490 dma_fence_signal(job
->done_fence
);
492 trace_job("done", job
);
493 ivpu_dbg(vdev
, JOB
, "Job complete: id %3u ctx %2d engine %d status 0x%x\n",
494 job
->job_id
, job
->file_priv
->ctx
.id
, job
->engine_idx
, job_status
);
496 ivpu_job_destroy(job
);
497 ivpu_stop_job_timeout_detection(vdev
);
503 void ivpu_jobs_abort_all(struct ivpu_device
*vdev
)
505 struct ivpu_job
*job
;
508 xa_for_each(&vdev
->submitted_jobs_xa
, id
, job
)
509 ivpu_job_signal_and_destroy(vdev
, id
, DRM_IVPU_JOB_STATUS_ABORTED
);
512 static int ivpu_job_submit(struct ivpu_job
*job
, u8 priority
)
514 struct ivpu_file_priv
*file_priv
= job
->file_priv
;
515 struct ivpu_device
*vdev
= job
->vdev
;
516 struct ivpu_cmdq
*cmdq
;
520 ret
= ivpu_rpm_get(vdev
);
524 mutex_lock(&file_priv
->lock
);
526 cmdq
= ivpu_cmdq_acquire(file_priv
, priority
);
528 ivpu_warn_ratelimited(vdev
, "Failed to get job queue, ctx %d engine %d prio %d\n",
529 file_priv
->ctx
.id
, job
->engine_idx
, priority
);
531 goto err_unlock_file_priv
;
534 xa_lock(&vdev
->submitted_jobs_xa
);
535 is_first_job
= xa_empty(&vdev
->submitted_jobs_xa
);
536 ret
= __xa_alloc_cyclic(&vdev
->submitted_jobs_xa
, &job
->job_id
, job
, file_priv
->job_limit
,
537 &file_priv
->job_id_next
, GFP_KERNEL
);
539 ivpu_dbg(vdev
, JOB
, "Too many active jobs in ctx %d\n",
542 goto err_unlock_submitted_jobs_xa
;
545 ret
= ivpu_cmdq_push_job(cmdq
, job
);
549 ivpu_start_job_timeout_detection(vdev
);
551 if (unlikely(ivpu_test_mode
& IVPU_TEST_MODE_NULL_HW
)) {
552 cmdq
->jobq
->header
.head
= cmdq
->jobq
->header
.tail
;
553 wmb(); /* Flush WC buffer for jobq header */
555 ivpu_cmdq_ring_db(vdev
, cmdq
);
557 vdev
->busy_start_ts
= ktime_get();
560 trace_job("submit", job
);
561 ivpu_dbg(vdev
, JOB
, "Job submitted: id %3u ctx %2d engine %d prio %d addr 0x%llx next %d\n",
562 job
->job_id
, file_priv
->ctx
.id
, job
->engine_idx
, priority
,
563 job
->cmd_buf_vpu_addr
, cmdq
->jobq
->header
.tail
);
565 xa_unlock(&vdev
->submitted_jobs_xa
);
567 mutex_unlock(&file_priv
->lock
);
569 if (unlikely(ivpu_test_mode
& IVPU_TEST_MODE_NULL_HW
))
570 ivpu_job_signal_and_destroy(vdev
, job
->job_id
, VPU_JSM_STATUS_SUCCESS
);
575 __xa_erase(&vdev
->submitted_jobs_xa
, job
->job_id
);
576 err_unlock_submitted_jobs_xa
:
577 xa_unlock(&vdev
->submitted_jobs_xa
);
578 err_unlock_file_priv
:
579 mutex_unlock(&file_priv
->lock
);
585 ivpu_job_prepare_bos_for_submit(struct drm_file
*file
, struct ivpu_job
*job
, u32
*buf_handles
,
586 u32 buf_count
, u32 commands_offset
)
588 struct ivpu_file_priv
*file_priv
= file
->driver_priv
;
589 struct ivpu_device
*vdev
= file_priv
->vdev
;
590 struct ww_acquire_ctx acquire_ctx
;
591 enum dma_resv_usage usage
;
596 for (i
= 0; i
< buf_count
; i
++) {
597 struct drm_gem_object
*obj
= drm_gem_object_lookup(file
, buf_handles
[i
]);
602 job
->bos
[i
] = to_ivpu_bo(obj
);
604 ret
= ivpu_bo_pin(job
->bos
[i
]);
609 bo
= job
->bos
[CMD_BUF_IDX
];
610 if (!dma_resv_test_signaled(bo
->base
.base
.resv
, DMA_RESV_USAGE_READ
)) {
611 ivpu_warn(vdev
, "Buffer is already in use\n");
615 if (commands_offset
>= ivpu_bo_size(bo
)) {
616 ivpu_warn(vdev
, "Invalid command buffer offset %u\n", commands_offset
);
620 job
->cmd_buf_vpu_addr
= bo
->vpu_addr
+ commands_offset
;
622 ret
= drm_gem_lock_reservations((struct drm_gem_object
**)job
->bos
, buf_count
,
625 ivpu_warn(vdev
, "Failed to lock reservations: %d\n", ret
);
629 for (i
= 0; i
< buf_count
; i
++) {
630 ret
= dma_resv_reserve_fences(job
->bos
[i
]->base
.base
.resv
, 1);
632 ivpu_warn(vdev
, "Failed to reserve fences: %d\n", ret
);
633 goto unlock_reservations
;
637 for (i
= 0; i
< buf_count
; i
++) {
638 usage
= (i
== CMD_BUF_IDX
) ? DMA_RESV_USAGE_WRITE
: DMA_RESV_USAGE_BOOKKEEP
;
639 dma_resv_add_fence(job
->bos
[i
]->base
.base
.resv
, job
->done_fence
, usage
);
643 drm_gem_unlock_reservations((struct drm_gem_object
**)job
->bos
, buf_count
, &acquire_ctx
);
645 wmb(); /* Flush write combining buffers */
650 static inline u8
ivpu_job_to_hws_priority(struct ivpu_file_priv
*file_priv
, u8 priority
)
652 if (priority
== DRM_IVPU_JOB_PRIORITY_DEFAULT
)
653 return DRM_IVPU_JOB_PRIORITY_NORMAL
;
658 int ivpu_submit_ioctl(struct drm_device
*dev
, void *data
, struct drm_file
*file
)
660 struct ivpu_file_priv
*file_priv
= file
->driver_priv
;
661 struct ivpu_device
*vdev
= file_priv
->vdev
;
662 struct drm_ivpu_submit
*params
= data
;
663 struct ivpu_job
*job
;
668 if (params
->engine
!= DRM_IVPU_ENGINE_COMPUTE
)
671 if (params
->priority
> DRM_IVPU_JOB_PRIORITY_REALTIME
)
674 if (params
->buffer_count
== 0 || params
->buffer_count
> JOB_MAX_BUFFER_COUNT
)
677 if (!IS_ALIGNED(params
->commands_offset
, 8))
680 if (!file_priv
->ctx
.id
)
683 if (file_priv
->has_mmu_faults
)
686 buf_handles
= kcalloc(params
->buffer_count
, sizeof(u32
), GFP_KERNEL
);
690 ret
= copy_from_user(buf_handles
,
691 (void __user
*)params
->buffers_ptr
,
692 params
->buffer_count
* sizeof(u32
));
695 goto err_free_handles
;
698 if (!drm_dev_enter(&vdev
->drm
, &idx
)) {
700 goto err_free_handles
;
703 ivpu_dbg(vdev
, JOB
, "Submit ioctl: ctx %u buf_count %u\n",
704 file_priv
->ctx
.id
, params
->buffer_count
);
706 job
= ivpu_job_create(file_priv
, params
->engine
, params
->buffer_count
);
708 ivpu_err(vdev
, "Failed to create job\n");
713 ret
= ivpu_job_prepare_bos_for_submit(file
, job
, buf_handles
, params
->buffer_count
,
714 params
->commands_offset
);
716 ivpu_err(vdev
, "Failed to prepare job: %d\n", ret
);
717 goto err_destroy_job
;
720 priority
= ivpu_job_to_hws_priority(file_priv
, params
->priority
);
722 down_read(&vdev
->pm
->reset_lock
);
723 ret
= ivpu_job_submit(job
, priority
);
724 up_read(&vdev
->pm
->reset_lock
);
726 goto err_signal_fence
;
733 dma_fence_signal(job
->done_fence
);
735 ivpu_job_destroy(job
);
744 ivpu_job_done_callback(struct ivpu_device
*vdev
, struct ivpu_ipc_hdr
*ipc_hdr
,
745 struct vpu_jsm_msg
*jsm_msg
)
747 struct vpu_ipc_msg_payload_job_done
*payload
;
751 ivpu_err(vdev
, "IPC message has no JSM payload\n");
755 if (jsm_msg
->result
!= VPU_JSM_STATUS_SUCCESS
) {
756 ivpu_err(vdev
, "Invalid JSM message result: %d\n", jsm_msg
->result
);
760 payload
= (struct vpu_ipc_msg_payload_job_done
*)&jsm_msg
->payload
;
761 ret
= ivpu_job_signal_and_destroy(vdev
, payload
->job_id
, payload
->job_status
);
762 if (!ret
&& !xa_empty(&vdev
->submitted_jobs_xa
))
763 ivpu_start_job_timeout_detection(vdev
);
766 void ivpu_job_done_consumer_init(struct ivpu_device
*vdev
)
768 ivpu_ipc_consumer_add(vdev
, &vdev
->job_done_consumer
,
769 VPU_IPC_CHAN_JOB_RET
, ivpu_job_done_callback
);
772 void ivpu_job_done_consumer_fini(struct ivpu_device
*vdev
)
774 ivpu_ipc_consumer_del(vdev
, &vdev
->job_done_consumer
);