sumo_smc.c 5.6 KB

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