Path: blob/master/drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c
29285 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_display_cfg(struct amdgpu_device *adev)30{31struct drm_device *ddev = adev_to_drm(adev);32struct amd_pp_display_configuration *cfg = &adev->pm.pm_display_cfg;33struct single_display_configuration *display_cfg;34struct drm_crtc *crtc;35struct amdgpu_crtc *amdgpu_crtc;36struct amdgpu_connector *conn;37int num_crtcs = 0;38int vrefresh;39u32 vblank_in_pixels, vblank_time_us;4041cfg->min_vblank_time = 0xffffffff; /* if the displays are off, vblank time is max */4243if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {44list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {45amdgpu_crtc = to_amdgpu_crtc(crtc);4647/* The array should only contain active displays. */48if (!amdgpu_crtc->enabled)49continue;5051conn = to_amdgpu_connector(amdgpu_crtc->connector);52display_cfg = &adev->pm.pm_display_cfg.displays[num_crtcs++];5354if (amdgpu_crtc->hw_mode.clock) {55vrefresh = drm_mode_vrefresh(&amdgpu_crtc->hw_mode);5657vblank_in_pixels =58amdgpu_crtc->hw_mode.crtc_htotal *59(amdgpu_crtc->hw_mode.crtc_vblank_end -60amdgpu_crtc->hw_mode.crtc_vdisplay +61(amdgpu_crtc->v_border * 2));6263vblank_time_us =64vblank_in_pixels * 1000 / amdgpu_crtc->hw_mode.clock;6566/* The legacy (non-DC) code has issues with mclk switching67* with refresh rates over 120 Hz. Disable mclk switching.68*/69if (vrefresh > 120)70vblank_time_us = 0;7172/* Find minimum vblank time. */73if (vblank_time_us < cfg->min_vblank_time)74cfg->min_vblank_time = vblank_time_us;7576/* Find vertical refresh rate of first active display. */77if (!cfg->vrefresh)78cfg->vrefresh = vrefresh;79}8081if (amdgpu_crtc->crtc_id < cfg->crtc_index) {82/* Find first active CRTC and its line time. */83cfg->crtc_index = amdgpu_crtc->crtc_id;84cfg->line_time_in_us = amdgpu_crtc->line_time;85}8687display_cfg->controller_id = amdgpu_crtc->crtc_id;88display_cfg->pixel_clock = conn->pixelclock_for_modeset;89}90}9192cfg->display_clk = adev->clock.default_dispclk;93cfg->num_display = num_crtcs;94}959697