5
5
6
6
#include "xe_guc_pc.h"
7
7
8
+ #include <linux/cleanup.h>
8
9
#include <linux/delay.h>
9
10
#include <linux/ktime.h>
10
11
@@ -553,6 +554,25 @@ u32 xe_guc_pc_get_rpn_freq(struct xe_guc_pc *pc)
553
554
return pc -> rpn_freq ;
554
555
}
555
556
557
+ static int xe_guc_pc_get_min_freq_locked (struct xe_guc_pc * pc , u32 * freq )
558
+ {
559
+ int ret ;
560
+
561
+ lockdep_assert_held (& pc -> freq_lock );
562
+
563
+ /* Might be in the middle of a gt reset */
564
+ if (!pc -> freq_ready )
565
+ return - EAGAIN ;
566
+
567
+ ret = pc_action_query_task_state (pc );
568
+ if (ret )
569
+ return ret ;
570
+
571
+ * freq = pc_get_min_freq (pc );
572
+
573
+ return 0 ;
574
+ }
575
+
556
576
/**
557
577
* xe_guc_pc_get_min_freq - Get the min operational frequency
558
578
* @pc: The GuC PC
@@ -562,27 +582,29 @@ u32 xe_guc_pc_get_rpn_freq(struct xe_guc_pc *pc)
562
582
* -EAGAIN if GuC PC not ready (likely in middle of a reset).
563
583
*/
564
584
int xe_guc_pc_get_min_freq (struct xe_guc_pc * pc , u32 * freq )
585
+ {
586
+ guard (mutex )(& pc -> freq_lock );
587
+
588
+ return xe_guc_pc_get_min_freq_locked (pc , freq );
589
+ }
590
+
591
+ static int xe_guc_pc_set_min_freq_locked (struct xe_guc_pc * pc , u32 freq )
565
592
{
566
593
int ret ;
567
594
568
- xe_device_assert_mem_access ( pc_to_xe ( pc ) );
595
+ lockdep_assert_held ( & pc -> freq_lock );
569
596
570
- mutex_lock (& pc -> freq_lock );
571
- if (!pc -> freq_ready ) {
572
- /* Might be in the middle of a gt reset */
573
- ret = - EAGAIN ;
574
- goto out ;
575
- }
597
+ /* Might be in the middle of a gt reset */
598
+ if (!pc -> freq_ready )
599
+ return - EAGAIN ;
576
600
577
- ret = pc_action_query_task_state (pc );
601
+ ret = pc_set_min_freq (pc , freq );
578
602
if (ret )
579
- goto out ;
603
+ return ret ;
580
604
581
- * freq = pc_get_min_freq ( pc ) ;
605
+ pc -> user_requested_min = freq ;
582
606
583
- out :
584
- mutex_unlock (& pc -> freq_lock );
585
- return ret ;
607
+ return 0 ;
586
608
}
587
609
588
610
/**
@@ -595,25 +617,29 @@ int xe_guc_pc_get_min_freq(struct xe_guc_pc *pc, u32 *freq)
595
617
* -EINVAL if value out of bounds.
596
618
*/
597
619
int xe_guc_pc_set_min_freq (struct xe_guc_pc * pc , u32 freq )
620
+ {
621
+ guard (mutex )(& pc -> freq_lock );
622
+
623
+ return xe_guc_pc_set_min_freq_locked (pc , freq );
624
+ }
625
+
626
+ static int xe_guc_pc_get_max_freq_locked (struct xe_guc_pc * pc , u32 * freq )
598
627
{
599
628
int ret ;
600
629
601
- mutex_lock (& pc -> freq_lock );
602
- if (!pc -> freq_ready ) {
603
- /* Might be in the middle of a gt reset */
604
- ret = - EAGAIN ;
605
- goto out ;
606
- }
630
+ lockdep_assert_held (& pc -> freq_lock );
607
631
608
- ret = pc_set_min_freq (pc , freq );
632
+ /* Might be in the middle of a gt reset */
633
+ if (!pc -> freq_ready )
634
+ return - EAGAIN ;
635
+
636
+ ret = pc_action_query_task_state (pc );
609
637
if (ret )
610
- goto out ;
638
+ return ret ;
611
639
612
- pc -> user_requested_min = freq ;
640
+ * freq = pc_get_max_freq ( pc ) ;
613
641
614
- out :
615
- mutex_unlock (& pc -> freq_lock );
616
- return ret ;
642
+ return 0 ;
617
643
}
618
644
619
645
/**
@@ -625,25 +651,29 @@ int xe_guc_pc_set_min_freq(struct xe_guc_pc *pc, u32 freq)
625
651
* -EAGAIN if GuC PC not ready (likely in middle of a reset).
626
652
*/
627
653
int xe_guc_pc_get_max_freq (struct xe_guc_pc * pc , u32 * freq )
654
+ {
655
+ guard (mutex )(& pc -> freq_lock );
656
+
657
+ return xe_guc_pc_get_max_freq_locked (pc , freq );
658
+ }
659
+
660
+ static int xe_guc_pc_set_max_freq_locked (struct xe_guc_pc * pc , u32 freq )
628
661
{
629
662
int ret ;
630
663
631
- mutex_lock (& pc -> freq_lock );
632
- if (!pc -> freq_ready ) {
633
- /* Might be in the middle of a gt reset */
634
- ret = - EAGAIN ;
635
- goto out ;
636
- }
664
+ lockdep_assert_held (& pc -> freq_lock );
637
665
638
- ret = pc_action_query_task_state (pc );
666
+ /* Might be in the middle of a gt reset */
667
+ if (!pc -> freq_ready )
668
+ return - EAGAIN ;
669
+
670
+ ret = pc_set_max_freq (pc , freq );
639
671
if (ret )
640
- goto out ;
672
+ return ret ;
641
673
642
- * freq = pc_get_max_freq ( pc ) ;
674
+ pc -> user_requested_max = freq ;
643
675
644
- out :
645
- mutex_unlock (& pc -> freq_lock );
646
- return ret ;
676
+ return 0 ;
647
677
}
648
678
649
679
/**
@@ -657,24 +687,9 @@ int xe_guc_pc_get_max_freq(struct xe_guc_pc *pc, u32 *freq)
657
687
*/
658
688
int xe_guc_pc_set_max_freq (struct xe_guc_pc * pc , u32 freq )
659
689
{
660
- int ret ;
661
-
662
- mutex_lock (& pc -> freq_lock );
663
- if (!pc -> freq_ready ) {
664
- /* Might be in the middle of a gt reset */
665
- ret = - EAGAIN ;
666
- goto out ;
667
- }
668
-
669
- ret = pc_set_max_freq (pc , freq );
670
- if (ret )
671
- goto out ;
690
+ guard (mutex )(& pc -> freq_lock );
672
691
673
- pc -> user_requested_max = freq ;
674
-
675
- out :
676
- mutex_unlock (& pc -> freq_lock );
677
- return ret ;
692
+ return xe_guc_pc_set_max_freq_locked (pc , freq );
678
693
}
679
694
680
695
/**
0 commit comments