amdgpu_powerplay.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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->powerplay.ip_funcs->hw_init)
  132. ret = adev->powerplay.ip_funcs->hw_init(
  133. adev->powerplay.pp_handle);
  134. return ret;
  135. }
  136. static int amdgpu_pp_hw_fini(void *handle)
  137. {
  138. int ret = 0;
  139. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  140. if (adev->powerplay.ip_funcs->hw_fini)
  141. ret = adev->powerplay.ip_funcs->hw_fini(
  142. adev->powerplay.pp_handle);
  143. return ret;
  144. }
  145. static void amdgpu_pp_late_fini(void *handle)
  146. {
  147. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  148. if (adev->powerplay.ip_funcs->late_fini)
  149. adev->powerplay.ip_funcs->late_fini(
  150. adev->powerplay.pp_handle);
  151. if (adev->powerplay.cgs_device)
  152. amdgpu_cgs_destroy_device(adev->powerplay.cgs_device);
  153. }
  154. static int amdgpu_pp_suspend(void *handle)
  155. {
  156. int ret = 0;
  157. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  158. if (adev->powerplay.ip_funcs->suspend)
  159. ret = adev->powerplay.ip_funcs->suspend(
  160. adev->powerplay.pp_handle);
  161. return ret;
  162. }
  163. static int amdgpu_pp_resume(void *handle)
  164. {
  165. int ret = 0;
  166. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  167. if (adev->powerplay.ip_funcs->resume)
  168. ret = adev->powerplay.ip_funcs->resume(
  169. adev->powerplay.pp_handle);
  170. return ret;
  171. }
  172. static int amdgpu_pp_set_clockgating_state(void *handle,
  173. enum amd_clockgating_state state)
  174. {
  175. int ret = 0;
  176. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  177. if (adev->powerplay.ip_funcs->set_clockgating_state)
  178. ret = adev->powerplay.ip_funcs->set_clockgating_state(
  179. adev->powerplay.pp_handle, state);
  180. return ret;
  181. }
  182. static int amdgpu_pp_set_powergating_state(void *handle,
  183. enum amd_powergating_state state)
  184. {
  185. int ret = 0;
  186. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  187. if (adev->powerplay.ip_funcs->set_powergating_state)
  188. ret = adev->powerplay.ip_funcs->set_powergating_state(
  189. adev->powerplay.pp_handle, state);
  190. return ret;
  191. }
  192. static bool amdgpu_pp_is_idle(void *handle)
  193. {
  194. bool ret = true;
  195. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  196. if (adev->powerplay.ip_funcs->is_idle)
  197. ret = adev->powerplay.ip_funcs->is_idle(
  198. adev->powerplay.pp_handle);
  199. return ret;
  200. }
  201. static int amdgpu_pp_wait_for_idle(void *handle)
  202. {
  203. int ret = 0;
  204. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  205. if (adev->powerplay.ip_funcs->wait_for_idle)
  206. ret = adev->powerplay.ip_funcs->wait_for_idle(
  207. adev->powerplay.pp_handle);
  208. return ret;
  209. }
  210. static int amdgpu_pp_soft_reset(void *handle)
  211. {
  212. int ret = 0;
  213. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  214. if (adev->powerplay.ip_funcs->soft_reset)
  215. ret = adev->powerplay.ip_funcs->soft_reset(
  216. adev->powerplay.pp_handle);
  217. return ret;
  218. }
  219. static const struct amd_ip_funcs amdgpu_pp_ip_funcs = {
  220. .name = "amdgpu_powerplay",
  221. .early_init = amdgpu_pp_early_init,
  222. .late_init = amdgpu_pp_late_init,
  223. .sw_init = amdgpu_pp_sw_init,
  224. .sw_fini = amdgpu_pp_sw_fini,
  225. .hw_init = amdgpu_pp_hw_init,
  226. .hw_fini = amdgpu_pp_hw_fini,
  227. .late_fini = amdgpu_pp_late_fini,
  228. .suspend = amdgpu_pp_suspend,
  229. .resume = amdgpu_pp_resume,
  230. .is_idle = amdgpu_pp_is_idle,
  231. .wait_for_idle = amdgpu_pp_wait_for_idle,
  232. .soft_reset = amdgpu_pp_soft_reset,
  233. .set_clockgating_state = amdgpu_pp_set_clockgating_state,
  234. .set_powergating_state = amdgpu_pp_set_powergating_state,
  235. };
  236. const struct amdgpu_ip_block_version amdgpu_pp_ip_block =
  237. {
  238. .type = AMD_IP_BLOCK_TYPE_SMC,
  239. .major = 1,
  240. .minor = 0,
  241. .rev = 0,
  242. .funcs = &amdgpu_pp_ip_funcs,
  243. };