blob: 0b785d5dffe19b852b6bfcaa2737f7537537c638 [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 Shahc62f3982014-03-05 14:28:26 -080056 enum { FORMAT_YUV, FORMAT_RGB };
57
58 struct PipeSpecs {
59 PipeSpecs() : formatClass(FORMAT_RGB), needsScaling(false), fb(false),
60 dpy(DPY_PRIMARY), mixer(MIXER_DEFAULT) {}
61 int formatClass;
62 bool needsScaling;
63 bool fb;
64 int dpy;
65 int mixer;
66 };
Saurabh Shah85234ec2013-04-12 17:09:00 -070067
Naseer Ahmed29a26812012-06-14 00:56:20 -070068 /* dtor close */
69 ~Overlay();
70
Naseer Ahmed758bfc52012-11-28 17:02:08 -050071 /* Marks the beginning of a drawing round, resets usage bits on pipes
72 * Should be called when drawing begins before any pipe config is done.
73 */
74 void configBegin();
Naseer Ahmed29a26812012-06-14 00:56:20 -070075
Naseer Ahmed758bfc52012-11-28 17:02:08 -050076 /* Marks the end of config for this drawing round
77 * Will do garbage collection of pipe objects and thus calling UNSETs,
78 * closing FDs, removing rotator objects and memory, if allocated.
79 * Should be called after all pipe configs are done.
80 */
81 void configDone();
Naseer Ahmed29a26812012-06-14 00:56:20 -070082
Saurabh Shahc62f3982014-03-05 14:28:26 -080083 /* Get a pipe that supported the specified format class (yuv, rgb) and has
84 * scaling capabilities.
85 */
86 utils::eDest getPipe(const PipeSpecs& pipeSpecs);
Zohaib Alam4b0a9242013-11-20 23:54:12 -050087 /* Returns the eDest corresponding to an already allocated pipeid.
88 * Useful for the reservation case, when libvpu reserves the pipe at its
89 * end, and expect the overlay to allocate a given pipe for a layer.
90 */
91 utils::eDest reservePipe(int pipeid);
92 /* getting dest for the given pipeid */
93 utils::eDest getDest(int pipeid);
94 /* getting overlay.pipeid for the given dest */
95 int getPipeId(utils::eDest dest);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070096
Naseer Ahmed758bfc52012-11-28 17:02:08 -050097 void setSource(const utils::PipeArgs args, utils::eDest dest);
98 void setCrop(const utils::Dim& d, utils::eDest dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -070099 void setColor(const uint32_t color, utils::eDest dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500100 void setTransform(const int orientation, utils::eDest dest);
101 void setPosition(const utils::Dim& dim, utils::eDest dest);
Saurabh Shah5daeee52013-01-23 16:52:26 +0800102 void setVisualParams(const MetaData_t& data, utils::eDest dest);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500103 bool commit(utils::eDest dest);
104 bool queueBuffer(int fd, uint32_t offset, utils::eDest dest);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500106 /* pipe reservation session is running */
107 bool sessionInProgress(utils::eDest dest);
108 /* pipe reservation session has ended*/
109 bool isSessionEnded(utils::eDest dest);
110 /* start session for the pipe reservation */
111 void startSession(utils::eDest dest);
112 /* end all started sesisons */
113 void endAllSessions();
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700114 /* Returns available ("unallocated") pipes for a display's mixer */
115 int availablePipes(int dpy, int mixer);
Saurabh Shah082468e2013-09-12 10:05:32 -0700116 /* Returns available ("unallocated") pipes for a display */
117 int availablePipes(int dpy);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700118 /* Returns available ("unallocated") pipe of given type for a display */
119 int availablePipes(int dpy, utils::eMdpPipeType type);
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700120 /* Returns if any of the requested pipe type is attached to any of the
121 * displays
122 */
123 bool isPipeTypeAttached(utils::eMdpPipeType type);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800124 /* Compare pipe priorities and return
125 * 1 if 1st pipe has a higher priority
126 * 0 if both have the same priority
127 *-1 if 2nd pipe has a higher priority
128 */
129 int comparePipePriority(utils::eDest pipe1Index, utils::eDest pipe2Index);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800130 /* Returns pipe dump. Expects a NULL terminated buffer of big enough size
131 * to populate.
132 */
Raj Kamal068f4572014-04-14 16:14:06 +0530133 /* Returns if DMA pipe multiplexing is supported by the mdss driver */
134 static bool isDMAMultiplexingSupported();
135 /* Returns if UI scaling on external is supported on the targets */
136 static bool isUIScalingOnExternalSupported();
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800137 void getDump(char *buf, size_t len);
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700138 /* Reset usage and allocation bits on all pipes for given display */
139 void clear(int dpy);
Saurabh Shaha36be922013-12-16 18:18:39 -0800140 /* Validate the set of pipes for a display and set them in driver */
141 bool validateAndSet(const int& dpy, const int& fbFd);
Saurabh Shah784e9852013-08-21 16:51:21 -0700142
143 /* Closes open pipes, called during startup */
144 static int initOverlay();
145 /* Returns the singleton instance of overlay */
146 static Overlay* getInstance();
Saurabh Shah85234ec2013-04-12 17:09:00 -0700147 static void setDMAMode(const int& mode);
148 static int getDMAMode();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700149 /* Returns the framebuffer node backing up the display */
150 static int getFbForDpy(const int& dpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700151 static bool displayCommit(const int& fd, const utils::Dim& roi);
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700152 static bool displayCommit(const int& fd);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700153
154private:
155 /* Ctor setup */
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500156 explicit Overlay();
157 /*Validate index range, abort if invalid */
158 void validate(int index);
Raj Kamala8c065f2013-10-22 14:52:45 +0530159 static void setDMAMultiplexingSupported();
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500160 void dump() const;
Saurabh Shahc62f3982014-03-05 14:28:26 -0800161 /* Returns an available pipe based on the type of pipe requested. When ANY
162 * is requested, the first available VG or RGB is returned. If no pipe is
163 * available for the display "dpy" then INV is returned. Note: If a pipe is
164 * assigned to a certain display, then it cannot be assigned to another
165 * display without being garbage-collected once. To add if a pipe is
166 * asisgned to a mixer within a display it cannot be reused for another
167 * mixer without being UNSET once*/
168 utils::eDest nextPipe(utils::eMdpPipeType, int dpy, int mixer);
169 /* Helpers that enfore target specific policies while returning pipes */
170 utils::eDest getPipe_8x26(const PipeSpecs& pipeSpecs);
171 utils::eDest getPipe_8x16(const PipeSpecs& pipeSpecs);
172
Saurabh Shaha36be922013-12-16 18:18:39 -0800173 /* Returns the scalar object */
174 static scale::Scale *getScalar();
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700175 /* Creates a scalar object using libscale.so */
176 static void initScalar();
177 /* Destroys the scalar object using libscale.so */
178 static void destroyScalar();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700179
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500180 /* Just like a Facebook for pipes, but much less profile info */
181 struct PipeBook {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500182 void init();
183 void destroy();
184 /* Check if pipe exists and return true, false otherwise */
185 bool valid();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500187 /* Hardware pipe wrapper */
188 GenericPipe *mPipe;
189 /* Display using this pipe. Refer to enums above */
190 int mDisplay;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700191 /* Mixer within a split display this pipe is attached to */
192 int mMixer;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700193
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500194 /* operations on bitmap */
195 static bool pipeUsageUnchanged();
196 static void setUse(int index);
197 static void resetUse(int index);
198 static bool isUsed(int index);
199 static bool isNotUsed(int index);
200 static void save();
201
202 static void setAllocation(int index);
203 static void resetAllocation(int index);
204 static bool isAllocated(int index);
205 static bool isNotAllocated(int index);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500206
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800207 static utils::eMdpPipeType getPipeType(utils::eDest dest);
208 static const char* getDestStr(utils::eDest dest);
209
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500210 static int NUM_PIPES;
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800211 static utils::eMdpPipeType pipeTypeLUT[utils::OV_MAX];
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500212 /* Session for reserved pipes */
213 enum Session {
214 NONE,
215 START,
216 END
217 };
218 Session mSession;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500219
220 private:
221 //usage tracks if a successful commit happened. So a pipe could be
222 //allocated to a display, but it may not end up using it for various
223 //reasons. If one display actually uses a pipe then it amy not be
224 //used by another display, without an UNSET in between.
225 static int sPipeUsageBitmap;
226 static int sLastUsageBitmap;
227 //Tracks which pipe objects are allocated. This does not imply that they
228 //will actually be used. For example, a display might choose to acquire
229 //3 pipe objects in one shot and proceed with config only if it gets all
230 //3. The bitmap helps allocate different pipe objects on each request.
231 static int sAllocatedBitmap;
232 };
233
234 PipeBook mPipeBook[utils::OV_INVALID]; //Used as max
235
236 /* Dump string */
Saurabh Shah9dc88fc2013-07-15 16:02:30 -0700237 char mDumpStr[1024];
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500238
239 /* Singleton Instance*/
240 static Overlay *sInstance;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700241 static int sDpyFbMap[DPY_MAX];
Saurabh Shah85234ec2013-04-12 17:09:00 -0700242 static int sDMAMode;
Raj Kamala8c065f2013-10-22 14:52:45 +0530243 static bool sDMAMultiplexingSupported;
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700244 static void *sLibScaleHandle;
245 static scale::Scale *sScale;
Saurabh Shaha36be922013-12-16 18:18:39 -0800246
247 friend class MdpCtrl;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700248};
249
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500250inline void Overlay::validate(int index) {
251 OVASSERT(index >=0 && index < PipeBook::NUM_PIPES, \
252 "%s, Index out of bounds: %d", __FUNCTION__, index);
253 OVASSERT(mPipeBook[index].valid(), "Pipe does not exist %s",
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800254 PipeBook::getDestStr((utils::eDest)index));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500255}
256
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700257inline int Overlay::availablePipes(int dpy, int mixer) {
258 int avail = 0;
259 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
260 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
261 mPipeBook[i].mDisplay == dpy) &&
262 (mPipeBook[i].mMixer == MIXER_UNUSED ||
263 mPipeBook[i].mMixer == mixer) &&
264 PipeBook::isNotAllocated(i) &&
265 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
266 PipeBook::getPipeType((utils::eDest)i) ==
267 utils::OV_MDP_PIPE_DMA)) {
268 avail++;
Jeykumar Sankaranccb44602013-01-03 12:48:22 -0800269 }
270 }
271 return avail;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500272}
273
Saurabh Shah082468e2013-09-12 10:05:32 -0700274inline int Overlay::availablePipes(int dpy) {
275 int avail = 0;
276 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
277 if( (mPipeBook[i].mDisplay == DPY_UNUSED ||
278 mPipeBook[i].mDisplay == dpy) &&
279 PipeBook::isNotAllocated(i) &&
280 !(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE &&
281 PipeBook::getPipeType((utils::eDest)i) ==
282 utils::OV_MDP_PIPE_DMA)) {
283 avail++;
284 }
285 }
286 return avail;
287}
288
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700289inline int Overlay::availablePipes(int dpy, utils::eMdpPipeType type) {
290 int avail = 0;
291 for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
292 if((mPipeBook[i].mDisplay == DPY_UNUSED ||
293 mPipeBook[i].mDisplay == dpy) &&
294 PipeBook::isNotAllocated(i) &&
295 type == PipeBook::getPipeType((utils::eDest)i)) {
296 avail++;
297 }
298 }
299 return avail;
300}
301
Saurabh Shah85234ec2013-04-12 17:09:00 -0700302inline void Overlay::setDMAMode(const int& mode) {
303 if(mode == DMA_LINE_MODE || mode == DMA_BLOCK_MODE)
304 sDMAMode = mode;
305}
306
Raj Kamala8c065f2013-10-22 14:52:45 +0530307inline void Overlay::setDMAMultiplexingSupported() {
308 sDMAMultiplexingSupported = false;
309 if(qdutils::MDPVersion::getInstance().is8x26())
310 sDMAMultiplexingSupported = true;
311}
312
Raj Kamal068f4572014-04-14 16:14:06 +0530313inline bool Overlay::isDMAMultiplexingSupported() {
314 return sDMAMultiplexingSupported;
315}
316
317inline bool Overlay::isUIScalingOnExternalSupported() {
318 if(qdutils::MDPVersion::getInstance().is8x26() or
319 qdutils::MDPVersion::getInstance().is8x16()) {
320 return false;
321 }
322 return true;
323}
324
Saurabh Shah85234ec2013-04-12 17:09:00 -0700325inline int Overlay::getDMAMode() {
326 return sDMAMode;
327}
328
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700329inline int Overlay::getFbForDpy(const int& dpy) {
330 OVASSERT(dpy >= 0 && dpy < DPY_MAX, "Invalid dpy %d", dpy);
331 return sDpyFbMap[dpy];
332}
333
Saurabh Shahb8f58e22013-09-26 16:20:07 -0700334inline scale::Scale *Overlay::getScalar() {
335 return sScale;
336}
337
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500338inline bool Overlay::PipeBook::valid() {
339 return (mPipe != NULL);
340}
341
342inline bool Overlay::PipeBook::pipeUsageUnchanged() {
343 return (sPipeUsageBitmap == sLastUsageBitmap);
344}
345
346inline void Overlay::PipeBook::setUse(int index) {
347 sPipeUsageBitmap |= (1 << index);
348}
349
350inline void Overlay::PipeBook::resetUse(int index) {
351 sPipeUsageBitmap &= ~(1 << index);
352}
353
354inline bool Overlay::PipeBook::isUsed(int index) {
355 return sPipeUsageBitmap & (1 << index);
356}
357
358inline bool Overlay::PipeBook::isNotUsed(int index) {
359 return !isUsed(index);
360}
361
362inline void Overlay::PipeBook::save() {
363 sLastUsageBitmap = sPipeUsageBitmap;
364}
365
366inline void Overlay::PipeBook::setAllocation(int index) {
367 sAllocatedBitmap |= (1 << index);
368}
369
370inline void Overlay::PipeBook::resetAllocation(int index) {
371 sAllocatedBitmap &= ~(1 << index);
372}
373
374inline bool Overlay::PipeBook::isAllocated(int index) {
375 return sAllocatedBitmap & (1 << index);
376}
377
378inline bool Overlay::PipeBook::isNotAllocated(int index) {
379 return !isAllocated(index);
380}
381
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800382inline utils::eMdpPipeType Overlay::PipeBook::getPipeType(utils::eDest dest) {
383 return pipeTypeLUT[(int)dest];
384}
385
Zohaib Alam4b0a9242013-11-20 23:54:12 -0500386inline void Overlay::startSession(utils::eDest dest) {
387 mPipeBook[(int)dest].mSession = PipeBook::START;
388}
389
390inline bool Overlay::sessionInProgress(utils::eDest dest) {
391 return (mPipeBook[(int)dest].mSession == PipeBook::START);
392}
393
394inline bool Overlay::isSessionEnded(utils::eDest dest) {
395 return (mPipeBook[(int)dest].mSession == PipeBook::END);
396}
397
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800398inline const char* Overlay::PipeBook::getDestStr(utils::eDest dest) {
399 switch(getPipeType(dest)) {
400 case utils::OV_MDP_PIPE_RGB: return "RGB";
401 case utils::OV_MDP_PIPE_VG: return "VG";
402 case utils::OV_MDP_PIPE_DMA: return "DMA";
403 default: return "Invalid";
404 }
405 return "Invalid";
406}
407
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500408}; // overlay
Naseer Ahmed29a26812012-06-14 00:56:20 -0700409
410#endif // OVERLAY_H