Lines Matching full:vdev
34 static void ivpu_pm_prepare_cold_boot(struct ivpu_device *vdev) in ivpu_pm_prepare_cold_boot() argument
36 struct ivpu_fw_info *fw = vdev->fw; in ivpu_pm_prepare_cold_boot()
38 ivpu_cmdq_reset_all_contexts(vdev); in ivpu_pm_prepare_cold_boot()
39 ivpu_ipc_reset(vdev); in ivpu_pm_prepare_cold_boot()
40 ivpu_fw_load(vdev); in ivpu_pm_prepare_cold_boot()
44 static void ivpu_pm_prepare_warm_boot(struct ivpu_device *vdev) in ivpu_pm_prepare_warm_boot() argument
46 struct ivpu_fw_info *fw = vdev->fw; in ivpu_pm_prepare_warm_boot()
50 ivpu_pm_prepare_cold_boot(vdev); in ivpu_pm_prepare_warm_boot()
54 ivpu_dbg(vdev, FW_BOOT, "Save/restore entry point %llx", bp->save_restore_ret_address); in ivpu_pm_prepare_warm_boot()
58 static int ivpu_suspend(struct ivpu_device *vdev) in ivpu_suspend() argument
62 ivpu_prepare_for_reset(vdev); in ivpu_suspend()
64 ret = ivpu_shutdown(vdev); in ivpu_suspend()
66 ivpu_err(vdev, "Failed to shutdown NPU: %d\n", ret); in ivpu_suspend()
71 static int ivpu_resume(struct ivpu_device *vdev) in ivpu_resume() argument
76 pci_restore_state(to_pci_dev(vdev->drm.dev)); in ivpu_resume()
77 pci_set_power_state(to_pci_dev(vdev->drm.dev), PCI_D0); in ivpu_resume()
79 ret = ivpu_hw_power_up(vdev); in ivpu_resume()
81 ivpu_err(vdev, "Failed to power up HW: %d\n", ret); in ivpu_resume()
85 ret = ivpu_mmu_enable(vdev); in ivpu_resume()
87 ivpu_err(vdev, "Failed to resume MMU: %d\n", ret); in ivpu_resume()
91 ret = ivpu_boot(vdev); in ivpu_resume()
98 ivpu_mmu_disable(vdev); in ivpu_resume()
100 ivpu_hw_power_down(vdev); in ivpu_resume()
101 pci_set_power_state(to_pci_dev(vdev->drm.dev), PCI_D3hot); in ivpu_resume()
103 if (!ivpu_fw_is_cold_boot(vdev)) { in ivpu_resume()
104 ivpu_pm_prepare_cold_boot(vdev); in ivpu_resume()
107 ivpu_err(vdev, "Failed to resume the FW: %d\n", ret); in ivpu_resume()
116 struct ivpu_device *vdev = pm->vdev; in ivpu_pm_recovery_work() local
120 ivpu_err(vdev, "Recovering the NPU (reset #%d)\n", atomic_read(&vdev->pm->reset_counter)); in ivpu_pm_recovery_work()
122 ret = pm_runtime_resume_and_get(vdev->drm.dev); in ivpu_pm_recovery_work()
124 ivpu_err(vdev, "Failed to resume NPU: %d\n", ret); in ivpu_pm_recovery_work()
126 ivpu_fw_log_dump(vdev); in ivpu_pm_recovery_work()
128 atomic_inc(&vdev->pm->reset_counter); in ivpu_pm_recovery_work()
129 atomic_set(&vdev->pm->reset_pending, 1); in ivpu_pm_recovery_work()
130 down_write(&vdev->pm->reset_lock); in ivpu_pm_recovery_work()
132 ivpu_suspend(vdev); in ivpu_pm_recovery_work()
133 ivpu_pm_prepare_cold_boot(vdev); in ivpu_pm_recovery_work()
134 ivpu_jobs_abort_all(vdev); in ivpu_pm_recovery_work()
135 ivpu_ms_cleanup_all(vdev); in ivpu_pm_recovery_work()
137 ret = ivpu_resume(vdev); in ivpu_pm_recovery_work()
139 ivpu_err(vdev, "Failed to resume NPU: %d\n", ret); in ivpu_pm_recovery_work()
141 up_write(&vdev->pm->reset_lock); in ivpu_pm_recovery_work()
142 atomic_set(&vdev->pm->reset_pending, 0); in ivpu_pm_recovery_work()
144 kobject_uevent_env(&vdev->drm.dev->kobj, KOBJ_CHANGE, evt); in ivpu_pm_recovery_work()
145 pm_runtime_mark_last_busy(vdev->drm.dev); in ivpu_pm_recovery_work()
146 pm_runtime_put_autosuspend(vdev->drm.dev); in ivpu_pm_recovery_work()
149 void ivpu_pm_trigger_recovery(struct ivpu_device *vdev, const char *reason) in ivpu_pm_trigger_recovery() argument
151 ivpu_err(vdev, "Recovery triggered by %s\n", reason); in ivpu_pm_trigger_recovery()
154 ivpu_err(vdev, "Recovery not available when disable_recovery param is set\n"); in ivpu_pm_trigger_recovery()
158 if (ivpu_is_fpga(vdev)) { in ivpu_pm_trigger_recovery()
159 ivpu_err(vdev, "Recovery not available on FPGA\n"); in ivpu_pm_trigger_recovery()
164 if (atomic_cmpxchg(&vdev->pm->reset_pending, 0, 1) == 0) { in ivpu_pm_trigger_recovery()
165 ivpu_hw_diagnose_failure(vdev); in ivpu_pm_trigger_recovery()
166 ivpu_hw_irq_disable(vdev); /* Disable IRQ early to protect from IRQ storm */ in ivpu_pm_trigger_recovery()
167 queue_work(system_long_wq, &vdev->pm->recovery_work); in ivpu_pm_trigger_recovery()
174 struct ivpu_device *vdev = pm->vdev; in ivpu_job_timeout_work() local
176 ivpu_pm_trigger_recovery(vdev, "TDR"); in ivpu_job_timeout_work()
179 void ivpu_start_job_timeout_detection(struct ivpu_device *vdev) in ivpu_start_job_timeout_detection() argument
181 unsigned long timeout_ms = ivpu_tdr_timeout_ms ? ivpu_tdr_timeout_ms : vdev->timeout.tdr; in ivpu_start_job_timeout_detection()
184 queue_delayed_work(system_wq, &vdev->pm->job_timeout_work, msecs_to_jiffies(timeout_ms)); in ivpu_start_job_timeout_detection()
187 void ivpu_stop_job_timeout_detection(struct ivpu_device *vdev) in ivpu_stop_job_timeout_detection() argument
189 cancel_delayed_work_sync(&vdev->pm->job_timeout_work); in ivpu_stop_job_timeout_detection()
195 struct ivpu_device *vdev = to_ivpu_device(drm); in ivpu_pm_suspend_cb() local
198 ivpu_dbg(vdev, PM, "Suspend..\n"); in ivpu_pm_suspend_cb()
200 timeout = jiffies + msecs_to_jiffies(vdev->timeout.tdr); in ivpu_pm_suspend_cb()
201 while (!ivpu_hw_is_idle(vdev)) { in ivpu_pm_suspend_cb()
204 ivpu_err(vdev, "Failed to enter idle on system suspend\n"); in ivpu_pm_suspend_cb()
209 ivpu_jsm_pwr_d0i3_enter(vdev); in ivpu_pm_suspend_cb()
211 ivpu_suspend(vdev); in ivpu_pm_suspend_cb()
212 ivpu_pm_prepare_warm_boot(vdev); in ivpu_pm_suspend_cb()
214 ivpu_dbg(vdev, PM, "Suspend done.\n"); in ivpu_pm_suspend_cb()
222 struct ivpu_device *vdev = to_ivpu_device(drm); in ivpu_pm_resume_cb() local
225 ivpu_dbg(vdev, PM, "Resume..\n"); in ivpu_pm_resume_cb()
227 ret = ivpu_resume(vdev); in ivpu_pm_resume_cb()
229 ivpu_err(vdev, "Failed to resume: %d\n", ret); in ivpu_pm_resume_cb()
231 ivpu_dbg(vdev, PM, "Resume done.\n"); in ivpu_pm_resume_cb()
239 struct ivpu_device *vdev = to_ivpu_device(drm); in ivpu_pm_runtime_suspend_cb() local
243 drm_WARN_ON(&vdev->drm, !xa_empty(&vdev->submitted_jobs_xa)); in ivpu_pm_runtime_suspend_cb()
244 drm_WARN_ON(&vdev->drm, work_pending(&vdev->pm->recovery_work)); in ivpu_pm_runtime_suspend_cb()
246 ivpu_dbg(vdev, PM, "Runtime suspend..\n"); in ivpu_pm_runtime_suspend_cb()
248 ivpu_mmu_disable(vdev); in ivpu_pm_runtime_suspend_cb()
250 is_idle = ivpu_hw_is_idle(vdev) || vdev->pm->dct_active_percent; in ivpu_pm_runtime_suspend_cb()
252 ivpu_err(vdev, "NPU is not idle before autosuspend\n"); in ivpu_pm_runtime_suspend_cb()
254 ret_d0i3 = ivpu_jsm_pwr_d0i3_enter(vdev); in ivpu_pm_runtime_suspend_cb()
256 ivpu_err(vdev, "Failed to prepare for d0i3: %d\n", ret_d0i3); in ivpu_pm_runtime_suspend_cb()
258 ret = ivpu_suspend(vdev); in ivpu_pm_runtime_suspend_cb()
260 ivpu_err(vdev, "Failed to suspend NPU: %d\n", ret); in ivpu_pm_runtime_suspend_cb()
263 ivpu_err(vdev, "Forcing cold boot due to previous errors\n"); in ivpu_pm_runtime_suspend_cb()
264 atomic_inc(&vdev->pm->reset_counter); in ivpu_pm_runtime_suspend_cb()
265 ivpu_fw_log_dump(vdev); in ivpu_pm_runtime_suspend_cb()
266 ivpu_pm_prepare_cold_boot(vdev); in ivpu_pm_runtime_suspend_cb()
268 ivpu_pm_prepare_warm_boot(vdev); in ivpu_pm_runtime_suspend_cb()
271 ivpu_dbg(vdev, PM, "Runtime suspend done.\n"); in ivpu_pm_runtime_suspend_cb()
279 struct ivpu_device *vdev = to_ivpu_device(drm); in ivpu_pm_runtime_resume_cb() local
282 ivpu_dbg(vdev, PM, "Runtime resume..\n"); in ivpu_pm_runtime_resume_cb()
284 ret = ivpu_resume(vdev); in ivpu_pm_runtime_resume_cb()
286 ivpu_err(vdev, "Failed to set RESUME state: %d\n", ret); in ivpu_pm_runtime_resume_cb()
288 ivpu_dbg(vdev, PM, "Runtime resume done.\n"); in ivpu_pm_runtime_resume_cb()
293 int ivpu_rpm_get(struct ivpu_device *vdev) in ivpu_rpm_get() argument
297 ret = pm_runtime_resume_and_get(vdev->drm.dev); in ivpu_rpm_get()
298 drm_WARN_ON(&vdev->drm, ret < 0); in ivpu_rpm_get()
303 void ivpu_rpm_put(struct ivpu_device *vdev) in ivpu_rpm_put() argument
305 pm_runtime_mark_last_busy(vdev->drm.dev); in ivpu_rpm_put()
306 pm_runtime_put_autosuspend(vdev->drm.dev); in ivpu_rpm_put()
311 struct ivpu_device *vdev = pci_get_drvdata(pdev); in ivpu_pm_reset_prepare_cb() local
313 ivpu_dbg(vdev, PM, "Pre-reset..\n"); in ivpu_pm_reset_prepare_cb()
314 atomic_inc(&vdev->pm->reset_counter); in ivpu_pm_reset_prepare_cb()
315 atomic_set(&vdev->pm->reset_pending, 1); in ivpu_pm_reset_prepare_cb()
317 pm_runtime_get_sync(vdev->drm.dev); in ivpu_pm_reset_prepare_cb()
318 down_write(&vdev->pm->reset_lock); in ivpu_pm_reset_prepare_cb()
319 ivpu_prepare_for_reset(vdev); in ivpu_pm_reset_prepare_cb()
320 ivpu_hw_reset(vdev); in ivpu_pm_reset_prepare_cb()
321 ivpu_pm_prepare_cold_boot(vdev); in ivpu_pm_reset_prepare_cb()
322 ivpu_jobs_abort_all(vdev); in ivpu_pm_reset_prepare_cb()
323 ivpu_ms_cleanup_all(vdev); in ivpu_pm_reset_prepare_cb()
325 ivpu_dbg(vdev, PM, "Pre-reset done.\n"); in ivpu_pm_reset_prepare_cb()
330 struct ivpu_device *vdev = pci_get_drvdata(pdev); in ivpu_pm_reset_done_cb() local
333 ivpu_dbg(vdev, PM, "Post-reset..\n"); in ivpu_pm_reset_done_cb()
334 ret = ivpu_resume(vdev); in ivpu_pm_reset_done_cb()
336 ivpu_err(vdev, "Failed to set RESUME state: %d\n", ret); in ivpu_pm_reset_done_cb()
337 up_write(&vdev->pm->reset_lock); in ivpu_pm_reset_done_cb()
338 atomic_set(&vdev->pm->reset_pending, 0); in ivpu_pm_reset_done_cb()
339 ivpu_dbg(vdev, PM, "Post-reset done.\n"); in ivpu_pm_reset_done_cb()
341 pm_runtime_mark_last_busy(vdev->drm.dev); in ivpu_pm_reset_done_cb()
342 pm_runtime_put_autosuspend(vdev->drm.dev); in ivpu_pm_reset_done_cb()
345 void ivpu_pm_init(struct ivpu_device *vdev) in ivpu_pm_init() argument
347 struct device *dev = vdev->drm.dev; in ivpu_pm_init()
348 struct ivpu_pm_info *pm = vdev->pm; in ivpu_pm_init()
351 pm->vdev = vdev; in ivpu_pm_init()
363 delay = vdev->timeout.autosuspend; in ivpu_pm_init()
368 ivpu_dbg(vdev, PM, "Autosuspend delay = %d\n", delay); in ivpu_pm_init()
371 void ivpu_pm_cancel_recovery(struct ivpu_device *vdev) in ivpu_pm_cancel_recovery() argument
373 drm_WARN_ON(&vdev->drm, delayed_work_pending(&vdev->pm->job_timeout_work)); in ivpu_pm_cancel_recovery()
374 cancel_work_sync(&vdev->pm->recovery_work); in ivpu_pm_cancel_recovery()
377 void ivpu_pm_enable(struct ivpu_device *vdev) in ivpu_pm_enable() argument
379 struct device *dev = vdev->drm.dev; in ivpu_pm_enable()
387 void ivpu_pm_disable(struct ivpu_device *vdev) in ivpu_pm_disable() argument
389 pm_runtime_get_noresume(vdev->drm.dev); in ivpu_pm_disable()
390 pm_runtime_forbid(vdev->drm.dev); in ivpu_pm_disable()
393 int ivpu_pm_dct_init(struct ivpu_device *vdev) in ivpu_pm_dct_init() argument
395 if (vdev->pm->dct_active_percent) in ivpu_pm_dct_init()
396 return ivpu_pm_dct_enable(vdev, vdev->pm->dct_active_percent); in ivpu_pm_dct_init()
401 int ivpu_pm_dct_enable(struct ivpu_device *vdev, u8 active_percent) in ivpu_pm_dct_enable() argument
412 ret = ivpu_jsm_dct_enable(vdev, active_us, inactive_us); in ivpu_pm_dct_enable()
414 ivpu_err_ratelimited(vdev, "Filed to enable DCT: %d\n", ret); in ivpu_pm_dct_enable()
418 vdev->pm->dct_active_percent = active_percent; in ivpu_pm_dct_enable()
420 ivpu_dbg(vdev, PM, "DCT set to %u%% (D0: %uus, D0i2: %uus)\n", in ivpu_pm_dct_enable()
425 int ivpu_pm_dct_disable(struct ivpu_device *vdev) in ivpu_pm_dct_disable() argument
429 ret = ivpu_jsm_dct_disable(vdev); in ivpu_pm_dct_disable()
431 ivpu_err_ratelimited(vdev, "Filed to disable DCT: %d\n", ret); in ivpu_pm_dct_disable()
435 vdev->pm->dct_active_percent = 0; in ivpu_pm_dct_disable()
437 ivpu_dbg(vdev, PM, "DCT disabled\n"); in ivpu_pm_dct_disable()
441 void ivpu_pm_dct_irq_thread_handler(struct ivpu_device *vdev) in ivpu_pm_dct_irq_thread_handler() argument
446 if (ivpu_hw_btrs_dct_get_request(vdev, &enable)) in ivpu_pm_dct_irq_thread_handler()
449 if (vdev->pm->dct_active_percent) in ivpu_pm_dct_irq_thread_handler()
450 ret = ivpu_pm_dct_enable(vdev, DCT_DEFAULT_ACTIVE_PERCENT); in ivpu_pm_dct_irq_thread_handler()
452 ret = ivpu_pm_dct_disable(vdev); in ivpu_pm_dct_irq_thread_handler()
455 ivpu_hw_btrs_dct_set_status(vdev, enable, vdev->pm->dct_active_percent); in ivpu_pm_dct_irq_thread_handler()