psm.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 "psm.h"
  24. int psm_get_ui_state(struct pp_eventmgr *eventmgr, enum PP_StateUILabel ui_label, unsigned long *state_id)
  25. {
  26. struct pp_power_state *state;
  27. int table_entries;
  28. struct pp_hwmgr *hwmgr = eventmgr->hwmgr;
  29. int i;
  30. table_entries = hwmgr->num_ps;
  31. state = hwmgr->ps;
  32. for (i = 0; i < table_entries; i++) {
  33. if (state->classification.ui_label & ui_label) {
  34. *state_id = state->id;
  35. return 0;
  36. }
  37. state = (struct pp_power_state *)((unsigned long)state + hwmgr->ps_size);
  38. }
  39. return -1;
  40. }
  41. int psm_get_state_by_classification(struct pp_eventmgr *eventmgr, enum PP_StateClassificationFlag flag, unsigned long *state_id)
  42. {
  43. struct pp_power_state *state;
  44. int table_entries;
  45. struct pp_hwmgr *hwmgr = eventmgr->hwmgr;
  46. int i;
  47. table_entries = hwmgr->num_ps;
  48. state = hwmgr->ps;
  49. for (i = 0; i < table_entries; i++) {
  50. if (state->classification.flags & flag) {
  51. *state_id = state->id;
  52. return 0;
  53. }
  54. state = (struct pp_power_state *)((unsigned long)state + hwmgr->ps_size);
  55. }
  56. return -1;
  57. }
  58. int psm_set_states(struct pp_eventmgr *eventmgr, unsigned long *state_id)
  59. {
  60. struct pp_power_state *state;
  61. int table_entries;
  62. struct pp_hwmgr *hwmgr = eventmgr->hwmgr;
  63. int i;
  64. table_entries = hwmgr->num_ps;
  65. state = hwmgr->ps;
  66. for (i = 0; i < table_entries; i++) {
  67. if (state->id == *state_id) {
  68. memcpy(hwmgr->request_ps, state, hwmgr->ps_size);
  69. return 0;
  70. }
  71. state = (struct pp_power_state *)((unsigned long)state + hwmgr->ps_size);
  72. }
  73. return -1;
  74. }
  75. int psm_adjust_power_state_dynamic(struct pp_eventmgr *eventmgr, bool skip)
  76. {
  77. struct pp_power_state *pcurrent;
  78. struct pp_power_state *requested;
  79. struct pp_hwmgr *hwmgr;
  80. bool equal;
  81. if (skip)
  82. return 0;
  83. hwmgr = eventmgr->hwmgr;
  84. pcurrent = hwmgr->current_ps;
  85. requested = hwmgr->request_ps;
  86. if (requested == NULL)
  87. return 0;
  88. phm_apply_state_adjust_rules(hwmgr, requested, pcurrent);
  89. if (pcurrent == NULL || (0 != phm_check_states_equal(hwmgr, &pcurrent->hardware, &requested->hardware, &equal)))
  90. equal = false;
  91. if (!equal || phm_check_smc_update_required_for_display_configuration(hwmgr)) {
  92. phm_set_power_state(hwmgr, &pcurrent->hardware, &requested->hardware);
  93. memcpy(hwmgr->current_ps, hwmgr->request_ps, hwmgr->ps_size);
  94. }
  95. return 0;
  96. }
  97. int psm_adjust_power_state_static(struct pp_eventmgr *eventmgr, bool skip)
  98. {
  99. return 0;
  100. }