sumo_smc.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 "sumod.h"
  26. #include "sumo_dpm.h"
  27. #include "ppsmc.h"
  28. #define SUMO_SMU_SERVICE_ROUTINE_PG_INIT 1
  29. #define SUMO_SMU_SERVICE_ROUTINE_ALTVDDNB_NOTIFY 27
  30. #define SUMO_SMU_SERVICE_ROUTINE_GFX_SRV_ID_20 20
  31. struct sumo_power_info *sumo_get_pi(struct radeon_device *rdev);
  32. static void sumo_send_msg_to_smu(struct radeon_device *rdev, u32 id)
  33. {
  34. u32 gfx_int_req;
  35. int i;
  36. for (i = 0; i < rdev->usec_timeout; i++) {
  37. if (RREG32(GFX_INT_STATUS) & INT_DONE)
  38. break;
  39. udelay(1);
  40. }
  41. gfx_int_req = SERV_INDEX(id) | INT_REQ;
  42. WREG32(GFX_INT_REQ, gfx_int_req);
  43. for (i = 0; i < rdev->usec_timeout; i++) {
  44. if (RREG32(GFX_INT_REQ) & INT_REQ)
  45. break;
  46. udelay(1);
  47. }
  48. for (i = 0; i < rdev->usec_timeout; i++) {
  49. if (RREG32(GFX_INT_STATUS) & INT_ACK)
  50. break;
  51. udelay(1);
  52. }
  53. for (i = 0; i < rdev->usec_timeout; i++) {
  54. if (RREG32(GFX_INT_STATUS) & INT_DONE)
  55. break;
  56. udelay(1);
  57. }
  58. gfx_int_req &= ~INT_REQ;
  59. WREG32(GFX_INT_REQ, gfx_int_req);
  60. }
  61. void sumo_initialize_m3_arb(struct radeon_device *rdev)
  62. {
  63. struct sumo_power_info *pi = sumo_get_pi(rdev);
  64. u32 i;
  65. if (!pi->enable_dynamic_m3_arbiter)
  66. return;
  67. for (i = 0; i < NUMBER_OF_M3ARB_PARAM_SETS; i++)
  68. WREG32_RCU(MCU_M3ARB_PARAMS + (i * 4),
  69. pi->sys_info.csr_m3_arb_cntl_default[i]);
  70. for (; i < NUMBER_OF_M3ARB_PARAM_SETS * 2; i++)
  71. WREG32_RCU(MCU_M3ARB_PARAMS + (i * 4),
  72. pi->sys_info.csr_m3_arb_cntl_uvd[i % NUMBER_OF_M3ARB_PARAM_SETS]);
  73. for (; i < NUMBER_OF_M3ARB_PARAM_SETS * 3; i++)
  74. WREG32_RCU(MCU_M3ARB_PARAMS + (i * 4),
  75. pi->sys_info.csr_m3_arb_cntl_fs3d[i % NUMBER_OF_M3ARB_PARAM_SETS]);
  76. }
  77. static bool sumo_is_alt_vddnb_supported(struct radeon_device *rdev)
  78. {
  79. struct sumo_power_info *pi = sumo_get_pi(rdev);
  80. bool return_code = false;
  81. if (!pi->enable_alt_vddnb)
  82. return return_code;
  83. if ((rdev->family == CHIP_SUMO) || (rdev->family == CHIP_SUMO2)) {
  84. if (pi->fw_version >= 0x00010C00)
  85. return_code = true;
  86. }
  87. return return_code;
  88. }
  89. void sumo_smu_notify_alt_vddnb_change(struct radeon_device *rdev,
  90. bool powersaving, bool force_nbps1)
  91. {
  92. u32 param = 0;
  93. if (!sumo_is_alt_vddnb_supported(rdev))
  94. return;
  95. if (powersaving)
  96. param |= 1;
  97. if (force_nbps1)
  98. param |= 2;
  99. WREG32_RCU(RCU_ALTVDDNB_NOTIFY, param);
  100. sumo_send_msg_to_smu(rdev, SUMO_SMU_SERVICE_ROUTINE_ALTVDDNB_NOTIFY);
  101. }
  102. void sumo_smu_pg_init(struct radeon_device *rdev)
  103. {
  104. sumo_send_msg_to_smu(rdev, SUMO_SMU_SERVICE_ROUTINE_PG_INIT);
  105. }
  106. static u32 sumo_power_of_4(u32 unit)
  107. {
  108. u32 ret = 1;
  109. u32 i;
  110. for (i = 0; i < unit; i++)
  111. ret *= 4;
  112. return ret;
  113. }
  114. void sumo_enable_boost_timer(struct radeon_device *rdev)
  115. {
  116. struct sumo_power_info *pi = sumo_get_pi(rdev);
  117. u32 period, unit, timer_value;
  118. u32 xclk = radeon_get_xclk(rdev);
  119. unit = (RREG32_RCU(RCU_LCLK_SCALING_CNTL) & LCLK_SCALING_TIMER_PRESCALER_MASK)
  120. >> LCLK_SCALING_TIMER_PRESCALER_SHIFT;
  121. period = 100 * (xclk / 100 / sumo_power_of_4(unit));
  122. timer_value = (period << 16) | (unit << 4);
  123. WREG32_RCU(RCU_GNB_PWR_REP_TIMER_CNTL, timer_value);
  124. WREG32_RCU(RCU_BOOST_MARGIN, pi->sys_info.sclk_dpm_boost_margin);
  125. WREG32_RCU(RCU_THROTTLE_MARGIN, pi->sys_info.sclk_dpm_throttle_margin);
  126. WREG32_RCU(GNB_TDP_LIMIT, pi->sys_info.gnb_tdp_limit);
  127. WREG32_RCU(RCU_SclkDpmTdpLimitPG, pi->sys_info.sclk_dpm_tdp_limit_pg);
  128. sumo_send_msg_to_smu(rdev, SUMO_SMU_SERVICE_ROUTINE_GFX_SRV_ID_20);
  129. }
  130. void sumo_set_tdp_limit(struct radeon_device *rdev, u32 index, u32 tdp_limit)
  131. {
  132. u32 regoffset = 0;
  133. u32 shift = 0;
  134. u32 mask = 0xFFF;
  135. u32 sclk_dpm_tdp_limit;
  136. switch (index) {
  137. case 0:
  138. regoffset = RCU_SclkDpmTdpLimit01;
  139. shift = 16;
  140. break;
  141. case 1:
  142. regoffset = RCU_SclkDpmTdpLimit01;
  143. shift = 0;
  144. break;
  145. case 2:
  146. regoffset = RCU_SclkDpmTdpLimit23;
  147. shift = 16;
  148. break;
  149. case 3:
  150. regoffset = RCU_SclkDpmTdpLimit23;
  151. shift = 0;
  152. break;
  153. case 4:
  154. regoffset = RCU_SclkDpmTdpLimit47;
  155. shift = 16;
  156. break;
  157. case 7:
  158. regoffset = RCU_SclkDpmTdpLimit47;
  159. shift = 0;
  160. break;
  161. default:
  162. break;
  163. }
  164. sclk_dpm_tdp_limit = RREG32_RCU(regoffset);
  165. sclk_dpm_tdp_limit &= ~(mask << shift);
  166. sclk_dpm_tdp_limit |= (tdp_limit << shift);
  167. WREG32_RCU(regoffset, sclk_dpm_tdp_limit);
  168. }
  169. void sumo_boost_state_enable(struct radeon_device *rdev, bool enable)
  170. {
  171. u32 boost_disable = RREG32_RCU(RCU_GPU_BOOST_DISABLE);
  172. boost_disable &= 0xFFFFFFFE;
  173. boost_disable |= (enable ? 0 : 1);
  174. WREG32_RCU(RCU_GPU_BOOST_DISABLE, boost_disable);
  175. }
  176. u32 sumo_get_running_fw_version(struct radeon_device *rdev)
  177. {
  178. return RREG32_RCU(RCU_FW_VERSION);
  179. }