1 /* 2 * Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, are permitted 5 * provided that the following conditions are met: 6 * * Redistributions of source code must retain the above copyright notice, this list of 7 * conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above copyright notice, this list of 9 * conditions and the following disclaimer in the documentation and/or other materials provided 10 * with the distribution. 11 * * Neither the name of The Linux Foundation nor the names of its contributors may be used to 12 * endorse or promote products derived from this software without specific prior written 13 * permission. 14 * 15 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 21 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25 #include <string.h> 26 #include <stdio.h> 27 #include <stdlib.h> 28 #include <fcntl.h> 29 #include <sys/stat.h> 30 #include <sys/types.h> 31 #include <utils/constants.h> 32 #include <utils/debug.h> 33 #include <utils/sys.h> 34 #include <dlfcn.h> 35 36 #include <algorithm> 37 #include <iostream> 38 #include <fstream> 39 #include <map> 40 #include <memory> 41 #include <string> 42 #include <utility> 43 #include <vector> 44 45 #include "hw_info.h" 46 47 #define __CLASS__ "HWInfo" 48 49 using std::vector; 50 using std::map; 51 using std::string; 52 using std::fstream; 53 using std::to_string; 54 55 namespace sdm { 56 57 // kDefaultFormatSupport contains the bit map of supported formats for each hw blocks. 58 // For eg: if Cursor supports MDP_RGBA_8888[bit-13] and MDP_RGB_565[bit-0], then cursor pipe array 59 // contains { 0x01[0-3], 0x00[4-7], 0x00[8-12], 0x01[13-16], 0x00[17-20], 0x00[21-24], 0x00[24-28] } 60 const std::bitset<8> HWInfo::kDefaultFormatSupport[kHWSubBlockMax][ 61 BITS_TO_BYTES(MDP_IMGTYPE_LIMIT1)] = { 62 { 0xFF, 0xF5, 0x1C, 0x1E, 0x20, 0xFF, 0x01, 0x00, 0xFE, 0x1F }, // kHWVIGPipe 63 { 0x33, 0xE0, 0x00, 0x16, 0x00, 0xBF, 0x00, 0x00, 0xFE, 0x07 }, // kHWRGBPipe 64 { 0x33, 0xE0, 0x00, 0x16, 0x00, 0xBF, 0x00, 0x00, 0xFE, 0x07 }, // kHWDMAPipe 65 { 0x12, 0x60, 0x0C, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00 }, // kHWCursorPipe 66 { 0xFF, 0xF5, 0x1C, 0x1E, 0x20, 0xFF, 0x01, 0x00, 0xFE, 0x1F }, // kHWRotatorInput 67 { 0xFF, 0xF5, 0x1C, 0x1E, 0x20, 0xFF, 0x01, 0x00, 0xFE, 0x1F }, // kHWRotatorOutput 68 { 0x3F, 0xF4, 0x10, 0x1E, 0x20, 0xFF, 0x01, 0x00, 0xAA, 0x16 }, // kHWWBIntfOutput 69 }; 70 71 int HWInfo::ParseString(const char *input, char *tokens[], const uint32_t max_token, 72 const char *delim, uint32_t *count) { 73 char *tmp_token = NULL; 74 char *temp_ptr; 75 uint32_t index = 0; 76 if (!input) { 77 return -1; 78 } 79 tmp_token = strtok_r(const_cast<char *>(input), delim, &temp_ptr); 80 while (tmp_token && index < max_token) { 81 tokens[index++] = tmp_token; 82 tmp_token = strtok_r(NULL, delim, &temp_ptr); 83 } 84 *count = index; 85 86 return 0; 87 } 88 89 DisplayError HWInfo::GetDynamicBWLimits(HWResourceInfo *hw_resource) { 90 Sys::fstream fs(kBWModeBitmap, fstream::in); 91 if (!fs.is_open()) { 92 DLOGE("File '%s' not found", kBWModeBitmap); 93 return kErrorHardware; 94 } 95 96 HWDynBwLimitInfo* bw_info = &hw_resource->dyn_bw_info; 97 for (int index = 0; index < kBwModeMax; index++) { 98 bw_info->total_bw_limit[index] = hw_resource->max_bandwidth_low; 99 bw_info->pipe_bw_limit[index] = hw_resource->max_pipe_bw; 100 } 101 102 uint32_t token_count = 0; 103 const uint32_t max_count = kBwModeMax; 104 char *tokens[max_count] = { NULL }; 105 string line; 106 while (Sys::getline_(fs, line)) { 107 if (!ParseString(line.c_str(), tokens, max_count, ":, =\n", &token_count)) { 108 if (!strncmp(tokens[0], "default_pipe", strlen("default_pipe"))) { 109 bw_info->pipe_bw_limit[kBwDefault] = UINT32(atoi(tokens[1])); 110 } else if (!strncmp(tokens[0], "camera_pipe", strlen("camera_pipe"))) { 111 bw_info->pipe_bw_limit[kBwCamera] = UINT32(atoi(tokens[1])); 112 } else if (!strncmp(tokens[0], "vflip_pipe", strlen("vflip_pipe"))) { 113 bw_info->pipe_bw_limit[kBwVFlip] = UINT32(atoi(tokens[1])); 114 } else if (!strncmp(tokens[0], "hflip_pipe", strlen("hflip_pipe"))) { 115 bw_info->pipe_bw_limit[kBwHFlip] = UINT32(atoi(tokens[1])); 116 } else if (!strncmp(tokens[0], "default", strlen("default"))) { 117 bw_info->total_bw_limit[kBwDefault] = UINT32(atoi(tokens[1])); 118 } else if (!strncmp(tokens[0], "camera", strlen("camera"))) { 119 bw_info->total_bw_limit[kBwCamera] = UINT32(atoi(tokens[1])); 120 } else if (!strncmp(tokens[0], "vflip", strlen("vflip"))) { 121 bw_info->total_bw_limit[kBwVFlip] = UINT32(atoi(tokens[1])); 122 } else if (!strncmp(tokens[0], "hflip", strlen("hflip"))) { 123 bw_info->total_bw_limit[kBwHFlip] = UINT32(atoi(tokens[1])); 124 } 125 } 126 } 127 128 return kErrorNone; 129 } 130 131 DisplayError HWInfo::GetHWResourceInfo(HWResourceInfo *hw_resource) { 132 if (hw_resource_) { 133 *hw_resource = *hw_resource_; 134 return kErrorNone; 135 } 136 string fb_path = "/sys/devices/virtual/graphics/fb" 137 + to_string(kHWCapabilitiesNode) + "/mdp/caps"; 138 139 Sys::fstream fs(fb_path, fstream::in); 140 if (!fs.is_open()) { 141 DLOGE("File '%s' not found", fb_path.c_str()); 142 return kErrorHardware; 143 } 144 145 hw_resource_ = new HWResourceInfo; 146 147 InitSupportedFormatMap(hw_resource_); 148 hw_resource_->hw_version = kHWMdssVersion5; 149 150 uint32_t token_count = 0; 151 const uint32_t max_count = 256; 152 char *tokens[max_count] = { NULL }; 153 string line; 154 while (Sys::getline_(fs, line)) { 155 // parse the line and update information accordingly 156 if (!ParseString(line.c_str(), tokens, max_count, ":, =\n", &token_count)) { 157 if (!strncmp(tokens[0], "hw_rev", strlen("hw_rev"))) { 158 hw_resource_->hw_revision = UINT32(atoi(tokens[1])); // HW Rev, v1/v2 159 } else if (!strncmp(tokens[0], "rot_input_fmts", strlen("rot_input_fmts"))) { 160 ParseFormats(&tokens[1], (token_count - 1), kHWRotatorInput, hw_resource_); 161 } else if (!strncmp(tokens[0], "rot_output_fmts", strlen("rot_output_fmts"))) { 162 ParseFormats(&tokens[1], (token_count - 1), kHWRotatorOutput, hw_resource_); 163 } else if (!strncmp(tokens[0], "wb_output_fmts", strlen("wb_output_fmts"))) { 164 ParseFormats(&tokens[1], (token_count - 1), kHWWBIntfOutput, hw_resource_); 165 } else if (!strncmp(tokens[0], "blending_stages", strlen("blending_stages"))) { 166 hw_resource_->num_blending_stages = UINT8(atoi(tokens[1])); 167 } else if (!strncmp(tokens[0], "max_downscale_ratio", strlen("max_downscale_ratio"))) { 168 hw_resource_->max_scale_down = UINT32(atoi(tokens[1])); 169 } else if (!strncmp(tokens[0], "max_upscale_ratio", strlen("max_upscale_ratio"))) { 170 hw_resource_->max_scale_up = UINT32(atoi(tokens[1])); 171 } else if (!strncmp(tokens[0], "max_bandwidth_low", strlen("max_bandwidth_low"))) { 172 hw_resource_->max_bandwidth_low = std::stoull(tokens[1]); 173 } else if (!strncmp(tokens[0], "max_bandwidth_high", strlen("max_bandwidth_high"))) { 174 hw_resource_->max_bandwidth_high = std::stoull(tokens[1]); 175 } else if (!strncmp(tokens[0], "max_mixer_width", strlen("max_mixer_width"))) { 176 hw_resource_->max_mixer_width = UINT32(atoi(tokens[1])); 177 } else if (!strncmp(tokens[0], "max_pipe_width", strlen("max_pipe_width"))) { 178 hw_resource_->max_pipe_width = UINT32(atoi(tokens[1])); 179 } else if (!strncmp(tokens[0], "max_cursor_size", strlen("max_cursor_size"))) { 180 hw_resource_->max_cursor_size = UINT32(atoi(tokens[1])); 181 } else if (!strncmp(tokens[0], "max_pipe_bw", strlen("max_pipe_bw"))) { 182 hw_resource_->max_pipe_bw = std::stoull(tokens[1]); 183 } else if (!strncmp(tokens[0], "max_mdp_clk", strlen("max_mdp_clk"))) { 184 hw_resource_->max_sde_clk = UINT32(atoi(tokens[1])); 185 } else if (!strncmp(tokens[0], "clk_fudge_factor", strlen("clk_fudge_factor"))) { 186 hw_resource_->clk_fudge_factor = FLOAT(atoi(tokens[1])) / FLOAT(atoi(tokens[2])); 187 } else if (!strncmp(tokens[0], "fmt_mt_nv12_factor", strlen("fmt_mt_nv12_factor"))) { 188 hw_resource_->macrotile_nv12_factor = UINT32(atoi(tokens[1])); 189 } else if (!strncmp(tokens[0], "fmt_mt_factor", strlen("fmt_mt_factor"))) { 190 hw_resource_->macrotile_factor = UINT32(atoi(tokens[1])); 191 } else if (!strncmp(tokens[0], "fmt_linear_factor", strlen("fmt_linear_factor"))) { 192 hw_resource_->linear_factor = UINT32(atoi(tokens[1])); 193 } else if (!strncmp(tokens[0], "scale_factor", strlen("scale_factor"))) { 194 hw_resource_->scale_factor = UINT32(atoi(tokens[1])); 195 } else if (!strncmp(tokens[0], "xtra_ff_factor", strlen("xtra_ff_factor"))) { 196 hw_resource_->extra_fudge_factor = UINT32(atoi(tokens[1])); 197 } else if (!strncmp(tokens[0], "amortizable_threshold", strlen("amortizable_threshold"))) { 198 hw_resource_->amortizable_threshold = UINT32(atoi(tokens[1])); 199 } else if (!strncmp(tokens[0], "system_overhead_lines", strlen("system_overhead_lines"))) { 200 hw_resource_->system_overhead_lines = UINT32(atoi(tokens[1])); 201 } else if (!strncmp(tokens[0], "wb_intf_index", strlen("wb_intf_index"))) { 202 hw_resource_->writeback_index = UINT32(atoi(tokens[1])); 203 } else if (!strncmp(tokens[0], "dest_scaler_count", strlen("dest_scaler_count"))) { 204 hw_resource_->hw_dest_scalar_info.count = UINT32(atoi(tokens[1])); 205 } else if (!strncmp(tokens[0], "max_dest_scale_up", strlen("max_dest_scale_up"))) { 206 hw_resource_->hw_dest_scalar_info.max_scale_up = UINT32(atoi(tokens[1])); 207 } else if (!strncmp(tokens[0], "max_dest_scaler_input_width", 208 strlen("max_dest_scaler_input_width"))) { 209 hw_resource_->hw_dest_scalar_info.max_input_width = UINT32(atoi(tokens[1])); 210 } else if (!strncmp(tokens[0], "max_dest_scaler_output_width", 211 strlen("max_dest_scaler_output_width"))) { 212 hw_resource_->hw_dest_scalar_info.max_output_width = UINT32(atoi(tokens[1])); 213 } else if (!strncmp(tokens[0], "features", strlen("features"))) { 214 for (uint32_t i = 0; i < token_count; i++) { 215 if (!strncmp(tokens[i], "bwc", strlen("bwc"))) { 216 hw_resource_->has_bwc = true; 217 } else if (!strncmp(tokens[i], "ubwc", strlen("ubwc"))) { 218 hw_resource_->has_ubwc = true; 219 } else if (!strncmp(tokens[i], "decimation", strlen("decimation"))) { 220 hw_resource_->has_decimation = true; 221 } else if (!strncmp(tokens[i], "tile_format", strlen("tile_format"))) { 222 hw_resource_->has_macrotile = true; 223 } else if (!strncmp(tokens[i], "src_split", strlen("src_split"))) { 224 hw_resource_->is_src_split = true; 225 } else if (!strncmp(tokens[i], "non_scalar_rgb", strlen("non_scalar_rgb"))) { 226 hw_resource_->has_non_scalar_rgb = true; 227 } else if (!strncmp(tokens[i], "dynamic_bw_limit", strlen("dynamic_bw_limit"))) { 228 hw_resource_->has_dyn_bw_support = true; 229 } else if (!strncmp(tokens[i], "separate_rotator", strlen("separate_rotator"))) { 230 hw_resource_->separate_rotator = true; 231 } else if (!strncmp(tokens[i], "qseed3", strlen("qseed3"))) { 232 hw_resource_->has_qseed3 = true; 233 } else if (!strncmp(tokens[i], "has_ppp", strlen("has_ppp"))) { 234 hw_resource_->has_ppp = true; 235 } else if (!strncmp(tokens[i], "concurrent_writeback", strlen("concurrent_writeback"))) { 236 hw_resource_->has_concurrent_writeback = true; 237 } else if (!strncmp(tokens[i], "avr", strlen("avr"))) { 238 hw_resource_->has_avr = true; 239 } else if (!strncmp(tokens[i], "hdr", strlen("hdr"))) { 240 hw_resource_->has_hdr = true; 241 } 242 } 243 } else if (!strncmp(tokens[0], "pipe_count", strlen("pipe_count"))) { 244 uint32_t pipe_count = UINT8(atoi(tokens[1])); 245 for (uint32_t i = 0; i < pipe_count; i++) { 246 Sys::getline_(fs, line); 247 if (!ParseString(line.c_str(), tokens, max_count, ": =\n", &token_count)) { 248 HWPipeCaps pipe_caps; 249 pipe_caps.type = kPipeTypeUnused; 250 for (uint32_t j = 0; j < token_count; j += 2) { 251 if (!strncmp(tokens[j], "pipe_type", strlen("pipe_type"))) { 252 if (!strncmp(tokens[j+1], "vig", strlen("vig"))) { 253 pipe_caps.type = kPipeTypeVIG; 254 hw_resource_->num_vig_pipe++; 255 } else if (!strncmp(tokens[j+1], "rgb", strlen("rgb"))) { 256 pipe_caps.type = kPipeTypeRGB; 257 hw_resource_->num_rgb_pipe++; 258 } else if (!strncmp(tokens[j+1], "dma", strlen("dma"))) { 259 pipe_caps.type = kPipeTypeDMA; 260 hw_resource_->num_dma_pipe++; 261 } else if (!strncmp(tokens[j+1], "cursor", strlen("cursor"))) { 262 pipe_caps.type = kPipeTypeCursor; 263 hw_resource_->num_cursor_pipe++; 264 } 265 } else if (!strncmp(tokens[j], "pipe_ndx", strlen("pipe_ndx"))) { 266 pipe_caps.id = UINT32(atoi(tokens[j+1])); 267 } else if (!strncmp(tokens[j], "rects", strlen("rects"))) { 268 pipe_caps.max_rects = UINT32(atoi(tokens[j+1])); 269 } else if (!strncmp(tokens[j], "fmts_supported", strlen("fmts_supported"))) { 270 char *tokens_fmt[max_count] = { NULL }; 271 uint32_t token_fmt_count = 0; 272 if (!ParseString(tokens[j+1], tokens_fmt, max_count, ",\n", &token_fmt_count)) { 273 if (pipe_caps.type == kPipeTypeVIG) { 274 ParseFormats(tokens_fmt, token_fmt_count, kHWVIGPipe, hw_resource_); 275 } else if (pipe_caps.type == kPipeTypeRGB) { 276 ParseFormats(tokens_fmt, token_fmt_count, kHWRGBPipe, hw_resource_); 277 } else if (pipe_caps.type == kPipeTypeDMA) { 278 ParseFormats(tokens_fmt, token_fmt_count, kHWDMAPipe, hw_resource_); 279 } else if (pipe_caps.type == kPipeTypeCursor) { 280 ParseFormats(tokens_fmt, token_fmt_count, kHWCursorPipe, hw_resource_); 281 } 282 } 283 } 284 } 285 hw_resource_->hw_pipes.push_back(pipe_caps); 286 } 287 } 288 } 289 } 290 } 291 292 // Disable destination scalar count to 0 if extension library is not present 293 DynLib extension_lib; 294 if (!extension_lib.Open("libsdmextension.so")) { 295 hw_resource_->hw_dest_scalar_info.count = 0; 296 } 297 298 DLOGI("SDE Version = %d, SDE Revision = %x, RGB = %d, VIG = %d, DMA = %d, Cursor = %d", 299 hw_resource_->hw_version, hw_resource_->hw_revision, hw_resource_->num_rgb_pipe, 300 hw_resource_->num_vig_pipe, hw_resource_->num_dma_pipe, hw_resource_->num_cursor_pipe); 301 DLOGI("Upscale Ratio = %d, Downscale Ratio = %d, Blending Stages = %d", 302 hw_resource_->max_scale_up, hw_resource_->max_scale_down, 303 hw_resource_->num_blending_stages); 304 DLOGI("SourceSplit = %d QSEED3 = %d", hw_resource_->is_src_split, hw_resource_->has_qseed3); 305 DLOGI("BWC = %d, UBWC = %d, Decimation = %d, Tile Format = %d Concurrent Writeback = %d", 306 hw_resource_->has_bwc, hw_resource_->has_ubwc, hw_resource_->has_decimation, 307 hw_resource_->has_macrotile, hw_resource_->has_concurrent_writeback); 308 DLOGI("MaxLowBw = %" PRIu64 " , MaxHighBw = % " PRIu64 "", hw_resource_->max_bandwidth_low, 309 hw_resource_->max_bandwidth_high); 310 DLOGI("MaxPipeBw = %" PRIu64 " KBps, MaxSDEClock = % " PRIu64 " Hz, ClockFudgeFactor = %f", 311 hw_resource_->max_pipe_bw, hw_resource_->max_sde_clk, hw_resource_->clk_fudge_factor); 312 DLOGI("Prefill factors: Tiled_NV12 = %d, Tiled = %d, Linear = %d, Scale = %d, Fudge_factor = %d", 313 hw_resource_->macrotile_nv12_factor, hw_resource_->macrotile_factor, 314 hw_resource_->linear_factor, hw_resource_->scale_factor, hw_resource_->extra_fudge_factor); 315 316 if (hw_resource_->separate_rotator || hw_resource_->num_dma_pipe) { 317 GetHWRotatorInfo(hw_resource_); 318 } 319 320 // If the driver doesn't spell out the wb index, assume it to be the number of rotators, 321 // based on legacy implementation. 322 if (hw_resource_->writeback_index == kHWBlockMax) { 323 hw_resource_->writeback_index = hw_resource_->hw_rot_info.num_rotator; 324 } 325 326 if (hw_resource_->has_dyn_bw_support) { 327 DisplayError ret = GetDynamicBWLimits(hw_resource_); 328 if (ret != kErrorNone) { 329 DLOGE("Failed to read dynamic band width info"); 330 return ret; 331 } 332 333 DLOGI("Has Support for multiple bw limits shown below"); 334 for (int index = 0; index < kBwModeMax; index++) { 335 DLOGI("Mode-index=%d total_bw_limit=%d and pipe_bw_limit=%d", 336 index, hw_resource_->dyn_bw_info.total_bw_limit[index], 337 hw_resource_->dyn_bw_info.pipe_bw_limit[index]); 338 } 339 } 340 341 *hw_resource = *hw_resource_; 342 343 return kErrorNone; 344 } 345 346 DisplayError HWInfo::GetHWRotatorInfo(HWResourceInfo *hw_resource) { 347 if (GetMDSSRotatorInfo(hw_resource) != kErrorNone) 348 return GetV4L2RotatorInfo(hw_resource); 349 350 return kErrorNone; 351 } 352 353 DisplayError HWInfo::GetMDSSRotatorInfo(HWResourceInfo *hw_resource) { 354 Sys::fstream fs(kRotatorCapsPath, fstream::in); 355 if (!fs.is_open()) { 356 DLOGW("File '%s' not found", kRotatorCapsPath); 357 return kErrorNotSupported; 358 } 359 360 uint32_t token_count = 0; 361 const uint32_t max_count = 10; 362 char *tokens[max_count] = { NULL }; 363 string line; 364 365 hw_resource->hw_rot_info.type = HWRotatorInfo::ROT_TYPE_MDSS; 366 while (Sys::getline_(fs, line)) { 367 if (!ParseString(line.c_str(), tokens, max_count, ":, =\n", &token_count)) { 368 if (!strncmp(tokens[0], "wb_count", strlen("wb_count"))) { 369 hw_resource->hw_rot_info.num_rotator = UINT8(atoi(tokens[1])); 370 hw_resource->hw_rot_info.device_path = "/dev/mdss_rotator"; 371 } else if (!strncmp(tokens[0], "downscale", strlen("downscale"))) { 372 hw_resource->hw_rot_info.has_downscale = UINT8(atoi(tokens[1])); 373 } 374 } 375 } 376 377 DLOGI("MDSS Rotator: Count = %d, Downscale = %d, Min_downscale = %f", 378 hw_resource->hw_rot_info.num_rotator, hw_resource->hw_rot_info.has_downscale, 379 hw_resource->hw_rot_info.min_downscale); 380 381 return kErrorNone; 382 } 383 384 DisplayError HWInfo::GetV4L2RotatorInfo(HWResourceInfo *hw_resource) { 385 string v4l2_path = "/sys/class/video4linux/video"; 386 const uint32_t kMaxV4L2Nodes = 64; 387 bool found = false; 388 389 for (uint32_t i = 0; (i < kMaxV4L2Nodes) && (false == found); i++) { 390 string path = v4l2_path + to_string(i) + "/name"; 391 Sys::fstream fs(path, fstream::in); 392 if (!fs.is_open()) { 393 continue; 394 } 395 396 string line; 397 if (Sys::getline_(fs, line) && 398 (!strncmp(line.c_str(), "sde_rotator", strlen("sde_rotator")))) { 399 hw_resource->hw_rot_info.device_path = string("/dev/video" + to_string(i)); 400 hw_resource->hw_rot_info.num_rotator++; 401 hw_resource->hw_rot_info.type = HWRotatorInfo::ROT_TYPE_V4L2; 402 hw_resource->hw_rot_info.has_downscale = true; 403 404 string caps_path = v4l2_path + to_string(i) + "/device/caps"; 405 Sys::fstream caps_fs(caps_path, fstream::in); 406 407 if (caps_fs.is_open()) { 408 uint32_t token_count = 0; 409 const uint32_t max_count = 10; 410 char *tokens[max_count] = { NULL }; 411 string caps; 412 while (Sys::getline_(caps_fs, caps)) { 413 if (!ParseString(caps.c_str(), tokens, max_count, ":, =\n", &token_count)) { 414 if (!strncmp(tokens[0], "downscale_compression", strlen("downscale_compression"))) { 415 hw_resource->hw_rot_info.downscale_compression = UINT8(atoi(tokens[1])); 416 } else if (!strncmp(tokens[0], "min_downscale", strlen("min_downscale"))) { 417 hw_resource->hw_rot_info.min_downscale = FLOAT(atof(tokens[1])); 418 } 419 } 420 } 421 } 422 423 // We support only 1 rotator 424 found = true; 425 } 426 } 427 428 DLOGI("V4L2 Rotator: Count = %d, Downscale = %d, Min_downscale = %f, Downscale_compression = %d", 429 hw_resource->hw_rot_info.num_rotator, hw_resource->hw_rot_info.has_downscale, 430 hw_resource->hw_rot_info.min_downscale, hw_resource->hw_rot_info.downscale_compression); 431 432 return kErrorNone; 433 } 434 435 LayerBufferFormat HWInfo::GetSDMFormat(int mdp_format) { 436 switch (mdp_format) { 437 case MDP_ARGB_8888: return kFormatARGB8888; 438 case MDP_RGBA_8888: return kFormatRGBA8888; 439 case MDP_BGRA_8888: return kFormatBGRA8888; 440 case MDP_XRGB_8888: return kFormatXRGB8888; 441 case MDP_RGBX_8888: return kFormatRGBX8888; 442 case MDP_BGRX_8888: return kFormatBGRX8888; 443 case MDP_RGBA_5551: return kFormatRGBA5551; 444 case MDP_RGBA_4444: return kFormatRGBA4444; 445 case MDP_RGB_888: return kFormatRGB888; 446 case MDP_BGR_888: return kFormatBGR888; 447 case MDP_RGB_565: return kFormatRGB565; 448 case MDP_BGR_565: return kFormatBGR565; 449 case MDP_RGBA_8888_UBWC: return kFormatRGBA8888Ubwc; 450 case MDP_RGBX_8888_UBWC: return kFormatRGBX8888Ubwc; 451 case MDP_RGB_565_UBWC: return kFormatBGR565Ubwc; 452 case MDP_Y_CB_CR_H2V2: return kFormatYCbCr420Planar; 453 case MDP_Y_CR_CB_H2V2: return kFormatYCrCb420Planar; 454 case MDP_Y_CR_CB_GH2V2: return kFormatYCrCb420PlanarStride16; 455 case MDP_Y_CBCR_H2V2: return kFormatYCbCr420SemiPlanar; 456 case MDP_Y_CRCB_H2V2: return kFormatYCrCb420SemiPlanar; 457 case MDP_Y_CBCR_H2V2_VENUS: return kFormatYCbCr420SemiPlanarVenus; 458 case MDP_Y_CBCR_H1V2: return kFormatYCbCr422H1V2SemiPlanar; 459 case MDP_Y_CRCB_H1V2: return kFormatYCrCb422H1V2SemiPlanar; 460 case MDP_Y_CBCR_H2V1: return kFormatYCbCr422H2V1SemiPlanar; 461 case MDP_Y_CRCB_H2V1: return kFormatYCrCb422H2V1SemiPlanar; 462 case MDP_Y_CBCR_H2V2_UBWC: return kFormatYCbCr420SPVenusUbwc; 463 case MDP_Y_CRCB_H2V2_VENUS: return kFormatYCrCb420SemiPlanarVenus; 464 case MDP_YCBYCR_H2V1: return kFormatYCbCr422H2V1Packed; 465 case MDP_RGBA_1010102: return kFormatRGBA1010102; 466 case MDP_ARGB_2101010: return kFormatARGB2101010; 467 case MDP_RGBX_1010102: return kFormatRGBX1010102; 468 case MDP_XRGB_2101010: return kFormatXRGB2101010; 469 case MDP_BGRA_1010102: return kFormatBGRA1010102; 470 case MDP_ABGR_2101010: return kFormatABGR2101010; 471 case MDP_BGRX_1010102: return kFormatBGRX1010102; 472 case MDP_XBGR_2101010: return kFormatXBGR2101010; 473 case MDP_RGBA_1010102_UBWC: return kFormatRGBA1010102Ubwc; 474 case MDP_RGBX_1010102_UBWC: return kFormatRGBX1010102Ubwc; 475 case MDP_Y_CBCR_H2V2_P010: return kFormatYCbCr420P010; 476 case MDP_Y_CBCR_H2V2_TP10_UBWC: return kFormatYCbCr420TP10Ubwc; 477 default: return kFormatInvalid; 478 } 479 } 480 481 void HWInfo::InitSupportedFormatMap(HWResourceInfo *hw_resource) { 482 hw_resource->supported_formats_map.clear(); 483 484 for (int sub_blk_type = INT(kHWVIGPipe); sub_blk_type < INT(kHWSubBlockMax); sub_blk_type++) { 485 PopulateSupportedFormatMap(kDefaultFormatSupport[sub_blk_type], MDP_IMGTYPE_LIMIT1, 486 (HWSubBlockType)sub_blk_type, hw_resource); 487 } 488 } 489 490 void HWInfo::ParseFormats(char *tokens[], uint32_t token_count, HWSubBlockType sub_blk_type, 491 HWResourceInfo *hw_resource) { 492 if (token_count > BITS_TO_BYTES(MDP_IMGTYPE_LIMIT1)) { 493 return; 494 } 495 496 std::unique_ptr<std::bitset<8>[]> format_supported(new std::bitset<8>[token_count]); 497 for (uint32_t i = 0; i < token_count; i++) { 498 format_supported[i] = UINT8(atoi(tokens[i])); 499 } 500 501 PopulateSupportedFormatMap(format_supported.get(), (token_count << 3), sub_blk_type, hw_resource); 502 } 503 504 void HWInfo::PopulateSupportedFormatMap(const std::bitset<8> *format_supported, 505 uint32_t format_count, HWSubBlockType sub_blk_type, 506 HWResourceInfo *hw_resource) { 507 vector <LayerBufferFormat> supported_sdm_formats; 508 for (uint32_t mdp_format = 0; mdp_format < format_count; mdp_format++) { 509 if (format_supported[mdp_format >> 3][mdp_format & 7]) { 510 LayerBufferFormat sdm_format = GetSDMFormat(INT(mdp_format)); 511 if (sdm_format != kFormatInvalid) { 512 supported_sdm_formats.push_back(sdm_format); 513 } 514 } 515 } 516 517 hw_resource->supported_formats_map.erase(sub_blk_type); 518 hw_resource->supported_formats_map.insert(make_pair(sub_blk_type, supported_sdm_formats)); 519 } 520 521 DisplayError HWInfo::GetFirstDisplayInterfaceType(HWDisplayInterfaceInfo *hw_disp_info) { 522 Sys::fstream fs("/sys/devices/virtual/graphics/fb0/msm_fb_type", fstream::in); 523 if (!fs.is_open()) { 524 return kErrorHardware; 525 } 526 527 string line; 528 if (!Sys::getline_(fs, line)) { 529 return kErrorHardware; 530 } 531 532 if (!strncmp(line.c_str(), "dtv panel", strlen("dtv panel")) || 533 !strncmp(line.c_str(), "dp panel", strlen("dp panel"))) { 534 hw_disp_info->type = kHDMI; 535 DLOGI("First display is HDMI"); 536 } else { 537 hw_disp_info->type = kPrimary; 538 DLOGI("First display is internal display"); 539 } 540 541 fs.close(); 542 fs.open("/sys/devices/virtual/graphics/fb0/connected", fstream::in); 543 if (!fs.is_open()) { 544 // If fb0 is for a DSI/connected panel, then connected node will not exist. 545 hw_disp_info->is_connected = true; 546 } else { 547 if (!Sys::getline_(fs, line)) { 548 return kErrorHardware; 549 } 550 551 hw_disp_info->is_connected = (!strncmp(line.c_str(), "1", strlen("1"))); 552 } 553 554 return kErrorNone; 555 } 556 557 } // namespace sdm 558 559