Path: blob/master/drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c
26517 views
/*1* Copyright 2021 Advanced Micro Devices, Inc.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.20*21*/2223#include "amdgpu.h"24#include "amdgpu_display.h"25#include "hwmgr.h"26#include "amdgpu_smu.h"27#include "amdgpu_dpm_internal.h"2829void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev)30{31struct drm_device *ddev = adev_to_drm(adev);32struct drm_crtc *crtc;33struct amdgpu_crtc *amdgpu_crtc;3435adev->pm.dpm.new_active_crtcs = 0;36adev->pm.dpm.new_active_crtc_count = 0;37if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {38list_for_each_entry(crtc,39&ddev->mode_config.crtc_list, head) {40amdgpu_crtc = to_amdgpu_crtc(crtc);41if (amdgpu_crtc->enabled) {42adev->pm.dpm.new_active_crtcs |= (1 << amdgpu_crtc->crtc_id);43adev->pm.dpm.new_active_crtc_count++;44}45}46}47}4849u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev)50{51struct drm_device *dev = adev_to_drm(adev);52struct drm_crtc *crtc;53struct amdgpu_crtc *amdgpu_crtc;54u32 vblank_in_pixels;55u32 vblank_time_us = 0xffffffff; /* if the displays are off, vblank time is max */5657if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {58list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {59amdgpu_crtc = to_amdgpu_crtc(crtc);60if (crtc->enabled && amdgpu_crtc->enabled && amdgpu_crtc->hw_mode.clock) {61vblank_in_pixels =62amdgpu_crtc->hw_mode.crtc_htotal *63(amdgpu_crtc->hw_mode.crtc_vblank_end -64amdgpu_crtc->hw_mode.crtc_vdisplay +65(amdgpu_crtc->v_border * 2));6667vblank_time_us = vblank_in_pixels * 1000 / amdgpu_crtc->hw_mode.clock;68break;69}70}71}7273return vblank_time_us;74}7576u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)77{78struct drm_device *dev = adev_to_drm(adev);79struct drm_crtc *crtc;80struct amdgpu_crtc *amdgpu_crtc;81u32 vrefresh = 0;8283if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {84list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {85amdgpu_crtc = to_amdgpu_crtc(crtc);86if (crtc->enabled && amdgpu_crtc->enabled && amdgpu_crtc->hw_mode.clock) {87vrefresh = drm_mode_vrefresh(&amdgpu_crtc->hw_mode);88break;89}90}91}9293return vrefresh;94}959697