1 /* 2 * Copyright (c) 2011-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 #ifndef OVERLAY_H 31 #define OVERLAY_H 32 33 #include "overlayUtils.h" 34 #include "mdp_version.h" 35 #include "utils/threads.h" 36 #ifdef USES_POST_PROCESSING 37 #include "lib-postproc.h" 38 #endif 39 40 struct MetaData_t; 41 42 namespace overlay { 43 class GenericPipe; 44 45 class Overlay : utils::NoCopy { 46 public: 47 enum { DMA_BLOCK_MODE, DMA_LINE_MODE }; 48 //Abstract Display types. Each backed by a LayerMixer, 49 //represented by a fb node. 50 //High res panels can be backed by 2 layer mixers and a single fb node. 51 enum { DPY_PRIMARY, DPY_EXTERNAL, DPY_WRITEBACK, DPY_UNUSED }; 52 enum { DPY_MAX = DPY_UNUSED }; 53 enum { MIXER_LEFT, MIXER_RIGHT, MIXER_UNUSED }; 54 enum { MIXER_DEFAULT = MIXER_LEFT, MIXER_MAX = MIXER_UNUSED }; 55 enum { MAX_FB_DEVICES = DPY_MAX }; 56 enum { FORMAT_YUV, FORMAT_RGB , FORMAT_NONE }; 57 58 struct PipeSpecs { 59 PipeSpecs() : formatClass(FORMAT_RGB), needsScaling(false), fb(false), 60 dpy(DPY_PRIMARY), mixer(MIXER_DEFAULT), numActiveDisplays(1) {} 61 int formatClass; 62 bool needsScaling; 63 bool fb; 64 int dpy; 65 int mixer; 66 int numActiveDisplays; 67 }; 68 69 /* dtor close */ 70 ~Overlay(); 71 72 /* Marks the beginning of a drawing round, resets usage bits on pipes 73 * Should be called when drawing begins before any pipe config is done. 74 */ 75 void configBegin(); 76 77 /* Marks the end of config for this drawing round 78 * Will do garbage collection of pipe objects and thus calling UNSETs, 79 * closing FDs, removing rotator objects and memory, if allocated. 80 * Should be called after all pipe configs are done. 81 */ 82 void configDone(); 83 84 /* Get a pipe that supported the specified format class (yuv, rgb) and has 85 * scaling capabilities. 86 */ 87 utils::eDest getPipe(const PipeSpecs& pipeSpecs); 88 /* Returns the eDest corresponding to an already allocated pipeid. 89 * Useful for the reservation case, when libvpu reserves the pipe at its 90 * end, and expect the overlay to allocate a given pipe for a layer. 91 */ 92 utils::eDest reservePipe(int pipeid); 93 /* getting dest for the given pipeid */ 94 utils::eDest getDest(int pipeid); 95 /* getting overlay.pipeid for the given dest */ 96 int getPipeId(utils::eDest dest); 97 98 void setSource(const utils::PipeArgs args, utils::eDest dest); 99 void setCrop(const utils::Dim& d, utils::eDest dest); 100 void setColor(const uint32_t color, utils::eDest dest); 101 void setTransform(const int orientation, utils::eDest dest); 102 void setPosition(const utils::Dim& dim, utils::eDest dest); 103 void setVisualParams(const MetaData_t& data, utils::eDest dest); 104 bool commit(utils::eDest dest); 105 bool queueBuffer(int fd, uint32_t offset, utils::eDest dest); 106 107 /* pipe reservation session is running */ 108 bool sessionInProgress(utils::eDest dest); 109 /* pipe reservation session has ended*/ 110 bool isSessionEnded(utils::eDest dest); 111 /* start session for the pipe reservation */ 112 void startSession(utils::eDest dest); 113 /* end all started sesisons */ 114 void endAllSessions(); 115 /* Returns available ("unallocated") pipes for a display's mixer */ 116 int availablePipes(int dpy, int mixer); 117 /* Returns available ("unallocated") pipes for a display */ 118 int availablePipes(int dpy); 119 /* Returns available ("unallocated") pipe of given type for a display */ 120 int availablePipes(int dpy, utils::eMdpPipeType type); 121 /* Returns if any of the requested pipe type is attached to any of the 122 * displays 123 */ 124 bool isPipeTypeAttached(utils::eMdpPipeType type); 125 /* Compare pipe priorities and return 126 * 1 if 1st pipe has a higher priority 127 * 0 if both have the same priority 128 *-1 if 2nd pipe has a higher priority 129 */ 130 int comparePipePriority(utils::eDest pipe1Index, utils::eDest pipe2Index); 131 /* Returns pipe dump. Expects a NULL terminated buffer of big enough size 132 * to populate. 133 */ 134 /* Returns if DMA pipe multiplexing is supported by the mdss driver */ 135 static bool isDMAMultiplexingSupported(); 136 /* Returns if UI scaling on external is supported on the targets */ 137 static bool isUIScalingOnExternalSupported(); 138 void getDump(char *buf, size_t len); 139 /* Reset usage and allocation bits on all pipes for given display */ 140 void clear(int dpy); 141 /* Validate the set of pipes for a display and set them in driver */ 142 bool validateAndSet(const int& dpy, const int& fbFd); 143 144 /* Closes open pipes, called during startup */ 145 static int initOverlay(); 146 /* Returns the singleton instance of overlay */ 147 static Overlay* getInstance(); 148 static void setDMAMode(const int& mode); 149 static int getDMAMode(); 150 /* Returns the framebuffer node backing up the display */ 151 static int getFbForDpy(const int& dpy); 152 153 static bool displayCommit(const int& fd); 154 /* Overloads display commit with ROI's of each halves. 155 * Single interface panels will only update left ROI. */ 156 static bool displayCommit(const int& fd, const utils::Dim& lRoi, 157 const utils::Dim& rRoi); 158 /* Logs pipe lifecycle events like set, unset, commit when enabled */ 159 static void debugPipeLifecycle(const bool& enable); 160 /* Returns true if pipe life cycle logging is enabled */ 161 static bool isDebugPipeLifecycle(); 162 163 private: 164 /* Ctor setup */ 165 explicit Overlay(); 166 /*Validate index range, abort if invalid */ 167 void validate(int index); 168 static void setDMAMultiplexingSupported(); 169 /* Returns an available pipe based on the type of pipe requested. When ANY 170 * is requested, the first available VG or RGB is returned. If no pipe is 171 * available for the display "dpy" then INV is returned. Note: If a pipe is 172 * assigned to a certain display, then it cannot be assigned to another 173 * display without being garbage-collected once. To add if a pipe is 174 * asisgned to a mixer within a display it cannot be reused for another 175 * mixer without being UNSET once*/ 176 utils::eDest nextPipe(utils::eMdpPipeType, const PipeSpecs& pipeSpecs); 177 /* Helpers that enfore target specific policies while returning pipes */ 178 utils::eDest getPipe_8x26(const PipeSpecs& pipeSpecs); 179 utils::eDest getPipe_8x16(const PipeSpecs& pipeSpecs); 180 utils::eDest getPipe_8x39(const PipeSpecs& pipeSpecs); 181 utils::eDest getPipe_8994(const PipeSpecs& pipeSpecs); 182 183 /* Returns the handle to libscale.so's programScale function */ 184 static int (*getFnProgramScale())(struct mdp_overlay_list *); 185 /* Creates a scalar object using libscale.so */ 186 static void initScalar(); 187 /* Destroys the scalar object using libscale.so */ 188 static void destroyScalar(); 189 /* Sets the pipe type RGB/VG/DMA*/ 190 void setPipeType(utils::eDest pipeIndex, const utils::eMdpPipeType pType); 191 192 /* Dynamically link ABL library */ 193 static void initPostProc(); 194 static void destroyPostProc(); 195 static int (*getFnPpParams())(const struct compute_params *, 196 struct mdp_overlay_pp_params *); 197 198 /* Just like a Facebook for pipes, but much less profile info */ 199 struct PipeBook { 200 void init(); 201 void destroy(); 202 /* Check if pipe exists and return true, false otherwise */ 203 bool valid(); 204 205 /* Hardware pipe wrapper */ 206 GenericPipe *mPipe; 207 /* Display using this pipe. Refer to enums above */ 208 int mDisplay; 209 /* Mixer within a split display this pipe is attached to */ 210 int mMixer; 211 /* Format for which this pipe is attached to the mixer*/ 212 int mFormatType; 213 214 /* operations on bitmap */ 215 static bool pipeUsageUnchanged(); 216 static void setUse(int index); 217 static void resetUse(int index); 218 static bool isUsed(int index); 219 static bool isNotUsed(int index); 220 static void save(); 221 222 static void setAllocation(int index); 223 static void resetAllocation(int index); 224 static bool isAllocated(int index); 225 static bool isNotAllocated(int index); 226 227 static utils::eMdpPipeType getPipeType(utils::eDest dest); 228 static const char* getDestStr(utils::eDest dest); 229 230 static int NUM_PIPES; 231 static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX]; 232 /* Session for reserved pipes */ 233 enum Session { 234 NONE, 235 START, 236 END 237 }; 238 Session mSession; 239 240 private: 241 //usage tracks if a successful commit happened. So a pipe could be 242 //allocated to a display, but it may not end up using it for various 243 //reasons. If one display actually uses a pipe then it amy not be 244 //used by another display, without an UNSET in between. 245 static int sPipeUsageBitmap; 246 static int sLastUsageBitmap; 247 //Tracks which pipe objects are allocated. This does not imply that they 248 //will actually be used. For example, a display might choose to acquire 249 //3 pipe objects in one shot and proceed with config only if it gets all 250 //3. The bitmap helps allocate different pipe objects on each request. 251 static int sAllocatedBitmap; 252 }; 253 254 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max 255 256 /* Singleton Instance*/ 257 static Overlay *sInstance; 258 static int sDpyFbMap[DPY_MAX]; 259 static int sDMAMode; 260 static bool sDMAMultiplexingSupported; 261 static void *sLibScaleHandle; 262 static int (*sFnProgramScale)(struct mdp_overlay_list *); 263 /* Dynamically link ABL library */ 264 static void *sLibAblHandle; 265 static int (*sFnppParams)(const struct compute_params *, 266 struct mdp_overlay_pp_params *); 267 static bool sDebugPipeLifecycle; 268 269 friend class MdpCtrl; 270 }; 271 272 inline void Overlay::validate(int index) { 273 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \ 274 "%s, Index out of bounds: %d", __FUNCTION__, index); 275 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s", 276 PipeBook::getDestStr((utils::eDest)index)); 277 } 278 279 inline int Overlay::availablePipes(int dpy, int mixer) { 280 int avail = 0; 281 for(int i = 0; i < PipeBook::NUM_PIPES; i++) { 282 if( (mPipeBook[i].mDisplay == DPY_UNUSED || 283 mPipeBook[i].mDisplay == dpy) && 284 (mPipeBook[i].mMixer == MIXER_UNUSED || 285 mPipeBook[i].mMixer == mixer) && 286 PipeBook::isNotAllocated(i) && 287 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE && 288 PipeBook::getPipeType((utils::eDest)i) == 289 utils::OV_MDP_PIPE_DMA)) { 290 avail++; 291 } 292 } 293 return avail; 294 } 295 296 inline int Overlay::availablePipes(int dpy) { 297 int avail = 0; 298 for(int i = 0; i < PipeBook::NUM_PIPES; i++) { 299 if( (mPipeBook[i].mDisplay == DPY_UNUSED || 300 mPipeBook[i].mDisplay == dpy) && 301 PipeBook::isNotAllocated(i) && 302 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE && 303 PipeBook::getPipeType((utils::eDest)i) == 304 utils::OV_MDP_PIPE_DMA)) { 305 avail++; 306 } 307 } 308 return avail; 309 } 310 311 inline int Overlay::availablePipes(int dpy, utils::eMdpPipeType type) { 312 int avail = 0; 313 for(int i = 0; i < PipeBook::NUM_PIPES; i++) { 314 if((mPipeBook[i].mDisplay == DPY_UNUSED || 315 mPipeBook[i].mDisplay == dpy) && 316 PipeBook::isNotAllocated(i) && 317 type == PipeBook::getPipeType((utils::eDest)i)) { 318 avail++; 319 } 320 } 321 return avail; 322 } 323 324 inline void Overlay::setDMAMode(const int& mode) { 325 if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE) 326 sDMAMode = mode; 327 } 328 329 inline void Overlay::setDMAMultiplexingSupported() { 330 sDMAMultiplexingSupported = false; 331 if(qdutils::MDPVersion::getInstance().is8x26()) 332 sDMAMultiplexingSupported = true; 333 } 334 335 inline bool Overlay::isDMAMultiplexingSupported() { 336 return sDMAMultiplexingSupported; 337 } 338 339 inline bool Overlay::isUIScalingOnExternalSupported() { 340 if(qdutils::MDPVersion::getInstance().is8x26() or 341 qdutils::MDPVersion::getInstance().is8x16() or 342 qdutils::MDPVersion::getInstance().is8x39()) { 343 return false; 344 } 345 return true; 346 } 347 348 inline int Overlay::getDMAMode() { 349 return sDMAMode; 350 } 351 352 inline int Overlay::getFbForDpy(const int& dpy) { 353 OVASSERT(dpy >= 0 && dpy < DPY_MAX, "Invalid dpy %d", dpy); 354 return sDpyFbMap[dpy]; 355 } 356 357 inline int (*Overlay::getFnProgramScale())(struct mdp_overlay_list *) { 358 return sFnProgramScale; 359 } 360 361 inline int (*Overlay::getFnPpParams())(const struct compute_params *, 362 struct mdp_overlay_pp_params *) { 363 return sFnppParams; 364 } 365 366 inline void Overlay::debugPipeLifecycle(const bool& enable) { 367 sDebugPipeLifecycle = enable; 368 } 369 370 inline bool Overlay::isDebugPipeLifecycle() { 371 return sDebugPipeLifecycle; 372 } 373 374 inline bool Overlay::PipeBook::valid() { 375 return (mPipe != NULL); 376 } 377 378 inline bool Overlay::PipeBook::pipeUsageUnchanged() { 379 return (sPipeUsageBitmap == sLastUsageBitmap); 380 } 381 382 inline void Overlay::PipeBook::setUse(int index) { 383 sPipeUsageBitmap |= (1 << index); 384 } 385 386 inline void Overlay::PipeBook::resetUse(int index) { 387 sPipeUsageBitmap &= ~(1 << index); 388 } 389 390 inline bool Overlay::PipeBook::isUsed(int index) { 391 return sPipeUsageBitmap & (1 << index); 392 } 393 394 inline bool Overlay::PipeBook::isNotUsed(int index) { 395 return !isUsed(index); 396 } 397 398 inline void Overlay::PipeBook::save() { 399 sLastUsageBitmap = sPipeUsageBitmap; 400 } 401 402 inline void Overlay::PipeBook::setAllocation(int index) { 403 sAllocatedBitmap |= (1 << index); 404 } 405 406 inline void Overlay::PipeBook::resetAllocation(int index) { 407 sAllocatedBitmap &= ~(1 << index); 408 } 409 410 inline bool Overlay::PipeBook::isAllocated(int index) { 411 return sAllocatedBitmap & (1 << index); 412 } 413 414 inline bool Overlay::PipeBook::isNotAllocated(int index) { 415 return !isAllocated(index); 416 } 417 418 inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) { 419 return pipeTypeLUT[(int)dest]; 420 } 421 422 inline void Overlay::startSession(utils::eDest dest) { 423 mPipeBook[(int)dest].mSession = PipeBook::START; 424 } 425 426 inline bool Overlay::sessionInProgress(utils::eDest dest) { 427 return (mPipeBook[(int)dest].mSession == PipeBook::START); 428 } 429 430 inline bool Overlay::isSessionEnded(utils::eDest dest) { 431 return (mPipeBook[(int)dest].mSession == PipeBook::END); 432 } 433 434 inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) { 435 switch(getPipeType(dest)) { 436 case utils::OV_MDP_PIPE_RGB: return "RGB"; 437 case utils::OV_MDP_PIPE_VG: return "VG"; 438 case utils::OV_MDP_PIPE_DMA: return "DMA"; 439 default: return "Invalid"; 440 } 441 return "Invalid"; 442 } 443 444 }; // overlay 445 446 #endif // OVERLAY_H 447