amdgpu_dpm_internal.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2021 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. */
  23. #include "amdgpu.h"
  24. #include "amdgpu_display.h"
  25. #include "hwmgr.h"
  26. #include "amdgpu_smu.h"
  27. #include "amdgpu_dpm_internal.h"
  28. void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev)
  29. {
  30. struct drm_device *ddev = adev_to_drm(adev);
  31. struct drm_crtc *crtc;
  32. struct amdgpu_crtc *amdgpu_crtc;
  33. adev->pm.dpm.new_active_crtcs = 0;
  34. adev->pm.dpm.new_active_crtc_count = 0;
  35. if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
  36. list_for_each_entry(crtc,
  37. &ddev->mode_config.crtc_list, head) {
  38. amdgpu_crtc = to_amdgpu_crtc(crtc);
  39. if (amdgpu_crtc->enabled) {
  40. adev->pm.dpm.new_active_crtcs |= (1 << amdgpu_crtc->crtc_id);
  41. adev->pm.dpm.new_active_crtc_count++;
  42. }
  43. }
  44. }
  45. }
  46. u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev)
  47. {
  48. struct drm_device *dev = adev_to_drm(adev);
  49. struct drm_crtc *crtc;
  50. struct amdgpu_crtc *amdgpu_crtc;
  51. u32 vblank_in_pixels;
  52. u32 vblank_time_us = 0xffffffff; /* if the displays are off, vblank time is max */
  53. if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
  54. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  55. amdgpu_crtc = to_amdgpu_crtc(crtc);
  56. if (crtc->enabled && amdgpu_crtc->enabled && amdgpu_crtc->hw_mode.clock) {
  57. vblank_in_pixels =
  58. amdgpu_crtc->hw_mode.crtc_htotal *
  59. (amdgpu_crtc->hw_mode.crtc_vblank_end -
  60. amdgpu_crtc->hw_mode.crtc_vdisplay +
  61. (amdgpu_crtc->v_border * 2));
  62. vblank_time_us = vblank_in_pixels * 1000 / amdgpu_crtc->hw_mode.clock;
  63. /* we have issues with mclk switching with
  64. * refresh rates over 120 hz on the non-DC code.
  65. */
  66. if (drm_mode_vrefresh(&amdgpu_crtc->hw_mode) > 120)
  67. vblank_time_us = 0;
  68. break;
  69. }
  70. }
  71. }
  72. return vblank_time_us;
  73. }
  74. u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)
  75. {
  76. struct drm_device *dev = adev_to_drm(adev);
  77. struct drm_crtc *crtc;
  78. struct amdgpu_crtc *amdgpu_crtc;
  79. u32 vrefresh = 0;
  80. if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
  81. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  82. amdgpu_crtc = to_amdgpu_crtc(crtc);
  83. if (crtc->enabled && amdgpu_crtc->enabled && amdgpu_crtc->hw_mode.clock) {
  84. vrefresh = drm_mode_vrefresh(&amdgpu_crtc->hw_mode);
  85. break;
  86. }
  87. }
  88. }
  89. return vrefresh;
  90. }