amdgpu_powerplay.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * Copyright 2015 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. * Authors: AMD
  23. *
  24. */
  25. #include "atom.h"
  26. #include "amdgpu.h"
  27. #include "amd_shared.h"
  28. #include <linux/module.h>
  29. #include <linux/moduleparam.h>
  30. #include "amdgpu_pm.h"
  31. #include <drm/amdgpu_drm.h>
  32. #include "amdgpu_powerplay.h"
  33. #include "si_dpm.h"
  34. #include "cik_dpm.h"
  35. #include "vi_dpm.h"
  36. static int amdgpu_pp_early_init(void *handle)
  37. {
  38. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  39. struct amd_powerplay *amd_pp;
  40. int ret = 0;
  41. amd_pp = &(adev->powerplay);
  42. amd_pp->pp_handle = (void *)adev;
  43. switch (adev->asic_type) {
  44. case CHIP_POLARIS11:
  45. case CHIP_POLARIS10:
  46. case CHIP_POLARIS12:
  47. case CHIP_TONGA:
  48. case CHIP_FIJI:
  49. case CHIP_TOPAZ:
  50. case CHIP_CARRIZO:
  51. case CHIP_STONEY:
  52. case CHIP_VEGA10:
  53. case CHIP_RAVEN:
  54. amd_pp->cgs_device = amdgpu_cgs_create_device(adev);
  55. amd_pp->ip_funcs = &pp_ip_funcs;
  56. amd_pp->pp_funcs = &pp_dpm_funcs;
  57. break;
  58. /* These chips don't have powerplay implemenations */
  59. #ifdef CONFIG_DRM_AMDGPU_SI
  60. case CHIP_TAHITI:
  61. case CHIP_PITCAIRN:
  62. case CHIP_VERDE:
  63. case CHIP_OLAND:
  64. case CHIP_HAINAN:
  65. amd_pp->ip_funcs = &si_dpm_ip_funcs;
  66. amd_pp->pp_funcs = &si_dpm_funcs;
  67. break;
  68. #endif
  69. #ifdef CONFIG_DRM_AMDGPU_CIK
  70. case CHIP_BONAIRE:
  71. case CHIP_HAWAII:
  72. if (amdgpu_dpm == -1) {
  73. amd_pp->ip_funcs = &ci_dpm_ip_funcs;
  74. amd_pp->pp_funcs = &ci_dpm_funcs;
  75. } else {
  76. amd_pp->cgs_device = amdgpu_cgs_create_device(adev);
  77. amd_pp->ip_funcs = &pp_ip_funcs;
  78. amd_pp->pp_funcs = &pp_dpm_funcs;
  79. }
  80. break;
  81. case CHIP_KABINI:
  82. case CHIP_MULLINS:
  83. case CHIP_KAVERI:
  84. amd_pp->ip_funcs = &kv_dpm_ip_funcs;
  85. amd_pp->pp_funcs = &kv_dpm_funcs;
  86. break;
  87. #endif
  88. default:
  89. ret = -EINVAL;
  90. break;
  91. }
  92. if (adev->powerplay.ip_funcs->early_init)
  93. ret = adev->powerplay.ip_funcs->early_init(
  94. amd_pp->cgs_device ? amd_pp->cgs_device :
  95. amd_pp->pp_handle);
  96. return ret;
  97. }
  98. static int amdgpu_pp_late_init(void *handle)
  99. {
  100. int ret = 0;
  101. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  102. if (adev->powerplay.ip_funcs->late_init)
  103. ret = adev->powerplay.ip_funcs->late_init(
  104. adev->powerplay.pp_handle);
  105. return ret;
  106. }
  107. static int amdgpu_pp_sw_init(void *handle)
  108. {
  109. int ret = 0;
  110. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  111. if (adev->powerplay.ip_funcs->sw_init)
  112. ret = adev->powerplay.ip_funcs->sw_init(
  113. adev->powerplay.pp_handle);
  114. return ret;
  115. }
  116. static int amdgpu_pp_sw_fini(void *handle)
  117. {
  118. int ret = 0;
  119. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  120. if (adev->powerplay.ip_funcs->sw_fini)
  121. ret = adev->powerplay.ip_funcs->sw_fini(
  122. adev->powerplay.pp_handle);
  123. if (ret)
  124. return ret;
  125. return ret;
  126. }
  127. static int amdgpu_pp_hw_init(void *handle)
  128. {
  129. int ret = 0;
  130. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  131. if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
  132. amdgpu_ucode_init_bo(adev);
  133. if (adev->powerplay.ip_funcs->hw_init)
  134. ret = adev->powerplay.ip_funcs->hw_init(
  135. adev->powerplay.pp_handle);
  136. return ret;
  137. }
  138. static int amdgpu_pp_hw_fini(void *handle)
  139. {
  140. int ret = 0;
  141. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  142. if (adev->powerplay.ip_funcs->hw_fini)
  143. ret = adev->powerplay.ip_funcs->hw_fini(
  144. adev->powerplay.pp_handle);
  145. if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
  146. amdgpu_ucode_fini_bo(adev);
  147. return ret;
  148. }
  149. static void amdgpu_pp_late_fini(void *handle)
  150. {
  151. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  152. if (adev->powerplay.ip_funcs->late_fini)
  153. adev->powerplay.ip_funcs->late_fini(
  154. adev->powerplay.pp_handle);
  155. if (adev->powerplay.cgs_device)
  156. amdgpu_cgs_destroy_device(adev->powerplay.cgs_device);
  157. }
  158. static int amdgpu_pp_suspend(void *handle)
  159. {
  160. int ret = 0;
  161. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  162. if (adev->powerplay.ip_funcs->suspend)
  163. ret = adev->powerplay.ip_funcs->suspend(
  164. adev->powerplay.pp_handle);
  165. return ret;
  166. }
  167. static int amdgpu_pp_resume(void *handle)
  168. {
  169. int ret = 0;
  170. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  171. if (adev->powerplay.ip_funcs->resume)
  172. ret = adev->powerplay.ip_funcs->resume(
  173. adev->powerplay.pp_handle);
  174. return ret;
  175. }
  176. static int amdgpu_pp_set_clockgating_state(void *handle,
  177. enum amd_clockgating_state state)
  178. {
  179. int ret = 0;
  180. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  181. if (adev->powerplay.ip_funcs->set_clockgating_state)
  182. ret = adev->powerplay.ip_funcs->set_clockgating_state(
  183. adev->powerplay.pp_handle, state);
  184. return ret;
  185. }
  186. static int amdgpu_pp_set_powergating_state(void *handle,
  187. enum amd_powergating_state state)
  188. {
  189. int ret = 0;
  190. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  191. if (adev->powerplay.ip_funcs->set_powergating_state)
  192. ret = adev->powerplay.ip_funcs->set_powergating_state(
  193. adev->powerplay.pp_handle, state);
  194. return ret;
  195. }
  196. static bool amdgpu_pp_is_idle(void *handle)
  197. {
  198. bool ret = true;
  199. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  200. if (adev->powerplay.ip_funcs->is_idle)
  201. ret = adev->powerplay.ip_funcs->is_idle(
  202. adev->powerplay.pp_handle);
  203. return ret;
  204. }
  205. static int amdgpu_pp_wait_for_idle(void *handle)
  206. {
  207. int ret = 0;
  208. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  209. if (adev->powerplay.ip_funcs->wait_for_idle)
  210. ret = adev->powerplay.ip_funcs->wait_for_idle(
  211. adev->powerplay.pp_handle);
  212. return ret;
  213. }
  214. static int amdgpu_pp_soft_reset(void *handle)
  215. {
  216. int ret = 0;
  217. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  218. if (adev->powerplay.ip_funcs->soft_reset)
  219. ret = adev->powerplay.ip_funcs->soft_reset(
  220. adev->powerplay.pp_handle);
  221. return ret;
  222. }
  223. static const struct amd_ip_funcs amdgpu_pp_ip_funcs = {
  224. .name = "amdgpu_powerplay",
  225. .early_init = amdgpu_pp_early_init,
  226. .late_init = amdgpu_pp_late_init,
  227. .sw_init = amdgpu_pp_sw_init,
  228. .sw_fini = amdgpu_pp_sw_fini,
  229. .hw_init = amdgpu_pp_hw_init,
  230. .hw_fini = amdgpu_pp_hw_fini,
  231. .late_fini = amdgpu_pp_late_fini,
  232. .suspend = amdgpu_pp_suspend,
  233. .resume = amdgpu_pp_resume,
  234. .is_idle = amdgpu_pp_is_idle,
  235. .wait_for_idle = amdgpu_pp_wait_for_idle,
  236. .soft_reset = amdgpu_pp_soft_reset,
  237. .set_clockgating_state = amdgpu_pp_set_clockgating_state,
  238. .set_powergating_state = amdgpu_pp_set_powergating_state,
  239. };
  240. const struct amdgpu_ip_block_version amdgpu_pp_ip_block =
  241. {
  242. .type = AMD_IP_BLOCK_TYPE_SMC,
  243. .major = 1,
  244. .minor = 0,
  245. .rev = 0,
  246. .funcs = &amdgpu_pp_ip_funcs,
  247. };