eventtasks.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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. */
  23. #include "eventmgr.h"
  24. #include "eventinit.h"
  25. #include "eventmanagement.h"
  26. #include "eventmanager.h"
  27. #include "hardwaremanager.h"
  28. #include "eventtasks.h"
  29. #include "power_state.h"
  30. #include "hwmgr.h"
  31. #include "amd_powerplay.h"
  32. #include "psm.h"
  33. #define TEMP_RANGE_MIN (90 * 1000)
  34. #define TEMP_RANGE_MAX (120 * 1000)
  35. int pem_task_update_allowed_performance_levels(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  36. {
  37. if (eventmgr == NULL || eventmgr->hwmgr == NULL)
  38. return -EINVAL;
  39. if (pem_is_hw_access_blocked(eventmgr))
  40. return 0;
  41. phm_force_dpm_levels(eventmgr->hwmgr, eventmgr->hwmgr->dpm_level);
  42. return 0;
  43. }
  44. /* eventtasks_generic.c */
  45. int pem_task_adjust_power_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  46. {
  47. struct pp_hwmgr *hwmgr;
  48. if (pem_is_hw_access_blocked(eventmgr))
  49. return 0;
  50. hwmgr = eventmgr->hwmgr;
  51. if (event_data->pnew_power_state != NULL)
  52. hwmgr->request_ps = event_data->pnew_power_state;
  53. if (phm_cap_enabled(eventmgr->platform_descriptor->platformCaps, PHM_PlatformCaps_DynamicPatchPowerState))
  54. psm_adjust_power_state_dynamic(eventmgr, event_data->skip_state_adjust_rules);
  55. else
  56. psm_adjust_power_state_static(eventmgr, event_data->skip_state_adjust_rules);
  57. return 0;
  58. }
  59. int pem_task_power_down_asic(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  60. {
  61. return phm_power_down_asic(eventmgr->hwmgr);
  62. }
  63. int pem_task_set_boot_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  64. {
  65. if (pem_is_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID))
  66. return psm_set_states(eventmgr, &(event_data->requested_state_id));
  67. return 0;
  68. }
  69. int pem_task_reset_boot_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  70. {
  71. /* TODO */
  72. return 0;
  73. }
  74. int pem_task_update_new_power_state_clocks(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  75. {
  76. /* TODO */
  77. return 0;
  78. }
  79. int pem_task_system_shutdown(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  80. {
  81. /* TODO */
  82. return 0;
  83. }
  84. int pem_task_register_interrupts(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  85. {
  86. /* TODO */
  87. return 0;
  88. }
  89. int pem_task_unregister_interrupts(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  90. {
  91. return pem_unregister_interrupts(eventmgr);
  92. }
  93. int pem_task_get_boot_state_id(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  94. {
  95. int result;
  96. result = psm_get_state_by_classification(eventmgr,
  97. PP_StateClassificationFlag_Boot,
  98. &(event_data->requested_state_id)
  99. );
  100. if (0 == result)
  101. pem_set_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID);
  102. else
  103. pem_unset_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID);
  104. return result;
  105. }
  106. int pem_task_enable_dynamic_state_management(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  107. {
  108. return phm_enable_dynamic_state_management(eventmgr->hwmgr);
  109. }
  110. int pem_task_disable_dynamic_state_management(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  111. {
  112. return phm_disable_dynamic_state_management(eventmgr->hwmgr);
  113. }
  114. int pem_task_enable_clock_power_gatings_tasks(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  115. {
  116. return phm_enable_clock_power_gatings(eventmgr->hwmgr);
  117. }
  118. int pem_task_powerdown_uvd_tasks(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  119. {
  120. return phm_powerdown_uvd(eventmgr->hwmgr);
  121. }
  122. int pem_task_powerdown_vce_tasks(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  123. {
  124. phm_powergate_uvd(eventmgr->hwmgr, true);
  125. phm_powergate_vce(eventmgr->hwmgr, true);
  126. return 0;
  127. }
  128. int pem_task_disable_clock_power_gatings_tasks(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  129. {
  130. phm_disable_clock_power_gatings(eventmgr->hwmgr);
  131. return 0;
  132. }
  133. int pem_task_start_asic_block_usage(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  134. {
  135. /* TODO */
  136. return 0;
  137. }
  138. int pem_task_stop_asic_block_usage(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  139. {
  140. /* TODO */
  141. return 0;
  142. }
  143. int pem_task_disable_smc_firmware_ctf(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  144. {
  145. return phm_disable_smc_firmware_ctf(eventmgr->hwmgr);
  146. }
  147. int pem_task_setup_asic(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  148. {
  149. return phm_setup_asic(eventmgr->hwmgr);
  150. }
  151. int pem_task_cleanup_asic(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  152. {
  153. /* TODO */
  154. return 0;
  155. }
  156. int pem_task_store_dal_configuration(struct pp_eventmgr *eventmgr, const struct amd_display_configuration *display_config)
  157. {
  158. /* TODO */
  159. return 0;
  160. /*phm_store_dal_configuration_data(eventmgr->hwmgr, display_config) */
  161. }
  162. int pem_task_notify_hw_mgr_display_configuration_change(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  163. {
  164. if (pem_is_hw_access_blocked(eventmgr))
  165. return 0;
  166. return phm_display_configuration_changed(eventmgr->hwmgr);
  167. }
  168. int pem_task_notify_hw_mgr_pre_display_configuration_change(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  169. {
  170. return 0;
  171. }
  172. int pem_task_notify_smc_display_config_after_power_state_adjustment(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  173. {
  174. if (pem_is_hw_access_blocked(eventmgr))
  175. return 0;
  176. return phm_notify_smc_display_config_after_ps_adjustment(eventmgr->hwmgr);
  177. }
  178. int pem_task_block_adjust_power_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  179. {
  180. eventmgr->block_adjust_power_state = true;
  181. /* to do PHM_ResetIPSCounter(pEventMgr->pHwMgr);*/
  182. return 0;
  183. }
  184. int pem_task_unblock_adjust_power_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  185. {
  186. eventmgr->block_adjust_power_state = false;
  187. return 0;
  188. }
  189. int pem_task_notify_power_state_change(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  190. {
  191. /* TODO */
  192. return 0;
  193. }
  194. int pem_task_block_hw_access(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  195. {
  196. /* TODO */
  197. return 0;
  198. }
  199. int pem_task_un_block_hw_access(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  200. {
  201. /* TODO */
  202. return 0;
  203. }
  204. int pem_task_reset_display_phys_access(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  205. {
  206. /* TODO */
  207. return 0;
  208. }
  209. int pem_task_set_cpu_power_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  210. {
  211. return phm_set_cpu_power_state(eventmgr->hwmgr);
  212. }
  213. /*powersaving*/
  214. int pem_task_set_power_source(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  215. {
  216. /* TODO */
  217. return 0;
  218. }
  219. int pem_task_notify_hw_of_power_source(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  220. {
  221. /* TODO */
  222. return 0;
  223. }
  224. int pem_task_get_power_saving_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  225. {
  226. /* TODO */
  227. return 0;
  228. }
  229. int pem_task_reset_power_saving_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  230. {
  231. /* TODO */
  232. return 0;
  233. }
  234. int pem_task_set_power_saving_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  235. {
  236. /* TODO */
  237. return 0;
  238. }
  239. int pem_task_set_screen_state_on(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  240. {
  241. /* TODO */
  242. return 0;
  243. }
  244. int pem_task_set_screen_state_off(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  245. {
  246. /* TODO */
  247. return 0;
  248. }
  249. int pem_task_enable_voltage_island_power_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  250. {
  251. /* TODO */
  252. return 0;
  253. }
  254. int pem_task_disable_voltage_island_power_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  255. {
  256. /* TODO */
  257. return 0;
  258. }
  259. int pem_task_enable_cgpg(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  260. {
  261. /* TODO */
  262. return 0;
  263. }
  264. int pem_task_disable_cgpg(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  265. {
  266. /* TODO */
  267. return 0;
  268. }
  269. int pem_task_enable_clock_power_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  270. {
  271. /* TODO */
  272. return 0;
  273. }
  274. int pem_task_enable_gfx_clock_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  275. {
  276. /* TODO */
  277. return 0;
  278. }
  279. int pem_task_disable_gfx_clock_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  280. {
  281. /* TODO */
  282. return 0;
  283. }
  284. /* performance */
  285. int pem_task_set_performance_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  286. {
  287. if (pem_is_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID))
  288. return psm_set_states(eventmgr, &(event_data->requested_state_id));
  289. return 0;
  290. }
  291. int pem_task_conditionally_force_3d_performance_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  292. {
  293. /* TODO */
  294. return 0;
  295. }
  296. int pem_task_enable_stutter_mode(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  297. {
  298. /* TODO */
  299. return 0;
  300. }
  301. int pem_task_get_2D_performance_state_id(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  302. {
  303. int result;
  304. if (eventmgr->features[PP_Feature_PowerPlay].supported &&
  305. !(eventmgr->features[PP_Feature_PowerPlay].enabled))
  306. result = psm_get_state_by_classification(eventmgr,
  307. PP_StateClassificationFlag_Boot,
  308. &(event_data->requested_state_id));
  309. else if (eventmgr->features[PP_Feature_User2DPerformance].enabled)
  310. result = psm_get_state_by_classification(eventmgr,
  311. PP_StateClassificationFlag_User2DPerformance,
  312. &(event_data->requested_state_id));
  313. else
  314. result = psm_get_ui_state(eventmgr, PP_StateUILabel_Performance,
  315. &(event_data->requested_state_id));
  316. if (0 == result)
  317. pem_set_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID);
  318. else
  319. pem_unset_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID);
  320. return result;
  321. }
  322. int pem_task_create_user_performance_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  323. {
  324. struct pp_power_state *state;
  325. int table_entries;
  326. struct pp_hwmgr *hwmgr = eventmgr->hwmgr;
  327. int i;
  328. table_entries = hwmgr->num_ps;
  329. state = hwmgr->ps;
  330. restart_search:
  331. for (i = 0; i < table_entries; i++) {
  332. if (state->classification.ui_label & event_data->requested_ui_label) {
  333. event_data->pnew_power_state = state;
  334. return 0;
  335. }
  336. state = (struct pp_power_state *)((unsigned long)state + hwmgr->ps_size);
  337. }
  338. switch (event_data->requested_ui_label) {
  339. case PP_StateUILabel_Battery:
  340. case PP_StateUILabel_Balanced:
  341. event_data->requested_ui_label = PP_StateUILabel_Performance;
  342. goto restart_search;
  343. default:
  344. break;
  345. }
  346. return -1;
  347. }
  348. int pem_task_initialize_thermal_controller(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  349. {
  350. struct PP_TemperatureRange range;
  351. range.max = TEMP_RANGE_MAX;
  352. range.min = TEMP_RANGE_MIN;
  353. if (eventmgr == NULL || eventmgr->platform_descriptor == NULL)
  354. return -EINVAL;
  355. if (phm_cap_enabled(eventmgr->platform_descriptor->platformCaps, PHM_PlatformCaps_ThermalController))
  356. return phm_start_thermal_controller(eventmgr->hwmgr, &range);
  357. return 0;
  358. }
  359. int pem_task_uninitialize_thermal_controller(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
  360. {
  361. return phm_stop_thermal_controller(eventmgr->hwmgr);
  362. }