trinity_smc.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2012 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 "drmP.h"
  24. #include "radeon.h"
  25. #include "trinityd.h"
  26. #include "trinity_dpm.h"
  27. #include "ppsmc.h"
  28. struct trinity_ps *trinity_get_ps(struct radeon_ps *rps);
  29. struct trinity_power_info *trinity_get_pi(struct radeon_device *rdev);
  30. static int trinity_notify_message_to_smu(struct radeon_device *rdev, u32 id)
  31. {
  32. int i;
  33. u32 v = 0;
  34. WREG32(SMC_MESSAGE_0, id);
  35. for (i = 0; i < rdev->usec_timeout; i++) {
  36. if (RREG32(SMC_RESP_0) != 0)
  37. break;
  38. udelay(1);
  39. }
  40. v = RREG32(SMC_RESP_0);
  41. if (v != 1) {
  42. if (v == 0xFF) {
  43. DRM_ERROR("SMC failed to handle the message!\n");
  44. return -EINVAL;
  45. } else if (v == 0xFE) {
  46. DRM_ERROR("Unknown SMC message!\n");
  47. return -EINVAL;
  48. }
  49. }
  50. return 0;
  51. }
  52. int trinity_dpm_bapm_enable(struct radeon_device *rdev, bool enable)
  53. {
  54. if (enable)
  55. return trinity_notify_message_to_smu(rdev, PPSMC_MSG_EnableBAPM);
  56. else
  57. return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DisableBAPM);
  58. }
  59. int trinity_dpm_config(struct radeon_device *rdev, bool enable)
  60. {
  61. if (enable)
  62. WREG32_SMC(SMU_SCRATCH0, 1);
  63. else
  64. WREG32_SMC(SMU_SCRATCH0, 0);
  65. return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_Config);
  66. }
  67. int trinity_dpm_force_state(struct radeon_device *rdev, u32 n)
  68. {
  69. WREG32_SMC(SMU_SCRATCH0, n);
  70. return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_ForceState);
  71. }
  72. int trinity_dpm_n_levels_disabled(struct radeon_device *rdev, u32 n)
  73. {
  74. WREG32_SMC(SMU_SCRATCH0, n);
  75. return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_N_LevelsDisabled);
  76. }
  77. int trinity_uvd_dpm_config(struct radeon_device *rdev)
  78. {
  79. return trinity_notify_message_to_smu(rdev, PPSMC_MSG_UVD_DPM_Config);
  80. }
  81. int trinity_dpm_no_forced_level(struct radeon_device *rdev)
  82. {
  83. return trinity_notify_message_to_smu(rdev, PPSMC_MSG_NoForcedLevel);
  84. }
  85. int trinity_dce_enable_voltage_adjustment(struct radeon_device *rdev,
  86. bool enable)
  87. {
  88. if (enable)
  89. return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DCE_AllowVoltageAdjustment);
  90. else
  91. return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DCE_RemoveVoltageAdjustment);
  92. }
  93. int trinity_gfx_dynamic_mgpg_config(struct radeon_device *rdev)
  94. {
  95. return trinity_notify_message_to_smu(rdev, PPSMC_MSG_PG_SIMD_Config);
  96. }
  97. void trinity_acquire_mutex(struct radeon_device *rdev)
  98. {
  99. int i;
  100. WREG32(SMC_INT_REQ, 1);
  101. for (i = 0; i < rdev->usec_timeout; i++) {
  102. if ((RREG32(SMC_INT_REQ) & 0xffff) == 1)
  103. break;
  104. udelay(1);
  105. }
  106. }
  107. void trinity_release_mutex(struct radeon_device *rdev)
  108. {
  109. WREG32(SMC_INT_REQ, 0);
  110. }