Lines Matching full:pc

52  * DOC: GuC Power Conservation (PC)
54 * GuC Power Conservation (PC) supports multiple features for the most
72 * Render-C states is also a GuC PC feature that is now enabled in Xe for
77 static struct xe_guc *pc_to_guc(struct xe_guc_pc *pc) in pc_to_guc() argument
79 return container_of(pc, struct xe_guc, pc); in pc_to_guc()
82 static struct xe_guc_ct *pc_to_ct(struct xe_guc_pc *pc) in pc_to_ct() argument
84 return &pc_to_guc(pc)->ct; in pc_to_ct()
87 static struct xe_gt *pc_to_gt(struct xe_guc_pc *pc) in pc_to_gt() argument
89 return guc_to_gt(pc_to_guc(pc)); in pc_to_gt()
92 static struct xe_device *pc_to_xe(struct xe_guc_pc *pc) in pc_to_xe() argument
94 return guc_to_xe(pc_to_guc(pc)); in pc_to_xe()
97 static struct iosys_map *pc_to_maps(struct xe_guc_pc *pc) in pc_to_maps() argument
99 return &pc->bo->vmap; in pc_to_maps()
114 static int wait_for_pc_state(struct xe_guc_pc *pc, in wait_for_pc_state() argument
120 xe_device_assert_mem_access(pc_to_xe(pc)); in wait_for_pc_state()
123 if (slpc_shared_data_read(pc, header.global_state) == state) in wait_for_pc_state()
136 static int pc_action_reset(struct xe_guc_pc *pc) in pc_action_reset() argument
138 struct xe_guc_ct *ct = pc_to_ct(pc); in pc_action_reset()
142 xe_bo_ggtt_addr(pc->bo), in pc_action_reset()
149 xe_gt_err(pc_to_gt(pc), "GuC PC reset failed: %pe\n", in pc_action_reset()
155 static int pc_action_query_task_state(struct xe_guc_pc *pc) in pc_action_query_task_state() argument
157 struct xe_guc_ct *ct = pc_to_ct(pc); in pc_action_query_task_state()
161 xe_bo_ggtt_addr(pc->bo), in pc_action_query_task_state()
166 if (wait_for_pc_state(pc, SLPC_GLOBAL_STATE_RUNNING)) in pc_action_query_task_state()
172 xe_gt_err(pc_to_gt(pc), "GuC PC query task state failed: %pe\n", in pc_action_query_task_state()
178 static int pc_action_set_param(struct xe_guc_pc *pc, u8 id, u32 value) in pc_action_set_param() argument
180 struct xe_guc_ct *ct = pc_to_ct(pc); in pc_action_set_param()
189 if (wait_for_pc_state(pc, SLPC_GLOBAL_STATE_RUNNING)) in pc_action_set_param()
194 xe_gt_err(pc_to_gt(pc), "GuC PC set param[%u]=%u failed: %pe\n", in pc_action_set_param()
200 static int pc_action_unset_param(struct xe_guc_pc *pc, u8 id) in pc_action_unset_param() argument
207 struct xe_guc_ct *ct = &pc_to_guc(pc)->ct; in pc_action_unset_param()
210 if (wait_for_pc_state(pc, SLPC_GLOBAL_STATE_RUNNING)) in pc_action_unset_param()
215 xe_gt_err(pc_to_gt(pc), "GuC PC unset param failed: %pe", in pc_action_unset_param()
221 static int pc_action_setup_gucrc(struct xe_guc_pc *pc, u32 mode) in pc_action_setup_gucrc() argument
223 struct xe_guc_ct *ct = pc_to_ct(pc); in pc_action_setup_gucrc()
232 xe_gt_err(pc_to_gt(pc), "GuC RC enable mode=%u failed: %pe\n", in pc_action_setup_gucrc()
249 static u32 pc_get_min_freq(struct xe_guc_pc *pc) in pc_get_min_freq() argument
254 slpc_shared_data_read(pc, task_state_data.freq)); in pc_get_min_freq()
259 static void pc_set_manual_rp_ctrl(struct xe_guc_pc *pc, bool enable) in pc_set_manual_rp_ctrl() argument
261 struct xe_gt *gt = pc_to_gt(pc); in pc_set_manual_rp_ctrl()
268 static void pc_set_cur_freq(struct xe_guc_pc *pc, u32 freq) in pc_set_cur_freq() argument
270 struct xe_gt *gt = pc_to_gt(pc); in pc_set_cur_freq()
273 pc_set_manual_rp_ctrl(pc, true); in pc_set_cur_freq()
282 pc_set_manual_rp_ctrl(pc, false); in pc_set_cur_freq()
285 static int pc_set_min_freq(struct xe_guc_pc *pc, u32 freq) in pc_set_min_freq() argument
291 if (freq < pc->rpn_freq || freq > pc->rp0_freq) in pc_set_min_freq()
298 pc_action_set_param(pc, SLPC_PARAM_IGNORE_EFFICIENT_FREQUENCY, in pc_set_min_freq()
299 freq < pc->rpe_freq); in pc_set_min_freq()
301 return pc_action_set_param(pc, in pc_set_min_freq()
306 static int pc_get_max_freq(struct xe_guc_pc *pc) in pc_get_max_freq() argument
311 slpc_shared_data_read(pc, task_state_data.freq)); in pc_get_max_freq()
316 static int pc_set_max_freq(struct xe_guc_pc *pc, u32 freq) in pc_set_max_freq() argument
323 if (freq < pc->rpn_freq || freq > pc->rp0_freq) in pc_set_max_freq()
326 return pc_action_set_param(pc, in pc_set_max_freq()
331 static void mtl_update_rpe_value(struct xe_guc_pc *pc) in mtl_update_rpe_value() argument
333 struct xe_gt *gt = pc_to_gt(pc); in mtl_update_rpe_value()
341 pc->rpe_freq = decode_freq(REG_FIELD_GET(MTL_RPE_MASK, reg)); in mtl_update_rpe_value()
344 static void tgl_update_rpe_value(struct xe_guc_pc *pc) in tgl_update_rpe_value() argument
346 struct xe_gt *gt = pc_to_gt(pc); in tgl_update_rpe_value()
360 pc->rpe_freq = REG_FIELD_GET(RPE_MASK, reg) * GT_FREQUENCY_MULTIPLIER; in tgl_update_rpe_value()
363 static void pc_update_rp_values(struct xe_guc_pc *pc) in pc_update_rp_values() argument
365 struct xe_gt *gt = pc_to_gt(pc); in pc_update_rp_values()
369 mtl_update_rpe_value(pc); in pc_update_rp_values()
371 tgl_update_rpe_value(pc); in pc_update_rp_values()
378 pc->rpn_freq = min(pc->rpn_freq, pc->rpe_freq); in pc_update_rp_values()
383 * @pc: The GuC PC
387 u32 xe_guc_pc_get_act_freq(struct xe_guc_pc *pc) in xe_guc_pc_get_act_freq() argument
389 struct xe_gt *gt = pc_to_gt(pc); in xe_guc_pc_get_act_freq()
409 * @pc: The GuC PC
413 * -EAGAIN if GuC PC not ready (likely in middle of a reset).
415 int xe_guc_pc_get_cur_freq(struct xe_guc_pc *pc, u32 *freq) in xe_guc_pc_get_cur_freq() argument
417 struct xe_gt *gt = pc_to_gt(pc); in xe_guc_pc_get_cur_freq()
439 * @pc: The GuC PC
443 u32 xe_guc_pc_get_rp0_freq(struct xe_guc_pc *pc) in xe_guc_pc_get_rp0_freq() argument
445 return pc->rp0_freq; in xe_guc_pc_get_rp0_freq()
450 * @pc: The GuC PC
454 u32 xe_guc_pc_get_rpe_freq(struct xe_guc_pc *pc) in xe_guc_pc_get_rpe_freq() argument
456 pc_update_rp_values(pc); in xe_guc_pc_get_rpe_freq()
458 return pc->rpe_freq; in xe_guc_pc_get_rpe_freq()
463 * @pc: The GuC PC
467 u32 xe_guc_pc_get_rpn_freq(struct xe_guc_pc *pc) in xe_guc_pc_get_rpn_freq() argument
469 return pc->rpn_freq; in xe_guc_pc_get_rpn_freq()
474 * @pc: The GuC PC
478 * -EAGAIN if GuC PC not ready (likely in middle of a reset).
480 int xe_guc_pc_get_min_freq(struct xe_guc_pc *pc, u32 *freq) in xe_guc_pc_get_min_freq() argument
482 struct xe_gt *gt = pc_to_gt(pc); in xe_guc_pc_get_min_freq()
485 mutex_lock(&pc->freq_lock); in xe_guc_pc_get_min_freq()
486 if (!pc->freq_ready) { in xe_guc_pc_get_min_freq()
500 ret = pc_action_query_task_state(pc); in xe_guc_pc_get_min_freq()
504 *freq = pc_get_min_freq(pc); in xe_guc_pc_get_min_freq()
509 mutex_unlock(&pc->freq_lock); in xe_guc_pc_get_min_freq()
515 * @pc: The GuC PC
519 * -EAGAIN if GuC PC not ready (likely in middle of a reset),
522 int xe_guc_pc_set_min_freq(struct xe_guc_pc *pc, u32 freq) in xe_guc_pc_set_min_freq() argument
526 mutex_lock(&pc->freq_lock); in xe_guc_pc_set_min_freq()
527 if (!pc->freq_ready) { in xe_guc_pc_set_min_freq()
533 ret = pc_set_min_freq(pc, freq); in xe_guc_pc_set_min_freq()
537 pc->user_requested_min = freq; in xe_guc_pc_set_min_freq()
540 mutex_unlock(&pc->freq_lock); in xe_guc_pc_set_min_freq()
546 * @pc: The GuC PC
550 * -EAGAIN if GuC PC not ready (likely in middle of a reset).
552 int xe_guc_pc_get_max_freq(struct xe_guc_pc *pc, u32 *freq) in xe_guc_pc_get_max_freq() argument
556 mutex_lock(&pc->freq_lock); in xe_guc_pc_get_max_freq()
557 if (!pc->freq_ready) { in xe_guc_pc_get_max_freq()
563 ret = pc_action_query_task_state(pc); in xe_guc_pc_get_max_freq()
567 *freq = pc_get_max_freq(pc); in xe_guc_pc_get_max_freq()
570 mutex_unlock(&pc->freq_lock); in xe_guc_pc_get_max_freq()
576 * @pc: The GuC PC
580 * -EAGAIN if GuC PC not ready (likely in middle of a reset),
583 int xe_guc_pc_set_max_freq(struct xe_guc_pc *pc, u32 freq) in xe_guc_pc_set_max_freq() argument
587 mutex_lock(&pc->freq_lock); in xe_guc_pc_set_max_freq()
588 if (!pc->freq_ready) { in xe_guc_pc_set_max_freq()
594 ret = pc_set_max_freq(pc, freq); in xe_guc_pc_set_max_freq()
598 pc->user_requested_max = freq; in xe_guc_pc_set_max_freq()
601 mutex_unlock(&pc->freq_lock); in xe_guc_pc_set_max_freq()
607 * @pc: XE_GuC_PC instance
609 enum xe_gt_idle_state xe_guc_pc_c_status(struct xe_guc_pc *pc) in xe_guc_pc_c_status() argument
611 struct xe_gt *gt = pc_to_gt(pc); in xe_guc_pc_c_status()
634 * @pc: Xe_GuC_PC instance
636 u64 xe_guc_pc_rc6_residency(struct xe_guc_pc *pc) in xe_guc_pc_rc6_residency() argument
638 struct xe_gt *gt = pc_to_gt(pc); in xe_guc_pc_rc6_residency()
648 * @pc: Xe_GuC_PC instance
650 u64 xe_guc_pc_mc6_residency(struct xe_guc_pc *pc) in xe_guc_pc_mc6_residency() argument
652 struct xe_gt *gt = pc_to_gt(pc); in xe_guc_pc_mc6_residency()
660 static void mtl_init_fused_rp_values(struct xe_guc_pc *pc) in mtl_init_fused_rp_values() argument
662 struct xe_gt *gt = pc_to_gt(pc); in mtl_init_fused_rp_values()
665 xe_device_assert_mem_access(pc_to_xe(pc)); in mtl_init_fused_rp_values()
672 pc->rp0_freq = decode_freq(REG_FIELD_GET(MTL_RP0_CAP_MASK, reg)); in mtl_init_fused_rp_values()
674 pc->rpn_freq = decode_freq(REG_FIELD_GET(MTL_RPN_CAP_MASK, reg)); in mtl_init_fused_rp_values()
677 static void tgl_init_fused_rp_values(struct xe_guc_pc *pc) in tgl_init_fused_rp_values() argument
679 struct xe_gt *gt = pc_to_gt(pc); in tgl_init_fused_rp_values()
683 xe_device_assert_mem_access(pc_to_xe(pc)); in tgl_init_fused_rp_values()
689 pc->rp0_freq = REG_FIELD_GET(RP0_MASK, reg) * GT_FREQUENCY_MULTIPLIER; in tgl_init_fused_rp_values()
690 pc->rpn_freq = REG_FIELD_GET(RPN_MASK, reg) * GT_FREQUENCY_MULTIPLIER; in tgl_init_fused_rp_values()
693 static void pc_init_fused_rp_values(struct xe_guc_pc *pc) in pc_init_fused_rp_values() argument
695 struct xe_gt *gt = pc_to_gt(pc); in pc_init_fused_rp_values()
699 mtl_init_fused_rp_values(pc); in pc_init_fused_rp_values()
701 tgl_init_fused_rp_values(pc); in pc_init_fused_rp_values()
704 static u32 pc_max_freq_cap(struct xe_guc_pc *pc) in pc_max_freq_cap() argument
706 struct xe_gt *gt = pc_to_gt(pc); in pc_max_freq_cap()
710 return min(LNL_MERT_FREQ_CAP, pc->rp0_freq); in pc_max_freq_cap()
712 return min(BMG_MERT_FREQ_CAP, pc->rp0_freq); in pc_max_freq_cap()
714 return pc->rp0_freq; in pc_max_freq_cap()
721 * @pc: Xe_GuC_PC instance
723 void xe_guc_pc_raise_unslice(struct xe_guc_pc *pc) in xe_guc_pc_raise_unslice() argument
725 struct xe_gt *gt = pc_to_gt(pc); in xe_guc_pc_raise_unslice()
728 pc_set_cur_freq(pc, pc_max_freq_cap(pc)); in xe_guc_pc_raise_unslice()
733 * @pc: Xe_GuC_PC instance
735 void xe_guc_pc_init_early(struct xe_guc_pc *pc) in xe_guc_pc_init_early() argument
737 struct xe_gt *gt = pc_to_gt(pc); in xe_guc_pc_init_early()
740 pc_init_fused_rp_values(pc); in xe_guc_pc_init_early()
743 static int pc_adjust_freq_bounds(struct xe_guc_pc *pc) in pc_adjust_freq_bounds() argument
747 lockdep_assert_held(&pc->freq_lock); in pc_adjust_freq_bounds()
749 ret = pc_action_query_task_state(pc); in pc_adjust_freq_bounds()
758 if (pc_get_max_freq(pc) > pc->rp0_freq) { in pc_adjust_freq_bounds()
759 ret = pc_set_max_freq(pc, pc->rp0_freq); in pc_adjust_freq_bounds()
768 if (pc_get_min_freq(pc) > pc->rp0_freq) in pc_adjust_freq_bounds()
769 ret = pc_set_min_freq(pc, pc->rp0_freq); in pc_adjust_freq_bounds()
775 static int pc_adjust_requested_freq(struct xe_guc_pc *pc) in pc_adjust_requested_freq() argument
779 lockdep_assert_held(&pc->freq_lock); in pc_adjust_requested_freq()
781 if (pc->user_requested_min != 0) { in pc_adjust_requested_freq()
782 ret = pc_set_min_freq(pc, pc->user_requested_min); in pc_adjust_requested_freq()
787 if (pc->user_requested_max != 0) { in pc_adjust_requested_freq()
788 ret = pc_set_max_freq(pc, pc->user_requested_max); in pc_adjust_requested_freq()
796 static int pc_set_mert_freq_cap(struct xe_guc_pc *pc) in pc_set_mert_freq_cap() argument
800 if (XE_WA(pc_to_gt(pc), 22019338487)) { in pc_set_mert_freq_cap()
804 ret = xe_guc_pc_get_min_freq(pc, &pc->stashed_min_freq); in pc_set_mert_freq_cap()
806 ret = xe_guc_pc_get_max_freq(pc, &pc->stashed_max_freq); in pc_set_mert_freq_cap()
813 mutex_lock(&pc->freq_lock); in pc_set_mert_freq_cap()
814 ret = pc_set_min_freq(pc, min(pc->rpe_freq, pc_max_freq_cap(pc))); in pc_set_mert_freq_cap()
816 ret = pc_set_max_freq(pc, min(pc->rp0_freq, pc_max_freq_cap(pc))); in pc_set_mert_freq_cap()
817 mutex_unlock(&pc->freq_lock); in pc_set_mert_freq_cap()
825 * @pc: The GuC PC
830 int xe_guc_pc_restore_stashed_freq(struct xe_guc_pc *pc) in xe_guc_pc_restore_stashed_freq() argument
834 if (IS_SRIOV_VF(pc_to_xe(pc)) || pc_to_xe(pc)->info.skip_guc_pc) in xe_guc_pc_restore_stashed_freq()
837 mutex_lock(&pc->freq_lock); in xe_guc_pc_restore_stashed_freq()
838 ret = pc_set_max_freq(pc, pc->stashed_max_freq); in xe_guc_pc_restore_stashed_freq()
840 ret = pc_set_min_freq(pc, pc->stashed_min_freq); in xe_guc_pc_restore_stashed_freq()
841 mutex_unlock(&pc->freq_lock); in xe_guc_pc_restore_stashed_freq()
848 * @pc: Xe_GuC_PC instance
854 int xe_guc_pc_gucrc_disable(struct xe_guc_pc *pc) in xe_guc_pc_gucrc_disable() argument
856 struct xe_device *xe = pc_to_xe(pc); in xe_guc_pc_gucrc_disable()
857 struct xe_gt *gt = pc_to_gt(pc); in xe_guc_pc_gucrc_disable()
863 ret = pc_action_setup_gucrc(pc, GUCRC_HOST_CONTROL); in xe_guc_pc_gucrc_disable()
880 * @pc: Xe_GuC_PC instance
885 int xe_guc_pc_override_gucrc_mode(struct xe_guc_pc *pc, enum slpc_gucrc_mode mode) in xe_guc_pc_override_gucrc_mode() argument
889 xe_pm_runtime_get(pc_to_xe(pc)); in xe_guc_pc_override_gucrc_mode()
890 ret = pc_action_set_param(pc, SLPC_PARAM_PWRGATE_RC_MODE, mode); in xe_guc_pc_override_gucrc_mode()
891 xe_pm_runtime_put(pc_to_xe(pc)); in xe_guc_pc_override_gucrc_mode()
898 * @pc: Xe_GuC_PC instance
902 int xe_guc_pc_unset_gucrc_mode(struct xe_guc_pc *pc) in xe_guc_pc_unset_gucrc_mode() argument
906 xe_pm_runtime_get(pc_to_xe(pc)); in xe_guc_pc_unset_gucrc_mode()
907 ret = pc_action_unset_param(pc, SLPC_PARAM_PWRGATE_RC_MODE); in xe_guc_pc_unset_gucrc_mode()
908 xe_pm_runtime_put(pc_to_xe(pc)); in xe_guc_pc_unset_gucrc_mode()
913 static void pc_init_pcode_freq(struct xe_guc_pc *pc) in pc_init_pcode_freq() argument
915 u32 min = DIV_ROUND_CLOSEST(pc->rpn_freq, GT_FREQUENCY_MULTIPLIER); in pc_init_pcode_freq()
916 u32 max = DIV_ROUND_CLOSEST(pc->rp0_freq, GT_FREQUENCY_MULTIPLIER); in pc_init_pcode_freq()
918 XE_WARN_ON(xe_pcode_init_min_freq_table(gt_to_tile(pc_to_gt(pc)), min, max)); in pc_init_pcode_freq()
921 static int pc_init_freqs(struct xe_guc_pc *pc) in pc_init_freqs() argument
925 mutex_lock(&pc->freq_lock); in pc_init_freqs()
927 ret = pc_adjust_freq_bounds(pc); in pc_init_freqs()
931 ret = pc_adjust_requested_freq(pc); in pc_init_freqs()
935 pc_update_rp_values(pc); in pc_init_freqs()
937 pc_init_pcode_freq(pc); in pc_init_freqs()
943 pc->freq_ready = true; in pc_init_freqs()
946 mutex_unlock(&pc->freq_lock); in pc_init_freqs()
952 * @pc: Xe_GuC_PC instance
954 int xe_guc_pc_start(struct xe_guc_pc *pc) in xe_guc_pc_start() argument
956 struct xe_device *xe = pc_to_xe(pc); in xe_guc_pc_start()
957 struct xe_gt *gt = pc_to_gt(pc); in xe_guc_pc_start()
972 pc_set_cur_freq(pc, UINT_MAX); in xe_guc_pc_start()
978 memset(pc->bo->vmap.vaddr, 0, size); in xe_guc_pc_start()
979 slpc_shared_data_write(pc, header.size, size); in xe_guc_pc_start()
981 ret = pc_action_reset(pc); in xe_guc_pc_start()
985 if (wait_for_pc_state(pc, SLPC_GLOBAL_STATE_RUNNING)) { in xe_guc_pc_start()
986 xe_gt_err(gt, "GuC PC Start failed\n"); in xe_guc_pc_start()
991 ret = pc_init_freqs(pc); in xe_guc_pc_start()
995 ret = pc_set_mert_freq_cap(pc); in xe_guc_pc_start()
1000 xe_guc_pc_gucrc_disable(pc); in xe_guc_pc_start()
1005 ret = pc_action_setup_gucrc(pc, GUCRC_FIRMWARE_CONTROL); in xe_guc_pc_start()
1014 * @pc: Xe_GuC_PC instance
1016 int xe_guc_pc_stop(struct xe_guc_pc *pc) in xe_guc_pc_stop() argument
1018 struct xe_device *xe = pc_to_xe(pc); in xe_guc_pc_stop()
1021 xe_gt_idle_disable_c6(pc_to_gt(pc)); in xe_guc_pc_stop()
1025 mutex_lock(&pc->freq_lock); in xe_guc_pc_stop()
1026 pc->freq_ready = false; in xe_guc_pc_stop()
1027 mutex_unlock(&pc->freq_lock); in xe_guc_pc_stop()
1038 struct xe_guc_pc *pc = arg; in xe_guc_pc_fini_hw() local
1039 struct xe_device *xe = pc_to_xe(pc); in xe_guc_pc_fini_hw()
1044 XE_WARN_ON(xe_force_wake_get(gt_to_fw(pc_to_gt(pc)), XE_FORCEWAKE_ALL)); in xe_guc_pc_fini_hw()
1045 xe_guc_pc_gucrc_disable(pc); in xe_guc_pc_fini_hw()
1046 XE_WARN_ON(xe_guc_pc_stop(pc)); in xe_guc_pc_fini_hw()
1049 pc_set_cur_freq(pc, min(pc_max_freq_cap(pc), pc->rpe_freq)); in xe_guc_pc_fini_hw()
1051 xe_force_wake_put(gt_to_fw(pc_to_gt(pc)), XE_FORCEWAKE_ALL); in xe_guc_pc_fini_hw()
1056 * @pc: Xe_GuC_PC instance
1058 int xe_guc_pc_init(struct xe_guc_pc *pc) in xe_guc_pc_init() argument
1060 struct xe_gt *gt = pc_to_gt(pc); in xe_guc_pc_init()
1070 err = drmm_mutex_init(&xe->drm, &pc->freq_lock); in xe_guc_pc_init()
1081 pc->bo = bo; in xe_guc_pc_init()
1083 return devm_add_action_or_reset(xe->drm.dev, xe_guc_pc_fini_hw, pc); in xe_guc_pc_init()