Lines Matching +full:max +full:- +full:freq
1 // SPDX-License-Identifier: MIT
63 * including frequency management, Render-C states management, and various
76 * Render-C States:
79 * Render-C states is also a GuC PC feature that is now enabled in Xe for
91 return &pc_to_guc(pc)->ct; in pc_to_ct()
106 return &pc->bo->vmap; in pc_to_maps()
138 wait = timeout_us - slept; in wait_for_pc_state()
141 return -ETIMEDOUT; in wait_for_pc_state()
150 xe_bo_ggtt_addr(pc->bo), in pc_action_reset()
169 xe_bo_ggtt_addr(pc->bo), in pc_action_query_task_state()
176 return -EAGAIN; in pc_action_query_task_state()
200 return -EAGAIN; in pc_action_set_param()
217 struct xe_guc_ct *ct = &pc_to_guc(pc)->ct; in pc_action_unset_param()
222 return -EAGAIN; in pc_action_unset_param()
254 static u32 encode_freq(u32 freq) in encode_freq() argument
256 return DIV_ROUND_CLOSEST(freq * GT_FREQUENCY_SCALER, in encode_freq()
262 u32 freq; in pc_get_min_freq() local
264 freq = FIELD_GET(SLPC_MIN_UNSLICE_FREQ_MASK, in pc_get_min_freq()
265 slpc_shared_data_read(pc, task_state_data.freq)); in pc_get_min_freq()
267 return decode_freq(freq); in pc_get_min_freq()
275 /* Allow/Disallow punit to process software freq requests */ in pc_set_manual_rp_ctrl()
276 xe_mmio_write32(>->mmio, RP_CONTROL, state); in pc_set_manual_rp_ctrl()
279 static void pc_set_cur_freq(struct xe_guc_pc *pc, u32 freq) in pc_set_cur_freq() argument
286 /* Req freq is in units of 16.66 Mhz */ in pc_set_cur_freq()
287 rpnswreq = REG_FIELD_PREP(REQ_RATIO_MASK, encode_freq(freq)); in pc_set_cur_freq()
288 xe_mmio_write32(>->mmio, RPNSWREQ, rpnswreq); in pc_set_cur_freq()
296 static int pc_set_min_freq(struct xe_guc_pc *pc, u32 freq) in pc_set_min_freq() argument
299 * Let's only check for the rpn-rp0 range. If max < min, in pc_set_min_freq()
302 if (freq < pc->rpn_freq || freq > pc->rp0_freq) in pc_set_min_freq()
303 return -EINVAL; in pc_set_min_freq()
310 freq < pc->rpe_freq); in pc_set_min_freq()
314 freq); in pc_set_min_freq()
319 u32 freq; in pc_get_max_freq() local
321 freq = FIELD_GET(SLPC_MAX_UNSLICE_FREQ_MASK, in pc_get_max_freq()
322 slpc_shared_data_read(pc, task_state_data.freq)); in pc_get_max_freq()
324 return decode_freq(freq); in pc_get_max_freq()
327 static int pc_set_max_freq(struct xe_guc_pc *pc, u32 freq) in pc_set_max_freq() argument
330 * Let's only check for the rpn-rp0 range. If max < min, in pc_set_max_freq()
334 if (freq < pc->rpn_freq || freq > pc->rp0_freq) in pc_set_max_freq()
335 return -EINVAL; in pc_set_max_freq()
339 freq); in pc_set_max_freq()
348 reg = xe_mmio_read32(>->mmio, MTL_MPA_FREQUENCY); in mtl_update_rpa_value()
350 reg = xe_mmio_read32(>->mmio, MTL_GT_RPA_FREQUENCY); in mtl_update_rpa_value()
352 pc->rpa_freq = decode_freq(REG_FIELD_GET(MTL_RPA_MASK, reg)); in mtl_update_rpa_value()
361 reg = xe_mmio_read32(>->mmio, MTL_MPE_FREQUENCY); in mtl_update_rpe_value()
363 reg = xe_mmio_read32(>->mmio, MTL_GT_RPE_FREQUENCY); in mtl_update_rpe_value()
365 pc->rpe_freq = decode_freq(REG_FIELD_GET(MTL_RPE_MASK, reg)); in mtl_update_rpe_value()
379 if (xe->info.platform == XE_PVC) { in tgl_update_rpa_value()
380 reg = xe_mmio_read32(>->mmio, PVC_RP_STATE_CAP); in tgl_update_rpa_value()
381 pc->rpa_freq = REG_FIELD_GET(RP0_MASK, reg) * GT_FREQUENCY_MULTIPLIER; in tgl_update_rpa_value()
383 reg = xe_mmio_read32(>->mmio, FREQ_INFO_REC); in tgl_update_rpa_value()
384 pc->rpa_freq = REG_FIELD_GET(RPA_MASK, reg) * GT_FREQUENCY_MULTIPLIER; in tgl_update_rpa_value()
399 if (xe->info.platform == XE_PVC) { in tgl_update_rpe_value()
400 reg = xe_mmio_read32(>->mmio, PVC_RP_STATE_CAP); in tgl_update_rpe_value()
401 pc->rpe_freq = REG_FIELD_GET(RP1_MASK, reg) * GT_FREQUENCY_MULTIPLIER; in tgl_update_rpe_value()
403 reg = xe_mmio_read32(>->mmio, FREQ_INFO_REC); in tgl_update_rpe_value()
404 pc->rpe_freq = REG_FIELD_GET(RPE_MASK, reg) * GT_FREQUENCY_MULTIPLIER; in tgl_update_rpe_value()
426 pc->rpn_freq = min(pc->rpn_freq, pc->rpe_freq); in pc_update_rp_values()
430 * xe_guc_pc_get_act_freq - Get Actual running frequency
433 * Returns: The Actual running frequency. Which might be 0 if GT is in Render-C sleep state (RC6).
439 u32 freq; in xe_guc_pc_get_act_freq() local
443 freq = xe_mmio_read32(>->mmio, MTL_MIRROR_TARGET_WP1); in xe_guc_pc_get_act_freq()
444 freq = REG_FIELD_GET(MTL_CAGF_MASK, freq); in xe_guc_pc_get_act_freq()
446 freq = xe_mmio_read32(>->mmio, GT_PERF_STATUS); in xe_guc_pc_get_act_freq()
447 freq = REG_FIELD_GET(CAGF_MASK, freq); in xe_guc_pc_get_act_freq()
450 freq = decode_freq(freq); in xe_guc_pc_get_act_freq()
452 return freq; in xe_guc_pc_get_act_freq()
457 u32 freq; in get_cur_freq() local
459 freq = xe_mmio_read32(>->mmio, RPNSWREQ); in get_cur_freq()
460 freq = REG_FIELD_GET(REQ_RATIO_MASK, freq); in get_cur_freq()
461 return decode_freq(freq); in get_cur_freq()
465 * xe_guc_pc_get_cur_freq - Get Current requested frequency
467 * @freq: A pointer to a u32 where the freq value will be returned
470 * -EAGAIN if GuC PC not ready (likely in middle of a reset).
472 int xe_guc_pc_get_cur_freq(struct xe_guc_pc *pc, u32 *freq) in xe_guc_pc_get_cur_freq() argument
478 * GuC SLPC plays with cur freq request when GuCRC is enabled in xe_guc_pc_get_cur_freq()
484 return -ETIMEDOUT; in xe_guc_pc_get_cur_freq()
487 *freq = get_cur_freq(gt); in xe_guc_pc_get_cur_freq()
494 * xe_guc_pc_get_rp0_freq - Get the RP0 freq
497 * Returns: RP0 freq.
501 return pc->rp0_freq; in xe_guc_pc_get_rp0_freq()
505 * xe_guc_pc_get_rpa_freq - Get the RPa freq
508 * Returns: RPa freq.
514 return pc->rpa_freq; in xe_guc_pc_get_rpa_freq()
518 * xe_guc_pc_get_rpe_freq - Get the RPe freq
521 * Returns: RPe freq.
527 return pc->rpe_freq; in xe_guc_pc_get_rpe_freq()
531 * xe_guc_pc_get_rpn_freq - Get the RPn freq
534 * Returns: RPn freq.
538 return pc->rpn_freq; in xe_guc_pc_get_rpn_freq()
542 * xe_guc_pc_get_min_freq - Get the min operational frequency
544 * @freq: A pointer to a u32 where the freq value will be returned
547 * -EAGAIN if GuC PC not ready (likely in middle of a reset).
549 int xe_guc_pc_get_min_freq(struct xe_guc_pc *pc, u32 *freq) in xe_guc_pc_get_min_freq() argument
555 mutex_lock(&pc->freq_lock); in xe_guc_pc_get_min_freq()
556 if (!pc->freq_ready) { in xe_guc_pc_get_min_freq()
558 ret = -EAGAIN; in xe_guc_pc_get_min_freq()
566 *freq = pc_get_min_freq(pc); in xe_guc_pc_get_min_freq()
569 mutex_unlock(&pc->freq_lock); in xe_guc_pc_get_min_freq()
574 * xe_guc_pc_set_min_freq - Set the minimal operational frequency
576 * @freq: The selected minimal frequency
579 * -EAGAIN if GuC PC not ready (likely in middle of a reset),
580 * -EINVAL if value out of bounds.
582 int xe_guc_pc_set_min_freq(struct xe_guc_pc *pc, u32 freq) in xe_guc_pc_set_min_freq() argument
586 mutex_lock(&pc->freq_lock); in xe_guc_pc_set_min_freq()
587 if (!pc->freq_ready) { in xe_guc_pc_set_min_freq()
589 ret = -EAGAIN; in xe_guc_pc_set_min_freq()
593 ret = pc_set_min_freq(pc, freq); in xe_guc_pc_set_min_freq()
597 pc->user_requested_min = freq; in xe_guc_pc_set_min_freq()
600 mutex_unlock(&pc->freq_lock); in xe_guc_pc_set_min_freq()
605 * xe_guc_pc_get_max_freq - Get Maximum operational frequency
607 * @freq: A pointer to a u32 where the freq value will be returned
610 * -EAGAIN if GuC PC not ready (likely in middle of a reset).
612 int xe_guc_pc_get_max_freq(struct xe_guc_pc *pc, u32 *freq) in xe_guc_pc_get_max_freq() argument
616 mutex_lock(&pc->freq_lock); in xe_guc_pc_get_max_freq()
617 if (!pc->freq_ready) { in xe_guc_pc_get_max_freq()
619 ret = -EAGAIN; in xe_guc_pc_get_max_freq()
627 *freq = pc_get_max_freq(pc); in xe_guc_pc_get_max_freq()
630 mutex_unlock(&pc->freq_lock); in xe_guc_pc_get_max_freq()
635 * xe_guc_pc_set_max_freq - Set the maximum operational frequency
637 * @freq: The selected maximum frequency value
640 * -EAGAIN if GuC PC not ready (likely in middle of a reset),
641 * -EINVAL if value out of bounds.
643 int xe_guc_pc_set_max_freq(struct xe_guc_pc *pc, u32 freq) in xe_guc_pc_set_max_freq() argument
647 mutex_lock(&pc->freq_lock); in xe_guc_pc_set_max_freq()
648 if (!pc->freq_ready) { in xe_guc_pc_set_max_freq()
650 ret = -EAGAIN; in xe_guc_pc_set_max_freq()
654 ret = pc_set_max_freq(pc, freq); in xe_guc_pc_set_max_freq()
658 pc->user_requested_max = freq; in xe_guc_pc_set_max_freq()
661 mutex_unlock(&pc->freq_lock); in xe_guc_pc_set_max_freq()
666 * xe_guc_pc_c_status - get the current GT C state
675 reg = xe_mmio_read32(>->mmio, MTL_MIRROR_TARGET_WP1); in xe_guc_pc_c_status()
678 reg = xe_mmio_read32(>->mmio, GT_CORE_STATUS); in xe_guc_pc_c_status()
693 * xe_guc_pc_rc6_residency - rc6 residency counter
701 reg = xe_mmio_read32(>->mmio, GT_GFX_RC6); in xe_guc_pc_rc6_residency()
707 * xe_guc_pc_mc6_residency - mc6 residency counter
715 reg = xe_mmio_read32(>->mmio, MTL_MEDIA_MC6); in xe_guc_pc_mc6_residency()
728 reg = xe_mmio_read32(>->mmio, MTL_MEDIAP_STATE_CAP); in mtl_init_fused_rp_values()
730 reg = xe_mmio_read32(>->mmio, MTL_RP_STATE_CAP); in mtl_init_fused_rp_values()
732 pc->rp0_freq = decode_freq(REG_FIELD_GET(MTL_RP0_CAP_MASK, reg)); in mtl_init_fused_rp_values()
734 pc->rpn_freq = decode_freq(REG_FIELD_GET(MTL_RPN_CAP_MASK, reg)); in mtl_init_fused_rp_values()
745 if (xe->info.platform == XE_PVC) in tgl_init_fused_rp_values()
746 reg = xe_mmio_read32(>->mmio, PVC_RP_STATE_CAP); in tgl_init_fused_rp_values()
748 reg = xe_mmio_read32(>->mmio, RP_STATE_CAP); in tgl_init_fused_rp_values()
749 pc->rp0_freq = REG_FIELD_GET(RP0_MASK, reg) * GT_FREQUENCY_MULTIPLIER; in tgl_init_fused_rp_values()
750 pc->rpn_freq = REG_FIELD_GET(RPN_MASK, reg) * GT_FREQUENCY_MULTIPLIER; in tgl_init_fused_rp_values()
770 return min(LNL_MERT_FREQ_CAP, pc->rp0_freq); in pc_max_freq_cap()
772 return min(BMG_MERT_FREQ_CAP, pc->rp0_freq); in pc_max_freq_cap()
774 return pc->rp0_freq; in pc_max_freq_cap()
779 * xe_guc_pc_raise_unslice - Initialize RPx values and request a higher GT
792 * xe_guc_pc_init_early - Initialize RPx values
807 lockdep_assert_held(&pc->freq_lock); in pc_adjust_freq_bounds()
818 if (pc_get_max_freq(pc) > pc->rp0_freq) { in pc_adjust_freq_bounds()
819 ret = pc_set_max_freq(pc, pc->rp0_freq); in pc_adjust_freq_bounds()
828 if (pc_get_min_freq(pc) > pc->rp0_freq) in pc_adjust_freq_bounds()
829 ret = pc_set_min_freq(pc, pc->rp0_freq); in pc_adjust_freq_bounds()
839 lockdep_assert_held(&pc->freq_lock); in pc_adjust_requested_freq()
841 if (pc->user_requested_min != 0) { in pc_adjust_requested_freq()
842 ret = pc_set_min_freq(pc, pc->user_requested_min); in pc_adjust_requested_freq()
847 if (pc->user_requested_max != 0) { in pc_adjust_requested_freq()
848 ret = pc_set_max_freq(pc, pc->user_requested_max); in pc_adjust_requested_freq()
862 * Get updated min/max and stash them. in pc_set_mert_freq_cap()
864 ret = xe_guc_pc_get_min_freq(pc, &pc->stashed_min_freq); in pc_set_mert_freq_cap()
866 ret = xe_guc_pc_get_max_freq(pc, &pc->stashed_max_freq); in pc_set_mert_freq_cap()
871 * Ensure min and max are bound by MERT_FREQ_CAP until driver loads. in pc_set_mert_freq_cap()
873 mutex_lock(&pc->freq_lock); in pc_set_mert_freq_cap()
874 ret = pc_set_min_freq(pc, min(pc->rpe_freq, pc_max_freq_cap(pc))); in pc_set_mert_freq_cap()
876 ret = pc_set_max_freq(pc, min(pc->rp0_freq, pc_max_freq_cap(pc))); in pc_set_mert_freq_cap()
877 mutex_unlock(&pc->freq_lock); in pc_set_mert_freq_cap()
884 * xe_guc_pc_restore_stashed_freq - Set min/max back to stashed values
894 if (IS_SRIOV_VF(pc_to_xe(pc)) || pc_to_xe(pc)->info.skip_guc_pc) in xe_guc_pc_restore_stashed_freq()
897 mutex_lock(&pc->freq_lock); in xe_guc_pc_restore_stashed_freq()
898 ret = pc_set_max_freq(pc, pc->stashed_max_freq); in xe_guc_pc_restore_stashed_freq()
900 ret = pc_set_min_freq(pc, pc->stashed_min_freq); in xe_guc_pc_restore_stashed_freq()
901 mutex_unlock(&pc->freq_lock); in xe_guc_pc_restore_stashed_freq()
907 * xe_guc_pc_gucrc_disable - Disable GuC RC
921 if (xe->info.skip_guc_pc) in xe_guc_pc_gucrc_disable()
931 return -ETIMEDOUT; in xe_guc_pc_gucrc_disable()
942 * xe_guc_pc_override_gucrc_mode - override GUCRC mode
960 * xe_guc_pc_unset_gucrc_mode - unset GUCRC mode override
978 u32 min = DIV_ROUND_CLOSEST(pc->rpn_freq, GT_FREQUENCY_MULTIPLIER); in pc_init_pcode_freq()
979 u32 max = DIV_ROUND_CLOSEST(pc->rp0_freq, GT_FREQUENCY_MULTIPLIER); in pc_init_pcode_freq() local
981 XE_WARN_ON(xe_pcode_init_min_freq_table(gt_to_tile(pc_to_gt(pc)), min, max)); in pc_init_pcode_freq()
988 mutex_lock(&pc->freq_lock); in pc_init_freqs()
1006 pc->freq_ready = true; in pc_init_freqs()
1009 mutex_unlock(&pc->freq_lock); in pc_init_freqs()
1025 * xe_guc_pc_start - Start GuC's Power Conservation component
1042 return -ETIMEDOUT; in xe_guc_pc_start()
1045 if (xe->info.skip_guc_pc) { in xe_guc_pc_start()
1046 if (xe->info.platform != XE_PVC) in xe_guc_pc_start()
1049 /* Request max possible since dynamic freq mgmt is not enabled */ in xe_guc_pc_start()
1056 memset(pc->bo->vmap.vaddr, 0, size); in xe_guc_pc_start()
1066 …xe_gt_warn(gt, "GuC PC start taking longer than normal [freq = %dMHz (req = %dMHz), perf_limit_rea… in xe_guc_pc_start()
1073 ret = -EIO; in xe_guc_pc_start()
1089 if (xe->info.platform == XE_PVC) { in xe_guc_pc_start()
1108 * xe_guc_pc_stop - Stop GuC's Power Conservation component
1115 if (xe->info.skip_guc_pc) { in xe_guc_pc_stop()
1120 mutex_lock(&pc->freq_lock); in xe_guc_pc_stop()
1121 pc->freq_ready = false; in xe_guc_pc_stop()
1122 mutex_unlock(&pc->freq_lock); in xe_guc_pc_stop()
1128 * xe_guc_pc_fini_hw - Finalize GuC's Power Conservation component
1144 /* Bind requested freq to mert_freq_cap before unload */ in xe_guc_pc_fini_hw()
1145 pc_set_cur_freq(pc, min(pc_max_freq_cap(pc), pc->rpe_freq)); in xe_guc_pc_fini_hw()
1151 * xe_guc_pc_init - Initialize GuC's Power Conservation component
1163 if (xe->info.skip_guc_pc) in xe_guc_pc_init()
1166 err = drmm_mutex_init(&xe->drm, &pc->freq_lock); in xe_guc_pc_init()
1177 pc->bo = bo; in xe_guc_pc_init()
1179 return devm_add_action_or_reset(xe->drm.dev, xe_guc_pc_fini_hw, pc); in xe_guc_pc_init()
1203 * xe_guc_pc_print - Print GuC's Power Conservation information for debug