blob: 6c29b06c936301d74a184c58ae9fa0c36e63b856 [file] [log] [blame]
Michael Bestas7af0fea2019-10-06 02:05:22 +03001/*
2 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#define LOG_NIDEBUG 0
31
32#include <dlfcn.h>
33#include <errno.h>
34#include <fcntl.h>
35#include <stdlib.h>
36#include <string.h>
37#include <sys/stat.h>
38#include <sys/types.h>
39
40#define LOG_TAG "QCOM PowerHAL"
41#include <hardware/hardware.h>
42#include <hardware/power.h>
43#include <log/log.h>
44
45#include "hint-data.h"
46#include "metadata-defs.h"
47#include "performance.h"
48#include "power-common.h"
49#include "utils.h"
50
51static int process_video_encode_hint(void* metadata) {
52 char governor[80];
53 struct video_encode_metadata_t video_encode_metadata;
54
55 if (!metadata) return HINT_NONE;
56
57 if (get_scaling_governor(governor, sizeof(governor)) == -1) {
58 ALOGE("Can't obtain scaling governor.");
59 return HINT_NONE;
60 }
61
62 /* Initialize encode metadata struct fields */
63 memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
64 video_encode_metadata.state = -1;
65 video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
66
67 if (parse_video_encode_metadata((char*)metadata, &video_encode_metadata) == -1) {
68 ALOGE("Error occurred while parsing metadata.");
69 return HINT_NONE;
70 }
71
72 if (video_encode_metadata.state == 1) {
73 if (is_interactive_governor(governor)) {
74 int resource_values[] = {TR_MS_30, HISPEED_LOAD_90, HS_FREQ_1026,
75 THREAD_MIGRATION_SYNC_OFF, INTERACTIVE_IO_BUSY_OFF};
76 perform_hint_action(video_encode_metadata.hint_id, resource_values,
77 ARRAY_SIZE(resource_values));
78 return HINT_HANDLED;
79 }
80 } else if (video_encode_metadata.state == 0) {
81 if (is_interactive_governor(governor)) {
82 undo_hint_action(video_encode_metadata.hint_id);
83 return HINT_HANDLED;
84 }
85 }
86 return HINT_NONE;
87}
88
89static int process_video_decode_hint(void* metadata) {
90 char governor[80];
91 struct video_decode_metadata_t video_decode_metadata;
92
93 if (!metadata) return HINT_NONE;
94
95 if (get_scaling_governor(governor, sizeof(governor)) == -1) {
96 ALOGE("Can't obtain scaling governor.");
97 return HINT_NONE;
98 }
99
100 /* Initialize encode metadata struct fields */
101 memset(&video_decode_metadata, 0, sizeof(struct video_decode_metadata_t));
102 video_decode_metadata.state = -1;
103 video_decode_metadata.hint_id = DEFAULT_VIDEO_DECODE_HINT_ID;
104
105 if (parse_video_decode_metadata((char*)metadata, &video_decode_metadata) == -1) {
106 ALOGE("Error occurred while parsing metadata.");
107 return HINT_NONE;
108 }
109
110 if (video_decode_metadata.state == 1) {
111 if (is_interactive_governor(governor)) {
112 int resource_values[] = {TR_MS_30, HISPEED_LOAD_90, HS_FREQ_1026,
113 THREAD_MIGRATION_SYNC_OFF};
114 perform_hint_action(video_decode_metadata.hint_id, resource_values,
115 ARRAY_SIZE(resource_values));
116 return HINT_HANDLED;
117 }
118 } else if (video_decode_metadata.state == 0) {
119 if (is_interactive_governor(governor)) {
120 undo_hint_action(video_decode_metadata.hint_id);
121 return HINT_HANDLED;
122 }
123 }
124 return HINT_NONE;
125}
126
127int power_hint_override(power_hint_t hint, void* data) {
128 int ret_val = HINT_NONE;
129 switch (hint) {
130 case POWER_HINT_VIDEO_ENCODE:
131 ret_val = process_video_encode_hint(data);
132 break;
133 case POWER_HINT_VIDEO_DECODE:
134 ret_val = process_video_decode_hint(data);
135 break;
136 default:
137 break;
138 }
139 return ret_val;
140}
Michael Bestas43b9e352019-10-06 01:34:17 +0300141
142int set_interactive_override(int on) {
143 char governor[80];
144
145 if (get_scaling_governor(governor, sizeof(governor)) == -1) {
146 ALOGE("Can't obtain scaling governor.");
147 return HINT_NONE;
148 }
149
150 if (!on) {
151 /* Display off */
152 if (is_interactive_governor(governor)) {
153 int resource_values[] = {TR_MS_50, THREAD_MIGRATION_SYNC_OFF};
154 perform_hint_action(DISPLAY_STATE_HINT_ID, resource_values,
155 ARRAY_SIZE(resource_values));
156 }
157 } else {
158 /* Display on */
159 if (is_interactive_governor(governor)) {
160 undo_hint_action(DISPLAY_STATE_HINT_ID);
161 }
162 }
163 return HINT_HANDLED;
164}