Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 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 | |
| 25 | int psm_get_ui_state(struct pp_eventmgr *eventmgr, enum PP_StateUILabel ui_label, unsigned long *state_id) |
| 26 | { |
| 27 | struct pp_power_state *state; |
| 28 | int table_entries; |
| 29 | struct pp_hwmgr *hwmgr = eventmgr->hwmgr; |
| 30 | int i; |
| 31 | |
| 32 | table_entries = hwmgr->num_ps; |
| 33 | state = hwmgr->ps; |
| 34 | |
| 35 | for (i = 0; i < table_entries; i++) { |
| 36 | if (state->classification.ui_label & ui_label) { |
| 37 | *state_id = state->id; |
| 38 | return 0; |
| 39 | } |
rezhu | 09b7a98 | 2015-11-12 16:40:50 +0800 | [diff] [blame] | 40 | state = (struct pp_power_state *)((unsigned long)state + hwmgr->ps_size); |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 41 | } |
| 42 | return -1; |
| 43 | } |
| 44 | |
| 45 | int psm_get_state_by_classification(struct pp_eventmgr *eventmgr, enum PP_StateClassificationFlag flag, unsigned long *state_id) |
| 46 | { |
| 47 | struct pp_power_state *state; |
| 48 | int table_entries; |
| 49 | struct pp_hwmgr *hwmgr = eventmgr->hwmgr; |
| 50 | int i; |
| 51 | |
| 52 | table_entries = hwmgr->num_ps; |
| 53 | state = hwmgr->ps; |
| 54 | |
| 55 | for (i = 0; i < table_entries; i++) { |
| 56 | if (state->classification.flags & flag) { |
| 57 | *state_id = state->id; |
| 58 | return 0; |
| 59 | } |
rezhu | 09b7a98 | 2015-11-12 16:40:50 +0800 | [diff] [blame] | 60 | state = (struct pp_power_state *)((unsigned long)state + hwmgr->ps_size); |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 61 | } |
| 62 | return -1; |
| 63 | } |
| 64 | |
Rex Zhu | 018462d | 2015-12-29 11:19:14 +0800 | [diff] [blame] | 65 | int psm_set_states(struct pp_eventmgr *eventmgr, unsigned long *state_id) |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 66 | { |
| 67 | struct pp_power_state *state; |
| 68 | int table_entries; |
| 69 | struct pp_hwmgr *hwmgr = eventmgr->hwmgr; |
| 70 | int i; |
| 71 | |
| 72 | table_entries = hwmgr->num_ps; |
Rex Zhu | 48fad3a | 2016-09-01 02:30:42 +0800 | [diff] [blame] | 73 | |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 74 | state = hwmgr->ps; |
| 75 | |
| 76 | for (i = 0; i < table_entries; i++) { |
| 77 | if (state->id == *state_id) { |
Rex Zhu | 48fad3a | 2016-09-01 02:30:42 +0800 | [diff] [blame] | 78 | memcpy(hwmgr->request_ps, state, hwmgr->ps_size); |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 79 | return 0; |
| 80 | } |
rezhu | 09b7a98 | 2015-11-12 16:40:50 +0800 | [diff] [blame] | 81 | state = (struct pp_power_state *)((unsigned long)state + hwmgr->ps_size); |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 82 | } |
| 83 | return -1; |
| 84 | } |
| 85 | |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 86 | int psm_adjust_power_state_dynamic(struct pp_eventmgr *eventmgr, bool skip) |
| 87 | { |
| 88 | |
Rex Zhu | f4caf3e5 | 2015-11-04 14:56:56 +0800 | [diff] [blame] | 89 | struct pp_power_state *pcurrent; |
| 90 | struct pp_power_state *requested; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 91 | struct pp_hwmgr *hwmgr; |
Rex Zhu | f4caf3e5 | 2015-11-04 14:56:56 +0800 | [diff] [blame] | 92 | bool equal; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 93 | |
| 94 | if (skip) |
| 95 | return 0; |
| 96 | |
| 97 | hwmgr = eventmgr->hwmgr; |
| 98 | pcurrent = hwmgr->current_ps; |
| 99 | requested = hwmgr->request_ps; |
| 100 | |
Rex Zhu | f4caf3e5 | 2015-11-04 14:56:56 +0800 | [diff] [blame] | 101 | if (requested == NULL) |
| 102 | return 0; |
| 103 | |
| 104 | if (pcurrent == NULL || (0 != phm_check_states_equal(hwmgr, &pcurrent->hardware, &requested->hardware, &equal))) |
| 105 | equal = false; |
| 106 | |
| 107 | if (!equal || phm_check_smc_update_required_for_display_configuration(hwmgr)) { |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 108 | phm_apply_state_adjust_rules(hwmgr, requested, pcurrent); |
| 109 | phm_set_power_state(hwmgr, &pcurrent->hardware, &requested->hardware); |
Rex Zhu | 48fad3a | 2016-09-01 02:30:42 +0800 | [diff] [blame] | 110 | memcpy(hwmgr->current_ps, hwmgr->request_ps, hwmgr->ps_size); |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 111 | } |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | int psm_adjust_power_state_static(struct pp_eventmgr *eventmgr, bool skip) |
| 116 | { |
| 117 | return 0; |
| 118 | } |