Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / gpu / drm / vmwgfx / svga_overlay.h
1 /**********************************************************
2  * Copyright 2007-2009 VMware, Inc.  All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  **********************************************************/
25
26 /*
27  * svga_overlay.h --
28  *
29  *    Definitions for video-overlay support.
30  */
31
32 #ifndef _SVGA_OVERLAY_H_
33 #define _SVGA_OVERLAY_H_
34
35 #include "svga_reg.h"
36
37 /*
38  * Video formats we support
39  */
40
41 #define VMWARE_FOURCC_YV12 0x32315659 /* 'Y' 'V' '1' '2' */
42 #define VMWARE_FOURCC_YUY2 0x32595559 /* 'Y' 'U' 'Y' '2' */
43 #define VMWARE_FOURCC_UYVY 0x59565955 /* 'U' 'Y' 'V' 'Y' */
44
45 typedef enum {
46    SVGA_OVERLAY_FORMAT_INVALID = 0,
47    SVGA_OVERLAY_FORMAT_YV12 = VMWARE_FOURCC_YV12,
48    SVGA_OVERLAY_FORMAT_YUY2 = VMWARE_FOURCC_YUY2,
49    SVGA_OVERLAY_FORMAT_UYVY = VMWARE_FOURCC_UYVY,
50 } SVGAOverlayFormat;
51
52 #define SVGA_VIDEO_COLORKEY_MASK             0x00ffffff
53
54 #define SVGA_ESCAPE_VMWARE_VIDEO             0x00020000
55
56 #define SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS    0x00020001
57         /* FIFO escape layout:
58          * Type, Stream Id, (Register Id, Value) pairs */
59
60 #define SVGA_ESCAPE_VMWARE_VIDEO_FLUSH       0x00020002
61         /* FIFO escape layout:
62          * Type, Stream Id */
63
64 typedef
65 struct SVGAEscapeVideoSetRegs {
66    struct {
67       uint32 cmdType;
68       uint32 streamId;
69    } header;
70
71    /* May include zero or more items. */
72    struct {
73       uint32 registerId;
74       uint32 value;
75    } items[1];
76 } SVGAEscapeVideoSetRegs;
77
78 typedef
79 struct SVGAEscapeVideoFlush {
80    uint32 cmdType;
81    uint32 streamId;
82 } SVGAEscapeVideoFlush;
83
84
85 /*
86  * Struct definitions for the video overlay commands built on
87  * SVGAFifoCmdEscape.
88  */
89 typedef
90 struct {
91    uint32 command;
92    uint32 overlay;
93 } SVGAFifoEscapeCmdVideoBase;
94
95 typedef
96 struct {
97    SVGAFifoEscapeCmdVideoBase videoCmd;
98 } SVGAFifoEscapeCmdVideoFlush;
99
100 typedef
101 struct {
102    SVGAFifoEscapeCmdVideoBase videoCmd;
103    struct {
104       uint32 regId;
105       uint32 value;
106    } items[1];
107 } SVGAFifoEscapeCmdVideoSetRegs;
108
109 typedef
110 struct {
111    SVGAFifoEscapeCmdVideoBase videoCmd;
112    struct {
113       uint32 regId;
114       uint32 value;
115    } items[SVGA_VIDEO_NUM_REGS];
116 } SVGAFifoEscapeCmdVideoSetAllRegs;
117
118
119 /*
120  *----------------------------------------------------------------------
121  *
122  * VMwareVideoGetAttributes --
123  *
124  *      Computes the size, pitches and offsets for YUV frames.
125  *
126  * Results:
127  *      TRUE on success; otherwise FALSE on failure.
128  *
129  * Side effects:
130  *      Pitches and offsets for the given YUV frame are put in 'pitches'
131  *      and 'offsets' respectively. They are both optional though.
132  *
133  *----------------------------------------------------------------------
134  */
135
136 static inline bool
137 VMwareVideoGetAttributes(const SVGAOverlayFormat format,    /* IN */
138                          uint32 *width,                     /* IN / OUT */
139                          uint32 *height,                    /* IN / OUT */
140                          uint32 *size,                      /* OUT */
141                          uint32 *pitches,                   /* OUT (optional) */
142                          uint32 *offsets)                   /* OUT (optional) */
143 {
144     int tmp;
145
146     *width = (*width + 1) & ~1;
147
148     if (offsets) {
149         offsets[0] = 0;
150     }
151
152     switch (format) {
153     case VMWARE_FOURCC_YV12:
154        *height = (*height + 1) & ~1;
155        *size = (*width + 3) & ~3;
156
157        if (pitches) {
158           pitches[0] = *size;
159        }
160
161        *size *= *height;
162
163        if (offsets) {
164           offsets[1] = *size;
165        }
166
167        tmp = ((*width >> 1) + 3) & ~3;
168
169        if (pitches) {
170           pitches[1] = pitches[2] = tmp;
171        }
172
173        tmp *= (*height >> 1);
174        *size += tmp;
175
176        if (offsets) {
177           offsets[2] = *size;
178        }
179
180        *size += tmp;
181        break;
182
183     case VMWARE_FOURCC_YUY2:
184     case VMWARE_FOURCC_UYVY:
185        *size = *width * 2;
186
187        if (pitches) {
188           pitches[0] = *size;
189        }
190
191        *size *= *height;
192        break;
193
194     default:
195        return false;
196     }
197
198     return true;
199 }
200
201 #endif /* _SVGA_OVERLAY_H_ */