11// SPDX-License-Identifier: GPL-2.0-only
22/*
3- * Copyright (C) 2020-2023 Intel Corporation
3+ * Copyright (C) 2020-2024 Intel Corporation
44 */
55
66#include <linux/firmware.h>
@@ -131,22 +131,6 @@ static int ivpu_get_capabilities(struct ivpu_device *vdev, struct drm_ivpu_param
131131 return 0 ;
132132}
133133
134- static int ivpu_get_core_clock_rate (struct ivpu_device * vdev , u64 * clk_rate )
135- {
136- int ret ;
137-
138- ret = ivpu_rpm_get_if_active (vdev );
139- if (ret < 0 )
140- return ret ;
141-
142- * clk_rate = ret ? ivpu_hw_reg_pll_freq_get (vdev ) : 0 ;
143-
144- if (ret )
145- ivpu_rpm_put (vdev );
146-
147- return 0 ;
148- }
149-
150134static int ivpu_get_param_ioctl (struct drm_device * dev , void * data , struct drm_file * file )
151135{
152136 struct ivpu_file_priv * file_priv = file -> driver_priv ;
@@ -170,7 +154,7 @@ static int ivpu_get_param_ioctl(struct drm_device *dev, void *data, struct drm_f
170154 args -> value = vdev -> platform ;
171155 break ;
172156 case DRM_IVPU_PARAM_CORE_CLOCK_RATE :
173- ret = ivpu_get_core_clock_rate (vdev , & args -> value );
157+ args -> value = ivpu_hw_ratio_to_freq (vdev , vdev -> hw -> pll . max_ratio );
174158 break ;
175159 case DRM_IVPU_PARAM_NUM_CONTEXTS :
176160 args -> value = ivpu_get_context_count (vdev );
@@ -387,12 +371,15 @@ int ivpu_shutdown(struct ivpu_device *vdev)
387371{
388372 int ret ;
389373
390- ivpu_prepare_for_reset (vdev );
374+ /* Save PCI state before powering down as it sometimes gets corrupted if NPU hangs */
375+ pci_save_state (to_pci_dev (vdev -> drm .dev ));
391376
392377 ret = ivpu_hw_power_down (vdev );
393378 if (ret )
394379 ivpu_warn (vdev , "Failed to power down HW: %d\n" , ret );
395380
381+ pci_set_power_state (to_pci_dev (vdev -> drm .dev ), PCI_D3hot );
382+
396383 return ret ;
397384}
398385
@@ -530,7 +517,7 @@ static int ivpu_dev_init(struct ivpu_device *vdev)
530517 vdev -> context_xa_limit .min = IVPU_USER_CONTEXT_MIN_SSID ;
531518 vdev -> context_xa_limit .max = IVPU_USER_CONTEXT_MAX_SSID ;
532519 atomic64_set (& vdev -> unique_id_counter , 0 );
533- xa_init_flags (& vdev -> context_xa , XA_FLAGS_ALLOC );
520+ xa_init_flags (& vdev -> context_xa , XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ );
534521 xa_init_flags (& vdev -> submitted_jobs_xa , XA_FLAGS_ALLOC1 );
535522 xa_init_flags (& vdev -> db_xa , XA_FLAGS_ALLOC1 );
536523 lockdep_set_class (& vdev -> submitted_jobs_xa .xa_lock , & submitted_jobs_xa_lock_class_key );
@@ -560,11 +547,11 @@ static int ivpu_dev_init(struct ivpu_device *vdev)
560547 /* Power up early so the rest of init code can access VPU registers */
561548 ret = ivpu_hw_power_up (vdev );
562549 if (ret )
563- goto err_power_down ;
550+ goto err_shutdown ;
564551
565552 ret = ivpu_mmu_global_context_init (vdev );
566553 if (ret )
567- goto err_power_down ;
554+ goto err_shutdown ;
568555
569556 ret = ivpu_mmu_init (vdev );
570557 if (ret )
@@ -601,10 +588,8 @@ static int ivpu_dev_init(struct ivpu_device *vdev)
601588 ivpu_mmu_reserved_context_fini (vdev );
602589err_mmu_gctx_fini :
603590 ivpu_mmu_global_context_fini (vdev );
604- err_power_down :
605- ivpu_hw_power_down (vdev );
606- if (IVPU_WA (d3hot_after_power_off ))
607- pci_set_power_state (to_pci_dev (vdev -> drm .dev ), PCI_D3hot );
591+ err_shutdown :
592+ ivpu_shutdown (vdev );
608593err_xa_destroy :
609594 xa_destroy (& vdev -> db_xa );
610595 xa_destroy (& vdev -> submitted_jobs_xa );
@@ -628,9 +613,8 @@ static void ivpu_bo_unbind_all_user_contexts(struct ivpu_device *vdev)
628613static void ivpu_dev_fini (struct ivpu_device * vdev )
629614{
630615 ivpu_pm_disable (vdev );
616+ ivpu_prepare_for_reset (vdev );
631617 ivpu_shutdown (vdev );
632- if (IVPU_WA (d3hot_after_power_off ))
633- pci_set_power_state (to_pci_dev (vdev -> drm .dev ), PCI_D3hot );
634618
635619 ivpu_jobs_abort_all (vdev );
636620 ivpu_job_done_consumer_fini (vdev );
0 commit comments