Lines Matching full:vdev

70 	struct ivpu_device *vdev = file_priv->vdev;  in ivpu_file_priv_get()  local
74 ivpu_dbg(vdev, KREF, "file_priv get: ctx %u refcount %u\n", in ivpu_file_priv_get()
80 static void file_priv_unbind(struct ivpu_device *vdev, struct ivpu_file_priv *file_priv) in file_priv_unbind() argument
84 ivpu_dbg(vdev, FILE, "file_priv unbind: ctx %u\n", file_priv->ctx.id); in file_priv_unbind()
87 ivpu_bo_unbind_all_bos_from_context(vdev, &file_priv->ctx); in file_priv_unbind()
88 ivpu_mmu_user_context_fini(vdev, &file_priv->ctx); in file_priv_unbind()
90 drm_WARN_ON(&vdev->drm, !xa_erase_irq(&vdev->context_xa, file_priv->ctx.id)); in file_priv_unbind()
98 struct ivpu_device *vdev = file_priv->vdev; in file_priv_release() local
100 ivpu_dbg(vdev, FILE, "file_priv release: ctx %u bound %d\n", in file_priv_release()
103 pm_runtime_get_sync(vdev->drm.dev); in file_priv_release()
104 mutex_lock(&vdev->context_list_lock); in file_priv_release()
105 file_priv_unbind(vdev, file_priv); in file_priv_release()
106 mutex_unlock(&vdev->context_list_lock); in file_priv_release()
107 pm_runtime_put_autosuspend(vdev->drm.dev); in file_priv_release()
117 struct ivpu_device *vdev = file_priv->vdev; in ivpu_file_priv_put() local
119 drm_WARN_ON(&vdev->drm, !file_priv); in ivpu_file_priv_put()
121 ivpu_dbg(vdev, KREF, "file_priv put: ctx %u refcount %u\n", in ivpu_file_priv_put()
128 static int ivpu_get_capabilities(struct ivpu_device *vdev, struct drm_ivpu_param *args) in ivpu_get_capabilities() argument
147 struct ivpu_device *vdev = file_priv->vdev; in ivpu_get_param_ioctl() local
148 struct pci_dev *pdev = to_pci_dev(vdev->drm.dev); in ivpu_get_param_ioctl()
164 args->value = vdev->platform; in ivpu_get_param_ioctl()
167 args->value = ivpu_hw_ratio_to_freq(vdev, vdev->hw->pll.max_ratio); in ivpu_get_param_ioctl()
170 args->value = ivpu_get_context_count(vdev); in ivpu_get_param_ioctl()
173 args->value = vdev->hw->ranges.user.start; in ivpu_get_param_ioctl()
182 fw_hdr = (struct vpu_firmware_header *)vdev->fw->file->data; in ivpu_get_param_ioctl()
189 ret = ivpu_jsm_get_heartbeat(vdev, args->index, &args->value); in ivpu_get_param_ioctl()
192 args->value = (u64)atomic64_inc_return(&vdev->unique_id_counter); in ivpu_get_param_ioctl()
195 args->value = vdev->hw->tile_fuse; in ivpu_get_param_ioctl()
198 args->value = vdev->hw->sku; in ivpu_get_param_ioctl()
201 ret = ivpu_get_capabilities(vdev, args); in ivpu_get_param_ioctl()
227 struct ivpu_device *vdev = to_ivpu_device(dev); in ivpu_open() local
243 file_priv->vdev = vdev; in ivpu_open()
249 mutex_lock(&vdev->context_list_lock); in ivpu_open()
251 ret = xa_alloc_irq(&vdev->context_xa, &ctx_id, file_priv, in ivpu_open()
252 vdev->context_xa_limit, GFP_KERNEL); in ivpu_open()
254 ivpu_err(vdev, "Failed to allocate context id: %d\n", ret); in ivpu_open()
258 ret = ivpu_mmu_user_context_init(vdev, &file_priv->ctx, ctx_id); in ivpu_open()
262 mutex_unlock(&vdev->context_list_lock); in ivpu_open()
267 ivpu_dbg(vdev, FILE, "file_priv create: ctx %u process %s pid %d\n", in ivpu_open()
273 xa_erase_irq(&vdev->context_xa, ctx_id); in ivpu_open()
275 mutex_unlock(&vdev->context_list_lock); in ivpu_open()
287 struct ivpu_device *vdev = to_ivpu_device(dev); in ivpu_postclose() local
289 ivpu_dbg(vdev, FILE, "file_priv close: ctx %u process %s pid %d\n", in ivpu_postclose()
309 static int ivpu_wait_for_ready(struct ivpu_device *vdev) in ivpu_wait_for_ready() argument
319 ivpu_ipc_consumer_add(vdev, &cons, IVPU_IPC_CHAN_BOOT_MSG, NULL); in ivpu_wait_for_ready()
321 timeout = jiffies + msecs_to_jiffies(vdev->timeout.boot); in ivpu_wait_for_ready()
323 ivpu_ipc_irq_handler(vdev); in ivpu_wait_for_ready()
324 ret = ivpu_ipc_receive(vdev, &cons, &ipc_hdr, NULL, 0); in ivpu_wait_for_ready()
331 ivpu_ipc_consumer_del(vdev, &cons); in ivpu_wait_for_ready()
334 ivpu_err(vdev, "Invalid NPU ready message: 0x%x\n", in ivpu_wait_for_ready()
340 ivpu_dbg(vdev, PM, "NPU ready message received successfully\n"); in ivpu_wait_for_ready()
345 static int ivpu_hw_sched_init(struct ivpu_device *vdev) in ivpu_hw_sched_init() argument
349 if (vdev->hw->sched_mode == VPU_SCHEDULING_MODE_HW) { in ivpu_hw_sched_init()
350 ret = ivpu_jsm_hws_setup_priority_bands(vdev); in ivpu_hw_sched_init()
352 ivpu_err(vdev, "Failed to enable hw scheduler: %d", ret); in ivpu_hw_sched_init()
362 * @vdev: VPU device
367 int ivpu_boot(struct ivpu_device *vdev) in ivpu_boot() argument
372 ivpu_fw_boot_params_setup(vdev, ivpu_bo_vaddr(vdev->fw->mem)); in ivpu_boot()
374 ret = ivpu_hw_boot_fw(vdev); in ivpu_boot()
376 ivpu_err(vdev, "Failed to start the firmware: %d\n", ret); in ivpu_boot()
380 ret = ivpu_wait_for_ready(vdev); in ivpu_boot()
382 ivpu_err(vdev, "Failed to boot the firmware: %d\n", ret); in ivpu_boot()
383 ivpu_hw_diagnose_failure(vdev); in ivpu_boot()
384 ivpu_mmu_evtq_dump(vdev); in ivpu_boot()
385 ivpu_fw_log_dump(vdev); in ivpu_boot()
389 ivpu_hw_irq_clear(vdev); in ivpu_boot()
390 enable_irq(vdev->irq); in ivpu_boot()
391 ivpu_hw_irq_enable(vdev); in ivpu_boot()
392 ivpu_ipc_enable(vdev); in ivpu_boot()
394 if (ivpu_fw_is_cold_boot(vdev)) { in ivpu_boot()
395 ret = ivpu_pm_dct_init(vdev); in ivpu_boot()
399 return ivpu_hw_sched_init(vdev); in ivpu_boot()
405 void ivpu_prepare_for_reset(struct ivpu_device *vdev) in ivpu_prepare_for_reset() argument
407 ivpu_hw_irq_disable(vdev); in ivpu_prepare_for_reset()
408 disable_irq(vdev->irq); in ivpu_prepare_for_reset()
409 ivpu_ipc_disable(vdev); in ivpu_prepare_for_reset()
410 ivpu_mmu_disable(vdev); in ivpu_prepare_for_reset()
413 int ivpu_shutdown(struct ivpu_device *vdev) in ivpu_shutdown() argument
418 pci_save_state(to_pci_dev(vdev->drm.dev)); in ivpu_shutdown()
420 ret = ivpu_hw_power_down(vdev); in ivpu_shutdown()
422 ivpu_warn(vdev, "Failed to power down HW: %d\n", ret); in ivpu_shutdown()
424 pci_set_power_state(to_pci_dev(vdev->drm.dev), PCI_D3hot); in ivpu_shutdown()
454 static void ivpu_context_abort_invalid(struct ivpu_device *vdev) in ivpu_context_abort_invalid() argument
459 mutex_lock(&vdev->context_list_lock); in ivpu_context_abort_invalid()
461 xa_for_each(&vdev->context_xa, ctx_id, file_priv) { in ivpu_context_abort_invalid()
471 mutex_unlock(&vdev->context_list_lock); in ivpu_context_abort_invalid()
476 struct ivpu_device *vdev = arg; in ivpu_irq_thread_handler() local
479 if (kfifo_is_empty(&vdev->hw->irq.fifo)) in ivpu_irq_thread_handler()
482 while (kfifo_get(&vdev->hw->irq.fifo, &irq_src)) { in ivpu_irq_thread_handler()
485 ivpu_ipc_irq_thread_handler(vdev); in ivpu_irq_thread_handler()
488 ivpu_context_abort_invalid(vdev); in ivpu_irq_thread_handler()
491 ivpu_pm_dct_irq_thread_handler(vdev); in ivpu_irq_thread_handler()
494 ivpu_err_ratelimited(vdev, "Unknown IRQ source: %u\n", irq_src); in ivpu_irq_thread_handler()
502 static int ivpu_irq_init(struct ivpu_device *vdev) in ivpu_irq_init() argument
504 struct pci_dev *pdev = to_pci_dev(vdev->drm.dev); in ivpu_irq_init()
509 ivpu_err(vdev, "Failed to allocate a MSI IRQ: %d\n", ret); in ivpu_irq_init()
513 ivpu_irq_handlers_init(vdev); in ivpu_irq_init()
515 vdev->irq = pci_irq_vector(pdev, 0); in ivpu_irq_init()
517 ret = devm_request_threaded_irq(vdev->drm.dev, vdev->irq, ivpu_hw_irq_handler, in ivpu_irq_init()
518 ivpu_irq_thread_handler, IRQF_NO_AUTOEN, DRIVER_NAME, vdev); in ivpu_irq_init()
520 ivpu_err(vdev, "Failed to request an IRQ %d\n", ret); in ivpu_irq_init()
525 static int ivpu_pci_init(struct ivpu_device *vdev) in ivpu_pci_init() argument
527 struct pci_dev *pdev = to_pci_dev(vdev->drm.dev); in ivpu_pci_init()
532 ivpu_dbg(vdev, MISC, "Mapping BAR0 (RegV) %pR\n", bar0); in ivpu_pci_init()
533 vdev->regv = devm_ioremap_resource(vdev->drm.dev, bar0); in ivpu_pci_init()
534 if (IS_ERR(vdev->regv)) { in ivpu_pci_init()
535 ivpu_err(vdev, "Failed to map bar 0: %pe\n", vdev->regv); in ivpu_pci_init()
536 return PTR_ERR(vdev->regv); in ivpu_pci_init()
539 ivpu_dbg(vdev, MISC, "Mapping BAR4 (RegB) %pR\n", bar4); in ivpu_pci_init()
540 vdev->regb = devm_ioremap_resource(vdev->drm.dev, bar4); in ivpu_pci_init()
541 if (IS_ERR(vdev->regb)) { in ivpu_pci_init()
542 ivpu_err(vdev, "Failed to map bar 4: %pe\n", vdev->regb); in ivpu_pci_init()
543 return PTR_ERR(vdev->regb); in ivpu_pci_init()
546 ret = dma_set_mask_and_coherent(vdev->drm.dev, DMA_BIT_MASK(vdev->hw->dma_bits)); in ivpu_pci_init()
548 ivpu_err(vdev, "Failed to set DMA mask: %d\n", ret); in ivpu_pci_init()
551 dma_set_max_seg_size(vdev->drm.dev, UINT_MAX); in ivpu_pci_init()
561 ivpu_err(vdev, "Failed to enable PCI device: %d\n", ret); in ivpu_pci_init()
570 static int ivpu_dev_init(struct ivpu_device *vdev) in ivpu_dev_init() argument
574 vdev->hw = drmm_kzalloc(&vdev->drm, sizeof(*vdev->hw), GFP_KERNEL); in ivpu_dev_init()
575 if (!vdev->hw) in ivpu_dev_init()
578 vdev->mmu = drmm_kzalloc(&vdev->drm, sizeof(*vdev->mmu), GFP_KERNEL); in ivpu_dev_init()
579 if (!vdev->mmu) in ivpu_dev_init()
582 vdev->fw = drmm_kzalloc(&vdev->drm, sizeof(*vdev->fw), GFP_KERNEL); in ivpu_dev_init()
583 if (!vdev->fw) in ivpu_dev_init()
586 vdev->ipc = drmm_kzalloc(&vdev->drm, sizeof(*vdev->ipc), GFP_KERNEL); in ivpu_dev_init()
587 if (!vdev->ipc) in ivpu_dev_init()
590 vdev->pm = drmm_kzalloc(&vdev->drm, sizeof(*vdev->pm), GFP_KERNEL); in ivpu_dev_init()
591 if (!vdev->pm) in ivpu_dev_init()
594 if (ivpu_hw_ip_gen(vdev) >= IVPU_HW_IP_40XX) in ivpu_dev_init()
595 vdev->hw->dma_bits = 48; in ivpu_dev_init()
597 vdev->hw->dma_bits = 38; in ivpu_dev_init()
599 vdev->platform = IVPU_PLATFORM_INVALID; in ivpu_dev_init()
600 vdev->context_xa_limit.min = IVPU_USER_CONTEXT_MIN_SSID; in ivpu_dev_init()
601 vdev->context_xa_limit.max = IVPU_USER_CONTEXT_MAX_SSID; in ivpu_dev_init()
602 atomic64_set(&vdev->unique_id_counter, 0); in ivpu_dev_init()
603 xa_init_flags(&vdev->context_xa, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ); in ivpu_dev_init()
604 xa_init_flags(&vdev->submitted_jobs_xa, XA_FLAGS_ALLOC1); in ivpu_dev_init()
605 xa_init_flags(&vdev->db_xa, XA_FLAGS_ALLOC1); in ivpu_dev_init()
606 lockdep_set_class(&vdev->submitted_jobs_xa.xa_lock, &submitted_jobs_xa_lock_class_key); in ivpu_dev_init()
607 INIT_LIST_HEAD(&vdev->bo_list); in ivpu_dev_init()
609 ret = drmm_mutex_init(&vdev->drm, &vdev->context_list_lock); in ivpu_dev_init()
613 ret = drmm_mutex_init(&vdev->drm, &vdev->bo_list_lock); in ivpu_dev_init()
617 ret = ivpu_pci_init(vdev); in ivpu_dev_init()
621 ret = ivpu_irq_init(vdev); in ivpu_dev_init()
626 ret = ivpu_hw_init(vdev); in ivpu_dev_init()
631 ret = ivpu_hw_power_up(vdev); in ivpu_dev_init()
635 ret = ivpu_mmu_global_context_init(vdev); in ivpu_dev_init()
639 ret = ivpu_mmu_init(vdev); in ivpu_dev_init()
643 ret = ivpu_mmu_reserved_context_init(vdev); in ivpu_dev_init()
647 ret = ivpu_fw_init(vdev); in ivpu_dev_init()
651 ret = ivpu_ipc_init(vdev); in ivpu_dev_init()
655 ivpu_pm_init(vdev); in ivpu_dev_init()
657 ret = ivpu_boot(vdev); in ivpu_dev_init()
661 ivpu_job_done_consumer_init(vdev); in ivpu_dev_init()
662 ivpu_pm_enable(vdev); in ivpu_dev_init()
667 ivpu_ipc_fini(vdev); in ivpu_dev_init()
669 ivpu_fw_fini(vdev); in ivpu_dev_init()
671 ivpu_mmu_reserved_context_fini(vdev); in ivpu_dev_init()
673 ivpu_mmu_global_context_fini(vdev); in ivpu_dev_init()
675 ivpu_shutdown(vdev); in ivpu_dev_init()
677 xa_destroy(&vdev->db_xa); in ivpu_dev_init()
678 xa_destroy(&vdev->submitted_jobs_xa); in ivpu_dev_init()
679 xa_destroy(&vdev->context_xa); in ivpu_dev_init()
683 static void ivpu_bo_unbind_all_user_contexts(struct ivpu_device *vdev) in ivpu_bo_unbind_all_user_contexts() argument
688 mutex_lock(&vdev->context_list_lock); in ivpu_bo_unbind_all_user_contexts()
690 xa_for_each(&vdev->context_xa, ctx_id, file_priv) in ivpu_bo_unbind_all_user_contexts()
691 file_priv_unbind(vdev, file_priv); in ivpu_bo_unbind_all_user_contexts()
693 mutex_unlock(&vdev->context_list_lock); in ivpu_bo_unbind_all_user_contexts()
696 static void ivpu_dev_fini(struct ivpu_device *vdev) in ivpu_dev_fini() argument
698 ivpu_jobs_abort_all(vdev); in ivpu_dev_fini()
699 ivpu_pm_cancel_recovery(vdev); in ivpu_dev_fini()
700 ivpu_pm_disable(vdev); in ivpu_dev_fini()
701 ivpu_prepare_for_reset(vdev); in ivpu_dev_fini()
702 ivpu_shutdown(vdev); in ivpu_dev_fini()
704 ivpu_ms_cleanup_all(vdev); in ivpu_dev_fini()
705 ivpu_job_done_consumer_fini(vdev); in ivpu_dev_fini()
706 ivpu_bo_unbind_all_user_contexts(vdev); in ivpu_dev_fini()
708 ivpu_ipc_fini(vdev); in ivpu_dev_fini()
709 ivpu_fw_fini(vdev); in ivpu_dev_fini()
710 ivpu_mmu_reserved_context_fini(vdev); in ivpu_dev_fini()
711 ivpu_mmu_global_context_fini(vdev); in ivpu_dev_fini()
713 drm_WARN_ON(&vdev->drm, !xa_empty(&vdev->db_xa)); in ivpu_dev_fini()
714 xa_destroy(&vdev->db_xa); in ivpu_dev_fini()
715 drm_WARN_ON(&vdev->drm, !xa_empty(&vdev->submitted_jobs_xa)); in ivpu_dev_fini()
716 xa_destroy(&vdev->submitted_jobs_xa); in ivpu_dev_fini()
717 drm_WARN_ON(&vdev->drm, !xa_empty(&vdev->context_xa)); in ivpu_dev_fini()
718 xa_destroy(&vdev->context_xa); in ivpu_dev_fini()
731 struct ivpu_device *vdev; in ivpu_probe() local
734 vdev = devm_drm_dev_alloc(&pdev->dev, &driver, struct ivpu_device, drm); in ivpu_probe()
735 if (IS_ERR(vdev)) in ivpu_probe()
736 return PTR_ERR(vdev); in ivpu_probe()
738 pci_set_drvdata(pdev, vdev); in ivpu_probe()
740 ret = ivpu_dev_init(vdev); in ivpu_probe()
744 ivpu_debugfs_init(vdev); in ivpu_probe()
745 ivpu_sysfs_init(vdev); in ivpu_probe()
747 ret = drm_dev_register(&vdev->drm, 0); in ivpu_probe()
750 ivpu_dev_fini(vdev); in ivpu_probe()
758 struct ivpu_device *vdev = pci_get_drvdata(pdev); in ivpu_remove() local
760 drm_dev_unplug(&vdev->drm); in ivpu_remove()
761 ivpu_dev_fini(vdev); in ivpu_remove()