blob: 4f5d56d4c064a1ad98fa68801937225278294e17 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Saurabh Shah5daeee52013-01-23 16:52:26 +08002* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07003*
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.
Naseer Ahmed758bfc52012-11-28 17:02:08 -050013* * Neither the name of The Linux Foundation. nor the names of its
Naseer Ahmed29a26812012-06-14 00:56:20 -070014* 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"
Raj Kamala8c065f2013-10-22 14:52:45 +053034#include "mdp_version.h"
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080035#include "utils/threads.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070036
Saurabh Shah5daeee52013-01-23 16:52:26 +080037struct MetaData_t;
38
Naseer Ahmed29a26812012-06-14 00:56:20 -070039namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050040class GenericPipe;
41
Naseer Ahmed29a26812012-06-14 00:56:20 -070042class Overlay : utils::NoCopy {
43public:
Saurabh Shah85234ec2013-04-12 17:09:00 -070044 enum { DMA_BLOCK_MODE, DMA_LINE_MODE };
Saurabh Shahc8118ac2013-06-27 10:03:19 -070045 //Abstract Display types. Each backed by a LayerMixer,
46 //represented by a fb node.
47 //High res panels can be backed by 2 layer mixers and a single fb node.
48 enum { DPY_PRIMARY, DPY_EXTERNAL, DPY_WRITEBACK, DPY_UNUSED };
49 enum { DPY_MAX = DPY_UNUSED };
Saurabh Shahaf5f5972013-07-30 13:56:35 -070050 enum { MIXER_LEFT, MIXER_RIGHT, MIXER_UNUSED };
51 enum { MIXER_DEFAULT = MIXER_LEFT, MIXER_MAX = MIXER_UNUSED };
Saurabh Shahc8118ac2013-06-27 10:03:19 -070052 enum { MAX_FB_DEVICES = DPY_MAX };
Saurabh Shahc62f3982014-03-05 14:28:26 -080053 enum { FORMAT_YUV, FORMAT_RGB };
54
55 struct PipeSpecs {
56 PipeSpecs() : formatClass(FORMAT_RGB), needsScaling(false), fb(false),
Xu Yang1e686f62014-04-08 13:56:47 +080057 dpy(DPY_PRIMARY), mixer(MIXER_DEFAULT), numActiveDisplays(1) {}
Saurabh Shahc62f3982014-03-05 14:28:26 -080058 int formatClass;
59 bool needsScaling;
60 bool fb;
61 int dpy;
62 int mixer;
Xu Yang1e686f62014-04-08 13:56:47 +080063 int numActiveDisplays;
Saurabh Shahc62f3982014-03-05 14:28:26 -080064 };
Saurabh Shah85234ec2013-04-12 17:09:00 -070065
Naseer Ahmed29a26812012-06-14 00:56:20 -070066 /* dtor close */
67 ~Overlay();
68
Naseer Ahmed758bfc52012-11-28 17:02:08 -050069 /* Marks the beginning of a drawing round, resets usage bits on pipes
70 * Should be called when drawing begins before any pipe config is done.
71 */
72 void configBegin();
Naseer Ahmed29a26812012-06-14 00:56:20 -070073
Naseer Ahmed758bfc52012-11-28 17:02:08 -050074 /* Marks the end of config for this drawing round
75 * Will do garbage collection of pipe objects and thus calling UNSETs,
76 * closing FDs, removing rotator objects and memory, if allocated.
77 * Should be called after all pipe configs are done.
78 */
79 void configDone();
Naseer Ahmed29a26812012-06-14 00:56:20 -070080
Saurabh Shahc62f3982014-03-05 14:28:26 -080081 /* Get a pipe that supported the specified format class (yuv, rgb) and has
82 * scaling capabilities.
83 */
84 utils::eDest getPipe(const PipeSpecs& pipeSpecs);
Zohaib Alam4b0a9242013-11-20 23:54:12 -050085 /* Returns the eDest corresponding to an already allocated pipeid.
86 * Useful for the reservation case, when libvpu reserves the pipe at its
87 * end, and expect the overlay to allocate a given pipe for a layer.
88 */
89 utils::eDest reservePipe(int pipeid);
90 /* getting dest for the given pipeid */
91 utils::eDest getDest(int pipeid);
92 /* getting overlay.pipeid for the given dest */
93 int getPipeId(utils::eDest dest);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070094
Naseer Ahmed758bfc52012-11-28 17:02:08 -050095 void setSource(const utils::PipeArgs args, utils::eDest dest);
96 void setCrop(const utils::Dim& d, utils::eDest dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -070097 void setColor(const uint32_t color, utils::eDest dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050098 void setTransform(const int orientation, utils::eDest dest);
99 void setPosition(const utils::Dim& dim, utils::eDest dest);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800100 void setVisualParams(const MetaData_t& data, utils::eDest dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500101 bool commit(utils::eDest dest);
102 bool queueBuffer(int fd, uint32_t offset, utils::eDest dest);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700103
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500104 /* pipe reservation session is running */
105 bool sessionInProgress(utils::eDest dest);
106 /* pipe reservation session has ended*/
107 bool isSessionEnded(utils::eDest dest);
108 /* start session for the pipe reservation */
109 void startSession(utils::eDest dest);
110 /* end all started sesisons */
111 void endAllSessions();
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700112 /* Returns available ("unallocated") pipes for a display's mixer */
113 int availablePipes(int dpy, int mixer);
Saurabh Shah082468e2013-09-12 10:05:32 -0700114 /* Returns available ("unallocated") pipes for a display */
115 int availablePipes(int dpy);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700116 /* Returns available ("unallocated") pipe of given type for a display */
117 int availablePipes(int dpy, utils::eMdpPipeType type);
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700118 /* Returns if any of the requested pipe type is attached to any of the
119 * displays
120 */
121 bool isPipeTypeAttached(utils::eMdpPipeType type);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800122 /* Compare pipe priorities and return
123 * 1 if 1st pipe has a higher priority
124 * 0 if both have the same priority
125 *-1 if 2nd pipe has a higher priority
126 */
127 int comparePipePriority(utils::eDest pipe1Index, utils::eDest pipe2Index);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800128 /* Returns pipe dump. Expects a NULL terminated buffer of big enough size
129 * to populate.
130 */
Raj Kamal068f4572014-04-14 16:14:06 +0530131 /* Returns if DMA pipe multiplexing is supported by the mdss driver */
132 static bool isDMAMultiplexingSupported();
133 /* Returns if UI scaling on external is supported on the targets */
134 static bool isUIScalingOnExternalSupported();
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800135 void getDump(char *buf, size_t len);
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700136 /* Reset usage and allocation bits on all pipes for given display */
137 void clear(int dpy);
Saurabh Shaha36be922013-12-16 18:18:39 -0800138 /* Validate the set of pipes for a display and set them in driver */
139 bool validateAndSet(const int& dpy, const int& fbFd);
Saurabh Shah784e9852013-08-21 16:51:21 -0700140
141 /* Closes open pipes, called during startup */
142 static int initOverlay();
143 /* Returns the singleton instance of overlay */
144 static Overlay* getInstance();
Saurabh Shah85234ec2013-04-12 17:09:00 -0700145 static void setDMAMode(const int& mode);
146 static int getDMAMode();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700147 /* Returns the framebuffer node backing up the display */
148 static int getFbForDpy(const int& dpy);
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800149
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700150 static bool displayCommit(const int& fd);
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800151 /* Overloads display commit with ROI's of each halves.
152 * Single interface panels will only update left ROI. */
153 static bool displayCommit(const int& fd, const utils::Dim& lRoi,
154 const utils::Dim& rRoi);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700155
156private:
157 /* Ctor setup */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500158 explicit Overlay();
159 /*Validate index range, abort if invalid */
160 void validate(int index);
Raj Kamala8c065f2013-10-22 14:52:45 +0530161 static void setDMAMultiplexingSupported();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500162 void dump() const;
Saurabh Shahc62f3982014-03-05 14:28:26 -0800163 /* Returns an available pipe based on the type of pipe requested. When ANY
164 * is requested, the first available VG or RGB is returned. If no pipe is
165 * available for the display "dpy" then INV is returned. Note: If a pipe is
166 * assigned to a certain display, then it cannot be assigned to another
167 * display without being garbage-collected once. To add if a pipe is
168 * asisgned to a mixer within a display it cannot be reused for another
169 * mixer without being UNSET once*/
170 utils::eDest nextPipe(utils::eMdpPipeType, int dpy, int mixer);
171 /* Helpers that enfore target specific policies while returning pipes */
172 utils::eDest getPipe_8x26(const PipeSpecs& pipeSpecs);
173 utils::eDest getPipe_8x16(const PipeSpecs& pipeSpecs);
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530174 utils::eDest getPipe_8x39(const PipeSpecs& pipeSpecs);
Saurabh Shah59788572014-07-29 10:07:57 -0700175 utils::eDest getPipe_8994(const PipeSpecs& pipeSpecs);
Saurabh Shahc62f3982014-03-05 14:28:26 -0800176
Saurabh Shaheac146b2014-05-13 11:36:20 -0700177 /* Returns the handle to libscale.so's programScale function */
178 static int (*getFnProgramScale())(struct mdp_overlay_list *);
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700179 /* Creates a scalar object using libscale.so */
180 static void initScalar();
181 /* Destroys the scalar object using libscale.so */
182 static void destroyScalar();
radhakrishna8ccb9082014-05-09 16:18:43 +0530183 /* Sets the pipe type RGB/VG/DMA*/
184 void setPipeType(utils::eDest pipeIndex, const utils::eMdpPipeType pType);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700185
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500186 /* Just like a Facebook for pipes, but much less profile info */
187 struct PipeBook {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500188 void init();
189 void destroy();
190 /* Check if pipe exists and return true, false otherwise */
191 bool valid();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700192
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500193 /* Hardware pipe wrapper */
194 GenericPipe *mPipe;
195 /* Display using this pipe. Refer to enums above */
196 int mDisplay;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700197 /* Mixer within a split display this pipe is attached to */
198 int mMixer;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700199
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500200 /* operations on bitmap */
201 static bool pipeUsageUnchanged();
202 static void setUse(int index);
203 static void resetUse(int index);
204 static bool isUsed(int index);
205 static bool isNotUsed(int index);
206 static void save();
207
208 static void setAllocation(int index);
209 static void resetAllocation(int index);
210 static bool isAllocated(int index);
211 static bool isNotAllocated(int index);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500212
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800213 static utils::eMdpPipeType getPipeType(utils::eDest dest);
214 static const char* getDestStr(utils::eDest dest);
215
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500216 static int NUM_PIPES;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800217 static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX];
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500218 /* Session for reserved pipes */
219 enum Session {
220 NONE,
221 START,
222 END
223 };
224 Session mSession;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500225
226 private:
227 //usage tracks if a successful commit happened. So a pipe could be
228 //allocated to a display, but it may not end up using it for various
229 //reasons. If one display actually uses a pipe then it amy not be
230 //used by another display, without an UNSET in between.
231 static int sPipeUsageBitmap;
232 static int sLastUsageBitmap;
233 //Tracks which pipe objects are allocated. This does not imply that they
234 //will actually be used. For example, a display might choose to acquire
235 //3 pipe objects in one shot and proceed with config only if it gets all
236 //3. The bitmap helps allocate different pipe objects on each request.
237 static int sAllocatedBitmap;
238 };
239
240 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max
241
242 /* Dump string */
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700243 char mDumpStr[1024];
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500244
245 /* Singleton Instance*/
246 static Overlay *sInstance;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700247 static int sDpyFbMap[DPY_MAX];
Saurabh Shah85234ec2013-04-12 17:09:00 -0700248 static int sDMAMode;
Raj Kamala8c065f2013-10-22 14:52:45 +0530249 static bool sDMAMultiplexingSupported;
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700250 static void *sLibScaleHandle;
Saurabh Shaheac146b2014-05-13 11:36:20 -0700251 static int (*sFnProgramScale)(struct mdp_overlay_list *);
Saurabh Shaha36be922013-12-16 18:18:39 -0800252
253 friend class MdpCtrl;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700254};
255
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500256inline void Overlay::validate(int index) {
257 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \
258 "%s, Index out of bounds: %d", __FUNCTION__, index);
259 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s",
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800260 PipeBook::getDestStr((utils::eDest)index));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500261}
262
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700263inline int Overlay::availablePipes(int dpy, int mixer) {
264 int avail = 0;
265 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
266 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
267 mPipeBook[i].mDisplay == dpy) &&
268 (mPipeBook[i].mMixer == MIXER_UNUSED ||
269 mPipeBook[i].mMixer == mixer) &&
270 PipeBook::isNotAllocated(i) &&
271 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
272 PipeBook::getPipeType((utils::eDest)i) ==
273 utils::OV_MDP_PIPE_DMA)) {
274 avail++;
Jeykumar Sankaranccb44602013-01-03 12:48:22 -0800275 }
276 }
277 return avail;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500278}
279
Saurabh Shah082468e2013-09-12 10:05:32 -0700280inline int Overlay::availablePipes(int dpy) {
281 int avail = 0;
282 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
283 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
284 mPipeBook[i].mDisplay == dpy) &&
285 PipeBook::isNotAllocated(i) &&
286 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
287 PipeBook::getPipeType((utils::eDest)i) ==
288 utils::OV_MDP_PIPE_DMA)) {
289 avail++;
290 }
291 }
292 return avail;
293}
294
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700295inline int Overlay::availablePipes(int dpy, utils::eMdpPipeType type) {
296 int avail = 0;
297 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
298 if((mPipeBook[i].mDisplay == DPY_UNUSED ||
299 mPipeBook[i].mDisplay == dpy) &&
300 PipeBook::isNotAllocated(i) &&
301 type == PipeBook::getPipeType((utils::eDest)i)) {
302 avail++;
303 }
304 }
305 return avail;
306}
307
Saurabh Shah85234ec2013-04-12 17:09:00 -0700308inline void Overlay::setDMAMode(const int& mode) {
309 if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE)
310 sDMAMode = mode;
311}
312
Raj Kamala8c065f2013-10-22 14:52:45 +0530313inline void Overlay::setDMAMultiplexingSupported() {
314 sDMAMultiplexingSupported = false;
315 if(qdutils::MDPVersion::getInstance().is8x26())
316 sDMAMultiplexingSupported = true;
317}
318
Raj Kamal068f4572014-04-14 16:14:06 +0530319inline bool Overlay::isDMAMultiplexingSupported() {
320 return sDMAMultiplexingSupported;
321}
322
323inline bool Overlay::isUIScalingOnExternalSupported() {
324 if(qdutils::MDPVersion::getInstance().is8x26() or
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530325 qdutils::MDPVersion::getInstance().is8x16() or
326 qdutils::MDPVersion::getInstance().is8x39()) {
Raj Kamal068f4572014-04-14 16:14:06 +0530327 return false;
328 }
329 return true;
330}
331
Saurabh Shah85234ec2013-04-12 17:09:00 -0700332inline int Overlay::getDMAMode() {
333 return sDMAMode;
334}
335
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700336inline int Overlay::getFbForDpy(const int& dpy) {
337 OVASSERT(dpy >= 0 && dpy < DPY_MAX, "Invalid dpy %d", dpy);
338 return sDpyFbMap[dpy];
339}
340
Saurabh Shaheac146b2014-05-13 11:36:20 -0700341inline int (*Overlay::getFnProgramScale())(struct mdp_overlay_list *) {
342 return sFnProgramScale;
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700343}
344
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500345inline bool Overlay::PipeBook::valid() {
346 return (mPipe != NULL);
347}
348
349inline bool Overlay::PipeBook::pipeUsageUnchanged() {
350 return (sPipeUsageBitmap == sLastUsageBitmap);
351}
352
353inline void Overlay::PipeBook::setUse(int index) {
354 sPipeUsageBitmap |= (1 << index);
355}
356
357inline void Overlay::PipeBook::resetUse(int index) {
358 sPipeUsageBitmap &= ~(1 << index);
359}
360
361inline bool Overlay::PipeBook::isUsed(int index) {
362 return sPipeUsageBitmap & (1 << index);
363}
364
365inline bool Overlay::PipeBook::isNotUsed(int index) {
366 return !isUsed(index);
367}
368
369inline void Overlay::PipeBook::save() {
370 sLastUsageBitmap = sPipeUsageBitmap;
371}
372
373inline void Overlay::PipeBook::setAllocation(int index) {
374 sAllocatedBitmap |= (1 << index);
375}
376
377inline void Overlay::PipeBook::resetAllocation(int index) {
378 sAllocatedBitmap &= ~(1 << index);
379}
380
381inline bool Overlay::PipeBook::isAllocated(int index) {
382 return sAllocatedBitmap & (1 << index);
383}
384
385inline bool Overlay::PipeBook::isNotAllocated(int index) {
386 return !isAllocated(index);
387}
388
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800389inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) {
390 return pipeTypeLUT[(int)dest];
391}
392
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500393inline void Overlay::startSession(utils::eDest dest) {
394 mPipeBook[(int)dest].mSession = PipeBook::START;
395}
396
397inline bool Overlay::sessionInProgress(utils::eDest dest) {
398 return (mPipeBook[(int)dest].mSession == PipeBook::START);
399}
400
401inline bool Overlay::isSessionEnded(utils::eDest dest) {
402 return (mPipeBook[(int)dest].mSession == PipeBook::END);
403}
404
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800405inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) {
406 switch(getPipeType(dest)) {
407 case utils::OV_MDP_PIPE_RGB: return "RGB";
408 case utils::OV_MDP_PIPE_VG: return "VG";
409 case utils::OV_MDP_PIPE_DMA: return "DMA";
410 default: return "Invalid";
411 }
412 return "Invalid";
413}
414
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500415}; // overlay
Naseer Ahmed29a26812012-06-14 00:56:20 -0700416
417#endif // OVERLAY_H