sumo_smc.c 5.5 KB

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