Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, The Linux Foundation. All rights reserved. |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 3 | * Copyright (C) 2018 The LineageOS Project |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are |
| 7 | * met: |
| 8 | * * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
| 14 | * * Neither the name of The Linux Foundation nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived |
| 16 | * from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 22 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 25 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 27 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 28 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #define LOG_NIDEBUG 0 |
| 32 | |
| 33 | #include <errno.h> |
| 34 | #include <string.h> |
| 35 | #include <sys/types.h> |
| 36 | #include <sys/stat.h> |
| 37 | #include <fcntl.h> |
| 38 | #include <dlfcn.h> |
| 39 | #include <stdlib.h> |
| 40 | |
Michael Bestas | 1add9ac | 2018-03-25 22:56:44 +0300 | [diff] [blame] | 41 | #define LOG_TAG "QCOM PowerHAL" |
Ethan Chen | a42f4a8 | 2018-03-01 21:31:15 -0800 | [diff] [blame] | 42 | #include <log/log.h> |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 43 | #include <hardware/hardware.h> |
| 44 | #include <hardware/power.h> |
| 45 | |
| 46 | #include "utils.h" |
| 47 | #include "metadata-defs.h" |
| 48 | #include "hint-data.h" |
| 49 | #include "performance.h" |
| 50 | #include "power-common.h" |
| 51 | |
Nikhil Kumar Kansal | 839d56f | 2017-04-18 15:50:25 +0530 | [diff] [blame] | 52 | #define MIN_VAL(X,Y) ((X>Y)?(Y):(X)) |
| 53 | |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 54 | static int video_encode_hint_sent; |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 55 | |
Zhao Wei Liew | 6fe5252 | 2016-07-19 19:57:06 +0800 | [diff] [blame] | 56 | /** |
| 57 | * If target is SDM630: |
| 58 | * return true |
| 59 | * else: |
| 60 | * return false |
| 61 | */ |
| 62 | static bool is_target_SDM630(void) |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 63 | { |
Zhao Wei Liew | 6fe5252 | 2016-07-19 19:57:06 +0800 | [diff] [blame] | 64 | static bool is_SDM630 = false; |
| 65 | int soc_id; |
| 66 | |
| 67 | soc_id = get_soc_id(); |
| 68 | if (soc_id == 318 || soc_id == 327) |
| 69 | is_SDM630 = true; |
| 70 | |
| 71 | return is_SDM630; |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 72 | } |
| 73 | |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 74 | static void process_video_encode_hint(void *metadata) |
| 75 | { |
| 76 | char governor[80]; |
| 77 | int resource_values[20]; |
| 78 | int num_resources; |
| 79 | struct video_encode_metadata_t video_encode_metadata; |
| 80 | |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 81 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) { |
| 82 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) { |
| 83 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) { |
| 84 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) { |
| 85 | ALOGE("Can't obtain scaling governor."); |
| 86 | return; |
| 87 | } |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 88 | } |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
| 92 | if (!metadata) { |
| 93 | return; |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /* Initialize encode metadata struct fields. */ |
| 97 | memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t)); |
| 98 | video_encode_metadata.state = -1; |
| 99 | video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID; |
| 100 | |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 101 | if (parse_video_encode_metadata((char *)metadata, |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 102 | &video_encode_metadata) == -1) { |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 103 | ALOGE("Error occurred while parsing metadata."); |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 104 | return; |
| 105 | } |
| 106 | |
| 107 | if (video_encode_metadata.state == 1) { |
Ethan Chen | 4b4acdf | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 108 | if (is_interactive_governor(governor)) { |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 109 | if (is_target_SDM630()) { |
| 110 | /* |
| 111 | 1. CPUfreq params |
| 112 | - hispeed freq for big - 1113Mhz |
| 113 | - go hispeed load for big - 95 |
| 114 | - above_hispeed_delay for big - 40ms |
| 115 | - target loads - 95 |
| 116 | - nr_run - 5 |
| 117 | 2. BusDCVS V2 params |
| 118 | - Sample_ms of 10ms |
| 119 | */ |
| 120 | int res[] = { |
| 121 | HISPEED_FREQ_BIG, 0x459, |
| 122 | GO_HISPEED_LOAD_BIG, 0x5F, |
| 123 | ABOVE_HISPEED_DELAY_BIG, 0x4, |
| 124 | TARGET_LOADS_BIG, 0x5F, |
dianlujitao | 5eb472d | 2018-09-06 21:43:14 +0800 | [diff] [blame^] | 125 | SCHED_SPILL_NR_RUN, 0X5, |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 126 | CPUBW_HWMON_SAMPLE_MS, 0xA |
| 127 | }; |
Nikhil Kumar Kansal | 839d56f | 2017-04-18 15:50:25 +0530 | [diff] [blame] | 128 | memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res))); |
Zhao Wei Liew | d4fe61e | 2016-06-26 11:37:59 +0800 | [diff] [blame] | 129 | num_resources = ARRAY_SIZE(res); |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 130 | } else { |
| 131 | /* |
| 132 | 1. CPUfreq params |
| 133 | - hispeed freq for little - 902Mhz |
| 134 | - go hispeed load for little - 95 |
| 135 | - above_hispeed_delay for little - 40ms |
| 136 | 2. BusDCVS V2 params |
| 137 | - Sample_ms of 10ms |
| 138 | */ |
| 139 | int res[] = { |
| 140 | HISPEED_FREQ_LITTLE, 0x386, |
| 141 | GO_HISPEED_LOAD_LITTLE, 0x5F, |
| 142 | ABOVE_HISPEED_DELAY_LITTLE, 0x4, |
| 143 | CPUBW_HWMON_SAMPLE_MS, 0xA |
| 144 | }; |
Nikhil Kumar Kansal | 839d56f | 2017-04-18 15:50:25 +0530 | [diff] [blame] | 145 | memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res))); |
Zhao Wei Liew | d4fe61e | 2016-06-26 11:37:59 +0800 | [diff] [blame] | 146 | num_resources = ARRAY_SIZE(res); |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 147 | } |
Michael Bestas | 50a6e28 | 2018-05-25 21:33:46 +0300 | [diff] [blame] | 148 | if (!video_encode_hint_sent) { |
| 149 | perform_hint_action(video_encode_metadata.hint_id, |
| 150 | resource_values, num_resources); |
| 151 | video_encode_hint_sent = 1; |
| 152 | } |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 153 | } |
| 154 | } else if (video_encode_metadata.state == 0) { |
Ethan Chen | 4b4acdf | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 155 | if (is_interactive_governor(governor)) { |
Michael Bestas | 50a6e28 | 2018-05-25 21:33:46 +0300 | [diff] [blame] | 156 | undo_hint_action(video_encode_metadata.hint_id); |
| 157 | video_encode_hint_sent = 0; |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 158 | } |
| 159 | } |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | int power_hint_override(power_hint_t hint, void *data) |
| 163 | { |
| 164 | switch (hint) { |
| 165 | case POWER_HINT_VSYNC: |
| 166 | break; |
| 167 | case POWER_HINT_VIDEO_ENCODE: |
| 168 | process_video_encode_hint(data); |
| 169 | return HINT_HANDLED; |
| 170 | default: |
| 171 | break; |
| 172 | } |
| 173 | return HINT_NONE; |
| 174 | } |
| 175 | |
| 176 | int set_interactive_override(int on) |
| 177 | { |
| 178 | char governor[80]; |
| 179 | int resource_values[20]; |
| 180 | int num_resources; |
| 181 | |
| 182 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) { |
| 183 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) { |
| 184 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) { |
| 185 | if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) { |
| 186 | ALOGE("Can't obtain scaling governor."); |
| 187 | return HINT_NONE; |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | if (!on) { |
| 194 | /* Display off. */ |
| 195 | if (is_interactive_governor(governor)) { |
| 196 | if (is_target_SDM630()) { |
| 197 | /* |
| 198 | 1. CPUfreq params |
| 199 | - hispeed freq for big - 1113Mhz |
| 200 | - go hispeed load for big - 95 |
| 201 | - above_hispeed_delay for big - 40ms |
| 202 | 2. BusDCVS V2 params |
| 203 | - Sample_ms of 10ms |
| 204 | */ |
| 205 | int res[] = { |
| 206 | HISPEED_FREQ_BIG, 0x459, |
| 207 | GO_HISPEED_LOAD_BIG, 0x5F, |
| 208 | ABOVE_HISPEED_DELAY_BIG, 0x4, |
| 209 | CPUBW_HWMON_SAMPLE_MS, 0xA |
| 210 | }; |
| 211 | memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res))); |
| 212 | num_resources = ARRAY_SIZE(res); |
| 213 | } else { |
| 214 | /* |
| 215 | 1. CPUfreq params |
| 216 | - hispeed freq for little - 902Mhz |
| 217 | - go hispeed load for little - 95 |
| 218 | - above_hispeed_delay for little - 40ms |
| 219 | 2. BusDCVS V2 params |
| 220 | - Sample_ms of 10ms |
| 221 | 3. Sched group upmigrate - 500 |
| 222 | */ |
| 223 | int res[] = { |
| 224 | HISPEED_FREQ_LITTLE, 0x386, |
| 225 | GO_HISPEED_LOAD_LITTLE, 0x5F, |
| 226 | ABOVE_HISPEED_DELAY_LITTLE, 0x4, |
| 227 | CPUBW_HWMON_SAMPLE_MS, 0xA, |
| 228 | SCHED_GROUP_UP_MIGRATE, 0x1F4 |
| 229 | }; |
| 230 | memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res))); |
| 231 | num_resources = ARRAY_SIZE(res); |
| 232 | |
| 233 | } |
| 234 | perform_hint_action(DISPLAY_STATE_HINT_ID, |
| 235 | resource_values, num_resources); |
| 236 | } |
| 237 | } else { |
| 238 | /* Display on. */ |
| 239 | if (is_interactive_governor(governor)) { |
| 240 | undo_hint_action(DISPLAY_STATE_HINT_ID); |
| 241 | } |
| 242 | } |
| 243 | return HINT_HANDLED; |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 244 | } |