blob: 44193be6aa75d6ddd64afb4fba2b4227a59830fa [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;
Saurabh Shahb8f58e22013-09-26 16:20:07 -070038namespace scale {
39class Scale;
40};
Saurabh Shah5daeee52013-01-23 16:52:26 +080041
Naseer Ahmed29a26812012-06-14 00:56:20 -070042namespace overlay {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050043class GenericPipe;
44
Naseer Ahmed29a26812012-06-14 00:56:20 -070045class Overlay : utils::NoCopy {
46public:
Saurabh Shah85234ec2013-04-12 17:09:00 -070047 enum { DMA_BLOCK_MODE, DMA_LINE_MODE };
Saurabh Shahc8118ac2013-06-27 10:03:19 -070048 //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 };
Saurabh Shahaf5f5972013-07-30 13:56:35 -070053 enum { MIXER_LEFT, MIXER_RIGHT, MIXER_UNUSED };
54 enum { MIXER_DEFAULT = MIXER_LEFT, MIXER_MAX = MIXER_UNUSED };
Saurabh Shahc8118ac2013-06-27 10:03:19 -070055 enum { MAX_FB_DEVICES = DPY_MAX };
Saurabh Shah85234ec2013-04-12 17:09:00 -070056
Naseer Ahmed29a26812012-06-14 00:56:20 -070057 /* dtor close */
58 ~Overlay();
59
Naseer Ahmed758bfc52012-11-28 17:02:08 -050060 /* Marks the beginning of a drawing round, resets usage bits on pipes
61 * Should be called when drawing begins before any pipe config is done.
62 */
63 void configBegin();
Naseer Ahmed29a26812012-06-14 00:56:20 -070064
Naseer Ahmed758bfc52012-11-28 17:02:08 -050065 /* Marks the end of config for this drawing round
66 * Will do garbage collection of pipe objects and thus calling UNSETs,
67 * closing FDs, removing rotator objects and memory, if allocated.
68 * Should be called after all pipe configs are done.
69 */
70 void configDone();
Naseer Ahmed29a26812012-06-14 00:56:20 -070071
Naseer Ahmed758bfc52012-11-28 17:02:08 -050072 /* Returns an available pipe based on the type of pipe requested. When ANY
73 * is requested, the first available VG or RGB is returned. If no pipe is
74 * available for the display "dpy" then INV is returned. Note: If a pipe is
75 * assigned to a certain display, then it cannot be assigned to another
Saurabh Shahaf5f5972013-07-30 13:56:35 -070076 * display without being garbage-collected once. To add if a pipe is
77 * asisgned to a mixer within a display it cannot be reused for another
78 * mixer without being UNSET once*/
79 utils::eDest nextPipe(utils::eMdpPipeType, int dpy, int mixer);
Zohaib Alam4b0a9242013-11-20 23:54:12 -050080 /* Returns the eDest corresponding to an already allocated pipeid.
81 * Useful for the reservation case, when libvpu reserves the pipe at its
82 * end, and expect the overlay to allocate a given pipe for a layer.
83 */
84 utils::eDest reservePipe(int pipeid);
85 /* getting dest for the given pipeid */
86 utils::eDest getDest(int pipeid);
87 /* getting overlay.pipeid for the given dest */
88 int getPipeId(utils::eDest dest);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070089
Naseer Ahmed758bfc52012-11-28 17:02:08 -050090 void setSource(const utils::PipeArgs args, utils::eDest dest);
91 void setCrop(const utils::Dim& d, utils::eDest dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -070092 void setColor(const uint32_t color, utils::eDest dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050093 void setTransform(const int orientation, utils::eDest dest);
94 void setPosition(const utils::Dim& dim, utils::eDest dest);
Saurabh Shah5daeee52013-01-23 16:52:26 +080095 void setVisualParams(const MetaData_t& data, utils::eDest dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050096 bool commit(utils::eDest dest);
97 bool queueBuffer(int fd, uint32_t offset, utils::eDest dest);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070098
Zohaib Alam4b0a9242013-11-20 23:54:12 -050099 /* pipe reservation session is running */
100 bool sessionInProgress(utils::eDest dest);
101 /* pipe reservation session has ended*/
102 bool isSessionEnded(utils::eDest dest);
103 /* start session for the pipe reservation */
104 void startSession(utils::eDest dest);
105 /* end all started sesisons */
106 void endAllSessions();
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700107 /* Returns available ("unallocated") pipes for a display's mixer */
108 int availablePipes(int dpy, int mixer);
Saurabh Shah082468e2013-09-12 10:05:32 -0700109 /* Returns available ("unallocated") pipes for a display */
110 int availablePipes(int dpy);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700111 /* Returns available ("unallocated") pipe of given type for a display */
112 int availablePipes(int dpy, utils::eMdpPipeType type);
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700113 /* Returns if any of the requested pipe type is attached to any of the
114 * displays
115 */
116 bool isPipeTypeAttached(utils::eMdpPipeType type);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800117 /* Compare pipe priorities and return
118 * 1 if 1st pipe has a higher priority
119 * 0 if both have the same priority
120 *-1 if 2nd pipe has a higher priority
121 */
122 int comparePipePriority(utils::eDest pipe1Index, utils::eDest pipe2Index);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800123 /* Returns pipe dump. Expects a NULL terminated buffer of big enough size
124 * to populate.
125 */
126 void getDump(char *buf, size_t len);
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700127 /* Reset usage and allocation bits on all pipes for given display */
128 void clear(int dpy);
Saurabh Shaha36be922013-12-16 18:18:39 -0800129 /* Validate the set of pipes for a display and set them in driver */
130 bool validateAndSet(const int& dpy, const int& fbFd);
Saurabh Shah784e9852013-08-21 16:51:21 -0700131
132 /* Closes open pipes, called during startup */
133 static int initOverlay();
134 /* Returns the singleton instance of overlay */
135 static Overlay* getInstance();
Saurabh Shah85234ec2013-04-12 17:09:00 -0700136 static void setDMAMode(const int& mode);
137 static int getDMAMode();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700138 /* Returns the framebuffer node backing up the display */
139 static int getFbForDpy(const int& dpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700140 static bool displayCommit(const int& fd, const utils::Dim& roi);
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700141 static bool displayCommit(const int& fd);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700142
143private:
144 /* Ctor setup */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500145 explicit Overlay();
146 /*Validate index range, abort if invalid */
147 void validate(int index);
Raj Kamala8c065f2013-10-22 14:52:45 +0530148 static void setDMAMultiplexingSupported();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500149 void dump() const;
Saurabh Shaha36be922013-12-16 18:18:39 -0800150 /* Returns the scalar object */
151 static scale::Scale *getScalar();
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700152 /* Creates a scalar object using libscale.so */
153 static void initScalar();
154 /* Destroys the scalar object using libscale.so */
155 static void destroyScalar();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700156
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500157 /* Just like a Facebook for pipes, but much less profile info */
158 struct PipeBook {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500159 void init();
160 void destroy();
161 /* Check if pipe exists and return true, false otherwise */
162 bool valid();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700163
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500164 /* Hardware pipe wrapper */
165 GenericPipe *mPipe;
166 /* Display using this pipe. Refer to enums above */
167 int mDisplay;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700168 /* Mixer within a split display this pipe is attached to */
169 int mMixer;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700170
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500171 /* operations on bitmap */
172 static bool pipeUsageUnchanged();
173 static void setUse(int index);
174 static void resetUse(int index);
175 static bool isUsed(int index);
176 static bool isNotUsed(int index);
177 static void save();
178
179 static void setAllocation(int index);
180 static void resetAllocation(int index);
181 static bool isAllocated(int index);
182 static bool isNotAllocated(int index);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500183
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800184 static utils::eMdpPipeType getPipeType(utils::eDest dest);
185 static const char* getDestStr(utils::eDest dest);
186
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500187 static int NUM_PIPES;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800188 static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX];
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500189 /* Session for reserved pipes */
190 enum Session {
191 NONE,
192 START,
193 END
194 };
195 Session mSession;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500196
197 private:
198 //usage tracks if a successful commit happened. So a pipe could be
199 //allocated to a display, but it may not end up using it for various
200 //reasons. If one display actually uses a pipe then it amy not be
201 //used by another display, without an UNSET in between.
202 static int sPipeUsageBitmap;
203 static int sLastUsageBitmap;
204 //Tracks which pipe objects are allocated. This does not imply that they
205 //will actually be used. For example, a display might choose to acquire
206 //3 pipe objects in one shot and proceed with config only if it gets all
207 //3. The bitmap helps allocate different pipe objects on each request.
208 static int sAllocatedBitmap;
209 };
210
211 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max
212
213 /* Dump string */
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700214 char mDumpStr[1024];
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500215
216 /* Singleton Instance*/
217 static Overlay *sInstance;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700218 static int sDpyFbMap[DPY_MAX];
Saurabh Shah85234ec2013-04-12 17:09:00 -0700219 static int sDMAMode;
Raj Kamala8c065f2013-10-22 14:52:45 +0530220 static bool sDMAMultiplexingSupported;
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700221 static void *sLibScaleHandle;
222 static scale::Scale *sScale;
Saurabh Shaha36be922013-12-16 18:18:39 -0800223
224 friend class MdpCtrl;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700225};
226
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500227inline void Overlay::validate(int index) {
228 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \
229 "%s, Index out of bounds: %d", __FUNCTION__, index);
230 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s",
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800231 PipeBook::getDestStr((utils::eDest)index));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500232}
233
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700234inline int Overlay::availablePipes(int dpy, int mixer) {
235 int avail = 0;
236 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
237 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
238 mPipeBook[i].mDisplay == dpy) &&
239 (mPipeBook[i].mMixer == MIXER_UNUSED ||
240 mPipeBook[i].mMixer == mixer) &&
241 PipeBook::isNotAllocated(i) &&
242 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
243 PipeBook::getPipeType((utils::eDest)i) ==
244 utils::OV_MDP_PIPE_DMA)) {
245 avail++;
Jeykumar Sankaranccb44602013-01-03 12:48:22 -0800246 }
247 }
248 return avail;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500249}
250
Saurabh Shah082468e2013-09-12 10:05:32 -0700251inline int Overlay::availablePipes(int dpy) {
252 int avail = 0;
253 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
254 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
255 mPipeBook[i].mDisplay == dpy) &&
256 PipeBook::isNotAllocated(i) &&
257 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
258 PipeBook::getPipeType((utils::eDest)i) ==
259 utils::OV_MDP_PIPE_DMA)) {
260 avail++;
261 }
262 }
263 return avail;
264}
265
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700266inline int Overlay::availablePipes(int dpy, utils::eMdpPipeType type) {
267 int avail = 0;
268 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
269 if((mPipeBook[i].mDisplay == DPY_UNUSED ||
270 mPipeBook[i].mDisplay == dpy) &&
271 PipeBook::isNotAllocated(i) &&
272 type == PipeBook::getPipeType((utils::eDest)i)) {
273 avail++;
274 }
275 }
276 return avail;
277}
278
Saurabh Shah85234ec2013-04-12 17:09:00 -0700279inline void Overlay::setDMAMode(const int& mode) {
280 if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE)
281 sDMAMode = mode;
282}
283
Raj Kamala8c065f2013-10-22 14:52:45 +0530284inline void Overlay::setDMAMultiplexingSupported() {
285 sDMAMultiplexingSupported = false;
286 if(qdutils::MDPVersion::getInstance().is8x26())
287 sDMAMultiplexingSupported = true;
288}
289
Saurabh Shah85234ec2013-04-12 17:09:00 -0700290inline int Overlay::getDMAMode() {
291 return sDMAMode;
292}
293
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700294inline int Overlay::getFbForDpy(const int& dpy) {
295 OVASSERT(dpy >= 0 && dpy < DPY_MAX, "Invalid dpy %d", dpy);
296 return sDpyFbMap[dpy];
297}
298
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700299inline scale::Scale *Overlay::getScalar() {
300 return sScale;
301}
302
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500303inline bool Overlay::PipeBook::valid() {
304 return (mPipe != NULL);
305}
306
307inline bool Overlay::PipeBook::pipeUsageUnchanged() {
308 return (sPipeUsageBitmap == sLastUsageBitmap);
309}
310
311inline void Overlay::PipeBook::setUse(int index) {
312 sPipeUsageBitmap |= (1 << index);
313}
314
315inline void Overlay::PipeBook::resetUse(int index) {
316 sPipeUsageBitmap &= ~(1 << index);
317}
318
319inline bool Overlay::PipeBook::isUsed(int index) {
320 return sPipeUsageBitmap & (1 << index);
321}
322
323inline bool Overlay::PipeBook::isNotUsed(int index) {
324 return !isUsed(index);
325}
326
327inline void Overlay::PipeBook::save() {
328 sLastUsageBitmap = sPipeUsageBitmap;
329}
330
331inline void Overlay::PipeBook::setAllocation(int index) {
332 sAllocatedBitmap |= (1 << index);
333}
334
335inline void Overlay::PipeBook::resetAllocation(int index) {
336 sAllocatedBitmap &= ~(1 << index);
337}
338
339inline bool Overlay::PipeBook::isAllocated(int index) {
340 return sAllocatedBitmap & (1 << index);
341}
342
343inline bool Overlay::PipeBook::isNotAllocated(int index) {
344 return !isAllocated(index);
345}
346
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800347inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) {
348 return pipeTypeLUT[(int)dest];
349}
350
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500351inline void Overlay::startSession(utils::eDest dest) {
352 mPipeBook[(int)dest].mSession = PipeBook::START;
353}
354
355inline bool Overlay::sessionInProgress(utils::eDest dest) {
356 return (mPipeBook[(int)dest].mSession == PipeBook::START);
357}
358
359inline bool Overlay::isSessionEnded(utils::eDest dest) {
360 return (mPipeBook[(int)dest].mSession == PipeBook::END);
361}
362
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800363inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) {
364 switch(getPipeType(dest)) {
365 case utils::OV_MDP_PIPE_RGB: return "RGB";
366 case utils::OV_MDP_PIPE_VG: return "VG";
367 case utils::OV_MDP_PIPE_DMA: return "DMA";
368 default: return "Invalid";
369 }
370 return "Invalid";
371}
372
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500373}; // overlay
Naseer Ahmed29a26812012-06-14 00:56:20 -0700374
375#endif // OVERLAY_H