Lines Matching +full:max +full:- +full:freq

1 // SPDX-License-Identifier: MIT
56 * including frequency management, Render-C states management, and various
69 * Render-C States:
72 * Render-C states is also a GuC PC feature that is now enabled in Xe for
84 return &pc_to_guc(pc)->ct; in pc_to_ct()
99 return &pc->bo->vmap; in pc_to_maps()
130 wait = timeout_us - slept; in wait_for_pc_state()
133 return -ETIMEDOUT; in wait_for_pc_state()
142 xe_bo_ggtt_addr(pc->bo), in pc_action_reset()
161 xe_bo_ggtt_addr(pc->bo), in pc_action_query_task_state()
167 return -EAGAIN; in pc_action_query_task_state()
190 return -EAGAIN; in pc_action_set_param()
207 struct xe_guc_ct *ct = &pc_to_guc(pc)->ct; in pc_action_unset_param()
211 return -EAGAIN; in pc_action_unset_param()
243 static u32 encode_freq(u32 freq) in encode_freq() argument
245 return DIV_ROUND_CLOSEST(freq * GT_FREQUENCY_SCALER, in encode_freq()
251 u32 freq; in pc_get_min_freq() local
253 freq = FIELD_GET(SLPC_MIN_UNSLICE_FREQ_MASK, in pc_get_min_freq()
254 slpc_shared_data_read(pc, task_state_data.freq)); in pc_get_min_freq()
256 return decode_freq(freq); in pc_get_min_freq()
264 /* Allow/Disallow punit to process software freq requests */ 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
275 /* Req freq is in units of 16.66 Mhz */ in pc_set_cur_freq()
276 rpnswreq = REG_FIELD_PREP(REQ_RATIO_MASK, encode_freq(freq)); 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
288 * Let's only check for the rpn-rp0 range. If max < min, in pc_set_min_freq()
291 if (freq < pc->rpn_freq || freq > pc->rp0_freq) in pc_set_min_freq()
292 return -EINVAL; in pc_set_min_freq()
299 freq < pc->rpe_freq); in pc_set_min_freq()
303 freq); in pc_set_min_freq()
308 u32 freq; in pc_get_max_freq() local
310 freq = FIELD_GET(SLPC_MAX_UNSLICE_FREQ_MASK, in pc_get_max_freq()
311 slpc_shared_data_read(pc, task_state_data.freq)); in pc_get_max_freq()
313 return decode_freq(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
319 * Let's only check for the rpn-rp0 range. If max < min, in pc_set_max_freq()
323 if (freq < pc->rpn_freq || freq > pc->rp0_freq) in pc_set_max_freq()
324 return -EINVAL; in pc_set_max_freq()
328 freq); in pc_set_max_freq()
341 pc->rpe_freq = decode_freq(REG_FIELD_GET(MTL_RPE_MASK, reg)); in mtl_update_rpe_value()
355 if (xe->info.platform == XE_PVC) in tgl_update_rpe_value()
360 pc->rpe_freq = REG_FIELD_GET(RPE_MASK, reg) * GT_FREQUENCY_MULTIPLIER; in tgl_update_rpe_value()
378 pc->rpn_freq = min(pc->rpn_freq, pc->rpe_freq); in pc_update_rp_values()
382 * xe_guc_pc_get_act_freq - Get Actual running frequency
385 * Returns: The Actual running frequency. Which might be 0 if GT is in Render-C sleep state (RC6).
391 u32 freq; in xe_guc_pc_get_act_freq() local
395 freq = xe_mmio_read32(gt, MTL_MIRROR_TARGET_WP1); in xe_guc_pc_get_act_freq()
396 freq = REG_FIELD_GET(MTL_CAGF_MASK, freq); in xe_guc_pc_get_act_freq()
398 freq = xe_mmio_read32(gt, GT_PERF_STATUS); in xe_guc_pc_get_act_freq()
399 freq = REG_FIELD_GET(CAGF_MASK, freq); in xe_guc_pc_get_act_freq()
402 freq = decode_freq(freq); in xe_guc_pc_get_act_freq()
404 return freq; in xe_guc_pc_get_act_freq()
408 * xe_guc_pc_get_cur_freq - Get Current requested frequency
410 * @freq: A pointer to a u32 where the freq value will be returned
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
421 * GuC SLPC plays with cur freq request when GuCRC is enabled in xe_guc_pc_get_cur_freq()
428 *freq = xe_mmio_read32(gt, RPNSWREQ); in xe_guc_pc_get_cur_freq()
430 *freq = REG_FIELD_GET(REQ_RATIO_MASK, *freq); in xe_guc_pc_get_cur_freq()
431 *freq = decode_freq(*freq); in xe_guc_pc_get_cur_freq()
438 * xe_guc_pc_get_rp0_freq - Get the RP0 freq
441 * Returns: RP0 freq.
445 return pc->rp0_freq; in xe_guc_pc_get_rp0_freq()
449 * xe_guc_pc_get_rpe_freq - Get the RPe freq
452 * Returns: RPe freq.
458 return pc->rpe_freq; in xe_guc_pc_get_rpe_freq()
462 * xe_guc_pc_get_rpn_freq - Get the RPn freq
465 * Returns: RPn freq.
469 return pc->rpn_freq; in xe_guc_pc_get_rpn_freq()
473 * xe_guc_pc_get_min_freq - Get the min operational frequency
475 * @freq: A pointer to a u32 where the freq value will be returned
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
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()
488 ret = -EAGAIN; in xe_guc_pc_get_min_freq()
493 * GuC SLPC plays with min freq request when GuCRC is enabled 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()
514 * xe_guc_pc_set_min_freq - Set the minimal operational frequency
516 * @freq: The selected minimal frequency
519 * -EAGAIN if GuC PC not ready (likely in middle of a reset),
520 * -EINVAL if value out of bounds.
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()
529 ret = -EAGAIN; 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()
545 * xe_guc_pc_get_max_freq - Get Maximum operational frequency
547 * @freq: A pointer to a u32 where the freq value will be returned
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()
559 ret = -EAGAIN; 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()
575 * xe_guc_pc_set_max_freq - Set the maximum operational frequency
577 * @freq: The selected maximum frequency value
580 * -EAGAIN if GuC PC not ready (likely in middle of a reset),
581 * -EINVAL if value out of bounds.
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()
590 ret = -EAGAIN; 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()
606 * xe_guc_pc_c_status - get the current GT C state
633 * xe_guc_pc_rc6_residency - rc6 residency counter
647 * xe_guc_pc_mc6_residency - mc6 residency counter
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()
685 if (xe->info.platform == XE_PVC) 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()
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()
719 * xe_guc_pc_raise_unslice - Initialize RPx values and request a higher GT
732 * xe_guc_pc_init_early - Initialize RPx values
747 lockdep_assert_held(&pc->freq_lock); 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()
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()
802 * Get updated min/max and stash them. 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()
811 * Ensure min and max are bound by MERT_FREQ_CAP until driver loads. 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()
824 * xe_guc_pc_restore_stashed_freq - Set min/max back to stashed values
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()
847 * xe_guc_pc_gucrc_disable - Disable GuC RC
860 if (xe->info.skip_guc_pc) in xe_guc_pc_gucrc_disable()
879 * xe_guc_pc_override_gucrc_mode - override GUCRC mode
897 * xe_guc_pc_unset_gucrc_mode - unset GUCRC mode override
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() local
918 XE_WARN_ON(xe_pcode_init_min_freq_table(gt_to_tile(pc_to_gt(pc)), min, max)); in pc_init_pcode_freq()
925 mutex_lock(&pc->freq_lock); in pc_init_freqs()
943 pc->freq_ready = true; in pc_init_freqs()
946 mutex_unlock(&pc->freq_lock); in pc_init_freqs()
951 * xe_guc_pc_start - Start GuC's Power Conservation component
967 if (xe->info.skip_guc_pc) { in xe_guc_pc_start()
968 if (xe->info.platform != XE_PVC) in xe_guc_pc_start()
971 /* Request max possible since dynamic freq mgmt is not enabled */ in xe_guc_pc_start()
978 memset(pc->bo->vmap.vaddr, 0, size); in xe_guc_pc_start()
987 ret = -EIO; in xe_guc_pc_start()
999 if (xe->info.platform == XE_PVC) { in xe_guc_pc_start()
1013 * xe_guc_pc_stop - Stop GuC's Power Conservation component
1020 if (xe->info.skip_guc_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()
1033 * xe_guc_pc_fini_hw - Finalize GuC's Power Conservation component
1048 /* Bind requested freq to mert_freq_cap before unload */ 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()
1055 * xe_guc_pc_init - Initialize GuC's Power Conservation component
1067 if (xe->info.skip_guc_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()