1 /*
2 * Copyright (c) 2014 - 2018, 2020 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 #include <stdlib.h>
31 #include <utils/debug.h>
32 #include <utils/constants.h>
33 #include <string>
34 #include <algorithm>
35 
36 namespace sdm {
37 
GetSimulationFlag()38 int Debug::GetSimulationFlag() {
39   int value = 0;
40   DebugHandler::Get()->GetProperty(COMPOSITION_MASK_PROP, &value);
41 
42   return value;
43 }
44 
GetExternalResolution(char * value)45 bool Debug::GetExternalResolution(char *value) {
46   uint32_t retval = 0;
47   DebugHandler::Get()->GetProperty(HDMI_CONFIG_INDEX_PROP, value);
48   if (value[0]) {
49     retval = 1;
50   }
51 
52   return retval;
53 }
54 
GetIdleTimeoutMs(uint32_t * active_ms,uint32_t * inactive_ms)55 void Debug::GetIdleTimeoutMs(uint32_t *active_ms, uint32_t *inactive_ms) {
56   int active_val = IDLE_TIMEOUT_ACTIVE_MS;
57   int inactive_val = IDLE_TIMEOUT_INACTIVE_MS;
58 
59   DebugHandler::Get()->GetProperty(IDLE_TIME_PROP, &active_val);
60   DebugHandler::Get()->GetProperty(IDLE_TIME_INACTIVE_PROP, &inactive_val);
61 
62   *active_ms = UINT32(active_val);
63   *inactive_ms = UINT32(inactive_val);
64 }
65 
IsRotatorDownScaleDisabled()66 bool Debug::IsRotatorDownScaleDisabled() {
67   int value = 0;
68   DebugHandler::Get()->GetProperty(DISABLE_ROTATOR_DOWNSCALE_PROP, &value);
69 
70   return (value == 1);
71 }
72 
IsDecimationDisabled()73 bool Debug::IsDecimationDisabled() {
74   int value = 0;
75   DebugHandler::Get()->GetProperty(DISABLE_DECIMATION_PROP, &value);
76 
77   return (value == 1);
78 }
79 
GetMaxPipesPerMixer(DisplayType display_type)80 int Debug::GetMaxPipesPerMixer(DisplayType display_type) {
81   int value = -1;
82   switch (display_type) {
83     case kBuiltIn:
84       DebugHandler::Get()->GetProperty(PRIMARY_MIXER_STAGES_PROP, &value);
85       break;
86     case kPluggable:
87       DebugHandler::Get()->GetProperty(EXTERNAL_MIXER_STAGES_PROP, &value);
88       break;
89     case kVirtual:
90       DebugHandler::Get()->GetProperty(VIRTUAL_MIXER_STAGES_PROP, &value);
91       break;
92     default:
93       break;
94   }
95 
96   return value;
97 }
98 
GetMaxUpscale()99 int Debug::GetMaxUpscale() {
100   int value = 0;
101   DebugHandler::Get()->GetProperty(MAX_UPSCALE_PROP, &value);
102 
103   return value;
104 }
105 
IsVideoModeEnabled()106 bool Debug::IsVideoModeEnabled() {
107   int value = 0;
108   DebugHandler::Get()->GetProperty(VIDEO_MODE_PANEL_PROP, &value);
109 
110   return (value == 1);
111 }
112 
IsRotatorUbwcDisabled()113 bool Debug::IsRotatorUbwcDisabled() {
114   int value = 0;
115   DebugHandler::Get()->GetProperty(DISABLE_ROTATOR_UBWC_PROP, &value);
116 
117   return (value == 1);
118 }
119 
IsRotatorSplitDisabled()120 bool Debug::IsRotatorSplitDisabled() {
121   int value = 0;
122   DebugHandler::Get()->GetProperty(DISABLE_ROTATOR_SPLIT_PROP, &value);
123 
124   return (value == 1);
125 }
126 
IsScalarDisabled()127 bool Debug::IsScalarDisabled() {
128   int value = 0;
129   DebugHandler::Get()->GetProperty(DISABLE_SCALER_PROP, &value);
130 
131   return (value == 1);
132 }
133 
IsUbwcTiledFrameBuffer()134 bool Debug::IsUbwcTiledFrameBuffer() {
135   int ubwc_disabled = 0;
136 
137   DebugHandler::Get()->GetProperty(DISABLE_UBWC_PROP, &ubwc_disabled);
138 
139   return (ubwc_disabled == 0);
140 }
141 
IsAVRDisabled()142 bool Debug::IsAVRDisabled() {
143   int value = 0;
144   DebugHandler::Get()->GetProperty(DISABLE_AVR_PROP, &value);
145 
146   return (value == 1);
147 }
148 
IsExtAnimDisabled()149 bool Debug::IsExtAnimDisabled() {
150   int value = 0;
151   DebugHandler::Get()->GetProperty(DISABLE_EXTERNAL_ANIMATION_PROP, &value);
152 
153   return (value == 1);
154 }
155 
IsPartialSplitDisabled()156 bool Debug::IsPartialSplitDisabled() {
157   int value = 0;
158   DebugHandler::Get()->GetProperty(DISABLE_PARTIAL_SPLIT_PROP, &value);
159 
160   return (value == 1);
161 }
162 
IsSrcSplitPreferred()163 bool Debug::IsSrcSplitPreferred() {
164   int value = 0;
165   DebugHandler::Get()->GetProperty(PREFER_SOURCE_SPLIT_PROP, &value);
166 
167   return (value == 1);
168 }
169 
GetMixerResolution(uint32_t * width,uint32_t * height)170 DisplayError Debug::GetMixerResolution(uint32_t *width, uint32_t *height) {
171   char value[64] = {};
172 
173   int error = DebugHandler::Get()->GetProperty(MIXER_RESOLUTION_PROP, value);
174   if (error != 0) {
175     return kErrorUndefined;
176   }
177 
178   std::string str(value);
179 
180   *width = UINT32(stoi(str));
181   *height = UINT32(stoi(str.substr(str.find('x') + 1)));
182 
183   return kErrorNone;
184 }
185 
GetWindowRect(float * left,float * top,float * right,float * bottom)186 DisplayError Debug::GetWindowRect(float *left, float *top, float *right, float *bottom) {
187   char value[64] = {};
188 
189   int error = DebugHandler::Get()->GetProperty(WINDOW_RECT_PROP, value);
190   if (error != 0) {
191     return kErrorUndefined;
192   }
193 
194   std::string str(value);
195   *left = FLOAT(stof(str));
196   str = (str.substr(str.find(',') + 1));
197   *top = FLOAT(stof(str));
198   str = (str.substr(str.find(',') + 1));
199   *right = FLOAT(stof(str));
200   str = (str.substr(str.find(',') + 1));
201   *bottom = FLOAT(stof(str));
202 
203   if (*left < 0 || *top < 0 || *right < 0 || *bottom < 0) {
204     *left = *top = *right = *bottom = 0;
205   }
206 
207   return kErrorNone;
208 }
209 
GetReducedConfig(uint32_t * num_vig_pipes,uint32_t * num_dma_pipes)210 DisplayError Debug::GetReducedConfig(uint32_t *num_vig_pipes, uint32_t *num_dma_pipes) {
211   char value[64] = {};
212 
213   int error = DebugHandler::Get()->GetProperty(SIMULATED_CONFIG_PROP, value);
214   if (error != 0) {
215     return kErrorUndefined;
216   }
217 
218   std::string str(value);
219 
220   *num_vig_pipes = UINT32(stoi(str));
221   *num_dma_pipes = UINT32(stoi(str.substr(str.find('x') + 1)));
222 
223   return kErrorNone;
224 }
225 
GetExtMaxlayers()226 int Debug::GetExtMaxlayers() {
227   int max_external_layers = 0;
228   DebugHandler::Get()->GetProperty(MAX_EXTERNAL_LAYERS_PROP, &max_external_layers);
229 
230   return std::max(max_external_layers, 2);
231 }
232 
GetProperty(const char * property_name,char * value)233 DisplayError Debug::GetProperty(const char *property_name, char *value) {
234   if (DebugHandler::Get()->GetProperty(property_name, value)) {
235     return kErrorUndefined;
236   }
237 
238   return kErrorNone;
239 }
240 
GetProperty(const char * property_name,int * value)241 DisplayError Debug::GetProperty(const char *property_name, int *value) {
242   if (DebugHandler::Get()->GetProperty(property_name, value)) {
243     return kErrorUndefined;
244   }
245 
246   return kErrorNone;
247 }
248 
249 }  // namespace sdm
250 
251